From 1a38a152e6951898a1d5dbf016fb9bacf17c659a Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 06:21:00 +0100 Subject: [PATCH 01/10] image_view_counter: - added view counter - only adds view every hour from same person - no way to display to user/admin yet (todo) --- ext/image_view_counter/main.php | 96 +++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ext/image_view_counter/main.php diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php new file mode 100644 index 00000000..23a2d21b --- /dev/null +++ b/ext/image_view_counter/main.php @@ -0,0 +1,96 @@ + + * Link: http://drudexsoftware.com + * License: GPLv2 + * Description: Tracks & displays how many times an image is viewed + * Documentation: + * Whenever anyone views an image, a view will be added to that image. + * This extension will also track any username & the IP adress. + * This is done to prevent duplicate views. + * A person can only count as a view again 1 hour after viewing the image initially. + */ +class image_view_counter extends Extension { + private $view_interval = 3600; # allows views to be added each hour + + # Add Setup Block with options for view counter + public function onSetupBuilding(SetupBuildingEvent $event) { + $sb = new SetupBlock("Image View Counter"); + $sb->add_bool_option("image_viewcounter_adminonly", "Display view counter only to admin"); + + $event->panel->add_block($sb); + } + + # Load Analytics tracking code on page request + public function onDisplayingImage(DisplayingImageEvent $event) { + $imgid = $event->image->id; // determines image id + $this->addview($imgid); // adds a view + } + + # Installs DB table + public function onInitExt(InitExtEvent $event) { + 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, + timestamp int(11) NOT NULL, + ipaddress varchar(255) NOT NULL, + PRIMARY KEY (id))"); + $config->set_bool("image_viewcounter_installed", true); + } + } + + # Adds a view to the item if needed + private function addview($imgid) + { + global $database; + // don't add view if person already viewed recently + if ($this->can_add_view($imgid) == false) return; + + // Add view for current IP + $database->execute("INSERT INTO image_views (image_id, timestamp, ipaddress) + VALUES (:image_id, :timestamp, :ipaddress)", array( + "image_id" => $imgid, + "timestamp" => time(), + "ipaddress" => $_SERVER['REMOTE_ADDR'], + )); + } + + # Returns true if this IP hasn't recently viewed this image + private function can_add_view($imgid) + { + global $database; + + // counts views from current IP in the last hour + $recent_from_ip = $database->get_row("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; + else return false; + } + + # Returns the int of the view count from the given image id + // $imgid - if not set or 0, return views of all images + private function get_view_count($imgid = 0) + { + global $database; + + if ($imgid == 0) // return view count of all images + $view_count = $database->get_row("SELECT COUNT(*) FROM image_views"); + else // return view count of specified image + $view_count = $database->get_row("SELECT COUNT(*) FROM image_views WHERE ". + "image_id =:image_id", array("image_id" => $imgid)); + + // returns the count as int + return intval($view_count["COUNT(*)"]); + } +} +?> From 93a431dce708e0418f22ace3793d7b2c5df21bd6 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 06:47:06 +0100 Subject: [PATCH 02/10] image_view_counter: - now displays views below image (only if it's okay with the admin settings) - comment changed --- ext/image_view_counter/main.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 23a2d21b..08e83d3e 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -22,12 +22,22 @@ class image_view_counter extends Extension { $event->panel->add_block($sb); } - # Load Analytics tracking code on page request + # Adds view to database if needed public function onDisplayingImage(DisplayingImageEvent $event) { $imgid = $event->image->id; // determines image id $this->addview($imgid); // adds a view } + # display views to user or admin below image if allowed + public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { + global $user, $config; + + $adminonly = $config->get_bool("image_viewcounter_adminonly"); + if ($adminonly == false || ($adminonly && $user->is_admin())) + $event->add_part("Views:". + $this->get_view_count($event->image->id) ."", 38); + } + # Installs DB table public function onInitExt(InitExtEvent $event) { global $database, $config; From b88f7a4d6b2cda0802cbbb2a925923dab0343028 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 07:17:58 +0100 Subject: [PATCH 03/10] image_view_counter: also saving with user ID with addview() for later use --- ext/image_view_counter/main.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 08e83d3e..0b3ede86 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -47,6 +47,7 @@ class image_view_counter extends Extension { $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))"); @@ -57,14 +58,16 @@ class image_view_counter extends Extension { # Adds a view to the item if needed private function addview($imgid) { - global $database; + global $database, $user; + // don't add view if person already viewed recently if ($this->can_add_view($imgid) == false) return; // Add view for current IP - $database->execute("INSERT INTO image_views (image_id, timestamp, ipaddress) - VALUES (:image_id, :timestamp, :ipaddress)", array( - "image_id" => $imgid, + $database->execute("INSERT INTO image_views (image_id, user_id, timestamp, ipaddress) + VALUES (:image_id, :user_id, :timestamp, :ipaddress)", array( + "image_id" => $imgid, + "user_id" => $user->id, "timestamp" => time(), "ipaddress" => $_SERVER['REMOTE_ADDR'], )); From dfd7157cd2fa68c5843de923f308d724f8d06fcb Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 08:00:59 +0100 Subject: [PATCH 04/10] arrow key navigation through images allows visitors to use left-right keyboard keys to navigate to different images using post/next/(id) and post/prev/(id) --- ext/arrowkey_navigation/main.php | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ext/arrowkey_navigation/main.php diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php new file mode 100644 index 00000000..15136dfa --- /dev/null +++ b/ext/arrowkey_navigation/main.php @@ -0,0 +1,35 @@ + + * Link: http://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) { + 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(""); + } +} +?> From 13d8b0831ea0bf4a23c79e43852e5a5b7e325ae3 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 22:17:20 +0100 Subject: [PATCH 05/10] 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; } } ?> From 069b7ee9ead7b50c631ccc2380b7102454a68731 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 23:26:08 +0100 Subject: [PATCH 06/10] arrowkey navigation on post/list now supports tags --- ext/arrowkey_navigation/main.php | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index f36dab94..c5cd5dda 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -50,36 +50,39 @@ class arrowkey_navigation extends Extension { # returns info about the current page number private function get_list_pageinfo($event) { global $config, $database; + + // get the amount of images per page + $images_per_page = $config->get_int('index_images'); - // 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 there are no tags, use default + if ($event->get_arg(1) == null){ + $prefix = ""; + $page_number = (int)$event->get_arg(0); + $total_pages = ceil($database->get_one( + "SELECT COUNT(*) FROM images") / $images_per_page); + } + + else { // if there are tags, use pages with tags + $prefix = $event->get_arg(0)."/"; + $page_number = (int)$event->get_arg(1); + $total_pages = ceil($database->get_one( + "SELECT count FROM tags WHERE tag=:tag", + array("tag"=>$event->get_arg(0))) / $images_per_page); } - // 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; } } From c55c984cfcac181505aeeef82cb67305bbef5c70 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 23:34:32 +0100 Subject: [PATCH 07/10] also correctly handle post/list without a page ID given --- ext/arrowkey_navigation/main.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index c5cd5dda..40f5da57 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -54,8 +54,16 @@ class arrowkey_navigation extends Extension { // get the amount of images per page $images_per_page = $config->get_int('index_images'); + // this occurs when viewing post/list without page number + if ($event->get_arg(0) == null) {// no page listed + $prefix = ""; + $page_number = 1; + $total_pages = ceil($database->get_one( + "SELECT COUNT(*) FROM images") / $images_per_page); + } + // if there are no tags, use default - if ($event->get_arg(1) == null){ + else if ($event->get_arg(1) == null){ $prefix = ""; $page_number = (int)$event->get_arg(0); $total_pages = ceil($database->get_one( From 937eefcb503a07a85e89e5109b14377824f1ae18 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sun, 24 Feb 2013 01:05:50 +0100 Subject: [PATCH 08/10] /post/view now also supports things like /post/view/4#search=tag1 --- ext/arrowkey_navigation/main.php | 41 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 40f5da57..49d6e6a0 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -9,16 +9,16 @@ * Simply enable this extention in the extention manager to enable arrow key navigation. */ 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")) { + if ($event->page_matches("post/view")) { + $pageinfo = $this->get_view_pageinfo($event); + $prev_url = make_http(make_link("post/prev/".$pageinfo["current"])); + $next_url = make_http(make_link("post/next/".$pageinfo["current"])); + $this->add_arrowkeys_code($prev_url, $next_url); + } + + else 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"])); @@ -40,8 +40,8 @@ class arrowkey_navigation extends Extension { if (e.srcElement.tagName != \"INPUT\") { - if(keycode==\"37\") window.location.href='$prev_url'; - else if(keycode==\"39\") window.location.href='$next_url'; + if(keycode==\"37\") window.location.href='$prev_url' + window.location.hash; + else if(keycode==\"39\") window.location.href='$next_url' + window.location.hash; } } "); @@ -87,11 +87,28 @@ class arrowkey_navigation extends Extension { // Create return array $pageinfo = array( - "prev" => $prefix.$prev, - "next" => $prefix.$next, + "prev" => $prefix.$prev.$after, + "next" => $prefix.$next.$after, ); return $pageinfo; } + + # returns url ext with any tags + private function get_view_pageinfo($event) { + // if there are no tags, use default + if ($event->get_arg(1) == null){ + $prefix = ""; + $image_id = (int)$event->get_arg(0); + } + + else { // if there are tags, use pages with tags + $prefix = $event->get_arg(0)."/"; + $image_id = (int)$event->get_arg(1); + } + + // returns result + return $prefix.$image_id; + } } ?> From cf9e0eae8c12f22a0cc2d50f4af5c22a9667b9b9 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sun, 24 Feb 2013 01:26:48 +0100 Subject: [PATCH 09/10] oops, forgot something --- ext/arrowkey_navigation/main.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 49d6e6a0..657f0891 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -13,8 +13,8 @@ class arrowkey_navigation extends Extension { public function onPageRequest(PageRequestEvent $event) { if ($event->page_matches("post/view")) { $pageinfo = $this->get_view_pageinfo($event); - $prev_url = make_http(make_link("post/prev/".$pageinfo["current"])); - $next_url = make_http(make_link("post/next/".$pageinfo["current"])); + $prev_url = make_http(make_link("post/prev/".$pageinfo)); + $next_url = make_http(make_link("post/next/".$pageinfo)); $this->add_arrowkeys_code($prev_url, $next_url); } @@ -99,7 +99,7 @@ class arrowkey_navigation extends Extension { // if there are no tags, use default if ($event->get_arg(1) == null){ $prefix = ""; - $image_id = (int)$event->get_arg(0); + $image_id = (int)$event->get_arg(0); } else { // if there are tags, use pages with tags From a03e4d5102e647386977f795b4e9886de3b13d98 Mon Sep 17 00:00:00 2001 From: Drudex Software <> Date: Mon, 25 Feb 2013 01:59:43 +0100 Subject: [PATCH 10/10] Custom HTML Headers added I may also expand it to allow headers specific pages later --- ext/custom_html_headers/main.php | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ext/custom_html_headers/main.php diff --git a/ext/custom_html_headers/main.php b/ext/custom_html_headers/main.php new file mode 100644 index 00000000..99c1d94c --- /dev/null +++ b/ext/custom_html_headers/main.php @@ -0,0 +1,33 @@ + + * Link: http://www.drudexsoftware.com + * License: GPLv2 + * Description: Allows admins to set custom content + * Documentation: + * When you go to board config you can find a block named Custom HTML Headers. + * In that block you can simply place any thing you can place within + * + * This can be useful if you want to add website tracking code or other javascript. + * NOTE: Only use if you know what you're doing. + * + */ +class custom_html_headers extends Extension { + # Adds setup block for custom content + public function onSetupBuilding(SetupBuildingEvent $event) { + $sb = new SetupBlock("Custom HTML Headers"); + $sb->add_longtext_option("custom_html_headers", + "HTML Code to place within <head></head> on all pages
"); + $event->panel->add_block($sb); + } + + # Load Analytics tracking code on page request + public function onPageRequest(PageRequestEvent $event) { + global $config, $page; + + $header = $config->get_string('custom_html_headers',''); + if ($header!='') $page->add_html_header($header); + } +} +?>