Ejemplo n.º 1
0
 public function edit_post()
 {
     if (!fse_try_to_login()) {
         header("location:/fse_login");
         return;
     }
     $project_id = $this->post('projectID');
     $domain_handle = $this->post('domainHandle');
     $volume_handle = $this->post('volumeHandle');
     $part_handle = $this->post('partHandle');
     $chapter_handle = $this->post('chapterHandle');
     $section_id = $this->post('sectionID');
     $form_token = $this->post('formToken');
     $type_handle = $this->post('typeHandle');
     $post_subject = $this->post('postSubject');
     $post_content = $this->post('postContent');
     $page_path = ProjectInfo::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle);
     $page = Page::getByPath($page_path);
     $page_id = $page->getCollectionID();
     if ($_SESSION['formToken4EditPost'] != $form_token) {
         set_page_action_status($page_id, t('Edit Post'), 'error', t('Bad request or session expired.'));
         header("Location: {$page_path}");
         return;
     }
     unset($_SESSION['formToken4EditPost']);
     if (mb_strlen($post_content) < self::MIN_CONTENT_LEN) {
         set_page_action_status($page_id, t('Edit Post'), 'error', t('Too short content!'));
         header("Location: {$page_path}");
         return;
     }
     $attached_files = '[';
     for ($i = 0; $i < DocSectionManager::MAX_ATTACHED_FILES; $i++) {
         $attached_file_id = (int) $this->post("attachmentFile{$i}");
         if ($attached_file_id > 0) {
             $attached_files .= "{$attached_file_id}, ";
         }
     }
     $attached_files = rtrim($attached_files, ', ');
     $attached_files .= ']';
     /* Add a new post version */
     $section_manager = new DocSectionManager();
     $res = $section_manager->addNewSectionVersion($project_id, $_SESSION['FSEInfo']['fse_id'], $domain_handle, $section_id, $type_handle, $post_subject, $post_content, $attached_files);
     if ($res != DocSectionManager::EC_OK) {
         set_page_action_status($page_id, t('Edit Post'), 'error', $section_manager->getErrorMessage($res));
         header("Location: {$page_path}");
         return;
     }
     set_page_action_status($page_id, t('Edit Post'), 'success', t('Succeed to edit post.'));
     header("Location: {$page_path}");
 }