示例#1
0
/**
 * 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;
}
示例#2
0
function ic2_checkAbornedFile($tmpfile, $params)
{
    global $ini;
    extract($params);
    // ブラックリスト検索
    $bl_check = new IC2_DataObject_BlackList();
    $bl_check->whereAddQuoted('size', '=', $size);
    $bl_check->whereAddQuoted('md5', '=', $md5);
    if ($bl_check->find(true)) {
        $bl_add = clone $bl_check;
        $bl_add->id = null;
        $bl_add->uri = $uri;
        switch ((int) $bl_check->type) {
            case 0:
                $errcode = 'x05';
                // No More
                break;
            case 1:
                $errcode = 'x01';
                // Aborn
                break;
            case 2:
                $errcode = 'x04';
                // Virus
                break;
            default:
                $errcode = 'x06';
                // Unknown
        }
        // 厳密には、その可能性が限りなく高いだけで100%ではない
        ic2_error($errcode, 'ブラックリストにある画像と同じ内容です。', false);
    }
    // あぼーん画像検索
    $check = new IC2_DataObject_Images();
    $check->whereAddQuoted('size', '=', $size);
    $check->whereAddQuoted('md5', '=', $md5);
    //$check->whereAddQuoted('mime', '=', $mime); // SizeとMD5で十分
    // 同じのが異なるURLで複数登録されていて、ランクが違う可能性があるので
    // (普通に使う分には起こらない...と思う。少なくとも起こりにくいはず)
    $check->orderByArray(array('rank' => 'ASC'));
    if ($check->find(true)) {
        if ($check->rank < 0) {
            ic2_aborn($params);
            // 現状では(たぶんずっと) -1 or -4 だけだが、一応
            if ($check->rank >= -5) {
                $errcode = 'x0' . abs($check->rank);
            } else {
                $errcode = 'x06';
                // Unknown
            }
            // 厳密には、以下同文
            if ($check->rank == -4) {
                $errmsg = 'ウィルスに感染していた画像と同じ内容です。';
            } else {
                $errmsg = '既にあぼーんされている画像と同じ内容です。';
            }
            ic2_error($errcode, $errmsg);
        } else {
            return $check->rank;
        }
    }
    return false;
}
示例#3
0
 /**
  * 画像1000枚ごとにインクリメントするディレクトリIDを取得
  */
 public function dirID($size = null, $md5 = null, $mime = null)
 {
     if ($size && $md5 && $mime) {
         $icdb = new IC2_DataObject_Images();
         $icdb->whereAddQUoted('size', '=', $size);
         $icdb->whereAddQuoted('md5', '=', $md5);
         $icdb->whereAddQUoted('mime', '=', $mime);
         $icdb->orderByArray(array('id' => 'ASC'));
         if ($icdb->find(true)) {
             $this->found = $icdb->toArray();
             return str_pad(ceil($icdb->id / 1000), 5, 0, STR_PAD_LEFT);
         }
     }
     $sql = 'SELECT MAX(' . $this->db->quoteIdentifier('id') . ') + 1 FROM ' . $this->db->quoteIdentifier($this->ini['General']['table']) . ';';
     $nextid = $this->db->getOne($sql);
     if (DB::isError($nextid) || !$nextid) {
         $nextid = 1;
     }
     return str_pad(ceil($nextid / 1000), 5, 0, STR_PAD_LEFT);
 }
