123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- <?php
- class phpok_input_lib
- {
- var $itype = "text";
- var $iclass = "";
- #[设置要生成的HTML文本属性的参数]
- function __construct()
- {
- $this->itype = "text";
- $this->iclass = "";
- }
- function PHPOK_INPUT()
- {
- $this->__construct();
- }
- function get_html($array)
- {
- if(!array_key_exists($array["input"],$this->InputType()))
- {
- return false;
- }
- $varname = "_".strtoupper($array["input"]);
- //判断是否有插件替换
- $plugin = load_plugin("phpok_input_lib:".$varname,$array,true);
- if($plugin)
- {
- return $plugin;
- }
- return $this->$varname($array);
- }
- function _TEXT($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td><input type='text' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
- $msg.= " value='".$array["default_val"]."'";
- $width = $array["width"] ? "width:".$array["width"].";" : "";
- if($width)
- {
- $msg.= " style='".$width."'";
- }
- $msg .= "></td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _SIMG($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td><input type='text' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
- $msg.= " value='".$array["default_val"]."' class='long_input clue_on' readonly";
- $msg.= "></td>";
- $msg.= "<td> </td>";
- $msg.= '<td><input type="button" class="btn2" value="选择" onclick="phpjs_onepic(\''.$array["identifier"].'\')"></td>';
- $msg.= "<td> </td>";
- $msg.= '<td><input type="button" class="btn2" value="预览" onclick="phpjs_onepic_view(\''.$array["identifier"].'\')"></td>';
- $msg.= "<td> </td>";
- $msg.= '<td><input type="button" class="btn2" value="清空" onclick="phpjs_onepic_clear(\''.$array["identifier"].'\')"></td>';
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _MODULE($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td><input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' ";
- $msg.= " value='".$array["default_val"]."'>";
- $msg.= "<input type='text' id='".$array["identifier"]."_tmp_show' value='请选择……' disabled class='long_input readonly' />";
- $msg.= "</td>";
- $msg.= "<td> </td>";
- $msg.= '<td><input type="button" class="btn2" value="选择" onclick="phpjs_module(\''.$array["identifier"].'\',\''.$array['link_id'].'\')"></td>';
- $msg.= "<td> </td>";
- $msg.= '<td><input type="button" class="btn2" value="清空" onclick="phpjs_module_clear(\''.$array["identifier"].'\')"></td>';
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _SELECT($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td><select name='".$array["identifier"]."' id='".$array["identifier"]."'>";
- $array["list_val"] = str_replace("\r","",$array["list_val"]);
- $tmparray = explode("\n",$array["list_val"]);
- if(!$tmparray)
- {
- $tmparray = array();
- }
- foreach($tmparray AS $key=>$value)
- {
- $v = explode(",",$value);
- if(!$v[1]) $v[1] = $v[0];
- $msg .= "<option value='".$v[0]."'";
- if($v[0] == $array["default_val"])
- {
- $msg .= " selected";
- }
- $msg .= ">".$v[1]."</option>";
- }
- $msg .= "</select></td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _RADIO($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td>";
- $array["list_val"] = str_replace("\r","",$array["list_val"]);
- $tmparray = explode("\n",$array["list_val"]);
- if(!$tmparray)
- {
- $tmparray = array();
- }
- $msg.= "<table cellpadding='0' cellspacing='0'><tr>";
- foreach($tmparray AS $key=>$value)
- {
- $v = explode(",",$value);
- if(!$v[1]) $v[1] = $v[0];
- $msg .= "<td>";
- $msg .= "<input type='radio' name='".$array["identifier"]."' value='".$v[0]."'";
- if($v[0] == $array["default_val"])
- {
- $msg .= " checked";
- }
- $msg .= "> ".$v[1]." ";
- $msg .= "</td>";
- if(($key+1)%4 == "")
- {
- $msg .= "</tr><tr>";
- }
- }
- $msg .= "</tr></table>";
- $msg .= "</td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _CHECKBOX($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td>";
- $array["identifier"] = str_replace("[]","",$array["identifier"]);#去除[]
- $array["list_val"] = str_replace("\r","",$array["list_val"]);
- $tmparray = explode("\n",$array["list_val"]);
- if(!$tmparray)
- {
- $tmparray = array();
- }
- $tmpvalue = explode(",",$array["default_val"]);
- if(!$tmpvalue)
- {
- $tmpvalue = array();
- }
- $msg.= "<table cellpadding='0' cellspacing='0'><tr>";
- foreach($tmparray AS $key=>$value)
- {
- $v = explode(",",$value);
- if(!$v[1]) $v[1] = $v[0];
- $msg .= "<td>";
- $msg .= "<input type='checkbox' name='".$array["identifier"]."[]' value='".$v[0]."'";
- if(in_array($v[0],$tmpvalue))
- {
- $msg .= " checked";
- }
- $msg .= "> ".$v[1]." ";
- $msg .= "</td>";
- if(($key+1)%4 == "")
- {
- $msg .= "</tr><tr>";
- }
- }
- $msg .= "</tr></table>";
- $msg .= "</td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _TEXTAREA($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<td>";
- $msg.= "<textarea style='width:".$array["width"].";height:".$array["height"]."'";
- $msg.= " name='".$array["identifier"]."' id='".$array["identifier"]."'>".$array["default_val"]."</textarea>";
- $msg.= "</td>";
- $msg.= $this->_RIGHT_($array);
- return $msg;
- }
- function _IMG($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
- $msg.= "<td id='_view_".$array["identifier"]."'><img src='images/nopic.gif' border='0' /></td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function _DOWNLOAD($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
- $t_msg = "<input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> ";
- $t_msg .= "<input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> ";
- $t_msg .= "<span id='_view_".$array["identifier"]."'></span>";
- $msg.= "<td>".$t_msg."</td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- //影音
- function _VIDEO($array)
- {
- $msg = $this->_LEFT_($array);
- $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
- $t_msg = "<input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> ";
- $t_msg .= "<input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> ";
- $t_msg .= "<span id='_view_".$array["identifier"]."'></span>";
- $msg.= "<td>".$t_msg."</td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- //可视化编辑器
- function _EDIT($array)
- {
- if(!$array["if_html"])
- {
- return $this->_TEXTAREA($array);
- }
- $msg = $this->_LEFT_($array);
- //$toolbar = (intval($array["height"])>0 && intval($array["height"])<300) ? "Basic" : "Default";
- $show_html = $array["show_html"] ? true : false;
- $height = $array["height"] ? $array["height"] : "370px";
- $width = $array["width"] ? $array["width"] : "690px";
- $array["default_val"] = $this->format_edit_msg($array["default_val"]);
- $fckeditor = $this->_FckEditor_($array["identifier"],$array["default_val"],$height,$width,$show_html);
- $msg.= "<td>".$fckeditor."</td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function format_edit_msg($msg)
- {
- if(!$msg)
- {
- return false;
- }
- if(function_exists("base_url"))
- {
- $url = base_url();
- }
- else
- {
- $app = sys_init();
- if($app->config["siteurl"])
- {
- $url = $app->config["siteurl"];
- }
- else
- {
- return false;
- }
- }
- $imgArray = array();
- preg_match_all("/src=[\"|'| ]((.*)\.(gif|jpg|jpeg|bmp|png|swf))/isU",$msg,$imgArray);
- $imgArray = array_unique($imgArray[1]);
- $count = count($imgArray);
- if($count < 1)
- {
- return $msg;
- }
- foreach($imgArray AS $key=>$value)
- {
- $value = trim($value);
- if(strpos($value,"http://") === false && $value)
- {
- $msg = str_replace($value,$url.$value,$msg);
- }
- }
- return $msg;
- }
- function _OPT($array)
- {
- if(!$array["link_id"])
- {
- return false;
- }
- $msg = $this->_LEFT_($array);
- $msg.= "<input type='hidden' name='".$array["identifier"]."' id='".$array["identifier"]."' value='".$array["default_val"]."'>";
- $msg.= "<td id='_opt_parent_".$array["identifier"]."'></td><td id='_opt_son_".$array["identifier"]."' style='padding-left:3px;'></td>";
- $msg .= $this->_RIGHT_($array);
- return $msg;
- }
- function InputType()
- {
- $fields["text"] = "文本框";
- $fields["radio"] = "单选框";
- $fields["checkbox"] = "复选框";
- $fields["textarea"] = "文本区域";
- $fields["edit"] = "可视化编辑器";
- $fields["select"] = "下拉菜单";
- $fields["img"] = "图片选择器";
- $fields["video"] = "影音选择器";
- $fields["download"] = "下载框选择器";
- $fields["opt"] = "联动选择";
- $fields["simg"] = "图片选择器(单选)";
- $fields["module"] = "内联模块";
- return $fields;
- }
- function _LEFT_($array)
- {
- $msg = "<div class='table'>";
- $msg.= "<div class='left'>";
- $array["sub_left"] = $array["sub_left"] ? str_replace(":","",$array["sub_left"]) : $array["title"];
- $array["sub_left"] = str_replace(":","",$array["sub_left"]);
- if($array["input"] == "img")
- {
- $msg .= "<div style='padding-bottom:3px;'>";
- if($array["if_must"])
- {
- $msg .= "<span class='red'>*</span> ";
- }
- $msg .= $array["sub_left"].":";
- $msg .= "</div>";
- $msg .= "<div style='padding-bottom:3px;'><input type='button' class='btn2' value='选择' onclick=\"phpjs_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."')\"> </div>";
- $msg .= "<div><input type='button' class='btn2' value='取消' onclick=\"phpjs_clear_".$array["input"]."('".$array["identifier"]."','_view_".$array["identifier"]."');\"> </div>";
- }
- elseif($array["input"] == "edit")
- {
- $msg .= "<div style='padding-bottom:3px;'>";
- if($array["if_must"])
- {
- $msg .= "<span class='red'>*</span> ";
- }
- $msg .= $array["sub_left"].":";
- $msg .= "</div>";
- }
- else
- {
- if($array["if_must"])
- {
- $msg .= "<span class='red'>*</span> ";
- }
- $msg .= $array["sub_left"].":";
- }
- $msg.= "</div><div class='right'>";
- $msg.= "<div><table cellpadding='0' cellspacing='0'><tr>";
- return $msg;
- }
- function _RIGHT_($array)
- {
- if($array["input"] == "edit" && $array["if_html"])
- {
- $msg .= "</tr></table></div>";
- $msg .= "<div>".$this->_FckExt($array["identifier"],$array["sub_note"],$array["width"])."</div>";
- }
- elseif($array["input"] == "textarea" || $array["input"] == "simg" || $array["input"] == "img" ||($array["input"] == "edit" && !$array["if_html"]))
- {
- $msg .= "</tr></table></div>";
- if($array["sub_note"])
- {
- $msg.= "<div class='clue_on' style='padding-top:3px;'>".$array["sub_note"]."</div>";
- }
- }
- else
- {
- if($array["sub_note"])
- {
- $msg.= "<td class='clue_on'> ".$array["sub_note"]."</td>";
- }
- $msg .= "</tr></table></div>";
- }
- $msg.= "</div>";
- $msg.= "<div class='clear'></div>";
- $msg.= "</div>";
- return $msg;
- }
- function _FckEditor_($var="",$defaultvalue="",$toolbar="Default",$height="370px",$width="690px")
- {
- return sys_fckeditor($var,$defaultvalue,$toolbar,$height,$width);
- }
- function _FckExt($inputname,$subnote="",$width="690px")
- {
- $msg = "<div><table width='".$width."'><tr>";
- $msg.= "<input type='hidden' name='".$inputname."_tmp_id' id='".$inputname."_tmp_id' value=''>";
- $msg .= "<td class='clue_on'> ".$subnote." </td>";
- $msg.= "<td style='text-align:right;width:44px;'><input type='button' value='图片' class='btn2' onclick=\"phpjs_fck_img('".$inputname."')\" style='width:40px;'></td>";
- $msg.= "</tr></table></div>";
- return $msg;
- }
- }
- ?>
|