/** * 构造函数,进行模板引擎的实例化操作 */ public function __construct() { if (FALSE == $GLOBALS['G_SP']['view']['enabled']) { return FALSE; } if (FALSE != $GLOBALS['G_SP']['view']['auto_ob_start']) { ob_start(); } $this->engine = spClass($GLOBALS['G_SP']['view']['engine_name'], null, $GLOBALS['G_SP']['view']['engine_path']); if ($GLOBALS['G_SP']['view']['config'] && is_array($GLOBALS['G_SP']['view']['config'])) { $engine_vars = get_class_vars(get_class($this->engine)); foreach ($GLOBALS['G_SP']['view']['config'] as $key => $value) { if (array_key_exists($key, $engine_vars)) { $this->engine->{$key} = $value; } } } if (!empty($GLOBALS['G_SP']['sp_app_id']) && isset($this->engine->compile_id)) { $this->engine->compile_id = $GLOBALS['G_SP']['sp_app_id']; } // 检查编译目录是否可写 if (empty($this->engine->no_compile_dir) && (!is_dir($this->engine->compile_dir) || !is_writable($this->engine->compile_dir))) { __mkdirs($this->engine->compile_dir); } spAddViewFunction('T', array('spView', '__template_T')); spAddViewFunction('spUrl', array('spView', '__template_spUrl')); }
function __construct() { // 公用 parent::__construct(); // 这是必须的 header('Content-type: application/json'); extension_loaded('openssl') or die('php需要openssl扩展支持'); spAddViewFunction('spTanslateError', array(&$this, '__template_TranslateError')); }
/** * 构造函数 */ public function __construct() { if ($GLOBALS['G_SP']['view']['enabled']) { $this->v = spClass($GLOBALS['G_SP']['view']['engine_name'], null, $GLOBALS['G_SP']['view']['engine_path']); foreach ($GLOBALS['G_SP']['view']['config'] as $key => $value) { $this->v->{$key} = $value; } if (!empty($GLOBALS['G_SP']['sp_app_id']) && isset($this->v->compile_id)) { $this->v->compile_id = $GLOBALS['G_SP']['sp_app_id']; } if (!is_writable($GLOBALS['G_SP']['view']['config']['compile_dir'])) { spError('View Engine: complie_dir is not writable!'); } if (!is_writable($GLOBALS['G_SP']['view']['config']['cache_dir'])) { spError('View Engine: cache_dir is not writable!'); } spAddViewFunction('spUrl', '__template_spUrl'); } }
/** * 构造函数,进行模板引擎的实例化操作 */ public function __construct() { if (FALSE == $GLOBALS['G_SP']['view']['enabled']) { return FALSE; } if (FALSE != $GLOBALS['G_SP']['view']['auto_ob_start']) { ob_start(); } $this->engine = spClass($GLOBALS['G_SP']['view']['engine_name'], null, $GLOBALS['G_SP']['view']['engine_path']); $configs = $GLOBALS['G_SP']['view']['config']; if (is_array($configs)) { $engine_vars = get_class_vars(get_class($this->engine)); foreach ($configs as $key => $value) { if (array_key_exists($key, $engine_vars)) { $this->engine->{$key} = $value; } } } spAddViewFunction('T', array('spView', '__template_T')); spAddViewFunction('spUrl', array('spView', '__template_spUrl')); }
function search() { spAddViewFunction('kred', 'SearchReplaceKw'); $kw = urldecode($this->spArgs("kw", "")); $page = $this->spArgs("page", "1"); $px = $this->spArgs("px", "1"); $cl = new SphinxClient(); $cl->SetServer('127.0.0.1', 9312); $cl->SetArrayResult(true); $cl->SetLimits(0, 150000); if ($px == "1") { $cl->SetSortMode(SPH_SORT_EXTENDED, "ctime DESC"); } elseif ($px == "2") { $cl->SetSortMode(SPH_SORT_EXTENDED, "length DESC"); } elseif ($px == "3") { $cl->SetSortMode(SPH_SORT_EXTENDED, "click DESC"); } else { $cl->SetSortMode(SPH_SORT_EXTENDED, "ctime DESC"); } $res = $cl->Query("{$kw}", "*"); $total_found = $res['total_found']; $pages = floor($total_found / 15); $time = $res['time']; $matches = $res['matches']; $dbfilm = spClass('dbfilm'); $dbsj = spClass('dbsj'); $this->sjresults = $sjresults; $arr = array(); if ($total_found > 15) { for ($x = 0; $x <= 15; $x++) { if ($page > 1) { $w = $page - 1; $i = $w * 15 + $x + 1; } else { $i = $x; } $id = $matches[$i]['id']; $conditions = array("id" => "{$id}"); $result = $dbfilm->find($conditions); $arr[$x] = $result; } } else { for ($x = 0; $x <= $total_found; $x++) { if ($page > 1) { $w = $page - 1; $i = $w * 15 + $x + 1; } else { $i = $x; } $id = $matches[$i]['id']; $conditions = array("id" => "{$id}"); $result = $dbfilm->find($conditions); $arr[$x] = $result; } } $this->total_found = $total_found; $this->time = $time; $this->results = $kw; $this->page = $page; $this->pages = $pages; $this->px = $px; $this->arr = $arr; $tpl = $this->spArgs("tpl", "template"); $this->display("{$tpl}/search.html"); }