Ticket #4949: 4949.04.patch
File 4949.04.patch, 6.0 KB (added by , 12 years ago) |
---|
-
bp-templates/bp-legacy/buddypress-functions.php
diff --git bp-templates/bp-legacy/buddypress-functions.php bp-templates/bp-legacy/buddypress-functions.php index af2a5cd..13b407b 100644
class BP_Legacy extends BP_Theme_Compat { 195 195 public function enqueue_styles() { 196 196 197 197 // LTR or RTL 198 $file = is_rtl() ? ' css/buddypress-rtl.css' : 'css/buddypress.css';198 $file = is_rtl() ? 'buddypress-rtl.css' : 'buddypress.css'; 199 199 200 // Check child theme 201 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $file ) ) { 202 $location = trailingslashit( get_stylesheet_directory_uri() ); 203 $handle = 'bp-child-css'; 200 // Locate the BP stylesheet 201 $asset = $this->locate_asset_in_stack( $file, 'css' ); 204 202 205 // Check parent theme 206 } elseif ( file_exists( trailingslashit( get_template_directory() ) . $file ) ) { 207 $location = trailingslashit( get_template_directory_uri() ); 208 $handle = 'bp-parent-css'; 209 210 // BuddyPress Theme Compatibility 211 } else { 212 $location = trailingslashit( $this->url ); 213 $handle = 'bp-legacy-css'; 203 // Enqueue BuddyPress-specific styling, if found 204 if ( isset( $asset['location'], $asset['handle'] ) ) { 205 wp_enqueue_style( $asset['handle'], $asset['location'], array(), $this->version, 'screen' ); 214 206 } 215 216 // Enqueue the BuddyPress styling217 wp_enqueue_style( $handle, $location . $file, array(), $this->version, 'screen' );218 207 } 219 208 220 209 /** … … class BP_Legacy extends BP_Theme_Compat { 224 213 */ 225 214 public function enqueue_scripts() { 226 215 227 // LTR or RTL 228 $file = 'js/buddypress.js'; 229 230 // Check child theme 231 if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $file ) ) { 232 $location = trailingslashit( get_stylesheet_directory_uri() ); 233 $handle = 'bp-child-js'; 216 $file = 'buddypress.js'; 234 217 235 // Check parent theme 236 } elseif ( file_exists( trailingslashit( get_template_directory() ) . $file ) ) { 237 $location = trailingslashit( get_template_directory_uri() ); 238 $handle = 'bp-parent-js'; 218 // Locate the BP JS file 219 $asset = $this->locate_asset_in_stack( $file, 'js' ); 239 220 240 // BuddyPress Theme Compatibility241 } else {242 $location = trailingslashit( $this->url );243 $handle = 'bp-legacy-js';221 // Enqueue the global JS, if found - AJAX will not work 222 // without it 223 if ( isset( $asset['location'], $asset['handle'] ) ) { 224 wp_enqueue_script( $asset['handle'], $asset['location'], array( 'jquery' ), $this->version ); 244 225 } 245 226 246 // Enqueue the global JS - Ajax will not work without it247 wp_enqueue_script( $handle, $location . $file, array( 'jquery' ), $this->version );248 249 227 // Add words that we need to use in JS to the end of the page so they can be translated and still used. 250 228 $params = array( 251 229 'my_favs' => __( 'My Favorites', 'buddypress' ), … … class BP_Legacy extends BP_Theme_Compat { 261 239 'remove_fav' => __( 'Remove Favorite', 'buddypress' ), 262 240 'unsaved_changes' => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ), 263 241 ); 264 wp_localize_script( $ handle, 'BP_DTheme', $params );242 wp_localize_script( $asset['handle'], 'BP_DTheme', $params ); 265 243 266 244 // Maybe enqueue comment reply JS 267 245 if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) ) { … … class BP_Legacy extends BP_Theme_Compat { 270 248 } 271 249 272 250 /** 251 * Get the URL and handle of a web-accessible CSS or JS asset 252 * 253 * We provide two levels of customizability with respect to where CSS 254 * and JS files can be stored: (1) the child theme/parent theme/theme 255 * compat hierarchy, and (2) the "template stack" of /buddypress/css/, 256 * /community/css/, and /css/. In this way, CSS and JS assets can be 257 * overloaded, and default versions provided, in exactly the same way 258 * as corresponding PHP templates. 259 * 260 * We are duplicating some of the logic that is currently found in 261 * bp_locate_template() and the _template_stack() functions. Those 262 * functions were built with PHP templates in mind, and will require 263 * refactoring in order to provide "stack" functionality for assets 264 * that must be accessible both using file_exists() (the file path) 265 * and at a public URI. 266 * 267 * This method is marked private, with the understanding that the 268 * implementation is subject to change or removal in an upcoming 269 * release, in favor of a unified _template_stack() system. Plugin 270 * and theme authors should not attempt to use what follows. 271 * 272 * @since BuddyPress (1.8) 273 * @access private 274 * @param string $file A filename like buddypress.cs 275 * @param string $type css|js 276 * @return array An array of data for the wp_enqueue_* function: 277 * 'handle' (eg 'bp-child-css') and a 'location' (the URI of the 278 * asset) 279 */ 280 private function locate_asset_in_stack( $file, $type = 'css' ) { 281 // Child, parent, theme compat 282 $locations = array(); 283 284 // No need to check child if template == stylesheet 285 if ( is_child_theme() ) { 286 $locations['bp-child'] = array( 287 'dir' => get_stylesheet_directory(), 288 'uri' => get_stylesheet_directory_uri(), 289 ); 290 } 291 292 $locations['bp-parent'] = array( 293 'dir' => get_template_directory(), 294 'uri' => get_template_directory_uri(), 295 ); 296 297 $locations['bp-legacy'] = array( 298 'dir' => bp_get_theme_compat_dir(), 299 'uri' => bp_get_theme_compat_url(), 300 ); 301 302 // Subdirectories within the top-level $locations directories 303 $subdirs = array( 304 'buddypress/' . $type, 305 'community/' . $type, 306 $type, 307 ); 308 309 $retval = array(); 310 311 foreach ( $locations as $location_type => $location ) { 312 foreach ( $subdirs as $subdir ) { 313 if ( file_exists( trailingslashit( $location['dir'] ) . trailingslashit( $subdir ) . $file ) ) { 314 $retval['location'] = trailingslashit( $location['uri'] ) . trailingslashit( $subdir ) . $file; 315 $retval['handle'] = $location_type . '-' . $type; 316 break 2; 317 } 318 } 319 } 320 321 return $retval; 322 } 323 324 /** 273 325 * Put some scripts in the header, like AJAX url for wp-lists 274 326 * 275 327 * @since BuddyPress (1.7)