public function update($queryString)
 {
     $user_name = $_POST['user_name'];
     $user_email = $_POST['user_email'];
     $thread_topic = $_POST['thread_topic'];
     $thread_content = $_POST['thread_content'];
     Thread::update($queryString, $user_name, $user_email, $thread_topic, $thread_content);
     header("Location: index.php");
 }
 public static function updateThread($id)
 {
     $params = $_POST;
     $oldThread = new Thread(Thread::find($id));
     $attributes = $oldThread->asArray();
     $attributes['id'] = $id;
     $attributes['name'] = $params['name'];
     $thread = new Thread($attributes);
     $errors = $thread->errors();
     if (count($errors) == 0) {
         $thread->update();
         Redirect::to('/thread/' . $id);
     } else {
         $thread = Thread::find($id);
         View::make('thread/thread_edit.html', array('errors' => $errors, 'thread' => $thread, 'attributes' => $attributes));
     }
 }
Beispiel #3
0
 public static function edit($thread_id, $post_id)
 {
     // begin
     if ($_SESSION[KEY_SESSION][Account::KEY_USERNAME] == "guest") {
         Utils::showNoPermissionPage();
         die;
     }
     // end
     $isMobile = Utils::is_mobile();
     $thread = new Thread();
     $error_message = "";
     $textarea_title = "";
     $textarea_content = "";
     $thread->initWithId($thread_id);
     $post = $thread->getPostById($post_id);
     if (!empty($_POST) && $post->getAuthor()->getId() == $_SESSION[KEY_SESSION][Account::KEY_ID]) {
         // update post
         $title = $_POST["title"];
         $update_time = Utils::getCurrentTime();
         $update_date = Utils::getCurrentDate();
         $latest_update = time();
         $content = $_POST["content"];
         $permission = $_POST["permission"];
         $title_len = strlen($title);
         $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 && $title_len > 5) {
             // success
             if ($thread->getHost()->getId() == $_SESSION[KEY_SESSION][Account::KEY_ID] && in_array($permission, Thread::$PERMISSIONS)) {
                 $thread->update($post_id, $title, $update_time, $update_date, $latest_update, $content, $permission);
             } else {
                 $thread->update($post_id, $title, $update_time, $update_date, $latest_update, $content, $thread->getPermission());
             }
             header("Location: /thread/" . $thread_id);
             unset($thread);
             unset($post_id);
             unset($thread_id);
             die;
         } else {
             // fail
             $error_message = "コンテンツ文字数は必ず5文字以上でなければいけません。";
             $textarea_content = $content;
             $textarea_title = $title;
         }
     } else {
         // get request
         $thread->initWithId($thread_id);
         $post = $thread->getPostById($post_id);
         $permission = $thread->getPermission();
         if (!self::checkingPermission($thread_id, $post_id, $permission) || !($_SESSION[KEY_SESSION][Account::KEY_ID] == $post->getAuthor()->getId())) {
             Utils::showNoPermissionPage();
             return;
         }
         $textarea_title = $thread->getTitle();
         $textarea_content = $post->getContent();
     }
     $textarea_content = preg_replace('/src="\\/?uploadManager\\//', " src=\"/common/uploadManager/", $textarea_content);
     if (get_magic_quotes_gpc()) {
         $textarea_content = stripslashes($textarea_content);
     }
     $textarea_content = new HTML_To_Markdown($textarea_content);
     $textarea_content = preg_replace_callback('/\\!\\[(.*?)\\]\\((.*?) \\"(.*?)\\"\\)/', function ($m) {
         $m[2] = preg_replace("/\\s/", "%20", $m[2]);
         return "![{$m['1']}]({$m['2']} \"{$m['3']}\")";
     }, $textarea_content);
     $content = "edit.php";
     include VIEWS_PATH . "private-nav.php";
     include VIEWS_PATH . "thread/thread.php";
 }
Beispiel #4
0
include __DIR__ . "/parts/sign_in_form.php";
require_once __DIR__ . '/../class/thread.php';
$get_id = filter_input(INPUT_GET, "id");
$action = $_SERVER['REQUEST_METHOD'];
if ($get_action = filter_input(INPUT_POST, "action")) {
    $action = filter_input(INPUT_POST, "action");
}
switch ($action) {
    case 'POST':
        $title = filter_input(INPUT_POST, "title");
        $text = filter_input(INPUT_POST, "text");
        $thread = new Thread();
        if ($get_id) {
            //既存をupdate
            $params = array('thread_id' => $get_id, 'title' => $title, 'text' => $text);
            $thread->update($params);
        } else {
            //新規をPOST
            $user_id = $_SESSION["user_id"];
            $params = array('user_id' => $user_id, 'title' => $title, 'text' => $text);
            $get_id = $thread->add($params);
        }
        break;
    case 'delete':
        print $action;
        if ($get_id) {
            //DELETE
            $thread = new Thread();
            $thread->deleteRow($get_id);
            header('Location: /bbs/');
            exit;