From aa0cf27e7ed5fbd045cbaf7c4ca88a7a2c52ec4d Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 5 Apr 2014 11:10:24 +0100 Subject: [PATCH 01/12] add theme name to cached css/js filename to avoid loading cached files of old theme after theme change --- core/page.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/page.class.php b/core/page.class.php index 903014c0..ae083bd2 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -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) { From 77607e0c024c27b278eaa1869cb1d16b9089d135 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 23 May 2014 23:28:56 +0100 Subject: [PATCH 02/12] keep aspect ratio when created video thumbnail --- core/basethemelet.class.php | 2 +- ext/handle_video/main.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 3d62d3da..6f189552 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -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{ diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index d9d0cfd3..781a9220 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -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. From 1dada97adca9a7d0de23b3e491d2b29c730c6c7d Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 May 2014 00:22:04 +0100 Subject: [PATCH 03/12] prev link for pools --- ext/pools/main.php | 72 ++++++++++++++++++++++++++++++---------- themes/default/style.css | 13 ++++++-- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index f4a12f6d..0c14e0a8 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -80,6 +80,12 @@ 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_int("ext_pools_version", 3); + } } // Add a block to the Board Config / Setup @@ -90,7 +96,7 @@ 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("poolsShowNavLinks", "
Show 'Prev' & 'Next' links when viewing pool images: "); //$sb->add_bool_option("poolsAdderOnViewImage", "
Show pool adder on image: "); $event->panel->add_block($sb); } @@ -258,8 +264,8 @@ 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); + + $show_nav = $config->get_bool("poolsShowNavLinks", false); $linksPools = array(); foreach($poolsIDs as $poolID) { @@ -267,11 +273,18 @@ class Pools extends Extension { 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'; + // Optionally show a link the Prev/Next image in the Pool. + if ($show_nav) { + $nav = $this->get_nav_posts($pool, $imageID); + $navlinks = ""; + if (!empty($nav['prev'])) { + $navlinks .= 'Prev'; + } + if (!empty($nav['next'])) { + $navlinks .= 'Next'; + } + if(!empty($navlinks)){ + $linksPools[] = $navlinks; } } } @@ -612,26 +625,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; diff --git a/themes/default/style.css b/themes/default/style.css index 3056deac..e3fe222f 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -114,11 +114,18 @@ NAV SELECT { } .pools_next_img { - display: block; - font-size: 77%; - text-align: right; + display: block; + font-size: 77%; + text-align: right; + float: right; } +.pools_prev_img { + display: block; + font-size: 77%; + text-align: left; + float: left; +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the main part of each page * From f228a8eb4fb1b09f2003c259f404ef0fd393b78a Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 May 2014 00:23:12 +0100 Subject: [PATCH 04/12] pools css should be in it's own folder, not the themes --- ext/pools/style.css | 13 +++++++++++++ themes/default/style.css | 14 -------------- 2 files changed, 13 insertions(+), 14 deletions(-) create mode 100644 ext/pools/style.css diff --git a/ext/pools/style.css b/ext/pools/style.css new file mode 100644 index 00000000..f64c0e40 --- /dev/null +++ b/ext/pools/style.css @@ -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; +} diff --git a/themes/default/style.css b/themes/default/style.css index e3fe222f..c59d1d57 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -113,20 +113,6 @@ NAV SELECT { box-shadow: none; } -.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; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the main part of each page * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ From 1dc668ca4143a3511974d28a835968dbc4b40493 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 May 2014 11:55:53 +0100 Subject: [PATCH 05/12] main.php shouldn't be generating HTML.. --- ext/pools/main.php | 30 ++++++++++-------------------- ext/pools/theme.php | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 0c14e0a8..66812ac4 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -267,29 +267,19 @@ class Pools extends Extension { $show_nav = $config->get_bool("poolsShowNavLinks", false); - $linksPools = array(); + $navInfo = 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 Prev/Next image in the Pool. - if ($show_nav) { - $nav = $this->get_nav_posts($pool, $imageID); - $navlinks = ""; - if (!empty($nav['prev'])) { - $navlinks .= 'Prev'; - } - if (!empty($nav['next'])) { - $navlinks .= 'Next'; - } - if(!empty($navlinks)){ - $linksPools[] = $navlinks; - } - } + $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); } } diff --git a/ext/pools/theme.php b/ext/pools/theme.php index efa86f94..c42bdbb0 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -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[] = "".html_escape($pool['info']['title']).""; + + if (array_key_exists('nav', $pool)){ + $navlinks = ""; + if (!empty($pool['nav']['prev'])) { + $navlinks .= 'Prev'; + } + if (!empty($pool['nav']['next'])) { + $navlinks .= 'Next'; + } + if(!empty($navlinks)){ + $linksPools[] = $navlinks; + } + } + } + if(count($linksPools) > 0) { $page->add_block(new Block("Pools", implode("
", $linksPools), "left")); } From 6a14360e7ace7dbe79a89faf1f2d7985fb5095fd Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 May 2014 13:12:34 +0100 Subject: [PATCH 06/12] option to use autoincrementing pool order when post is added rather than having everything default to 0 order --- ext/pools/main.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 66812ac4..0845e861 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -83,6 +83,7 @@ class Pools extends Extension { 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); } @@ -97,7 +98,9 @@ class Pools extends Extension { $sb->add_int_option("poolsUpdatedPerPage", "
Updated list items per page: "); $sb->add_bool_option("poolsInfoOnViewImage", "
Show pool info on image: "); $sb->add_bool_option("poolsShowNavLinks", "
Show 'Prev' & 'Next' links when viewing pool images: "); + $sb->add_bool_option("poolsAutoIncrementOrder", "
Autoincrement order when post is added to pool:"); //$sb->add_bool_option("poolsAdderOnViewImage", "
Show pool adder on image: "); + $event->panel->add_block($sb); } @@ -903,13 +906,23 @@ class Pools extends Extension { * @param bool $history */ private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) { - global $database; + global $database, $config; if(!$this->check_post($poolID, $imageID)) { + $imageOrder = 0; + + if($config->get_bool("poolsAutoIncrementOrder")){ + $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)); From bca4fdffa599378a504953f396d924e31f0ba1a9 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 30 May 2014 14:41:03 +0100 Subject: [PATCH 07/12] make sure pool nav & manage pool show when needed --- ext/pools/main.php | 5 +- ext/pools/theme.php | 114 +++++++++++--------------------------------- 2 files changed, 30 insertions(+), 89 deletions(-) diff --git a/ext/pools/main.php b/ext/pools/main.php index 0845e861..cba63ea9 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -108,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"]); @@ -502,7 +501,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)); } diff --git a/ext/pools/theme.php b/ext/pools/theme.php index c42bdbb0..b546d129 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -87,12 +87,6 @@ class PoolsTheme extends Themelet { $html .= ""; - $nav_html = ' - Index -
Create Pool -
Pool Changes - '; - $order_html = ' '; - $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 */ @@ -128,9 +121,7 @@ class PoolsTheme extends Themelet { "; - $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)); } @@ -144,6 +135,17 @@ class PoolsTheme extends Themelet { $page->set_title($heading); $page->set_heading($heading); + + $nav_html = 'Index'; + $poolnav_html = ' + Index +
Create Pool +
Pool Changes + '; + + $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 @@ -155,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 = ' - - - - - '; - - foreach($pools as $pool) { - $pool_info .= "". - "". - "". - ""; - - // 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 .= "
TitleDescription
".html_escape($pool['title'])."".html_escape($pool['description'])."
"; - $page->add_block(new Block($heading, $pool_info, "main", 10)); - } } - /** * HERE WE DISPLAY THE POOL WITH TITLE DESCRIPTION AND IMAGES WITH PAGINATION. * @@ -202,14 +178,7 @@ class PoolsTheme extends Themelet { $pool_images .= "\n".$thumb_html."\n"; } - $nav_html = ' - Index -
Create Pool -
Pool Changes - '; - - $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); } @@ -265,12 +234,7 @@ class PoolsTheme extends Themelet { @@ -278,7 +242,7 @@ class PoolsTheme extends Themelet { "; } - $page->add_block(new Block("Manage Pool", $editor, "left", 10)); + $page->add_block(new Block("Manage Pool", $editor, "left", 15)); } @@ -287,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 = "