/**
 * redirect_url
 * 
 * this function translates a url into a usable request
 * (obviously this is for mod-rewrite friendly urls - if a conventional
 * url query string is provided it returns that and doesn't process further)
 * 
 * this is called by process_request() on the index page
 */
function process_url()
{
    // first check if we're using a standard query string
    if (!empty($_SERVER["QUERY_STRING"])) {
        return $_SERVER["QUERY_STRING"];
    }
    // if not start to derive the actual request
    $url_request = str_replace(WW_ROOT_SUFFIX, '', $_SERVER['REQUEST_URI']);
    $url_request = clean_start_slash($url_request);
    $url_request = clean_end_slash($url_request);
    // if nothing is requested this must be the front page
    if (empty($url_request)) {
        return false;
    }
    // break up urldata into an array
    $url_request = strtolower($url_request);
    $urldata = explode('/', $url_request);
    // theme option
    if ($urldata[0] == 'theme') {
        if (isset($urldata[1])) {
            $_SESSION['theme'] = start_slash($urldata[1]);
            header('Location: ' . WW_WEB_ROOT);
            exit;
        } elseif (isset($_SESSION['theme'])) {
            unset($_SESSION['theme']);
            header('Location: ' . WW_WEB_ROOT);
            exit;
        } else {
            header('Location: ' . WW_WEB_ROOT);
            exit;
        }
    }
    /*	
    	author, page, p, tag - can all appear at various places within the url string,
    	so we work out the parameter position and succeeding value first
    	n.b. 'page' refers to a listing page number; 'p' is an article page number
    */
    $var_pos = array('author', 'page', 'p', 'tag');
    foreach ($var_pos as $vp) {
        if (in_array($vp, $urldata)) {
            $var_key = array_search($vp, $urldata);
            $val_key = $var_key + 1;
            $var_value = $urldata[$val_key];
            // specific code for author
            if ($vp == 'author') {
                $_GET['author_url'] = $var_value;
                if (empty($urldata[2])) {
                    return $urldata;
                }
                // specific code for tag
            } elseif ($vp == 'tag') {
                $_GET['tag_url'] = $var_value;
                if (empty($urldata[2])) {
                    return $urldata;
                }
                // otherwise value must be page number
            } else {
                $var_value = (int) $var_value;
                if (!empty($var_value)) {
                    $_GET[$vp] = $var_value;
                } else {
                    show_404($urldata);
                    return $urldata;
                }
            }
        }
    }
    // does the number of GET vars already match the size of the urldata array?
    if (sizeof($urldata) == sizeof($_GET) * 2) {
        return $urldata;
    }
    /*	
    	allowed values for first position defined first_pos array - if any other value 
    	is sent then a string is assumed to be a category, while an integer is assumed to be a year
    */
    $first_pos = array('author', 'admin', 'download', 'id', 'feeds', 'feed', 'podcast', 'rss', 'rss-external', 'search', 'sitemap', 'tag');
    // now start checking for valid requests in the url string
    switch ($urldata) {
        //	redirect to admin pages (e.g. www.domain.com/admin/)
        case $urldata[0] == 'admin':
            $location = WW_REAL_WEB_ROOT . "/ww_edit/index.php";
            header('Location: ' . $location);
            exit;
            break;
            //	downloads (e.g. www.domain.com/download/mp3/sample/ OR www.domain.com/download/12/)
        //	downloads (e.g. www.domain.com/download/mp3/sample/ OR www.domain.com/download/12/)
        case $urldata[0] == 'download':
            if (!empty($urldata[2])) {
                $download_id = get_attachment_id($urldata[1], $urldata[2]);
                serve_attachment($download_id);
                // ext/filename
            } elseif (!empty($urldata[1])) {
                serve_attachment($urldata[1]);
                // id only
            }
            break;
            // feeds listing (e.g. www.domain.com/feeds/)
        // feeds listing (e.g. www.domain.com/feeds/)
        case $urldata[0] == 'feeds':
            $_GET['page_name'] = 'listing';
            $_GET['feed_listing'] = 1;
            break;
            //	article id - provides a quick way of accessing articles (e.g. www.domain.com/id/12/)
        //	article id - provides a quick way of accessing articles (e.g. www.domain.com/id/12/)
        case $urldata[0] == 'id':
            header('HTTP/1.1 302 Moved Temporarily');
            $_GET['article_id'] = (int) $urldata[1];
            break;
            //	podcast feed (e.g. www.domain.com/podcast/ OR www.domain.com/podcast/[category_url]/)
        //	podcast feed (e.g. www.domain.com/podcast/ OR www.domain.com/podcast/[category_url]/)
        case $urldata[0] == 'podcast':
            $_GET['feed'] = 'podcast';
            $_GET['page_name'] = 'feed';
            if (!empty($urldata[1])) {
                $_GET['category_url'] = $urldata[1];
            }
            break;
            //	redirect to rss feeds, check for additional parameters
            /*		e.g. www.domain.com/rss/
            					e.g. www.domain.com/feed/author/[author_url]
            					e.g. www.domain.com/rss/tag/[tag_url]
            					e.g. www.domain.com/rss/[category_url]
            					e.g. www.domain.com/rss/comments/[article_id - optional]
            					e.g. www.domain.com/rss-external/GET/param
            			*/
        //	redirect to rss feeds, check for additional parameters
        /*		e.g. www.domain.com/rss/
        					e.g. www.domain.com/feed/author/[author_url]
        					e.g. www.domain.com/rss/tag/[tag_url]
        					e.g. www.domain.com/rss/[category_url]
        					e.g. www.domain.com/rss/comments/[article_id - optional]
        					e.g. www.domain.com/rss-external/GET/param
        			*/
        case $urldata[0] == 'rss':
        case $urldata[0] == 'feed':
            if (!empty($feed_url)) {
                // redirect the main feed (i.e. no url parameters) if feed_url is specified
                header('HTTP/1.1 302 Moved Temporarily');
                header('Location: ' . $feed_url);
            }
            // but keep rss-external URLs on site permanently
        // but keep rss-external URLs on site permanently
        case $urldata[0] == 'rss-external':
            $_GET['page_name'] = 'feed';
            $_GET['feed'] = 'articles';
            // for comments
            if (!empty($urldata[1])) {
                if ($urldata[1] == 'comments') {
                    // defaults to all comments
                    $_GET['feed'] = 'comments';
                    // unless an article id is sent
                    if (!empty($urldata[2])) {
                        $_GET['article_id'] = (int) $urldata[2];
                        // article ID for comments
                    }
                    // for category (author or tag would have been picked up already
                } elseif (empty($urldata[2])) {
                    // other option is a category url
                    $_GET['category_url'] = $urldata[1];
                }
            }
            break;
            // redirect for searches (e.g. www.domain.com/search/[search term])
        // redirect for searches (e.g. www.domain.com/search/[search term])
        case $urldata[0] == 'search':
            $_GET['search'] = $urldata[1];
            break;
            // redirect to sitemap
            /* 
            	sitemap.xml is redirected in .htaccess but this line allows use to use
            	www.domain.com/sitemap/ as well
            */
        // redirect to sitemap
        /* 
        	sitemap.xml is redirected in .htaccess but this line allows use to use
        	www.domain.com/sitemap/ as well
        */
        case $urldata[0] == 'sitemap':
            include WW_ROOT . '/ww_view/sitemap-xml.php';
            exit;
            break;
            // translate months, years, days, permatitled posts
        // translate months, years, days, permatitled posts
        case $urldata[0] > '1900' && $urldata[0] < '2056':
            $_GET['year'] = $urldata[0];
            // if we find a year, let's also check for month
            if (!empty($urldata[1]) && ($urldata[1] >= '01' && $urldata[1] <= '12')) {
                $_GET['month'] = $urldata[1];
                // now check for day
                if (!empty($urldata[2]) && ($urldata[2] >= '01' && $urldata[2] <= '31')) {
                    $_GET['day'] = $urldata[2];
                    // check for a title
                    if (!empty($urldata[3])) {
                        $_GET['article_url'] = $urldata[3];
                    }
                }
            }
            break;
            // our final option is a category
        // our final option is a category
        case !in_array($urldata[0], $first_pos):
            $category_url = $urldata[0];
            $_GET['category_url'] = $category_url;
            $allowed_after = array('author', 'page', 'tag');
            if (!empty($urldata[1]) && !in_array($urldata[1], $allowed_after)) {
                $_GET['article_url'] = $urldata[1];
            }
            break;
            // if nothing matches then 404 it
        // if nothing matches then 404 it
        default:
            show_404($urldata);
            return false;
            break;
    }
    return $urldata;
}
Ejemplo n.º 2
0
/**
 * get_server_path
 * 
 * returns the server path to the bouncer folder
 * this function is designed to return a value for the BOUNCE_ROOT constant
 * however, to make it portable the line used to strip the _scripts folder name
 * has been made optional
 * 
 * @param 	string	$file_path - usually provided by __FILE__
 * @param 	bool	$strip_folder	set to true/on by default, simply strips the
 * 									_scripts foldername, but can be disabled
 */
