/**
  * 返回工厂实例,单例模式
  */
 public static function factory($options)
 {
     $options = is_array($options) ? $options : array();
     //只实例化一个对象
     if (is_null(self::$cacheFactory)) {
         self::$cacheFactory = new cacheFactory();
     }
     $driver = isset($options['driver']) ? $options['driver'] : C("CACHE_TYPE");
     //静态缓存实例名称
     $driverName = md5_d($options);
     //对象实例存在
     if (isset(self::$cacheFactory->cacheList[$driverName])) {
         return self::$cacheFactory->cacheList[$driverName];
     }
     $class = 'Cache' . ucwords(strtolower($driver));
     //缓存驱动
     $classFile = HDPHP_DRIVER_PATH . 'Cache/' . $class . '.class.php';
     //加载驱动类库文件
     if (!require_cache($classFile)) {
         throw_exception("缓存类型指定错误,不存在缓存驱动文件:" . $classFile);
     }
     $cacheObj = new $class($options);
     self::$cacheFactory->cacheList[$driverName] = $cacheObj;
     return self::$cacheFactory->cacheList[$driverName];
 }
Example #2
0
 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0, $force = false)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // 处理不带端口号的socket连接情况
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         // 是否长连接
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         if ($pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum]) || C('SPARE_DB_DEBUG')) {
             $errStr = mysql_error();
             $errno = mysql_errno();
             if ($errno == 13047 || C('SPARE_DB_DEBUG')) {
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('mysql超额被禁用,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR);
                 }
                 //[sae]启动备用数据库
                 if (C('SPARE_DB_HOST')) {
                     $this->linkID[$linkNum] = mysql_connect(C('SPARE_DB_HOST') . (C('SPARE_DB_PORT') ? ':' . C('SPARE_DB_PORT') : ''), C('SPARE_DB_USER'), C('SPARE_DB_PWD'), true, CLIENT_MULTI_RESULTS);
                     if (!$this->linkID[$linkNum]) {
                         throw_exception('备用数据库连接失败');
                     }
                     mysql_select_db(C('SPARE_DB_NAME'), $this->linkID[$linkNum]);
                     //标记使用备用数据库状态
                     $this->is_spare = true;
                 } else {
                     throw_exception($errStr);
                 }
             } else {
                 //[sae] 短信预警
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('数据库连接时出错,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR);
                 }
                 throw_exception($errStr);
             }
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         if ($dbVersion >= '4.1') {
             //使用UTF8存取数据库 需要mysql 4.1.0以上支持
             mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         }
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // 标记连接成功
         $this->connected = true;
         // 注销数据库连接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     if ('think' == $engine) {
         // 采用Think模板引擎
         if ($this->checkCache($_data['file'])) {
             // 缓存有效
             // 分解变量并载入模板缓存
             extract($_data['var'], EXTR_OVERWRITE);
             //载入模版缓存文件
             include C('CACHE_PATH') . md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($_data['file'], $_data['var']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         $class = 'Template' . ucwords($engine);
         if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
             // 内置驱动
             $path = CORE_PATH;
         } else {
             // 扩展驱动
             $path = EXTEND_PATH;
         }
         if (require_cache($path . 'Driver/Template/' . $class . '.class.php')) {
             $tpl = new $class();
             $tpl->fetch($_data['file'], $_data['var']);
         } else {
             // 类没有定义
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
 }
 public function __construct()
 {
     if (!extension_loaded('eAccelerator')) {
         throw_exception('eAccelerator failed to load');
     }
     $this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6) . '_';
 }
Example #5
0
 /**
  * 连接数据库方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'mssql_pconnect' : 'mssql_connect';
         // 处理不带端口号的socket连接情况
         $sepr = IS_WIN ? ',' : ':';
         $host = $config['hostname'] . ($config['hostport'] ? $sepr . "{$config['hostport']}" : '');
         $this->linkID[$linkNum] = $conn($host, $config['username'], $config['password']);
         if (!$this->linkID[$linkNum]) {
             throw_exception("Couldn't connect to SQL Server on {$host}");
         }
         if (!empty($config['database']) && !mssql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception("Couldn't open database '" . $config['database']);
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
Example #6
0
 /**
  * 连接数据库方法
  * @access public
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         $conn = $pconnect ? 'pg_pconnect' : 'pg_connect';
         $this->linkID[$linkNum] = $conn('host=' . $config['hostname'] . ' port=' . $config['hostport'] . ' dbname=' . $config['database'] . ' user='******'username'] . '  password='******'password']);
         if (0 !== pg_connection_status($this->linkID[$linkNum])) {
             throw_exception($this->error(false));
         }
         //设置编码
         pg_set_client_encoding($this->linkID[$linkNum], C('DB_CHARSET'));
         //$pgInfo = pg_version($this->linkID[$linkNum]);
         //$dbVersion = $pgInfo['server'];
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         // 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 缓存有效
             // 分解变量并载入模板缓存
             extract($_data['var'], EXTR_OVERWRITE);
             //载入模版缓存文件
             include C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         $class = 'Template' . ucwords($engine);
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 类没有定义
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
 }
Example #8
0
 public function __construct()
 {
     if (!function_exists("xcache_info")) {
         throw_exception("Xcache failed to load");
     }
     $this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6) . "_";
 }
 /**
  * 连接
  * @access public
  * @param array $options  配置数组
  * @return object
  */
 public static function connect($options = array())
 {
     if (isset($options['type']) && $options['type']) {
         $type = $options['type'];
         unset($options['type']);
     } else {
         //网站配置
         $config = F("Config");
         if ((int) $config['ftpstatus']) {
             $type = 'Ftp';
         } else {
             $type = 'Local';
         }
     }
     //附件存储方案
     $type = trim($type);
     $class = 'Attachment' . ucwords($type);
     import("Driver.Attachment.{$class}", LIB_PATH);
     if (class_exists($class)) {
         $Atta = new $class($options);
     } else {
         throw_exception('无法加载附件上传方案:' . $type);
     }
     return $Atta;
 }
Example #10
0
 public function login()
 {
     if (is_empty($this->post->user) || is_empty($this->post->password)) {
         throw_exception("User and Password are required");
     }
     $options['user']['lvl2'] = "one_login";
     $cod['user']['user'] = $this->post->user;
     $cod['user']['password'] = $this->post->password;
     $this->orm->connect();
     $this->orm->read_data(array("user"), $options, $cod);
     $user = $this->orm->get_objects("user");
     #echo $user[0]->get('type');
     $this->orm->close();
     if (is_empty($user)) {
         throw_exception("User or Password Incorrect");
     } else {
         $_SESSION['user']['id'] = $user[0]->get('id');
         $_SESSION['user']['name'] = $user[0]->get('name');
         $_SESSION['user']['user'] = $user[0]->get('user');
         $_SESSION['user']['type'] = $user[0]->get('type');
         $_SESSION['user']['email'] = $user[0]->get('email');
         $this->session = $_SESSION;
         $this->engine->assign('type_warning', 'success');
         $this->engine->assign('msg_warning', "Welcome!");
         $this->temp_aux = 'message.tpl';
     }
 }
 /**
  * Connection database method
  * @access public
  * @throws SenExecption
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306);
         if (mysqli_connect_errno()) {
             throw_exception(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         // Set the database encoding
         $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'");
         //Setup sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // Mark connection successful
         $this->connected = true;
         //Unregister database security information
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         //[sae] 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 缓存有效
             //[sae],为方便saeCacheBuilder编译, 模板编译缓存不分组
             SaeMC::include_file(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         $class = 'Template' . ucwords($engine);
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 类没有定义
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
     //[sae] 添加trace信息。
     if (!SAE_RUNTIME) {
         trace($_SERVER['HTTP_APPVERSION'] . '/' . RUNTIME_FILE, '核心缓存Mecache KEY', 'SAE');
         trace($_SERVER['HTTP_APPVERSION'] . '/' . C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), '模版缓存Mecache KEY', 'SAE');
     }
 }
 public function agregar()
 {
     $parque = new parque($this->post);
     if (is_empty($parque->get('codigo'))) {
         throw_exception("Debe ingresar un codigo");
     }
     if ($parque->get("nivel") == "alto" || $parque->get("nivel") == "bajo") {
     } else {
         throw_exception("El nivel debe de ser alto o bajo");
     }
     if ($parque->get("municipio") == "medellin" || $parque->get("municipio") == "rionegro" || $parque->get("municipio") == "la estrella" || $parque->get(" municipio") == "copacabana" || $parque->get(" municipio") == "guatape") {
     } else {
         throw_exception("El municipio debe de ser medellin, rionegro, la estrella, copacabana o guatape");
     }
     print_r($parque);
     $this->orm->connect();
     $this->orm->insert_data("normal", $parque);
     $this->orm->close();
     settype($data, 'object');
     $data->fecha = date("y-m-d");
     $data->calificacion = 0;
     $data->parque = $parque->get("codigo");
     $calificacion = new calificacion($data);
     $this->orm->connect();
     $this->orm->insert_data("normal", $calificacion);
     $this->orm->close();
     $this->type_warning = "sucess";
     $this->msg_warning = "parque agregado correctamente";
     $this->temp_aux = 'message.tpl';
     $this->engine->assign('type_warning', $this->type_warning);
     $this->engine->assign('msg_warning', $this->msg_warning);
 }
Example #14
0
/**
+----------------------------------------------------------
* 缓存检查
* 缓存目录创建、目录权限检查
+----------------------------------------------------------
* @access private 
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
function CheckCache()
{
    //检测模版缓存目录,并尝试创建
    if (!file_exists(CACHE_PATH)) {
        if (!@mkdir(CACHE_PATH)) {
            throw_exception(L('模版缓存目录不存在:') . CACHE_PATH);
        }
    }
    //检测数据缓存目录,并尝试创建
    if (!file_exists(TEMP_PATH)) {
        if (!@mkdir(TEMP_PATH)) {
            throw_exception(L('数据缓存目录不存在:') . TEMP_PATH);
        }
    }
    //检测静态缓存目录,并尝试创建
    if (!file_exists(HTML_PATH)) {
        if (!@mkdir(HTML_PATH)) {
            throw_exception(L('静态缓存目录不存在:') . HTML_PATH);
        }
    }
    //检测日志目录,并尝试创建
    if (!file_exists(LOG_PATH)) {
        if (!@mkdir(LOG_PATH)) {
            throw_exception(L('日志目录不存在:') . LOG_PATH);
        }
    }
    return;
}
Example #15
0
	public function __construct(){
		$this->config = C('memcache');
		if (!extension_loaded('memcache') || !is_array($this->config[1])) {
			throw_exception('memcache failed to load');
		}
		$this->init();
	}
Example #16
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  * @access public
  */
 function __construct($options = array())
 {
     if (!extension_loaded('memcached')) {
         throw_exception(L('_NOT_SUPPERT_') . ':memcached');
     }
     if (empty($options)) {
         $options = array('host' => C('MEMCACHE_HOST') ? C('MEMCACHE_HOST') : '127.0.0.1', 'port' => C('MEMCACHE_PORT') ? C('MEMCACHE_PORT') : 11211, 'weight' => C('MEMCACHE_WEIGHT') ? C('MEMCACHE_WEIGHT') : 0, 'timeout' => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false, 'compress' => C('DATA_CACHE_COMPRESS') ? C('DATA_CACHE_COMPRESS') : false, 'persistent' => false);
     }
     $this->options = $options;
     $this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME');
     $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX');
     $this->options['length'] = isset($options['length']) ? $options['length'] : 0;
     $func = $options['persistent'] ? 'pconnect' : 'connect';
     $key = $this->options['host'] . $this->options['port'];
     $this->handler = new Memcached($key);
     if (!count($this->handler->getServerList())) {
         //This code block will only execute if we are setting up a new EG(persistent_list) entry
         $this->handler->setOption(Memcached::OPT_RECV_TIMEOUT, $this->options['timeout']);
         $this->handler->setOption(Memcached::OPT_SEND_TIMEOUT, $this->options['timeout']);
         $this->handler->setOption(Memcached::OPT_COMPRESSION, $this->options['compress']);
         $this->handler->setOption(Memcached::OPT_TCP_NODELAY, true);
         $this->handler->setOption(Memcached::OPT_PREFIX_KEY, $this->options['prefix']);
         $this->connected = $this->handler->addServer($this->options['host'], $this->options['port']);
     }
 }
 /**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // 解析规则为 分组@模板主题:模块:操作
         if (strpos($templateFile, '@')) {
             list($group, $templateFile) = explode('@', $templateFile);
             if (1 == C('APP_GROUP_MODE')) {
                 $basePath = dirname(BASE_LIB_PATH) . '/';
             } else {
                 $basePath = TMPL_PATH;
             }
             $basePath .= $group . '/' . basename(TMPL_PATH) . '/' . (THEME_NAME ? THEME_NAME . '/' : '');
         } else {
             $basePath = THEME_PATH;
         }
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : MODULE_NAME;
         if (!empty($path)) {
             // 设置模板主题
             $basePath = dirname($basePath) . '/' . array_pop($path) . '/';
         }
         $templateFile = $basePath . $module . C('TMPL_FILE_DEPR') . $action . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
 /**
  * Connection database method
  * @access public
  * @throws SenExecption
  */
 public function connect($config = '', $linkNum = 0, $force = false)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // Deal with the port number of the socket connection
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         // Whether long connection
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         if ($pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], 131072);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, 131072);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception(mysql_error());
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         //Access database using UTF8
         mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         //Setup sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // Mark connection successful
         $this->connected = true;
         // Unregister database connection configuration information
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
Example #19
0
 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0, $force = false)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // 处理不带端口号的socket连接情况
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         // 是否长连接
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         if ($pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], 131072);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, 131072);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception(mysql_error());
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         //使用UTF8存取数据库
         mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // 标记连接成功
         $this->connected = true;
         // 注销数据库连接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         // 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 缓存有效
             //[cluster]载入模版缓存文件
             ThinkFS::include_file(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         $class = 'Template' . ucwords($engine);
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 类没有定义
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
     //[cluster] 增加有用的trace信息
     trace(RUNTIME_FILE, '核心编译缓存KEY', 'DEBUG');
     trace(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), '模板缓存KEY', 'DEBUG');
 }
