Changeset 1430
- Timestamp:
- 03/06/08 06:15:30 (9 months ago)
- Files:
-
- 1 modified
-
trunk/htdocs/system/classes/theme.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/htdocs/system/classes/theme.php
r1392 r1430 19 19 /** 20 20 * We build the Post filters by analyzing the handler_var 21 * data which is assigned to the handler ( by the Controller and22 * also, optionally, by the Theme )23 */21 * data which is assigned to the handler ( by the Controller and 22 * also, optionally, by the Theme ) 23 */ 24 24 public $valid_filters= array( 25 'content_type',25 'content_type', 26 26 'slug', 27 27 'status', … … 36 36 'nolimit', 37 37 'fetch_fn', 38 'id', 38 39 ); 39 40 … … 50 51 * @param theme_dir ( optional ) specify a theme directory 51 52 */ 52 public function __construct( $themedata)53 public function __construct( $themedata ) 53 54 { 54 55 $this->name= $themedata->name; … … 70 71 public function info( $theme ) 71 72 { 72 $xml_file= Site::get_path( 'user') . '/themes/' . $theme . '/theme.xml';73 $xml_file= Site::get_path( 'user' ) . '/themes/' . $theme . '/theme.xml'; 73 74 if ( $xml_content= file_get_contents( $xml_file ) ) { 74 75 $theme_data= new SimpleXMLElement( $xml_file ); … … 101 102 { 102 103 $handler= Controller::get_handler(); 103 if ( isset( $handler ) ) {104 Plugins::act( 'add_template_vars', $this, Controller::get_handler()->handler_vars);104 if ( isset( $handler ) ) { 105 Plugins::act( 'add_template_vars', $this, Controller::get_handler()->handler_vars ); 105 106 } 106 107 } … … 110 111 * @param array $template_list The list of templates to search for 111 112 */ 112 public function display_fallback( $template_list)113 { 114 foreach ( $template_list as $template ) {115 if ( $this->template_exists( $template ) ) {113 public function display_fallback( $template_list ) 114 { 115 foreach ( $template_list as $template ) { 116 if ( $this->template_exists( $template ) ) { 116 117 $this->display( $template ); 117 118 return true; … … 150 151 $where_filters= array(); 151 152 $where_filters= array_intersect_key( Controller::get_handler()->handler_vars, array_flip( $this->valid_filters ) ); 152 //$where_filters['status']= Post::status( 'published');153 if ( array_key_exists('tag', $where_filters)) {153 //$where_filters['status']= Post::status( 'published' ); 154 if ( array_key_exists( 'tag', $where_filters ) ) { 154 155 $where_filters['tag_slug']= $where_filters['tag']; 155 unset( $where_filters['tag']);156 unset( $where_filters['tag'] ); 156 157 } 157 158 if ( User::identify() ) { 158 $where_filters['status']= Post::status( 'any');159 $where_filters['status']= Post::status( 'any' ); 159 160 } 160 161 else { 161 $where_filters['status']= Post::status( 'published');162 } 163 164 if ( !isset( $posts ) ) {162 $where_filters['status']= Post::status( 'published' ); 163 } 164 165 if ( !isset( $posts ) ) { 165 166 $user_filters= Plugins::filter( 'template_user_filters', $user_filters ); 166 167 $user_filters= array_intersect_key( $user_filters, array_flip( $this->valid_filters ) ); … … 180 181 $type= $types[$post->content_type]; 181 182 } 182 elseif ( $posts === false ) {183 $fallback= array( '404');183 elseif ( $posts === false ) { 184 $fallback= array( '404' ); 184 185 header( 'HTTP/1.0 404 Not Found' ); 185 186 // Replace template variables with the 404 rewrite rule … … 194 195 // Default fallbacks based on the number of posts 195 196 $fallback= array( '{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}' ); 196 if ( count( $posts ) > 1 ) {197 if ( count( $posts ) > 1 ) { 197 198 $fallback[]= '{$type}.multiple'; 198 199 $fallback[]= 'multiple'; … … 204 205 } 205 206 206 $searches= array( '{$id}','{$slug}','{$year}','{$month}','{$day}','{$type}','{$tag}',);207 $searches= array( '{$id}','{$slug}','{$year}','{$month}','{$day}','{$type}','{$tag}', ); 207 208 $replacements= array( 208 ( isset($post) && $post instanceof Post)?$post->id:'-',209 ( isset($post) && $post instanceof Post)?$post->slug:'-',210 isset( $year)?$year:'-',211 isset( $month)?$month:'-',212 isset( $day)?$day:'-',213 isset( $type)?$type:'-',214 isset( $tag)?$tag:'-',209 ( isset( $post ) && $post instanceof Post ) ? $post->id : '-', 210 ( isset( $post ) && $post instanceof Post ) ? $post->slug : '-', 211 isset( $year ) ? $year : '-', 212 isset( $month ) ? $month : '-', 213 isset( $day ) ? $day : '-', 214 isset( $type ) ? $type : '-', 215 isset( $tag ) ? $tag : '-', 215 216 ); 216 217 $fallback[]= 'home'; 217 218 $fallback= Plugins::filter( 'template_fallback', $fallback ); 218 $fallback= array_unique( str_replace( $searches, $replacements, $fallback) );219 for ($z = 0; $z < count($fallback); $z++) {220 if ( (strpos($fallback[$z], '{$posttag}') !== false) && (isset($post)) && ($post instanceof Post)) {219 $fallback= array_unique( str_replace( $searches, $replacements, $fallback ) ); 220 for ( $z= 0; $z < count( $fallback ); $z++ ) { 221 if ( ( strpos( $fallback[$z], '{$posttag}' ) !== false ) && ( isset( $post ) ) && ( $post instanceof Post ) ) { 221 222 $replacements= array(); 222 if ( $alltags= $post->tags ) {223 foreach ($alltags as $tag_slug => $tag_text ) {224 $replacements[] = str_replace('{$posttag}', $tag_slug, $fallback[$z]);223 if ( $alltags= $post->tags ) { 224 foreach ( $alltags as $tag_slug => $tag_text ) { 225 $replacements[]= str_replace( '{$posttag}', $tag_slug, $fallback[$z] ); 225 226 } 226 array_splice( $fallback, $z, 1, $replacements);227 array_splice( $fallback, $z, 1, $replacements ); 227 228 } 228 229 else { … … 248 249 // Makes sure home displays only entries 249 250 $default_filters= array( 250 'content_type' => Post::type('entry'),251 'content_type' => Post::type( 'entry' ), 251 252 ); 252 253 … … 289 290 $commenter_email= ''; 290 291 $commenter_url= ''; 291 $commenter_content = '';292 $user = User::identify();292 $commenter_content= ''; 293 $user= User::identify(); 293 294 if ( isset( $_SESSION['comment'] ) ) { 294 $details= Session::get_set( 'comment');295 $details= Session::get_set( 'comment' ); 295 296 $commenter_name= $details['name']; 296 297 $commenter_email= $details['email']; 297 298 $commenter_url= $details['url']; 298 $commenter_content = $details['content'];299 $commenter_content= $details['content']; 299 300 } 300 301 elseif ( $user ) { 301 302 $commenter_name= $user->username; 302 303 $commenter_email= $user->email; 303 $commenter_url= Site::get_url( 'habari');304 $commenter_url= Site::get_url( 'habari' ); 304 305 } 305 306 elseif ( isset( $_COOKIE[$cookie] ) ) { … … 307 308 } 308 309 309 $this->commenter_name = $commenter_name;310 $this->commenter_email = $commenter_email;311 $this->commenter_url = $commenter_url;312 $this->commenter_content = $commenter_content;313 314 $this->comments_require_id = Options::get('comments_require_id');310 $this->commenter_name= $commenter_name; 311 $this->commenter_email= $commenter_email; 312 $this->commenter_url= $commenter_url; 313 $this->commenter_content= $commenter_content; 314 315 $this->comments_require_id= Options::get( 'comments_require_id' ); 315 316 316 317 return $this->act_display( $paramarray ); … … 331 332 // Makes sure home displays only entries 332 333 $default_filters= array( 333 'content_type' => Post::type('entry'),334 'content_type' => Post::type( 'entry' ), 334 335 ); 335 336 … … 346 347 { 347 348 $handler_vars= Controller::get_handler()->handler_vars; 348 $y = isset( $handler_vars['year'] ); 349 $m = isset( $handler_vars['month'] ); 350 $d = isset( $handler_vars['day'] ); 351 352 if($y&&$m&&$d) $paramarray['fallback'][]= 'year.{$year}.month.{$month}.day.{$day}'; 353 if($y&&$m&&$d) $paramarray['fallback'][]= 'year.month.day'; 354 if($m&&$d) $paramarray['fallback'][]= 'month.{$month}.day.{$day}'; 355 if($y&&$m) $paramarray['fallback'][]= 'year.{$year}.month.{$month}'; 356 if($y&&$d) $paramarray['fallback'][]= 'year.{$year}.day.{$day}'; 357 if($m&&$d) $paramarray['fallback'][]= 'month.day'; 358 if($y&&$d) $paramarray['fallback'][]= 'year.day'; 359 if($y&&$m) $paramarray['fallback'][]= 'year.month'; 360 if($m) $paramarray['fallback'][]= 'month.{$month}'; 361 if($d) $paramarray['fallback'][]= 'day.{$day}'; 362 if($y) $paramarray['fallback'][]= 'year.{$year}'; 363 if($y) $paramarray['fallback'][]= 'year'; 364 if($m) $paramarray['fallback'][]= 'month'; 365 if($d) $paramarray['fallback'][]= 'day'; 349 $y= isset( $handler_vars['year'] ); 350 $m= isset( $handler_vars['month'] ); 351 $d= isset( $handler_vars['day'] ); 352 353 if ( $y && $m && $d ) { 354 $paramarray['fallback'][]= 'year.{$year}.month.{$month}.day.{$day}'; 355 } 356 if ( $y && $m && $d) { 357 $paramarray['fallback'][]= 'year.month.day'; 358 } 359 if ( $m && $d ) { 360 $paramarray['fallback'][]= 'month.{$month}.day.{$day}'; 361 } 362 if ( $y && $m ) { 363 $paramarray['fallback'][]= 'year.{$year}.month.{$month}'; 364 } 365 if ( $y && $d ) { 366 $paramarray['fallback'][]= 'year.{$year}.day.{$day}'; 367 } 368 if ( $m && $d ) { 369 $paramarray['fallback'][]= 'month.day'; 370 } 371 if ( $y && $d ) { 372 $paramarray['fallback'][]= 'year.day'; 373 } 374 if ( $y && $m ) { 375 $paramarray['fallback'][]= 'year.month'; 376 } 377 if ( $m ) { 378 $paramarray['fallback'][]= 'month.{$month}'; 379 } 380 if ( $d ) { 381 $paramarray['fallback'][]= 'day.{$day}'; 382 } 383 if ( $y ) { 384 $paramarray['fallback'][]= 'year.{$year}'; 385 } 386 if ( $y ) { 387 $paramarray['fallback'][]= 'year'; 388 } 389 if ( $m ) { 390 $paramarray['fallback'][]= 'month'; 391 } 392 if ( $d ) { 393 $paramarray['fallback'][]= 'day'; 394 } 366 395 $paramarray['fallback'][]= 'multiple'; 367 396 $paramarray['fallback'][]= 'home'; … … 413 442 $this->add_template_vars(); 414 443 415 if ( isset( Controller::get_handler()->handler_vars ) ) {444 if ( isset( Controller::get_handler()->handler_vars ) ) { 416 445 foreach ( Controller::get_handler()->handler_vars as $key => $value ) { 417 446 $this->assign( $key, $value ); … … 427 456 $this->add_template_vars(); 428 457 429 if ( isset( Controller::get_handler()->handler_vars ) ) {458 if ( isset( Controller::get_handler()->handler_vars ) ) { 430 459 foreach ( Controller::get_handler()->handler_vars as $key => $value ) { 431 460 $this->assign( $key, $value ); … … 448 477 * Aggregates and echos the additional header code by combining Plugins and Stack calls. 449 478 */ 450 public function theme_header( $theme ) { 451 $output = Stack::get( 'template_stylesheet', '<link rel="stylesheet" type="text/css" href="%s" media="%s">'."\r\n" ); 452 $output .= Stack::get( 'template_header_javascript', '<script src="%s" type="text/javascript"></script>'."\r\n" ); 479 public function theme_header( $theme ) 480 { 481 $output= Stack::get( 'template_stylesheet', '<link rel="stylesheet" type="text/css" href="%s" media="%s">'."\r\n" ); 482 $output.= Stack::get( 'template_header_javascript', '<script src="%s" type="text/javascript"></script>'."\r\n" ); 453 483 return $output; 454 484 } … … 457 487 * Aggregates and echos the additional footer code by combining Plugins and Stack calls. 458 488 */ 459 public function theme_footer( $theme ) { 489 public function theme_footer( $theme ) 490 { 460 491 Plugins::act( 'template_footer', $theme ); 461 $output = Stack::get( 'template_footer_javascript', ' <script src="%s" type="text/javascript"></script>'."\r\n" );492 $output= Stack::get( 'template_footer_javascript', ' <script src="%s" type="text/javascript"></script>'."\r\n" ); 462 493 return $output; 463 494 } … … 473 504 { 474 505 $matched_rule= URL::get_matched_rule(); 475 if (is_object($matched_rule)) {506 if ( is_object( $matched_rule ) ) { 476 507 // This is not a 404 477 $rulename = $matched_rule->name;508 $rulename= $matched_rule->name; 478 509 } 479 510 else { 480 511 // If this is a 404 and no rewrite rule matched the request 481 $rulename = '';512 $rulename= ''; 482 513 } 483 514 switch ( $rulename ) { 484 515 case 'display_entry': 485 516 case 'display_page': 486 return URL::get( 'atom_entry', array( 'slug' => Controller::get_var( 'slug') ) );517 return URL::get( 'atom_entry', array( 'slug' => Controller::get_var( 'slug' ) ) ); 487 518 break; 488 519 case 'display_entries_by_tag': 489 return URL::get( 'atom_feed_tag', array( 'tag' => Controller::get_var( 'tag') ) );520 return URL::get( 'atom_feed_tag', array( 'tag' => Controller::get_var( 'tag' ) ) ); 490 521 break; 491 522 case 'display_home': … … 552 583 public function __call( $function, $params ) 553 584 { 554 if (strpos($function, 'act_') === 0) {585 if ( strpos( $function, 'act_' ) === 0 ) { 555 586 // The first parameter is an array, get it 556 if (count($params) > 0) {557 list( $user_filters)= $params;587 if ( count( $params ) > 0 ) { 588 list( $user_filters )= $params; 558 589 } 559 590 else { 560 591 $user_filters= array(); 561 592 } 562 $action = substr($function, 4);563 Plugins::act( 'theme_action', $action, $this, $user_filters);593 $action= substr( $function, 4 ); 594 Plugins::act( 'theme_action', $action, $this, $user_filters ); 564 595 } 565 596 else { 566 $purposed = 'output';567 if (preg_match('%^(.*)_(return|end)$%', $function, $matches)) {568 $purposed = $matches[2];569 $function = $matches[1];570 } 571 array_unshift( $params, $function, $this);572 $result = call_user_func_array(array('Plugins', 'theme'), $params);573 switch( $purposed) {597 $purposed= 'output'; 598 if ( preg_match( '%^(.*)_(return|end)$%', $function, $matches ) ) { 599 $purposed= $matches[2]; 600 $function= $matches[1]; 601 } 602 array_unshift( $params, $function, $this ); 603 $result= call_user_func_array( array( 'Plugins', 'theme' ), $params ); 604 switch( $purposed ) { 574 605 case 'return': 575 606 return $result; 576 607 case 'end': 577 echo end( $result);578 return end( $result);608 echo end( $result ); 609 return end( $result ); 579 610 default: 580 $output = implode('', (array)$result);611 $output= implode( '', ( array ) $result ); 581 612 echo $output; 582 613 return $output; … … 584 615 } 585 616 } 586 587 617 } 588 589 590 591 618 ?>
