/* $s=str_replace('KC_DB_TYPE','DB_TYPE',$s); $s=str_replace('KC_DB_CHARSET','DB_CHARSET',$s); $s=str_replace('KC_DB_PRE','DB_PRE',$s); //$s=str_replace('KC_DB_ADMIN','DB_ADMIN',$s); $s=str_replace('KC_DB_HOST','DB_HOST',$s); $s=str_replace('KC_DB_DATA','DB_DATA',$s); $s=str_replace('KC_DB_USER','DB_USER',$s); $s=str_replace('KC_DB_PASS','DB_PASS',$s); $s=str_replace('KC_DB_SQLITE','DB_SQLITE',$s); $s=str_replace('KC_CONFIG_LANGUAGE','LANGUAGE',$s); $s=str_replace('KC_CACHE_PATH','PATH_CACHE',$s); $s=str_replace('KC_CONFIG_DEBUG','DEBUG',$s); */ kc_f_put_contents('config.php', $s); require ROOT . 'config.php'; } require ROOT . 'system/lib/kc_' . DB_TYPE . '_class.php'; require ROOT . 'system/lib/kc_language_class.php'; require ROOT . 'system/lib/kc_cache_class.php'; require ROOT . 'system/lib/kc_skin_class.php'; /* ------>>> 全局变量 <<<---------------------------- */ $action = isset($_GET['action']) ? $_GET['action'] : ''; $ismethod = False; //是否POST提交 $ischeck = True; //是否通过表单验证 $check_num = 0; //出现验证错误次数 /* ------>>> 定义常量 <<<---------------------------- */
function kc_grab_get($imgpath) { global $king; if ($img = file_get_contents($imgpath)) { $fext = kc_f_ext($imgpath); //扩展名 $date = kc_formatdate(time(), 'Y-m-d h:i'); list($msec, $sec) = explode(' ', microtime()); $path = $king->config('uppath') . '/image/' . kc_formatdate(time(), 'Y/m/d/h/i') . '/' . kc_random(3) . round($msec * 1000000.0) . '.' . $fext; if (kc_f_put_contents($path, $img)) { //写文件成功 return $path; } else { return $imgpath; } } else { return False; } }
/** 加载语言包文件 @param $module : 模块(插件)名称 @param $language: 语言 @return */ private function load($module = 'system') { /* */ $filepath = ''; $getLanguage = ''; $this->mDoc[$module] = new DOMDocument(); if ($this->mLang == '') { $language = kc_cookie('language'); } if (!isset($language[0])) { $language = LANGUAGE; } if ($module == 'plugin') { $path = $this->getPath(); global $action; $plugin = $action == 'ajax' ? CMD : $action; $filepath = ROOT . $path . '/plugin/' . $plugin . '/' . $language . '.xml'; } else { $filepath = ROOT . $module . '/language/' . $language . '.xml'; } if (!file_exists($filepath)) { $language = LANGUAGE; $filepath = ROOT . $module . '/language/' . $language . '.xml'; } if (file_exists($filepath)) { $this->mLang = $language; } else { return False; } $this->mDoc[$module]->load($filepath); $this->mPath[$module] = new DOMXPath($this->mDoc[$module]); $this->mModule[] = $module; if ($module == 'system') { $jsFile = 'system/js/lang.' . $language . '.js'; if (!file_exists(ROOT . $jsFile)) { //若无文件 $entries = @$this->mPath['system']; $lang = array(); $s = "jQuery.extend({kc_lang:function(s){var lang=new Array();" . NL; $array = array('delete', 'clear', 'logout', 'set', 'close'); foreach ($array as $val) { $s .= "lang['{$val}']='" . addslashes($entries->evaluate('//kingcms/confirm/' . $val)->item(0)->nodeValue) . "';" . NL; } $s .= "lang['timeout']='" . addslashes($entries->evaluate('//kingcms/error/timeout')->item(0)->nodeValue) . "';" . NL; $s .= "lang['empty']='" . addslashes($entries->evaluate('//kingcms/error/empty')->item(0)->nodeValue) . "';" . NL; $s .= "lang['enter']='" . addslashes($entries->evaluate('//kingcms/common/enter')->item(0)->nodeValue) . "';" . NL; $s .= "lang['up']='" . addslashes($entries->evaluate('//kingcms/common/moveup')->item(0)->nodeValue) . "';" . NL; $s .= "lang['down']='" . addslashes($entries->evaluate('//kingcms/common/movedown')->item(0)->nodeValue) . "';" . NL; $s .= "lang['updown']='" . addslashes($entries->evaluate('//kingcms/common/updown')->item(0)->nodeValue) . "';" . NL; for ($i = 0; $i <= 6; $i++) { $s .= "lang['week{$i}']='" . addslashes($entries->evaluate('//kingcms/time/week' . $i)->item(0)->nodeValue) . "';" . NL; } $s .= "return lang[s];}});"; kc_f_put_contents($jsFile, $s); } } return True; }
function king_ajax_config() { global $king; //dbtype $dbtype = kc_post('dbtype'); if (!in_array($dbtype, array('mysql', 'sqlite'))) { kc_error($king->lang->get('system/install/dbtypeerr')); } //licensed $license = kc_post('license'); if ($license != 1) { kc_error($king->lang->get('system/install/licenseerr')); } $host = kc_post('host'); $data = kc_post('data'); $user = kc_post('user'); $pass = kc_post('pass'); $sqlitedata = kc_post('sqlitedata'); //验证 if ($dbtype == 'mysql') { //host if (!kc_validate($host, '/^[A-Za-z0-9\\.\\:\\/]+$/')) { kc_error($king->lang->get('system/install/ckhost')); } //data if (!kc_validate($data, '/^[A-Za-z0-9\\-\\_]+$/')) { kc_error($king->lang->get('system/install/ckdata')); } //user if (!kc_validate($user, '/^[A-Za-z0-9\\-\\_]+$/')) { kc_error($king->lang->get('system/install/ckuser')); } } else { //sqlitedata if (!kc_validate($sqlitedata, '/^[A-Za-z0-9\\-\\_\\.]+$/')) { kc_error($king->lang->get('system/install/ckdata')); } } //pre $pre = kc_post('pre'); if (!kc_validate($pre, '/^[A-Za-z0-9\\_]+$/')) { kc_error($king->lang->get('system/install/ckpre')); } //preadmin $preadmin = kc_post('preadmin'); if (!kc_validate($preadmin, '/^[A-Za-z0-9\\_]+$/')) { kc_error($king->lang->get('system/install/ckpreadmin')); } //adminname $adminname = kc_get('adminname', 1, 1); if (strlen($adminname) < 2 || strlen($adminname) > 12) { kc_error($king->lang->get('system/install/ckadminname')); } //adminpass $adminpass = kc_get('adminpass', 0, 1); if (strlen($adminpass) < 6 || strlen($adminname) > 30) { kc_error($king->lang->get('system/install/ckadminpass')); } //cache $cache = kc_post('cache'); if (!kc_validate($cache, '/^[A-Za-z0-9\\_]+$/')) { kc_error($king->lang->get('system/install/ckcache')); } //inst $inst = kc_post('inst'); //timediff $timediff = kc_get('timediff', 2, 1); //debug $debug = kc_post('debug') == 1 ? 'True' : 'False'; //isdelete $isdelete = kc_post('isdelete') == 1 ? 1 : 0; $s = kc_f_get_contents('config.php'); $s = preg_replace("%(define\\('DB_TYPE',')([A-Za-z]+)('\\))%s", "\${1}{$dbtype}\${3}", $s); $s = preg_replace("%(define\\('DB_PRE',')([A-Za-z0-9\\_]*)('\\))%s", "\${1}{$pre}\${3}", $s); $s = preg_replace("%(define\\('KC_DB_ADMIN',')([A-Za-z0-9\\_]*)('\\))%s", "\${1}{$preadmin}\${3}", $s); //sqlite $s = preg_replace("%(define\\('DB_SQLITE',')([A-Za-z0-9\\-\\_\\.\\/]+)('\\))%s", "\${1}{$sqlitedata}\${3}", $s); //mysql $s = preg_replace("%(define\\('DB_HOST',')([A-Za-z0-9\\.\\:\\/]+)('\\))%s", "\${1}{$host}\${3}", $s); $s = preg_replace("%(define\\('DB_DATA',')([A-Za-z0-9\\-\\_]+)('\\))%s", "\${1}{$data}\${3}", $s); $s = preg_replace("%(define\\('DB_USER',')([A-Za-z0-9\\-\\_]+)('\\))%s", "\${1}{$user}\${3}", $s); $s = preg_replace("%(define\\('DB_PASS',')([^']*)('\\))%s", "\${1}{$pass}\${3}", $s); $s = preg_replace("%(define\\('PATH_CACHE',')([A-Za-z0-9\\_]*)('\\))%s", "\${1}{$cache}\${3}", $s); $s = preg_replace("%(define\\('DEBUG',)(True|False)(\\))%s", "\${1}{$debug}\${3}", $s); if (kc_f_put_contents('config.php', $s)) { //写入成功 $js = "\$.kc_ajax('{CMD:\\'install\\',adminname:\\'{$adminname}\\',adminpass:\\'{$adminpass}\\',timediff:\\'{$timediff}\\',inst:\\'{$inst}\\',isdelete:\\'{$isdelete}\\'}')"; kc_ajax('OK', "<p class=\"k_ok\">" . $king->lang->get('system/install/crtdb') . "</p>", "<a href=\"javascript:;\">" . $king->lang->get('system/common/cancel') . "</a>", $js); } else { kc_error($king->lang->get('system/install/puterror')); } //写config.php,并输出ajax执行程序,进入下一步install }
/** 写入缓存的内容 @param string $path 路径 @param string $content 要缓存的内容 */ public function put($path, $content) { $path = PATH_CACHE . '/' . strtolower($path) . $this->ext; /**/ kc_f_put_contents($path, '<?php exit(\'No direct script access allowed\'); ?>' . serialize($content)); /** if(is_array($content)){ kc_f_put_contents(PATH_CACHE.'/'.$path.$this->ext,print_r($content,1)); }else{ kc_f_put_contents(PATH_CACHE.'/'.$path.$this->ext,$content); } /**/ $GLOBALS['file_get_contents_array'][$path] = $content; return $content; }
public function createPage($listid, $kid, $pid = 1, $is = null) { global $king; if (!kc_validate($kid, 2)) { return false; } $info = $this->infoList($listid); $model = $this->infoModel($info['modelid']); $site = $this->infoSite($info['siteid']); if ($info['npage'] != 0 && $is == null) { return; } if ($info['modelid'] <= 0) { kc_error($king->lang->get('system/error/param') . kc_clew(__FILE__, __LINE__)); } $id = $this->infoID($listid, $kid); //读取模板 $tmp = new KC_Template_class($info['ktemplatepage1'], $info['ktemplatepage2']); $tmp->assign('type', 'page'); foreach ($this->getField('list', 'field') as $val) { $tmp->assign(substr($val, 1), $info[$val]); } foreach ($this->getField('list', 'site') as $val) { $tmp->assign($val, $site[$val]); } foreach ($this->getField('list', 'id') as $val) { $tmp->assign($val, $info[$val]); } foreach ($model['field']['html'] as $key => $val) { $tmp->assign(substr($key, 1), kc_val($id, $key)); } foreach ($model['field']['text'] as $key => $val) { $tmp->assign(substr($key, 1), kc_val($id, $key)); } foreach ($model['field']['attrib'] as $val) { $tmp->assign(substr($val, 1), kc_val($id, $val)); } foreach ($model['field']['id'] as $val) { $tmp->assign($val, $id[$val]); } foreach ($model['field']['images'] as $key => $val) { //图片组类型 $array = $this->tab2array(kc_val($id, $key), 'images'); $tmp->assign(substr($key, 1), $array); //替换已经提交过的字符串值 } foreach ($model['field']['files'] as $key => $val) { //文件组类型 $array = $this->tab2array(kc_val($id, $key), 'files'); $tmp->assign(substr($key, 1), $array); } $kpath = $this->pathPage($info, $kid, $id['kpath'], 0, 1); //第一页的路径,不要指定为$pid,会出错 $tmp->assign('path', $kpath); $tmp->assign('pid', $pid); //前置命令 $tmp->assign('add', $king->config('inst') . "portal/index.php?action=edt&listid={$listid}"); //添加新话题 $tmp->assign('reply', $king->config('inst') . "portal/index.php?action=edt&listid={$listid}&kid1={$kid}"); //回复话题 $tmp->assign('commentlink', $king->config('inst') . "comment.php?modelid={$info['modelid']}&listid={$listid}&kid={$kid}"); $tmp->assign('edit', $king->config('inst') . "portal/index.php?action=edt&listid={$listid}&kid={$kid}"); //编辑话题 $tmp->assign('hit', "<em id=\"k_hit\">" . ($info['npage'] == 0 ? 'Loading...' : $id['nhit'] + 1) . "</em><script type=\"text/javascript\" charset=\"UTF-8\"><!--\n\$.kc_ajax('{URL:\\'" . $king->config('inst') . "portal/index.php\\',CMD:\\'hit\\',kid:{$kid},modelid:{$info['modelid']},IS:1}')\n--></script>"); //访问统计 $tmp->assign('comment', "<em id=\"k_comment\">" . 'Loading...' . "</em><script type=\"text/javascript\" charset=\"UTF-8\"><!--\n\$.kc_ajax('{URL:\\'" . $king->config('inst') . "portal/index.php\\',CMD:\\'commentcount\\',kid:{$kid},modelid:{$info['modelid']},IS:1}')\n--></script>"); //评论统计 $tmp->assign('digg', "<div id=\"k_digg\"><p id=\"k_digg1\" onclick=\"\$.kc_ajax('{URL:\\'" . $king->config('inst') . "portal/index.php\\',CMD:\\'digg\\',kid:{$kid},modelid:{$info['modelid']},type:1,IS:1}');\">Loading...</p><p id=\"k_digg0\" onclick=\"\$.kc_ajax('{URL:\\'" . $king->config('inst') . "portal/index.php\\',CMD:\\'digg\\',kid:{$kid},modelid:{$info['modelid']},type:0,IS:1}');\">Loading...</p><script type=\"text/javascript\" charset=\"UTF-8\"><!--\n\$.kc_ajax('{URL:\\'" . $king->config('inst') . "portal/index.php\\',CMD:\\'digg\\',kid:{$kid},modelid:{$info['modelid']},type:2,IS:1}')\n--></script></div>"); //顶踩 if ($is || $info['npage'] != 0) { return $tmp->output(); } else { kc_f_put_contents($this->pathPage($info, $kid, $id['kpath'], 1, $pid), $tmp->output(), 1); } }
/** 编辑文本 */ function king_ajax_edit() { global $king; $king->access('webftp_edit'); $path = kc_post('path'); $ext = kc_f_ext($path); switch ($ext) { case 'html': $code = 'html'; break; case 'htm': $code = 'html'; break; case 'shtml': $code = 'html'; break; case 'shtm': $code = 'html'; break; case 'css': $code = 'css'; break; case 'js': $code = 'js'; break; case 'php': $code = 'php'; break; case 'php3': $code = 'php'; break; case 'php4': $code = 'php'; break; case 'sql': $code = 'sql'; break; case 'xml': $code = 'xml'; break; default: $code = ''; } if (isset($_POST['webftpcontent'])) { //写文件 kc_f_put_contents($path, $_POST['webftpcontent'], 1); kc_ajax('OK', "<p class=\"k_ok\">" . $king->lang->get('system/ok/save') . "</p>"); } if (!kc_f_isfile($path)) { kc_error($king->lang->get('system/error/notfile')); } $content = kc_f_get_contents($path); $js = "editAreaLoader.init({\r\n\t\t\tid: \"webftpcontent\"\r\n\t\t\t,start_highlight: " . (strlen($content) > 10240 ? 'false' : 'true') . "\r\n\t\t\t,allow_resize: \"both\"\r\n\t\t\t,allow_toggle: false\r\n\t\t\t,word_wrap: true\r\n\t\t\t,language: \"en\"\r\n\t\t\t,syntax: \"php\"\r\n\t\t});"; $s = "<textarea id=\"webftpcontent\" name=\"webftpcontent\" rows=\"15\" cols=\"80\" style=\"width:870px;height:420px\">"; $s .= htmlspecialchars($content); $s .= "</textarea>"; $but = kc_htm_a($king->lang->get('system/common/save'), "{CMD:'edit',IS:1,path:'{$path}'}"); kc_ajax($king->lang->get('system/common/edit') . ' : ' . $path, $s, $but, $js, 900, 450); }