OSDN Git Service

一頁に表示できる最大件数を200に拡大。ユーザーTLとキーワードTLで長い投稿を省略しないように変更。
[yanmah2/YANMAH2-season2-.git] / coco.php
1 <?php
2 //YANMAH2 - Yet ANother Mobile Accelerated HatenaHaiku
3 //(c) 2014 YANMAH2 project
4 //This program is freesoftware. you can redistribute it and/or modify it under the terms of the [GNU Affero GPL v3](http://www.gnu.org/licenses/agpl.html).
5 ?>
6 <?php
7 //coco.php?q=ADDRESS&return=URL
8 define("HELLO","world");
9 require_once "product_definitions.php";
10 require_once "configurable_variables.php";
11 require_once "common_functions.php";
12 ?>
13 <?php
14 require_once 'init_processor.php';
15 // var_dump($_SESSION);
16 ?>
17 <?php
18 $selfcall = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES);
19 $safequery = htmlspecialchars($_SERVER["QUERY_STRING"], ENT_QUOTES);
20 ?>
21 <?php //セキュリティのための前処理。
22 ?>
23 <?php
24 if (!isset($_SESSION['auth']) || $_SESSION['auth'] != TRUE){
25   $_SESSION = array();
26   if (isset($_COOKIE[session_name()])){
27         setcookie(session_name(), '', time() - 42000, dirname($_SERVER['SCRIPT_NAME']) . '/', $_SERVER["SERVER_NAME"]);
28   }
29   session_destroy();
30 }
31 ?>
32 <?php
33 //検索処理
34 if (isset($_GET['q'])){
35 }
36 ?>
37 <?php
38 if (isset($_GET['q'])){
39   $get_q = htmlspecialchars($_GET['q'], ENT_QUOTES);
40   $get_q = mb_convert_encoding($get_q, 'UTF-8', $charcode);
41   $address = mb_convert_encoding($_GET['q'], 'UTF-8', $charcode);
42   $address = urlencode($address);
43   if (isset($_GET['return'])) $get_return = htmlspecialchars($_GET['return'], ENT_QUOTES);
44   $json_url = "http://maps.google.com/maps/api/geocode/json?address={$address}&language=ja&sensor=false";
45   $page_head = "{$get_q} でイマココ";
46   $self_anchor = "http://{$_SERVER["SERVER_NAME"]}{$selfcall}?q={$get_q}";
47   if (isset($_GET['return'])) $self_anchor = $self_anchor.'&amp;return='.$get_return;
48   $coco_mode = 'coco-result';
49 } else {
50   if (isset($_GET['return'])) $get_return = htmlspecialchars($_GET['return'], ENT_QUOTES);
51   $page_head = "検索してイマココ";
52   $self_anchor = "http://{$_SERVER["SERVER_NAME"]}{$selfcall}";
53   if (isset($_GET['return'])) $self_anchor = $self_anchor.'?return='.$get_return;
54   $coco_mode = 'coco-ready';
55 }
56 $self_anchor_possibly_with_pagenum = $self_anchor;
57 if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != ''){
58   $relog_back = $self_anchor_possibly_with_pagenum . '&log=try';
59   $relogin = $self_anchor_possibly_with_pagenum . '&amp;with=haiku&amp;callback='.rawurlencode($relog_back);
60 } else {
61   $relog_back = $self_anchor_possibly_with_pagenum . '?log=try';
62   $relogin = $self_anchor_possibly_with_pagenum . '?with=haiku&amp;callback='.rawurlencode($relog_back);
63 }
64 if (isset($_GET['image']) && $_GET['image'] == 'on'){
65         if (preg_match('/^image=on$/u', $_SERVER['QUERY_STRING'])){
66                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
67         } elseif (isset($_GET['log']) && preg_match('/^log=(on|off)$/u', $_SERVER['QUERY_STRING'])){
68                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
69         } elseif ($_SERVER["QUERY_STRING"] != ""){
70                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&amp;image=on';
71         } else {
72                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
73         }
74 } else {
75         if (preg_match('/^image=off$/u', $_SERVER['QUERY_STRING'])){
76                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
77         } elseif (isset($_GET['log']) && preg_match('/^log=(off|on)$/u', $_SERVER['QUERY_STRING'])){
78                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
79         } elseif ($_SERVER["QUERY_STRING"] != ""){
80                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&amp;image=off';
81         } else {
82                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
83         }
84 }
85
86 ?>
87 <?php
88 $echo = <<<EOL
89 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
90    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
91 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
92 <head>
93         <meta http-equiv="Content-Type" content="text/html; charset={$meta_charset}" />
94         <meta http-equiv="Content-Style-Type" content="text/css" />
95         <meta http-equiv="Content-Script-Type" content="text/javascript" />
96         <meta name="viewport" content="initial-scale={$iscale}, minimum-scale=0.1" />
97         <title>{$page_head} - {$site_name} {$site_name_caption}</title>
98         <link rel="stylesheet" href="{$style_sheet}" />
99         <link rel="icon" href="./favicon.ico" type="image/vnd.microsoft.icon" />
100         <link rel="shortcut icon" href="./favicon.ico" type="image/vnd.microsoft.icon" />
101         <link rel="apple-touch-icon" href="./apple-touch-icon.png" />
102 </head>
103 <body>
104 EOL;
105 ?>
106 <?php
107 $echo = $echo . echoCommonHeader('#navigation-menu', $self_anchor_with_imagemode) . "<hr />\n";
108 $echo = $echo . "<div id=\"header\" class=\"{$coco_mode}\">\n";
109 $echo = $echo . "<h1 id=\"entries-head\" class=\"head1\">{$page_head}</h1>\n<hr /></div>";
110 ?>
111 <?php
112 $echo = $echo . '<div class="coco-search">';
113 $echo = $echo . '<form method="get" action="" enctype="application/x-www-form-urlencoded" accept-charset="'.$meta_charset.'">'."\n";
114 $echo = $echo . '<label for="cocoq">場所:</label>';
115 $echo = $echo . '<input type="text" id="cocoq" name="q" maxlength="256" value="" title="場所を入力" />';
116 $echo = $echo . '<input type="hidden" id="toreturn" name="return" value="'.$get_return.'" />';
117 $echo = $echo . '<input type="submit" id="cocos" value="検索" title="場所を検索" />';
118 $echo = $echo . '</form>';
119 $echo = $echo . '</div>';
120 ?>
121 <?php
122 if (isset($_GET['q'])){
123   $echo = $echo . '<div class="geo-result">';
124   $request_url = $json_url;
125   $json = getJson($request_url, FALSE);
126   if ($json['stat'] !== TRUE){
127         $contents = strip_tags($json['stat']);
128         $echo = $echo . "<p>Google Geocoding API からデータを取得できなかったような気がします。</p>\n";
129         $echo = $echo . "<blockquote>";
130         if (isset($json['http'])) $echo = $echo . "HTTP {$json['http']}<br />";
131         $echo = $echo . "{$json['stat']}<br />{$contents}</blockquote>\n";
132   } else {
133         $json_body = $json['body'];
134         $contents = json_decode($json_body);
135 //      var_dump($contents);
136 //      var_dump($contents->status);
137         if (!isset($contents->status)){
138           $error = 'json';
139           $echo = $echo . "<p>はわわ、何かのエラーです。</p>";
140           $echo = $echo . "<blockquote>{$json_body}</blockquote>";
141 //        var_dump($error_mes);
142         } elseif ($contents->status != 'OK'){
143           $error = 'staus';
144           if ($contents->status == 'ZERO_RESULTS'){
145                 $error_mes = $contents->status.': 住所が見つかりません。';
146           } elseif ($contents->status == 'OVER_QUERY_LIMIT'){
147                 $error_mes = $contents->status.': 現在検索できません。';
148           } elseif ($contents->status == 'REQUEST_DENIED'){
149                 $error_mes = $contents->status.': 要求が成立しませんでした。';
150           } elseif ($contents->status == 'INVALID_REQUEST'){
151                 $error_mes = $contents->status.': クエリーが不正です。';
152           }
153         } else {
154           $error = 'noerror';
155         }
156         if ($error == 'json'){
157         } elseif ($error == 'status'){
158           $echo = $echo . '<p>'.$error_mes.'</p>';
159         } else {
160           $echo = $echo . '<ul class="coco-list">';
161           foreach ($contents->results as $val){
162                 if (isset($_GET['return'])){
163                   $parsed_url = parse_url($_GET['return']);
164                   if ($parsed_url['query'] != ''){
165                         $return_base_url = $_GET['return'].'&amp;';
166                   } else {
167                         $return_base_url = $_GET['return'].'?';
168                   }
169                 } else {
170                   $return_base_url = "./entries.php?";
171                 }
172                 $return_url = $return_base_url."body=".rawurlencode("{$val->formatted_address}\nmap:{$val->geometry->location->lat}:{$val->geometry->location->lng}").'&amp;from='.rawurlencode($val->address_components[0]->long_name);
173                 $echo = $echo . '<li>';
174                 $echo = $echo . "<p><a href=\"{$return_url}\" class=\"navigation-link\">";
175                 $echo = $echo . $val->formatted_address;
176                 $echo = $echo . '</a></p>';
177                   $echo = $echo . "<a href=\"http://www.google.co.jp/m/local?site=local&amp;q={$val->geometry->location->lat}%2C{$val->geometry->location->lng}\" class=\"external-link\">";
178                 if ($get_image == 'on') {
179                   $echo = $echo . "<img src=\"http://maps.google.com/maps/api/staticmap?maptype=mobile&amp;markers={$val->geometry->location->lat}%2C{$val->geometry->location->lng}&amp;sensor=false&amp;size=140x140&amp;zoom=13\" width=\"140\" height=\"140\" />";
180                 } else {
181                   $echo = $echo . "→Google Maps で確認";
182                 }
183                   $echo = $echo . "</a>";
184                 $echo = $echo . '</li>'."\n";
185           }
186           $echo = $echo . '</ul>';
187         }
188   }
189 //   var_dump($error);
190   $echo = $echo . "</div>";
191 }
192 $echo = $echo . '<p class="credit">位置情報の取得には <a href="' . $mobile_gateway . 'http://code.google.com/intl/ja/apis/maps/documentation/geocoding/">Google Geocoding API</a> を利用しています。</p>'."\n".'<hr />';
193 ?>
194 <?php
195 $navi_paging = FALSE;
196 $navi_imaging = TRUE;
197 require 'footer_include.php';
198 $echo = $echo . '</body></html>';
199 echo mb_convert_encoding($echo, $charcode, 'UTF-8');
200 ?>