/** * ImageCache2 - メモから件数を取得する */ function getIC2ImageCount($key, $threshold = null) { require_once P2EX_LIB_DIR . '/ImageCache2/bootstrap.php'; // 設定ファイル読み込み $ini = ic2_loadconfig(); $icdb = new ImageCache2_DataObject_Images(); // 閾値でフィルタリング if ($threshold === null) { $threshold = $ini['Viewer']['threshold']; } if (!($threshold == -1)) { $icdb->whereAddQuoted('rank', '>=', $threshold); } $db = $icdb->getDatabaseConnection(); $db_class = strtolower(get_class($db)); $keys = explode(' ', $icdb->uniform($key, 'CP932')); foreach ($keys as $k) { $operator = 'LIKE'; $wildcard = '%'; $not = false; if ($k[0] == '-' && strlen($k) > 1) { $not = true; $k = substr($k, 1); } if (strpos($k, '%') !== false || strpos($k, '_') !== false) { // SQLite2はLIKE演算子の右辺でバックスラッシュによるエスケープや // ESCAPEでエスケープ文字を指定することができないのでGLOB演算子を使う if ($db_class == 'db_sqlite') { if (strpos($k, '*') !== false || strpos($k, '?') !== false) { throw new InvalidArgumentException('「%または_」と「*または?」が混在するキーワードは使えません。'); } else { $operator = 'GLOB'; $wildcard = '*'; } } else { $k = preg_replace('/[%_]/', '\\\\$0', $k); } } $expr = $wildcard . $k . $wildcard; if ($not) { $operator = 'NOT ' . $operator; } $icdb->whereAddQuoted('memo', $operator, $expr); } $sql = sprintf('SELECT COUNT(*) FROM %s %s', $db->quoteIdentifier($ini['General']['table']), $icdb->_query['condition']); $all = $db->getOne($sql); if (DB::isError($all)) { throw new InvalidArgumentException($all->getMessage()); } return $all; }
} } } // テンポラリファイルを作成、終了時に自動削除 $dl_lock_obj = new IC2TempFile($dl_lock_file); } // }}} // {{{ search // 画像がキャッシュされているか確認 $search = new ImageCache2_DataObject_Images(); $filepath = null; $fileurl = null; $mtime = -1; $retry = false; if ($memo !== null) { $memo = $search->uniform($memo, 'CP932'); } if ($doDL) { $result = $search->get($uri); } else { if (isset($id)) { $search->whereAddQuoted('id', '=', $id); } else { $search->whereAddQuoted('size', '=', $fdata['size']); $search->whereAddQuoted('md5', '=', $fdata['md5']); } $result = $search->find(true); if (!$result) { ic2_error('404'); } $force = false;
} } } else { //$lightbox = ($mode == 0 || $mode == 3) ? $ini['Viewer']['lightbox'] : false; $lightbox = $ini['Viewer']['lightbox']; } // }}} // {{{ query $removed_files = array(); // 閾値でフィルタリング if (!($threshold == -1 && $compare == '>=')) { $icdb->whereAddQuoted('rank', $compare, $threshold); } // キーワード検索をするとき if ($keyword !== '') { $keywords = explode(' ', $icdb->uniform($keyword, 'CP932', $field == 'memo')); foreach ($keywords as $k) { $operator = 'LIKE'; $wildcard = '%'; $not = false; if ($k[0] == '-' && strlen($k) > 1) { $not = true; $k = substr($k, 1); } if (strpos($k, '%') !== false || strpos($k, '_') !== false) { // SQLite2はLIKE演算子の右辺でバックスラッシュによるエスケープや // ESCAPEでエスケープ文字を指定することができないのでGLOB演算子を使う if ($db_class == 'db_sqlite') { if (strpos($k, '*') !== false || strpos($k, '?') !== false) { p2die('ImageCache2 Warning', '「%または_」と「*または?」が混在するキーワードは使えません。'); } else {
/** * イメージキャッシュの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; }