function &cache_server()
{
    import('cache.lib');
    static $CS = null;
    if ($CS === null) {
        switch (CACHE_SERVER) {
            case 'memcached':
                $CS = new MemcacheServer(array('host' => MEMCACHE_HOST, 'port' => MEMCACHE_PORT));
                break;
            default:
                $CS = new PhpCacheServer();
                //TODO:根据语言,使用不同的cachedir
                $temp_dir = ROOT_PATH . '/temp/caches/' . trim(LANG);
                $CS->set_cache_dir($temp_dir);
                if (!is_dir($temp_dir)) {
                    ecm_mkdir($temp_dir);
                }
                break;
        }
    }
    return $CS;
}
Beispiel #2
0
 function _get_cache_path($key)
 {
     $dir = str_pad(abs(crc32($key)) % CACHE_DIR_NUM, 4, '0', STR_PAD_LEFT);
     ecm_mkdir($this->_cache_dir . '/' . $dir);
     return $this->_cache_dir . '/' . $dir . '/' . $this->_get_file_name($key);
 }
Beispiel #3
0
 function save_cache($id)
 {
     $file_path = ROOT_PATH . '/temp/js/datacallcache' . $id . '.js';
     ecm_mkdir(dirname($file_path));
     file_put_contents($file_path, "{$this->charset}|{$this->_expires}%^@#!*" . $this->_doc_contents);
 }
