/** * Update a category when a blog entry is edited * */ function update_post_in_categories($post_id, $title) { $_POST += array('category' => array()); //get order of all posts $post_times = SimpleBlogCommon::AStrToArray('post_times'); arsort($post_times); $post_times = array_keys($post_times); //loop through each category $categories = SimpleBlogCommon::AStrToArray('categories'); $edited_categories = array(); foreach ($categories as $catindex => $catname) { SimpleBlogCommon::AStrRmValue('category_posts_' . $catindex, $post_id); if (in_array($catindex, $_POST['category'])) { //add and order correctly $category_posts = SimpleBlogCommon::AStrToArray('category_posts_' . $catindex); $category_posts[] = $post_id; $category_posts = array_intersect($post_times, $category_posts); SimpleBlogCommon::$data['category_posts_' . $catindex] = SimpleBlogCommon::AStrFromArray($category_posts); } } }
/** * 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']); }
/** * 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; }