Fixed problems from notes by shish
Added arrowkey navigator to post/list as well arrowkey navigator also works with tags on post/list now
This commit is contained in:
		
							parent
							
								
									dfd7157cd2
								
							
						
					
					
						commit
						13d8b0831e
					
				| @ -2,19 +2,34 @@ | |||||||
| /** | /** | ||||||
|  * Name: Arrow Key Navigation |  * Name: Arrow Key Navigation | ||||||
|  * Author: Drudex Software <support@drudexsoftware.com> |  * Author: Drudex Software <support@drudexsoftware.com> | ||||||
|  * Link: http://drudexsoftware.com |  * Link: http://www.drudexsoftware.com/ | ||||||
|  * License: GPLv2 |  * License: GPLv2 | ||||||
|  * Description: Allows viewers no navigate between images using the left & right arrow keys. |  * Description: Allows viewers no navigate between images using the left & right arrow keys. | ||||||
|  * Documentation: |  * Documentation: | ||||||
|  *  Simply enable this extention in the extention manager to enable arrow key navigation. |  *  Simply enable this extention in the extention manager to enable arrow key navigation. | ||||||
|  */ |  */ | ||||||
| class arrowkey_navigation extends Extension {    | class arrowkey_navigation extends Extension {   | ||||||
|     public function onDisplayingImage(DisplayingImageEvent $event) { |     # 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; |         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("<script type=\"text/javascript\">
 |         $page->add_html_header("<script type=\"text/javascript\">
 | ||||||
|             document.onkeyup=checkKeycode; |             document.onkeyup=checkKeycode; | ||||||
|             function checkKeycode(e) |             function checkKeycode(e) | ||||||
| @ -30,6 +45,42 @@ class arrowkey_navigation extends Extension { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             </script>");
 |             </script>");
 | ||||||
|     }   |     } | ||||||
|  |      | ||||||
|  |     # 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; | ||||||
|  |     } | ||||||
| } | } | ||||||
| ?>
 | ?>
 | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ | |||||||
| /** | /** | ||||||
|  * Name: Image View Counter |  * Name: Image View Counter | ||||||
|  * Author: Drudex Software <support@drudexsoftware.com> |  * Author: Drudex Software <support@drudexsoftware.com> | ||||||
|  * Link: http://drudexsoftware.com |  * Link: http://www.drudexsoftware.com/ | ||||||
|  * License: GPLv2 |  * License: GPLv2 | ||||||
|  * Description: Tracks & displays how many times an image is viewed |  * Description: Tracks & displays how many times an image is viewed | ||||||
|  * Documentation: |  * Documentation: | ||||||
| @ -32,7 +32,7 @@ class image_view_counter extends Extension { | |||||||
|         public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { |         public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { | ||||||
| 		global $user, $config; | 		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())) |                 if ($adminonly == false ||  ($adminonly && $user->is_admin())) | ||||||
|                     $event->add_part("<tr><th>Views:</th><td>".  |                     $event->add_part("<tr><th>Views:</th><td>".  | ||||||
|                         $this->get_view_count($event->image->id) ."</th></tr>", 38); |                         $this->get_view_count($event->image->id) ."</th></tr>", 38); | ||||||
| @ -43,14 +43,13 @@ class image_view_counter extends Extension { | |||||||
|             global $database, $config; |             global $database, $config; | ||||||
|              |              | ||||||
|             // if the sql table doesn't exist yet, create it
 |             // if the sql table doesn't exist yet, create it
 | ||||||
|             if($config->get_bool("image_viewcounter_installed") == false) { |             if($config->get_bool("image_viewcounter_installed") == false) { //todo
 | ||||||
|                 $database->execute("CREATE TABLE image_views (
 |                 $database->create_table("image_views"," | ||||||
|                 id bigint(20) NOT NULL AUTO_INCREMENT, |                     id bigint(20) SCORE_AIPK, | ||||||
|                 image_id int(11) NOT NULL, |                     image_id INTEGER NOT NULL, | ||||||
|                 user_id int(11) NOT NULL, |                     user_id INTEGER NOT NULL, | ||||||
|                 timestamp int(11) NOT NULL, |                     timestamp INTEGER NOT NULL, | ||||||
|                 ipaddress varchar(255) NOT NULL,  |                     ipaddress SCORE_INET NOT NULL");
 | ||||||
|                 PRIMARY KEY (id))"); 
 |  | ||||||
|                 $config->set_bool("image_viewcounter_installed", true); |                 $config->set_bool("image_viewcounter_installed", true); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @ -79,14 +78,14 @@ class image_view_counter extends Extension { | |||||||
|             global $database; |             global $database; | ||||||
|              |              | ||||||
|             // counts views from current IP in the last hour
 |             // 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", 
 |                 ipaddress=:ipaddress AND timestamp >:lasthour AND image_id =:image_id", 
 | ||||||
|                     array(  "ipaddress" => $_SERVER['REMOTE_ADDR'], |                     array(  "ipaddress" => $_SERVER['REMOTE_ADDR'], | ||||||
|                             "lasthour" => time() - $this->view_interval, |                             "lasthour" => time() - $this->view_interval, | ||||||
|                             "image_id" => $imgid)); |                             "image_id" => $imgid)); | ||||||
|              |              | ||||||
|             // if no views were found with the set criteria, return true
 |             // 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; |             else return false; | ||||||
|         } |         } | ||||||
|          |          | ||||||
| @ -97,13 +96,13 @@ class image_view_counter extends Extension { | |||||||
|             global $database; |             global $database; | ||||||
|              |              | ||||||
|             if ($imgid == 0) // return view count of all images
 |             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
 |             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)); |                     "image_id =:image_id", array("image_id" => $imgid)); | ||||||
|              |              | ||||||
|             // returns the count as int
 |             // returns the count as int
 | ||||||
|             return intval($view_count["COUNT(*)"]); |             return $view_count; | ||||||
|         } |         } | ||||||
| } | } | ||||||
| ?>
 | ?>
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user