function get_server_path($file_path, $strip_folder = 1)
{
    $this_path = dirname($file_path);
    // strip filename from provided path
    $this_dir = !empty($strip_folder) ? basename($this_path) : "";
    // get the current directory name
    $server_path = str_replace($this_dir, '', $this_path);
    // remove $this_dir from $this_path
    $server_path = clean_end_slash($server_path);
    // clean path name
    return $server_path;
}
define('WW_LAST_SESS', 'last_sess');
// user last session field
/*-------------------------------------------------------------------------------------------------------*/
// you should not need to edit below this line
include_once 'bouncer_functions.php';
// get the server path to this file - use the __FILE__ constant to ensure the path remains, well, constant
$bounce_root = clean_end_slash($set_bounce_root);
define('WW_BOUNCE_ROOT', $bounce_root);
// check we got the root correct
if (constant('WW_BOUNCE_ROOT') . "/_scripts/bouncer_params.php" != __FILE__) {
    echo "WARNING: Bouncer configuration error:<br/>";
    echo "set_bounce_root needs to be manually configured in bouncer_params.php<br/>";
    exit;
}
// now get the web path
$bounce_html_root = clean_end_slash($set_bounce_html_root);
define('WW_BOUNCE_WEB_ROOT', $bounce_html_root);
// there's no way of checking the html_root automatically, but if css files aren't loading
// then that's a fairly good sign that things have gone awry...
$bouncer_page = array();
// page locations - for redirecting users
$bouncer_page['password_change'] = WW_REAL_WEB_ROOT . '/ww_edit/admin.php?changepass';
$bouncer_page['password_forgot'] = WW_REAL_WEB_ROOT . '/ww_edit/admin.php?forgotpass';
if (isset($_POST['email'])) {
    $bouncer_page['password_forgot'] .= '&amp;email=' . $_POST['email'];
}
// optional pages - must be designed by user
$bouncer_page['signup'] = '';
$bouncer_page['renewal'] = '';
// user messages
$bouncer_message = array();