commit
						937016d104
					
				@ -1,19 +1,31 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Name: Pools System
 | 
					 * Name: Pools System
 | 
				
			||||||
 * Author: Sein Kraft <mail@seinkraft.info>
 | 
					 * Author: Sein Kraft <mail@seinkraft.info>, jgen <jgen.tech@gmail.com>
 | 
				
			||||||
 * License: GPLv2
 | 
					 * License: GPLv2
 | 
				
			||||||
 * Description: Allow users to create groups of images
 | 
					 * Description: Allow users to create groups of images and order them.
 | 
				
			||||||
 * Documentation:
 | 
					 * Documentation: This extension allows users to created named groups of
 | 
				
			||||||
 | 
					 *   images, and order the images within the group.
 | 
				
			||||||
 | 
					 *   Useful for related images like in a comic, etc.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This class is just a wrapper around SCoreException.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
class PoolCreationException extends SCoreException {
 | 
					class PoolCreationException extends SCoreException {
 | 
				
			||||||
 | 
						var $error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function __construct($error) {
 | 
				
			||||||
 | 
							$this->error = $error;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Pools extends Extension {
 | 
					class Pools extends Extension {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onInitExt(InitExtEvent $event) {
 | 
						public function onInitExt(InitExtEvent $event) {
 | 
				
			||||||
		global $config, $database;
 | 
							global $config, $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Create the database tables
 | 
				
			||||||
		if ($config->get_int("ext_pools_version") < 1){
 | 
							if ($config->get_int("ext_pools_version") < 1){
 | 
				
			||||||
			$database->create_table("pools", "
 | 
								$database->create_table("pools", "
 | 
				
			||||||
					id SCORE_AIPK,
 | 
										id SCORE_AIPK,
 | 
				
			||||||
@ -41,6 +53,7 @@ class Pools extends Extension {
 | 
				
			|||||||
					INDEX (id)
 | 
										INDEX (id)
 | 
				
			||||||
					");
 | 
										");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Set the defaults for the pools extension
 | 
				
			||||||
			$config->set_int("ext_pools_version", 1);
 | 
								$config->set_int("ext_pools_version", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$config->set_int("poolsMaxImportResults", 1000);
 | 
								$config->set_int("poolsMaxImportResults", 1000);
 | 
				
			||||||
@ -49,11 +62,13 @@ class Pools extends Extension {
 | 
				
			|||||||
			$config->set_int("poolsUpdatedPerPage", 20);
 | 
								$config->set_int("poolsUpdatedPerPage", 20);
 | 
				
			||||||
			$config->set_bool("poolsInfoOnViewImage", "N");
 | 
								$config->set_bool("poolsInfoOnViewImage", "N");
 | 
				
			||||||
			$config->set_bool("poolsAdderOnViewImage", "N");
 | 
								$config->set_bool("poolsAdderOnViewImage", "N");
 | 
				
			||||||
 | 
								$config->set_bool("poolsShowNextLink","N");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			log_info("pools", "extension installed");
 | 
								log_info("pools", "extension installed");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Add a block to the Board Config / Setup
 | 
				
			||||||
	public function onSetupBuilding(SetupBuildingEvent $event) {
 | 
						public function onSetupBuilding(SetupBuildingEvent $event) {
 | 
				
			||||||
		$sb = new SetupBlock("Pools");
 | 
							$sb = new SetupBlock("Pools");
 | 
				
			||||||
		$sb->add_int_option("poolsMaxImportResults", "Max results on import: ");
 | 
							$sb->add_int_option("poolsMaxImportResults", "Max results on import: ");
 | 
				
			||||||
@ -61,6 +76,7 @@ class Pools extends Extension {
 | 
				
			|||||||
		$sb->add_int_option("poolsListsPerPage", "<br>Index list items per page: ");
 | 
							$sb->add_int_option("poolsListsPerPage", "<br>Index list items per page: ");
 | 
				
			||||||
		$sb->add_int_option("poolsUpdatedPerPage", "<br>Updated list items per page: ");
 | 
							$sb->add_int_option("poolsUpdatedPerPage", "<br>Updated list items per page: ");
 | 
				
			||||||
		$sb->add_bool_option("poolsInfoOnViewImage", "<br>Show pool info on image: ");
 | 
							$sb->add_bool_option("poolsInfoOnViewImage", "<br>Show pool info on image: ");
 | 
				
			||||||
 | 
							$sb->add_bool_option("poolsShowNextLink", "<br>Show 'Next' link when viewing pool images: ");
 | 
				
			||||||
		//$sb->add_bool_option("poolsAdderOnViewImage", "<br>Show pool adder on image: ");
 | 
							//$sb->add_bool_option("poolsAdderOnViewImage", "<br>Show pool adder on image: ");
 | 
				
			||||||
		$event->panel->add_block($sb);
 | 
							$event->panel->add_block($sb);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -68,13 +84,24 @@ class Pools extends Extension {
 | 
				
			|||||||
	public function onPageRequest(PageRequestEvent $event) {
 | 
						public function onPageRequest(PageRequestEvent $event) {
 | 
				
			||||||
		global $config, $page, $user;
 | 
							global $config, $page, $user;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if($event->page_matches("pool")) {
 | 
							if ($event->page_matches("pool")) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$pool_id = 0;
 | 
				
			||||||
 | 
								$pool = array();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// Check if we have pool id, since this is most often the case.
 | 
				
			||||||
 | 
								if (isset($_POST["pool_id"])) {
 | 
				
			||||||
 | 
									$pool_id = int_escape($_POST["pool_id"]);
 | 
				
			||||||
 | 
									$pool = $this->get_single_pool($pool_id);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// What action are we trying to perform?
 | 
				
			||||||
			switch($event->get_arg(0)) {
 | 
								switch($event->get_arg(0)) {
 | 
				
			||||||
				case "list": //index
 | 
									case "list": //index
 | 
				
			||||||
					$this->list_pools($page, int_escape($event->get_arg(1)));
 | 
										$this->list_pools($page, int_escape($event->get_arg(1)));
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "new": // Show form
 | 
									case "new": // Show form for new pools
 | 
				
			||||||
					if(!$user->is_anonymous()){
 | 
										if(!$user->is_anonymous()){
 | 
				
			||||||
						$this->theme->new_pool_composer($page);
 | 
											$this->theme->new_pool_composer($page);
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
@ -89,8 +116,8 @@ class Pools extends Extension {
 | 
				
			|||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$page->set_redirect(make_link("pool/view/".$newPoolID));
 | 
											$page->set_redirect(make_link("pool/view/".$newPoolID));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					catch(PoolCreationException $pce) {
 | 
										catch(PoolCreationException $e) {
 | 
				
			||||||
						$this->theme->display_error($pce->getMessage());
 | 
											$this->theme->display_error($e->error);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -112,41 +139,26 @@ class Pools extends Extension {
 | 
				
			|||||||
					}
 | 
										}
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "edit":
 | 
									case "edit": // Edit the pool (remove images)
 | 
				
			||||||
					$poolID = int_escape($event->get_arg(1));
 | 
										if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
					$pools = $this->get_pool($poolID);
 | 
											$this->theme->edit_pool($page, $this->get_pool($pool_id), $this->edit_posts($pool_id));
 | 
				
			||||||
 | 
					 | 
				
			||||||
					foreach($pools as $pool) {
 | 
					 | 
				
			||||||
						// if the pool is public and user is logged OR if the user is admin OR the user is the owner
 | 
					 | 
				
			||||||
						if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
							$this->theme->edit_pool($page, $this->get_pool($poolID), $this->edit_posts($poolID));
 | 
					 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
							$page->set_redirect(make_link("pool/view/".$poolID));
 | 
											$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "order":
 | 
									case "order": // Order the pool (view and change the order of images within the pool)
 | 
				
			||||||
					if($_SERVER["REQUEST_METHOD"] == "GET") {
 | 
										if (isset($_POST["order_view"])) {
 | 
				
			||||||
						$poolID = int_escape($event->get_arg(1));
 | 
											if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
						$pools = $this->get_pool($poolID);
 | 
												$this->theme->edit_order($page, $this->get_pool($pool_id), $this->edit_order($pool_id));
 | 
				
			||||||
 | 
					 | 
				
			||||||
						foreach($pools as $pool) {
 | 
					 | 
				
			||||||
							//if the pool is public and user is logged OR if the user is admin
 | 
					 | 
				
			||||||
							if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
								$this->theme->edit_order($page, $this->get_pool($poolID), $this->edit_order($poolID));
 | 
					 | 
				
			||||||
						} else {
 | 
											} else {
 | 
				
			||||||
							$page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
								$page->set_redirect(make_link("pool/view/".$poolID));
 | 
												$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
				
			||||||
							}
 | 
					 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else {
 | 
										else {
 | 
				
			||||||
						$pool_id = int_escape($_POST["pool_id"]);
 | 
											if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
						$pool = $this->get_single_pool($pool_id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
						if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
							$this->order_posts();
 | 
												$this->order_posts();
 | 
				
			||||||
							$page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
							$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
												$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
				
			||||||
@ -157,21 +169,15 @@ class Pools extends Extension {
 | 
				
			|||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "import":
 | 
									case "import":
 | 
				
			||||||
					$pool_id = int_escape($_POST["pool_id"]);
 | 
										if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
					$pool = $this->get_single_pool($pool_id);
 | 
											$this->import_posts($pool_id);
 | 
				
			||||||
 | 
					 | 
				
			||||||
					if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
						$this->import_posts();
 | 
					 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						$this->theme->display_error("Permssion denied.");
 | 
											$this->theme->display_error("Permssion denied.");
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "add_posts":
 | 
									case "add_posts":
 | 
				
			||||||
					$pool_id = int_escape($_POST["pool_id"]);
 | 
										if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
					$pool = $this->get_single_pool($pool_id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
						$this->add_posts();
 | 
											$this->add_posts();
 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
											$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
				
			||||||
@ -181,10 +187,7 @@ class Pools extends Extension {
 | 
				
			|||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "remove_posts":
 | 
									case "remove_posts":
 | 
				
			||||||
					$pool_id = int_escape($_POST["pool_id"]);
 | 
										if ($this->have_permission($user, $pool)) {
 | 
				
			||||||
					$pool = $this->get_single_pool($pool_id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) {
 | 
					 | 
				
			||||||
						$this->remove_posts();
 | 
											$this->remove_posts();
 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
											$page->set_redirect(make_link("pool/view/".$pool_id));
 | 
				
			||||||
@ -195,10 +198,8 @@ class Pools extends Extension {
 | 
				
			|||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				case "nuke":
 | 
									case "nuke":
 | 
				
			||||||
					$pool_id = int_escape($_POST['pool_id']);
 | 
										// Completely remove the given pool.
 | 
				
			||||||
					$pool = $this->get_single_pool($pool_id);
 | 
										//  -> Only admins and owners may do this	
 | 
				
			||||||
 | 
					 | 
				
			||||||
					// only admins and owners may do this
 | 
					 | 
				
			||||||
					if($user->is_admin() || $user->id == $pool['user_id']) {	
 | 
										if($user->is_admin() || $user->id == $pool['user_id']) {	
 | 
				
			||||||
						$this->nuke_pool($pool_id);
 | 
											$this->nuke_pool($pool_id);
 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
@ -221,8 +222,10 @@ class Pools extends Extension {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * HERE WE GET THE POOLS WHERE THE IMAGE APPEARS WHEN THE IMAGE IS DISPLAYED
 | 
						 * When displaying an image, optionally list all the pools that the
 | 
				
			||||||
 | 
						 * image is currently a member of on a side panel, as well as a link
 | 
				
			||||||
 | 
						 * to the Next image in the pool.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function onDisplayingImage(DisplayingImageEvent $event) {
 | 
						public function onDisplayingImage(DisplayingImageEvent $event) {
 | 
				
			||||||
		global $config, $database, $page;
 | 
							global $config, $database, $page;
 | 
				
			||||||
@ -231,11 +234,21 @@ class Pools extends Extension {
 | 
				
			|||||||
			$imageID = $event->image->id;
 | 
								$imageID = $event->image->id;
 | 
				
			||||||
			$poolsIDs = $this->get_pool_id($imageID);
 | 
								$poolsIDs = $this->get_pool_id($imageID);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
 | 
								$show_next = $config->get_bool("poolsShowNextLink", false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$linksPools = array();
 | 
								$linksPools = array();
 | 
				
			||||||
			foreach($poolsIDs as $poolID) {
 | 
								foreach($poolsIDs as $poolID) {
 | 
				
			||||||
				$pools = $this->get_pool($poolID['pool_id']);
 | 
									$pools = $this->get_pool($poolID['pool_id']);
 | 
				
			||||||
				foreach ($pools as $pool){
 | 
									foreach ($pools as $pool){
 | 
				
			||||||
					$linksPools[] = "<a href='".make_link("pool/view/".$pool['id'])."'>".html_escape($pool['title'])."</a>";
 | 
										$linksPools[] = "<a href='".make_link("pool/view/".$pool['id'])."'>".html_escape($pool['title'])."</a>";
 | 
				
			||||||
 | 
										
 | 
				
			||||||
 | 
										// Optionally show a link the Next image in the Pool.
 | 
				
			||||||
 | 
										if ($show_next) {
 | 
				
			||||||
 | 
											$next_image_in_pool = $this->get_next_post($pool, $imageID);
 | 
				
			||||||
 | 
											if (!empty($next_image_in_pool)) {
 | 
				
			||||||
 | 
												$linksPools[] = '<a href="'.make_link('post/view/'.$next_image_in_pool).'" class="pools_next_img">Next</a>';
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			$this->theme->pool_info($linksPools);
 | 
								$this->theme->pool_info($linksPools);
 | 
				
			||||||
@ -257,6 +270,24 @@ class Pools extends Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* ------------------------------------------------- */
 | 
				
			||||||
 | 
						/* --------------  Private Functions  -------------- */
 | 
				
			||||||
 | 
						/* ------------------------------------------------- */
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Check if the given user has permission to edit/change the pool.
 | 
				
			||||||
 | 
						 * TODO: Should the user variable be global?
 | 
				
			||||||
 | 
						 * @retval bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function have_permission($user, $pool) {
 | 
				
			||||||
 | 
							// If the pool is public and user is logged OR if the user is admin OR if the pool is owned by the user.
 | 
				
			||||||
 | 
							if ( (($pool['public'] == "Y" || $pool['public'] == "y") && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id'])
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE GET THE LIST OF POOLS
 | 
						 * HERE WE GET THE LIST OF POOLS
 | 
				
			||||||
@ -309,27 +340,40 @@ class Pools extends Extension {
 | 
				
			|||||||
				VALUES (:uid, :public, :title, :desc, now())",
 | 
									VALUES (:uid, :public, :title, :desc, now())",
 | 
				
			||||||
				array("uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"]));
 | 
									array("uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"]));
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		$result = $database->get_row("SELECT LAST_INSERT_ID() AS poolID"); # FIXME database specific?
 | 
							//$result = $database->get_row("SELECT LAST_INSERT_ID() AS poolID"); # FIXME database specific?
 | 
				
			||||||
 | 
							$result['poolID'] = $database->get_last_insert_id();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log_info("pools", "Pool {$result["poolID"]} created by {$user->name}");
 | 
							log_info("pools", "Pool {$result["poolID"]} created by {$user->name}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return $result["poolID"];
 | 
							return $result["poolID"];
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private function get_pool($poolID) {
 | 
						/**
 | 
				
			||||||
 | 
						 * Retrieve information about pools given mulitiple pool IDs.
 | 
				
			||||||
 | 
						 * @param $poolID Array of integers
 | 
				
			||||||
 | 
						 * @retval 2D Array
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function get_pool(/*int*/ $poolID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
 | 
							return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private function get_single_pool($poolID) {
 | 
						/**
 | 
				
			||||||
 | 
						 * Retrieve information about a pool given a pool ID.
 | 
				
			||||||
 | 
						 * @param $poolID Integer
 | 
				
			||||||
 | 
						 * @retval 2D array (with only 1 element in the one dimension)
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function get_single_pool(/*int*/ $poolID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
 | 
							return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * HERE WE GET THE ID OF THE POOL FROM AN IMAGE
 | 
						 * Get all of the pool IDs that an image is in, given an image ID.
 | 
				
			||||||
 | 
						 * @param $imageID Integer
 | 
				
			||||||
 | 
						 * @retval 2D array
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function get_pool_id($imageID) {
 | 
						private function get_pool_id(/*int*/ $imageID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
 | 
							return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -338,11 +382,9 @@ class Pools extends Extension {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE GET THE IMAGES FROM THE TAG ON IMPORT
 | 
						 * HERE WE GET THE IMAGES FROM THE TAG ON IMPORT
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function import_posts() {
 | 
						private function import_posts(/*int*/ $pool_id) {
 | 
				
			||||||
		global $page, $config, $database;
 | 
							global $page, $config, $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool_id = int_escape($_POST["pool_id"]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000);
 | 
							$poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		$images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"]));
 | 
							$images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"]));
 | 
				
			||||||
@ -352,6 +394,8 @@ class Pools extends Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE ADD CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
 | 
						 * HERE WE ADD CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * TODO: Fix this so that the pool ID and images are passed as Arguments to the function.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function add_posts() {
 | 
						private function add_posts() {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
@ -385,6 +429,9 @@ class Pools extends Extension {
 | 
				
			|||||||
		return $poolID;	 
 | 
							return $poolID;	 
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * TODO: Fix this so that the pool ID and images are passed as Arguments to the function.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
	private function order_posts() {
 | 
						private function order_posts() {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -406,6 +453,8 @@ class Pools extends Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE REMOVE CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
 | 
						 * HERE WE REMOVE CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * TODO: Fix this so that the pool ID and images are passed as Arguments to the function.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function remove_posts() {
 | 
						private function remove_posts() {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
@ -424,21 +473,54 @@ class Pools extends Extension {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * HERE WE CHECK IF THE POST IS ALREADY ON POOL
 | 
						 * This function checks if a given image is contained within a given pool.
 | 
				
			||||||
	 * USED IN add_posts()
 | 
						 * Used by add_posts()
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @see add_posts()
 | 
				
			||||||
 | 
						 * @param $poolID integer
 | 
				
			||||||
 | 
						 * @param $imageID integer
 | 
				
			||||||
 | 
						 * @retval bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function check_post($poolID, $imageID) {
 | 
						private function check_post(/*int*/ $poolID, /*int*/ $imageID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		$result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", array("pid"=>$poolID, "iid"=>$imageID));
 | 
							$result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", array("pid"=>$poolID, "iid"=>$imageID));
 | 
				
			||||||
		return ($result != 0);
 | 
							return ($result != 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
	/*
 | 
						 * Gets the next successive image from a pool, given a pool ID and an image ID.
 | 
				
			||||||
	 * HERE WE GET ALL IMAGES FOR THE POOL
 | 
						 *
 | 
				
			||||||
 | 
						 * @param $pool Array for the given pool
 | 
				
			||||||
 | 
						 * @param $imageID Integer
 | 
				
			||||||
 | 
						 * @retval Integer which is the next Image ID or NULL if none.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function get_posts($event, $poolID) {
 | 
						private function get_next_post(/*array*/ $pool, /*int*/ $imageID) {
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (empty($pool) || empty($imageID))
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$result = $database->get_one("
 | 
				
			||||||
 | 
										SELECT image_id
 | 
				
			||||||
 | 
										FROM pool_images
 | 
				
			||||||
 | 
										WHERE pool_id=:pid
 | 
				
			||||||
 | 
										AND image_order > (SELECT image_order FROM pool_images WHERE pool_id=:pid AND image_id =:iid LIMIT 1 )
 | 
				
			||||||
 | 
										ORDER BY image_order ASC LIMIT 1",
 | 
				
			||||||
 | 
										array("pid"=>$pool['id'], "iid"=>$imageID) );
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (empty($result)) {
 | 
				
			||||||
 | 
								// assume that we are at the end of the pool
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return $result;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Retrieve all the images in a pool, given a pool ID.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function get_posts($event, /*int*/ $poolID) {
 | 
				
			||||||
		global $config, $user, $database;
 | 
							global $config, $user, $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pageNumber = int_escape($event->get_arg(2));
 | 
							$pageNumber = int_escape($event->get_arg(2));
 | 
				
			||||||
@ -450,6 +532,7 @@ class Pools extends Extension {
 | 
				
			|||||||
			$pageNumber--;
 | 
								$pageNumber--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$poolID = int_escape($poolID);
 | 
							$poolID = int_escape($poolID);
 | 
				
			||||||
 | 
							$pool = $this->get_pool($poolID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$imagesPerPage = $config->get_int("poolsImagesPerPage");
 | 
							$imagesPerPage = $config->get_int("poolsImagesPerPage");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -457,6 +540,8 @@ class Pools extends Extension {
 | 
				
			|||||||
		// WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER
 | 
							// WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER
 | 
				
			||||||
		if(class_exists("Ratings")) {
 | 
							if(class_exists("Ratings")) {
 | 
				
			||||||
			$rating = Ratings::privs_to_sql(Ratings::get_user_privs($user));
 | 
								$rating = Ratings::privs_to_sql(Ratings::get_user_privs($user));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (isset($rating) && !empty($rating)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$result = $database->get_all("
 | 
								$result = $database->get_all("
 | 
				
			||||||
					SELECT p.image_id
 | 
										SELECT p.image_id
 | 
				
			||||||
@ -473,8 +558,8 @@ class Pools extends Extension {
 | 
				
			|||||||
					INNER JOIN images AS i ON i.id = p.image_id
 | 
										INNER JOIN images AS i ON i.id = p.image_id
 | 
				
			||||||
					WHERE pool_id=:pid AND i.rating IN ($rating)",
 | 
										WHERE pool_id=:pid AND i.rating IN ($rating)",
 | 
				
			||||||
					array("pid"=>$poolID)) / $imagesPerPage);
 | 
										array("pid"=>$poolID)) / $imagesPerPage);
 | 
				
			||||||
		}
 | 
							} else {
 | 
				
			||||||
		else {
 | 
							
 | 
				
			||||||
			$result = $database->get_all("
 | 
								$result = $database->get_all("
 | 
				
			||||||
					SELECT image_id
 | 
										SELECT image_id
 | 
				
			||||||
					FROM pool_images
 | 
										FROM pool_images
 | 
				
			||||||
@ -482,6 +567,7 @@ class Pools extends Extension {
 | 
				
			|||||||
					ORDER BY image_order ASC
 | 
										ORDER BY image_order ASC
 | 
				
			||||||
					LIMIT :l OFFSET :o",
 | 
										LIMIT :l OFFSET :o",
 | 
				
			||||||
					array("pid"=>$poolID, "l"=>$imagesPerPage, "o"=>$pageNumber * $imagesPerPage));
 | 
										array("pid"=>$poolID, "l"=>$imagesPerPage, "o"=>$pageNumber * $imagesPerPage));
 | 
				
			||||||
 | 
										
 | 
				
			||||||
			$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", array("pid"=>$poolID)) / $imagesPerPage);
 | 
								$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", array("pid"=>$poolID)) / $imagesPerPage);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -490,24 +576,24 @@ class Pools extends Extension {
 | 
				
			|||||||
			$images[] = Image::by_id($singleResult["image_id"]);
 | 
								$images[] = Image::by_id($singleResult["image_id"]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool = $this->get_pool($poolID);
 | 
					 | 
				
			||||||
		$this->theme->view_pool($pool, $images, $pageNumber + 1, $totalPages);
 | 
							$this->theme->view_pool($pool, $images, $pageNumber + 1, $totalPages);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * WE GET THE ORDER OF THE IMAGES
 | 
						 * This function gets the current order of images from a given pool.
 | 
				
			||||||
 | 
						 * @param $poolID integer
 | 
				
			||||||
 | 
						 * @retval Array of image objects.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function edit_posts($poolID) {
 | 
						private function edit_posts(/*int*/ $poolID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));
 | 
							$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));
 | 
				
			||||||
 | 
					 | 
				
			||||||
		$images = array();
 | 
							$images = array();
 | 
				
			||||||
		while(!$result->EOF) {
 | 
							
 | 
				
			||||||
			$image = Image::by_id($result->fields["image_id"]);
 | 
							while($row = $result->fetch()) {
 | 
				
			||||||
 | 
								$image = Image::by_id($row["image_id"]);
 | 
				
			||||||
			$images[] = array($image);
 | 
								$images[] = array($image);
 | 
				
			||||||
			$result->MoveNext();
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		return $images;
 | 
							return $images;
 | 
				
			||||||
@ -517,29 +603,23 @@ class Pools extends Extension {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * WE GET THE ORDER OF THE IMAGES BUT HERE WE SEND KEYS ADDED IN ARRAY TO GET THE ORDER IN THE INPUT VALUE
 | 
						 * WE GET THE ORDER OF THE IMAGES BUT HERE WE SEND KEYS ADDED IN ARRAY TO GET THE ORDER IN THE INPUT VALUE
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function edit_order($poolID) {
 | 
						private function edit_order(/*int*/ $poolID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));									
 | 
							$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID));									
 | 
				
			||||||
		$images = array();
 | 
							$images = array();
 | 
				
			||||||
		while(!$result->EOF) {
 | 
							
 | 
				
			||||||
 | 
							while($row = $result->fetch())
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			$image = $database->get_row("
 | 
								$image = $database->get_row("
 | 
				
			||||||
					SELECT * FROM images AS i
 | 
										SELECT * FROM images AS i
 | 
				
			||||||
					INNER JOIN pool_images AS p ON i.id = p.image_id
 | 
										INNER JOIN pool_images AS p ON i.id = p.image_id
 | 
				
			||||||
					WHERE pool_id=:pid AND i.id=:iid",
 | 
										WHERE pool_id=:pid AND i.id=:iid",
 | 
				
			||||||
					array("pid"=>$poolID, "iid"=>$result->fields["image_id"]));
 | 
										array("pid"=>$poolID, "iid"=>$row['image_id']));
 | 
				
			||||||
			$image = ($image ? new Image($image) : null);
 | 
								$image = ($image ? new Image($image) : null);
 | 
				
			||||||
			$images[] = array($image);
 | 
								$images[] = array($image);
 | 
				
			||||||
			$result->MoveNext();
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//		Original code
 | 
							
 | 
				
			||||||
		//		
 | 
					 | 
				
			||||||
		//		$images = array();
 | 
					 | 
				
			||||||
		//		while(!$result->EOF) {
 | 
					 | 
				
			||||||
		//			$image = Image::by_id($result->fields["image_id"]);
 | 
					 | 
				
			||||||
		//			$images[] = array($image);
 | 
					 | 
				
			||||||
		//			$result->MoveNext();
 | 
					 | 
				
			||||||
		//		}
 | 
					 | 
				
			||||||
		return $images;
 | 
							return $images;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -547,7 +627,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE NUKE ENTIRE POOL. WE REMOVE POOLS AND POSTS FROM REMOVED POOL AND HISTORIES ENTRIES FROM REMOVED POOL
 | 
						 * HERE WE NUKE ENTIRE POOL. WE REMOVE POOLS AND POSTS FROM REMOVED POOL AND HISTORIES ENTRIES FROM REMOVED POOL
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function nuke_pool($poolID) {
 | 
						private function nuke_pool(/*int*/ $poolID) {
 | 
				
			||||||
		global $user, $database;
 | 
							global $user, $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID));
 | 
							$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID));
 | 
				
			||||||
@ -567,7 +647,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	 * HERE WE ADD A HISTORY ENTRY
 | 
						 * HERE WE ADD A HISTORY ENTRY
 | 
				
			||||||
	 * FOR $action 1 (one) MEANS ADDED, 0 (zero) MEANS REMOVED
 | 
						 * FOR $action 1 (one) MEANS ADDED, 0 (zero) MEANS REMOVED
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function add_history($poolID, $action, $images, $count) {
 | 
						private function add_history(/*int*/ $poolID, $action, $images, $count) {
 | 
				
			||||||
		global $user, $database;
 | 
							global $user, $database;
 | 
				
			||||||
		$database->execute("
 | 
							$database->execute("
 | 
				
			||||||
				INSERT INTO pool_history (pool_id, user_id, action, images, count, date)
 | 
									INSERT INTO pool_history (pool_id, user_id, action, images, count, date)
 | 
				
			||||||
@ -579,7 +659,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE GET THE HISTORY LIST
 | 
						 * HERE WE GET THE HISTORY LIST
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function get_history($pageNumber) {
 | 
						private function get_history(/*int*/ $pageNumber) {
 | 
				
			||||||
		global $config, $database;
 | 
							global $config, $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(is_null($pageNumber) || !is_numeric($pageNumber))
 | 
							if(is_null($pageNumber) || !is_numeric($pageNumber))
 | 
				
			||||||
@ -614,7 +694,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL
 | 
						 * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function revert_history($historyID) {
 | 
						private function revert_history(/*int*/ $historyID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		$status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", array("hid"=>$historyID));
 | 
							$status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", array("hid"=>$historyID));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -656,7 +736,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	 * HERE WE ADD A SIMPLE POST FROM POOL
 | 
						 * HERE WE ADD A SIMPLE POST FROM POOL
 | 
				
			||||||
	 * USED WITH FOREACH IN revert_history()
 | 
						 * USED WITH FOREACH IN revert_history()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function add_post($poolID, $imageID) {
 | 
						private function add_post(/*int*/ $poolID, /*int*/ $imageID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!$this->check_post($poolID, $imageID)) {
 | 
							if(!$this->check_post($poolID, $imageID)) {
 | 
				
			||||||
@ -675,7 +755,7 @@ class Pools extends Extension {
 | 
				
			|||||||
	 * HERE WE REMOVE A SIMPLE POST FROM POOL
 | 
						 * HERE WE REMOVE A SIMPLE POST FROM POOL
 | 
				
			||||||
	 * USED WITH FOREACH IN revert_history()
 | 
						 * USED WITH FOREACH IN revert_history()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function delete_post($poolID, $imageID) {
 | 
						private function delete_post(/*int*/ $poolID, /*int*/ $imageID) {
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID));
 | 
							$database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID));
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PoolsTheme extends Themelet {
 | 
					class PoolsTheme extends Themelet {
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * HERE WE ADD THE POOL INFO ON IMAGE
 | 
						 * Adds a block to the panel with information on the pool(s) the image is in.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function pool_info($linksPools) {
 | 
						public function pool_info($linksPools) {
 | 
				
			||||||
		global $page;
 | 
							global $page;
 | 
				
			||||||
@ -10,14 +11,13 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_adder_html(Image $image, $pools) {
 | 
						public function get_adder_html(Image $image, /*array*/ $pools) {
 | 
				
			||||||
		$editor = "";
 | 
							$editor = "";
 | 
				
			||||||
		$h = "";
 | 
							$h = "";
 | 
				
			||||||
		foreach($pools as $pool) {
 | 
							foreach($pools as $pool) {
 | 
				
			||||||
			$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
 | 
								$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$editor = "
 | 
							$editor = "\n".make_form(make_link("pool/add_post"))."
 | 
				
			||||||
			".make_form(make_link("pool/add_post"))."
 | 
					 | 
				
			||||||
				<select name='pool_id'>
 | 
									<select name='pool_id'>
 | 
				
			||||||
					$h
 | 
										$h
 | 
				
			||||||
				</select>
 | 
									</select>
 | 
				
			||||||
@ -32,17 +32,20 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE SHOWS THE LIST OF POOLS
 | 
						 * HERE WE SHOWS THE LIST OF POOLS
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function list_pools(Page $page, $pools, $pageNumber, $totalPages) {
 | 
						public function list_pools(Page $page, /*array*/ $pools, /*int*/ $pageNumber, /*int*/ $totalPages) {
 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
		$html = '<table id="poolsList" class="zebra">'.
 | 
							$html = '
 | 
				
			||||||
			"<thead><tr>".
 | 
									<table id="poolsList" class="zebra">
 | 
				
			||||||
			"<th>Name</th>".
 | 
										<thead><tr>
 | 
				
			||||||
			"<th>Creator</th>".
 | 
											<th>Name</th>
 | 
				
			||||||
			"<th>Posts</th>".
 | 
											<th>Creator</th>
 | 
				
			||||||
			"<th>Public</th>".
 | 
											<th>Posts</th>
 | 
				
			||||||
			"</tr></thead>";
 | 
											<th>Public</th>
 | 
				
			||||||
 | 
										</tr></thead><tbody>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$n = 0;
 | 
							$n = 0;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Build up the list of pools.
 | 
				
			||||||
		foreach($pools as $pool) {
 | 
							foreach($pools as $pool) {
 | 
				
			||||||
			$oe = ($n++ % 2 == 0) ? "even" : "odd";
 | 
								$oe = ($n++ % 2 == 0) ? "even" : "odd";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,12 +63,11 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$html .= "</tbody></table>";
 | 
							$html .= "</tbody></table>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$nav_html = '
 | 
				
			||||||
		$nav_html = "
 | 
								<a href="'.make_link().'">Index</a>
 | 
				
			||||||
			<a href=".make_link().">Index</a>
 | 
								<br><a href="'.make_link("pool/new").'">Create Pool</a>
 | 
				
			||||||
			<br><a href=".make_link("pool/new").">Create Pool</a>
 | 
								<br><a href="'.make_link("pool/updated").'">Pool Changes</a>
 | 
				
			||||||
			<br><a href=".make_link("pool/updated").">Pool Changes</a>
 | 
							';
 | 
				
			||||||
		";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$blockTitle = "Pools";
 | 
							$blockTitle = "Pools";
 | 
				
			||||||
		$page->set_title(html_escape($blockTitle));
 | 
							$page->set_title(html_escape($blockTitle));
 | 
				
			||||||
@ -99,7 +101,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private function display_top($pools, $heading, $check_all=false) {
 | 
						private function display_top(/*array*/ $pools, /*string*/ $heading, $check_all=false) {
 | 
				
			||||||
		global $page, $user;
 | 
							global $page, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page->set_title($heading);
 | 
							$page->set_title($heading);
 | 
				
			||||||
@ -114,11 +116,12 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
			$page->add_block(new Block(html_escape($pool['title']), html_escape($pool['description']), "main", 10));
 | 
								$page->add_block(new Block(html_escape($pool['title']), html_escape($pool['description']), "main", 10));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			$pool_info = "<table id='poolsList' class='zebra'>".
 | 
								$pool_info = '
 | 
				
			||||||
				"<thead><tr>".
 | 
											<table id="poolsList" class="zebra">
 | 
				
			||||||
				"<th class='left'>Title</th>".
 | 
												<thead><tr>
 | 
				
			||||||
				"<th class='left'>Description</th>".
 | 
													<th class="left">Title</th>
 | 
				
			||||||
				"</tr></thead>";
 | 
													<th class="left">Description</th>
 | 
				
			||||||
 | 
												</tr></thead><tbody>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$n = 0;
 | 
								$n = 0;
 | 
				
			||||||
			foreach($pools as $pool) {
 | 
								foreach($pools as $pool) {
 | 
				
			||||||
@ -146,7 +149,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION
 | 
						 * HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function view_pool($pools, $images, $pageNumber, $totalPages) {
 | 
						public function view_pool(/*array*/ $pools, /*array*/ $images, /*int*/ $pageNumber, /*int*/ $totalPages) {
 | 
				
			||||||
		global $user, $page;
 | 
							global $user, $page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->display_top($pools, "Pool: ".html_escape($pools[0]['title']));
 | 
							$this->display_top($pools, "Pool: ".html_escape($pools[0]['title']));
 | 
				
			||||||
@ -154,9 +157,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
		$pool_images = '';
 | 
							$pool_images = '';
 | 
				
			||||||
		foreach($images as $image) {
 | 
							foreach($images as $image) {
 | 
				
			||||||
			$thumb_html = $this->build_thumb_html($image);
 | 
								$thumb_html = $this->build_thumb_html($image);
 | 
				
			||||||
			$pool_images .= '<span class="thumb">'.
 | 
								$pool_images .= "\n".$thumb_html."\n";
 | 
				
			||||||
				'<a href="$image_link">'.$thumb_html.'</a>'.
 | 
					 | 
				
			||||||
				'</span>';
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));		
 | 
							$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));		
 | 
				
			||||||
@ -167,35 +168,40 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE DISPLAY THE POOL OPTIONS ON SIDEBAR BUT WE HIDE REMOVE OPTION IF THE USER IS NOT THE OWNER OR ADMIN
 | 
						 * HERE WE DISPLAY THE POOL OPTIONS ON SIDEBAR BUT WE HIDE REMOVE OPTION IF THE USER IS NOT THE OWNER OR ADMIN
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function sidebar_options(Page $page, $pool, $check_all) {
 | 
						public function sidebar_options(Page $page, $pool, /*bool*/ $check_all) {
 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$editor = "
 | 
							$editor = "\n".make_form( make_link('pool/import') ).'
 | 
				
			||||||
			".make_form(make_link("pool/import"))."
 | 
									<input type="text" name="pool_tag" id="edit_pool_tag" value="Please enter a tag" onclick="this.value=\'\';"/>
 | 
				
			||||||
			<input type='text' name='pool_tag' id='edit' value='Please enter a tag' onclick='this.value=\"\";'/>
 | 
									<input type="submit" name="edit" id="edit_pool_import_btn" value="Import"/>
 | 
				
			||||||
			<input type='submit' name='edit' id='edit' value='Import'/>
 | 
									<input type="hidden" name="pool_id" value="'.$pool['id'].'">
 | 
				
			||||||
			<input type='hidden' name='pool_id' value='".$pool['id']."'>
 | 
					 | 
				
			||||||
			</form>
 | 
								</form>
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			<form method='GET' action='".make_link("pool/edit/".$pool['id'])."'>
 | 
								'.make_form( make_link('pool/edit') ).'
 | 
				
			||||||
			<input type='submit' name='edit' id='edit' value='Edit Pool'/>
 | 
									<input type="submit" name="edit" id="edit_pool_btn" value="Edit Pool"/>
 | 
				
			||||||
 | 
									<input type="hidden" name="edit_pool" value="yes">
 | 
				
			||||||
 | 
									<input type="hidden" name="pool_id" value="'.$pool['id'].'">
 | 
				
			||||||
			</form>
 | 
								</form>
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			<form method='GET' action='".make_link("pool/order/".$pool['id'])."'>
 | 
								'.make_form( make_link('pool/order') ).'
 | 
				
			||||||
			<input type='submit' name='edit' id='edit' value='Order Pool'/>
 | 
									<input type="submit" name="edit" id="edit_pool_order_btn" value="Order Pool"/>
 | 
				
			||||||
 | 
									<input type="hidden" name="order_view" value="yes">
 | 
				
			||||||
 | 
									<input type="hidden" name="pool_id" value="'.$pool['id'].'">
 | 
				
			||||||
			</form>
 | 
								</form>
 | 
				
			||||||
			";
 | 
								';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($user->id == $pool['user_id'] || $user->is_admin()){
 | 
							if($user->id == $pool['user_id'] || $user->is_admin()){
 | 
				
			||||||
			$editor .= "
 | 
								$editor .= "
 | 
				
			||||||
				<script type='text/javascript'>
 | 
									<script language='javascript' type='text/javascript'>
 | 
				
			||||||
 | 
									<!--
 | 
				
			||||||
				function confirm_action() {
 | 
									function confirm_action() {
 | 
				
			||||||
					return confirm('Are you sure that you want to delete this pool?');
 | 
										return confirm('Are you sure that you want to delete this pool?');
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									//-->
 | 
				
			||||||
				</script>
 | 
									</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				".make_form(make_link("pool/nuke"))."
 | 
									".make_form(make_link("pool/nuke"))."
 | 
				
			||||||
				<input type='submit' name='delete' id='delete' value='Delete Pool' onclick='return confirm_action()' />
 | 
										<input type='submit' name='delete' id='delete_pool_btn' value='Delete Pool' onclick='return confirm_action()' />
 | 
				
			||||||
					<input type='hidden' name='pool_id' value='".$pool['id']."'>
 | 
										<input type='hidden' name='pool_id' value='".$pool['id']."'>
 | 
				
			||||||
				</form>
 | 
									</form>
 | 
				
			||||||
				";
 | 
									";
 | 
				
			||||||
@ -203,7 +209,8 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if($check_all) {
 | 
							if($check_all) {
 | 
				
			||||||
			$editor .= "
 | 
								$editor .= "
 | 
				
			||||||
				<script language='JavaScript' type='text/javascript'>
 | 
									<script language='javascript' type='text/javascript'>
 | 
				
			||||||
 | 
									<!--
 | 
				
			||||||
				function setAll(value) {
 | 
									function setAll(value) {
 | 
				
			||||||
					var a=new Array();
 | 
										var a=new Array();
 | 
				
			||||||
					a=document.getElementsByName('check[]');
 | 
										a=document.getElementsByName('check[]');
 | 
				
			||||||
@ -212,6 +219,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
						a[i].checked = value;
 | 
											a[i].checked = value;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									//-->
 | 
				
			||||||
				</script>
 | 
									</script>
 | 
				
			||||||
				<br><input type='button' name='CheckAll' value='Check All' onClick='setAll(true)'>
 | 
									<br><input type='button' name='CheckAll' value='Check All' onClick='setAll(true)'>
 | 
				
			||||||
				<input type='button' name='UnCheckAll' value='Uncheck All' onClick='setAll(false)'>
 | 
									<input type='button' name='UnCheckAll' value='Uncheck All' onClick='setAll(false)'>
 | 
				
			||||||
@ -224,9 +232,11 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE DISPLAY THE RESULT OF THE SEARCH ON IMPORT
 | 
						 * HERE WE DISPLAY THE RESULT OF THE SEARCH ON IMPORT
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function pool_result(Page $page, $images, $pool_id) {
 | 
						public function pool_result(Page $page, /*array*/ $images, /*int*/ $pool_id) {
 | 
				
			||||||
 | 
							// TODO: this could / should be done using jQuery
 | 
				
			||||||
		$pool_images = "
 | 
							$pool_images = "
 | 
				
			||||||
			<script language='JavaScript' type='text/javascript'>
 | 
								<script language='javascript' type='text/javascript'>
 | 
				
			||||||
 | 
								<!--
 | 
				
			||||||
			function setAll(value) {
 | 
								function setAll(value) {
 | 
				
			||||||
				var a=new Array();
 | 
									var a=new Array();
 | 
				
			||||||
				a=document.getElementsByName('check[]');
 | 
									a=document.getElementsByName('check[]');
 | 
				
			||||||
@ -239,6 +249,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
			function confirm_action() {
 | 
								function confirm_action() {
 | 
				
			||||||
				return confirm('Are you sure you want to add selected posts to this pool?');
 | 
									return confirm('Are you sure you want to add selected posts to this pool?');
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								//-->
 | 
				
			||||||
			</script>
 | 
								</script>
 | 
				
			||||||
		";
 | 
							";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -247,14 +258,12 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
		foreach($images as $image) {
 | 
							foreach($images as $image) {
 | 
				
			||||||
			$thumb_html = $this->build_thumb_html($image);
 | 
								$thumb_html = $this->build_thumb_html($image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$pool_images .= '<span class="thumb">'.
 | 
								$pool_images .= '<span class="thumb">'. $thumb_html .'<br>'.
 | 
				
			||||||
				'<a href="$image_link">'.$thumb_html.'</a>'.
 | 
					 | 
				
			||||||
				'<br>'.
 | 
					 | 
				
			||||||
				'<input name="check[]" type="checkbox" value="'.$image->id.'" />'.
 | 
									'<input name="check[]" type="checkbox" value="'.$image->id.'" />'.
 | 
				
			||||||
				'</span>';
 | 
									'</span>';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$pool_images .= "<br>".
 | 
							$pool_images .= "<br>".
 | 
				
			||||||
			"<input type='submit' name='edit' id='edit' value='Add Selected' onclick='return confirm_action()'/>".
 | 
								"<input type='submit' name='edit' id='edit_pool_add_btn' value='Add Selected' onclick='return confirm_action()'/>".
 | 
				
			||||||
			"<input type='hidden' name='pool_id' value='".$pool_id."'>".
 | 
								"<input type='hidden' name='pool_id' value='".$pool_id."'>".
 | 
				
			||||||
			"</form>";
 | 
								"</form>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -273,18 +282,17 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	 * HERE WE DISPLAY THE POOL ORDERER
 | 
						 * HERE WE DISPLAY THE POOL ORDERER
 | 
				
			||||||
	 * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH A TEXT INPUT TO SET A NUMBER AND CHANGE THE ORDER
 | 
						 * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH A TEXT INPUT TO SET A NUMBER AND CHANGE THE ORDER
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function edit_order(Page $page, $pools, $images) {
 | 
						public function edit_order(Page $page, /*array*/ $pools, /*array*/ $images) {
 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->display_top($pools, "Sorting Pool");
 | 
							$this->display_top($pools, "Sorting Pool");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool_images = "<form action='".make_link("pool/order")."' method='POST' name='checks'>";
 | 
							$pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>";
 | 
				
			||||||
		$n = 0;
 | 
							$n = 0;
 | 
				
			||||||
		foreach($images as $pair) {
 | 
							foreach($images as $pair) {
 | 
				
			||||||
			$image = $pair[0];
 | 
								$image = $pair[0];
 | 
				
			||||||
			$thumb_html = $this->build_thumb_html($image);
 | 
								$thumb_html = $this->build_thumb_html($image);
 | 
				
			||||||
			$pool_images .= '<span class="thumb">'.
 | 
								$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
 | 
				
			||||||
				'<a href="$image_link">'.$thumb_html.'</a>'.
 | 
					 | 
				
			||||||
				'<br><input name="imgs['.$n.'][]" type="text" style="max-width:50px;" value="'.$image->image_order.'" />'.
 | 
									'<br><input name="imgs['.$n.'][]" type="text" style="max-width:50px;" value="'.$image->image_order.'" />'.
 | 
				
			||||||
				'<input name="imgs['.$n.'][]" type="hidden" value="'.$image->id.'" />'.
 | 
									'<input name="imgs['.$n.'][]" type="hidden" value="'.$image->id.'" />'.
 | 
				
			||||||
				'</span>';
 | 
									'</span>';
 | 
				
			||||||
@ -292,7 +300,7 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool_images .= "<br>".
 | 
							$pool_images .= "<br>".
 | 
				
			||||||
			"<input type='submit' name='edit' id='edit' value='Order'/>".
 | 
								"<input type='submit' name='edit' id='edit_pool_order' value='Order'/>".
 | 
				
			||||||
			"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
 | 
								"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
 | 
				
			||||||
			"</form>";
 | 
								"</form>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -305,29 +313,25 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	 * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH
 | 
						 * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH
 | 
				
			||||||
	 * A CHECKBOX TO SELECT WHICH IMAGE WE WANT TO REMOVE
 | 
						 * A CHECKBOX TO SELECT WHICH IMAGE WE WANT TO REMOVE
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function edit_pool(Page $page, $pools, $images) {
 | 
						public function edit_pool(Page $page, /*array*/ $pools, /*array*/ $images) {
 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->display_top($pools, "Editing Pool", true);
 | 
							$this->display_top($pools, "Editing Pool", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool_images = "
 | 
							$pool_images = "\n<form action='".make_link("pool/remove_posts")."' method='POST' name='checks'>";
 | 
				
			||||||
		";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$pool_images = "<form action='".make_link("pool/remove_posts")."' method='POST' name='checks'>";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		foreach($images as $pair) {
 | 
							foreach($images as $pair) {
 | 
				
			||||||
			$image = $pair[0];
 | 
								$image = $pair[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$thumb_html = $this->build_thumb_html($image);
 | 
								$thumb_html = $this->build_thumb_html($image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$pool_images .= '<span class="thumb">'.
 | 
								$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
 | 
				
			||||||
				'<a href="$image_link">'.$thumb_html.'</a>'.
 | 
					 | 
				
			||||||
				'<br><input name="check[]" type="checkbox" value="'.$image->id.'" />'.
 | 
									'<br><input name="check[]" type="checkbox" value="'.$image->id.'" />'.
 | 
				
			||||||
				'</span>';
 | 
									'</span>';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$pool_images .= "<br>".
 | 
							$pool_images .= "<br>".
 | 
				
			||||||
			"<input type='submit' name='edit' id='edit' value='Remove Selected'/>".
 | 
								"<input type='submit' name='edit' id='edit_pool_remove_sel' value='Remove Selected'/>".
 | 
				
			||||||
			"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
 | 
								"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
 | 
				
			||||||
			"</form>";
 | 
								"</form>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -338,17 +342,18 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * HERE WE DISPLAY THE HISTORY LIST
 | 
						 * HERE WE DISPLAY THE HISTORY LIST
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function show_history($histories, $pageNumber, $totalPages) {
 | 
						public function show_history($histories, /*int*/ $pageNumber, /*int*/ $totalPages) {
 | 
				
			||||||
		global $page;
 | 
							global $page;
 | 
				
			||||||
		$html = "<table id='poolsList' class='zebra'>".
 | 
							$html = '
 | 
				
			||||||
			"<thead><tr>".
 | 
								<table id="poolsList" class="zebra">
 | 
				
			||||||
			"<th>Pool</th>".
 | 
									<thead><tr>
 | 
				
			||||||
			"<th>Post Count</th>".
 | 
										<th>Pool</th>
 | 
				
			||||||
			"<th>Changes</th>".
 | 
										<th>Post Count</th>
 | 
				
			||||||
			"<th>Updater</th>".
 | 
										<th>Changes</th>
 | 
				
			||||||
			"<th>Date</th>".
 | 
										<th>Updater</th>
 | 
				
			||||||
			"<th>Action</th>".
 | 
										<th>Date</th>
 | 
				
			||||||
			"</tr></thead>";
 | 
										<th>Action</th>
 | 
				
			||||||
 | 
									</tr></thead><tbody>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$n = 0;
 | 
							$n = 0;
 | 
				
			||||||
		foreach($histories as $history) {
 | 
							foreach($histories as $history) {
 | 
				
			||||||
@ -392,10 +397,10 @@ class PoolsTheme extends Themelet {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/**
 | 
				
			||||||
	 * HERE WE DISPLAY THE ERROR
 | 
						 * Display an error message to the user.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function display_error($errMessage) {
 | 
						public function display_error(/*string*/ $errMessage) {
 | 
				
			||||||
		global $page;
 | 
							global $page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page->set_title("Error");
 | 
							$page->set_title("Error");
 | 
				
			||||||
 | 
				
			|||||||
@ -24,6 +24,7 @@ class RandomImage extends Extension {
 | 
				
			|||||||
	public function onPageRequest(PageRequestEvent $event) {
 | 
						public function onPageRequest(PageRequestEvent $event) {
 | 
				
			||||||
		global $config, $database, $page, $user;
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if($event->page_matches("random_image")) {
 | 
							if($event->page_matches("random_image")) {
 | 
				
			||||||
 | 
								$action = '';
 | 
				
			||||||
			if($event->count_args() == 1) {
 | 
								if($event->count_args() == 1) {
 | 
				
			||||||
				$action = $event->get_arg(0);
 | 
									$action = $event->get_arg(0);
 | 
				
			||||||
				$search_terms = array();
 | 
									$search_terms = array();
 | 
				
			||||||
@ -37,14 +38,14 @@ class RandomImage extends Extension {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			$image = Image::by_random($search_terms);
 | 
								$image = Image::by_random($search_terms);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if($action == "download") {
 | 
								if($action === "download") {
 | 
				
			||||||
				if(!is_null($image)) {
 | 
									if(!is_null($image)) {
 | 
				
			||||||
					$page->set_mode("data");
 | 
										$page->set_mode("data");
 | 
				
			||||||
					$page->set_type("image/jpeg");
 | 
										$page->set_type("image/jpeg");
 | 
				
			||||||
					$page->set_data(file_get_contents($image->get_image_filename()));
 | 
										$page->set_data(file_get_contents($image->get_image_filename()));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if($action == "view") {
 | 
								if($action === "view") {
 | 
				
			||||||
				if(!is_null($image)) {
 | 
									if(!is_null($image)) {
 | 
				
			||||||
					send_event(new DisplayingImageEvent($image, $page));
 | 
										send_event(new DisplayingImageEvent($image, $page));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@ class RandomImageTheme extends Themelet {
 | 
				
			|||||||
			<center><div>
 | 
								<center><div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
 | 
									<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
 | 
				
			||||||
					<img id='thumb_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
 | 
										<img id='thumb_rand_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
 | 
				
			||||||
				</a>
 | 
									</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			</div></center>
 | 
								</div></center>
 | 
				
			||||||
 | 
				
			|||||||
@ -19,13 +19,109 @@ class RatingSetEvent extends Event {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Ratings extends Extension {
 | 
					class Ratings extends Extension {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function get_priority() {return 50;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onInitExt($event) {
 | 
				
			||||||
 | 
							global $config;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($config->get_int("ext_ratings2_version") < 2) {
 | 
				
			||||||
 | 
								$this->install();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$config->set_default_string("ext_rating_anon_privs", 'squ');
 | 
				
			||||||
 | 
							$config->set_default_string("ext_rating_user_privs", 'sqeu');
 | 
				
			||||||
 | 
							$config->set_default_string("ext_rating_admin_privs", 'sqeu');
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function onSetupBuilding(SetupBuildingEvent $event) {
 | 
				
			||||||
 | 
							$privs = array();
 | 
				
			||||||
 | 
							$privs['Safe Only'] = 's';
 | 
				
			||||||
 | 
							$privs['Safe and Unknown'] = 'su';
 | 
				
			||||||
 | 
							$privs['Safe and Questionable'] = 'sq';
 | 
				
			||||||
 | 
							$privs['Safe, Questionable, Unknown'] = 'squ';
 | 
				
			||||||
 | 
							$privs['All'] = 'sqeu';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$sb = new SetupBlock("Image Ratings");
 | 
				
			||||||
 | 
							$sb->add_choice_option("ext_rating_anon_privs", $privs, "Anonymous: ");
 | 
				
			||||||
 | 
							$sb->add_choice_option("ext_rating_user_privs", $privs, "<br>Users: ");
 | 
				
			||||||
 | 
							$sb->add_choice_option("ext_rating_admin_privs", $privs, "<br>Admins: ");
 | 
				
			||||||
 | 
							$event->panel->add_block($sb);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public function onAdminBuilding(AdminBuildingEvent $event) {
 | 
						public function onAdminBuilding(AdminBuildingEvent $event) {
 | 
				
			||||||
		$this->theme->display_bulk_rater();
 | 
							$this->theme->display_bulk_rater();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						public function onDisplayingImage(DisplayingImageEvent $event) {
 | 
				
			||||||
 | 
							global $user, $database, $page;
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * Deny images upon insufficient permissions.
 | 
				
			||||||
 | 
							 **/
 | 
				
			||||||
 | 
							$user_view_level = Ratings::get_user_privs($user);
 | 
				
			||||||
 | 
							$user_view_level = preg_split('//', $user_view_level, -1);
 | 
				
			||||||
 | 
							if(!in_array($event->image->rating, $user_view_level)) {
 | 
				
			||||||
 | 
								$page->set_mode("redirect");
 | 
				
			||||||
 | 
								$page->set_redirect(make_link("post/list"));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function onRatingSet(RatingSetEvent $event) {
 | 
				
			||||||
 | 
							if(empty($event->image->rating)){
 | 
				
			||||||
 | 
								$old_rating = "";
 | 
				
			||||||
 | 
							}else{
 | 
				
			||||||
 | 
								$old_rating = $event->image->rating;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$this->set_rating($event->image->id, $event->rating, $old_rating);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
 | 
				
			||||||
 | 
							if($this->can_rate()) {
 | 
				
			||||||
 | 
								$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public function onImageInfoSet(ImageInfoSetEvent $event) {
 | 
				
			||||||
 | 
							global $user;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if($this->can_rate() && isset($_POST["rating"])) {
 | 
				
			||||||
 | 
								send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onParseLinkTemplate(ParseLinkTemplateEvent $event) {
 | 
				
			||||||
 | 
							$event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onSearchTermParse(SearchTermParseEvent $event) {
 | 
				
			||||||
 | 
							global $user;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							$matches = array();
 | 
				
			||||||
 | 
							if(is_null($event->term) && $this->no_rating_query($event->context)) {
 | 
				
			||||||
 | 
								$set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
 | 
				
			||||||
 | 
								$event->add_querylet(new Querylet("rating IN ($set)"));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if(preg_match("/^rating=([sqeu]+)$/", $event->term, $matches)) {
 | 
				
			||||||
 | 
								$sqes = $matches[1];
 | 
				
			||||||
 | 
								$arr = array();
 | 
				
			||||||
 | 
								$length = strlen($sqes);
 | 
				
			||||||
 | 
								for($i=0; $i<$length; $i++) {
 | 
				
			||||||
 | 
									$arr[] = "'" . $sqes[$i] . "'";
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								$set = join(', ', $arr);
 | 
				
			||||||
 | 
								$event->add_querylet(new Querylet("rating IN ($set)"));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if(preg_match("/^rating=(safe|questionable|explicit|unknown)$/", strtolower($event->term), $matches)) {
 | 
				
			||||||
 | 
								$text = $matches[1];
 | 
				
			||||||
 | 
								$char = $text[0];
 | 
				
			||||||
 | 
								$event->add_querylet(new Querylet("rating = :img_rating", array("img_rating"=>$char)));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onPageRequest(PageRequestEvent $event) {
 | 
						public function onPageRequest(PageRequestEvent $event) {
 | 
				
			||||||
		if($event->page_matches("admin/bulk_rate")) {
 | 
					 | 
				
			||||||
		global $database, $user, $page;
 | 
							global $database, $user, $page;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if ($event->page_matches("admin/bulk_rate")) {
 | 
				
			||||||
			if(!$user->is_admin()) {
 | 
								if(!$user->is_admin()) {
 | 
				
			||||||
				throw PermissionDeniedException();
 | 
									throw PermissionDeniedException();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -53,96 +149,11 @@ class Ratings extends Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public function onInitExt(InitExtEvent $event) {
 | 
					 | 
				
			||||||
		global $config;
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
		if($config->get_int("ext_ratings2_version") < 2) {
 | 
					 | 
				
			||||||
			$this->install();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
		$config->set_default_string("ext_rating_anon_privs", 'squ');
 | 
					 | 
				
			||||||
		$config->set_default_string("ext_rating_user_privs", 'sqeu');
 | 
					 | 
				
			||||||
		$config->set_default_string("ext_rating_admin_privs", 'sqeu');
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public function onRatingSet(RatingSetEvent $event) {
 | 
					 | 
				
			||||||
		if(empty($event->image->rating)){
 | 
					 | 
				
			||||||
			$old_rating = "";
 | 
					 | 
				
			||||||
		}else{
 | 
					 | 
				
			||||||
			$old_rating = $event->image->rating;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$this->set_rating($event->image->id, $event->rating, $old_rating);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
 | 
						public static function get_user_privs($user) {
 | 
				
			||||||
		if($this->can_rate()) {
 | 
					 | 
				
			||||||
			$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public function onImageInfoSet(ImageInfoSetEvent $event) {
 | 
					 | 
				
			||||||
		global $user;
 | 
					 | 
				
			||||||
		if($this->can_rate() && isset($_POST["rating"])) {
 | 
					 | 
				
			||||||
			send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public function onSetupBuilding(SetupBuildingEvent $event) {
 | 
					 | 
				
			||||||
		$privs = array();
 | 
					 | 
				
			||||||
		$privs['Safe Only'] = 's';
 | 
					 | 
				
			||||||
		$privs['Safe and Unknown'] = 'su';
 | 
					 | 
				
			||||||
		$privs['Safe and Questionable'] = 'sq';
 | 
					 | 
				
			||||||
		$privs['Safe, Questionable, Unknown'] = 'squ';
 | 
					 | 
				
			||||||
		$privs['All'] = 'sqeu';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$sb = new SetupBlock("Image Ratings");
 | 
					 | 
				
			||||||
		$sb->add_choice_option("ext_rating_anon_privs", $privs, "Anonymous: ");
 | 
					 | 
				
			||||||
		$sb->add_choice_option("ext_rating_user_privs", $privs, "<br>Users: ");
 | 
					 | 
				
			||||||
		$sb->add_choice_option("ext_rating_admin_privs", $privs, "<br>Admins: ");
 | 
					 | 
				
			||||||
		$event->panel->add_block($sb);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public function onParseLinkTemplate(ParseLinkTemplateEvent $event) {
 | 
					 | 
				
			||||||
		$event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public function onSearchTermParse(SearchTermParseEvent $event) {
 | 
					 | 
				
			||||||
		$matches = array();
 | 
					 | 
				
			||||||
		if(is_null($event->term) && $this->no_rating_query($event->context)) {
 | 
					 | 
				
			||||||
			$set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
 | 
					 | 
				
			||||||
			$event->add_querylet(new Querylet("rating IN ($set)"));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if(preg_match("/^rating=([sqeu]+)$/", $event->term, $matches)) {
 | 
					 | 
				
			||||||
			$sqes = $matches[1];
 | 
					 | 
				
			||||||
			$arr = array();
 | 
					 | 
				
			||||||
			$length = strlen($sqes);
 | 
					 | 
				
			||||||
			for($i=0; $i<$length; $i++) {
 | 
					 | 
				
			||||||
				$arr[] = "'" . $sqes[$i] . "'";
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			$set = join(', ', $arr);
 | 
					 | 
				
			||||||
			$event->add_querylet(new Querylet("rating IN ($set)"));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if(preg_match("/^rating=(safe|questionable|explicit|unknown)$/", strtolower($event->term), $matches)) {
 | 
					 | 
				
			||||||
			$text = $matches[1];
 | 
					 | 
				
			||||||
			$char = $text[0];
 | 
					 | 
				
			||||||
			$event->add_querylet(new Querylet("rating = :img_rating", array("img_rating"=>$char)));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public function onDisplayingImage(DisplayingImageEvent $event) {
 | 
					 | 
				
			||||||
		/**
 | 
					 | 
				
			||||||
		 * Deny images upon insufficient permissions.
 | 
					 | 
				
			||||||
		 **/
 | 
					 | 
				
			||||||
		global $user, $page;
 | 
					 | 
				
			||||||
		$user_view_level = Ratings::get_user_privs($user);
 | 
					 | 
				
			||||||
		$user_view_level = preg_split('//', $user_view_level, -1);
 | 
					 | 
				
			||||||
		if(!in_array($event->image->rating, $user_view_level)) {
 | 
					 | 
				
			||||||
			$page->set_mode("redirect");
 | 
					 | 
				
			||||||
			$page->set_redirect(make_link("post/list"));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public static function get_user_privs(User $user) {
 | 
					 | 
				
			||||||
		global $config;
 | 
							global $config;
 | 
				
			||||||
		if($user->is_anonymous()) {
 | 
							if($user->is_anonymous()) {
 | 
				
			||||||
			$sqes = $config->get_string("ext_rating_anon_privs");
 | 
								$sqes = $config->get_string("ext_rating_anon_privs");
 | 
				
			||||||
 | 
				
			|||||||
@ -149,6 +149,12 @@ UL {
 | 
				
			|||||||
	margin-bottom: 32px;
 | 
						margin-bottom: 32px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.pools_next_img {
 | 
				
			||||||
 | 
					    display: block;
 | 
				
			||||||
 | 
					    font-size: 77%;
 | 
				
			||||||
 | 
					    text-align: right;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 | 
					/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 | 
				
			||||||
*                 the main part of each page                     *
 | 
					*                 the main part of each page                     *
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user