Skip to:
Content

bbPress.org

Changeset 838


Ignore:
Timestamp:
05/29/2007 11:48:11 PM (17 years ago)
Author:
mdawaffe
Message:

deprecate bb_path_to_url(), bb_url_to_path(). BBTHEMEURL and BBPLUGINURL to match the *DIR consts. bb_get_theme_uri(), bb_get_plugin_uri() fixes #589

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-admin/themes.php

    r799 r838  
    2929function bb_admin_theme_row( $theme ) {
    3030    $theme_data = file_exists( $theme . 'style.css' ) ? bb_get_theme_data( $theme . 'style.css' ) : false;
    31     $screen_shot = file_exists( $theme . 'screenshot.png' ) ? attribute_escape( bb_path_to_url( $theme . 'screenshot.png' ) ) : false;
     31    $screen_shot = file_exists( $theme . 'screenshot.png' ) ? clean_url( bb_get_theme_uri( $theme . 'screenshot.png' ) ) : false;
    3232    $activation_url = clean_url( bb_nonce_url( add_query_arg( 'theme', urlencode($theme), bb_get_option( 'uri' ) . 'bb-admin/themes.php' ), 'switch-theme' ) );
    3333?>
  • trunk/bb-includes/deprecated.php

    r824 r838  
    297297endif;
    298298
     299// It's not omnipotent
     300function bb_path_to_url( $path ) {
     301    return apply_filters( 'bb_path_to_url', bb_convert_path_base( $path, BBPATH, bb_get_option( 'uri' ) ), $path );
     302}
     303
     304// Neither is this one
     305function bb_url_to_path( $url ) {
     306    return apply_filters( 'bb_url_to_path', bb_convert_path_base( $url, bb_get_option( 'uri' ), BBPATH ), $url );
     307}
     308
     309function bb_convert_path_base( $path, $from_base, $to_base ) {
     310    $last_char = $path{strlen($path)-1};
     311    if ( '/' != $last_char && '\\' != $last_char )
     312        $last_char = '';
     313
     314    list($from_base, $to_base) = bb_trim_common_path_right($from_base, $to_base);
     315
     316    if ( 0 === strpos( $path, $from_base ) )
     317        $r = $to_base . substr($path, strlen($from_base)) . $last_char;
     318    else
     319        return false;
     320
     321    $r = str_replace(array('//', '\\\\'), array('/', '\\'), $r);
     322    $r = preg_replace('|:/([^/])|', '://$1', $r);
     323
     324    return $r;
     325}
     326
     327function bb_trim_common_path_right( $one, $two ) {
     328    $root_one = false;
     329    $root_two = false;
     330
     331    while ( false === $root_one ) {
     332        $base_one = basename($one);
     333        $base_two = basename($two);
     334        if ( !$base_one || !$base_two )
     335            break;     
     336        if ( $base_one == $base_two ) {
     337            $one = dirname($one);
     338            $two = dirname($two);
     339        } else {
     340            $root_one = $one;
     341            $root_two = $two;
     342        }
     343    }
     344
     345    return array($root_one, $root_two);
     346}
     347
    299348?>
  • trunk/bb-includes/functions.php

    r834 r838  
    16971697}
    16981698
    1699 // It's not omnipotent
    1700 function bb_path_to_url( $path ) {
    1701     return apply_filters( 'bb_path_to_url', bb_convert_path_base( $path, BBPATH, bb_get_option( 'uri' ) ), $path );
    1702 }
    1703 
    1704 // Neither is this one
    1705 function bb_url_to_path( $url ) {
    1706     return apply_filters( 'bb_url_to_path', bb_convert_path_base( $url, bb_get_option( 'uri' ), BBPATH ), $url );
    1707 }
    1708 
    1709 function bb_convert_path_base( $path, $from_base, $to_base ) {
    1710     $last_char = $path{strlen($path)-1};
    1711     if ( '/' != $last_char && '\\' != $last_char )
    1712         $last_char = '';
    1713 
    1714     list($from_base, $to_base) = bb_trim_common_path_right($from_base, $to_base);
    1715 
    1716     if ( 0 === strpos( $path, $from_base ) )
    1717         $r = $to_base . substr($path, strlen($from_base)) . $last_char;
    1718     else
    1719         return false;
    1720 
    1721     $r = str_replace(array('//', '\\\\'), array('/', '\\'), $r);
    1722     $r = preg_replace('|:/([^/])|', '://$1', $r);
    1723 
    1724     return $r;
    1725 }
    1726 
    1727 function bb_trim_common_path_right( $one, $two ) {
    1728     $root_one = false;
    1729     $root_two = false;
    1730 
    1731     while ( false === $root_one ) {
    1732         $base_one = basename($one);
    1733         $base_two = basename($two);
    1734         if ( !$base_one || !$base_two )
    1735             break;     
    1736         if ( $base_one == $base_two ) {
    1737             $one = dirname($one);
    1738             $two = dirname($two);
    1739         } else {
    1740             $root_one = $one;
    1741             $root_two = $two;
    1742         }
    1743     }
    1744 
    1745     return array($root_one, $root_two);
    1746 }
    1747 
    17481699/* Profile/Admin */
    17491700
     
    20291980}
    20301981
     1982function bb_get_plugin_uri( $plugin = false ) {
     1983    if ( !$plugin )
     1984        $r = BBPLUGINURL;
     1985    elseif ( 0 === strpos($plugin, BBPLUGINDIR) )
     1986        $r = BBPLUGINURL . substr($plugin, strlen(BBPLUGINDIR));
     1987    else
     1988        $r = false;
     1989
     1990    return apply_filters( 'bb_get_plugin_uri', $r, $plugin );
     1991}
     1992
    20311993/* Themes / Templates */
    20321994
  • trunk/bb-includes/template-functions.php

    r836 r838  
    7070
    7171function bb_get_active_theme_uri() {
    72     return apply_filters( 'bb_get_active_theme_uri', bb_path_to_url( bb_get_active_theme_folder() ) );
     72    if ( !$active_theme = bb_get_option( 'bb_active_theme' ) )
     73        $active_theme = BBPATH . 'bb-templates/kakumei/';
     74    return apply_filters( 'bb_get_active_theme_uri', bb_get_theme_uri( $active_theme ) );
     75}
     76
     77function bb_get_theme_uri( $theme = false ) {
     78    if ( !$theme )
     79        $r = BBTHEMEURL;
     80    elseif ( 0 === strpos($theme, BBTHEMEDIR) )
     81        $r = BBTHEMEURL . substr($theme, strlen(BBTHEMEDIR));
     82    elseif ( 0 === strpos($theme, BBPATH) )
     83        $r = bb_get_option( 'uri' ) . substr($theme, strlen(BBPATH));
     84    else
     85        $r = false;
     86
     87    return apply_filters( 'bb_get_theme_uri', $r, $theme );
    7388}
    7489
  • trunk/bb-settings.php

    r835 r838  
    5858error_reporting(E_ALL ^ E_NOTICE);
    5959
     60if ( isset($bb->uri) ) {
     61    $bb->domain = preg_replace('|(?<!/)/(?!/).*$|', '', $bb->uri);
     62    $bb->path = substr($bb->uri, strlen($bb->domain));
     63} elseif ( isset($bb->path) && isset($bb->domain) ) {
     64    $bb->domain = rtrim($bb->domain, '/');
     65    $bb->path = '/' . ltrim($bb->path, '/');
     66} else {
     67    bb_die( '<code>$bb->uri</cade> must be set in your <code>config.php</code> file.' );
     68}
     69
     70foreach ( array('wp_site_url', 'wp_home', 'path') as $p )
     71    if ( isset($bb->$p) && $bb->$p )
     72        $bb->$p = rtrim($bb->$p, '/');
     73unset($p);
     74
     75$bb->path = "$bb->path/";
     76$bb->uri = $bb->domain . $bb->path;
     77
    6078define('BBINC', 'bb-includes/');
    6179if ( !defined('BBLANGDIR') )
     
    6381if ( !defined('BBPLUGINDIR') )
    6482    define('BBPLUGINDIR', BBPATH . 'my-plugins/');
     83if ( !defined('BBPLUGINURL') )
     84    define('BBPLUGINURL', $bb->uri . 'my-plugins/');
    6585if ( !defined('BBTHEMEDIR') )
    6686    define('BBTHEMEDIR', BBPATH . 'my-templates/');
     87if ( !defined('BBTHEMEURL') )
     88    define('BBTHEMEDIR', $bb->uri . 'my-templates/');
    6789
    6890if ( extension_loaded('mysqli') ) {
     
    144166    $bbdb->usermeta = CUSTOM_USER_META_TABLE;
    145167
    146 if ( isset($bb->uri) ) {
    147     $bb->domain = preg_replace('|(?<!/)/(?!/).*$|', '', $bb->uri);
    148     $bb->path = substr($bb->uri, strlen($bb->domain));
    149 } elseif ( isset($bb->path) && isset($bb->domain) ) {
    150     $bb->domain = rtrim($bb->domain, '/');
    151     $bb->path = '/' . ltrim($bb->path, '/');
    152 } else {
    153     bb_die( '<code>$bb->uri</cade> must be set in your <code>config.php</code> file.' );
    154 }
    155 
    156 foreach ( array('wp_site_url', 'wp_home', 'path') as $p )
    157     if ( isset($bb->$p) && $bb->$p )
    158         $bb->$p = rtrim($bb->$p, '/');
    159 unset($p);
    160 
    161 $bb->path = "$bb->path/";
    162 $bb->uri = $bb->domain . $bb->path;
    163 
    164168define('BBHASH', $bb->wp_siteurl ? md5($bb->wp_siteurl) : md5($bb_table_prefix) );
    165169
Note: See TracChangeset for help on using the changeset viewer.