/** * 显示404页 * @function 404 ERROR 需要显示错误的信息 * * @param string $message */ public function error404($message = "非常抱歉,你需要的页面暂时不存在,可能它已经躲起来了。.") { $this->assign("message", $message); if (File::file_exists(T('Home@Index/404'))) { $this->display('Index/404'); } else { $this->show($message); } Hook::listen('app_end'); die; }
/** * 未知类型单页显示 支持年月日限定 * @param $method 魔术方法名称 即文章类型 * @param $args */ public function _empty($method, $args) { //TODO 通用模板机制 $Posts = new PostsLogic(); $info = I('get.info'); $post_detail = $Posts->detail($info, true); $Posts->viewInc($post_detail['post_id']); $this->assign('post', $post_detail); // 赋值数据集 if (File::file_exists(T('Home@Post/' . $post_detail['post_template']))) { $this->display($post_detail['post_template']); } else { //TODO 这里怎么处理却决于你自己了。 $this->error404('缺少对应的模版而不能显示'); // $this->display('single'); } // $this->display($post_res['post_type']); }
/** * 获取插件列表 * @param string $addon_dir * @param int $limit * @return array|bool */ public function getList($addon_dir = '', $limit = 0) { if (!$addon_dir) { $addon_dir = Addon_PATH; } $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR)); if ($dirs === false || !File::file_exists($addon_dir)) { $this->error = '插件目录不可读或者不存在'; return false; } $addons = array(); $where['name'] = array('in', $dirs); $list = $this->where($where)->field(true)->limit($limit)->select(); foreach ($list as $addon) { $addon['uninstall'] = 0; $addons[$addon['name']] = $addon; } foreach ($dirs as $value) { if (!isset($addons[$value])) { $class = get_addon_class($value); if (!class_exists($class)) { // 实例化插件失败忽略执行 \Think\Log::record('插件' . $value . '的入口文件不存在!'); continue; } $obj = new $class(); $addons[$value] = $obj->info; if ($addons[$value]) { $addons[$value]['uninstall'] = 1; $addons[$value]['status'] = 99; } } else { //todo 已安装的 } } int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', 99 => '未安装'))); $addons = list_sort_by($addons, 'uninstall', 'desc'); return $addons; }
/** * WordPress 导入处理 */ public function wordpressHandle() { $config = array("savePath" => 'Data/', "maxSize" => 10000000, "exts" => array('xml'), "subName" => array('date', 'Y/m-d')); $upload = new Upload($config); $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $file_path_full = $info['file']['fullpath']; if (File::file_exists($file_path_full)) { $Wordpress = new WordpressEvent(); $Wordpress->catImport($file_path_full); $Wordpress->tagImport($file_path_full); $Wordpress->postImport($file_path_full); File::delFile($file_path_full); $this->success('导入完成'); } $this->error('导入失败'); } }
public function restorelocalhandle() { $config = array('rootPath' => DB_Backup_PATH, "savePath" => '', "maxSize" => 100000000, "exts" => array('sql'), "subName" => array()); $upload = new Upload($config); $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $file_path_full = $info['file']['fullpath']; //dump($info);die($file_path_full); if (File::file_exists($file_path_full)) { $this->success("上传成功", U('Admin/Data/restore')); } else { $this->error('文件不存在'); } } }
/** * 兼容旧式CMS深目录结构的二级cat结构 * @param $info */ public function channel($info) { //TODO 兼容旧式CMS深目录结构的二级cat结构 $CatsLogic = new CatsLogic(); $cat = $CatsLogic->detail($info); $children = $CatsLogic->getChildren($cat['cat_id']); if (empty($children['cat_children'])) { $children = $CatsLogic->getChildren($children['cat_father']); } $CatsLogic = new CatsLogic(); $Posts = new PostsLogic(); $cat = $CatsLogic->detail($info); $this->if404($cat, "非常抱歉,没有这个分类,可能它已经躲起来了"); //优雅的404 $posts_id = $CatsLogic->getPostsIdWithChildren($cat['cat_id']); $count = sizeof($posts_id); $count == 0 ? $res404 = 0 : ($res404 = 1); if (!empty($posts_id)) { $Page = new GreenPage($count, get_opinion('PAGER')); $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $Posts->getList($limit, 'single', 'post_date desc', true, array(), $posts_id); } $this->assign('children', $children); $this->assign('title', $cat['cat_name']); // 赋值数据集 $this->assign('res404', $res404); $this->assign('postslist', $posts_list); // 赋值数据集 $this->assign('pager', $pager_bar); // 赋值分页输出 $this->assign('breadcrumbs', get_breadcrumbs('cats', $cat['cat_id'])); if (File::file_exists(T('Home@Archive/channel-list'))) { $this->display('Archive/channel-list'); } else { //TODO 这里怎么处理却决于你自己了。 // $this->error404('缺少对应的模版而不能显示'); $this->display('Archive/single-list'); } }
/** * */ public function updateHandle() { G("UpdateHandle"); $message = ""; $version = I('get.version'); $now_version = get_opinion('software_build', true); $url = Server_API . 'api/update/' . $now_version . '/'; $json = json_decode(file_get_contents($url), true); G("GetJson"); $message .= "下载Index文件成功,用时 " . G("UpdateHandle", "getJson") . "秒<br />"; if (empty($json)) { $message .= "连接主升级服务器出错,使用备用服务器<br />"; // try backup $url = Server_API2 . 'api/update/' . $now_version . '/'; $json = json_decode(file_get_contents($url), true); G("GetJson"); if (empty($json)) { $this->error('连接升级服务器出错'); } } $target_version_info = $json['file_list'][$version]; if (!empty($target_version_info)) { File::mkDir(WEB_CACHE_PATH); G("WebCache"); $message .= "清空WEB_CACHE_PATH,用时 " . G("GetJson", "WebCache") . "秒<br />"; $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name']; $file = file_get_contents($target_version_info['file_url']); if (File::writeFile($file_downloaded, $file)) { G("DownFile"); $message .= "下载升级文件成功,用时 " . G("WebCache", "DownFile") . "秒<br />"; } else { $this->error('下载文件失败'); } //calculate md5 of file $file_md5 = md5_file($file_downloaded); G("MD5"); $message .= "文件MD5值: {$file_md5} ,用时 " . G("DownFile", "MD5") . "秒<br />"; //todo 系统备份 $System = new SystemEvent(); //$System->backupFile(); G("BackupFile"); $message .= "系统备份已跳过 ,用时 " . G("MD5", "BackupFile") . "秒<br />"; $zip = new \ZipArchive(); //新建一个ZipArchive的对象 if ($zip->open($file_downloaded) === true) { $zip->extractTo(WEB_ROOT); //假设解压缩到在当前路径下/文件夹内 $zip->close(); //关闭处理的zip文件 File::delFile($file_downloaded); G("UnzipFile"); $message .= "解压成功 ,用时 " . G("BackupFile", "UnzipFile") . "秒<br />"; $System->clearCacheAll(); $message .= "清空缓存成功 <br />"; } else { $this->error('文件损坏'); } $old_build = get_opinion('software_build'); $new_build = $target_version_info['build_to']; set_opinion('software_version', $target_version_info['version_to']); set_opinion('software_build', $target_version_info['build_to']); set_opinion('db_build', $target_version_info['build_to']); if (File::file_exists(Upgrade_PATH . 'init.php')) { include Upgrade_PATH . 'init.php'; if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) { $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build; G("FunctionStart"); call_user_func($fuction_name); G("FunctionEnd"); $message .= "处理升级函数 ,用时 " . G("FunctionStart", "FunctionEnd") . "秒 <br />"; } } $this->updateComplete('升级成功' . $target_version_info['build_to'] . "<br />" . $message); } else { $this->error('升级出错'); } }
/** * */ public function updateHandle() { $version = I('get.version'); $now_version = get_opinion('software_build', true); $url = Server_API . 'api/update/' . $now_version . '/'; $json = json_decode(file_get_contents($url), true); $target_version_info = $json['file_list'][$version]; if (!empty($target_version_info)) { File::mkDir(WEB_CACHE_PATH); $file_downloaded = WEB_CACHE_PATH . $target_version_info['file_name']; $file = file_get_contents($target_version_info['file_url']); File::writeFile($file_downloaded, $file); //todo 系统备份 $System = new SystemEvent(); //$System->backupFile(); $zip = new \ZipArchive(); //新建一个ZipArchive的对象 if ($zip->open($file_downloaded) === true) { $zip->extractTo(WEB_ROOT); //假设解压缩到在当前路径下/文件夹内 $zip->close(); //关闭处理的zip文件 File::delFile($file_downloaded); $System->clearCacheAll(); } else { $this->error('文件损坏'); } $old_build = get_opinion('software_build'); $new_build = $target_version_info['build_to']; set_opinion('software_version', $target_version_info['version_to']); set_opinion('software_build', $target_version_info['build_to']); if (File::file_exists(Upgrade_PATH . 'init.php')) { include Upgrade_PATH . 'init.php'; if (function_exists("upgrade_" . $old_build . "_to_" . $new_build)) { $fuction_name = "upgrade_" . $old_build . "_to_" . $new_build; call_user_func($fuction_name); } } $this->success('升级成功' . $target_version_info['build_to'], U('Admin/Index/updateComplete')); } else { $this->error('升级出错'); } }
/** * 未知类型归档 支持年月日参数传递 和用户id * @param $method 未知类型 * @param array $args 参数 */ public function _empty($method, $args) { $title_prefix = (I('get.year', '') ? I('get.year', '') . '年' : '') . (I('get.month', '') ? I('get.month', '') . '月' : '') . (I('get.day', '') ? I('get.day', '') . '日' : ''); //TODO 通用类型 $post_type = $method; $map['post_date'] = array('like', I('get.year', '%') . '-' . I('get.month', '%') . '-' . I('get.day', '%') . '%'); if (I('get.uid') != '') { $map['user_id'] = I('get.uid'); } $PostsLogic = new PostsLogic(); $count = $PostsLogic->countAll($post_type, $map); // 查询满足要求的总记录数 $count == 0 ? $res404 = 0 : ($res404 = 1); if ($count != 0) { $Page = new GreenPage($count, C('PAGER')); $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $PostsLogic->getList($limit, $post_type, 'post_id desc', true, $map); } $this->assign('title', $title_prefix . '所有' . $post_type); $this->assign('res404', $res404); // 赋值数据集 $this->assign('postslist', $posts_list); // 赋值数据集 $this->assign('pager', $pager_bar); // 赋值分页输出 if (File::file_exists(T('Home@Archive/' . $post_type . '-list'))) { $this->display($post_type); } else { //TODO 这里怎么处理却决于你自己了。 $this->error404('缺少对应的模版而不能显示'); // $this->display('single-list'); } }
/** */ public function pluginExportHandle($plugin_name = '') { $plugin_path = 'Addons/' . $plugin_name . '/'; $temp_path = WEB_CACHE_PATH; File::delDir(WEB_CACHE_PATH); File::mkDir(WEB_CACHE_PATH); $file_path = $temp_path . "\\" . 'GCS_Plugin-' . $plugin_name . '-' . md5(time()) . '.zip'; $zip = new \ZipArchive(); //新建一个ZipArchive的对象 $res = $zip->open($file_path, \ZipArchive::CREATE); if ($res == true) { PHPZip::folderToZip($plugin_path, $zip); $zip->close(); } if (!File::file_exists($file_path)) { $this->error("该文件不存在,可能是被删除"); } $filename = basename($file_path); header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Length: " . filesize($file_path)); readfile($file_path); }
/** * */ public function step4() { $time = date("Y-m-d H:m:s"); $db_host = $_POST["db_host"]; $db_port = $_POST["db_port"]; $db_user = $_POST["db_user"]; $db_password = $_POST["db_password"]; $db_name = $_POST["db_name"]; $db_prefix = $_POST["db_prefix"]; if ($_POST['admin_password'] != $_POST['admin_password2'] || trim($_POST['admin_password']) == '' || trim($_POST['admin_password2']) == '') { $this->error("两次输入的密码不一致,请重新设定!,或者密码为空"); } else { $admin_user = $_POST['admin_user']; $admin_password = encrypt($_POST['admin_password']); $admin_email = $_POST['admin_email']; $user_session = encrypt($admin_user . $admin_password . time()); } $title = $_POST['cfg_title']; $site_url = $_POST['cfg_basehost'] . $_POST['cfg_cmspath']; if (!test_db_connect($db_host . ":" . $db_port, $db_user, $db_password)) { $this->error("数据库服务器或登录密码无效,\n\n无法连接数据库,请重新设定!"); } $conn = mysql_connect($db_host . ":" . $db_port, $db_user, $db_password); mysql_query("CREATE DATABASE IF NOT EXISTS `" . $db_name . "`;", $conn); if (!mysql_select_db($db_name)) { $this->error("选择数据库失败,可能是你没权限,请预先创建一个数据库!"); } mysql_query("set character set 'utf8'"); mysql_query("set names 'utf8'"); $file = WEB_ROOT . 'Data/Install/db_config_sample.php'; if (!File::file_exists($file)) { $this->error('Data/Install/db_config_sample.php文件不存在,请检查'); } $content = File::readFile($file); $content = str_replace("~dbhost~", $db_host, $content); $content = str_replace("~dbport~", $db_port, $content); $content = str_replace("~dbname~", $db_name, $content); $content = str_replace("~dbuser~", $db_user, $content); $content = str_replace("~dbpwd~", $db_password, $content); $content = str_replace("~dbprefix~", $db_prefix, $content); if (!File::writeFile(WEB_ROOT . 'db_config.php', $content, 'w+')) { $this->error("数据库配置文件写入失败,请您手动根据Data/Install/db_config_sample.php文件在根目录创建文件"); } File::makeDir(WEB_ROOT . 'Data/Cache'); $sql_empty = File::readFile(WEB_ROOT . 'Data/Install/greencms_empty.sql'); $sql_query = str_replace('{$db_prefix}', $db_prefix, $sql_empty); $file = WEB_ROOT . 'Data/Cache/greencms_sample.sql'; File::writeFile($file, $sql_query, 'w+'); insertDB($file, $conn); File::delFile($file); $sql_empty = File::readFile(WEB_ROOT . 'Data/Install/greencms_init.sql'); $sql_query = str_replace('{$db_prefix}', $db_prefix, $sql_empty); $file2 = WEB_ROOT . 'Data/Cache/greencms_init_sample.sql'; File::writeFile($file2, $sql_query, 'w+'); insertDB($file2, $conn); File::delFile($file2); /** * 插入管理员数据&更新配置 */ $admin_query = "INSERT INTO `{$db_prefix}user` (`user_id`, `user_login`, `user_pass`, `user_nicename`, `user_email`,\n `user_url`, `user_registered`, `user_activation_key`, `user_status`, `user_intro`,\n `user_level`, `user_session`) VALUES(1, '{$admin_user}', '" . $admin_password . "', '管理员', '{$admin_email}',\n '', '{$time}', '', 1, '我是admin,欢迎使用', 2, '{$user_session}');"; if (!mysql_query($admin_query, $conn)) { $this->error(' 插入管理员数据出错'); } $cquery = "Update `{$db_prefix}options` set option_value='{$title}' where option_name='title';"; if (!mysql_query($cquery, $conn)) { $this->error(' 更新配置数据出错'); } $cquery = "Update `{$db_prefix}options` set option_value='{$site_url}' where option_name='site_url';"; if (!mysql_query($cquery, $conn)) { $this->error(' 更新配置数据出错'); } $software_version = GreenCMS_Version; $software_build = GreenCMS_Build; $cquery = "Update `{$db_prefix}options` set option_value='{$software_version}' where option_name='software_version';"; if (!mysql_query($cquery, $conn)) { $this->error(' 更新配置数据出错'); } $cquery = "Update `{$db_prefix}options` set option_value='{$software_build}' where option_name='software_build';"; if (!mysql_query($cquery, $conn)) { $this->error(' 更新配置数据出错'); } //TODO 写不下去了 $this->redirect('Install/Index/step5'); }
public function themeAddLocal() { File::mkDir(WEB_CACHE_PATH); $config = array('rootPath' => WEB_CACHE_PATH, "savePath" => '', "maxSize" => 100000000, "exts" => array('zip'), "subName" => array()); $upload = new Upload($config); $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 获取上传文件信息 $file_path_full = $info['file']['fullpath']; //dump($info);die($file_path_full); if (File::file_exists($file_path_full)) { $Update = new UpdateEvent(); $applyRes = $Update->applyPatch($file_path_full); $applyInfo = json_decode($applyRes, true); if ($applyInfo['status']) { $this->success($applyInfo['info'], U('Admin/Custom/theme')); } else { $this->error($applyInfo['info']); } } else { $this->error('文件不存在'); } } }