public function edit_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_handle = $this->post('chapterHandle'); $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('Edit Blog'), 'error', t('Bad request or session expired!')); unset($_SESSION[$form_token_name]); 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('Edit 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('Edit Blog'), 'error', t('Too short/long blog summary!')); header("Location: {$curr_page_path}"); return; } $cpt_page_path = ProjectInfo::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle); $chapter_page = Page::getByPath($cpt_page_path); if ($chapter_page->getCollectionID() == false) { set_page_action_status($curr_page_id, t('Edit Blog'), 'error', t('No such blog page!')); header("Location: {$curr_page_path}"); return; } $db = Loader::db(); $doc_lang = substr($project_id, -2); $db->Execute("UPDATE fsen_project_doc_volume_part_chapters_{$doc_lang} SET chapter_name=?, chapter_desc=?\n\tWHERE project_id=? AND domain_handle=? AND volume_handle=? AND part_handle=? AND chapter_handle=?", array($chapter_name, $chapter_desc, $project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle)); $db->Execute("DELETE FROM fsen_chapter_tags_{$doc_lang} WHERE chapter_handle=?", array($chapter_handle)); $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 INTO fsen_chapter_categories (chapter_handle, category) VALUES (?, ?) ON DUPLICATE KEY UPDATE category=?', array($chapter_handle, $blog_category, $blog_category)); } $chapter_page->update(array("cName" => $chapter_name, "cDescription" => $chapter_desc)); ProjectInfo::onUpdateBlogInfo($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle); set_page_action_status($chapter_page->getCollectionID(), t('Edit Blog'), 'success', t('Succeed to edit blog.')); header("Location: {$cpt_page_path}"); }