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/gsearch.php at master · thermon/p2-php Expand file tree/ Copy pathgsearch.phpMore file actions 182 lines (159 loc) · 6.1 KB / Copy pathgsearch.phpFile metadata and controls182 lines (159 loc) · 6.1 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 <?php /** * 2chからGoogle APIを使って検索し、p2で読むためのリンクに変換する * * 予定: * ・1日1,000回までの制限があるので検索結果をキャッシュして再問い合わせを防ぐ。 * ・ログにその日の検索回数を記録するようにする。 * * 参考にしたところ: * ・http://www.itmedia.co.jp/enterprise/0405/28/epn04_3.html * ・まるごとPHP! (Vol.1) 月宮さんの記事「PHPで簡単 SOAPサービス」 * * 必要なもの: * ・Google アカウント * ・Google Web APIs のページから入手できる Developer’s Kit に含まれるWSDLファイル * ・PHPのmbstring機能拡張 * ・PHP4ならPEAR::SOAP、PHP5ならSOAP拡張機能 * ・PEAR::Pager (2.x) * ・PEAR::Var_Dump (1.x) */ // {{{ p2基本設定読み込み&認証 require_once './conf/conf.inc.php'; $_login->authorize(); // }}} if ($_conf['expack.google.enabled'] == 0) { p2die('Google検索は無効です。', 'conf/conf_admin_ex.inc.php の設定を変えてください。'); } if ($_conf['view_forced_by_query']) { output_add_rewrite_var('b', $_conf['b']); } // {{{ Init // ライブラリ読み込み require_once P2EX_LIB_DIR . '/google/Search.php'; require_once P2EX_LIB_DIR . '/google/Converter.php'; require_once P2EX_LIB_DIR . '/google/Renderer.php'; // Google Search WSDLファイルのパス $wsdl = $_conf['expack.google.wsdl']; // Google Web APIs のライセンスキー $key = $_conf['expack.google.key']; // 1ページ当たりの表示件数 (Max:10) $perPage = 10; // 検索文字列 if (isset($_GET['word'])) { $_GET['q'] = $_GET['word']; unset($_GET['word']); } if (isset($_GET['q'])) { $q = mb_convert_encoding($_GET['q'], 'UTF-8', 'CP932'); $word = htmlspecialchars($_GET['q'], ENT_QUOTES); } else { $word = $q = ''; } // ページ番号 $p = isset($_GET['p']) ? max((int)$_GET['p'], 1) : 1; $start = ($p - 1) * $perPage; // 出力用変数 $totalItems = 0; $result = NULL; $popups = NULL; // }}} // {{{ Search if (!empty($q)) { // 検索文字列を2ch内検索用に変換 //$q = trim(preg_replace('/( | )\w+:.*( | )/u', '', $q)); //$q .= ' site:2ch.net -site:www.2ch.net -site:info.2ch.net -site:find.2ch.net -site:p2.2ch.net'; $q .= ' site:2ch.net'; // Google検索クラスのインスタンスを生成する $google = Google_Search::factory($wsdl, $key); // インスタンス生成に失敗 if (PEAR::isError($google)) { $result = '<b>Error: ' . $google->getMessage() . '</b>'; // インスタンス生成に成功 } else { $resultObj = $google->doSearch($q, $perPage, $start); // エラー発生 if (PEAR::isError($resultObj)) { $result = '<b>Error: ' . $resultObj->getMessage() . '</b>'; if (!empty($resultObj->userinfo)) { if (!class_exists('Var_Dump', false)) { require 'Var_Dump.php'; } $result .= Var_Dump::display($resultObj->getUserInfo(), TRUE, 'HTML4_Table'); } // リクエスト成功 } else { $totalItems = $resultObj->estimatedTotalResultsCount; // ヒットあり if ($totalItems > 0) { $converter = new Google_Converter; $result = array(); $popups = array(); $id = 1; foreach ($resultObj->resultElements as $obj) { $result[$id] = $converter->toOutputValue($obj); $popups[$id] = $converter->toPopUpValue($obj); $id++; } // ヒット数ゼロ } else { $result = '"' . $word . '" Not Found.'; // 検索結果の最後のページを表示しようとしたとき、 // ヒット数がブレて$startより小さくなり、結果として0件となることがある if ($start > 0) { $result .= '<br><a href="javascript:history.back();">Back</a>'; } } } // end of リクエスト成功 } // end of インスタンス生成に成功 } // }}} // {{{ Display $renderer = new Google_Renderer; $search_element_type = 'text'; $search_element_extra_attributes = ''; if ($_conf['input_type_search']) { $search_element_type = 'search'; $search_element_extra_attributes = " autosave=\"rep2.expack.search.google\" results=\"{$_conf['expack.google.recent2_num']}\" placeholder=\"Google\""; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> <?php echo $_conf['extra_headers_ht']; ?> <title>2ch検索 by Google : <?php echo $word; ?></title> <link rel="stylesheet" type="text/css" href="css.php?css=style&skin=<?php echo $skin_en; ?>"> <link rel="stylesheet" type="text/css" href="css.php?css=read&skin=<?php echo $skin_en; ?>"> <link rel="stylesheet" type="text/css" href="css.php?css=subject&skin=<?php echo $skin_en; ?>"> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico"> <script type="text/javascript" src="js/basic.js?<?php echo $_conf['p2_version_id']; ?>"></script> <script type="text/javascript" src="js/gpopup.js?<?php echo $_conf['p2_version_id']; ?>"></script> </head> <body> <table id="sbtoolbar1" class="toolbar" cellspacing="0"><tr><td class="toolbar-title"> <span class="itatitle"><a class="aitatitle" href="<?php echo $_SERVER['SCRIPT_NAME']; ?>"><b>2ch検索 by Google</b></a></span> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="get" accept-charset="<?php echo $_conf['accept_charset']; ?>" style="display:inline;"> <input type="<?php echo $search_element_type; ?>" name="q" value="<?php echo $word; ?>"<?php echo $search_element_extra_attributes; ?>> <input type="submit" value="検索"> </form> </td></tr></table> <?php $renderer->printSearchResult($result, $word, $perPage, $start, $totalItems); ?> <?php $renderer->printPager($perPage, $totalItems); ?> <?php $renderer->printPopup($popups); ?> </body> </html> <?php /* * Local Variables: * mode: php * coding: cp932 * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: nil * End: */ // vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: |
| 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. |