Skip to:
Content

bbPress.org

Opened 17 years ago

Closed 16 years ago

Last modified 15 years ago

#715 closed enhancement (fixed)

New bb_uri() and bb_get_uri() functions

Reported by: sambauers's profile sambauers Owned by: sambauers's profile sambauers
Milestone: 1.0 Priority: normal
Severity: normal Version: 1.0-rc-2
Component: Front-end Keywords: SSL URI
Cc: sambauers

Description

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.

Attachments (1)

bb_uri_patch.build912.patch (56.9 KB) - added by sambauers 17 years ago.

Download all attachments as: .zip

Change History (13)

#1 follow-up: @mdawaffe
17 years ago

  • Owner set to sambauers

This looks cool. What do you think we should do about tag links (tagpath), and theme and plugin URLs?

#2 in reply to: ↑ 1 @sambauers
17 years ago

Replying to mdawaffe:

This looks cool. What do you think we should do about tag links (tagpath), and theme and plugin URLs?

I guess we could extend it to cover a few different types of URI and then we can deprecate some of the existing bb_get_xxx_uri() functions.

We could add a "type":

$example1 = bb_get_uri(); // base URI
$example2 = bb_get_uri('bb-login.php'); // simple URI of bb-login.php page
$example3 = bb_get_uri('some user tag', 'topic_tag'); // link to tag page for "some user tag"
$example4 = bb_get_uri('kakumei', 'theme'); // link to kakumei theme directory
$example5 = bb_get_uri('some-active-plugin.php', 'plugin_dir'); // link to plugins directory (more useful than link to actual plugin)
$example6 = bb_get_uri('bb-login.php', null, 'action'); // bb-login.php in form action

etc...

But there isn't all that much value in doing that, except that filtering might become a little easier for these instances as well.

#3 @mdawaffe
17 years ago

Can we move this to 0.8.4 so we can think through all the details?

I really like the idea, but I'm not sure exactly how useful it is for plugins. You mention SSL. Does output buffering and preg_replace not suffice?

#4 @sambauers
17 years ago

  • Milestone changed from 0.8.3 & XML-RPC to 0.8.4 & WP-Taxonomy
  • Status changed from new to assigned

I don't mind moving it, I'm in no rush now.

Does output buffering and preg_replace not suffice

I don't know how well that would work with different templates (which was my main concern) or when someone added similar strings into posts.

#5 @ruzel
17 years ago

Just a note that "bb_get_option()" is already built with a switch structure and cases like "uri" and "url." Wouldn't it be more concise to add cases like "styelsheet" or "active-template-dir" rather than develop a separate function. These URL locations are, after all, things that could be set elsewhere in BBpress.

So, for instance, you need to call up an image in your template directory:
bb_get_option('active-template-dir') . "images/somfile.gif"


#6 @sambauers
17 years ago

  • Milestone changed from 0.8.4 to 0.8.5 & XML-RPC

#7 @sambauers
16 years ago

This is very similar to, but more broad in scope than, the site_url() function in WordPress.

WPs site_url() is designed to automatically determine when SSL is required based on the context it is supplied.

I'm going to go ahead with this on a slightly experimental basis and see how it feels.

#8 @sambauers
16 years ago

First pass in [1575]

#9 @sambauers
16 years ago

A few fixes in [1586]

#10 @sambauers
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Seems to be sticking as a concept. Closing.

#11 @(none)
15 years ago

  • Milestone 1.0-beta deleted

Milestone 1.0-beta deleted

#12 @sambauers
15 years ago

  • Milestone set to 1.0
Note: See TracTickets for help on using tickets.