[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/_core/ -> _template.funcs.php (source)

   1  <?php
   2  /**

   3   * This file implements misc functions to be called from the templates.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.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-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * {@internal License choice

  12   * - If you have received this file as part of a package, please find the license.txt file in

  13   *   the same folder or the closest folder above for complete license terms.

  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  15   *   then you must choose one of the following licenses before using the file:

  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  18   * }}

  19   *

  20   * {@internal Open Source relicensing agreement:

  21   * Daniel HAHLER grants Francois PLANQUE the right to license

  22   * Daniel HAHLER's contributions to this file and the b2evolution project

  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  24   * }}

  25   *

  26   * @package evocore

  27   *

  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  29   * @author blueyed: Daniel HAHLER.

  30   * @author fplanque: Francois PLANQUE.

  31   *

  32   * @version $Id: _template.funcs.php,v 1.11 2007/11/03 23:54:39 fplanque Exp $

  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  
  37  /**

  38   * Display a global title matching filter params

  39   *

  40   * Outputs the title of the category when you load the page with <code>?cat=</code>

  41   * Display "Archive Directory" title if it has been requested

  42   * Display "Latest comments" title if these have been requested

  43   * Display "Statistics" title if these have been requested

  44   * Display "User profile" title if it has been requested

  45   *

  46   * @todo single month: Respect locales datefmt

  47   * @todo single post: posts do no get proper checking (wether they are in the requested blog or wether their permissions match user rights,

  48   * thus the title sometimes gets displayed even when it should not. We need to pre-query the ItemList instead!!

  49   * @todo make it complete with all possible params!

  50   *

  51   * @param array params

  52   */
  53  function request_title( $params = array() )
  54  {
  55      global $MainList, $preview, $disp;
  56  
  57      $r = array();
  58  
  59      $params = array_merge( array(
  60              'auto_pilot'          => 'none',
  61              'title_before'        => '',
  62              'title_after'         => '',
  63              'title_none'          => '',
  64              'title_single_disp'   => true,
  65              'title_single_before' => '#',
  66              'title_single_after'  => '#',
  67              'title_page_disp'     => true,
  68              'title_page_before'   => '#',
  69              'title_page_after'    => '#',
  70              'glue'                => ' - ',
  71              'format'              => 'htmlbody',
  72              'arcdir_text'         => T_('Archive directory'),
  73              'catdir_text'         => T_('Category directory'),
  74          ), $params );
  75  
  76      if( $params['auto_pilot'] == 'seo_title' )
  77      {    // We want to use the SEO title autopilot. Do overrides:
  78          global $Blog;
  79          $params['format'] = 'htmlhead';
  80          $params['title_after'] = $params['glue'].$Blog->get('name');
  81          $params['title_single_after'] = '';
  82          $params['title_page_after'] = '';
  83          $params['title_none'] = $Blog->dget('name','htmlhead');
  84      }
  85  
  86  
  87      $before = $params['title_before'];
  88      $after = $params['title_after'];
  89  
  90      switch( $disp )
  91      {
  92          case 'arcdir':
  93              // We are requesting the archive directory:

  94              $r[] = $params['arcdir_text'];
  95              break;
  96  
  97          case 'catdir':
  98              // We are requesting the archive directory:

  99              $r[] = $params['catdir_text'];
 100              break;
 101  
 102          case 'comments':
 103              // We are requesting the latest comments:

 104              global $Item;
 105              if( isset( $Item ) )
 106              {
 107                  $r[] = sprintf( /* TRANS: %s is an item title */ T_('Latest comments on %s'), $Item->get('title') );
 108              }
 109              else
 110              {
 111                  $r[] = T_('Latest comments');
 112              }
 113              break;
 114  
 115          case 'feedback-popup':
 116              // We are requesting the comments on a specific post:

 117              // Should be in first position

 118              $Item = & $MainList->get_by_idx( 0 );
 119              $r[] = sprintf( /* TRANS: %s is an item title */ T_('Feedback on %s'), $Item->get('title') );
 120              break;
 121  
 122          case 'profile':
 123              // We are requesting the user profile:

 124              $r[] = T_('User profile');
 125              break;
 126  
 127          case 'subs':
 128              // We are requesting the subscriptions screen:

 129              $r[] = T_('Subscriptions');
 130              break;
 131  
 132          case 'msgform':
 133              // We are requesting the message form:

 134              $r[] = T_('Send an email message');
 135              break;
 136  
 137          case 'single':
 138          case 'page':
 139              // We are displaying a single message:

 140              if( $preview )
 141              {    // We are requesting a post preview:
 142                  $r[] = T_('PREVIEW');
 143              }
 144              elseif( $params['title_'.$disp.'_disp'] && isset( $MainList ) )
 145              {
 146                  $r = array_merge( $r, $MainList->get_filter_titles( array( 'visibility', 'hide_future' ), $params ) );
 147              }
 148              if( $params['title_'.$disp.'_before'] != '#' )
 149              {
 150                  $before = $params['title_'.$disp.'_before'];
 151              }
 152              if( $params['title_'.$disp.'_after'] != '#' )
 153              {
 154                  $after = $params['title_'.$disp.'_after'];
 155              }
 156              break;
 157  
 158          default:
 159              if( isset( $MainList ) )
 160              {
 161                  $r = array_merge( $r, $MainList->get_filter_titles( array( 'visibility', 'hide_future' ), $params ) );
 162              }
 163              break;
 164      }
 165  
 166  
 167      if( ! empty( $r ) )
 168      {
 169          $r = implode( $params['glue'], $r );
 170          $r = $before.format_to_output( $r, $params['format'] ).$after;
 171      }
 172      elseif( !empty( $params['title_none'] ) )
 173      {
 174          $r = $params['title_none'];
 175      }
 176  
 177      if( !empty( $r ) )
 178      { // We have something to display:
 179          echo $r;
 180      }
 181  
 182  }
 183  
 184  
 185  /**

 186   * Robots tag

 187   *

 188   * Outputs the robots meta tag if necessary

 189   */
 190  function robots_tag()
 191  {
 192      global $robots_index, $robots_follow;
 193  
 194      if( is_null($robots_index) && is_null($robots_follow) )
 195      {
 196          return;
 197      }
 198  
 199      $r = '<meta name="robots" content="';
 200  
 201      if( $robots_index === false )
 202       $r .= 'NOINDEX';
 203      else
 204       $r .= 'INDEX';
 205  
 206      $r .= ',';
 207  
 208      if( $robots_follow === false )
 209       $r .= 'NOFOLLOW';
 210      else
 211       $r .= 'FOLLOW';
 212  
 213      $r .= '" />'."\n";
 214  
 215      echo $r;
 216  }
 217  
 218  
 219  /**

 220   * Output a link to current blog.

 221   *

 222   * We need this function because if no Blog is currently active (some admin pages or site pages)

 223   * then we'll go to the general home.

 224   */
 225  function blog_home_link( $before = '', $after = '', $blog_text = 'Blog', $home_text = 'Home' )
 226  {
 227      global $Blog, $baseurl;
 228  
 229      if( !empty( $Blog ) )
 230      {
 231        echo $before.'<a href="'.$Blog->get( 'url' ).'">'.$blog_text.'</a>'.$after;
 232      }
 233      elseif( !empty($home_text) )
 234      {
 235        echo $before.'<a href="'.$baseurl.'">'.$home_text.'</a>'.$after;
 236      }
 237  }
 238  
 239  
 240  
 241  /**

 242   * Memorize that a specific javascript file will be required by the current page.

 243   * All requested files will be included in the page head only once (when headlines is called)

 244   *

 245   * Accepts absolute urls, filenames relative to the rsc/js directory and certain aliases, like 'jquery' and 'jquery_debug'

 246   * If 'jquery' is used and $debug is set to true, the 'jquery_debug' is automatically swapped in.

 247   * Any javascript added to the page is also added to the $required_js array, which is then checked to prevent adding the same code twice

 248   *

 249   * @param string alias, url or filename (relative to rsc/js) for javascript file

 250   * @param boolean relative_to_base.  False (default) if the file is in the rsc/js folder.  True to make it relative

 251   */
 252  function require_js( $js_file, $relative_to_base = FALSE )
 253  {
 254    global $required_js, $rsc_url, $debug;
 255    
 256    $js_aliases = array(
 257      '#jquery#' => 'jquery.min.js',
 258      '#jquery_debug#' => 'jquery.js',
 259      );
 260      
 261    // First get the real filename or url

 262    $absolute = FALSE;
 263    if( stristr( $js_file, 'http://' ) )
 264    { // It's an absolute url
 265      $js_url = $js_file;
 266      $absolute = TRUE;
 267    }
 268    elseif( !empty( $js_aliases[$js_file]) )
 269    { // It's an alias
 270      if ( $js_file == '#jquery#' and $debug ) $js_file = '#jquery_debug#';
 271      $js_file = $js_aliases[$js_file];
 272    }
 273    
 274    if ( $relative_to_base or $absolute )
 275    {
 276      $js_url = $js_file;
 277    } 
 278    else
 279    { // Add on the $rsc_url
 280      $js_url = $rsc_url . 'js/' . $js_file;
 281    }
 282  
 283    // Then check to see if it has already been added

 284    if ( empty( $required_js ) or !in_array( strtolower( $js_url ), $required_js ) )
 285    { // Not required before, add it to the array, so the next plugin won't add it again
 286          $start_script_tag = '<script type="text/javascript" src="';
 287          $end_script_tag = '"></script>';
 288          add_headline( $start_script_tag . $js_url . $end_script_tag );
 289      $required_js[] = $js_url;
 290    }
 291    
 292  }
 293  
 294  /**

 295   * Memorize that a specific css that file will be required by the current page.

 296   * All requested files will be included in the page head only once (when headlines is called)

 297   *

 298   * Accepts absolute urls, filenames relative to the rsc/css directory.  Set $relative_to_base to TRUE to prevent this function from adding on the rsc_path

 299   *

 300   * @param string alias, url or filename (relative to rsc/js) for javascript file

 301   * @param boolean relative_to_base.  False (default) if the file is in the rsc/css folder.  True to make it relative

 302   * @param string title.  The title for the link tag

 303   * @param string media.  ie, 'print'

 304   */
 305  function require_css( $css_file, $relative_to_base = FALSE, $title = NULL, $media = NULL )
 306  {
 307    global $required_css, $rsc_url, $debug;
 308    
 309    $css_aliases = array();
 310      
 311    // First get the real filename or url

 312    $absolute = FALSE;
 313    if( stristr( $css_file, 'http://' ) )
 314    { // It's an absolute url
 315      $css_url = $css_file;
 316      $absolute = TRUE;
 317    }
 318    elseif( !empty( $css_aliases[$css_file]) )
 319    { // It's an alias
 320      $css_url = $css_aliases[$css_file];
 321    }
 322   
 323    if ( $relative_to_base or $absolute )
 324    {
 325      $css_url = $css_file;
 326    }
 327    else
 328    { // The add on the $rsc_url
 329      $css_url = $rsc_url . 'css/' . $css_file;
 330    }
 331  
 332    // Then check to see if it has already been added

 333    if ( empty( $required_css ) or !in_array( strtolower( $css_url ), $required_css ) )
 334    { // Not required before, add it to the array, so it won't be added again
 335          $start_link_tag = '<link rel="stylesheet"';
 336          if ( !empty( $title ) ) $start_link_tag .= ' title="' . $title . '"';
 337          if ( !empty( $media ) ) $start_link_tag .= ' media="' . $media . '"';
 338          $start_link_tag .= ' type="text/css" href="';
 339          $end_link_tag = '" />';
 340          add_headline( $start_link_tag . $css_url . $end_link_tag );
 341      $required_css[] = $css_url;
 342    }
 343    
 344  }
 345  
 346  
 347  /**

 348   *

 349   */
 350  function add_headline($headline)
 351  {
 352    global $headlines;
 353    $headlines[] = $headline;
 354  }
 355  
 356  
 357  /**

 358   *

 359   */
 360  function include_headlines()
 361  {
 362    global $headlines;
 363    $r = implode( "\n\t", $headlines )."\n\t";
 364    echo $r;
 365  }
 366  
 367  
 368  /**

 369   * Template tag.

 370   */
 371  function app_version()
 372  {
 373      global $app_version;
 374      echo $app_version;
 375  }
 376  
 377  
 378  /**

 379   * Stub: Links to previous and next post in single post mode

 380   */
 381  function item_prevnext_links( $params = array() )
 382  {
 383      global $MainList;
 384  
 385      if( isset($MainList) )
 386      {
 387          $MainList->prevnext_item_links( $params );
 388      }
 389  }
 390  
 391  
 392  /**

 393   * Stub

 394   */
 395  function messages( $params = array() )
 396  {
 397      global $Messages;
 398  
 399      $Messages->disp( $params['block_start'], $params['block_end'] );
 400  }
 401  
 402  
 403  /**

 404   * Stub: Links to list pages:

 405   */
 406  function mainlist_page_links( $params = array() )
 407  {
 408      global $MainList;
 409  
 410      if( isset($MainList) )
 411      {
 412          $MainList->page_links( $params );
 413      }
 414  }
 415  
 416  
 417  /**

 418   * Stub

 419   *

 420   * @return Item

 421   */
 422  function & mainlist_get_item()
 423  {
 424      global $MainList;
 425  
 426      if( isset($MainList) )
 427      {
 428          return $MainList->get_item();
 429      }
 430  
 431      $r = NULL;
 432      return $r;
 433  }
 434  
 435  
 436  /**

 437   * Stub

 438   *

 439   * @return boolean true if empty MainList

 440   */
 441  function display_if_empty( $params = array() )
 442  {
 443      global $MainList;
 444  
 445      if( isset($MainList) )
 446      {
 447          return $MainList->display_if_empty( $params );
 448      }
 449  
 450      return NULL;
 451  }
 452  
 453  
 454  /**

 455   * Template tag

 456   */
 457  function credits( $params = array() )
 458  {
 459      global $credit_links;
 460  
 461      // Make sure we are not missing any param:

 462      $params = array_merge( array(
 463              'list_start'  => ' ',
 464              'list_end'    => ' ',
 465              'item_start'  => ' ',
 466              'item_end'    => ' ',
 467              'separator'   => ',',
 468              'after_item'  => '#',
 469          ), $params );
 470  
 471      display_list( $credit_links, $params['list_start'], $params['list_end'], $params['separator'], $params['item_start'], $params['item_end'] );
 472  }
 473  
 474  /*

 475   * $Log: _template.funcs.php,v $

 476   * Revision 1.11  2007/11/03 23:54:39  fplanque

 477   * skin cleanup continued

 478   *

 479   * Revision 1.10  2007/11/03 21:04:25  fplanque

 480   * skin cleanup

 481   *

 482   * Revision 1.9  2007/10/01 01:06:31  fplanque

 483   * Skin/template functions cleanup.

 484   *

 485   * Revision 1.8  2007/09/30 04:55:34  fplanque

 486   * request_title() cleanup

 487   *

 488   * Revision 1.7  2007/09/28 09:28:36  fplanque

 489   * per blog advanced SEO settings

 490   *

 491   * Revision 1.6  2007/09/23 18:55:17  fplanque

 492   * attempting to debloat. The Log class is insane.

 493   *

 494   * Revision 1.5  2007/09/13 23:39:50  blueyed

 495   * trans: use printf

 496   *

 497   * Revision 1.4  2007/08/05 17:23:33  waltercruz

 498   * Feed of the comments on a specific post. Just add the &id=? or &title=? to the URL

 499   *

 500   * Revision 1.3  2007/07/01 03:57:20  fplanque

 501   * toolbar eveywhere

 502   *

 503   * Revision 1.2  2007/06/30 22:03:34  fplanque

 504   * cleanup

 505   *

 506   * Revision 1.1  2007/06/25 10:58:53  fplanque

 507   * MODULES (refactored MVC)

 508   *

 509   * Revision 1.30  2007/06/24 20:19:00  personman2

 510   * Don't add .js or .css on when they're not there.  Added documentation for require_css

 511   *

 512   * Revision 1.29  2007/06/24 19:43:39  personman2

 513   * changing backoffice over to new js and css handling

 514   *

 515   * Revision 1.26  2007/06/24 01:05:31  fplanque

 516   * skin_include() now does all the template magic for skins 2.0.

 517   * .disp.php templates still need to be cleaned up.

 518   *

 519   * Revision 1.25  2007/06/23 00:12:26  fplanque

 520   * doc

 521   *

 522   * Revision 1.24  2007/06/22 15:44:25  personman2

 523   * Moved output of require_js() to another callback, as Daniel suggested

 524   *

 525   * Revision 1.23  2007/06/22 02:30:12  personman2

 526   * Added require_js() function to add javascript files.  Can be called from a skin or from a plugin using the SkinBeginHtmlHead hook.

 527   *

 528   * Revision 1.22  2007/05/02 20:39:27  fplanque

 529   * meta robots handling

 530   *

 531   * Revision 1.21  2007/04/26 00:11:08  fplanque

 532   * (c) 2007

 533   *

 534   * Revision 1.20  2007/03/25 10:20:02  fplanque

 535   * cleaned up archive urls

 536   *

 537   * Revision 1.19  2007/03/04 21:42:49  fplanque

 538   * category directory / albums

 539   *

 540   * Revision 1.18  2007/03/04 19:47:37  fplanque

 541   * enhanced toolbar menu

 542   *

 543   * Revision 1.17  2007/03/04 05:24:52  fplanque

 544   * some progress on the toolbar menu

 545   *

 546   * Revision 1.16  2007/01/26 04:52:53  fplanque

 547   * clean comment popups (skins 2.0)

 548   *

 549   * Revision 1.15  2007/01/25 13:41:52  fplanque

 550   * wording

 551   *

 552   * Revision 1.14  2006/12/05 00:01:15  fplanque

 553   * enhanced photoblog skin

 554   *

 555   * Revision 1.13  2006/11/24 18:27:27  blueyed

 556   * Fixed link to b2evo CVS browsing interface in file docblocks

 557   */
 558  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics