[16329] | 1 | <?php
|
---|
[16582] | 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2007 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. |
---|
[16329] | 22 | *
|
---|
| 23 | * 端末の画面解像度にあわせて画像を変換する
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | define("MOBILE_IMAGE_INC_PATH", realpath(dirname( __FILE__)) . "/../include");
|
---|
| 27 | require_once(MOBILE_IMAGE_INC_PATH . "/image_converter.inc");
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * 画像変換クラス
|
---|
| 31 | */
|
---|
| 32 | class SC_MobileImage {
|
---|
[16582] | 33 | /**
|
---|
| 34 | * 画像を端末の解像度に合わせて変換する
|
---|
| 35 | * output buffering 用コールバック関数
|
---|
| 36 | *
|
---|
| 37 | * @param string 入力
|
---|
| 38 | * @return string 出力
|
---|
| 39 | */
|
---|
| 40 | function handler($buffer) {
|
---|
[16329] | 41 |
|
---|
[16582] | 42 | // 端末情報を取得する
|
---|
| 43 | $carrier = SC_MobileUserAgent::getCarrier();
|
---|
| 44 | $model = SC_MobileUserAgent::getModel();
|
---|
[16329] | 45 |
|
---|
[16582] | 46 | // 携帯電話の場合のみ処理を行う
|
---|
| 47 | if ($carrier !== FALSE) {
|
---|
[16329] | 48 |
|
---|
[16582] | 49 | // HTML中のIMGタグを取得する
|
---|
| 50 | $pattern = '/<img\s+src=[\'"]([^>"]+)[\'"]\s*\/*>/i';
|
---|
| 51 | $result = preg_match_all($pattern, $buffer, $images);
|
---|
[16329] | 52 |
|
---|
[16582] | 53 | // 端末の情報を取得する
|
---|
| 54 | $fp = fopen(MOBILE_IMAGE_INC_PATH . "/mobile_image_map_$carrier.csv", "r");
|
---|
| 55 | while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {
|
---|
| 56 | if ($data[1] == $model || $data[1] == '*') {
|
---|
| 57 | $cacheSize = $data[2];
|
---|
| 58 | $imageFileSize = $data[7];
|
---|
| 59 | $imageType = $data[6];
|
---|
| 60 | $imageWidth = $data[5];
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | fclose($fp);
|
---|
[16329] | 65 |
|
---|
[16582] | 66 | // docomoとsoftbankの場合は画像ファイル一つに利用可能なサイズの上限を計算する
|
---|
| 67 | // auはHTMLのbyte数上限に画像ファイルサイズが含まれないのでimageFileSizeのまま。
|
---|
| 68 | if ($carrier == "docomo" or $carrier == "softbank") {
|
---|
[17676] | 69 | if( $result != false && $result > 0){
|
---|
| 70 | // 計算式:(利用端末で表示可能なcacheサイズ - HTMLのバイト数 - 変換後の画像名のバイト数(目安値) ) / HTML中の画像数
|
---|
| 71 | $temp_imagefilesize = ($cacheSize - strlen($buffer) - (140 * $result) ) / $result;
|
---|
| 72 | } else {
|
---|
| 73 | // 計算式:(利用端末で表示可能なcacheサイズ - HTMLのバイト数 )
|
---|
| 74 | $temp_imagefilesize = ($cacheSize - strlen($buffer) );
|
---|
| 75 | }
|
---|
[16582] | 76 | // 計算結果が端末の表示可能ファイルサイズ上限より小さい場合は計算結果の値を有効にする
|
---|
| 77 | if ($temp_imagefilesize < $imageFileSize) {
|
---|
| 78 | $imageFileSize = $temp_imagefilesize;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
[16329] | 81 |
|
---|
[16582] | 82 | // 画像変換の情報をセットする
|
---|
| 83 | $imageConverter = New ImageConverter();
|
---|
| 84 | $imageConverter->setOutputDir(MOBILE_IMAGE_DIR);
|
---|
| 85 | $imageConverter->setImageType($imageType);
|
---|
| 86 | $imageConverter->setImageWidth($imageWidth);
|
---|
| 87 | $imageConverter->setFileSize($imageFileSize);
|
---|
[16329] | 88 |
|
---|
[16582] | 89 | // HTML中のIMGタグを変換後のファイルパスに置換する
|
---|
| 90 | foreach ($images[1] as $key => $value) {
|
---|
| 91 | $converted = $imageConverter->execute(preg_replace('|^' . URL_DIR . '|', HTML_PATH, $value));
|
---|
| 92 | if (isset($converted['outputImageName'])) {
|
---|
| 93 | $buffer = str_replace($value, MOBILE_IMAGE_URL . '/' . $converted['outputImageName'], $buffer);
|
---|
| 94 | } else {
|
---|
| 95 | $buffer = str_replace($images[0][$key], '<!--No image-->', $buffer);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | return $buffer;
|
---|
| 100 | }
|
---|
[16329] | 101 | }
|
---|
| 102 | ?>
|
---|