Code: Select all
$cute_url = new cute_url_handler();
after ?
Code: Select all
$cute_url = new cute_url_handler();
Code: Select all
http://yoursite.com/cute/
Code: Select all
$cute_url = new cute_url_handler('/cute/');
Code: Select all
echo $cute_url->build(array('test', 'first', 'second'));
Code: Select all
/cute/test/first/second/
Code: Select all
echo $cute_url->build(array('test', 'first', 'second'), array('arg' => 'value'));
Code: Select all
/cute/test/first/second/?arg=value
Code: Select all
http://yoursite.com/cute/index.php/test/first/
Code: Select all
print_r($cute_url->url);
Code: Select all
Array ( [0] => index.php [1] => test [2] => first )
Code: Select all
# rewrite
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Code: Select all
http://yoursite.com/cute/test/first/
Code: Select all
Array ( [0] => test [1] => first )
Code: Select all
switch ($mode = $cute_url->get(''))
{
case 'about':
echo '<h2>About me</h2>';
echo 'Welcome to my about page. I co-founded phpbbmodders.net, a mod authors\' community, and i\'ve also created a lot of MODs. In my free time i like biking or playing the guitar. I have a very big epiphone with f-holes (like a violin).';
break;
default:
echo 'Welcome to my page! I am igor, MOD team member. Click <a href="' . $cute_url->build(array('about')) . '">here</a> for more information about me.';
break;
}
Code: Select all
include($phpbb_root_path . '_functions_cute_url.' . $phpEx);
$cute_url = new cute_url_handler('/');
/*
./
about/
about/phpbb/
about/me/
*/
echo '<br />
<a href="' . $cute_url->build(array('.')) . '">home</a><br />
<a href="' . $cute_url->build(array('about')) . '">about</a><br />
<a href="' . $cute_url->build(array('about','phpbb')) . '">about phpbb</a><br />
<a href="' . $cute_url->build(array('about','me')) . '">about me</a><br /><br />';
switch ($mode = $cute_url->get(''))
{
case 'about':
switch ($mode = $cute_url->get('about'))
{
case 'phpbb':
echo '<h2>about phpbb</h2>';
break;
case 'me':
echo '<h2>about me</h2>';
break;
default:
echo '<h2>about</h2>';
break;
}
break;
default:
echo '<h2>home page</h2>';
break;
} Â
Code: Select all
$cute_url->build(array('.'))
Code: Select all
$cute_url->build()
Code: Select all
// full url: http://test.loc/phpbb3/phpBB-3.0.2_page/about_phpbb
print_r($cute_url->url);
/*
Array
(
[0] => phpbb3 // directory 1
[1] => phpBB-3.0.2_page // directory 2
[2] => about_phpbb // fake directory
)
*/
echo $cute_url->url[2];
// about_phpbb
$page_name = $cute_url->url[2];
$sql = 'SELECT *
FROM ' . PAGE_TABLE . '
WHERE page_name = ' . $page_name . '
ORDER BY page_id DESC';
$result = $db->sql_query($sql);
Code: Select all
<?php
/**
* Breadcrumb Url Rewrites
*
* This class is used for a created "breadcrumb" style url structures
* for dynamic web applications, each "bit" or "directory" of the url
* is read in to an array inside this class and accessed via the request
* method.
*
* This class also provides a method to be used for generating an absolute
* url to where the script is located allowing for dynamic creation of absolute
* paths to the host script.
*
* @author Dean Newman < [email protected] >
* @license GNU/General Public License v2 (GPL)
* @copyright Copyright 2007, Dean Newman
*/
/**
* Crumbs Class
*
* @version 1.0.0.0-php5
* @package class_crumbs.php
*/
final class crumbs
{
const MAX_BITS = 10;
public $raw;
public $crumbs;
public function __construct()
{
/**
* Define as array to prevent errors
*/
$this->raw = array();
/**
* If the REQUEST_URI is set and not empty
*/
if ( isset ( $_SERVER['REQUEST_URI'] ) && ! empty ( $_SERVER['REQUEST_URI'] ) )
{
/**
* Slice off query strings
*/
$this->raw = $_SERVER['REQUEST_URI'] = str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']);
/**
* Seperate the sections by forward slash
*/
$this->crumbs = explode('/', $this->raw, self::MAX_BITS);
/**
* Remove the lower level directories and this file
*/
$index = array_search(basename(dirname($_SERVER['SCRIPT_NAME'])), $this->crumbs);
if ( in_array(basename($_SERVER['SCRIPT_NAME']), $this->crumbs) )
{
$index = array_search(basename($_SERVER['SCRIPT_NAME']), $this->crumbs);
}
if ( array_search ($this->raw, $this->crumbs) )
{
/**
* If the name of this file is found, remove it
*/
$index++;
}
$this->crumbs = array_slice($this->crumbs, ($index + 1));
/**
* Remove empty values
*/
foreach ( $this->crumbs AS $key => $crumb )
{
if ( empty ( $crumb ) )
{
unset($this->crumbs[$key]);
}
}
/**
* Sort the array by key
*/
ksort($this->crumbs);
/**
* Decode the special chars of the entries
*/
$this->crumbs = array_map('urldecode', $this->crumbs);
}
/**
* Return parsed url, or empty array.
*/
return $this->crumbs;
}
public function __destruct()
{
}
public function push($item)
{
$tmparray = array_merge(array($item), $this->crumbs);
return ($this->crumbs = $tmparray);
}
public function shift()
{
return array_shift($this->crumbs);
}
public function request($key = 0, $default = null, $type = null, $maxlen = null, $walk = null)
{
$return = array_key_exists($key, $this->crumbs) ? $this->crumbs[$key] : $default;
if ( $type )
{
settype($return, $type);
}
if ( $walk )
{
$return = $walk($return);
}
if ( $maxlen )
{
$return = substr($return, 0, $maxlen);
}
return $return;
}
public static function get_external_url()
{
$http = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
$host = ( isset($_SERVER['HTTP_HOST']) ) ? $_SERVER['HTTP_HOST'] : false;
$path = ( isset($_SERVER['SCRIPT_NAME']) ) ? dirname($_SERVER['SCRIPT_NAME']) : false;
if ( substr($path, strlen($path) - 1) == '/' )
{
$path = substr($path, 0, strlen($path) - 2);
}
if ( strstr($_SERVER['SERVER_SOFTWARE'], 'IIS') )
{
$path .= '/' . basename($_SERVER['SCRIPT_NAME']);
}
return ($http . $host . $path);
}
}
?>
Code: Select all
<?php
/**
*
* @package phpbbmodders_site
* @version $Id: hook_fix_url.php 237 2008-01-14 18:43:22Z evil3 $
* @copyright (c) 2007 phpbbmodders
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Hook for $template->display()
* will fix urls of the site so they point to phpbb
*/
function template_display_fix_url(&$hook, $handle, $include_once = true)
{
global $template;
// Get possible previous results (and ignore them)
$result = $hook->previous_hook_result(array('template', 'display'));
// no idea what to do with this...
if (!empty($result))
{
$result['result'];
}
ob_start();
$template->display($handle, $include_once);
$output = ob_get_clean();
$tags_ary = array(
'a' => 'href',
'link' => 'href',
'script' => array('src', 'type'),
'img' => 'src',
'form' => 'action',
);
foreach ($tags_ary as $tag_name => $tag_attribute)
{
$tag_name = preg_quote_pound($tag_name);
if (is_array($tag_attribute))
{
$tag_attribute = '(' . implode('|', array_map('preg_quote_pound', $tag_attribute)) . ')';
}
else
{
$tag_attribute = preg_quote_pound($tag_attribute);
}
$output = preg_replace_callback("#(<$tag_name\s$tag_attribute=\"(.+?)\"(\s|)(>|/>))#s", 'fix_url_callback', $output);
}
echo $output;
return true;
}
/**
* Callback function for fix_url
*/
function fix_url_callback($matches)
{
if (!empty($matches[1]))
{
return fix_url($matches[1]);
}
}
/**
* Fountain of Apples would like this function
* It's used for array_map, returns preg_quoted string, quoting the "pound" (#) char.
*
* @param string $string
* @return string Result
*/
function preg_quote_pound($string)
{
return preg_quote($string, '#');
}
// we only need this hook if we're in the website
if (defined('IN_WEBSITE'))
{
// so we'll have to use template->display()
$phpbb_hook->register(array('template', 'display'), 'template_display_fix_url', 'last');
}
?>
Code: Select all
/**
* Adjusts an URL from append_sid to point to the correct location (no more relative url)
*
* @param string $url The url after being run through append_sid
* @return string Adjusted URL
*/
function fix_url($url)
{
global $phpbb_root_path;
global $cute_url;
if (!empty($cute_url) && is_object($cute_url))
{
$url = str_replace($phpbb_root_path, $cute_url->url_base . 'board/', $url);
}
return $url;
}