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 .= "