Example #1
0
 public function main_category($main)
 {
     # make sure we have enough information to continue
     if (!isset($_GET['name'])) {
         $reason = "no_category_requested";
     } elseif (!($category = Category::getCategorybyClean($_GET['name']))) {
         $reason = "category_not_found";
     }
     if (isset($reason)) {
         return $main->resort(array("pages/category", "pages/index"), array("reason" => $reason), __("Invalid Category", "categorize"));
     }
     $attributes = SQL::current()->select("post_attributes", array("post_id"), array("name" => "category_id", "value" => $category->id));
     $ids = array();
     foreach ($attributes->fetchAll() as $index => $row) {
         $ids[] = $row["post_id"];
     }
     if (empty($ids)) {
         return $main->resort(array("pages/category", "pages/index"), array("reason" => "category_not_found"), __("Invalid Category", "categorize"));
     }
     $posts = new Paginator(Post::find(array("placeholders" => true, "where" => array("id" => $ids))), Config::current()->posts_per_page);
     if (empty($posts)) {
         return false;
     }
     $main->display(array("pages/category", "pages/index"), array("posts" => $posts, "category" => $category->name), _f("Posts in category %s", $_GET['name'], "categorize"));
 }