resolve conflicts

joe/cache-regex-fix
butterbutt 1 year ago
commit 0424030487
Signed by: butterbutt
GPG Key ID: 4D2AD715BC930E49
  1. 32
      .github/workflows/test_and_publish.yml
  2. 2
      Dockerfile
  3. 15
      composer.json
  4. 2635
      composer.lock
  5. 96
      core/basepage.php
  6. 2
      core/basethemelet.php
  7. 28
      core/block.php
  8. 31
      core/cacheengine.php
  9. 6
      core/command_builder.php
  10. 12
      core/config.php
  11. 17
      core/database.php
  12. 36
      core/dbengine.php
  13. 59
      core/event.php
  14. 22
      core/exceptions.php
  15. 67
      core/extension.php
  16. 48
      core/imageboard/event.php
  17. 94
      core/imageboard/image.php
  18. 18
      core/imageboard/search.php
  19. 2
      core/install.php
  20. 4
      core/permissions.php
  21. 18
      core/polyfills.php
  22. 2
      core/sys_config.php
  23. 4
      core/urls.php
  24. 22
      core/user.php
  25. 23
      core/userclass.php
  26. 22
      core/util.php
  27. 24
      ext/admin/info.php
  28. 57
      ext/admin/main.php
  29. 53
      ext/admin/test.php
  30. 38
      ext/admin/theme.php
  31. 16
      ext/alias_editor/info.php
  32. 10
      ext/alias_editor/main.php
  33. 10
      ext/approval/info.php
  34. 2
      ext/approval/main.php
  35. 8
      ext/approval/theme.php
  36. 14
      ext/artists/info.php
  37. 13
      ext/artists/main.php
  38. 2
      ext/artists/theme.php
  39. 10
      ext/auto_tagger/info.php
  40. 10
      ext/auto_tagger/main.php
  41. 10
      ext/autocomplete/info.php
  42. 62
      ext/autocomplete/main.php
  43. 4
      ext/autocomplete/script.js
  44. 14
      ext/ban_words/info.php
  45. 3
      ext/ban_words/main.php
  46. 51
      ext/bbcode/info.php
  47. 4
      ext/bbcode/test.php
  48. 13
      ext/biography/info.php
  49. 34
      ext/biography/main.php
  50. 18
      ext/biography/test.php
  51. 25
      ext/biography/theme.php
  52. 12
      ext/blocks/info.php
  53. 2
      ext/blocks/main.php
  54. 12
      ext/blotter/info.php
  55. 5
      ext/blotter/main.php
  56. 8
      ext/blotter/theme.php
  57. 16
      ext/browser_search/info.php
  58. 3
      ext/browser_search/main.php
  59. 12
      ext/bulk_actions/info.php
  60. 35
      ext/bulk_actions/main.php
  61. 28
      ext/bulk_actions/script.js
  62. 6
      ext/bulk_actions/theme.php
  63. 14
      ext/bulk_add/info.php
  64. 6
      ext/bulk_add/main.php
  65. 2
      ext/bulk_add/theme.php
  66. 14
      ext/bulk_add_csv/info.php
  67. 2
      ext/bulk_add_csv/main.php
  68. 2
      ext/bulk_add_csv/theme.php
  69. 12
      ext/bulk_download/info.php
  70. 4
      ext/bulk_download/main.php
  71. 8
      ext/bulk_import_export/events.php
  72. 12
      ext/bulk_import_export/info.php
  73. 4
      ext/bulk_import_export/main.php
  74. 16
      ext/comment/info.php
  75. 62
      ext/comment/main.php
  76. 12
      ext/comment/theme.php
  77. 58
      ext/cron_uploader/config.php
  78. 12
      ext/cron_uploader/info.php
  79. 183
      ext/cron_uploader/main.php
  80. 7
      ext/cron_uploader/script.js
  81. 70
      ext/cron_uploader/theme.php
  82. 14
      ext/custom_html_headers/info.php
  83. 4
      ext/custom_html_headers/main.php
  84. 10
      ext/danbooru_api/info.php
  85. 15
      ext/danbooru_api/main.php
  86. 10
      ext/download/events.php
  87. 14
      ext/download/info.php
  88. 14
      ext/downtime/info.php
  89. 7
      ext/downtime/main.php
  90. 16
      ext/emoticons/info.php
  91. 14
      ext/emoticons_list/info.php
  92. 2
      ext/emoticons_list/main.php
  93. 12
      ext/eokm/info.php
  94. 5
      ext/eokm/main.php
  95. 16
      ext/et/info.php
  96. 4
      ext/et/main.php
  97. 2
      ext/et/theme.php
  98. 16
      ext/et_server/info.php
  99. 18
      ext/ext_manager/info.php
  100. 6
      ext/ext_manager/main.php
  101. Some files were not shown because too many files have changed in this diff Show More

