formatting pass

This commit is contained in:
Shish 2019-06-14 13:47:50 +01:00
parent d1102cd635
commit 064b24ffc1
18 changed files with 265 additions and 255 deletions

View File

@ -178,8 +178,7 @@ function create_thumbnail_convert($hash): bool
$q = $config->get_int("thumb_quality"); $q = $config->get_int("thumb_quality");
$convert = $config->get_string("thumb_convert_path"); $convert = $config->get_string("thumb_convert_path");
if($convert==null||$convert=="") if ($convert==null||$convert=="") {
{
return false; return false;
} }
@ -321,9 +320,15 @@ function calc_memory_use(array $info): int
return (int)$memory_use; return (int)$memory_use;
} }
function image_resize_gd(String $image_filename, array $info, int $new_width, int $new_height, function image_resize_gd(
string $output_filename=null, string $output_type=null, int $output_quality = 80) String $image_filename,
{ array $info,
int $new_width,
int $new_height,
string $output_filename=null,
string $output_type=null,
int $output_quality = 80
) {
$width = $info[0]; $width = $info[0];
$height = $info[1]; $height = $info[1];
@ -448,7 +453,8 @@ function image_resize_gd(String $image_filename, array $info, int $new_width, in
} }
} }
function is_animated_gif(String $image_filename) { function is_animated_gif(String $image_filename)
{
$isanigif = 0; $isanigif = 0;
if (($fh = @fopen($image_filename, 'rb'))) { if (($fh = @fopen($image_filename, 'rb'))) {
//check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473) //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)

View File

@ -12,22 +12,23 @@
class BulkActionBlockBuildingEvent extends Event class BulkActionBlockBuildingEvent extends Event
{ {
/** @var array */ /** @var array */
public $actions = array(); public $actions = [];
public function add_action(String $action, string $button_text, String $confirmation_message = "", String $block = "", int $position = 40) public function add_action(String $action, string $button_text, String $confirmation_message = "", String $block = "", int $position = 40)
{ {
if ($block == null) if ($block == null) {
$block = ""; $block = "";
}
array_push( array_push(
$this->actions, $this->actions,
array( [
"block" => $block, "block" => $block,
"confirmation_message" => $confirmation_message, "confirmation_message" => $confirmation_message,
"action" => $action, "action" => $action,
"button_text" => $button_text, "button_text" => $button_text,
"position" => $position "position" => $position
) ]
); );
} }
} }
@ -41,7 +42,7 @@ class BulkActionEvent extends Event
/** @var PageRequestEvent */ /** @var PageRequestEvent */
public $page_request; public $page_request;
function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items) public function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items)
{ {
$this->action = $action; $this->action = $action;
$this->page_request = $pageRequestEvent; $this->page_request = $pageRequestEvent;
@ -59,10 +60,11 @@ class BulkActions extends Extension
$babbe = new BulkActionBlockBuildingEvent(); $babbe = new BulkActionBlockBuildingEvent();
send_event($babbe); send_event($babbe);
if (sizeof($babbe->actions) == 0) if (sizeof($babbe->actions) == 0) {
return; return;
}
usort($babbe->actions, array($this, "sort_blocks")); usort($babbe->actions, [$this, "sort_blocks"]);
$this->theme->display_selector($page, $babbe->actions, Tag::implode($event->search_terms)); $this->theme->display_selector($page, $babbe->actions, Tag::implode($event->search_terms));
} }

View File

@ -2,8 +2,6 @@
class BulkActionsTheme extends Themelet class BulkActionsTheme extends Themelet
{ {
public function display_selector(Page $page, $actions, $query) public function display_selector(Page $page, $actions, $query)
{ {
global $user; global $user;
@ -33,7 +31,7 @@ class BulkActionsTheme extends Themelet
} }
foreach ($actions as $action) { foreach ($actions as $action) {
$body .= "<div class='bulk_action'>" . make_form(make_link("bulk_action"), "POST", False, "", "return validate_selections(this,'" . html_escape($action["confirmation_message"]) . "');") . $body .= "<div class='bulk_action'>" . make_form(make_link("bulk_action"), "POST", false, "", "return validate_selections(this,'" . html_escape($action["confirmation_message"]) . "');") .
"<input type='hidden' name='bulk_query' value='" . html_escape($query) . "'>" . "<input type='hidden' name='bulk_query' value='" . html_escape($query) . "'>" .
"<input type='hidden' name='bulk_selected_ids' />" . "<input type='hidden' name='bulk_selected_ids' />" .
"<input type='hidden' name='bulk_action' value='" . $action["action"] . "' />" . "<input type='hidden' name='bulk_action' value='" . $action["action"] . "' />" .

View File

@ -299,7 +299,8 @@ class CronUploader extends Extension
} }
try { try {
$database->rollback(); $database->rollback();
} catch (Exception $e) {} } catch (Exception $e) {
}
} }
} }
@ -330,8 +331,7 @@ class CronUploader extends Extension
// Move to corrupt dir // Move to corrupt dir
$newDir .= "/failed_to_upload/".$output_subdir.$relativeDir; $newDir .= "/failed_to_upload/".$output_subdir.$relativeDir;
$info = "ERROR: Image was not uploaded."; $info = "ERROR: Image was not uploaded.";
} } else {
else {
$newDir .= "/uploaded/".$output_subdir.$relativeDir; $newDir .= "/uploaded/".$output_subdir.$relativeDir;
$info = "Image successfully uploaded. "; $info = "Image successfully uploaded. ";
} }

