Beispiel #1
0
 static function Run()
 {
     EClassApi::CheckDir(PAGE_CACHE_DIR);
     if (isset($_REQUEST['page']) && $_REQUEST['page'] != '') {
         if ($_REQUEST['page'] == "home") {
             Url::redirect_url(WEB_DIR, 301);
         }
         $page_name = strtolower($_REQUEST['page']);
     } else {
         //echo $_COOKIE['lang'];die();
         $page_name = 'home';
     }
     EClass::$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(EClass::$page_cache_file)) {
         require_once EClass::$page_cache_file;
     } else {
         $re = DB::query('SELECT id, name, title, layout  FROM page WHERE name="' . addslashes($page_name) . '"', __LINE__ . __FILE__);
         if ($re) {
             EClass::$page = mysql_fetch_assoc($re);
         }
         if (!EClass::$page) {
             Url::redirect_url(WEB_DIR, 301);
         }
         require_once ROOT_PATH . 'core/EClassGen.php';
         EClassGen::PageGenerate();
     }
 }
Beispiel #2
0
 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 && EClassApi::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'>\n\t\t\t\t\t\t\t\t<tr>\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>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t <td style='font-family:courier, monaco, arial;font-size:14px;color:green'>{$sql}</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\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>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t       </table><br />\n\n";
             }
         }
     } else {
         $result = self::getRows($sql, $call_pos);
     }
     return $result;
 }
Beispiel #3
0
 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 = eb_memcache::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 (EClassApi::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;
 }
Beispiel #4
0
 function output($template = '', $return = false, $direct_dir_path = false)
 {
     if ($direct_dir_path) {
         if ($this->templateAdvance && file_exists(DIR_MODULE . Module::$name . '/templates/' . $direct_dir_path . $template . $this->cache_ext)) {
             $this->template_dir = DIR_MODULE . Module::$name . '/templates/';
             $template_dir = $this->template_dir;
         } else {
             $this->template_dir = ROOT_PATH . "templates/";
             if (CGlobal::$adminRegion) {
                 if (file_exists($this->template_dir . CGlobal::$adminTemplate . $direct_dir_path . '/' . $template . $this->cache_ext)) {
                     $template_dir = $this->template_dir . CGlobal::$adminTemplate . $direct_dir_path . '/';
                 } elseif (file_exists($this->template_dir . 'default/' . Module::$name . '/' . $template . $this->cache_ext)) {
                     $template_dir = $this->template_dir . 'default/' . Module::$name . '/';
                 } else {
                     $template_dir = $this->template_dir . $direct_dir_path . '/';
                 }
             } else {
                 if (@file_exists($this->template_dir . CGlobal::$curTemplate['folder'] . $direct_dir_path . '/' . $template . $this->cache_ext)) {
                     @($template_dir = $this->template_dir . @CGlobal::$curTemplate['folder'] . $direct_dir_path . '/');
                 } elseif (file_exists($this->template_dir . 'default/' . $direct_dir_path . '/' . $template . $this->cache_ext)) {
                     $template_dir = $this->template_dir . 'default/' . $direct_dir_path . '/';
                 } else {
                     $template_dir = $this->template_dir . $direct_dir_path . '/';
                 }
             }
         }
     } else {
         if (Module::$name != '') {
             if ($this->templateAdvance && file_exists(DIR_MODULE . Module::$name . '/templates/' . $template . $this->cache_ext)) {
                 $this->template_dir = DIR_MODULE . Module::$name . '/templates/';
                 $template_dir = $this->template_dir;
             } else {
                 $this->template_dir = ROOT_PATH . "templates/";
                 if (CGlobal::$adminRegion) {
                     if (file_exists($this->template_dir . CGlobal::$adminTemplate . Module::$name . '/' . $template . $this->cache_ext)) {
                         $template_dir = $this->template_dir . CGlobal::$adminTemplate . Module::$name . '/';
                     } elseif (file_exists($this->template_dir . 'default/' . Module::$name . '/' . $template . $this->cache_ext)) {
                         $template_dir = $this->template_dir . 'default/' . Module::$name . '/';
                     } else {
                         $template_dir = $this->template_dir . Module::$name . '/';
                     }
                 } else {
                     if (file_exists($this->template_dir . CGlobal::$curTemplate['folder'] . Module::$name . '/' . $template . $this->cache_ext)) {
                         $template_dir = $this->template_dir . CGlobal::$curTemplate['folder'] . Module::$name . '/';
                     } elseif (file_exists($this->template_dir . 'default/' . Module::$name . '/' . $template . $this->cache_ext)) {
                         $template_dir = $this->template_dir . 'default/' . Module::$name . '/';
                     } else {
                         $template_dir = $this->template_dir . Module::$name . '/';
                     }
                 }
             }
         } else {
             if (file_exists($this->template_dir . 'default/' . $template . $this->cache_ext)) {
                 $template_dir = $this->template_dir . 'default/';
             } elseif (file_exists($this->template_dir . CGlobal::$adminTemplate . $template . $this->cache_ext)) {
                 $template_dir = $this->template_dir . CGlobal::$adminTemplate;
             } else {
                 $template_dir = $this->template_dir . $template . '/';
             }
         }
     }
     $this->templateAdvance = FALSE;
     EClassApi::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);
     }
 }
