OSDN Git Service

一頁に表示できる最大件数を200に拡大。ユーザーTLとキーワードTLで長い投稿を省略しないように変更。
[yanmah2/YANMAH2-season2-.git] / entry.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 define("HELLO","world");
8 require_once "product_definitions.php";
9 require_once "configurable_variables.php";
10 require_once "common_functions.php";
11 ?>
12 <?php
13 require_once "init_processor.php";
14 $selfcall = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES);
15 if (!isset($_SERVER['QUERY_STRING']) || $_SERVER['QUERY_STRING'] == '') {
16   echo 'nan nimo nai.';
17   exit();
18 }
19 $safequery = htmlspecialchars($_SERVER["QUERY_STRING"], ENT_QUOTES);
20 ?>
21 <?php
22 ?>
23 <?php
24 //entry id
25 if (isset($_GET['entry'])) checkEntryid($_GET['entry']);
26 //不正なはてなID
27 if (isset($_GET["user"])) checkId($_GET["user"]);
28 //長すぎる keyword
29 if (isset($_GET["keyword"])) checkKeyword($_GET["keyword"]);
30 //
31 if (isset($_GET['image'])) checkImagemode($_GET['image']);
32 if (isset($_SESSION['image'])) checkImagemode($_SESSION['image']);
33 ?>
34 <?php
35 if (!isset($_SESSION['auth']) || $_SESSION['auth'] != TRUE){
36   $_SESSION = array();
37   if (isset($_COOKIE[session_name()])){
38         setcookie(session_name(), '', time() - 42000, dirname($_SERVER['SCRIPT_NAME']) . '/', $_SERVER["SERVER_NAME"]);
39   }
40   session_destroy();
41 }
42 ?>
43 <?php
44 //
45 if (isset($_GET['with']) || isset($_GET['log'])){
46   require 'login_processor.php';
47 }
48 // if (isset($_SESSION['oauth_stat'])) session_regenerate_id(TRUE);
49
50 //投稿処理の呼び出し。
51 if (isset($_POST['posting'])){
52   require 'post_processor.php';
53 }
54 ?>
55 <?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";
59 }
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'] == ''){
68         $page_head = 'エントリー';
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;
72 }
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';
77 } else {
78                 $self_anchor_with_imagemode = $self_anchor_possibly_with_pagenum . '&image=off';
79 }
80 $relog_back = $self_anchor_with_imagemode . '&log=try';
81 $relogin = $self_anchor_with_imagemode . '&amp;with=haiku&amp;callback='.rawurlencode(rawurldecode($relog_back));
82 ?>
83 <?php
84 $echo = <<<EOL
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">
88 <head>
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" />
98
99 EOL;
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 = {
105           entryNodes: {
106                 'div.entry': {
107                   uri: 'a.to-original-link',
108                   title: 'a.keyword',
109                   container: 'span.entry-head'
110                 }
111           }
112         };
113         </script>
114
115 EOL;
116 }
117 $echo = $echo . <<<EOL
118 </head>
119 <body>
120 <div id="page">
121 EOL;
122 ?>
123 <?php
124 //var_dump($_GET);
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\">&nbsp;‡&nbsp;</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";      
145                   } else {
146                         $echo = $echo . '<span>' . $_SESSION['post_result_mes'] . '</span>';
147                   }
148
149         }
150         if ($_SESSION['post_result'] === FALSE){
151                 $echo = $echo . '<span>' . $_SESSION['post_result_mes'] . '</span>';
152                 $echo = $echo . "<blockquote>{$_SESSION['post_error']}</blockquote>";
153         }
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();
161   }
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";
166   } else {
167         $echo = $echo . "<span>アクセストークンを取得できませんでした。</span>\n";
168         $echo = $echo . "<blockquote>{$oauth_stat}</blockquote>";
169   }
170   $echo = $echo . '</div>'."\n";
171 }
172 $echo = $echo . '<div class="contents">'."\n";
173 ?>
174
175 <?php
176 if (isset($_GET['image'])){
177         $_SESSION['image'] = $_GET['image'];
178 }
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";
186   } else {
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";    
198     } else {
199           $entry_processor_mode = "entry";
200           $val = $contents;
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';
208                   }
209                   $echo = $echo . '</dd>';
210                   $echo = $echo . '</dl>';
211             }
212     }
213   }
214 } else {
215   $echo = $echo . '<p>内容を読むには<a href="./login.php?return='.rawurlencode(rawurldecode($self_anchor_with_imagemode)).'" class="navigation-link">ログイン</a>してください。</p>';
216 }
217 ?>
218 <?php
219 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
220   if ($device_who == 'ktai'){
221         $rows = '3';
222   } else {
223         $rows = '6';
224   }
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}">
229 EOL;
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
234 </textarea><br />
235 <input type="hidden" name="posting" value="status" />
236 <input type="hidden" name="return" value="
237 EOL;
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);
241   }
242   if (isset($_SESSION['source']) && $_SESSION['source'] != ''){
243         $from = $_SESSION['source'];
244   } else {
245         $from = $product_name_abbr;
246   }
247   $echo = $echo . <<<EOL
248 " />
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" />
252  <a href="./coco.php?
253 EOL;
254   $echo = $echo . "return=".rawurlencode($self_anchor_with_imagemode);
255   $echo = $echo . '" class="navigation-link">イマココ</a>';
256   $echo = $echo . '</form>';
257   $echo = $echo . '</dd>';
258 }
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>';
271 //   }
272 // }
273 ?>
274 <?php
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']);
281 ?>