$thumb_type = $thumb | ImageCache2_Thumbnailer::DPR_1_5; } elseif ($dpr === 2.0) { $thumb_type = $thumb | ImageCache2_Thumbnailer::DPR_2_0; } else { $thumb_type = $thumb; $dpr = 1.0; } if ($rank < -1) { $rank = -1; } elseif ($rank > 5) { $rank = 5; } if ($memo === '') { $memo = null; } $thumbnailer = new ImageCache2_Thumbnailer($thumb_type); // }}} // {{{ IC2TempFile class IC2TempFile { private $_filename = null; public function __construct($filename) { if (touch($filename)) { $this->_filename = realpath($filename); } } public function __destruct() { if ($this->_filename !== null) { if (file_exists($this->_filename)) {
$qfe['padding']->updateAttributes('disabled="disabled"'); } // }}} // {{{ generate if ($execDL) { if (is_null($serial)) { $URLs = array($params['uri']); } else { $URLs = array(); for ($i = $serial['from']; $i <= $serial['to']; $i++) { // URLエンコードされた文字列も%を含むので sprintf() は使わない。 // URLエンコードのフォーマットは%+16進数なので"%s"を置換しても影響しない。 $URLs[] = str_replace('%s', str_pad($i, $serial['pad'], '0', STR_PAD_LEFT), $params['uri']); } } $thumbnailer = new ImageCache2_Thumbnailer($thumb_type); $images = array(); foreach ($URLs as $url) { $icdb = new ImageCache2_DataObject_Images(); $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"; // 既にキャッシュされているとき
/** * 画像を削除 */ public static function remove($target, $to_blacklist = false) { $ini = ic2_loadconfig(); $removed_files = array(); if (empty($target)) { return $removed_files; } if (!is_array($target)) { if (is_integer($target) || ctype_digit($target)) { $id = (int) $target; if ($id > 0) { $target = array($id); } else { return $removed_files; } } else { P2Util::pushInfoHtml('<p>WARNING! ImageCache2_DatabaseManager::remove(): 不正な引数</p>'); return $removed_files; } } // トランザクションの開始 $ta = new ImageCache2_DataObject_Images(); $db = $ta->getDatabaseConnection(); if ($db->phptype == 'pgsql') { $ta->query('BEGIN'); } elseif ($db->phptype == 'sqlite') { $db->query('BEGIN;'); } // 画像を削除 $parent_dir = dirname($ini['General']['cachedir']) . DIRECTORY_SEPARATOR; $pattern = '/^' . preg_quote($parent_dir, '/') . '/'; foreach ($target as $id) { $icdb = new ImageCache2_DataObject_Images(); $icdb->whereAdd("id = {$id}"); if ($icdb->find(true)) { // キャッシュしているファイルを削除 $sizes = array(ImageCache2_Thumbnailer::SIZE_PC, ImageCache2_Thumbnailer::SIZE_MOBILE, ImageCache2_Thumbnailer::SIZE_INTERMD); $dprs = array(ImageCache2_Thumbnailer::DPR_DEFAULT, ImageCache2_Thumbnailer::DPR_1_5, ImageCache2_Thumbnailer::DPR_2_0); foreach ($sizes as $size) { foreach ($dprs as $dpr) { $t = new ImageCache2_Thumbnailer($size | $dpr); $path = $t->thumbPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($path)) { unlink($path); $removed_files[] = preg_replace($pattern, '', $path); } } } $t = new ImageCache2_Thumbnailer(); $path = $t->srcPath($icdb->size, $icdb->md5, $icdb->mime); if (file_exists($path)) { unlink($path); $removed_files[] = preg_replace($pattern, '', $path); } // ブラックリスト送りの準備 if ($to_blacklist) { $_blacklist = new ImageCache2_DataObject_BlackList(); $_blacklist->size = $icdb->size; $_blacklist->md5 = $icdb->md5; if ($icdb->mime === 'clamscan/infected' || $icdb->rank == -4) { $_blacklist->type = 2; } elseif ($icdb->rank < 0) { $_blacklist->type = 1; } else { $_blacklist->type = 0; } } // 同一画像を検索 $remover = new ImageCache2_DataObject_Images(); $remover->whereAddQuoted('size', '=', $icdb->size); $remover->whereAddQuoted('md5', '=', $icdb->md5); //$remover->whereAddQuoted('mime', '=', $icdb->mime); // SizeとMD5で十分 $remover->find(); while ($remover->fetch()) { // ブラックリスト送りにする if ($to_blacklist) { $blacklist = clone $_blacklist; $blacklist->uri = $remover->uri; $blacklist->insert(); } // テーブルから抹消 $remover->delete(); } } } // トランザクションのコミット if ($db->phptype == 'pgsql') { $ta->query('COMMIT'); } elseif ($db->phptype == 'sqlite') { $db->query('COMMIT;'); } return $removed_files; }
$thumbtype = ImageCache2_ParameterUtility::getValidValue('thumbtype', $_defaults['thumbtype'], 'intval'); // サムネイル作成クラス $thumbsize = $thumbtype; if (!empty($_SESSION['device_pixel_ratio'])) { $dpr = $_SESSION['device_pixel_ratio']; if ($dpr === 1.5) { $thumbsize |= ImageCache2_Thumbnailer::DPR_1_5; } elseif ($dpr === 2.0) { $thumbsize |= ImageCache2_Thumbnailer::DPR_2_0; } else { $dpr = 1.0; } } else { $dpr = 1.0; } $thumb = new ImageCache2_Thumbnailer($thumbsize); // 携帯用に調整 if ($_conf['ktai']) { $lightbox = false; $mode = 1; $inum = (int) $ini['Viewer']['inum']; $overwritable_params = array('order', 'sort', 'field', 'keyword', 'threshold', 'compare'); // 絵文字を読み込む require_once P2_LIB_DIR . '/emoji.inc.php'; $emj = p2_get_emoji(); $flexy->setData('e', $emj); $flexy->setData('ak', $_conf['k_accesskey_at']); $flexy->setData('as', $_conf['k_accesskey_st']); // フィルタリング用フォームを表示 if (!empty($_GET['show_iv2_kfilter'])) { !defined('P2_NO_SAVE_PACKET') && define('P2_NO_SAVE_PACKET', true);
$thumb = new ImageCache2_Thumbnailer(ImageCache2_Thumbnailer::SIZE_DEFAULT); $src = $thumb->srcPath($search->size, $search->md5, $search->mime); if (!file_exists($src)) { ic2_mkthumb_error(""{$uri}"のローカルキャッシュがありません。"); } else { ic2_mkthumb_success(basename($src), $search->mime, $src, true, $attachment); } } else { if ($dpr === 1.5) { $thumb_type = $thumb | ImageCache2_Thumbnailer::DPR_1_5; } elseif ($dpr === 2.0) { $thumb_type = $thumb | ImageCache2_Thumbnailer::DPR_2_0; } else { $thumb_type = $thumb; } $thumb = new ImageCache2_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()); } else { $mime = $thumb->type == '.png' ? 'image/png' : 'image/jpeg'; ic2_mkthumb_success(basename($result), $mime, $thumb->buf, false, $attachment); } } } else { ic2_mkthumb_error(""{$uri}"はキャッシュされていません。"); } // }}} // {{{ ic2_mkthumb_success() /** * サムネイルの作成に成功した場合
* ImageCache2 - 画像のダウンロード・サムネイル作成 */ // {{{ p2基本設定読み込み&認証 require_once __DIR__ . '/../init.php'; require_once P2EX_LIB_DIR . '/ImageCache2/bootstrap.php'; $_login->authorize(); if (!$_conf['expack.ic2.enabled']) { p2die('ImageCache2は無効です。', 'conf/conf_admin_ex.inc.php の設定を変えてください。'); } // }}} // {{{ 画像検索・出力用変数設定 $url = $_GET['url']; $info_key_type = 'url'; $info_key_value = $url; $icdb = new ImageCache2_DataObject_Images(); $thumbnailer = new ImageCache2_Thumbnailer(ImageCache2_Thumbnailer::SIZE_DEFAULT); if (preg_match('/^' . preg_quote($thumbnailer->sourceuri, '/') . '/', $url) && file_exists($url)) { $info = getimagesize($url); $x = $info[0]; $y = $info[1]; $info_key_type = 'md5'; $info_key_value = preg_replace('/^\\d+_([0-9a-f]+)\\..*/', '\\1', basename($url)); } elseif (preg_match('{(?:[\\w.]*/)?ic2\\.php\\?(?:.*&)?ur[il]=([^&]+)(?:&|$)}', $url, $m)) { $url = rawurldecode($m[1]); if ($icdb->get($url)) { $url = $thumbnailer->srcUrl($icdb->size, $icdb->md5, $icdb->mime); $x = (int) $icdb->width; $y = (int) $icdb->height; } else { $x = 0; $y = 0;
/** * イメージキャッシュの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; }
$dpr = 1.0; } switch ($thumb_type) { case ImageCache2_Thumbnailer::SIZE_PC: case ImageCache2_Thumbnailer::SIZE_MOBILE: case ImageCache2_Thumbnailer::SIZE_INTERMD: $calculator = new ImageCache2_Thumbnailer($thumb_type); if ($dpr === 1.5) { $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; // }}}