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
This commit is contained in:
parent
3ad6ce74d9
commit
72268d529d
59 changed files with 363 additions and 239 deletions
|
@ -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";
|
||||
|
|
|
@ -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,
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<br/>");
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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", "<br />Number of recent entries to display: ");
|
||||
$sb->add_text_option("blotter_color", "<br />Color of important updates: (ABCDEF format) ");
|
||||
$sb->add_choice_option("blotter_position", ["Top of page" => "subheading", "In navigation bar" => "left"], "<br>Position: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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("<br>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("<br>Make samefags public ");
|
||||
$sb->add_bool_option("comment_samefags_public");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||
|
|
|
@ -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("<a href='$documentation_link'>Read the documentation</a> for cron setup instructions.");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onAdminBuilding(AdminBuildingEvent $event)
|
||||
|
|
|
@ -5,7 +5,7 @@ class CustomHtmlHeaders extends Extension
|
|||
# Adds setup block for custom <head> 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"
|
||||
], "<br>Add website name in title");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
|
|
|
@ -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", "<br>");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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", "<br>Threads per page: ");
|
||||
$sb->add_int_option("forumPostsPerPage", "<br>Posts per page: ");
|
||||
|
||||
$sb->add_int_option("forumMaxCharsPerPost", "<br>Max chars per post: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onUserPageBuilding(UserPageBuildingEvent $event)
|
||||
|
|
|
@ -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("<br>(eg. UA-xxxxxxxx-x)");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
# Load Analytics tracking code on page request
|
||||
|
|
|
@ -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", "<br>Extraction command: ");
|
||||
$sb->add_label("<br>%f for archive, %d for temporary directory");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onDataUpload(DataUploadEvent $event)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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", "<br>Page Text:<br>");
|
||||
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:<br>(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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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, "<br>Posts per page: ");
|
||||
$sb->add_int_option(PoolsConfig::LISTS_PER_PAGE, "<br>Index list items per page: ");
|
||||
|
@ -186,8 +186,6 @@ class Pools extends Extension
|
|||
$sb->add_bool_option(PoolsConfig::SHOW_NAV_LINKS, "<br>Show 'Prev' & 'Next' links when viewing pool images: ");
|
||||
$sb->add_bool_option(PoolsConfig::AUTO_INCREMENT_ORDER, "<br>Autoincrement order when post is added to pool:");
|
||||
//$sb->add_bool_option(PoolsConfig::ADDER_ON_VIEW_IMAGE, "<br>Show pool adder on image: ");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onPageNavBuilding(PageNavBuildingEvent $event)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -36,31 +36,4 @@ class PrivateImageTheme extends Themelet
|
|||
</div>
|
||||
';
|
||||
}
|
||||
|
||||
public function get_user_options(User $user, bool $set_by_default, bool $view_by_default): string
|
||||
{
|
||||
$html = "
|
||||
<p>".make_form(make_link("user_admin/private_image"))."
|
||||
<input type='hidden' name='id' value='$user->id'>
|
||||
<table style='width: 300px;'>
|
||||
<tbody>
|
||||
<tr><th colspan='2'>Private Images</th></tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label><input type='checkbox' name='set_default' value='true' " .($set_by_default ? 'checked=checked': ''). " />Mark images private by default</label>
|
||||
</td>
|
||||
</tr><tr>
|
||||
<td>
|
||||
<label><input type='checkbox' name='view_default' value='true' " .($view_by_default ? 'checked=checked': ''). " />View private images by default</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><td><input type='submit' value='Save'></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</form>
|
||||
";
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -96,7 +96,7 @@ class RatingsTheme extends Themelet
|
|||
<input type='hidden' name='id' value='$user->id'>
|
||||
<table style='width: 300px;'>
|
||||
<thead>
|
||||
<tr><th colspan='2'>Default Rating Filter</th></tr>
|
||||
<tr><th colspan='2'></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td>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.</td></tr>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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("<br>Ratios ");
|
||||
$sb->add_text_option("upload_ratios");
|
||||
$sb->add_label("<br>(eg. '4:3 16:9', blank for no limit)");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("</td><td>px</td></tr>");
|
||||
$sb->add_label("<tr><td></td><td>(enter 0 for no default)</td></tr>");
|
||||
$sb->end_table();
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onDataUpload(DataUploadEvent $event)
|
||||
|
|
|
@ -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("<br>Default Orientation: ");
|
||||
$sb->add_int_option("rotate_default_deg");
|
||||
$sb->add_label(" deg");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
|
|
|
@ -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 = "<input type='text' id='{$name}' name='_config_{$name}' value='{$val}'>\n";
|
||||
$html .= "<input type='hidden' name='_type_{$name}' value='string'>\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 = "<textarea rows='$rows' id='$name' name='_config_$name'>$val</textarea>\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 = "<input type='number' id='$name' name='_config_$name' value='$val' size='4' style='text-align: center;' step='1' />\n";
|
||||
$html .= "<input type='hidden' name='_type_$name' value='int' />\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 = "<input type='text' id='$name' name='_config_$name' value='$val' size='6' style='text-align: center;'>\n";
|
||||
$html .= "<input type='hidden' name='_type_$name' value='int'>\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 = "<select id='$name' name='_config_$name'>";
|
||||
|
@ -260,8 +266,7 @@ class SetupBlock extends Block
|
|||
|
||||
public function add_multichoice_option(string $name, array $options, string $label=null, bool $table_row = false)
|
||||
{
|
||||
global $config;
|
||||
$current = $config->get_array($name);
|
||||
$current = $this->config->get_array($name);
|
||||
|
||||
$html = "<select id='$name' name='_config_{$name}[]' multiple size='5'>";
|
||||
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 = "<input type='color' id='{$name}' name='_config_{$name}' value='{$val}'>\n";
|
||||
$html .= "<input type='hidden' name='_type_{$name}' value='string'>\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
|
|||
}
|
||||
});
|
||||
</script>";
|
||||
$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, "<br>Front page: ");
|
||||
|
@ -380,20 +384,18 @@ class Setup extends Extension
|
|||
//$sb->add_multichoice_option("testarray", array("a" => "b", "c" => "d"), "<br>Test Array: ");
|
||||
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
|
||||
$sb->add_label("<span title='$test_url' id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");
|
||||
$event->panel->add_block($sb);
|
||||
|
||||
$sb = new SetupBlock("Remote API Integration");
|
||||
$sb = $event->panel->create_new_block("Remote API Integration");
|
||||
$sb->add_label("<a href='https://akismet.com/'>Akismet</a>");
|
||||
$sb->add_text_option("comment_wordpress_key", "<br>API key: ");
|
||||
$sb->add_label("<br> <br><a href='https://www.google.com/recaptcha/admin'>ReCAPTCHA</a>");
|
||||
$sb->add_text_option("api_recaptcha_privkey", "<br>Secret key: ");
|
||||
$sb->add_text_option("api_recaptcha_pubkey", "<br>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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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", "<br>Keywords: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("<br>(Enabled: every image and tag in sitemap, generation takes longer)");
|
||||
$sb->add_label("<br>(Disabled: only display the last 50 uploads in the sitemap)");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
// sitemap with only the latest 50 images
|
||||
|
|
|
@ -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("<br>(-1 for unlimited)");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -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, "<br>Sort the tags by:");
|
||||
$sb->add_bool_option("tageditcloud_usedfirst", "<br>Always show used tags first: ");
|
||||
|
@ -47,8 +47,6 @@ class TagEditCloud extends Extension
|
|||
$sb->add_label(" tags.");
|
||||
$sb->add_label("<br><b>Relevance sort</b>:<br>Ignore tags (space separated): ");
|
||||
$sb->add_text_option("tageditcloud_ignoretags");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
private function build_tag_map(Image $image): ?string
|
||||
|
|
|
@ -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("<br>(-1 for unlimited)");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -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, "<br>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, "<br>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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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("<i>PHP Limit = " . ini_get('upload_max_filesize') . "</i>");
|
||||
$sb->add_choice_option(UploadConfig::TRANSLOAD_ENGINE, $tes, "<br/>Transload: ");
|
||||
$sb->add_bool_option(UploadConfig::TLSOURCE, "<br/>Use transloaded URL as source if none is provided: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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'"));
|
||||
|
|
|
@ -229,7 +229,8 @@ class UserPageTheme extends Themelet
|
|||
$page->add_block(new Block("Stats", join("<br>", $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();
|
||||
|
|
|
@ -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
|
||||
|
|
43
ext/user_config/style.css
Normal file
43
ext/user_config/style.css
Normal file
|
@ -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;
|
||||
}
|
|
@ -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 = "
|
||||
<p>".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"))."
|
||||
<input type='hidden' name='id' value='".$user->id."'>
|
||||
<div class='setupblocks'>$setupblock_html</div>
|
||||
<input type='submit' value='Save Settings'>
|
||||
</form>
|
||||
";
|
||||
|
||||
$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 = "
|
||||
<section class='setupblock'>
|
||||
<b class='shm-toggler' data-toggle-sel='#$i'>$h</b>
|
||||
<br><div id='$i'>$b</div>
|
||||
</section>
|
||||
";
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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("<br>(each line should be search term and replace term, separated by a comma)");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
private function filter(string $text): string
|
||||
|
|
42
themes/lite/user_config.theme.php
Normal file
42
themes/lite/user_config.theme.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Class CustomSetupTheme
|
||||
*
|
||||
* A customised version of the Setup theme.
|
||||
*
|
||||
*/
|
||||
class CustomUserConfigTheme extends UserConfigTheme
|
||||
{
|
||||
protected function sb_to_html(SetupBlock $block)
|
||||
{
|
||||
$h = $block->header;
|
||||
$b = $block->body;
|
||||
$i = preg_replace('/[^a-zA-Z0-9]/', '_', $h) . "-setup";
|
||||
$html = "
|
||||
<script type='text/javascript'><!--
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
$(\"#$i-toggle\").click(function() {
|
||||
$(\"#$i\").slideToggle(\"slow\", function() {
|
||||
if($(\"#$i\").is(\":hidden\")) {
|
||||
Cookies.set(\"$i-hidden\", 'true', {path: '/'});
|
||||
}
|
||||
else {
|
||||
Cookies.set(\"$i-hidden\", 'false', {path: '/'});
|
||||
}
|
||||
});
|
||||
});
|
||||
if(Cookies.get(\"$i-hidden\") == 'true') {
|
||||
$(\"#$i\").hide();
|
||||
}
|
||||
});
|
||||
//--></script>
|
||||
<div class='setupblock'>
|
||||
<b id='$i-toggle'>$h</b>
|
||||
<br><div id='$i'>$b</div>
|
||||
</div>
|
||||
";
|
||||
|
||||
return $this->rr($html);
|
||||
}
|
||||
}
|
Reference in a new issue