svnno****@sourc*****
svnno****@sourc*****
2011年 1月 10日 (月) 20:54:35 JST
Revision: 896 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=896 Author: rsk Date: 2011-01-10 20:54:35 +0900 (Mon, 10 Jan 2011) Log Message: ----------- expack: - iPhoneã§ãã°ã¤ã³æã«devicePixelRatioã®å¤ãéä¿¡ããããã«ããã - ImageCache2ã§devicePixelRatioã«å¿ãããµã ãã¤ã«ãä½æããããã«ããã - Limelightã®å寸表示ã¢ã¼ãã§WebKitã®devicePixelRatioã«å¿ãã ãµã¤ãºã«ã¹ã±ã¼ã«ããããã«ããã Modified Paths: -------------- p2ex/trunk/ic2.php p2ex/trunk/ic2_mkthumb.php p2ex/trunk/iv2.php p2ex/trunk/js/limelight.js p2ex/trunk/lib/Login.php p2ex/trunk/lib/expack/ExpackLoader.php p2ex/trunk/lib/expack/ic2/DatabaseManager.php p2ex/trunk/lib/expack/ic2/Thumbnailer.php p2ex/trunk/lib/login_first.inc.php -------------- next part -------------- Modified: p2ex/trunk/ic2.php =================================================================== --- p2ex/trunk/ic2.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/ic2.php 2011-01-10 11:54:35 UTC (rev 896) @@ -37,6 +37,7 @@ $file = isset($_REQUEST['file']) ? $_REQUEST['file'] : null; $force = !empty($_REQUEST['f']); // §XV $thumb = isset($_REQUEST['t']) ? intval($_REQUEST['t']) : IC2_Thumbnailer::SIZE_SOURCE; // TlC^Cv +$dpr = isset($_REQUEST['d']) ? floatval($_REQUEST['d']) : 1.0; // device pixel ratio $redirect = isset($_REQUEST['r']) ? intval($_REQUEST['r']) : 1; // \¦û@ $rank = isset($_REQUEST['rank']) ? intval($_REQUEST['rank']) : 0; // [eBO $memo = (isset($_REQUEST['memo']) && strlen($_REQUEST['memo']) > 0) ? $_REQUEST['memo'] : null; // @@ -98,6 +99,15 @@ $thumb = IC2_Thumbnailer::SIZE_DEFAULT; } +if ($dpr === 1.5) { + $thumb_type = $thumb | IC2_Thumbnailer::DPR_1_5; +} elseif ($dpr === 2.0) { + $thumb_type = $thumb | IC2_Thumbnailer::DPR_2_0; +} else { + $thumb_type = $thumb; + $dpr = 1.0; +} + if ($rank < -1) { $rank = -1; } elseif ($rank > 5) { @@ -108,7 +118,7 @@ $memo = null; } -$thumbnailer = new IC2_Thumbnailer($thumb); +$thumbnailer = new IC2_Thumbnailer($thumb_type); // }}} // {{{ IC2TempFile @@ -333,16 +343,17 @@ } // }}} -// {{{ head +// {{{ get -// ܸÍHEADÅ`FbN -$client_h = clone $client; -$code = $client_h->head($uri); +// _E[h +$code = $client->get($uri); if (PEAR::isError($code)) { ic2_error('x02', $code->getMessage()); } -$head = $client_h->currentResponse(); +$response = $client->currentResponse(); + + // 304 Not Modified ÌÆ« if ($filepath && $force && $time && $code == 304) { ic2_finish($filepath, $thumb, $params, false); @@ -354,16 +365,16 @@ } // Content-TypeØ -if (isset($head['headers']['content-type'])) { - $conent_type = $head['headers']['content-type']; +if (isset($response['headers']['content-type'])) { + $conent_type = $response['headers']['content-type']; if (!preg_match('{^image/}', $conent_type) && $conent_type != 'application/x-shockwave-flash') { ic2_error('x02', "T|[g³êĢȢt@C^CvÅ·B({$conent_type})"); } } // Content-LengthØ -if (isset($head['headers']['content-length'])) { - $conent_length = (int)$head['headers']['content-length']; +if (isset($response['headers']['content-length'])) { + $conent_length = (int)$response['headers']['content-length']; $maxsize = $ini['Source']['maxsize']; if (preg_match('/(\d+\.?\d*)([KMG])/i', $maxsize, $m)) { $maxsize = p2_si2int($m[1], $m[2]); @@ -375,21 +386,6 @@ } } -unset($client_h, $code, $head); - -// }}} -// {{{ get - -// _E[h -$code = $client->get($uri); -if (PEAR::isError($code)) { - ic2_error('x02', $code->getMessage()); -} elseif ($code != 200) { - ic2_error($code); -} - -$response = $client->currentResponse(); - // êt@CÉÛ¶ $tmpfile = tempnam($_conf['tmp_dir'], 'ic2_get_'); $tmpobj = new IC2TempFile($tmpfile); @@ -649,7 +645,7 @@ function ic2_display($path, $params) { - global $_conf, $ini, $thumb, $redirect, $id, $uri, $file, $thumbnailer; + global $_conf, $ini, $thumb, $dpr, $redirect, $id, $uri, $file, $thumbnailer; if (P2_OS_WINDOWS) { $path = str_replace('\\', '/', $path); @@ -721,6 +717,7 @@ 'o' => sprintf('´¡ (%dx%d)', $params['width'], $params['height']), 's' => 'ì¬', 't' => $thumb, + 'd' => $dpr, 'u' => $img_p, 'v' => $img_o, 'x' => $_size[0], Modified: p2ex/trunk/ic2_mkthumb.php =================================================================== --- p2ex/trunk/ic2_mkthumb.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/ic2_mkthumb.php 2011-01-10 11:54:35 UTC (rev 896) @@ -28,6 +28,7 @@ $uri = $_GET['u']; $type = $_GET['v']; $thumb = isset($_GET['t']) ? intval($_GET['t']) : 0; +$dpr = isset($_REQUEST['d']) ? floatval($_REQUEST['d']) : 1.0; $options = array(); $options['quality'] = isset($_GET['q']) ? intval($_GET['q']) : null; $options['rotate'] = isset($_GET['r']) ? intval($_GET['r']) : 0; @@ -60,7 +61,7 @@ $search->whereAddQuoted('id', '=', $uri); break; case 'file': - preg_match('/^([1-9][0-9]*)_([0-9a-f]{32})(?:\.(jpg|png|gif))?$/', $uri, $fdata); + preg_match('/^([1-9][0-9]*)_([0-9a-f]{32})(?:_x(15|20))?(?:\.(jpg|png|gif))?$/', $uri, $fdata); $search->whereAddQuoted('size', '=', $fdata[0]); $search->whereAddQuoted('md5', '=', $fdata[1]); break; @@ -78,7 +79,14 @@ ic2_mkthumb_success(basename($src), $search->mime, $src, true, $attachment); } } else { - $thumb = new IC2_Thumbnailer($thumb, $options); + if ($dpr === 1.5) { + $thumb_type = $thumb | IC2_Thumbnailer::DPR_1_5; + } elseif ($dpr === 2.0) { + $thumb_type = $thumb | IC2_Thumbnailer::DPR_2_0; + } else { + $thumb_type = $thumb; + } + $thumb = new IC2_Thumbnailer($thumb_type, $options); $result = $thumb->convert($search->size, $search->md5, $search->mime, $search->width, $search->height); if (PEAR::isError($result)) { ic2_mkthumb_error($result->getMessage()); Modified: p2ex/trunk/iv2.php =================================================================== --- p2ex/trunk/iv2.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/iv2.php 2011-01-10 11:54:35 UTC (rev 896) @@ -171,7 +171,20 @@ $db_class = strtolower(get_class($db)); // TlCì¬NX -$thumb = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_DEFAULT); +$thumb_size = IC2_Thumbnailer::SIZE_PC; +if (!empty($_SESSION['device_pixel_ratio'])) { + $dpr = $_SESSION['device_pixel_ratio']; + if ($dpr === 1.5) { + $thumb_size |= IC2_Thumbnailer::DPR_1_5; + } elseif ($dpr === 2.0) { + $thumb_size |= IC2_Thumbnailer::DPR_2_0; + } else { + $dpr = 1.0; + } +} else { + $dpr = 1.0; +} +$thumb = new IC2_Thumbnailer($thumb_size); if ($ini['Viewer']['cache']) { $kvs = P2KeyValueStore::getStore($_conf['iv2_cache_db_path'], @@ -214,7 +227,7 @@ } else { $use_cache = false; } - +$use_cache = false; // }}} // {{{ prepare (Form & Template) @@ -837,6 +850,9 @@ } else { $add['thumb'] .= '&uri=' . rawurlencode($img['uri']); } + if ($dpr === 1.5 || $dpr === 2.0) { + $add['thumb'] .= '&d=' . $dpr; + } } if ($_conf['ktai']) { $add['thumb_k'] = 'ic2.php?r=0&t=2'; @@ -846,6 +862,9 @@ $add['thumb_k'] .= '&uri=' . rawurlencode($img['uri']); } $add['thumb_k'] .= $k_backto; + if ($dpr === 1.5 || $dpr === 2.0) { + $add['thumb_k'] .= '&d=' . $dpr; + } } } $item = array_merge($img, $add, $status); Modified: p2ex/trunk/js/limelight.js =================================================================== --- p2ex/trunk/js/limelight.js 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/js/limelight.js 2011-01-10 11:54:35 UTC (rev 896) @@ -1018,6 +1018,7 @@ fillScale: 0, fitToWidthScale: 0, fitToHeightScale: 0, + origScale: 1, scale: 0, rotation: 0, diagonalLength: 0, @@ -1088,6 +1089,10 @@ 'standalone': false }; + if (typeof window.devicePixelRatio === 'number') { + this.origScale = 1 / window.devicePixelRatio; + } + if (options) { for (name in options) { bool = (options[name]) ? true : false; @@ -1231,7 +1236,7 @@ this.toolbar.origButton.attachEvent('click', function(event) { Limelight.dom.stopEvent(event); - self.scaleTo(1); + self.scaleTo(self.origScale); self.setLastClicked(self.toolbar.origButton); return false; }); @@ -2227,7 +2232,7 @@ this.scaleTo(this.fillScale); this.setLastClicked(toolbar.fillButton); } else if (toolbar.origButton.isTargetOf(event)) { - this.scaleTo(1); + this.scaleTo(this.origScale); this.setLastClicked(toolbar.origButton); } else { this.focus(); Modified: p2ex/trunk/lib/Login.php =================================================================== --- p2ex/trunk/lib/Login.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/lib/Login.php 2011-01-10 11:54:35 UTC (rev 896) @@ -187,6 +187,14 @@ if (!array_key_exists('login_microtime', $_SESSION)) { $_SESSION['login_microtime'] = microtime(); } + + // devicePixelRatiowèª êÎÛ + if (!empty($_REQUEST['device_pixel_ratio'])) { + $device_pixel_ratio = floatval($_REQUEST['device_pixel_ratio']); + if ($device_pixel_ratio === 1.5 || $device_pixel_ratio === 2.0) { + $_SESSION['device_pixel_ratio'] = $device_pixel_ratio; + } + } } // }}} Modified: p2ex/trunk/lib/expack/ExpackLoader.php =================================================================== --- p2ex/trunk/lib/expack/ExpackLoader.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/lib/expack/ExpackLoader.php 2011-01-10 11:54:35 UTC (rev 896) @@ -158,8 +158,24 @@ $aShowThread->thumb_id_suffix = '-' . strtr(microtime(), '. ', '--'); $aShowThread->thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC); } else { - $aShowThread->inline_prvw = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC); - $aShowThread->thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_MOBILE); + $preview_size = IC2_Thumbnailer::SIZE_PC; + $thumb_size = IC2_Thumbnailer::SIZE_MOBILE; + if (!empty($_SESSION['device_pixel_ratio'])) { + $dpr = $_SESSION['device_pixel_ratio']; + if ($dpr === 1.5) { + $preview_size |= IC2_Thumbnailer::DPR_1_5; + $thumb_size |= IC2_Thumbnailer::DPR_1_5; + } elseif ($dpr === 2.0) { + $preview_size |= IC2_Thumbnailer::DPR_2_0; + $thumb_size |= IC2_Thumbnailer::DPR_2_0; + } else { + $dpr = 1.0; + } + } else { + $dpr = 1.0; + } + $aShowThread->inline_prvw = new IC2_Thumbnailer($preview_size); + $aShowThread->thumbnailer = new IC2_Thumbnailer($thumb_size); } if ($aShowThread->thumbnailer->ini['General']['automemo']) { @@ -170,6 +186,9 @@ $aShowThread->img_memo = null; $aShowThread->img_memo_query = ''; } + if ($dpr === 1.5 || $dpr === 2.0) { + $aShowThread->img_memo_query .= '&d=' . $dpr; + } self::loadClass('IC2_Switch', 'ic2/Switch.php'); if (!IC2_Switch::get($_conf['ktai'])) { Modified: p2ex/trunk/lib/expack/ic2/DatabaseManager.php =================================================================== --- p2ex/trunk/lib/expack/ic2/DatabaseManager.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/lib/expack/ic2/DatabaseManager.php 2011-01-10 11:54:35 UTC (rev 896) @@ -105,29 +105,32 @@ if ($icdb->find(true)) { // LbV µÄ¢ét@Cðí - $t1 = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC); - $t2 = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_MOBILE); - $t3 = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_INTERMD); - $srcPath = $t1->srcPath($icdb->size, $icdb->md5, $icdb->mime); - $t1Path = $t1->thumbPath($icdb->size, $icdb->md5, $icdb->mime); - $t2Path = $t2->thumbPath($icdb->size, $icdb->md5, $icdb->mime); - $t3Path = $t3->thumbPath($icdb->size, $icdb->md5, $icdb->mime); - if (file_exists($srcPath)) { - unlink($srcPath); - $removed_files[] = $srcPath; + $sizes = array( + IC2_Thumbnailer::SIZE_PC, + IC2_Thumbnailer::SIZE_MOBILE, + IC2_Thumbnailer::SIZE_INTERMD, + ); + $dprs = array( + IC2_Thumbnailer::DPR_DEFAULT, + IC2_Thumbnailer::DPR_1_5, + IC2_Thumbnailer::DPR_2_0, + ); + foreach ($sizes as $size) { + foreach ($dprs as $dpr) { + $t = new IC2_Thumbnailer($size | $dpr); + $path = $t->thumbPath($icdb->size, $icdb->md5, $icdb->mime); + if (file_exists($path)) { + unlink($path); + $removed_files[] = $path; + } + } } - if (file_exists($t1Path)) { - unlink($t1Path); - $removed_files[] = $t1Path; + $t = new IC2_Thumbnailer(); + $path = $t->srcPath($icdb->size, $icdb->md5, $icdb->mime); + if (file_exists($path)) { + unlink($path); + $removed_files[] = $path; } - if (file_exists($t2Path)) { - unlink($t2Path); - $removed_files[] = $t2Path; - } - if (file_exists($t3Path)) { - unlink($t3Path); - $removed_files[] = $t3Path; - } // ubNXgèÌõ if ($to_blacklist) { Modified: p2ex/trunk/lib/expack/ic2/Thumbnailer.php =================================================================== --- p2ex/trunk/lib/expack/ic2/Thumbnailer.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/lib/expack/ic2/Thumbnailer.php 2011-01-10 11:54:35 UTC (rev 896) @@ -16,6 +16,11 @@ const SIZE_DEFAULT = 1; + const DPR_DEFAULT = 0; + const DPR_1_5 = 0x150000; + const DPR_2_0 = 0x200000; + const DPR_MASK = 0xff0000; + // }}} // {{{ properties @@ -52,6 +57,8 @@ ); // @var array $mimemap, MIME^CvÆg£qÌÎ\ public $mimemap = array('image/jpeg' => '.jpg', 'image/png' => '.png', 'image/gif' => '.gif'); + // @var int + protected $dpr = self::DPR_DEFAULT; // }}} // {{{ constructor @@ -85,6 +92,13 @@ } // TlC[h»è + $dpr = $mode & self::DPR_MASK; + $mode = $mode & ~self::DPR_MASK; + if ($dpr === self::DPR_1_5 || $dpr === self::DPR_2_0) { + $this->dpr = $dpr; + } else { + $this->dpr = $dpr = self::DPR_DEFAULT; + } switch ($mode) { case self::SIZE_SOURCE: case self::SIZE_PC: @@ -329,8 +343,28 @@ $this->resize = false; $this->coord = false; + // ÅåTCYâ³ + if ($return_array) { + switch ($this->dpr) { + case self::DPR_1_5: + $max_width = intval($this->max_width * 1.5); + $max_height = intval($this->max_height * 1.5); + break; + case self::DPR_2_0: + $max_width = $this->max_width * 2; + $max_height = $this->max_height * 2; + break; + default: + $max_width = $this->max_width; + $max_height = $this->max_height; + } + } else { + $max_width = $this->max_width; + $max_height = $this->max_height; + } + // \[XªTlCÌÅåTCYæ謳¢Æ«A\[XÌ嫳ð»ÌÜÜÔ· - if ($width <= $this->max_width && $height <= $this->max_height) { + if ($width <= $max_width && $height <= $max_height) { // TCYEg~OÆàɳø if ($return_array) { return array((int)$t_width, (int)$t_height); @@ -340,12 +374,12 @@ } // c¡Ç¿çÉí¹é©ð»èiÅåTCYæè¡· = ¡Éí¹éj - if (($width / $height) >= ($this->max_width / $this->max_height)) { + if (($width / $height) >= ($max_width / $max_height)) { // ¡Éí¹é $main = $width; $sub = $height; - $max_main = $this->max_width; - $max_sub = $this->max_height; + $max_main = $max_width; + $max_sub = $max_height; $t_main = &$t_width; // $t_mainÆ$t_subðTlCTCYÌ $t_sub = &$t_height; // t@XɵĢéÌªÌ $c_main = 'x'; @@ -354,8 +388,8 @@ // cÉí¹é $main = $height; $sub = $width; - $max_main = $this->max_height; - $max_sub = $this->max_width; + $max_main = $max_height; + $max_sub = $max_width; $t_main = &$t_height; $t_sub = &$t_width; $c_main = 'y'; @@ -431,6 +465,14 @@ } $basename = $size . '_' . $md5; + switch ($this->dpr) { + case self::DPR_1_5: + $basename .= '_x15'; + break; + case self::DPR_2_0: + $basename .= '_x20'; + break; + } if ($this->rotate) { $basename .= '_' . str_pad($this->rotate, 3, 0, STR_PAD_LEFT); } Modified: p2ex/trunk/lib/login_first.inc.php =================================================================== --- p2ex/trunk/lib/login_first.inc.php 2010-12-31 02:02:21 UTC (rev 895) +++ p2ex/trunk/lib/login_first.inc.php 2011-01-10 11:54:35 UTC (rev 896) @@ -159,9 +159,12 @@ $ignore_cip_checked = ' checked'; } } - $auth_sub_input_ht = '<input type="hidden" name="ctl_regist_cookie" value="1">' - . sprintf('<input type="checkbox" id="regist_cookie" name="regist_cookie" value="1"%s><label for="regist_cookie">OCîñðCookieÉÛ¶·éi§j</label><br>', $regist_cookie_checked) - . sprintf('<input type="checkbox" id="ignore_cip" name="ignore_cip" value="1"%s><label for="ignore_cip">CookieFØÉIP̯ê«ð`FbNµÈ¢</label><br>', $ignore_cip_checked); + $auth_sub_input_ht = <<<EOP +<input type="hidden" name="device_pixel_ratio" id="device_pixel_ratio" value="1"> +<input type="hidden" name="ctl_regist_cookie" value="1"> +<input type="checkbox" id="regist_cookie" name="regist_cookie" value="1"{$regist_cookie_checked}><label for="regist_cookie">OCîñðCookieÉÛ¶·éi§j</label><br> +<input type="checkbox" id="ignore_cip" name="ignore_cip" value="1"{$ignore_cip_checked}><label for="ignore_cip">CookieFØÉIP̯ê«ð`FbNµÈ¢</label><br> +EOP; } // }}} @@ -345,7 +348,27 @@ </style>\n EOP; } - echo "</head><body>\n"; + if ($_conf['iphone']) { + echo <<<EOP +<script type="text/javascript"> +// <![CDATA[ +function setDevicePixelRatio() +{ + if (typeof window.devicePixelRatio === 'number') { + var dpr = document.getElementById('device_pixel_ratio'); + if (dpr) { + dpr.value = window.devicePixelRatio; + } + } +} +// ]]> +</script> +</head> +<body onload="setDevicePixelRatio()"> +EOP; + } else { + echo "</head><body>\n"; + } echo "<h3>{$ptitle}</h3>\n"; // îñ\¦