示例#1
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;
}
示例#2
0
    exit;
}
$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);
示例#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
 /**
  * メモを追加
  */
 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;');
     }
 }
示例#5
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;
}
示例#6
0
    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:
        $thumbnailer = new IC2_Thumbnailer();
}
$src = $thumbnailer->srcPath($icdb->size, $icdb->md5, $icdb->mime);
$thumb = $thumbnailer->thumbPath($icdb->size, $icdb->md5, $icdb->mime);
示例#7
0
// }}}
// {{{ 画像を検索・サムネイルを作成
$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;のローカルキャッシュがありません。");
        } else {
            ic2_mkthumb_success(basename($src), $search->mime, $src, true, $attachment);
        }
    } else {
        $thumb = new IC2_Thumbnailer($thumb, $options);
        $result = $thumb->convert($search->size, $search->md5, $search->mime, $search->width, $search->height);
        if (PEAR::isError($result)) {
            ic2_mkthumb_error($result->getMessage());
        } else {
            $mime = $thumb->type == '.png' ? 'image/png' : 'image/jpeg';
示例#8
0
文件: iv2.php 项目: unpush/p2-php
         // 32400 = 9*60*60 (時差補正)
         $time2date = sprintf('floor((%s + 32400) / 86400)', $db->quoteIdentifier('time'));
     }
     $orderBy = sprintf('%s %s, %s ', $time2date, $sort, $db->quoteIdentifier('uri'));
     if ($order == 'date_uri') {
         $orderBy .= $sort;
     } else {
         $orderBy .= $sort == 'ASC' ? 'DESC' : 'ASC';
     }
 } else {
     $orderBy = $db->quoteIdentifier($order) . ' ' . $sort;
 }
 $orderBy .= ' , id ' . $sort;
 $icdb->orderBy($orderBy);
 $icdb->limit($from, $ipp);
 $found = $icdb->find();
 // テーブルのブロックに表示する値を取得&オブジェクトに代入
 $flexy->setData('all', $all);
 $flexy->setData('cols', $cols);
 $flexy->setData('last', $last_page);
 $flexy->setData('from', $from + 1);
 $flexy->setData('to', $from + $found);
 $flexy->setData('submit', array());
 $flexy->setData('reset', array());
 if ($_conf['ktai']) {
     $show_exif = false;
     $popup = false;
     $r_type = $ini['General']['redirect'] == 1 ? 1 : 2;
 } else {
     switch ($mode) {
         case 3: