a load more pools work

This commit is contained in:
Shish 2009-12-30 07:07:10 +00:00
parent c7408d3445
commit 96c3cf73e5
2 changed files with 140 additions and 122 deletions

View file

@ -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", "<br>Index 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("poolsAdderOnViewImage", "<br>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[] = "<a href='".make_link("pool/view/".$pool['id'])."'>".$pool['title']."</a>";
$linksPools[] = "<a href='".make_link("pool/view/".$pool['id'])."'>".html_escape($pool['title'])."</a>";
}
}
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);

View file

@ -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("<br>", $linksPools), "left"));
}
}
public function get_adder_html(Image $image, $pools) {
$editor = "";
$h = "";
foreach($pools as $pool) {
$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
}
$editor = "
<form method='POST' action='".make_link("pool/add_post")."'>
<select name='pool_id'>
$h
</select>
<input type='hidden' name='image_id' value='{$image->id}'>
<input type='submit' value='Add Image to Pool'>
</form>
";
return $editor;
}
@ -15,18 +34,13 @@ class PoolsTheme extends Themelet {
*/
public function list_pools(Page $page, $pools, $pageNumber, $totalPages) {
global $user;
$html = '<table id="poolsList" class="zebra">'.
"<thead><tr>".
"<th>Name</th>".
"<th>Creator</th>".
"<th>Posts</th>".
"<th>Public</th>";
if($user->is_admin()){
$html .= "<th>Action</th>";
}
$html .= "</tr></thead>";
"<th>Public</th>".
"</tr></thead>";
$n = 0;
foreach($pools as $pool) {
@ -34,30 +48,30 @@ class PoolsTheme extends Themelet {
$pool_link = '<a href="'.make_link("pool/view/".$pool['id']).'">'.html_escape($pool['title'])."</a>";
$user_link = '<a href="'.make_link("user/".url_escape($pool['user_name'])).'">'.html_escape($pool['user_name'])."</a>";
$edit_link = '<a href="'.make_link("pool/edit/".$pool['id']).'">Edit</a>';
$del_link = '<a href="'.make_link("pool/nuke/".$pool['id']).'">Delete</a>';
$public = ($pool['public'] == "Y" ? "Yes" : "No");
$html .= "<tr class='$oe'>".
"<td class='left'>".$pool_link."</td>".
"<td>".$user_link."</td>".
"<td>".$pool['posts']."</td>".
"<td>".$public."</td>";
if($user->is_admin()){
$html .= "<td>$edit_link / $del_link</td>";
}
$html .= "</tr>";
"<td>".$public."</td>".
"</tr>";
}
$html .= "</tbody></table>";
$nav_html = "
<a href=".make_link().">Index</a>
<br><a href=".make_link("pool/new").">Create Pool</a>
<br><a href=".make_link("pool/updated").">Pool Changes</a>
";
$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 = "<form action=".make_link("pool/create")." method='POST'>
$create_html = "<form action=".make_link("pool/create")." method='POST'>
<table>
<tr><td>Title:</td><td><input type='text' name='title'></td></tr>
<tr><td>Public?</td><td><input name='public' type='checkbox' value='Y' checked='checked'/></td></tr>
<tr><td>Description:</td><td><textarea name='description'></textarea></td></tr>
<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr>
</table>
";
";
$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 = "<table id='poolsList' class='zebra'>".
"<thead><tr>".
"<th class='left'>Title</th>".
@ -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 .= "</tbody></table>";
$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 .= '<span class="thumb">'.
'<a href="$image_link">'.$thumb_html.'</a>'.
@ -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 = " <form action='".make_link("pool/import")."' method='POST'>
@ -155,14 +174,12 @@ class PoolsTheme extends Themelet {
<input type='hidden' name='pool_id' value='".$pool['id']."'>
</form>
<form id='form1' name='form1' method='post' action='".make_link("pool/edit_pool")."'>
<form method='GET' action='".make_link("pool/edit/".$pool['id'])."'>
<input type='submit' name='edit' id='edit' value='Edit Pool'/>
<input type='hidden' name='pool_id' value='".$pool['id']."'>
</form>
<form id='form1' name='form1' method='post' action='".make_link("pool/edit_order")."'>
<form method='GET' action='".make_link("pool/order/".$pool['id'])."'>
<input type='submit' name='edit' id='edit' value='Order Pool'/>
<input type='hidden' name='pool_id' value='".$pool['id']."'>
</form>
";
@ -172,14 +189,31 @@ class PoolsTheme extends Themelet {
function confirm_action() {
return confirm('Are you sure that you want to delete this pool?');
}
</script>
</script>
<form action='".make_link("pool/nuke_pool")."' method='POST'>
<form action='".make_link("pool/nuke")."' method='POST'>
<input type='submit' name='delete' id='delete' value='Delete Pool' onclick='return confirm_action()' />
<input type='hidden' name='pool_id' value='".$pool['id']."'>
</form>
";
}
if($check_all) {
$editor .= "
<script language='JavaScript' type='text/javascript'>
function setAll(value) {
var a=new Array();
a=document.getElementsByName('check[]');
var p=0;
for(i=0;i<a.length;i++){
a[i].checked = value;
}
}
</script>
<br><input type='button' name='CheckAll' value='Check All' onClick='setAll(true)'>
<input type='button' name='UnCheckAll' value='Uncheck All' onClick='setAll(false)'>
";
}
$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 = "<form action='".make_link("pool/order_posts")."' method='POST' name='checks'>";
$pool_images = "<form action='".make_link("pool/order")."' method='POST' name='checks'>";
$n = 0;
foreach($images as $pair) {
$image = $pair[0];
@ -256,7 +290,7 @@ class PoolsTheme extends Themelet {
$pool_images .= "<br>".
"<input type='submit' name='edit' id='edit' value='Order'/>".
"<input type='hidden' name='pool_id' value='".$pool['id']."'>".
"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
"</form>";
$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 = "
<script language='JavaScript' type='text/javascript'>
function setAll(value) {
var a=new Array();
a=document.getElementsByName('check[]');
var p=0;
for(i=0;i<a.length;i++){
a[i].checked = value;
}
}
</script>
";
$pool_images .= "<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) {
$image = $pair[0];
@ -304,12 +329,6 @@ class PoolsTheme extends Themelet {
"</form>";
$page->add_block(new Block("Editing Posts", $pool_images, "main", 30));
$editor = "
<input type='button' name='CheckAll' value='Check All' onClick='setAll(true)'>
<input type='button' name='UnCheckAll' value='Uncheck All' onClick='setAll(false)'>";
$page->add_block(new Block("Manage Pool", $editor, "left", 10));
}