GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — p2-php/iv2.php at master · thermon/p2-php Expand file tree/ Copy pathiv2.phpMore file actions 1066 lines (965 loc) · 37.8 KB / Copy pathiv2.phpFile metadata and controls1066 lines (965 loc) · 37.8 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 <?php /** * ImageCache2 - 画像キャッシュ一覧 */ // {{{ p2基本設定読み込み&認証 define('P2_FORCE_USE_SESSION', 1); define('P2_SESSION_NO_CLOSE', 1); define('P2_OUTPUT_XHTML', 1); define('P2_USE_PEAR_HACK', 1); require_once './conf/conf.inc.php'; $_login->authorize(); if (!$_conf['expack.ic2.enabled']) { p2die('ImageCache2は無効です。', 'conf/conf_admin_ex.inc.php の設定を変えてください。'); } if ($_conf['iphone']) { $_conf['extra_headers_ht'] .= <<<EOP \n<link rel="stylesheet" type="text/css" href="css/ic2_iphone.css?{$_conf['p2_version_id']}"> <link rel="stylesheet" type="text/css" href="css/iv2_iphone.css?{$_conf['p2_version_id']}"> <script type="text/javascript" src="js/json2.js?{$_conf['p2_version_id']}"></script> <script type="text/javascript" src="js/ic2_iphone.js?{$_conf['p2_version_id']}"></script> <script type="text/javascript" src="js/iv2_iphone.js?{$_conf['p2_version_id']}"></script>\n EOP; $_conf['extra_headers_xht'] .= <<<EOP \n<link rel="stylesheet" type="text/css" href="css/ic2_iphone.css?{$_conf['p2_version_id']}" /> <link rel="stylesheet" type="text/css" href="css/iv2_iphone.css?{$_conf['p2_version_id']}" /> <script type="text/javascript" src="js/json2.js?{$_conf['p2_version_id']}"></script> <script type="text/javascript" src="js/ic2_iphone.js?{$_conf['p2_version_id']}"></script> <script type="text/javascript" src="js/iv2_iphone.js?{$_conf['p2_version_id']}"></script>\n EOP; } // ビュー判定用の隠し要素 if ($_conf['view_forced_by_query']) { output_add_rewrite_var('b', $_conf['b']); } // }}} // {{{ 初期化 // ライブラリ読み込み require_once 'PEAR.php'; require_once 'Cache.php'; require_once 'Cache/Function.php'; require_once 'DB.php'; require_once 'DB/DataObject.php'; require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php'; require_once 'HTML/Template/Flexy.php'; require_once 'HTML/Template/Flexy/Element.php'; require_once P2EX_LIB_DIR . '/ic2/loadconfig.inc.php'; require_once P2EX_LIB_DIR . '/ic2/DataObject/Common.php'; require_once P2EX_LIB_DIR . '/ic2/DataObject/Images.php'; require_once P2EX_LIB_DIR . '/ic2/Thumbnailer.php'; require_once P2EX_LIB_DIR . '/ic2/QuickForm/Rules.php'; require_once P2EX_LIB_DIR . '/ic2/EditForm.php'; require_once P2EX_LIB_DIR . '/ic2/managedb.inc.php'; require_once P2EX_LIB_DIR . '/ic2/getvalidvalue.inc.php'; require_once P2EX_LIB_DIR . '/ic2/buildimgcell.inc.php'; require_once P2EX_LIB_DIR . '/ic2/Matrix.php'; // }}} // {{{ config // 設定ファイル読み込み $ini = ic2_loadconfig(); // Exif表示が有効か? $show_exif = ($ini['Viewer']['exif'] && extension_loaded('exif')); $_default_mode = (int)$_conf['expack.ic2.viewer_default_mode']; if ($_default_mode < 0 || $_default_mode > 3) { $_default_mode = 0; } // フォームのデフォルト値 $_defaults = array( 'page' => 1, 'cols' => $ini['Viewer']['cols'], 'rows' => $ini['Viewer']['rows'], 'inum' => $ini['Viewer']['inum'], 'order' => $ini['Viewer']['order'], 'sort' => $ini['Viewer']['sort'], 'field' => $ini['Viewer']['field'], 'key' => '', 'threshold' => $ini['Viewer']['threshold'], 'compare' => $ini['Viewer']['compare'], 'mode' => $_default_mode, 'thumbtype' => IC2_Thumbnailer::SIZE_DEFAULT, ); // フォームの固定値 $_constants = array( 'start' => '<<', 'prev' => '<', 'next' => '>', 'end' => '>>', 'jump' => 'Go', 'search' => '検索', 'cngmode' => '変更', '_hint' => $_conf['detect_hint'], ); // 閾値比較方法 $_compare = array( '>=' => '>=', '=' => '=', '<=' => '<=', ); // 閾値 $_threshold = array( '-1' => '-1', '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', ); // ソート基準 $_order = array( 'time' => '取得日時', 'uri' => 'URL', 'date_uri' => '日付+URL', 'date_uri2' => '日付+URL(2)', 'name' => 'ファイル名', 'size' => 'ファイルサイズ', 'width' => '横幅', 'height' => '高さ', 'pixels' => 'ピクセル数', 'id' => 'ID', ); // ソート方向 $_sort = array( 'ASC' => '昇順', 'DESC' => '降順', ); // 検索フィールド $_field = array( 'uri' => 'URL', 'name' => 'ファイル名', 'memo' => 'メモ', ); // モード $_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']) { // データキャッシュにはCache_Container_db(Cache 1.5.4)をハックしてMySQL以外にも対応させ、 // コンストラクタがDB_xxx(DB_mysqlなど)のインスタンスを受け取れるようにしたものを使う。 // (ファイル名・クラス名は同じで、include_pathを調整して // オリジナルのCache/Container/db.phpの代わりにする) $cache_options = array( 'dsn' => $ini['General']['dsn'], 'cache_table' => $ini['Cache']['table'], 'highwater' => (int)$ini['Cache']['highwater'], 'lowwater' => (int)$ini['Cache']['lowwater'], 'db' => $db ); $cache = new Cache_Function('db', $cache_options, (int)$ini['Cache']['expires']); // 有効期限切れキャッシュのガーベッジコレクションなど if (isset($_GET['cache_clean'])) { $cache_clean = $_GET['cache_clean']; } elseif (isset($_POST['cache_clean'])) { $cache_clean = $_POST['cache_clean']; } else { $cache_clean = false; } switch ($cache_clean) { // キャッシュを全削除 case 'all': $sql = sprintf('DELETE FROM %s', $db->quoteIdentifier($ini['Cache']['table'])); $result = $db->query($sql); if (DB::isError($result)) { p2die($result->getMessage()); } $vacuumdb = true; break; // 強制的にガーベッジコレクション case 'gc': $cache->garbageCollection(true); $vacuumdb = true; break; // gc_probability(デフォルトは1)/100の確率でガーベッジコレクション default: // $cache->gc_probability = 1; $cache->garbageCollection(); $vacuumdb = false; } // SQLiteならVACUUMを実行(PostgreSQLは普通cronでvacuumdbするのでここではしない) if ($vacuumdb && $db_class == 'db_sqlite') { $result = $db->query('VACUUM'); if (DB::isError($result)) { p2die($result->getMessage()); } } $enable_cache = true; } else { $enable_cache = false; } // }}} // {{{ prepare (Form & Template) // conf.inc.phpで一括stripslashes()しているけど、HTML_QuickFormでも独自にstripslashes()するので。 // バグの温床となる可能性も否定できない・・・ if (get_magic_quotes_gpc()) { $_GET = array_map('addslashes_r', $_GET); $_POST = array_map('addslashes_r', $_POST); $_REQUEST = array_map('addslashes_r', $_REQUEST); } // ページ遷移用フォームを設定 // ページ遷移はGETで行うが、画像情報の更新はPOSTで行うのでどちらでも受け入れるようにする // (レンダリング前に $qf->updateAttributes(array('method' => 'get')); とする) $_attribures = array('accept-charset' => 'UTF-8,Shift_JIS'); $_method = ($_SERVER['REQUEST_METHOD'] == 'GET') ? 'get' : 'post'; $qf = new HTML_QuickForm('go', $_method, $_SERVER['SCRIPT_NAME'], '_self', $_attribures); $qf->registerRule('numberInRange', null, 'IC2_QuickForm_Rule_NumberInRange'); $qf->registerRule('inArray', null, 'IC2_QuickForm_Rule_InArray'); $qf->registerRule('arrayKeyExists', null, 'IC2_QuickForm_ArrayKeyExists'); $qf->setDefaults($_defaults); $qf->setConstants($_constants); $qfe = array(); // フォーム要素の定義 // ページ移動のためのsubmit要素 $qfe['start'] = $qf->addElement('button', 'start'); $qfe['prev'] = $qf->addElement('button', 'prev'); $qfe['next'] = $qf->addElement('button', 'next'); $qfe['end'] = $qf->addElement('button', 'end'); $qfe['jump'] = $qf->addElement('button', 'jump'); // 表示方法などを指定するinput要素 $qfe['page'] = $qf->addElement('text', 'page', 'ページ番号を指定', array('size' => 3)); $qfe['cols'] = $qf->addElement('text', 'cols', '横', array('size' => 3, 'maxsize' => 2)); $qfe['rows'] = $qf->addElement('text', 'rows', '縦', array('size' => 3, 'maxsize' => 2)); $qfe['order'] = $qf->addElement('select', 'order', '並び順', $_order); $qfe['sort'] = $qf->addElement('select', 'sort', '方向', $_sort); $qfe['field'] = $qf->addElement('select', 'field', 'フィールド', $_field); $qfe['key'] = $qf->addElement('text', 'key', 'キーワード', array('size' => 20)); $qfe['compare'] = $qf->addElement('select', 'compare', '比較方法', $_compare); $qfe['threshold'] = $qf->addElement('select', 'threshold', 'しきい値', $_threshold); $qfe['thumbtype'] = $qf->addElement('select', 'thumbtype', 'サムネイルタイプ', $_thumbtype); // 文字コード判定のヒントにする隠し要素 $qfe['_hint'] = $qf->addElement('hidden', '_hint'); // 検索を実行するsubmit要素 $qfe['search'] = $qf->addElement('submit', 'search'); // モード変更をするselect要素 $qfe['mode'] = $qf->addElement('select', 'mode', 'モード', $_mode); // モード変更を確定するsubmit要素 $qfe['cngmode'] = $qf->addElement('submit', 'cngmode'); // フォームのルール $qf->addRule('cols', '1 to 20', 'numberInRange', array('min' => 1, 'max' => 20), 'client', true); $qf->addRule('rows', '1 to 100', 'numberInRange', array('min' => 1, 'max' => 100), 'client', true); $qf->addRule('order', 'invalid order.', 'arrayKeyExists', $_order); $qf->addRule('sort', 'invalid sort.', 'arrayKeyExists', $_sort); $qf->addRule('field', 'invalid field.', 'arrayKeyExists', $_field); $qf->addRule('threshold', '-1 to 5', 'numberInRange', array('min' => -1, 'max' => 5)); $qf->addRule('compare', 'invalid compare.', 'arrayKeyExists', $_compare); $qf->addRule('mode', 'invalid mode.', 'arrayKeyExists', $_mode); $qf->addRule('thumbtype', 'invalid thumbtype.', 'arrayKeyExists', $_thumbtype); // Flexy $_flexy_options = array( 'locale' => 'ja', 'charset' => 'cp932', 'compileDir' => $_conf['compile_dir'] . DIRECTORY_SEPARATOR . 'iv2', 'templateDir' => P2EX_LIB_DIR . '/ic2/templates', 'numberFormat' => '', // ",0,'.',','" と等価 'plugins' => array('P2Util' => P2_LIB_DIR . '/P2Util.php') ); if (!is_dir($_conf['compile_dir'])) { FileCtl::mkdir_for($_conf['compile_dir'] . '/__dummy__'); } $flexy = new HTML_Template_Flexy($_flexy_options); $flexy->setData('php_self', $_SERVER['SCRIPT_NAME']); $flexy->setData('base_dir', dirname($_SERVER['SCRIPT_NAME'])); $flexy->setData('p2vid', P2_VERSION_ID); $flexy->setData('_hint', $_conf['detect_hint']); if ($_conf['iphone']) { $flexy->setData('top_url', 'index.php'); } elseif ($_conf['ktai']) { $flexy->setData('k_color', array( 'c_bgcolor' => !empty($_conf['mobile.background_color']) ? $_conf['mobile.background_color'] : '#ffffff', 'c_text' => !empty($_conf['mobile.text_color']) ? $_conf['mobile.text_color'] : '#000000', 'c_link' => !empty($_conf['mobile.link_color']) ? $_conf['mobile.link_color'] : '#0000ff', 'c_vlink' => !empty($_conf['mobile.vlink_color']) ? $_conf['mobile.vlink_color'] : '#9900ff', )); $flexy->setData('top_url', dirname($_SERVER['SCRIPT_NAME']) . '/index.php'); $flexy->setData('accesskey', $_conf['accesskey']); } else { $flexy->setData('skin', str_replace('&', '&', $skin_en)); } $flexy->setData('pc', !$_conf['ktai']); $flexy->setData('iphone', $_conf['iphone']); $flexy->setData('doctype', $_conf['doctype']); $flexy->setData('extra_headers', $_conf['extra_headers_ht']); $flexy->setData('extra_headers_x', $_conf['extra_headers_xht']); // }}} // {{{ validate // 検証 $qf->validate(); $sv = $qf->getSubmitValues(); $page = getValidValue('page', $_defaults['page'], 'intval'); $cols = getValidValue('cols', $_defaults['cols'], 'intval'); $rows = getValidValue('rows', $_defaults['rows'], 'intval'); $order = getValidValue('order', $_defaults['order']); $sort = getValidValue('sort', $_defaults['sort'] ); $field = getValidValue('field', $_defaults['field']); $key = getValidValue('key', $_defaults['key']); $threshold = getValidValue('threshold', $_defaults['threshold'], 'intval'); $compare = getValidValue('compare', $_defaults['compare']); $mode = getValidValue('mode', $_defaults['mode'], 'intval'); $thumbtype = getValidValue('thumbtype', $_defaults['thumbtype'], 'intval'); // サムネイル作成クラス $thumb = new IC2_Thumbnailer($thumbtype); // 携帯用に調整 if ($_conf['ktai']) { $lightbox = false; $mode = 1; $inum = (int) $ini['Viewer']['inum']; $overwritable_params = array('order', 'sort', 'field', 'key', 'threshold', 'compare'); // 絵文字を読み込む require_once P2_LIB_DIR . '/emoji.inc.php'; $emj = p2_get_emoji(); $flexy->setData('e', $emj); $flexy->setData('ak', $_conf['k_accesskey_at']); $flexy->setData('as', $_conf['k_accesskey_st']); // フィルタリング用フォームを表示 if (!empty($_GET['show_iv2_kfilter'])) { !defined('P2_NO_SAVE_PACKET') && define('P2_NO_SAVE_PACKET', true); $r = new HTML_QuickForm_Renderer_ObjectFlexy($flexy); $qfe['key']->removeAttribute('size'); $qf->updateAttributes(array('method' => 'get')); $qf->accept($r); $qfObj = $r->toObject(); $flexy->setData('page', $page); $flexy->setData('move', $qfObj); P2Util::header_nocache(); $flexy->compile('iv2if.tpl.html'); $flexy->output(); exit; } // フィルタをリセット elseif (!empty($_GET['reset_filter'])) { unset($_SESSION['iv2i_filter']); session_write_close(); } // フィルタを設定 elseif (!empty($_GET['session_no_close'])) { foreach ($overwritable_params as $ow_key) { if (isset($$ow_key)) { $_SESSION['iv2i_filter'][$ow_key] = $$ow_key; } } session_write_close(); } // フィルタリング用変数を更新 elseif (!empty($_SESSION['iv2i_filter'])) { foreach ($overwritable_params as $ow_key) { if (isset($_SESSION['iv2i_filter'][$ow_key])) { $$ow_key = $_SESSION['iv2i_filter'][$ow_key]; } } } } else { //$lightbox = ($mode == 0 || $mode == 3) ? $ini['Viewer']['lightbox'] : false; $lightbox = $ini['Viewer']['lightbox']; } // }}} // {{{ query $removed_files = array(); // 閾値でフィルタリング if (!($threshold == -1 && $compate == '>=')) { $icdb->whereAddQuoted('rank', $compare, $threshold); } // キーワード検索をするとき if ($key !== '') { $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) { p2die('ImageCache2 Warning', '「%または_」と「*または?」が混在するキーワードは使えません。'); } else { $operator = 'GLOB'; $wildcard = '*'; } } else { $k = preg_replace('/[%_]/', '\\\\$0', $k); } } $expr = $wildcard . $k . $wildcard; if ($not) { $operator = 'NOT ' . $operator; } $icdb->whereAddQuoted($field, $operator, $expr); } $qfe['key']->setValue($key); } // 重複画像をスキップするとき $_find_duplicated = 0; // 試験的パラメータ、登録レコード数がこれ以上の画像のみを抽出 if ($ini['Viewer']['unique'] || $_find_duplicated > 1) { $subq = 'SELECT ' . (($sort == 'ASC') ? 'MIN' : 'MAX') . '(id) FROM '; $subq .= $db->quoteIdentifier($ini['General']['table']); if (isset($keys)) { // サブクエリ内でフィルタリングするので親クエリのWHERE句をパクってきてリセット $subq .= $icdb->_query['condition']; $icdb->whereAdd(); } // md5だけでグループ化しても十分とは思うけど、一応。 $subq .= ' GROUP BY size, md5, mime'; if ($_find_duplicated > 1) { $subq .= sprintf(' HAVING COUNT(*) > %d', $_find_duplicated - 1); } // echo '<!--', mb_convert_encoding($subq, 'CP932', 'UTF-8'), '-->'; $icdb->whereAdd("id IN ($subq)"); } // データベースを更新するとき if (isset($_POST['edit_submit']) && !empty($_POST['change'])) { $target = array_unique(array_map('intval', $_POST['change'])); switch ($mode) { // 一括でパラメータ変更 case 1: // ランクを変更 $newrank = intoRange($_POST['setrank'], -1, 5); manageDB_setRank($target, $newrank); // メモを追加 if (!empty($_POST['addmemo'])) { $newmemo = get_magic_quotes_gpc() ? stripslashes($_POST['addmemo']) : $_POST['addmemo']; $newmemo = $icdb->uniform($newmemo, 'CP932'); if ($newmemo !== '') { manageDB_addMemo($target, $newmemo); } } break; // 個別にパラメータ変更 case 2: // 更新用のデータをまとめる $updated = array(); $removed = array(); $to_blacklist = false; $no_blacklist = false; foreach ($target as $id) { if (!empty($_POST['img'][$id]['remove'])) { if (!empty($_POST['img'][$id]['black'])) { $to_blacklist = true; $removed[$id] = true; } else { $no_blacklist = true; $removed[$id] = false; } } else { $newmemo = get_magic_quotes_gpc() ? stripslashes($_POST['img'][$id]['memo']) : $_POST['img'][$id]['memo']; $data = array( 'rank' => intval($_POST['img'][$id]['rank']), 'memo' => $icdb->uniform($newmemo, 'CP932') ); if (0 < $id && -1 <= $data['rank'] && $data['rank'] <= 5) { $updated[$id] = $data; } } } // 情報を更新 if (count($updated) > 0) { manageDB_update($updated); } // 削除(&ブラックリスト送り) if (count($removed) > 0) { foreach ($removed as $id => $to_blacklist) { $removed_files = array_merge($removed_files, manageDB_remove(array($id), $to_blacklist)); } if ($to_blacklist) { if ($no_blacklist) { $flexy->setData('toBlackListAll', false); $flexy->setData('toBlackListPartial', true); } else { $flexy->setData('toBlackListAll', true); $flexy->setData('toBlackListPartial', false); } } else { $flexy->setData('toBlackListAll', false); $flexy->setData('toBlackListPartial', false); } } break; } // endswitch // 一括で画像を削除するとき } elseif ($mode == 1 && isset($_POST['edit_remove']) && !empty($_POST['change'])) { $target = array_unique(array_map('intval', $_POST['change'])); $to_blacklist = !empty($_POST['edit_toblack']); $removed_files = array_merge($removed_files, manageDB_remove($target, $to_blacklist)); $flexy->setData('toBlackList', $to_blacklist); } // }}} // {{{ build // 総レコード数を数える //$db->setFetchMode(DB_FETCHMODE_ORDERED); //$all = (int)$icdb->count('*', true); //$db->setFetchMode(DB_FETCHMODE_ASSOC); $sql = sprintf('SELECT COUNT(*) FROM %s %s', $db->quoteIdentifier($ini['General']['table']), $icdb->_query['condition']); $all = $db->getOne($sql); if (DB::isError($all)) { p2die($all->getMessage()); } // マッチするレコードがなかったらエラーを表示、レコードがあれば表示用オブジェクトに値を代入 if ($all == 0) { // レコードなし $flexy->setData('nomatch', true); $flexy->setData('reset', $_SERVER['SCRIPT_NAME']); if ($_conf['ktai']) { $flexy->setData('kfilter', !empty($_SESSION['iv2i_filter'])); } $qfe['start']->updateAttributes('disabled'); $qfe['prev']->updateAttributes('disabled'); $qfe['next']->updateAttributes('disabled'); $qfe['end']->updateAttributes('disabled'); $qfe['page']->updateAttributes('disabled'); $qfe['jump']->updateAttributes('disabled'); } else { // レコードあり $flexy->setData('nomatch', false); // 表示範囲を設定 $ipp = $_conf['ktai'] ? $inum : $cols * $rows; // images per page $last_page = ceil($all / $ipp); // ページ遷移用パラメータを準備 if (isset($sv['search']) || isset($sv['cngmode'])) { $page = 1; } elseif (isset($sv['page'])) { $page = max(1, min((int)$sv['page'], $last_page)); } else { $page = 1; } $prev_page = max(1, $page - 1); $next_page = min($page + 1, $last_page); // ページ遷移用リンク(iPhone)を生成 if ($_conf['iphone']) { $pg_base = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); $pager = ''; if ($page != 1) { $pager .= sprintf('<a href="%s?page=%d">%s</a> ', $pg_base, 1, $emj['lt2']); $pager .= sprintf('<a href="%s?page=%d">%s</a> ', $pg_base, $prev_page, $emj['lt1']); } $pager .= sprintf('%d/%d', $page, $last_page); if ($page != $last_page) { $pager .= sprintf(' <a href="%s?page=%d">%s</a>', $pg_base, $next_page, $emj['rt1']); $pager .= sprintf(' <a href="%s?page=%d">%s</a>', $pg_base, $last_page, $emj['rt2']); } $flexy->setData('pager', $pager); // ページ遷移用リンク(携帯)を生成 } elseif ($_conf['ktai']) { $pg_base = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES); $pg_pos = sprintf('%d/%d', $page, $last_page); $pager1 = ''; $pager2 = ''; if ($page != 1) { $pager1 .= sprintf('<a href="%s?page=%d"%s>%s%s</a> ', $pg_base, 1, $_conf['k_accesskey_at'][1], $_conf['k_accesskey_st'][1], $emj['lt2'] ); $pager1 .= sprintf('<a href="%s?page=%d"%s>%s%s</a> ', $pg_base, $prev_page, $_conf['k_accesskey_at'][4], $_conf['k_accesskey_st'][4], $emj['lt1'] ); $pager2 .= sprintf('<a href="%s?page=%d">%s</a> ', $pg_base, 1, $emj['lt2']); $pager2 .= sprintf('<a href="%s?page=%d">%s</a> ', $pg_base, $prev_page, $emj['lt1']); } $pager1 .= $pg_pos; $pager2 .= $pg_pos; if ($page != $last_page) { $pager1 .= sprintf(' <a href="%s?page=%d">%s</a>', $pg_base, $next_page, $emj['rt1']); $pager1 .= sprintf(' <a href="%s?page=%d">%s</a>', $pg_base, $last_page, $emj['rt2']); $pager2 .= sprintf(' <a href="%s?page=%d"%s>%s%s</a>', $pg_base, $next_page, $_conf['k_accesskey_at'][6], $_conf['k_accesskey_st'][6], $emj['rt1'] ); $pager2 .= sprintf(' <a href="%s?page=%d"%s>%s%s</a>', $pg_base, $last_page, $_conf['k_accesskey_at'][9], $_conf['k_accesskey_st'][9], $emj['rt2'] ); } $flexy->setData('pager1', $pager1); $flexy->setData('pager2', $pager2); // ページ遷移用フォーム(PC)を生成 } else { $mf_hiddens = array( '_hint' => $_conf['detect_hint'], 'mode' => $mode, 'page' => $page, 'cols' => $cols, 'rows' => $rows, 'order' => $order, 'sort' => $sort, 'field' => $field, 'key' => $key, 'compare' => $compare, 'threshold' => $threshold, 'thumbtype' => $thumbtype ); $pager_q = $mf_hiddens; mb_convert_variables('UTF-8', 'CP932', $pager_q); // ページ番号を更新 $qfe['page']->setValue($page); $qf->addRule('page', "1 to {$last_page}", 'numberInRange', array('min' => 1, 'max' => $last_page), 'client', true); // 一時的にパラメータ区切り文字を & にして現在のページのURLを生成 $pager_separator = ini_get('arg_separator.output'); ini_set('arg_separator.output', '&'); $flexy->setData('current_page', $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($pager_q)); ini_set('arg_separator.output', $pager_separator); unset($pager_q, $pager_separator); // ページ後方移動ボタンの属性を更新 if ($page == 1) { $qfe['start']->updateAttributes('disabled'); $qfe['prev']->updateAttributes('disabled'); } else { $qfe['start']->updateAttributes(array('onclick' => "pageJump(1)")); $qfe['prev']->updateAttributes(array('onclick' => "pageJump({$prev_page})")); } // ページ前方移動ボタンの属性を更新 if ($page == $last_page) { $qfe['next']->updateAttributes('disabled'); $qfe['end']->updateAttributes('disabled'); } else { $qfe['next']->updateAttributes(array('onclick' => "pageJump({$next_page})")); $qfe['end']->updateAttributes(array('onclick' => "pageJump({$last_page})")); } // ページ指定移動用ボタンの属性を更新 if ($last_page == 1) { $qfe['jump']->updateAttributes('disabled'); } else { $qfe['jump']->updateAttributes(array('onclick' => "if(validate_go(this.form))pageJump(this.form.page.value)")); } } // 編集モード用フォームを生成 if ($mode == 1 || $mode == 2) { $flexy->setData('editFormHeader', IC2_EditForm::header((isset($mf_hiddens) ? $mf_hiddens : array()), $mode)); if ($mode == 1) { $flexy->setData('editFormCheckAllOn', IC2_EditForm::checkAllOn()); $flexy->setData('editFormCheckAllOff', IC2_EditForm::checkAllOff()); $flexy->setData('editFormCheckAllReverse', IC2_EditForm::checkAllReverse()); $flexy->setData('editFormSelect', IC2_EditForm::selectRank($_threshold)); $flexy->setData('editFormText', IC2_EditForm::textMemo()); $flexy->setData('editFormSubmit', IC2_EditForm::submit()); $flexy->setData('editFormReset', IC2_EditForm::reset()); $flexy->setData('editFormRemove', IC2_EditForm::remove()); $flexy->setData('editFormBlackList', IC2_EditForm::toblack()); } elseif ($mode == 2) { $flexy->setData('editForm', new IC2_EditForm_Object); } } // DBから取得する範囲を設定して検索 $from = ($page - 1) * $ipp; if ($order == 'pixels') { $orderBy = '(width * height) ' . $sort; } elseif ($order == 'date_uri' || $order == 'date_uri2') { if ($db_class == 'db_sqlite') { /* function iv2_sqlite_unix2date($ts) { return date('Ymd', (int)$ts); } sqlite_create_function($db->connection, 'unix2date', 'iv2_sqlite_unix2date', 1); $time2date = 'unix2date("time")'; */ $time2date = 'php(\'date\', \'Ymd\', "time")'; } else { // 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: $show_exif = false; case 2: $popup = false; break; default: $popup = true; } $r_type = 1; } $items = array(); if (!empty($_SERVER['REQUEST_URI'])) { $k_backto = '&from=' . rawurlencode($_SERVER['REQUEST_URI']); } else { $k_backto = ''; } $sid_at_a = str_replace('&', '&', $_conf['sid_at_a']); while ($icdb->fetch()) { // 検索結果を配列にし、レンダリング用の要素を付加 // 配列どうしなら+演算子で要素を追加できる // (キーの重複する値を上書きしたいときはarray_merge()を使う) $img = $icdb->toArray(); mb_convert_variables('CP932', 'UTF-8', $img); // ランク・メモは変更されることが多く、一覧用のデータキャッシュに影響を与えないように別に処理する $status = array(); $status['rank'] = $img['rank']; $status['rank_f'] = ($img['rank'] == -1) ? 'あぼーん' : $img['rank']; if ($img['rank'] == -1) { $status['rank_i'] = '<img src="img/sn1a.png" width="16" height="16">'; } elseif ($img['rank'] > 0 && $img['rank'] <= 5) { $status['rank_i'] = str_repeat('<img src="img/s1a.png" width="16" height="16">', $img['rank']); } else { $status['rank_i'] = ''; } $status['memo'] = $img['memo']; unset($img['rank'], $img['memo']); // 表示用変数を設定 if ($enable_cache) { $add = $cache->call('ic2_image_extra_info', $img); if ($mode == 1) { $chk = IC2_EditForm::imgChecker($img); // 比較的軽いのでキャッシュしない $add += $chk; } elseif ($mode == 2) { $mng = $cache->call('IC2_EditForm::imgManager', $img, $status); $add += $mng; } } else { $add = ic2_image_extra_info($img); if ($mode == 1) { $chk = IC2_EditForm::imgChecker($img); $add += $chk; } elseif ($mode == 2) { $mng = IC2_EditForm::imgManager($img, $status); $add += $mng; } } // オリジナル画像が存在しないレコードを自動で削除 if ($ini['Viewer']['delete_src_not_exists'] && !file_exists($add['src'])) { $add['thumb_k'] = $add['thumb'] = 'img/ic_removed.png'; $add['t_width'] = $add['t_height'] = 32; $to_blacklist = false; $removed_files = array_merge($removed_files, manageDB_remove(array($img['id'], $to_blacklist))); $flexy->setData('toBlackList', $to_blacklist); } else { if (!file_exists($add['thumb'])) { // レンダリング時に自動でhtmlspecialchars()されるので&にしない $add['thumb'] = 'ic2.php?r=' . $r_type . "&t={$thumb->mode}"; if (file_exists($add['src'])) { $add['thumb'] .= '&id=' . $img['id']; } else { $add['thumb'] .= '&uri=' . rawurlencode($img['uri']); } $add['thumb'] .= $sid_at_a; } if ($_conf['ktai']) { $add['thumb_k'] = 'ic2.php?r=0&t=2'; if (file_exists($add['src'])) { $add['thumb_k'] .= '&id=' . $img['id']; } else { $add['thumb_k'] .= '&uri=' . rawurlencode($img['uri']); } $add['thumb_k'] .= $k_backto . $sid_at_a; } } $item = array_merge($img, $add, $status); // Exif情報を取得 if ($show_exif && file_exists($add['src']) && $img['mime'] == 'image/jpeg') { $item['exif'] = $enable_cache ? $cache->call('ic2_read_exif', $add['src']) : ic2_read_exif($add['src']); } else { $item['exif'] = null; } // Lightbox Plus 用パラメータを設定 if ($lightbox) { $item['lightbox_attrs'] = ' rel="lightbox[iv2]" class="ineffectable"'; $item['lightbox_attrs'] .= ' title="' . htmlspecialchars($item['memo'], ENT_QUOTES) . '"'; } else { $item['lightbox_attrs'] = ''; } $items[] = $item; } $i = count($items); // == $found // テーブルの余白を埋めるためにnullを挿入 if (!$_conf['ktai'] && $i > $cols && ($j = $i % $cols) > 0) { for ($k = 0; $k < $cols - $j; $k++) { $items[] = null; $i++; } } // この時点で $i == $cols * 自然数 $flexy->setData('items', $items); $flexy->setData('popup', $popup); $flexy->setData('matrix', new IC2_Matrix($cols, $rows, $i)); } $flexy->setData('removedFiles', $removed_files); // }}} // {{{ output // モード別の最終処理 if ($_conf['ktai']) { $title = str_replace('ImageCache2', 'IC2', $ini['Viewer']['title']); $list_template = ($_conf['iphone']) ? 'iv2ip.tpl.html' : 'iv2i.tpl.html'; } else { switch ($mode) { case 2: $title = $ini['Manager']['title']; $list_template = 'iv2m.tpl.html'; break; case 1: $title = $ini['Viewer']['title']; $list_template = 'iv2a.tpl.html'; break; default: $title = $ini['Viewer']['title']; $list_template = 'iv2.tpl.html'; } } // フォームを最終調整し、テンプレート用オブジェクトに変換 $r = new HTML_QuickForm_Renderer_ObjectFlexy($flexy); //$r->setLabelTemplate('_label.tpl.html'); //$r->setHtmlTemplate('_html.tpl.html'); $qf->updateAttributes(array('method' => 'get')); // リクエストをPOSTでも受け入れるため、ここで変更 /*if ($_conf['input_type_search']) { $input_type_search_attributes = array( 'type' => 'search', 'autosave' => 'rep2.expack.search.imgcache', 'results' => '10', 'placeholder' => '', ); $qfe['key']->updateAttributes($input_type_search_attributes); }*/ $qf->accept($r); $qfObj = $r->toObject(); // 変数をAssign $js = $qf->getValidationScript() . <<<EOJS \n<script type="text/javascript"> // <![CDATA[ var ic2_cols = {$cols}; var ic2_rows = {$rows}; var ic2_lightbox_options = { no_loop: false, no_updown: false }; // ]]> </script>\n EOJS; $flexy->setData('title', $title); $flexy->setData('mode', $mode); $flexy->setData('js', $js); $flexy->setData('page', $page); $flexy->setData('move', $qfObj); $flexy->setData('lightbox', $lightbox); // ページを表示 P2Util::header_nocache(); $flexy->compile($list_template); if ($list_template == 'iv2ip.tpl.html') { if (!isset($prev_page)) { $prev_page = $page; } if (!isset($next_page)) { $next_page = $page; } $ll_autoactivate = empty($_GET['ll_autoactivate']) ? 'false' : 'true'; $limelight_header = <<<EOP <link rel="stylesheet" type="text/css" href="css/limelight.css?{$_conf['p2_version_id']}"> <script type="text/javascript" src="js/limelight.js?{$_conf['p2_version_id']}"></script> <script type="text/javascript"> // <![CDATA[ |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |