Example #1
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) {
         uk86_throw_exception($e->getMessage());
     }
 }
Example #2
0
 public function __construct()
 {
     $this->config = C('memcache');
     if (!extension_loaded('memcache') || !is_array($this->config[1])) {
         uk86_throw_exception('memcache failed to load');
     }
     $this->uk86_init();
 }
Example #3
0
 protected function parseWhereItem($key, $val)
 {
     $whereStr = '';
     if (is_array($val)) {
         if (is_string($val[0])) {
             if (preg_match('/^(EQ|NEQ|GT|EGT|LT|ELT|NOTLIKE|LIKE)$/i', $val[0])) {
                 // 比较运算
                 $whereStr .= $key . ' ' . $this->comparison[strtolower($val[0])] . ' ' . $this->parseValue($val[1]);
             } elseif ('exp' == strtolower($val[0])) {
                 // 使用表达式
                 //                    $whereStr .= ' ('.$key.' '.$val[1].') ';
                 $whereStr .= $val[1];
             } elseif (preg_match('/IN/i', $val[0])) {
                 // IN 运算
                 if (isset($val[2]) && 'exp' == $val[2]) {
                     $whereStr .= $key . ' ' . strtoupper($val[0]) . ' ' . $val[1];
                 } else {
                     if (empty($val[1])) {
                         $whereStr .= $key . ' ' . strtoupper($val[0]) . '(\'\')';
                     } elseif (is_string($val[1]) || is_numeric($val[1])) {
                         $val[1] = explode(',', $val[1]);
                         $zone = implode(',', $this->parseValue($val[1]));
                         $whereStr .= $key . ' ' . strtoupper($val[0]) . ' (' . $zone . ')';
                     } elseif (is_array($val[1])) {
                         $zone = implode(',', $this->parseValue($val[1]));
                         $whereStr .= $key . ' ' . strtoupper($val[0]) . ' (' . $zone . ')';
                     }
                 }
             } elseif (preg_match('/BETWEEN/i', $val[0])) {
                 $data = is_string($val[1]) ? explode(',', $val[1]) : $val[1];
                 if ($data[0] && $data[1]) {
                     $whereStr .= ' (' . $key . ' ' . strtoupper($val[0]) . ' ' . $this->parseValue($data[0]) . ' AND ' . $this->parseValue($data[1]) . ' )';
                 } elseif ($data[0]) {
                     $whereStr .= $key . ' ' . $this->comparison['gt'] . ' ' . $this->parseValue($data[0]);
                 } elseif ($data[1]) {
                     $whereStr .= $key . ' ' . $this->comparison['lt'] . ' ' . $this->parseValue($data[1]);
                 }
             } elseif (preg_match('/TIME/i', $val[0])) {
                 $data = is_string($val[1]) ? explode(',', $val[1]) : $val[1];
                 if ($data[0] && $data[1]) {
                     $whereStr .= ' (' . $key . ' BETWEEN ' . $this->parseValue($data[0]) . ' AND ' . $this->parseValue($data[1] + 86400 - 1) . ' )';
                 } elseif ($data[0]) {
                     $whereStr .= $key . ' ' . $this->comparison['gt'] . ' ' . $this->parseValue($data[0]);
                 } elseif ($data[1]) {
                     $whereStr .= $key . ' ' . $this->comparison['lt'] . ' ' . $this->parseValue($data[1] + 86400);
                 }
             } else {
                 $error = 'Model Error: args ' . $val[0] . ' is error!';
                 uk86_throw_exception($error);
             }
         } else {
             $count = count($val);
             if (in_array(strtoupper(trim($val[$count - 1])), array('AND', 'OR', 'XOR'))) {
                 $rule = strtoupper(trim($val[$count - 1]));
                 $count = $count - 1;
             } else {
                 $rule = 'AND';
             }
             for ($i = 0; $i < $count; $i++) {
                 if (is_array($val[$i])) {
                     if (is_array($val[$i][1])) {
                         $data = implode(',', $val[$i][1]);
                     } else {
                         $data = $val[$i][1];
                     }
                 } else {
                     $data = $val[$i];
                 }
                 if ('exp' == strtolower($val[$i][0])) {
                     $whereStr .= '(' . $key . ' ' . $data . ') ' . $rule . ' ';
                 } else {
                     $op = is_array($val[$i]) ? $this->comparison[strtolower($val[$i][0])] : '=';
                     if (preg_match('/IN/i', $op)) {
                         $whereStr .= '(' . $key . ' ' . $op . ' (' . $this->parseValue($data) . ')) ' . $rule . ' ';
                     } else {
                         $whereStr .= '(' . $key . ' ' . $op . ' ' . $this->parseValue($data) . ') ' . $rule . ' ';
                     }
                 }
             }
             $whereStr = substr($whereStr, 0, -4);
         }
     } else {
         $whereStr .= $key . ' = ' . $this->parseValue($val);
     }
     return $whereStr;
 }
