$update->update(); unset($update); } // ランク変更 if (isset($_REQUEST['rank'])) { $update = new ImageCache2_DataObject_Images(); $update->rank = $params['rank'] = $rank; $update->whereAddQuoted('size', '=', $search->size); $update->whereAddQuoted('md5', '=', $search->md5); $update->whereAddQuoted('mime', '=', $search->mime); $update->update(); unset($update); } // ファイルが保存されていればそれでよし、保存されていなければレコードを削除する。 if (file_exists($filepath)) { $fileurl = $thumbnailer->srcUrl($search->size, $search->md5, $search->mime); if ($force) { $_size = $search->size; $_md5 = $search->md5; $_mime = $search->mime; $mtime = $search->time; } else { ic2_finish($fileurl, $thumb, $params, false); } } else { $retry = true; $force = false; $_size = $search->size; $_md5 = $search->md5; $_mime = $search->mime; }
/** * イメージキャッシュのURLと画像サイズを返す (ImageCache2) */ function rss_get_image_ic2($src_url, $memo = '') { static $thumbnailer = null; static $thumbnailer_k = null; if (is_null($thumbnailer)) { $thumbnailer = new ImageCache2_Thumbnailer(ImageCache2_Thumbnailer::SIZE_PC); $thumbnailer_k = new ImageCache2_Thumbnailer(ImageCache2_Thumbnailer::SIZE_MOBILE); } $icdb = new ImageCache2_DataObject_Images(); if ($thumbnailer->ini['General']['automemo'] && $memo !== '') { $img_memo = $icdb->uniform($memo, 'CP932'); if ($memo !== '') { $img_memo_query = '&' . $_conf['detect_hint_q_utf8']; $img_memo_query .= '&memo=' . rawurlencode($img_memo); } else { $img_memo = null; $img_memo_query = ''; } } else { $img_memo = null; $img_memo_query = ''; } $url_en = rawurlencode($src_url); // 画像表示方法 // r=0:HTML;r=1:リダイレクト;r=2:PHPで表示 // インライン表示用サムネイルはオリジナルがキャッシュされているとURLが短くなるのでr=2 // 携帯用サムネイル(全画面表示が目的)はインライン表示しないのでr=0 // サムネイルの大きさ // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ $img_url = 'ic2.php?r=1&uri=' . $url_en; $img_size = ''; $thumb_url = 'ic2.php?r=2&t=1&uri=' . $url_en; $thumb_url2 = 'ic2.php?r=2&t=1&id='; $thumb_size = ''; $thumb_k_url = 'ic2.php?r=0&t=2&uri=' . $url_en; $thumb_k_url2 = 'ic2.php?r=0&t=1&id='; $thumb_k_size = ''; $src_exists = false; // DBに画像情報が登録されていたとき if ($icdb->get($src_url)) { // ウィルスに感染していたファイルのとき if ($icdb->mime == 'clamscan/infected') { $aborn_img = array('./img/x04.png', 'width="32" height="32"'); return array($aborn_img, $aborn_img, $aborn_img, P2_IMAGECACHE_ABORN); } // あぼーん画像のとき if ($icdb->rank < 0) { $virus_img = array('./img/x01.png', 'width="32" height="32"'); return array($virus_img, $virus_img, $virus_img, P2_IMAGECACHE_VIRUS); } // オリジナルがキャッシュされているときは画像を直接読み込む $_img_path = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($_img_path)) { $img_url = $thumbnailer->srcUrl($icdb->size, $icdb->md5, $icdb->mime); $img_size = "width=\"{$icdb->width}\" height=\"{$icdb->height}\""; $src_exists = true; } // サムネイルが作成されていているときは画像を直接読み込む $_thumb_path = $thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($_thumb_path)) { $thumb_url = $thumbnailer->thumbUrl($icdb->size, $icdb->md5, $icdb->mime); // 自動タイトルメモ機能がONでタイトルが記録されていないときはDBを更新 if (!is_null($img_memo) && strpos($icdb->memo, $img_memo) === false) { $update = new ImageCache2_DataObject_Images(); if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) { $update->memo = $img_memo . ' ' . $icdb->memo; } else { $update->memo = $img_memo; } $update->whereAddQuoted('uri', '=', $src_url); $update->update(); } } elseif ($src_exists) { $thumb_url = $thumb_url2 . $icdb->id; } // 携帯用サムネイルが作成されていているときは画像を直接読み込む $_thumb_k_path = $thumbnailer_k->thumbPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($_thumb_k_path)) { $thumb_k_url = $thumbnailer_k->thumbUrl($icdb->size, $icdb->md5, $icdb->mime); } elseif ($src_exists) { $thumb_k_url = $thumb_k_url2 . $icdb->id; } // サムネイルの画像サイズ $thumb_size = $thumbnailer->calc($icdb->width, $icdb->height); $thumb_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_size); // 携帯用サムネイルの画像サイズ $thumb_k_size = $thumbnailer_k->calc($icdb->width, $icdb->height); $thumb_k_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_k_size); // 画像がキャッシュされていないとき // 自動タイトルメモ機能がONならクエリにUTF-8エンコードしたタイトルを含める } else { $img_url .= $img_memo_query; $thumb_url .= $img_memo_query; $thumb_k_url .= $img_memo_query; } $result = array(); $result[] = array($img_url, $img_size); $result[] = array($thumb_url, $thumb_size); $result[] = array($thumb_k_url, $thumb_k_size); $result[] = P2_IMAGECACHE_OK; return $result; }
$img_title = p2h($url); $url_en = rawurlencode($url); $src_url = 'ic2.php?r=1&uri=' . $url_en; $thumb_url = 'ic2.php?r=1&t=' . $thumb_type . '&uri=' . $url_en; $thumb_x = ''; $thumb_y = ''; $img_memo = $new_memo; // 画像がブラックリストorエラーログにあるとき if (false !== ($errcode = $icdb->ic2_isError($url))) { $img_title = "<s>{$img_title}</s>"; $thumb_url = "./img/{$errcode}.png"; // 既にキャッシュされているとき } elseif ($icdb->get($url)) { $_src_path = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($_src_path)) { $src_url = $thumbnailer->srcUrl($icdb->size, $icdb->md5, $icdb->mime); } $_thumb_path = $thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($_thumb_path)) { $thumb_url = $thumbnailer->thumbUrl($icdb->size, $icdb->md5, $icdb->mime); } if (preg_match('/(\\d+)x(\\d+)/', $thumbnailer->calc($icdb->width, $icdb->height), $thumb_xy)) { $thumb_x = $thumb_xy[1]; $thumb_y = $thumb_xy[2]; } // メモが記録されていないときはDBを更新 if (isset($new_memo) && strpos($icdb->memo, $new_memo) === false) { $update = clone $icdb; if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) { $update->memo = $new_memo . ' ' . $icdb->memo; } else {
$thumb_type |= ImageCache2_Thumbnailer::DPR_1_5; } elseif ($dpr === 2.0) { $thumb_type |= ImageCache2_Thumbnailer::DPR_2_0; } $thumbnailer = new ImageCache2_Thumbnailer($thumb_type); break; default: $thumbnailer = new ImageCache2_Thumbnailer(); $calculator = $thumbnailer; } $size = (int) $icdb->size; $md5 = $icdb->md5; $mime = $icdb->mime; $srcPath = $thumbnailer->srcPath($size, $md5, $mime); $thumbPath = $thumbnailer->thumbPath($size, $md5, $mime); $srcUrl = $thumbnailer->srcUrl($size, $md5, $mime); $thumbUrl = $thumbnailer->thumbUrl($size, $md5, $mime); $width = (int) $icdb->width; $height = (int) $icdb->height; list($thumbWidth, $thumbHeight) = $calculator->calc($width, $height, true); echo json_encode(array('id' => (int) $icdb->id, 'uri' => $icdb->uri, 'host' => $icdb->host, 'name' => $icdb->name, 'size' => $size, 'md5' => $md5, 'width' => (int) $icdb->width, 'height' => (int) $icdb->height, 'mime' => $mime, 'rank' => (int) $icdb->rank, 'time' => (int) $icdb->time, 'memo' => $icdb->memo, 'url' => $icdb->uri, 'src' => $srcPath && file_exists($srcPath) ? $srcUrl : null, 'thumb' => $thumbPath && file_exists($thumbPath) ? $thumbUrl : null, 'thumbWidth' => $thumbWidth, 'thumbHeight' => $thumbHeight)); exit; // }}} /* * Local Variables: * mode: php * coding: cp932 * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: nil * End: