diff --git a/core/polyfills.php b/core/polyfills.php index d4299a28..33be6cec 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -556,17 +556,41 @@ function to_shorthand_int(int $int): string return (string)$int; } } - -const TIME_UNITS = ["s"=>60,"m"=>60,"h"=>24,"d"=>365,"y"=>PHP_INT_MAX]; -function format_milliseconds(int $input): string +abstract class TIME_UNITS +{ + public const MILLISECONDS = "ms"; + public const SECONDS = "s"; + public const MINUTES = "m"; + public const HOURS = "h"; + public const DAYS = "d"; + public const YEARS = "y"; + public const CONVERSION = [ + self::MILLISECONDS=>1000, + self::SECONDS=>60, + self::MINUTES=>60, + self::HOURS=>24, + self::DAYS=>365, + self::YEARS=>PHP_INT_MAX + ]; +} +function format_milliseconds(int $input, string $min_unit = TIME_UNITS::SECONDS): string { $output = ""; - $remainder = floor($input / 1000); + $remainder = $input; - foreach (TIME_UNITS as $unit=>$conversion) { + $found = false; + + foreach (TIME_UNITS::CONVERSION as $unit=>$conversion) { $count = $remainder % $conversion; $remainder = floor($remainder / $conversion); + + if ($found||$unit==$min_unit) { + $found = true; + } else { + continue; + } + if ($count==0&&$remainder<1) { break; } @@ -575,6 +599,32 @@ function format_milliseconds(int $input): string return trim($output); } +function parse_to_milliseconds(string $input): int +{ + $output = 0; + $current_multiplier = 1; + + if (preg_match('/^([0-9]+)$/i', $input, $match)) { + // If just a number, then we treat it as milliseconds + $length = $match[0]; + if (is_numeric($length)) { + $length = floatval($length); + $output += $length; + } + } else { + foreach (TIME_UNITS::CONVERSION as $unit=>$conversion) { + if (preg_match('/([0-9]+)'.$unit.'/i', $input, $match)) { + $length = $match[1]; + if (is_numeric($length)) { + $length = floatval($length); + $output += $length * $current_multiplier; + } + } + $current_multiplier *= $conversion; + } + } + return intval($output); +} /** * Turn a date into a time, a date, an "X minutes ago...", etc diff --git a/core/tests/polyfills.test.php b/core/tests/polyfills.test.php index 9ca56d33..de44f4c3 100644 --- a/core/tests/polyfills.test.php +++ b/core/tests/polyfills.test.php @@ -105,6 +105,13 @@ class PolyfillsTest extends TestCase $this->assertEquals("1y 213d 16h 53m 20s", format_milliseconds(50000000000)); } + public function test_parse_to_milliseconds() + { + $this->assertEquals(10, parse_to_milliseconds("10")); + $this->assertEquals(5000, parse_to_milliseconds("5s")); + $this->assertEquals(50000000000, parse_to_milliseconds("1y 213d 16h 53m 20s")); + } + public function test_autodate() { $this->assertEquals( diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index f43c12dd..be707e4c 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -462,6 +462,9 @@ class CronUploader extends Extension // Generate info message if ($event->image_id == -1) { + if(array_key_exists("mime",$event->metadata)) { + throw new UploadException("File type not recognised (".$event->metadata["mime"]."). Filename: {$filename}"); + } throw new UploadException("File type not recognised. Filename: {$filename}"); } elseif ($event->merged === true) { $infomsg = "Image merged. ID: {$event->image_id} - Filename: {$filename}"; diff --git a/ext/featured/info.php b/ext/featured/info.php index 23e42a90..dc3e8bad 100644 --- a/ext/featured/info.php +++ b/ext/featured/info.php @@ -5,7 +5,7 @@ class FeaturedInfo extends ExtensionInfo public const KEY = "featured"; public $key = self::KEY; - public $name = "Featured Image"; + public $name = "Featured Post"; public $url = self::SHIMMIE_URL; public $authors = self::SHISH_AUTHOR; public $license = self::LICENSE_GPLV2; @@ -15,9 +15,9 @@ class FeaturedInfo extends ExtensionInfo to the other image control buttons (delete, rotate, etc). Clicking it will set the image as the site's current feature, which will be shown in the side bar of the post list. -

Viewing a featured image +

Viewing a featured post
Visit /featured_image/view -

Downloading a featured image +

Downloading a featured post
Link to /featured_image/download. This will give the raw data for an image (no HTML). This is useful so that you can set your desktop wallpaper to be the download URL, refreshed diff --git a/ext/featured/main.php b/ext/featured/main.php index 8e427c7f..f0227766 100644 --- a/ext/featured/main.php +++ b/ext/featured/main.php @@ -20,7 +20,7 @@ class Featured extends Extension $id = int_escape($_POST['image_id']); if ($id > 0) { $config->set_int("featured_id", $id); - log_info("featured", "Featured image set to >>$id", "Featured image set"); + log_info("featured", "Featured post set to >>$id", "Featured post set"); $page->set_mode(PageMode::REDIRECT); $page->set_redirect(make_link("post/view/$id")); } diff --git a/ext/featured/test.php b/ext/featured/test.php index bd3a7c1f..66de698e 100644 --- a/ext/featured/test.php +++ b/ext/featured/test.php @@ -18,7 +18,7 @@ class FeaturedTest extends ShimmiePHPUnitTestCase $config->set_int("featured_id", $image_id); $this->get_page("post/list"); - $this->assert_text("Featured Image"); + $this->assert_text("Featured Post"); # FIXME: test changing from one feature to another @@ -31,6 +31,6 @@ class FeaturedTest extends ShimmiePHPUnitTestCase // after deletion, there should be no feature $this->delete_image($image_id); $this->get_page("post/list"); - $this->assert_no_text("Featured Image"); + $this->assert_no_text("Featured Post"); } } diff --git a/ext/featured/theme.php b/ext/featured/theme.php index d82c1a32..8d94d3fc 100644 --- a/ext/featured/theme.php +++ b/ext/featured/theme.php @@ -8,7 +8,7 @@ class FeaturedTheme extends Themelet { public function display_featured(Page $page, Image $image): void { - $page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3)); + $page->add_block(new Block("Featured Post", $this->build_featured_html($image), "left", 3)); } public function get_buttons_html(int $image_id): string diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 8dd4eb60..a941d3ef 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -60,7 +60,7 @@ class VideoFileHandlerTheme extends Themelet $html .= "

Searching is largely based on tags, with a number of special keywords available that allow searching based on properties of the images.

+ return '

Searching is largely based on tags, with a number of special keywords available that allow searching based on properties of the posts.

tagname
-

Returns images that are tagged with "tagname".

+

Returns posts that are tagged with "tagname".

tagname othertagname
-

Returns images that are tagged with "tagname" and "othertagname".

+

Returns posts that are tagged with "tagname" and "othertagname".

-

Most tags and keywords can be prefaced with a negative sign (-) to indicate that you want to search for images that do not match something.

+

Most tags and keywords can be prefaced with a negative sign (-) to indicate that you want to search for posts that do not match something.

-tagname
-

Returns images that are not tagged with "tagname".

+

Returns posts that are not tagged with "tagname".

-tagname -othertagname
-

Returns images that are not tagged with "tagname" and "othertagname". This is different than without the negative sign, as images with "tagname" or "othertagname" can still be returned as long as the other one is not present.

+

Returns posts that are not tagged with "tagname" and "othertagname". This is different than without the negative sign, as posts with "tagname" or "othertagname" can still be returned as long as the other one is not present.

tagname -othertagname
-

Returns images that are tagged with "tagname", but are not tagged with "othertagname".

+

Returns posts that are tagged with "tagname", but are not tagged with "othertagname".

Wildcard searches are possible as well using * for "any one, more, or none" and ? for "any one".

tagn*
-

Returns images that are tagged with "tagname", "tagnot", or anything else that starts with "tagn".

+

Returns posts that are tagged with "tagname", "tagnot", or anything else that starts with "tagn".

tagn?me
-

Returns images that are tagged with "tagname", "tagnome", or anything else that starts with "tagn", has one character, and ends with "me".

+

Returns posts that are tagged with "tagname", "tagnome", or anything else that starts with "tagn", has one character, and ends with "me".

tags=1
-

Returns images with exactly 1 tag.

+

Returns posts with exactly 1 tag.

tags>0
-

Returns images with 1 or more tags.

+

Returns posts with 1 or more tags.

Can use <, <=, >, >=, or =.


-

Search for images by aspect ratio

+

Search for posts by aspect ratio

ratio=4:3
-

Returns images with an aspect ratio of 4:3.

+

Returns posts with an aspect ratio of 4:3.

ratio>16:9
-

Returns images with an aspect ratio greater than 16:9.

+

Returns posts with an aspect ratio greater than 16:9.

Can use <, <=, >, >=, or =. The relation is calculated by dividing width by height.


-

Search for images by file size

+

Search for posts by file size

filesize=1
-

Returns images exactly 1 byte in size.

+

Returns posts exactly 1 byte in size.

filesize>100mb
-

Returns images greater than 100 megabytes in size.

+

Returns posts greater than 100 megabytes in size.

Can use <, <=, >, >=, or =. Supported suffixes are kb, mb, and gb. Uses multiples of 1024.


-

Search for images by MD5 hash

+

Search for posts by MD5 hash

hash=0D3512CAA964B2BA5D7851AF5951F33B
@@ -277,65 +277,86 @@ and of course start organising your images :-)
-

Search for images by file name

+

Search for posts by file name

filename=picasso.jpg
-

Returns images that are named "picasso.jpg".

+

Returns posts that are named "picasso.jpg".


-

Search for images by source

+

Search for posts by source

source=http://google.com/
-

Returns images with a source of "http://google.com/".

+

Returns posts with a source of "http://google.com/".

source=any
-

Returns images with a source set.

+

Returns posts with a source set.

source=none
-

Returns images without a source set.

+

Returns posts without a source set.


-

Search for images by date posted.

+

Search for posts by date posted.

posted>=07-19-2019
-

Returns images posted on or after 07-19-2019.

+

Returns posts posted on or after 07-19-2019.

Can use <, <=, >, >=, or =. Date format is mm-dd-yyyy. Date posted includes time component, so = will not work unless the time is exact.


-

Search for images by image dimensions

+

Search for posts by length.

+ +
+
length>=1h
+

Returns posts that are longer than an hour.

+
+ +
+
length<=10h15m
+

Returns posts that are shorter than 10 hours and 15 minutes.

+
+ +
+
length>=10000
+

Returns posts that are longer than 10,000 milliseconds, or 10 seconds.

+
+ +

Can use <, <=, >, >=, or =. Available suffixes are ms, s, m, h, d, and y. A number by itself will be interpreted as milliseconds. Searches using = are not likely to work unless time is specified down to the millisecond.

+ +
+ +

Search for posts by dimensions

size=640x480
-

Returns images exactly 640 pixels wide by 480 pixels high.

+

Returns posts exactly 640 pixels wide by 480 pixels high.

size>1920x1080
-

Returns images with a width larger than 1920 and a height larger than 1080.

+

Returns posts with a width larger than 1920 and a height larger than 1080.

width=1000
-

Returns images exactly 1000 pixels wide.

+

Returns posts exactly 1000 pixels wide.

height=1000
-

Returns images exactly 1000 pixels high.

+

Returns posts exactly 1000 pixels high.

Can use <, <=, >, >=, or =.

@@ -346,12 +367,12 @@ and of course start organising your images :-)
order:id_asc
-

Returns images sorted by ID, smallest first.

+

Returns posts sorted by ID, smallest first.

order:width_desc
-

Returns images sorted by width, largest first.

+

Returns posts sorted by width, largest first.

These fields are supported: diff --git a/ext/media/media_engine.php b/ext/media/media_engine.php index 5f1d8a39..bb10ae1e 100644 --- a/ext/media/media_engine.php +++ b/ext/media/media_engine.php @@ -55,6 +55,7 @@ abstract class MediaEngine MimeType::GIF, MimeType::JPEG, MimeType::PNG, + MimeType::PPM, MimeType::PSD, MimeType::TIFF, MimeType::WEBP, diff --git a/ext/mime/file_extension.php b/ext/mime/file_extension.php index 0f093fab..e570ae4d 100644 --- a/ext/mime/file_extension.php +++ b/ext/mime/file_extension.php @@ -46,6 +46,7 @@ class FileExtension public const PHP5 = 'php5'; public const PNG = 'png'; public const PSD = 'psd'; + public const PPM = 'ppm'; public const MOV = 'mov'; public const RSS = 'rss'; public const SVG = 'svg'; diff --git a/ext/mime/mime_map.php b/ext/mime/mime_map.php index a434f782..23245ae4 100644 --- a/ext/mime/mime_map.php +++ b/ext/mime/mime_map.php @@ -144,6 +144,11 @@ class MimeMap self::MAP_EXT => [FileExtension::PNG], self::MAP_MIME => [MimeType::PNG], ], + MimeType::PPM => [ + self::MAP_NAME => "Portable Pixel Map", + self::MAP_EXT => [FileExtension::PPM], + self::MAP_MIME => [MimeType::PPM], + ], MimeType::PSD => [ self::MAP_NAME => "PSD", self::MAP_EXT => [FileExtension::PSD], diff --git a/ext/mime/mime_type.php b/ext/mime/mime_type.php index eec112c9..99667a52 100644 --- a/ext/mime/mime_type.php +++ b/ext/mime/mime_type.php @@ -38,6 +38,7 @@ class MimeType public const PDF = 'application/pdf'; public const PHP = 'text/x-php'; public const PNG = 'image/png'; + public const PPM = 'image/x-portable-pixmap'; public const PSD = 'image/vnd.adobe.photoshop'; public const QUICKTIME = 'video/quicktime'; public const RSS = 'application/rss+xml'; @@ -242,6 +243,9 @@ class MimeType case FileExtension::ANI: $output = MimeType::ANI; break; + case FileExtension::PPM: + $output = MimeType::PPM; + break; // TODO: There is no uniquely defined Mime type for the cursor format. Need to figure this out. // case FileExtension::CUR: // $output = MimeType::CUR; diff --git a/ext/transcode/main.php b/ext/transcode/main.php index 8eb8b016..7fb9b92d 100644 --- a/ext/transcode/main.php +++ b/ext/transcode/main.php @@ -22,6 +22,7 @@ class TranscodeImage extends Extension "ICO" => MimeType::ICO, "JPG" => MimeType::JPEG, "PNG" => MimeType::PNG, + "PPM" => MimeType::PPM, "PSD" => MimeType::PSD, "TIFF" => MimeType::TIFF, "WEBP" => MimeType::WEBP