content_form.class.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. class content_form {
  3. var $modelid;
  4. var $fields;
  5. var $id;
  6. var $formValidator;
  7. function __construct($modelid,$catid = 0,$categorys = array()) {
  8. $this->modelid = $modelid;
  9. $this->catid = $catid;
  10. $this->categorys = $categorys;
  11. $this->fields = getcache('model_field_'.$modelid,'model');
  12. $this->siteid = get_siteid();
  13. }
  14. function get($data = array()) {
  15. $_groupid = param::get_cookie('_groupid');
  16. $this->data = $data;
  17. if(isset($data['id'])) $this->id = $data['id'];
  18. $info = array();
  19. $this->content_url = $data['url'];
  20. foreach($this->fields as $field=>$v) {
  21. if(defined('IN_ADMIN')) {
  22. if($v['iscore'] || check_in($_SESSION['roleid'], $v['unsetroleids'])) continue;
  23. } else {
  24. if($v['iscore'] || !$v['isadd'] || check_in($_groupid, $v['unsetgroupids'])) continue;
  25. }
  26. $func = $v['formtype'];
  27. $value = isset($data[$field]) ? new_html_special_chars($data[$field]) : '';
  28. if($func=='pages' && isset($data['maxcharperpage'])) {
  29. $value = $data['paginationtype'].'|'.$data['maxcharperpage'];
  30. }
  31. if(!method_exists($this, $func)) continue;
  32. $form = $this->$func($field, $value, $v);
  33. if($form !== false) {
  34. if(defined('IN_ADMIN')) {
  35. if($v['isbase']) {
  36. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  37. $info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  38. } else {
  39. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  40. $info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  41. }
  42. } else {
  43. $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
  44. $info[$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star,'isomnipotent'=>$v['isomnipotent'],'formtype'=>$v['formtype']);
  45. }
  46. }
  47. }
  48. return $info;
  49. }
  50. function text($field, $value, $fieldinfo) {
  51. extract($fieldinfo);
  52. $setting = string2array($setting);
  53. $size = $setting['size'];
  54. if(!$value) $value = $defaultvalue;
  55. $type = $ispassword ? 'password' : 'text';
  56. $errortips = $this->fields[$field]['errortips'];
  57. if($errortips || $minlength) $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"",onfocus:"'.$errortips.'"}).inputValidator({min:1,onerror:"'.$errortips.'"});';
  58. return '<input type="text" name="info['.$field.']" id="'.$field.'" size="'.$size.'" value="'.$value.'" class="input-text" '.$formattribute.' '.$css.'>';
  59. }
  60. function textarea($field, $value, $fieldinfo) {
  61. extract($fieldinfo);
  62. $setting = string2array($setting);
  63. extract($setting);
  64. if(!$value) $value = $defaultvalue;
  65. $allow_empty = 'empty:true,';
  66. if($minlength || $pattern) $allow_empty = '';
  67. if($errortips) $this->formValidator .= '$("#'.$field.'").formValidator({'.$allow_empty.'onshow:"'.$errortips.'",onfocus:"'.$errortips.'"}).inputValidator({min:1,onerror:"'.$errortips.'"});';
  68. $value = empty($value) ? $setting[defaultvalue] : $value;
  69. $str = "<textarea name='info[{$field}]' id='$field' style='width:{$width}%;height:{$height}px;' $formattribute $css";
  70. if($maxlength) $str .= " onkeyup=\"strlen_verify(this, '{$field}_len', {$maxlength})\"";
  71. $str .= ">{$value}</textarea>";
  72. if($maxlength) $str .= L('can_enter').'<B><span id="'.$field.'_len">'.$maxlength.'</span></B> '.L('characters');
  73. return $str;
  74. }
  75. function editor($field, $value, $fieldinfo) {
  76. $grouplist = getcache('grouplist','member');
  77. $_groupid = param::get_cookie('_groupid');
  78. $grouplist = $grouplist[$_groupid];
  79. extract($fieldinfo);
  80. extract(string2array($setting));
  81. $disabled_page = isset($disabled_page) ? $disabled_page : 0;
  82. if(!$height) $height = 300;
  83. $allowupload = defined('IN_ADMIN') ? 1 : $grouplist['allowattachment'] ? 1: 0;
  84. if(!$value) $value = $defaultvalue;
  85. //if(!$toolvalue) $toolvalue = '\'Source\',\'Bold\', \'Italic\', \'Underline\'';
  86. if($minlength || $pattern) $allow_empty = '';
  87. if($minlength) $this->formValidator .= '$("#'.$field.'").formValidator({'.$allow_empty.'onshow:"",onfocus:"'.$errortips.'"}).functionValidator({
  88. fun:function(val,elem){
  89. var oEditor = CKEDITOR.instances.'.$field.';
  90. var data = oEditor.getData();
  91. if($(\'#islink\').attr(\'checked\')){
  92. return true;
  93. } else if(($(\'#islink\').attr(\'checked\')==false) && (data==\'\')){
  94. return "'.$errortips.'";
  95. } else if (data==\'\' || $.trim(data)==\'\') {
  96. return "'.$errortips.'";
  97. }
  98. return true;
  99. }
  100. });';
  101. return "<div id='{$field}_tip'></div>".'<textarea name="info['.$field.']" id="'.$field.'" boxid="'.$field.'">'.$value.'</textarea>'.form::editor($field,$toolbar,$toolvalue,'content',$this->catid,'',$allowupload,1,'',$height,$disabled_page);
  102. }
  103. function catid($field, $value, $fieldinfo) {
  104. if(!$value) $value = $this->catid;
  105. $publish_str = '';
  106. if(defined('IN_ADMIN') && ROUTE_A=='add') $publish_str = " <a href='javascript:;' onclick=\"omnipotent('selectid','?m=content&c=content&a=add_othors&siteid=".$this->siteid."','".L('publish_to_othor_category')."',1);return false;\" style='color:#B5BFBB'>[".L('publish_to_othor_category')."]</a><ul class='list-dot-othors' id='add_othors_text'></ul>";
  107. return '<input type="hidden" name="info['.$field.']" value="'.$value.'">'.$this->categorys[$value]['catname'].$publish_str;
  108. }
  109. function title($field, $value, $fieldinfo) {
  110. extract($fieldinfo);
  111. $style_arr = explode(';',$this->data['style']);
  112. $style_color = $style_arr[0];
  113. $style_font_weight = $style_arr[1] ? $style_arr[1] : '';
  114. $style = 'color:'.$this->data['style'];
  115. if(!$value) $value = $defaultvalue;
  116. $errortips = $this->fields[$field]['errortips'];
  117. $errortips_max = L('title_is_empty');
  118. if($errortips) $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"",onfocus:"'.$errortips.'"}).inputValidator({min:'.$minlength.',max:'.$maxlength.',onerror:"'.$errortips_max.'"});';
  119. $str = '<input type="text" style="width:400px;'.($style_color ? 'color:'.$style_color.';' : '').($style_font_weight ? 'font-weight:'.$style_font_weight.';' : '').'" name="info['.$field.']" id="'.$field.'" value="'.$value.'" style="'.$style.'" class="measure-input " onBlur="$.post(\'api.php?op=get_keywords&number=3&sid=\'+Math.random()*5, {data:$(\'#title\').val()}, function(data){if(data && $(\'#keywords\').val()==\'\') $(\'#keywords\').val(data); })" onkeyup="strlen_verify(this, \'title_len\', '.$maxlength.');"/><input type="hidden" name="style_color" id="style_color" value="'.$style_color.'">
  120. <input type="hidden" name="style_font_weight" id="style_font_weight" value="'.$style_font_weight.'">';
  121. if(defined('IN_ADMIN')) $str .= '<input type="button" class="button" id="check_title_alt" value="'.L('check_title','','content').'" onclick="$.get(\'?m=content&c=content&a=public_check_title&catid='.$this->catid.'&sid=\'+Math.random()*5, {data:$(\'#title\').val()}, function(data){if(data==\'1\') {$(\'#check_title_alt\').val(\''.L('title_repeat').'\');$(\'#check_title_alt\').css(\'background-color\',\'#FFCC66\');} else if(data==\'0\') {$(\'#check_title_alt\').val(\''.L('title_not_repeat').'\');$(\'#check_title_alt\').css(\'background-color\',\'#F8FFE1\')}})" style="width:73px;"/><img src="'.IMG_PATH.'icon/colour.png" width="15" height="16" onclick="colorpicker(\''.$field.'_colorpanel\',\'set_title_color\');" style="cursor:hand"/>
  122. <img src="'.IMG_PATH.'icon/bold.png" width="10" height="10" onclick="input_font_bold()" style="cursor:hand"/> <span id="'.$field.'_colorpanel" style="position:absolute;" class="colorpanel"></span>';
  123. $str .= L('can_enter').'<B><span id="title_len">'.$maxlength.'</span></B> '.L('characters');
  124. return $str;
  125. }
  126. function box($field, $value, $fieldinfo) {
  127. $setting = string2array($fieldinfo['setting']);
  128. if($value=='') $value = $this->fields[$field]['defaultvalue'];
  129. $options = explode("\n",$this->fields[$field]['options']);
  130. foreach($options as $_k) {
  131. $v = explode("|",$_k);
  132. $k = trim($v[1]);
  133. $option[$k] = $v[0];
  134. }
  135. $values = explode(',',$value);
  136. $value = array();
  137. foreach($values as $_k) {
  138. if($_k != '') $value[] = $_k;
  139. }
  140. $value = implode(',',$value);
  141. switch($this->fields[$field]['boxtype']) {
  142. case 'radio':
  143. $string = form::radio($option,$value,"name='info[$field]' $fieldinfo[formattribute]",$setting['width'],$field);
  144. break;
  145. case 'checkbox':
  146. $string = form::checkbox($option,$value,"name='info[$field][]' $fieldinfo[formattribute]",1,$setting['width'],$field);
  147. break;
  148. case 'select':
  149. $string = form::select($option,$value,"name='info[$field]' id='$field' $fieldinfo[formattribute]");
  150. break;
  151. case 'multiple':
  152. $string = form::select($option,$value,"name='info[$field][]' id='$field ' size=2 multiple='multiple' style='height:60px;' $fieldinfo[formattribute]");
  153. break;
  154. }
  155. return $string;
  156. }
  157. function image($field, $value, $fieldinfo) {
  158. $setting = string2array($fieldinfo['setting']);
  159. extract($setting);
  160. if(!defined('IMAGES_INIT')) {
  161. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  162. define('IMAGES_INIT', 1);
  163. }
  164. $html = '';
  165. if (defined('IN_ADMIN')) {
  166. $html = "<input type=\"button\" style=\"width: 66px;\" class=\"button\" onclick=\"crop_cut_".$field."($('#$field').val());return false;\" value=\"".L('cut_the_picture','','content')."\"><input type=\"button\" style=\"width: 66px;\" class=\"button\" onclick=\"$('#".$field."_preview').attr('src','".IMG_PATH."icon/upload-pic.png');$('#".$field."').val(' ');return false;\" value=\"".L('cancel_the_picture','','content')."\"><script type=\"text/javascript\">function crop_cut_".$field."(id){
  167. if (id=='') { alert('".L('upload_thumbnails', '', 'content')."');return false;}
  168. window.top.art.dialog({title:'".L('cut_the_picture','','content')."', id:'crop', iframe:'index.php?m=content&c=content&a=public_crop&module=content&catid='+catid+'&picurl='+encodeURIComponent(id)+'&input=$field&preview=".($show_type && defined('IN_ADMIN') ? $field."_preview" : '')."', width:'680px', height:'480px'}, function(){var d = window.top.art.dialog({id:'crop'}).data.iframe;
  169. d.uploadfile();return false;}, function(){window.top.art.dialog({id:'crop'}).close()});
  170. };</script>";
  171. }
  172. $authkey = upload_key("1,$upload_allowext,$isselectimage,$images_width,$images_height,$watermark");
  173. if($show_type && defined('IN_ADMIN')) {
  174. $preview_img = $value ? $value : IMG_PATH.'icon/upload-pic.png';
  175. return $str."<div class='upload-pic img-wrap'><input type='hidden' name='info[$field]' id='$field' value='$value'>
  176. <a href='javascript:void(0);' onclick=\"flashupload('{$field}_images', '".L('attachment_upload', '', 'content')."','{$field}',thumb_images,'1,{$upload_allowext},$isselectimage,$images_width,$images_height,$watermark','content','$this->catid','$authkey');return false;\">
  177. <img src='$preview_img' id='{$field}_preview' width='135' height='113' style='cursor:hand' /></a>".$html."</div>";
  178. } else {
  179. return $str."<input type='text' name='info[$field]' id='$field' value='$value' size='$size' class='input-text' /> <input type='button' class='button' onclick=\"flashupload('{$field}_images', '".L('attachment_upload', '', 'content')."','{$field}',submit_images,'1,{$upload_allowext},$isselectimage,$images_width,$images_height,$watermark','content','$this->catid','$authkey')\"/ value='".L('upload_pic', '', 'content')."'>".$html;
  180. }
  181. }
  182. function images($field, $value, $fieldinfo) {
  183. extract($fieldinfo);
  184. $list_str = '';
  185. if($value) {
  186. $value = string2array(new_html_entity_decode($value));
  187. if(is_array($value)) {
  188. foreach($value as $_k=>$_v) {
  189. $list_str .= "<div id='image_{$field}_{$_k}' style='padding:1px'><input type='text' name='{$field}_url[]' value='{$_v[url]}' style='width:310px;' ondblclick='image_priview(this.value);' class='input-text'> <input type='text' name='{$field}_alt[]' value='{$_v[alt]}' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('image_{$field}_{$_k}')\">".L('remove_out', '', 'content')."</a></div>";
  190. }
  191. }
  192. } else {
  193. $list_str .= "<center><div class='onShow' id='nameTip'>".L('upload_pic_max', '', 'content')." <font color='red'>{$upload_number}</font> ".L('tips_pics', '', 'content')."</div></center>";
  194. }
  195. $string = '<input name="info['.$field.']" type="hidden" value="1">
  196. <fieldset class="blue pad-10">
  197. <legend>'.L('pic_list').'</legend>';
  198. $string .= $list_str;
  199. $string .= '<div id="'.$field.'" class="picList"></div>
  200. </fieldset>
  201. <div class="bk10"></div>
  202. ';
  203. if(!defined('IMAGES_INIT')) {
  204. $str = '<script type="text/javascript" src="statics/js/swfupload/swf2ckeditor.js"></script>';
  205. define('IMAGES_INIT', 1);
  206. }
  207. $authkey = upload_key("$upload_number,$upload_allowext,$isselectimage");
  208. $string .= $str."<div class='picBut cu'><a href='javascript:void(0);' onclick=\"javascript:flashupload('{$field}_images', '".L('attachment_upload')."','{$field}',change_images,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/> ".L('select_pic')." </a></div>";
  209. return $string;
  210. } function number($field, $value, $fieldinfo) {
  211. extract($fieldinfo);
  212. $setting = string2array($setting);
  213. $size = $setting['size'];
  214. if(!$value) $value = $defaultvalue;
  215. return "<input type='text' name='info[$field]' id='$field' value='$value' class='input-text' size='$size' {$formattribute} {$css}>";
  216. }
  217. function datetime($field, $value, $fieldinfo) {
  218. extract(string2array($fieldinfo['setting']));
  219. $isdatetime = 0;
  220. $timesystem = 0;
  221. if($fieldtype=='int') {
  222. if(!$value) $value = SYS_TIME;
  223. $format_txt = $format == 'm-d' ? 'm-d' : $format;
  224. if($format == 'Y-m-d Ah:i:s') $format_txt = 'Y-m-d h:i:s';
  225. $value = date($format_txt,$value);
  226. $isdatetime = strlen($format) > 6 ? 1 : 0;
  227. if($format == 'Y-m-d Ah:i:s') {
  228. $timesystem = 0;
  229. } else {
  230. $timesystem = 1;
  231. }
  232. } elseif($fieldtype=='datetime') {
  233. $isdatetime = 1;
  234. $timesystem = 1;
  235. } elseif($fieldtype=='datetime_a') {
  236. $isdatetime = 1;
  237. $timesystem = 0;
  238. }
  239. return form::date("info[$field]",$value,$isdatetime,1,'true',$timesystem);
  240. }
  241. function posid($field, $value, $fieldinfo) {
  242. $setting = string2array($fieldinfo['setting']);
  243. $position = getcache('position','commons');
  244. if(empty($position)) return '';
  245. $array = array();
  246. foreach($position as $_key=>$_value) {
  247. if($_value['modelid'] && ($_value['modelid'] != $this->modelid) || ($_value['catid'] && strpos(','.$this->categorys[$_value['catid']]['arrchildid'].',',','.$this->catid.',')===false)) continue;
  248. $array[$_key] = $_value['name'];
  249. }
  250. $posids = array();
  251. if(ROUTE_A=='edit') {
  252. $this->position_data_db = pc_base::load_model('position_data_model');
  253. $result = $this->position_data_db->select(array('id'=>$this->id,'modelid'=>$this->modelid),'*','','','','posid');
  254. $posids = implode(',', array_keys($result));
  255. } else {
  256. $posids = $setting['defaultvalue'];
  257. }
  258. return "<input type='hidden' name='info[$field][]' value='-1'>".form::checkbox($array,$posids,"name='info[$field][]'",'',$setting['width']);
  259. }
  260. function keyword($field, $value, $fieldinfo) {
  261. extract($fieldinfo);
  262. if(!$value) $value = $defaultvalue;
  263. return "<input type='text' name='info[$field]' id='$field' value='$value' style='width:280px' {$formattribute} {$css} class='input-text'>";
  264. }
  265. function author($field, $value, $fieldinfo) {
  266. return '<input type="text" name="info['.$field.']" value="'.$value.'" size="30">';
  267. }
  268. function copyfrom($field, $value, $fieldinfo) {
  269. $value_data = '';
  270. if($value && strpos($value,'|')!==false) {
  271. $arr = explode('|',$value);
  272. $value = $arr[0];
  273. $value_data = $arr[1];
  274. }
  275. $copyfrom_array = getcache('copyfrom','admin');
  276. $copyfrom_datas = array(L('copyfrom_tips'));
  277. if(!empty($copyfrom_array)) {
  278. foreach($copyfrom_array as $_k=>$_v) {
  279. if($this->siteid==$_v['siteid']) $copyfrom_datas[$_k] = $_v['sitename'];
  280. }
  281. }
  282. return "<input type='text' name='info[$field]' value='$value' style='width: 400px;' class='input-text'>".form::select($copyfrom_datas,$value_data,"name='{$field}_data' ");
  283. }
  284. function groupid($field, $value, $fieldinfo) {
  285. extract(string2array($fieldinfo['setting']));
  286. $grouplist = getcache('grouplist','member');
  287. foreach($grouplist as $_key=>$_value) {
  288. $data[$_key] = $_value['name'];
  289. }
  290. return '<input type="hidden" name="info['.$field.']" value="1">'.form::checkbox($data,$value,'name="'.$field.'[]" id="'.$field.'"','','120');
  291. }
  292. function islink($field, $value, $fieldinfo) {
  293. if($value) {
  294. $url = $this->data['url'];
  295. $checked = 'checked';
  296. $_GET['islink'] = 1;
  297. } else {
  298. $disabled = 'disabled';
  299. $url = $checked = '';
  300. $_GET['islink'] = 0;
  301. }
  302. $size = $fieldinfo['size'] ? $fieldinfo['size'] : 25;
  303. return '<input type="hidden" name="info[islink]" value="0"><input type="text" name="linkurl" id="linkurl" value="'.$url.'" size="'.$size.'" maxlength="255" '.$disabled.' class="input-text"> <input name="info[islink]" type="checkbox" id="islink" value="1" onclick="ruselinkurl();" '.$checked.'> <font color="red">'.L('islink_url').'</font>';
  304. }
  305. function template($field, $value, $fieldinfo) {
  306. $sitelist = getcache('sitelist','commons');
  307. $default_style = $sitelist[$this->siteid]['default_style'];
  308. return form::select_template($default_style,'content',$value,'name="info['.$field.']" id="'.$field.'"','show');
  309. }
  310. function pages($field, $value, $fieldinfo) {
  311. extract($fieldinfo);
  312. if($value) {
  313. $v = explode('|', $value);
  314. $data = "<select name=\"info[paginationtype]\" id=\"paginationtype\" onchange=\"if(this.value==1)\$('#paginationtype1').css('display','');else \$('#paginationtype1').css('display','none');\">";
  315. $type = array(L('page_type1'), L('page_type2'), L('page_type3'));
  316. if($v[0]==1) $con = 'style="display:"';
  317. else $con = 'style="display:none"';
  318. foreach($type as $i => $val) {
  319. if($i==$v[0]) $tag = 'selected';
  320. else $tag = '';
  321. $data .= "<option value=\"$i\" $tag>$val</option>";
  322. }
  323. $data .= "</select><span id=\"paginationtype1\" $con><input name=\"info[maxcharperpage]\" type=\"text\" id=\"maxcharperpage\" value=\"$v[1]\" size=\"8\" maxlength=\"8\">".L('page_maxlength')."</span>";
  324. return $data;
  325. } else {
  326. return "<select name=\"info[paginationtype]\" id=\"paginationtype\" onchange=\"if(this.value==1)\$('#paginationtype1').css('display','');else \$('#paginationtype1').css('display','none');\">
  327. <option value=\"0\">".L('page_type1')."</option>
  328. <option value=\"1\">".L('page_type2')."</option>
  329. <option value=\"2\">".L('page_type3')."</option>
  330. </select>
  331. <span id=\"paginationtype1\" style=\"display:none\"><input name=\"info[maxcharperpage]\" type=\"text\" id=\"maxcharperpage\" value=\"10000\" size=\"8\" maxlength=\"8\">".L('page_maxlength')."</span>";
  332. }
  333. }
  334. function typeid($field, $value, $fieldinfo) {
  335. extract($fieldinfo);
  336. $setting = string2array($setting);
  337. if(!$value) $value = $setting['defaultvalue'];
  338. if($errortips) {
  339. $errortips = $this->fields[$field]['errortips'];
  340. $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"",onfocus:"'.$errortips.'"}).inputValidator({min:1,onerror:"'.$errortips.'"});';
  341. }
  342. $usable_type = $this->categorys[$this->catid]['usable_type'];
  343. $usable_array = array();
  344. if($usable_type) $usable_array = explode(',',$usable_type);
  345. //获取站点ID
  346. if(intval($_GET['siteid'])){
  347. $siteid = intval($_GET['siteid']);
  348. }else{
  349. $siteid = $this->siteid;
  350. }
  351. $type_data = getcache('type_content_'.$siteid,'commons');
  352. if($type_data) {
  353. foreach($type_data as $_key=>$_value) {
  354. if(in_array($_key,$usable_array)) $data[$_key] = $_value['name'];
  355. }
  356. }
  357. return form::select($data,$value,'name="info['.$field.']" id="'.$field.'" '.$formattribute.' '.$css,L('copyfrom_tips'));
  358. }
  359. function readpoint($field, $value, $fieldinfo) {
  360. $paytype = $this->data['paytype'];
  361. if($paytype) {
  362. $checked1 = '';
  363. $checked2 = 'checked';
  364. } else {
  365. $checked1 = 'checked';
  366. $checked2 = '';
  367. }
  368. return '<input type="text" name="info['.$field.']" value="'.$value.'" size="5"><input type="radio" name="info[paytype]" value="0" '.$checked1.'> '.L('point').' <input type="radio" name="info[paytype]" value="1" '.$checked2.'>'.L('money');
  369. }
  370. function linkage($field, $value, $fieldinfo) {
  371. $setting = string2array($fieldinfo['setting']);
  372. $linkageid = $setting['linkageid'];
  373. return menu_linkage($linkageid,$field,$value);
  374. }
  375. function downfile($field, $value, $fieldinfo) {
  376. $list_str = $str = '';
  377. extract(string2array($fieldinfo['setting']));
  378. if($value){
  379. $value_arr = explode('|',$value);
  380. $value = $value_arr['0'];
  381. $sel_server = $value_arr['1'] ? explode(',',$value_arr['1']) : '';
  382. $edit = 1;
  383. } else {
  384. $edit = 0;
  385. }
  386. $server_list = getcache('downservers','commons');
  387. if(is_array($server_list)) {
  388. foreach($server_list as $_k=>$_v) {
  389. if (in_array($_v['siteid'],array(0,$fieldinfo['siteid']))) {
  390. $checked = $edit ? ((is_array($sel_server) && in_array($_k,$sel_server)) ? ' checked' : '') : ' checked';
  391. $list_str .= "<lable id='downfile{$_k}' class='ib lh24' style='width:25%'><input type='checkbox' value='{$_k}' name='{$field}_servers[]' {$checked}> {$_v['sitename']}</lable>";
  392. }
  393. }
  394. }
  395. $string = '
  396. <fieldset class="blue pad-10">
  397. <legend>'.L('mirror_server_list').'</legend>';
  398. $string .= $list_str;
  399. $string .= '</fieldset>
  400. <div class="bk10"></div>
  401. ';
  402. if(!defined('IMAGES_INIT')) {
  403. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  404. define('IMAGES_INIT', 1);
  405. }
  406. $authkey = upload_key("$upload_number,$upload_allowext,$isselectimage");
  407. $string .= $str."<input type='text' name='info[$field]' id='$field' value='$value' class='input-text' style='width:80%'/> <input type='button' class='button' onclick=\"javascript:flashupload('{$field}_downfield', '".L('attachment_upload')."','{$field}',submit_files,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/ value='".L('upload_soft')."'>";
  408. return $string;
  409. }
  410. function file($field, $value, $fieldinfo) {
  411. $list_str = $str = '';
  412. extract(string2array($fieldinfo['setting']));
  413. if($value){
  414. $value_arr = explode('|',$value);
  415. $value = $value_arr['0'];
  416. $sel_server = $value_arr['1'] ? explode(',',$value_arr['1']) : '';
  417. $edit = 1;
  418. } else {
  419. $edit = 0;
  420. }
  421. if(!defined('IMAGES_INIT')) {
  422. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  423. define('IMAGES_INIT', 1);
  424. }
  425. $authkey = upload_key("$upload_number,$upload_allowext,$isselectimage");
  426. $string .= $str."<input type='text' name='info[$field]' id='$field' value='$value' class='input-text' size='$size' /> <input type='button' class='button' onclick=\"javascript:flashupload('{$field}_downfield', '".L('attachment_upload')."','{$field}',submit_attachment,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/ value='".L('attachment_upload')."'>";
  427. return $string;
  428. }
  429. function downfiles($field, $value, $fieldinfo) {
  430. extract(string2array($fieldinfo['setting']));
  431. $list_str = '';
  432. if($value) {
  433. $value = string2array(new_html_entity_decode($value));
  434. if(is_array($value)) {
  435. foreach($value as $_k=>$_v) {
  436. $list_str .= "<div id='multifile{$_k}'><input type='text' name='{$field}_fileurl[]' value='{$_v[fileurl]}' style='width:310px;' class='input-text'> <input type='text' name='{$field}_filename[]' value='{$_v[filename]}' style='width:160px;' class='input-text'> <a href=\"javascript:remove_div('multifile{$_k}')\">".L('remove_out')."</a></div>";
  437. }
  438. }
  439. }
  440. $string = '<input name="info['.$field.']" type="hidden" value="1">
  441. <fieldset class="blue pad-10">
  442. <legend>'.L('file_list').'</legend>';
  443. $string .= $list_str;
  444. $string .= '<ul id="'.$field.'" class="picList"></ul>
  445. </fieldset>
  446. <div class="bk10"></div>
  447. ';
  448. if(!defined('IMAGES_INIT')) {
  449. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  450. define('IMAGES_INIT', 1);
  451. }
  452. $authkey = upload_key("$upload_number,$upload_allowext,$isselectimage");
  453. $string .= $str."<input type=\"button\" class=\"button\" value=\"".L('multiple_file_list')."\" onclick=\"javascript:flashupload('{$field}_multifile', '".L('attachment_upload')."','{$field}',change_multifile,'{$upload_number},{$upload_allowext},{$isselectimage}','content','$this->catid','{$authkey}')\"/> <input type=\"button\" class=\"button\" value=\"".L('add_remote_url')."\" onclick=\"add_multifile('{$field}')\">";
  454. return $string;
  455. }
  456. function map($field, $value, $fieldinfo) {
  457. extract($fieldinfo);
  458. $setting = string2array($setting);
  459. $size = $setting['size'];
  460. $errortips = $this->fields[$field]['errortips'];
  461. $modelid = $this->fields[$field]['modelid'];
  462. $tips = $value ? L('editmark','','map') : L('addmark','','map');
  463. return '<input type="button" name="'.$field.'_mark" id="'.$field.'_mark" value="'.$tips.'" class="button" onclick="omnipotent(\'selectid\',\''.APP_PATH.'api.php?op=map&field='.$field.'&modelid='.$modelid.'\',\''.L('mapmark','','map').'\',1,700,420)"><input type="hidden" name="info['.$field.']" value="'.$value.'" id="'.$field.'" >';
  464. }
  465. function omnipotent($field, $value, $fieldinfo) {
  466. extract($fieldinfo);
  467. $formtext = str_replace('{FIELD_VALUE}',$value,$formtext);
  468. $formtext = str_replace('{MODELID}',$this->modelid,$formtext);
  469. preg_match_all('/{FUNC\((.*)\)}/',$formtext,$_match);
  470. foreach($_match[1] as $key=>$match_func) {
  471. $string = '';
  472. $params = explode('~~',$match_func);
  473. $user_func = $params[0];
  474. $string = $user_func($params[1]);
  475. $formtext = str_replace($_match[0][$key],$string,$formtext);
  476. }
  477. $id = $this->id ? $this->id : 0;
  478. $formtext = str_replace('{ID}',$id,$formtext);
  479. $errortips = $this->fields[$field]['errortips'];
  480. if($errortips) $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"",onfocus:"'.$errortips.'"}).inputValidator({min:'.$minlength.',max:'.$maxlength.',onerror:"'.$errortips.'"});';
  481. if($errortips) $this->formValidator .= '$("#'.$field.'").formValidator({onshow:"'.$errortips.'",onfocus:"'.$errortips.'"}).inputValidator({min:1,onerror:"'.$errortips.'"});';
  482. return $formtext;
  483. }
  484. function video($field, $value, $fieldinfo) {
  485. $value_data = '';
  486. //获取flash上传属性
  487. pc_base::load_app_class('ku6api', 'video', 0);
  488. $setting = getcache('video', 'video');
  489. if(empty($setting)) return L('please_input_video_setting');
  490. $ku6api = new ku6api($setting['sn'], $setting['skey']);
  491. $flash_info = $ku6api->flashuploadparam();
  492. //获取上传的视频
  493. $key = 0;
  494. $list_str = "<div style='padding:1px'><ul class=\"tbsa\" id=\"video_{$field}_list\">";
  495. if($value) {
  496. $video_content_db = pc_base::load_model('video_content_model');
  497. $video_store_db = pc_base::load_model('video_store_model');
  498. $videos = $video_content_db->select(array('contentid'=>$this->id), 'videoid, listorder', '', '`listorder` ASC', '', 'videoid');
  499. if (!empty($videos)) {
  500. $videoids = '';
  501. foreach ($videos as $v) {
  502. $videoids .= $v['videoid'].',';
  503. }
  504. $videoids = substr($videoids, 0, -1);
  505. $result = $video_store_db->select("`videoid` IN($videoids)", '`videoid`, `title`, `picpath`', '', '', '', 'videoid');
  506. if (is_array($result)) {
  507. //首先对$result按照$videos的videoid排序
  508. foreach ($videos as $_vid => $v) {
  509. $new_result[] = $result[$_vid];
  510. }
  511. unset($result, $_vid, $v);
  512. foreach ($new_result as $_k => $r) {
  513. $key = $_k+1;
  514. $picpath = $r['picpath'] ? $r['picpath'] : IMG_PATH.'nopic.gif';
  515. $list_str .= "<li class=\"ac\" id=\"video_{$field}_{$key}\"><div class=\"r1\"><img src=\"{$r['picpath']}\" onerror=\"".IMG_PATH."nopic.jpg\" width=\"132\" height=\"75\"><input type='text' name='{$field}_video[{$key}][title]' value='".$r['title']."' class=\"input-text ipt_box\"><input type='hidden' name='{$field}_video[{$key}][videoid]' value='{$r[videoid]}'><div class=\"r2\"><span class=\"l\"><label>".L('listorder')."</label><input type='text' name='{$field}_video[$key][listorder]' value='".$videos[$r['videoid']]['listorder']."' class=\"input-text\"></span><span class=\"r\"> <a href=\"javascript:remove_div('video_{$field}_{$key}')\">".L('delete')."</a></span></li>";
  516. }
  517. }
  518. }
  519. }
  520. $list_str .= "</ul></div>";
  521. $data = '';
  522. if (!defined('SWFOBJECT_INIT')) {
  523. $data .= '<script type="text/javascript" src="'.JS_PATH.'video/swfobject2.js"></script>';
  524. $data .= '<script type="text/javascript" src="'.JS_PATH.'video/vod2ckedit.js"></script>';
  525. define('SWFOBJECT_INIT', 1);
  526. $data .= '<SCRIPT LANGUAGE="JavaScript">
  527. <!--
  528. var js4swf = {
  529. onInit: function(list)
  530. {
  531. // 初始化时调用, 若 list.length > 0 代表有可续传文件
  532. // [{file}, {file}]
  533. if(list.length > 0) {
  534. var length = list.length-1;
  535. $("#list_name").html("'.L('file', '', 'video').'"+list[length].name+"'.L('failed_uplaod_choose_again', '', 'video').'");
  536. }
  537. this.showMessage("init", list);
  538. },
  539. onSelect: function(files)
  540. {
  541. // 选中文件后调用, 返回文件列表
  542. // [{file}, {file}]
  543. this.showMessage("select", files);
  544. },
  545. onSid: function(evt)
  546. {
  547. // 获得 sid 后返回, 更新 sid 用 (key, sid, name, type, size)
  548. $("#video_title").val(evt.name);
  549. var ku6vid = evt.vid;
  550. $.get(\'index.php\', {m:\'video\', c:\'vid\', a:\'check\', vid:ku6vid});
  551. this.showMessage("sid", evt);
  552. },
  553. onStart: function()
  554. {
  555. // 开始上传 (选择文件后自动开始)
  556. this.showMessage("start");
  557. },
  558. onCancel: function()
  559. {
  560. // 上传取消事件
  561. this.showMessage("cancel");
  562. },
  563. onProgress: function(evt)
  564. {
  565. // 上传进度事件 (bytesLoaded, bytesTotal, speed) m=1 时没有这事件
  566. this.showMessage("progress", evt);
  567. },
  568. onComplete: function(evt)
  569. {
  570. // 上传完成事件 (包含文件信息和完成后返回数据(data))
  571. $("#vid").val(evt.vid);
  572. var video_num = parseInt($("#key").val()) + 1;
  573. var title = $("#video_title").val();
  574. var vid = $("#vid").val();
  575. var html = "<li id=\"video_'.$field.'_"+video_num+"\"><div class=\"r1\"><img src=\"'.IMG_PATH.'nopic.jpg\" width=\"132\" height=\"75\"><input type=\"text\" name=\"'.$field.'_video["+video_num+"][title]\" value=\""+title+"\" class=\"input-text\"><input type=\"hidden\" name=\"'.$field.'_video["+video_num+"][vid]\" value=\""+vid+"\"><div class=\"r2\"><span class=\"l\"><label>'.L('listorder').'</label><input type=\"text\" class=\"input-text\" name=\"'.$field.'_video["+video_num+"][listorder]\" value=\""+video_num+"\" ></span><span class=\"r\"> <a href=\"javascript:remove_div(\'video_'.$field.'_"+video_num+"\')\">'.L('delete').'</a></span></li>";
  576. $("#video_'.$field.'_list").append(html);
  577. $("#key").val(video_num);
  578. $("#video_title").val("");
  579. swfobject.embedSWF("'.$flash_info['flashurl'].'", "ku6uploader", "450", "45", "10.0.0", null, flashvars, params, attributes);
  580. //document.getElementById("frm").submit();
  581. this.showMessage("complete", evt);
  582. },
  583. onWarn: function(evt)
  584. {
  585. // 报错事件 (key, message)
  586. //this.showMessage("warn", evt);
  587. alert(evt.msg);
  588. },
  589. showMessage: function()
  590. {
  591. console.log(arguments);
  592. }
  593. };
  594. //-->
  595. </SCRIPT>
  596. <script type="text/javascript">
  597. var flashvars = { m: "1", u: "'.$flash_info['userid'].'", ctime: "'.$flash_info['passport_ctime'].'", sig:"'.$flash_info['passport_sig'].'", c: "vms", t: "1", n: "js4swf", k: "190000" ,ms:"39",s: "8000000"};
  598. var params = { allowScriptAccess: "always" , wmode: "transparent"};
  599. var attributes = { };
  600. //swfobject.embedSWF("http://player.ku6cdn.com/default/podcast/upload/201104261840/ku6uploader.swf", "ku6uploader", "450", "45", "10.0.0", null, flashvars, params, attributes);
  601. swfobject.embedSWF("'.$flash_info['flashurl'].'", "ku6uploader", "450", "45", "10.0.0", null, flashvars, params, attributes);
  602. </script>';
  603. }
  604. $authkey = upload_key("$upload_number,$upload_allowext,$isselectimage");
  605. $video_store_sel = defined('IN_ADMIN') ? '<div class="picBut cu video_btn" style="float:right; margin-top:10px;"><a herf="javascript:void(0);" onclick="javascript:video_store_select(\''.$field.'_videoes\', \''.L('choose_videoes').'\',\'video_'.$field.'_list\',change_videoes, \''.$_GET['pc_hash'].'\')"> '.L('videoes_store').' </a></div>' : '';
  606. $vms_str = $flash_info['allow_upload_to_vms'] ? '<label class="ib cu" style="width:125px"><input type="radio" name="channelid" value="2">'. L('upload_to_ku6vms', '', 'video').' </label>' : '';
  607. return $data.'<input name="info['.$field.']" type="hidden" value="1"><input type="hidden" id="key" value="'.$key.'"><fieldset class="blue pad-10">
  608. <legend>'.L('videoes_lists').'</legend><center><div class="onShow" id="nameTip">'.L('videoes_num').'</center><div id="videoes" class="picList">'.$list_str.'</div>
  609. </fieldset>
  610. <table width="100%" border="0" cellspacing="1" class="tbb">
  611. <tbody><tr>
  612. <td width="15%" height="40">'.L('select_upload_channel', '', 'video').'</td>
  613. <td height="40"><label class="ib cu" style="width:125px"><input type="radio" name="channelid" value="1" checked> '.L('upload_to_ku6').' </label>'.$vms_str.'
  614. </td>
  615. </tr>
  616. <tr>
  617. <td width="15%" height="40"><div align="right" ><input class="input_style" type="text" value="'.L('video_title', '', 'video').'" name="video_title" id="video_title" size="10"></div></td>
  618. <td height="40">
  619. '.$video_store_sel.'
  620. <div id="ku6uploader"></div><BR><span id="list_name" style="color:red"></span></td><input type="hidden" id="vid" name="vid" value="">
  621. </tr>
  622. </tbody></table>';
  623. }
  624. }
  625. ?>