From 72268d529d12ae769aa03485370ec1b093467be2 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Mon, 26 Oct 2020 10:13:28 -0500 Subject: [PATCH] Moved user options to separate page, modularized the settings page code so that it can be re-used to simplify and standardize user settings in the same manner as global settings --- core/permissions.php | 3 + core/userclass.php | 3 + ext/approval/theme.php | 3 +- ext/ban_words/main.php | 3 +- ext/blotter/main.php | 3 +- ext/browser_search/main.php | 3 +- ext/bulk_download/main.php | 4 +- ext/comment/main.php | 3 +- ext/cron_uploader/main.php | 4 +- ext/custom_html_headers/main.php | 4 +- ext/downtime/main.php | 3 +- ext/eokm/main.php | 4 +- ext/forum/main.php | 3 +- ext/google_analytics/main.php | 3 +- ext/handle_archive/main.php | 3 +- ext/handle_video/main.php | 3 +- ext/holiday/main.php | 3 +- ext/home/main.php | 3 +- ext/image/main.php | 7 +- ext/image_view_counter/main.php | 8 +++ ext/index/main.php | 4 +- ext/ipban/main.php | 3 +- ext/link_image/main.php | 3 +- ext/livefeed/main.php | 3 +- ext/log_db/main.php | 3 +- ext/media/main.php | 4 +- ext/pools/main.php | 4 +- ext/post_titles/main.php | 4 +- ext/private_image/main.php | 14 ++-- ext/private_image/theme.php | 27 -------- ext/random_image/main.php | 3 +- ext/random_list/main.php | 4 +- ext/rating/main.php | 55 +++++----------- ext/rating/theme.php | 2 +- ext/report_image/main.php | 4 +- ext/res_limit/main.php | 4 +- ext/resize/main.php | 3 +- ext/rotate/main.php | 3 +- ext/setup/main.php | 52 ++++++++------- ext/setup/theme.php | 2 +- ext/site_description/main.php | 3 +- ext/sitemap/main.php | 4 +- ext/source_history/main.php | 3 +- ext/tag_editcloud/main.php | 4 +- ext/tag_history/main.php | 3 +- ext/tag_list/main.php | 6 +- ext/transcode/main.php | 3 +- ext/transcode_video/main.php | 5 +- ext/update/main.php | 3 +- ext/upload/main.php | 3 +- ext/user/events.php | 13 +++- ext/user/main.php | 23 ++++--- ext/user/theme.php | 3 +- ext/user_config/main.php | 105 +++++++++++++++++++++++++----- ext/user_config/style.css | 43 ++++++++++++ ext/user_config/theme.php | 55 +++++++++++++++- ext/wiki/main.php | 4 +- ext/word_filter/main.php | 3 +- themes/lite/user_config.theme.php | 42 ++++++++++++ 59 files changed, 363 insertions(+), 239 deletions(-) create mode 100644 ext/user_config/style.css create mode 100644 themes/lite/user_config.theme.php diff --git a/core/permissions.php b/core/permissions.php index 21429ae7..8cd7545b 100644 --- a/core/permissions.php +++ b/core/permissions.php @@ -7,6 +7,9 @@ abstract class Permissions { public const CHANGE_SETTING = "change_setting"; # modify web-level settings, eg the config table public const OVERRIDE_CONFIG = "override_config"; # modify sys-level settings, eg shimmie.conf.php + public const CHANGE_USER_SETTING = "change_user_setting"; # modify own user-level settings + public const CHANGE_OTHER_USER_SETTING = "change_other_user_setting"; # modify own user-level settings + public const BIG_SEARCH = "big_search"; # search for more than 3 tags at once (speed mode only) public const MANAGE_EXTENSION_LIST = "manage_extension_list"; diff --git a/core/userclass.php b/core/userclass.php index a24c879e..3ec979a0 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -100,6 +100,7 @@ new UserClass("user", "base", [ Permissions::READ_PM => true, Permissions::SET_PRIVATE_IMAGE => true, Permissions::BULK_DOWNLOAD => true, + Permissions::CHANGE_USER_SETTING => true ]); new UserClass("hellbanned", "user", [ @@ -108,6 +109,8 @@ new UserClass("hellbanned", "user", [ new UserClass("admin", "base", [ Permissions::CHANGE_SETTING => true, + Permissions::CHANGE_USER_SETTING => true, + Permissions::CHANGE_OTHER_USER_SETTING => true, Permissions::OVERRIDE_CONFIG => true, Permissions::BIG_SEARCH => true, diff --git a/ext/approval/theme.php b/ext/approval/theme.php index 7b85c43c..e6033d72 100644 --- a/ext/approval/theme.php +++ b/ext/approval/theme.php @@ -41,9 +41,8 @@ class ApprovalTheme extends Themelet public function display_admin_block(SetupBuildingEvent $event) { - $sb = new SetupBlock("Approval"); + $sb = $event->panel->create_new_block("Approval"); $sb->add_bool_option(ApprovalConfig::IMAGES, "Posts: "); - $event->panel->add_block($sb); } public function display_admin_form() diff --git a/ext/ban_words/main.php b/ext/ban_words/main.php index 3ed7d253..99f2d6ab 100644 --- a/ext/ban_words/main.php +++ b/ext/ban_words/main.php @@ -55,7 +55,7 @@ xanax public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Banned Phrases"); + $sb = $event->panel->create_new_block("Banned Phrases"); $sb->add_label("One per line, lines that start with slashes are treated as regex
"); $sb->add_longtext_option("banned_words"); $failed = []; @@ -69,7 +69,6 @@ xanax if ($failed) { $sb->add_label("Failed regexes: ".join(", ", $failed)); } - $event->panel->add_block($sb); } /** diff --git a/ext/blotter/main.php b/ext/blotter/main.php index 08adf4bd..32c322ac 100644 --- a/ext/blotter/main.php +++ b/ext/blotter/main.php @@ -40,11 +40,10 @@ class Blotter extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Blotter"); + $sb = $event->panel->create_new_block("Blotter"); $sb->add_int_option("blotter_recent", "
Number of recent entries to display: "); $sb->add_text_option("blotter_color", "
Color of important updates: (ABCDEF format) "); $sb->add_choice_option("blotter_position", ["Top of page" => "subheading", "In navigation bar" => "left"], "
Position: "); - $event->panel->add_block($sb); } public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) diff --git a/ext/browser_search/main.php b/ext/browser_search/main.php index 4781c9a2..b6cd8f19 100644 --- a/ext/browser_search/main.php +++ b/ext/browser_search/main.php @@ -78,8 +78,7 @@ class BrowserSearch extends Extension $sort_by['Tag Count'] = 't'; $sort_by['Disabled'] = 'n'; - $sb = new SetupBlock("Browser Search"); + $sb = $event->panel->create_new_block("Browser Search"); $sb->add_choice_option("search_suggestions_results_order", $sort_by, "Sort the suggestions by:"); - $event->panel->add_block($sb); } } diff --git a/ext/bulk_download/main.php b/ext/bulk_download/main.php index 28ff60e9..228bb671 100644 --- a/ext/bulk_download/main.php +++ b/ext/bulk_download/main.php @@ -30,13 +30,11 @@ class BulkDownload extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Bulk Download"); + $sb = $event->panel->create_new_block("Bulk Download"); $sb->start_table(); $sb->add_shorthand_int_option(BulkDownloadConfig::SIZE_LIMIT, "Size Limit", true); $sb->end_table(); - - $event->panel->add_block($sb); } public function onBulkAction(BulkActionEvent $event) diff --git a/ext/comment/main.php b/ext/comment/main.php index 3ded122f..ca471aa0 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -379,7 +379,7 @@ class CommentList extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Comment Options"); + $sb = $event->panel->create_new_block("Comment Options"); $sb->add_bool_option("comment_captcha", "Require CAPTCHA for anonymous comments: "); $sb->add_label("
Limit to "); $sb->add_int_option("comment_limit"); @@ -394,7 +394,6 @@ class CommentList extends Extension $sb->add_label(" comments per image on the list"); $sb->add_label("
Make samefags public "); $sb->add_bool_option("comment_samefags_public"); - $event->panel->add_block($sb); } public function onSearchTermParse(SearchTermParseEvent $event) diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index f8bce0a1..3a70165c 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -55,7 +55,7 @@ class CronUploader extends Extension $users = $database->get_pairs("SELECT name, id FROM users UNION ALL SELECT '', null order by name"); - $sb = new SetupBlock("Cron Uploader"); + $sb = $event->panel->create_new_block("Cron Uploader"); $sb->start_table(); $sb->add_text_option(CronUploaderConfig::DIR, "Root dir", true); $sb->add_text_option(CronUploaderConfig::KEY, "Key", true); @@ -71,8 +71,6 @@ class CronUploader extends Extension $sb->add_bool_option(CronUploaderConfig::INCLUDE_ALL_LOGS, "Include All Logs", true); $sb->end_table(); $sb->add_label("Read the documentation for cron setup instructions."); - - $event->panel->add_block($sb); } public function onAdminBuilding(AdminBuildingEvent $event) diff --git a/ext/custom_html_headers/main.php b/ext/custom_html_headers/main.php index 52a09687..3fa6e665 100644 --- a/ext/custom_html_headers/main.php +++ b/ext/custom_html_headers/main.php @@ -5,7 +5,7 @@ class CustomHtmlHeaders extends Extension # Adds setup block for custom content public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Custom HTML Headers"); + $sb = $event->panel->create_new_block("Custom HTML Headers"); // custom headers $sb->add_longtext_option( @@ -19,8 +19,6 @@ class CustomHtmlHeaders extends Extension "as prefix" => "prefix", "as suffix" => "suffix" ], "
Add website name in title"); - - $event->panel->add_block($sb); } public function onInitExt(InitExtEvent $event) diff --git a/ext/downtime/main.php b/ext/downtime/main.php index 29507e69..6bc823aa 100644 --- a/ext/downtime/main.php +++ b/ext/downtime/main.php @@ -12,10 +12,9 @@ class Downtime extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Downtime"); + $sb = $event->panel->create_new_block("Downtime"); $sb->add_bool_option("downtime", "Disable non-admin access: "); $sb->add_longtext_option("downtime_message", "
"); - $event->panel->add_block($sb); } public function onPageRequest(PageRequestEvent $event) diff --git a/ext/eokm/main.php b/ext/eokm/main.php index 83e43633..45b0f32f 100644 --- a/ext/eokm/main.php +++ b/ext/eokm/main.php @@ -38,13 +38,11 @@ class Eokm extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("EOKM Filter"); + $sb = $event->panel->create_new_block("EOKM Filter"); $sb->start_table(); $sb->add_text_option("eokm_username", "Username", true); $sb->add_text_option("eokm_password", "Password", true); $sb->end_table(); - - $event->panel->add_block($sb); } } diff --git a/ext/forum/main.php b/ext/forum/main.php index b2aac68f..f4d941a2 100644 --- a/ext/forum/main.php +++ b/ext/forum/main.php @@ -62,13 +62,12 @@ class Forum extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Forum"); + $sb = $event->panel->create_new_block("Forum"); $sb->add_int_option("forumTitleSubString", "Title max long: "); $sb->add_int_option("forumThreadsPerPage", "
Threads per page: "); $sb->add_int_option("forumPostsPerPage", "
Posts per page: "); $sb->add_int_option("forumMaxCharsPerPost", "
Max chars per post: "); - $event->panel->add_block($sb); } public function onUserPageBuilding(UserPageBuildingEvent $event) diff --git a/ext/google_analytics/main.php b/ext/google_analytics/main.php index c38f8100..72c0f4e9 100644 --- a/ext/google_analytics/main.php +++ b/ext/google_analytics/main.php @@ -5,10 +5,9 @@ class GoogleAnalytics extends Extension # Add analytics to config public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Google Analytics"); + $sb = $event->panel->create_new_block("Google Analytics"); $sb->add_text_option("google_analytics_id", "Analytics ID: "); $sb->add_label("
(eg. UA-xxxxxxxx-x)"); - $event->panel->add_block($sb); } # Load Analytics tracking code on page request diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index d6a57098..55c7b686 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -12,11 +12,10 @@ class ArchiveFileHandler extends DataHandlerExtension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Archive Handler Options"); + $sb = $event->panel->create_new_block("Archive Handler Options"); $sb->add_text_option("archive_tmp_dir", "Temporary folder: "); $sb->add_text_option("archive_extract_command", "
Extraction command: "); $sb->add_label("
%f for archive, %d for temporary directory"); - $event->panel->add_block($sb); } public function onDataUpload(DataUploadEvent $event) diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index e0134103..11d3a356 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -46,14 +46,13 @@ class VideoFileHandler extends DataHandlerExtension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Video Options"); + $sb = $event->panel->create_new_block("Video Options"); $sb->start_table(); $sb->add_bool_option(VideoFileHandlerConfig::PLAYBACK_AUTOPLAY, "Autoplay", true); $sb->add_bool_option(VideoFileHandlerConfig::PLAYBACK_LOOP, "Loop", true); $sb->add_bool_option(VideoFileHandlerConfig::PLAYBACK_MUTE, "Mute", true); $sb->add_multichoice_option(VideoFileHandlerConfig::ENABLED_FORMATS, $this->get_options(), "Enabled Formats", true); $sb->end_table(); - $event->panel->add_block($sb); } protected function media_check_properties(MediaCheckPropertiesEvent $event): void diff --git a/ext/holiday/main.php b/ext/holiday/main.php index 9c722fd9..7d911c36 100644 --- a/ext/holiday/main.php +++ b/ext/holiday/main.php @@ -13,9 +13,8 @@ class Holiday extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Holiday Theme"); + $sb = $event->panel->create_new_block("Holiday Theme"); $sb->add_bool_option("holiday_aprilfools", "Enable April Fools"); - $event->panel->add_block($sb); } public function onPageRequest(PageRequestEvent $event) diff --git a/ext/home/main.php b/ext/home/main.php index 4da456ed..6dbcfbf4 100644 --- a/ext/home/main.php +++ b/ext/home/main.php @@ -27,11 +27,10 @@ class Home extends Extension $counters[ucfirst($name)] = $name; } - $sb = new SetupBlock("Home Page"); + $sb = $event->panel->create_new_block("Home Page"); $sb->add_longtext_option("home_links", 'Page Links (Use BBCode, leave blank for defaults)'); $sb->add_longtext_option("home_text", "
Page Text:
"); $sb->add_choice_option("home_counter", $counters, "
Counter: "); - $event->panel->add_block($sb); } diff --git a/ext/image/main.php b/ext/image/main.php index 0c568c65..80a03391 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -256,7 +256,7 @@ class ImageIO extends Extension { global $config; - $sb = new SetupBlock("Post Options"); + $sb = $event->panel->create_new_block("Post Options"); $sb->start_table(); $sb->position = 30; // advanced only @@ -270,9 +270,8 @@ class ImageIO extends Extension $sb->add_bool_option(ImageConfig::SHOW_META, "Show metadata", true); } $sb->end_table(); - $event->panel->add_block($sb); - $sb = new SetupBlock("Thumbnailing"); + $sb = $event->panel->create_new_block("Thumbnailing"); $sb->start_table(); $sb->add_choice_option(ImageConfig::THUMB_ENGINE, self::THUMBNAIL_ENGINES, "Engine", true); $sb->add_choice_option(ImageConfig::THUMB_MIME, self::THUMBNAIL_TYPES, "Filetype", true); @@ -294,8 +293,6 @@ class ImageIO extends Extension } $sb->end_table(); - - $event->panel->add_block($sb); } public function onParseLinkTemplate(ParseLinkTemplateEvent $event) diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 77f67f94..d4b4b682 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -5,6 +5,14 @@ class ImageViewCounter extends Extension protected $theme; private $view_interval = 3600; # allows views to be added each hour + # Add Setup Block with options for view counter + public function onSetupBuilding(SetupBuildingEvent $event) + { + $sb = $event->panel->create_new_block("Post View Counter"); + $sb->add_bool_option("image_viewcounter_adminonly", "Display view counter only to admin"); + } + + # Adds view to database if needed public function onDisplayingImage(DisplayingImageEvent $event) { global $database, $user; diff --git a/ext/index/main.php b/ext/index/main.php index cd73aa16..20e7793e 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -120,14 +120,12 @@ class Index extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Index Options"); + $sb = $event->panel->create_new_block("Index Options"); $sb->position = 20; $sb->add_label("Show "); $sb->add_int_option(IndexConfig::IMAGES); $sb->add_label(" images on the post list"); - - $event->panel->add_block($sb); } public function onPageNavBuilding(PageNavBuildingEvent $event) diff --git a/ext/ipban/main.php b/ext/ipban/main.php index 7c7da3be..99b36e78 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -209,7 +209,7 @@ class IPBan extends Extension { global $config; - $sb = new SetupBlock("IP Ban"); + $sb = $event->panel->create_new_block("IP Ban"); $sb->add_longtext_option("ipban_message", 'Message to show to banned users:
(with $IP, $DATE, $ADMIN, $REASON, and $CONTACT)'); if ($config->get_string("ipban_message_ghost")) { $sb->add_longtext_option("ipban_message_ghost", 'Message to show to ghost users:'); @@ -217,7 +217,6 @@ class IPBan extends Extension if ($config->get_string("ipban_message_anon-ghost")) { $sb->add_longtext_option("ipban_message_anon-ghost", 'Message to show to ghost anons:'); } - $event->panel->add_block($sb); } public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) diff --git a/ext/link_image/main.php b/ext/link_image/main.php index 11e70cb5..d0fe036c 100644 --- a/ext/link_image/main.php +++ b/ext/link_image/main.php @@ -13,9 +13,8 @@ class LinkImage extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Link to Post"); + $sb = $event->panel->create_new_block("Link to Post"); $sb->add_text_option("ext_link-img_text-link_format", "Text Link Format: "); - $event->panel->add_block($sb); } public function onInitExt(InitExtEvent $event) diff --git a/ext/livefeed/main.php b/ext/livefeed/main.php index 730881c3..259be290 100644 --- a/ext/livefeed/main.php +++ b/ext/livefeed/main.php @@ -4,9 +4,8 @@ class LiveFeed extends Extension { public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Live Feed"); + $sb = $event->panel->create_new_block("Live Feed"); $sb->add_text_option("livefeed_host", "IP:port to send events to: "); - $event->panel->add_block($sb); } public function onUserCreation(UserCreationEvent $event) diff --git a/ext/log_db/main.php b/ext/log_db/main.php index f290fc5a..71ad422c 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -235,7 +235,7 @@ class LogDatabase extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Logging (Database)"); + $sb = $event->panel->create_new_block("Logging (Database)"); $sb->add_choice_option("log_db_priority", [ LOGGING_LEVEL_NAMES[SCORE_LOG_DEBUG] => SCORE_LOG_DEBUG, LOGGING_LEVEL_NAMES[SCORE_LOG_INFO] => SCORE_LOG_INFO, @@ -243,7 +243,6 @@ class LogDatabase extends Extension LOGGING_LEVEL_NAMES[SCORE_LOG_ERROR] => SCORE_LOG_ERROR, LOGGING_LEVEL_NAMES[SCORE_LOG_CRITICAL] => SCORE_LOG_CRITICAL, ], "Debug Level: "); - $event->panel->add_block($sb); } public function onPageRequest(PageRequestEvent $event) diff --git a/ext/media/main.php b/ext/media/main.php index b9371965..a636814e 100644 --- a/ext/media/main.php +++ b/ext/media/main.php @@ -79,7 +79,7 @@ class Media extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Media Engines"); + $sb = $event->panel->create_new_block("Media Engines"); // if (self::imagick_available()) { // try { @@ -101,8 +101,6 @@ class Media extends Extension $sb->add_shorthand_int_option(MediaConfig::MEM_LIMIT, "Mem limit", true); $sb->end_table(); - - $event->panel->add_block($sb); } public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) diff --git a/ext/pools/main.php b/ext/pools/main.php index 86ec0484..c4d4366e 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -177,7 +177,7 @@ class Pools extends Extension // Add a block to the Board Config / Setup public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Pools"); + $sb = $event->panel->create_new_block("Pools"); $sb->add_int_option(PoolsConfig::MAX_IMPORT_RESULTS, "Max results on import: "); $sb->add_int_option(PoolsConfig::IMAGES_PER_PAGE, "
Posts per page: "); $sb->add_int_option(PoolsConfig::LISTS_PER_PAGE, "
Index list items per page: "); @@ -186,8 +186,6 @@ class Pools extends Extension $sb->add_bool_option(PoolsConfig::SHOW_NAV_LINKS, "
Show 'Prev' & 'Next' links when viewing pool images: "); $sb->add_bool_option(PoolsConfig::AUTO_INCREMENT_ORDER, "
Autoincrement order when post is added to pool:"); //$sb->add_bool_option(PoolsConfig::ADDER_ON_VIEW_IMAGE, "
Show pool adder on image: "); - - $event->panel->add_block($sb); } public function onPageNavBuilding(PageNavBuildingEvent $event) diff --git a/ext/post_titles/main.php b/ext/post_titles/main.php index dbff1404..d0e7aa9f 100644 --- a/ext/post_titles/main.php +++ b/ext/post_titles/main.php @@ -64,13 +64,11 @@ class PostTitles extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Post Titles"); + $sb = $event->panel->create_new_block("Post Titles"); $sb->start_table(); $sb->add_bool_option(PostTitlesConfig::DEFAULT_TO_FILENAME, "Default to filename", true); $sb->add_bool_option(PostTitlesConfig::SHOW_IN_WINDOW_TITLE, "Show in window title", true); $sb->end_table(); - - $event->panel->add_block($sb); } public function onBulkExport(BulkExportEvent $event) diff --git a/ext/private_image/main.php b/ext/private_image/main.php index fcb17dd8..08786317 100644 --- a/ext/private_image/main.php +++ b/ext/private_image/main.php @@ -25,15 +25,11 @@ class PrivateImage extends Extension public function onUserOptionsBuilding(UserOptionsBuildingEvent $event) { - global $user, $user_config; - - $event->add_html( - $this->theme->get_user_options( - $user, - $user_config->get_bool(PrivateImageConfig::USER_SET_DEFAULT), - $user_config->get_bool(PrivateImageConfig::USER_VIEW_DEFAULT), - ) - ); + $sb = $event->panel->create_new_block("Private Posts"); + $sb->start_table(); + $sb->add_bool_option(PrivateImageConfig::USER_SET_DEFAULT, "Mark posts private by default", true); + $sb->add_bool_option(PrivateImageConfig::USER_VIEW_DEFAULT, "View private posts by default", true); + $sb->end_table(); } public function onPageRequest(PageRequestEvent $event) diff --git a/ext/private_image/theme.php b/ext/private_image/theme.php index b937c924..dac0d9dd 100644 --- a/ext/private_image/theme.php +++ b/ext/private_image/theme.php @@ -36,31 +36,4 @@ class PrivateImageTheme extends Themelet '; } - - public function get_user_options(User $user, bool $set_by_default, bool $view_by_default): string - { - $html = " -

