avoid stringy class names

This commit is contained in:
Shish 2024-01-20 01:03:01 +00:00
parent 12ca708be8
commit 373be4e05c
14 changed files with 27 additions and 27 deletions

View file

@ -245,7 +245,7 @@ abstract class ExtensionInfo
public static function load_all_extension_info(): void
{
foreach (get_subclasses_of("Shimmie2\ExtensionInfo") as $class) {
foreach (get_subclasses_of(ExtensionInfo::class) 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");
@ -399,13 +399,13 @@ abstract class DataHandlerExtension extends Extension
public static function get_all_supported_mimes(): array
{
$arr = [];
foreach (get_subclasses_of("Shimmie2\DataHandlerExtension") as $handler) {
foreach (get_subclasses_of(DataHandlerExtension::class) 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("Shimmie2\TranscodeImage")) {
if (Extension::is_enabled(TranscodeImageInfo::KEY)) {
$arr = array_merge($arr, TranscodeImage::get_enabled_mimes());
}

View file

@ -48,7 +48,7 @@ function _set_event_listeners(): void
global $_shm_event_listeners;
$_shm_event_listeners = [];
foreach (get_subclasses_of("Shimmie2\Extension") as $class) {
foreach (get_subclasses_of(Extension::class) as $class) {
/** @var Extension $extension */
$extension = new $class();

View file

@ -50,7 +50,7 @@ class SearchTest extends ShimmiePHPUnitTestCase
array $expected_img_conditions,
string $expected_order,
): void {
$class = new \ReflectionClass('\Shimmie2\Search');
$class = new \ReflectionClass(Search::class);
$terms_to_conditions = $class->getMethod("terms_to_conditions");
$terms_to_conditions->setAccessible(true); // Use this if you are running PHP older than 8.1.0
@ -171,7 +171,7 @@ class SearchTest extends ShimmiePHPUnitTestCase
Search::$_search_path = [];
$class = new \ReflectionClass('\Shimmie2\Search');
$class = new \ReflectionClass(Search::class);
$build_search_querylet = $class->getMethod("build_search_querylet");
$build_search_querylet->setAccessible(true); // Use this if you are running PHP older than 8.1.0

View file

@ -44,7 +44,7 @@ class UserClass
{
global $_all_false;
$perms = [];
foreach ((new \ReflectionClass('\Shimmie2\Permissions'))->getConstants() as $k => $v) {
foreach ((new \ReflectionClass(Permissions::class))->getConstants() as $k => $v) {
if ($this->can($v)) {
$perms[] = $v;
}
@ -80,7 +80,7 @@ class UserClass
}
$_all_false = [];
foreach ((new \ReflectionClass('\Shimmie2\Permissions'))->getConstants() as $k => $v) {
foreach ((new \ReflectionClass(Permissions::class))->getConstants() as $k => $v) {
$_all_false[$v] = false;
}
new UserClass("base", null, $_all_false);

View file

@ -224,7 +224,7 @@ class BulkActions extends Extension
$size = 0;
foreach ($posts as $post) {
try {
if (class_exists("Shimmie2\ImageBan") && isset($_POST['bulk_ban_reason'])) {
if (Extension::is_enabled(ImageBanInfo::KEY) && isset($_POST['bulk_ban_reason'])) {
$reason = $_POST['bulk_ban_reason'];
if ($reason) {
send_event(new AddImageHashBanEvent($post->hash, $reason));

View file

@ -51,7 +51,7 @@ class BulkActionsTheme extends Themelet
public function render_ban_reason_input(): string
{
if (class_exists("Shimmie2\ImageBan")) {
if (Extension::is_enabled(ImageBanInfo::KEY)) {
return "<input type='text' name='bulk_ban_reason' placeholder='Ban reason (leave blank to not ban)' />";
} else {
return "";

View file

@ -71,10 +71,10 @@ class Home extends Extension
$main_links = $config->get_string('home_links');
} else {
$main_links = '[url=site://post/list]Posts[/url][url=site://comment/list]Comments[/url][url=site://tags]Tags[/url]';
if (class_exists("Shimmie2\Pools")) {
if (Extension::is_enabled(PoolsInfo::KEY)) {
$main_links .= '[url=site://pool/list]Pools[/url]';
}
if (class_exists("Shimmie2\Wiki")) {
if (Extension::is_enabled(WikiInfo::KEY)) {
$main_links .= '[url=site://wiki]Wiki[/url]';
}
$main_links .= '[url=site://ext_doc]Documentation[/url]';

View file

@ -113,7 +113,7 @@ and of course start organising your images :-)
{
global $config;
if (class_exists('Shimmie2\Wiki') && $config->get_bool(WikiConfig::TAG_SHORTWIKIS)) {
if (Extension::is_enabled(WikiInfo::KEY) && $config->get_bool(WikiConfig::TAG_SHORTWIKIS)) {
if (count($this->search_terms) == 1) {
$st = Tag::implode($this->search_terms);
@ -127,7 +127,7 @@ and of course start organising your images :-)
$short_wiki_description = $tfe->formatted;
}
$wikiLink = make_link("wiki/$st");
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tagcategories = new TagCategories();
$tag_category_dict = $tagcategories->getKeyedDict();
$st = $tagcategories->getTagHtml(html_escape($st), $tag_category_dict);

View file

@ -89,7 +89,7 @@ class TagList extends Extension
if ($config->get_int(TagListConfig::LENGTH) > 0) {
$type = $config->get_string(TagListConfig::IMAGE_TYPE);
if ($type == TagListConfig::TYPE_TAGS || $type == TagListConfig::TYPE_BOTH) {
if (class_exists("Shimmie2\TagCategories") and $config->get_bool(TagCategoriesConfig::SPLIT_ON_VIEW)) {
if (Extension::is_enabled(TagCategoriesInfo::KEY) and $config->get_bool(TagCategoriesConfig::SPLIT_ON_VIEW)) {
$this->add_split_tags_block($page, $event->image);
} else {
$this->add_tags_block($page, $event->image);
@ -266,7 +266,7 @@ class TagList extends Extension
$html .= $this->build_az();
}
$tag_category_dict = [];
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$this->tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict();
}
@ -278,7 +278,7 @@ class TagList extends Extension
$size = 0.5;
}
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$h_tag_no_underscores = $this->tagcategories->getTagHtml($h_tag, $tag_category_dict);
}
$html .= "&nbsp;<a style='font-size: {$size}em' href='$link'>$h_tag_no_underscores</a>&nbsp;\n";
@ -336,7 +336,7 @@ class TagList extends Extension
mb_internal_encoding('UTF-8');
$tag_category_dict = [];
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$this->tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict();
}
@ -355,7 +355,7 @@ class TagList extends Extension
}
$link = $this->theme->tag_link($tag);
$h_tag = html_escape($tag);
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$h_tag = $this->tagcategories->getTagHtml($h_tag, $tag_category_dict, "&nbsp;($count)");
}
$html .= "<a href='$link'>$h_tag</a>\n";

View file

@ -74,7 +74,7 @@ class TagListTheme extends Themelet
asort($tag_infos);
}
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$this->tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict();
} else {
@ -136,7 +136,7 @@ class TagListTheme extends Themelet
asort($tag_infos);
}
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$this->tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict();
} else {

View file

@ -180,7 +180,7 @@ class Upload extends Extension
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event): void
{
if ($event->parent == "upload") {
if (class_exists("Shimmie2\Wiki")) {
if (Extension::is_enabled(WikiInfo::KEY)) {
$event->add_nav_link("upload_guidelines", new Link('wiki/upload_guidelines'), "Guidelines");
}
}

View file

@ -200,7 +200,7 @@ class UserPage extends Extension
$this->theme->display_user_classes(
$page,
$_shm_user_classes,
(new \ReflectionClass('\Shimmie2\Permissions'))->getReflectionConstants()
(new \ReflectionClass(Permissions::class))->getReflectionConstants()
);
} elseif ($event->get_arg(0) == "logout") {
$this->page_logout();
@ -789,7 +789,7 @@ class UserPage extends Extension
private function count_log_ips(User $duser): array
{
if (!class_exists('Shimmie2\LogDatabase')) {
if (!Extension::is_enabled(LogDatabaseInfo::KEY)) {
return [];
}
global $database;

View file

@ -392,7 +392,7 @@ class Wiki extends Extension
$template = $config->get_string(WikiConfig::TAG_PAGE_TEMPLATE);
//CATEGORIES
if (class_exists("Shimmie2\TagCategories")) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tagcategories = new TagCategories();
$tag_category_dict = $tagcategories->getKeyedDict();
}
@ -415,7 +415,7 @@ class Wiki extends Extension
$template = format_text($template);
//Things after this line will NOT be escaped!!! Be careful what you add.
if (class_exists("Shimmie2\AutoTagger")) {
if (Extension::is_enabled(AutoTaggerInfo::KEY)) {
$auto_tags = $database->get_one("
SELECT additional_tags
FROM auto_tag

View file

@ -30,7 +30,7 @@ class WikiTheme extends Themelet
// see if title is a category'd tag
$title_html = html_escape($wiki_page->title);
if (class_exists('Shimmie2\TagCategories')) {
if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
$tagcategories = new TagCategories();
$tag_category_dict = $tagcategories->getKeyedDict();
$title_html = $tagcategories->getTagHtml($title_html, $tag_category_dict);