Esempio n. 1
0
 public function add_new_blog()
 {
     if (!fse_try_to_login()) {
         header("location:/fse_login");
         return;
     }
     $curr_page_id = $this->post('cID');
     $project_id = $this->post('projectID');
     $domain_handle = $this->post('domainHandle');
     $volume_handle = $this->post('volumeHandle');
     $part_handle = $this->post('partHandle');
     $chapter_name = $this->post('blogSubject');
     $chapter_desc = $this->post('blogSummary');
     $blog_category = $this->post('blogCategory');
     $blog_tags = $this->post('blogTags');
     $author_suggested = (int) $this->post('authorSuggested');
     $curr_page_path = Page::getByID($curr_page_id)->getCollectionPath();
     $form_token_name = $this->post('formTokenName');
     $form_token = $this->post('formToken');
     if ($_SESSION[$form_token_name] != $form_token) {
         set_page_action_status($curr_page_id, t('Add New Blog'), 'error', t('Bad request or session expired!'));
         header("Location: {$curr_page_path}");
         return;
     }
     unset($_SESSION[$form_token_name]);
     if (!preg_match("/^.{1,64}\$/", $chapter_name)) {
         set_page_action_status($curr_page_id, t('Add New Blog'), 'error', t('Too short/long blog name!'));
         header("Location: {$curr_page_path}");
         return;
     }
     if (!preg_match("/^.{2,255}\$/", $chapter_desc)) {
         set_page_action_status($curr_page_id, t('Add New Blog'), 'error', t('Too short/long blog summary!'));
         header("Location: {$curr_page_path}");
         return;
     }
     $part_page_path = ProjectInfo::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle);
     $part_page = Page::getByPath($part_page_path);
     if ($part_page->getCollectionID() == false) {
         set_page_action_status($curr_page_id, t('Add New Blog'), 'error', t('No parent (blog zone) page!'));
         header("Location: {$curr_page_path}");
         return;
     }
     $chapter_handle = hash_hmac("md5", microtime() . rand(), $chapter_name . $part_handle);
     $chapter_page = ProjectInfo::addChapterPage($project_id, $domain_handle, $volume_handle, $part_page, $chapter_handle, $chapter_name, $chapter_desc, $author_suggested);
     if ($chapter_page == false) {
         set_page_action_status($curr_page_id, t('Add New Blog'), 'error', t('Failed to add a blog page!'));
         header("Location: {$curr_page_path}");
         return false;
     }
     /* store blog tags here */
     $db = Loader::db();
     $doc_lang = substr($project_id, -2);
     $tag = strtok($blog_tags, " \n\t");
     while ($tag !== false) {
         $db->Execute("INSERT IGNORE fsen_chapter_tags_{$doc_lang} (chapter_handle, tag) VALUES (?, ?)", array($chapter_handle, $tag));
         $tag = strtok(" \n\t");
     }
     if (strlen($blog_category) >= 2) {
         $db->Execute('INSERT IGNORE fsen_chapter_categories (chapter_handle, category) VALUES (?, ?)', array($chapter_handle, $blog_category));
     }
     set_page_action_status($chapter_page->getCollectionID(), t('Add New Blog'), 'success', t('Succeed to add a new blog.'));
     header('Location: ' . $chapter_page->getCollectionPath());
 }