/** 从文件中读取创建xml对象 @param string $filepath @return void */ public function load_file($filepath) { $path = ROOT . $filepath; if (is_file($path)) { kc_runtime('loadXMLFile'); $this->dom = simplexml_load_file($path); kc_runtime('loadXMLFile', 1); } else { global $king; kc_error($king->lang->get('system/error/notxmlfile') . ' ' . $path); } }
/** 输出最终结果 */ public function output($t = null) { $tmp = $t ? $t : $this->tmp; if (substr($tmp, 0, 6) == '{Tags}') { $s = '<div style="border:5px solid #CCC;background:#EFEEEE;padding:15px;line-height:20px;">'; foreach ($this->array as $key => $val) { $s .= "<tt>{king:{$key}/}</tt> -> {$val} <br/>"; } $s .= '</div>'; } else { kc_runtime('Template'); $s = preg_replace_callback($this->parent, array(&$this, 'regexcallback'), $tmp); kc_runtime('Template', 1); } //开始解析php代码 $parent = '/<\\?(php)?(\\S*?)((.|\\n)+?)\\?>/is'; $s = preg_replace_callback($parent, array(&$this, 'regexphpcallback'), $s); return $s; }
/** 查询 @param string $sql SQL代码 @param int $is 是否忽略错误;1忽略 */ public function query($sql, $is = 0) { kc_runtime('DataQuery'); //查询计时开始 $num = stripos($sql, 'where'); if (!empty($num)) { $sql_left = substr($sql, 0, $num); $sql_right = substr($sql, $num); $sql = str_replace(array('%s', '%a'), array(DB_PRE, KC_DB_ADMIN), $sql_left) . $sql_right; } else { $sql = str_replace(array('%s', '%a'), array(DB_PRE, KC_DB_ADMIN), $sql); } if (!isset($this->link)) { $this->connect(); } //判断数据库连接是否可用 $this->mQuery = $this->link->query($sql); kc_runtime('DataQuery', 1); return $this->mQuery; }
/** 把字符串写入文件,返回是否成功 @param string $filename 要写入的文件地址,相对于安装目录 @param string $s 要写入的文本内容 @param bool $is 当写入失败的时候,是否提示错误,默认为不提示 @return bool */ function kc_f_put_contents($filename, $s, $is = false) { global $king; $filename = kc_f_iconv($filename, 1); kc_f_md(dirname($filename)); //创建目录 //去掉bom if (substr($s, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $s = substr($s, 3); } kc_runtime('putContent'); $strlen = @file_put_contents(ROOT . $filename, $s, LOCK_EX); kc_runtime('putContent', 1); if (is_int($strlen)) { //写入成功 return true; } else { //写入失败 if ($is) { kc_error($king->lang->get('system/error/putcontents') . '<br/>' . $filename); } } }
/** 查询 @param string $_str SQL代码 @param int $is 是否忽略错误;1忽略 */ public function query($_str, $is = 0) { kc_runtime('DataQuery'); $num = stripos($_str, 'where'); if (!empty($num)) { $_str_left = substr($_str, 0, $num); $_str_right = substr($_str, $num); $_str = str_replace(array('%s', '%a'), array(DB_PREFIX, KC_DB_ADMIN), $_str_left) . $_str_right; } else { $_str = str_replace(array('%s', '%a'), array(DB_PREFIX, KC_DB_ADMIN), $_str); } /* if($this->mQuery){//释放上次查询消耗的内存 $this->free(); } */ $this->link == 0 && $this->connect(); //判断数据库连接是否可用 try { mysql_query('set names ' . DB_CHARSET); //设置字符集 $this->mQuery = mysql_query($_str, $this->link); } catch (Exception $e) { if (DEBUG) { kc_error('<label>' . $e . '</label><textarea style="width:300px;" rows="6">' . htmlspecialchars($_str) . '</textarea>'); } else { global $king; kc_error('<label>' . $king->lang->get('system/dberr/err3') . '</label>'); } } kc_runtime('DataQuery', 1); return $this->mQuery; }