Esempio n. 1
0
 public function ic2_errlog_lotate()
 {
     $ini = ic2_loadconfig();
     $error_log_num = $ini['General']['error_log_num'];
     if ($error_log_num > 0) {
         $q_table = $this->_db->quoteIdentifier($this->__table);
         $sql1 = 'SELECT COUNT(*) FROM ' . $q_table;
         $sql2 = 'SELECT MIN(occured) FROM ' . $q_table;
         $sql3 = 'DELETE FROM ' . $q_table . ' WHERE occured = ';
         while (($r1 = $this->_db->getOne($sql1)) > $error_log_num) {
             if (DB::isError($r1)) {
                 return $r1;
             }
             $r2 = $this->_db->getOne($sql2);
             if (DB::isError($r2)) {
                 return $r2;
             }
             $r3 = $this->_db->query($sql3 . $r2);
             if (DB::isError($r3)) {
                 return $r3;
             }
             if ($this->_db->affectedRows() == 0) {
                 break;
             }
         }
     }
     return DB_OK;
 }
Esempio n. 2
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;
}
Esempio n. 3
0
 /**
  * (non-PHPdoc)
  * @see Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->config = ic2_loadconfig();
     $this->dryRun = (bool) $input->getOption('check-only');
     $this->pgTrgm = $input->getOption('pg-trgm');
     $this->output = $output;
     if ($this->checkConfiguration()) {
         $result = $this->connect();
         if ($result) {
             $this->info('Database: OK');
             $this->serialPriamryKey = $result[0];
             $this->tableExtraDefs = $result[1];
             $this->createTables();
             $this->createIndexes();
         }
     }
 }
Esempio n. 4
0
 /**
  * コンストラクタ
  */
 public function __construct()
 {
     static $set_to_utf8 = false;
     // 設定の読み込み
     $ini = ic2_loadconfig();
     $this->_ini = $ini;
     if (!$ini['General']['dsn']) {
         p2die('DSNが設定されていません。');
     }
     // データベースへ接続
     $this->_database_dsn = $ini['General']['dsn'];
     $this->_db = $this->getDatabaseConnection();
     if (DB::isError($this->_db)) {
         p2die($this->_db->getMessage());
     }
     // クライアントの文字セットに UTF-8 を指定
     if (!$set_to_utf8) {
         if (preg_match('/^(\\w+)(?:\\((\\w+)\\))?:/', $this->_database_dsn, $m)) {
             $driver = strtolower($m[1]);
         } else {
             $driver = 'unknown';
         }
         switch ($driver) {
             case 'mysql':
             case 'mysqli':
                 if ($driver == 'mysql' && function_exists('mysql_set_charset')) {
                     mysql_set_charset('utf8', $this->_db->connection);
                 } elseif ($driver == 'mysqli' && function_exists('mysqli_set_charset')) {
                     mysqli_set_charset($this->_db->connection, 'utf8');
                 } else {
                     $this->_db->query("SET NAMES utf8");
                 }
                 break;
             case 'pgsql':
                 if (function_exists('pg_set_client_encoding')) {
                     pg_set_client_encoding($this->_db->connection, 'UNICODE');
                 } else {
                     $this->_db->query("SET CLIENT_ENCODING TO 'UNICODE'");
                 }
                 break;
         }
         $set_to_utf8 = true;
     }
 }
Esempio n. 5
0
// {{{ p2基本設定読み込み&認証
define('P2_OUTPUT_XHTML', 1);
require_once './conf/conf.inc.php';
$_login->authorize();
if (!$_conf['expack.ic2.enabled']) {
    p2die('ImageCache2は無効です。', 'conf/conf_admin_ex.inc.php の設定を変えてください。');
}
// }}}
// {{{ 初期化
// ライブラリ読み込み
require_once 'HTTP/Client.php';
require_once P2EX_LIB_DIR . '/ic2/bootstrap.php';
// 受け付けるMIMEタイプ
$mimemap = array('image/jpeg' => '.jpg', 'image/png' => '.png', 'image/gif' => '.gif');
// 設定ファイル読み込み
$ini = ic2_loadconfig();
// }}}
// {{{ prepare
// パラメータを設定
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$uri = isset($_REQUEST['uri']) ? $_REQUEST['uri'] : (isset($_REQUEST['url']) ? $_REQUEST['url'] : null);
$file = isset($_REQUEST['file']) ? $_REQUEST['file'] : null;
$force = !empty($_REQUEST['f']);
// 強制更新
$thumb = isset($_REQUEST['t']) ? intval($_REQUEST['t']) : IC2_Thumbnailer::SIZE_SOURCE;
// サムネイルタイプ
$dpr = isset($_REQUEST['d']) ? floatval($_REQUEST['d']) : 1.0;
// device pixel ratio
$redirect = isset($_REQUEST['r']) ? intval($_REQUEST['r']) : 1;
// 表示方法
$rank = isset($_REQUEST['rank']) ? intval($_REQUEST['rank']) : 0;
Esempio n. 6
0
    echo <<<EOP
<div id="read_new_footer">{$sb_ht_btm}の<a href="{$shinchaku_matome_url}"{$_conf['k_accesskey_at']['next']}>{$_conf['k_accesskey_st']['next']}{$str}</a>
<a class="button" id="bottom" name="bottom" href="#above"{$_conf['k_accesskey_at']['above']}>{$_conf['k_accesskey_st']['above']}▲</a></div>
<hr>
<div class="center">{$_conf['k_to_index_ht']}</div>
EOP;
}
// }}}
// iPhone
if ($_conf['iphone']) {
    // ImageCache2
    if ($_conf['expack.ic2.enabled']) {
        if (!function_exists('ic2_loadconfig')) {
            include P2EX_LIB_DIR . '/ic2/bootstrap.php';
        }
        $ic2conf = ic2_loadconfig();
        if ($ic2conf['Thumb1']['width'] > 80) {
            include P2EX_LIB_DIR . '/ic2/templates/info-v.tpl.html';
        } else {
            include P2EX_LIB_DIR . '/ic2/templates/info-h.tpl.html';
        }
    }
    // SPM
    if ($_conf['expack.spm.enabled']) {
        echo ShowThreadK::getSpmElementHtml();
    }
}
echo '</body></html>';
$matomeCache->concat(ob_get_flush());
// NGあぼーんを記録
NgAbornCtl::saveNgAborns();
Esempio n. 7
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;
 }
Esempio n. 8
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);
 }