Example #21
0
 public function parseXmlAttr($attr, $tag)
 {
     $attr = str_replace('&', '___', $attr);
     $xml = '<tpl><tag ' . $attr . ' /></tpl>';
     $xml = simplexml_load_string($xml);
     if (!$xml) {
         throw_exception(L('_XML_TAG_ERROR_') . ' : ' . $attr);
     }
     $xml = (array) $xml->tag->attributes();
     $array = array_change_key_case($xml['@attributes']);
     if ($array) {
         $attrs = explode(',', $this->tags[strtolower($tag)]['attr']);
         if (isset($this->tags[strtolower($tag)]['must'])) {
             $must = explode(',', $this->tags[strtolower($tag)]['must']);
         } else {
             $must = array();
         }
         foreach ($attrs as $name) {
             if (isset($array[$name])) {
                 $array[$name] = str_replace('___', '&', $array[$name]);
             } elseif (false !== array_search($name, $must)) {
                 throw_exception(L('_PARAM_ERROR_') . ':' . $name);
             }
         }
         return $array;
     }
 }
Example #22
0
 /**
  * 入列
  * @param unknown $value
  */
 public function push($value) {
     try {
         return $this->_redis->lPush($this->_tb_prefix.rand(1,$this->_tb_num),$value);
     }catch(Exception $e) {
          throw_exception($e->getMessage());
     }
 }
