content_input.class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. class content_input {
  3. var $modelid;
  4. var $fields;
  5. var $data;
  6. function __construct($modelid) {
  7. $this->db = pc_base::load_model('sitemodel_field_model');
  8. $this->db_pre = $this->db->db_tablepre;
  9. $this->modelid = $modelid;
  10. $this->fields = getcache('model_field_'.$modelid,'model');
  11. //初始化附件类
  12. pc_base::load_sys_class('attachment','',0);
  13. $this->siteid = param::get_cookie('siteid');
  14. $this->attachment = new attachment('content','0',$this->siteid);
  15. $this->site_config = getcache('sitelist','commons');
  16. $this->site_config = $this->site_config[$this->siteid];
  17. }
  18. function get($data,$isimport = 0) {
  19. //$this->data = $data = trim_script($data);
  20. $this->data = $data;
  21. $info = array();
  22. foreach($data as $field=>$value) {
  23. if(!isset($this->fields[$field]) && !check_in($field,'paytype,paginationtype,maxcharperpage,id')) continue;
  24. if(defined('IN_ADMIN')) {
  25. if(check_in($_SESSION['roleid'], $this->fields[$field]['unsetroleids'])) continue;
  26. } else {
  27. $_groupid = param::get_cookie('_groupid');
  28. if(check_in($_groupid, $this->fields[$field]['unsetgroupids'])) continue;
  29. }
  30. $name = $this->fields[$field]['name'];
  31. $minlength = $this->fields[$field]['minlength'];
  32. $maxlength = $this->fields[$field]['maxlength'];
  33. $pattern = $this->fields[$field]['pattern'];
  34. $errortips = $this->fields[$field]['errortips'];
  35. if(empty($errortips)) $errortips = $name.' '.L('not_meet_the_conditions');
  36. $length = empty($value) ? 0 : (is_string($value) ? strlen($value) : count($value));
  37. if($minlength && $length < $minlength) {
  38. if($isimport) {
  39. return false;
  40. } else {
  41. showmessage($name.' '.L('not_less_than').' '.$minlength.L('characters'));
  42. }
  43. }
  44. if($maxlength && $length > $maxlength) {
  45. if($isimport) {
  46. $value = str_cut($value,$maxlength,'');
  47. } else {
  48. showmessage($name.' '.L('not_more_than').' '.$maxlength.L('characters'));
  49. }
  50. } elseif($maxlength) {
  51. $value = str_cut($value,$maxlength,'');
  52. }
  53. if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);
  54. $MODEL = getcache('model', 'commons');
  55. $this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre.$MODEL[$this->modelid]['tablename'] : $this->db_pre.$MODEL[$this->modelid]['tablename'].'_data';
  56. if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage($name.L('the_value_must_not_repeat'));
  57. $func = $this->fields[$field]['formtype'];
  58. if(method_exists($this, $func)) $value = $this->$func($field, $value);
  59. if($this->fields[$field]['issystem']) {
  60. $info['system'][$field] = $value;
  61. } else {
  62. $info['model'][$field] = $value;
  63. }
  64. //颜色选择为隐藏域 在这里进行取值
  65. $info['system']['style'] = $_POST['style_color'] && preg_match('/^#([0-9a-z]+)/i', $_POST['style_color']) ? $_POST['style_color'] : '';
  66. if($_POST['style_font_weight']=='bold') $info['system']['style'] = $info['system']['style'].';'.strip_tags($_POST['style_font_weight']);
  67. }
  68. return $info;
  69. }
  70. function textarea($field, $value) {
  71. if(!$this->fields[$field]['enablehtml']) $value = strip_tags($value);
  72. return $value;
  73. }
  74. function editor($field, $value) {
  75. $setting = string2array($this->fields[$field]['setting']);
  76. $enablesaveimage = $setting['enablesaveimage'];
  77. if(isset($_POST['spider_img'])) $enablesaveimage = 0;
  78. if($enablesaveimage) {
  79. $site_setting = string2array($this->site_config['setting']);
  80. $watermark_enable = intval($site_setting['watermark_enable']);
  81. $value = $this->attachment->download('content', $value,$watermark_enable);
  82. }
  83. return $value;
  84. }
  85. function box($field, $value) {
  86. if($this->fields[$field]['boxtype'] == 'checkbox') {
  87. if(!is_array($value) || empty($value)) return false;
  88. array_shift($value);
  89. $value = ','.implode(',', $value).',';
  90. return $value;
  91. } elseif($this->fields[$field]['boxtype'] == 'multiple') {
  92. if(is_array($value) && count($value)>0) {
  93. $value = ','.implode(',', $value).',';
  94. return $value;
  95. }
  96. } else {
  97. return $value;
  98. }
  99. }
  100. function image($field, $value) {
  101. $value = remove_xss(str_replace(array("'",'"','(',')'),'',$value));
  102. $value = safe_replace($value);
  103. return trim($value);
  104. }
  105. function images($field, $value) {
  106. //取得图片列表
  107. $pictures = $_POST[$field.'_url'];
  108. //取得图片说明
  109. $pictures_alt = isset($_POST[$field.'_alt']) ? $_POST[$field.'_alt'] : array();
  110. $array = $temp = array();
  111. if(!empty($pictures)) {
  112. foreach($pictures as $key=>$pic) {
  113. $temp['url'] = $pic;
  114. $temp['alt'] = str_replace(array('"',"'"),'`',$pictures_alt[$key]);
  115. $array[$key] = $temp;
  116. }
  117. }
  118. $array = array2string($array);
  119. return $array;
  120. }
  121. function datetime($field, $value) {
  122. $setting = string2array($this->fields[$field]['setting']);
  123. if($setting['fieldtype']=='int') {
  124. $value = strtotime($value);
  125. }
  126. return $value;
  127. }
  128. function posid($field, $value) {
  129. $number = count($value);
  130. $value = $number==1 ? 0 : 1;
  131. return $value;
  132. }
  133. function copyfrom($field, $value) {
  134. $field_data = $field.'_data';
  135. if(isset($_POST[$field_data])) {
  136. $value .= '|'.safe_replace($_POST[$field_data]);
  137. }
  138. return $value;
  139. }
  140. function groupid($field, $value) {
  141. $datas = '';
  142. if(!empty($_POST[$field]) && is_array($_POST[$field])) {
  143. $datas = implode(',',$_POST[$field]);
  144. }
  145. return $datas;
  146. }
  147. function downfile($field, $value) {
  148. //取得镜像站点列表
  149. $result = '';
  150. $server_list = count($_POST[$field.'_servers']) > 0 ? implode(',' ,$_POST[$field.'_servers']) : '';
  151. $result = $value.'|'.$server_list;
  152. return $result;
  153. }
  154. function file($field, $value) {
  155. return trim($value);
  156. }
  157. function downfiles($field, $value) {
  158. $files = $_POST[$field.'_fileurl'];
  159. $files_alt = $_POST[$field.'_filename'];
  160. $array = $temp = array();
  161. if(!empty($files)) {
  162. foreach($files as $key=>$file) {
  163. $temp['fileurl'] = $file;
  164. $temp['filename'] = $files_alt[$key];
  165. $array[$key] = $temp;
  166. }
  167. }
  168. $array = array2string($array);
  169. return $array;
  170. }
  171. function video($field, $value) {
  172. $post_f = $field.'_video';
  173. if (isset($_POST[$post_f]) && !empty($_POST[$post_f])) {
  174. $value = 1;
  175. $video_store_db = pc_base::load_model('video_store_model');
  176. $setting = getcache('video', 'video');
  177. pc_base::load_app_class('ku6api', 'video', 0);
  178. $ku6api = new ku6api($setting['sn'], $setting['skey']);
  179. pc_base::load_app_class('v', 'video', 0);
  180. $v_class = new v($video_store_db);
  181. $GLOBALS[$field] = '';
  182. foreach ($_POST[$post_f] as $_k => $v) {
  183. if (!$v['vid'] && !$v['videoid']) unset($_POST[$post_f][$_k]);
  184. $info = array();
  185. if (!$v['title']) $v['title'] = safe_replace($this->data['title']);
  186. if ($v['vid']) {
  187. $info = array('vid'=>$v['vid'], 'title'=>$v['title'], 'cid'=>intval($this->data['catid']));
  188. $info['channelid'] = intval($_POST['channelid']);
  189. if ($this->data['keywords']) $info['tag'] = addslashes($this->data['keywords']);
  190. if ($this->data['description']) $info['description'] = addslashes($this->data['description']);
  191. $get_data = $ku6api->vms_add($info);
  192. if (!$get_data) {
  193. continue;
  194. }
  195. $info['vid'] = $get_data['vid'];
  196. $info['addtime'] = SYS_TIME;
  197. $info['keywords'] = $info['tag'];
  198. unset($info['cid'], $info['tag']);
  199. $info['userupload'] = 1;
  200. $videoid = $v_class->add($info);
  201. $GLOBALS[$field][] = array('videoid' => $videoid, 'listorder' => $v['listorder']);
  202. } else {
  203. $v_class->edit(array('title'=>$v['title']), $v['videoid']);
  204. $GLOBALS[$field][] = array('videoid' => $v['videoid'], 'listorder' => $v['listorder']);
  205. }
  206. }
  207. } else {
  208. $value = 0;
  209. }
  210. return $value;
  211. }
  212. }
  213. ?>