| 72 | | 'list_member' => \&list_member, |
|---|
| 73 | | 'list_user' => \&list_authors, |
|---|
| 74 | | 'list_author' => \&list_authors, |
|---|
| 75 | | 'list_commenter' => \&list_commenter, |
|---|
| 76 | | 'list_asset' => \&list_assets, |
|---|
| 77 | | 'list_blog' => \&list_blogs, |
|---|
| 78 | | 'list_category' => \&list_category, |
|---|
| 79 | | 'list_tag' => \&list_tag, |
|---|
| 80 | | 'list_association' => \&list_associations, |
|---|
| 81 | | 'list_role' => \&list_roles, |
|---|
| 82 | | |
|---|
| 83 | | 'asset_insert' => \&asset_insert, |
|---|
| 84 | | 'asset_userpic' => \&asset_userpic, |
|---|
| 85 | | 'save_commenter_perm' => \&save_commenter_perm, |
|---|
| 86 | | 'trust_commenter' => \&trust_commenter, |
|---|
| 87 | | 'ban_commenter' => \&ban_commenter, |
|---|
| 88 | | 'approve_item' => \&approve_item, |
|---|
| 89 | | 'unapprove_item' => \&unapprove_item, |
|---|
| 90 | | 'preview_entry' => \&preview_entry, |
|---|
| | 66 | 'list_member' => "${pkg}User::list_member", |
|---|
| | 67 | 'list_user' => "${pkg}User::list", |
|---|
| | 68 | 'list_author' => "${pkg}User::list", |
|---|
| | 69 | 'list_commenter' => "${pkg}Comment::list_commenter", |
|---|
| | 70 | 'list_asset' => "${pkg}Asset::list", |
|---|
| | 71 | 'list_blog' => "${pkg}Blog::list", |
|---|
| | 72 | 'list_category' => "${pkg}Category::list", |
|---|
| | 73 | 'list_tag' => "${pkg}Tag::list", |
|---|
| | 74 | 'list_association' => "${pkg}User::list_association", |
|---|
| | 75 | 'list_role' => "${pkg}User::list_role", |
|---|
| | 76 | |
|---|
| | 77 | 'asset_insert' => "${pkg}Asset::insert", |
|---|
| | 78 | 'asset_userpic' => "${pkg}User::asset_userpic", |
|---|
| | 79 | 'save_commenter_perm' => "${pkg}Comment::save_commenter_perm", |
|---|
| | 80 | 'trust_commenter' => "${pkg}Comment::trust_commenter", |
|---|
| | 81 | 'ban_commenter' => "${pkg}Comment::ban_commenter", |
|---|
| | 82 | 'approve_item' => "${pkg}Comment::approve_item", |
|---|
| | 83 | 'unapprove_item' => "${pkg}Comment::unapprove_item", |
|---|
| | 84 | 'preview_entry' => "${pkg}Entry::preview", |
|---|
| 111 | | 'enable_object' => \&enable_object, |
|---|
| 112 | | 'disable_object' => \&disable_object, |
|---|
| 113 | | 'list_action' => \&do_list_action, |
|---|
| 114 | | 'empty_junk' => \&empty_junk, |
|---|
| 115 | | 'handle_junk' => \&handle_junk, |
|---|
| 116 | | 'not_junk' => \¬_junk, |
|---|
| 117 | | |
|---|
| 118 | | 'ping' => \&send_pings, |
|---|
| 119 | | 'rebuild_phase' => \&rebuild_phase, |
|---|
| 120 | | 'rebuild' => \&rebuild_pages, |
|---|
| 121 | | 'rebuild_new_phase' => \&rebuild_new_phase, |
|---|
| 122 | | 'start_rebuild' => \&start_rebuild_pages, |
|---|
| 123 | | 'rebuild_confirm' => \&rebuild_confirm, |
|---|
| 124 | | 'entry_notify' => \&entry_notify, |
|---|
| 125 | | 'send_notify' => \&send_notify, |
|---|
| 126 | | 'start_upload' => \&start_upload, |
|---|
| 127 | | 'upload_file' => \&upload_file, |
|---|
| 128 | | 'upload_userpic' => \&upload_userpic, |
|---|
| 129 | | 'complete_insert' => \&complete_insert, |
|---|
| 130 | | 'complete_upload' => \&complete_upload, |
|---|
| 131 | | 'start_upload_entry' => \&start_upload_entry, |
|---|
| | 105 | 'enable_object' => "${pkg}User::enable", |
|---|
| | 106 | 'disable_object' => "${pkg}User::disable", |
|---|
| | 107 | 'list_action' => "${pkg}Tools::do_list_action", |
|---|
| | 108 | 'empty_junk' => "${pkg}Comment::empty_junk", |
|---|
| | 109 | 'handle_junk' => "${pkg}Comment::handle_junk", |
|---|
| | 110 | 'not_junk' => "${pkg}Comment::not_junk", |
|---|
| | 111 | |
|---|
| | 112 | 'ping' => "${pkg}Entry::send_pings", |
|---|
| | 113 | 'rebuild_phase' => "${pkg}Blog::rebuild_phase", |
|---|
| | 114 | 'rebuild' => "${pkg}Blog::rebuild_pages", |
|---|
| | 115 | 'rebuild_new_phase' => "${pkg}Blog::rebuild_new_phase", |
|---|
| | 116 | 'start_rebuild' => "${pkg}Blog::start_rebuild_pages", |
|---|
| | 117 | 'rebuild_confirm' => "${pkg}Blog::rebuild_confirm", |
|---|
| | 118 | 'entry_notify' => "${pkg}AddressBook::entry_notify", |
|---|
| | 119 | 'send_notify' => "${pkg}AddressBook::send_notify", |
|---|
| | 120 | 'start_upload' => "${pkg}Asset::start_upload", |
|---|
| | 121 | 'upload_file' => "${pkg}Asset::upload_file", |
|---|
| | 122 | 'upload_userpic' => "${pkg}User::upload_userpic", |
|---|
| | 123 | 'complete_insert' => "${pkg}Asset::complete_insert", |
|---|
| | 124 | 'complete_upload' => "${pkg}Asset::complete_upload", |
|---|
| | 125 | 'start_upload_entry' => "${pkg}Asset::start_upload_entry", |
|---|
| 145 | | 'view_log' => \&view_log, |
|---|
| 146 | | 'list_log' => \&view_log, |
|---|
| 147 | | 'reset_log' => \&reset_log, |
|---|
| 148 | | 'export_log' => \&export_log, |
|---|
| 149 | | 'export_notification' => \&export_notification, |
|---|
| 150 | | 'start_import' => \&start_import, |
|---|
| 151 | | 'start_export' => \&start_export, |
|---|
| 152 | | 'export' => \&export, |
|---|
| 153 | | 'import' => \&do_import, |
|---|
| 154 | | 'pinged_urls' => \&pinged_urls, |
|---|
| 155 | | 'save_entry_prefs' => \&save_entry_prefs, |
|---|
| 156 | | 'save_favorite_blogs' => \&save_favorite_blogs, |
|---|
| 157 | | 'reg_file' => \®_file, |
|---|
| | 139 | 'view_log' => "${pkg}Log::view", |
|---|
| | 140 | 'list_log' => "${pkg}Log::view", |
|---|
| | 141 | 'reset_log' => "${pkg}Log::reset", |
|---|
| | 142 | 'export_log' => "${pkg}Log::export", |
|---|
| | 143 | 'export_notification' => "${pkg}AddressBook::export", |
|---|
| | 144 | 'start_import' => "${pkg}Import::start_import", |
|---|
| | 145 | 'start_export' => "${pkg}Export::start_export", |
|---|
| | 146 | 'export' => "${pkg}Export::export", |
|---|
| | 147 | 'import' => "${pkg}Import::do_import", |
|---|
| | 148 | 'pinged_urls' => "${pkg}Entry::pinged_urls", |
|---|
| | 149 | 'save_entry_prefs' => "${pkg}Entry::save_entry_prefs", |
|---|
| | 150 | 'save_favorite_blogs' => "${pkg}Blog::save_favorite_blogs", |
|---|
| | 151 | 'reg_file' => "${pkg}Tools::reg_file", |
|---|
| 162 | | 'folder_add' => \&category_add, |
|---|
| 163 | | 'category_add' => \&category_add, |
|---|
| 164 | | 'category_do_add' => \&category_do_add, |
|---|
| 165 | | 'cc_return' => \&cc_return, |
|---|
| 166 | | 'reset_blog_templates' => \&reset_blog_templates, |
|---|
| 167 | | 'handshake' => \&handshake, |
|---|
| 168 | | 'itemset_action' => \&do_list_action, |
|---|
| 169 | | 'page_action' => \&do_page_action, |
|---|
| 170 | | 'cfg_system' => \&cfg_system_general, |
|---|
| 171 | | 'cfg_system_users' => \&cfg_system_users, |
|---|
| 172 | | 'cfg_system_feedback' => \&cfg_system_feedback, |
|---|
| 173 | | 'save_plugin_config' => \&save_plugin_config, |
|---|
| 174 | | 'reset_plugin_config' => \&reset_plugin_config, |
|---|
| 175 | | 'save_cfg_system_feedback' => \&save_cfg_system_feedback, |
|---|
| 176 | | 'save_cfg_system_general' => \&save_cfg_system_general, |
|---|
| 177 | | 'save_cfg_system_users' => \&save_cfg_system_users, |
|---|
| 178 | | 'update_welcome_message' => \&update_welcome_message, |
|---|
| | 156 | 'folder_add' => "${pkg}Category::category_add", |
|---|
| | 157 | 'category_add' => "${pkg}Category::category_add", |
|---|
| | 158 | 'category_do_add' => "${pkg}Category::category_do_add", |
|---|
| | 159 | 'cc_return' => "${pkg}Blog::cc_return", |
|---|
| | 160 | 'reset_blog_templates' => "${pkg}Template::reset_blog_templates", |
|---|
| | 161 | 'handshake' => "${pkg}Blog::handshake", |
|---|
| | 162 | 'itemset_action' => "${pkg}Tools::do_list_action", |
|---|
| | 163 | 'page_action' => "${pkg}Tools::do_page_action", |
|---|
| | 164 | 'cfg_system' => "${pkg}Tools::cfg_system_general", |
|---|
| | 165 | 'cfg_system_users' => "${pkg}User::cfg_system_users", |
|---|
| | 166 | 'cfg_system_feedback' => "${pkg}Comment::cfg_system_feedback", |
|---|
| | 167 | 'save_plugin_config' => "${pkg}Plugin::save_config", |
|---|
| | 168 | 'reset_plugin_config' => "${pkg}Plugin::reset_config", |
|---|
| | 169 | 'save_cfg_system_feedback' => "${pkg}Comment::save_cfg_system_feedback", |
|---|
| | 170 | 'save_cfg_system_general' => "${pkg}Tools::save_cfg_system_general", |
|---|
| | 171 | 'save_cfg_system_users' => "${pkg}User::save_cfg_system_users", |
|---|
| | 172 | 'update_welcome_message' => "${pkg}Blog::update_welcome_message", |
|---|
| 183 | | 'plugin_control' => \&plugin_control, |
|---|
| 184 | | 'recover_profile_password' => \&recover_profile_password, |
|---|
| 185 | | 'rename_tag' => \&rename_tag, |
|---|
| 186 | | 'remove_user_assoc' => \&remove_user_assoc, |
|---|
| 187 | | 'revoke_role' => \&revoke_role, |
|---|
| 188 | | 'grant_role' => \&grant_role, |
|---|
| 189 | | 'start_backup' => \&start_backup, |
|---|
| 190 | | 'start_restore' => \&start_restore, |
|---|
| 191 | | 'backup' => \&backup, |
|---|
| 192 | | 'backup_download' => \&backup_download, |
|---|
| 193 | | 'restore' => \&restore, |
|---|
| 194 | | 'restore_premature_cancel' => \&restore_premature_cancel, |
|---|
| 195 | | 'adjust_sitepath' => \&adjust_sitepath, |
|---|
| 196 | | 'system_check' => \&system_check, |
|---|
| 197 | | 'dialog_refresh_templates' => \&dialog_refresh_templates, |
|---|
| 198 | | 'refresh_all_templates' => \&refresh_all_templates, |
|---|
| | 177 | 'plugin_control' => "${pkg}Plugin::plugin_control", |
|---|
| | 178 | 'recover_profile_password' => "${pkg}User::recover_profile_password", |
|---|
| | 179 | 'rename_tag' => "${pkg}Tag::rename_tag", |
|---|
| | 180 | 'remove_user_assoc' => "${pkg}User::remove_user_assoc", |
|---|
| | 181 | 'revoke_role' => "${pkg}User::revoke_role", |
|---|
| | 182 | 'grant_role' => "${pkg}User::grant_role", |
|---|
| | 183 | 'start_backup' => "${pkg}Tools::start_backup", |
|---|
| | 184 | 'start_restore' => "${pkg}Tools::start_restore", |
|---|
| | 185 | 'backup' => "${pkg}Tools::backup", |
|---|
| | 186 | 'backup_download' => "${pkg}Tools::backup_download", |
|---|
| | 187 | 'restore' => "${pkg}Tools::restore", |
|---|
| | 188 | 'restore_premature_cancel' => "${pkg}Tools::restore_premature_cancel", |
|---|
| | 189 | 'adjust_sitepath' => "${pkg}Tools::adjust_sitepath", |
|---|
| | 190 | 'system_check' => "${pkg}Tools::system_check", |
|---|
| | 191 | 'dialog_refresh_templates' => "${pkg}Template::dialog_refresh_templates", |
|---|
| | 192 | 'refresh_all_templates' => "${pkg}Template::refresh_all_templates", |
|---|
| 340 | | } |
|---|
| 341 | | sub js_recent_entries_for_tag { |
|---|
| 342 | | my $app = shift; |
|---|
| 343 | | my $user = $app->user or return; |
|---|
| 344 | | my $tag_class = $app->model('tag') or return; |
|---|
| 345 | | my $objtag_class = $app->model('objecttag') or return; |
|---|
| 346 | | my $limit = $app->param('limit') || 10; |
|---|
| 347 | | my $obj_ds = $app->param('_type') || 'entry'; |
|---|
| 348 | | my $blog_id = $app->param('blog_id'); |
|---|
| 349 | | my $obj_class = $app->model($obj_ds) or return; |
|---|
| 350 | | my $tag_name = $app->param('tag') or return; |
|---|
| 351 | | if ( 'utf-8' ne lc( $app->config->PublishCharset) ) { |
|---|
| 352 | | $tag_name = MT::I18N::encode_text( $tag_name, 'utf-8', $app->config->PublishCharset ); |
|---|
| 353 | | } |
|---|
| 354 | | my $tag_obj = |
|---|
| 355 | | $tag_class->load( { name => $tag_name }, { binary => { name => 1 } } ); |
|---|
| 356 | | |
|---|
| 357 | | if ( !$tag_obj ) { |
|---|
| 358 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 359 | | } |
|---|
| 360 | | my $tag_id = $tag_obj->id; |
|---|
| 361 | | |
|---|
| 362 | | my @entries = $obj_class->load( |
|---|
| 363 | | { |
|---|
| 364 | | ( $blog_id ? ( blog_id => $blog_id ) : () ), |
|---|
| 365 | | status => MT::Entry::RELEASE(), |
|---|
| 366 | | }, |
|---|
| 367 | | { |
|---|
| 368 | | sort => 'authored_on', |
|---|
| 369 | | direction => 'descend', |
|---|
| 370 | | limit => $limit, |
|---|
| 371 | | join => $objtag_class->join_on( |
|---|
| 372 | | 'object_id', |
|---|
| 373 | | { |
|---|
| 374 | | ( $blog_id ? ( blog_id => $blog_id ) : () ), |
|---|
| 375 | | tag_id => $tag_id, |
|---|
| 376 | | object_datasource => $obj_ds, |
|---|
| 377 | | } |
|---|
| 378 | | ), |
|---|
| 379 | | } |
|---|
| 380 | | ); |
|---|
| 381 | | my $count = |
|---|
| 382 | | $obj_class->tagged_count( $tag_id, |
|---|
| 383 | | { ( $blog_id ? ( blog_id => $blog_id ) : () ) } ); |
|---|
| 384 | | require MT::Template; |
|---|
| 385 | | require MT::Blog; |
|---|
| 386 | | my $tmpl = $app->load_tmpl('widget/blog_stats_recent_entries.tmpl'); |
|---|
| 387 | | my $ctx = $tmpl->context; |
|---|
| 388 | | $ctx->stash( 'blog', MT::Blog->load($blog_id) ) if $blog_id; |
|---|
| 389 | | $ctx->stash( 'entries', \@entries ); |
|---|
| 390 | | $tmpl->param( 'entry_count', scalar @entries ); |
|---|
| 391 | | $tmpl->param( 'script_url', $app->uri ); |
|---|
| 392 | | $tmpl->param( 'tag', $tag_name ); |
|---|
| 393 | | $tmpl->param( 'blog_id', $blog_id ) if $blog_id; |
|---|
| 394 | | my $editable = $app->user->is_superuser; |
|---|
| 395 | | if ( $blog_id && !$editable ) { |
|---|
| 396 | | $editable = $user->permissions($blog_id)->can_edit_all_posts; |
|---|
| 397 | | } |
|---|
| 398 | | $tmpl->param('editable', $editable); |
|---|
| 399 | | my $html = $app->build_page( $tmpl ); |
|---|
| 400 | | return $app->json_result( { html => $html } ); |
|---|
| 401 | | } |
|---|
| 402 | | |
|---|
| 403 | | sub js_add_category { |
|---|
| 404 | | my $app = shift; |
|---|
| 405 | | unless ( $app->validate_magic ) { |
|---|
| 406 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 407 | | } |
|---|
| 408 | | my $user = $app->user; |
|---|
| 409 | | my $blog_id = $app->param('blog_id'); |
|---|
| 410 | | my $perms = $app->permissions; |
|---|
| 411 | | my $type = $app->param('_type') || 'category'; |
|---|
| 412 | | my $class = $app->model($type); |
|---|
| 413 | | if ( !$class ) { |
|---|
| 414 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 415 | | } |
|---|
| 416 | | |
|---|
| 417 | | my $label = $app->param('label'); |
|---|
| 418 | | my $enc = $app->config->PublishCharset; |
|---|
| 419 | | |
|---|
| 420 | | # XMLHttpRequest always send text in UTF-8... right? |
|---|
| 421 | | if ( 'utf-8' ne lc($enc) ) { |
|---|
| 422 | | $label = MT::I18N::encode_text( $label, 'utf-8', $enc ); |
|---|
| 423 | | } |
|---|
| 424 | | my $basename = $app->param('basename'); |
|---|
| 425 | | if ( !defined($label) || ( $label =~ m/^\s*$/ ) ) { |
|---|
| 426 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 427 | | } |
|---|
| 428 | | |
|---|
| 429 | | my $blog = $app->blog; |
|---|
| 430 | | if ( !$blog ) { |
|---|
| 431 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 432 | | } |
|---|
| 433 | | |
|---|
| 434 | | my $parent; |
|---|
| 435 | | if ( my $parent_id = $app->param('parent') ) { |
|---|
| 436 | | if ( $parent_id != -1 ) { # special case for 'root' folder |
|---|
| 437 | | $parent = $class->load( { id => $parent_id, blog_id => $blog_id } ); |
|---|
| 438 | | if ( !$parent ) { |
|---|
| 439 | | return $app->json_error( $app->translate("Invalid request.") ); |
|---|
| 440 | | } |
|---|
| 441 | | } |
|---|
| 442 | | } |
|---|
| 443 | | |
|---|
| 444 | | my $obj = $class->new; |
|---|
| 445 | | my $original = $obj->clone; |
|---|
| 446 | | |
|---|
| 447 | | if ( |
|---|
| 448 | | !$app->run_callbacks( |
|---|
| 449 | | 'cms_save_permission.' . $type, |
|---|
| 450 | | $app, $obj, $original |
|---|
| 451 | | ) |
|---|
| 452 | | ) |
|---|
| 453 | | { |
|---|
| 454 | | return $app->json_error( $app->translate("Permission denied.") ); |
|---|
| 455 | | } |
|---|
| 456 | | |
|---|
| 457 | | $obj->label($label); |
|---|
| 458 | | $obj->basename($basename) if $basename; |
|---|
| 459 | | $obj->parent( $parent->id ) if $parent; |
|---|
| 460 | | $obj->blog_id($blog_id); |
|---|
| 461 | | $obj->author_id( $user->id ); |
|---|
| 462 | | $obj->created_by( $user->id ); |
|---|
| 463 | | |
|---|
| 464 | | if ( |
|---|
| 465 | | !$app->run_callbacks( 'cms_pre_save.' . $type, $app, $obj, $original ) ) |
|---|
| 466 | | { |
|---|
| 467 | | return $app->json_error( $app->errstr ); |
|---|
| 468 | | } |
|---|
| 469 | | |
|---|
| 470 | | $obj->save; |
|---|
| 471 | | |
|---|
| 472 | | $app->run_callbacks( 'cms_post_save.' . $type, $app, $obj, $original ); |
|---|
| 473 | | |
|---|
| 474 | | return $app->json_result( |
|---|
| 475 | | { |
|---|
| 476 | | id => $obj->id, |
|---|
| 477 | | basename => $obj->basename |
|---|
| 478 | | } |
|---|
| 479 | | ); |
|---|
| 480 | | } |
|---|
| 481 | | |
|---|
| 482 | | sub convert_to_html { |
|---|
| 483 | | my $app = shift; |
|---|
| 484 | | my $format = $app->param('format'); |
|---|
| 485 | | my $text = $app->param('text'); |
|---|
| 486 | | # XMLHttpRequest always send text in UTF-8... right? |
|---|
| 487 | | if ( defined $text ) { |
|---|
| 488 | | $text = encode_text($text, 'utf-8', $app->config->PublishCharset); |
|---|
| 489 | | } |
|---|
| 490 | | else { |
|---|
| 491 | | $text = '' ; |
|---|
| 492 | | } |
|---|
| 493 | | my $text_more = $app->param('text_more'); |
|---|
| 494 | | if ( defined $text_more ) { |
|---|
| 495 | | $text_more = encode_text($text_more, 'utf-8', $app->config->PublishCharset); |
|---|
| 496 | | } |
|---|
| 497 | | else { |
|---|
| 498 | | $text_more = '' ; |
|---|
| 499 | | } |
|---|
| 500 | | my $result = { |
|---|
| 501 | | text => $app->apply_text_filters( $text, [$format] ), |
|---|
| 502 | | text_more => $app->apply_text_filters( $text_more, [$format] ), |
|---|
| 503 | | format => $format, |
|---|
| 504 | | }; |
|---|
| 505 | | return $app->json_result($result); |
|---|
| 506 | | } |
|---|
| 507 | | |
|---|
| 508 | | sub tools { |
|---|
| 509 | | my $app = shift; |
|---|
| 510 | | $app->system_check; |
|---|
| 511 | | } |
|---|
| 512 | | |
|---|
| 513 | | sub system_check { |
|---|
| 514 | | my $app = shift; |
|---|
| 515 | | |
|---|
| 516 | | if ( my $blog_id = $app->param('blog_id') ) { |
|---|
| 517 | | return $app->redirect( |
|---|
| 518 | | $app->uri( |
|---|
| 519 | | 'mode' => 'view_log', |
|---|
| 520 | | args => { blog_id => $blog_id } |
|---|
| 521 | | ) |
|---|
| 522 | | ); |
|---|
| 523 | | } |
|---|
| 524 | | |
|---|
| 525 | | my %param; |
|---|
| 526 | | # licensed user count: someone who has logged in within 90 days |
|---|
| 527 | | my $sess_class = $app->model('session'); |
|---|
| 528 | | my $from = time - ( 60 * 60 * 24 * 90 + 60 * 60 * 24 ); |
|---|
| 529 | | $sess_class->remove( |
|---|
| 530 | | { kind => 'UA', start => [ undef, $from ] }, |
|---|
| 531 | | { range => { start => 1 } } |
|---|
| 532 | | ); |
|---|
| 533 | | $param{licensed_user_count} = $sess_class->count( { kind => 'UA' } ); |
|---|
| 534 | | |
|---|
| 535 | | my $author_class = $app->model('author'); |
|---|
| 536 | | $param{user_count} = $author_class->count( |
|---|
| 537 | | { type => MT::Author::AUTHOR() } ); |
|---|
| 538 | | |
|---|
| 539 | | # commeters: users with only comment permission and MT::Author::COMMENTER |
|---|
| 540 | | my $cmntrs = $author_class->count( |
|---|
| 541 | | { type => MT::Author::COMMENTER() } ); |
|---|
| 542 | | |
|---|
| 543 | | my @perms = $app->model('permission')->load( |
|---|
| 544 | | { |
|---|
| 545 | | permissions => "%'comment'%", |
|---|
| 546 | | blog_id => '0', |
|---|
| 547 | | }, |
|---|
| 548 | | { |
|---|
| 549 | | 'like' => { 'permissions' => 1 }, |
|---|
| 550 | | 'not' => { 'blog_id' => 1 }, |
|---|
| 551 | | } |
|---|
| 552 | | ); |
|---|
| 553 | | @perms = grep { $_->permissions =~ m/'comment'/ } @perms; |
|---|
| 554 | | $param{commenter_count} = scalar(@perms) + $cmntrs; |
|---|
| 555 | | $param{screen_id} = "system-check"; |
|---|
| 556 | | $param{syscheck_html} = $app->get_syscheck_content() || ''; |
|---|
| 557 | | |
|---|
| 558 | | $app->load_tmpl( 'system_check.tmpl', \%param ); |
|---|
| 559 | | } |
|---|
| 560 | | |
|---|
| 561 | | sub get_syscheck_content { |
|---|
| 562 | | my $app = shift; |
|---|
| 563 | | |
|---|
| 564 | | my $syscheck_url = $app->base . $app->mt_path . $app->config('CheckScript') . |
|---|
| 565 | | '?view=tools&version=' . MT->version_id; |
|---|
| 566 | | if ( $syscheck_url && $syscheck_url ne 'disable' ) { |
|---|
| 567 | | my $SYSCHECKCACHE_TIMEOUT = 60 * 60 * 24; |
|---|
| 568 | | my $sess_class = $app->model('session'); |
|---|
| 569 | | my ($syscheck_object) = (""); |
|---|
| 570 | | my $retries = 0; |
|---|
| 571 | | $syscheck_object = $sess_class->load( { id => 'SC' } ); |
|---|
| 572 | | if ( $syscheck_object |
|---|
| 573 | | && ( $syscheck_object->start() < ( time - $SYSCHECKCACHE_TIMEOUT ) ) ) |
|---|
| 574 | | { |
|---|
| 575 | | $syscheck_object->remove; |
|---|
| 576 | | $syscheck_object = undef; |
|---|
| 577 | | } |
|---|
| 578 | | return encode_text( $syscheck_object->data(), 'utf-8', undef ) |
|---|
| 579 | | if ($syscheck_object); |
|---|
| 580 | | |
|---|
| 581 | | my $ua = $app->new_ua({ timeout => 20 }); |
|---|
| 582 | | return unless $ua; |
|---|
| 583 | | $ua->max_size(undef) if $ua->can('max_size'); |
|---|
| 584 | | |
|---|
| 585 | | my $req = new HTTP::Request( GET => $syscheck_url ); |
|---|
| 586 | | my $resp = $ua->request($req); |
|---|
| 587 | | return unless $resp->is_success(); |
|---|
| 588 | | my $result = $resp->content(); |
|---|
| 589 | | if ($result) { |
|---|
| 590 | | require MT::Sanitize; |
|---|
| 591 | | |
|---|
| 592 | | # allowed html |
|---|
| 593 | | my $spec = '* style class id,ul,li,div,span,br,h2,h3,strong,code,blockquote,p'; |
|---|
| 594 | | $result = MT::Sanitize->sanitize( $result, $spec ); |
|---|
| 595 | | $syscheck_object = MT::Session->new(); |
|---|
| 596 | | $syscheck_object->set_values( |
|---|
| 597 | | { |
|---|
| 598 | | id => 'SC', |
|---|
| 599 | | kind => 'SC', |
|---|
| 600 | | start => time(), |
|---|
| 601 | | data => $result |
|---|
| 602 | | } |
|---|
| 603 | | ); |
|---|
| 604 | | $syscheck_object->save(); |
|---|
| 605 | | $result = encode_text( $result, 'utf-8', undef ); |
|---|
| 606 | | } |
|---|
| 607 | | return $result; |
|---|
| 608 | | } |
|---|