source: branches/version-2_13_0/data/class/pages/LC_Page_ResizeImage.php @ 23126

Revision 23126, 5.0 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * リサイズイメージ のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_ResizeImage extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        $this->skip_load_page_layout = true;
43        parent::init();
44    }
45
46    /**
47     * Page のプロセス.
48     *
49     * @return void
50     */
51    public function process()
52    {
53        parent::process();
54        $this->action();
55    }
56
57    /**
58     * Page のAction.
59     *
60     * @return void
61     */
62    public function action()
63    {
64        $objFormParam = new SC_FormParam_Ex();
65        $this->lfInitParam($objFormParam);
66        $objFormParam->setParam($_GET);
67        $arrErr = $objFormParam->checkError();
68        if (SC_Utils_Ex::isBlank($arrErr)) {
69
70            $arrForm  = $objFormParam->getHashArray();
71
72            // TODO: ファイル名を直接指定するような処理は避けるべき
73            // NO_IMAGE_REALFILE以外のファイル名が直接渡された場合、ファイル名のチェックを行う
74            if (strlen($arrForm['image']) >= 1 && $arrForm['image'] !== NO_IMAGE_REALFILE ) {
75                if (!$this->lfCheckFileName($arrForm['image'])) {
76                    GC_Utils_Ex::gfPrintLog('invalid access :resize_image.php image=' . $arrForm['image']);
77                }
78                $file = SC_Utils_Ex::getSaveImagePath($arrForm['image']);
79            } else {
80                // 商品画像を取得する
81                $file = $this->lfGetProductImage($arrForm);
82            }
83
84            // リサイズ画像の出力
85            $this->lfOutputImage($file, $arrForm['width'], $arrForm['height']);
86        }
87    }
88
89    public function lfInitParam(&$objFormParam)
90    {
91        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n',  array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
92        $objFormParam->addParam('商品イメージキー', 'image_key', STEXT_LEN, '',  array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
93        $objFormParam->addParam('画像ファイル名', 'image', STEXT_LEN, 'a',  array('MAX_LENGTH_CHECK'));
94        $objFormParam->addParam('画像の幅', 'width', STEXT_LEN, 'n',  array('NUM_CHECK'));
95        $objFormParam->addParam('画像の高さ', 'height', STEXT_LEN, 'n',  array('NUM_CHECK'));
96    }
97
98    /**
99     * ファイル名の形式をチェック.
100     *
101     * @deprecated 2.13.0 商品IDを渡す事を推奨
102     * @param $image
103     * @return boolean 正常な形式:true 不正な形式:false
104     */
105    public function lfCheckFileName($image)
106    {
107        $file    = trim($image);
108        if (!preg_match("/^[[:alnum:]_\.-]+$/i", $file)) {
109            return false;
110        } else {
111            return true;
112        }
113    }
114
115    /**
116     * 商品画像のパスを取得する
117     *
118     * @param $arrForm
119     * @return string 指定された商品画像のパス
120     */
121    public function lfGetProductImage($arrForm)
122    {
123        $objQuery = SC_Query_Ex::getSingletonInstance();
124        $table = 'dtb_products';
125        $col = $arrForm['image_key'];
126        $product_id = $arrForm['product_id'];
127        //指定されたカラムが存在する場合にのみ商品テーブルからファイル名を取得
128        if (SC_Helper_DB_Ex::sfColumnExists($table, $col, '', '', false)) {
129            $product_image = $objQuery->get($col, $table, 'product_id = ?', array($product_id));
130        } else {
131            GC_Utils_Ex::gfPrintLog('invalid access :resize_image.php image_key=' . $col);
132            $product_image = '';
133        }
134        // ファイル名が正しく、ファイルが存在する場合だけ、$fileを設定
135        $file = SC_Utils_Ex::getSaveImagePath($product_image);
136
137        return $file;
138    }
139
140    /**
141     * 画像の出力
142     *
143     * @param string  $file   画像ファイル名
144     * @param integer $width  画像の幅
145     * @param integer $height 画像の高さ
146     *
147     * @return void
148     */
149    public function lfOutputImage($file, $width, $height)
150    {
151        $objThumb = new gdthumb();
152        $objThumb->Main($file, $width, $height, '', true);
153    }
154}
Note: See TracBrowser for help on using the repository browser.