static function is_not_cached($a_name = '', $expire = 3600, $subDirCache = '', $del_cache = false) { self::$arr_cache = array(); if (CACHE_ON) { $c_name = ($subDirCache ? $subDirCache . '/' : '') . $a_name; self::$cache_file = $c_name; if ($del_cache || isset($_GET['delscache']) && (int) $_GET['delscache'] == '1') { self::del_cache($c_name); return true; } self::$expire = $expire < 0 ? 0 : $expire; if (MEMCACHE_ON) { self::$arr_cache = AZMemcache::do_get("acache:{$c_name}"); if (!empty(self::$arr_cache)) { if (DEBUG) { $info = "<br /><font color=red><b>" . self::$cache_file . "</b></font><br /><b>Cache Time:</b> " . self::$expire . "s "; if (!self::$expire) { $info .= "<b> Expire:</b> forever"; } self::$cache_list .= "<li>" . $info . "</li>"; } return false; } } elseif (AZLib::CheckDir(DIR_CACHE . 'arr/' . ($subDirCache ? $subDirCache . '/' : ''), MEMCACHE_ON)) { self::$cache_file = DIR_CACHE . 'arr/' . $c_name . '.eb'; if (file_exists(self::$cache_file)) { self::$createdTime = filemtime(self::$cache_file); if (self::$expire == 0 || self::$expire > 0 && TIME_NOW < self::$createdTime + self::$expire) { self::$arr_cache = unserialize(stripslashes(@file_get_contents(self::$cache_file))); if (DEBUG) { $info = "<br /><font color=red><b>" . self::$cache_file . "</b></font><br /><b>Cache Time:</b> " . self::$expire . "s "; $info .= "<b>Created:</b> " . date('d/m/Y H:i:s', self::$createdTime); if (self::$expire > 0) { $info .= "<b> Expire:</b> " . date('d/m/Y H:i:s', self::$expire + self::$createdTime); } else { $info .= "<b> Expire:</b> forever"; } self::$cache_list .= "<li>" . $info . "</li>"; } return false; } } } } return true; }
function update_user_online() { $user_id = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0; $session_id = session_id(); $page = ''; $page_id = 0; $user_name = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 0; $login_type = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? 1 : 0; $open_id = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? $_SESSION['openid_url'] : ''; if (class_exists('AZNet')) { $page = AZNet::$page['name']; $page_id = (int) AZNet::$page['id']; } if (($page == 'ItemDetail' || $page == 'item_detail') && isset($_GET['id']) && $_GET['id']) { $item_id = (int) $_GET['id']; } else { $item_id = 0; } if (in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = ''; } else { AZLib::check_uri(); $ref_url = CGlobal::$query_string; } $sql = "SELECT session_referer, page, page_id, item_id FROM " . _SESS_TABLE . " WHERE session_id = '{$session_id}'"; $result = DB::query($sql, __LINE__ . __FILE__); if (mysql_num_rows($result)) { $s_row = mysql_fetch_assoc($result); } else { $s_row = array(); } if ($s_row) { if ($ref_url == '' || in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = stripslashes($s_row['session_referer']); } if (!$page) { $page = $s_row['page']; } if (!$page_id) { $page_id = (int) $s_row['page_id']; } if (!$item_id) { $item_id = (int) $s_row['item_id']; } $sql = "UPDATE " . _SESS_TABLE . " SET\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_expires = " . time() . ", \r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_referer = '" . addslashes($ref_url) . "',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tsession_ip \t\t= '" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "', \r\n\t\t\t\t\t\t\t\t\t\t\t\t \tpage \t\t\t= '{$page}',\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tpage_id \t\t= {$page_id},\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tcategory_id \t= " . CGlobal::$curCategory . ",\r\n\t\t\t\t\t\t\t\t\t\t\t\t \titem_id \t\t= {$item_id},\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tuser_id \t\t= '{$user_id}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tuser_name\t\t= '{$user_name}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \tlogin_type\t\t= '{$login_type}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t \topen_id\t\t\t= '{$open_id}'\r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE session_id \t= '{$session_id}'"; } else { $sql = "INSERT INTO " . _SESS_TABLE . " \r\n\t\t\t\t\t\t\t\t (\r\n\t\t\t\t\t\t\t\t \tsession_id, \r\n\t\t\t\t\t\t\t\t \tsession_expires, \r\n\t\t\t\t\t\t\t\t \tsession_referer, \r\n\t\t\t\t\t\t\t\t \tsession_ip, \r\n\t\t\t\t\t\t\t\t \tpage, \r\n\t\t\t\t\t\t\t\t \tpage_id, \r\n\t\t\t\t\t\t\t\t \tcategory_id, \r\n\t\t\t\t\t\t\t\t \titem_id, \r\n\t\t\t\t\t\t\t\t \tuser_id, \r\n\t\t\t\t\t\t\t\t \tuser_name,\r\n\t\t\t\t\t\t\t\t \tlogin_type,\r\n\t\t\t\t\t\t\t\t \topen_id\r\n\t\t\t\t\t\t\t\t \t) \r\n\t\t VALUES (\r\n\t\t \t\t\t'{$session_id}', \t\t\t\t\r\n\t\t \t\t\t" . time() . ", \t\t\t\r\n\t\t \t\t\t'" . addslashes($ref_url) . "', \t \r\n\t\t \t\t\t'" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "',\t\r\n\t\t \t\t\t'{$page}',\t \r\n\t\t \t\t\t{$page_id},\t\t \r\n\t\t \t\t\t" . CGlobal::$curCategory . ", \t\t \r\n\t\t \t\t\t{$item_id}, \t \r\n\t\t \t\t\t{$user_id} ,\t\t\r\n\t\t \t\t\t'{$user_name}' ,\t\t\r\n\t\t \t\t\t{$login_type} ,\t\t\r\n\t\t \t\t\t'{$open_id}')"; } DB::query($sql, __LINE__ . __FILE__); if (User::is_login() && MEMCACHE_ON) { $user = User::$current->data; if ($user && !isset($user['last_login']) || isset($user['last_login']) && $user['last_login'] < TIME_NOW - 300) { DB::query("UPDATE user SET last_login="******" WHERE id={$user['id']}"); $user_memcache = AZMemcache::do_get("user:{$user['id']}"); if ($user_memcache) { $user_memcache['last_login'] = TIME_NOW; AZMemcache::do_put("user:{$user['id']}", $user_memcache); } } } if (StaticCache::notExistCache('del_exs', 1)) { //Run 1 cronjob/15s StaticCache::startCache(); StaticCache::endCache(); DB::query("DELETE FROM " . _SESS_TABLE . " WHERE session_expires <= " . (time() - _SESS_TIME_EXPIRE)); } }
static function get_list_ban_ip() { $list_ip = array(); if (MEMCACHE_ON) { $list_ip = AZMemcache::do_get('list_ban_ip'); } if (!$list_ip) { $sql = "select * from ban_ip"; $list_ip_temp = DB::fetch_all_array($sql); foreach ($list_ip_temp as $value) { $list_ip[$value['ip']] = $value; } } return $list_ip; }
function lockItemWhenLockAccount($value = array(), $is_lock = 1) { // $is_lock = 1: lock, $is_lock = 0: Unlock $user_id = $value["user_id"]; $reason_invalid = isset($value["reason_invalid"]) ? $value["reason_invalid"] : ""; if ($user_id) { $user = User::getUser($user_id); } if ($is_lock == 0 && User::have_permit(array(ADMIN_USER))) { $sql = 'SELECT id, admin_id, time FROM user_lock WHERE user_id = ' . $user_id . ' AND type = 0 ORDER BY id DESC LIMIT 1'; $user_invalid = DB::fetch($sql); if (isset($user_invalid["id"])) { $sql = "SELECT * FROM item WHERE user_id = {$user_id} AND state = 1"; $re = DB::query($sql); while ($item = mysql_fetch_assoc($re)) { $sql = "SELECT user_id, lock_time FROM item_lock WHERE item_id = {$item['id']} ORDER BY id DESC LIMIT 1"; $re_lock = DB::query($sql); $item_lock = mysql_fetch_assoc($re_lock); if ($item_lock["lock_time"] == $user_invalid["time"] && $item_lock["user_id"] == $user_invalid["admin_id"]) { if (MEMCACHE_ON) { $item_memcache = AZMemcache::do_get("item:{$item['id']}"); $item_memcache['state'] = 0; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } DB::update('item', array('state' => 0), "id={$item['id']}"); } } } } elseif ($is_lock == 1) { // chi thuc hien voi khoa theo ngay $sql_item = 'SELECT id FROM item WHERE user_id = ' . $user_id . ' AND status = 1 AND state=0'; $re_item = DB::query($sql_item); while ($item = mysql_fetch_assoc($re_item)) { $sql_insert = "INSERT INTO item_lock (item_id, user_id \t,user_name, lock_time, reason_lock) VALUES ({$item['id']}," . User::id() . ",'" . User::user_name() . "'," . TIME_NOW . ",'" . $reason_invalid . "')"; DB::query($sql_insert); } if (MEMCACHE_ON) { $sql = "SELECT * FROM item WHERE user_id = {$user_id} AND status = 1"; $re = DB::query($sql); while ($item_memcache = mysql_fetch_assoc($re)) { $item_memcache['state'] = 1; AZMemcache::do_put("item:" . $item_memcache['id'], $item_memcache); } } DB::update('item', array('state' => "1"), 'user_id = ' . $user_id . ' AND status = 1'); $receiver_user = User::getUser($user_id); $link_help = 'http://help.enbac.com/index.php/Quy_%C4%91%E1%BB%8Bnh_%C4%91%C4%83ng_tin'; $title_pm = 'Thông báo từ EnBac'; $content_pm = 'Tất cả tin đăng của bạn đã bị khóa với lý do: ' . $reason_invalid . ' Đề nghị bạn hãy thực hiện đúng các quy định của Én Bạc. Xin cảm ơn bạn. Vui lòng không trả lời tin nhắn này!'; AZLib::Send_pm(User::id(), User::user_name(), $receiver_user, $title_pm, $content_pm, true); } }
function update_notify_read() { $total_new_comment = 0; $total_comment_user = 0; $total_pm = 0; $item_ids_ar = Url::get('item_ids_ar', ''); $item_ids_ar2 = Url::get('item_ids_ar2', ''); $c_user_ids_ar = Url::get('c_user_ids_ar', ''); $pm_ids_ar = Url::get('pm_ids_ar', ''); if ($item_ids_ar) { //Mảng item_id cập nhật bỏ qua cho các feed chủ thể tương ứng khi giao dịch bị xoá hoặc khoá! $item_ids = explode(',', $item_ids_ar); DB::query("UPDATE comment SET status=1 WHERE item_id IN({$item_ids_ar})"); $total_new_comment -= count($item_ids); } if ($item_ids_ar2) { //Mảng item_id cập nhật bỏ qua cho các feed khách thể tương ứng khi giao dịch bị xoá hoặc khoá! $item_ids = explode(',', $item_ids_ar2); DB::query("UPDATE comment SET replied_status=1 WHERE item_id IN({$item_ids_ar2})"); $total_new_comment += count($item_ids); } if ($c_user_ids_ar) { $u_user_ids = explode(',', $c_user_ids_ar); DB::query("UPDATE comment_user SET status=1 WHERE id IN({$c_user_ids_ar})"); $total_comment_user += count($u_user_ids); } if ($pm_ids_ar) { $pm_ids = explode(',', $pm_ids_ar); DB::query("UPDATE message_topics SET mt_read=1 WHERE mt_id IN({$pm_ids_ar})"); $total_pm += count($pm_ids); } if ($unread_feed_ids != '' && $unread_feed_ids != 0) { DB::query("UPDATE feed SET status=1 WHERE id IN({$unread_feed_ids})"); } if ($total_new_comment || $total_comment_user || $total_pm) { $update_sql = ""; if ($item_comment_ids) { //$total_new_comment = User::$current->data['total_new_comment'] - $total_new_comment; //$total_new_comment = DB::fetch("SELECT count(*) AS total_feed FROM feed WHERE user_id = ".User::id()." AND type IN(1,2) AND status=0 AND time>".(TIME_NOW-15*24*3600),'total_feed',0); //$total_new_comment = DB::fetch("SELECT count(*) AS total_feed FROM comment WHERE receiver_user_id = ".User::id()." AND mt_read=0 AND mt_vid_folder='inbox' AND mt_date>".(TIME_NOW-15*24*3600),'total_feed',0); //$update_sql.="total_new_comment=$total_new_comment"; $total_new_comment = 0; $update_sql .= "total_new_comment={$total_new_comment}"; } if ($total_comment_user) { //$total_comment_user = User::$current->data['total_comment_user'] - $total_comment_user; //$total_comment_user = DB::fetch("SELECT count(*) AS total_feed FROM feed WHERE user_id = ".User::id()." AND type = 3 AND status=0 AND time>".(TIME_NOW-15*24*3600),'total_feed',0); $total_comment_user = DB::fetch("SELECT count(*) AS total_feed FROM comment_user WHERE receiver_user_id = " . User::id() . " AND status=0 AND sender_user_id != " . User::id() . " AND time>" . (TIME_NOW - 15 * 24 * 3600), 'total_feed', 0); $update_sql .= ($update_sql != '' ? ', ' : '') . "total_comment_user={$total_comment_user}"; } if ($total_pm) { //$total_pm = User::$current->data['total_pm'] - $total_pm; //$total_pm = DB::fetch("SELECT count(*) AS total_feed FROM feed WHERE user_id = ".User::id()." AND type = 4 AND status=0 AND time>".(TIME_NOW-15*24*3600),'total_feed',0); $total_pm = DB::fetch("SELECT count(*) AS total_feed FROM message_topics WHERE mt_owner_id = " . User::id() . " AND mt_read=0 AND mt_vid_folder='inbox' AND mt_date>" . (TIME_NOW - 15 * 24 * 3600), 'total_feed', 0); $update_sql .= ($update_sql != '' ? ', ' : '') . "total_pm={$total_pm}"; } if ($update_sql != '') { DB::query("UPDATE user SET {$update_sql} WHERE id=" . User::id()); if (MEMCACHE_ON) { $user_memcache = AZMemcache::do_get("user:"******"user:" . User::id(), $user_memcache); } } else { User::getUser(User::id(), 0, 1); } } } echo 'success'; exit; }
function on_submit() { if (Url::get('item_update') == 'Cập nhật') { $name_arr = $_POST['names']; $sku_arr = $_POST['skus']; $offer_arr = $_POST['offers']; $list_brief_arr = $_POST['list_briefs']; $price_arr = $_POST['prices']; $price_out_arr = $_POST['price_outs']; $currency_id_arr = $_POST['currency_ids']; $quantity_arr = $_POST['quantitys']; $item_order_arr = $_POST['item_orders']; $made_in_arr = $_POST['made_ins']; $warranty_arr = $_POST['warrantys']; $sql = array(); foreach ($price_arr as $id => $price) { if (strlen($name_arr[$id]) < 1) { $this->setFormError("name" . $id, "Tên sản phẩm có mã " . $id . " phải có độ dài từ 1 ký tự trở lên !"); return; } if (URL::cdouble($price_arr[$id]) < 0) { $this->setFormError("price" . $id, "Đơn giá sản phẩm có mã " . $id . " phải là giá trị >=0 !"); return; } if (URL::cdouble($price_out_arr[$id]) < 0) { $this->setFormError("price_out" . $id, "Giá thị trường sản phẩm có mã " . $id . " phải là giá trị >=0 !"); return; } $sql[] = "UPDATE item SET name='" . addslashes($name_arr[$id]) . "' ,sku='" . addslashes($sku_arr[$id]) . "' ,list_brief='" . addslashes($list_brief_arr[$id]) . "' ,offer='" . addslashes($offer_arr[$id]) . "' ,\r\n\t\t\t\t\t\t\t\t\t\tprice='" . URL::cdouble($price_arr[$id]) . "' ,price_out='" . URL::cdouble($price_out_arr[$id]) . "', \r\n\t\t\t\t\t\t\t\t\t\tcurrency_id=" . (int) $currency_id_arr[$id] . " , quantity=" . (int) $quantity_arr[$id] . " ,`item_order`='" . (int) $item_order_arr[$id] . "',`warranty`='" . $warranty_arr[$id] . "',`made_in`='" . $made_in_arr[$id] . "' , \r\n\t\t\t\t\t\t\t\t\t\tmodify_time=" . TIME_NOW . ", modify_user_name='" . User::user_name() . "' WHERE id=" . $id; } foreach ($sql as $query) { DB::query($query, __LINE__ . __FILE__); } Url::redirect_url(Url::build_all(array('cmd'))); } if (Url::get('cmd') == 'move_content') { $str_ids = trim(AZLib::getParam('product_item'), ','); $catid = (int) Url::get('id_cats', 0); if ($catid != 0 && $str_ids) { $result = DB::fetch("SELECT parent_id FROM category WHERE id={$catid}"); $parent_id = $result['parent_id']; $l1_id = 0; $l2_id = 0; if ($parent_id) { $result = DB::fetch("SELECT parent_id FROM category WHERE id={$parent_id}"); $l1_id = $parent_id; $l2_id = $catid; $sql = 'UPDATE item SET category_id= ' . $catid . ',level_1_catid = ' . $parent_id . ' ,level_2_catid = ' . $catid . ' WHERE id IN(' . $str_ids . ')'; } else { $l1_id = $catid; $l2_id = 0; $sql = 'UPDATE item SET category_id= ' . $catid . ',level_1_catid = ' . $catid . ',level_2_catid = 0 WHERE id IN(' . $str_ids . ')'; } DB::query($sql); if (MEMCACHE_ON) { $arr = explode(',', $str_ids); if ($arr) { foreach ($arr as $item_id) { $item_memcache = AZMemcache::do_get("item:{$item_id}"); if ($item_memcache) { $item_memcache['category_id'] = $catid; $item_memcache['level_1_catid'] = $l1_id; $item_memcache['level_2_catid'] = $l2_id; AZMemcache::do_put("item:{$item_id}", $item_memcache); } } } } } Url::redirect_url(Url::build_all(array('cmd'))); } if (Url::get('cmd') == 'delete_item') { if (isset($_REQUEST['selected_ids'])) { $this->delete_multi($_REQUEST['selected_ids']); } else { if (isset($_REQUEST['product_item'])) { $product_item = array(0 => $_REQUEST['product_item']); $this->delete_multi($product_item); } } } }
static function getUser($user_id, $update_cache = FALSE, $delcache = FALSE) { $user = array(); if ($user_id) { if (MEMCACHE_ON) { if ($delcache) { //Xoá cache if (MEMCACHE_ON) { AZMemcache::do_remove("user:{$user_id}"); } return TRUE; } else { if (!$update_cache && MEMCACHE_ON) { $user = AZMemcache::do_get("user:{$user_id}"); } if (!$user) { $sql = "SELECT * FROM user WHERE id=" . (int) $user_id . " LIMIT 1"; $user = mysql_fetch_assoc(DB::query($sql)); $user['is_block'] = $user['block_time'] > TIME_NOW || $user['block_time'] == -1 ? TRUE : FALSE; if (MEMCACHE_ON && $user) { AZMemcache::do_put("user:{$user_id}", $user); } } } } else { //cache file $subDir = 'user/' . floor($user_id / 1000); $user = AZCache::cache('SELECT * FROM user WHERE id=' . (int) $user_id . ' LIMIT 0,1', __LINE__ . __FILE__, 2592000, $update_cache, '', $subDir, $delcache); if ($user && !$delcache) { $user[0]['is_block'] = $user[0]['block_time'] > TIME_NOW || $user[0]['block_time'] == -1 ? TRUE : FALSE; return $user[0]; } } } return $user; }
static function get() { if (isset($_GET['delcache']) && (int) $_GET['delcache'] == 1) { self::auto_delete(self::_my_file()); return false; } if (MEMCACHE_ON) { $arr = AZMemcache::do_get("qcache:" . self::_my_file()); if ($arr !== false) { return $arr; } } else { $cfile = DIR_CACHE . 'db/' . self::_my_file(); if (file_exists($cfile)) { self::$createdTime = filemtime($cfile); if (self::$expire > 0 && TIME_NOW < self::$createdTime + self::$expire || self::$expire == 0) { return unserialize(stripslashes(@file_get_contents($cfile))); } } } return false; }
function process_description($item_detail) { if (!isset($item_detail["filter_des"]) || $item_detail["filter_des"] == "") { ################################################################################################################################ //$filter_des = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['description'])); $filter_des = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['description'], ENT_QUOTES, "UTF-8")); $filter_des = preg_replace('#(<[/]?iframe.*>.*</iframe>)#iU', '', $filter_des); //$filter_des = preg_replace('#(<[/]?script.*>.*</script>)#iU', '', $filter_des); //$filter_des = preg_replace('#(<[/]?style.*>.*</style>)#iU', '', $filter_des); //Loại bỏ thẻ CDATA // <![CDATA[ //window.location='http://otothegioi.vn/raovat/HOT/Honda%20Accord%202.0%20Model%202011/re.html'; // ]]> //$filter_des = str_replace(array('<![CDATA[',']]>'), "", $filter_des); //$filter_des = str_replace(array('window.location'), "", $filter_des); //TuanNK edit 2010.08.17 //$filter_des = str_replace(array('>','<'), array(">","<"), $filter_des); $filter_des = strip_tags($filter_des, '<p><a><span><table><tr><td><th><br><strong><b><i><em><li><ol><ul><hr><u><font><strike>'); $filter_des = preg_replace("/\\[([\\s]*[0-9]{1,2}|100[\\s]*)\\]/eis", "\$this->embeded('\$1')", $filter_des); $filter_des = preg_replace('/<a[\\s]*(.*)[\\s]*href=[\'"](.*)[\'"][\\s]*[^>]*[\\s]*>(.*)<\\/a>/eisU', "\$this->filter_link('\$2','\$3')", $filter_des); ################################################################################################################################ ################################################################################################################################ $filter_brief = preg_replace('#(<[/]?img.*>)#iU', '', html_entity_decode($item_detail['brief'], ENT_QUOTES, "UTF-8")); $filter_brief = preg_replace('#(<[/]?iframe.*>.*</iframe>)#iU', '', $filter_brief); $filter_brief = strip_tags($filter_brief, '<p><a><span><table><tr><td><th><br><strong><b><i><em><li><ol><ul><hr><u><font><strike>'); $filter_brief = preg_replace("/\\[([\\s]*[0-9]{1,2}|100[\\s]*)\\]/eis", "\$this->embeded('\$1')", $filter_brief); $filter_brief = preg_replace('/<a[\\s]*(.*)[\\s]*href=[\'"](.*)[\'"][\\s]*[^>]*[\\s]*>(.*)<\\/a>/eisU', "\$this->filter_link('\$2','\$3')", $filter_brief); ################################################################################################################################ if (MEMCACHE_ON) { $item_memcache = AZMemcache::do_get("item:{$item_detail["id"]}"); $item_memcache["filter_brief"] = $filter_brief; $item_memcache["filter_des"] = $filter_des; AZMemcache::do_put("item:{$item_detail["id"]}", $item_memcache); } return array('filter_brief' => $filter_brief, 'filter_des' => $filter_des); } else { return array('filter_brief' => $item_detail["filter_brief"], 'filter_des' => $item_detail["filter_des"]); } }
/** * Write the session * @param int session id * @param string data of the session */ function write($session_id, $data) { $page = ''; $page_id = 0; $user_id = isset($_SESSION['user_id']) ? (int) $_SESSION['user_id'] : 0; $user_name = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 0; $login_type = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? 1 : 0; $open_id = isset($_SESSION['openid_url']) && $_SESSION['openid_url'] != '' ? $_SESSION['openid_url'] : ''; if (class_exists('AZNet')) { $page = AZNet::$page['name']; $page_id = (int) AZNet::$page['id']; } if (($page == 'ItemDetail' || $page == 'item_detail') && isset($_GET['id']) && $_GET['id']) { $item_id = (int) $_GET['id']; } else { $item_id = 0; } if (in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = ''; } else { AZLib::check_uri(); $ref_url = CGlobal::$query_string; } if ($this->data) { if ($ref_url == '' || in_array(basename($_SERVER['PHP_SELF']), array('ebxml.php', 'ajax.php', 'captcha.php'))) { $ref_url = stripslashes($this->data['session_referer']); } if (!$page) { $page = $this->data['page']; } if (!$page_id) { $page_id = (int) $this->data['page_id']; } if (!$item_id) { $item_id = (int) $this->data['item_id']; } $sql = "UPDATE " . _SESS_TABLE . " SET\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_expires = " . TIME_NOW . ", \r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_data \t= '{$data}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_referer = '" . addslashes($ref_url) . "',\r\n\t\t\t\t\t\t\t\t\t\t\t \tsession_ip \t\t= '" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "', \r\n\t\t\t\t\t\t\t\t\t\t\t \tpage \t\t\t= '{$page}',\t\r\n\t\t\t\t\t\t\t\t\t\t\t \tpage_id \t\t= {$page_id},\r\n\t\t\t\t\t\t\t\t\t\t\t \tcategory_id \t= " . CGlobal::$curCategory . ",\r\n\t\t\t\t\t\t\t\t\t\t\t \titem_id \t\t= {$item_id},\r\n\t\t\t\t\t\t\t\t\t\t\t \tuser_id \t\t= '{$user_id}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tuser_name\t\t= '{$user_name}',\r\n\t\t\t\t\t\t\t\t\t\t\t \tlogin_type\t\t= '{$login_type}',\r\n\t\t\t\t\t\t\t\t\t\t\t \topen_id\t\t\t= '{$open_id}'\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE session_id \t= '{$session_id}'"; } else { $sql = "INSERT INTO " . _SESS_TABLE . " \r\n \t\t\t\t\t\t (\r\n \t\t\t\t\t\t \tsession_id, \r\n \t\t\t\t\t\t \tsession_expires, \r\n \t\t\t\t\t\t \tsession_data, \r\n \t\t\t\t\t\t \tsession_referer, \r\n \t\t\t\t\t\t \tsession_ip, \r\n \t\t\t\t\t\t \tpage, \r\n \t\t\t\t\t\t \tpage_id, \r\n \t\t\t\t\t\t \tcategory_id, \r\n \t\t\t\t\t\t \titem_id, \r\n \t\t\t\t\t\t \tuser_id, \r\n \t\t\t\t\t\t \tuser_name,\r\n\t\t\t\t\t\t\t \tlogin_type,\r\n\t\t\t\t\t\t\t \topen_id\r\n \t\t\t\t\t\t \t) \r\n VALUES (\r\n \t\t\t'{$session_id}', \t\t\t\t\r\n \t\t\t" . TIME_NOW . ", \t\t\t\r\n \t\t\t'{$data}', \t\t\t \r\n \t\t\t'" . addslashes($ref_url) . "', \t \r\n \t\t\t'" . $_SERVER['SERVER_ADDR'] . '::' . $_SERVER['REMOTE_ADDR'] . "',\t\r\n \t\t\t'{$page}',\t \r\n \t\t\t{$page_id},\t\t \r\n \t\t\t" . CGlobal::$curCategory . ", \t\t \r\n \t\t\t{$item_id}, \t \r\n \t\t\t{$user_id} ,\t\t\r\n \t\t\t'{$user_name}',\t\t\r\n\t \t\t\t{$login_type} ,\t\t\r\n\t \t\t\t'{$open_id}')"; } $this->query($sql, __LINE__ . __FILE__); if (User::is_login() && MEMCACHE_ON) { //Nếu đã đăng nhập $user = User::$current->data; if ($user && !isset($user['last_login']) || isset($user['last_login']) && $user['last_login'] < TIME_NOW - 300) { DB::query("UPDATE user SET last_login="******" WHERE id={$user['id']}"); $user_memcache = AZMemcache::do_get("user:{$user['id']}"); if ($user_memcache) { $user_memcache['last_login'] = TIME_NOW; AZMemcache::do_put("user:{$user['id']}", $user_memcache); } } } if ($this->effect_rows) { //if row was created, return true return true; } return false; //an unknown error occured }
static function get_item($item_id, $delcache = 0) { $item = array(); if ($item_id) { if ($delcache) { //Xoá cache if (MEMCACHE_ON) { AZMemcache::do_remove("item:{$item_id}"); } return true; } else { if (MEMCACHE_ON) { $item = AZMemcache::do_get("item:{$item_id}"); } if (!$item || isset($_GET['delcache']) && $_GET['delcache'] == 1) { //Nếu item chưa đc cache thì lấy từ db ra $sql = "SELECT * FROM item\tWHERE \tid={$item_id}"; $item = mysql_fetch_assoc(DB::query($sql)); if (MEMCACHE_ON && $item) { AZMemcache::do_put("item:{$item_id}", $item); } } } } return $item; }
static function notExistCache($filePath, $exp_time = 0, $handleContent = false, $subDir = '') { self::$curentContent = ''; self::$handleContent = $handleContent; if (!CACHE_ON) { //Nếu tắt chế độ cache return true; } if (MEMCACHE_ON) { //Nếu bật chế độ mem_cache if ($subDir != '') { $filePath = $subDir . '/' . $filePath; } self::$curentCacheFilePath = $filePath; self::$curentExpTime = $exp_time; if (isset($_GET['delscache']) && (int) $_GET['delscache'] == '1') { self::delCache($filePath); return true; } $s_content = AZMemcache::do_get("scache:{$filePath}"); if ($s_content !== false) { if (DEBUG) { self::$cNum++; self::$pNum++; if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } $info = "<b>" . $module_name . "</b><br /><font color=red><b>" . self::$curentCacheFilePath . "</b></font><br /><b>Cache Time:</b> " . $exp_time . "s "; if ($exp_time > 0) { $info .= "<b> Expire:</b> {$exp_time} sec"; } else { $info .= "<b> Expire:</b> forever"; } self::$cacheFilesList .= "<li>" . $info . "</li>"; } if (self::$handleContent) { self::$curentContent = $s_content; } else { echo $s_content; } return false; } } else { if ($subDir != '') { AZLib::CheckDir(DIR_CACHE . 'html/' . $subDir . '/', MEMCACHE_ON); $filePath = $subDir . '/' . $filePath; } else { AZLib::CheckDir(DIR_CACHE . 'html/', MEMCACHE_ON); } self::$curentCacheFilePath = DIR_CACHE . 'html/' . $filePath . '.html'; self::$curentExpTime = $exp_time; if (isset($_GET['delscache']) && (int) $_GET['delscache'] == '1') { self::delCache($filePath); return true; } if (file_exists(self::$curentCacheFilePath)) { if ($exp_time > 0) { $filemtime = filemtime(self::$curentCacheFilePath); if (TIME_NOW > $filemtime + $exp_time) { return true; } } else { $filemtime = 0; } if (DEBUG) { self::$cNum++; self::$pNum++; if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } $info = "<b>" . $module_name . "</b><br /><font color=red><b>" . self::$curentCacheFilePath . "</b></font><br /><b>Cache Time:</b> " . $exp_time . "s "; $info .= "<b>Created:</b> " . date('d/m/Y H:i:s', $filemtime); if ($exp_time > 0) { $info .= "<b> Expire:</b> " . date('d/m/Y H:i:s', TIME_NOW + $exp_time); } else { $info .= "<b> Expire:</b> forever"; } self::$cacheFilesList .= "<li>" . $info . "</li>"; } if (self::$handleContent) { self::$curentContent = file_get_contents(self::$curentCacheFilePath); } else { echo file_get_contents(self::$curentCacheFilePath); } return false; } } return true; }