public function execute() { $this->output->description = "News"; $this->output->keywords = "news"; $this->output->title = "News"; $this->output->add_alternate("News", "application/rss+xml", "/news.xml"); if ($this->page->type == "xml") { /* RSS feed */ $rss = new RSS($this->output); if ($rss->fetch_from_cache("news_rss") == false) { $rss->title = $this->settings->head_title . " news"; $rss->description = $this->settings->head_description; if (($news = $this->model->get_news(0, $this->settings->news_rss_page_size)) != false) { foreach ($news as $item) { $link = "/news/" . $item["id"]; $rss->add_item($item["title"], $item["content"], $link, $item["timestamp"]); } } $rss->to_output(); } } else { if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) { /* News item */ if (($item = $this->model->get_news_item($this->page->pathinfo[1])) == false) { $this->output->add_tag("result", "Unknown news item"); } else { $this->output->title = $item["title"] . " - News"; $item["timestamp"] = date("j F Y, H:i", strtotime($item["timestamp"])); $this->output->record($item, "news"); } } else { /* News overview */ if (($count = $this->model->count_news()) === false) { $this->output->add_tag("result", "Database error"); return; } $paging = new pagination($this->output, "news", $this->settings->news_page_size, $count); if (($news = $this->model->get_news($paging->offset, $paging->size)) === false) { $this->output->add_tag("result", "Database error"); return; } foreach ($news as $item) { $item["timestamp"] = date("j F Y, H:i", $item["timestamp"]); $this->output->record($item, "news"); } $paging->show_browse_links(7, 3); } } }
public function execute() { if ($this->page->type == "xml") { /* RSS feed */ $rss = new RSS($this->output); if ($rss->fetch_from_cache("rss_cache_id") == false) { $rss->title = "RSS title"; $rss->description = "RSS description"; if (($items = $this->model->get_items()) != false) { foreach ($items as $item) { $rss->add_item($item["title"], $item["content"], $item["link"], $item["timestamp"]); } $rss->to_output(); } } } else { /* Other page type */ } }
public function execute() { $months_of_year = config_array(MONTHS_OF_YEAR); $this->output->title = "Weblog"; $this->output->description = "Weblog"; $this->output->keywords = "weblog"; $this->output->add_alternate("Weblog", "application/rss+xml", "/weblog.xml"); $this->url = array("url" => $this->page->page); /* Sidebar */ $this->output->open_tag("sidebar"); /* Tags */ if (($tags = $this->model->get_all_tags()) != false) { $this->output->open_tag("tags"); foreach ($tags as $tag) { $this->output->add_tag("tag", $tag["tag"], array("id" => $tag["id"])); } $this->output->close_tag(); } /* Years */ if (($years = $this->model->get_years()) != false) { $this->output->open_tag("years"); foreach ($years as $year) { $this->output->add_tag("year", $year["year"]); } $this->output->close_tag(); } /* Periods */ if (($periods = $this->model->get_periods()) != false) { $this->output->open_tag("periods"); foreach ($periods as $period) { $link = array("link" => $period["year"] . "/" . $period["month"]); $text = $months_of_year[$period["month"] - 1] . " " . $period["year"]; $this->output->add_tag("period", $text, $link); } $this->output->close_tag(); } $this->output->close_tag(); if ($this->page->type == "xml") { /* RSS feed */ $rss = new RSS($this->output); if ($rss->fetch_from_cache("weblog_rss") == false) { $rss->title = $this->settings->head_title . " weblog"; $rss->description = $this->settings->head_description; if (($weblogs = $this->model->get_last_weblogs($this->settings->weblog_rss_page_size)) != false) { foreach ($weblogs as $weblog) { $link = "/weblog/" . $weblog["id"]; $rss->add_item($weblog["title"], $weblog["content"], $link, $weblog["timestamp"]); } } $rss->to_output(); } } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { /* Comment submits */ if ($this->model->comment_oke($_POST) == false) { $this->show_weblog($_POST["weblog_id"]); $this->show_comment($_POST); } else { if ($this->model->add_comment($_POST) == false) { $this->output->add_message("Error while adding comment."); $this->show_weblog($_POST["weblog_id"]); $this->show_comment($_POST); } else { $this->output->add_tag("result", "Comment has been added.", array("url" => $this->page->page . "/" . $_POST["weblog_id"])); } } } else { if ($this->page->pathinfo[1] == "tag" && valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) { /* Tagged weblogs */ if (($tag = $this->model->get_tag($this->page->pathinfo[2])) == false) { $this->output->add_tag("result", "Unknown tag", $this->url); } else { if (($weblogs = $this->model->get_tagged_weblogs($this->page->pathinfo[2])) === false) { $this->output->add_tag("result", "Error fetching tags", $this->url); } else { $this->output->title = "Tag " . $tag . " - Weblog"; $this->output->open_tag("list", array("label" => "Weblogs with '" . $tag . "' tag")); foreach ($weblogs as $weblog) { $this->output->record($weblog, "weblog"); } $this->output->close_tag(); } } } else { if ($this->page->pathinfo[1] == "period" && valid_input($this->page->pathinfo[2], VALIDATE_NUMBERS, VALIDATE_NONEMPTY) && valid_input($this->page->pathinfo[3], VALIDATE_NUMBERS)) { /* Weblogs of certain period */ if (($weblogs = $this->model->get_weblogs_of_period($this->page->pathinfo[2], $this->page->pathinfo[3])) === false) { $this->output->add_tag("result", "Error fetching weblogs", $this->url); } else { if ($this->page->pathinfo[3] == null) { $this->output->title = "Year " . $this->page->pathinfo[2] . " - Weblog"; } else { $month = $months_of_year[$this->page->pathinfo[3] - 1]; $this->output->title = $month . " " . $this->page->pathinfo[2] . " - Weblog"; } $month = 0; $count = count($weblogs); for ($i = 0; $i < $count; $i++) { if ((int) $weblogs[$i]["month"] != $month) { if ($month != 0) { $this->output->close_tag(); } if ($i < $count) { $label = $months_of_year[$weblogs[$i]["month"] - 1] . " " . $this->page->pathinfo[2]; $this->output->open_tag("list", array("label" => $label)); } } $this->output->record($weblogs[$i], "weblog"); $month = (int) $weblogs[$i]["month"]; } if ($month != 0) { $this->output->close_tag(); } } } else { if (valid_input($this->page->pathinfo[1], VALIDATE_NUMBERS, VALIDATE_NONEMPTY)) { /* Show weblog */ $this->show_weblog($this->page->pathinfo[1]); if ($this->user->logged_in) { $this->show_comment(array("author" => $this->user->fullname)); } } else { /* Show last weblogs */ $this->show_last_weblogs(); } } } } } }