示例#4
0
if ($id <= 0 || $rank > 5 || $rank < -1 && !($remove && $rank == -5)) {
    echo '0';
    exit;
}
// ライブラリ読み込み
require_once P2EX_LIB_DIR . '/ic2/bootstrap.php';
// }}}
// {{{ execute
$finder = new IC2_DataObject_Images();
$finder->whereAdd(sprintf('id = %d', $id));
$code = -1;
if ($finder->find(1)) {
    if ($rank != -5) {
        $setter = new IC2_DataObject_Images();
        $setter->rank = $rank;
        $setter->whereAddQuoted('size', '=', $finder->size);
        $setter->whereAddQuoted('md5', '=', $finder->md5);
        $setter->whereAddQuoted('mime', '=', $finder->mime);
        if ($setter->update()) {
            $code = 1;
        } else {
            $code = 0;
        }
    }
    if ($remove) {
        $orig_info_msg_ht = P2Util::getInfoHtml();
        $removed_files = IC2_DatabaseManager::remove(array($finder->id), $rank < 0);
        if ($code != 0 && !P2Util::hasInfoHtml()) {
            $code = 1;
        } else {
            $code = 0;
示例#5
0
 /**
  * 置換画像URL+ImageCache2
  */
 function plugin_replaceImageURL($url, $purl, $str)
 {
     global $_conf;
     global $pre_thumb_unlimited, $pre_thumb_ignore_limit, $pre_thumb_limit;
     static $serial = 0;
     // +Wiki
     global $replaceimageurl;
     $url = $purl[0];
     $replaced = $replaceimageurl->replaceImageURL($url);
     if (!$replaced[0]) {
         return FALSE;
     }
     foreach ($replaced as $v) {
         $url_en = rawurlencode($v['url']);
         $url_ht = htmlspecialchars($v['url'], ENT_QUOTES);
         $ref_en = $v['referer'] ? '&amp;ref=' . rawurlencode($v['referer']) : '';
         // 準備
         $serial++;
         $thumb_id = 'thumbs' . $serial . $this->thumb_id_suffix;
         $tmp_thumb = './img/ic_load.png';
         $icdb = new IC2_DataObject_Images();
         // r=0:リンク;r=1:リダイレクト;r=2:PHPで表示
         // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ
         // +Wiki
         $img_url = 'ic2.php?r=1&amp;uri=' . $url_en . $ref_en;
         $thumb_url = 'ic2.php?r=1&amp;t=1&amp;uri=' . $url_en . $ref_en;
         // お気にスレ自動画像ランク
         $rank = null;
         if ($_conf['expack.ic2.fav_auto_rank']) {
             $rank = $this->getAutoFavRank();
             if ($rank !== null) {
                 $thumb_url .= '&rank=' . $rank;
             }
         }
         // DBに画像情報が登録されていたとき
         if ($icdb->get($v['url'])) {
             // ウィルスに感染していたファイルのとき
             if ($icdb->mime == 'clamscan/infected') {
                 $result .= "<img class=\"thumbnail\" src=\"./img/x04.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             // あぼーん画像のとき
             if ($icdb->rank < 0) {
                 $result .= "<img class=\"thumbnail\" src=\"./img/x01.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             // オリジナルがキャッシュされているときは画像を直接読み込む
             $_img_url = $this->thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_img_url)) {
                 $img_url = $_img_url;
                 $cached = true;
             } else {
                 $cached = false;
             }
             // サムネイルが作成されていているときは画像を直接読み込む
             $_thumb_url = $this->thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_thumb_url)) {
                 $thumb_url = $_thumb_url;
                 // 自動スレタイメモ機能がONでスレタイが記録されていないときはDBを更新
                 if (!is_null($this->img_memo) && strpos($icdb->memo, $this->img_memo) === false) {
                     $update = new IC2_DataObject_Images();
                     if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
                         $update->memo = $this->img_memo . ' ' . $icdb->memo;
                     } else {
                         $update->memo = $this->img_memo;
                     }
                     $update->whereAddQuoted('uri', '=', $v['url']);
                 }
                 // expack.ic2.fav_auto_rank_override の設定とランク条件がOKなら
                 // お気にスレ自動画像ランクを上書き更新
                 if ($rank !== null && self::isAutoFavRankOverride($icdb->rank, $rank)) {
                     if ($update === null) {
                         $update = new IC2_DataObject_Images();
                         $update->whereAddQuoted('uri', '=', $v['url']);
                     }
                     $update->rank = $rank;
                 }
                 if ($update !== null) {
                     $update->update();
                 }
             }
             // サムネイルの画像サイズ
             $thumb_size = $this->thumbnailer->calc($icdb->width, $icdb->height);
             $thumb_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_size);
             $tmp_thumb = './img/ic_load1.png';
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             // 画像がキャッシュされていないとき
             // 自動スレタイメモ機能がONならクエリにUTF-8エンコードしたスレタイを含める
         } else {
             // 画像がブラックリストorエラーログにあるか確認
             if (false !== ($errcode = $icdb->ic2_isError($v['url']))) {
                 $result .= "<img class=\"thumbnail\" src=\"./img/{$errcode}.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
                 continue;
             }
             $cached = false;
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             $img_url .= $this->img_memo_query;
             $thumb_url .= $this->img_memo_query;
             $thumb_size = '';
             $tmp_thumb = './img/ic_load2.png';
         }
         // キャッシュされておらず、表示数制限が有効のとき
         if (!$cached && !$pre_thumb_unlimited && !$pre_thumb_ignore_limit) {
             // 表示制限を超えていたら、表示しない
             // 表示制限を超えていなければ、表示制限カウンタを下げる
             if ($pre_thumb_limit <= 0) {
                 $show_thumb = false;
             } else {
                 $show_thumb = true;
                 $pre_thumb_limit--;
             }
         } else {
             $show_thumb = true;
         }
         // 表示モード
         if ($show_thumb) {
             $img_tag = "<img class=\"thumbnail\" src=\"{$thumb_url}\" {$thumb_size} hspace=\"4\" vspace=\"4\" align=\"middle\">";
             if ($_conf['iframe_popup']) {
                 $view_img = $this->imageHtmlPopup($img_url, $img_tag, '');
             } else {
                 $view_img = "<a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$img_tag}</a>";
             }
         } else {
             $img_tag = "<img id=\"{$thumb_id}\" class=\"thumbnail\" src=\"{$tmp_thumb}\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
             $view_img = "<a href=\"{$img_url}\" onclick=\"return loadThumb('{$thumb_url}','{$thumb_id}')\"{$_conf['ext_win_target_at']}>{$img_tag}</a><a href=\"{$img_url}\"{$_conf['ext_win_target_at']}></a>";
         }
         $view_img .= '<img class="ic2-info-opener" src="img/s2a.png" width="16" height="16" onclick="ic2info.show(' . "'{$url_ht}', event)\">";
         $result .= $view_img;
     }
     // ソースへのリンクをime付きで表示
     $ime_url = P2Util::throughIme($url);
     $result .= "<a class=\"img_through_ime\" href=\"{$ime_url}\"{$_conf['ext_win_target_at']}>{$str}</a>";
     return $result;
 }
