XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
function.xoops_link.php
Go to the documentation of this file.
1 <?php
2 // $Id: function.xoops_link.php 8066 2011-11-06 05:09:33Z beckmi $
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 {
53  $urlstr = '';
54  if (isset($params['urlvars'])) {
55  $szvars = explode('&', $params['urlvars']);
56  $vars = array();
57  // Split the string making an array from the ('name','value') pairs
58  foreach ($szvars as $szvar) {
59  $pos = strpos($szvar, '=');
60  if ($pos != false) { // If a value is specified, use it
61  $vars[] = array('name' => substr($szvar, 0, $pos), 'value' => substr($szvar, $pos + 1));
62  } else { // Otherwise use current one (if any)
63  if (isset($_POST[$szvar])) {
64  $vars[] = array('name' => $szvar, 'value' => $_POST[$szvar]);
65  } elseif ( isset($_GET[$szvar]) ) {
66  $vars[] = array('name' => $szvar, 'value' => $_GET[$szvar]);
67  }
68  }
69  }
70  // Now reconstruct query string from specified variables
71  foreach ($vars as $var) {
72  $urlstr = "$urlstr&{$var['name']}={$var['value']}";
73  }
74  if (strlen($urlstr) > 0) {
75  $urlstr = '?' . substr($urlstr, 1);
76  }
77  }
78 
79  // Get default module/page from current ones if necessary
80  $module = '';
81  $page = '';
82  if (!isset($params['module'])) {
83  if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) {
84  $module = $GLOBALS['xoopsModule']->getVar('dirname');
85  }
86  } else {
87  $module = $params['module'];
88  }
89  if (!isset($params['page'])) {
90  $cur = $_SERVER['PHP_SELF'];
91  $page = substr($cur, strrpos($cur, '/') + 1);
92  } else {
93  $page = $params['page'];
94  }
95  // Now, return entire link URL :-)
96  if (empty($module)) {
97  echo XOOPS_URL . "/{$page}" . $urlstr;
98  } else {
99  echo XOOPS_URL . "/modules/{$module}/{$page}" . $urlstr;
100  }
101 }
102 
103 ?>