/** * 相册上传+缩略图 */ public function actionUploadImg() { if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $fileTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'], $fileTypes)) { $file = new File(); $file->backThumbImage($tempFile, $fileParts['extension']); } else { echo 'Invalid file type.'; } } }
public function getThemeNameList() { $tpl_view_folder = File::scanDir(WEB_ROOT . 'Application/Home/View'); $tpl_static_folder = File::scanDir(WEB_ROOT . 'Public'); $this->theme_exist = array_intersect($tpl_view_folder, $tpl_static_folder); return $this->theme_exist; }
/** * 显示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; }
public function actionClientThumb() { $input = file_get_contents("php://input"); $post = json_decode($input, true); $img = base64_decode($post['base64']); $file = new File(); $imagePath = $file->getImagePath(__DIR__ . "/../../images/"); $time = time(); $fileName = $imagePath . ".jpg"; ob_start(); file_put_contents($fileName, $img); ob_flush(); $fileInfo = getimagesize($fileName); $picInfo = $file->pictureRatio($fileInfo[0], $fileInfo[1]); $path = substr($imagePath, strpos($imagePath, "picture/") + 8); if (rename($fileName, $imagePath . '_' . $picInfo[0] . '_' . $picInfo[1] . '.jpg')) { $res = array('status' => 1, 'info' => '上传成功', 'path' => $path . '_' . $picInfo[0] . '_' . $picInfo[1] . '.jpg', 'extension' => 'jpg', 'time' => $time); ob_flush(); $file->thumbPhoto($res); } $this->renderAjax(['status' => 1]); }
public function applyPatch($filename) { $System = new SystemEvent(); $zip = new \ZipArchive(); //新建一个ZipArchive的对象 if ($zip->open($filename) === true) { $zip->extractTo(WEB_ROOT); //假设解压缩到在当前路径下/文件夹内 $zip->close(); //关闭处理的zip文件 File::delFile($filename); $System->clearCacheAll(); return $this->jsonResult(1, "安装成功"); } else { return $this->jsonResult(0, "文件损坏"); } }
/** * 未知类型单页显示 支持年月日限定 * @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']); }
/** * */ 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('导入失败'); } }
/** * 获取插件列表 * @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; }
/** * */ 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('升级出错'); } }
/** * @function imageManager */ public function imageManager() { header("Content-Type: text/html; charset=utf-8"); //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时 $paths = array(Upload_PATH, 'upload1/'); // $action = htmlspecialchars($_POST["action"]); $action = htmlspecialchars($_REQUEST["action"]); if ($action == "get") { if (!defined('SAE_TMP_PATH')) { $files = array(); foreach ($paths as $path) { //$dir = new Dir(); //$tmp = $dir->getfiles($path); $tmp = File::getFiles($path); if ($tmp) { $files = array_merge($files, $tmp); } } if (!count($files)) { return; } rsort($files, SORT_STRING); $str = ""; foreach ($files as $file) { $str .= __ROOT__ . '/' . $file . "ue_separate_ue"; } echo $str; } else { // SAE环境下 $st = new \SaeStorage(); // 实例化 /* * getList:获取指定domain下的文件名列表 * return: 执行成功时返回文件列表数组,否则返回false * 参数:存储域,路径前缀,返回条数,起始条数 */ $num = 0; while ($ret = $st->getList(get_opinion('SaeStorage'), null, 100, $num)) { foreach ($ret as $file) { if (preg_match("/\\.(gif|jpeg|jpg|png|bmp)\$/i", $file)) { echo $st->getUrl('upload', $file) . "ue_separate_ue"; } $num++; } } } } }
/** * 功能:生成zip压缩文件,存放都 WEB_CACHE_PATH 中 * * @param $files array 需要压缩的文件 * @param $filename string 压缩后的zip文件名 包括zip后缀 * @param $path string 文件所在目录 * @param $outDir string 输出目录 * * @return array */ public static function zip($files, $filename, $outDir = WEB_CACHE_PATH, $path = DB_Backup_PATH) { $zip = new \ZipArchive(); File::makeDir($outDir); $res = $zip->open($outDir . "\\" . $filename, \ZipArchive::CREATE); if ($res == true) { foreach ($files as $file) { if (empty($file)) { continue; } if ($t = $zip->addFile($path . $file, str_replace('/', '', $file))) { $t = $zip->addFile($path . $file, str_replace('/', '', $file)); } } $zip->close(); return true; } else { return false; } }
/** * */ public function step5() { File::delAll(RUNTIME_PATH); File::delAll(LOG_PATH); File::delAll(WEB_CACHE_PATH); File::delAll(WEB_ROOT . 'Data/Cache'); File::delAll(WEB_ROOT . 'Data/Temp'); //A('Install/Test')->init($key = 'zts'); $Access = new AccessEvent(); $Access->initAdmin(); $Access->initWeixin(); // File::delAll(WEB_ROOT . 'Data/Install'); if (File::writeFile(WEB_ROOT . 'Data/Install/install.lock', 'installed', 'w+')) { C('URL_MODEL', 3); $this->success('GreenCMS安装成功,5秒钟返回首页', U('Home/Index/index'), 5); } }
/** * 兼容旧式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 logClearHandle() { $res = File::delAll(LOG_PATH, true); $this->success("清除成功"); }
/** * */ public function step5() { File::delAll(RUNTIME_PATH); File::delAll(LOG_PATH); File::delAll(WEB_CACHE_PATH); File::delAll(WEB_ROOT . 'Data/Cache'); File::delAll(WEB_ROOT . 'Data/Temp'); // $dirs = array(); // // array_push($dirs, WEB_ROOT . 'Extend'); // array_push($dirs, WEB_ROOT . 'Public'); // array_push($dirs, WEB_ROOT . 'Upload'); // array_push($dirs, WEB_ROOT . 'Data/Cache'); // array_push($dirs, WEB_ROOT . 'Data/Temp'); // array_push($dirs, LOG_PATH); // array_push($dirs, RUNTIME_PATH); // array_push($dirs, WEB_CACHE_PATH); // array_push($dirs, DB_Backup_PATH); // array_push($dirs, System_Backup_PATH); // array_push($dirs, Upgrade_PATH); //build_dir_secure($dirs); //A('Install/Test')->init($key = 'zts'); // $Access = new AccessEvent(); // $Access->initAdmin(); // $Access->initWeixin(); // File::delAll(WEB_ROOT . 'Install/Data'); if (File::writeFile(WEB_ROOT . 'Data/Install.lock', 'installed', 'w+')) { C('URL_MODEL', 3); $this->success('GreenCMS安装成功,5秒钟返回首页', get_opinion("site_url"), 5); } }
/** * */ public function clear() { $caches = array("HTMLCache" => array("name" => "网站HTML缓存文件", "path" => RUNTIME_PATH . "HTML", "size" => File::realSize(RUNTIME_PATH . "HTML")), "HomeCache" => array("name" => "网站缓存文件", "path" => RUNTIME_PATH . "Cache", "size" => File::realSize(RUNTIME_PATH . "Cache")), "HomeData" => array("name" => "网站数据库字段缓存文件", "path" => RUNTIME_PATH . "Data", "size" => File::realSize(RUNTIME_PATH . "Data")), "AdminLog" => array("name" => "网站日志文件", "path" => LOG_PATH, "size" => File::realSize(LOG_PATH)), "AdminTemp" => array("name" => "网站临时文件", "path" => RUNTIME_PATH . "Temp", "size" => File::realSize(RUNTIME_PATH . "Temp")), "Homeruntime" => array("name" => "网站~runtime.php缓存文件", "path" => RUNTIME_PATH . "common~runtime.php", "size" => File::realSize(RUNTIME_PATH . "common~runtime.php"))); // p($_POST['cache']);die; if (IS_POST) { $paths = $_POST['cache']; foreach ($paths as $path) { if (isset($caches[$path])) { $res = File::delAll($caches[$path]['path'], true); } } $SystemEvent = new SystemEvent(); $SystemEvent->clearCacheAll(); $this->success("清除成功"); } else { $this->assign("caches", $caches); $this->display(); } }
/** * 备份数据库 * @param string $type * @param array $tables * @param string $path * @return array */ public function backupDB($type = "系统自动备份", $tables = array(), $path = DB_Backup_PATH) { $M = M(); function_exists('set_time_limit') && set_time_limit(0); //防止备份数据过程超时 /** * 如果备份文件夹不存在,则自动建立 */ if (!is_dir(DB_Backup_PATH)) { File::makeDir(DB_Backup_PATH, 0777); } G('Backup_start'); $pre = "# -----------------------------------------------------------\n" . "# " . get_opinion('title') . " database backup files\n" . "# URL: " . get_opinion('site_url') . "\n" . "# Type: {$type}\n"; $MySQLLogic = new \Common\Util\MySQLUtil(); $bdTable = $MySQLLogic->backupTable($tables); //取得表结构信息 $outPut = ""; $file_n = 1; $backedTable = array(); foreach ($tables as $table) { $backedTable[] = $table; $outPut .= "\n\n# 数据库表:{$table} 数据信息\n"; $tableInfo = $M->query("SHOW TABLE STATUS LIKE '{$table}'"); $page = ceil($tableInfo[0]['Rows'] / 10000) - 1; for ($i = 0; $i <= $page; $i++) { $query = $M->query("SELECT * FROM {$table} LIMIT " . $i * 10000 . ", 10000"); foreach ($query as $val) { $temSql = ""; $tn = 0; $temSql = ''; foreach ($val as $v) { $temSql .= $tn == 0 ? "" : ","; $temSql .= $v == '' ? "''" : "'{$v}'"; $tn++; } $temSql = "INSERT INTO `{$table}` VALUES ({$temSql});\n"; $sqlNo = "\n# Time: " . date("Y-m-d H:i:s") . "\n" . "# -----------------------------------------------------------\n" . "# 当前SQL卷标:#{$file_n}\n# -----------------------------------------------------------\n\n\n"; if ($file_n == 1) { $sqlNo = "# Description:当前SQL文件包含了表:" . implode("、", $tables) . "的结构信息,表:" . implode("、", $backedTable) . "的数据" . $sqlNo; } else { $sqlNo = "# Description:当前SQL文件包含了表:" . implode("、", $backedTable) . "的数据" . $sqlNo; } if (strlen($pre) + strlen($sqlNo) + strlen($bdTable) + strlen($outPut) + strlen($temSql) > get_opinion("sqlFileSize")) { $file_name = $path . "_" . $file_n . ".sql"; $outPut = $file_n == 1 ? $pre . $sqlNo . $bdTable . $outPut : $pre . $sqlNo . $outPut; //file_put_contents($file, $outPut, FILE_APPEND); //TODO file_put_contents-->> File::writeFile需要测试 File::writeFile($file_name, $outPut); $bdTable = $outPut = ""; $backedTable = array(); $backedTable[] = $table; $file_n++; } $outPut .= $temSql; } } } if (strlen($bdTable . $outPut) > 0) { $sqlNo = "\n# Time: " . date("Y-m-d H:i:s") . "\n" . "# -----------------------------------------------------------\n" . "# 当前SQL卷标:#{$file_n}\n# -----------------------------------------------------------\n\n\n"; if ($file_n == 1) { $sqlNo = "# Description:当前SQL文件包含了表:" . implode("、", $tables) . "的结构信息,表:" . implode("、", $backedTable) . "的数据" . $sqlNo; } else { $sqlNo = "# Description:当前SQL文件包含了表:" . implode("、", $backedTable) . "的数据" . $sqlNo; } $file_name = $path . "_" . $file_n . ".sql"; $outPut = $file_n == 1 ? $pre . $sqlNo . $bdTable . $outPut : $pre . $sqlNo . $outPut; // file_put_contents($file_name, $outPut, FILE_APPEND); File::writeFile($file_name, $outPut); $file_n++; } G('Backup_end'); $res = array("status" => 1, "info" => "成功备份所选数据库表结构和数据,本次备份共生成了" . ($file_n - 1) . "个SQL文件。耗时:" . G('Backup_start', 'Backup_end') . "秒", "url" => U('Admin/Data/restore')); return $res; }
/** * @return array */ public function getZipFilesList() { $list = array(); $size = 0; $handle = opendir(DB_Backup_PATH . "Zip/"); while ($file = readdir($handle)) { if ($file != "." && $file != "..") { $tem = array(); $tem['file'] = $file; // checkCharset($file); $_size = filesize(DB_Backup_PATH . "Zip/{$file}"); $tem['size'] = File::byteFormat($_size); $tem['time'] = date("Y-m-d H:i:s", filectime(DB_Backup_PATH . "Zip/{$file}")); $size += $_size; $list[] = $tem; } } return array("list" => $list, "size" => File::byteFormat($size)); }
/** * */ 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); }
/** * 编辑分类 * @author jry <*****@*****.**> */ public function edit($id, $group) { if (IS_POST) { $category_object = D('Category'); $data = $category_object->create(); if ($data) { if ($category_object->save() !== false) { $this->success('更新成功', U('Category/index', array('group' => I('post.group')))); } else { $this->error('更新失败'); } } else { $this->error($category_object->getError()); } } else { //获取分类信息 $category_object = D('Category'); $info = $category_object->find($id); //获取前台模版供选择 $current_theme = D('SystemTheme')->where(array('current' => 1))->order('id asc')->getField('name'); //从系统主题数据表获取当前主题的名称 $template_list = \Common\Util\File::get_dirs(getcwd() . '/Application/Home/View/' . $current_theme . '/Document'); foreach ($template_list['file'] as $val) { $val = substr($val, 0, -5); if (strstr($val, 'index')) { $template_list_index[$val] = $val; } elseif (strstr($val, 'detail')) { $template_list_detail[$val] = $val; } } //使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('编辑分类')->setPostUrl(U('Admin/Category/edit/id/' . $id . '/group/' . $group))->addFormItem('id', 'hidden', 'ID', 'ID')->addFormItem('group', 'radio', '分组', '分组', C('CATEGORY_GROUP_LIST'))->addFormItem('pid', 'select', '上级分类', '所属的上级分类', select_list_as_tree('Category', array('group' => $group), '顶级分类'))->addFormItem('title', 'text', '分类标题', '分类标题')->addFormItem('doc_type', 'radio', '分类内容模型', '分类内容模型', select_list_as_tree('DocumentType'))->addFormItem('url', 'text', '链接', 'U函数解析的URL或者外链', null, $info['doc_type'] == 1 ?: 'hidden')->addFormItem('content', 'kindeditor', '内容', '单页模型填写内容', null, $info['doc_type'] == 2 ?: 'hidden')->addFormItem('index_template', 'select', '模版', '文档列表或封面模版', $template_list_index, $info['doc_type'] > 2 ?: 'hidden')->addFormItem('detail_template', 'select', '详情页模版', '单页使用的模版或其他模型文档详情页模版', $template_list_detail, $info['doc_type'] > 1 ?: 'hidden')->addFormItem('icon', 'icon', '图标', '菜单图标')->addFormItem('sort', 'num', '排序', '用于显示的顺序')->addFormItem('post_auth', 'radio', '投稿权限', '前台用户投稿权限', $category_object->post_auth())->setFormData($info)->setExtraHtml($this->extra_html)->display(); } }
public function delFileHandle($id) { $file_name = base64_decode($id); if (File::delFile($file_name)) { $this->success('删除成功'); } }
/** * @param $filename */ public function catImport($filename) { if (!file_exists($filename)) { exit; } $file_content = File::readFile($filename); $wordpress_xml = new \SimpleXMLElement($file_content); $wordpress_channel = $wordpress_xml->channel->children('wp', true); foreach ($wordpress_channel as $key => $value) { if ($value->category_nicename != '') { $value->cat_name = simplexml_load_string($value->cat_name->asXML(), 'SimpleXMLElement', LIBXML_NOCDATA); $item = object_to_array($value); $cat_temp = array(); $cat_temp['cat_id'] = $item['term_id']; $cat_temp['cat_slug'] = $item['category_nicename']; $cat_temp['cat_name'] = $item['cat_name']; $cat_father = D('Cats', 'Logic')->detail($item['category_parent']); $cat_temp['cat_father'] = (int) $cat_father['cat_id']; D('Cats', 'Logic')->data($cat_temp)->add(); } } }
/** * @return mixed */ public function getTotalLengthFormated() { return File::byteFormat($this->total_length); }
/** * 编辑分类 * @author jry <*****@*****.**> */ public function edit_with_tree($id, $group = 1) { if (IS_POST) { $category_object = D('Category'); $data = $category_object->create(); if ($data) { if ($category_object->save() !== false) { $this->success('更新成功', U('index', array('group' => I('post.group')))); } else { $this->error('更新失败'); } } else { $this->error($category_object->getError()); } } else { // 获取分类信息 $category_object = D('Category'); $info = $category_object->find($id); // 获取前台模版供选择 if (C('CURRENT_THEME')) { $template_list = \Common\Util\File::get_dirs(getcwd() . '/Theme/' . C('CURRENT_THEME') . '/Article/article'); } else { $template_list = \Common\Util\File::get_dirs(getcwd() . '/Application/Article/View/Home/article'); } foreach ($template_list['file'] as $val) { $val = substr($val, 0, -5); if (strstr($val, 'index')) { $template_list_index[$val] = $val; } elseif (strstr($val, 'detail')) { $template_list_detail[$val] = $val; } } // 使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('编辑分类')->setPostUrl(U('edit', array('id' => $id, 'group' => $group)))->addFormItem('id', 'hidden', 'ID', 'ID')->addFormItem('group', 'radio', '分组', '分组', D('Category')->group_list())->addFormItem('pid', 'select', '上级分类', '所属的上级分类', select_list_as_tree('Category', array('group' => $group), '顶级分类'))->addFormItem('title', 'text', '分类标题', '分类标题')->addFormItem('doc_type', 'radio', '分类内容模型', '分类内容模型', select_list_as_tree('Type'))->addFormItem('url', 'text', '链接', 'U函数解析的URL或者外链', null, $info['doc_type'] == 1 ?: 'hidden')->addFormItem('content', 'kindeditor', '内容', '单页模型填写内容', null, $info['doc_type'] == 2 ?: 'hidden')->addFormItem('index_template', 'select', '模版', '文档列表或封面模版', $template_list_index, $info['doc_type'] > 2 ?: 'hidden')->addFormItem('detail_template', 'select', '详情页模版', '单页使用的模版或其他模型文档详情页模版', $template_list_detail, $info['doc_type'] > 1 ?: 'hidden')->addFormItem('icon', 'icon', '图标', '菜单图标')->addFormItem('sort', 'num', '排序', '用于显示的顺序')->addFormItem('post_auth', 'radio', '投稿权限', '前台用户投稿权限', $category_object->post_auth())->setFormData($info)->setExtraHtml($this->extra_html)->setTemplate('Admin/builder/form')->display(); } }
/** * @param string $theme_name */ public function themeDelHandle($theme_name = '') { if ($this->themeStatus($theme_name) == 'enabled') { $this->error('请先禁用主题'); } $tpl_view_path = WEB_ROOT . 'Application/Home/View/' . $theme_name . '/'; $tpl_static_path = WEB_ROOT . 'Public/' . $theme_name . '/'; File::delAll($tpl_view_path, true); File::delAll($tpl_static_path, true); $this->success('删除成功'); }