|
From: FlorinCB <ory...@us...> - 2008-08-28 18:51:00
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26537 Modified Files: Tag: core28x mx_functions_phpbb.php Log Message: this is required by modules. Index: mx_functions_phpbb.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/Attic/mx_functions_phpbb.php,v retrieving revision 1.32.2.17 retrieving revision 1.32.2.18 diff -C2 -d -r1.32.2.17 -r1.32.2.18 *** mx_functions_phpbb.php 27 Mar 2008 14:10:01 -0000 1.32.2.17 --- mx_functions_phpbb.php 28 Aug 2008 18:50:56 -0000 1.32.2.18 *************** *** 519,522 **** --- 519,627 ---- /** + * Append session id to url + * + * @param string $url The url the session id needs to be appended to (can have params) + * @param mixed $params String or array of additional url parameters + * @param bool $is_amp Is url using & (true) or & (false) + * @param string $session_id Possibility to use a custom session id instead of the global one + * + * Examples: + * <code> + * mx_append_sid("{$phpbb_root_path}viewtopic.$phpEx?t=1&f=2", false, true); + * mx_append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=1&f=2', true); + * mx_append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=1&f=2', false); + * mx_append_sid("{$phpbb_root_path}viewtopic.$phpEx", array('t' => 1, 'f' => 2)); + * </code> + */ + function mx3_append_sid($url, $params = false, $is_amp = true, $session_id = false, $mod_rewrite_only = false) + { + global $SID, $_EXTRA_URL, $portal_config, $mx_mod_rewrite; + + // Assign sid if session id is not specified + if ($session_id === false) + { + $session_id = $SID; + } + + if ( is_array($session_id) ) + { + $session_id = $userdata['session_id']; + } + + $amp_delim = ($is_amp) ? '&' : '&'; + $url_delim = (strpos($url, '?') === false) ? '?' : $amp_delim; + + // Appending custom url parameter? + $append_url = (!empty($_EXTRA_URL)) ? implode($amp_delim, $_EXTRA_URL) : ''; + + // Is mod_rewrite enabled? If so, do some url rewrites... + if (is_object($mx_mod_rewrite)) + { + $url = $mx_mod_rewrite->encode($url); + } + + // Replaces same function in mx_sessions_phpbbx.php + if ($mod_rewrite_only) + { + return $url; + } + + $anchor = ''; + if (strpos($url, '#') !== false) + { + list($url, $anchor) = explode('#', $url, 2); + $anchor = '#' . $anchor; + } + else if (!is_array($params) && strpos($params, '#') !== false) + { + list($params, $anchor) = explode('#', $params, 2); + $anchor = '#' . $anchor; + } + + // Use the short variant if possible ;) + if ($params === false) + { + // Append session id + if (!$session_id) + { + return $url . (($append_url) ? $url_delim . $append_url : '') . $anchor; + } + else + { + return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . 'sid=' . $session_id . $anchor; + } + } + + // Build string if parameters are specified as array + if (is_array($params)) + { + $output = array(); + + foreach ($params as $key => $item) + { + if ($item === NULL) + { + continue; + } + + if ($key == '#') + { + $anchor = '#' . $item; + continue; + } + + $output[] = $key . '=' . $item; + } + + $params = implode($amp_delim, $output); + } + + // Append session id and parameters (even if they are empty) + // If parameters are empty, the developer can still append his/her parameters without caring about the delimiter + return $url . (($append_url) ? $url_delim . $append_url . $amp_delim : $url_delim) . $params . ((!$session_id) ? '' : $amp_delim . 'sid=' . $session_id) . $anchor; + } + + + /** * append_sid. * |