[Bb-trac] [bbPress] #715: New bb_uri() and bb_get_uri() functions
bbPress
bb-trac at lists.bbpress.org
Wed Aug 1 01:11:53 GMT 2007
#715: New bb_uri() and bb_get_uri() functions
-------------------------+--------------------------------------------------
Reporter: sambauers | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 0.8.3 & XML-RPC
Component: Front-end | Version: 1.0-alpha (trunk)
Severity: normal | Keywords: SSL URI
-------------------------+--------------------------------------------------
I set out to build an SSL plugin and found that transforming URIs in the
template selectively was very difficult, in fact impossible.
I'm proposing that we add a `bb_uri()` and a `bb_get_uri()` function.
`bb_uri()` is (by convention) an echo of `bb_get_uri()` with a filter.
`bb_get_uri()` is passed two values, the path to the file and the context.
The path to the file is simply the path that is added to the base URI of
the bbPress site. The context is a helpful pointer that filters can use to
better understand the context within which the function is being called.
The output is passed through a filter.
example where base URI is "http://www.example.org/forum/":
{{{
$example = bb_get_uri('bb-login.php'); // default context is "href"
echo $example; // outputs "http://www.example.org/forum/bb-login.php"
}}}
This construct means that if I want to change all links to bb-login.php to
a secure address, all I have to do is this...
{{{
function addSSL($r, $file) {
if ($file == 'bb-login.php') {
$r = str_replace('http://', 'https://', $r);
}
return $r;
}
add_filter('bb_get_uri', 'addSSL');
$example = bb_get_uri('bb-login.php');
echo $example; // outputs "https://www.example.org/forum/bb-login.php"
}}}
The context parameter would allows you to narrow it down to just the URI
in form actions for bb-login.php:
{{{
function addSSL($r, $file, $context) {
if ($file == 'bb-login.php' && $context == 'action') {
$r = str_replace('http://', 'https://', $r);
}
return $r;
}
add_filter('bb_get_uri', 'addSSL', 10, 2);
$example1 = bb_get_uri('bb-login.php');
$example2 = bb_get_uri('bb-login.php', 'action');
echo $example1; // outputs "http://www.example.org/forum/bb-login.php"
echo $example2; // outputs "https://www.example.org/forum/bb-login.php"
}}}
The attached patch contains the new functioons in bb-
includes/functions.php and implements the function with some contexts
added throughout the trunk code.
Existing templates will not be affected by these changes as the functions
are built on top of the existing bb_get_option() function.
--
Ticket URL: <http://trac.bbpress.org/ticket/715>
bbPress <http://bbpress.org/>
Innovative forum development
More information about the Bb-trac
mailing list