@ -7,12 +7,40 @@ on:
- cron: '0 2 * * 0' # Weekly on Sundays at 02:00
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set Up Cache
uses: actions/cache@v2
with:
path: |
vendor
key: php-cs-fixer-${{ hashFiles('composer.lock') }}
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install PHP dependencies
run: composer update && composer install --prefer-dist --no-progress
- name: Set up PHP
uses: shivammathur/setup-php@master
with:
php-version: 7.4
- name: Check format
run: ./vendor/bin/php-cs-fixer fix --dry-run
test:
name: PHP ${{ matrix.php }} / DB ${{ matrix.database }}
strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
php: ['7.4', '8.0']
database: ['pgsql', 'mysql', 'sqlite']
runs-on: ubuntu-latest
@ -86,7 +114,7 @@ jobs:
publish:
name: Publish
runs-on: ubuntu-latest
needs: test
needs: [format, test]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@master

@ -35,7 +35,7 @@ RUN curl -k -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa
# Actually run shimmie
FROM debian:testing-slim
EXPOSE 8000
HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://127.0.0.1:8000/ || exit 1
HEALTHCHECK --interval=1m --timeout=3s CMD curl --fail http://127.0.0.1:8000/ || exit 1
ENV UID=1000 \
GID=1000
RUN apt update && apt install -y curl \

@ -5,6 +5,12 @@
"license" : "GPL-2.0-or-later",
"minimum-stability" : "dev",
"config": {
"platform": {
"php": "7.4.0"
}
},
"repositories" : [
{
"type": "composer",
@ -25,7 +31,7 @@
],
"require" : {
"php" : "^7.3 | ^8.0",
"php" : "^7.4 | ^8.0",
"ext-pdo": "*",
"ext-json": "*",
"ext-fileinfo": "*",
@ -38,18 +44,17 @@
"shish/ffsphp" : "^1.0",
"shish/microcrud" : "^2.0",
"shish/microhtml" : "^2.0",
"enshrined/svg-sanitize" : "^0.13",
"enshrined/svg-sanitize" : "^0.14",
"bower-asset/jquery" : "^1.12",
"bower-asset/jquery-timeago" : "^1.5",
"bower-asset/mediaelement" : "^2.21",
"bower-asset/js-cookie" : "^2.1"
},
"require-dev" : {
"phpunit/phpunit" : "^9.0"
"phpunit/phpunit" : "^9.0",
"friendsofphp/php-cs-fixer" : "^2.18"
},
"suggest": {
"ext-memcache": "memcache caching",
"ext-memcached": "memcached caching",

2635
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -20,10 +20,8 @@ abstract class PageMode
*/
class BasePage
{
/** @var string */
public $mode = PageMode::PAGE;
/** @var string */
private $mime;
public string $mode = PageMode::PAGE;
private string $mime;
/**
* Set what this page should do; "page", "data", or "redirect".
@ -52,19 +50,11 @@ class BasePage
// ==============================================
/** @var string; public only for unit test */
public $data = "";
/** @var string */
private $file = null;
/** @var bool */
private $file_delete = false;
/** @var string */
private $filename = null;
private $disposition = null;
public string $data = ""; // public only for unit test
private ?string $file = null;
private bool $file_delete = false;
private ?string $filename = null;
private ?string $disposition = null;
/**
* Set the raw data to be sent.
@ -91,8 +81,7 @@ class BasePage
// ==============================================
/** @var string */
public $redirect = "";
public string $redirect = "";
/**
* Set the URL to redirect to (remember to use make_link() if linking
@ -105,32 +94,25 @@ class BasePage
// ==============================================
/** @var int */
public $code = 200;
/** @var string */
public $title = "";
/** @var string */
public $heading = "";
/** @var string */
public $subheading = "";
public int $code = 200;
public string $title = "";
public string $heading = "";
public string $subheading = "";
/** @var string[] */
public $html_headers = [];
public array $html_headers = [];
/** @var string[] */
public $http_headers = [];
public array $http_headers = [];
/** @var string[][] */
public $cookies = [];
public array $cookies = [];
/** @var Block[] */
public $blocks = [];
public array $blocks = [];
/** @var string[] */
public $flash = [];
public array $flash = [];
/**
* Set the HTTP status code
@ -355,8 +337,6 @@ class BasePage
* Why do this? Two reasons:
* 1. Reduces the number of files the user's browser needs to download.
* 2. Allows these cached files to be compressed/minified by the admin.
*
* TODO: This should really be configurable somehow...
*/
public function add_auto_html_headers(): void
{
@ -381,7 +361,7 @@ class BasePage
$css_latest = $config_latest;
$css_files = array_merge(
zglob("ext/{" . Extension::get_enabled_extensions_as_string() . "}/style.css"),
zglob("themes/$theme_name/style.css")
zglob("themes/$theme_name/{" . implode(",", $this->get_theme_stylesheets()) . "}")
);
foreach ($css_files as $css) {
$css_latest = max($css_latest, filemtime($css));
@ -411,7 +391,7 @@ class BasePage
"ext/static_files/modernizr-3.3.1.custom.js",
],
zglob("ext/{" . Extension::get_enabled_extensions_as_string() . "}/script.js"),
zglob("themes/$theme_name/script.js")
zglob("themes/$theme_name/{" . implode(",", $this->get_theme_scripts()) . "}")
);
foreach ($js_files as $js) {
$js_latest = max($js_latest, filemtime($js));
@ -428,7 +408,25 @@ class BasePage
$this->add_html_header("<script defer src='$data_href/$js_cache_file' type='text/javascript'></script>", 44);
}
protected function get_nav_links()
/**
* @return array A list of stylesheets relative to the theme root.
*/
protected function get_theme_stylesheets(): array
{
return ["style.css"];
}
/**
* @return array A list of script files relative to the theme root.
*/
protected function get_theme_scripts(): array
{
return ["script.js"];
}
protected function get_nav_links(): array
{
$pnbe = send_event(new PageNavBuildingEvent());
@ -574,7 +572,7 @@ EOD;
class PageNavBuildingEvent extends Event
{
public $links = [];
public array $links = [];
public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50)
{
@ -584,9 +582,9 @@ class PageNavBuildingEvent extends Event
class PageSubNavBuildingEvent extends Event
{
public $parent;
public string $parent;
public $links = [];
public array $links = [];
public function __construct(string $parent)
{
@ -602,11 +600,11 @@ class PageSubNavBuildingEvent extends Event
class NavLink
{
public $name;
public $link;
public $description;
public $order;
public $active = false;
public string $name;
public Link $link;
public string $description;
public int $order;
public bool $active = false;
public function __construct(String $name, Link $link, String $description, ?bool $active = null, int $order = 50)
{
@ -663,7 +661,7 @@ class NavLink
}
}
function sort_nav_links(NavLink $a, NavLink $b)
function sort_nav_links(NavLink $a, NavLink $b): int
{
return $a->order - $b->order;
}

@ -72,7 +72,7 @@ class BaseThemelet
}
}
return "<a href='$h_view_link' class='thumb shm-thumb shm-thumb-link {$custom_classes}' data-tags='$h_tags' data-post-id='$i_id'>".
return "<a href='$h_view_link' class='thumb shm-thumb shm-thumb-link {$custom_classes}' data-tags='$h_tags' data-height='$image->height' data-width='$image->width' data-mime='{$image->get_mime()}' data-post-id='$i_id'>".
"<img id='thumb_$i_id' title='$h_tip' alt='$h_tip' height='{$tsize[1]}' width='{$tsize[0]}' src='$h_thumb_link'>".
"</a>\n";
}

@ -9,49 +9,37 @@ class Block
{
/**
* The block's title.
*
* @var string
*/
public $header;
public ?string $header;
/**
* The content of the block.
*
* @var string
*/
public $body;
public ?string $body;
/**
* Where the block should be placed. The default theme supports
* "main" and "left", other themes can add their own areas.
*
* @var string
*/
public $section;
public string $section;
/**
* How far down the section the block should appear, higher
* numbers appear lower. The scale is 0-100 by convention,
* though any number will work.
*
* @var int
*/
public $position;
public int $position;
/**
* A unique ID for the block.
*
* @var string
*/
public $id;
public string $id;
/**
* Should this block count as content for the sake of
* the 404 handler
*
* @var boolean
*/
public $is_content = true;
public bool $is_content = true;
public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null)
{
@ -63,7 +51,9 @@ class Block
if (is_null($id)) {
$id = (empty($header) ? md5($body ?? '') : $header) . $section;
}
$this->id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id));
$str_id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id));
assert(is_string($str_id));
$this->id = $str_id;
}
/**

@ -2,8 +2,8 @@
interface CacheEngine
{
public function get(string $key);
public function set(string $key, $val, int $time=0);
public function delete(string $key);
public function set(string $key, $val, int $time=0): void;
public function delete(string $key): void;
}
class NoCache implements CacheEngine
@ -12,18 +12,17 @@ class NoCache implements CacheEngine
{
return false;
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
}
public function delete(string $key)
public function delete(string $key): void
{
}
}
class MemcachedCache implements CacheEngine
{
/** @var ?Memcached */
public $memcache=null;
public ?Memcached $memcache=null;
public function __construct(string $args)
{
@ -52,7 +51,7 @@ class MemcachedCache implements CacheEngine
}
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
$key = urlencode($key);
@ -63,7 +62,7 @@ class MemcachedCache implements CacheEngine
}
}
public function delete(string $key)
public function delete(string $key): void
{
$key = urlencode($key);
@ -87,12 +86,12 @@ class APCCache implements CacheEngine
return apc_fetch($key);
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
apc_store($key, $val, $time);
}
public function delete(string $key)
public function delete(string $key): void
{
apc_delete($key);
}
@ -100,7 +99,7 @@ class APCCache implements CacheEngine
class RedisCache implements CacheEngine
{
private $redis=null;
private Redis $redis;
public function __construct(string $args)
{
@ -116,7 +115,7 @@ class RedisCache implements CacheEngine
return $this->redis->get($key);
}
public function set(string $key, $val, int $time=0)
public function set(string $key, $val, int $time=0): void
{
if ($time > 0) {
$this->redis->setEx($key, $time, $val);
@ -125,7 +124,7 @@ class RedisCache implements CacheEngine
}
}
public function delete(string $key)
public function delete(string $key): void
{
$this->redis->del($key);
}
@ -134,9 +133,9 @@ class RedisCache implements CacheEngine
class Cache
{
public $engine;
public $hits=0;
public $misses=0;
public $time=0;
public int $hits=0;
public int $misses=0;
public int $time=0;
public function __construct(?string $dsn)
{

@ -5,9 +5,9 @@
// quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27
class CommandBuilder
{
private $executable;
private $args = [];
public $output;
private string $executable;
private array $args = [];
public array $output;
public function __construct(String $executable)
{

@ -130,7 +130,7 @@ interface Config
*/
abstract class BaseConfig implements Config
{
public $values = [];
public array $values = [];
public function set_int(string $name, ?int $value): void
{
@ -256,12 +256,10 @@ abstract class BaseConfig implements Config
*/
class DatabaseConfig extends BaseConfig
{
/** @var Database */
private $database = null;
private $table_name;
private $sub_column;
private $sub_value;
private Database $database;
private string $table_name;
private ?string $sub_column;
private ?string $sub_value;
public function __construct(
Database $database,

@ -13,30 +13,23 @@ abstract class DatabaseDriver
*/
class Database
{
/** @var string */
private $dsn;
private string $dsn;
/**
* The PDO database connection object, for anyone who wants direct access.
* @var null|PDO
*/
private $db = null;
/**
* @var float
*/
public $dbtime = 0.0;
private ?PDO $db = null;
public float $dbtime = 0.0;
/**
* Meta info about the database engine.
* @var DBEngine|null
*/
private $engine = null;
private ?DBEngine $engine = null;
/**
* How many queries this DB object has run
*/
public $query_count = 0;
public int $query_count = 0;
public function __construct(string $dsn)
{

@ -7,16 +7,15 @@ abstract class SCORE
abstract class DBEngine
{
/** @var null|string */
public $name = null;
public ?string $name = null;
public function init(PDO $db)
{
}
public function scoreql_to_sql(string $scoreql): string
public function scoreql_to_sql(string $data): string
{
return $scoreql;
return $data;
}
public function create_table_sql(string $name, string $data): string
@ -33,8 +32,7 @@ abstract class DBEngine
class MySQL extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::MYSQL;
public ?string $name = DatabaseDriver::MYSQL;
public function init(PDO $db)
{
@ -73,8 +71,7 @@ class MySQL extends DBEngine
class PostgreSQL extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::PGSQL;
public ?string $name = DatabaseDriver::PGSQL;
public function init(PDO $db)
{
@ -122,19 +119,19 @@ class PostgreSQL extends DBEngine
}
// shimmie functions for export to sqlite
function _unix_timestamp($date)
function _unix_timestamp($date): int
{
return strtotime($date);
}
function _now()
function _now(): string
{
return date("Y-m-d H:i:s");
}
function _floor($a)
function _floor($a): float
{
return floor($a);
}
function _log($a, $b=null)
function _log($a, $b=null): float
{
if (is_null($b)) {
return log($a);
@ -142,35 +139,34 @@ function _log($a, $b=null)
return log($a, $b);
}
}
function _isnull($a)
function _isnull($a): bool
{
return is_null($a);
}
function _md5($a)
function _md5($a): string
{
return md5($a);
}
function _concat($a, $b)
function _concat($a, $b): string
{
return $a . $b;
}
function _lower($a)
function _lower($a): string
{
return strtolower($a);
}
function _rand()
function _rand(): int
{
return rand();
}
function _ln($n)
function _ln($n): float
{
return log($n);
}
class SQLite extends DBEngine
{
/** @var string */
public $name = DatabaseDriver::SQLITE;
public ?string $name = DatabaseDriver::SQLITE;
public function init(PDO $db)
{

@ -6,13 +6,13 @@
*/
abstract class Event
{
public $stop_processing = false;
public bool $stop_processing = false;
public function __construct()
{
}
public function __toString()
public function __toString(): string
{
return var_export($this, true);
}
@ -42,19 +42,11 @@ class InitExtEvent extends Event
class PageRequestEvent extends Event
{
/**
* @var array
* @var string[]
*/
public $args;
/**
* @var int
*/
public $arg_count;
/**
* @var int
*/
public $part_count;
public int $arg_count;
public int $part_count;
public function __construct(string $path)
{
@ -179,15 +171,12 @@ class PageRequestEvent extends Event
*/
class CommandEvent extends Event
{
/**
* @var string
*/
public $cmd = "help";
public string $cmd = "help";
/**
* @var array
* @var string[]
*/
public $args = [];
public array $args = [];
/**
* #param string[] $args
@ -256,24 +245,18 @@ class TextFormattingEvent extends Event
{
/**
* For reference
*
* @var string
*/
public $original;
public string $original;
/**
* with formatting applied
*
* @var string
*/
public $formatted;
public string $formatted;
/**
* with formatting removed
*
* @var string
*/
public $stripped;
public string $stripped;
public function __construct(string $text)
{
@ -296,38 +279,30 @@ class LogEvent extends Event
{
/**
* a category, normally the extension name
*
* @var string
*/
public $section;
public string $section;
/**
* See python...
*
* @var int
*/
public $priority = 0;
public int $priority = 0;
/**
* Free text to be logged
*
* @var string
*/
public $message;
public string $message;
/**
* The time that the event was created
*
* @var int
*/
public $time;
public int $time;
/**
* Extra data to be held separate
*
* @var array
* @var string[]
*/
public $args;
public array $args;
public function __construct(string $section, int $priority, string $message)
{

@ -7,11 +7,8 @@
*/
class SCoreException extends RuntimeException
{
/** @var string|null */
public $query;
/** @var string */
public $error;
public ?string $query;
public string $error;
public function __construct(string $msg, ?string $query=null)
{
@ -23,21 +20,16 @@ class SCoreException extends RuntimeException
class InstallerException extends RuntimeException
{
/** @var string */
public $title;
/** @var string */
public $body;
/** @var int */
public $code;
public string $title;
public string $body;
public int $exit_code;
public function __construct(string $title, string $body, int $code)
public function __construct(string $title, string $body, int $exit_code)
{
parent::__construct($body);
$this->title = $title;
$this->body = $body;
$this->code = $code;
$this->exit_code = $exit_code;
}
}

@ -13,16 +13,11 @@
*/
abstract class Extension
{
/** @var string */
public $key;
public string $key;
protected ?Themelet $theme;
public ?ExtensionInfo $info;
/** @var Themelet */
protected $theme;
/** @var ExtensionInfo */
public $info;
private static $enabled_extensions = [];
private static array $enabled_extensions = [];
public function __construct($class = null)
{
@ -122,35 +117,31 @@ abstract class ExtensionInfo
public const LICENSE_MIT = "MIT";
public const LICENSE_WTFPL = "WTFPL";
public const VISIBLE_DEFAULT = "default";
public const VISIBLE_ADMIN = "admin";
public const VISIBLE_HIDDEN = "hidden";
private const VALID_VISIBILITY = [self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
public $key;
public $core = false;
public $beta = false;
private const VALID_VISIBILITY = [self::VISIBLE_DEFAULT, self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN];
public $name;
public $authors = [];
public $link;
public $license;
public $version;
public $dependencies = [];
public $conflicts = [];
public $visibility;
public $description;
public $documentation;
public string $key;
/** @var array which DBs this ext supports (blank for 'all') */
public $db_support = [];
public bool $core = false;
public bool $beta = false;
/** @var bool */
private $supported = null;
public string $name;
public string $license;
public string $description;
public array $authors = [];
public array $dependencies = [];
public array $conflicts = [];
public string $visibility = self::VISIBLE_DEFAULT;
public ?string $link = null;
public ?string $version = null;
public ?string $documentation = null;
/** @var string */
private $support_info = null;
/** @var string[] which DBs this ext supports (blank for 'all') */
public array $db_support = [];
private ?bool $supported = null;
private ?string $support_info = null;
public function is_supported(): bool
{
@ -168,9 +159,9 @@ abstract class ExtensionInfo
return $this->support_info;
}
private static $all_info_by_key = [];
private static $all_info_by_class = [];
private static $core_extensions = [];
private static array $all_info_by_key = [];
private static array $all_info_by_class = [];
private static array $core_extensions = [];
protected function __construct()
{
@ -283,7 +274,7 @@ abstract class FormatterExtension extends Extension
*/
abstract class DataHandlerExtension extends Extension
{
protected $SUPPORTED_MIME = [];
protected array $SUPPORTED_MIME = [];
protected function move_upload_to_archive(DataUploadEvent $event)
{
@ -335,7 +326,9 @@ abstract class DataHandlerExtension extends Extension
}
send_event(new ImageReplaceEvent($event->replace_id, $image));
$event->image_id = $event->replace_id;
$_id = $event->replace_id;
assert(!is_null($_id));
$event->image_id = $_id;
} else {
$image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->hash), $event->metadata);
if (is_null($image)) {

@ -5,13 +5,9 @@
*/
class ImageAdditionEvent extends Event
{
/** @var User */
public $user;
/** @var Image */
public $image;
public $merged = false;
public User $user;
public Image $image;
public bool $merged = false;
/**
* Inserts a new image into the database with its associated
@ -34,11 +30,8 @@ class ImageAdditionException extends SCoreException
*/
class ImageDeletionEvent extends Event
{
/** @var Image */
public $image;
/** @var bool */
public $force = false;
public Image $image;
public bool $force = false;
/**
* Deletes an image.
@ -59,10 +52,8 @@ class ImageDeletionEvent extends Event
*/
class ImageReplaceEvent extends Event
{
/** @var int */
public $id;
/** @var Image */
public $image;
public int $id;
public Image $image;
/**
* Replaces an image.
@ -88,15 +79,10 @@ class ImageReplaceException extends SCoreException
*/
class ThumbnailGenerationEvent extends Event
{
/** @var string */
public $hash;
/** @var string */
public $mime;
/** @var bool */
public $force;
/** @var bool */
public $generated;
public string $hash;
public string $mime;
public bool $force;
public bool $generated;
/**
* Request a thumbnail be made for an image object
@ -121,14 +107,10 @@ class ThumbnailGenerationEvent extends Event
*/
class ParseLinkTemplateEvent extends Event
{
/** @var string */
public $link;
/** @var string */
public $text;
/** @var string */
public $original;
/** @var Image */
public $image;
public string $link;
public string $text;
public string $original;
public Image $image;
public function __construct(string $link, Image $image)
{

@ -13,68 +13,31 @@ class Image
public const IMAGE_DIR = "images";
public const THUMBNAIL_DIR = "thumbs";
/** @var null|int */
public $id = null;
/** @var int */
public $height;
/** @var int */
public $width;
/** @var string */
public $hash;
/** @var int */
public $filesize;
/** @var string */
public $filename;
/** @var string */
private $ext;
/** @var string */
private $mime;
public ?int $id = null;
public int $height = 0;
public int $width = 0;
public string $hash;
public int $filesize;
public string $filename;
private string $ext;
private string $mime;
/** @var string[]|null */
public $tag_array;
/** @var int */
public $owner_id;
/** @var string */
public $owner_ip;
/** @var string */
public $posted;
/** @var string */
public $source;
/** @var boolean */
public $locked = false;
/** @var boolean */
public $lossless = null;
/** @var boolean */
public $video = null;
/** @var string */
public $video_codec = null;
/** @var boolean */
public $image = null;
/** @var boolean */
public $audio = null;
/** @var int */
public $length = null;
public static $bool_props = ["locked", "lossless", "video", "audio"];
public static $int_props = ["id", "owner_id", "height", "width", "filesize", "length"];
public ?array $tag_array;
public int $owner_id;
public string $owner_ip;
public string $posted;
public ?string $source;
public bool $locked = false;
public ?bool $lossless = null;
public ?bool $video = null;
public ?string $video_codec = null;
public ?bool $image = null;
public ?bool $audio = null;
public ?int $length = null;
public static array $bool_props = ["locked", "lossless", "video", "audio", "image"];
public static array $int_props = ["id", "owner_id", "height", "width", "filesize", "length"];
/**
* One will very rarely construct an image directly, more common
@ -145,7 +108,7 @@ class Image
private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags=[]): iterable
{
global $database, $user, $config;
global $database, $user;
if ($start < 0) {
$start = 0;
@ -161,9 +124,7 @@ class Image
}
$querylet = Image::build_search_querylet($tags, $limit, $start);
$result = $database->get_all_iterable($querylet->sql, $querylet->variables);
return $result;
return $database->get_all_iterable($querylet->sql, $querylet->variables);
}
/**
@ -483,6 +444,7 @@ class Image
WHERE image_id=:id
ORDER BY tag
", ["id"=>$this->id]);
sort($this->tag_array);
}
return $this->tag_array;
}
@ -624,7 +586,9 @@ class Image
public function set_mime($mime): void
{
$this->mime = $mime;
$this->ext = FileExtension::get_for_mime($this->get_mime());
$ext = FileExtension::get_for_mime($this->get_mime());
assert($ext != null);
$this->ext = $ext;
}

@ -1,10 +1,8 @@
<?php declare(strict_types=1);
class Querylet
{
/** @var string */
public $sql;
/** @var array */
public $variables;
public string $sql;
public array $variables;
public function __construct(string $sql, array $variables=[])
{
@ -31,10 +29,8 @@ class Querylet
class TagCondition
{
/** @var string */
public $tag;
/** @var bool */
public $positive;
public string $tag;
public bool $positive;
public function __construct(string $tag, bool $positive)
{
@ -45,10 +41,8 @@ class TagCondition
class ImgCondition
{
/** @var Querylet */
public $qlet;
/** @var bool */
public $positive;
public Querylet $qlet;
public bool $positive;
public function __construct(Querylet $qlet, bool $positive)
{

@ -68,7 +68,7 @@ function do_install($dsn)
create_tables(new Database($dsn));
write_config($dsn);
} catch (InstallerException $e) {
die_nicely($e->title, $e->body, $e->code);
die_nicely($e->title, $e->body, $e->exit_code);
}
}

@ -7,6 +7,9 @@ abstract class Permissions
{
public const CHANGE_SETTING = "change_setting"; # modify web-level settings, eg the config table
public const OVERRIDE_CONFIG = "override_config"; # modify sys-level settings, eg shimmie.conf.php
public const CHANGE_USER_SETTING = "change_user_setting"; # modify own user-level settings
public const CHANGE_OTHER_USER_SETTING = "change_other_user_setting"; # modify own user-level settings
public const BIG_SEARCH = "big_search"; # search for more than 3 tags at once (speed mode only)
public const MANAGE_EXTENSION_LIST = "manage_extension_list";
@ -100,6 +103,7 @@ abstract class Permissions
public const SET_PRIVATE_IMAGE = "set_private_image";
public const SET_OTHERS_PRIVATE_IMAGES = "set_others_private_images";
public const CRON_RUN = "cron_run";
public const BULK_IMPORT = "bulk_import";
public const BULK_EXPORT = "bulk_export";
public const BULK_DOWNLOAD = "bulk_download";

@ -246,21 +246,22 @@ function find_header(array $headers, string $name): ?string
if (!function_exists('mb_strlen')) {
// TODO: we should warn the admin that they are missing multibyte support
function mb_strlen($str, $encoding)
/** @noinspection PhpUnusedParameterInspection */
function mb_strlen($str, $encoding): int
{
return strlen($str);
}
function mb_internal_encoding($encoding)
function mb_internal_encoding($encoding): void
{
}
function mb_strtolower($str)
function mb_strtolower($str): string
{
return strtolower($str);
}
}
/** @noinspection PhpUnhandledExceptionInspection */
function get_subclasses_of(string $parent)
function get_subclasses_of(string $parent): array
{
$result = [];
foreach (get_declared_classes() as $class) {
@ -327,7 +328,7 @@ function get_base_href(): string
/**
* The opposite of the standard library's parse_url
*/
function unparse_url($parsed_url)
function unparse_url(array $parsed_url): string
{
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
@ -345,14 +346,14 @@ function unparse_url($parsed_url)
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle): bool
{
return \strncmp($haystack, $needle, \strlen($needle)) === 0;
return strncmp($haystack, $needle, strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool
{
return $needle === '' || $needle === \substr($haystack, - \strlen($needle));
return $needle === '' || $needle === substr($haystack, - strlen($needle));
}
}
@ -525,7 +526,6 @@ function parse_shorthand_int(string $limit): int
/** @noinspection PhpMissingBreakStatementInspection */
// no break
case 'm': $value *= 1024; // fall through
/** @noinspection PhpMissingBreakStatementInspection */
// no break
case 'k': $value *= 1024; break;
default: $value = -1;
@ -800,7 +800,7 @@ function iterator_map_to_array(callable $callback, iterator $iter): array
return iterator_to_array(iterator_map($callback, $iter));
}
function stringer($s)
function stringer($s): string
{
if (is_array($s)) {
if (isset($s[0])) {

@ -26,7 +26,7 @@ _d("DEBUG", false); // boolean print various debugging details
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
_d("VERSION", "2.8.4$_g"); // string shimmie version
_d("VERSION", "2.9.1$_g"); // string shimmie version
_d("TIMEZONE", null); // string timezone
_d("EXTRA_EXTS", ""); // string optional extra extensions
_d("BASE_HREF", null); // string force a specific base URL (default is auto-detect)

@ -2,8 +2,8 @@
class Link
{
public $page;
public $query;
public ?string $page;
public ?string $query;
public function __construct(?string $page=null, ?string $query=null)
{