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 / function.xoops_link.php < prev    next >
Encoding:
PHP Script  |  2006-05-27  |  4.6 KB  |  102 lines

  1. <?php
  2. // $Id: function.xoops_link.php 506 2006-05-26 23:10:37Z skalpa $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27.  
  28. /*
  29.  * Smarty plugin
  30.  * -------------------------------------------------------------
  31.  * Type:     function
  32.  * Name:     xoops_link
  33.  * Version:  1.0
  34.  * Author:     Skalpa Keo <skalpa@xoops.org>
  35.  * Purpose:  format URL for linking to specific Xoops page
  36.  * Input:    module    = module to link to (optional, default to current module)
  37.  *           page    = page to link to (optional, default to current page)
  38.  *           params    = query string parameters (optional, default to empty)
  39.  *                    ex: urlparm1=,urlparm2,urlparm3=val3, etc.....
  40.  *                        urlparm3 value will be set to val3
  41.  *                        urlparm2 value will keep current one (no = sign)
  42.  *                        urlparm1 value will be set to empty ( = sign, but nothing after)
  43.  *
  44.  *            I.e: The template called by 'index.php?cid=5' calls this function with
  45.  *                {xoops_link page="viewcat.php" urlvars="cid,orderby=titleA"}>
  46.  *            Then the generated URL will be:
  47.  *                XOOPS_URL/modules/MODULENAME/viewcat.php?cid=5&orderby=titleA
  48.  * -------------------------------------------------------------
  49.  */
  50.  
  51. function smarty_function_xoops_link($params, $smarty) {
  52.     $urlstr='';
  53.     if (isset($params['urlvars'])) {
  54.         $szvars=explode( '&', $params['urlvars'] );
  55.         $vars=array();
  56.         // Split the string making an array from the ('name','value') pairs
  57.         foreach ($szvars as $szvar) {
  58.             $pos=strpos($szvar,'=');
  59.             if ( $pos != false ) {            // If a value is specified, use it
  60.                 $vars[] = array( 'name' => substr($szvar,0,$pos), 'value' => substr($szvar,$pos+1) );
  61.             } else {                        // Otherwise use current one (if any)
  62.                 if ( isset($_POST[$szvar]) ) {
  63.                     $vars[] = array( 'name' => $szvar, 'value' => $_POST[$szvar] );
  64.                 } elseif ( isset($_GET[$szvar]) ) {
  65.                     $vars[] = array( 'name' => $szvar, 'value' => $_GET[$szvar] );
  66.                 }
  67.             }
  68.         }
  69.         // Now reconstruct query string from specified variables
  70.         foreach ($vars as $var) {
  71.             $urlstr = "$urlstr&{$var['name']}={$var['value']}";
  72.         }
  73.         if ( strlen($urlstr) > 0 ) {
  74.             $urlstr = '?' . substr( $urlstr, 1 );
  75.         }
  76.     }
  77.  
  78.     // Get default module/page from current ones if necessary
  79.     $module='';
  80.     $page='';
  81.     if ( !isset($params['module']) ) {
  82.         if ( isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) ) {
  83.             $module = $GLOBALS['xoopsModule']->getVar('dirname');
  84.         }
  85.     } else {
  86.         $module = $params['module'];
  87.     }
  88.     if ( !isset($params['page']) ) {
  89.         $cur = $_SERVER['PHP_SELF'];
  90.         $page = substr( $cur, strrpos( $cur, '/' ) + 1 );
  91.     } else {
  92.         $page = $params['page'];
  93.     }
  94.     // Now, return entire link URL :-)
  95.     if ( empty($module) ) {
  96.         echo XOOPS_URL . "/$page" . $urlstr;
  97.     } else {
  98.         echo XOOPS_URL . "/modules/$module/$page" . $urlstr;
  99.     }
  100. }
  101.  
  102. ?>