OSDN Git Service

一頁に表示できる最大件数を200に拡大。ユーザーTLとキーワードTLで長い投稿を省略しないように変更。
[yanmah2/YANMAH2-season2-.git] / entry_processor.php
1 <?php
2 //YANMAH2 - Yet ANother Mobile Accelerated HatenaHaiku
3 //(c) 2019 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 defined("HELLO") or exit(); ?>
7 <?php
8 if ((isset($entry_processor_mode) && ($entry_processor_mode == 'users' || $entry_processor_mode == 'keyword_users')) || (isset($entries_mode) && $entries_mode == 'favours')){
9 //   echo "...";
10   if (in_array("{$val->user->id}", $ustock)) return;
11   $echo = $echo . "<dt>";
12   if ($get_image == 'on' || (isset($show_icon) && $show_icon == 'yes')){
13           $echo = $echo . '<img src="' . $val->user->profile_image_url . '" width="16" height="16" class="user-icon" alt="" /> ';
14   }
15   if (preg_match("/^(id:{1})([[:alpha:]]{1}[-_a-zA-Z1234567890]{1,30}[[:alnum:]]{1})$/u", $val->keyword)) {
16         $keyword_title = $val->keyword;
17   } else {
18         $keyword_title = $val->target->title;
19   }
20   $echo = $echo . "<a href=\"./entries.php?user={$val->user->id}";
21   $echo = $echo . "\" class=\"hatena-id\">{$val->user->name} (id:{$val->user->id})</a></dt>\n";
22   $echo = $echo . "<dd><a href=\"./entries.php?keyword=".rawurlencode($val->keyword);
23   $echo = $echo . "\" class=\"keyword\">".htmlspecialchars($keyword_title)."</a></dd>\n";
24   $ustock[] = "{$val->user->id}";
25 } else {
26 //タイムスタンプ-0
27   $unix_time = strtotime($val->created_at);
28   if (isset($first_e) && $first_e != '') $first_time = $unix_time; unset($first_e);
29   $entry_body = $val->html_touch;
30   if ($entries_mode == 'default' || $entries_mode == 'album'){
31     foreach ($dict as $dfn) {
32 //       var_dump($dfn);
33       $dmt = preg_grep("/".preg_quote("{$entry_body}", '/')."/u", $dfn);
34 //       var_dump($dmt);
35       if (isset($dmt["{$val->user->id}"])){ $spam = $spam + 1; return; }
36     }
37     $dict[] = array("{$val->user->id}" => "{$entry_body}");
38   }
39 //   if (($entries_mode == 'default'  || $entries_mode == 'album') && 
40 //       preg_match("/(^{$http_url_regexp}$)/u", "{$val->keyword}")){ $spam = $spam + 1;  return; }
41   if (preg_match("/^(id:{1})([[:alpha:]]{1}[-_a-zA-Z1234567890]{1,30}[[:alnum:]]{1})$/u", $val->keyword)) {
42         $keyword_title = $val->keyword;
43   } else {
44         $keyword_title = $val->target->title;
45   }
46 $entry_body = preg_replace("/^([  ]*<br>){1,}/u", "", $entry_body);
47 $entry_body = preg_replace("/(<br>){1,}$/u", "", $entry_body);
48 $entry_body = preg_replace("/<br>/u", "<br />", $entry_body);
49 $entry_body = preg_replace("/([  ]*<br \/>){3,}/u", "<br /><br />", $entry_body);
50 $entry_body = preg_replace("/<br \/>/u", "<br />\n", $entry_body);
51 //改行削減
52 if (isset($disbr) && $disbr == 'no'){
53 } elseif ($entries_mode == 'friends_timeline' || $entries_mode == 'default' || $entries_mode == 'keyword_timeline'){
54   $list_mark = "-1234567890一二三四五六七八九〇1234567890・*○●◎△▲▽▼□■◇◆×>#;#;";
55   $entry_body = preg_replace("/([  ]*<br \/>){2,}/u", "<br />", $entry_body);
56   $entry_body = preg_replace("/(^[{$list_mark}]{1,}.+|^&gt;.+)(<br \/>)/um", " \${1}\${2}<br />", $entry_body);
57   $entry_body = preg_replace("/<br \/>\n/u", "<br />", $entry_body);
58   $entry_body = preg_replace("/([^><」」』】\]]。.  ]{1})<br \/>([^{$list_mark}  ><「「『【\[[]{1})/u", "\${1} \${2}", $entry_body);
59 //   var_dump($entry_body);
60   $entry_body = preg_replace("/([,、]{1})[ ]{1}/u", "\${1}", $entry_body);
61   $entry_body = preg_replace("/([  ]*<br \/>){2,}/u", "<br />", $entry_body);
62 }
63 //
64 $entry_body = preg_replace("/(<br \/>)/u", "\n\${1}\n", $entry_body);
65 $entry_body = preg_replace("/\n+/u", "\n", $entry_body);
66 $entry_body = preg_replace("/\n$/u", "", $entry_body);
67 if (preg_match("/((<br \/>|\n)*&gt;&gt;(<br \/>|\n))(.+)((<br \/>\n)&lt;&lt;(<br \/>|\n)*)/us", $entry_body)) {
68   $bquote = "1";
69 } else {
70   $bquote = "0";
71 }
72 //文字数制限
73 if ($entry_processor_mode == "entries" && !preg_match('/^(kalen_t|fumobot)$/u', $val->user->id)
74     && $entries_mode != 'user_timeline' && $entries_mode != 'keyword_timeline'){
75   $see_more = "<a href=\"./entry.php?entry={$val->id}&amp;user={$val->user->id}&amp;keyword=" . rawurlencode($val->keyword) . "\" class=\"see-more\">(…)</a>";
76   $plain_body = strip_tags($entry_body);
77   $entry_width = mb_strwidth($plain_body);
78   if (($entries_mode == 'default'  || $entries_mode == 'album') && 
79       preg_match("/(^{$http_url_regexp}$)|(^{$http_path_regexp}$)|(^{$http_url_regexp}.+{$http_url_regexp}$)/us", $plain_body) && 
80       !preg_match("/<img[^>]+>/u", $entry_body)){ $spam = $spam + 1;  return; }
81   $tranc_width = $entry_limit - ($entry_limit/3);
82   if ($entry_width > ($entry_limit)){
83         $plain_body = mb_strimwidth($plain_body, 0, $tranc_width, '', "UTF-8");
84         $text_a = explode("\n", $entry_body);
85         $plain_a = explode("\n", $plain_body);
86 //      var_dump($text_a);
87         $tail = count($plain_a) - 1;
88         $text_a[$tail] = $plain_a[$tail];
89         $text_a = array_slice($text_a, 0, $tail + 1);
90         $entry_body = implode("\n", $text_a) . $see_more;
91         //var_dump($entry_body_temp);
92   }
93 }
94 //引用記法
95 if ($bquote == 1) {
96         $entry_body = preg_replace("/(\n|<br \/>)*&gt;&gt;(\n|<br \/>)/us", "<blockquote>", $entry_body);
97         $entry_body = preg_replace("/(\n|<br \/>)&lt;&lt;(\n|<br \/>)*/us", "</blockquote>", $entry_body);
98         $entry_body = preg_replace("/(<blockquote>|<\/blockquote>)<br \/>/u", "\${1}", $entry_body);
99 }
100 if (preg_match("/<blockquote>/u", $entry_body) && !preg_match("/<\/blockquote>/u", $entry_body)){
101   $entry_body = $entry_body."</blockquote>";
102 }
103   $entry_body = preg_replace("/<a href=\"http:\/\/h[^\.]*\.hatena\.[^\/]+\/touch\/target\?word=([^\"]+)\" class=\"keyword\">/u", "<a href=\"./entries.php?keyword=\${1}\" class=\"keyword\">", $entry_body);
104   $entry_body = preg_replace("/<a href=\"http:\/\/h[^\.]*\.hatena\.[^\/]+\/touch\/([^\/]+)\/\" class=\"user\">/u", "<a href=\"./entries.php?user=\${1}\" class=\"user\">", $entry_body);
105   $entry_body = preg_replace("/<a[^>]*href=\"(http:\/\/h[[:alnum:]]*\.hatena\.[^\/]+\/*)\/touch\/asin\/([[:alnum:]]+)\"[^>]*>/u", "<a href=\"./entries.php?keyword=asin%3A\${2}\" class=\"keyword\">", $entry_body);
106 $entry_body = preg_replace("/<div class=\"*user-map\"*><a[^>]*><img[^>]*alt=\"((map):(-*[[:digit:]]{1,3}\.*[[:digit:]]*):(-*[[:digit:]]{1,3}\.*[[:digit:]]*))\"[^>]*><\/a><\/div>/u", "\${1}", $entry_body);
107
108 if ($get_image != 'on'){
109   $entry_body = preg_replace("/<a[^>]*><img[^>]*class=\"*(profile-image|favicon)\"*[^>]*><\/a>/u", "", $entry_body);
110   $entry_body = preg_replace("/<div[^>]*><iframe[^>]*src=\"http:\/\/www\.youtube\.com\/embed\/([^\"]+)\"[^>]*><\/iframe><\/div>/u", "<a href=\"http://m.youtube.com/watch?v=\${1}\">YouTube(\${1})</a>", $entry_body);
111 } else {
112   if ($device_who == 'ktai' || $device_who == 'android-old'){
113         $entry_body = preg_replace("/<div[^>]*><iframe[^>]*src=\"http:\/\/www\.youtube\.com\/embed\/([^\"]+)\"[^>]*><\/iframe><\/div>/u", "<a href=\"http://m.youtube.com/watch?v=\${1}\"><img src=\"http://img.youtube.com/vi/\${1}/0.jpg\" alt=\"\" /></a>", $entry_body);
114   } else {
115         $entry_body = preg_replace("/<div[^>]*>(<iframe[^>]*src=\"http:\/\/www\.youtube\.com\/embed\/([^\"]+)\"[^>]*><\/iframe>)<\/div>/u", "\${1}", $entry_body);
116   }
117 }
118 //はてなスター
119 if ($val->favorited != "0"){
120 if (isset($starisjs) && $starisjs == '1'){
121   $show_star = '';
122 } else {
123         $show_star = "<span class=\"hatena-star\"><a href=\"http://s.hatena.ne.jp/mobile/entry?uri=" . rawurlencode("http://h.hatena.ne.jp/{$val->user->id}/{$val->id}") . "\">★{$val->favorited}</a></span>";
124 }
125 } else {
126         $show_star = "";
127         }
128 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
129 if (isset($starisjs) && $starisjs == '1'){
130   $add_star = '';
131 } else {
132         $add_star = '<input type="submit" value="☆+" title="add-star" class="add-star-button" style="vertical-align: middle;"><input type="hidden" name="posting" value="favo" /><input type="hidden" name="entry" value="' . $val->id . '" /><input type="hidden" name="return" value="' . htmlspecialchars($self_anchor_possibly_with_pagenum, ENT_QUOTES);
133         if (isset($entry_processor_mode) && $entry_processor_mode != 'entry') $add_star = $add_star . '&amp;reftime=-'.$first_time . ',0'. '#'.$val->id;
134         $add_star = $add_star . '" /> ';
135 }
136 }       else {
137         $add_star = '';
138 }
139 //キーワードの前処理
140   $headend = "<br />";
141 if ($entries_mode == 'keyword_timeline'){
142   $entry_kw = '';
143 } elseif (mb_ereg_match("^{$http_url_regexp}$",htmlspecialchars($val->keyword, ENT_QUOTES))){
144         $entry_kw = "URL:%KEYWORD%</span>{$headend}\n";
145 //      var_dump($entry_body);
146 } elseif (preg_match("/^asin:[[:alnum:]]+$/u", $val->keyword)){
147         $entry_kw = "ASIN:%KEYWORD%</span>{$headend}\n";
148 } elseif (!isset($val->keyword)){
149         $entry_kw = "</span>{$headend}\n";
150 } elseif (preg_match("/^(id:{1})(.+)/u", $val->keyword) == 0) {
151 //      var_dump($entry_body);
152         $entry_kw = "%KEYWORD%</span>{$headend}\n";
153 } else {
154         $entry_kw = "%KEYWORD%</span>{$headend}\n";
155 }
156 //var_dump($entry_body);
157 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
158         $replying = '<a href="./entry.php?entry=' . $val->id . '&amp;user=' . $val->user->id . '&amp;keyword=' . rawurlencode($val->keyword) . '" class="replying">Re</a> ';
159 } else {
160   $replying = '';
161 }
162 //
163 // var_dump($entry_body);
164 //公式モバイル版における各エントリへのリンク URL 生成
165 $refer_link = "http://{$haiku_host}/" . $val->user->id . "/" . $val->id;
166 //タイムスタンプ
167 if (preg_match("/[0-2][0-9]:[0-9]{2}:[0-9]{2}/u", $val->keyword)){
168   $dating = date("Y-m-d H:i:s", $unix_time);
169 } else {
170   $day = date("Ymd", $unix_time);
171   $time = date("H:i", $unix_time);
172   $year = date("Y", $unix_time);
173   $today = date("Ymd");
174   $tyear = date("Y");
175   if ($year < $tyear){
176         $dating = date("Y-m-d", $unix_time).' '.$time;
177   } elseif ($day == $today){
178         $dating = ''.$time;
179   } elseif ($day == $today-1){
180         $dating = '昨日 '.$time;
181   } elseif ($day == $today-2){
182         $dating = '一昨日 '.$time;
183   } elseif ($day <= $today-3 && $day >= $today-6){
184         $wdaynum = getdate($unix_time);
185         $wdaylabel = array('日曜日','月曜日','火曜日','水曜日','木曜日','金曜日','土曜日');
186         $dating = $wdaylabel[$wdaynum['wday']].' '.$time;
187   } else {
188         $dating = date("Y-m-d", $unix_time).' '.$time;
189   }
190 }
191 $entry_body_a = explode("\n", $entry_body);
192 $entry_body_b = array();
193 foreach ($entry_body_a as $line){
194   if ($get_image == 'on' && $mobile_gateway_for_images != ''){
195   if (preg_match("/<a[^>]*href=\".+(youtube|ugomemo|nicovideo).+\"[^>]*><img/u", $line)){
196         $line = preg_replace("/<a[^>]*href=\"({$http_url_regexp})\"[^>]*>(<img[^>]*src=\")({$http_url_regexp})(\"[^>]*>)/ue", "'<a href=\"\\1\">\\2{$mobile_gateway_for_images}'.rawurlencode(rawurldecode('\\3')).'\\4';", $line);
197   } elseif (preg_match("/<a[^>]*href=\"({$http_url_regexp})\"[^>]*>(<img[^>]*src=\")({$http_url_regexp})(\"[^>]*>)/u", $line)){
198         $line = preg_replace("/<a[^>]*href=\"(http:{$http_path_regexp})\"[^>]*>(<img[^>]*src=\")({$http_url_regexp})(\"[^>]*>)/ue", "'<a href=\"\\3\">\\2{$mobile_gateway_for_images}'.rawurlencode(rawurldecode('\\3')).'\\4';", $line);
199   }
200   }
201   if (mb_check_encoding(urldecode($line), 'UTF-8')){
202         $line = preg_replace("/<a[^>]*href=\"(http:{$http_path_regexp})\"[^>]*>([^<]+)<\/a>/ue", "'<a href=\"{$mobile_gateway}'.rawurlencode(rawurldecode('\\1')).'\">'.rawurldecode('\\2').'</a>';", $line);
203   } else {
204   }
205   if ($get_image != 'on'){
206         if (preg_match("/<a[^>]*href=\".+(youtube|ugomemo|nicovideo).+\"[^>]*><img/u", $line)){
207           $line = preg_replace("/<img[^>]*alt=\"([^>\"]*)\"[^>]*>/ui", "\${1}", $line);
208           
209         } else {
210           $line = preg_replace("/<img[^>]*src=\"([^>\"]*)\"[^>]*>/uie", "parse_url('\\1', PHP_URL_HOST) . '(' . basename('\\1') . ')';", $line);
211         }
212   }
213   $line = mb_ereg_replace('\\\("|\'|\\\)', "\\1", $line);
214   $entry_body_b[] = $line;
215 }
216 $entry_body = implode("\n", $entry_body_b);
217
218 // var_dump($entry_body);
219 //map 記法の処理
220 if ($get_image == 'on'){
221   $entry_body = preg_replace("/(map):(-*[[:digit:]]{1,3}\.*[[:digit:]]*):(-*[[:digit:]]{1,3}\.*[[:digit:]]*)/u", "<a href=\"http://www.google.co.jp/m/local?site=local&amp;q=\${2}%2C\${3}\" class=\"to-map\"><img src=\"http://maps.google.com/maps/api/staticmap?maptype=mobile&amp;markers=\${2}%2C\${3}&amp;sensor=false&amp;size=140x140&amp;zoom=13\" width=\"140\" height=\"140\" /></a><br />", $entry_body);
222 } else {
223   $entry_body = preg_replace("/(map):(-*[[:digit:]]{1,3}\.*[[:digit:]]*):(-*[[:digit:]]{1,3}\.*[[:digit:]]*)/u", "<a href=\"http://www.google.co.jp/m/local?site=local&amp;q=\${2}%2C\${3}\" class=\"to-map\">\${1}:\${2}:\${3}</a><br />", $entry_body);
224 }
225 //表示
226 $echo = $echo . "<div class=\"entry\"";
227 if (!isset($eprocessor_sub_mode) || $eprocessor_sub_mode != 'presult'){
228   $echo = $echo . " id=\"{$val->id}\"";
229 }
230 $echo = $echo . ">";
231
232 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
233   if (isset($starisjs) && $starisjs == '1'){
234   } else {
235     $echo = $echo . '<form method="post" action="';
236     $echo = $echo . './post.php';
237     $echo = $echo . '" class="star-form">';
238   }
239 }
240 $echo = $echo . "<span class=\"entry-head\">";
241 if ($get_image == 'on' || (isset($show_icon) && $show_icon == 'yes')){
242         $echo = $echo . '<img src="' . $val->user->profile_image_url . '" width="16" height="16" class="user-icon" alt="" /> ';
243 }
244
245 //キーワードの処理
246 if (!isset($val->keyword)){
247         $entry_body = ' ' . $add_star . $show_star . $entry_body;
248 }
249 if ($entries_mode == 'keyword_timeline'){
250   $entry_kw = $add_star . $show_star . '</span>' . $headend . "\n";
251 } else {
252   $entry_kw = str_replace("%KEYWORD%","<a href=\"./entries.php?keyword=" . rawurlencode($val->keyword) . "\" class=\"keyword\">". htmlspecialchars($val->target->title, ENT_QUOTES) . "</a> {$add_star}{$show_star}",$entry_kw);
253
254 //id キーワードの処理
255   if (preg_match('/^(id:{1}[a-zA-Z]{1}[-_a-zA-Z1234567890]{1,30}[a-zA-Z1234567890]{1})$/u',$val->keyword) >= 1){
256
257   $entry_kw = "<a href=\"./entries.php?keyword=" . rawurlencode($val->keyword) . "\" class=\"keyword\">" . htmlspecialchars($val->target->word, ENT_QUOTES) . "</a> {$add_star}{$show_star}</span>{$headend}\n";
258   }
259 }
260 //Reply-to
261 if ($val->in_reply_to_status_id != ''){
262 //      echo "...";
263         $reply_to = "<span class=\"reply-to reply\"><a href=\"./entry.php?entry={$val->in_reply_to_status_id}&amp;user={$val->in_reply_to_user_id}&amp;keyword=" . rawurlencode($val->keyword) . "\" class=\"hatena-id\">[← " . $val->in_reply_to_user_id . " へ</a></span>";
264         if (mb_substr_count($entry_body, '<br />') < 1){
265                 if (preg_match('/\[画像\(.+\)\]/u', $entry_body) || preg_match('/<img[^>]+\/>/u', $entry_body)){
266                         $reply_to = $reply_to."<br />\n";
267                 } else {
268                         $reply_to = $reply_to.' ';
269                 }
270         } else {
271                 $reply_to = $reply_to."<br />\n";
272         }
273         $entry_body = $reply_to.$entry_body;
274 }
275 //Reply-from
276 if (isset($reply_from)){
277         unset($reply_from);
278 }
279 if (isset($in_reply)){
280         unset($in_reply);
281 }
282 if (isset($val->replies[0]->id)){
283   $in_reply = '';
284         foreach($val->replies as $replies){
285                 $in_reply = $in_reply . " <a href=\"./entry.php?entry={$replies->id}&user={$replies->user->id}&amp;keyword=" . rawurlencode($val->keyword) . "\" class=\"hatena-id\">[← {$replies->user->id} から</a> ";
286         }
287         $reply_from = "<span class=\"reply-from reply\">{$in_reply}</span>";
288 } else {
289   $reply_from = '';
290 }
291 //
292 $entry_body = mb_ereg_replace('\\\("|\'|\\\)', "\\1", $entry_body);
293 // var_dump($entry_body);
294 $echo = $echo . "{$dating} ";
295 $echo = $echo . $entry_kw;
296 if ($get_image == 'on'){
297   $echo = $echo . "<p class=\"entry-body eb-rich\">";
298 } else {
299   $echo = $echo . "<p class=\"entry-body\">";
300 }
301 $echo = $echo . $entry_body;
302 $echo = $echo . "</p>\n";
303 $echo = $echo . "<span class=\"dating\">";
304 $echo = $echo . "by <a href=\"./entries.php?user=";
305 $echo = $echo . $val->user->id;
306 $echo = $echo . "\" class=\"hatena-id\" title=\"id:{$val->user->screen_name}\">";
307 $echo = $echo . htmlspecialchars($val->user->name, ENT_QUOTES);
308 $echo = $echo . '</a> ';
309 $echo = $echo . ' ';
310 if ($entry_processor_mode == 'entry'){
311   $echo = $echo . 'from ' . $val->source . ' ';
312 }
313 $echo = $echo . "{$replying}{$reply_from} <a href=\"{$refer_link}\" class=\"to-original-link\">&nbsp;†&nbsp;</a>";
314 $echo = $echo . '</span>';
315 if (isset($_SESSION['auth']) && $_SESSION['auth'] === TRUE){
316 if (isset($starisjs) && $starisjs == '1'){
317 } else {
318   $echo  = $echo . "</form>";
319 }
320
321 $echo = $echo . "</div><hr />\n";
322 }
323 ?>