phpok_input.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?php
  2. class phpok_input_lib
  3. {
  4. var $itype = "text";
  5. var $iclass = "";
  6. #[设置要生成的HTML文本属性的参数]
  7. function __construct()
  8. {
  9. $this->itype = "text";
  10. $this->iclass = "";
  11. }
  12. function PHPOK_INPUT()
  13. {
  14. $this->__construct();
  15. }
  16. function get_html($array)
  17. {
  18. if(!array_key_exists($array["input"],$this->InputType()))
  19. {
  20. return false;
  21. }
  22. $varname = "_".strtoupper($array["input"]);
  23. //判断是否有插件替换
  24. $plugin = load_plugin("phpok_input_lib:".$varname,$array,true);
  25. if($plugin)
  26. {
  27. return $plugin;
  28. }
  29. return $this->$varname($array);
  30. }
  31. function _TEXT($array)
  32. {
  33. $msg = $this->_LEFT_($array);
  34. $msg.= "<td><input type='text' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
  35. $msg.= " value='".$array["default_val"]."'";
  36. $width = $array["width"] ? "width:".$array["width"].";" : "";
  37. if($width)
  38. {
  39. $msg.= " style='".$width."'";
  40. }
  41. $msg .= "></td>";
  42. $msg .= $this->_RIGHT_($array);
  43. return $msg;
  44. }
  45. function _SIMG($array)
  46. {
  47. $msg = $this->_LEFT_($array);
  48. $msg.= "<td><input type='text' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
  49. $msg.= " value='".$array["default_val"]."' class='long_input clue_on' readonly";
  50. $msg.= "></td>";
  51. $msg.= "<td>&nbsp;</td>";
  52. $msg.= '<td><input type="button" class="btn2" value="选择" onclick="phpjs_onepic(\''.$array["identifier"].'\')"></td>';
  53. $msg.= "<td>&nbsp;</td>";
  54. $msg.= '<td><input type="button" class="btn2" value="预览" onclick="phpjs_onepic_view(\''.$array["identifier"].'\')"></td>';
  55. $msg.= "<td>&nbsp;</td>";
  56. $msg.= '<td><input type="button" class="btn2" value="清空" onclick="phpjs_onepic_clear(\''.$array["identifier"].'\')"></td>';
  57. $msg .= $this->_RIGHT_($array);
  58. return $msg;
  59. }
  60. function _MODULE($array)
  61. {
  62. $msg = $this->_LEFT_($array);
  63. $msg.= "<td><input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
  64. $msg.= " value='".$array["default_val"]."'>";
  65. $msg.= "<input type='text' id='".$array["identifier"]."_tmp_show' value='请选择……' disabled class='long_input readonly' />";
  66. $msg.= "</td>";
  67. $msg.= "<td>&nbsp;</td>";
  68. $msg.= '<td><input type="button" class="btn2" value="选择" onclick="phpjs_module(\''.$array["identifier"].'\',\''.$array['link_id'].'\')"></td>';
  69. $msg.= "<td>&nbsp;</td>";
  70. $msg.= '<td><input type="button" class="btn2" value="清空" onclick="phpjs_module_clear(\''.$array["identifier"].'\')"></td>';
  71. $msg .= $this->_RIGHT_($array);
  72. return $msg;
  73. }
  74. function _SELECT($array)
  75. {
  76. $msg = $this->_LEFT_($array);
  77. $msg.= "<td><select name='".$array["identifier"]."' id='".$array["identifier"]."'>";
  78. $array["list_val"] = str_replace("\r","",$array["list_val"]);
  79. $tmparray = explode("\n",$array["list_val"]);
  80. if(!$tmparray)
  81. {
  82. $tmparray = array();
  83. }
  84. foreach($tmparray AS $key=>$value)
  85. {
  86. $v = explode(",",$value);
  87. if(!$v[1]) $v[1] = $v[0];
  88. $msg .= "<option value='".$v[0]."'";
  89. if($v[0] == $array["default_val"])
  90. {
  91. $msg .= " selected";
  92. }
  93. $msg .= ">".$v[1]."</option>";
  94. }
  95. $msg .= "</select></td>";
  96. $msg .= $this->_RIGHT_($array);
  97. return $msg;
  98. }
  99. function _RADIO($array)
  100. {
  101. $msg = $this->_LEFT_($array);
  102. $msg.= "<td>";
  103. $array["list_val"] = str_replace("\r","",$array["list_val"]);
  104. $tmparray = explode("\n",$array["list_val"]);
  105. if(!$tmparray)
  106. {
  107. $tmparray = array();
  108. }
  109. $msg.= "<table cellpadding='0' cellspacing='0'><tr>";
  110. foreach($tmparray AS $key=>$value)
  111. {
  112. $v = explode(",",$value);
  113. if(!$v[1]) $v[1] = $v[0];
  114. $msg .= "<td>";
  115. $msg .= "<input type='radio' name='".$array["identifier"]."' value='".$v[0]."'";
  116. if($v[0] == $array["default_val"])
  117. {
  118. $msg .= " checked";
  119. }
  120. $msg .= "> ".$v[1]." &nbsp; ";
  121. $msg .= "</td>";
  122. if(($key+1)%4 == "")
  123. {
  124. $msg .= "</tr><tr>";
  125. }
  126. }
  127. $msg .= "</tr></table>";
  128. $msg .= "</td>";
  129. $msg .= $this->_RIGHT_($array);
  130. return $msg;
  131. }
  132. function _CHECKBOX($array)
  133. {
  134. $msg = $this->_LEFT_($array);
  135. $msg.= "<td>";
  136. $array["identifier"] = str_replace("[]","",$array["identifier"]);#去除[]
  137. $array["list_val"] = str_replace("\r","",$array["list_val"]);
  138. $tmparray = explode("\n",$array["list_val"]);
  139. if(!$tmparray)
  140. {
  141. $tmparray = array();
  142. }
  143. $tmpvalue = explode(",",$array["default_val"]);
  144. if(!$tmpvalue)
  145. {
  146. $tmpvalue = array();
  147. }
  148. $msg.= "<table cellpadding='0' cellspacing='0'><tr>";
  149. foreach($tmparray AS $key=>$value)
  150. {
  151. $v = explode(",",$value);
  152. if(!$v[1]) $v[1] = $v[0];
  153. $msg .= "<td>";
  154. $msg .= "<input type='checkbox' name='".$array["identifier"]."[]' value='".$v[0]."'";
  155. if(in_array($v[0],$tmpvalue))
  156. {
  157. $msg .= " checked";
  158. }
  159. $msg .= "> ".$v[1]." &nbsp; ";
  160. $msg .= "</td>";
  161. if(($key+1)%4 == "")
  162. {
  163. $msg .= "</tr><tr>";
  164. }
  165. }
  166. $msg .= "</tr></table>";
  167. $msg .= "</td>";
  168. $msg .= $this->_RIGHT_($array);
  169. return $msg;
  170. }
  171. function _TEXTAREA($array)
  172. {
  173. $msg = $this->_LEFT_($array);
  174. $msg.= "<td>";
  175. $msg.= "<textarea style='width:".$array["width"].";height:".$array["height"]."'";
  176. $msg.= " name='".$array["identifier"]."' id='".$array["identifier"]."'>".$array["default_val"]."</textarea>";
  177. $msg.= "</td>";
  178. $msg.= $this->_RIGHT_($array);
  179. return $msg;
  180. }
  181. function _IMG($array)
  182. {
  183. $msg = $this->_LEFT_($array);
  184. $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
  185. $msg.= "<td id='_view_".$array["identifier"]."'><img src='images/nopic.gif' border='0' /></td>";
  186. $msg .= $this->_RIGHT_($array);
  187. return $msg;
  188. }
  189. function _DOWNLOAD($array)
  190. {
  191. $msg = $this->_LEFT_($array);
  192. $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
  193. $t_msg = "<input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> ";
  194. $t_msg .= "<input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> ";
  195. $t_msg .= "<span id='_view_".$array["identifier"]."'></span>";
  196. $msg.= "<td>".$t_msg."</td>";
  197. $msg .= $this->_RIGHT_($array);
  198. return $msg;
  199. }
  200. //影音
  201. function _VIDEO($array)
  202. {
  203. $msg = $this->_LEFT_($array);
  204. $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
  205. $t_msg = "<input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> ";
  206. $t_msg .= "<input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> ";
  207. $t_msg .= "<span id='_view_".$array["identifier"]."'></span>";
  208. $msg.= "<td>".$t_msg."</td>";
  209. $msg .= $this->_RIGHT_($array);
  210. return $msg;
  211. }
  212. //可视化编辑器
  213. function _EDIT($array)
  214. {
  215. if(!$array["if_html"])
  216. {
  217. return $this->_TEXTAREA($array);
  218. }
  219. $msg = $this->_LEFT_($array);
  220. //$toolbar = (intval($array["height"])>0 && intval($array["height"])<300) ? "Basic" : "Default";
  221. $show_html = $array["show_html"] ? true : false;
  222. $height = $array["height"] ? $array["height"] : "370px";
  223. $width = $array["width"] ? $array["width"] : "690px";
  224. $array["default_val"] = $this->format_edit_msg($array["default_val"]);
  225. $fckeditor = $this->_FckEditor_($array["identifier"],$array["default_val"],$height,$width,$show_html);
  226. $msg.= "<td>".$fckeditor."</td>";
  227. $msg .= $this->_RIGHT_($array);
  228. return $msg;
  229. }
  230. function format_edit_msg($msg)
  231. {
  232. if(!$msg)
  233. {
  234. return false;
  235. }
  236. if(function_exists("base_url"))
  237. {
  238. $url = base_url();
  239. }
  240. else
  241. {
  242. $app = sys_init();
  243. if($app->config["siteurl"])
  244. {
  245. $url = $app->config["siteurl"];
  246. }
  247. else
  248. {
  249. return false;
  250. }
  251. }
  252. $imgArray = array();
  253. preg_match_all("/src=[\"|'| ]((.*)\.(gif|jpg|jpeg|bmp|png|swf))/isU",$msg,$imgArray);
  254. $imgArray = array_unique($imgArray[1]);
  255. $count = count($imgArray);
  256. if($count < 1)
  257. {
  258. return $msg;
  259. }
  260. foreach($imgArray AS $key=>$value)
  261. {
  262. $value = trim($value);
  263. if(strpos($value,"http://") === false && $value)
  264. {
  265. $msg = str_replace($value,$url.$value,$msg);
  266. }
  267. }
  268. return $msg;
  269. }
  270. function _OPT($array)
  271. {
  272. if(!$array["link_id"])
  273. {
  274. return false;
  275. }
  276. $msg = $this->_LEFT_($array);
  277. $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
  278. $msg.= "<td id='_opt_parent_".$array["identifier"]."'></td><td id='_opt_son_".$array["identifier"]."' style='padding-left:3px;'></td>";
  279. $msg .= $this->_RIGHT_($array);
  280. return $msg;
  281. }
  282. function InputType()
  283. {
  284. $fields["text"] = "文本框";
  285. $fields["radio"] = "单选框";
  286. $fields["checkbox"] = "复选框";
  287. $fields["textarea"] = "文本区域";
  288. $fields["edit"] = "可视化编辑器";
  289. $fields["select"] = "下拉菜单";
  290. $fields["img"] = "图片选择器";
  291. $fields["video"] = "影音选择器";
  292. $fields["download"] = "下载框选择器";
  293. $fields["opt"] = "联动选择";
  294. $fields["simg"] = "图片选择器(单选)";
  295. $fields["module"] = "内联模块";
  296. return $fields;
  297. }
  298. function _LEFT_($array)
  299. {
  300. $msg = "<div class='table'>";
  301. $msg.= "<div class='left'>";
  302. $array["sub_left"] = $array["sub_left"] ? str_replace(":","",$array["sub_left"]) : $array["title"];
  303. $array["sub_left"] = str_replace(":","",$array["sub_left"]);
  304. if($array["input"] == "img")
  305. {
  306. $msg .= "<div style='padding-bottom:3px;'>";
  307. if($array["if_must"])
  308. {
  309. $msg .= "<span class='red'>*</span> ";
  310. }
  311. $msg .= $array["sub_left"].":";
  312. $msg .= "</div>";
  313. $msg .= "<div style='padding-bottom:3px;'><input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> &nbsp;</div>";
  314. $msg .= "<div><input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> &nbsp;</div>";
  315. }
  316. elseif($array["input"] == "edit")
  317. {
  318. $msg .= "<div style='padding-bottom:3px;'>";
  319. if($array["if_must"])
  320. {
  321. $msg .= "<span class='red'>*</span> ";
  322. }
  323. $msg .= $array["sub_left"].":";
  324. $msg .= "</div>";
  325. }
  326. else
  327. {
  328. if($array["if_must"])
  329. {
  330. $msg .= "<span class='red'>*</span> ";
  331. }
  332. $msg .= $array["sub_left"].":";
  333. }
  334. $msg.= "</div><div class='right'>";
  335. $msg.= "<div><table cellpadding='0' cellspacing='0'><tr>";
  336. return $msg;
  337. }
  338. function _RIGHT_($array)
  339. {
  340. if($array["input"] == "edit" && $array["if_html"])
  341. {
  342. $msg .= "</tr></table></div>";
  343. $msg .= "<div>".$this->_FckExt($array["identifier"],$array["sub_note"],$array["width"])."</div>";
  344. }
  345. elseif($array["input"] == "textarea" || $array["input"] == "simg" || $array["input"] == "img" ||($array["input"] == "edit" && !$array["if_html"]))
  346. {
  347. $msg .= "</tr></table></div>";
  348. if($array["sub_note"])
  349. {
  350. $msg.= "<div class='clue_on' style='padding-top:3px;'>".$array["sub_note"]."</div>";
  351. }
  352. }
  353. else
  354. {
  355. if($array["sub_note"])
  356. {
  357. $msg.= "<td class='clue_on'>&nbsp;".$array["sub_note"]."</td>";
  358. }
  359. $msg .= "</tr></table></div>";
  360. }
  361. $msg.= "</div>";
  362. $msg.= "<div class='clear'></div>";
  363. $msg.= "</div>";
  364. return $msg;
  365. }
  366. function _FckEditor_($var="",$defaultvalue="",$toolbar="Default",$height="370px",$width="690px")
  367. {
  368. return sys_fckeditor($var,$defaultvalue,$toolbar,$height,$width);
  369. }
  370. function _FckExt($inputname,$subnote="",$width="690px")
  371. {
  372. $msg = "<div><table width='".$width."'><tr>";
  373. $msg.= "<input type='hidden' name='".$inputname."_tmp_id' id='".$inputname."_tmp_id' value=''>";
  374. $msg .= "<td class='clue_on'>&nbsp;".$subnote."&nbsp;</td>";
  375. $msg.= "<td style='text-align:right;width:44px;'><input type='button' value='图片' class='btn2' onclick=\"phpjs_fck_img('".$inputname."')\" style='width:40px;'></td>";
  376. $msg.= "</tr></table></div>";
  377. return $msg;
  378. }
  379. }
  380. ?>