/** * 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']); } }
/** * Save the comment data for a blog post * */ public static function SaveCommentData($post_index, $data) { global $langmessage; // check directory $dir = self::$data_dir . '/comments'; if (!gpFiles::CheckDir($dir)) { return false; } $commentDataFile = $dir . '/' . $post_index . '.txt'; $dataTxt = serialize($data); if (!gpFiles::Save($commentDataFile, $dataTxt)) { return false; } // clean pre 1.7.4 files $commentDataFile = self::$data_dir . '/comments_data_' . $post_index . '.txt'; if (file_exists($commentDataFile)) { unlink($commentDataFile); } SimpleBlogCommon::AStrSet('comment_counts', $post_index, count($data)); SimpleBlogCommon::SaveIndex(); SimpleBlogCommon::ClearCommentCache(); 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; }