コード例 #1
0
ファイル: ic2_getcount.inc.php プロジェクト: unpush/p2-php
/**
 * 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
 /**
  * コンストラクタ
  *
  * @param int $mode
  * @param array $dynamic_options
  */
 public function __construct($mode = self::SIZE_DEFAULT, array $dynamic_options = null)
 {
     if ($dynamic_options) {
         $options = array_merge($this->default_options, $dynamic_options);
         $this->dynamic = true;
         $this->intermd = $options['intermd'];
     } else {
         $options = $this->default_options;
         $this->dynamic = false;
         $this->intermd = false;
     }
     // 設定
     $this->ini = ic2_loadconfig();
     // データベースに接続
     $icdb = new IC2_DataObject_Images();
     $this->db = $icdb->getDatabaseConnection();
     if (DB::isError($this->db)) {
         $this->error($this->db->getMessage());
     }
     // サムネイルモード判定
     $dpr = $mode & self::DPR_MASK;
     $mode = $mode & ~self::DPR_MASK;
     if ($dpr === self::DPR_1_5 || $dpr === self::DPR_2_0) {
         $this->dpr = $dpr;
     } else {
         $this->dpr = $dpr = self::DPR_DEFAULT;
     }
     switch ($mode) {
         case self::SIZE_SOURCE:
         case self::SIZE_PC:
             $this->mode = self::SIZE_PC;
             $setting = $this->ini['Thumb1'];
             break;
         case self::SIZE_MOBILE:
             $this->mode = self::SIZE_MOBILE;
             $setting = $this->ini['Thumb2'];
             break;
         case self::SIZE_INTERMD:
             $this->mode = self::SIZE_INTERMD;
             $setting = $this->ini['Thumb3'];
             break;
         default:
             $this->error('無効なサムネイルモードです。');
     }
     // イメージドライバ判定
     $driver = strtolower($this->ini['General']['driver']);
     $this->driver = $driver;
     switch ($driver) {
         case 'imagemagick6':
             // ImageMagick6 の convert コマンド
             $this->driver = 'imagemagick';
         case 'imagemagick':
             // ImageMagick の convert コマンド
             $searchpath = $this->ini['General']['magick'];
             if (!ic2_findexec('convert', $searchpath)) {
                 $this->error('ImageMagickが使えません。');
             }
             if ($searchpath) {
                 $this->magick = $searchpath . DIRECTORY_SEPARATOR . 'convert';
             } else {
                 $this->magick = 'convert';
             }
             break;
         case 'gd':
             // PHP の GD 拡張機能
         // PHP の GD 拡張機能
         case 'imagick':
             // PHP の ImageMagick 拡張機能
         // PHP の ImageMagick 拡張機能
         case 'imlib2':
             // PHP の Imlib2 拡張機能
             if (!extension_loaded($driver)) {
                 $this->error($driver . 'エクステンションが使えません。');
             }
             break;
         default:
             $this->error('無効なイメージドライバです。');
     }
     // ディレクトリ設定
     $this->cachedir = $this->ini['General']['cachedir'];
     $this->sourcedir = $this->cachedir . '/' . $this->ini['Source']['name'];
     $this->thumbdir = $this->cachedir . '/' . $setting['name'];
     // サムネイルの画像形式・幅・高さ・回転角度・品質設定
     $rotate = (int) $options['rotate'];
     if (abs($rotate) < 4) {
         $rotate = $rotate * 90;
     }
     $rotate = $rotate < 0 ? $rotate % 360 + 360 : $rotate % 360;
     $this->rotate = $rotate % 90 == 0 ? $rotate : 0;
     if ($options['width'] >= 1 && $options['height'] >= 1) {
         $setting['width'] = $options['width'];
         $setting['height'] = $options['height'];
     }
     if ($this->rotate % 180 == 90) {
         $this->max_width = (int) $setting['height'];
         $this->max_height = (int) $setting['width'];
     } else {
         $this->max_width = (int) $setting['width'];
         $this->max_height = (int) $setting['height'];
     }
     if (is_null($options['quality'])) {
         $this->quality = (int) $setting['quality'];
     } else {
         $this->quality = (int) $options['quality'];
     }
     if (0 < $this->quality && $this->quality <= 100) {
         $this->type = '.jpg';
     } else {
         $this->type = '.png';
         $this->quality = 0;
     }
     $this->trim = (bool) $options['trim'];
     // Epeg使用判定
     if ($this->ini['General']['epeg'] && extension_loaded('epeg') && !$this->dynamic && $this->type == '.jpg' && $this->quality <= $this->ini['General']['epeg_quality_limit']) {
         $this->epeg = true;
     } else {
         $this->epeg = false;
     }
     // サムネイルの背景色設定
     if (preg_match('/^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i', $this->ini['General']['bgcolor'], $c)) {
         $r = hexdec($c[1]);
         $g = hexdec($c[2]);
         $b = hexdec($c[3]);
     } elseif (preg_match('/^#?([0-9A-F])([0-9A-F])([0-9A-F])$/i', $this->ini['General']['bgcolor'], $c)) {
         $r = hexdec($c[1] . $c[1]);
         $g = hexdec($c[2] . $c[2]);
         $b = hexdec($c[3] . $c[3]);
     } elseif (preg_match('/^(\\d{1,3}),(\\d{1,3}),(\\d{1,3})$/', $this->ini['General']['bgcolor'], $c)) {
         $r = max(0, min(intval($c[1]), 255));
         $g = max(0, min(intval($c[2]), 255));
         $b = max(0, min(intval($c[3]), 255));
     } else {
         $r = null;
         $g = null;
         $b = null;
     }
     $this->bgcolor = array($r, $g, $b);
 }
コード例 #3
0
ファイル: DatabaseManager.php プロジェクト: unpush/p2-php
 /**
  * メモを追加
  */
 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;');
     }
 }
コード例 #4
0
ファイル: iv2.php プロジェクト: unpush/p2-php
// サムネイルタイプ
$_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') {
        $kvs->gc($cache_lifetime);