/** * 添加购物车 * @param array $data * $data为数组包含以下几个值 * $data=array( * "id"=>1, //商品ID * "name"=>"后盾网2周年西服", //商品名称 * "num"=>2, //商品数量 * "price"=>188.88, //商品价格 * "options"=>array( //其他参数,如价格、颜色可以是数组或字符串|可以不添加 * "color"=>"red", * "size"=>"L" * ) */ static function add($data) { if (!is_array($data) || !isset($data['id']) || !isset($data['name']) || !isset($data['num']) || !isset($data['price'])) { error(L("cart_add_error")); } $data = isset($data[0]) ? $data : array($data); $goods = self::get_goods(); //获得商品数据 foreach ($data as $v) { $options = isset($v['options']) ? $v['options'] : ''; $sid = $v['id'] . md5_d($options); //生成维一ID用于处理相同商品有不同属性时 if (isset($goods[$sid])) { if ($v['num'] == 0) { //如果数量为0删除商品 unset($goods[$sid]); continue; } $goods[$sid] = $v; $goods[$sid]['total'] = $v['num'] * $v['price']; } else { if ($v['num'] == 0) { continue; } $goods[$sid] = $v; $goods[$sid]['total'] = $v['num'] * $v['price']; } } self::save($goods); }
/** * 返回工厂实例,单例模式 */ 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)); //缓存驱动 if (!class_exists($class)) { $classFile = HDPHP_DRIVER_PATH . 'Cache/' . $class . '.class.php'; //加载驱动类库文件 if (!require_cache($classFile)) { halt("缓存类型指定错误,不存在缓存驱动文件:" . $classFile); } } $cacheObj = new $class($options); self::$cacheFactory->cacheList[$driverName] = $cacheObj; return self::$cacheFactory->cacheList[$driverName]; }
/** * 模板显示 * @param string $tpl_file 模板文件 * @param number $cacheTime 缓存时间 * @param string $contentType 文件类型 * @param string $charset 字符集 * @param boolean $show 是否显示 */ public function display($tplFile = "", $cacheTime = null, $contentType = "text/html", $charset = "", $show = true) { $this->endFix = '.' . trim(C("TPL_FIX"), '.'); $this->tplFile = $this->getTemplateFile($tplFile); $this->set_cache_file(); //设置缓存文件 $this->set_cache_time($cacheTime); //设置缓存时间 $this->compileFile = CACHE_COMPILE_PATH . '/' . md5_d($this->tplFile) . '.php'; if (C("debug")) { tplCompile(array(basename($this->tplFile), $this->compileFile)); //记录模板编译文件 } $content = false; //静态缓存数据内容 if ($this->cacheTime > 0) { //缓存控制ssp dir::create(CACHE_TPL_PATH); //缓存目录 if ($this->cacheStat || $this->is_cache($this->cacheTime)) { $content = file_get_contents($this->cacheFile); } } if ($content === false) { //不使用缓存 if ($this->checkCompile($tplFile)) { //编译文件失效 $this->compile(); } $_CONFIG = C(); $_LANGUAGE = L(); if (!empty(self::$vars)) { //加载全局变量 extract(self::$vars); } ob_start(); include $this->compileFile; $content = ob_get_clean(); if ($this->cacheTime > 0) { file_put_contents($this->cacheFile, $content); } } if ($show) { $charset = strtoupper(C("CHARSET")) == 'UTF8' ? "UTF-8" : strtoupper(C("CHARSET")); header("Content-type:" . $contentType . ';charset=' . $charset); echo $content; } else { return $content; } }
/** * 模板显示 * @param string $tplFile 模板文件 * @param string $cachePath 缓存目录 * @param null $cacheTime 缓存时间 * @param string $contentType 文件类型 * @param string $charset 字符集 * @param bool $show 是否显示 * @return bool|string */ public function display($tplFile = null, $cacheTime = null, $cachePath = null, $contentType = "text/html", $charset = "", $show = true) { $this->tplFile = $this->getTemplateFile($tplFile); $this->compileFile = COMPILE_PATH . md5_d($this->tplFile) . '.php'; if (DEBUG) { Debug::$tpl[] = array(basename($this->tplFile), $this->compileFile); //记录模板编译文件 } //缓存时间设置 $cacheTime = is_int($cacheTime) ? $cacheTime : intval(C("CACHE_TPL_TIME")); $content = false; $cachePath = $cachePath ? $cachePath : CACHE_PATH; if ($cacheTime >= 0) { $content = S($_SERVER['REQUEST_URI'], false, $cacheTime, array("dir" => $cachePath, "Driver" => "File")); } //缓存失效 if (!$content) { if ($this->compileInvalid($tplFile)) { //编译文件失效 $this->compile(); } $_CONFIG = C(); $_LANGUAGE = L(); if (!empty($this->vars)) { //加载全局变量 extract($this->vars); } ob_start(); include $this->compileFile; $content = ob_get_clean(); if ($cacheTime >= 0) { is_dir(CACHE_PATH) || dir_create(CACHE_PATH); //创建缓存目录 S($_SERVER['REQUEST_URI'], $content, $cacheTime, array("dir" => $cachePath, "Driver" => "File")); //写入缓存 } } if ($show) { $charset = strtoupper(C("CHARSET")) == 'UTF8' ? "UTF-8" : strtoupper(C("CHARSET")); if (!headers_sent()) { header("Content-type:" . $contentType . ';charset=' . $charset); } echo $content; } else { return $content; } }
function change_password($data) { $result = FALSE; $info = $this->auth_model->get_user_by_id($_SESSION['uid']); if (md5_d($data['old_pwd']) == $info['password']) { if ($this->auth_model->set_user($_SESSION['uid'], array('password' => md5_d($data['password']))) >= 0) { $result = TRUE; } } else { $this->error = '原密码错误!'; } return $result; }
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]; }
/** * 修改用户信息 */ public function editUserInfo() { $cond = 'uid=' . $_GET['id']; if (empty($_POST['password'])) { unset($_POST['password']); } else { $_POST['password'] = md5_d($_POST['password']); } $_POST['user_point'] = array('point' => $_POST['point']); if ($this->user->updateUserinfo($cond, $_POST)) { //更新用户信息,user、point表 go('userList'); } }
function get_key($key, $user_id) { $db = V('user'); $db->view = array('user_autologin' => array('type' => 'inner', 'on' => 'user_autologin.user_id=user.uid')); $result = $db->field('user.uid,user.username,user.last_ip,user.last_login')->where("user.uid={$user_id} AND user_autologin.key_id='" . md5_d($key) . "'")->find(); //$result = $this->user_autologin->query($sql); return $result; }
/** * 修改密码 */ public function password() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $db = M('user'); $userinfo = $db->find($_SESSION['uid']); if ($userinfo['password'] != md5_d($_POST['old_pwd'])) { $this->error('原始密码错误,修改用户密码失败。'); } $db->validate = array(array("pwd", "length:5,21", "密码长度为6-20 ", 2), array("re_pwd", "confirm:pwd", "两次密码不一致 ", 2)); if (!$db->validate()) { $this->error($db->error); } if ($db->where('uid=' . $_SESSION['uid'])->update(array('password' => md5_d($_POST['pwd']))) >= 0) { session_destroy(); $this->success('密码修改成功,请重新登录。', 'index'); } } $this->display('company/password'); }
/** * 创建缓存数据 * @param string $name 缓存变量名 * @param void $data 需要缓存数据 * @return string 缓存数据 */ public function createCatchData($name, $data) { $name = "cache_" . md5_d($name); $str = ''; if (is_array($data)) { $str .= "\${$name} = " . array_to_String($data); } else { $str .= "\${$name} = '" . addcslashes($data, '\'\\') . '\''; } return $str . ";\r\n"; }
/** * 生成对象 || 执行方法 * @param $class 类名 * @param string $method 方法 * @param array $args 参数 * @return mixed */ function O($class, $method = '', $args = array()) { static $result = array(); $name = empty($args) ? $class . $method : $class . $method . md5_d($args); if (!isset($result [$name])) { $class = new $class (); if (!empty($method) && method_exists($class, $method)) { if (!empty($args)) { $result [$name] = call_user_func_array(array(&$class, $method), $args); } else { $result [$name] = $class->$method(); } } else { $result [$name] = $class; } } return $result [$name]; }
function createtable() { if ($_SESSION['step'] < 3) { go("setconifg"); } $_SESSION['step'] = 4; $admin = $_SESSION['adminpost']; $username = $admin['username']; $password = md5_d($admin['password']); $email = $admin['email']; $dbconfig = (include "../config/database.php"); $dbprefix = $dbconfig['DB_PREFIX']; //表前缀 $sql = PATH_APP . '/data/hd_recruit.sql'; //获取数据库SQL $content = file_get_contents($sql); $search = array('{_DB_PREFIX_}', '{_ADMIN_USER_}', '{_ADMIN_PASSWORD_}', '{_ADMIN_EMAIL_}', '{_ADMIN_CREATE_}'); $replace = array($dbprefix, $username, $password, $email, time()); $content = str_replace($search, $replace, $content); $sql_array = explode('---------------INSERT--DATA--------------', $content); $created_sql = explode('-----------------------------------', $sql_array[0]); $insert_sql = explode('-----------------------------------', $sql_array[1]); // $preg = "/(CREATE|USE).*;/sU"; // preg_match_all($preg, $sql, $tables); //连接数据库 $db = mysql_connect($dbconfig['DB_HOST'], $dbconfig['DB_USER'], $dbconfig['DB_PASSWORD']); if (!$db) { $this->error("数据库连接配置错误"); } mysql_query("SET NAMES UTF8"); mysql_query("CREATE DATABASE IF NOT EXISTS " . $dbconfig['DB_DATABASE'] . " CHARSET utf8"); // mysql_query("USE " . $dbconfig['DB_DATABASE']); mysql_select_db($dbconfig['DB_DATABASE']); $buffer = ini_get("output_buffering"); $error = 0; //错误状态码 foreach ($created_sql as $sql) { $preg = "/CREATE\\s+TABLE\\s+IF\\s+NOT\\s+EXISTS\\s+`(.*?`)/iU"; preg_match($preg, $sql, $tb); echo str_repeat(" ", $buffer); //将缓冲区填满 if ($tb) { if (mysql_query($sql)) { echo "<span style='font-size:14px;height:20px;display:block;width:500px;color:#89B928;'>数据表" . $tb[1] . "创建成功.....</span>"; } else { $error = 1; echo "<span style='font-size:14px;height:20px;display:block;width:500px;color:#f00;'>数据表" . $tb[1] . "创建失败.....</span>"; } } else { mysql_query($sql); } // sleep(1); ob_flush(); flush(); } //写入系统数据,包括管理员 foreach ($insert_sql as $sql) { mysql_query($sql); } echo "<script>\n setTimeout(function(){\n parent.window.location.href='" . __CONTROL__ . "/finish';\n },0)\n \n </script>"; exit; }