This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/pools/theme.php

417 lines
13 KiB
PHP
Raw Normal View History

2009-12-24 07:36:09 +00:00
<?php
2012-02-08 04:15:23 +00:00
2009-12-24 07:36:09 +00:00
class PoolsTheme extends Themelet {
2012-02-08 04:15:23 +00:00
/**
* Adds a block to the panel with information on the pool(s) the image is in.
* @param array Multidimensional array containing pool id, info & nav IDs.
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function pool_info(array $navIDs) {
2009-12-26 00:56:53 +00:00
global $page;
$linksPools = array();
foreach($navIDs as $poolID => $pool){
$linksPools[] = "<a href='".make_link("pool/view/".$poolID)."'>".html_escape($pool['info']['title'])."</a>";
if (array_key_exists('nav', $pool)){
$navlinks = "";
if (!empty($pool['nav']['prev'])) {
$navlinks .= '<a href="'.make_link('post/view/'.$pool['nav']['prev']).'" class="pools_prev_img">Prev</a>';
}
if (!empty($pool['nav']['next'])) {
$navlinks .= '<a href="'.make_link('post/view/'.$pool['nav']['next']).'" class="pools_next_img">Next</a>';
}
if(!empty($navlinks)){
$navlinks .= "<div style='height: 5px'></div>";
$linksPools[] = $navlinks;
}
}
}
2009-12-30 07:07:10 +00:00
if(count($linksPools) > 0) {
$page->add_block(new Block("Pools", implode("<br>", $linksPools), "left"));
}
}
2014-04-28 22:22:57 +00:00
/**
* @param Image $image
* @param array $pools
* @return string
*/
2017-09-19 17:55:43 +00:00
public function get_adder_html(Image $image, array $pools) {
2009-12-30 07:07:10 +00:00
$h = "";
foreach($pools as $pool) {
$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
}
2012-02-08 20:06:58 +00:00
$editor = "\n".make_form(make_link("pool/add_post"))."
2009-12-30 07:07:10 +00:00
<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;
2009-12-24 07:36:09 +00:00
}
2014-04-28 22:22:57 +00:00
/**
* HERE WE SHOWS THE LIST OF POOLS.
*
* @param Page $page
* @param array $pools
* @param int $pageNumber
* @param int $totalPages
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function list_pools(Page $page, array $pools, int $pageNumber, int $totalPages) {
2012-02-08 20:06:58 +00:00
$html = '
<table id="poolsList" class="zebra">
<thead><tr>
<th>Name</th>
<th>Creator</th>
<th>Posts</th>
<th>Public</th>
2012-02-09 06:42:45 +00:00
</tr></thead><tbody>';
2009-12-26 00:31:02 +00:00
2012-02-08 20:06:58 +00:00
// Build up the list of pools.
2009-12-26 00:31:02 +00:00
foreach($pools as $pool) {
2009-12-26 00:56:53 +00:00
$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>";
2009-12-26 00:31:02 +00:00
$public = ($pool['public'] == "Y" ? "Yes" : "No");
2012-02-22 14:27:56 +00:00
$html .= "<tr>".
2009-12-26 00:31:02 +00:00
"<td class='left'>".$pool_link."</td>".
"<td>".$user_link."</td>".
2009-12-24 07:36:09 +00:00
"<td>".$pool['posts']."</td>".
2009-12-30 07:07:10 +00:00
"<td>".$public."</td>".
"</tr>";
2009-12-24 07:36:09 +00:00
}
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
$html .= "</tbody></table>";
$order_html = '<select id="order_pool">';
$order_selected = $page->get_cookie('ui-order-pool');
$order_arr = ['created' => 'Recently created', 'updated' => 'Last updated', 'name' => 'Name', 'count' => 'Post Count'];
foreach($order_arr as $value => $text) {
$selected = ($value == $order_selected ? "selected" : "");
$order_html .= "<option value=\"{$value}\" {$selected}>{$text}</option>\n";
}
$order_html .= '</select>';
$this->display_top(null, "Pools");
$page->add_block(new Block("Order By", $order_html, "left", 15));
2009-12-24 07:36:09 +00:00
$page->add_block(new Block("Pools", $html, "main", 10));
2009-12-26 00:31:02 +00:00
$this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages);
}
2009-12-24 07:36:09 +00:00
/*
2009-12-26 00:31:02 +00:00
* HERE WE DISPLAY THE NEW POOL COMPOSER
*/
public function new_pool_composer(Page $page) {
$create_html = "
".make_form(make_link("pool/create"))."
<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='Create' /></td></tr>
</table>
</form>
2009-12-30 07:07:10 +00:00
";
2009-12-24 07:36:09 +00:00
$this->display_top(null, "Create Pool");
2009-12-30 07:07:10 +00:00
$page->add_block(new Block("Create Pool", $create_html, "main", 20));
2009-12-26 00:31:02 +00:00
}
2017-09-19 17:55:43 +00:00
private function display_top(array $pools=null, string $heading, bool $check_all=false) {
2009-12-30 07:07:10 +00:00
global $page, $user;
2009-12-26 00:31:02 +00:00
$page->set_title($heading);
$page->set_heading($heading);
$poolnav_html = '
<a href="'.make_link("pool/list").'">Pool Index</a>
<br><a href="'.make_link("pool/new").'">Create Pool</a>
<br><a href="'.make_link("pool/updated").'">Pool Changes</a>
';
$page->add_block(new NavBlock());
$page->add_block(new Block("Pool Navigation", $poolnav_html, "left", 10));
2009-12-30 07:07:10 +00:00
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);
}
}
2014-02-15 21:04:26 +00:00
$tfe = new TextFormattingEvent($pool['description']);
send_event($tfe);
$page->add_block(new Block(html_escape($pool['title']), $tfe->formatted, "main", 10));
2009-12-30 07:07:10 +00:00
}
2009-12-26 00:31:02 +00:00
}
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION.
*
* @param array $pools
* @param array $images
* @param int $pageNumber
* @param int $totalPages
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function view_pool(array $pools, array $images, int $pageNumber, int $totalPages) {
2015-09-12 10:43:28 +00:00
global $page;
2009-12-24 07:36:09 +00:00
2010-07-26 22:29:07 +00:00
$this->display_top($pools, "Pool: ".html_escape($pools[0]['title']));
2009-12-24 07:36:09 +00:00
$pool_images = '';
2009-12-30 07:07:10 +00:00
foreach($images as $image) {
2009-12-24 07:36:09 +00:00
$thumb_html = $this->build_thumb_html($image);
2012-02-08 04:15:23 +00:00
$pool_images .= "\n".$thumb_html."\n";
2009-12-24 07:36:09 +00:00
}
2009-12-26 00:31:02 +00:00
$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));
2009-12-30 07:07:10 +00:00
$this->display_paginator($page, "pool/view/".$pools[0]['id'], null, $pageNumber, $totalPages);
2009-12-26 00:31:02 +00:00
}
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE POOL OPTIONS ON SIDEBAR BUT WE HIDE REMOVE OPTION IF THE USER IS NOT THE OWNER OR ADMIN.
*
* @param Page $page
* @param array $pool
* @param bool $check_all
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function sidebar_options(Page $page, $pool, bool $check_all) {
2009-12-24 07:36:09 +00:00
global $user;
2009-12-26 00:31:02 +00:00
2012-02-08 19:10:33 +00:00
$editor = "\n".make_form( make_link('pool/import') ).'
<input type="text" name="pool_tag" id="edit_pool_tag" placeholder="Please enter a tag"/>
2012-02-08 19:10:33 +00:00
<input type="submit" name="edit" id="edit_pool_import_btn" value="Import"/>
<input type="hidden" name="pool_id" value="'.$pool['id'].'">
2009-12-26 00:31:02 +00:00
</form>
2012-02-08 19:10:33 +00:00
'.make_form( make_link('pool/edit') ).'
<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'].'">
2009-12-26 00:31:02 +00:00
</form>
2012-02-08 19:10:33 +00:00
'.make_form( make_link('pool/order') ).'
<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'].'">
2009-12-26 00:31:02 +00:00
</form>
2012-02-08 19:10:33 +00:00
';
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
if($user->id == $pool['user_id'] || $user->is_admin()){
$editor .= "
<script type='text/javascript'>
2012-02-08 20:06:58 +00:00
<!--
2009-12-26 00:31:02 +00:00
function confirm_action() {
return confirm('Are you sure that you want to delete this pool?');
}
2012-02-08 20:06:58 +00:00
//-->
2009-12-30 07:07:10 +00:00
</script>
2009-12-26 00:31:02 +00:00
".make_form(make_link("pool/nuke"))."
2012-02-08 19:10:33 +00:00
<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']."'>
2009-12-26 00:31:02 +00:00
</form>
";
2009-12-24 07:36:09 +00:00
}
2009-12-30 07:07:10 +00:00
if($check_all) {
$editor .= "
<script type='text/javascript'>
2012-02-08 20:06:58 +00:00
<!--
2009-12-30 07:07:10 +00:00
function setAll(value) {
$('[name=\"check[]\"]').attr('checked', value);
2009-12-30 07:07:10 +00:00
}
2012-02-08 20:06:58 +00:00
//-->
2009-12-30 07:07:10 +00:00
</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", 15));
2009-12-24 07:36:09 +00:00
}
2009-12-26 00:31:02 +00:00
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE RESULT OF THE SEARCH ON IMPORT.
*
* @param Page $page
* @param array $images
* @param array $pool
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function pool_result(Page $page, array $images, array $pool) {
$this->display_top($pool, "Importing Posts", true);
2009-12-24 07:36:09 +00:00
$pool_images = "
<script type='text/javascript'>
2012-02-08 20:06:58 +00:00
<!--
2009-12-24 07:36:09 +00:00
function confirm_action() {
return confirm('Are you sure you want to add selected posts to this pool?');
}
2012-02-08 20:06:58 +00:00
//-->
2009-12-26 00:31:02 +00:00
</script>
2009-12-24 07:36:09 +00:00
";
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
$pool_images .= "<form action='".make_link("pool/add_posts")."' method='POST' name='checks'>";
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
foreach($images as $image) {
2009-12-26 00:31:02 +00:00
$thumb_html = $this->build_thumb_html($image);
2012-02-08 04:15:23 +00:00
$pool_images .= '<span class="thumb">'. $thumb_html .'<br>'.
2009-12-26 00:31:02 +00:00
'<input name="check[]" type="checkbox" value="'.$image->id.'" />'.
'</span>';
2009-12-24 07:36:09 +00:00
}
2009-12-24 07:36:09 +00:00
$pool_images .= "<br>".
2012-02-08 04:15:23 +00:00
"<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[0]['id']."'>".
2009-12-26 00:31:02 +00:00
"</form>";
$page->add_block(new Block("Import", $pool_images, "main", 30));
2009-12-24 07:36:09 +00:00
}
2009-12-26 00:31:02 +00:00
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE POOL ORDERER.
2009-12-26 00:31:02 +00:00
* WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH A TEXT INPUT TO SET A NUMBER AND CHANGE THE ORDER
2014-04-28 22:22:57 +00:00
*
* @param Page $page
* @param array $pools
* @param array $images
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function edit_order(Page $page, array $pools, array $images) {
2009-12-26 00:31:02 +00:00
$this->display_top($pools, "Sorting Pool");
2012-02-08 04:15:23 +00:00
$pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>";
2014-03-29 11:44:34 +00:00
$i = 0;
2009-12-24 07:36:09 +00:00
foreach($images as $pair) {
$image = $pair[0];
$thumb_html = $this->build_thumb_html($image);
2012-02-08 04:15:23 +00:00
$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
'<br><input name="imgs['.$i.'][]" type="number" style="max-width:50px;" value="'.$image->image_order.'" />'.
2014-03-29 11:44:34 +00:00
'<input name="imgs['.$i.'][]" type="hidden" value="'.$image->id.'" />'.
2009-12-26 00:31:02 +00:00
'</span>';
2014-03-29 11:44:34 +00:00
$i++;
2009-12-24 07:36:09 +00:00
}
2009-12-26 00:31:02 +00:00
$pool_images .= "<br>".
2012-02-08 04:15:23 +00:00
"<input type='submit' name='edit' id='edit_pool_order' value='Order'/>".
2009-12-30 07:07:10 +00:00
"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
2009-12-26 00:31:02 +00:00
"</form>";
2009-12-24 07:36:09 +00:00
$page->add_block(new Block("Sorting Posts", $pool_images, "main", 30));
}
2009-12-26 00:31:02 +00:00
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE POOL EDITOR.
*
2009-12-30 07:07:10 +00:00
* WE LIST ALL IMAGES ON POOL WITHOUT PAGINATION AND WITH
* A CHECKBOX TO SELECT WHICH IMAGE WE WANT TO REMOVE
2014-04-28 22:22:57 +00:00
*
* @param Page $page
* @param array $pools
* @param array $images
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function edit_pool(Page $page, array $pools, array $images) {
/* EDIT POOL DESCRIPTION */
$desc_html = "
".make_form(make_link("pool/edit_description"))."
<textarea name='description'>".$pools[0]['description']."</textarea><br />
<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>
<input type='submit' value='Change Description' />
</form>
";
/* REMOVE POOLS */
2012-02-08 04:15:23 +00:00
$pool_images = "\n<form action='".make_link("pool/remove_posts")."' method='POST' name='checks'>";
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
foreach($images as $pair) {
$image = $pair[0];
$thumb_html = $this->build_thumb_html($image);
2012-02-08 04:15:23 +00:00
$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
2009-12-26 00:31:02 +00:00
'<br><input name="check[]" type="checkbox" value="'.$image->id.'" />'.
'</span>';
}
2009-12-24 07:36:09 +00:00
2009-12-26 00:31:02 +00:00
$pool_images .= "<br>".
2012-02-08 04:15:23 +00:00
"<input type='submit' name='edit' id='edit_pool_remove_sel' value='Remove Selected'/>".
2009-12-26 00:56:53 +00:00
"<input type='hidden' name='pool_id' value='".$pools[0]['id']."'>".
2009-12-26 00:31:02 +00:00
"</form>";
2009-12-24 07:36:09 +00:00
$pools[0]['description'] = ""; //This is a rough fix to avoid showing the description twice.
$this->display_top($pools, "Editing Pool", true);
$page->add_block(new Block("Editing Description", $desc_html, "main", 28));
2009-12-24 07:36:09 +00:00
$page->add_block(new Block("Editing Posts", $pool_images, "main", 30));
2009-12-26 00:31:02 +00:00
}
2014-04-28 22:22:57 +00:00
/**
* HERE WE DISPLAY THE HISTORY LIST.
*
* @param array $histories
* @param int $pageNumber
* @param int $totalPages
2009-12-26 00:31:02 +00:00
*/
2017-09-19 17:55:43 +00:00
public function show_history($histories, int $pageNumber, int $totalPages) {
2009-12-24 07:36:09 +00:00
global $page;
2012-02-08 20:06:58 +00:00
$html = '
<table id="poolsList" class="zebra">
<thead><tr>
<th>Pool</th>
<th>Post Count</th>
<th>Changes</th>
<th>Updater</th>
<th>Date</th>
<th>Action</th>
2012-02-09 06:42:45 +00:00
</tr></thead><tbody>';
2009-12-26 00:31:02 +00:00
foreach($histories as $history) {
$pool_link = "<a href='".make_link("pool/view/".$history['pool_id'])."'>".html_escape($history['title'])."</a>";
$user_link = "<a href='".make_link("user/".url_escape($history['user_name']))."'>".html_escape($history['user_name'])."</a>";
$revert_link = "<a href='".make_link("pool/revert/".$history['id'])."'>Revert</a>";
if ($history['action'] == 1) {
$prefix = "+";
} elseif ($history['action'] == 0) {
$prefix = "-";
}
$images = trim($history['images']);
$images = explode(" ", $images);
$image_link = "";
2014-04-28 22:22:57 +00:00
foreach ($images as $image) {
2009-12-26 00:31:02 +00:00
$image_link .= "<a href='".make_link("post/view/".$image)."'>".$prefix.$image." </a>";
}
2012-02-22 14:27:56 +00:00
$html .= "<tr>".
2009-12-26 00:31:02 +00:00
"<td class='left'>".$pool_link."</td>".
2009-12-24 07:36:09 +00:00
"<td>".$history['count']."</td>".
2009-12-26 00:31:02 +00:00
"<td>".$image_link."</td>".
2009-12-24 07:36:09 +00:00
"<td>".$user_link."</td>".
2009-12-26 00:31:02 +00:00
"<td>".$history['date']."</td>".
2009-12-24 07:36:09 +00:00
"<td>".$revert_link."</td>".
"</tr>";
}
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
$html .= "</tbody></table>";
2009-12-26 00:31:02 +00:00
$this->display_top(null, "Recent Changes");
2009-12-24 07:36:09 +00:00
$page->add_block(new Block("Recent Changes", $html, "main", 10));
2009-12-26 00:31:02 +00:00
2009-12-24 07:36:09 +00:00
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);
}
}