2 //YANMAH2 - Yet ANother Mobile Accelerated HatenaHaiku
3 //(c) 2012 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).
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";
14 require_once 'init_processor.php';
15 // var_dump($_SESSION);
18 $selfcall = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES);
19 $safequery = htmlspecialchars($_SERVER["QUERY_STRING"], ENT_QUOTES);
21 <?php //セキュリティのための前処理。
24 if (!isset($_SESSION['auth']) || $_SESSION['auth'] != TRUE){
25 // if ($_SESSION['image'] != 'on'){
27 if (isset($_COOKIE[session_name()])){
28 setcookie(session_name(), '', time() - 42000, dirname($_SERVER['SCRIPT_NAME']) . '/', $_SERVER["SERVER_NAME"]);
36 if (isset($_GET['q'])){
40 if (isset($_GET['q'])){
41 $get_q = htmlspecialchars($_GET['q'], ENT_QUOTES);
42 $get_q = mb_convert_encoding($get_q, 'UTF-8', $charcode);
43 $address = mb_convert_encoding($_GET['q'], 'UTF-8', $charcode);
44 $address = urlencode($address);
45 if (isset($_GET['return'])) $get_return = htmlspecialchars($_GET['return'], ENT_QUOTES);
46 $json_url = "http://maps.google.com/maps/api/geocode/json?address={$address}&language=ja&sensor=false";
47 $page_head = "{$get_q} でイマココ";
48 $self_anchor = "http://{$_SERVER["SERVER_NAME"]}{$selfcall}?q={$get_q}";
49 if (isset($_GET['return'])) $self_anchor = $self_anchor.'&return='.$get_return;
50 $coco_mode = 'coco-result';
52 if (isset($_GET['return'])) $get_return = htmlspecialchars($_GET['return'], ENT_QUOTES);
53 $page_head = "検索してイマココ";
54 $self_anchor = "http://{$_SERVER["SERVER_NAME"]}{$selfcall}";
55 if (isset($_GET['return'])) $self_anchor = $self_anchor.'?return='.$get_return;
56 $coco_mode = 'coco-ready';
58 $self_anchor_possibly_with_pagenum = $self_anchor;
59 if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != ''){
60 $relog_back = $self_anchor_possibly_with_pagenum . '&log=try';
61 $relogin = $self_anchor_possibly_with_pagenum . '&with=haiku&callback='.rawurlencode($relog_back);
63 $relog_back = $self_anchor_possibly_with_pagenum . '?log=try';
64 $relogin = $self_anchor_possibly_with_pagenum . '?with=haiku&callback='.rawurlencode($relog_back);
66 if (isset($_GET['image']) && $_GET['image'] == 'on'){
67 if (preg_match('/^image=on$/u', $_SERVER['QUERY_STRING'])){
68 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
69 } elseif (isset($_GET['log']) && preg_match('/^log=(on|off)$/u', $_SERVER['QUERY_STRING'])){
70 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
71 } elseif ($_SERVER["QUERY_STRING"] != ""){
72 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&image=on';
74 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=on';
77 if (preg_match('/^image=off$/u', $_SERVER['QUERY_STRING'])){
78 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
79 } elseif (isset($_GET['log']) && preg_match('/^log=(off|on)$/u', $_SERVER['QUERY_STRING'])){
80 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
81 } elseif ($_SERVER["QUERY_STRING"] != ""){
82 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&image=off';
84 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '?image=off';
91 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
92 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
93 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
95 <meta http-equiv="Content-Type" content="text/html; charset={$meta_charset}" />
96 <meta http-equiv="Content-Style-Type" content="text/css" />
97 <meta http-equiv="Content-Script-Type" content="text/javascript" />
98 <meta name="viewport" content="initial-scale={$iscale}, minimum-scale=0.1" />
99 <title>{$page_head} - {$site_name} {$site_name_caption}</title>
100 <link rel="stylesheet" href="{$style_sheet}" />
101 <link rel="icon" href="./favicon.ico" type="image/vnd.microsoft.icon" />
102 <link rel="shortcut icon" href="./favicon.ico" type="image/vnd.microsoft.icon" /></head>
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>";
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>';
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";
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)){
139 // $error_mes = libxml_get_last_error();
140 $echo = $echo . "<p>はわわ、何かのエラーです。</p>";
141 $echo = $echo . "<blockquote>{$json_body}</blockquote>";
142 // var_dump($error_mes);
143 } elseif ($contents->status != 'OK'){
145 if ($contents->status == 'ZERO_RESULTS'){
146 $error_mes = $contents->status.': 住所が見つかりません。';
147 } elseif ($contents->status == 'OVER_QUERY_LIMIT'){
148 $error_mes = $contents->status.': 現在検索できません。';
149 } elseif ($contents->status == 'REQUEST_DENIED'){
150 $error_mes = $contents->status.': 要求が成立しませんでした。';
151 } elseif ($contents->status == 'INVALID_REQUEST'){
152 $error_mes = $contents->status.': クエリーが不正です。';
157 if ($error == 'json'){
158 } elseif ($error == 'status'){
159 $echo = $echo . '<p>'.$error_mes.'</p>';
161 $echo = $echo . '<ul class="coco-list">';
162 foreach ($contents->results as $val){
163 if (isset($_GET['return'])){
164 $parsed_url = parse_url($_GET['return']);
165 if ($parsed_url['query'] != ''){
166 $return_base_url = $_GET['return'].'&';
168 $return_base_url = $_GET['return'].'?';
171 $return_base_url = "./entries.php?";
173 $return_url = $return_base_url."body=".rawurlencode("{$val->formatted_address} にイマココ!\nmap:{$val->geometry->location->lat}:{$val->geometry->location->lng}").'&from='.rawurlencode($val->address_components[0]->long_name);
174 $echo = $echo . '<li>';
175 $echo = $echo . "<p><a href=\"{$return_url}\" class=\"navigation-link\">";
176 $echo = $echo . $val->formatted_address . ' にイマココする';
177 $echo = $echo . '</a></p>';
178 $echo = $echo . "<a href=\"http://www.google.co.jp/m/local?site=local&q={$val->geometry->location->lat}%2C{$val->geometry->location->lng}\" class=\"external-link\">";
179 if ($get_image == 'on') {
180 $echo = $echo . "<img src=\"http://maps.google.com/maps/api/staticmap?maptype=mobile&markers={$val->geometry->location->lat}%2C{$val->geometry->location->lng}&sensor=false&size=140x140&zoom=13\" width=\"140\" height=\"140\" />";
182 $echo = $echo . "→Google Maps で確認";
184 $echo = $echo . "</a>";
185 $echo = $echo . '</li>'."\n";
187 $echo = $echo . '</ul>';
191 $echo = $echo . "</div>";
193 $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 />';
196 $navi_paging = FALSE;
197 $navi_imaging = TRUE;
198 require 'footer_include.php';
199 $echo = $echo . '</body></html>';
200 echo mb_convert_encoding($echo, $charcode, 'UTF-8');