mourningdove/htdocs/manage/settings/index.bml
2026-05-24 01:03:05 +00:00

466 lines
16 KiB
Text

<?_c
# This code was forked from the LiveJournal project owned and operated
# by Live Journal, Inc. The code has been modified and expanded by
# Dreamwidth Studios, LLC. These files were originally licensed under
# the terms of the license supplied by Live Journal, Inc, which can
# currently be found at:
#
# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
#
# In accordance with the original license, this code and all its
# modifications are provided under the GNU General Public License.
# A copy of that license can be found in the LICENSE file included as
# part of this distribution.
_c?>
<?page
body<=
<?_code
{
use strict;
use vars qw(%GET %POST $title $windowtitle $headextra @errors @warnings);
use LJ::Setting;
use DW::Template;
BML::set_language_scope('/manage/settings/index.bml');
LJ::need_res("stc/tabs.css", "stc/settings.css", "js/settings.js");
LJ::need_res({ group => 'jquery' },
"js/jquery.settings.js"
);
LJ::set_active_resource_group( "jquery" );
my $remote = LJ::get_remote();
my $authas;
my $u;
$authas = $GET{authas} || $remote->user if $remote;
my $can_view_other = $remote && $remote->has_priv( "canview", "subscriptions" );
if ( $can_view_other && $GET{user} && $GET{cat} && $GET{cat} eq 'notifications' ) {
# impersonation mode - check for $u->user ne $authas
$u = LJ::load_user( $GET{user} );
}
if ( $remote && ! defined $u ) {
$u = LJ::get_authas_user($authas);
return LJ::bad_input($ML{'error.invalidauth'})
unless $u;
}
my @cats_order = qw(
account
display
community
notifications
mobile
shortcuts
privacy
history
othersites
);
# the different navigation categories and their settings
my %cats_with_settings = (
account => {
name => $ML{'.cat.account'},
visible => 1,
disabled => !$u ? 1 : 0,
form => 0,
desc => $ML{'.cat.account.desc'},
settings => [qw(
DW::Setting::Display::AccountLevel
LJ::Setting::Display::AccountStatus
LJ::Setting::Display::Email
LJ::Setting::Display::Password
DW::Setting::Display::Manage2FA
)],
},
display => {
name => $ML{'.cat.display'},
visible => 1,
disabled => 0,
form => 1,
desc => $ML{'.cat.display.desc'},
settings => [qw(
LJ::Setting::TimeZone
DW::Setting::TimeFormat
LJ::Setting::ImagePlaceholders
LJ::Setting::EmbedPlaceholders
DW::Setting::CutDisable
DW::Setting::CutInbox
LJ::Setting::EmailFormat
LJ::Setting::EntryEditor
DW::Setting::JournalEntryStyle
DW::Setting::JournalIconsStyle
DW::Setting::ViewEntryStyle
DW::Setting::ViewIconsStyle
DW::Setting::ViewJournalStyle
LJ::Setting::NavStrip
LJ::Setting::NCTalkLinks
LJ::Setting::StyleMine
DW::Setting::DisplayEchi
LJ::Setting::CtxPopup
LJ::Setting::AdultContent
DW::Setting::AdultContentReason
LJ::Setting::ViewingAdultContent
LJ::Setting::SafeSearch
DW::Setting::GoogleAnalytics
DW::Setting::GoogleAnalytics4
DW::Setting::ExcludeOwnStats
DW::Setting::StickyEntry
DW::Setting::MobileView
DW::Setting::RPAccount
LJ::Setting::SiteScheme
)],
},
shortcuts => {
name => $ML{'.cat.shortcuts'},
visible => 1,
disabled => !$u || $u->is_community ? 1 : 0,
form => 1,
desc => $ML{'.cat.shortcuts.desc2'},
settings => [qw(
DW::Setting::Shortcuts
DW::Setting::ShortcutsNext
DW::Setting::ShortcutsPrev
DW::Setting::ShortcutsTouch
DW::Setting::ShortcutsTouchNext
DW::Setting::ShortcutsTouchPrev
)],
},
notifications => {
name => $ML{'.cat.notifications'},
visible => 1,
disabled => !$u || $u->is_community ? 1 : 0,
form => 1,
desc => BML::ml( '.cat.notifications.desc', { aopts => "href='$LJ::SITEROOT/manage/circle/edit'" } ),
settings => [],
},
mobile => {
name => $ML{'.cat.mobile'},
visible => 1,
disabled => !$u || $u->is_community ? 1 : 0,
form => 1,
desc => $ML{'.cat.mobile.desc2'},
settings => [qw(
LJ::Setting::EmailPosting
DW::Setting::ResetReplyEmail
DW::Setting::ApiKeyDelete
DW::Setting::ApiKeyGenerate
)],
},
privacy => {
name => $ML{'.cat.privacy'},
visible => 1,
disabled => !$u ? 1 : 0,
form => 1,
desc => $ML{'.cat.privacy.desc'},
settings => [qw(
DW::Setting::EmailAlias
DW::Setting::ContactInfo
LJ::Setting::UserMessaging
LJ::Setting::MinSecurity
DW::Setting::SynLevel
LJ::Setting::SearchInclusion
LJ::Setting::EnableComments
LJ::Setting::CommentScreening
LJ::Setting::CommentCaptcha
DW::Setting::Captcha
LJ::Setting::CommentIP
LJ::Setting::Display::BanUsers
DW::Setting::AllowVgiftsFrom
DW::Setting::RandomPaidGifts
DW::Setting::GlobalSearch
DW::Setting::AllowSearchBy
DW::Setting::CommunityPromo
)],
},
history => {
name => $ML{'.cat.history'},
visible => 1,
disabled => !$u || $u->is_community ? 1 : 0,
form => 0,
desc => $ML{'.cat.history.desc'},
settings => [qw(
LJ::Setting::Display::Logins
LJ::Setting::Display::Emails
LJ::Setting::Display::EmailPosts
LJ::Setting::Display::Orders
DW::Setting::Display::CommunityInvites
DW::Setting::Display::OpenIDClaim
)],
},
othersites => {
name => $ML{'.cat.othersites'},
visible => 1,
disabled => !$u || $u->is_community ? 1 : 0,
form => 1,
desc => $ML{'.cat.othersites.desc'},
settings => [qw(
DW::Setting::XPostAccounts
)],
},
community => {
name => $ML{'.cat.community'},
visible => $u && $u->is_community ? 1 : 0,
disabled => 0,
form => 1,
desc => $ML{'.cat.community.desc'},
settings => [qw(
DW::Setting::CommunityMembership
DW::Setting::CommunityPostLevel
DW::Setting::CommunityPostLevelNew
DW::Setting::CommunityEntryModeration
DW::Setting::CommunityJoinLinks
DW::Setting::CommunityGuidelinesLocation
DW::Setting::CommunityGuidelinesEntry
)],
}
);
LJ::Hooks::run_hook("settings_extra_cats", \@cats_order, \%cats_with_settings, user => $u);
my $given_cat = $GET{cat};
if ($u) {
$given_cat = "account"
unless defined $cats_with_settings{$given_cat} &&
$cats_with_settings{$given_cat}->{visible} &&
!$cats_with_settings{$given_cat}->{disabled};
} else {
$given_cat = "display";
}
if ( $u && $u->user ne $authas ) {
# can only impersonate notification settings -
# if invisible or disabled, print this error
return LJ::bad_input( $ML{'error.invalidauth'} )
if $given_cat ne 'notifications';
# don't allow editing
$cats_with_settings{notifications}->{form} = 0;
}
my @settings = @{$cats_with_settings{$given_cat}->{settings}};
# remove any settings that don't exist for this category
my $remove_setting = sub {
my $el_ref = shift;
splice(@settings, $$el_ref, 1);
$$el_ref--;
};
for (my $i = 0; $i < scalar @settings; $i++) {
my $setting = $settings[$i];
if (eval "use $setting; 1;") {
$remove_setting->(\$i) unless $setting->should_render($u);
} else {
$remove_setting->(\$i);
}
}
my $save_rv;
my $submit_msg;
if (LJ::did_post()) {
return LJ::bad_input($ML{'error.invalidform'})
unless LJ::check_form_auth();
# can't make changes while impersonating
return LJ::bad_input( $ML{'error.invalidauth'} )
if $u && $u->user ne $authas;
if ( $given_cat eq "notifications" && $POST{deleteinactive} ) {
$u->delete_all_inactive_subscriptions;
$submit_msg .= "<?errorbar $ML{'.success.deleteinactive2'} errorbar?><br />";
} elsif ( $given_cat eq "notifications" ) {
my @notif_errors = $u->save_subscriptions( \%POST );
delete $u->{_subscriptions};
return BML::redirect($POST{ret_url}) if $POST{ret_url} && !scalar @notif_errors;
# save the LJ::Setting notifications too
unless ($POST{post_to_settings_page}) {
$save_rv = LJ::Setting->save_all($u, \%POST, \@settings);
}
if (scalar @notif_errors || LJ::Setting->save_had_errors($save_rv)) {
$submit_msg .= LJ::error_list(@notif_errors) . "<br />";
} else {
$submit_msg .= "<?warningbar $ML{'.success'} warningbar?><br />";
}
} else {
$save_rv = LJ::Setting->save_all($u, \%POST, \@settings);
if (LJ::Setting->save_had_errors($save_rv)) {
$submit_msg .= "<?errorbar $ML{'.errors'} errorbar?><br />";
} else {
$submit_msg .= "<?warningbar $ML{'.success'} warningbar?><br />";
}
}
}
if ( $given_cat eq "notifications" && $u->user eq $authas ) {
# look for deletions from GET
my $deleted_subs = 0;
foreach my $subscr ($u->subscriptions) {
my $id = $subscr->id;
next unless $id;
if ($GET{"deletesub_$id"}) {
$subscr->delete;
$deleted_subs = 1;
}
}
$submit_msg .= "<?warningbar $ML{'.success'} warningbar?><br />"
if $deleted_subs;
}
my $ret = "<div id='settings_page'>";
my ($getextra, $getsep) = ("", "?");
if ( $u && $u->user ne $remote->user ) {
$getextra = "?authas=$authas";
$getsep = "&";
}
$title = $windowtitle = LJ::Lang::ml('.title.anon');
if ($u) {
$title = LJ::Lang::ml('.title.page', { user => $u->ljuser_display({ head_size => "24x24" }) });
$windowtitle = LJ::Lang::ml('.title.page', { user => $u->display_username });
$ret .= "<div id='authas_select'>";
$ret .= "<form action='$LJ::SITEROOT/manage/settings/' method='get'>";
$ret .= LJ::make_authas_select( $remote, { authas => $GET{authas}, showall => ( $given_cat eq "account" ) } );
$ret .= LJ::html_hidden( cat => $given_cat );
$ret .= "</form>";
$ret .= "</div>";
}
# if they're working as a community, reproduce the community management linkbar:
if ( $u && $u->is_community ) {
my $linkbar;
$linkbar = $u->maintainer_linkbar( "settingsaccount" );
$ret .= "<p class='intro'>" . $linkbar . "</p>";
}
$ret .= "<p class='intro'>" . BML::ml('.intro3', { aopts1 => "href='$LJ::SITEROOT/manage/profile/$getextra'", aopts2 => "href='$LJ::SITEROOT/customize/$getextra'" }) . "</p>"
if $u;
$ret .= $submit_msg;
$ret .= "<div id='settings_left'>";
$ret .= "<ul class='tablist' id='settings_nav'>";
foreach my $cat (@cats_order) {
next unless $cats_with_settings{$cat}->{visible};
if ($cats_with_settings{$cat}->{disabled}) {
$ret .= "<li class='tab disabled'>$cats_with_settings{$cat}->{name}</li>";
} else {
my $active_class = $cat eq $given_cat ? " class='active'" : "";
$ret .= "<li class='tab'><a href='$LJ::SITEROOT/manage/settings/$getextra${getsep}cat=$cat'$active_class>$cats_with_settings{$cat}->{name}</a></li>";
}
}
$ret .= "</ul>";
$ret .= "<div id='settings_nav_title' class='tab-header'><p>";
$ret .= $cats_with_settings{$given_cat}->{desc};
$ret .= "</p></div>";
if ($given_cat eq "notifications") {
$u = $u->subscription_default_setup;
my $template_vars = {
has_admin_form => $can_view_other,
has_user_form => $cats_with_settings{$given_cat}->{form},
post_action => "$LJ::SITEROOT/manage/settings/$getextra${getsep}cat=$given_cat",
viewing_self => ( $u->user eq $authas ) ? 1 : 0,
get_args => \%GET,
subscribe_interface => LJ::subscribe_interface(
$u,
journal => $u,
categories => $u->subscription_categories_for_settings_page,
settings_page => 1,
num_per_page => 250,
page => int( $GET{page} || 0 ),
)
};
$ret .= DW::Template->template_string( 'tracking/settings-interface.tt', $template_vars );
} else {
$ret .= "<div class='settings_content'>";
$ret .= "<div class='$given_cat'>";
if ($cats_with_settings{$given_cat}->{form}) {
if ( $LJ::ACTIVE_RES_GROUP ne "jquery" ) {
my $confirm_msg = LJ::ejs($ML{'.form.confirm1'});
$ret .= "<script>Settings.confirm_msg = \"$confirm_msg\";</script>";
}
$ret .= "<form class='table-form' id='settings_form' action='$LJ::SITEROOT/manage/settings/$getextra${getsep}cat=$given_cat' method='post'>";
$ret .= LJ::form_auth();
}
my $setting_ct = 0;
$ret .= "<table summary=''>";
foreach my $setting (@settings) {
$setting_ct++ unless $setting->is_conditional_setting;
my $errors = $setting->errors_from_save($save_rv);
my $args = $setting->args_from_save($save_rv);
my $label = $setting->label;
my $option = $setting->option($u, $errors, $args, getargs => \%GET );
my $actionlink = $setting->actionlink($u);
my $helpicon = LJ::help_icon($setting->helpurl($u));
my $last_class = $setting_ct == scalar @settings ? " last" : "";
my $row_class = $setting_ct % 2 == 0 ? "even" : "odd";
my $setting_id = $setting->pkgkey;
$ret .= "<tr class='$row_class' id='$setting_id'>";
$ret .= "<th class='${given_cat}_label$last_class'>$label</th>" if $label;
$ret .= "<td class='${given_cat}_option$last_class'>" . ($option ? $option : "&nbsp;") . "</td>";
$ret .= "<td class='${given_cat}_actionlink$last_class'>" . ($actionlink ? $actionlink : "&nbsp;") . "</td>";
$ret .= "<td class='help$last_class'>" . ($helpicon ? $helpicon : "&nbsp;") . "</td>";
$ret .= "</tr>";
}
$ret .= "</table>";
if ($given_cat eq "account") {
my $account_stats = LJ::Hooks::run_hook("settings_account_stats", $u);
if ($account_stats) {
$ret .= "<div class='account_stats'>";
$ret .= $account_stats;
$ret .= "</div>";
}
}
$ret .= "</div>";
$ret .= "</div>";
$ret .= "<div id='settings_save' class='action-bar'>";
$ret .= $cats_with_settings{$given_cat}->{form} ? LJ::html_submit($ML{'.btn.save'}) : "&nbsp;";
$ret .= "</div>";
$ret .= "</form>" if $cats_with_settings{$given_cat}->{form};
}
$ret .= "</div>";
$ret .= "</div>";
return $ret;
}
_code?>
<=body
title=><?_code return $title; _code?>
windowtitle=><?_code return $windowtitle; _code?>
head<=
<?_code return $headextra; _code?>
<=head
page?>