static function getCms() { $dataRoot = dirname(__FILE__) . "/"; $privateDataDir = DATA_ROOT . self::$dataDir; $publicDataDir = DATA_ROOT . rtrim(self::$dataRoot, "/") . "/base/"; $dataName = "data.php"; //指定data的路径(仅能指定同目录下私有数据) $assignDataName = $_GET["data"]; if (!empty($assignDataName)) { $dataName = $assignDataName . ".php"; } //复制url的参数值到$root.urlparam中 $arr = array("urlparam" => array_merge($_GET, $_POST)); //set smarty $sysInfo = array("baseDataDir" => $publicDataDir . "data\\.php", "privateDataDir" => $privateDataDir . "data\\.php", "templateRoot" => TEMPLATE_PATH, "country" => self::$country, "host" => self::$host); //获取query_string以便判断是否开启smarty或者data调试模式 if (isset($_SERVER['QUERY_STRING'])) { self::$_query_string = $_SERVER['QUERY_STRING']; } //判断是否启动smarty调试 self::isSmartyDebug(); //所有data都有一个公共data,先把公共的data加载到cmsdata中 $severBaseDataPath = rtrim(self::$dataRoot, "/") . "/base/" . self::$serverDataName; $localBaseDataPath = $publicDataDir . self::$dataName; $arr = CmsDataAdapter::saveAndGetOrMergeData($localBaseDataPath, $severBaseDataPath, $arr); //如果指定私有数据路径使用私有数据 if (strpos(self::$dataDir, 'fetchwidget') !== false) { $assignDir = $_GET['dataDir']; if (!$assignDir) { $assignDir = "index"; } $privateDataDir = DATA_ROOT . self::$dataRoot . $assignDir . "/"; } $severPrivateDataPath = self::$dataDir . self::$serverDataName; $localPrivateDataPath = $privateDataDir . self::$dataName; $arrTmp = CmsDataAdapter::saveAndGetOrMergeData($localPrivateDataPath, $severPrivateDataPath, $arrTmp); if (!empty($arrTmp['head']['privateBaseData'])) { $serverPrivateBaseDataPath = $arrTmp["head"]["privateBaseData"]; $localPrivateBaseDataPath = DATA_ROOT . $arrTmp["head"]["privateBaseData"]; $arr = CmsDataAdapter::saveAndGetOrMergeData($localPrivateBaseDataPath, $serverPrivateBaseDataPath, $arr); } $arr = self::array_merge_recursive_new($arr, $arrTmp); //这个数据流程为总base-》指定base-》页面数据 $severPrivateDataPath = self::$dataDir . self::$serverDataName; $localPrivateDataPath = $privateDataDir . self::$dataName; //支持选择性的三层数据继承 遗留bug ,这个数据流程为总base->页面数据-》指定base if (!empty($arr["head"]["baseData"])) { $baseData = $sysInfo["privateDataDir"] = DATA_ROOT . $arr["head"]["baseData"]; $severPrivateDataPath = $arr["head"]["baseData"]; $arr = CmsDataAdapter::saveAndGetOrMergeData($baseData, $severPrivateDataPath, $arr); } //支持第三层数据继承,为了抽样 $sample = empty($_GET['sample']) ? "" : $_GET['sample']; if (!empty($sample) && !empty($arr["head"]["sample"][$sample])) { //////////////////////////// //支持子通道(返回功能) $sub_channel_cookie = 'sample_channel_' . $sample; //=back'; $sub_sample_name = $_COOKIE[$sub_channel_cookie]; if (!empty($sub_sample_name)) { $sample = $sample . '_' . $sub_sample_name; //'searchtest' => 'searchtest_back' } ///////////////// $sampleDir = ltrim($arr["head"]["sample"][$sample], "/"); $sampleDataPath = $sysInfo["privateDataDir"] = DATA_ROOT . $sampleDir; //fis需要转移"."为"\." $sysInfo["privateDataDir"] = str_replace('data.php', 'data\\.php', $sysInfo["privateDataDir"]); $baseData = $sysInfo["privateDataDir"] = DATA_ROOT . $arr["head"]["baseData"]; $serverSampleDataPath = $sampleDir; $arr = CmsDataAdapter::saveAndGetOrMergeData($sampleDataPath, $serverSampleDataPath, $arr); } /////////////////////////////////////////////////////// //支持读取外部数据的插件机制 if (isset($arr['body']['extendDataPlugin']) && $arr['body']['extendDataPlugin']['on']) { $extend_data_plugins = $arr['body']['extendDataPlugin']['plugins']; // /*array( array( 'start' => 0, 'end' => 2395212684, 'sample_name' => '', 'params' => '{}', 'name' => 'recommendhottab' ) );*/ $action_time = time(); foreach ($extend_data_plugins as $api_plugin) { if ($api_plugin['need_baiduid'] && empty($_COOKIE['BAIDUID'])) { //判断是否有baiduid continue; } if ($api_plugin['start'] <= $action_time && $action_time <= $api_plugin['end']) { //判断插件生效时间,用timestamp //正式开始引入插件处理 $params = $api_plugin['params']; if (!empty($params)) { try { $params = json_decode($params, true); } catch (Exception $e) { $params = array(); } } else { $params = array(); } $api_plugin_name = $api_plugin['name']; $api_plugin_class = ucfirst($api_plugin_name); try { $api_plugin_config = (include_once $dataRoot . 'plugin/' . $api_plugin_name . '/' . $api_plugin_class . '.inc.php'); } catch (Exception $e) { //TODO LOG continue; } if (empty($api_plugin_config)) { continue; //配置不合法,退出 } try { include_once $dataRoot . '/plugin/' . $api_plugin_name . '/' . $api_plugin_class . '.class.php'; } catch (Exception $e) { //TODO LOG continue; } if (!class_exists($api_plugin_class)) { continue; //类加载有问题,退出 } $api_plugin_instance = new $api_plugin_class($api_plugin_config, $sysInfo['country']); if (empty($api_plugin_instance)) { continue; //初始化失败,退出 } $ret = $api_plugin_instance->process($arr['body'], $params); //执行数据干预 if ($ret === false) { //LOG } } } } //smarty extend(为了选择布局)不能用条件判断语句,但是可以使用变量 $layoutRoot = "web/base/layout/"; $sysInfo['layout'] = empty($arr["head"]["layout"]) ? "home/page/layout/layout-index.tpl" : $arr["head"]["layout"]; // 把cookie记录到smarty变量中,方便前端模板调用 $baiduId = $sysInfo["baiduid"] = isset($_COOKIE["FLASHID"]) ? $_COOKIE["FLASHID"] : (isset($_COOKIE["BAIDUID"]) ? $_COOKIE["BAIDUID"] : ""); $sysInfo["serverTime"] = time(); //测试环境,需要置空cdn $arr["head"]["cdn"] = ""; if (!empty($baiduId) && extension_loaded("decodecookie")) { $sysInfo["baiduidCt"] = decodecookie($baiduId); } else { $sysInfo["baiduidCt"] = $sysInfo["serverTime"]; } self::$cmsData = array("sysInfo" => $sysInfo, "root" => $arr); }