| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2014 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 | 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 | /** |
|---|
| 90 | * @param SC_FormParam_Ex $objFormParam |
|---|
| 91 | */ |
|---|
| 92 | public function lfInitParam(&$objFormParam) |
|---|
| 93 | { |
|---|
| 94 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
|---|
| 95 | $objFormParam->addParam('商品イメージキー', 'image_key', STEXT_LEN, '', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK')); |
|---|
| 96 | $objFormParam->addParam('画像ファイル名', 'image', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK')); |
|---|
| 97 | $objFormParam->addParam('画像の幅', 'width', STEXT_LEN, 'n', array('NUM_CHECK')); |
|---|
| 98 | $objFormParam->addParam('画像の高さ', 'height', STEXT_LEN, 'n', array('NUM_CHECK')); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * ファイル名の形式をチェック. |
|---|
| 103 | * |
|---|
| 104 | * @deprecated 2.13.0 商品IDを渡す事を推奨 |
|---|
| 105 | * @param $image |
|---|
| 106 | * @return boolean 正常な形式:true 不正な形式:false |
|---|
| 107 | */ |
|---|
| 108 | public function lfCheckFileName($image) |
|---|
| 109 | { |
|---|
| 110 | $file = trim($image); |
|---|
| 111 | if (!preg_match("/^[[:alnum:]_\.-]+$/i", $file)) { |
|---|
| 112 | return false; |
|---|
| 113 | } else { |
|---|
| 114 | return true; |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /** |
|---|
| 119 | * 商品画像のパスを取得する |
|---|
| 120 | * |
|---|
| 121 | * @param $arrForm |
|---|
| 122 | * @return string 指定された商品画像のパス |
|---|
| 123 | */ |
|---|
| 124 | public function lfGetProductImage($arrForm) |
|---|
| 125 | { |
|---|
| 126 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
|---|
| 127 | $table = 'dtb_products'; |
|---|
| 128 | $col = $arrForm['image_key']; |
|---|
| 129 | $product_id = $arrForm['product_id']; |
|---|
| 130 | //指定されたカラムが存在する場合にのみ商品テーブルからファイル名を取得 |
|---|
| 131 | if (SC_Helper_DB_Ex::sfColumnExists($table, $col, '', '', false)) { |
|---|
| 132 | $product_image = $objQuery->get($col, $table, 'product_id = ?', array($product_id)); |
|---|
| 133 | } else { |
|---|
| 134 | GC_Utils_Ex::gfPrintLog('invalid access :resize_image.php image_key=' . $col); |
|---|
| 135 | $product_image = ''; |
|---|
| 136 | } |
|---|
| 137 | // ファイル名が正しく、ファイルが存在する場合だけ、$fileを設定 |
|---|
| 138 | $file = SC_Utils_Ex::getSaveImagePath($product_image); |
|---|
| 139 | |
|---|
| 140 | return $file; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | /** |
|---|
| 144 | * 画像の出力 |
|---|
| 145 | * |
|---|
| 146 | * @param string $file 画像ファイル名 |
|---|
| 147 | * @param integer $width 画像の幅 |
|---|
| 148 | * @param integer $height 画像の高さ |
|---|
| 149 | * |
|---|
| 150 | * @return void |
|---|
| 151 | */ |
|---|
| 152 | public function lfOutputImage($file, $width, $height) |
|---|
| 153 | { |
|---|
| 154 | $objThumb = new gdthumb(); |
|---|
| 155 | $objThumb->Main($file, $width, $height, '', true); |
|---|
| 156 | } |
|---|
| 157 | } |
|---|