OSDN Git Service

一頁に表示できる最大件数を200に拡大。ユーザーTLとキーワードTLで長い投稿を省略しないように変更。
[yanmah2/YANMAH2-season2-.git] / post_processor.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/ormodify 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 $post_return = $_POST['return'];
9 $post_posting = $_POST['posting'];
10 if ($post_posting == 'favo'){
11   $post_entry = $_POST['entry'];
12   $api = "{$api_base_url}favorites/create/{$post_entry}.xml?body_formats=html_touch,api";
13   unset($_POST['entry']);
14 // } elseif ($post_posting == 'hateb'){
15 //   $post_url = $_POST['url'];
16 //   $post_comment = $_POST['comment'];
17 //   $api = "http://b.hatena.ne.jp/atom/post";
18 //   unset($_POST['url'], $_POST['comment']);
19 } else {
20   if ($_POST['status'] == ''){
21         if (isset($_POST['keyword']) && $_POST['keyword'] != ''){
22           $keyword = mb_convert_encoding($_POST['keyword'], 'UTF-8', $charcode);
23           $redirect = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/entries.php?keyword='.rawurlencode($keyword);
24         } else {
25                   $redirect = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/entries.php';
26         }
27
28         header('HTTP/1.1 303 See Other');
29 //      header('HTTP/1.1 302 found');
30         header('Location: '.$redirect);
31         exit();
32   }
33   if (isset($_POST['source'])) $_SESSION['source'] = $_POST['source'];
34   if ($_POST['source'] == '') $_POST['source'] = $product_name_abbr;
35   if (isset($_POST['status'])) $_POST['status'] = mb_convert_encoding($_POST['status'], 'UTF-8', $charcode);
36   if (isset($_POST['keyword'])) $_POST['keyword'] = mb_convert_encoding($_POST['keyword'], 'UTF-8', $charcode);
37   if (!isset($_POST['keyword']) || $_POST['keyword'] == '') $_POST['keyword'] = 'id:' . $_SESSION['hatenaid'];
38         $api = "{$api_base_url}statuses/update.xml?body_formats=html_touch,api";
39 }
40 unset($_POST['return'], $_POST['posting']);
41 $postd = $_POST;
42 /*var_dump($_SESSION);
43 var_dump($_POST);
44 exit();*/
45 if ($post_posting == 'favo' || $post_posting == 'status'){
46 $_SESSION['post_to'] = 'haiku';
47   $json = postGeneric($api, $postd, $conkey, $conkey_sec, $_SESSION['acstoken'], $_SESSION['acs_sec']);
48   if ($json['stat'] === TRUE){
49         $json_body = $json['body'];
50         $contents = checkEntryData($json_body);
51         if ($contents['stat'] == FALSE){
52           $post_return = preg_replace("/^([^#]+)(#.*)/u", "\${1}", $post_return);                       
53         }
54           $_SESSION['post_result'] = TRUE;
55           if ($post_posting == 'status'){
56                 $_SESSION['post_result_mes'] = '投稿しました。';
57           } elseif ($post_posting == 'favo'){
58                 $_SESSION['post_result_mes'] = '.。.:*・゜゚・*☆';
59           } else {
60                 $_SESSION['post_result_mes'] = '投稿しました。';
61           }
62           $_SESSION['post_body'] = $json_body;
63           
64   } else {
65           $_SESSION['post_result'] = FALSE;
66           $_SESSION['post_result_mes'] = 'なんかのエラーですすす。';
67           $_SESSION['post_error'] = $json['error'];
68           $post_return = preg_replace("/^([^#]+)(#.*)/u", "\${1}", $post_return);
69 //        $_SESSION['post_session'] = $json['session'];
70   }
71 }/* elseif ($post_posting == 'hateb'){
72   $_SESSION['post_to'] = 'hateb';
73   $post_comment = mb_convert_encoding($post_comment, 'UTF-8', $charcode);
74   $body = <<<EOL
75 <entry xmlns="http://purl.org/atom/ns#">
76   <title>dummy</title>
77   <link rel="related" type="text/html" href="{$post_url}" />
78   <summary type="text/plain">{$post_comment}</summary>
79 </entry>
80 EOL;
81   $xml = postGeneric($api, $postd, $conkey, $conkey_sec, $_SESSION['acstoken'], $_SESSION['acs_sec'], $body);
82   if ($xml['http'] != '201'){
83         $_SESSION['post_result'] = FALSE;
84         $_SESSION['post_result_mes'] = 'なんかのエラーです。';
85         $_SESSION['post_error'] = $xml['body'];
86   } else {
87         $_SESSION['post_result'] = TRUE;
88         $_SESSION['post_result_mes'] = 'ブックマークを投稿しました。';
89         $_SESSION['post_body'] = $xml['body'];
90   }
91 }*/
92 // if ($device_who == 'android' && preg_match("/(1\.6)|(1\.5)/", $_SERVER['HTTP_USER_AGENT'])){
93 //   $post_return = htmlspecialchars($post_return, ENT_QUOTES);
94 //   echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
95 //   echo "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
96 //   echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" lang=\"ja\">\n";
97 //   echo "<head>\n";
98 //   echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
99 //   echo "<meta http-equiv=\"Refresh\" content=\"1;URL={$post_return}\" />";
100 //   echo "<title>Redirect for POST after...</title>";
101 //   echo "</head>\n";
102 //   echo "<body><p><a href=\"{$post_return}\">Redirecting...</a></p></body></html>";
103 //   exit();
104 // } else {
105   header('HTTP/1.1 303 See Other');
106   // header('HTTP/1.1 302 found');
107   header('Location: ' . $post_return);
108   exit();
109 // }
110 ?>