示例#6
0
 /**
  * 画像を削除
  */
 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;
 }
示例#7
0
/**
 * アップロードされた画像ファイルをDBに登録する。
 * 成功したときはファイル情報(配列)を、
 * 失敗したときはエラーメッセージ(文字列)を返す。
 */
function ic2_register_uploaded_file($file)
{
    global $_conf, $ini, $err_fmt;
    global $thumbnailer;
    global $f_host, $f_time, $f_memo, $f_rank;
    $utf8_path = mb_convert_encoding($file['path'], 'UTF-8', 'CP932');
    $utf8_name = mb_convert_encoding($file['name'], 'UTF-8', 'CP932');
    $file['path'] = htmlspecialchars($file['path'], ENT_QUOTES);
    $file['name'] = htmlspecialchars($file['name'], ENT_QUOTES);
    $file['memo'] = $f_memo;
    $file['rank'] = $f_rank;
    $file['img_src'] = $thumbnailer->srcPath($file['size'], $file['md5'], $file['mime']);
    $file['thumb'] = $thumbnailer->thumbPath($file['size'], $file['md5'], $file['mime']);
    if (!file_exists($file['thumb'])) {
        $file['thumb'] = 'ic2.php?r=1&t=1&file=' . $file['size'] . '_' . $file['md5'];
    }
    if (preg_match('/(\\d+)x(\\d+)/', $thumbnailer->calc($file['width'], $file['height']), $thumb_xy)) {
        $file['thumb_x'] = $thumb_xy[1];
        $file['thumb_y'] = $thumb_xy[2];
    }
    // 既存の画像か検索
    $search1 = new IC2_DataObject_Images();
    $search1->whereAddQuoted('size', '=', $file['size']);
    $search1->whereAddQuoted('md5', '=', $file['md5']);
    $search1->whereAddQuoted('mime', '=', $file['mime']);
    $search2 = clone $search1;
    $search1->whereAddQuoted('uri', '=', $utf8_path);
    // 全く同じ画像が登録されていたとき
    if ($search1->find(TRUE)) {
        $update = clone $search1;
        $changed = FALSE;
        if (strlen($f_memo) > 0 && strpos($search1->memo, $f_memo) === false) {
            if (!is_null($search1->memo) && strlen($search1->memo) > 0) {
                $update->memo = $f_memo . ' ' . $search1->memo;
            } else {
                $update->memo = $f_memo;
            }
            $file['memo'] = mb_convert_encoding($update->memo, 'CP932', 'UTF-8');
            $changed = TRUE;
        }
        if ($search1->rank != $f_rank) {
            $update->rank = $f_rank;
            $changed = TRUE;
        }
        if ($changed) {
            $update->update();
        }
        $file['message'] = '同じ画像が登録されていました。';
        if ($changed) {
            $file['message'] .= '(ステータスの更新あり)';
        }
    } else {
        $record = new IC2_DataObject_Images();
        $record->uri = $utf8_path;
        $record->host = $f_host;
        $record->name = $utf8_name;
        $record->size = $file['size'];
        $record->md5 = $file['md5'];
        $record->width = $file['width'];
        $record->height = $file['height'];
        $record->mime = $file['mime'];
        $record->time = $f_time;
        $record->rank = $f_rank;
        if (strlen($f_memo) > 0) {
            $record->memo = $f_memo;
        }
        // 登録済みの画像で、URLが異なるとき
        if ($search2->find(TRUE) && file_exists($file['img_src'])) {
            $record->insert();
            $file['message'] = '同じ画像が異なるURLで登録されていました。';
            // 未登録の画像だったとき
        } else {
            $newdir = dirname($file['img_src']);
            if (!is_dir($newdir) && !@mkdir($newdir)) {
                return sprintf($err_fmt['dir'], $file['path'], $newdir);
            }
            if (!@move_uploaded_file($file['tmp_name'], $file['img_src'])) {
                return sprintf($err_fmt['file'], $file['path'], $file['tmp_name'], $file['img_src']);
            }
            $record->insert();
            $file['message'] = 'アップロード成功。';
        }
    }
    return $file;
}
示例#8
0
// }}}
// {{{ 初期化
// パラメータを検証
if (!isset($_GET['id']) && !isset($_GET['url']) && !isset($_GET['md5'])) {
    echo 'null';
    exit;
}
// ライブラリ読み込み
require_once P2EX_LIB_DIR . '/ic2/bootstrap.php';
// }}}
// {{{ execute
$icdb = new IC2_DataObject_Images();
if (isset($_GET['id'])) {
    $icdb->whereAdd(sprintf('id=%d', (int) $_GET['id']));
} elseif (isset($_GET['url'])) {
    $icdb->whereAddQuoted('uri', '=', (string) $_GET['url']);
} 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:
示例#9
0
    $preset = $_GET['p'];
    if (isset($ini['Dynamic']['presets'][$preset])) {
        $options['width'] = $ini['Dynamic']['presets'][$preset][0];
        $options['height'] = $ini['Dynamic']['presets'][$preset][1];
        if (isset($ini['Dynamic']['presets'][$preset][2])) {
            $options['quality'] = $ini['Dynamic']['presets'][$preset][2];
        }
    }
}
$attachment = !empty($_GET['z']);
// }}}
// {{{ 画像を検索・サムネイルを作成
$search = new IC2_DataObject_Images();
switch ($type) {
    case 'id':
        $search->whereAddQuoted('id', '=', $uri);
        break;
    case 'file':
        preg_match('/^([1-9][0-9]*)_([0-9a-f]{32})(?:\\.(jpg|png|gif))?$/', $uri, $fdata);
        $search->whereAddQuoted('size', '=', $fdata[0]);
        $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("&quot;{$uri}&quot;のローカルキャッシュがありません。");
示例#10
0
 /**
  * 画像URLのImageCache2変換
  */
 public function plugin_imageCache2($url, $purl, $str)
 {
     global $_conf;
     global $pre_thumb_unlimited, $pre_thumb_ignore_limit, $pre_thumb_limit_k;
     if (P2Util::isUrlWikipediaJa($url)) {
         return false;
     }
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $purl[0]) && empty($purl['query'])) {
         // インラインプレビューの有効判定
         if ($pre_thumb_unlimited || $pre_thumb_ignore_limit || $pre_thumb_limit_k > 0) {
             $inline_preview_flag = true;
             $inline_preview_done = false;
         } else {
             $inline_preview_flag = false;
             $inline_preview_done = false;
         }
         $url_ht = $url;
         $url = $purl[0];
         $url_en = rawurlencode($url);
         $img_str = null;
         $img_id = null;
         $icdb = new IC2_DataObject_Images();
         // r=0:リンク;r=1:リダイレクト;r=2:PHPで表示
         // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ
         $img_url = 'ic2.php?r=0&amp;t=2&amp;uri=' . $url_en;
         $img_url2 = 'ic2.php?r=0&amp;t=2&amp;id=';
         $src_url = 'ic2.php?r=1&amp;t=0&amp;uri=' . $url_en;
         $src_url2 = 'ic2.php?r=1&amp;t=0&amp;id=';
         $src_exists = false;
         // DBに画像情報が登録されていたとき
         if ($icdb->get($url)) {
             $img_id = $icdb->id;
             // ウィルスに感染していたファイルのとき
             if ($icdb->mime == 'clamscan/infected') {
                 return '[IC2:ウィルス警告]';
             }
             // あぼーん画像のとき
             if ($icdb->rank < 0) {
                 return '[IC2:あぼーん画像]';
             }
             // オリジナルの有無を確認
             $_src_url = $this->thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_src_url)) {
                 $src_exists = true;
                 $img_url = $img_url2 . $icdb->id;
                 $src_url = $_src_url;
             } else {
                 $img_url = $this->thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
                 $src_url = $src_url2 . $icdb->id;
             }
             // インラインプレビューが有効のとき
             $prv_url = null;
             if ($this->thumbnailer->ini['General']['inline'] == 1) {
                 // PCでread_new_k.phpにアクセスしたとき等
                 if (!isset($this->inline_prvw) || !is_object($this->inline_prvw)) {
                     $this->inline_prvw = $this->thumbnailer;
                 }
                 $prv_url = $this->inline_prvw->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
                 // サムネイル表示制限数以内のとき
                 if ($inline_preview_flag) {
                     // プレビュー画像が作られているかどうかでimg要素の属性を決定
                     if (file_exists($prv_url)) {
                         $prv_size = explode('x', $this->inline_prvw->calc($icdb->width, $icdb->height));
                         $img_str = "<img src=\"{$prv_url}\" width=\"{$prv_size[0]}\" height=\"{$prv_size[1]}\">";
                     } else {
                         $r_type = $this->thumbnailer->ini['General']['redirect'] == 1 ? 1 : 2;
                         if ($src_exists) {
                             $prv_url = "ic2.php?r={$r_type}&amp;t=1&amp;id={$icdb->id}";
                         } else {
                             $prv_url = "ic2.php?r={$r_type}&amp;t=1&amp;uri={$url_en}";
                         }
                         $prv_url .= $this->img_dpr_query;
                         if ($this->img_dpr === 1.5 || $this->img_dpr === 2.0) {
                             $prv_onload = " onload=\"this.width=parseInt((this.width/{$this->img_dpr}).toString());" . "this.height=parseInt((this.height/{$this->img_dpr}).toString());\"";
                         } else {
                             $prv_onload = '';
                         }
                         $img_str = "<img src=\"{$prv_url}\"{$prv_onload}>";
                     }
                     $inline_preview_done = true;
                 } else {
                     $img_str = '[p2:既得画像(ランク:' . $icdb->rank . ')]';
                 }
             }
             // 自動スレタイメモ機能がONでスレタイが記録されていないときはDBを更新
             if (!is_null($this->img_memo) && strpos($icdb->memo, $this->img_memo) === false) {
                 $update = new IC2_DataObject_Images();
                 if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
                     $update->memo = $this->img_memo . ' ' . $icdb->memo;
                 } else {
                     $update->memo = $this->img_memo;
                 }
                 $update->whereAddQuoted('uri', '=', $url);
                 $update->update();
             }
             // 画像がキャッシュされていないとき
             // 自動スレタイメモ機能がONならクエリにUTF-8エンコードしたスレタイを含める
         } else {
             // 画像がブラックリストorエラーログにあるか確認
             if (false !== ($errcode = $icdb->ic2_isError($url))) {
                 return "<s>[IC2:エラー({$errcode})]</s>";
             }
             // インラインプレビューが有効で、サムネイル表示制限数以内なら
             if ($this->thumbnailer->ini['General']['inline'] == 1 && $inline_preview_flag) {
                 $img_str = "<img src=\"ic2.php?r=2&amp;t=1&amp;uri={$url_en}{$this->img_memo_query}\">";
                 $inline_preview_done = true;
             } else {
                 $img_url .= $this->img_memo_query;
             }
         }
         // 表示数制限をデクリメント
         if ($inline_preview_flag && $inline_preview_done) {
             $pre_thumb_limit_k--;
         }
         if (!empty($_SERVER['REQUEST_URI'])) {
             $backto = '&amp;from=' . rawurlencode($_SERVER['REQUEST_URI']);
         } else {
             $backto = '';
         }
         if (is_null($img_str)) {
             return sprintf('<a href="%s%s">[IC2:%s:%s]</a>', $img_url, $backto, htmlspecialchars($purl['host'], ENT_QUOTES), htmlspecialchars(basename($purl['path']), ENT_QUOTES));
         }
         if ($_conf['iphone']) {
             $img_title = htmlspecialchars($purl['host'], ENT_QUOTES) . '&#10;' . htmlspecialchars(basename($purl['path']), ENT_QUOTES);
             return "<a class=\"limelight\" href=\"{$src_url}\" title=\"{$img_title}\" target=\"_blank\">{$img_str}</a>" . ' <input type="button" class="ic2-show-info" value="i" onclick="ic2info.show(' . ($img_id ? $img_id : "'{$url_ht}'") . ', event)">';
         } else {
             return "<a href=\"{$img_url}{$backto}\">{$img_str}</a>";
         }
     }
     return false;
 }
