home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / smarty / xoops_plugins / compiler.xoAppUrl.php < prev    next >
Encoding:
PHP Script  |  2006-09-04  |  3.1 KB  |  90 lines

  1. <?php
  2. /**
  3.  * xoAppUrl Smarty compiler plug-in
  4.  *
  5.  * See the enclosed file LICENSE for licensing information.
  6.  * If you did not receive this file, get it at http://www.fsf.org/copyleft/gpl.html
  7.  *
  8.  * @copyright   The XOOPS project http://www.xoops.org/
  9.  * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
  10.  * @author        Skalpa Keo <skalpa@xoops.org>
  11.  * @package        xos_opal
  12.  * @subpackage    xos_opal_Smarty
  13.  * @since       2.0.14
  14.  * @version        $Id: compiler.xoAppUrl.php 694 2006-09-04 11:33:22Z skalpa $
  15.  */
  16.  
  17. /**
  18.  * Inserts the URL of an application page
  19.  * 
  20.  * This plug-in allows you to generate a module location URL. It uses any URL rewriting
  21.  * mechanism and rules you'll have configured for the system.
  22.  * 
  23.  * To ensure this can be as optimized as possible, it accepts 2 modes of operation:
  24.  * 
  25.  * <b>Static address generation</b>:<br>
  26.  * This is the default mode and fastest mode. When used, the URL is generated during
  27.  * the template compilation, and statically written in the compiled template file.
  28.  * To use it, you just need to provide a location in a format XOOPS understands.
  29.  * 
  30.  * <code>
  31.  * // Generate an URL using a physical path
  32.  * ([xoAppUrl modules/something/yourpage.php])
  33.  * // Generate an URL using a module+location identifier (2.3+)
  34.  * ([xoAppUrl mod_xoops_Identification#logout])
  35.  * </code>
  36.  * 
  37.  * <b>Dynamic address generation</b>:<br>
  38.  * The is the slowest mode, and its use should be prevented unless necessary. Here,
  39.  * the URL is generated dynamically each time the template is displayed, thus allowing
  40.  * you to use the value of a template variable in the location string. To use it, you
  41.  * must surround your location with double-quotes ("), and use the
  42.  * {@link http://smarty.php.net/manual/en/language.syntax.quotes.php Smarty quoted strings}
  43.  * syntax to insert variables values.
  44.  * 
  45.  * <code>
  46.  * // Use the value of the $sortby template variable in the URL
  47.  * ([xoAppUrl "modules/something/yourpage.php?order=`$sortby`"])
  48.  * </code>
  49.  */
  50. function smarty_compiler_xoAppUrl( $argStr, &$compiler ) {
  51.     global $xoops;
  52.     $argStr = trim( $argStr );
  53.     
  54.     @list( $url, $params ) = explode( ' ', $argStr, 2 );
  55.     
  56.     if ( substr( $url, 0, 1 ) == '/' ) {
  57.         $url = 'www' . $url;
  58.     }
  59.     // Static URL generation
  60.     if ( strpos( $argStr, '$' ) === false && $url != '.' ) {
  61.         if ( isset($params) ) {
  62.             $params = $compiler->_parse_attrs( $params, false );
  63.             foreach ( $params as $k => $v ) {
  64.                 if ( in_array( substr( $v, 0, 1 ), array( '"', "'" ) ) ) {
  65.                     $params[$k] = substr( $v, 1, -1 );
  66.                 }
  67.             }
  68.             $url = $xoops->buildUrl( $url, $params );
  69.         }
  70.         $url = $xoops->path( $url, true );
  71.         return "echo '" . addslashes( htmlspecialchars( $url ) ) . "';";
  72.     }
  73.     // Dynamic URL generation
  74.     if ( $url == '.' ) {
  75.         $str = "\$_SERVER['REQUEST_URI']";
  76.     } else {
  77.         $str = "\$GLOBALS['xoops']->path( '$url', true )";
  78.     }
  79.     if ( isset($params) ) {
  80.         $params = $compiler->_parse_attrs( $params, false );
  81.         $str = "\$GLOBALS['xoops']->buildUrl( $str, array(\n";
  82.         foreach ( $params as $k => $v ) {
  83.             $str .= var_export( $k, true ) . " => $v,\n";
  84.         }
  85.         $str .= ") )";        
  86.     }
  87.     return "echo htmlspecialchars( $str );";
  88. }
  89.  
  90. ?>