public function updatePages($params = array()) { if (!empty($params)) { $clears = array(); foreach ($params as $key => $value) { if (strncmp($key, XT_OPTION_PAGE_WIDGETS_PRE, strlen(XT_OPTION_PAGE_WIDGETS_PRE)) === 0) { $widgets = maybe_unserialize(stripslashes($value)); if (is_array($widgets)) { if (in_array($key, array(XT_OPTION_PAGE_WIDGETS_PRE . 'header', XT_OPTION_PAGE_WIDGETS_PRE . 'footer'))) { update_option($key, $widgets); } else { if (!add_option($key, $widgets, '', 'no')) { update_option($key, $widgets); } $page = str_replace(XT_OPTION_PAGE_WIDGETS_PRE, '', $key); if ($page == 'home' || is_numeric($page)) { $clears[$page] = true; } } } } elseif (strncmp($key, XT_OPTION_PAGE_PRE, strlen(XT_OPTION_PAGE_PRE)) === 0) { $layouts = maybe_unserialize(stripslashes($value)); if (is_array($layouts)) { $layouts = xt_layout_convert($layouts); if (in_array($key, array(XT_OPTION_PAGE_PRE . 'header', XT_OPTION_PAGE_PRE . 'footer'))) { update_option($key, $layouts); } else { if (!add_option($key, $layouts, '', 'no')) { update_option($key, $layouts); } $page = str_replace(XT_OPTION_PAGE_PRE, '', $key); if ($page == 'home' || is_numeric($page)) { $clears[$page] = true; } } } } } if (!empty($clears)) { foreach ($clears as $page => $flag) { if ($flag) { do_action('xt_page_updated', $page); } } } return true; } return false; }
function xt_init_page($page = 'home', $page_name = '首页', $cache = false) { global $xt_registered_widgets, $xt_page_widgets_setting, $xt_page_layouts, $xt_page_widgets, $xt_current_page, $xt_widget_factory, $xt_need_cache; $xt_current_page = $page; $isEdit = defined('XT_PAGE_EDIT') && XT_PAGE_EDIT; if (!$isEdit && $cache && ($xt_current_page == 'home' || is_numeric($xt_current_page))) { $cache = xt_get_option(XT_OPTION_PAGE_HTML_PRE . $page); if (!empty($cache)) { if (time() < $cache['time'] + 3600 && !empty($cache['data'])) { $cache = xt_cache_covert($cache); $time = gmdate('Y-m-d H:i:s', $cache['time'] + xt_get_option('gmt_offset') * 3600); echo '<!--CACHE[' . $time . '] START-->' . $cache['data'] . '<!--CACHE[' . $time . '] END-->'; return false; } } } xt_register_page(array('name' => $page_name, 'id' => $page, 'description' => '', 'class' => '')); $xt_registered_widgets = array(); $xt_widget_factory = new XT_Widget_Factory(); $widgetsAndLayouts = xt_get_option_page($page); $xt_page_widgets_setting = $widgetsAndLayouts['widgets']; $xt_page_layouts = xt_layout_convert($widgetsAndLayouts['layouts']); $xt_page_layouts = $xt_page_layouts['layouts']; $xt_need_cache = true; if (!$isEdit && empty($xt_page_layouts)) { if (!xt_is_headerOrfooter($xt_current_page)) { $isInstalled = get_option(XT_OPTION_INSTALLED); $xt_need_cache = false; $xt_page_layouts = array(array('name' => 'row-12', 'delete' => 0, 'layout' => array('span12' => array('text-2' => array('edit' => 0, 'delete' => 0))))); $text = '<div class="well xt-unvalid"><h1>尚未装修该页面</h1><p>登录<a href="http://plugin.xintaonet.com/" target="_blank">新淘客平台</a>-页面管理-设计!</p></div>'; if (!$isInstalled) { $text = '<div class="well xt-unvalid"><h1>尚未初始化站点</h1><p>注册,登录<a href="http://plugin.xintaonet.com/" target="_blank">新淘客平台</a>添加验证自己的网站即可初始化!</p></div>'; } $xt_page_widgets_setting = array('text-2' => array('title' => '', 'text' => $text, 'filter' => 0, 'widefat' => 0, 'widget' => 1, 'widget_id' => 'text-2', 'widget_name' => 'text')); } } $_widgets = xt_widgets(); foreach ($_widgets as $_widget) { xt_register_widget($_widget); } do_action('xt_widgets_init'); return true; }