View File

@ -97,8 +97,15 @@ class PixelFileHandler extends DataHandlerExtension
try { try {
$info = getimagesize($inname); $info = getimagesize($inname);
$tsize = get_thumbnail_size_scaled($info[0], $info[1]); $tsize = get_thumbnail_size_scaled($info[0], $info[1]);
$image = image_resize_gd($inname, $info, $tsize[0], $tsize[1], $image = image_resize_gd(
$outname, $config->get_string('thumb_type'),$config->get_int('thumb_quality')); $inname,
$info,
$tsize[0],
$tsize[1],
$outname,
$config->get_string('thumb_type'),
$config->get_int('thumb_quality')
);
} catch (InsufficientMemoryException $e) { } catch (InsufficientMemoryException $e) {
$tsize = get_thumbnail_max_size_scaled(); $tsize = get_thumbnail_max_size_scaled();
$thumb = imagecreatetruecolor($tsize[0], min($tsize[1], 64)); $thumb = imagecreatetruecolor($tsize[0], min($tsize[1], 64));

View File

@ -172,7 +172,6 @@ class Ratings extends Extension
if ($user->is_admin()) { if ($user->is_admin()) {
$event->add_action("bulk_rate", "Set Rating", "", $this->theme->get_selection_rater_html("bulk_rating")); $event->add_action("bulk_rate", "Set Rating", "", $this->theme->get_selection_rater_html("bulk_rating"));
} }
} }
public function onBulkAction(BulkActionEvent $event) public function onBulkAction(BulkActionEvent $event)

View File

@ -46,7 +46,8 @@ class RatingsTheme extends Themelet
$page->add_block(new Block("List Controls", $html, "left")); $page->add_block(new Block("List Controls", $html, "left"));
} }
public function get_selection_rater_html(String $id = "select_rating") { public function get_selection_rater_html(String $id = "select_rating")
{
return "<select name='".$id."'> return "<select name='".$id."'>
<option value='s'>Safe</option> <option value='s'>Safe</option>
<option value='q'>Questionable</option> <option value='q'>Questionable</option>

View File

@ -71,7 +71,6 @@ class RegenThumb extends Extension
if ($user->can("delete_image")) { if ($user->can("delete_image")) {
$event->add_action("bulk_regen", "Regen Thumbnails", "", $this->theme->bulk_html()); $event->add_action("bulk_regen", "Regen Thumbnails", "", $this->theme->bulk_html());
} }
} }
public function onBulkAction(BulkActionEvent $event) public function onBulkAction(BulkActionEvent $event)
@ -83,8 +82,7 @@ class RegenThumb extends Extension
if ($user->can("delete_image")) { if ($user->can("delete_image")) {
$force = true; $force = true;
if (isset($_POST["bulk_regen_thumb_missing_only"]) if (isset($_POST["bulk_regen_thumb_missing_only"])
&&$_POST["bulk_regen_thumb_missing_only"]=="true") &&$_POST["bulk_regen_thumb_missing_only"]=="true") {
{
$force=false; $force=false;
} }
@ -110,7 +108,8 @@ class RegenThumb extends Extension
$this->theme->display_admin_block(); $this->theme->display_admin_block();
} }
public function onAdminAction(AdminActionEvent $event) { public function onAdminAction(AdminActionEvent $event)
{
global $database; global $database;
switch ($event->action) { switch ($event->action) {
@ -176,7 +175,7 @@ class RegenThumb extends Extension
} }
} }
function get_images(String $ext = null) public function get_images(String $ext = null)
{ {
global $database; global $database;
@ -190,7 +189,7 @@ class RegenThumb extends Extension
return $database->get_all($query, $args); return $database->get_all($query, $args);
} }
function remove_dir_recursively($dir) public function remove_dir_recursively($dir)
{ {
if (is_dir($dir)) { if (is_dir($dir)) {
$objects = scandir($dir); $objects = scandir($dir);
@ -207,5 +206,4 @@ class RegenThumb extends Extension
rmdir($dir); rmdir($dir);
} }
} }
} }

View File

@ -38,7 +38,8 @@ class RegenThumbTheme extends Themelet
return $html; return $html;
} }
public function bulk_html() { public function bulk_html()
{
return "<label><input type='checkbox' name='bulk_regen_thumb_missing_only' id='bulk_regen_thumb_missing_only' style='width:13px' value='true' />Only missing thumbs</label>"; return "<label><input type='checkbox' name='bulk_regen_thumb_missing_only' id='bulk_regen_thumb_missing_only' style='width:13px' value='true' />Only missing thumbs</label>";
} }
@ -67,7 +68,7 @@ class RegenThumbTheme extends Themelet
<tr><td colspan='2'><input type='submit' value='Regenerate Thumbnails'></td></tr> <tr><td colspan='2'><input type='submit' value='Regenerate Thumbnails'></td></tr>
</table> </table>
</form></p> </form></p>
<p>".make_form(make_link("admin/delete_thumbs"),"POST",False, "","return confirm('Are you sure you want to delete all thumbnails?')")." <p>".make_form(make_link("admin/delete_thumbs"), "POST", false, "", "return confirm('Are you sure you want to delete all thumbnails?')")."
<table class='form'> <table class='form'>
<tr><th><label for='delete_thumb_type'>Type</label></th><td> <tr><th><label for='delete_thumb_type'>Type</label></th><td>
<select name='delete_thumb_type' id='delete_thumb_type' value='1000'> <select name='delete_thumb_type' id='delete_thumb_type' value='1000'>

View File

@ -15,7 +15,9 @@
/* /*
* This is used by the image transcoding code when there is an error while transcoding * This is used by the image transcoding code when there is an error while transcoding
*/ */
class ImageTranscodeException extends SCoreException{ } class ImageTranscodeException extends SCoreException
{
}
class TranscodeImage extends Extension class TranscodeImage extends Extension
@ -193,7 +195,6 @@ class TranscodeImage extends Extension
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id"); $this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
} else { } else {
if (isset($_POST['transcode_format'])) { if (isset($_POST['transcode_format'])) {
try { try {
$this->transcode_and_replace_image($image_obj, $_POST['transcode_format']); $this->transcode_and_replace_image($image_obj, $_POST['transcode_format']);
$page->set_mode("redirect"); $page->set_mode("redirect");
@ -216,7 +217,6 @@ class TranscodeImage extends Extension
if ($user->is_admin()) { if ($user->is_admin()) {
$event->add_action("bulk_transcode", "Transcode", "", $this->theme->get_transcode_picker_html($this->get_supported_output_formats($engine))); $event->add_action("bulk_transcode", "Transcode", "", $this->theme->get_transcode_picker_html($this->get_supported_output_formats($engine)));
} }
} }
public function onBulkAction(BulkActionEvent $event) public function onBulkAction(BulkActionEvent $event)
@ -248,17 +248,18 @@ class TranscodeImage extends Extension
log_error("transcode", "Error while bulk transcode on item $id to $format: ".$e->getMessage()); log_error("transcode", "Error while bulk transcode on item $id to $format: ".$e->getMessage());
try { try {
$database->rollback(); $database->rollback();
} catch (Exception $e) {} } catch (Exception $e) {
}
} }
} }
flash_message("Transcoded $total items"); flash_message("Transcoded $total items");
} }
break; break;
} }
} }
private function clean_format($format): ?string { private function clean_format($format): ?string
{
if (array_key_exists($format, self::FORMAT_ALIASES)) { if (array_key_exists($format, self::FORMAT_ALIASES)) {
return self::FORMAT_ALIASES[$format]; return self::FORMAT_ALIASES[$format];
} }
@ -327,7 +328,6 @@ class TranscodeImage extends Extension
@unlink($tmp_filename); @unlink($tmp_filename);
send_event(new ImageReplaceEvent($image_obj->id, $new_image)); send_event(new ImageReplaceEvent($image_obj->id, $new_image));
} }
@ -356,7 +356,6 @@ class TranscodeImage extends Extension
case "convert": case "convert":
return $this->transcode_image_convert($source_name, $source_format, $target_format); return $this->transcode_image_convert($source_name, $source_format, $target_format);
} }
} }
private function transcode_image_gd(String $source_name, String $source_format, string $target_format): string private function transcode_image_gd(String $source_name, String $source_format, string $target_format): string
@ -418,8 +417,7 @@ class TranscodeImage extends Extension
$q = $config->get_int("transcode_quality"); $q = $config->get_int("transcode_quality");
$convert = $config->get_string("thumb_convert_path"); $convert = $config->get_string("thumb_convert_path");
if($convert==null||$convert=="") if ($convert==null||$convert=="") {
{
throw new ImageTranscodeException("ImageMagick path not configured"); throw new ImageTranscodeException("ImageMagick path not configured");
} }
$ext = $this->determine_ext($target_format); $ext = $this->determine_ext($target_format);
@ -455,5 +453,4 @@ class TranscodeImage extends Extension
return $tmp_name; return $tmp_name;
} }
} }

View File

@ -20,14 +20,14 @@ class TranscodeImageTheme extends Themelet
return $html; return $html;
} }
public function get_transcode_picker_html(array $options) { public function get_transcode_picker_html(array $options)
{
$html = "<select id='transcode_format' name='transcode_format' required='required' >"; $html = "<select id='transcode_format' name='transcode_format' required='required' >";
foreach ($options as $display=>$value) { foreach ($options as $display=>$value) {
$html .= "<option value='$value'>$display</option>"; $html .= "<option value='$value'>$display</option>";
} }
return $html."</select>"; return $html."</select>";
} }
public function display_transcode_error(Page $page, string $title, string $message) public function display_transcode_error(Page $page, string $title, string $message)
@ -37,5 +37,4 @@ class TranscodeImageTheme extends Themelet
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block($title, $message)); $page->add_block(new Block($title, $message));
} }
} }

View File

@ -57,12 +57,14 @@ class DataUploadEvent extends Event
} }
} }
public function set_type(String $type) { public function set_type(String $type)
{
$this->type = strtolower($type); $this->type = strtolower($type);
$this->metadata["extension"] = $this->type; $this->metadata["extension"] = $this->type;
} }
public function set_tmpname(String $tmpname) { public function set_tmpname(String $tmpname)
{
$this->tmpname = $tmpname; $this->tmpname = $tmpname;
$this->metadata['hash'] = md5_file($tmpname); $this->metadata['hash'] = md5_file($tmpname);
$this->metadata['size'] = filesize($tmpname); $this->metadata['size'] = filesize($tmpname);