/** * 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 blog entry from a category * */ public static function DeletePostFromCategories($post_id) { $categories = SimpleBlogCommon::AStrToArray('categories'); foreach ($categories as $catindex => $catname) { SimpleBlogCommon::AStrRmValue('category_posts_' . $catindex, $post_id); } }