From 13d8b0831ea0bf4a23c79e43852e5a5b7e325ae3 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 22:17:20 +0100 Subject: [PATCH] Fixed problems from notes by shish Added arrowkey navigator to post/list as well arrowkey navigator also works with tags on post/list now --- ext/arrowkey_navigation/main.php | 65 ++++++++++++++++++++++++++++---- ext/image_view_counter/main.php | 29 +++++++------- 2 files changed, 72 insertions(+), 22 deletions(-) diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 15136dfa..f36dab94 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -2,19 +2,34 @@ /** * Name: Arrow Key Navigation * Author: Drudex Software - * Link: http://drudexsoftware.com + * Link: http://www.drudexsoftware.com/ * License: GPLv2 * Description: Allows viewers no navigate between images using the left & right arrow keys. * Documentation: * Simply enable this extention in the extention manager to enable arrow key navigation. */ -class arrowkey_navigation extends Extension { - public function onDisplayingImage(DisplayingImageEvent $event) { +class arrowkey_navigation extends Extension { + # Adds functionality for post/view on images + public function onDisplayingImage(DisplayingImageEvent $event) { + $prev_url = make_http(make_link("post/prev/".$event->image->id)); + $next_url = make_http(make_link("post/next/".$event->image->id)); + $this->add_arrowkeys_code($prev_url, $next_url); + } + + # Adds functionality for post/list + public function onPageRequest(PageRequestEvent $event) { + if($event->page_matches("post/list")) { + $pageinfo = $this->get_list_pageinfo($event); + $prev_url = make_http(make_link("post/list/".$pageinfo["prev"])); + $next_url = make_http(make_link("post/list/".$pageinfo["next"])); + $this->add_arrowkeys_code($prev_url, $next_url); + } + } + + # adds the javascript to the page with the given urls + private function add_arrowkeys_code($prev_url, $next_url) { global $page; - $prev_url = "http://".$_SERVER['HTTP_HOST']."/post/prev/".$event->image->id; - $next_url = "http://".$_SERVER['HTTP_HOST']."/post/next/".$event->image->id; - $page->add_html_header(""); - } + } + + # returns info about the current page number + private function get_list_pageinfo($event) { + global $config, $database; + + // determine if post/list with tag, add prefix if needed + $prefix = ""; + $page_number = (int)$event->get_arg(0); + if ($page_number == 0) { + $prefix = $event->get_arg(0)."/"; + $page_number = (int)$event->get_arg(1); + } + + // if the page number is still invalid, set it to 1 + if(is_null($page_number) || $page_number <= 0) + $page_number = 1; + + // Determine the amount of pages + $images_per_page = $config->get_int('index_images'); + $total_pages = ceil($database->get_one("SELECT COUNT(*) FROM images") / $images_per_page); + + // creates previous & next values + // When previous first page, go to last page + if ($page_number <= 1) $prev = $total_pages; + else $prev = $page_number-1; + if ($page_number >= $total_pages) $next = 1; + else $next = $page_number+1; + + // Create return array + $pageinfo = array( + "prev" => $prefix.$prev, + "next" => $prefix.$next, + ); + + return $pageinfo; + } } ?> diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 0b3ede86..74ae01c1 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -2,7 +2,7 @@ /** * Name: Image View Counter * Author: Drudex Software - * Link: http://drudexsoftware.com + * Link: http://www.drudexsoftware.com/ * License: GPLv2 * Description: Tracks & displays how many times an image is viewed * Documentation: @@ -32,7 +32,7 @@ class image_view_counter extends Extension { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { global $user, $config; - $adminonly = $config->get_bool("image_viewcounter_adminonly"); + $adminonly = $config->get_bool("image_viewcounter_adminonly"); // todo0 if ($adminonly == false || ($adminonly && $user->is_admin())) $event->add_part("Views:". $this->get_view_count($event->image->id) ."", 38); @@ -43,14 +43,13 @@ class image_view_counter extends Extension { global $database, $config; // if the sql table doesn't exist yet, create it - if($config->get_bool("image_viewcounter_installed") == false) { - $database->execute("CREATE TABLE image_views ( - id bigint(20) NOT NULL AUTO_INCREMENT, - image_id int(11) NOT NULL, - user_id int(11) NOT NULL, - timestamp int(11) NOT NULL, - ipaddress varchar(255) NOT NULL, - PRIMARY KEY (id))"); + if($config->get_bool("image_viewcounter_installed") == false) { //todo + $database->create_table("image_views"," + id bigint(20) SCORE_AIPK, + image_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + timestamp INTEGER NOT NULL, + ipaddress SCORE_INET NOT NULL"); $config->set_bool("image_viewcounter_installed", true); } } @@ -79,14 +78,14 @@ class image_view_counter extends Extension { global $database; // counts views from current IP in the last hour - $recent_from_ip = $database->get_row("SELECT COUNT(*) FROM image_views WHERE + $recent_from_ip = (int)$database->get_one("SELECT COUNT(*) FROM image_views WHERE ipaddress=:ipaddress AND timestamp >:lasthour AND image_id =:image_id", array( "ipaddress" => $_SERVER['REMOTE_ADDR'], "lasthour" => time() - $this->view_interval, "image_id" => $imgid)); // if no views were found with the set criteria, return true - if($recent_from_ip["COUNT(*)"] == "0") return true; + if($recent_from_ip == 0) return true; else return false; } @@ -97,13 +96,13 @@ class image_view_counter extends Extension { global $database; if ($imgid == 0) // return view count of all images - $view_count = $database->get_row("SELECT COUNT(*) FROM image_views"); + $view_count = (int)$database->get_one("SELECT COUNT(*) FROM image_views"); else // return view count of specified image - $view_count = $database->get_row("SELECT COUNT(*) FROM image_views WHERE ". + $view_count = (int)$database->get_one("SELECT COUNT(*) FROM image_views WHERE ". "image_id =:image_id", array("image_id" => $imgid)); // returns the count as int - return intval($view_count["COUNT(*)"]); + return $view_count; } } ?>