Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/22/2008 04:20:04 AM (17 years ago)
Author:
apeatling
Message:

Brought most core functions under the bp_core_ naming convention
Added extensive function commenting for the core component.
Updated other components to support changes to core function names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-catchuri.php

    r194 r304  
    11<?php
    22/*
    3 Contributor: Chris Taylor - http://www.stillbreathing.co.uk/
    4 Modified By: Andy Peatling
     3Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
     4Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
    55*/
    66
    7 /*************************************************************
    8   Functions for catching and displaying the right template pages
    9  *************************************************************/
    10 $component_index = 0;
    11 $action_index = 1;
     7/**
     8 * bp_core_set_uri_globals()
     9 *
     10 * Analyzes the URI structure and breaks it down into parts for use in code.
     11 * The idea is that BuddyPress can use complete custom friendly URI's without the
     12 * user having to add new re-write rules.
     13 *
     14 * Future custom components would then be able to use their own custom URI structure.
     15 *
     16 * The URI's are broken down as follows:
     17 *   - VHOST: http:// andy.domain.com / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
     18 *   - NO VHOST: http:// domain.com / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
     19 *
     20 * Example:
     21 *    - http://andy.domain.com/profile/edit/group/5/
     22 *    - $current_component: string 'profile'
     23 *    - $current_action: string 'edit'
     24 *    - $action_variables: array ['group', 5]
     25 *
     26 * @package BuddyPress Core
     27 * @global $menu WordPress admin navigation array global
     28 * @global $submenu WordPress admin sub navigation array global
     29 * @global $thirdlevel BuddyPress admin third level navigation
     30 * @uses add_menu_page() WordPress function to add a new top level admin navigation tab
     31 */
     32function bp_core_set_uri_globals() {
     33    global $current_component, $current_action, $action_variables;
     34   
     35    /* Set the indexes, these are incresed by one if we are not on a VHOST install */
     36    $component_index = 0;
     37    $action_index = 1;
    1238
    13 if ( VHOST == 'no' ) {
    14     $component_index++;
    15     $action_index++;
     39    if ( VHOST == 'no' ) {
     40        $component_index++;
     41        $action_index++;
     42    }
     43
     44    /* Fetch the current URI and explode each part seperated by '/' into an array */
     45    $bp_uri = explode( "/", $_SERVER['REQUEST_URI'] );
     46
     47    /* Take empties off the end */
     48    if ( $bp_uri[count($bp_uri) - 1] == "" )
     49        array_pop( $bp_uri );
     50
     51    /* Take empties off the start */
     52    if ( $bp_uri[0] == "" )
     53        array_shift( $bp_uri );
     54
     55    /* Get total URI segment count */
     56    $bp_uri_count = count( $bp_uri ) - 1;
     57   
     58    /* Set the current component */
     59    $current_component = $bp_uri[$component_index];
     60   
     61    /* Set the current action */
     62    $current_action = $bp_uri[$action_index];
     63
     64    /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
     65    $action_variables = $bp_uri;
     66
     67    /* Remove the username from action variables if this is not a VHOST install */
     68    if ( VHOST == 'no' )
     69        unset($action_variables[0]);
     70
     71    /* Unset the current_component and action from action_variables */
     72    unset($action_variables[$component_index]);
     73    unset($action_variables[$action_index]);
     74   
     75    /* Reset the keys by merging with an empty array */
     76    $action_variables = array_merge( array(), $action_variables );
     77
     78    /* catch 'blog' */
     79    if ( $current_component == 'blog' )
     80        bp_catch_uri( 'blog' );
    1681}
     82add_action( 'wp', 'bp_core_set_uri_globals', 0 );
    1783
    18 $bp_uri = explode( "/", $_SERVER['REQUEST_URI'] );
    19 
    20 if ( $bp_uri[count($bp_uri) - 1] == "" )
    21     array_pop( $bp_uri );
    22    
    23 if ( $bp_uri[0] == "" )
    24     array_shift( $bp_uri );
    25 
    26 $bp_uri_count = count( $bp_uri ) - 1;
    27 $current_component = $bp_uri[$component_index];
    28 $current_action = $bp_uri[$action_index];
    29 
    30 $action_variables = $bp_uri;
    31 
    32 if ( VHOST == 'no' )
    33     unset($action_variables[0]);
    34    
    35 unset($action_variables[$component_index]);
    36 unset($action_variables[$action_index]);
    37 $action_variables = array_merge( array(), $action_variables );
    38 
    39 // catch 'blog'
    40 if ( $current_component == 'blog' )
    41     bp_catch_uri( 'blog' );
    42 
    43 // is the string a guid (lowercase, - instead of spaces, a-z and 0-9 only)
    44 function bp_is_guid( $text ) {
    45     $safe = trim( strtolower( $text ) );
    46     $safe = preg_replace( "/[^-0-9a-zA-Z\s]/", '', $safe );
    47     $safe = preg_replace( "/\s+/", ' ', trim( $safe ) );
    48     $safe = str_replace( "/-+/", "-", $safe );
    49     $safe = str_replace( ' ', '-', $safe );
    50     $safe = preg_replace( "/[-]+/", "-", $safe );
    51    
    52     if ( $safe == '' )
    53         return false;
    54    
    55     return true;
    56 }
    57 
    58 // takes either a single page name or array of page names and
    59 // loads the first template file that can be found
     84/**
     85 * bp_catch_uri()
     86 *
     87 * Takes either a single page name or array of page names and
     88 * loads the first template file that can be found.
     89 *
     90 * @package BuddyPress Core
     91 * @global $bp_path BuddyPress global containing the template file names to use.
     92 * @param $pages Template file names to use.
     93 * @uses add_action() Hooks a function on to a specific action
     94 */
    6095function bp_catch_uri( $pages ) {
    6196    global $bp_path;
     
    6398    $bp_path = $pages;
    6499
    65     add_action( "template_redirect", "bp_do_catch_uri", 10, 1 );
     100    add_action( "template_redirect", "bp_core_do_catch_uri", 10, 1 );
    66101}
    67102
    68 // loads the first template that can be found
    69 function bp_do_catch_uri() {
     103/**
     104 * bp_core_do_catch_uri()
     105 *
     106 * Loads the first template file found based on the $bp_path global.
     107 *
     108 * @package BuddyPress Core
     109 * @global $bp_path BuddyPress global containing the template file names to use.
     110 */
     111function bp_core_do_catch_uri() {
    70112    global $bp_path;
    71113
Note: See TracChangeset for help on using the changeset viewer.