Example #23
0
 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306);
         if (mysqli_connect_errno()) {
             throw_exception(mysqli_connect_error());
         }
         $dbVersion = $this->linkID[$linkNum]->server_version;
         // 设置数据库编码
         $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'");
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             $this->linkID[$linkNum]->query("SET sql_mode=''");
         }
         // 标记连接成功
         $this->connected = true;
         //注销数据库安全信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
Example #24
0
 /**
  * 生成静态页面
  * <code>
  * array(控制器名,方法名,表态数据,保存表态文件路径)
  * array(news,show,1,'h/b/Hd.html');表示生成news控制器中的show方法生成ID为1的文章
  * </code>
  * @param $control
  * @param $method
  * @param $data
  * @return bool
  */
 public static function create($control, $method, $data)
 {
     //创建控制器对象
     if (is_null(self::$obj)) {
         $obj = control($control);
         if (!method_exists($obj, $method)) {
             error("方法{$method}不存在,请查看HD手册", false);
         }
     }
     foreach ($data as $d) {
         //************创建GET数据****************
         $_GET = array_merge($_GET, $d);
         $htmlPath = dirname($d['html_file']);
         //生成静态目录
         if (!dir_create($htmlPath)) {
             //创建生成静态的目录
             throw_exception(L("html_create_error2"));
             return false;
         }
         ob_start();
         $obj->{$method}();
         //执行控制器方法
         $content = ob_get_clean();
         file_put_contents($d['html_file'], $content);
     }
     return true;
 }
 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     if ('think' == $engine) {
         //[sae] 采用Think模板引擎
         if ($this->checkCache($_data['file'])) {
             // 缓存有效
             SaeMC::include_file(md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
         } else {
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($_data['file'], $_data['var']);
         }
     } else {
         // 调用第三方模板引擎解析和输出
         $class = 'Template' . ucwords($engine);
         if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
             // 内置驱动
             $path = CORE_PATH;
         } else {
             // 扩展驱动
             $path = EXTEND_PATH;
         }
         if (require_cache($path . 'Driver/Template/' . $class . '.class.php')) {
             $tpl = new $class();
             $tpl->fetch($_data['file'], $_data['var']);
         } else {
             // 类没有定义
             throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
         }
     }
     //[sae] 添加trace信息。
     trace(array('[SAE]核心缓存' => $_SERVER['HTTP_APPVERSION'] . '/' . RUNTIME_FILE, '[SAE]模板缓存' => $_SERVER['HTTP_APPVERSION'] . '/' . md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX')));
 }
Example #26
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  */
 public function __construct($options = array())
 {
     if (!extension_loaded('memcache')) {
         throw_exception(L('_NOT_SUPPORT_') . ':memcache');
     }
     $hosts = array();
     //服务器列表
     $servers = explode(',', C('MEMCACHE_HOST'));
     //支持多服务器配置
     foreach ($servers as $k => $host) {
         list($host, $port) = explode(':', $host, 2);
         $hosts[] = array('host' => $host ? $host : '127.0.0.1', 'port' => empty($port) ? 11211 : $port);
     }
     if (empty($options)) {
         $options = array('host' => $hosts[0]['host'], 'port' => $hosts[0]['port'], 'timeout' => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false, 'persistent' => false, 'servers' => $hosts);
     }
     $this->options = $options;
     $this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME');
     $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX');
     $this->options['length'] = isset($options['length']) ? $options['length'] : 0;
     $func = $options['persistent'] ? 'pconnect' : 'connect';
     $this->handler = new Memcache();
     //Memcache集群支持
     if (isset($hosts[1])) {
         foreach ($hosts as $host) {
             $this->handler->addServer($host['host'], $host['port'], $options['persistent']);
         }
     } else {
         $host = $hosts[0];
         $options['timeout'] === false ? $this->handler->{$func}($host['host'], $host['port']) : $this->handler->{$func}($host['host'], $host['port'], $options['timeout']);
     }
     //设置大数据压缩
     $this->handler->setCompressThreshold(8 * 1024);
 }
Example #27
0
 /**
  * 添加购物车
  * @access  public
  * @param array $data
  * <code>
  * $data为数组包含以下几个值
  * $Data=array(
  *  "id"=>1,                        //商品ID
  *  "name"=>"后盾网2周年西服",         //商品名称
  *  "num"=>2,                       //商品数量
  *  "price"=>188.88,                //商品价格
  *  "options"=>array(               //其他参数,如价格、颜色可以是数组或字符串|可以不添加
  *      "color"=>"red",
  *      "size"=>"L"
  *  )
  * </code>
  * @return void
  */
 static function add($data)
 {
     if (!is_array($data) || !isset($data['id']) || !isset($data['name']) || !isset($data['num']) || !isset($data['price'])) {
         throw_exception('购物车ADD方法参数设置错误');
     }
     $data = isset($data[0]) ? $data : array($data);
     $goods = self::getGoods();
     //获得商品数据
     //添加商品增持多商品添加
     foreach ($data as $v) {
         $options = isset($v['options']) ? $v['options'] : '';
         $sid = substr(md5($v['id'] . serialize($options)), 0, 8);
         //生成维一ID用于处理相同商品有不同属性时
         if (isset($goods[$sid])) {
             if ($v['num'] == 0) {
                 //如果数量为0删除商品
                 unset($goods[$sid]);
                 continue;
             }
             //已经存在相同商品时增加商品数量
             $goods[$sid]['num'] = $goods[$sid]['num'] + $v['num'];
             $goods[$sid]['total'] = $goods[$sid]['num'] * $goods[$sid]['price'];
         } else {
             if ($v['num'] == 0) {
                 continue;
             }
             $goods[$sid] = $v;
             $goods[$sid]['total'] = $v['num'] * $v['price'];
         }
     }
     self::save($goods);
 }
Example #28
0
 /**
 +----------------------------------------------------------
 * 渲染模板输出 供render方法内部调用
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $templateFile  模板文件
 * @param mixed $var  模板变量
 * @param string $charset  模板编码
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
 protected function renderFile($templateFile = '', $var = '', $charset = 'utf-8')
 {
     ob_start();
     ob_implicit_flush(0);
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         $name = substr(get_class($this), 0, -6);
         $filename = empty($templateFile) ? $name : $templateFile;
         $templateFile = LIB_PATH . 'Widget/' . $name . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     $template = $this->template ? $this->template : strtolower(C('TMPL_ENGINE_TYPE') ? C('TMPL_ENGINE_TYPE') : 'php');
     if ('php' == $template) {
         // 使用PHP模板
         if (!empty($var)) {
             extract($var, EXTR_OVERWRITE);
         }
         // 直接载入PHP模板
         include $templateFile;
     } else {
         $className = 'Template' . ucwords($template);
         require_cache(THINK_PATH . '/Lib/Think/Util/Template/' . $className . '.class.php');
         $tpl = new $className();
         $tpl->fetch($templateFile, $var, $charset);
     }
     $content = ob_get_clean();
     return $content;
 }
Example #29
0
 public function __construct()
 {
     if (!function_exists('apc_cache_info')) {
         throw_exception('Apc failed to load');
     }
     $this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6) . '_';
 }
Example #30
0
 public function add()
 {
     $parque = new parque($this->post);
     if (is_empty($parque->get('nivel'))) {
         throw_exception("Debe ingresar un nivel");
     }
     $parque = new parque($this->post);
     if (is_empty($parque->get('nivel'))) {
         throw_exception("Debe ingresar un municipio");
     }
     if ($parque->get('municipio') != "Medellín" && $parque->get('municipio') != "La estrella" && $parque->get('municipio') != "Rionegro" && $parque->get('municipio') != "Copacabana" && $parque->get('municipio') != "Guatapé") {
         throw_exception("Municipio inválido");
     }
     if ($parque->get('nivel') != "alto" && $parque->get('nivel') != "bajo") {
         throw_exception("Nivel inválido");
     }
     $this->orm->connect();
     $this->orm->insert_data("normal", $parque);
     $this->orm->close();
     $this->type_warning = "sucess";
     $this->msg_warning = "Parque registrado correctamente";
     $this->temp_aux = 'message.tpl';
     $this->engine->assign('type_warning', $this->type_warning);
     $this->engine->assign('msg_warning', $this->msg_warning);
 }