/** * ImageCache2 - メモから件数を取得する */ function getIC2ImageCount($key, $threshold = null) { require_once P2EX_LIB_DIR . '/ic2/bootstrap.php'; // 設定ファイル読み込み $ini = ic2_loadconfig(); $icdb = new IC2_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; }
$offtimer--; if ($offtimer < 0) { ic2_error(504); } } } // テンポラリファイルを作成、終了時に自動削除 $dl_lock_obj = new IC2TempFile($dl_lock_file); } // }}} // {{{ search // 画像がキャッシュされているか確認 $search = new IC2_DataObject_Images(); $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 ($key !== '') { $keys = explode(' ', $icdb->uniform($key, 'CP932', $field == 'memo')); 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) { p2die('ImageCache2 Warning', '「%または_」と「*または?」が混在するキーワードは使えません。'); } else {