static function Run() { AZLib::CheckDir(PAGE_CACHE_DIR); if (isset($_REQUEST['page'])) { if ($_REQUEST['page'] == "home") { Url::redirect_url(WEB_DIR, 301); } $page_name = strtolower($_REQUEST['page']); } else { $page_name = 'home'; } AZNet::$page_cache_file = PAGE_CACHE_DIR . $page_name . '.php'; if (Url::get('refresh_page') == 1) { self::del_page_cache($page_name); } if (Url::get('refresh_page') != 1 && PAGE_CACHE_ON && file_exists(AZNet::$page_cache_file)) { require_once AZNet::$page_cache_file; } else { $re = DB::query('SELECT id, name, title, layout FROM page WHERE name="' . addslashes($page_name) . '"', __LINE__ . __FILE__); if ($re) { AZNet::$page = mysql_fetch_assoc($re); } if (!AZNet::$page) { Url::redirect_url(WEB_DIR, 301); } AZGen::PageGenerate(); } }
static function cache($sql, $call_pos = '', $expire = 3600, $update_type = 0, $key = '', $subDirCache = '', $del_cache = false) { // $update_type: // 0: auto // 1: Xoá cache ( multi server ) và tạo lại cache // 2: Tạo lại cache if (!self::is_select($sql)) { self::$result = DB::query($sql, $call_pos); return; } if ($subDirCache != '') { self::$subDir = $subDirCache; } else { self::$subDir = 'system'; } if (CACHE_ON && AZLib::CheckDir(DIR_CACHE . 'db/' . self::$subDir . '/', MEMCACHE_ON)) { self::$key = $key ? $key : md5($sql); if ($del_cache) { self::auto_delete(self::_my_file()); return true; } if ($expire < 0) { $expire = 0; } self::$expire = $expire; if ($update_type == 1) { self::auto_delete(self::_my_file()); $result = false; //$result = self::get(); } else { $result = self::get(); } if ($result === false) { $result = self::getRows($sql, $call_pos); self::set($result); } else { if (DEBUG) { if (class_exists('Module') && Module::$name != '') { $module_name = Module::$name; } else { $module_name = "-- Enbac system"; } CGlobal::$query_debug .= "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE' align='center'>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t <td style='font-size:14px' bgcolor='#EFEFEF'><span style='color:green'><b>Query cache</b> -- Module : <span style='color:red;font-weight:bold'>" . $module_name . "</span></span> " . ($call_pos ? "<br /><b>Run at:</b> {$call_pos}" : "") . "</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t <td style='font-family:courier, monaco, arial;font-size:14px;color:green'>{$sql}</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t <td style='font-size:14px' bgcolor='#EFEFEF'>[ Cache time : {$expire}s - <b>Created:</b> " . date('d/m/Y H:i:s', self::$createdTime) . "<b> Expire:</b> " . (self::$expire ? date('d/m/Y H:i:s', self::$createdTime + self::$expire) : 'forever') . " ]<br /><b>File:</b> " . DIR_CACHE . 'db/' . self::_my_file() . "</span></td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t </table><br />\n\n"; } } } else { $result = self::getRows($sql, $call_pos); } return $result; }
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; }
/** * thực thi template cho module, output trực tiếp hoặc trả về giá trị output * * @param string $template : tên template * @param string $direct_dir_path : lấy thư mục chứa template trực tiếp * @param boolean $return : false - output trực tiếp, true - trả về giá trị output */ function output($template = '', $return = false, $direct_dir_path = false) { if ($direct_dir_path) { $template_dir = $this->template_dir . $direct_dir_path . '/'; } else { if (Module::$name != '') { $template_dir = $this->template_dir . Module::$name . '/'; } else { $template_dir = $this->template_dir . $template . '/'; } } AZLib::CheckDir($template_dir); $template = $template ? $template_dir . $template . $this->cache_ext : ""; if (isset($_GET['tpl']) && $_GET['tpl'] == 1) { echo '<div style="overflow:hidden;border:1px solid red;padding:5px;margin:5px;">' . $template . '</div>'; } if ($return) { return $this->fetch($template); } else { $this->display($template); } }
function item_image_upload() { // if ((User::have_permit(ADMIN_ITEM) || User::is_mod()) && (int) Url::get('user_id', 0) && (int) Url::get('user_id', 0) != User::id()) { $user_id = (int) Url::get('user_id', 0); $user_name = ''; $user = User::getUser($user_id); if ($user) { $user_name = $user['user_name']; } } else { $user_id = User::id(); $user_name = User::user_name(); } $json['error'] = 'not_uploaded'; $json['id'] = 0; $json['image_url'] = ''; if (User::is_login()) { if (User::is_az_team() || User::level() > 0) { $upload_path = AZLib::folderUpload($user_id); if (AZLib::ftp_check_dir($upload_path, true, IMAGE_SERVER_NO)) { //Check dir for upload if (isset($_FILES['img_upload']) && !$_FILES['img_upload']['error'] && $_FILES['img_upload']['name']) { list($imagewidth, $imageheight, $imageType) = getimagesize($_FILES['img_upload']['tmp_name']); if ($imagewidth && $_FILES['img_upload']['size'] <= Item::MAX_UPLOAD_SIZE) { /* if(($imagewidth > 479)||($imageheight > 359)) { if($imagewidth > 479)//&& ($imagewidth < 1281) && ($imageheight < 1025)) { if($imageheight > 359) { */ $file_name = $_FILES['img_upload']['name']; $sourceName = $_FILES['img_upload']['tmp_name']; $file_ext = AZLib::getExtension($file_name); if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) { $img_url = $upload_path . date("YmdHis", TIME_NOW) . '_' . substr(AZLib::make_safe_name(basename(strtolower($file_name), $file_ext)), 0, 36) . $file_ext; /* $json['error'] = AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO); echo json_encode($json); exit; */ if (AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO)) { $image_id = DB::insert('item_image', array('des' => '', 'item_id' => 0, 'title' => '', 'position' => 0, 'img_server' => IMAGE_SERVER_NO, 'img_url' => $img_url, 'root_id' => 0, 'time' => TIME_NOW, 'user_id' => $user_id, 'user_name' => $user_name)); if ($image_id) { $json['id'] = $image_id; $json['img_server'] = IMAGE_SERVER_NO; $json['image_url'] = $img_url; $json['error'] = 'success'; } } } else { $json['error'] = 'ext_invalid'; //Sai định dạng file } /* } else { $json['error'] = 'height_not_allow'; } } else { $json['error'] = 'width_not_allow'; } } else { $json['error'] = 'width_n_height_not_allow'; } */ } else { $json['error'] = 'over_max_size'; //Sai định dạng file hoặc upload dung lượng quá lớn } } elseif ($_POST['url'] && $_POST['url'] != 'Hoặc Url') { $url = $_POST['url']; $tem_cache_dir = DIR_CACHE . 'user_images/'; AZLib::CheckDir($tem_cache_dir); $tem_cache_file = User::user_name() . md5($url) . '.gif'; $image_content = disguise_curl($url); if ($image_content) { if (@file_put_contents($tem_cache_dir . $tem_cache_file, $image_content)) { if (getimagesize($tem_cache_dir . $tem_cache_file) && filesize($tem_cache_dir . $tem_cache_file) <= Item::MAX_UPLOAD_SIZE) { $sourceName = $tem_cache_dir . $tem_cache_file; $img_url = $upload_path . TIME_NOW . '_' . $tem_cache_file; //$json['error'] = AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO); //echo json_encode($json); //exit; if (AZLib::ftp_image_put_file($img_url, $sourceName, IMAGE_SERVER_NO)) { $image_id = DB::insert('item_image', array('des' => '', 'item_id' => 0, 'title' => '', 'position' => 0, 'img_server' => IMAGE_SERVER_NO, 'img_url' => $img_url, 'root_id' => 0, 'time' => TIME_NOW, 'user_id' => $user_id, 'user_name' => $user_name)); if ($image_id) { $json['id'] = $image_id; $json['img_server'] = IMAGE_SERVER_NO; $json['image_url'] = $img_url; $json['url_error'] = 'success'; } else { $json['url_error'] = 'over_max_size'; } } else { $json['url_error'] = 'not_uploaded'; } } else { $json['url_error'] = 'over_max_size'; } @unlink($tem_cache_dir . $tem_cache_file); } else { $json['url_error'] = 'not_cache_file'; } } else { $json['url_error'] = 'not_get_img'; } } elseif ($_FILES['img_upload']['error'] == 1) { $json['error'] = 'over_max_size'; } } } } else { $json['error'] = 'not_login'; } echo json_encode($json); exit; }
function upload() { $json['error'] = 'not_uploaded'; $json['image_url'] = ''; if (User::is_login()) { $upload_path = DIR_CACHE . 'ad_images/'; AZLib::CheckDir($upload_path); $uploadFile = $_FILES["fast_upload"]; if (isset($uploadFile) && $uploadFile['name']) { $file_name = TIME_NOW . strtolower($uploadFile['name']); $sourceName = $uploadFile['tmp_name']; $file_ext = AZLib::getExtension($file_name); if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) { if (!$uploadFile['error']) { $newFile = $upload_path . $file_name; //$width = 300; //$height = 255; //$this->genImageFromSource($sourceName,$upload_path.$file_name,$width); include_once ROOT_PATH . 'core/ThumbImage.php'; $ThumbImage = new ThumbImage(); $ThumbImage->ThumbImageWithBackground($sourceName, $file_name, 300); // Tạo cache đã resize cho ảnh quảng cáo // Upload lên server ảnh, fix lỗi không tìm thấy file cache với server load balancing $img_path = 'upnew/cpc/'; AZLib::ftp_image_put_file($img_path . $file_name, $newFile, IMAGE_SERVER_NO); $img_url = $img_path . $file_name; $json['image_domain'] = 'http://' . CGlobal::$img_server[IMAGE_SERVER_NO]; $json['image_url'] = $img_url; $json['error'] = 'success'; } elseif ($uploadFile['error'] == 1) { $json['error'] = 'over_max_size'; } } else { $json['error'] = 'ext_invalid'; //Sai định dạng file } } else { $json['error'] = 'destination_not_exist'; } } else { $json['error'] = 'not_login'; } echo json_encode($json); exit; }
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; }