Merge pull request #429 from DakuTree/patch-misc

Pool updates + other misc tweaks.
This commit is contained in:
Shish 2014-06-09 21:05:19 +01:00
commit 9069b0c1fb
9 changed files with 167 additions and 139 deletions

View File

@ -56,7 +56,7 @@ class BaseThemelet {
$h_tip = html_escape($image->get_tooltip());
$h_tags = strtolower($image->get_tag_list());
$extArr = array_flip(array('swf', 'svg', 'mp4', 'ogv', 'webm', 'flv')); //List of thumbless filetypes
$extArr = array_flip(array('swf', 'svg')); //List of thumbless filetypes
if(!isset($extArr[$image->ext])){
$tsize = get_thumbnail_size($image->width, $image->height);
}else{

View File

@ -292,7 +292,7 @@ class Page {
$css_files[] = $css;
$css_latest = max($css_latest, filemtime($css));
}
$css_cache_file = data_path("cache/style.$css_latest.css");
$css_cache_file = data_path("cache/style.$theme_name.$css_latest.css");
if(!file_exists($css_cache_file)) {
$css_data = "";
foreach($css_files as $file) {
@ -312,7 +312,7 @@ class Page {
$js_files[] = $js;
$js_latest = max($js_latest, filemtime($js));
}
$js_cache_file = data_path("cache/script.$js_latest.js");
$js_cache_file = data_path("cache/script.$theme_name.$js_latest.js");
if(!file_exists($js_cache_file)) {
$js_data = "";
foreach($js_files as $file) {

View File

@ -70,7 +70,8 @@ class VideoFileHandler extends DataHandlerExtension {
$inname = escapeshellarg(warehouse_path("images", $hash));
$outname = escapeshellarg(warehouse_path("thumbs", $hash));
$cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -s {$w}x{$h} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}");
$cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -vf scale='if(gt(a,{$w}/{$h}),{$w},-1)':'if(gt(a,{$w}/{$h}),-1,{$h})' -ss 00:00:00.0 -f image2 -vframes 1 {$outname}");
exec($cmd, $output, $ret);
// TODO: We should really check the result of the exec to see if it really succeeded.

View File

@ -1,7 +1,7 @@
<?php
/**
* Name: Pools System
* Author: Sein Kraft <mail@seinkraft.info>, jgen <jgen.tech@gmail.com>
* Author: Sein Kraft <mail@seinkraft.info>, jgen <jgen.tech@gmail.com>, Daku <admin@codeanimu.net>
* License: GPLv2
* Description: Allow users to create groups of images and order them.
* Documentation: This extension allows users to created named groups of
@ -80,6 +80,13 @@ class Pools extends Extension {
$config->set_int("ext_pools_version", 2);
}
if ($config->get_int("ext_pools_version") < 3){
$config->set_bool("poolsShowNavLinks","N"); //A $config->rename() function would be nice here...
$config->set_bool("poolsAutoIncrementOrder","N");
$config->set_int("ext_pools_version", 3);
}
}
// Add a block to the Board Config / Setup
@ -90,8 +97,10 @@ class Pools extends Extension {
$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("poolsShowNextLink", "<br>Show 'Next' link when viewing pool images: ");
$sb->add_bool_option("poolsShowNavLinks", "<br>Show 'Prev' & 'Next' links when viewing pool images: ");
$sb->add_bool_option("poolsAutoIncrementOrder", "<br>Autoincrement order when post is added to pool:");
//$sb->add_bool_option("poolsAdderOnViewImage", "<br>Show pool adder on image: ");
$event->panel->add_block($sb);
}
@ -99,10 +108,9 @@ class Pools extends Extension {
global $page, $user;
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"]);
@ -258,25 +266,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();
$show_nav = $config->get_bool("poolsShowNavLinks", false);
$navInfo = array();
foreach($poolsIDs as $poolID) {
$pools = $this->get_pool($poolID['pool_id']);
foreach ($pools as $pool){
$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>';
}
}
$pool = $this->get_single_pool($poolID['pool_id']);
$navInfo[$pool['id']] = array();
$navInfo[$pool['id']]['info'] = $pool;
// Optionally show a link the Prev/Next image in the Pool.
if ($show_nav) {
$navInfo[$pool['id']]['nav'] = $this->get_nav_posts($pool, $imageID);
}
}
$this->theme->pool_info($linksPools);
$this->theme->pool_info($navInfo);
}
}
@ -320,19 +325,24 @@ class Pools extends Extension {
public function onTagTermParse(TagTermParseEvent $event) {
$matches = array();
if(preg_match("/^pool[=|:](.*)$/i", $event->term, $matches)) {
if(preg_match("/^pool[=|:]([^:]*|lastcreated):?([0-9]*)$/i", $event->term, $matches)) {
global $user;
$poolTag = (string) str_replace("_", " ", $matches[1]);
$pool = null;
if(ctype_digit($poolTag)){ //If only digits, assume PoolID
if($poolTag == 'lastcreated'){
$pool = $this->get_last_userpool($user->id);
}
elseif(ctype_digit($poolTag)){ //If only digits, assume PoolID
$pool = $this->get_single_pool($poolTag);
}else{ //assume PoolTitle
$pool = $this->get_single_pool_from_title($poolTag);
}
if($pool ? $this->have_permission($user, $pool) : FALSE){
$this->add_post($pool['id'], $event->id, true);
$image_order = ($matches[2] ?: 0);
$this->add_post($pool['id'], $event->id, true, $image_order);
}
}
@ -486,6 +496,16 @@ class Pools extends Extension {
return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
}
/**
* Retrieve information about the last pool the given userID created
* @param int $userID
* @return array
*/
private function get_last_userpool(/*int*/ $userID){
global $database;
return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", array("uid"=>$userID));
}
/**
* HERE WE GET THE IMAGES FROM THE TAG ON IMPORT
* @param int $pool_id
@ -496,7 +516,7 @@ class Pools extends Extension {
$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);
$this->theme->pool_result($page, $images, $this->get_pool($pool_id));
}
@ -612,26 +632,49 @@ class Pools extends Extension {
}
/**
* Gets the next successive image from a pool, given a pool ID and an image ID.
* Gets the previous and next successive images from a pool, given a pool ID and an image ID.
*
* @param array $pool Array for the given pool
* @param int $imageID Integer
* @return int Integer which is the next Image ID or NULL if none.
* @return array Array returning two elements (prev, next) in 1 dimension. Each returns ImageID or NULL if none.
*/
private function get_next_post(/*array*/ $pool, /*int*/ $imageID) {
private function get_nav_posts(/*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",
$result = $database->get_row("
SELECT (
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 DESC LIMIT 1
) AS prev,
(
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
) AS next
LIMIT 1",
array("pid"=>$pool['id'], "iid"=>$imageID) );
if (empty($result)) {
// assume that we are at the end of the pool
return null;
@ -875,15 +918,24 @@ class Pools extends Extension {
* @param int $poolID
* @param int $imageID
* @param bool $history
* @param int $imageOrder
*/
private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) {
global $database;
private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false, $imageOrder=0) {
global $database, $config;
if(!$this->check_post($poolID, $imageID)) {
if($config->get_bool("poolsAutoIncrementOrder") && $imageOrder === 0){
$imageOrder = $database->get_one("
SELECT CASE WHEN image_order IS NOT NULL THEN MAX(image_order) + 1 ELSE 0 END
FROM pool_images
WHERE pool_id = :pid",
array("pid"=>$poolID));
}
$database->execute("
INSERT INTO pool_images (pool_id, image_id)
VALUES (:pid, :iid)",
array("pid"=>$poolID, "iid"=>$imageID));
INSERT INTO pool_images (pool_id, image_id, image_order)
VALUES (:pid, :iid, :ord)",
array("pid"=>$poolID, "iid"=>$imageID, "ord"=>$imageOrder));
}
$database->execute("UPDATE pools SET posts=(SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid) WHERE id=:pid", array("pid"=>$poolID));

13
ext/pools/style.css Normal file
View File

@ -0,0 +1,13 @@
.pools_next_img {
display: block;
font-size: 77%;
text-align: right;
float: right;
}
.pools_prev_img {
display: block;
font-size: 77%;
text-align: left;
float: left;
}

View File

@ -3,9 +3,29 @@
class PoolsTheme extends Themelet {
/**
* 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.
*/
public function pool_info($linksPools) {
public function pool_info(/*array*/ $navIDs) {
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)){
$linksPools[] = $navlinks;
}
}
}
if(count($linksPools) > 0) {
$page->add_block(new Block("Pools", implode("<br>", $linksPools), "left"));
}
@ -67,12 +87,6 @@ class PoolsTheme extends Themelet {
$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>
';
$order_html = '
<select id="order_pool">
<option value="created">Recently created</option>
@ -82,17 +96,16 @@ class PoolsTheme extends Themelet {
</select>
';
$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_top(null, "Pools");
$page->add_block(new Block("Order By", $order_html, "left", 15));
$page->add_block(new Block("Pools", $html, "main", 10));
$this->display_paginator($page, "pool/list", null, $pageNumber, $totalPages);
}
/*
* HERE WE DISPLAY THE NEW POOL COMPOSER
*/
@ -108,9 +121,7 @@ class PoolsTheme extends Themelet {
</form>
";
$blockTitle = "Create Pool";
$page->set_title(html_escape($blockTitle));
$page->set_heading(html_escape($blockTitle));
$this->display_top(null, "Create Pool");
$page->add_block(new Block("Create Pool", $create_html, "main", 20));
}
@ -124,6 +135,17 @@ class PoolsTheme extends Themelet {
$page->set_title($heading);
$page->set_heading($heading);
$nav_html = '<a href="'.make_link().'">Index</a>';
$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 Block($nav_html, null, "left", 5));
$page->add_block(new Block("Pool Navigation", $poolnav_html, "left", 10));
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
@ -135,34 +157,8 @@ class PoolsTheme extends Themelet {
$bb = new BBCode();
$page->add_block(new Block(html_escape($pool['title']), $bb->format($pool['description']), "main", 10));
}
else {
$pool_info = '
<table id="poolsList" class="zebra">
<thead><tr>
<th class="left">Title</th>
<th class="left">Description</th>
</tr></thead><tbody>';
foreach($pools as $pool) {
$pool_info .= "<tr>".
"<td class='left'>".html_escape($pool['title'])."</td>".
"<td class='left'>".html_escape($pool['description'])."</td>".
"</tr>";
// 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, $check_all);
}
}
}
$pool_info .= "</tbody></table>";
$page->add_block(new Block($heading, $pool_info, "main", 10));
}
}
/**
* HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION.
*
@ -182,14 +178,7 @@ class PoolsTheme extends Themelet {
$pool_images .= "\n".$thumb_html."\n";
}
$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>
';
$page->add_block(new Block("Navigation", $nav_html, "left", 10));
$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));
$page->add_block(new Block("Viewing Posts", $pool_images, "main", 30));
$this->display_paginator($page, "pool/view/".$pools[0]['id'], null, $pageNumber, $totalPages);
}
@ -245,12 +234,7 @@ class PoolsTheme extends Themelet {
<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;
}
$('[name=\"check[]\"]').attr('checked', value);
}
//-->
</script>
@ -258,7 +242,7 @@ class PoolsTheme extends Themelet {
<input type='button' name='UnCheckAll' value='Uncheck All' onClick='setAll(false)'>
";
}
$page->add_block(new Block("Manage Pool", $editor, "left", 10));
$page->add_block(new Block("Manage Pool", $editor, "left", 15));
}
@ -267,22 +251,14 @@ class PoolsTheme extends Themelet {
*
* @param Page $page
* @param array $images
* @param int $pool_id
* @param array $pool
*/
public function pool_result(Page $page, /*array*/ $images, /*int*/ $pool_id) {
// TODO: this could / should be done using jQuery
public function pool_result(Page $page, /*array*/ $images, /*array*/ $pool) {
$this->display_top($pool, "Importing Posts", 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;
}
}
function confirm_action() {
return confirm('Are you sure you want to add selected posts to this pool?');
}
@ -299,19 +275,13 @@ class PoolsTheme extends Themelet {
'<input name="check[]" type="checkbox" value="'.$image->id.'" />'.
'</span>';
}
$pool_images .= "<br>".
"<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[0]['id']."'>".
"</form>";
$page->add_block(new Block("Import", $pool_images, "main", 10));
$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));
$page->add_block(new Block("Import", $pool_images, "main", 30));
}
@ -446,15 +416,7 @@ class PoolsTheme extends Themelet {
$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>
';
$page->set_title("Recent Changes");
$page->set_heading("Recent Changes");
$page->add_block(new Block("Navigation", $nav_html, "left", 10));
$this->display_top(null, "Recent Changes");
$page->add_block(new Block("Recent Changes", $html, "main", 10));
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);

View File

@ -114,7 +114,7 @@ class Ratings extends Extension {
}
public function onParseLinkTemplate(ParseLinkTemplateEvent $event) {
$event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
$event->replace('$rating', $this->rating_to_human($event->image->rating));
}
public function onSearchTermParse(SearchTermParseEvent $event) {
@ -265,7 +265,7 @@ class Ratings extends Extension {
global $database;
if($old_rating != $rating){
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
log_info("rating", "Rating for Image #{$image_id} set to: ".$this->theme->rating_to_name($rating));
log_info("rating", "Rating for Image #{$image_id} set to: ".$this->rating_to_human($rating));
}
}
}

View File

@ -23,7 +23,14 @@
* </ul>
* <li>Pools
* <ul>
* <li>pool=(PoolID, PoolTitle) -- add post to pool (if exists)
* <li>pool=(PoolID, PoolTitle, lastcreated) -- add post to pool (if exists)
* <li>pool=(PoolID, PoolTitle, lastcreated):(PoolOrder) -- add post to pool (if exists) with set pool order
* <ul>
* <li>pool=50 -- add post to pool with ID of 50
* <li>pool=10:25 -- add post to pool with ID of 10 and with order 25
* <li>pool=This_is_a_Pool -- add post to pool with a title of "This is a Pool"
* <li>pool=lastcreated -- add post to the last pool the user created
* </ul>
* </ul>
* <li>Post Relationships
* <ul>

View File

@ -113,13 +113,6 @@ NAV SELECT {
box-shadow: none;
}
.pools_next_img {
display: block;
font-size: 77%;
text-align: right;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* the main part of each page *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */