formatting pass
This commit is contained in:
parent
d1102cd635
commit
064b24ffc1
18 changed files with 265 additions and 255 deletions
|
@ -178,8 +178,7 @@ function create_thumbnail_convert($hash): bool
|
|||
$q = $config->get_int("thumb_quality");
|
||||
$convert = $config->get_string("thumb_convert_path");
|
||||
|
||||
if($convert==null||$convert=="")
|
||||
{
|
||||
if ($convert==null||$convert=="") {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -321,9 +320,15 @@ function calc_memory_use(array $info): int
|
|||
return (int)$memory_use;
|
||||
}
|
||||
|
||||
function image_resize_gd(String $image_filename, array $info, int $new_width, int $new_height,
|
||||
string $output_filename=null, string $output_type=null, int $output_quality = 80)
|
||||
{
|
||||
function image_resize_gd(
|
||||
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];
|
||||
$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;
|
||||
if (($fh = @fopen($image_filename, 'rb'))) {
|
||||
//check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
|
||||
|
|
|
@ -12,22 +12,23 @@
|
|||
class BulkActionBlockBuildingEvent extends Event
|
||||
{
|
||||
/** @var array */
|
||||
public $actions = array();
|
||||
public $actions = [];
|
||||
|
||||
public function add_action(String $action, string $button_text, String $confirmation_message = "", String $block = "", int $position = 40)
|
||||
{
|
||||
if ($block == null)
|
||||
if ($block == null) {
|
||||
$block = "";
|
||||
}
|
||||
|
||||
array_push(
|
||||
$this->actions,
|
||||
array(
|
||||
[
|
||||
"block" => $block,
|
||||
"confirmation_message" => $confirmation_message,
|
||||
"action" => $action,
|
||||
"button_text" => $button_text,
|
||||
"position" => $position
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +42,7 @@ class BulkActionEvent extends Event
|
|||
/** @var PageRequestEvent */
|
||||
public $page_request;
|
||||
|
||||
function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items)
|
||||
public function __construct(String $action, PageRequestEvent $pageRequestEvent, array $items)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->page_request = $pageRequestEvent;
|
||||
|
@ -59,10 +60,11 @@ class BulkActions extends Extension
|
|||
$babbe = new BulkActionBlockBuildingEvent();
|
||||
send_event($babbe);
|
||||
|
||||
if (sizeof($babbe->actions) == 0)
|
||||
if (sizeof($babbe->actions) == 0) {
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
class BulkActionsTheme extends Themelet
|
||||
{
|
||||
|
||||
|
||||
public function display_selector(Page $page, $actions, $query)
|
||||
{
|
||||
global $user;
|
||||
|
@ -33,7 +31,7 @@ class BulkActionsTheme extends Themelet
|
|||
}
|
||||
|
||||
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_selected_ids' />" .
|
||||
"<input type='hidden' name='bulk_action' value='" . $action["action"] . "' />" .
|
||||
|
|
|
@ -299,7 +299,8 @@ class CronUploader extends Extension
|
|||
}
|
||||
try {
|
||||
$database->rollback();
|
||||
} catch (Exception $e) {}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,8 +331,7 @@ class CronUploader extends Extension
|
|||
// Move to corrupt dir
|
||||
$newDir .= "/failed_to_upload/".$output_subdir.$relativeDir;
|
||||
$info = "ERROR: Image was not uploaded.";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$newDir .= "/uploaded/".$output_subdir.$relativeDir;
|
||||
$info = "Image successfully uploaded. ";
|
||||
}
|
||||
|
|
|
@ -97,8 +97,15 @@ class PixelFileHandler extends DataHandlerExtension
|
|||
try {
|
||||
$info = getimagesize($inname);
|
||||
$tsize = get_thumbnail_size_scaled($info[0], $info[1]);
|
||||
$image = image_resize_gd($inname, $info, $tsize[0], $tsize[1],
|
||||
$outname, $config->get_string('thumb_type'),$config->get_int('thumb_quality'));
|
||||
$image = image_resize_gd(
|
||||
$inname,
|
||||
$info,
|
||||
$tsize[0],
|
||||
$tsize[1],
|
||||
$outname,
|
||||
$config->get_string('thumb_type'),
|
||||
$config->get_int('thumb_quality')
|
||||
);
|
||||
} catch (InsufficientMemoryException $e) {
|
||||
$tsize = get_thumbnail_max_size_scaled();
|
||||
$thumb = imagecreatetruecolor($tsize[0], min($tsize[1], 64));
|
||||
|
|
|
@ -172,7 +172,6 @@ class Ratings extends Extension
|
|||
if ($user->is_admin()) {
|
||||
$event->add_action("bulk_rate", "Set Rating", "", $this->theme->get_selection_rater_html("bulk_rating"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function onBulkAction(BulkActionEvent $event)
|
||||
|
|
|
@ -46,7 +46,8 @@ class RatingsTheme extends Themelet
|
|||
$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."'>
|
||||
<option value='s'>Safe</option>
|
||||
<option value='q'>Questionable</option>
|
||||
|
|
|
@ -71,7 +71,6 @@ class RegenThumb extends Extension
|
|||
if ($user->can("delete_image")) {
|
||||
$event->add_action("bulk_regen", "Regen Thumbnails", "", $this->theme->bulk_html());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function onBulkAction(BulkActionEvent $event)
|
||||
|
@ -83,8 +82,7 @@ class RegenThumb extends Extension
|
|||
if ($user->can("delete_image")) {
|
||||
$force = true;
|
||||
if (isset($_POST["bulk_regen_thumb_missing_only"])
|
||||
&&$_POST["bulk_regen_thumb_missing_only"]=="true")
|
||||
{
|
||||
&&$_POST["bulk_regen_thumb_missing_only"]=="true") {
|
||||
$force=false;
|
||||
}
|
||||
|
||||
|
@ -110,7 +108,8 @@ class RegenThumb extends Extension
|
|||
$this->theme->display_admin_block();
|
||||
}
|
||||
|
||||
public function onAdminAction(AdminActionEvent $event) {
|
||||
public function onAdminAction(AdminActionEvent $event)
|
||||
{
|
||||
global $database;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -190,7 +189,7 @@ class RegenThumb extends Extension
|
|||
return $database->get_all($query, $args);
|
||||
}
|
||||
|
||||
function remove_dir_recursively($dir)
|
||||
public function remove_dir_recursively($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
|
@ -207,5 +206,4 @@ class RegenThumb extends Extension
|
|||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ class RegenThumbTheme extends Themelet
|
|||
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>";
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,7 @@ class RegenThumbTheme extends Themelet
|
|||
<tr><td colspan='2'><input type='submit' value='Regenerate Thumbnails'></td></tr>
|
||||
</table>
|
||||
</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'>
|
||||
<tr><th><label for='delete_thumb_type'>Type</label></th><td>
|
||||
<select name='delete_thumb_type' id='delete_thumb_type' value='1000'>
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
/*
|
||||
* 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
|
||||
|
@ -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");
|
||||
} else {
|
||||
if (isset($_POST['transcode_format'])) {
|
||||
|
||||
try {
|
||||
$this->transcode_and_replace_image($image_obj, $_POST['transcode_format']);
|
||||
$page->set_mode("redirect");
|
||||
|
@ -216,7 +217,6 @@ class TranscodeImage extends Extension
|
|||
if ($user->is_admin()) {
|
||||
$event->add_action("bulk_transcode", "Transcode", "", $this->theme->get_transcode_picker_html($this->get_supported_output_formats($engine)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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());
|
||||
try {
|
||||
$database->rollback();
|
||||
} catch (Exception $e) {}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
flash_message("Transcoded $total items");
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function clean_format($format): ?string {
|
||||
private function clean_format($format): ?string
|
||||
{
|
||||
if (array_key_exists($format, self::FORMAT_ALIASES)) {
|
||||
return self::FORMAT_ALIASES[$format];
|
||||
}
|
||||
|
@ -327,7 +328,6 @@ class TranscodeImage extends Extension
|
|||
@unlink($tmp_filename);
|
||||
|
||||
send_event(new ImageReplaceEvent($image_obj->id, $new_image));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -356,7 +356,6 @@ class TranscodeImage extends Extension
|
|||
case "convert":
|
||||
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
|
||||
|
@ -418,8 +417,7 @@ class TranscodeImage extends Extension
|
|||
$q = $config->get_int("transcode_quality");
|
||||
$convert = $config->get_string("thumb_convert_path");
|
||||
|
||||
if($convert==null||$convert=="")
|
||||
{
|
||||
if ($convert==null||$convert=="") {
|
||||
throw new ImageTranscodeException("ImageMagick path not configured");
|
||||
}
|
||||
$ext = $this->determine_ext($target_format);
|
||||
|
@ -455,5 +453,4 @@ class TranscodeImage extends Extension
|
|||
|
||||
return $tmp_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,14 +20,14 @@ class TranscodeImageTheme extends Themelet
|
|||
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' >";
|
||||
foreach ($options as $display=>$value) {
|
||||
$html .= "<option value='$value'>$display</option>";
|
||||
}
|
||||
|
||||
return $html."</select>";
|
||||
|
||||
}
|
||||
|
||||
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 Block($title, $message));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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->metadata["extension"] = $this->type;
|
||||
}
|
||||
|
||||
public function set_tmpname(String $tmpname) {
|
||||
public function set_tmpname(String $tmpname)
|
||||
{
|
||||
$this->tmpname = $tmpname;
|
||||
$this->metadata['hash'] = md5_file($tmpname);
|
||||
$this->metadata['size'] = filesize($tmpname);
|
||||
|
|
Reference in a new issue