forked from Cavemanon/cavepaintings
PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...
This commit is contained in:
@@ -7,62 +7,64 @@
|
||||
* Description: Self explanatory
|
||||
*/
|
||||
|
||||
class RSS_Images extends Extension {
|
||||
public function onPostListBuilding(PostListBuildingEvent $event) {
|
||||
global $config, $page;
|
||||
$title = $config->get_string('title');
|
||||
class RSS_Images extends Extension
|
||||
{
|
||||
public function onPostListBuilding(PostListBuildingEvent $event)
|
||||
{
|
||||
global $config, $page;
|
||||
$title = $config->get_string('title');
|
||||
|
||||
if(count($event->search_terms) > 0) {
|
||||
$search = html_escape(implode(' ', $event->search_terms));
|
||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images with tags: $search\" href=\"".make_link("rss/images/$search/1")."\" />");
|
||||
}
|
||||
else {
|
||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images\" href=\"".make_link("rss/images/1")."\" />");
|
||||
}
|
||||
}
|
||||
if (count($event->search_terms) > 0) {
|
||||
$search = html_escape(implode(' ', $event->search_terms));
|
||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images with tags: $search\" href=\"".make_link("rss/images/$search/1")."\" />");
|
||||
} else {
|
||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images\" href=\"".make_link("rss/images/1")."\" />");
|
||||
}
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event) {
|
||||
if($event->page_matches("rss/images")) {
|
||||
$search_terms = $event->get_search_terms();
|
||||
$page_number = $event->get_page_number();
|
||||
$page_size = $event->get_page_size();
|
||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||
$this->do_rss($images, $search_terms, $page_number);
|
||||
}
|
||||
}
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
{
|
||||
if ($event->page_matches("rss/images")) {
|
||||
$search_terms = $event->get_search_terms();
|
||||
$page_number = $event->get_page_number();
|
||||
$page_size = $event->get_page_size();
|
||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||
$this->do_rss($images, $search_terms, $page_number);
|
||||
}
|
||||
}
|
||||
|
||||
private function do_rss(array $images, array $search_terms, int $page_number) {
|
||||
global $page;
|
||||
global $config;
|
||||
$page->set_mode("data");
|
||||
$page->set_type("application/rss+xml");
|
||||
private function do_rss(array $images, array $search_terms, int $page_number)
|
||||
{
|
||||
global $page;
|
||||
global $config;
|
||||
$page->set_mode("data");
|
||||
$page->set_type("application/rss+xml");
|
||||
|
||||
$data = "";
|
||||
foreach($images as $image) {
|
||||
$data .= $this->thumb($image);
|
||||
}
|
||||
$data = "";
|
||||
foreach ($images as $image) {
|
||||
$data .= $this->thumb($image);
|
||||
}
|
||||
|
||||
$title = $config->get_string('title');
|
||||
$base_href = make_http(get_base_href());
|
||||
$search = "";
|
||||
if(count($search_terms) > 0) {
|
||||
$search = url_escape(Tag::implode($search_terms)) . "/";
|
||||
}
|
||||
$title = $config->get_string('title');
|
||||
$base_href = make_http(get_base_href());
|
||||
$search = "";
|
||||
if (count($search_terms) > 0) {
|
||||
$search = url_escape(Tag::implode($search_terms)) . "/";
|
||||
}
|
||||
|
||||
if($page_number > 1) {
|
||||
$prev_url = make_link("rss/images/$search".($page_number-1));
|
||||
$prev_link = "<atom:link rel=\"previous\" href=\"$prev_url\" />";
|
||||
}
|
||||
else {
|
||||
$prev_link = "";
|
||||
}
|
||||
$next_url = make_link("rss/images/$search".($page_number+1));
|
||||
$next_link = "<atom:link rel=\"next\" href=\"$next_url\" />"; // no end...
|
||||
if ($page_number > 1) {
|
||||
$prev_url = make_link("rss/images/$search".($page_number-1));
|
||||
$prev_link = "<atom:link rel=\"previous\" href=\"$prev_url\" />";
|
||||
} else {
|
||||
$prev_link = "";
|
||||
}
|
||||
$next_url = make_link("rss/images/$search".($page_number+1));
|
||||
$next_link = "<atom:link rel=\"next\" href=\"$next_url\" />"; // no end...
|
||||
|
||||
$version = VERSION;
|
||||
$xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\" ?".">
|
||||
$version = VERSION;
|
||||
$xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\" ?".">
|
||||
<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\" xmlns:atom=\"http://www.w3.org/2005/Atom\">
|
||||
<channel>
|
||||
<title>$title</title>
|
||||
@@ -75,27 +77,30 @@ class RSS_Images extends Extension {
|
||||
$data
|
||||
</channel>
|
||||
</rss>";
|
||||
$page->set_data($xml);
|
||||
}
|
||||
$page->set_data($xml);
|
||||
}
|
||||
|
||||
private function thumb(Image $image): string {
|
||||
global $database;
|
||||
private function thumb(Image $image): string
|
||||
{
|
||||
global $database;
|
||||
|
||||
$cached = $database->cache->get("rss-thumb:{$image->id}");
|
||||
if($cached) return $cached;
|
||||
$cached = $database->cache->get("rss-thumb:{$image->id}");
|
||||
if ($cached) {
|
||||
return $cached;
|
||||
}
|
||||
|
||||
$link = make_http(make_link("post/view/{$image->id}"));
|
||||
$tags = html_escape($image->get_tag_list());
|
||||
$thumb_url = $image->get_thumb_link();
|
||||
$image_url = $image->get_image_link();
|
||||
$posted = date(DATE_RSS, strtotime($image->posted));
|
||||
$content = html_escape(
|
||||
"<div>" .
|
||||
"<p>" . $this->theme->build_thumb_html($image) . "</p>" .
|
||||
"</div>"
|
||||
);
|
||||
$link = make_http(make_link("post/view/{$image->id}"));
|
||||
$tags = html_escape($image->get_tag_list());
|
||||
$thumb_url = $image->get_thumb_link();
|
||||
$image_url = $image->get_image_link();
|
||||
$posted = date(DATE_RSS, strtotime($image->posted));
|
||||
$content = html_escape(
|
||||
"<div>" .
|
||||
"<p>" . $this->theme->build_thumb_html($image) . "</p>" .
|
||||
"</div>"
|
||||
);
|
||||
|
||||
$data = "
|
||||
$data = "
|
||||
<item>
|
||||
<title>{$image->id} - $tags</title>
|
||||
<link>$link</link>
|
||||
@@ -107,9 +112,8 @@ class RSS_Images extends Extension {
|
||||
</item>
|
||||
";
|
||||
|
||||
$database->cache->set("rss-thumb:{$image->id}", $data, 3600);
|
||||
$database->cache->set("rss-thumb:{$image->id}", $data, 3600);
|
||||
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user