/**
 * 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;
}
Esempio n. 2
0
<?php

// page title - if undefined the site title is displayed by default
$page_title = 'CSS Editor';
// get main data
$edit_theme = isset($_GET['theme']) ? $_GET['theme'] : $config['site']['theme'];
$edit_theme = clean_start_slash($edit_theme);
$file = isset($_GET['file']) ? $_GET['file'] : '';
$theme_dir = WW_ROOT . '/ww_view/themes/' . $edit_theme . '/';
$file_path = $theme_dir . $file;
if (isset($_GET['create_file'])) {
    $file_path = $theme_dir . $_GET['create_file'];
}
// process post actions
// create backup
if (isset($_POST['backup_file']) && $_POST['backup_file'] == 'backup') {
    $pathinfo = pathinfo($file_path);
    $filename = $pathinfo['filename'];
    $bu_filename = $filename . '-' . time();
    $backup = str_replace($filename, $bu_filename, $file_path);
    $bu_fh = fopen($backup, 'w');
    if (!$bu_fh) {
        $error = "Couldn't create file - check CHMOD permissions";
    } else {
        fclose($bu_fh);
        header('Location: ' . $url);
    }
}
// update file
if (isset($_POST['update_file']) && $_POST['update_file'] == 'update') {
    $fh = fopen($file_path, 'w');
/**
 * insert_css
 * 
 * 
 * 
 * 
 * 
 * 
 */
function insert_css($theme = '/default')
{
    // set paths
    $theme_folder = "/ww_view/themes" . $theme;
    // smartphone user - don't bother with the other stylesheets
    /*
    if(detect_smartphone() == true) {
    	
    	if (file_exists(WW_ROOT.$theme_folder.'/iphone.css')) {
    		$css = '
    	<link rel="stylesheet" media="screen" type="text/css" href="'.WW_REAL_WEB_ROOT.$theme_folder.'/iphone.css" />
    	<meta name="viewport" content="width=device-width" />'."\n";
    	} else {
    		$css = '
    	<link rel="stylesheet" media="screen" type="text/css" href="'.WW_REAL_WEB_ROOT.'/ww_view/themes/default/iphone.css" />
    	<meta name="viewport" content="width=device-width" />'."\n";			
    	}
    	return $css;
    }
    */
    $css = '
	<!-- css -->';
    // build path, with parameters, to compiled css file
    $stylesheet_path = WW_REAL_WEB_ROOT . '/ww_view/css.php?theme=' . clean_start_slash($theme);
    // if a dedicated 'page name' css file exists
    if (file_exists(WW_ROOT . $theme_folder . '/' . $_GET['page_name'] . '.css')) {
        $stylesheet_path .= '&amp;page_name=' . $_GET['page_name'];
    }
    // if a dedicated category css file exists
    if (isset($_GET['category_url']) && file_exists(WW_ROOT . $theme_folder . '/' . $_GET['category_url'] . '.css')) {
        $stylesheet_path .= '&amp;category_url=' . $_GET['category_url'];
    }
    // build css link
    $css .= '
	<link rel="stylesheet" type="text/css" href="' . $stylesheet_path . '" />' . "\n";
    // IE 7 fixes
    if (file_exists(WW_ROOT . $theme_folder . '/ie7.css')) {
        $css .= '
	<!--[if IE 7]>
	<link rel="stylesheet" type="text/css" href="' . WW_REAL_WEB_ROOT . $theme_folder . '/ie7.css" />
	<![endif]-->' . "\n";
    }
    // other IE fixes
    if (file_exists(WW_ROOT . $theme_folder . '/ie6.css')) {
        $css .= '
	<!--[if lt IE 7]>
	<link rel="stylesheet" type="text/css" href="' . WW_REAL_WEB_ROOT . $theme_folder . '/ie6.css" />
	<![endif]-->' . "\n";
    }
    // print
    if (file_exists(WW_ROOT . $theme_folder . '/print.css')) {
        $css .= '
	<link rel="stylesheet" media="print" type="text/css" href="' . WW_REAL_WEB_ROOT . $theme_folder . '/print.css" />' . "\n";
    }
    /*
    // pda
    if (file_exists(WW_ROOT.$theme_folder.'/pda.css')) {
    	$css .= '
    <link rel="stylesheet" media="handheld" type="text/css" href="'.WW_REAL_WEB_ROOT.$theme_folder.'/pda.css" />'."\n";
    }
    */
    return $css;
}