XOOPS
2.6.0
Main Page
Related Pages
Classes
Files
Examples
File List
File Members
function.xoops_link.php
Go to the documentation of this file.
1
<?php
2
// $Id$
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
$xoops
=
Xoops::getInstance
();
54
$urlstr =
''
;
55
if
(isset($params[
'urlvars'
])) {
56
$szvars = explode(
'&'
, $params[
'urlvars'
]);
57
$vars = array();
58
// Split the string making an array from the ('name','value') pairs
59
foreach
($szvars as $szvar) {
60
$pos = strpos($szvar,
'='
);
61
if
($pos !=
false
) {
// If a value is specified, use it
62
$vars[] = array(
'name'
=> substr($szvar, 0, $pos),
'value'
=> substr($szvar, $pos + 1));
63
}
else
{
// Otherwise use current one (if any)
64
if
(isset($_POST[$szvar])) {
65
$vars[] = array(
'name'
=> $szvar,
'value'
=> $_POST[$szvar]);
66
} elseif (isset($_GET[$szvar])) {
67
$vars[] = array(
'name'
=> $szvar,
'value'
=> $_GET[$szvar]);
68
}
69
}
70
}
71
// Now reconstruct query string from specified variables
72
foreach
($vars as
$var
) {
73
$urlstr =
"$urlstr&{$var['name']}={$var['value']}"
;
74
}
75
if
(strlen($urlstr) > 0) {
76
$urlstr =
'?'
. substr($urlstr, 1);
77
}
78
}
79
80
// Get default module/page from current ones if necessary
81
$module
=
''
;
82
if
(!isset($params[
'module'
])) {
83
if
(
$xoops
->isModule()) {
84
$module
=
$xoops
->module->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
}
Xoops\getInstance
static getInstance()
Definition:
Xoops.php:160
$page
$page
Definition:
help.php:31
$_SERVER
$_SERVER['REQUEST_URI']
Definition:
comment_delete.php:23
smarty_function_xoops_link
smarty_function_xoops_link($params, &$smarty)
Definition:
function.xoops_link.php:51
$xoops
$xoops
Definition:
admin.php:25
$module
$module
Definition:
main.php:52
$var
$var
Definition:
userinfo.php:125
usr64
htdocs
xoops_lib
smarty
xoops_plugins
function.xoops_link.php
Generated on Fri May 22 2015 03:07:04 for XOOPS by
1.8.9.1