Changeset 2877
- Timestamp:
- 08/01/08 01:43:09 (4 months ago)
- Files:
-
- branches/release-42/lib/MT/App.pm (modified) (178 diffs)
- branches/release-42/lib/MT/App/ActivityFeeds.pm (modified) (26 diffs)
- branches/release-42/lib/MT/App/CMS.pm (modified) (107 diffs)
- branches/release-42/lib/MT/App/Comments.pm (modified) (91 diffs)
- branches/release-42/lib/MT/App/NotifyList.pm (modified) (11 diffs)
- branches/release-42/lib/MT/App/Search.pm (modified) (55 diffs)
- branches/release-42/lib/MT/App/Trackback.pm (modified) (25 diffs)
- branches/release-42/lib/MT/App/Upgrader.pm (modified) (37 diffs)
- branches/release-42/lib/MT/App/Viewer.pm (modified) (7 diffs)
- branches/release-42/lib/MT/App/Wizard.pm (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-42/lib/MT/App.pm
r2846 r2877 3 3 # GNU General Public License, version 2. 4 4 # 5 # $Id $5 # $Id: App.pm 2846 2008-07-28 02:46:54Z fumiakiy $ 6 6 7 7 package MT::App; … … 17 17 18 18 my $COOKIE_NAME = 'mt_user'; 19 sub COMMENTER_COOKIE_NAME () { "mt_commenter"}19 sub COMMENTER_COOKIE_NAME () {"mt_commenter"} 20 20 use vars qw( %Global_actions ); 21 21 … … 37 37 38 38 sub core_list_filters { 39 {} 39 {}; 40 40 } 41 41 42 42 sub core_widgets { 43 {} 43 {}; 44 44 } 45 45 46 46 sub core_blog_stats_tabs { 47 {} 47 {}; 48 48 } 49 49 50 50 sub core_search_apis { 51 {} 51 {}; 52 52 } 53 53 54 54 sub __massage_page_action { 55 my ( $app, $action, $type) = @_;55 my ( $app, $action, $type ) = @_; 56 56 return if exists $action->{__massaged}; 57 57 … … 59 59 my $plugin = $action->{plugin}; 60 60 61 if ( my $link = $action->{link}) {61 if ( my $link = $action->{link} ) { 62 62 my $envelope = $plugin->envelope; 63 63 $link .= '?' unless $link =~ m.\?.; … … 66 66 $page .= $envelope . '/' if $envelope; 67 67 $page .= $link; 68 my $has_params = ( $page =~ m/\?/)69 && ( $page !~ m!(&|;|\?)$!);70 $action->{page} = $page;68 my $has_params = ( $page =~ m/\?/ ) 69 && ( $page !~ m!(&|;|\?)$! ); 70 $action->{page} = $page; 71 71 $action->{page_has_params} = $has_params; 72 } elsif ($action->{mode} || $action->{dialog}) { 72 } 73 elsif ( $action->{mode} || $action->{dialog} ) { 73 74 if ( $app->user->is_superuser ) { 74 75 $action->{allowed} = 1; … … 80 81 foreach my $p (@p) { 81 82 my $perm = 'can_' . $p; 82 $action->{allowed} = 1, last if ( $perms && $perms->$perm() ); 83 $action->{allowed} = 1, last 84 if ( $perms && $perms->$perm() ); 83 85 } 84 86 } … … 92 94 elsif ( $action->{dialog} ) { 93 95 if ( $action->{args} ) { 94 my @args = map { $_ . '=' . $action->{args}->{$_} } keys %{ $action->{args} }; 96 my @args = map { $_ . '=' . $action->{args}->{$_} } 97 keys %{ $action->{args} }; 95 98 $action->{dialog_args} .= join '&', @args; 96 99 } 97 100 } 98 } else { 99 $action->{page} = $app->uri(mode => 'page_action', args => { action_name => $action->{key}, '_type' => $type } ); 101 } 102 else { 103 $action->{page} = $app->uri( 104 mode => 'page_action', 105 args => { action_name => $action->{key}, '_type' => $type } 106 ); 100 107 $action->{page_has_params} = 1; 101 108 } 102 109 $action->{core} = $plugin->isa('MT::Plugin') ? 0 : 1; 103 $action->{order} = -10000 + ( $action->{order} || 0) if $action->{core};110 $action->{order} = -10000 + ( $action->{order} || 0 ) if $action->{core}; 104 111 $action->{label} = $action->{link_text} if exists $action->{link_text}; 105 if ( $plugin && !ref($action->{label})) {112 if ( $plugin && !ref( $action->{label} ) ) { 106 113 my $label = $action->{label}; 107 114 if ($plugin) { 108 115 $action->{label} = sub { $plugin->translate($label) }; 109 } else { 116 } 117 else { 110 118 $action->{label} = sub { $app->translate($label) }; 111 119 } … … 116 124 117 125 sub filter_conditional_list { 118 my ( $app, $list, @param) = @_;126 my ( $app, $list, @param ) = @_; 119 127 120 128 # $list may either be an array of things or a hashref of things 121 129 122 130 my $perms = $app->permissions; 123 my $user = $app->user;124 my $admin = ( $user && $user->is_superuser())125 || ( $perms && $perms->blog_id && $perms->has('administer_blog'));131 my $user = $app->user; 132 my $admin = ( $user && $user->is_superuser() ) 133 || ( $perms && $perms->blog_id && $perms->has('administer_blog') ); 126 134 my $system_perms = $user->permissions(0) unless $perms && $perms->blog_id; 127 135 … … 129 137 my ($item) = @_; 130 138 if ( $system_perms 131 && (my $sp = $item->{system_permission}) ) { 139 && ( my $sp = $item->{system_permission} ) ) 140 { 132 141 my $allowed = 0; 133 142 my @sp = split /,/, $sp; … … 135 144 my $perm = 'can_' . $sp; 136 145 $allowed = 1, last 137 if $admin || ($system_perms && $system_perms->can($perm) && $system_perms->$perm()); 146 if $admin 147 || ( $system_perms 148 && $system_perms->can($perm) 149 && $system_perms->$perm() ); 138 150 } 139 151 return 0 unless $allowed; 140 152 } 141 if ( my $p = $item->{permission}) {153 if ( my $p = $item->{permission} ) { 142 154 my $allowed = 0; 143 155 my @p = split /,/, $p; … … 145 157 my $perm = 'can_' . $p; 146 158 $allowed = 1, last 147 if $admin || ($perms && $perms->can($perm) && $perms->$perm()); 159 if $admin 160 || ( $perms 161 && $perms->can($perm) 162 && $perms->$perm() ); 148 163 } 149 164 return 0 unless $allowed; 150 165 } 151 if ( my $cond = $item->{condition}) {152 if ( !ref($cond)) {166 if ( my $cond = $item->{condition} ) { 167 if ( !ref($cond) ) { 153 168 $cond = $item->{condition} = $app->handler_to_coderef($cond); 154 169 } … … 158 173 }; 159 174 160 if ( ref $list eq 'ARRAY') {175 if ( ref $list eq 'ARRAY' ) { 161 176 my @list; 162 177 if (@$list) { 178 163 179 # translate the link text here... 164 180 foreach my $item (@$list) { … … 167 183 } 168 184 return \@list; 169 } elsif (ref $list eq 'HASH') { 185 } 186 elsif ( ref $list eq 'HASH' ) { 170 187 my %list; 171 188 if (%$list) { 189 172 190 # translate the link text here... 173 foreach my $item ( keys %$list) {191 foreach my $item ( keys %$list ) { 174 192 $list{$item} = $list->{$item} 175 if $test->( $list->{$item});193 if $test->( $list->{$item} ); 176 194 } 177 195 } … … 183 201 sub page_actions { 184 202 my $app = shift; 185 my ( $type, @param) = @_;186 my $actions = $app->registry( "page_actions", $type) or return;187 foreach my $a ( keys %$actions) {203 my ( $type, @param ) = @_; 204 my $actions = $app->registry( "page_actions", $type ) or return; 205 foreach my $a ( keys %$actions ) { 188 206 $actions->{$a}{key} = $a; 189 __massage_page_action( $app, $actions->{$a}, $type);207 __massage_page_action( $app, $actions->{$a}, $type ); 190 208 } 191 209 my @actions = values %$actions; 192 $actions = $app->filter_conditional_list( \@actions, @param);210 $actions = $app->filter_conditional_list( \@actions, @param ); 193 211 no warnings; 194 212 @$actions = sort { $a->{order} <=> $b->{order} } @$actions; … … 198 216 sub list_actions { 199 217 my $app = shift; 200 my ( $type, @param) = @_;201 202 my $actions = $app->registry( "list_actions", $type) or return;218 my ( $type, @param ) = @_; 219 220 my $actions = $app->registry( "list_actions", $type ) or return; 203 221 my @actions; 204 foreach my $a ( keys %$actions) {205 $actions->{$a}{key} = $a;222 foreach my $a ( keys %$actions ) { 223 $actions->{$a}{key} = $a; 206 224 $actions->{$a}{core} = 1 207 unless UNIVERSAL::isa( $actions->{$a}{plugin}, 'MT::Plugin');225 unless UNIVERSAL::isa( $actions->{$a}{plugin}, 'MT::Plugin' ); 208 226 if ( exists $actions->{$a}{continue_prompt_handler} ) { 209 my $code = $app->handler_to_coderef($actions->{$a}{continue_prompt_handler}); 227 my $code = $app->handler_to_coderef( 228 $actions->{$a}{continue_prompt_handler} ); 210 229 $actions->{$a}{continue_prompt} = $code->() 211 230 if 'CODE' eq ref($code); … … 213 232 push @actions, $actions->{$a}; 214 233 } 215 $actions = $app->filter_conditional_list( \@actions, @param);234 $actions = $app->filter_conditional_list( \@actions, @param ); 216 235 no warnings; 217 236 @$actions = sort { $a->{order} <=> $b->{order} } @$actions; … … 221 240 sub list_filters { 222 241 my $app = shift; 223 my ( $type, @param) = @_;224 225 my $filters = $app->registry( "list_filters", $type) or return;242 my ( $type, @param ) = @_; 243 244 my $filters = $app->registry( "list_filters", $type ) or return; 226 245 my @filters; 227 foreach my $a ( keys %$filters) {246 foreach my $a ( keys %$filters ) { 228 247 $filters->{$a}{key} = $a; 229 next if $a =~ m/^_/; # not shown...248 next if $a =~ m/^_/; # not shown... 230 249 push @filters, $filters->{$a}; 231 250 } 232 $filters = $app->filter_conditional_list( \@filters, @param);251 $filters = $app->filter_conditional_list( \@filters, @param ); 233 252 no warnings; 234 253 @$filters = sort { $a->{order} <=> $b->{order} } @$filters; … … 238 257 sub search_apis { 239 258 my $app = shift; 240 my ( $view, @param) = @_;259 my ( $view, @param ) = @_; 241 260 242 261 my $apis = $app->registry("search_apis") or return; 243 262 my @apis; 244 foreach my $a ( keys %$apis) {263 foreach my $a ( keys %$apis ) { 245 264 next if $apis->{$a}->{view} && $apis->{$a}->{view} ne $view; 246 $apis->{$a}{key} = $a;265 $apis->{$a}{key} = $a; 247 266 $apis->{$a}{core} = 1 248 unless UNIVERSAL::isa( $apis->{$a}{plugin}, 'MT::Plugin');267 unless UNIVERSAL::isa( $apis->{$a}{plugin}, 'MT::Plugin' ); 249 268 push @apis, $apis->{$a}; 250 269 } 251 $apis = $app->filter_conditional_list( \@apis, @param);270 $apis = $app->filter_conditional_list( \@apis, @param ); 252 271 no warnings; 253 272 @$apis = sort { $a->{order} <=> $b->{order} } @$apis; … … 260 279 261 280 my $type = $opt->{type} || $opt->{Type} || $app->param('_type'); 262 my $tmpl = $opt->{template} 263 || $opt->{Template} 264 || 'list_' . $type . '.tmpl'; 281 my $tmpl 282 = $opt->{template} 283 || $opt->{Template} 284 || 'list_' . $type . '.tmpl'; 265 285 my $iter_method = $opt->{iterator} || $opt->{Iterator} || 'load_iter'; 266 286 my $param = $opt->{params} || $opt->{Params} || {}; 267 287 $param->{listing_screen} = 1; 268 288 my $add_pseudo_new_user = delete $param->{pseudo_new_user} 269 if exists $param->{pseudo_new_user};270 my $hasher = $opt->{code}|| $opt->{Code};271 my $terms = $opt->{terms}|| $opt->{Terms} || {};272 my $args = $opt->{args}|| $opt->{Args} || {};273 my $no_html = $opt->{no_html}|| $opt->{NoHTML};289 if exists $param->{pseudo_new_user}; 290 my $hasher = $opt->{code} || $opt->{Code}; 291 my $terms = $opt->{terms} || $opt->{Terms} || {}; 292 my $args = $opt->{args} || $opt->{Args} || {}; 293 my $no_html = $opt->{no_html} || $opt->{NoHTML}; 274 294 my $no_limit = $opt->{no_limit} || 0; 275 my $json = $opt->{json}|| $app->param('json');276 my $pre_build = $opt->{pre_build} if ref( $opt->{pre_build}) eq 'CODE';295 my $json = $opt->{json} || $app->param('json'); 296 my $pre_build = $opt->{pre_build} if ref( $opt->{pre_build} ) eq 'CODE'; 277 297 $param->{json} = 1 if $json; 278 298 … … 289 309 if ( my $search = $app->param('search') ) { 290 310 $app->param( 'do_search', 1 ); 291 if ( $app->can('do_search_replace')) {311 if ( $app->can('do_search_replace') ) { 292 312 my $search_param = $app->do_search_replace(); 293 313 if ($hasher) { … … 306 326 } 307 327 else { 328 308 329 # handle filter options 309 330 my $filter_key = $app->param('filter_key'); … … 311 332 $filter_key = 'default'; 312 333 } 313 if ( $filter_key) {334 if ($filter_key) { 314 335 315 336 # set filter based on type … … 318 339 if ( my $code = $filter->{code} || $filter->{handler} ) { 319 340 if ( ref($code) ne 'CODE' ) { 320 $code = $filter->{code} =321 $app->handler_to_coderef($code);341 $code = $filter->{code} 342 = $app->handler_to_coderef($code); 322 343 } 323 344 if ( ref($code) eq 'CODE' ) { … … 333 354 && ( my $val = $app->param('filter_val') ) ) 334 355 { 335 if ( 336 ( 337 ( $filter_col eq 'normalizedtag' ) 356 if (( ( $filter_col eq 'normalizedtag' ) 338 357 || ( $filter_col eq 'exacttag' ) 339 358 ) 340 359 && ( $class->isa('MT::Taggable') ) 341 )360 ) 342 361 { 343 362 my $normalize = ( $filter_col eq 'normalizedtag' ); … … 349 368 if ($normalize) { 350 369 push @filter_tags, MT::Tag->normalize($_) 351 foreach @filter_vals;370 foreach @filter_vals; 352 371 } 353 my @tags = $tag_class->load( { name => [@filter_tags] }, 354 { binary => { name => 1 } } ); 372 my @tags = $tag_class->load( 373 { name => [@filter_tags] }, 374 { binary => { name => 1 } } 375 ); 355 376 my @tag_ids; 356 377 foreach (@tags) { … … 365 386 $args->{'join'} = $ot_class->join_on( 366 387 'object_id', 367 { 368 tag_id => \@tag_ids, 388 { tag_id => \@tag_ids, 369 389 object_datasource => $class->datasource 370 390 }, … … 373 393 } 374 394 elsif ( !exists( $terms->{$filter_col} ) ) { 375 if ( $class->has_column($filter_col)) {395 if ( $class->has_column($filter_col) ) { 376 396 $terms->{$filter_col} = $val; 377 397 } … … 396 416 397 417 $args->{sort} = 'id' 398 unless exists $args->{sort}; # must always provide sort column399 400 $app->run_callbacks( 'app_pre_listing_' .$app->mode,401 $app, $terms, $args, $param, \$hasher );402 403 my $iter =404 ref($iter_method) eq 'CODE'405 ? $iter_method406 : ( $class->$iter_method( $terms, $args )407 or return $app->error( $class->errstr ) );418 unless exists $args->{sort}; # must always provide sort column 419 420 $app->run_callbacks( 'app_pre_listing_' . $app->mode, 421 $app, $terms, $args, $param, \$hasher ); 422 423 my $iter 424 = ref($iter_method) eq 'CODE' 425 ? $iter_method 426 : ( $class->$iter_method( $terms, $args ) 427 or return $app->error( $class->errstr ) ); 408 428 my @data; 409 429 while ( my $obj = $iter->() ) { 410 430 my $row = $obj->column_values(); 411 431 $hasher->( $obj, $row ) if $hasher; 432 412 433 #$app->run_callbacks( 'app_listing_'.$app->mode, 413 434 # $app, $obj, $row ); 414 435 push @data, $row; 415 last if ( scalar @data == $limit) && (!$no_limit);436 last if ( scalar @data == $limit ) && ( !$no_limit ); 416 437 } 417 438 … … 432 453 $param->{pager_json} = $json ? $pager : JSON::objToJson($pager); 433 454 434 # pager.rows (number of rows shown)435 # pager.listTotal (total number of rows in datasource)436 # pager.offset (offset currently used)437 # pager.chronological (boolean, whether the listing is chronological or not)455 # pager.rows (number of rows shown) 456 # pager.listTotal (total number of rows in datasource) 457 # pager.offset (offset currently used) 458 # pager.chronological (boolean, whether the listing is chronological or not) 438 459 } 439 460 … … 470 491 return $param; 471 492 } 472 if ( ref $tmpl) {473 $tmpl->param( $param);493 if ( ref $tmpl ) { 494 $tmpl->param($param); 474 495 return $tmpl; 475 } else { 496 } 497 else { 476 498 return $app->load_tmpl( $tmpl, $param ); 477 499 } … … 485 507 $app->{no_print_body} = 1; 486 508 require JSON; 487 $app->print( JSON::objToJson( { error => undef, result => $result }));509 $app->print( JSON::objToJson( { error => undef, result => $result } ) ); 488 510 return undef; 489 511 } … … 495 517 $app->{no_print_body} = 1; 496 518 require JSON; 497 $app->print( JSON::objToJson( { error => $error } ));519 $app->print( JSON::objToJson( { error => $error } ) ); 498 520 return undef; 499 521 } … … 525 547 sub send_http_header { 526 548 my $app = shift; 527 my ($type) = @_;549 my ($type) = @_; 528 550 $type ||= $app->{response_content_type} || 'text/html'; 529 if ( my $charset = $app->charset) {551 if ( my $charset = $app->charset ) { 530 552 $type .= "; charset=$charset" 531 if $type =~ m!^text/! && $type !~ /\bcharset\b/; 532 } 533 if ($ENV{MOD_PERL}) { 534 if ($app->{response_message}) { 535 $app->{apache}->status_line(($app->response_code || 200) 536 . ($app->{response_message} ? ' ' . $app->{response_message} : '')); 537 } else { 538 $app->{apache}->status($app->response_code || 200); 553 if ( $type =~ m!^text/! || $type =~ m!\+xml$! ) 554 && $type !~ /\bcharset\b/; 555 } 556 if ( $ENV{MOD_PERL} ) { 557 if ( $app->{response_message} ) { 558 $app->{apache}->status_line( 559 ( $app->response_code || 200 ) 560 . ( $app->{response_message} 561 ? ' ' . $app->{response_message} 562 : '' 563 ) 564 ); 565 } 566 else { 567 $app->{apache}->status( $app->response_code || 200 ); 539 568 } 540 569 $app->{apache}->send_http_header($type); 541 if ($MT::DebugMode & 128) { 542 print "Status: " . ($app->response_code || 200) 543 . ($app->{response_message} ? ' ' . $app->{response_message} : '') 570 if ( $MT::DebugMode & 128 ) { 571 print "Status: " 572 . ( $app->response_code || 200 ) 573 . ( $app->{response_message} 574 ? ' ' . $app->{response_message} 575 : '' ) 544 576 . "\n"; 545 577 print "Content-Type: $type\n\n"; 546 578 } 547 } else { 548 $app->{cgi_headers}{-status} = ($app->response_code || 200) 549 . ($app->{response_message} ? ' ' . $app->{response_message} : ''); 579 } 580 else { 581 $app->{cgi_headers}{-status} 582 = ( $app->response_code || 200 ) 583 . ( 584 $app->{response_message} ? ' ' . $app->{response_message} : '' ); 550 585 $app->{cgi_headers}{-type} = $type; 551 $app->print( $app->{query}->header(%{ $app->{cgi_headers} }));586 $app->print( $app->{query}->header( %{ $app->{cgi_headers} } ) ); 552 587 } 553 588 } … … 555 590 sub print { 556 591 my $app = shift; 557 if ( $ENV{MOD_PERL}) {592 if ( $ENV{MOD_PERL} ) { 558 593 $app->{apache}->print(@_); 559 } else { 594 } 595 else { 560 596 CORE::print(@_); 561 597 } 562 if ( $MT::DebugMode & 128) {598 if ( $MT::DebugMode & 128 ) { 563 599 CORE::print STDERR @_; 564 600 } … … 567 603 sub handler ($$) { 568 604 my $class = shift; 569 my ($r) = @_;605 my ($r) = @_; 570 606 require Apache::Constants; 571 if ( lc($r->dir_config('Filter') || '') eq 'on') {607 if ( lc( $r->dir_config('Filter') || '' ) eq 'on' ) { 572 608 $r = $r->filter_register; 573 609 } 574 610 my $config_file = $r->dir_config('MTConfig'); 575 my $mt_dir = $r->dir_config('MTHome'); 576 my %params = (Config => $config_file, ApacheObject => $r, 577 ( $mt_dir ? ( Directory => $mt_dir ) : () )); 578 my $app = $class->new( %params ) 611 my $mt_dir = $r->dir_config('MTHome'); 612 my %params = ( 613 Config => $config_file, 614 ApacheObject => $r, 615 ( $mt_dir ? ( Directory => $mt_dir ) : () ) 616 ); 617 my $app = $class->new(%params) 579 618 or die $class->errstr; 580 619 … … 583 622 584 623 my $cfg = $app->config; 585 if ( my @extra = $r->dir_config('MTSetVar')) {624 if ( my @extra = $r->dir_config('MTSetVar') ) { 586 625 for my $d (@extra) { 587 my ($var, $val) = $d =~ /^\s*(\S+)\s+(.+)$/;588 $cfg->set( $var, $val);626 my ( $var, $val ) = $d =~ /^\s*(\S+)\s+(.+)$/; 627 $cfg->set( $var, $val ); 589 628 } 590 629 } … … 602 641 603 642 sub init { 604 my $app = shift;643 my $app = shift; 605 644 my %param = @_; 606 645 $app->{apache} = $param{ApacheObject} if exists $param{ApacheObject}; 607 646 $app->SUPER::init(%param) or return; 608 $app->{vtbl} = {};609 $app->{is_admin} = 0;610 $app->{template_dir} = 'cms';#$app->id;611 $app->{user_class} = 'MT::Author';647 $app->{vtbl} = {}; 648 $app->{is_admin} = 0; 649 $app->{template_dir} = 'cms'; #$app->id; 650 $app->{user_class} = 'MT::Author'; 612 651 $app->{plugin_template_path} = 'tmpl'; 613 $app->run_callbacks('init_app', $app, @_); 614 if ($MT::DebugMode & 4) { 652 $app->run_callbacks( 'init_app', $app, @_ ); 653 654 if ( $MT::DebugMode & 4 ) { 655 615 656 # SQL profiling 616 657 my $dbh = MT::Object->driver->r_handle; … … 618 659 $dbh->{Profile} = DBI::Profile->new(); 619 660 } 620 if ( $MT::DebugMode & 128) {621 MT->add_callback( 'pre_run', 1, $app, sub { $app->pre_run_debug });622 MT->add_callback( 'takedown', 1, $app, sub { $app->post_run_debug });661 if ( $MT::DebugMode & 128 ) { 662 MT->add_callback( 'pre_run', 1, $app, sub { $app->pre_run_debug } ); 663 MT->add_callback( 'takedown', 1, $app, sub { $app->post_run_debug } ); 623 664 } 624 665 $app->{vtbl} = $app->registry("methods"); … … 629 670 sub pre_run_debug { 630 671 my $app = shift; 631 if ( $MT::DebugMode & 128) {672 if ( $MT::DebugMode & 128 ) { 632 673 print STDERR "=====START: $$===========================\n"; 633 674 print STDERR "Package: " . ref($app) . "\n"; … … 639 680 foreach my $key (@param) { 640 681 my @val = $app->param($key); 641 print STDERR "\t" . $key . ": " . $_ . "\n" 642 for @val; 682 print STDERR "\t" . $key . ": " . $_ . "\n" for @val; 643 683 } 644 684 } … … 648 688 649 689 sub post_run_debug { 650 if ( $MT::DebugMode & 128) {690 if ( $MT::DebugMode & 128 ) { 651 691 print STDERR "\n=====END: $$=============================\n"; 652 692 } … … 655 695 sub run_callbacks { 656 696 my $app = shift; 657 my ( $meth, @param) = @_;658 $meth = ( ref($app)||$app) . '::' . $meth unless $meth =~ m/::/;659 return $app->SUPER::run_callbacks( $meth, @param);697 my ( $meth, @param ) = @_; 698 $meth = ( ref($app) || $app ) . '::' . $meth unless $meth =~ m/::/; 699 return $app->SUPER::run_callbacks( $meth, @param ); 660 700 } 661 701 … … 663 703 my $app = shift; 664 704 $app->SUPER::init_callbacks(@_); 665 MT->add_callback('post_save', 0, $app, \&_cb_mark_blog ); 666 MT->add_callback('MT::Blog::post_remove', 0, $app, \&_cb_unmark_blog ); 667 MT->add_callback('pre_build', 9, $app, sub { $app->touch_blogs() } ); 668 MT->add_callback('new_user_provisioning', 5, $app, \&_cb_user_provisioning); 705 MT->add_callback( 'post_save', 0, $app, \&_cb_mark_blog ); 706 MT->add_callback( 'MT::Blog::post_remove', 0, $app, \&_cb_unmark_blog ); 707 MT->add_callback( 'pre_build', 9, $app, sub { $app->touch_blogs() } ); 708 MT->add_callback( 'new_user_provisioning', 5, $app, 709 \&_cb_user_provisioning ); 669 710 } 670 711 671 712 sub init_request { 672 my $app = shift;713 my $app = shift; 673 714 my %param = @_; 674 715 … … 676 717 677 718 if ($MT::DebugMode) { 678 if ( $MT::DebugMode & 4) {# SQL profile reporting is enabled719 if ( $MT::DebugMode & 4 ) { # SQL profile reporting is enabled 679 720 my $h = MT::Object->driver->r_handle; 680 if ( my $Profile = $h->{Profile}) { # if DBI profiling is enabled681 $Profile->{Data} = {}; # reset the profile data721 if ( my $Profile = $h->{Profile} ) { # if DBI profiling is enabled 722 $Profile->{Data} = {}; # reset the profile data 682 723 } 683 724 } … … 686 727 } 687 728 688 if ( $app->{request_read_config}) {689 $app->init_config( \%param) or return;729 if ( $app->{request_read_config} ) { 730 $app->init_config( \%param ) or return; 690 731 $app->{request_read_config} = 0; 691 732 } … … 699 740 delete $app->{$_} foreach @req_vars; 700 741 $app->user(undef); 701 if ( $ENV{MOD_PERL}) {742 if ( $ENV{MOD_PERL} ) { 702 743 require Apache::Request; 703 744 $app->{apache} = $param{ApacheObject} || Apache->request; 704 $app->{query} = Apache::Request->instance($app->{apache}, 705 POST_MAX => $app->config->CGIMaxUpload); 706 } else { 707 if ($param{CGIObject}) { 745 $app->{query} = Apache::Request->instance( $app->{apache}, 746 POST_MAX => $app->config->CGIMaxUpload ); 747 } 748 else { 749 if ( $param{CGIObject} ) { 708 750 $app->{query} = $param{CGIObject}; 709 751 require CGI; 710 752 $CGI::POST_MAX = $app->config->CGIMaxUpload; 711 } else { 712 if (my $path_info = $ENV{PATH_INFO}) { 713 if ($path_info =~ m/\.cgi$/) { 753 } 754 else { 755 if ( my $path_info = $ENV{PATH_INFO} ) { 756 if ( $path_info =~ m/\.cgi$/ ) { 757 714 758 # some CGI environments (notably 'sbox') leaves PATH_INFO 715 759 # defined which interferes with CGI.pm determining the … … 730 774 ## Initialize the MT::Request singleton for this particular request. 731 775 $app->request->reset(); 732 $app->request( 'App-Class', ref $app);733 734 $app->run_callbacks( ref($app) . '::init_request', $app, @_);776 $app->request( 'App-Class', ref $app ); 777 778 $app->run_callbacks( ref($app) . '::init_request', $app, @_ ); 735 779 736 780 $app->{init_request} = 1; … … 739 783 sub init_query { 740 784 my $app = shift; 741 my $q = $app->{query}; 785 my $q = $app->{query}; 786 742 787 # CGI.pm has this terrible flaw in that if a POST is in effect, 743 788 # it totally ignores any query parameters. 744 if ( $app->request_method eq 'POST') {745 if ( ! $ENV{MOD_PERL}) {789 if ( $app->request_method eq 'POST' ) { 790 if ( !$ENV{MOD_PERL} ) { 746 791 my $query_string = $ENV{'QUERY_STRING'} 747 792 if defined $ENV{'QUERY_STRING'}; 748 793 $query_string ||= $ENV{'REDIRECT_QUERY_STRING'} 749 794 if defined $ENV{'REDIRECT_QUERY_STRING'}; 750 if ( defined($query_string) and $query_string ne '') {795 if ( defined($query_string) and $query_string ne '' ) { 751 796 $q->parse_params($query_string); 752 797 } … … 755 800 } 756 801 802 { 803 my $has_encode; 804 805 sub validate_request_params { 806 my $app = shift; 807 808 $has_encode = eval { require Encode; 1 } ? 1 : 0 809 unless defined $has_encode; 810 return 1 unless $has_encode; 811 812 my $q = $app->param; 813 814 # validate all parameter data matches the expected character set. 815 my @p = $q->param(); 816 my $charset = $app->charset; 817 require Encode; 818 $charset = 'UTF-8' if $charset =~ m/utf-?8/i; 819 foreach my $p (@p) { 820 if ( $p =~ m/[^\x20-\x7E]/ ) { 821 822 # non-ASCII parameter name 823 return $app->errtrans("Invalid request"); 824 } 825 826 my @d = $q->param($p); 827 foreach my $d (@d) { 828 next 829 if ( !defined $d ) 830 || ( $d eq '' ) 831 || ( $d !~ m/[^\x20-\x7E]/ ); 832 eval { Encode::decode( $charset, $d, 1 ); }; 833 return $app->errtrans( 834 "Invalid request: corrupt character data for character set [_1]", 835 $charset 836 ) if $@; 837 } 838 } 839 840 return 1; 841 } 842 } 843 757 844 sub registry { 758 845 my $app = shift; 759 my $ar = $app->SUPER::registry("applications", $app->id, @_);760 my $gr = $app->SUPER::registry(@_) if @_;846 my $ar = $app->SUPER::registry( "applications", $app->id, @_ ); 847 my $gr = $app->SUPER::registry(@_) if @_; 761 848 if ($ar) { 762 MT::__merge_hash( $ar, $gr);849 MT::__merge_hash( $ar, $gr ); 763 850 return $ar; 764 851 } … … 767 854 768 855 sub _cb_unmark_blog { 769 my ( $eh, $obj) = @_;856 my ( $eh, $obj ) = @_; 770 857 my $mt_req = MT->instance->request; 771 if ( my $blogs_touched = $mt_req->stash('blogs_touched')) {772 delete $blogs_touched->{ $obj->id};773 $mt_req->stash( 'blogs_touched', $blogs_touched);858 if ( my $blogs_touched = $mt_req->stash('blogs_touched') ) { 859 delete $blogs_touched->{ $obj->id }; 860 $mt_req->stash( 'blogs_touched', $blogs_touched ); 774 861 } 775 862 } 776 863 777 864 sub _cb_mark_blog { 778 my ( $eh, $obj) = @_;865 my ( $eh, $obj ) = @_; 779 866 my $obj_type = ref $obj; 780 867 781 if ( $obj_type eq 'MT::Author') {868 if ( $obj_type eq 'MT::Author' ) { 782 869 require MT::Touch; 783 MT::Touch->touch( 0, 'author');870 MT::Touch->touch( 0, 'author' ); 784 871 return; 785 872 } 786 873 787 return if ($obj_type eq 'MT::Log' || $obj_type eq 'MT::Session' || 788 $obj_type eq 'MT::Touch' || 789 (($obj_type ne 'MT::Blog') && !$obj->has_column('blog_id'))); 874 return 875 if ( $obj_type eq 'MT::Log' 876 || $obj_type eq 'MT::Session' 877 || $obj_type eq 'MT::Touch' 878 || ( ( $obj_type ne 'MT::Blog' ) && !$obj->has_column('blog_id') ) ); 790 879 my $mt_req = MT->instance->request; 791 880 my $blogs_touched = $mt_req->stash('blogs_touched') || {}; … … 793 882 # Issue MT::Touch touches for specific types we track 794 883 my $type = $obj->datasource; 795 if ( $obj->properties->{class_column}) {884 if ( $obj->properties->{class_column} ) { 796 885 $type = $obj->class_type; 797 886 } 798 if ($type !~ m/^(entry|comment|page|folder|category|tbping|asset|author|template)$/) { 887 if ( $type 888 !~ m/^(entry|comment|page|folder|category|tbping|asset|author|template)$/ 889 ) 890 { 799 891 undef $type; 800 892 } 801 893 802 if ($obj_type eq 'MT::Blog') { 803 delete $blogs_touched->{$obj->id}; 804 } else { 805 if ($obj->blog_id) { 806 my $th = $blogs_touched->{$obj->blog_id} ||= {}; 894 if ( $obj_type eq 'MT::Blog' ) { 895 delete $blogs_touched->{ $obj->id }; 896 } 897 else { 898 if ( $obj->blog_id ) { 899 my $th = $blogs_touched->{ $obj->blog_id } ||= {}; 807 900 $th->{$type} = 1 if $type; 808 901 } 809 902 } 810 $mt_req->stash( 'blogs_touched', $blogs_touched);903 $mt_req->stash( 'blogs_touched', $blogs_touched ); 811 904 } 812 905 813 906 sub _cb_user_provisioning { 814 my ( $cb, $user) = @_;907 my ( $cb, $user ) = @_; 815 908 816 909 # Supply user with what they need... … … 820 913 my $new_blog; 821 914 my $blog_name = $user->nickname || MT->translate("First Weblog"); 822 if ( my $blog_id = MT->config('NewUserTemplateBlogId')) {915 if ( my $blog_id = MT->config('NewUserTemplateBlogId') ) { 823 916 my $blog = MT::Blog->load($blog_id); 824 if (!$blog) { 825 MT->log({ 826 message => MT->translate("Error loading blog #[_1] for user provisioning. Check your NewUserTemplateBlogId setting.", $blog_id), 827 level => MT::Log::ERROR(), 828 }); 917 if ( !$blog ) { 918 MT->log( 919 { message => MT->translate( 920 "Error loading blog #[_1] for user provisioning. Check your NewUserTemplateBlogId setting.", 921 $blog_id 922 ), 923 level => MT::Log::ERROR(), 924 } 925 ); 829 926 return; 830 927 } 831 $new_blog = $blog->clone({ 832 Children => 1, 833 Classes => { 'MT::Permission' => 0, 'MT::Association' => 0 }, 834 BlogName => $blog_name, 835 }); 836 if (!$new_blog) { 837 MT->log({ 838 message => MT->translate("Error provisioning blog for new user '[_1]' using template blog #[_2].", $user->id, $blog->id), 839 level => MT::Log::ERROR(), 840 }); 928 $new_blog = $blog->clone( 929 { Children => 1, 930 Classes => { 'MT::Permission' => 0, 'MT::Association' => 0 }, 931 BlogName => $blog_name, 932 &n
