source: branches/version-2_12-dev/data/class/pages/LC_Page_ResizeImage.php @ 21764

Revision 21764, 3.7 KB checked in by shutta, 12 years ago (diff)

#1765 LC_Page_ResizeImage を2.11の構造っぽく改修

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
26
27/**
28 * リサイズイメージ のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_ResizeImage extends LC_Page_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46    }
47
48    /**
49     * Page のプロセス.
50     *
51     * @return void
52     */
53    function process() {
54        parent::process();
55        $this->action();
56        $this->sendResponse();
57    }
58
59    /**
60     * Page のAction.
61     *
62     * @return void
63     */
64    function action() {
65        $objFormParam = new SC_FormParam_Ex();
66        $this->lfInitParam($objFormParam);
67        $objFormParam->setParam($_GET);
68        $arrForm  = $objFormParam->getHashArray();
69
70        $file = NO_IMAGE_REALFILE;
71
72        // NO_IMAGE_REALFILE以外のファイル名が渡された場合、ファイル名のチェックを行う
73        if (strlen($arrForm['image']) >= 1
74            && $arrForm['image'] !== NO_IMAGE_REALFILE) {
75
76            // ファイル名が正しく、ファイルが存在する場合だけ、$fileを設定
77            if (!$this->lfCheckFileName()) {
78                GC_Utils_Ex::gfPrintLog('invalid access :resize_image.php image=' . $arrForm['image']);
79            } elseif (file_exists(IMAGE_SAVE_REALDIR . $arrForm['image'])) {
80                $file = IMAGE_SAVE_REALDIR . $arrForm['image'];
81            }
82        }
83
84        // リサイズ画像の出力
85        $this->lfOutputImage($file, $arrForm['width'], $arrForm['height']);
86    }
87
88    /**
89     * デストラクタ.
90     *
91     * @return void
92     */
93    function destroy() {
94        parent::destroy();
95    }
96
97    function lfInitParam(&$objFormParam) {
98        $objFormParam->addParam('画像ファイル名', 'image', STEXT_LEN, 'a',  array('MAX_LENGTH_CHECK'));
99        $objFormParam->addParam('画像の幅', 'width', STEXT_LEN, 'n',  array('NUM_CHECK'));
100        $objFormParam->addParam('画像の高さ', 'width', STEXT_LEN, 'n',  array('NUM_CHECK'));
101    }
102
103    /**
104     * ファイル名の形式をチェック.
105     *
106     * @return boolean 正常な形式:true 不正な形式:false
107     */
108    function lfCheckFileName() {
109        //$pattern = '|^[0-9]+_[0-9a-z]+\.[a-z]{3}$|';
110        $pattern = '|\./|';
111        $file    = trim($_GET['image']);
112        if (preg_match_all($pattern, $file, $matches)) {
113            return false;
114        } else {
115            return true;
116        }
117    }
118
119    /**
120     * 画像の出力
121     *
122     * @param string $file 画像ファイル名
123     * @param integer $width 画像の幅
124     * @param integer $height 画像の高さ
125     *
126     * @return void
127     */
128    function lfOutputImage($file, $width, $height) {
129        $objThumb = new gdthumb();
130        $objThumb->Main($file, $width, $height, '', true);
131    }
132}
Note: See TracBrowser for help on using the repository browser.