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