Beispiel #1
0
 public static function show($thread_id)
 {
     $thread = new Thread();
     $error_message = "";
     $textarea_content = "";
     $isMobile = Utils::is_mobile();
     // comment
     if (!empty($_POST)) {
         // insert post into thread
         $thread->initWithId($thread_id);
         $author_id = $_SESSION[KEY_SESSION][Account::KEY_ID];
         $title = $thread->getTitle();
         $update_time = Utils::getCurrentTime();
         $update_date = Utils::getCurrentDate();
         $latest_update = time();
         $content = $_POST["content"];
         $content_len = 0;
         if ($isMobile) {
             $content = preg_replace("/<br \\/>|<br\\/>|<br>/", '', $content);
             $content = preg_replace("/\r\n|\r|\n/", '<br />', $content);
             $content_len = strlen($content);
         } else {
             $content_len = Utils::textLength($content);
         }
         if ($content_len > 5) {
             // post request success
             Post::create($thread_id, $title, $content, $update_date, $update_time, $author_id, "text");
             header("Location: /thread/" . $thread_id);
             die;
         } else {
             // post request fail
             $error_message = "コンテンツ文字数は必ず5文字以上でなければいけません。";
             $textarea_content = $content;
         }
         // end of post comment
     } else {
         // get request
         $thread_id = $_GET[KEY_TARGET];
         $thread->initWithId($thread_id);
     }
     if ($isMobile) {
         foreach ($thread->getAllPosts() as $p) {
             if (Utils::appletTagFound($p->getContent())) {
                 // if applet tag is found, redirect to unable_to_access
                 $content = ROOT . "common/no-available-applet.php";
                 include VIEWS_PATH . "private-nav.php";
                 include VIEWS_PATH . "thread/thread.php";
                 die;
             }
         }
     }
     // number of thread show per page. Current is 10
     $show = 10;
     if (empty($_GET["page"])) {
         $offset = 0;
         $page = 1;
     } else {
         $page = abs(intval($_GET["page"]));
         if ($page == 0) {
             $page = 1;
         }
         $offset = ($page - 1) * $show;
     }
     $showPageCallback = function ($i, $current_page) {
         if ($i == $current_page) {
             echo "<a class='anchor' href='/thread/{$_GET[KEY_TARGET]}/page/{$i}'><span class='page_number current'>{$i}</span></a>";
         } else {
             echo "<a class='anchor' href='/thread/{$_GET[KEY_TARGET]}/page/{$i}'><span class='page_number'>{$i}</span></a>";
         }
     };
     $posts = array();
     // query single post
     if ($offset == 0) {
         foreach ($thread->queryPosts(" WHERE _id=1;") as $t) {
             $script_text = $t->getScriptText();
             if (empty($script_text)) {
                 // there is no script tag inside this post
                 array_push($posts, $t);
             } else {
                 // script tag
                 $json = json_decode($script_text, true);
                 $new_content = '<script>parseRSS("' . $json["url"] . '",function(data){var newElement = document.createElement("div");' . 'newElement.innerHTML = "<p class=\\"rss-link\\">このスレッドは<a href=\'"+data.getLinkByTitle("' . $json["title"] . '") + "\'>こちら</a>から引用しました。</p>";' . 'console.log(data.getTitle("' . $json["title"] . '"));' . 'newElement.innerHTML += data.getTitle("' . $json["title"] . '").content;' . 'document.getElementsByClassName("post")[0].insertBefore(newElement,document.getElementsByClassName("post")[0].childNode);});</script>';
                 $t->setContent($new_content);
                 array_push($posts, $t);
             }
         }
         foreach ($thread->queryPosts(" WHERE _id!=1 ORDER BY " . Post::KEY_MODIFIED_TIME . " DESC LIMIT " . $offset . "," . ($show - 1)) as $t) {
             array_push($posts, $t);
         }
     } else {
         $posts = $thread->queryPosts(" WHERE _id!=1 ORDER BY " . Post::KEY_MODIFIED_TIME . " DESC LIMIT " . $offset . "," . $show);
     }
     // query multiple post
     $content = "show.php";
     include VIEWS_PATH . "private-nav.php";
     include VIEWS_PATH . "thread/thread.php";
 }