[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements Template tags for use withing skins. 4 * 5 * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}. 9 * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}. 10 * 11 * @license http://b2evolution.net/about/license.html GNU General Public License (GPL) 12 * 13 * {@internal Open Source relicensing agreement: 14 * Daniel HAHLER grants Francois PLANQUE the right to license 15 * Daniel HAHLER's contributions to this file and the b2evolution project 16 * under any OSI approved OSS license (http://www.opensource.org/licenses/). 17 * }} 18 * 19 * @package evocore 20 * 21 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 22 * @author blueyed: Daniel HAHLER. 23 * @author fplanque: Francois PLANQUE. 24 * 25 * @version $Id: _skin.funcs.php,v 1.14 2007/11/02 02:41:25 fplanque Exp $ 26 */ 27 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 28 29 30 /** 31 * Template tag. Initializes internal states for the most common skin displays. 32 * 33 * For more specific skins, this function should not be called and 34 * equivalent code should be customized within the skin. 35 * 36 * @param string What are we going to display. Most of the time the global $disp should be passed. 37 */ 38 function skin_init( $disp ) 39 { 40 /** 41 * @var Blog 42 */ 43 global $Blog; 44 45 global $robots_index; 46 47 global $redir, $ReqHost, $ReqURI; 48 49 global $Chapter; 50 51 /** 52 * @var ItemList2 53 */ 54 global $MainList; 55 56 // This is the main template; it may be used to display very different things. 57 // Do inits depending on current $disp: 58 switch( $disp ) 59 { 60 case 'posts': 61 case 'single': 62 case 'page': 63 case 'feedback-popup': 64 // We need to load posts for this display: 65 66 // Note: even if we request the same post as $Item above, the following will do more restrictions (dates, etc.) 67 // Init the MainList object: 68 init_MainList( $Blog->get_setting('posts_per_page') ); 69 break; 70 } 71 72 // SEO stuff: 73 switch( $disp ) 74 { 75 case 'posts': 76 // Get list of active filters: 77 $active_filters = $MainList->get_active_filters(); 78 79 if( !empty($active_filters) ) 80 { // The current page is being filtered... 81 82 if( array_diff( $active_filters, array( 'page' ) ) == array() ) 83 { // This is just a follow "paged" page 84 if( $Blog->get_setting( 'paged_noindex' ) ) 85 { // We prefer robots not to index category pages: 86 $robots_index = false; 87 } 88 } 89 elseif( array_diff( $active_filters, array( 'cat_array', 'cat_modifier', 'cat_focus' ) ) == array() ) 90 { // This is a category home page (note: subsequent pages are a different story) 91 if( $Blog->get_setting( 'category_noindex' ) ) 92 { // We prefer robots not to index category pages: 93 $robots_index = false; 94 } 95 96 global $cat, $catsel; 97 if( empty( $catsel ) && preg_match( '¤[0-9]+¤', $cat ) ) 98 { // We are on a single cat page: 99 // NOTE: we must have selected EXACTLY ONE CATEGORY thrpught the cat parameter 100 // BUT: - this can resolved to including children 101 // - selecting exactly one cat through catsel[] is NOT OK since not equivalent (will exclude children) 102 // echo 'SINGLE CAT PAGE'; 103 // EXPERIMENTAL: Please document encountered problems. 104 if( $Blog->get_setting( 'canonical_cat_urls' ) && $redir == 'yes' ) 105 { // Check if the URL was canonical: 106 if( !isset( $Chapter ) ) 107 { 108 $ChapterCache = & get_Cache( 'ChapterCache' ); 109 $Chapter = & $ChapterCache->get_by_ID( $MainList->filters['cat_array'][0], false ); 110 } 111 $canoncical_url = $Chapter->get_permanent_url( NULL, NULL, '&' ); 112 if( $ReqHost.$ReqURI != $canoncical_url ) 113 { 114 // REDIRECT TO THE CANONICAL URL: 115 // fp> TODO: we're going to lose the additional params, it would be better to keep them... 116 // fp> what additional params actually? 117 header_redirect( $canoncical_url, true ); 118 } 119 } 120 121 } 122 } 123 elseif( array_diff( $active_filters, array( 'ymdhms', 'week', 'page' ) ) == array() ) 124 { // This is an archive page 125 // echo 'archive page'; 126 if( $Blog->get_setting( 'archive_noindex' ) ) 127 { // We prefer robots not to index archive pages: 128 $robots_index = false; 129 } 130 } 131 else 132 { // Other filtered pages: 133 if( $Blog->get_setting( 'filtered_noindex' ) ) 134 { // We prefer robots not to index other filtered pages: 135 $robots_index = false; 136 } 137 } 138 } 139 else 140 { // This is the default blog page 141 if( $Blog->get_setting( 'default_noindex' ) ) 142 { // We prefer robots not to index archive pages: 143 $robots_index = false; 144 } 145 } 146 147 break; 148 149 case 'feedback-popup': 150 case 'arcdir': 151 case 'catdir': 152 case 'msgform': 153 if( $Blog->get_setting( $disp.'_noindex' ) ) 154 { // We prefer robots not to index these pages: 155 $robots_index = false; 156 } 157 break; 158 159 case 'profile': 160 case 'subs': 161 if( $Blog->get_setting( 'special_noindex' ) ) 162 { // We prefer robots not to index these pages: 163 $robots_index = false; 164 } 165 break; 166 } 167 } 168 169 170 /** 171 * Template tag. Include a sub-template at the current position 172 * 173 * @todo plugin hook to handle a special disp 174 */ 175 function skin_include( $template_name, $params = array() ) 176 { 177 global $skins_path, $ads_current_skin_path, $disp; 178 179 // Globals that may be needed by the template: 180 global $Blog, $MainList, $Item; 181 global $Plugins, $Skin; 182 global $current_User, $Hit, $Session, $Settings; 183 global $skin_url, $htsrv_url, $htsrv_url_sensitive; 184 global $credit_links, $skin_links, $francois_links, $fplanque_links, $skinfaktory_links; 185 186 if( $template_name == '$disp$' ) 187 { // This is a special case. 188 // We are going to include a template based on $disp: 189 190 // Default display handlers: 191 $disp_handlers = array_merge( array( 192 'disp_posts' => '_posts.disp.php', 193 'disp_single' => '_single.disp.php', 194 'disp_page' => '_page.disp.php', 195 'disp_arcdir' => '_arcdir.php', 196 'disp_catdir' => '_catdir.disp.php', 197 'disp_comments' => '_lastcomments.php', 198 'disp_msgform' => '_msgform.php', 199 'disp_profile' => '_profile.php', 200 'disp_subs' => '_subscriptions.php', 201 ), $params ); 202 203 if( !isset( $disp_handlers['disp_'.$disp] ) ) 204 { 205 printf( '<div class="skin_error">Unhandled disp type [%s]</div>', $disp ); 206 return; 207 } 208 209 $template_name = $disp_handlers['disp_'.$disp]; 210 211 if( empty( $template_name ) ) 212 { // The caller asked not to display this handler 213 return; 214 } 215 } 216 217 if( file_exists( $ads_current_skin_path.$template_name ) ) 218 { // The skin has a customized handler, use that one instead: 219 require $ads_current_skin_path.$template_name; 220 } 221 elseif( file_exists( $skins_path.$template_name ) ) 222 { // Use the default template: 223 require $skins_path.$template_name; 224 } 225 else 226 { 227 printf( '<div class="skin_error">Sub template [%s] not found.</div>', $template_name ); 228 if( !empty($current_User) && $current_User->level == 10 ) 229 { 230 printf( '<div class="skin_error">User level 10 help info: [%s]</div>', $ads_current_skin_path.$template_name ); 231 } 232 } 233 } 234 235 236 /** 237 * Template tag. Output HTML base tag to current skin. 238 * 239 * This is needed for relative css and img includes. 240 */ 241 function skin_base_tag() 242 { 243 global $skins_url, $skin, $Blog, $disp; 244 245 if( ! empty( $skin ) ) 246 { 247 $base_href = $skins_url.$skin.'/'; 248 } 249 else 250 { // No skin used: 251 if( ! empty( $Blog ) ) 252 { 253 $base_href = $Blog->gen_baseurl(); 254 } 255 else 256 { 257 $base_href = $baseurl; 258 } 259 } 260 261 $target = NULL; 262 if( !empty($disp) && strpos( $disp, '-popup' ) ) 263 { // We are (normally) displaying in a popup window, we need most links to open a new window! 264 $target = '_blank'; 265 } 266 267 base_tag( $base_href, $target ); 268 } 269 270 271 /** 272 * Template tag. Output content-type header 273 * 274 * We use this method when we are NOT generating a static page 275 * 276 * @see skin_content_meta() 277 * 278 * @param string content-type; override for RSS feeds 279 */ 280 function skin_content_header( $type = 'text/html' ) 281 { 282 global $generating_static, $io_charset; 283 284 if( empty($generating_static) ) 285 { // We use this method when we are NOT generating a static page 286 header( 'Content-type: '.$type.'; charset='.$io_charset ); 287 } 288 } 289 290 291 /** 292 * Template tag. Output content-type http_equiv meta tag 293 * 294 * We use this method when we ARE generating a static page 295 * 296 * @see skin_content_header() 297 * 298 * @param string content-type; override for RSS feeds 299 */ 300 function skin_content_meta( $type = 'text/html' ) 301 { 302 global $generating_static, $io_charset; 303 304 if( ! empty($generating_static) ) 305 { // We use this method when we ARE generating a static page 306 echo '<meta http-equiv="Content-Type" content="'.$type.'; charset='.$io_charset.'" />'; 307 } 308 } 309 310 311 /** 312 * Template tag. Display a Widget. 313 * 314 * This load the widget class, instantiates it, and displays it. 315 * 316 * @param array 317 */ 318 function skin_widget( $params ) 319 { 320 if( empty( $params['widget'] ) ) 321 { 322 echo 'No widget code provided!'; 323 return false; 324 } 325 326 $widget_code = $params['widget']; 327 unset( $params['widget'] ); 328 329 if( ! load_class( 'widgets/widgets/_'.$widget_code.'.widget.php', false ) ) 330 { // For some reason, that widget doesn't seem to exist... (any more?) 331 echo "Invalid widget code provided [$widget_code]!"; 332 return false; 333 } 334 335 $widget_classname = $widget_code.'_Widget'; 336 337 /** 338 * @var ComponentWidget 339 */ 340 $Widget = new $widget_classname(); // COPY !! 341 342 return $Widget->display( $params ); 343 } 344 345 346 /** 347 * Display a container 348 * 349 * @param string 350 * @param array 351 */ 352 function skin_container( $sco_name, $params = array() ) 353 { 354 global $Skin; 355 356 $Skin->container( $sco_name, $params ); 357 } 358 359 /** 360 * Checks if a skin is provided by a plugin. 361 * 362 * Used by front-end. 363 * 364 * @uses Plugin::GetProvidedSkins() 365 * @return false|integer False in case no plugin provides the skin or ID of the first plugin that provides it. 366 */ 367 function skin_provided_by_plugin( $name ) 368 { 369 static $plugin_skins; 370 if( ! isset($plugin_skins) || ! isset($plugin_skins[$name]) ) 371 { 372 global $Plugins; 373 374 $plugin_r = $Plugins->trigger_event_first_return('GetProvidedSkins', NULL, array('in_array'=>$name)); 375 if( $plugin_r ) 376 { 377 $plugin_skins[$name] = $plugin_r['plugin_ID']; 378 } 379 else 380 { 381 $plugin_skins[$name] = false; 382 } 383 } 384 385 return $plugin_skins[$name]; 386 } 387 388 389 /** 390 * Checks if a skin exists. This can either be a regular skin directory 391 * or can be in the list {@link Plugin::GetProvidedSkins()}. 392 * 393 * Used by front-end. 394 * 395 * @param skin name (directory name) 396 * @return boolean true is exists, false if not 397 */ 398 function skin_exists( $name, $filename = 'index.main.php' ) 399 { 400 global $skins_path; 401 402 if( is_readable( $skins_path.$name.'/'.$filename ) ) 403 { 404 return true; 405 } 406 407 // Check list provided by plugins: 408 if( skin_provided_by_plugin($name) ) 409 { 410 return true; 411 } 412 413 return false; 414 } 415 416 417 418 /* 419 * $Log: _skin.funcs.php,v $ 420 * Revision 1.14 2007/11/02 02:41:25 fplanque 421 * refactored blog settings / UI 422 * 423 * Revision 1.13 2007/10/12 05:26:59 fplanque 424 * global $DB has been added to _subscriptions already and its use should not be encouraged. Therefore I don't want it available by default. _subscriptions.php should be cleaned up at some point. 425 * 426 * Revision 1.11 2007/10/09 02:10:50 fplanque 427 * URL fixes 428 * 429 * Revision 1.10 2007/10/06 21:31:40 fplanque 430 * Category redirector fix 431 * 432 * Revision 1.9 2007/10/01 13:37:28 fplanque 433 * fix 434 * 435 * Revision 1.8 2007/10/01 08:03:57 yabs 436 * minor fix 437 * 438 * Revision 1.7 2007/10/01 01:06:31 fplanque 439 * Skin/template functions cleanup. 440 * 441 * Revision 1.6 2007/09/28 09:28:36 fplanque 442 * per blog advanced SEO settings 443 * 444 * Revision 1.5 2007/09/11 23:10:39 fplanque 445 * translation updates 446 * 447 * Revision 1.4 2007/09/11 21:07:09 fplanque 448 * minor fixes 449 * 450 * Revision 1.3 2007/06/30 20:37:50 fplanque 451 * fixes 452 * 453 * Revision 1.2 2007/06/27 02:23:25 fplanque 454 * new default template for skins named index.main.php 455 * 456 * Revision 1.1 2007/06/25 11:01:28 fplanque 457 * MODULES (refactored MVC) 458 * 459 * Revision 1.24 2007/06/24 18:28:56 fplanque 460 * refactored skin install 461 * 462 * Revision 1.23 2007/06/24 01:05:31 fplanque 463 * skin_include() now does all the template magic for skins 2.0. 464 * .disp.php templates still need to be cleaned up. 465 * 466 * Revision 1.22 2007/06/20 21:42:13 fplanque 467 * implemented working widget/plugin params 468 * 469 * Revision 1.21 2007/05/28 15:18:31 fplanque 470 * cleanup 471 * 472 * Revision 1.20 2007/05/07 18:59:45 fplanque 473 * renamed skin .page.php files to .tpl.php 474 * 475 * Revision 1.19 2007/05/07 18:03:28 fplanque 476 * cleaned up skin code a little 477 * 478 * Revision 1.18 2007/04/26 00:11:12 fplanque 479 * (c) 2007 480 * 481 * Revision 1.17 2007/03/18 01:39:54 fplanque 482 * renamed _main.php to main.page.php to comply with 2.0 naming scheme. 483 * (more to come) 484 * 485 * Revision 1.16 2007/01/26 04:52:53 fplanque 486 * clean comment popups (skins 2.0) 487 * 488 * Revision 1.15 2007/01/14 01:33:34 fplanque 489 * losely restrict to *installed* XML feed skins 490 * 491 * Revision 1.14 2007/01/08 02:11:56 fplanque 492 * Blogs now make use of installed skins 493 * next step: make use of widgets inside of skins 494 * 495 * Revision 1.13 2006/12/04 21:25:18 fplanque 496 * removed user skin switching 497 * 498 * Revision 1.12 2006/11/13 17:00:02 fplanque 499 * doc 500 * 501 * Revision 1.11 2006/10/30 12:57:33 blueyed 502 * Fix for XHTML 503 * 504 * Revision 1.10 2006/10/08 22:59:31 blueyed 505 * Added GetProvidedSkins and DisplaySkin hooks. Allow for optimization in Plugins::trigger_event_first_return() 506 */ 507 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |