source: temp/branches/mobile/data/class/GC_MobileImage.php @ 11432

Revision 11432, 1.7 KB checked in by rebelt, 17 years ago (diff)

テスト

  • Property svn:eol-style set to native
Line 
1<?php
2/**
3 * üËö¤Î²èÌ̲òÁüÅ٤ˤ¢¤ï¤»¤Æ²èÁü¤òÊÑ´¹¤¹¤ë
4 *
5 */
6
7define("INC_PATH", realpath(dirname( __FILE__)) . "/../include");
8require_once(INC_PATH . "/image_converter.inc");
9
10/**
11 * ·ÈÂÓüËö¤Î¥¯¥é¥¹
12 */
13class GC_MobileImage {
14    /**
15     * ²èÁü¤òüËö¤Î²òÁüÅ٤˹ç¤ï¤»¤ÆÊÑ´¹¤¹¤ë
16     * output buffering ÍÑ¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô
17     *
18     * @param string ÆþÎÏ
19     * @return string ½ÐÎÏ
20     */
21    function handler($buffer) {
22
23        // üËö¾ðÊó¤ò¼èÆÀ¤¹¤ë
24        $carrier = GC_MobileUserAgent::getCarrier();
25        $model   = GC_MobileUserAgent::getModel();
26
27        // ·ÈÂÓÅÅÏäξì¹ç¤Î¤ß½èÍý¤ò¹Ô¤¦
28        if ($carrier !== FALSE) {
29
30            // HTMLÃæ¤ÎIMG¥¿¥°¤ò¼èÆÀ¤¹¤ë
31            $pattern = '/<img\s+src=[\'"]([^>"]+)[\'"]\s*\/*>/i';
32            preg_match_all($pattern, $buffer, $images);
33
34            // üËö¤Î¾ðÊó¤ò¼èÆÀ¤¹¤ë
35            $fp = @fopen(INC_PATH . "/mobile_image_map_$carrier.inc", "r");
36            flock($fp, LOCK_SH);
37            while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {
38                if ($data[1] == $model) {
39                    $imageType  = $data[6];
40                    $imageWidth = $data[5];
41                }
42            }
43            flock($fp, LOCK_UN);
44            fclose($fp);
45
46            // ²èÁüÊÑ´¹¤Î¾ðÊó¤ò¥»¥Ã¥È¤¹¤ë
47            $imageConverter = New ImageConverter();
48            $imageConverter->setOutputDir(MOBILE_IMAGE_DIR);
49            $imageConverter->setImageType($imageType);
50            $imageConverter->setImageWidth($imageWidth);
51
52            // HTMLÃæ¤ÎIMG¥¿¥°¤òÊÑ´¹¸å¤Î¥Õ¥¡¥¤¥ë¥Ñ¥¹¤ËÃÖ´¹¤¹¤ë
53            foreach ($images[1] as $key => $value) {
54                $converted = $imageConverter->execute(str_replace(PC_URL_DIR, PC_HTML_PATH, $value));
55$fp = fopen('/tmp/rebelt', 'a'); fwrite($fp, count($converted['outputImageName'])); fclose($fp);
56                $buffer = str_replace($value, MOBILE_IMAGE_URL . '/' . $converted['outputImageName'], $buffer);
57            }
58        }
59        return $buffer;
60    }
61}
62?>
Note: See TracBrowser for help on using the repository browser.