示例#11
0
 /**
  * ImageCache2サムネイル変換
  *
  * @param   string $url
  * @param   array $purl
  * @param   string $str
  * @return  string|false
  */
 public function plugin_imageCache2($url, $purl, $str)
 {
     global $_conf;
     global $pre_thumb_unlimited, $pre_thumb_ignore_limit, $pre_thumb_limit;
     static $serial = 0;
     if (P2Util::isUrlWikipediaJa($url)) {
         return false;
     }
     if (preg_match('{^https?://.+?\\.(jpe?g|gif|png)$}i', $purl[0]) && empty($purl['query'])) {
         // 準備
         $serial++;
         $thumb_id = 'thumbs' . $serial . $this->thumb_id_suffix;
         $tmp_thumb = './img/ic_load.png';
         $url_ht = $url;
         $url = $purl[0];
         $url_en = rawurlencode($url);
         $img_id = null;
         $icdb = new IC2_DataObject_Images();
         // r=0:リンク;r=1:リダイレクト;r=2:PHPで表示
         // t=0:オリジナル;t=1:PC用サムネイル;t=2:携帯用サムネイル;t=3:中間イメージ
         $img_url = 'ic2.php?r=1&amp;uri=' . $url_en;
         $thumb_url = 'ic2.php?r=1&amp;t=1&amp;uri=' . $url_en;
         // DBに画像情報が登録されていたとき
         if ($icdb->get($url)) {
             $img_id = $icdb->id;
             // ウィルスに感染していたファイルのとき
             if ($icdb->mime == 'clamscan/infected') {
                 return "<img class=\"thumbnail\" src=\"./img/x04.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             // あぼーん画像のとき
             if ($icdb->rank < 0) {
                 return "<img class=\"thumbnail\" src=\"./img/x01.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             // オリジナルがキャッシュされているときは画像を直接読み込む
             $_img_url = $this->thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_img_url)) {
                 $img_url = $_img_url;
                 $cached = true;
             } else {
                 $cached = false;
             }
             // サムネイルが作成されていているときは画像を直接読み込む
             $_thumb_url = $this->thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($_thumb_url)) {
                 $thumb_url = $_thumb_url;
                 // 自動スレタイメモ機能がONでスレタイが記録されていないときはDBを更新
                 if (!is_null($this->img_memo) && strpos($icdb->memo, $this->img_memo) === false) {
                     $update = new IC2_DataObject_Images();
                     if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
                         $update->memo = $this->img_memo . ' ' . $icdb->memo;
                     } else {
                         $update->memo = $this->img_memo;
                     }
                     $update->whereAddQuoted('uri', '=', $url);
                     $update->update();
                 }
             }
             // サムネイルの画像サイズ
             $thumb_size = $this->thumbnailer->calc($icdb->width, $icdb->height);
             $thumb_size = preg_replace('/(\\d+)x(\\d+)/', 'width="$1" height="$2"', $thumb_size);
             $tmp_thumb = './img/ic_load1.png';
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             // 画像がキャッシュされていないとき
             // 自動スレタイメモ機能がONならクエリにUTF-8エンコードしたスレタイを含める
         } else {
             // 画像がブラックリストorエラーログにあるか確認
             if (false !== ($errcode = $icdb->ic2_isError($url))) {
                 return "<img class=\"thumbnail\" src=\"./img/{$errcode}.png\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\"> <s>{$str}</s>";
             }
             $cached = false;
             $orig_img_url = $img_url;
             $orig_thumb_url = $thumb_url;
             $img_url .= $this->img_memo_query;
             $thumb_url .= $this->img_memo_query;
             $thumb_size = '';
             $tmp_thumb = './img/ic_load2.png';
         }
         // キャッシュされておらず、表示数制限が有効のとき
         if (!$cached && !$pre_thumb_unlimited && !$pre_thumb_ignore_limit) {
             // 表示制限を超えていたら、表示しない
             // 表示制限を超えていなければ、表示制限カウンタを下げる
             if ($pre_thumb_limit <= 0) {
                 $show_thumb = false;
             } else {
                 $show_thumb = true;
                 $pre_thumb_limit--;
             }
         } else {
             $show_thumb = true;
         }
         // 表示モード
         if ($show_thumb) {
             $img_tag = "<img class=\"thumbnail\" src=\"{$thumb_url}\" {$thumb_size} hspace=\"4\" vspace=\"4\" align=\"middle\">";
             if ($_conf['iframe_popup']) {
                 $view_img = $this->imageHtmlPopup($img_url, $img_tag, $str);
             } else {
                 $view_img = "<a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$img_tag}{$str}</a>";
             }
         } else {
             $img_tag = "<img id=\"{$thumb_id}\" class=\"thumbnail\" src=\"{$tmp_thumb}\" width=\"32\" height=\"32\" hspace=\"4\" vspace=\"4\" align=\"middle\">";
             $view_img = "<a href=\"{$img_url}\" onclick=\"return loadThumb('{$thumb_url}','{$thumb_id}')\"{$_conf['ext_win_target_at']}>{$img_tag}</a><a href=\"{$img_url}\"{$_conf['ext_win_target_at']}>{$str}</a>";
         }
         // ソースへのリンクをime付きで表示
         if ($_conf['expack.ic2.enabled'] && $_conf['expack.ic2.through_ime']) {
             $ime_url = P2Util::throughIme($url);
             if ($_conf['iframe_popup'] == 3) {
                 $ime_mark = '<img src="img/ime.png" width="22" height="12" alt="">';
             } else {
                 $ime_mark = '[ime]';
             }
             $view_img .= " <a class=\"img_through_ime\" href=\"{$ime_url}\"{$_conf['ext_win_target_at']}>{$ime_mark}</a>";
         }
         $view_img .= '<img class="ic2-info-opener" src="img/s2a.png" width="16" height="16" onclick="ic2info.show(' . ($img_id ? $img_id : "'{$url_ht}'") . ', event)">';
         return $view_img;
     }
     return false;
 }
示例#12
0
文件: iv2.php 项目: unpush/p2-php
        foreach ($overwritable_params as $ow_key) {
            if (isset($_SESSION['iv2i_filter'][$ow_key])) {
                ${$ow_key} = $_SESSION['iv2i_filter'][$ow_key];
            }
        }
    }
} 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演算子を使う