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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
namespace Shimmie2;
// Provides mechanisms for cleanly executing command-line applications
// 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

View File

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

View File

@ -1,7 +1,10 @@
<?php
declare(strict_types=1);
use FFSPHP\PDO;
namespace Shimmie2;
use FFSPHP\PDO, FFSPHP\PDOStatement;
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.
*/
public function get_col_iterable(string $query, array $args = []): Generator
public function get_col_iterable(string $query, array $args = []): \Generator
{
$_start = microtime(true);
$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.
*/
public function get_pairs_iterable(string $query, array $args = []): Generator
public function get_pairs_iterable(string $query, array $args = []): \Generator
{
$_start = microtime(true);
$stmt = $this->execute($query, $args);

View File

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

View File

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

View File

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

View File

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/**
* Class Extension
*
@ -17,7 +20,7 @@ abstract class Extension
{
public string $key;
protected ?Themelet $theme;
public ?ExtensionInfo $info;
public ExtensionInfo $info;
private static array $enabled_extensions = [];
@ -26,9 +29,6 @@ abstract class Extension
$class = $class ?? get_called_class();
$this->theme = $this->get_theme_object($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;
}
@ -37,8 +37,9 @@ abstract class Extension
*/
private function get_theme_object(string $base): ?Themelet
{
$custom = 'Custom'.$base.'Theme';
$normal = $base.'Theme';
$base = str_replace("Shimmie2\\", "", $base);
$custom = "Shimmie2\Custom{$base}Theme";
$normal = "Shimmie2\\{$base}Theme";
if (class_exists($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)) {
return self::$all_info_by_class[$normal];
} 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()
{
foreach (get_subclasses_of("ExtensionInfo") as $class) {
foreach (get_subclasses_of("Shimmie2\ExtensionInfo") as $class) {
$extension_info = new $class();
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");
@ -435,13 +437,13 @@ abstract class DataHandlerExtension extends Extension
public static function get_all_supported_mimes(): array
{
$arr = [];
foreach (get_subclasses_of("DataHandlerExtension") as $handler) {
foreach (get_subclasses_of("Shimmie2\DataHandlerExtension") as $handler) {
$handler = (new $handler());
$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
if (class_exists("TranscodeImage")) {
if (class_exists("Shimmie2\TranscodeImage")) {
$arr = array_merge($arr, TranscodeImage::get_enabled_mimes());
}

View File

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

View File

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/**
* Class Image
*
@ -149,7 +152,7 @@ class 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);
foreach ($result as $row) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Things which should be in the core API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -267,7 +270,7 @@ function get_subclasses_of(string $parent): array
{
$result = [];
foreach (get_declared_classes() as $class) {
$rclass = new ReflectionClass($class);
$rclass = new \ReflectionClass($class);
if (!$rclass->isAbstract() && is_subclass_of($class, $parent)) {
$result[] = $class;
}
@ -771,7 +774,7 @@ function join_path(string ...$paths): string
/**
* 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) {
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.
*/
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));
}
@ -790,7 +793,7 @@ function stringer($s): string
{
if (is_array($s)) {
if (isset($s[0])) {
return "[" . implode(", ", array_map("stringer", $s)) . "]";
return "[" . implode(", ", array_map("Shimmie2\stringer", $s)) . "]";
} else {
$pairs = [];
foreach ($s as $k=>$v) {

View File

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/*
* 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

View File

@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* Event API *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@ -37,7 +40,7 @@ function _set_event_listeners(): void
global $_shm_event_listeners;
$_shm_event_listeners = [];
foreach (get_subclasses_of("Extension") as $class) {
foreach (get_subclasses_of("Shimmie2\Extension") as $class) {
/** @var Extension $extension */
$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
{
$p = "<"."?php\n";
$p = "<"."?php\nnamespace Shimmie2;\n";
foreach (get_subclasses_of("Extension") as $class) {
$p .= "\$$class = new $class(); ";
foreach (get_subclasses_of("Shimmie2\Extension") as $class) {
$scn = _namespaced_class_name($class);
$p .= "\$$scn = new $scn(); ";
}
$p .= "\$_shm_event_listeners = array(\n";
foreach ($event_listeners as $event => $listeners) {
$p .= "\t'$event' => array(\n";
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";
}
@ -93,10 +101,11 @@ function send_event(Event $event): Event
global $tracer_enabled;
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;
}
$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
// 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));
}
// 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);
foreach ($my_event_listeners as $listener) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
namespace Shimmie2;
class BulkActionException extends SCoreException
{
}
@ -39,10 +41,10 @@ class BulkActionBlockBuildingEvent extends Event
class BulkActionEvent extends Event
{
public string $action;
public Generator $items;
public \Generator $items;
public bool $redirect = true;
public function __construct(String $action, Generator $items)
public function __construct(String $action, \Generator $items)
{
parent::__construct();
$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) {
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);
return Image::find_images_iterable(0, null, $tags);
@ -231,7 +233,7 @@ class BulkActions extends Extension
$size = 0;
foreach ($posts as $post) {
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'];
if ($reason) {
send_event(new AddImageHashBanEvent($post->hash, $reason));
@ -240,7 +242,7 @@ class BulkActions extends Extension
send_event(new ImageDeletionEvent($post));
$total++;
$size += $post->filesize;
} catch (Exception $e) {
} catch (\Exception $e) {
$page->flash("Error while removing {$post->id}: " . $e->getMessage());
}
}

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
namespace Shimmie2;
class BulkActionsTheme extends Themelet
{
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
{
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)' />";
} else {
return "";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
namespace Shimmie2;
class BulkAddCSV extends Extension
{
/** @var BulkAddCSVTheme */
@ -62,7 +64,7 @@ class BulkAddCSV extends Extension
if ($event->image_id == -1) {
throw new UploadException("File type not recognised");
} 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));
}
if (file_exists($thumbfile)) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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