Beispiel #5
0
 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 = eb_memcache::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 != '') {
             EClassApi::CheckDir(DIR_CACHE . 'html/' . $subDir . '/', MEMCACHE_ON);
             $filePath = $subDir . '/' . $filePath;
         } else {
             EClassApi::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;
 }
Beispiel #6
0
    function item_image_upload() {//
        if ((User::have_permit(ADMIN_ITEM) || User::is_mod_cat()) && (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_foodnet_team() || User::level() > 0) {
                $upload_path = EClassApi::folderUpload($user_id);

                if (EClassApi::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 = EClassApi::getExtension($file_name);

                            if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) {
                                $original_image_url = $upload_path . date("YmdHis", TIME_NOW) . '_' . substr(EClassApi::make_safe_name(basename(strtolower($file_name), $file_ext)), 0, 36) . $file_ext;
                                /* $json['error'] = EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO);
                                  echo json_encode($json);
                                  exit; */
                                if (EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO)) {
                                    $image_id = DB::insert('item_image', array(
                                                'des' => '',
                                                'item_id' => 0,
                                                'title' => '',
                                                'position' => 0,
                                                'img_server' => IMAGE_SERVER_NO,
                                                'original_image_url' => $original_image_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'] = $original_image_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/';
                        EClassApi::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;

                                    $original_image_url = $upload_path . TIME_NOW . '_' . $tem_cache_file;
                                    //$json['error'] = EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO);
                                    //echo json_encode($json);
                                    //exit;
                                    if (EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO)) {
                                        $image_id = DB::insert('item_image', array(
                                                    'des' => '',
                                                    'item_id' => 0,
                                                    'title' => '',
                                                    'position' => 0,
                                                    'img_server' => IMAGE_SERVER_NO,
                                                    'original_image_url' => $original_image_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'] = $original_image_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();
    }
Beispiel #7
0
    static function doUploadImageFromUrl($url, $upload_path = '', $prefix = '')
    {
        $tem_cache_dir = DIR_CACHE . 'upload_img_url/';
        EClassApi::CheckDir($tem_cache_dir);
        $tem_cache_file     = $prefix . md5($url) . TIME_NOW . '.png';
        $image_content      = self::disguise_curl($url);

        if ($image_content) {
            if (@file_put_contents($tem_cache_dir . $tem_cache_file, $image_content)) {
                $sourceName         = $tem_cache_dir . $tem_cache_file;
                $original_image_url = $upload_path . $tem_cache_file;
                if (EClassApi::ftp_image_put_file($original_image_url, $sourceName, IMAGE_SERVER_NO)) {
                    @unlink($sourceName);
                    return $tem_cache_file;
                }
            }
        }
        return '';
    }