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