/** * 装载主题自定义函数 */ function load_theme_function() { $THEME = I('get.theme', get_kv('home_theme', false, 'NovaGreenStudio')); $file_theme_function = WEB_ROOT . 'Application/Home/View/' . $THEME . '/function.php'; if (file_exists($file_theme_function)) { include $file_theme_function; } }
/** * @return array */ public function get_tpl_type_list() { $tpl_static_path = WEB_ROOT . 'Public/' . get_kv('home_theme') . '/'; if (file_exists($tpl_static_path . 'theme.xml')) { $theme = simplexml_load_file($tpl_static_path . '/theme.xml'); $tpl_type = object_to_array($theme->post); $tpl_type_list = array(); foreach ($tpl_type as $key => $value) { $tpl_type_list[$value['tpl']] = $value['name']; } } else { $tpl_type_list = array("single" => "文章", "page" => "页面"); } return $tpl_type_list; }
/** * 获取当前主题的模板列表 * @return array */ public function getTplList() { if (S("post_tpl")) { return S("post_tpl"); } $tpl_static_path = WEB_ROOT . 'Public/' . get_kv('home_theme') . '/'; if (file_exists($tpl_static_path . 'theme.xml')) { $theme = simplexml_load_file($tpl_static_path . '/theme.xml'); $tpl_type = object_to_array($theme->post); $tpl_type_list = array_column_5($tpl_type, 'name', 'tpl'); } else { $tpl_type_list = get_opinion('post_tpl'); } S("post_tpl", $tpl_type_list, 600); return $tpl_type_list; }
/** * 获取主题个性设置 * 缓存key : $theme_name . '_theme_config' */ protected function themeConfig() { $theme_name = get_kv('home_theme'); if (S($theme_name . '_theme_config')) { //有缓存 C('theme_config', S($theme_name . '_theme_config')); } else { $theme = D("Theme")->field('theme_config')->where(array("theme_name" => $theme_name))->find(); $theme = json_decode($theme['theme_config'], true); $theme = $theme['kv']; $theme_config = array(); foreach ($theme as $key => $value) { $theme_config[$key] = $value['value']; } S($theme_name . '_theme_config', $theme_config, DEFAULT_EXPIRES_TIME); C('theme_config', $theme_config); } }
/** * 获取kv * @param $key * @param bool $realtime * @param string $default * @return mixed|string */ function get_kv($key, $realtime = false, $default = '') { if (!$realtime) { $res = S('kv_' . $key); if ($res != null) { return $res; } else { return get_kv($key, true, $default); } } else { $options = D('Kv')->field('kv_value')->where(array('kv_key' => $key))->find(); if ($options['kv_value'] == '') { return $default; } else { S('kv_' . $key, $options['kv_value'], DEFAULT_EXPIRES_TIME); return $options['kv_value']; } } }
<?php if (APP_DEBUG) { $DEFAULT_THEME = I('get.theme', get_kv('home_theme', false, 'NovaGreenStudio')); } else { $DEFAULT_THEME = get_kv('home_theme', false, 'NovaGreenStudio'); } $config = array('HTML_CACHE_ON' => get_opinion('HTML_CACHE_ON', false, false), 'HTML_CACHE_TIME' => get_opinion('HTML_CACHE_TIME', false, 60), 'HTML_CACHE_RULES' => array('*' => array('{$_SERVER.REQUEST_URI|md5}')), 'URL_MODEL' => get_opinion('home_url_model', false, 0), 'DEFAULT_THEME' => $DEFAULT_THEME, 'LOG_LEVEL' => get_opinion('LOG_LEVEL', false), 'LOG_RECORD' => (bool) get_opinion('LOG_RECORD', false), 'DATA_CACHE_TIME' => get_opinion("DATA_CACHE_TIME", false, 10), 'DEFAULT_FILTER' => get_opinion('DEFAULT_FILTER', false, 'htmlspecialchars'), 'SHOW_PAGE_TRACE' => get_opinion('SHOW_PAGE_TRACE', false, false), 'COOKIE_PREFIX' => get_opinion('COOKIE_PREFIX', false, 'greencms_'), 'COOKIE_EXPIRE' => get_opinion('COOKIE_EXPIRE', false, 3600), 'COOKIE_DOMAIN' => get_opinion('COOKIE_DOMAIN', false), 'COOKIE_PATH' => get_opinion('COOKIE_PATH', false)); $config_router = array('URL_HTML_SUFFIX' => get_opinion('URL_HTML_SUFFIX', false, 'html'), 'URL_ROUTER_ON' => true, 'URL_ROUTE_RULES' => array('Post/single/info/:info' => 'Post/single', 'Post/single/:year/:month/:day/:info' => 'Post/single', 'Post/single/:year/:month/:info' => 'Post/single', 'Post/single/:year/:info' => 'Post/single', 'Post/single/:info' => 'Post/single', 'Post/page/info/:info' => 'Post/page', 'Post/page/:year/:month/:day/:info' => 'Post/page', 'Post/page/:year/:month/:info' => 'Post/page', 'Post/page/:year/:info' => 'Post/page', 'Post/page/:info' => 'Post/page', 'Tag/:info' => 'Tag/detail', 'Cat/:father1^channel/:father2/:info' => 'Cat/detail', 'Cat/:father^channel/:info' => 'Cat/detail', 'Cat/:info^channel' => 'Cat/detail'), 'OUR_URL_MODEL' => "native", 'OUR_TAG_MODEL' => "native", 'OUR_CAT_MODEL' => "native"); return array_merge($config, $config_router);
/** * @param string $theme_name */ public function themeDelHandle($theme_name = '') { if (get_kv('home_theme') == $theme_name) { $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('删除成功'); }
/** * @param string $theme_name */ public function themeChangeHandle($theme_name = 'NovaGreenStudio') { if (get_kv('home_theme') == $theme_name) { $this->error('无需切换'); } if ($this->themeStatus($theme_name) == 'disabled') { $this->error('请先启用主题'); } $res = set_kv('home_theme', $theme_name); if ($res) { $cache_control = new SystemEvent(); $cache_control->clearCacheAll(); $this->success('切换成功'); } else { $this->error('切换失败'); } }