".make_form(make_link("user_admin/private_image"))." - - - - - - - - - - - - - -
Private Images
- -
- -
- - "; - return $html; - } } diff --git a/ext/random_image/main.php b/ext/random_image/main.php index e0e59355..b9092f49 100644 --- a/ext/random_image/main.php +++ b/ext/random_image/main.php @@ -43,9 +43,8 @@ class RandomImage extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Random Post"); + $sb = $event->panel->create_new_block("Random Post"); $sb->add_bool_option("show_random_block", "Show Random Block: "); - $event->panel->add_block($sb); } public function onPostListBuilding(PostListBuildingEvent $event) diff --git a/ext/random_list/main.php b/ext/random_list/main.php index 95a43ee0..17d47267 100644 --- a/ext/random_list/main.php +++ b/ext/random_list/main.php @@ -57,15 +57,13 @@ class RandomList extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Random Posts List"); + $sb = $event->panel->create_new_block("Random Posts List"); // custom headers $sb->add_int_option( "random_images_list_count", "Amount of Random posts to display " ); - - $event->panel->add_block($sb); } public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) diff --git a/ext/rating/main.php b/ext/rating/main.php index 661831e2..42ed72d6 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -143,15 +143,19 @@ class Ratings extends Extension public function onUserOptionsBuilding(UserOptionsBuildingEvent $event) { - global $user; + global $user, $_shm_ratings; - $event->add_html( - $this->theme->get_user_options( - $user, - self::get_user_default_ratings($user), - self::get_user_class_privs($user) - ) - ); + $levels = self::get_user_class_privs($user); + $options = []; + foreach ($levels as $level) { + $options[$_shm_ratings[$level]->name] = $level; + } + + $sb = $event->panel->create_new_block("Default Rating Filter"); + $sb->start_table(); + $sb->add_multichoice_option(RatingsConfig::USER_DEFAULTS, $options, "Output Log Level: ", true); + $sb->end_table(); + $sb->add_label("This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search."); } public function onSetupBuilding(SetupBuildingEvent $event) @@ -165,7 +169,7 @@ class Ratings extends Extension $options[$rating->name] = $rating->code; } - $sb = new SetupBlock("Post Ratings"); + $sb = $event->panel->create_new_block("Post Ratings"); $sb->start_table(); foreach (array_keys($_shm_user_classes) as $key) { if ($key == "base" || $key == "hellbanned") { @@ -174,8 +178,6 @@ class Ratings extends Extension $sb->add_multichoice_option("ext_rating_" . $key . "_privs", $options, $key, true); } $sb->end_table(); - - $event->panel->add_block($sb); } public function onDisplayingImage(DisplayingImageEvent $event) @@ -417,33 +419,6 @@ class Ratings extends Extension $page->set_redirect(make_link("post/list")); } } - - if ($event->page_matches("user_admin")) { - if (!$user->check_auth_token()) { - return; - } - switch ($event->get_arg(0)) { - case "default_ratings": - if (!array_key_exists("id", $_POST) || empty($_POST["id"])) { - return; - } - if (!array_key_exists("rating", $_POST) || empty($_POST["rating"])) { - return; - } - $id = intval($_POST["id"]); - if ($id != $user->id) { - throw new SCoreException("Cannot change another user's settings"); - } - $ratings = $_POST["rating"]; - - $user_config->set_array(RatingsConfig::USER_DEFAULTS, $ratings); - - $page->set_mode(PageMode::REDIRECT); - $page->set_redirect(make_link("user")); - - break; - } - } } public static function get_sorted_ratings(): array @@ -464,9 +439,9 @@ class Ratings extends Extension return $config->get_array("ext_rating_".$user->class->name."_privs"); } - public static function get_user_default_ratings(User $user): array + public static function get_user_default_ratings(): array { - global $user_config; + global $user_config, $user; $available = self::get_user_class_privs($user); $selected = $user_config->get_array(RatingsConfig::USER_DEFAULTS); diff --git a/ext/rating/theme.php b/ext/rating/theme.php index 52317ea1..7ff8393e 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -96,7 +96,7 @@ class RatingsTheme extends Themelet - + diff --git a/ext/report_image/main.php b/ext/report_image/main.php index 65580cbf..e1547706 100644 --- a/ext/report_image/main.php +++ b/ext/report_image/main.php @@ -157,7 +157,7 @@ class ReportImage extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Post Reports"); + $sb = $event->panel->create_new_block("Post Reports"); $opts = [ "Reporter Only" => "user", @@ -166,8 +166,6 @@ class ReportImage extends Extension "None" => "none", ]; $sb->add_choice_option("report_image_publicity", $opts, "Show publicly: "); - - $event->panel->add_block($sb); } public function delete_reports_by(int $user_id) diff --git a/ext/res_limit/main.php b/ext/res_limit/main.php index e5df6be9..700e7f1e 100644 --- a/ext/res_limit/main.php +++ b/ext/res_limit/main.php @@ -58,7 +58,7 @@ class ResolutionLimit extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Resolution Limits"); + $sb = $event->panel->create_new_block("Resolution Limits"); $sb->add_label("Min "); $sb->add_int_option("upload_min_width"); @@ -77,7 +77,5 @@ class ResolutionLimit extends Extension $sb->add_label("
Ratios "); $sb->add_text_option("upload_ratios"); $sb->add_label("
(eg. '4:3 16:9', blank for no limit)"); - - $event->panel->add_block($sb); } } diff --git a/ext/resize/main.php b/ext/resize/main.php index 234fb232..f3a7af4c 100644 --- a/ext/resize/main.php +++ b/ext/resize/main.php @@ -50,7 +50,7 @@ class ResizeImage extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Image Resize"); + $sb = $event->panel->create_new_block("Image Resize"); $sb->start_table(); $sb->add_choice_option(ResizeConfig::ENGINE, MediaEngine::IMAGE_ENGINES, "Engine", true); $sb->add_bool_option(ResizeConfig::ENABLED, "Allow resizing images", true); @@ -67,7 +67,6 @@ class ResizeImage extends Extension $sb->add_label(""); $sb->add_label(""); $sb->end_table(); - $event->panel->add_block($sb); } public function onDataUpload(DataUploadEvent $event) diff --git a/ext/rotate/main.php b/ext/rotate/main.php index b947ce0d..c0b3d8a6 100644 --- a/ext/rotate/main.php +++ b/ext/rotate/main.php @@ -38,12 +38,11 @@ class RotateImage extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Image Rotate"); + $sb = $event->panel->create_new_block("Image Rotate"); $sb->add_bool_option("rotate_enabled", "Allow rotating images: "); $sb->add_label("
Default Orientation: "); $sb->add_int_option("rotate_default_deg"); $sb->add_label(" deg"); - $event->panel->add_block($sb); } public function onPageRequest(PageRequestEvent $event) diff --git a/ext/setup/main.php b/ext/setup/main.php index 430b3695..305d71fd 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -40,10 +40,19 @@ class SetupPanel { /** @var SetupBlock[] */ public $blocks = []; + /** @var BaseConfig */ + public $config; - public function add_block(SetupBlock $block) + public function __construct(BaseConfig $config) { + $this->config = $config; + } + + public function create_new_block(string $title): SetupBlock + { + $block = new SetupBlock($title, $this->config); $this->blocks[] = $block; + return $block; } } @@ -53,10 +62,13 @@ class SetupBlock extends Block public $header; /** @var string */ public $body; + /** @var BaseConfig */ + public $config; - public function __construct(string $title) + public function __construct(string $title, BaseConfig $config) { parent::__construct($title, "", "main", 50); + $this->config = $config; } public function add_label(string $text) @@ -166,8 +178,7 @@ class SetupBlock extends Block public function add_text_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $val = html_escape($config->get_string($name)); + $val = html_escape($this->config->get_string($name)); $html = "\n"; $html .= "\n"; @@ -177,8 +188,7 @@ class SetupBlock extends Block public function add_longtext_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $val = html_escape($config->get_string($name)); + $val = html_escape($this->config->get_string($name)); $rows = max(3, min(10, count(explode("\n", $val)))); $html = "\n"; @@ -189,8 +199,7 @@ class SetupBlock extends Block public function add_bool_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $checked = $config->get_bool($name) ? " checked" : ""; + $checked = $this->config->get_bool($name) ? " checked" : ""; $html = ""; if (!$table_row&&!is_null($label)) { @@ -215,8 +224,7 @@ class SetupBlock extends Block public function add_int_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $val = $config->get_int($name); + $val = $this->config->get_int($name); $html = "\n"; $html .= "\n"; @@ -226,8 +234,7 @@ class SetupBlock extends Block public function add_shorthand_int_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $val = to_shorthand_int($config->get_int($name)); + $val = to_shorthand_int($this->config->get_int($name)); $html = "\n"; $html .= "\n"; @@ -236,11 +243,10 @@ class SetupBlock extends Block public function add_choice_option(string $name, array $options, string $label=null, bool $table_row = false) { - global $config; if (is_int(array_values($options)[0])) { - $current = $config->get_int($name); + $current = $this->config->get_int($name); } else { - $current = $config->get_string($name); + $current = $this->config->get_string($name); } $html = ""; foreach ($options as $optname => $optval) { @@ -281,8 +286,7 @@ class SetupBlock extends Block public function add_color_option(string $name, string $label=null, bool $table_row = false) { - global $config; - $val = html_escape($config->get_string($name)); + $val = html_escape($this->config->get_string($name)); $html = "\n"; $html .= "\n"; @@ -320,7 +324,7 @@ class Setup extends Extension $this->theme->display_permission_denied(); } else { if ($event->count_args() == 0) { - $panel = new SetupPanel(); + $panel = new SetupPanel($config); send_event(new SetupBuildingEvent($panel)); $this->theme->display_page($page, $panel); } elseif ($event->get_arg(0) == "save" && $user->check_auth_token()) { @@ -370,7 +374,7 @@ class Setup extends Extension } }); "; - $sb = new SetupBlock("General"); + $sb = $event->panel->create_new_block("General"); $sb->position = 0; $sb->add_text_option(SetupConfig::TITLE, "Site title: "); $sb->add_text_option(SetupConfig::FRONT_PAGE, "
Front page: "); @@ -380,20 +384,18 @@ class Setup extends Extension //$sb->add_multichoice_option("testarray", array("a" => "b", "c" => "d"), "
Test Array: "); $sb->add_bool_option("nice_urls", "
Nice URLs: "); $sb->add_label("(Javascript inactive, can't test!)$nicescript"); - $event->panel->add_block($sb); - $sb = new SetupBlock("Remote API Integration"); + $sb = $event->panel->create_new_block("Remote API Integration"); $sb->add_label("Akismet"); $sb->add_text_option("comment_wordpress_key", "
API key: "); $sb->add_label("
 
ReCAPTCHA"); $sb->add_text_option("api_recaptcha_privkey", "
Secret key: "); $sb->add_text_option("api_recaptcha_pubkey", "
Site key: "); - $event->panel->add_block($sb); } public function onConfigSave(ConfigSaveEvent $event) { - global $config; + $config = $event->config; foreach ($_POST as $_name => $junk) { if (substr($_name, 0, 6) == "_type_") { $name = substr($_name, 6); diff --git a/ext/setup/theme.php b/ext/setup/theme.php index 71aa0d9f..1c039c1a 100644 --- a/ext/setup/theme.php +++ b/ext/setup/theme.php @@ -8,7 +8,7 @@ class SetupTheme extends Themelet * $panel = the container of the blocks * $panel->blocks the blocks to be displayed, unsorted * - * It's recommented that the theme sort the blocks before doing anything + * It's recommended that the theme sort the blocks before doing anything * else, using: usort($panel->blocks, "blockcmp"); * * The page should wrap all the options in a form which links to setup_save diff --git a/ext/site_description/main.php b/ext/site_description/main.php index c6b73902..38b19fb2 100644 --- a/ext/site_description/main.php +++ b/ext/site_description/main.php @@ -17,9 +17,8 @@ class SiteDescription extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Site Description"); + $sb = $event->panel->create_new_block("Site Description"); $sb->add_text_option("site_description", "Description: "); $sb->add_text_option("site_keywords", "
Keywords: "); - $event->panel->add_block($sb); } } diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 5c940d4e..3983ce82 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -28,13 +28,11 @@ class XMLSitemap extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Sitemap"); + $sb = $event->panel->create_new_block("Sitemap"); $sb->add_bool_option("sitemap_generatefull", "Generate full sitemap"); $sb->add_label("
(Enabled: every image and tag in sitemap, generation takes longer)"); $sb->add_label("
(Disabled: only display the last 50 uploads in the sitemap)"); - - $event->panel->add_block($sb); } // sitemap with only the latest 50 images diff --git a/ext/source_history/main.php b/ext/source_history/main.php index 788dcc6b..5bf2fac3 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -61,12 +61,11 @@ class SourceHistory extends Extension // so let's default to -1 and the user can go advanced if // they /really/ want to public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Source History"); + $sb = $event->panel->create_new_block("Source History"); $sb->add_label("Limit to "); $sb->add_int_option("history_limit"); $sb->add_label(" entires per image"); $sb->add_label("
(-1 for unlimited)"); - $event->panel->add_block($sb); } */ diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index d8c69755..27e2f89c 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -34,7 +34,7 @@ class TagEditCloud extends Extension { $sort_by = ['Alphabetical'=>'a','Popularity'=>'p','Relevance'=>'r','Categories'=>'c']; - $sb = new SetupBlock("Tag Edit Cloud"); + $sb = $event->panel->create_new_block("Tag Edit Cloud"); $sb->add_bool_option("tageditcloud_disable", "Disable Tag Selection Cloud: "); $sb->add_choice_option("tageditcloud_sort", $sort_by, "
Sort the tags by:"); $sb->add_bool_option("tageditcloud_usedfirst", "
Always show used tags first: "); @@ -47,8 +47,6 @@ class TagEditCloud extends Extension $sb->add_label(" tags."); $sb->add_label("
Relevance sort:
Ignore tags (space separated): "); $sb->add_text_option("tageditcloud_ignoretags"); - - $event->panel->add_block($sb); } private function build_tag_map(Image $image): ?string diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index ae898f07..f99a7df9 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -61,12 +61,11 @@ class TagHistory extends Extension // so let's default to -1 and the user can go advanced if // they /really/ want to public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Tag History"); + $sb = $event->panel->create_new_block("Tag History"); $sb->add_label("Limit to "); $sb->add_int_option("history_limit"); $sb->add_label(" entires per image"); $sb->add_label("
(-1 for unlimited)"); - $event->panel->add_block($sb); } */ diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 610c3aa5..2b8a38bb 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -97,13 +97,12 @@ class TagList extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Tag Map Options"); + $sb = $event->panel->create_new_block("Tag Map Options"); $sb->add_int_option(TagListConfig::TAGS_MIN, "Only show tags used at least "); $sb->add_label(" times"); $sb->add_bool_option(TagListConfig::PAGES, "
Paged tag lists: "); - $event->panel->add_block($sb); - $sb = new SetupBlock("Popular / Related Tag List"); + $sb = $event->panel->create_new_block("Popular / Related Tag List"); $sb->add_int_option(TagListConfig::LENGTH, "Show top "); $sb->add_label(" related tags"); $sb->add_int_option(TagListConfig::POPULAR_TAG_LIST_LENGTH, "
Show top "); @@ -131,7 +130,6 @@ class TagList extends Extension ); $sb->add_bool_option("tag_list_numbers", "Show tag counts", true); $sb->end_table(); - $event->panel->add_block($sb); } /** diff --git a/ext/transcode/main.php b/ext/transcode/main.php index 04fc468f..ab55c1d3 100644 --- a/ext/transcode/main.php +++ b/ext/transcode/main.php @@ -141,7 +141,7 @@ class TranscodeImage extends Extension $engine = $config->get_string(TranscodeConfig::ENGINE); - $sb = new SetupBlock("Image Transcode"); + $sb = $event->panel->create_new_block("Image Transcode"); $sb->start_table(); $sb->add_bool_option(TranscodeConfig::ENABLED, "Allow transcoding images", true); $sb->add_bool_option(TranscodeConfig::GET_ENABLED, "Enable GET args", true); @@ -156,7 +156,6 @@ class TranscodeImage extends Extension $sb->add_int_option(TranscodeConfig::QUALITY, "Lossy Format Quality", true); $sb->add_color_option(TranscodeConfig::ALPHA_COLOR, "Alpha Conversion Color", true); $sb->end_table(); - $event->panel->add_block($sb); } public function onDataUpload(DataUploadEvent $event) diff --git a/ext/transcode_video/main.php b/ext/transcode_video/main.php index 8ca820de..ce7a4613 100644 --- a/ext/transcode_video/main.php +++ b/ext/transcode_video/main.php @@ -54,12 +54,13 @@ class TranscodeVideo extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Video Transcode"); + global $config; + + $sb = $event->panel->create_new_block("Video Transcode"); $sb->start_table(); $sb->add_bool_option(TranscodeVideoConfig::ENABLED, "Allow transcoding images: ", true); $sb->add_bool_option(TranscodeVideoConfig::UPLOAD_TO_NATIVE_CONTAINER, "Convert videos using MPEG-4 or WEBM to their native containers:", true); $sb->end_table(); - $event->panel->add_block($sb); } public function onDataUpload(DataUploadEvent $event) diff --git a/ext/update/main.php b/ext/update/main.php index d6d5c36f..94c24492 100644 --- a/ext/update/main.php +++ b/ext/update/main.php @@ -15,9 +15,8 @@ class Update extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Update"); + $sb = $event->panel->create_new_block("Update"); $sb->add_text_option("update_guserrepo", "User/Repo: "); - $event->panel->add_block($sb); } public function onAdminBuilding(AdminBuildingEvent $event) diff --git a/ext/upload/main.php b/ext/upload/main.php index 6ffb4cc8..f30b2a88 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -132,7 +132,7 @@ class Upload extends Extension $tes["fopen"] = "fopen"; $tes["WGet"] = "wget"; - $sb = new SetupBlock("Upload"); + $sb = $event->panel->create_new_block("Upload"); $sb->position = 10; // Output the limits from PHP so the user has an idea of what they can set. $sb->add_int_option(UploadConfig::COUNT, "Max uploads: "); @@ -141,7 +141,6 @@ class Upload extends Extension $sb->add_label("PHP Limit = " . ini_get('upload_max_filesize') . ""); $sb->add_choice_option(UploadConfig::TRANSLOAD_ENGINE, $tes, "
Transload: "); $sb->add_bool_option(UploadConfig::TLSOURCE, "
Use transloaded URL as source if none is provided: "); - $event->panel->add_block($sb); } diff --git a/ext/user/events.php b/ext/user/events.php index ad012a63..0fd73f1e 100644 --- a/ext/user/events.php +++ b/ext/user/events.php @@ -14,10 +14,21 @@ class UserBlockBuildingEvent extends Event } } -class UserOptionsBuildingEvent extends Event +class UserOperationsBuildingEvent extends Event { /** @var array */ public $parts = []; + /** @var User */ + public $user = []; + /** @var BaseConfig */ + public $user_config = []; + + public function __construct(User $user, BaseConfig $user_config) + { + parent::__construct(); + $this->user = $user; + $this->user_config = $user_config; + } public function add_html(string $html) { diff --git a/ext/user/main.php b/ext/user/main.php index b3d54433..e80ff95c 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -240,10 +240,11 @@ class UserPage extends Extension if (!$user->is_anonymous()) { if ($user->id == $event->display_user->id || $user->can("edit_user_info")) { - $uobe = new UserOptionsBuildingEvent(); - send_event($uobe); + $user_config = UserConfig::get_for_user($event->display_user->id); - $page->add_block(new Block("Options", $this->theme->build_options($event->display_user, $uobe), "main", 60)); + $uobe = new UserOperationsBuildingEvent($event->display_user, $user_config); + send_event($uobe); + $page->add_block(new Block("Operations", $this->theme->build_operations($event->display_user, $uobe), "main", 60)); } } @@ -275,7 +276,7 @@ class UserPage extends Extension "Gravatar" => "gravatar" ]; - $sb = new SetupBlock("User Options"); + $sb = $event->panel->create_new_block("User Options"); $sb->start_table(); $sb->add_bool_option(UserConfig::ENABLE_API_KEYS, "Enable user API keys", true); $sb->add_bool_option("login_signup_enabled", "Allow new signups", true); @@ -316,8 +317,6 @@ class UserPage extends Extension ); } $sb->end_table(); - - $event->panel->add_block($sb); } public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) @@ -361,8 +360,8 @@ class UserPage extends Extension } } - public const USER_SEARCH_REGEX = "/^(?:poster|user)[=|:](.*)$/i"; - public const USER_ID_SEARCH_REGEX = "/^(?:poster|user)_id[=|:]([0-9]+)$/i"; + public const USER_SEARCH_REGEX = "/^(?:poster|user)(!?)[=|:](.*)$/i"; + public const USER_ID_SEARCH_REGEX = "/^(?:poster|user)_id(!?)[=|:]([0-9]+)$/i"; public static function has_user_query(array $context): bool { @@ -385,11 +384,11 @@ class UserPage extends Extension $matches = []; if (preg_match(self::USER_SEARCH_REGEX, $event->term, $matches)) { - $user_id = User::name_to_id($matches[1]); - $event->add_querylet(new Querylet("images.owner_id = $user_id")); + $user_id = User::name_to_id($matches[2]); + $event->add_querylet(new Querylet("images.owner_id ${matches[1]}= $user_id")); } elseif (preg_match(self::USER_ID_SEARCH_REGEX, $event->term, $matches)) { - $user_id = int_escape($matches[1]); - $event->add_querylet(new Querylet("images.owner_id = $user_id")); + $user_id = int_escape($matches[2]); + $event->add_querylet(new Querylet("images.owner_id ${matches[1]}= $user_id")); } elseif ($user->can(Permissions::VIEW_IP) && preg_match("/^(?:poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) { $user_ip = $matches[1]; // FIXME: ip_escape? $event->add_querylet(new Querylet("images.owner_ip = '$user_ip'")); diff --git a/ext/user/theme.php b/ext/user/theme.php index 0add94ad..35854925 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -229,7 +229,8 @@ class UserPageTheme extends Themelet $page->add_block(new Block("Stats", join("
", $stats), "main", 10)); } - public function build_options(User $duser, UserOptionsBuildingEvent $event): string + + public function build_operations(User $duser, UserOperationsBuildingEvent $event): string { global $config, $user; $html = emptyHTML(); diff --git a/ext/user_config/main.php b/ext/user_config/main.php index 4a9510e1..7d47abb3 100644 --- a/ext/user_config/main.php +++ b/ext/user_config/main.php @@ -19,6 +19,27 @@ class InitUserConfigEvent extends Event } } + +class UserOptionsBuildingEvent extends Event +{ + /** @var SetupTheme */ + protected $theme; + + /** @var SetupPanel */ + public $panel; + + /** @var User */ + public $user = []; + + + public function __construct(User $user, SetupPanel $panel) + { + parent::__construct(); + $this->user = $user; + $this->panel = $panel; + } +} + class UserConfig extends Extension { /** @var UserConfigTheme */ @@ -36,10 +57,20 @@ class UserConfig extends Extension public function onUserLogin(UserLoginEvent $event) { - global $database, $user_config; + global $user_config; - $user_config = new DatabaseConfig($database, "user_config", "user_id", "{$event->user->id}"); - send_event(new InitUserConfigEvent($event->user, $user_config)); + $user_config = self::get_for_user($event->user->id); + } + + public static function get_for_user(int $id): BaseConfig + { + global $database; + + $user = User::by_id($id); + + $user_config = new DatabaseConfig($database, "user_config", "user_id", "$id"); + send_event(new InitUserConfigEvent($user, $user_config)); + return $user_config; } public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void @@ -60,9 +91,17 @@ class UserConfig extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if ($event->parent==="user" && !$user->is_anonymous()) { + $event->add_nav_link("user_config", new Link('user_config'), "User Options", false, 40); + } + } + public function onPageRequest(PageRequestEvent $event) { - global $user, $database, $config, $page; + global $user, $database, $config, $page, $user_config; if ($config->get_bool(self::ENABLE_API_KEYS)) { if (!empty($_GET["api_key"]) && $user->is_anonymous()) { @@ -79,8 +118,6 @@ class UserConfig extends Extension } } - global $user_config; - if ($event->page_matches("user_admin")) { if (!$user->check_auth_token()) { return; @@ -96,22 +133,58 @@ class UserConfig extends Extension } } } - } - public function onUserOptionsBuilding(UserOptionsBuildingEvent $event) - { - global $config, $user_config; + if ($event->page_matches("user_config")) { + if (!$user->can(Permissions::CHANGE_USER_SETTING)) { + $this->theme->display_permission_denied(); + } else { + if ($event->count_args() == 0) { + $display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0)); - if ($config->get_bool(self::ENABLE_API_KEYS)) { - $key = $user_config->get_string(self::API_KEY, ""); - if (empty($key)) { - $key = generate_key(); - $user_config->set_string(self::API_KEY, $key); + if ($user->id!=$display_user->id && !$user->can(Permissions::CHANGE_OTHER_USER_SETTING)) { + $this->theme->display_permission_denied(); + return; + } + + $uobe = new UserOptionsBuildingEvent($display_user, new SetupPanel($user_config)); + send_event($uobe); + + $this->theme->display_user_config_page($page, $uobe->user, $uobe->panel); + } elseif ($event->get_arg(0) == "save" && $user->check_auth_token()) { + $input = validate_input([ + 'id' => 'user_id,exists' + ]); + $duser = User::by_id($input['id']); + + if ($user->id!=$duser->id && !$user->can(Permissions::CHANGE_OTHER_USER_SETTING)) { + $this->theme->display_permission_denied(); + return; + } + + $target_config = UserConfig::get_for_user($duser->id); + send_event(new ConfigSaveEvent($target_config)); + $target_config->save(); + $page->flash("Config saved"); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link("user_config")); + } } - $event->add_html($this->theme->get_user_options($key)); } } + public function onUserOperationsBuilding(UserOperationsBuildingEvent $event) + { + global $config; + + if ($config->get_bool(self::ENABLE_API_KEYS)) { + $key = $event->user_config->get_string(self::API_KEY, ""); + if (empty($key)) { + $key = generate_key(); + $event->user_config->set_string(self::API_KEY, $key); + } + $event->add_html($this->theme->get_user_operations($key)); + } + } // This needs to happen before any other events, but after db upgrade public function get_priority(): int diff --git a/ext/user_config/style.css b/ext/user_config/style.css new file mode 100644 index 00000000..bc460fa4 --- /dev/null +++ b/ext/user_config/style.css @@ -0,0 +1,43 @@ +.setupblocks { + column-width: 400px; + -moz-column-width: 400px; + -webkit-column-width: 400px; + max-width: 1200px; + margin: auto; +} +.setupblocks > .setupblock:first-of-type { margin-top: 0; } + +.setupblock { + break-inside: avoid; + -moz-break-inside: avoid; + -webkit-break-inside: avoid; + column-break-inside: avoid; + -moz-column-break-inside: avoid; + -webkit-column-break-inside: avoid; + text-align: center; + width: 90%; +} +.setupblock TEXTAREA { + width: 100%; + font-size: 0.75em; + resize: vertical; +} + +.helpable { + border-bottom: 1px dashed gray; +} + +.ok { + background: #AFA; +} +.bad { + background: #FAA; +} + +#Setupmain .blockbody { + background: none; + border: none; + box-shadow: none; + margin: 0; + padding: 0; +} diff --git a/ext/user_config/theme.php b/ext/user_config/theme.php index ebca7c3d..144eca67 100644 --- a/ext/user_config/theme.php +++ b/ext/user_config/theme.php @@ -2,7 +2,7 @@ class UserConfigTheme extends Themelet { - public function get_user_options(string $key): string + public function get_user_operations(string $key): string { $html = "

".make_form(make_link("user_admin/reset_api_key"))." @@ -22,4 +22,57 @@ class UserConfigTheme extends Themelet "; return $html; } + + + /* + * Display a set of setup option blocks + * + * $panel = the container of the blocks + * $panel->blocks the blocks to be displayed, unsorted + * + * It's recommended that the theme sort the blocks before doing anything + * else, using: usort($panel->blocks, "blockcmp"); + * + * The page should wrap all the options in a form which links to setup_save + */ + public function display_user_config_page(Page $page, User $user, SetupPanel $panel) + { + usort($panel->blocks, "blockcmp"); + + /* + * Try and keep the two columns even; count the line breaks in + * each an calculate where a block would work best + */ + $setupblock_html = ""; + foreach ($panel->blocks as $block) { + $setupblock_html .= $this->sb_to_html($block); + } + + $table = " + ".make_form(make_link("user_config/save"))." + +

$setupblock_html
+ + + "; + + $page->set_title("User Options"); + $page->set_heading("User Options"); + $page->add_block(new Block("User Options", $table)); + $page->set_mode(PageMode::PAGE); + } + + protected function sb_to_html(SetupBlock $block) + { + $h = $block->header; + $b = $block->body; + $i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup"; + $html = " +
+ $h +
$b
+
+ "; + return $html; + } } diff --git a/ext/wiki/main.php b/ext/wiki/main.php index c85eeeb5..df8787f1 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -115,10 +115,8 @@ class Wiki extends Extension // Add a block to the Board Config / Setup public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Wiki"); + $sb = $event->panel->create_new_block("Wiki"); $sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: "); - - $event->panel->add_block($sb); } public function onDatabaseUpgrade(DatabaseUpgradeEvent $event) diff --git a/ext/word_filter/main.php b/ext/word_filter/main.php index 306cdb2a..1b3bd4e9 100644 --- a/ext/word_filter/main.php +++ b/ext/word_filter/main.php @@ -16,10 +16,9 @@ class WordFilter extends Extension public function onSetupBuilding(SetupBuildingEvent $event) { - $sb = new SetupBlock("Word Filter"); + $sb = $event->panel->create_new_block("Word Filter"); $sb->add_longtext_option("word_filter"); $sb->add_label("
(each line should be search term and replace term, separated by a comma)"); - $event->panel->add_block($sb); } private function filter(string $text): string diff --git a/themes/lite/user_config.theme.php b/themes/lite/user_config.theme.php new file mode 100644 index 00000000..c1b6f68e --- /dev/null +++ b/themes/lite/user_config.theme.php @@ -0,0 +1,42 @@ +header; + $b = $block->body; + $i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup"; + $html = " + +
+ $h +
$b
+
+ "; + + return $this->rr($html); + } +}
Default Rating Filter
This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search.
px
(enter 0 for no default)