/** * Open/Close the comments for a blog post * * @param boolean $closed */ function ToggleComments($closed, $post_id) { global $langmessage; if ($closed) { SimpleBlogCommon::AStrSet('comments_closed', $post_id, 1); } else { SimpleBlogCommon::AStrRm('comments_closed', $post_id); } if (SimpleBlogCommon::SaveIndex()) { $this->comments_closed = $closed; message($langmessage['SAVED']); } else { message($langmessage['OOPS']); } }
/** * Remove a category * */ function DeleteCategory() { global $langmessage; if (!isset($_POST['index'])) { message($langmessage['OOPS'] . ' (Invalid Index)'); return false; } $index = $_POST['index']; if (!isset($this->categories[$index])) { message($langmessage['OOPS'] . ' (Invalid Index)'); return false; } unset($this->categories[$index]); unset(SimpleBlogCommon::$data['category_posts_' . $index]); SimpleBlogCommon::AStrRm('categories_hidden', $index); SimpleBlogCommon::$data['categories'] = SimpleBlogCommon::AStrFromArray($this->categories); if (!$this->SaveIndex()) { message($langmessage['OOPS']); return false; } $this->GenStaticContent(); message($langmessage['SAVED']); }
/** * Allow commenting for a blog post * */ function OpenComments($post_index) { global $langmessage; SimpleBlogCommon::AStrRm('comments_closed', $post_index); if (!$this->SaveIndex()) { message($langmessage['OOPS']); } else { message($langmessage['SAVED']); } }
/** * Save an edited blog post * @return bool */ function SaveEdit() { global $langmessage; $_POST += array('title' => '', 'content' => '', 'subtitle' => '', 'isDraft' => '', 'category' => array()); $post_index = $this->post_id; $posts = $this->GetPostFile($post_index, $post_file); if ($posts === false) { message($langmessage['OOPS'] . ' (Invalid ID)'); return; } $_POST['subtitle'] = htmlspecialchars($_POST['subtitle']); $title =& $_POST['title']; $title = htmlspecialchars($title); $title = trim($title); if (empty($title)) { message($langmessage['TITLE_REQUIRED']); return false; } $content =& $_POST['content']; gpFiles::cleanText($content); $posts[$post_index]['title'] = $title; $posts[$post_index]['content'] = $content; $posts[$post_index]['subtitle'] = $_POST['subtitle']; $posts[$post_index]['categories'] = $_POST['category']; unset($posts[$post_index]['isDraft']); if ($_POST['isDraft'] === 'on') { SimpleBlogCommon::AStrValue('drafts', $post_index, 1); } else { SimpleBlogCommon::AStrRm('drafts', $post_index); } //save to data file if (!gpFiles::SaveArray($post_file, 'posts', $posts)) { message($langmessage['OOPS']); return false; } //update title SimpleBlogCommon::AStrValue('titles', $post_index, $title); //find and update the edited post in categories and archives $this->update_post_in_categories($post_index, $title); $this->SaveIndex(); message($langmessage['SAVED']); return true; }
/** * Delete a blog post * @return bool * */ public static function Delete() { global $langmessage; $post_id = $_POST['del_id']; $posts = false; //post in single file or collection $post_file = self::PostFilePath($post_id); if (!file_exists($post_file)) { $posts = self::GetPostFile($post_id, $post_file); if ($posts === false) { message($langmessage['OOPS']); return false; } if (!isset($posts[$post_id])) { message($langmessage['OOPS']); return false; } unset($posts[$post_id]); //don't use array_splice here because it will reset the numeric keys } //now delete post also from categories: self::DeletePostFromCategories($post_id); //reset the index string $new_index = SimpleBlogCommon::$data['str_index']; $new_index = preg_replace('#"\\d+>' . $post_id . '"#', '"', $new_index); preg_match_all('#(?:"\\d+>)([^">]*)#', $new_index, $matches); SimpleBlogCommon::$data['str_index'] = SimpleBlogCommon::AStrFromArray($matches[1]); //remove post from other index strings SimpleBlogCommon::AStrRm('drafts', $post_id); SimpleBlogCommon::AStrRm('comments_closed', $post_id); SimpleBlogCommon::AStrRm('titles', $post_id); SimpleBlogCommon::AStrRm('post_times', $post_id); if (!SimpleBlogCommon::SaveIndex()) { message($langmessage['OOPS']); return false; } //save data file or remove the file if ($posts) { if (!gpFiles::SaveArray($post_file, 'posts', $posts)) { message($langmessage['OOPS']); return false; } } elseif (!unlink($post_file)) { message($langmessage['OOPS']); return false; } //delete the comments $commentDataFile = self::$data_dir . '/comments/' . $post_id . '.txt'; if (file_exists($commentDataFile)) { unlink($commentDataFile); SimpleBlogCommon::ClearCommentCache(); } SimpleBlogCommon::GenStaticContent(); message($langmessage['file_deleted']); return true; }
/** * Save the post * */ public static function SavePost($post_id, $post) { global $langmessage; $_POST += array('title' => '', 'content' => '', 'subtitle' => '', 'isDraft' => '', 'category' => array()); $title = htmlspecialchars($_POST['title']); $title = trim($title); if (empty($title)) { message($langmessage['TITLE_REQUIRED']); return false; } self::GetPostedTime(); //different time //organize posts based on publish time SimpleBlogCommon::AStrSet('post_times', $post_id, $_POST['time']); $post_times = SimpleBlogCommon::AStrToArray('post_times'); arsort($post_times); $str_index = array_keys($post_times); SimpleBlogCommon::$data['str_index'] = SimpleBlogCommon::AStrFromArray($str_index); //get next static gen time SimpleBlogCommon::NextGenTime(); //create post array $post['title'] = $title; $post['content'] = $_POST['content']; $post['subtitle'] = htmlspecialchars($_POST['subtitle']); $post['categories'] = $_POST['category']; $post['time'] = $_POST['time']; unset($post['isDraft']); //save to data file if (!parent::SavePost($post_id, $post)) { return false; } //draft if ($_POST['isDraft'] === 'on') { SimpleBlogCommon::AStrSet('drafts', $post_id, 1); } else { SimpleBlogCommon::AStrRm('drafts', $post_id); } SimpleBlogCommon::AStrSet('titles', $post_id, $title); self::UpdatePostCategories($post_id); //find and update the edited post in categories and archives if (!SimpleBlogCommon::SaveIndex()) { message($langmessage['OOPS'] . ' (Index not saved)'); return false; } SimpleBlogCommon::GenStaticContent(); message($langmessage['SAVED']); return true; }