Namespaces are one honking great idea—let's do more of those!

This commit is contained in:
Shish 2023-01-10 22:44:09 +00:00
parent 90c419b0c4
commit bce2d55744
470 changed files with 1163 additions and 103 deletions

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
require_once "core/event.php"; require_once "core/event.php";
enum PageMode: string enum PageMode: string
@ -255,7 +258,7 @@ class BasePage
case PageMode::MANUAL: case PageMode::MANUAL:
break; break;
case PageMode::PAGE: case PageMode::PAGE:
usort($this->blocks, "blockcmp"); usort($this->blocks, "Shimmie2\blockcmp");
$this->add_auto_html_headers(); $this->add_auto_html_headers();
$this->render(); $this->render();
break; break;
@ -468,8 +471,8 @@ class BasePage
} }
$sub_links = $sub_links??[]; $sub_links = $sub_links??[];
usort($nav_links, "sort_nav_links"); usort($nav_links, "Shimmie2\sort_nav_links");
usort($sub_links, "sort_nav_links"); usort($sub_links, "Shimmie2\sort_nav_links");
return [$nav_links, $sub_links]; return [$nav_links, $sub_links];
} }

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Class BaseThemelet * Class BaseThemelet
* *
@ -64,7 +66,7 @@ class BaseThemelet
} }
$custom_classes = ""; $custom_classes = "";
if (class_exists("Relationships")) { if (class_exists("Shimmie2\Relationships")) {
if (property_exists($image, 'parent_id') && $image->parent_id !== null) { if (property_exists($image, 'parent_id') && $image->parent_id !== null) {
$custom_classes .= "shm-thumb-has_parent "; $custom_classes .= "shm-thumb-has_parent ";
} }

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Class Block * Class Block
* *

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
interface CacheEngine interface CacheEngine
{ {
public function get(string $key); public function get(string $key);

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* CAPTCHA abstraction * * CAPTCHA abstraction *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
// Provides mechanisms for cleanly executing command-line applications // Provides mechanisms for cleanly executing command-line applications
// Was created to try to centralize a solution for whatever caused this: // Was created to try to centralize a solution for whatever caused this:
// quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27 // quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Interface Config * Interface Config
* *

View file

@ -1,7 +1,10 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
use FFSPHP\PDO;
namespace Shimmie2;
use FFSPHP\PDO, FFSPHP\PDOStatement;
enum DatabaseDriverID: string enum DatabaseDriverID: string
{ {
@ -204,7 +207,7 @@ class Database
/** /**
* Execute an SQL query and return the first column of each row as a single iterable object. * Execute an SQL query and return the first column of each row as a single iterable object.
*/ */
public function get_col_iterable(string $query, array $args = []): Generator public function get_col_iterable(string $query, array $args = []): \Generator
{ {
$_start = microtime(true); $_start = microtime(true);
$stmt = $this->execute($query, $args); $stmt = $this->execute($query, $args);
@ -229,7 +232,7 @@ class Database
/** /**
* Execute an SQL query and return the the first column => the second column as an iterable object. * 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 public function get_pairs_iterable(string $query, array $args = []): \Generator
{ {
$_start = microtime(true); $_start = microtime(true);
$stmt = $this->execute($query, $args); $stmt = $this->execute($query, $args);

View file

@ -1,6 +1,11 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use FFSPHP\PDO;
abstract class SCORE abstract class SCORE
{ {
public const AIPK = "SCORE_AIPK"; public const AIPK = "SCORE_AIPK";
@ -177,16 +182,16 @@ class SQLite extends DBEngine
{ {
ini_set('sqlite.assoc_case', '0'); ini_set('sqlite.assoc_case', '0');
$db->exec("PRAGMA foreign_keys = ON;"); $db->exec("PRAGMA foreign_keys = ON;");
$db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1); $db->sqliteCreateFunction('UNIX_TIMESTAMP', 'Shimmie2\_unix_timestamp', 1);
$db->sqliteCreateFunction('now', '_now', 0); $db->sqliteCreateFunction('now', 'Shimmie2\_now', 0);
$db->sqliteCreateFunction('floor', '_floor', 1); $db->sqliteCreateFunction('floor', 'Shimmie2\_floor', 1);
$db->sqliteCreateFunction('log', '_log'); $db->sqliteCreateFunction('log', 'Shimmie2\_log');
$db->sqliteCreateFunction('isnull', '_isnull', 1); $db->sqliteCreateFunction('isnull', 'Shimmie2\_isnull', 1);
$db->sqliteCreateFunction('md5', '_md5', 1); $db->sqliteCreateFunction('md5', 'Shimmie2\_md5', 1);
$db->sqliteCreateFunction('concat', '_concat', 2); $db->sqliteCreateFunction('concat', 'Shimmie2\_concat', 2);
$db->sqliteCreateFunction('lower', '_lower', 1); $db->sqliteCreateFunction('lower', 'Shimmie2\_lower', 1);
$db->sqliteCreateFunction('rand', '_rand', 0); $db->sqliteCreateFunction('rand', 'Shimmie2\_rand', 0);
$db->sqliteCreateFunction('ln', '_ln', 1); $db->sqliteCreateFunction('ln', 'Shimmie2\_ln', 1);
} }
public function scoreql_to_sql(string $data): string public function scoreql_to_sql(string $data): string

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Generic parent class for all events. * Generic parent class for all events.
* *

View file

@ -2,10 +2,12 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* A base exception to be caught by the upper levels. * A base exception to be caught by the upper levels.
*/ */
class SCoreException extends RuntimeException class SCoreException extends \RuntimeException
{ {
public ?string $query; public ?string $query;
public string $error; public string $error;
@ -19,7 +21,7 @@ class SCoreException extends RuntimeException
} }
} }
class InstallerException extends RuntimeException class InstallerException extends \RuntimeException
{ {
public string $title; public string $title;
public string $body; public string $body;

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Class Extension * Class Extension
* *
@ -17,7 +20,7 @@ abstract class Extension
{ {
public string $key; public string $key;
protected ?Themelet $theme; protected ?Themelet $theme;
public ?ExtensionInfo $info; public ExtensionInfo $info;
private static array $enabled_extensions = []; private static array $enabled_extensions = [];
@ -26,9 +29,6 @@ abstract class Extension
$class = $class ?? get_called_class(); $class = $class ?? get_called_class();
$this->theme = $this->get_theme_object($class); $this->theme = $this->get_theme_object($class);
$this->info = ExtensionInfo::get_for_extension_class($class); $this->info = ExtensionInfo::get_for_extension_class($class);
if ($this->info===null) {
throw new ScoreException("Info class not found for extension $class");
}
$this->key = $this->info->key; $this->key = $this->info->key;
} }
@ -37,8 +37,9 @@ abstract class Extension
*/ */
private function get_theme_object(string $base): ?Themelet private function get_theme_object(string $base): ?Themelet
{ {
$custom = 'Custom'.$base.'Theme'; $base = str_replace("Shimmie2\\", "", $base);
$normal = $base.'Theme'; $custom = "Shimmie2\Custom{$base}Theme";
$normal = "Shimmie2\\{$base}Theme";
if (class_exists($custom)) { if (class_exists($custom)) {
return new $custom(); return new $custom();
@ -224,20 +225,21 @@ abstract class ExtensionInfo
} }
} }
public static function get_for_extension_class(string $base): ?ExtensionInfo public static function get_for_extension_class(string $base): ExtensionInfo
{ {
$normal = $base.'Info'; $normal = "{$base}Info";
if (array_key_exists($normal, self::$all_info_by_class)) { if (array_key_exists($normal, self::$all_info_by_class)) {
return self::$all_info_by_class[$normal]; return self::$all_info_by_class[$normal];
} else { } else {
return null; $infos = print_r(array_keys(self::$all_info_by_class), true);
throw new ScoreException("$normal not found in {$infos}");
} }
} }
public static function load_all_extension_info() public static function load_all_extension_info()
{ {
foreach (get_subclasses_of("ExtensionInfo") as $class) { foreach (get_subclasses_of("Shimmie2\ExtensionInfo") as $class) {
$extension_info = new $class(); $extension_info = new $class();
if (array_key_exists($extension_info->key, self::$all_info_by_key)) { if (array_key_exists($extension_info->key, self::$all_info_by_key)) {
throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded"); throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded");
@ -435,13 +437,13 @@ abstract class DataHandlerExtension extends Extension
public static function get_all_supported_mimes(): array public static function get_all_supported_mimes(): array
{ {
$arr = []; $arr = [];
foreach (get_subclasses_of("DataHandlerExtension") as $handler) { foreach (get_subclasses_of("Shimmie2\DataHandlerExtension") as $handler) {
$handler = (new $handler()); $handler = (new $handler());
$arr = array_merge($arr, $handler->SUPPORTED_MIME); $arr = array_merge($arr, $handler->SUPPORTED_MIME);
} }
// Not sure how to handle this otherwise, don't want to set up a whole other event for this one class // Not sure how to handle this otherwise, don't want to set up a whole other event for this one class
if (class_exists("TranscodeImage")) { if (class_exists("Shimmie2\TranscodeImage")) {
$arr = array_merge($arr, TranscodeImage::get_enabled_mimes()); $arr = array_merge($arr, TranscodeImage::get_enabled_mimes());
} }

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* An image is being added to the database. * An image is being added to the database.
*/ */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Class Image * Class Image
* *
@ -149,7 +152,7 @@ class Image
/** /**
* Search for an array of images, returning a iterable object of Image * Search for an array of images, returning a iterable object of Image
*/ */
public static function find_images_iterable(int $start = 0, ?int $limit = null, array $tags=[]): Generator public static function find_images_iterable(int $start = 0, ?int $limit = null, array $tags=[]): \Generator
{ {
$result = self::find_images_internal($start, $limit, $tags); $result = self::find_images_internal($start, $limit, $tags);
foreach ($result as $row) { foreach ($result as $row) {

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Misc functions * * Misc functions *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class Querylet class Querylet
{ {
public function __construct( public function __construct(

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Class Tag * Class Tag
* *
@ -144,7 +147,7 @@ class Tag
foreach ($tags as $tag) { foreach ($tags as $tag) {
try { try {
$tag = Tag::sanitize($tag); $tag = Tag::sanitize($tag);
} catch (Exception $e) { } catch (\Exception $e) {
$page->flash($e->getMessage()); $page->flash($e->getMessage());
continue; continue;
} }

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Shimmie Installer * Shimmie Installer
* *

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Logging convenience * * Logging convenience *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
// action_object_attribute // action_object_attribute
// action = create / view / edit / delete // action = create / view / edit / delete
// object = image / user / tag / setting // object = image / user / tag / setting

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Things which should be in the core API * * Things which should be in the core API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -267,7 +270,7 @@ function get_subclasses_of(string $parent): array
{ {
$result = []; $result = [];
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
$rclass = new ReflectionClass($class); $rclass = new \ReflectionClass($class);
if (!$rclass->isAbstract() && is_subclass_of($class, $parent)) { if (!$rclass->isAbstract() && is_subclass_of($class, $parent)) {
$result[] = $class; $result[] = $class;
} }
@ -771,7 +774,7 @@ function join_path(string ...$paths): string
/** /**
* Perform callback on each item returned by an iterator. * Perform callback on each item returned by an iterator.
*/ */
function iterator_map(callable $callback, iterator $iter): Generator function iterator_map(callable $callback, \iterator $iter): \Generator
{ {
foreach ($iter as $i) { foreach ($iter as $i) {
yield call_user_func($callback, $i); yield call_user_func($callback, $i);
@ -781,7 +784,7 @@ function iterator_map(callable $callback, iterator $iter): Generator
/** /**
* Perform callback on each item returned by an iterator and combine the result into an array. * Perform callback on each item returned by an iterator and combine the result into an array.
*/ */
function iterator_map_to_array(callable $callback, iterator $iter): array function iterator_map_to_array(callable $callback, \iterator $iter): array
{ {
return iterator_to_array(iterator_map($callback, $iter)); return iterator_to_array(iterator_map($callback, $iter));
} }
@ -790,7 +793,7 @@ function stringer($s): string
{ {
if (is_array($s)) { if (is_array($s)) {
if (isset($s[0])) { if (isset($s[0])) {
return "[" . implode(", ", array_map("stringer", $s)) . "]"; return "[" . implode(", ", array_map("Shimmie2\stringer", $s)) . "]";
} else { } else {
$pairs = []; $pairs = [];
foreach ($s as $k=>$v) { foreach ($s as $k=>$v) {

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* /*
* A small number of PHP-sanity things (eg don't silently ignore errors) to * A small number of PHP-sanity things (eg don't silently ignore errors) to
* be included right at the very start of index.php and tests/bootstrap.php * be included right at the very start of index.php and tests/bootstrap.php

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Event API * * Event API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -37,7 +40,7 @@ function _set_event_listeners(): void
global $_shm_event_listeners; global $_shm_event_listeners;
$_shm_event_listeners = []; $_shm_event_listeners = [];
foreach (get_subclasses_of("Extension") as $class) { foreach (get_subclasses_of("Shimmie2\Extension") as $class) {
/** @var Extension $extension */ /** @var Extension $extension */
$extension = new $class(); $extension = new $class();
@ -59,19 +62,24 @@ function _set_event_listeners(): void
} }
} }
function _namespaced_class_name(string $class): string {
return str_replace("Shimmie2\\", "", $class);
}
function _dump_event_listeners(array $event_listeners, string $path): void function _dump_event_listeners(array $event_listeners, string $path): void
{ {
$p = "<"."?php\n"; $p = "<"."?php\nnamespace Shimmie2;\n";
foreach (get_subclasses_of("Extension") as $class) { foreach (get_subclasses_of("Shimmie2\Extension") as $class) {
$p .= "\$$class = new $class(); "; $scn = _namespaced_class_name($class);
$p .= "\$$scn = new $scn(); ";
} }
$p .= "\$_shm_event_listeners = array(\n"; $p .= "\$_shm_event_listeners = array(\n";
foreach ($event_listeners as $event => $listeners) { foreach ($event_listeners as $event => $listeners) {
$p .= "\t'$event' => array(\n"; $p .= "\t'$event' => array(\n";
foreach ($listeners as $id => $listener) { foreach ($listeners as $id => $listener) {
$p .= "\t\t$id => \$".get_class($listener).",\n"; $p .= "\t\t$id => \$"._namespaced_class_name(get_class($listener)).",\n";
} }
$p .= "\t),\n"; $p .= "\t),\n";
} }
@ -93,10 +101,11 @@ function send_event(Event $event): Event
global $tracer_enabled; global $tracer_enabled;
global $_shm_event_listeners, $_shm_event_count, $_tracer; global $_shm_event_listeners, $_shm_event_count, $_tracer;
if (!isset($_shm_event_listeners[get_class($event)])) { $event_name = _namespaced_class_name(get_class($event));
if (!isset($_shm_event_listeners[$event_name])) {
return $event; return $event;
} }
$method_name = "on".str_replace("Event", "", get_class($event)); $method_name = "on".str_replace("Event", "", $event_name);
// send_event() is performance sensitive, and with the number // send_event() is performance sensitive, and with the number
// of times tracer gets called the time starts to add up // of times tracer gets called the time starts to add up
@ -104,7 +113,7 @@ function send_event(Event $event): Event
$_tracer->begin(get_class($event)); $_tracer->begin(get_class($event));
} }
// SHIT: https://bugs.php.net/bug.php?id=35106 // SHIT: https://bugs.php.net/bug.php?id=35106
$my_event_listeners = $_shm_event_listeners[get_class($event)]; $my_event_listeners = $_shm_event_listeners[$event_name];
ksort($my_event_listeners); ksort($my_event_listeners);
foreach ($my_event_listeners as $listener) { foreach ($my_event_listeners as $listener) {

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* For any values that aren't defined in data/config/*.php, * For any values that aren't defined in data/config/*.php,
* Shimmie will set the values to their defaults * Shimmie will set the values to their defaults

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/basepage.php"; require_once "core/basepage.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/block.php"; require_once "core/block.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TestInit extends TestCase class TestInit extends TestCase

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/polyfills.php"; require_once "core/polyfills.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/imageboard/tag.php"; require_once "core/imageboard/tag.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/urls.php"; require_once "core/urls.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
require_once "core/util.php"; require_once "core/util.php";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class Link class Link
{ {
public ?string $page; public ?string $page;

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
function _new_user(array $row): User function _new_user(array $row): User
{ {
return new User($row); return new User($row);

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* @global UserClass[] $_shm_user_classes * @global UserClass[] $_shm_user_classes
*/ */
@ -58,7 +61,7 @@ class UserClass
} }
$_all_false = []; $_all_false = [];
foreach ((new ReflectionClass('Permissions'))->getConstants() as $k => $v) { foreach ((new \ReflectionClass('\Shimmie2\Permissions'))->getConstants() as $k => $v) {
$_all_false[$v] = false; $_all_false[$v] = false;
} }
new UserClass("base", null, $_all_false); new UserClass("base", null, $_all_false);

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use MicroHTML\HTMLElement; use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML; use function MicroHTML\emptyHTML;
@ -259,7 +262,7 @@ function load_balance_url(string $tmpl, string $hash, int $n=0): string
if (isset($flexihashes[$opts])) { if (isset($flexihashes[$opts])) {
$flexihash = $flexihashes[$opts]; $flexihash = $flexihashes[$opts];
} else { } else {
$flexihash = new Flexihash\Flexihash(); $flexihash = new \Flexihash\Flexihash();
foreach (explode(",", $opts) as $opt) { foreach (explode(",", $opts) as $opt) {
$parts = explode("=", $opt); $parts = explode("=", $opt);
$parts_count = count($parts); $parts_count = count($parts);
@ -490,18 +493,18 @@ function scan_dir(string $path): array
$bytestotal = 0; $bytestotal = 0;
$nbfiles = 0; $nbfiles = 0;
$ite = new RecursiveDirectoryIterator( $ite = new \RecursiveDirectoryIterator(
$path, $path,
FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::KEY_AS_PATHNAME |
FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::CURRENT_AS_FILEINFO |
FilesystemIterator::SKIP_DOTS \FilesystemIterator::SKIP_DOTS
); );
foreach (new RecursiveIteratorIterator($ite) as $filename => $cur) { foreach (new \RecursiveIteratorIterator($ite) as $filename => $cur) {
try { try {
$filesize = $cur->getSize(); $filesize = $cur->getSize();
$bytestotal += $filesize; $bytestotal += $filesize;
$nbfiles++; $nbfiles++;
} catch (RuntimeException $e) { } catch (\RuntimeException $e) {
// This usually just means that the file got eaten by the import // This usually just means that the file got eaten by the import
continue; continue;
} }
@ -579,7 +582,9 @@ function _load_core_files()
function _load_theme_files() function _load_theme_files()
{ {
require_all(_get_themelet_files(get_theme())); $theme = get_theme();
$files = _get_themelet_files($theme);
require_all($files);
} }
function _set_up_shimmie_environment(): void function _set_up_shimmie_environment(): void
@ -621,13 +626,13 @@ function _get_themelet_files(string $_theme): array
/** /**
* Used to display fatal errors to the web user. * Used to display fatal errors to the web user.
*/ */
function _fatal_error(Exception $e): void function _fatal_error(\Exception $e): void
{ {
$version = VERSION; $version = VERSION;
$message = $e->getMessage(); $message = $e->getMessage();
$phpver = phpversion(); $phpver = phpversion();
$query = is_subclass_of($e, "SCoreException") ? $e->query : null; $query = is_subclass_of($e, "Shimmie2\SCoreException") ? $e->query : null;
$code = is_subclass_of($e, "SCoreException") ? $e->http_code : 500; $code = is_subclass_of($e, "Shimmie2\SCoreException") ? $e->http_code : 500;
//$hash = exec("git rev-parse HEAD"); //$hash = exec("git rev-parse HEAD");
//$h_hash = $hash ? "<p><b>Hash:</b> $hash" : ""; //$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AdminPageInfo extends ExtensionInfo class AdminPageInfo extends ExtensionInfo
{ {
public const KEY = "admin"; public const KEY = "admin";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
/** /**
* Sent when the admin page is ready to be added to * Sent when the admin page is ready to be added to
*/ */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AdminPageTest extends ShimmiePHPUnitTestCase class AdminPageTest extends ShimmiePHPUnitTestCase
{ {
public function testAuth() public function testAuth()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AdminPageTheme extends Themelet class AdminPageTheme extends Themelet
{ {
/* /*

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AliasEditorInfo extends ExtensionInfo class AliasEditorInfo extends ExtensionInfo
{ {
public const KEY = "alias_editor"; public const KEY = "alias_editor";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use MicroCRUD\ActionColumn; use MicroCRUD\ActionColumn;
use MicroCRUD\TextColumn; use MicroCRUD\TextColumn;
use MicroCRUD\Table; use MicroCRUD\Table;

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AliasEditorTest extends ShimmiePHPUnitTestCase class AliasEditorTest extends ShimmiePHPUnitTestCase
{ {
public function testAliasList() public function testAliasList()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AliasEditorTheme extends Themelet class AliasEditorTheme extends Themelet
{ {
/** /**

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class ApprovalInfo extends ExtensionInfo class ApprovalInfo extends ExtensionInfo
{ {
public const KEY = "approval"; public const KEY = "approval";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
abstract class ApprovalConfig abstract class ApprovalConfig
{ {
public const VERSION = "ext_approval_version"; public const VERSION = "ext_approval_version";

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\BR; use function MicroHTML\BR;
use function MicroHTML\BUTTON; use function MicroHTML\BUTTON;
use function MicroHTML\INPUT; use function MicroHTML\INPUT;

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class ArtistsInfo extends ExtensionInfo class ArtistsInfo extends ExtensionInfo
{ {
public const KEY = "artists"; public const KEY = "artists";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AuthorSetEvent extends Event class AuthorSetEvent extends Event
{ {
public Image $image; public Image $image;

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class ArtistsTest extends ShimmiePHPUnitTestCase class ArtistsTest extends ShimmiePHPUnitTestCase
{ {
public function testSearch() public function testSearch()

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class ArtistsTheme extends Themelet class ArtistsTheme extends Themelet
{ {
public function get_author_editor_html(string $author): string public function get_author_editor_html(string $author): string

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
abstract class AutoTaggerConfig abstract class AutoTaggerConfig
{ {
public const VERSION = "ext_auto_tagger_ver"; public const VERSION = "ext_auto_tagger_ver";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoTaggerInfo extends ExtensionInfo class AutoTaggerInfo extends ExtensionInfo
{ {
public const KEY = "auto_tagger"; public const KEY = "auto_tagger";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
require_once 'config.php'; require_once 'config.php';
use MicroCRUD\ActionColumn; use MicroCRUD\ActionColumn;

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoTaggerTest extends ShimmiePHPUnitTestCase class AutoTaggerTest extends ShimmiePHPUnitTestCase
{ {
public function testAutoTaggerList() public function testAutoTaggerList()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoTaggerTheme extends Themelet class AutoTaggerTheme extends Themelet
{ {
/** /**

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoCompleteInfo extends ExtensionInfo class AutoCompleteInfo extends ExtensionInfo
{ {
public const KEY = "autocomplete"; public const KEY = "autocomplete";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoComplete extends Extension class AutoComplete extends Extension
{ {
/** @var AutoCompleteTheme */ /** @var AutoCompleteTheme */

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoCompleteTest extends ShimmiePHPUnitTestCase class AutoCompleteTest extends ShimmiePHPUnitTestCase
{ {
public function testAuth() public function testAuth()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class AutoCompleteTheme extends Themelet class AutoCompleteTheme extends Themelet
{ {
public function build_autocomplete(Page $page) public function build_autocomplete(Page $page)

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BanWordsInfo extends ExtensionInfo class BanWordsInfo extends ExtensionInfo
{ {
public const KEY = "ban_words"; public const KEY = "ban_words";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BanWords extends Extension class BanWords extends Extension
{ {
public function onInitExt(InitExtEvent $event) public function onInitExt(InitExtEvent $event)

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BanWordsTest extends ShimmiePHPUnitTestCase class BanWordsTest extends ShimmiePHPUnitTestCase
{ {
public function check_blocked($image_id, $words) public function check_blocked($image_id, $words)

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BBCodeInfo extends ExtensionInfo class BBCodeInfo extends ExtensionInfo
{ {
public const KEY = "bbcode"; public const KEY = "bbcode";

View file

@ -2,6 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BBCode extends FormatterExtension class BBCode extends FormatterExtension
{ {

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BBCodeTest extends ShimmiePHPUnitTestCase class BBCodeTest extends ShimmiePHPUnitTestCase
{ {
public function testBasics() public function testBasics()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BiographyInfo extends ExtensionInfo class BiographyInfo extends ExtensionInfo
{ {
public const KEY = "biography"; public const KEY = "biography";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class Biography extends Extension class Biography extends Extension
{ {
/** @var BiographyTheme */ /** @var BiographyTheme */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BiographyTest extends ShimmiePHPUnitTestCase class BiographyTest extends ShimmiePHPUnitTestCase
{ {
public function testBio() public function testBio()

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\TEXTAREA; use function MicroHTML\TEXTAREA;
class BiographyTheme extends Themelet class BiographyTheme extends Themelet

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BlocksInfo extends ExtensionInfo class BlocksInfo extends ExtensionInfo
{ {
public const KEY = "blocks"; public const KEY = "blocks";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class Blocks extends Extension class Blocks extends Extension
{ {
/** @var BlocksTheme */ /** @var BlocksTheme */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BlocksTest extends ShimmiePHPUnitTestCase class BlocksTest extends ShimmiePHPUnitTestCase
{ {
public function testBlocks() public function testBlocks()

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\TABLE; use function MicroHTML\TABLE;
use function MicroHTML\TR; use function MicroHTML\TR;
use function MicroHTML\TH; use function MicroHTML\TH;

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BlotterInfo extends ExtensionInfo class BlotterInfo extends ExtensionInfo
{ {
public const KEY = "blotter"; public const KEY = "blotter";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class Blotter extends Extension class Blotter extends Extension
{ {
/** @var BlotterTheme */ /** @var BlotterTheme */

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BlotterTest extends ShimmiePHPUnitTestCase class BlotterTest extends ShimmiePHPUnitTestCase
{ {
public function testDenial() public function testDenial()

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BlotterTheme extends Themelet class BlotterTheme extends Themelet
{ {
public function display_editor($entries) public function display_editor($entries)

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BrowserSearchInfo extends ExtensionInfo class BrowserSearchInfo extends ExtensionInfo
{ {
public const KEY = "browser_search"; public const KEY = "browser_search";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BrowserSearch extends Extension class BrowserSearch extends Extension
{ {
public function onInitExt(InitExtEvent $event) public function onInitExt(InitExtEvent $event)

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BrowserSearchTest extends ShimmiePHPUnitTestCase class BrowserSearchTest extends ShimmiePHPUnitTestCase
{ {
public function testBasic() public function testBasic()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkActionsInfo extends ExtensionInfo class BulkActionsInfo extends ExtensionInfo
{ {
public const KEY = "bulk_actions"; public const KEY = "bulk_actions";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkActionException extends SCoreException class BulkActionException extends SCoreException
{ {
} }
@ -39,10 +41,10 @@ class BulkActionBlockBuildingEvent extends Event
class BulkActionEvent extends Event class BulkActionEvent extends Event
{ {
public string $action; public string $action;
public Generator $items; public \Generator $items;
public bool $redirect = true; public bool $redirect = true;
public function __construct(String $action, Generator $items) public function __construct(String $action, \Generator $items)
{ {
parent::__construct(); parent::__construct();
$this->action = $action; $this->action = $action;
@ -201,7 +203,7 @@ class BulkActions extends Extension
} }
} }
private function yield_items(array $data): Generator private function yield_items(array $data): \Generator
{ {
foreach ($data as $id) { foreach ($data as $id) {
if (is_numeric($id)) { if (is_numeric($id)) {
@ -213,7 +215,7 @@ class BulkActions extends Extension
} }
} }
private function yield_search_results(string $query): Generator private function yield_search_results(string $query): \Generator
{ {
$tags = Tag::explode($query); $tags = Tag::explode($query);
return Image::find_images_iterable(0, null, $tags); return Image::find_images_iterable(0, null, $tags);
@ -231,7 +233,7 @@ class BulkActions extends Extension
$size = 0; $size = 0;
foreach ($posts as $post) { foreach ($posts as $post) {
try { try {
if (class_exists("ImageBan") && isset($_POST['bulk_ban_reason'])) { if (class_exists("Shimmie2\ImageBan") && isset($_POST['bulk_ban_reason'])) {
$reason = $_POST['bulk_ban_reason']; $reason = $_POST['bulk_ban_reason'];
if ($reason) { if ($reason) {
send_event(new AddImageHashBanEvent($post->hash, $reason)); send_event(new AddImageHashBanEvent($post->hash, $reason));
@ -240,7 +242,7 @@ class BulkActions extends Extension
send_event(new ImageDeletionEvent($post)); send_event(new ImageDeletionEvent($post));
$total++; $total++;
$size += $post->filesize; $size += $post->filesize;
} catch (Exception $e) { } catch (\Exception $e) {
$page->flash("Error while removing {$post->id}: " . $e->getMessage()); $page->flash("Error while removing {$post->id}: " . $e->getMessage());
} }
} }

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkActionsTheme extends Themelet class BulkActionsTheme extends Themelet
{ {
public function display_selector(Page $page, array $actions, string $query) public function display_selector(Page $page, array $actions, string $query)
@ -49,7 +51,7 @@ class BulkActionsTheme extends Themelet
public function render_ban_reason_input(): string public function render_ban_reason_input(): string
{ {
if (class_exists("ImageBan")) { if (class_exists("Shimmie2\ImageBan")) {
return "<input type='text' name='bulk_ban_reason' placeholder='Ban reason (leave blank to not ban)' />"; return "<input type='text' name='bulk_ban_reason' placeholder='Ban reason (leave blank to not ban)' />";
} else { } else {
return ""; return "";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddInfo extends ExtensionInfo class BulkAddInfo extends ExtensionInfo
{ {
public const KEY = "bulk_add"; public const KEY = "bulk_add";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddEvent extends Event class BulkAddEvent extends Event
{ {
public string $dir; public string $dir;

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddTest extends ShimmiePHPUnitTestCase class BulkAddTest extends ShimmiePHPUnitTestCase
{ {
public function testInvalidDir() public function testInvalidDir()

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddTheme extends Themelet class BulkAddTheme extends Themelet
{ {
private array $messages = []; private array $messages = [];

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddCSVInfo extends ExtensionInfo class BulkAddCSVInfo extends ExtensionInfo
{ {
public const KEY = "bulk_add_csv"; public const KEY = "bulk_add_csv";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddCSV extends Extension class BulkAddCSV extends Extension
{ {
/** @var BulkAddCSVTheme */ /** @var BulkAddCSVTheme */
@ -62,7 +64,7 @@ class BulkAddCSV extends Extension
if ($event->image_id == -1) { if ($event->image_id == -1) {
throw new UploadException("File type not recognised"); throw new UploadException("File type not recognised");
} else { } else {
if (class_exists("RatingSetEvent") && in_array($rating, ["s", "q", "e"])) { if (class_exists("Shimmie2\RatingSetEvent") && in_array($rating, ["s", "q", "e"])) {
send_event(new RatingSetEvent(Image::by_id($event->image_id), $rating)); send_event(new RatingSetEvent(Image::by_id($event->image_id), $rating));
} }
if (file_exists($thumbfile)) { if (file_exists($thumbfile)) {

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkAddCSVTheme extends Themelet class BulkAddCSVTheme extends Themelet
{ {
private array $messages = []; private array $messages = [];

View file

@ -2,6 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkDownloadInfo extends ExtensionInfo class BulkDownloadInfo extends ExtensionInfo
{ {

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkDownloadConfig class BulkDownloadConfig
{ {
public const SIZE_LIMIT = "bulk_download_size_limit"; public const SIZE_LIMIT = "bulk_download_size_limit";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkExportEvent extends Event class BulkExportEvent extends Event
{ {
public Image $image; public Image $image;

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
include_once "events.php"; include_once "events.php";
class BulkImportExportInfo extends ExtensionInfo class BulkImportExportInfo extends ExtensionInfo

View file

@ -2,6 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class BulkImportExport extends DataHandlerExtension class BulkImportExport extends DataHandlerExtension
{ {

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class CommentListInfo extends ExtensionInfo class CommentListInfo extends ExtensionInfo
{ {
public const KEY = "comment"; public const KEY = "comment";

View file

@ -2,6 +2,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
require_once "vendor/ifixit/php-akismet/akismet.class.php"; require_once "vendor/ifixit/php-akismet/akismet.class.php";
class CommentPostingEvent extends Event class CommentPostingEvent extends Event

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class CommentListTest extends ShimmiePHPUnitTestCase class CommentListTest extends ShimmiePHPUnitTestCase
{ {
public function setUp(): void public function setUp(): void

View file

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
class CommentListTheme extends Themelet class CommentListTheme extends Themelet
{ {
private bool $show_anon_id = false; private bool $show_anon_id = false;

View file

@ -2,6 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace Shimmie2;
abstract class CronUploaderConfig abstract class CronUploaderConfig
{ {

Some files were not shown because too many files have changed in this diff Show more