📄 cms.pm
字号:
} return $app->build_page("bm_entry.tmpl", \%param); } elsif ($param{output}) { return $app->build_page($param{output}, \%param); } else { return $app->build_page("edit_${type}.tmpl", \%param); } } sub save_object { my $app = shift; my $q = $app->{query}; my $type = $q->param('_type'); my $id = $q->param('id'); $app->validate_magic() or return; # Check permissions my $perms = $app->{perms}; return $app->error($app->translate("No permissions")) if !$perms && $id && $type ne 'author'; if ($id && ($type eq 'blog' && !$perms->can_edit_config) || ($type eq 'template' && !$perms->can_edit_templates)) { return $app->error($app->translate("Permission denied.")) } if ($type eq 'blog' && !$id && !$app->{author}->can_create_blog) { return $app->error($app->translate("Permission denied.")); } if ($type eq 'category' && !$perms->can_edit_categories()) { return $app->error($app->translate("Permission denied")); } if ($type eq 'author') { my $name = $app->param('name'); $name =~ s/(^\s+|\s+$)//g; $app->param('name', $name); return $app->errtrans("Author requires username") if ($name !~ /\w/); ## If we are saving an author profile, we need to do some ## password maintenance. First make sure that the two ## passwords match... if ($q->param('pass') ne $q->param('pass_verify')) { my %param = (error => 'Passwords do not match.'); my $qual = $id ? '' : 'author_state_'; for my $f (qw( name email url )) { $param{$qual . $f} = $q->param($f); } $param{checked_blog_ids} = { map { $_ => 1 } $q->param('add_to_blog') }; my $meth = $id ? 'edit_object' : 'edit_permissions'; return $app->$meth(\%param); } ## ... then check to make sure that the author isn't trying ## to change his/her username to one that already exists. $name = $q->param('name'); my $existing = MT::Author->load({ name => $name, type => MT::Author::AUTHOR}); if ($existing && (!$q->param('id') || $existing->id != $q->param('id'))) { my %param = (error => 'An author by that name already exists.'); my $qual = $id ? '' : 'author_state_'; for my $f (qw( name email url )) { $param{$qual . $f} = $q->param($f); } $param{checked_blog_ids} = { map { $_ => 1 } $q->param('add_to_blog') }; my $meth = $id ? 'edit_object' : 'edit_permissions'; return $app->$meth(\%param); } } elsif ($type eq 'notification') { my $email = lc $q->param('email'); $email =~ s/(^\s+|\s+$)//g; my $blog_id = $q->param('blog_id'); if (!is_valid_email($email)) { return $app->error($app->translate("The value you entered was not a valid email address")); } require MT::Notification; # duplicate check my $notification_iter = MT::Notification->load_iter({blog_id => $blog_id}); while (my $obj = $notification_iter->()) { if (lc($obj->email) eq $email) { return $app->error($app->translate("The e-mail address you entered is already on the Notification List for this weblog.")); } } } if ($type eq 'banlist') { my $ip = $q->param('ip'); $ip =~ s/(^\s+|\s+$)//g; return $app->error($app->translate("You did not enter an IP address to ban.")) if ('' eq $ip); my $blog_id = $q->param('blog_id'); require MT::IPBanList; my $existing = MT::IPBanList->load({ 'ip' => $ip, 'blog_id' => $blog_id}); if ($existing && (!$id || $existing->id != $id)) { return $app->error($app->translate("The IP you entered is already banned for this weblog.")); } } if ($type eq 'blog') { my $name = $q->param('name'); $name =~ s/(^\s+|\s+$)//g; $q->param('name', $name); return $app->errtrans("You did not specify a weblog name.") if $q->param('name') eq '' && !$q->param('cfg_screen'); return $app->errtrans("There is already a weblog by that name!") if (grep { $_->id != $q->param('id')} MT::Blog->load({name => $name})); } if ($type eq 'category') { return $app->errtrans("The name '[_1]' is too long!", $q->param('label')) if (length($q->param('label')) > 100); } my $class = $app->_load_driver_for($type) or return; my($obj); if ($id) { $obj = $class->load($id); } else { $obj = $class->new; } my $original = $obj->clone(); my $names = $obj->column_names; my %values = map { $_ => (scalar $q->param($_)) } @$names; if ($type eq 'comment') { my $entry = MT::Entry->load($obj->entry_id); if (!($entry->author_id == $app->{author}->id || $perms->can_edit_all_posts)) { return $app->error($app->translate("Permission denied.")); } } $obj->set_values(\%values); if ($type eq 'author') { # Authors should only be of type AUTHOR when created from # the CMS app; COMMENTERs are created from the Comments app. $obj->type(MT::Author::AUTHOR); if (my $pass = $q->param('pass')) { $obj->set_password($pass); } ## If this is an author editing his/her profile, $id will be ## some defined value; if so we should update the author's ## cookie to reflect any changes made to username and password. ## Otherwise, this is a new user, and we shouldn't update the ## cookie. if ($id) { my($remember)=(split /::/, $app->{cookies}->{mt_user}->value)[2]; my %arg = ( -name => 'mt_user', -value => join('::', $obj->name, $obj->password, $remember), -path => $app->path, ); $arg{-expires} = '+10y' if $remember; $app->bake_cookie(%arg); } } elsif ($type eq 'template') { $obj->rebuild_me(0) unless $q->param('rebuild_me'); # (this is to hack around browsers' unwillingness to send value # of a disabled checkbox.) my $blog = MT::Blog->load($obj->blog_id); if ($blog->custom_dynamic_templates eq 'custom') { $obj->build_dynamic(0) unless $q->param('build_dynamic'); } elsif ($blog->custom_dynamic_templates eq 'archives') { $obj->build_dynamic($obj->type eq 'archive' || $obj->type eq 'category' || $obj->type eq 'individual') } else { $obj->build_dynamic(0) unless $obj->build_dynamic; } ## Strip linefeed characters. (my $text = $values{text}) =~ tr/\r//d; $obj->text($text); } elsif ($type eq 'blog') { if ($q->param('cfg_screen')) { my @fields = qw( email_new_comments allow_comment_html autolink_urls allow_comments_default convert_paras_comments allow_anon_comments allow_unreg_comments allow_reg_comments moderate_unreg_comments require_comment_emails old_style_archive_links manual_approve_commenters ping_weblogs ping_blogs ping_technorati allow_pings_default email_new_pings autodiscover_links ); for my $cb (@fields) { $obj->$cb(0) if !defined $q->param($cb); } $obj->manual_approve_commenters($q->param('auto_approve_commenters') ? 0 : 1); $obj->allow_anon_comments($q->param('non_anonymous_comments') ? 0 : 1); my $tok = ''; ($tok = $obj->remote_auth_token) =~ s/\s//g; $obj->remote_auth_token($tok); } else { $obj->is_dynamic(0) unless defined $q->param('is_dynamic'); } if ($obj->sanitize_spec eq '1') { $obj->sanitize_spec(scalar $q->param('sanitize_spec_manual')); } ## If this is a new blog, set the preferences and archive ## settings to the defaults. if (!$id) { $obj->days_on_index(7); $obj->words_in_excerpt(40); $obj->sort_order_posts('descend'); $obj->language($app->{author}->preferred_language); $obj->sort_order_comments('ascend'); $obj->file_extension('html'); $obj->convert_paras('__default__'); $obj->allow_unreg_comments(1); $obj->allow_reg_comments(0); $obj->moderate_unreg_comments(1); $obj->allow_comments_default(1); $obj->allow_pings_default(0); $obj->require_comment_emails(0); $obj->convert_paras_comments(1); $obj->sanitize_spec(0); $obj->ping_weblogs(0); $obj->ping_blogs(0); $obj->ping_technorati(0); $obj->archive_type('Individual,Monthly'); $obj->archive_type_preferred('Individual'); $obj->status_default(1); $obj->custom_dynamic_templates('none'); } } elsif ($type eq 'category') { $obj->category_parent(0) if !defined $q->param('category_parent'); $obj->allow_pings(0) if !defined $q->param('allow_pings'); if (defined(my $pass = $q->param('tb_passphrase'))) { $obj->{__tb_passphrase} = $pass; } my @siblings = MT::Category->load({ parent => $obj->parent, blog_id => $obj->blog_id }); foreach (@siblings) { next if $_->id == $obj->id; return $app->errtrans("No categories with the same name can have the same parent") if $_->label eq $obj->label; } } # Done pre-processing the record-to-be-saved; now save it. $obj->touch() if ($type eq 'blog'); $obj->save or return $app->error($app->translate( "Saving object failed: [_1]", $obj->errstr)); if ($type ne 'blog') { my $blog = MT::Blog->load($obj->blog_id); $blog->touch(); $blog->save() or return $app->error("Failed to touch blog"); } if ($type eq 'blog' && !$id) { ## If this is a new blog, we need to set up a permissions ## record for the existing user. require MT::Permission; my $perms = MT::Permission->new; $perms->author_id($app->{author}->id); $perms->blog_id($obj->id); $perms->set_full_permissions; $perms->save; ## Load default templates into new blog database. my $tmpl_list; eval { $tmpl_list = require 'MT/default-templates.pl' }; return $app->error($app->translate( "Can't find default template list; where is " . "'default-templates.pl'?")) if $@ || !$tmpl_list || ref($tmpl_list) ne 'ARRAY' ||!@$tmpl_list; require MT::Template; my @arch_tmpl; for my $val (@$tmpl_list) { $val->{name} = $app->translate($val->{name}); $val->{text} = $app->translate_templatized($val->{text}); my $tmpl = MT::Template->new; $tmpl->set_values($val); $tmpl->build_dynamic(0) unless $tmpl->build_dynamic(); $tmpl->blog_id($obj->id); $tmpl->save or return $app->error($app->translate( "Populating blog with default templates failed: [_1]", $tmpl->errstr)); if ($val->{type} eq 'archive' || $val->{type} eq 'category' || $val->{type} eq 'individual') { push @arch
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -