formguide_input.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. class formguide_input {
  3. var $formid;
  4. var $fields;
  5. var $data;
  6. function __construct($formid) {
  7. $this->formid = $formid;
  8. $this->fields = getcache('formguide_field_'.$formid, 'model');
  9. $this->siteid = get_siteid();
  10. //初始化附件类
  11. pc_base::load_sys_class('attachment','',0);
  12. $this->siteid = param::get_cookie('siteid');
  13. $this->attachment = new attachment('formguide','0',$this->siteid);
  14. $this->site_config = getcache('sitelist','commons');
  15. $this->site_config = $this->site_config[$this->siteid];
  16. }
  17. function get($data,$isimport = 0) {
  18. $this->data = $data = trim_script($data);
  19. $info = array();
  20. foreach($this->fields as $field) {
  21. //if(!isset($this->fields[$field]) || check_in($_roleid, $this->fields[$field]['unsetroleids']) || check_in($_groupid, $this->fields[$field]['unsetgroupids'])) continue;
  22. $name = $field['name'];
  23. $minlength = $field['minlength'];
  24. $maxlength = $field['maxlength'];
  25. $pattern = $field['pattern'];
  26. $errortips = $field['errortips'];
  27. $value = $data[$field['field']];
  28. if(empty($errortips)) $errortips = $name.' '.L('not_meet_the_conditions');
  29. $length = is_array($value) ? (empty($value) ? 0 : 1) : strlen($value);
  30. if($minlength && $length < $minlength) {
  31. if($isimport) {
  32. return false;
  33. } else {
  34. showmessage($name.' '.L('not_less_than').' '.$minlength.L('characters'));
  35. }
  36. }
  37. if($maxlength && $length > $maxlength) {
  38. if($isimport) {
  39. $value = str_cut($value,$maxlength,'');
  40. } else {
  41. showmessage($name.' '.L('not_more_than').' '.$maxlength.L('characters'));
  42. }
  43. } elseif($maxlength) {
  44. $value = str_cut($value,$maxlength,'');
  45. }
  46. if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);
  47. $func = $field['formtype'];
  48. if(method_exists($this, $func)) $value = $this->$func($field['field'], $value);
  49. $info[$field['field']] = $value;
  50. //颜色选择为隐藏域 在这里进行取值
  51. if ($_POST['style_color']) $info['style'] = $_POST['style_color'];
  52. if($_POST['style_font_weight']) $info['style'] = $info['style'].';'.strip_tags($_POST['style_font_weight']);
  53. }
  54. return $info;
  55. }
  56. function textarea($field, $value) {
  57. if(!$this->fields[$field]['enablehtml']) $value = strip_tags($value);
  58. return $value;
  59. }
  60. function editor($field, $value) {
  61. $setting = string2array($this->fields[$field]['setting']);
  62. $enablesaveimage = $setting['enablesaveimage'];
  63. $site_setting = string2array($this->site_config['setting']);
  64. $watermark_enable = intval($site_setting['watermark_enable']);
  65. $value = $this->attachment->download('content', $value,$watermark_enable);
  66. return $value;
  67. }
  68. function box($field, $value) {
  69. if($this->fields[$field]['boxtype'] == 'checkbox') {
  70. if(!is_array($value) || empty($value)) return false;
  71. array_shift($value);
  72. $value = implode(',', $value);
  73. return $value;
  74. } elseif($this->fields[$field]['boxtype'] == 'multiple') {
  75. if(is_array($value) && count($value)>1) {
  76. $value = implode(',', $value);
  77. return $value;
  78. }
  79. } else {
  80. return $value;
  81. }
  82. }
  83. function images($field, $value) {
  84. //取得图片列表
  85. $pictures = $_POST[$field.'_url'];
  86. //取得图片说明
  87. $pictures_alt = isset($_POST[$field.'_alt']) ? $_POST[$field.'_alt'] : array();
  88. $array = $temp = array();
  89. if(!empty($pictures)) {
  90. foreach($pictures as $key=>$pic) {
  91. $temp['url'] = $pic;
  92. $temp['alt'] = str_replace(array('"',"'"),'`',$pictures_alt[$key]);
  93. $array[$key] = $temp;
  94. }
  95. }
  96. $array = array2string($array);
  97. return $array;
  98. }
  99. function datetime($field, $value) {
  100. $setting = string2array($this->fields[$field]['setting']);
  101. if($setting['fieldtype']=='int') {
  102. $value = strtotime($value);
  103. }
  104. return $value;
  105. }
  106. }
  107. ?>