/** * 画像を削除 */ public static function remove($target, $to_blacklist = false) { $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! IC2_DatabaseManager::remove(): 不正な引数</p>'); return $removed_files; } } // トランザクションの開始 $ta = new IC2_DataObject_Images(); $db = $ta->getDatabaseConnection(); if ($db->phptype == 'pgsql') { $ta->query('BEGIN'); } elseif ($db->phptype == 'sqlite') { $db->query('BEGIN;'); } // 画像を削除 foreach ($target as $id) { $icdb = new IC2_DataObject_Images(); $icdb->whereAdd("id = {$id}"); if ($icdb->find(true)) { // キャッシュしているファイルを削除 $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; } if (file_exists($t1Path)) { unlink($t1Path); $removed_files[] = $t1Path; } if (file_exists($t2Path)) { unlink($t2Path); $removed_files[] = $t2Path; } if (file_exists($t3Path)) { unlink($t3Path); $removed_files[] = $t3Path; } // ブラックリスト送りの準備 if ($to_blacklist) { $_blacklist = new IC2_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 IC2_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; }
$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) { $rank = 5; } if ($memo === '') { $memo = null; } $thumbnailer = new IC2_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)) {
} else { $icdb->whereAddQuoted('md5', '=', (string) $_GET['md5']); } if (!$icdb->find(1)) { echo 'null'; exit; } $thumb_type = isset($_GET['t']) ? $_GET['t'] : IC2_Thumbnailer::SIZE_DEFAULT; switch ($thumb_type) { case IC2_Thumbnailer::SIZE_PC: case IC2_Thumbnailer::SIZE_MOBILE: case IC2_Thumbnailer::SIZE_INTERMD: $thumbnailer = new IC2_Thumbnailer($thumb_type); break; default: $thumbnailer = new IC2_Thumbnailer(); } $src = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime); $thumb = $thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime); echo json_encode(array('id' => (int) $icdb->id, 'uri' => $icdb->uri, 'host' => $icdb->host, 'name' => $icdb->name, 'size' => (int) $icdb->size, 'md5' => $icdb->md5, 'width' => (int) $icdb->width, 'height' => (int) $icdb->height, 'mime' => $icdb->mime, 'rank' => (int) $icdb->rank, 'time' => (int) $icdb->time, 'memo' => $icdb->memo, 'url' => $icdb->uri, 'src' => $src && file_exists($src) ? $src : null, 'thumb' => $thumb && file_exists($thumb) ? $thumb : null)); exit; // }}} /* * Local Variables: * mode: php * coding: cp932 * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: nil * End: */
$search->whereAddQuoted('md5', '=', $fdata[1]); break; default: $search->whereAddQuoted('uri', '=', $uri); } if ($search->find(true)) { if (!empty($_GET['o'])) { $thumb = new IC2_Thumbnailer(IC2_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 { $thumb = new IC2_Thumbnailer($thumb, $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 './conf/conf.inc.php'; require_once P2EX_LIB_DIR . '/ic2/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 IC2_DataObject_Images(); $thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_DEFAULT); if (preg_match('/^' . preg_quote($thumbnailer->sourcedir, '/') . '/', $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->srcPath($icdb->size, $icdb->md5, $icdb->mime); $x = (int) $icdb->width; $y = (int) $icdb->height; } else { $x = 0; $y = 0;
$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 IC2_Thumbnailer($thumb_type); $images = array(); foreach ($URLs as $url) { $icdb = new IC2_DataObject_Images(); $img_title = htmlspecialchars($url, ENT_QUOTES); $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"; // 既にキャッシュされているとき
$db_class = strtolower(get_class($db)); // サムネイル作成クラス $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'], P2KeyValueStore::CODEC_SERIALIZING); $cache_lifetime = (int) $ini['Viewer']['cache_lifetime']; if (array_key_exists('cache_clean', $_REQUEST)) { $cache_clear = $_REQUEST['cache_clean']; } else { $cache_clear = false; } $optimize_db = false; if ($cache_clear == 'all') { $kvs->clear(); $optimize_db = true; } elseif ($cache_clear == 'gc') { $kvs->gc($cache_lifetime); $optimize_db = true;