示例#1
0
 /**
  * 画像を削除
  */
 public static function remove($target, $to_blacklist = false)
 {
     $ini = ic2_loadconfig();
     $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! ImageCache2_DatabaseManager::remove(): 不正な引数</p>');
             return $removed_files;
         }
     }
     // トランザクションの開始
     $ta = new ImageCache2_DataObject_Images();
     $db = $ta->getDatabaseConnection();
     if ($db->phptype == 'pgsql') {
         $ta->query('BEGIN');
     } elseif ($db->phptype == 'sqlite') {
         $db->query('BEGIN;');
     }
     // 画像を削除
     $parent_dir = dirname($ini['General']['cachedir']) . DIRECTORY_SEPARATOR;
     $pattern = '/^' . preg_quote($parent_dir, '/') . '/';
     foreach ($target as $id) {
         $icdb = new ImageCache2_DataObject_Images();
         $icdb->whereAdd("id = {$id}");
         if ($icdb->find(true)) {
             // キャッシュしているファイルを削除
             $sizes = array(ImageCache2_Thumbnailer::SIZE_PC, ImageCache2_Thumbnailer::SIZE_MOBILE, ImageCache2_Thumbnailer::SIZE_INTERMD);
             $dprs = array(ImageCache2_Thumbnailer::DPR_DEFAULT, ImageCache2_Thumbnailer::DPR_1_5, ImageCache2_Thumbnailer::DPR_2_0);
             foreach ($sizes as $size) {
                 foreach ($dprs as $dpr) {
                     $t = new ImageCache2_Thumbnailer($size | $dpr);
                     $path = $t->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
                     if (file_exists($path)) {
                         unlink($path);
                         $removed_files[] = preg_replace($pattern, '', $path);
                     }
                 }
             }
             $t = new ImageCache2_Thumbnailer();
             $path = $t->srcPath($icdb->size, $icdb->md5, $icdb->mime);
             if (file_exists($path)) {
                 unlink($path);
                 $removed_files[] = preg_replace($pattern, '', $path);
             }
             // ブラックリスト送りの準備
             if ($to_blacklist) {
                 $_blacklist = new ImageCache2_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 ImageCache2_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;
 }
示例#2
0
/**
 * イメージキャッシュの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 = '&amp;' . $_conf['detect_hint_q_utf8'];
            $img_memo_query .= '&amp;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&amp;uri=' . $url_en;
    $img_size = '';
    $thumb_url = 'ic2.php?r=2&amp;t=1&amp;uri=' . $url_en;
    $thumb_url2 = 'ic2.php?r=2&amp;t=1&amp;id=';
    $thumb_size = '';
    $thumb_k_url = 'ic2.php?r=0&amp;t=2&amp;uri=' . $url_en;
    $thumb_k_url2 = 'ic2.php?r=0&amp;t=1&amp;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;
}
示例#3
0
 $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_path = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
     if (file_exists($_src_path)) {
         $src_url = $thumbnailer->srcUrl($icdb->size, $icdb->md5, $icdb->mime);
     }
     $_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);
     }
     if (preg_match('/(\\d+)x(\\d+)/', $thumbnailer->calc($icdb->width, $icdb->height), $thumb_xy)) {
         $thumb_x = $thumb_xy[1];
         $thumb_y = $thumb_xy[2];
     }
     // メモが記録されていないときはDBを更新
     if (isset($new_memo) && strpos($icdb->memo, $new_memo) === false) {
         $update = clone $icdb;
         if (!is_null($icdb->memo) && strlen($icdb->memo) > 0) {
             $update->memo = $new_memo . ' ' . $icdb->memo;
         } else {
             $update->memo = $new_memo;
         }
示例#4
0
        if ($dpr === 1.5) {
            $thumb_type |= ImageCache2_Thumbnailer::DPR_1_5;
        } elseif ($dpr === 2.0) {
            $thumb_type |= ImageCache2_Thumbnailer::DPR_2_0;
        }
        $thumbnailer = new ImageCache2_Thumbnailer($thumb_type);
        break;
    default:
        $thumbnailer = new ImageCache2_Thumbnailer();
        $calculator = $thumbnailer;
}
$size = (int) $icdb->size;
$md5 = $icdb->md5;
$mime = $icdb->mime;
$srcPath = $thumbnailer->srcPath($size, $md5, $mime);
$thumbPath = $thumbnailer->thumbPath($size, $md5, $mime);
$srcUrl = $thumbnailer->srcUrl($size, $md5, $mime);
$thumbUrl = $thumbnailer->thumbUrl($size, $md5, $mime);
$width = (int) $icdb->width;
$height = (int) $icdb->height;
list($thumbWidth, $thumbHeight) = $calculator->calc($width, $height, true);
echo json_encode(array('id' => (int) $icdb->id, 'uri' => $icdb->uri, 'host' => $icdb->host, 'name' => $icdb->name, 'size' => $size, 'md5' => $md5, 'width' => (int) $icdb->width, 'height' => (int) $icdb->height, 'mime' => $mime, 'rank' => (int) $icdb->rank, 'time' => (int) $icdb->time, 'memo' => $icdb->memo, 'url' => $icdb->uri, 'src' => $srcPath && file_exists($srcPath) ? $srcUrl : null, 'thumb' => $thumbPath && file_exists($thumbPath) ? $thumbUrl : null, 'thumbWidth' => $thumbWidth, 'thumbHeight' => $thumbHeight));
exit;
// }}}
/*
 * Local Variables:
 * mode: php
 * coding: cp932
 * tab-width: 4
 * c-basic-offset: 4
 * indent-tabs-mode: nil