Beispiel #4
0
 /**
  *    数据库备份
  *
  *    @author    Hyber
  *    @return    void
  */
 function backup()
 {
     /* ECMall需要备份的表 */
     $all_tables = $this->db->getAll("show tables LIKE '" . $this->_mysql_like_quote(DB_PREFIX) . "%'");
     $tables = array();
     //备份队列
     foreach ($all_tables as $key => $table) {
         $tables[current($table)] = -1;
     }
     if (!IS_POST) {
         $allow_max_size = $this->_return_bytes(@ini_get('upload_max_filesize')) / 1024;
         //单位为KB;
         $this->assign('vol_size', $allow_max_size);
         $this->assign('backup_name', $this->_make_backup_name());
         $this->assign('tables', $tables);
         $this->display('db.backup.html');
     } else {
         $exp_tables = array();
         //用户选择要备份的队列
         isset($_POST['backup_type']) && $_POST['backup_type'] == 'backup_all' && ($exp_tables = $tables);
         isset($_POST['backup_type']) && $_POST['backup_type'] == 'backup_custom' && ($exp_tables = $_POST['tables']);
         $vol_size = isset($_POST['vol_size']) ? intval($_POST['vol_size']) : 0;
         //分卷大小
         $ext_insert = isset($_POST['ext_insert']) ? intval($_POST['ext_insert']) : 0;
         $backup_name = isset($_POST['backup_name']) ? trim($_POST['backup_name']) : '';
         if ($ext_insert) {
             $this->ext_insert = true;
         }
         if (!$exp_tables) {
             $this->show_warning('no_table_selected');
             return;
         }
         if ($vol_size < $this->min_vol_size) {
             $this->show_warning(sprintf(Lang::get('invalid_vol_size'), $this->min_vol_size));
             return;
         }
         if (!$backup_name) {
             $this->show_warning('no_backup_name');
             return;
         }
         if (!preg_match("/^[\\w]{" . $this->limit_backup_name . "}\$/", $backup_name)) {
             $limit_arr = explode(',', $this->limit_backup_name);
             $this->show_warning(sprintf(Lang::get('invalid_backup_name'), $limit_arr[0], $limit_arr[1]));
             return;
         }
         $this->backup_name = $backup_name;
         if (is_dir($this->backup_path . $this->backup_name)) {
             $this->show_warning('backup_name_exist');
             return;
         }
         ecm_mkdir(ROOT_PATH . '/data/' . $this->backup_dir . '/' . $this->backup_name);
         if (!file_exists($this->backup_path . $this->backup_name . '/queue.log')) {
             /*加入需要导出的数据表队列,写入文件*/
             $this->_put_queue($exp_tables);
         }
         /*开始备份*/
         $tables = $this->_dump_queue(1, $vol_size * 1024);
         if ($tables === false) {
             $this->show_warning('invalid_queue_file');
             return;
         }
         $this->_deal_result($tables, 1, $vol_size);
     }
 }
 function remote_image()
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(SIZE_GOODS_IMAGE);
     // 2M
     $upload_mod =& m('uploadedfile');
     /* 取得剩余空间(单位:字节),false表示不限制 */
     $store_mod =& m('store');
     $settings = $store_mod->get_settings($this->store_id);
     $remain = $settings['space_limit'] > 0 ? $settings['space_limit'] * 1024 * 1024 - $upload_mod->get_file_size($this->store_id) : false;
     $uploader->root_dir(ROOT_PATH);
     $dirname = '';
     $remote_url = trim($_POST['remote_url']);
     if (!empty($remote_url)) {
         if (preg_match("/^(http:\\/\\/){1,1}.+(gif|png|jpeg|jpg){1,1}\$/i", $remote_url)) {
             $result = $this->url_exist($remote_url, 2097152, $remain);
             if ($result === 1) {
                 $this->view_remote();
                 $res = Lang::get("url_invalid");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 2) {
                 $this->view_remote();
                 $res = Lang::get("not_allowed_size");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 3) {
                 $this->view_remote();
                 $res = Lang::get("space_limit_arrived");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             $img_url = _at('file_get_contents', $remote_url);
             $dirname = '';
             if ($this->belong == BELONG_GOODS) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200;
             } elseif ($this->belong == BELONG_STORE) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other';
             } elseif ($this->belong == BELONG_ARTICLE) {
                 $dirname = 'data/files/mall/store_' . $this->visitor->get('manage_store') . '/article';
             }
             $filename = $uploader->random_filename();
             $new_url = $dirname . '/' . $filename . '.' . substr($remote_url, strrpos($remote_url, '.') + 1);
             ecm_mkdir(ROOT_PATH . '/' . $dirname);
             $fp = _at('fopen', ROOT_PATH . '/' . $new_url, "w");
             _at('fwrite', $fp, $img_url);
             _at('fclose', $fp);
             if (!file_exists(ROOT_PATH . '/' . $new_url)) {
                 $this->view_remote();
                 $res = Lang::get("system_error");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             /* 处理文件入库 */
             $data = array('store_id' => $this->store_id, 'file_type' => $this->_return_mimetype(ROOT_PATH . '/' . $new_url), 'file_size' => filesize(ROOT_PATH . '/' . $new_url), 'file_name' => substr($remote_url, strrpos($remote_url, '/') + 1), 'file_path' => $new_url, 'belong' => $this->belong, 'item_id' => $this->id, 'add_time' => gmtime());
             $file_id = $upload_mod->add($data);
             if (!$file_id) {
                 $this->_error($uf_mod->get_error());
                 return false;
             }
             if ($this->instance == 'goods_image') {
                 /* 生成缩略图 */
                 $thumbnail = dirname($new_url) . '/small_' . basename($new_url);
                 make_thumb(ROOT_PATH . '/' . $new_url, ROOT_PATH . '/' . $thumbnail, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
                 /* 更新商品相册 */
                 $mod_goods_image =& m('goodsimage');
                 $goods_image = array('goods_id' => $this->id, 'image_url' => $new_url, 'thumbnail' => $thumbnail, 'sort_order' => 255, 'file_id' => $file_id);
                 if (!$mod_goods_image->add($goods_image)) {
                     $this->_error($this->mod_goods_imaged->get_error());
                     return false;
                 }
                 $data['thumbnail'] = $thumbnail;
             }
             $data['instance'] = $this->instance;
             $data['file_id'] = $file_id;
             $res = "{";
             foreach ($data as $key => $val) {
                 $res .= "\"{$key}\":\"{$val}\",";
             }
             $res = substr($res, 0, strrpos($res, ','));
             $res .= '}';
             $this->view_remote();
             echo "<script type='text/javascript'>window.parent.add_uploadedfile({$res});</script>";
         } else {
             $res = Lang::get('url_invalid');
             $this->view_remote();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
     } else {
         $res = Lang::get('remote_empty');
         $this->view_remote();
         echo "<script type='text/javascript'>alert('{$res}');</script>";
         return false;
     }
 }
Beispiel #6
0
/**
 * 写入 log 文件
 *
 * @param   string  $msg
 * @param   string  $file
 * @param   string  $line
 */
function put_log($err, $msg, $file, $line)
{
    $filename = ROOT_PATH . "/temp/logs/" . date("Ym") . ".log";
    if (!is_dir('temp/logs')) {
        ecm_mkdir(ROOT_PATH . '/' . 'temp/logs');
    }
    $handler = null;
    if (($handler = fopen($filename, 'ab+')) !== false) {
        fwrite($handler, date('r') . "\t[{$err}]{$msg}\t{$file}\t{$line}\n");
        fclose($handler);
    }
}
 /**
  *    将上传的文件移动到指定的位置
  *
  *    @author    Garbin
  *    @param     string $src
  *    @param     string $target
  *    @return    bool
  */
 function move_uploaded_file($src, $target)
 {
     $abs_path = $this->_root_dir ? $this->_root_dir . '/' . $target : $target;
     $dirname = dirname($target);
     if (!ecm_mkdir(ROOT_PATH . '/' . $dirname)) {
         $this->_error('dir_doesnt_exists');
         return false;
     }
     if (move_uploaded_file($src, $abs_path)) {
         @chmod($abs_path, 0666);
         return $target;
     } else {
         return false;
     }
 }
Beispiel #8
0
 /**
  * 编译模板函数
  *
  * @access  public
  * @param   string      $filename
  *
  * @return  sring        编译后文件地址
  */
 function make_compiled($filename)
 {
     $name = $this->compile_dir;
     $name .= '/' . basename($filename) . '.php';
     $exists = is_file($name);
     if ($this->_expires) {
         $expires = $this->_expires - $this->cache_lifetime;
     } else {
         if ($exists) {
             $filestat = @stat($name);
             $expires = $filestat['mtime'];
         } else {
             $expires = 0;
         }
     }
     $filestat = @stat($filename);
     if ($filestat['mtime'] <= $expires && !$this->force_compile) {
         if (is_file($name)) {
             $source = $this->_require($name);
             if ($source == '') {
                 $expires = 0;
             }
         } else {
             $source = '';
             $expires = 0;
         }
     }
     if ($this->force_compile || $filestat['mtime'] > $expires || 1) {
         $this->_current_file = $filename;
         $content = file_get_contents($filename);
         $source = $this->fetch_str($content);
         if (!file_exists(dirname($name))) {
             ecm_mkdir(dirname($name));
         }
         if (file_put_contents($name, $source, LOCK_EX) === false) {
             trigger_error('can\'t write:' . $name);
         }
         $source = $this->_eval($source);
     }
     return $source;
 }
Beispiel #9
0
/**
 * 利用gd库生成缩略图
 *
 * @author  weberliu
 * @param   string      $src            原图片路径
 * @param   string      $dst            缩略图保存路径
 * @param   int         $thumb_width    缩略图高度
 * @param   int         $thumb_height   缩略图高度 可选
 * @param   int         $quality        缩略图品质 100之内的正整数
 * @return  boolean     成功返回 true 失败返回 false
 */
function make_thumb($src, $dst, $thumb_width, $thumb_height = 0, $quality = 85)
{
    if (function_exists('imagejpeg')) {
        $func_imagecreate = function_exists('imagecreatetruecolor') ? 'imagecreatetruecolor' : 'imagecreate';
        $func_imagecopy = function_exists('imagecopyresampled') ? 'imagecopyresampled' : 'imagecopyresized';
        $dirpath = dirname($dst);
        if (!ecm_mkdir($dirpath, 0777)) {
            return false;
        }
        $data = getimagesize($src);
        $src_width = $data[0];
        $src_height = $data[1];
        if ($thumb_height == 0) {
            if ($src_width > $src_height) {
                $thumb_height = $src_height * $thumb_width / $src_width;
            } else {
                $thumb_height = $thumb_width;
                $thumb_width = $src_width * $thumb_height / $src_height;
            }
            $dst_x = 0;
            $dst_y = 0;
            $dst_w = $thumb_width;
            $dst_h = $thumb_height;
        } else {
            if ($src_width / $src_height > $thumb_width / $thumb_height) {
                $dst_w = $thumb_width;
                $dst_h = $dst_w * $src_height / $src_width;
                $dst_x = 0;
                $dst_y = ($thumb_height - $dst_h) / 2;
            } else {
                $dst_h = $thumb_height;
                $dst_w = $src_width * $dst_h / $src_height;
                $dst_y = 0;
                $dst_x = ($thumb_width - $dst_w) / 2;
            }
        }
        switch ($data[2]) {
            case 1:
                $im = imagecreatefromgif($src);
                break;
            case 2:
                $im = imagecreatefromjpeg($src);
                break;
            case 3:
                $im = imagecreatefrompng($src);
                break;
            default:
                trigger_error("Cannot process this picture format: " . $data['mime']);
                break;
        }
        $ni = $func_imagecreate($thumb_width, $thumb_height);
        if ($func_imagecreate == 'imagecreatetruecolor') {
            imagefill($ni, 0, 0, imagecolorallocate($ni, 255, 255, 255));
        } else {
            imagecolorallocate($ni, 255, 255, 255);
        }
        $func_imagecopy($ni, $im, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $src_width, $src_height);
        imagejpeg($ni, $dst, $quality);
        return is_file($dst) ? $dst : false;
    } else {
        trigger_error("Unable to process picture.", E_USER_ERROR);
    }
}
Beispiel #10
0
function copy_files($source, $target)
{
    if (is_dir($source)) {
        if (!file_exists($target)) {
            ecm_mkdir($target);
        }
        $dh = opendir($source);
        while (($file = readdir($dh)) !== false) {
            if ($file[0] != '.') {
                copy_files($source . '/' . $file, $target . '/' . $file);
            }
        }
        closedir($dh);
    } else {
        copy($source, $target);
        @chmod($target, 0777);
    }
}
Beispiel #11
0
 function remote_image()
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(2097152);
     // 400KB
     $upload_mod =& m('uploadedfile');
     $uploader->root_dir(ROOT_PATH);
     $dirname = '';
     $remote_url = trim($_POST['remote_url']);
     if (!empty($remote_url)) {
         if (preg_match("/^(http:\\/\\/){1,1}.+(gif|png|jpeg|jpg){1,1}\$/i", $remote_url)) {
             $result = $this->url_exist($remote_url, 2097152, 0);
             if ($result === 1) {
                 $this->view_iframe();
                 $res = Lang::get("url_invalid");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             } elseif ($result === 2) {
                 $this->view_iframe();
                 $res = Lang::get("not_allowed_size");
                 echo "<script type='text/javascript'>alert('{$res}');</script>";
                 return false;
             }
             $img_url = @file_get_contents($remote_url);
             $dirname = '';
             if ($this->belong == BELONG_GOODS) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/goods_' . time() % 200;
             } elseif ($this->belong == BELONG_STORE) {
                 $dirname = 'data/files/store_' . $this->visitor->get('manage_store') . '/other';
             } elseif ($this->belong == BELONG_ARTICLE) {
                 $dirname = 'data/files/mall/store_' . $this->visitor->get('manage_store') . '/article';
             }
             $filename = $uploader->random_filename();
             $new_url = $dirname . '/' . $filename . '.' . substr($remote_url, strrpos($remote_url, '.') + 1);
             ecm_mkdir(ROOT_PATH . '/' . $dirname);
             $fp = @fopen(ROOT_PATH . '/' . $new_url, "w");
             @fwrite($fp, $img_url);
             @fclose($fp);
             if (!file_exists(ROOT_PATH . '/' . $new_url)) {
                 $this->view_iframe();
                 $res = Lang::get("system_error");
                 echo "<script type='text/javascript'>alert({$res});</script>";
                 return false;
             }
             /* 处理文件入库 */
             $data = array('store_id' => $this->visitor->get('manage_store'), 'file_type' => filetype(ROOT_PATH . '/' . $new_url), 'file_size' => filesize(ROOT_PATH . '/' . $new_url), 'file_name' => substr($remote_url, strrpos($remote_url, '/') + 1), 'file_path' => $new_url, 'belong' => $this->belong, 'item_id' => $this->id, 'add_time' => gmtime());
             $file_id = $upload_mod->add($data);
             if (!$file_id) {
                 $this->_error($uf_mod->get_error());
                 return false;
             }
             $data['file_id'] = $file_id;
             $res = "{";
             foreach ($data as $key => $val) {
                 $res .= "\"{$key}\":\"{$val}\",";
             }
             $res = substr($res, 0, strrpos($res, ','));
             $res .= '}';
             $this->view_iframe();
             echo "<script type='text/javascript'>window.parent.add_uploadedfile({$res});</script>";
         } else {
             $res = Lang::get('url_invalid');
             $this->view_iframe();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
     } else {
         $res = Lang::get('remote_empty');
         $this->view_iframe();
         echo "<script type='text/javascript'>alert('{$res}');</script>";
         return false;
     }
 }