diff --git a/contrib/pools/main.php b/contrib/pools/main.php index afec342c..dd562548 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -1,19 +1,31 @@ + * Author: Sein Kraft , jgen * License: GPLv2 - * Description: Allow users to create groups of images - * Documentation: + * Description: Allow users to create groups of images and order them. + * 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 { + var $error; + + public function __construct($error) { + $this->error = $error; + } } class Pools extends Extension { + public function onInitExt(InitExtEvent $event) { global $config, $database; + // Create the database tables if ($config->get_int("ext_pools_version") < 1){ $database->create_table("pools", " id SCORE_AIPK, @@ -41,6 +53,7 @@ class Pools extends Extension { INDEX (id) "); + // Set the defaults for the pools extension $config->set_int("ext_pools_version", 1); $config->set_int("poolsMaxImportResults", 1000); @@ -49,11 +62,13 @@ class Pools extends Extension { $config->set_int("poolsUpdatedPerPage", 20); $config->set_bool("poolsInfoOnViewImage", "N"); $config->set_bool("poolsAdderOnViewImage", "N"); + $config->set_bool("poolsShowNextLink","N"); log_info("pools", "extension installed"); } } + // Add a block to the Board Config / Setup public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Pools"); $sb->add_int_option("poolsMaxImportResults", "Max results on import: "); @@ -61,20 +76,32 @@ class Pools extends Extension { $sb->add_int_option("poolsListsPerPage", "
Index list items per page: "); $sb->add_int_option("poolsUpdatedPerPage", "
Updated list items per page: "); $sb->add_bool_option("poolsInfoOnViewImage", "
Show pool info on image: "); + $sb->add_bool_option("poolsShowNextLink", "
Show 'Next' link when viewing pool images: "); //$sb->add_bool_option("poolsAdderOnViewImage", "
Show pool adder on image: "); $event->panel->add_block($sb); } public function onPageRequest(PageRequestEvent $event) { 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)) { case "list": //index $this->list_pools($page, int_escape($event->get_arg(1))); break; - case "new": // Show form + case "new": // Show form for new pools if(!$user->is_anonymous()){ $this->theme->new_pool_composer($page); } else { @@ -89,8 +116,8 @@ class Pools extends Extension { $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$newPoolID)); } - catch(PoolCreationException $pce) { - $this->theme->display_error($pce->getMessage()); + catch(PoolCreationException $e) { + $this->theme->display_error($e->error); } break; @@ -112,41 +139,26 @@ class Pools extends Extension { } break; - case "edit": - $poolID = int_escape($event->get_arg(1)); - $pools = $this->get_pool($poolID); - - 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 { - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$poolID)); - } + case "edit": // Edit the pool (remove images) + if ($this->have_permission($user, $pool)) { + $this->theme->edit_pool($page, $this->get_pool($pool_id), $this->edit_posts($pool_id)); + } else { + $page->set_mode("redirect"); + $page->set_redirect(make_link("pool/view/".$pool_id)); } break; - case "order": - if($_SERVER["REQUEST_METHOD"] == "GET") { - $poolID = int_escape($event->get_arg(1)); - $pools = $this->get_pool($poolID); - - 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 { - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$poolID)); - } + case "order": // Order the pool (view and change the order of images within the pool) + if (isset($_POST["order_view"])) { + if ($this->have_permission($user, $pool)) { + $this->theme->edit_order($page, $this->get_pool($pool_id), $this->edit_order($pool_id)); + } else { + $page->set_mode("redirect"); + $page->set_redirect(make_link("pool/view/".$pool_id)); } } else { - $pool_id = int_escape($_POST["pool_id"]); - $pool = $this->get_single_pool($pool_id); - - if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) { + if ($this->have_permission($user, $pool)) { $this->order_posts(); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); @@ -157,21 +169,15 @@ class Pools extends Extension { break; case "import": - $pool_id = int_escape($_POST["pool_id"]); - $pool = $this->get_single_pool($pool_id); - - if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) { - $this->import_posts(); + if ($this->have_permission($user, $pool)) { + $this->import_posts($pool_id); } else { $this->theme->display_error("Permssion denied."); } break; case "add_posts": - $pool_id = int_escape($_POST["pool_id"]); - $pool = $this->get_single_pool($pool_id); - - if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) { + if ($this->have_permission($user, $pool)) { $this->add_posts(); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); @@ -181,10 +187,7 @@ class Pools extends Extension { break; case "remove_posts": - $pool_id = int_escape($_POST["pool_id"]); - $pool = $this->get_single_pool($pool_id); - - if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) { + if ($this->have_permission($user, $pool)) { $this->remove_posts(); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$pool_id)); @@ -195,11 +198,9 @@ class Pools extends Extension { break; case "nuke": - $pool_id = int_escape($_POST['pool_id']); - $pool = $this->get_single_pool($pool_id); - - // only admins and owners may do this - if($user->is_admin() || $user->id == $pool['user_id']) { + // Completely remove the given pool. + // -> Only admins and owners may do this + if($user->is_admin() || $user->id == $pool['user_id']) { $this->nuke_pool($pool_id); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/list")); @@ -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) { global $config, $database, $page; @@ -230,12 +233,22 @@ class Pools extends Extension { if($config->get_bool("poolsInfoOnViewImage")) { $imageID = $event->image->id; $poolsIDs = $this->get_pool_id($imageID); + + $show_next = $config->get_bool("poolsShowNextLink", false); $linksPools = array(); foreach($poolsIDs as $poolID) { $pools = $this->get_pool($poolID['pool_id']); foreach ($pools as $pool){ $linksPools[] = "".html_escape($pool['title']).""; + + // 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[] = 'Next'; + } + } } } $this->theme->pool_info($linksPools); @@ -257,7 +270,25 @@ 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 */ @@ -308,28 +339,41 @@ class Pools extends Extension { INSERT INTO pools (user_id, public, title, description, date) VALUES (:uid, :public, :title, :desc, now())", 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}"); 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; 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; 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; return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID)); } @@ -338,13 +382,11 @@ class Pools extends Extension { /* * 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; - $pool_id = int_escape($_POST["pool_id"]); - $poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000); - + $images = $images = Image::find_images(0, $poolsMaxResults, Tag::explode($_POST["pool_tag"])); $this->theme->pool_result($page, $images, $pool_id); } @@ -352,6 +394,8 @@ class Pools extends Extension { /* * 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() { global $database; @@ -385,6 +429,9 @@ class Pools extends Extension { return $poolID; } + /* + * TODO: Fix this so that the pool ID and images are passed as Arguments to the function. + */ private function order_posts() { global $database; @@ -406,6 +453,8 @@ class Pools extends Extension { /* * 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() { global $database; @@ -420,25 +469,58 @@ class Pools extends Extension { $count = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", array("pid"=>$poolID)); $this->add_history($poolID, 0, $images, $count); - return $poolID; + return $poolID; } - /* - * HERE WE CHECK IF THE POST IS ALREADY ON POOL - * USED IN add_posts() + /** + * This function checks if a given image is contained within a given pool. + * 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; $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); } - - /* - * HERE WE GET ALL IMAGES FOR THE POOL + /** + * Gets the next successive image from a pool, given a pool ID and an image ID. + * + * @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; $pageNumber = int_escape($event->get_arg(2)); @@ -450,6 +532,7 @@ class Pools extends Extension { $pageNumber--; $poolID = int_escape($poolID); + $pool = $this->get_pool($poolID); $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 if(class_exists("Ratings")) { $rating = Ratings::privs_to_sql(Ratings::get_user_privs($user)); + } + if (isset($rating) && !empty($rating)) { $result = $database->get_all(" SELECT p.image_id @@ -473,8 +558,8 @@ class Pools extends Extension { INNER JOIN images AS i ON i.id = p.image_id WHERE pool_id=:pid AND i.rating IN ($rating)", array("pid"=>$poolID)) / $imagesPerPage); - } - else { + } else { + $result = $database->get_all(" SELECT image_id FROM pool_images @@ -482,6 +567,7 @@ class Pools extends Extension { ORDER BY image_order ASC LIMIT :l OFFSET :o", 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); } @@ -490,26 +576,26 @@ class Pools extends Extension { $images[] = Image::by_id($singleResult["image_id"]); } - $pool = $this->get_pool($poolID); $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; $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); - $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); - $result->MoveNext(); } - + 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 */ - private function edit_order($poolID) { + private function edit_order(/*int*/ $poolID) { global $database; $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); $images = array(); - while(!$result->EOF) { + + while($row = $result->fetch()) + { $image = $database->get_row(" SELECT * FROM images AS i INNER JOIN pool_images AS p ON i.id = p.image_id 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); $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; } @@ -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 */ - private function nuke_pool($poolID) { + private function nuke_pool(/*int*/ $poolID) { global $user, $database; $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 * 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; $database->execute(" 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 */ - private function get_history($pageNumber) { + private function get_history(/*int*/ $pageNumber) { global $config, $database; 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 */ - private function revert_history($historyID) { + private function revert_history(/*int*/ $historyID) { global $database; $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 * USED WITH FOREACH IN revert_history() */ - private function add_post($poolID, $imageID) { + private function add_post(/*int*/ $poolID, /*int*/ $imageID) { global $database; if(!$this->check_post($poolID, $imageID)) { @@ -675,7 +755,7 @@ class Pools extends Extension { * HERE WE REMOVE A SIMPLE POST FROM POOL * USED WITH FOREACH IN revert_history() */ - private function delete_post($poolID, $imageID) { + private function delete_post(/*int*/ $poolID, /*int*/ $imageID) { global $database; $database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID)); diff --git a/contrib/pools/theme.php b/contrib/pools/theme.php index 1f44a904..687fbba5 100644 --- a/contrib/pools/theme.php +++ b/contrib/pools/theme.php @@ -1,7 +1,8 @@ ".html_escape($pool['title']).""; } - $editor = " - ".make_form(make_link("pool/add_post"))." + $editor = "\n".make_form(make_link("pool/add_post"))." @@ -32,17 +32,20 @@ class PoolsTheme extends Themelet { /* * 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; - $html = ''. - "". - "". - "". - "". - "". - ""; + $html = ' +
NameCreatorPostsPublic
+ + + + + + '; $n = 0; + + // Build up the list of pools. foreach($pools as $pool) { $oe = ($n++ % 2 == 0) ? "even" : "odd"; @@ -60,12 +63,11 @@ class PoolsTheme extends Themelet { $html .= "
NameCreatorPostsPublic
"; - - $nav_html = " - Index -
Create Pool -
Pool Changes - "; + $nav_html = ' + Index +
Create Pool +
Pool Changes + '; $blockTitle = "Pools"; $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; $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)); } else { - $pool_info = "". - "". - "". - "". - ""; + $pool_info = ' +
TitleDescription
+ + + + '; $n = 0; foreach($pools as $pool) { @@ -146,7 +149,7 @@ class PoolsTheme extends Themelet { /* * 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; $this->display_top($pools, "Pool: ".html_escape($pools[0]['title'])); @@ -154,9 +157,7 @@ class PoolsTheme extends Themelet { $pool_images = ''; foreach($images as $image) { $thumb_html = $this->build_thumb_html($image); - $pool_images .= ''. - ''.$thumb_html.''. - ''; + $pool_images .= "\n".$thumb_html."\n"; } $page->add_block(new Block("Viewing Posts", $pool_images, "main", 30)); @@ -167,43 +168,49 @@ 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 */ - public function sidebar_options(Page $page, $pool, $check_all) { + public function sidebar_options(Page $page, $pool, /*bool*/ $check_all) { global $user; - $editor = " - ".make_form(make_link("pool/import"))." - - - + $editor = "\n".make_form( make_link('pool/import') ).' + + + - - - + + '.make_form( make_link('pool/edit') ).' + + + - - - + + '.make_form( make_link('pool/order') ).' + + + - "; + '; if($user->id == $pool['user_id'] || $user->is_admin()){ $editor .= " - ".make_form(make_link("pool/nuke"))." - - + + "; } if($check_all) { $editor .= " -
@@ -224,9 +232,11 @@ class PoolsTheme extends Themelet { /* * 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 = " - "; @@ -247,14 +258,12 @@ class PoolsTheme extends Themelet { foreach($images as $image) { $thumb_html = $this->build_thumb_html($image); - $pool_images .= ''. - ''.$thumb_html.''. - '
'. + $pool_images .= ''. $thumb_html .'
'. ''. '
'; } $pool_images .= "
". - "". + "". "". ""; @@ -273,18 +282,17 @@ class PoolsTheme extends Themelet { * 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 */ - public function edit_order(Page $page, $pools, $images) { + public function edit_order(Page $page, /*array*/ $pools, /*array*/ $images) { global $user; $this->display_top($pools, "Sorting Pool"); - $pool_images = "
"; + $pool_images = "\n"; $n = 0; foreach($images as $pair) { $image = $pair[0]; $thumb_html = $this->build_thumb_html($image); - $pool_images .= ''. - ''.$thumb_html.''. + $pool_images .= ''."\n".$thumb_html."\n". '
'. ''. '
'; @@ -292,7 +300,7 @@ class PoolsTheme extends Themelet { } $pool_images .= "
". - "". + "". "". ""; @@ -305,29 +313,25 @@ class PoolsTheme extends Themelet { * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH * 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; $this->display_top($pools, "Editing Pool", true); - $pool_images = " - "; - - $pool_images = "
"; + $pool_images = "\n"; foreach($images as $pair) { $image = $pair[0]; $thumb_html = $this->build_thumb_html($image); - $pool_images .= ''. - ''.$thumb_html.''. + $pool_images .= ''."\n".$thumb_html."\n". '
'. '
'; } $pool_images .= "
". - "". + "". "". ""; @@ -338,17 +342,18 @@ class PoolsTheme extends Themelet { /* * HERE WE DISPLAY THE HISTORY LIST */ - public function show_history($histories, $pageNumber, $totalPages) { + public function show_history($histories, /*int*/ $pageNumber, /*int*/ $totalPages) { global $page; - $html = "
TitleDescription
". - "". - "". - "". - "". - "". - "". - "". - ""; + $html = ' +
PoolPost CountChangesUpdaterDateAction
+ + + + + + + + '; $n = 0; 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; $page->set_title("Error"); diff --git a/contrib/random_image/main.php b/contrib/random_image/main.php index 0ff3a1b2..5a77bb25 100644 --- a/contrib/random_image/main.php +++ b/contrib/random_image/main.php @@ -24,6 +24,7 @@ class RandomImage extends Extension { public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; if($event->page_matches("random_image")) { + $action = ''; if($event->count_args() == 1) { $action = $event->get_arg(0); $search_terms = array(); @@ -37,14 +38,14 @@ class RandomImage extends Extension { } $image = Image::by_random($search_terms); - if($action == "download") { + if($action === "download") { if(!is_null($image)) { $page->set_mode("data"); $page->set_type("image/jpeg"); $page->set_data(file_get_contents($image->get_image_filename())); } } - if($action == "view") { + if($action === "view") { if(!is_null($image)) { send_event(new DisplayingImageEvent($image, $page)); } diff --git a/contrib/random_image/theme.php b/contrib/random_image/theme.php index 306f984f..87806bec 100644 --- a/contrib/random_image/theme.php +++ b/contrib/random_image/theme.php @@ -17,7 +17,7 @@ class RandomImageTheme extends Themelet {
- $h_tip + $h_tip
diff --git a/contrib/rating/main.php b/contrib/rating/main.php index a2a57633..ac9ba0fb 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -19,13 +19,109 @@ class RatingSetEvent extends Event { } 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, "
Users: "); + $sb->add_choice_option("ext_rating_admin_privs", $privs, "
Admins: "); + $event->panel->add_block($sb); + } + public function onAdminBuilding(AdminBuildingEvent $event) { $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) { - 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()) { throw PermissionDeniedException(); } @@ -52,97 +148,12 @@ 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) { - 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, "
Users: "); - $sb->add_choice_option("ext_rating_admin_privs", $privs, "
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) { + public static function get_user_privs($user) { global $config; if($user->is_anonymous()) { $sqes = $config->get_string("ext_rating_anon_privs"); diff --git a/themes/default/style.css b/themes/default/style.css index 1b2c7355..7aa10387 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -149,6 +149,12 @@ UL { margin-bottom: 32px; } +.pools_next_img { + display: block; + font-size: 77%; + text-align: right; +} + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the main part of each page *
PoolPost CountChangesUpdaterDateAction