diff --git a/core/extension.php b/core/extension.php index c7364856..5f54305d 100644 --- a/core/extension.php +++ b/core/extension.php @@ -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()); } diff --git a/core/send_event.php b/core/send_event.php index 73af571d..c791936a 100644 --- a/core/send_event.php +++ b/core/send_event.php @@ -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(); diff --git a/core/tests/SearchTest.php b/core/tests/SearchTest.php index a9b1be28..3e90772c 100644 --- a/core/tests/SearchTest.php +++ b/core/tests/SearchTest.php @@ -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 diff --git a/core/userclass.php b/core/userclass.php index bbc60863..2f4789f5 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -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); diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php index b27d4dae..e141ea34 100644 --- a/ext/bulk_actions/main.php +++ b/ext/bulk_actions/main.php @@ -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)); diff --git a/ext/bulk_actions/theme.php b/ext/bulk_actions/theme.php index e9af61fa..bb7afa64 100644 --- a/ext/bulk_actions/theme.php +++ b/ext/bulk_actions/theme.php @@ -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 ""; } else { return ""; diff --git a/ext/home/main.php b/ext/home/main.php index 8442bc72..8df72915 100644 --- a/ext/home/main.php +++ b/ext/home/main.php @@ -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]'; diff --git a/ext/index/theme.php b/ext/index/theme.php index 6b7eac27..bc601a3b 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -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); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index ad22b6f2..2a8a47d7 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -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 .= " $h_tag_no_underscores \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, " ($count)"); } $html .= "$h_tag\n"; diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index 1116a10a..da0e0bbc 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -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 { diff --git a/ext/upload/main.php b/ext/upload/main.php index 5fb59287..b61b7277 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -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"); } } diff --git a/ext/user/main.php b/ext/user/main.php index f810e6a8..a9744911 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -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; diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 9c02f96a..3fafd7cf 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -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 diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index 861ed4aa..2f6cb5a2 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -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);