From b7b8786f1853f15e7f32f4203167df020199b22d Mon Sep 17 00:00:00 2001 From: Drudex Software <> Date: Sun, 10 Feb 2013 17:41:19 +0100 Subject: [PATCH 01/18] Remade the sitemap extension - now makes full sitemap with specific with higher priorities for newer/more popular content - Sitemap is cached for 6 hours several things still need to be added --- ext/sitemap/main.php | 189 ++++++++++++++++++++++++++++++------------- 1 file changed, 135 insertions(+), 54 deletions(-) diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index e481510f..37f494c0 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -1,54 +1,135 @@ - - * License: GPLv2 - * Description: Adds sitemap.xml on request. - * Documentation: - */ - -class XMLSitemap extends Extension { - public function onPageRequest(PageRequestEvent $event) { - if($event->page_matches("sitemap.xml")) { - $images = Image::find_images(0, 50, array()); - $this->do_xml($images); - } - } - - private function do_xml(/*array(Image)*/ $images) { - global $page; - $page->set_mode("data"); - $page->set_type("application/xml"); - - $data = ""; - foreach($images as $image) { - $link = make_http(make_link("post/view/{$image->id}")); - $posted = date("Y-m-d", $image->posted_timestamp); - - $data .= " - - $link - $posted - monthly - 0.8 - - "; - } - - $base_href = make_http(make_link("post/list")); - - $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> - - - $base_href - 2009-01-01 - monthly - 1 - - $data - - "; - $page->set_data($xml); - } -} -?> +, Drudex Software set_default_string("last_sitemap", // set initial date to a year ago + date($this->time_structure, strtotime('-1 year',time()))); + } + + public function onPageRequest(PageRequestEvent $event) { + global $database, $config; + if($event->page_matches("sitemap.xml")) + { + // creates default value + $config->set_default_string("last_sitemap", // set initial date to a year ago + date($this->time_structure, strtotime('-1 year',time()))); + + // remakes sitemap if needed + $lastsitemaptime = date($this->time_structure, $config->get_string("last_sitemap")); + $sitemap_creation_allowed_time = date($this->time_structure, strtotime("+$this->sitemap_creation_interval hours", $lastsitemaptime)); + if ($sitemap_creation_allowed_time < time() || // sitemap is allowed to reset + !file_exists($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml")) // or sitemap can be remade + { + // add index + $index[0] = $base_href = make_http(make_link("post/list")); + $this->add_sitemap_queue($index, "weekly", "1"); + + /* --- Add 20 most used tags --- */ + $popular_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 0,20"); + foreach($popular_tags as $arrayid => $tag) { + $tag = $tag['tag']; + // create url from tags (tagme ignored) + if ($tag != "tagme") + $popular_tags[$arrayid] = "post/list/$tag/"; + } + $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); + + /* --- Add latest images to sitemap with higher priority --- */ + $latestimages = Image::find_images(0, 50, array()); + $latestimages_urllist = array(); + foreach($latestimages as $arrayid => $image) + // create url from image id's + $latestimages_urllist[$arrayid] = "post/view/$image->id"; + $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); + + /* --- Add other tags --- */ + $other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000"); + foreach($other_tags as $arrayid => $tag) { + $tag = $tag['tag']; + // create url from tags (tagme ignored) + if ($tag != "tagme") + $other_tags[$arrayid] = "post/list/$tag/"; + } + $this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */); + + /* --- Add all other images to sitemap with lower priority --- */ + $otherimages = Image::find_images(51, 10000000, array()); + foreach($otherimages as $arrayid => $image) + // create url from image id's + $otherimages[$arrayid] = "post/view/$image->id"; + $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp)); + + // Creates the sitemap file + $this->create_sitemap(); + } + + /* --- Display page --- */ + // when sitemap is ok, display it from the file + $this->display_sitemap(); + } + } + + // Adds an array of urls to the sitemap with the given information + private function add_sitemap_queue(/*array(urls)*/ $urls, $changefreq="monthly", $priority="0.5", $date="2013-02-01") { + foreach($urls as $url) { + $link = make_http(make_link("$url")); + $this->sitemap_queue .= " + + $link + $date + $changefreq + $priority + "; + } + } + + // sets sitemap with entries in the queue + private function display_sitemap() + { + global $page; + $page->set_mode("data"); + $page->set_type("application/xml"); + + // read file + $filename = $_SERVER['DOCUMENT_ROOT']."/sitemap.xml"; + $xmlreader = fopen($filename, 'r') or die("can't open file"); + $xml = fread($xmlreader, filesize($filename)); + fclose($xmlreader); + + // sets + $page->set_data($xml); + } + + // creates the xml sitemap file from the queue + private function create_sitemap() + { + global $config; + + $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> + + $this->sitemap_queue + "; + + $fh = fopen($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml", 'w') or die("can't open file"); + fwrite($fh, $this->sitemap_queue); + fclose($fh); + + file_put_contents($_SERVER['DOCUMENT_ROOT']."/sitemap.xml", $xml); + $config->set_string("last_sitemap", date($this->time_structure, time())); + } +} +?> From 59ec209c4a3c5564ec3a0c286a4c002aa03d5dc3 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Mon, 11 Feb 2013 08:43:06 +0100 Subject: [PATCH 02/18] Caching not working properly for various reasons, removed for now --- ext/sitemap/main.php | 226 +++++++++++++++++-------------------------- 1 file changed, 91 insertions(+), 135 deletions(-) diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 37f494c0..6db61708 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -1,135 +1,91 @@ -, Drudex Software set_default_string("last_sitemap", // set initial date to a year ago - date($this->time_structure, strtotime('-1 year',time()))); - } - - public function onPageRequest(PageRequestEvent $event) { - global $database, $config; - if($event->page_matches("sitemap.xml")) - { - // creates default value - $config->set_default_string("last_sitemap", // set initial date to a year ago - date($this->time_structure, strtotime('-1 year',time()))); - - // remakes sitemap if needed - $lastsitemaptime = date($this->time_structure, $config->get_string("last_sitemap")); - $sitemap_creation_allowed_time = date($this->time_structure, strtotime("+$this->sitemap_creation_interval hours", $lastsitemaptime)); - if ($sitemap_creation_allowed_time < time() || // sitemap is allowed to reset - !file_exists($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml")) // or sitemap can be remade - { - // add index - $index[0] = $base_href = make_http(make_link("post/list")); - $this->add_sitemap_queue($index, "weekly", "1"); - - /* --- Add 20 most used tags --- */ - $popular_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 0,20"); - foreach($popular_tags as $arrayid => $tag) { - $tag = $tag['tag']; - // create url from tags (tagme ignored) - if ($tag != "tagme") - $popular_tags[$arrayid] = "post/list/$tag/"; - } - $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); - - /* --- Add latest images to sitemap with higher priority --- */ - $latestimages = Image::find_images(0, 50, array()); - $latestimages_urllist = array(); - foreach($latestimages as $arrayid => $image) - // create url from image id's - $latestimages_urllist[$arrayid] = "post/view/$image->id"; - $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); - - /* --- Add other tags --- */ - $other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000"); - foreach($other_tags as $arrayid => $tag) { - $tag = $tag['tag']; - // create url from tags (tagme ignored) - if ($tag != "tagme") - $other_tags[$arrayid] = "post/list/$tag/"; - } - $this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */); - - /* --- Add all other images to sitemap with lower priority --- */ - $otherimages = Image::find_images(51, 10000000, array()); - foreach($otherimages as $arrayid => $image) - // create url from image id's - $otherimages[$arrayid] = "post/view/$image->id"; - $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp)); - - // Creates the sitemap file - $this->create_sitemap(); - } - - /* --- Display page --- */ - // when sitemap is ok, display it from the file - $this->display_sitemap(); - } - } - - // Adds an array of urls to the sitemap with the given information - private function add_sitemap_queue(/*array(urls)*/ $urls, $changefreq="monthly", $priority="0.5", $date="2013-02-01") { - foreach($urls as $url) { - $link = make_http(make_link("$url")); - $this->sitemap_queue .= " - - $link - $date - $changefreq - $priority - "; - } - } - - // sets sitemap with entries in the queue - private function display_sitemap() - { - global $page; - $page->set_mode("data"); - $page->set_type("application/xml"); - - // read file - $filename = $_SERVER['DOCUMENT_ROOT']."/sitemap.xml"; - $xmlreader = fopen($filename, 'r') or die("can't open file"); - $xml = fread($xmlreader, filesize($filename)); - fclose($xmlreader); - - // sets - $page->set_data($xml); - } - - // creates the xml sitemap file from the queue - private function create_sitemap() - { - global $config; - - $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> - - $this->sitemap_queue - "; - - $fh = fopen($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml", 'w') or die("can't open file"); - fwrite($fh, $this->sitemap_queue); - fclose($fh); - - file_put_contents($_SERVER['DOCUMENT_ROOT']."/sitemap.xml", $xml); - $config->set_string("last_sitemap", date($this->time_structure, time())); - } -} -?> + + * License: GPLv2 + * Description: Adds sitemap.xml on request. + * Documentation: + */ + +class XMLSitemap extends Extension { + private $sitemap_queue = ""; + + public function onPageRequest(PageRequestEvent $event) { + global $database, $config; + if($event->page_matches("sitemap.xml")) + { + // add index + $index[0] = $base_href = $config->get_string("front_page"); + $this->add_sitemap_queue($index, "weekly", "1"); + + /* --- Add 20 most used tags --- */ + $popular_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 0,20"); + foreach($popular_tags as $arrayid => $tag) { + $tag = $tag['tag']; + $popular_tags[$arrayid] = "post/list/$tag/"; + } + $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); + + /* --- Add latest images to sitemap with higher priority --- */ + $latestimages = Image::find_images(0, 50, array()); + $latestimages_urllist = array(); + foreach($latestimages as $arrayid => $image) + // create url from image id's + $latestimages_urllist[$arrayid] = "post/view/$image->id"; + $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); + + /* --- Add other tags --- */ + $other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000"); + foreach($other_tags as $arrayid => $tag) { + $tag = $tag['tag']; + // create url from tags (tagme ignored) + if ($tag != "tagme") + $other_tags[$arrayid] = "post/list/$tag/"; + } + $this->add_sitemap_queue($other_tags, "monthly", "0.7" /* not sure how to deal with date here */); + + /* --- Add all other images to sitemap with lower priority --- */ + $otherimages = Image::find_images(51, 10000000, array()); + foreach($otherimages as $arrayid => $image) + // create url from image id's + $otherimages[$arrayid] = "post/view/$image->id"; + $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp)); + + + /* --- Display page --- */ + // when sitemap is ok, display it from the file + $this->display_sitemap(); + } + } + + // Adds an array of urls to the sitemap with the given information + private function add_sitemap_queue(/*array(urls)*/ $urls, $changefreq="monthly", $priority="0.5", $date="2013-02-01") { + foreach($urls as $url) { + $link = make_http(make_link("$url")); + $this->sitemap_queue .= " + + $link + $date + $changefreq + $priority + "; + } + } + + // sets sitemap with entries in the queue + private function display_sitemap() + { + global $page; + $page->set_mode("data"); + $page->set_type("application/xml"); + + $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> + + $this->sitemap_queue + "; + + // sets + $page->set_data($xml); + } +} +?> From 62ad4c0ecb8e29a967ce9f12a4e4407a59656f8f Mon Sep 17 00:00:00 2001 From: Drudex Software Date: Thu, 14 Feb 2013 22:34:43 +0100 Subject: [PATCH 03/18] Update ext/user/main.php Site owners can now choose in board config what page users will go to when logging in: - Previous page (default) - My Profile (old default) --- ext/user/main.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ext/user/main.php b/ext/user/main.php index d0ac076f..5aab495c 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -144,7 +144,12 @@ class UserPage extends Extension { } log_info("user", "Logged out"); $page->set_mode("redirect"); - $page->set_redirect(make_link()); + + // Try forwarding to same page on logout unless user comes from registration page + if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create")) + $page->set_redirect ($_SERVER['HTTP_REFERER']); + else + $page->set_redirect(make_link()); } if(!$user->check_auth_token()) { @@ -330,7 +335,12 @@ class UserPage extends Extension { $this->set_login_cookie($duser->name, $pass); log_info("user", "{$user->class->name} logged in"); $page->set_mode("redirect"); - $page->set_redirect(make_link("user")); + + // Try returning to previous page + if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create")) + $page->set_redirect ($_SERVER['HTTP_REFERER']); + else + $page->set_redirect(make_link("user")); } else { log_warning("user", "Failed to log in as ".html_escape($name)." [$hash]"); From 55b09194657e56ca959b810afd32cb09ed0b6886 Mon Sep 17 00:00:00 2001 From: Drudex Software Date: Thu, 14 Feb 2013 23:54:23 +0100 Subject: [PATCH 04/18] Update ext/user/main.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also don't return to same page if page is "user_admin/login".  Otherwise it can occur if user first failed to log in with the correct credentials --- ext/user/main.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/user/main.php b/ext/user/main.php index 5aab495c..be60faf7 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -337,7 +337,8 @@ class UserPage extends Extension { $page->set_mode("redirect"); // Try returning to previous page - if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create")) + if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create") && + !strstr($_SERVER['HTTP_REFERER'], "user_admin/login")) $page->set_redirect ($_SERVER['HTTP_REFERER']); else $page->set_redirect(make_link("user")); From c90689a63e98b9fc62d6d139e3bb8b52e3e5b5ce Mon Sep 17 00:00:00 2001 From: Drudex Software Date: Fri, 15 Feb 2013 02:22:09 +0100 Subject: [PATCH 05/18] Update ext/user/main.php - Added board config option for user login forwarding - Set user_loginshowprofile default to 0 - now only applies when user is on a page containing post/ in its url (to avoid weird messages) --- ext/user/main.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/user/main.php b/ext/user/main.php index be60faf7..c87fbe8f 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -146,7 +146,9 @@ class UserPage extends Extension { $page->set_mode("redirect"); // Try forwarding to same page on logout unless user comes from registration page - if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create")) + if ($config->get_int("user_loginshowprofile",0) == 0 && + isset($_SERVER['HTTP_REFERER']) && + strstr($_SERVER['HTTP_REFERER'], "post/")) $page->set_redirect ($_SERVER['HTTP_REFERER']); else $page->set_redirect(make_link()); @@ -278,7 +280,11 @@ class UserPage extends Extension { array('G'=>'g', 'PG'=>'pg', 'R'=>'r', 'X'=>'x'), "
Rating: "); } - + + $sb->add_choice_option("user_loginshowprofile", array( + "return to previous page" => 0, // 0 is default + "send to user profile" => 1), + "
When user logs in/out"); $event->panel->add_block($sb); } @@ -319,6 +325,7 @@ class UserPage extends Extension { // Things done *with* the user {{{ private function login(Page $page) { global $user; + global $config; $name = $_POST['user']; $pass = $_POST['pass']; @@ -336,12 +343,12 @@ class UserPage extends Extension { log_info("user", "{$user->class->name} logged in"); $page->set_mode("redirect"); - // Try returning to previous page - if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], "user_admin/create") && - !strstr($_SERVER['HTTP_REFERER'], "user_admin/login")) - $page->set_redirect ($_SERVER['HTTP_REFERER']); - else - $page->set_redirect(make_link("user")); + // Try returning to previous page + if ($config->get_int("user_loginshowprofile",0) == 0 && + isset($_SERVER['HTTP_REFERER']) && + strstr($_SERVER['HTTP_REFERER'], "post/")) + $page->set_redirect($_SERVER['HTTP_REFERER']); + else $page->set_redirect(make_link("user")); } else { log_warning("user", "Failed to log in as ".html_escape($name)." [$hash]"); From 52893d0f04574bb6a011da29ebdcf985c8a14839 Mon Sep 17 00:00:00 2001 From: Drudex Software Date: Fri, 15 Feb 2013 03:04:58 +0100 Subject: [PATCH 06/18] Update ext/sitemap/main.php - Added setup block to choose between generating full sitemap or smaller sitemap --- ext/sitemap/main.php | 47 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 6db61708..5fcb5343 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -11,9 +11,48 @@ class XMLSitemap extends Extension { private $sitemap_queue = ""; public function onPageRequest(PageRequestEvent $event) { - global $database, $config; if($event->page_matches("sitemap.xml")) - { + { + global $config; + + if ($config->get_bool("sitemap_generatefull",false)) + $this->handle_full_sitemap(); // default false until cache fixed + else + $this->handle_smaller_sitemap(); + } + + } + + public function onSetupBuilding(SetupBuildingEvent $event) { + $sb = new SetupBlock("Sitemap (Beta)"); // beta until sitemap cache fixed + + $sb->add_bool_option("sitemap_generatefull", "Generate full sitemap"); + $sb->add_label("
(Enabled: every image and tag in sitemap, generation takes longer)"); + $sb->add_label("
(Disabled: only display the last 50 uploads in the sitemap)"); + + $event->panel->add_block($sb); + } + + // sitemap with only the latest 50 images + private function handle_smaller_sitemap() + { + /* --- Add latest images to sitemap with higher priority --- */ + $latestimages = Image::find_images(0, 50, array()); + $latestimages_urllist = array(); + foreach($latestimages as $arrayid => $image) + // create url from image id's + $latestimages_urllist[$arrayid] = "post/view/$image->id"; + $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); + + /* --- Display page --- */ + // when sitemap is ok, display it from the file + $this->display_sitemap(); + } + + // Full sitemap + private function handle_full_sitemap() + { + global $database, $config; // add index $index[0] = $base_href = $config->get_string("front_page"); $this->add_sitemap_queue($index, "weekly", "1"); @@ -55,8 +94,7 @@ class XMLSitemap extends Extension { /* --- Display page --- */ // when sitemap is ok, display it from the file $this->display_sitemap(); - } - } + } // Adds an array of urls to the sitemap with the given information private function add_sitemap_queue(/*array(urls)*/ $urls, $changefreq="monthly", $priority="0.5", $date="2013-02-01") { @@ -73,6 +111,7 @@ class XMLSitemap extends Extension { } // sets sitemap with entries in the queue + // todo: cache sitemap for a config specified amount of time private function display_sitemap() { global $page; From e64f1f0bcbcc5daaa4493ccfab81feb1d1f55331 Mon Sep 17 00:00:00 2001 From: Drudex Software Date: Fri, 15 Feb 2013 04:31:31 +0100 Subject: [PATCH 07/18] Update ext/sitemap/main.php - Added setup block to choose between generating full sitemap or smaller sitemap - Added sitemap caching, regenerating at most every day --- ext/sitemap/main.php | 61 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 5fcb5343..389d560a 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -2,29 +2,37 @@ /* * Name: XML Sitemap * Author: Sein Kraft + * Author: Drudex Software * License: GPLv2 - * Description: Adds sitemap.xml on request. + * Description: Sitemap with caching & advanced priorities * Documentation: */ class XMLSitemap extends Extension { private $sitemap_queue = ""; + private $sitemap_filepath = ""; // set onPageRequest public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("sitemap.xml")) { global $config; - if ($config->get_bool("sitemap_generatefull",false)) - $this->handle_full_sitemap(); // default false until cache fixed - else - $this->handle_smaller_sitemap(); - } - + $this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/ext/sitemap/generated_sitemap.xml"; + // determine if new sitemap needs to be generated + if ($this->new_sitemap_needed()) + { + // determine which type of sitemap to generate + if ($config->get_bool("sitemap_generatefull",false)) + $this->handle_full_sitemap(); // default false until cache fixed + else + $this->handle_smaller_sitemap(); + } + else $this->display_existing_sitemap(); + } } public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Sitemap (Beta)"); // beta until sitemap cache fixed + $sb = new SetupBlock("Sitemap"); $sb->add_bool_option("sitemap_generatefull", "Generate full sitemap"); $sb->add_label("
(Enabled: every image and tag in sitemap, generation takes longer)"); @@ -46,7 +54,7 @@ class XMLSitemap extends Extension { /* --- Display page --- */ // when sitemap is ok, display it from the file - $this->display_sitemap(); + $this->generate_display_sitemap(); } // Full sitemap @@ -93,7 +101,7 @@ class XMLSitemap extends Extension { /* --- Display page --- */ // when sitemap is ok, display it from the file - $this->display_sitemap(); + $this->generate_display_sitemap(); } // Adds an array of urls to the sitemap with the given information @@ -111,10 +119,10 @@ class XMLSitemap extends Extension { } // sets sitemap with entries in the queue - // todo: cache sitemap for a config specified amount of time - private function display_sitemap() + private function generate_display_sitemap() { - global $page; + global $page, $config; + $page->set_mode("data"); $page->set_type("application/xml"); @@ -124,6 +132,33 @@ class XMLSitemap extends Extension { "; // sets + $config->set_int("sitemap_lastgenerated", time()); + file_put_contents($this->sitemap_filepath, $xml); + $page->set_data($xml); + } + + // returns true if a new sitemap is needed + private function new_sitemap_needed() + { + global $config; + + $sitemap_generation_interval = 86400; // allow new site map every day + $last_generated_time = $config->get_int("sitemap_lastgenerated",0); + + if (!file_exists($this->sitemap_filepath) || + ($last_generated_time + $sitemap_generation_interval < time())) + return true; + else return false; + } + + private function display_existing_sitemap() + { + global $page; + + $page->set_mode("data"); + $page->set_type("application/xml"); + + $xml = file_get_contents($this->sitemap_filepath); $page->set_data($xml); } } From 4c170110e8f516d45938fc2905ea28ba0bcb9569 Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Wed, 20 Feb 2013 00:31:52 +0100 Subject: [PATCH 08/18] Moved sitemap file to /data/cache/sitemap.xml Sitemap creation time now determined by filemtime instead of via config --- ext/sitemap/main.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 389d560a..7a58ab05 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -17,7 +17,7 @@ class XMLSitemap extends Extension { { global $config; - $this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/ext/sitemap/generated_sitemap.xml"; + $this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/data/cache/sitemap.xml"; // determine if new sitemap needs to be generated if ($this->new_sitemap_needed()) { @@ -121,7 +121,7 @@ class XMLSitemap extends Extension { // sets sitemap with entries in the queue private function generate_display_sitemap() { - global $page, $config; + global $page; $page->set_mode("data"); $page->set_type("application/xml"); @@ -131,8 +131,7 @@ class XMLSitemap extends Extension { $this->sitemap_queue "; - // sets - $config->set_int("sitemap_lastgenerated", time()); + // Generate new sitemap & display file_put_contents($this->sitemap_filepath, $xml); $page->set_data($xml); } @@ -140,13 +139,14 @@ class XMLSitemap extends Extension { // returns true if a new sitemap is needed private function new_sitemap_needed() { - global $config; - $sitemap_generation_interval = 86400; // allow new site map every day - $last_generated_time = $config->get_int("sitemap_lastgenerated",0); + $last_generated_time = filemtime($this->sitemap_filepath); - if (!file_exists($this->sitemap_filepath) || - ($last_generated_time + $sitemap_generation_interval < time())) + // if file doesn't exist, return true + if ($last_generated_time == false) return true; + + // if it's been a day since last sitemap creation, return true + if ($last_generated_time + $sitemap_generation_interval < time()) return true; else return false; } @@ -162,4 +162,4 @@ class XMLSitemap extends Extension { $page->set_data($xml); } } -?> +?> \ No newline at end of file From 1a38a152e6951898a1d5dbf016fb9bacf17c659a Mon Sep 17 00:00:00 2001 From: DrudexSoftware Date: Sat, 23 Feb 2013 06:21:00 +0100 Subject: [PATCH 09/18] 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 10/18] 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 11/18] 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 12/18] 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 13/18] 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 14/18] 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 15/18] 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 16/18] /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 17/18] 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 18/18] 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); + } +} +?>