| 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 https://xoops.org/ | 
| 14: | * @license GNU GPL 2 or later (https://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 string[] $params | 
| 45: | * @param Smarty $smarty | 
| 46: | * | 
| 47: | * @return void | 
| 48: | */ | 
| 49: | function smarty_function_xoops_link($params, &$smarty) | 
| 50: | { | 
| 51: | $urlstr = ''; | 
| 52: | if (isset($params['urlvars'])) { | 
| 53: | $szvars = explode('&', $params['urlvars']); | 
| 54: | $vars = array(); | 
| 55: | // Split the string making an array from the ('name','value') pairs | 
| 56: | foreach ($szvars as $szvar) { | 
| 57: | $pos = strpos($szvar, '='); | 
| 58: | if ($pos != false) { // If a value is specified, use it | 
| 59: | $vars[] = array('name' => substr($szvar, 0, $pos), 'value' => substr($szvar, $pos + 1)); | 
| 60: | } else { // Otherwise, use current one (if any) | 
| 61: | if (isset($_POST[$szvar])) { | 
| 62: | $vars[] = array('name' => $szvar, 'value' => $_POST[$szvar]); | 
| 63: | } elseif (isset($_GET[$szvar])) { | 
| 64: | $vars[] = array('name' => $szvar, 'value' => $_GET[$szvar]); | 
| 65: | } | 
| 66: | } | 
| 67: | } | 
| 68: | // Now reconstruct query string from specified variables | 
| 69: | foreach ($vars as $var) { | 
| 70: | $urlstr = "$urlstr&{$var['name']}={$var['value']}"; | 
| 71: | } | 
| 72: | if (strlen($urlstr) > 0) { | 
| 73: | $urlstr = '?' . substr($urlstr, 1); | 
| 74: | } | 
| 75: | } | 
| 76: | |
| 77: | // Get default module/page from current ones if necessary | 
| 78: | $module = ''; | 
| 79: | $page = ''; | 
| 80: | if (!isset($params['module'])) { | 
| 81: | if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) { | 
| 82: | $module = $GLOBALS['xoopsModule']->getVar('dirname'); | 
| 83: | } | 
| 84: | } else { | 
| 85: | $module = $params['module']; | 
| 86: | } | 
| 87: | if (!isset($params['page'])) { | 
| 88: | $cur = $_SERVER['PHP_SELF']; | 
| 89: | $page = substr($cur, strrpos($cur, '/') + 1); | 
| 90: | } else { | 
| 91: | $page = $params['page']; | 
| 92: | } | 
| 93: | // Now, return entire link URL :-) | 
| 94: | if (empty($module)) { | 
| 95: | echo XOOPS_URL . "/{$page}" . $urlstr; | 
| 96: | } else { | 
| 97: | echo XOOPS_URL . "/modules/{$module}/{$page}" . $urlstr; | 
| 98: | } | 
| 99: | } | 
| 100: |