From 96c3cf73e5ba0bc0f3842a0acc6269f59295733e Mon Sep 17 00:00:00 2001 From: Shish Date: Wed, 30 Dec 2009 07:07:10 +0000 Subject: [PATCH] a load more pools work --- contrib/pools/main.php | 123 ++++++++++++++++++----------------- contrib/pools/theme.php | 139 +++++++++++++++++++++++----------------- 2 files changed, 140 insertions(+), 122 deletions(-) diff --git a/contrib/pools/main.php b/contrib/pools/main.php index 57595906..5e2f63ed 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -45,6 +45,7 @@ class Pools extends SimpleExtension { $config->set_int("poolsListsPerPage", 20); $config->set_int("poolsUpdatedPerPage", 20); $config->set_bool("poolsInfoOnViewImage", "N"); + $config->set_bool("poolsAdderOnViewImage", "N"); log_info("pools", "extension installed"); } @@ -57,6 +58,7 @@ class Pools extends SimpleExtension { $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("poolsAdderOnViewImage", "
Show pool adder on image: "); $event->panel->add_block($sb); } @@ -79,7 +81,7 @@ class Pools extends SimpleExtension { break; case "create": // ADD _POST - if(!$user->is_anonymous()){ + if(!$user->is_anonymous()) { $newPoolID = $this->add_pool(); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/view/".$newPoolID)); @@ -121,49 +123,35 @@ class Pools extends SimpleExtension { } break; - case "edit_pool": - $poolID = int_escape($_POST["pool_id"]); - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/edit/".$poolID)); - break; - - /* case "order": - $poolID = int_escape($event->get_arg(1)); - $pools = $this->get_pool($poolID); + 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)); + 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)); + } } - } - break; + } + else { + $pool_id = int_escape($_POST["pool_id"]); + $pool = $this->get_single_pool($pool_id); - case "edit_order": - $poolID = int_escape($_POST["pool_id"]); - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/order/".$poolID)); - break; - - case "order_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']) { - $this->order_posts(); - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/view/".$pool_id)); - } else { - $this->theme->display_error("Permssion denied."); + if(($pool['public'] == "Y" && !$user->is_anonymous()) || $user->is_admin() || $user->id == $pool['user_id']) { + $this->order_posts(); + $page->set_mode("redirect"); + $page->set_redirect(make_link("pool/view/".$pool_id)); + } else { + $this->theme->display_error("Permssion denied."); + } } break; - */ - case "import": $pool_id = int_escape($_POST["pool_id"]); $pool = $this->get_single_pool($pool_id); @@ -203,7 +191,7 @@ class Pools extends SimpleExtension { break; case "nuke": - $pool_id = int_escape($event->get_arg(1)); + $pool_id = int_escape($_POST['pool_id']); $pool = $this->get_single_pool($pool_id); // only admins and owners may do this @@ -216,12 +204,6 @@ class Pools extends SimpleExtension { } break; - case "nuke_pool": - $poolID = int_escape($_POST["pool_id"]); - $page->set_mode("redirect"); - $page->set_redirect(make_link("pool/nuke/".$poolID)); - break; - default: $page->set_mode("redirect"); $page->set_redirect(make_link("pool/list")); @@ -230,12 +212,16 @@ class Pools extends SimpleExtension { } } + public function onUserBlockBuilding($event) { + $event->add_link("Pools", make_link("pool/list")); + } + /* * HERE WE GET THE POOLS WHERE THE IMAGE APPEARS WHEN THE IMAGE IS DISPLAYED */ public function onDisplayingImage($event) { - global $config, $page; + global $config, $database, $page; if($config->get_bool("poolsInfoOnViewImage")) { $imageID = $event->image->id; @@ -245,11 +231,24 @@ class Pools extends SimpleExtension { foreach($poolsIDs as $poolID) { $pools = $this->get_pool($poolID['pool_id']); foreach ($pools as $pool){ - $linksPools[] = "".$pool['title'].""; + $linksPools[] = "".html_escape($pool['title']).""; } } - if(count($linksPools) > 0) { - $this->theme->pool_info(implode($linksPools)); + $this->theme->pool_info($linksPools); + } + } + + public function onImageAdminBlockBuilding($event) { + global $config, $database, $user; + if($config->get_bool("poolsAdderOnViewImage") && !$user->is_anonymous()) { + if($user->is_admin()) { + $pools = $database->get_all("SELECT * FROM pools"); + } + else { + $pools = $database->get_all("SELECT * FROM pools WHERE user_id=?", array($user->id)); + } + if(count($pools) > 0) { + $event->add_part($this->theme->get_adder_html($event->image, $pools)); } } } @@ -442,18 +441,9 @@ class Pools extends SimpleExtension { $imagesPerPage = $config->get_int("poolsImagesPerPage"); - // WE CHECK IF THE EXTENSION RATING IS INSTALLED, WICH VERSION AND IF IT WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER - if(!class_exists("Ratings") || $config->get_int("ext_ratings2_version") < 3) { - $result = $database->get_all(" - SELECT image_id - FROM pool_images - WHERE pool_id=? - ORDER BY image_order ASC - LIMIT ?, ?", - array($poolID, $pageNumber * $imagesPerPage, $imagesPerPage)); - $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_images WHERE pool_id=?",array($poolID)) / $imagesPerPage); - } - else if(class_exists("Ratings") && $config->get_int("ext_ratings2_version") >= 3) { + // WE CHECK IF THE EXTENSION RATING IS INSTALLED, WHICH VERSION AND IF IT + // 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)); $result = $database->get_all(" @@ -472,11 +462,20 @@ class Pools extends SimpleExtension { WHERE pool_id=? AND i.rating IN ($rating)", array($poolID)) / $imagesPerPage); } + else { + $result = $database->get_all(" + SELECT image_id + FROM pool_images + WHERE pool_id=? + ORDER BY image_order ASC + LIMIT ?, ?", + array($poolID, $pageNumber * $imagesPerPage, $imagesPerPage)); + $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM pool_images WHERE pool_id=?", array($poolID)) / $imagesPerPage); + } $images = array(); foreach($result as $singleResult) { - $image = Image::by_id($singleResult["image_id"]); - $images[] = array($image); + $images[] = Image::by_id($singleResult["image_id"]); } $pool = $this->get_pool($poolID); diff --git a/contrib/pools/theme.php b/contrib/pools/theme.php index 87b99be4..3ef967a6 100644 --- a/contrib/pools/theme.php +++ b/contrib/pools/theme.php @@ -5,8 +5,27 @@ class PoolsTheme extends Themelet { */ public function pool_info($linksPools) { global $page; - $editor = 'This post belongs to the '.$linksPools.' pool.'; - $page->add_block(new Block("Pool Info", $editor, "main", 1)); + if(count($linksPools) > 0) { + $page->add_block(new Block("Pools", implode("
", $linksPools), "left")); + } + } + + public function get_adder_html(Image $image, $pools) { + $editor = ""; + $h = ""; + foreach($pools as $pool) { + $h .= ""; + } + $editor = " +
+ + + +
+ "; + return $editor; } @@ -15,18 +34,13 @@ class PoolsTheme extends Themelet { */ public function list_pools(Page $page, $pools, $pageNumber, $totalPages) { global $user; - $html = ''. "". "". "". "". - ""; - - if($user->is_admin()){ - $html .= ""; - } - $html .= ""; + "". + ""; $n = 0; foreach($pools as $pool) { @@ -34,30 +48,30 @@ class PoolsTheme extends Themelet { $pool_link = ''.html_escape($pool['title']).""; $user_link = ''.html_escape($pool['user_name']).""; - $edit_link = 'Edit'; - $del_link = 'Delete'; $public = ($pool['public'] == "Y" ? "Yes" : "No"); $html .= "". "". "". "". - ""; - - if($user->is_admin()){ - $html .= ""; - } - - $html .= ""; - + "". + ""; } $html .= "
NameCreatorPostsPublicAction
Public
".$pool_link."".$user_link."".$pool['posts']."".$public."$edit_link / $del_link
".$public."
"; + + $nav_html = " + Index +
Create Pool +
Pool Changes + "; + $blockTitle = "Pools"; $page->set_title(html_escape($blockTitle)); $page->set_heading(html_escape($blockTitle)); $page->add_block(new Block($blockTitle, $html, "main", 10)); + $page->add_block(new Block("Navigation", $nav_html, "left", 10)); $this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages); } @@ -67,28 +81,37 @@ class PoolsTheme extends Themelet { * HERE WE DISPLAY THE NEW POOL COMPOSER */ public function new_pool_composer(Page $page) { - $html = "
+ $create_html = "
Title:
Public?
Description:
- "; + "; $blockTitle = "Create Pool"; $page->set_title(html_escape($blockTitle)); $page->set_heading(html_escape($blockTitle)); - $page->add_block(new Block($blockTitle, $html, "main", 10)); + $page->add_block(new Block("Create Pool", $create_html, "main", 20)); } - private function display_top($pools, $heading) { - global $page; + private function display_top($pools, $heading, $check_all=false) { + global $page, $user; $page->set_title($heading); $page->set_heading($heading); - if(count($pools) > 1) { + if(count($pools) == 1) { + $pool = $pools[0]; + if($pool['public'] == "Y" || $user->is_admin()) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL + if(!$user->is_anonymous()) {// IF THE USER IS REGISTERED AND LOGGED IN SHOW EDIT PANEL + $this->sidebar_options($page, $pool, $check_all); + } + } + $page->add_block(new Block(html_escape($pool['title']), html_escape($pool['description']), "main", 10)); + } + else { $pool_info = "". "". "". @@ -107,18 +130,14 @@ class PoolsTheme extends Themelet { // this will make disasters if more than one pool comes in the parameter if($pool['public'] == "Y" || $user->is_admin()) {// IF THE POOL IS PUBLIC OR IS ADMIN SHOW EDIT PANEL if(!$user->is_anonymous()) {// IF THE USER IS REGISTERED AND LOGGED IN SHOW EDIT PANEL - $this->sidebar_options($page, $pool); + $this->sidebar_options($page, $pool, $check_all); } } - $this->display_paginator($page, "pool/view/".$pool['id'], null, $pageNumber, $totalPages); } $pool_info .= "
Title
"; $page->add_block(new Block($heading, $pool_info, "main", 10)); } - else { - $page->add_block(new Block(html_escape($pools[0]['title']), html_escape($pools[0]['description']), "main", 10)); - } } @@ -131,8 +150,7 @@ class PoolsTheme extends Themelet { $this->display_top($pools, "Viewing Pool"); $pool_images = ''; - foreach($images as $pair) { - $image = $pair[0]; + foreach($images as $image) { $thumb_html = $this->build_thumb_html($image); $pool_images .= ''. ''.$thumb_html.''. @@ -140,13 +158,14 @@ class PoolsTheme extends Themelet { } $page->add_block(new Block("Viewing Posts", $pool_images, "main", 30)); + $this->display_paginator($page, "pool/view/".$pools[0]['id'], null, $pageNumber, $totalPages); } /* * 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){ + public function sidebar_options(Page $page, $pool, $check_all) { global $user; $editor = " @@ -155,14 +174,12 @@ class PoolsTheme extends Themelet { -
+ -
-
+ -
"; @@ -172,14 +189,31 @@ class PoolsTheme extends Themelet { function confirm_action() { return confirm('Are you sure that you want to delete this pool?'); } - + -
+
"; } + + if($check_all) { + $editor .= " + +
+ + "; + } $page->add_block(new Block("Manage Pool", $editor, "left", 10)); } @@ -241,7 +275,7 @@ class PoolsTheme extends Themelet { $this->display_top($pools, "Sorting Pool"); - $pool_images = "
"; + $pool_images = ""; $n = 0; foreach($images as $pair) { $image = $pair[0]; @@ -256,7 +290,7 @@ class PoolsTheme extends Themelet { $pool_images .= "
". "". - "". + "". "
"; $page->add_block(new Block("Sorting Posts", $pool_images, "main", 30)); @@ -265,27 +299,18 @@ class PoolsTheme extends Themelet { /* * HERE WE DISPLAY THE POOL EDITOR - * WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH A CHECKBOX TO SELECT WHICH IMAGE WE WANT REMOVE + * 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) { global $user; - $this->display_top($pools, "Editing Pool"); + $this->display_top($pools, "Editing Pool", true); $pool_images = " - "; - $pool_images .= "
"; + $pool_images = ""; foreach($images as $pair) { $image = $pair[0]; @@ -304,12 +329,6 @@ class PoolsTheme extends Themelet { "
"; $page->add_block(new Block("Editing Posts", $pool_images, "main", 30)); - - $editor = " - - "; - - $page->add_block(new Block("Manage Pool", $editor, "left", 10)); }