commit
547c6d98da
@ -258,6 +258,20 @@ class Database
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an SQL query and return the the first column => the second column as an iterable object.
|
||||||
|
*/
|
||||||
|
public function get_pairs_iterable(string $query, array $args = []): Generator
|
||||||
|
{
|
||||||
|
$_start = microtime(true);
|
||||||
|
$stmt = $this->execute($query, $args);
|
||||||
|
$this->count_time("get_pairs_iterable", $_start, $query, $args);
|
||||||
|
foreach ($stmt as $row) {
|
||||||
|
yield $row[0] => $row[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute an SQL query and return a single value, or null.
|
* Execute an SQL query and return a single value, or null.
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +61,7 @@ abstract class Extension
|
|||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function determine_enabled_extensions()
|
public static function determine_enabled_extensions(): void
|
||||||
{
|
{
|
||||||
self::$enabled_extensions = [];
|
self::$enabled_extensions = [];
|
||||||
foreach (array_merge(
|
foreach (array_merge(
|
||||||
@ -138,6 +138,7 @@ abstract class ExtensionInfo
|
|||||||
public $license;
|
public $license;
|
||||||
public $version;
|
public $version;
|
||||||
public $dependencies = [];
|
public $dependencies = [];
|
||||||
|
public $conflicts = [];
|
||||||
public $visibility;
|
public $visibility;
|
||||||
public $description;
|
public $description;
|
||||||
public $documentation;
|
public $documentation;
|
||||||
@ -193,6 +194,13 @@ abstract class ExtensionInfo
|
|||||||
if (!empty($this->db_support) && !in_array($database->get_driver_name(), $this->db_support)) {
|
if (!empty($this->db_support) && !in_array($database->get_driver_name(), $this->db_support)) {
|
||||||
$this->support_info .= "Database not supported. ";
|
$this->support_info .= "Database not supported. ";
|
||||||
}
|
}
|
||||||
|
if (!empty($this->conflicts)) {
|
||||||
|
$intersects = array_intersect($this->conflicts, Extension::get_enabled_extensions());
|
||||||
|
if (!empty($intersects)) {
|
||||||
|
$this->support_info .= "Conflicts with other extension(s): " . join(", ", $intersects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Additional checks here as needed
|
// Additional checks here as needed
|
||||||
|
|
||||||
$this->supported = empty($this->support_info);
|
$this->supported = empty($this->support_info);
|
||||||
|
@ -187,3 +187,27 @@ function create_scaled_image(string $inname, string $outname, array $tsize, stri
|
|||||||
true
|
true
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function redirect_to_next_image(Image $image): void
|
||||||
|
{
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
if (isset($_GET['search'])) {
|
||||||
|
$search_terms = Tag::explode(Tag::decaret($_GET['search']));
|
||||||
|
$query = "search=" . url_escape($_GET['search']);
|
||||||
|
} else {
|
||||||
|
$search_terms = [];
|
||||||
|
$query = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$target_image = $image->get_next($search_terms);
|
||||||
|
|
||||||
|
if ($target_image == null) {
|
||||||
|
$redirect_target = referer_or(make_link("post/list"), ['post/view']);
|
||||||
|
} else {
|
||||||
|
$redirect_target = make_link("post/view/{$target_image->id}", null, $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
|
$page->set_redirect($redirect_target);
|
||||||
|
}
|
||||||
|
@ -23,4 +23,8 @@ abstract class ImageConfig
|
|||||||
|
|
||||||
const COLLISION_MERGE = 'merge';
|
const COLLISION_MERGE = 'merge';
|
||||||
const COLLISION_ERROR = 'error';
|
const COLLISION_ERROR = 'error';
|
||||||
|
|
||||||
|
const ON_DELETE = 'image_on_delete';
|
||||||
|
const ON_DELETE_NEXT = 'next';
|
||||||
|
const ON_DELETE_LIST = 'list';
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ class ImageIO extends Extension
|
|||||||
'Merge'=>ImageConfig::COLLISION_MERGE
|
'Merge'=>ImageConfig::COLLISION_MERGE
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ON_DELETE_OPTIONS = [
|
||||||
|
'Return to post list'=>ImageConfig::ON_DELETE_LIST,
|
||||||
|
'Go to next image'=>ImageConfig::ON_DELETE_NEXT
|
||||||
|
];
|
||||||
|
|
||||||
const EXIF_READ_FUNCTION = "exif_read_data";
|
const EXIF_READ_FUNCTION = "exif_read_data";
|
||||||
|
|
||||||
const THUMBNAIL_ENGINES = [
|
const THUMBNAIL_ENGINES = [
|
||||||
@ -70,16 +75,22 @@ class ImageIO extends Extension
|
|||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
if ($event->page_matches("image/delete")) {
|
if ($event->page_matches("image/delete")) {
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
if ($user->can(Permissions::DELETE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) {
|
if ($user->can(Permissions::DELETE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) {
|
||||||
$image = Image::by_id(int_escape($_POST['image_id']));
|
$image = Image::by_id(int_escape($_POST['image_id']));
|
||||||
if ($image) {
|
if ($image) {
|
||||||
send_event(new ImageDeletionEvent($image));
|
send_event(new ImageDeletionEvent($image));
|
||||||
|
|
||||||
|
if ($config->get_string(ImageConfig::ON_DELETE)===ImageConfig::ON_DELETE_NEXT) {
|
||||||
|
redirect_to_next_image($image);
|
||||||
|
} else {
|
||||||
$page->set_mode(PageMode::REDIRECT);
|
$page->set_mode(PageMode::REDIRECT);
|
||||||
$page->set_redirect(referer_or(make_link("post/list"), ['post/view']));
|
$page->set_redirect(referer_or(make_link("post/list"), ['post/view']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} elseif ($event->page_matches("image/replace")) {
|
} elseif ($event->page_matches("image/replace")) {
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
if ($user->can(Permissions::REPLACE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) {
|
if ($user->can(Permissions::REPLACE_IMAGE) && isset($_POST['image_id']) && $user->check_auth_token()) {
|
||||||
@ -254,6 +265,7 @@ class ImageIO extends Extension
|
|||||||
$sb->add_text_option(ImageConfig::TIP, "Image tooltip", true);
|
$sb->add_text_option(ImageConfig::TIP, "Image tooltip", true);
|
||||||
$sb->add_text_option(ImageConfig::INFO, "Image info", true);
|
$sb->add_text_option(ImageConfig::INFO, "Image info", true);
|
||||||
$sb->add_choice_option(ImageConfig::UPLOAD_COLLISION_HANDLER, self::COLLISION_OPTIONS, "Upload collision handler", true);
|
$sb->add_choice_option(ImageConfig::UPLOAD_COLLISION_HANDLER, self::COLLISION_OPTIONS, "Upload collision handler", true);
|
||||||
|
$sb->add_choice_option(ImageConfig::ON_DELETE, self::ON_DELETE_OPTIONS, "On Delete", true);
|
||||||
if (function_exists(self::EXIF_READ_FUNCTION)) {
|
if (function_exists(self::EXIF_READ_FUNCTION)) {
|
||||||
$sb->add_bool_option(ImageConfig::SHOW_META, "Show metadata", true);
|
$sb->add_bool_option(ImageConfig::SHOW_META, "Show metadata", true);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ class Index extends Extension
|
|||||||
} elseif (preg_match("/^(phash)[=|:]([0-9a-fA-F]*)$/i", $event->term, $matches)) {
|
} elseif (preg_match("/^(phash)[=|:]([0-9a-fA-F]*)$/i", $event->term, $matches)) {
|
||||||
$phash = strtolower($matches[2]);
|
$phash = strtolower($matches[2]);
|
||||||
$event->add_querylet(new Querylet('images.phash = :phash', ["phash" => $phash]));
|
$event->add_querylet(new Querylet('images.phash = :phash', ["phash" => $phash]));
|
||||||
} elseif (preg_match("/^(filename|name)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
} elseif (preg_match("/^(filename|name)[=|:](.+)$/i", $event->term, $matches)) {
|
||||||
$filename = strtolower($matches[2]);
|
$filename = strtolower($matches[2]);
|
||||||
$event->add_querylet(new Querylet("lower(images.filename) LIKE :filename{$this->stpen}", ["filename{$this->stpen}"=>"%$filename%"]));
|
$event->add_querylet(new Querylet("lower(images.filename) LIKE :filename{$this->stpen}", ["filename{$this->stpen}"=>"%$filename%"]));
|
||||||
} elseif (preg_match("/^(source)[=|:](.*)$/i", $event->term, $matches)) {
|
} elseif (preg_match("/^(source)[=|:](.*)$/i", $event->term, $matches)) {
|
||||||
|
@ -581,7 +581,7 @@ class Media extends Extension
|
|||||||
$resize_suffix .= "\!";
|
$resize_suffix .= "\!";
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = "";
|
$args = " -auto-orient ";
|
||||||
$resize_arg = "-resize";
|
$resize_arg = "-resize";
|
||||||
if ($minimize) {
|
if ($minimize) {
|
||||||
$args .= "-strip ";
|
$args .= "-strip ";
|
||||||
@ -611,8 +611,8 @@ class Media extends Extension
|
|||||||
case Media::RESIZE_TYPE_FIT_BLUR:
|
case Media::RESIZE_TYPE_FIT_BLUR:
|
||||||
$blur_size = max(ceil(max($new_width, $new_height) / 25), 5);
|
$blur_size = max(ceil(max($new_width, $new_height) / 25), 5);
|
||||||
$args .= "${file_arg} ".
|
$args .= "${file_arg} ".
|
||||||
"\( -clone 0 -resize ${new_width}x${new_height}\^ -background ${bg} -flatten -gravity center -fill black -colorize 50% -extent ${new_width}x${new_height} -blur 0x${blur_size} \) ".
|
"\( -clone 0 -auto-orient -resize ${new_width}x${new_height}\^ -background ${bg} -flatten -gravity center -fill black -colorize 50% -extent ${new_width}x${new_height} -blur 0x${blur_size} \) ".
|
||||||
"\( -clone 0 -resize ${new_width}x${new_height} \) ".
|
"\( -clone 0 -auto-orient -resize ${new_width}x${new_height} \) ".
|
||||||
"-delete 0 -gravity center -compose over -composite";
|
"-delete 0 -gravity center -compose over -composite";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -131,15 +131,17 @@ class MimeType
|
|||||||
if (($fh = @fopen($image_filename, 'rb'))) {
|
if (($fh = @fopen($image_filename, 'rb'))) {
|
||||||
try {
|
try {
|
||||||
//check if gif is animated (via https://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
|
//check if gif is animated (via https://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
|
||||||
|
$chunk = false;
|
||||||
|
|
||||||
while (!feof($fh) && $is_anim_gif < 2) {
|
while (!feof($fh) && $is_anim_gif < 2) {
|
||||||
$chunk = fread($fh, 1024 * 100);
|
$chunk = ($chunk ? substr($chunk, -20) : "") . fread($fh, 1024 * 100); //read 100kb at a time
|
||||||
$is_anim_gif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
|
$is_anim_gif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@fclose($fh);
|
@fclose($fh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ($is_anim_gif == 0);
|
return ($is_anim_gif >=2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user