form.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php
  2. class form {
  3. /**
  4. * 编辑器
  5. * @param int $textareaid
  6. * @param int $toolbar
  7. * @param string $module 模块名称
  8. * @param int $catid 栏目id
  9. * @param int $color 编辑器颜色
  10. * @param boole $allowupload 是否允许上传
  11. * @param boole $allowbrowser 是否允许浏览文件
  12. * @param string $alowuploadexts 允许上传类型
  13. * @param string $height 编辑器高度
  14. * @param string $disabled_page 是否禁用分页和子标题
  15. */
  16. public static function editor($textareaid = 'content', $toolbar = 'basic', $toolvalue = '', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0, $allowuploadnum = '10') {
  17. $str ='';
  18. if(!defined('EDITOR_INIT')) {
  19. $str .= '<script type="text/javascript" src="'.JS_PATH.'ueditor/ueditor.config.js"></script>';
  20. $str .= '<script type="text/javascript" src="'.JS_PATH.'ueditor/ueditor.all.js"></script>';
  21. define('EDITOR_INIT', 1);
  22. }
  23. if($toolbar == 'basic') {
  24. $toolbar = defined('IN_ADMIN') ? "['Source'," : '[';
  25. $toolbar .= "'Bold', 'Italic', '|', 'InsertOrderedList', 'InsertUnorderedList', '|', 'Link', 'Unlink' ]";
  26. } elseif($toolbar == 'standard') {
  27. if(defined('IN_ADMIN')) {
  28. $toolbar = "['Source',";
  29. } else {
  30. $toolbar = '[';
  31. }
  32. $toolbar .= "'FullScreen', 'Undo', 'Redo', '|', 'Bold', 'Italic', 'Underline', 'StrikeThrough', 'Superscript', 'Subscript', 'RemoveFormat', 'FormatMatch','AutoTypeSet', '|', 'BlockQuote', '|', 'PastePlain', '|', 'ForeColor', 'BackColor', 'InsertOrderedList', 'InsertUnorderedList','SelectAll', 'ClearDoc', '|', 'CustomStyle', 'Paragraph', '|','RowSpacingTop', 'RowSpacingBottom','LineHeight', '|','FontFamily', 'FontSize', '|', 'DirectionalityLtr', 'DirectionalityRtl', '|', '', 'Indent', '|', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyJustify', '|', 'Link', 'Unlink', 'Anchor', '|', 'ImageNone', 'ImageLeft', 'ImageRight', 'ImageCenter', '|', 'SimpleUpload', 'InsertImage', 'Emotion', 'Scrawl', 'InsertVideo', 'Attachment', 'Map', 'InsertFrame', 'PageBreak', 'HighlightCode', '|', 'Horizontal', 'Date', 'Time', 'Spechars','SnapScreen', 'WordImage', '|', 'InsertTable', 'DeleteTable', 'InsertParagraphBeforeTable', 'InsertRow', 'DeleteRow', 'InsertCol', 'DeleteCol', 'MergeCells', 'MergeRight', 'MergeDown', 'SplittoCells', 'SplittoRows', 'SplittoCols', '|', 'Print', 'Preview', 'SearchReplace','Help']";
  33. } elseif($toolbar == 'desc') {
  34. $toolbar = "['Bold', 'Italic', '|', 'InsertOrderedList', 'InsertUnorderedList', '|', 'Link', 'Unlink', '|', 'SimpleUpload', 'InsertImage', '|','Source']";
  35. } elseif($toolbar == 'full') {
  36. $toolbar = "['Fullscreen', 'Source', '|', 'Undo', 'Redo', '|',
  37. 'Bold', 'Italic', 'Underline', 'Fontborder', 'Strikethrough', 'Superscript', 'Subscript', 'Removeformat', 'Formatmatch', 'Autotypeset', 'Blockquote', 'Pasteplain', '|', 'Forecolor', 'Backcolor', 'Insertorderedlist', 'Insertunorderedlist', 'Selectall', 'Cleardoc', '|',
  38. 'Rowspacingtop', 'Rowspacingbottom', 'Lineheight', '|',
  39. 'Customstyle', 'Paragraph', 'Fontfamily', 'Fontsize', '|',
  40. 'Directionalityltr', 'Directionalityrtl', 'Indent', '|',
  41. 'Justifyleft', 'Justifycenter', 'Justifyright', 'Justifyjustify', '|', 'Touppercase', 'Tolowercase', '|',
  42. 'Link', 'Unlink', 'Anchor', '|', 'Imagenone', 'Imageleft', 'Imageright', 'Imagecenter', '|',
  43. 'Simpleupload', 'Insertimage', 'Emotion', 'Scrawl', 'Insertvideo', 'Music', 'Attachment', 'Map', 'Insertframe', 'Insertcode', 'Pagebreak', 'Subtitle', 'Template', 'Background', '|',
  44. 'Horizontal', 'Date', 'Time', 'Spechars', 'Snapscreen', 'Wordimage', '|',
  45. 'Inserttable', 'Deletetable', 'Insertparagraphbeforetable', 'Insertrow', 'Deleterow', 'Insertcol', 'Deletecol', 'Mergecells', 'Mergeright', 'Mergedown', 'Splittocells', 'Splittorows', 'Splittocols', 'Charts', '|',
  46. 'Print', 'Preview', 'Searchreplace', 'Help']";
  47. } else {
  48. $toolbar = "['Fullscreen', 'Source', '|', " . $toolvalue . "]";
  49. }
  50. $str .= "<script type=\"text/javascript\">\r\n";
  51. $opt = array();
  52. if($toolbar<>'') {$opt[] = "toolbars:[".$toolbar."]";}
  53. $opt[] = "initialFrameHeight:".$height;
  54. $opt[] = "uploadImageMaxNum:".$allowuploadnum;
  55. $str .= "var editor = new baidu.editor.ui.Editor({serverUrl:'".JS_PATH."ueditor/php/controller.php?siteid=".get_siteid()."',".join(",",$opt)."});editor.render('$textareaid');\n";
  56. $str .= '</script>';
  57. $show_page = ($module == 'content' && !$disabled_page) ? 'true' : 'false';
  58. $ext_str = "<div class='editor_bottom'>";
  59. if(!defined('IMAGES_INIT')) {
  60. $ext_str .= '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  61. define('IMAGES_INIT', 1);
  62. }
  63. $ext_str .= "<div class='cke_footer'>";
  64. if ($show_page=="true") {
  65. $ext_str .= "<a href='javascript:insert_page(\"$textareaid\")'>".L('pagebreak')."</a><a href='javascript:insert_page_title(\"$textareaid\")'>".L('subtitle')."</a>";
  66. }
  67. if($allowupload) {
  68. $authkey = upload_key("$allowuploadnum,$alowuploadexts,$allowbrowser");
  69. $ext_str.="<a onclick=\"flashupload('flashupload', '".L('attachmentupload')."','{$textareaid}','','{$allowuploadnum},{$alowuploadexts},{$allowbrowser}','{$module}','{$catid}','{$authkey}');return false;\" href=\"javascript:void(0);\">".L('attachmentupload')."</a>";
  70. }
  71. $ext_str .= "</div>";
  72. $ext_str .= "<div id='page_title_div'><div class='title'>".L('subtitle')."<span id='msg_page_title_value'></span><a class='close' href='javascript:;' onclick='javascript:$(\"#page_title_div\").hide();'><span>×</span></a></div><div class='page_content'><input name='page_title_value' id='page_title_value' class='input-text' value='' size='30'>&nbsp;<input type='button' class='button' value='".L('submit')."' onclick=insert_page_title(\"$textareaid\",1)></div></div>";
  73. $ext_str .= "</div>";
  74. /*if(!defined('EDITOR_INIT')) {
  75. $str = '<script type="text/javascript" src="'.JS_PATH.'ckeditor/ckeditor.js"></script>';
  76. define('EDITOR_INIT', 1);
  77. }
  78. if($toolbar == 'basic') {
  79. $toolbar = defined('IN_ADMIN') ? "['Source']," : '';
  80. $toolbar .= "['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ],['Maximize'],\r\n";
  81. } elseif($toolbar == 'full') {
  82. if(defined('IN_ADMIN')) {
  83. $toolbar = "['Source',";
  84. } else {
  85. $toolbar = '[';
  86. }
  87. $toolbar .= "'-','Templates'],
  88. ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'],
  89. ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],['ShowBlocks'],['Image','Capture','Flash','flashplayer','MyVideo'],['Maximize'],
  90. '/',
  91. ['Bold','Italic','Underline','Strike','-'],
  92. ['Subscript','Superscript','-'],
  93. ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
  94. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
  95. ['Link','Unlink','Anchor'],
  96. ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
  97. '/',
  98. ['Styles','Format','Font','FontSize'],
  99. ['TextColor','BGColor'],
  100. ['attachment'],\r\n";
  101. } elseif($toolbar == 'desc') {
  102. $toolbar = "['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', '-', 'Image', '-','Source'],['Maximize'],\r\n";
  103. } else {
  104. $toolbar = '';
  105. }
  106. $str .= "<script type=\"text/javascript\">\r\n";
  107. $str .= "CKEDITOR.replace( '$textareaid',{";
  108. $str .= "height:{$height},";
  109. $show_page = ($module == 'content' && !$disabled_page) ? 'true' : 'false';
  110. $str .="pages:$show_page,subtitle:$show_page,textareaid:'".$textareaid."',module:'".$module."',catid:'".$catid."',\r\n";
  111. if($allowupload) {
  112. $authkey = upload_key("$allowuploadnum,$alowuploadexts,$allowbrowser");
  113. $str .="flashupload:true,alowuploadexts:'".$alowuploadexts."',allowbrowser:'".$allowbrowser."',allowuploadnum:'".$allowuploadnum."',authkey:'".$authkey."',\r\n";
  114. }
  115. if($allowupload) $str .= "filebrowserUploadUrl : 'index.php?m=attachment&c=attachments&a=upload&module=".$module."&catid=".$catid."&dosubmit=1',\r\n";
  116. if($color) {
  117. $str .= "extraPlugins : 'uicolor',uiColor: '$color',";
  118. }
  119. $str .= "toolbar :\r\n";
  120. $str .= "[\r\n";
  121. $str .= $toolbar;
  122. $str .= "]\r\n";
  123. //$str .= "fullPage : true";
  124. $str .= "});\r\n";
  125. $str .= '</script>';
  126. $ext_str = "<div class='editor_bottom'>";
  127. if(!defined('IMAGES_INIT')) {
  128. $ext_str .= '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  129. define('IMAGES_INIT', 1);
  130. }
  131. $ext_str .= "<div id='page_title_div'>
  132. <table cellpadding='0' cellspacing='1' border='0'><tr><td class='title'>".L('subtitle')."<span id='msg_page_title_value'></span></td><td>
  133. <a class='close' href='javascript:;' onclick='javascript:$(\"#page_title_div\").hide();'><span>×</span></a></td>
  134. <tr><td colspan='2'><input name='page_title_value' id='page_title_value' class='input-text' value='' size='30'>&nbsp;<input type='button' class='button' value='".L('submit')."' onclick=insert_page_title(\"$textareaid\",1)></td></tr>
  135. </table></div>";
  136. $ext_str .= "</div>";*/
  137. if(is_ie()) $ext_str .= "<div style='display:none'><OBJECT id='PC_Capture' classid='clsid:021E8C6F-52D4-42F2-9B36-BCFBAD3A0DE4'><PARAM NAME='_Version' VALUE='0'><PARAM NAME='_ExtentX' VALUE='0'><PARAM NAME='_ExtentY' VALUE='0'><PARAM NAME='_StockProps' VALUE='0'></OBJECT></div>";
  138. $str .= $ext_str;
  139. return $str;
  140. }
  141. /**
  142. *
  143. * @param string $name 表单名称
  144. * @param int $id 表单id
  145. * @param string $value 表单默认值
  146. * @param string $moudle 模块名称
  147. * @param int $catid 栏目id
  148. * @param int $size 表单大小
  149. * @param string $class 表单风格
  150. * @param string $ext 表单扩展属性 如果 js事件等
  151. * @param string $alowexts 允许图片格式
  152. * @param array $thumb_setting
  153. * @param int $watermark_setting 0或1
  154. */
  155. public static function images($name, $id = '', $value = '', $moudle='', $catid='', $size = 50, $class = '', $ext = '', $alowexts = '',$thumb_setting = array(),$watermark_setting = 0 ) {
  156. if(!$id) $id = $name;
  157. if(!$size) $size= 50;
  158. if(!empty($thumb_setting) && count($thumb_setting)) $thumb_ext = $thumb_setting[0].','.$thumb_setting[1];
  159. else $thumb_ext = ',';
  160. if(!$alowexts) $alowexts = 'jpg|jpeg|gif|bmp|png';
  161. if(!defined('IMAGES_INIT')) {
  162. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  163. define('IMAGES_INIT', 1);
  164. }
  165. $value = new_html_special_chars($value);
  166. $authkey = upload_key("1,$alowexts,1,$thumb_ext,$watermark_setting");
  167. return $str."<input type=\"text\" name=\"$name\" id=\"$id\" value=\"$value\" size=\"$size\" class=\"$class\" $ext/> <input type=\"button\" class=\"button\" onclick=\"javascript:flashupload('{$id}_images', '".L('attachmentupload')."','{$id}',submit_images,'1,{$alowexts},1,{$thumb_ext},{$watermark_setting}','{$moudle}','{$catid}','{$authkey}')\"/ value=\"".L('imagesupload')."\">";
  168. }
  169. /**
  170. *
  171. * @param string $name 表单名称
  172. * @param int $id 表单id
  173. * @param string $value 表单默认值
  174. * @param string $moudle 模块名称
  175. * @param int $catid 栏目id
  176. * @param int $size 表单大小
  177. * @param string $class 表单风格
  178. * @param string $ext 表单扩展属性 如果 js事件等
  179. * @param string $alowexts 允许上传的文件格式
  180. * @param array $file_setting
  181. */
  182. public static function upfiles($name, $id = '', $value = '', $moudle='', $catid='', $size = 50, $class = '', $ext = '', $alowexts = '',$file_setting = array() ) {
  183. if(!$id) $id = $name;
  184. if(!$size) $size= 50;
  185. if(!empty($file_setting) && count($file_setting)) $file_ext = $file_setting[0].','.$file_setting[1];
  186. else $file_ext = ',';
  187. if(!$alowexts) $alowexts = 'rar|zip';
  188. if(!defined('IMAGES_INIT')) {
  189. $str = '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>';
  190. define('IMAGES_INIT', 1);
  191. }
  192. $authkey = upload_key("1,$alowexts,1,$file_ext");
  193. return $str."<input type=\"text\" name=\"$name\" id=\"$id\" value=\"$value\" size=\"$size\" class=\"$class\" $ext/> <input type=\"button\" class=\"button\" onclick=\"javascript:flashupload('{$id}_files', '".L('attachmentupload')."','{$id}',submit_attachment,'1,{$alowexts},1,{$file_ext}','{$moudle}','{$catid}','{$authkey}')\"/ value=\"".L('filesupload')."\">";
  194. }
  195. /**
  196. * 日期时间控件
  197. *
  198. * @param $name 控件name,id
  199. * @param $value 选中值
  200. * @param $isdatetime 是否显示时间
  201. * @param $loadjs 是否重复加载js,防止页面程序加载不规则导致的控件无法显示
  202. * @param $showweek 是否显示周,使用,true | false
  203. */
  204. public static function date($name, $value = '', $isdatetime = 0, $loadjs = 0, $showweek = 'true', $timesystem = 1) {
  205. if($value == '0000-00-00 00:00:00') $value = '';
  206. $id = preg_match("/\[(.*)\]/", $name, $m) ? $m[1] : $name;
  207. if($isdatetime) {
  208. $size = 21;
  209. $format = '%Y-%m-%d %H:%M:%S';
  210. if($timesystem){
  211. $showsTime = 'true';
  212. } else {
  213. $showsTime = '12';
  214. }
  215. } else {
  216. $size = 10;
  217. $format = '%Y-%m-%d';
  218. $showsTime = 'false';
  219. }
  220. $str = '';
  221. if($loadjs || !defined('CALENDAR_INIT')) {
  222. define('CALENDAR_INIT', 1);
  223. $str .= '<link rel="stylesheet" type="text/css" href="'.JS_PATH.'calendar/jscal2.css"/>
  224. <link rel="stylesheet" type="text/css" href="'.JS_PATH.'calendar/border-radius.css"/>
  225. <link rel="stylesheet" type="text/css" href="'.JS_PATH.'calendar/win2k.css"/>
  226. <script type="text/javascript" src="'.JS_PATH.'calendar/calendar.js"></script>
  227. <script type="text/javascript" src="'.JS_PATH.'calendar/lang/en.js"></script>';
  228. }
  229. $str .= '<input type="text" name="'.$name.'" id="'.$id.'" value="'.$value.'" size="'.$size.'" class="date" readonly>&nbsp;';
  230. $str .= '<script type="text/javascript">
  231. Calendar.setup({
  232. weekNumbers: '.$showweek.',
  233. inputField : "'.$id.'",
  234. trigger : "'.$id.'",
  235. dateFormat: "'.$format.'",
  236. showTime: '.$showsTime.',
  237. minuteStep: 1,
  238. onSelect : function() {this.hide();}
  239. });
  240. </script>';
  241. return $str;
  242. }
  243. /**
  244. * 栏目选择
  245. * @param string $file 栏目缓存文件名
  246. * @param intval/array $catid 别选中的ID,多选是可以是数组
  247. * @param string $str 属性
  248. * @param string $default_option 默认选项
  249. * @param intval $modelid 按所属模型筛选
  250. * @param intval $type 栏目类型
  251. * @param intval $onlysub 只可选择子栏目
  252. * @param intval $siteid 如果设置了siteid 那么则按照siteid取
  253. */
  254. public static function select_category($file = '',$catid = 0, $str = '', $default_option = '', $modelid = 0, $type = -1, $onlysub = 0,$siteid = 0,$is_push = 0) {
  255. $tree = pc_base::load_sys_class('tree');
  256. if(!$siteid) $siteid = param::get_cookie('siteid');
  257. if (!$file) {
  258. $file = 'category_content_'.$siteid;
  259. }
  260. $result = getcache($file,'commons');
  261. $string = '<select '.$str.'>';
  262. if($default_option) $string .= "<option value='0'>$default_option</option>";
  263. //加载权限表模型 ,获取会员组ID值,以备下面投入判断用
  264. if($is_push=='1'){
  265. $priv = pc_base::load_model('category_priv_model');
  266. $user_groupid = param::get_cookie('_groupid') ? param::get_cookie('_groupid') : 8;
  267. }
  268. if (is_array($result)) {
  269. foreach($result as $r) {
  270. //检查当前会员组,在该栏目处是否允许投稿?
  271. if($is_push=='1' and $r['child']=='0'){
  272. $sql = array('catid'=>$r['catid'],'roleid'=>$user_groupid,'action'=>'add');
  273. $array = $priv->get_one($sql);
  274. if(!$array){
  275. continue;
  276. }
  277. }
  278. if($siteid != $r['siteid'] || ($type >= 0 && $r['type'] != $type)) continue;
  279. $r['selected'] = '';
  280. if(is_array($catid)) {
  281. $r['selected'] = in_array($r['catid'], $catid) ? 'selected' : '';
  282. } elseif(is_numeric($catid)) {
  283. $r['selected'] = $catid==$r['catid'] ? 'selected' : '';
  284. }
  285. $r['html_disabled'] = "0";
  286. if (!empty($onlysub) && $r['child'] != 0) {
  287. $r['html_disabled'] = "1";
  288. }
  289. $categorys[$r['catid']] = $r;
  290. if($modelid && $r['modelid']!= $modelid ) unset($categorys[$r['catid']]);
  291. }
  292. }
  293. $str = "<option value='\$catid' \$selected>\$spacer \$catname</option>;";
  294. $str2 = "<optgroup label='\$spacer \$catname'></optgroup>";
  295. $tree->init($categorys);
  296. $string .= $tree->get_tree_category(0, $str, $str2);
  297. $string .= '</select>';
  298. return $string;
  299. }
  300. public static function select_linkage($keyid = 0, $parentid = 0, $name = 'parentid', $id ='', $alt = '', $linkageid = 0, $property = '') {
  301. $tree = pc_base::load_sys_class('tree');
  302. $result = getcache($keyid,'linkage');
  303. $id = $id ? $id : $name;
  304. $string = "<select name='$name' id='$id' $property>\n<option value='0'>$alt</option>\n";
  305. if($result['data']) {
  306. foreach($result['data'] as $area) {
  307. $categorys[$area['linkageid']] = array('id'=>$area['linkageid'], 'parentid'=>$area['parentid'], 'name'=>$area['name']);
  308. }
  309. }
  310. $str = "<option value='\$id' \$selected>\$spacer \$name</option>";
  311. $tree->init($categorys);
  312. $string .= $tree->get_tree($parentid, $str, $linkageid);
  313. $string .= '</select>';
  314. return $string;
  315. }
  316. /**
  317. * 下拉选择框
  318. */
  319. public static function select($array = array(), $id = 0, $str = '', $default_option = '') {
  320. $string = '<select '.$str.'>';
  321. $default_selected = (empty($id) && $default_option) ? 'selected' : '';
  322. if($default_option) $string .= "<option value='' $default_selected>$default_option</option>";
  323. if(!is_array($array) || count($array)== 0) return false;
  324. $ids = array();
  325. if(isset($id)) $ids = explode(',', $id);
  326. foreach($array as $key=>$value) {
  327. $selected = in_array($key, $ids) ? 'selected' : '';
  328. $string .= '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
  329. }
  330. $string .= '</select>';
  331. return $string;
  332. }
  333. /**
  334. * 复选框
  335. *
  336. * @param $array 选项 二维数组
  337. * @param $id 默认选中值,多个用 '逗号'分割
  338. * @param $str 属性
  339. * @param $defaultvalue 是否增加默认值 默认值为 -99
  340. * @param $width 宽度
  341. */
  342. public static function checkbox($array = array(), $id = '', $str = '', $defaultvalue = '', $width = 0, $field = '') {
  343. $string = '';
  344. $id = trim($id);
  345. if($id != '') $id = strpos($id, ',') ? explode(',', $id) : array($id);
  346. if($defaultvalue) $string .= '<input type="hidden" '.$str.' value="-99">';
  347. $i = 1;
  348. foreach($array as $key=>$value) {
  349. $key = trim($key);
  350. $checked = ($id && in_array($key, $id)) ? 'checked' : '';
  351. if($width) $string .= '<label class="ib" style="width:'.$width.'px">';
  352. $string .= '<input type="checkbox" '.$str.' id="'.$field.'_'.$i.'" '.$checked.' value="'.new_html_special_chars($key).'"> '.new_html_special_chars($value);
  353. if($width) $string .= '</label>';
  354. $i++;
  355. }
  356. return $string;
  357. }
  358. /**
  359. * 单选框
  360. *
  361. * @param $array 选项 二维数组
  362. * @param $id 默认选中值
  363. * @param $str 属性
  364. */
  365. public static function radio($array = array(), $id = 0, $str = '', $width = 0, $field = '') {
  366. $string = '';
  367. foreach($array as $key=>$value) {
  368. $checked = trim($id)==trim($key) ? 'checked' : '';
  369. if($width) $string .= '<label class="ib" style="width:'.$width.'px">';
  370. $string .= '<input type="radio" '.$str.' id="'.$field.'_'.new_html_special_chars($key).'" '.$checked.' value="'.$key.'"> '.$value;
  371. if($width) $string .= '</label>';
  372. }
  373. return $string;
  374. }
  375. /**
  376. * 模板选择
  377. *
  378. * @param $style 风格
  379. * @param $module 模块
  380. * @param $id 默认选中值
  381. * @param $str 属性
  382. * @param $pre 模板前缀
  383. */
  384. public static function select_template($style, $module, $id = '', $str = '', $pre = '') {
  385. $tpl_root = pc_base::load_config('system', 'tpl_root');
  386. $templatedir = PC_PATH.$tpl_root.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;
  387. $confing_path = PC_PATH.$tpl_root.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.'config.php';
  388. $localdir = str_replace(array('/', '\\'), '', $tpl_root).'|'.$style.'|'.$module;
  389. $templates = glob($templatedir.$pre.'*.html');
  390. if(empty($templates)) {
  391. $style = 'default';
  392. $templatedir = PC_PATH.$tpl_root.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;
  393. $confing_path = PC_PATH.$tpl_root.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.'config.php';
  394. $localdir = str_replace(array('/', '\\'), '', $tpl_root).'|'.$style.'|'.$module;
  395. $templates = glob($templatedir.$pre.'*.html');
  396. }
  397. if(empty($templates)) return false;
  398. $files = @array_map('basename', $templates);
  399. $names = array();
  400. if(file_exists($confing_path)) {
  401. $names = include $confing_path;
  402. }
  403. $templates = array();
  404. if(is_array($files)) {
  405. foreach($files as $file) {
  406. $key = substr($file, 0, -5);
  407. $templates[$key] = isset($names['file_explan'][$localdir][$file]) && !empty($names['file_explan'][$localdir][$file]) ? $names['file_explan'][$localdir][$file].'('.$file.')' : $file;
  408. }
  409. }
  410. ksort($templates);
  411. return self::select($templates, $id, $str,L('please_select'));
  412. }
  413. /**
  414. * 验证码
  415. * @param string $id 生成的验证码ID
  416. * @param integer $code_len 生成多少位验证码
  417. * @param integer $font_size 验证码字体大小
  418. * @param integer $width 验证图片的宽
  419. * @param integer $height 验证码图片的高
  420. * @param string $font 使用什么字体,设置字体的URL
  421. * @param string $font_color 字体使用什么颜色
  422. * @param string $background 背景使用什么颜色
  423. */
  424. public static function checkcode($id = 'checkcode',$code_len = 4, $font_size = 20, $width = 130, $height = 50, $font = '', $font_color = '', $background = '') {
  425. return "<img id='$id' onclick='this.src=this.src+\"&\"+Math.random()' src='".SITE_PROTOCOL.SITE_URL.WEB_PATH."api.php?op=checkcode&code_len=$code_len&font_size=$font_size&width=$width&height=$height&font_color=".urlencode($font_color)."&background=".urlencode($background)."'>";
  426. }
  427. /**
  428. * url 规则调用
  429. *
  430. * @param $module 模块
  431. * @param $file 文件名
  432. * @param $ishtml 是否为静态规则
  433. * @param $id 选中值
  434. * @param $str 表单属性
  435. * @param $default_option 默认选项
  436. */
  437. public static function urlrule($module, $file, $ishtml, $id, $str = '', $default_option = '') {
  438. if(!$module) $module = 'content';
  439. $urlrules = getcache('urlrules_detail','commons');
  440. $array = array();
  441. foreach($urlrules as $roleid=>$rules) {
  442. if($rules['module'] == $module && $rules['file']==$file && $rules['ishtml']==$ishtml) $array[$roleid] = $rules['example'];
  443. }
  444. return form::select($array, $id,$str,$default_option);
  445. }
  446. }
  447. ?>