Example #4
0
 /**
  * 调用显示模板
  *
  * @param string $page_name
  * @param string $layout
  * @param int $time
  */
 public static function showpage($page_name = '', $layout = '', $time = 2000)
 {
     if (!defined('TPL_NAME')) {
         define('TPL_NAME', 'default');
     }
     self::getInstance();
     if (!empty(self::$tpl_dir)) {
         $tpl_dir = self::$tpl_dir . DS;
     }
     //默认是带有布局文件
     if (empty($layout)) {
         $layout = 'layout' . DS . self::$layout_file . '.php';
     } else {
         $layout = 'layout' . DS . $layout . '.php';
     }
     $layout_file = BASE_PATH . '/templates/' . TPL_NAME . DS . $layout;
     $tpl_file = BASE_PATH . '/templates/' . TPL_NAME . DS . $tpl_dir . $page_name . '.php';
     if (file_exists($tpl_file)) {
         //对模板变量进行赋值
         $output = self::$output_value;
         //页头
         $output['html_title'] = $output['html_title'] != '' ? $output['html_title'] : $GLOBALS['setting_config']['site_name'];
         $output['seo_keywords'] = $output['seo_keywords'] != '' ? $output['seo_keywords'] : $GLOBALS['setting_config']['site_name'];
         $output['seo_description'] = $output['seo_description'] != '' ? $output['seo_description'] : $GLOBALS['setting_config']['site_name'];
         $output['ref_url'] = uk86_getReferer();
         Uk86Language::uk86_read('common');
         $lang = Uk86Language::uk86_getLangContent();
         @header("Content-type: text/html; charset=" . CHARSET);
         //判断是否使用布局方式输出模板,如果是,那么包含布局文件,并且在布局文件中包含模板文件
         if ($layout != '') {
             if (file_exists($layout_file)) {
                 include_once $layout_file;
             } else {
                 $error = 'Tpl ERROR:' . 'templates' . DS . $layout . ' is not exists';
                 uk86_throw_exception($error);
             }
         } else {
             include_once $tpl_file;
         }
     } else {
         $error = 'Tpl ERROR:' . 'templates' . DS . $tpl_dir . $page_name . '.php' . ' is not exists';
         uk86_throw_exception($error);
     }
 }
Example #5
0
 public static function rollback($host = 'master')
 {
     if (!self::$iftransacte) {
         $result = self::$link[$host]->rollback();
         self::$link[$host]->autocommit(true);
         self::$iftransacte = true;
         if (!$result) {
             uk86_throw_exception("Db Error: " . mysqli_error(self::$link[$host]));
         }
     }
 }
Example #6
0
 public static function rollback($host = 'master')
 {
     if (!self::$iftransacte) {
         $result = mysql_query('ROLLBACK', self::$link[$host]);
         self::$iftransacte = true;
         if (!$result) {
             uk86_throw_exception("Db Error: " . mysql_error(self::$link[$host]));
         }
     }
 }
Example #7
0
/**
 * 实例化类
 *
 * @param string $model_name 模型名称
 * @return obj 对象形式的返回结果
 */
function uk86_nc_class($classname = null)
{
    static $_cache = array();
    if (!is_null($classname) && isset($_cache[$classname])) {
        return $_cache[$classname];
    }
    $file_name = BASE_PATH . '/framework/libraries/' . $classname . '.class.php';
    $newname = $classname . 'Class';
    if (file_exists($file_name)) {
        require_once $file_name;
        if (class_exists($newname)) {
            return $_cache[$classname] = new $newname();
        }
    }
    uk86_throw_exception('Class Error:  Class ' . $classname . ' is not exists!');
}
Example #8
0
 /**
  * 控制器调度
  *
  */
 private static function uk86_control()
 {
     //二级域名
     if ($GLOBALS['setting_config']['enabled_subdomain'] == '1' && $_GET['act'] == 'index' && $_GET['op'] == 'index') {
         $store_id = uk86_subdomain();
         if ($store_id > 0) {
             $_GET['act'] = 'show_store';
         }
     }
     $act_file = realpath(BASE_PATH . '/control/' . $_GET['act'] . '.php');
     $class_name = $_GET['act'] . 'Control';
     if (!@(include $act_file)) {
         if (C('debug')) {
             uk86_throw_exception("Uk86Base Error: access file isn't exists!");
         } else {
             uk86_showMessage('抱歉!您访问的页面不存在', '', 'html', 'error');
         }
     }
     if (class_exists($class_name)) {
         $main = new $class_name();
         $function = $_GET['op'] . 'Op';
         if (method_exists($main, $function)) {
             $main->{$function}();
         } elseif (method_exists($main, 'indexOp')) {
             $main->indexOp();
         } else {
             $error = "Uk86Base Error: function {$function} not in {$class_name}!";
             uk86_throw_exception($error);
         }
     } else {
         $error = "Uk86Base Error: class {$class_name} isn't exists!";
         uk86_throw_exception($error);
     }
 }