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).
7 define("HELLO","world");
8 require_once "product_definitions.php";
9 require_once "configurable_variables.php";
10 require_once "common_functions.php";
13 require_once "init_processor.php";
14 $selfcall = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES);
15 if (!isset($_SERVER['QUERY_STRING']) || $_SERVER['QUERY_STRING'] == '') {
19 $safequery = htmlspecialchars($_SERVER["QUERY_STRING"], ENT_QUOTES);
25 if (isset($_GET['entry'])) checkEntryid($_GET['entry']);
27 if (isset($_GET["user"])) checkId($_GET["user"]);
29 if (isset($_GET["keyword"])) checkKeyword($_GET["keyword"]);
31 if (isset($_GET['image'])) checkImagemode($_GET['image']);
32 if (isset($_SESSION['image'])) checkImagemode($_SESSION['image']);
35 if (!isset($_SESSION['auth']) || $_SESSION['auth'] != TRUE){
37 if (isset($_COOKIE[session_name()])){
38 setcookie(session_name(), '', time() - 42000, dirname($_SERVER['SCRIPT_NAME']) . '/', $_SERVER["SERVER_NAME"]);
45 if (isset($_GET['with']) || isset($_GET['log'])){
46 require 'login_processor.php';
48 // if (isset($_SESSION['oauth_stat'])) session_regenerate_id(TRUE);
51 if (isset($_POST['posting'])){
52 require 'post_processor.php';
56 if ($_GET['entry'] != ''){
57 $get_entry = htmlspecialchars($_GET['entry'],ENT_QUOTES);
58 $json_url = "{$api_base_url}statuses/show/{$_GET['entry']}.xml?body_formats=html_touch";
60 if ($_GET['user'] != ''){
61 $get_user = htmlspecialchars($_GET['user'], ENT_QUOTES);
62 $get_keyword = htmlspecialchars($_GET['keyword'], ENT_QUOTES);
63 $page_head = $get_user . ' さんのエントリー';
64 $official = $haiku_official_url . $get_user . '/' . $get_entry;
65 $self_anchor = 'http://' . $_SERVER['SERVER_NAME'] . $selfcall . '?entry=' . rawurlencode($_GET['entry']) . '&user=' . rawurlencode($_GET['user']) . '&;keyword='. rawurlencode($_GET['keyword']);
66 $self_anchor_possibly_with_pagenum = $self_anchor;
67 } elseif ($_GET['user'] == ''){
69 $official = $haiku_official_url . 'entry' . '/' . $get_entry;
70 $self_anchor = 'http://' . $_SERVER['SERVER_NAME'] . $selfcall . '?entry=' . rawurlencode($_GET['entry']);
71 $self_anchor_possibly_with_pagenum = $self_anchor;
73 $relog_back = $self_anchor_possibly_with_pagenum . '&log=try';
74 $relogin = $self_anchor_possibly_with_pagenum . '&with=haiku&callback='.rawurlencode(rawurldecode($relog_back));
75 if ($get_image == 'on'){
76 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&image=on';
78 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&image=off';
80 $relog_back = $self_anchor_with_imagemode . '&log=try';
81 $relogin = $self_anchor_with_imagemode . '&with=haiku&callback='.rawurlencode(rawurldecode($relog_back));
85 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
86 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
87 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
89 <meta http-equiv="Content-Type" content="text/html; charset={$meta_charset}" />
90 <meta http-equiv="Content-Style-Type" content="text/css" />
91 <meta http-equiv="Content-Script-Type" content="text/javascript" />
92 <meta name="viewport" content="initial-scale={$iscale}, minimum-scale=0.1" />
93 <title>{$page_head} - {$site_name} {$site_name_caption}</title>
94 <link rel="stylesheet" href="{$style_sheet}" />
95 <link rel="icon" href="./favicon.ico" type="image/vnd.microsoft.icon" />
96 <link rel="shortcut icon" href="./favicon.ico" type="image/vnd.microsoft.icon" />
97 <link rel="apple-touch-icon" href="./apple-touch-icon.png" />
100 if (isset($starisjs) && $starisjs == '1'){
101 $echo = $echo . <<<EOL
102 <script type="text/javascript" src="http://s.hatena.ne.jp/js/HatenaStar.js"></script>
103 <script type="text/javascript">
104 Hatena.Star.SiteConfig = {
107 uri: 'a.to-original-link',
109 container: 'span.entry-head'
117 $echo = $echo . <<<EOL
125 $echo = $echo . echoCommonHeader('#navigation-menu', $self_anchor_with_imagemode) . "<hr />\n";
126 $echo = $echo . "<div id=\"header\" class=\"entry_cat\">\n";
127 $echo = $echo . "<h1 id=\"entries-head\" class=\"head1\">{$page_head} <a href=\"{$official}\" class=\"to-original-link\"> ‡ </a></h1>\n<hr />";
128 $echo = $echo . "</div>\n";
129 if (isset($_SESSION['post_result']) && $_SESSION['post_result'] === TRUE or FALSE){
130 $echo = $echo . '<div class="post-result">';
131 // var_dump($_SESSION);
132 if ($_SESSION['post_result'] === TRUE){
133 // var_dump($_SESSION['post_to']);
134 $json_body = $_SESSION['post_body'];
135 $contents = checkEntryData($json_body);
136 if (preg_match("/^oauth_problem=token_rejected$/", $json_body)){
137 $echo = $echo . "<p class=\"oauth-res\">認証情報が無効です。<a href=\"{$relogin}\">再認証</a>を行なってください。</p>";
138 } elseif ($contents['stat'] == FALSE && $contents['ercode'] != 'x'){
139 $echo = $echo . "<p>何かのエラーです。</p>\n";
140 $echo = $echo . print_r(strip_tags($contents['contents']));
141 $echo = $echo . "<br />{$json_body}</blockquote>\n";
142 } elseif ($contents['stat'] == FALSE && $contents['ercode'] == 'x'){
143 $echo = $echo . "<p>何かのエラーですす。</p>\n";
144 $echo = $echo . "<blockquote>{$contents['ermes']}</blockquote>\n";
146 $echo = $echo . '<span>' . $_SESSION['post_result_mes'] . '</span>';
150 if ($_SESSION['post_result'] === FALSE){
151 $echo = $echo . '<span>' . $_SESSION['post_result_mes'] . '</span>';
152 $echo = $echo . "<blockquote>{$_SESSION['post_error']}</blockquote>";
154 $echo = $echo . '</div>';
155 $_SESSION['post_to'] = '';
156 $_SESSION['post_result'] = '';
157 $_SESSION['post_result_mes'] = '';
158 $_SESSION['post_error'] = '';
159 $_SESSION['post_body'] = '';
160 libxml_clear_errors();
162 if (isset($_SESSION['oauth_stat'])){
163 $echo = $echo . '<div class="oauth-res">'."\n";
164 if ($oauth_stat === TRUE) {
165 $echo = $echo . "<span>アクセストークンを更新しました。</span>\n";
167 $echo = $echo . "<span>アクセストークンを取得できませんでした。</span>\n";
168 $echo = $echo . "<blockquote>{$oauth_stat}</blockquote>";
170 $echo = $echo . '</div>'."\n";
172 $echo = $echo . '<div class="contents">'."\n";
176 if (isset($_GET['image'])){
177 $_SESSION['image'] = $_GET['image'];
179 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
180 $request_url = $json_url;
181 $json = getJson($request_url, FALSE);
182 if ($json['stat'] !== TRUE){
183 $contents = strip_tags($json['stat']);
184 $echo = $echo . "<p>はてなハイク API からデータを取得できなかったような気がします。</p>\n";
185 $echo = $echo . "<blockquote>{$contents}</blockquote>\n";
187 $json_body = $json['body'];
188 $contents = simplexml_load_string($json['body']);
189 if (preg_match("/^oauth_problem=token_rejected$/", $json_body)){
190 $echo = $echo . "<p>認証情報が無効です。<a href=\"{$relogin}\">再認証</a>を行なってください。</p>";
191 } elseif (libxml_get_last_error() !== FALSE){
192 $contents = strip_tags($contents);
193 $echo = $echo . "<p>はてなハイク API からデータを取得できなかったような気がします。</p>\n";
194 $echo = $echo . "<blockquote>{$contents}</blockquote>\n";
195 } elseif (isset($contents['error'])){
196 $echo = $echo . "<p>はてなハイク API からデータを取得できなかったような気がします。</p>\n";
197 $echo = $echo . "<blockquote>{$contents['error']}</blockquote>\n";
199 $entry_processor_mode = "entry";
201 require 'entry_processor.php';
202 if (isset($contents->replies) && $contents->replies[0]->id != ''){
203 $echo = $echo . '<dl><dt>リプライ</dt>';
204 $echo = $echo . '<dd>';
205 foreach($contents->replies as $val){
206 $val->keyword = $_GET['keyword'];
207 require 'entry_processor.php';
209 $echo = $echo . '</dd>';
210 $echo = $echo . '</dl>';
215 $echo = $echo . '<p>内容を読むには<a href="./login.php?return='.rawurlencode(rawurldecode($self_anchor_with_imagemode)).'" class="navigation-link">ログイン</a>してください。</p>';
219 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
220 if ($device_who == 'ktai'){
225 $echo = $echo . '<dl class="post-box">';
226 $echo = $echo . '<dt>リプライする</dt><dd>';
227 $echo = $echo . <<<EOL
228 <form method="post" action="./post.php" enctype="application/x-www-form-urlencoded" accept-charset="{$meta_charset}">
230 if (isset($_GET['keyword'])) $echo = $echo . '<input type="hidden" id="post-keyword" name="keyword" value="' . htmlspecialchars($_GET['keyword'], ENT_QUOTES) . '" />';
231 $echo = $echo . '<textarea id="post-text" name="status" rows="'. $rows .'" cols="40">';
232 if (isset($_GET['body'])) $echo = $echo . htmlspecialchars($_GET['body']);
233 $echo = $echo . <<<EOL
235 <input type="hidden" name="posting" value="status" />
236 <input type="hidden" name="return" value="
238 $echo = $echo . htmlspecialchars($self_anchor_possibly_with_pagenum,ENT_QUOTES);
239 if (isset($_GET['from']) && $_GET['from'] != ''){
240 $_SESSION['source'] = htmlspecialchars($_GET['from'], ENT_QUOTES);
242 if (isset($_SESSION['source']) && $_SESSION['source'] != ''){
243 $from = $_SESSION['source'];
245 $from = $product_name_abbr;
247 $echo = $echo . <<<EOL
249 <input type="hidden" name="in_reply_to_status_id" value="{$get_entry}" />
250 <input type="submit" id="post-haiku" value="Haiku!" />
251 <label for="post-from">from </label><input type="text" id="post-from" name="source" value="{$from}" maxlength="170" />
254 $echo = $echo . "return=".rawurlencode($self_anchor_with_imagemode);
255 $echo = $echo . '" class="navigation-link">イマココ</a>';
256 $echo = $echo . '</form>';
257 $echo = $echo . '</dd>';
259 $echo = $echo . "</div>\n";
260 // if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
261 // if (isset($get_entry) && isset($get_user)){
262 // $echo = $echo . '<form method="post" action="" enctype="application/x-www-form-urlencoded" accept-charset="'.$meta_charset.'" class="hateb-form">'."\n";
263 // $echo = $echo . '<label for="bcomment">このエントリをはてなブックマークに追加する。</label><br />';
264 // $echo = $echo . '<label for="bcomment">コメント:</label>';
265 // $echo = $echo . '<input type="text" id="bcomment" name="comment" maxlength="100" value="" title="ブックマークコメント" />';
266 // $echo = $echo . '<input type="hidden" name="url" value="http://'.$haiku_host.'/'.$get_user.'/'.$get_entry.'" />';
267 // $echo = $echo . '<input type="hidden" name="posting" value="hateb" />';
268 // $echo = $echo . '<input type="hidden" name="return" value="'.htmlspecialchars($self_anchor_possibly_with_pagenum, ENT_QUOTES).'" />';
269 // $echo = $echo . '<input type="submit" id="post-hateb" value="[B!]" title="このエントリをはてなブックマークに追加する。" />';
270 // $echo = $echo . '</form>';
275 $navi_paging = FALSE;
276 $navi_imaging = TRUE;
277 require 'footer_include.php';
278 $echo = $echo . '</div></body></html>';
279 echo mb_convert_encoding($echo, $charcode, 'UTF-8');
280 if (isset($_SESSION['oauth_stat'])) unset($_SESSION['oauth_stat']);