Beispiel #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;
}
Beispiel #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;
}
Beispiel #3
0
 /**
  * スレッド表示オブジェクトにImageCache2で使う変数をアサインする
  */
 public static function initImageCache($aShowThread)
 {
     global $_conf;
     if (!$_conf['ktai']) {
         $aShowThread->thumb_id_suffix = '-' . strtr(microtime(), '. ', '--');
         $aShowThread->thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC);
     } else {
         $aShowThread->inline_prvw = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC);
         $aShowThread->thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_MOBILE);
     }
     if ($aShowThread->thumbnailer->ini['General']['automemo']) {
         $aShowThread->img_memo = IC2_DataObject_Images::staticUniform($aShowThread->thread->ttitle, 'CP932');
         $aShowThread->img_memo_query = '&amp;memo=' . rawurlencode($aShowThread->img_memo);
         $aShowThread->img_memo_query .= '&amp;' . $_conf['detect_hint_q_utf8'];
     } else {
         $aShowThread->img_memo = null;
         $aShowThread->img_memo_query = '';
     }
     self::loadClass('IC2_Switch', 'ic2/Switch.php');
     if (!IC2_Switch::get($_conf['ktai'])) {
         $GLOBALS['pre_thumb_limit'] = 0;
         $GLOBALS['pre_thumb_limit_k'] = 0;
         $GLOBALS['pre_thumb_unlimited'] = false;
         $GLOBALS['pre_thumb_ignore_limit'] = false;
         $_conf['expack.ic2.newres_ignore_limit'] = false;
         $_conf['expack.ic2.newres_ignore_limit_k'] = false;
     }
 }
Beispiel #4
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);
 }
Beispiel #5
0
$id = (int) $_GET['id'];
$rank = isset($_GET['rank']) ? (int) $_GET['rank'] : 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;
Beispiel #6
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;
 }
Beispiel #7
0
 /**
  * メモを追加
  */
 public static function addMemo($target, $memo)
 {
     if (empty($target)) {
         return;
     }
     if (!is_array($target)) {
         if (is_integer($updated) || ctype_digit($updated)) {
             $id = (int) $updated;
             if ($id > 0) {
                 $updated = array($id);
             } else {
                 return;
             }
         } else {
             P2Util::pushInfoHtml('<p>WARNING! IC2_DatabaseManager::addMemo(): 不正な引数</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) {
         $find = new IC2_DataObject_Images();
         $find->whereAdd("id = {$id}");
         if ($find->find(true) && strpos($find->memo, $memo) === false) {
             $update = new IC2_DataObject_Images();
             $update->whereAdd("id = {$id}");
             if (strlen($find->memo) > 0) {
                 $update->memo = $find->memo . ' ' . $memo;
             } else {
                 $update->memo = $memo;
             }
             $update->update();
             unset($update);
         }
         unset($find);
     }
     // トランザクションのコミット
     if ($db->phptype == 'pgsql') {
         $ta->query('COMMIT');
     } elseif ($db->phptype == 'sqlite') {
         $db->query('COMMIT;');
     }
 }
Beispiel #8
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;
}
Beispiel #9
0
// }}}
// {{{ HTTPヘッダ
P2Util::header_nocache();
header('Content-Type: application/json; charset=UTF-8');
// }}}
// {{{ 初期化
// パラメータを検証
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:
Beispiel #10
0
/**
 * 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;
Beispiel #11
0
$preset = isset($_GET['p']) ? $_GET['p'] : '';
if (!empty($preset)) {
    $ini = ic2_loadconfig();
    $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);
Beispiel #12
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;
 }
Beispiel #13
0
 /**
  * スレッド表示オブジェクトにImageCache2で使う変数をアサインする
  */
 public static function initImageCache($aShowThread)
 {
     global $_conf;
     $dpr = 1.0;
     if (!$_conf['ktai']) {
         $aShowThread->thumb_id_suffix = '-' . strtr(microtime(), '. ', '--');
         $aShowThread->thumbnailer = new IC2_Thumbnailer(IC2_Thumbnailer::SIZE_PC);
     } else {
         $preview_size = IC2_Thumbnailer::SIZE_PC;
         $thumb_size = IC2_Thumbnailer::SIZE_MOBILE;
         if ($_conf['iphone'] && !empty($_SESSION['device_pixel_ratio'])) {
             $dpr = $_SESSION['device_pixel_ratio'];
             if ($dpr === 1.5) {
                 $preview_size |= IC2_Thumbnailer::DPR_1_5;
                 $thumb_size |= IC2_Thumbnailer::DPR_1_5;
             } elseif ($dpr === 2.0) {
                 $preview_size |= IC2_Thumbnailer::DPR_2_0;
                 $thumb_size |= IC2_Thumbnailer::DPR_2_0;
             } else {
                 $dpr = 1.0;
             }
         }
         $aShowThread->inline_prvw = new IC2_Thumbnailer($preview_size);
         $aShowThread->thumbnailer = new IC2_Thumbnailer($thumb_size);
     }
     if ($aShowThread->thumbnailer->ini['General']['automemo']) {
         $aShowThread->img_memo = IC2_DataObject_Images::staticUniform($aShowThread->thread->ttitle, 'CP932');
         $aShowThread->img_memo_query = '&amp;memo=' . rawurlencode($aShowThread->img_memo);
         $aShowThread->img_memo_query .= '&amp;' . $_conf['detect_hint_q_utf8'];
     } else {
         $aShowThread->img_memo = null;
         $aShowThread->img_memo_query = '';
     }
     $aShowThread->img_dpr = $dpr;
     if ($dpr === 1.5 || $dpr === 2.0) {
         $aShowThread->img_dpr_query = '&amp;d=' . $dpr;
     } else {
         $aShowThread->img_dpr_query = '';
     }
     self::loadClass('IC2_Switch', 'ic2/Switch.php');
     if (!IC2_Switch::get($_conf['ktai'])) {
         $GLOBALS['pre_thumb_limit'] = 0;
         $GLOBALS['pre_thumb_limit_k'] = 0;
         $GLOBALS['pre_thumb_unlimited'] = false;
         $GLOBALS['pre_thumb_ignore_limit'] = false;
         $_conf['expack.ic2.newres_ignore_limit'] = false;
         $_conf['expack.ic2.newres_ignore_limit_k'] = false;
     }
 }
Beispiel #14
0
// {{{ 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";
            // 既にキャッシュされているとき
        } elseif ($icdb->get($url)) {
            $_src_url = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
            if (file_exists($_src_url)) {
Beispiel #15
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;
 }
Beispiel #16
0
$_mode = array('3' => 'サムネイルだけ', '0' => '一覧', '1' => '一括変更', '2' => '個別管理');
// サムネイルタイプ
$_thumbtype = array('1' => 'デフォ', '2' => '携帯', '3' => '中間');
// 携帯用に変換(フォームをパケット節約の対象外とするため)
if ($_conf['ktai']) {
    foreach ($_order as $_k => $_v) {
        $_order[$_k] = mb_convert_kana($_v, 'ask');
    }
    foreach ($_field as $_k => $_v) {
        $_field[$_k] = mb_convert_kana($_v, 'ask');
    }
}
// }}}
// {{{ prepare (DB & Cache)
// DB_DataObjectを継承したDAO
$icdb = new IC2_DataObject_Images();
$db = $icdb->getDatabaseConnection();
$db_class = strtolower(get_class($db));
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') {