Changeset 2943 for branches/plugin/bbp-themes/bbp-twentyten/functions.php
- Timestamp:
- 02/28/2011 09:54:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-themes/bbp-twentyten/functions.php
r2818 r2943 1 1 <?php 2 3 /** 4 * bbPress Theme Functions 5 * 6 * @package bbPress 7 * @subpackage Theme 8 */ 9 10 /** 11 * Load the theme CSS 12 * 13 * @uses is_admin() To check if it's the admin section 14 * @uses wp_enqueue_style() To enqueue the styles 15 */ 16 function bbp_twentyten_enqueue_styles () { 17 if ( is_admin() ) 18 return false; 19 20 // Default styling, taken from twentyten theme 21 wp_enqueue_style( 'bbp-twentyten-default', get_stylesheet_directory_uri() . '/css/twentyten.css', false, 20100312, 'screen' ); 22 23 // bbPress specific 24 wp_enqueue_style( 'bbp-twentyten-bbpress', get_stylesheet_directory_uri() . '/css/bbpress.css', 'bbp-twentyten-default', 20100312, 'screen' ); 25 } 26 27 /** 28 * Add or remove a topic from a user's favorites 29 * 30 * @since bbPress (r2652) 31 * 32 * @uses bbp_get_current_user_id() To get the current user id 33 * @uses current_user_can() To check if the current user can edit the user 34 * @uses bbp_get_topic() To get the topic 35 * @uses check_ajax_referer() To verify the nonce & check the referer 36 * @uses bbp_is_user_favorite() To check if the topic is user's favorite 37 * @uses bbp_remove_user_favorite() To remove the topic from user's favorites 38 * @uses bbp_add_user_favorite() To add the topic from user's favorites 39 */ 40 function bbp_twentyten_dim_favorite () { 41 $user_id = bbp_get_current_user_id(); 42 $id = intval( $_POST['id'] ); 43 44 if ( !current_user_can( 'edit_user', $user_id ) ) 45 die( '-1' ); 46 47 if ( !$topic = bbp_get_topic( $id ) ) 48 die( '0' ); 49 50 check_ajax_referer( "toggle-favorite_$topic->ID" ); 51 52 if ( bbp_is_user_favorite( $user_id, $topic->ID ) ) { 53 if ( bbp_remove_user_favorite( $user_id, $topic->ID ) ) 54 die( '1' ); 2 /** 3 * TwentyTen functions and definitions 4 * 5 * Sets up the theme and provides some helper functions. Some helper functions 6 * are used in the theme as custom template tags. Others are attached to action and 7 * filter hooks in WordPress to change core functionality. 8 * 9 * The first function, twentyten_setup(), sets up the theme by registering support 10 * for various features in WordPress, such as post thumbnails, navigation menus, and the like. 11 * 12 * When using a child theme (see http://codex.wordpress.org/Theme_Development and 13 * http://codex.wordpress.org/Child_Themes), you can override certain functions 14 * (those wrapped in a function_exists() call) by defining them first in your child theme's 15 * functions.php file. The child theme's functions.php file is included before the parent 16 * theme's file, so the child theme functions would be used. 17 * 18 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached 19 * to a filter or action hook. The hook can be removed by using remove_action() or 20 * remove_filter() and you can attach your own function to the hook. 21 * 22 * We can remove the parent theme's hook only after it is attached, which means we need to 23 * wait until setting up the child theme: 24 * 25 * <code> 26 * add_action( 'after_setup_theme', 'my_child_theme_setup' ); 27 * function my_child_theme_setup() { 28 * // We are providing our own filter for excerpt_length (or using the unfiltered value) 29 * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 30 * ... 31 * } 32 * </code> 33 * 34 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API. 35 * 36 * @package WordPress 37 * @subpackage Twenty_Ten 38 * @since Twenty Ten 1.0 39 */ 40 41 /** 42 * Set the content width based on the theme's design and stylesheet. 43 * 44 * Used to set the width of images and content. Should be equal to the width the theme 45 * is designed for, generally via the style.css stylesheet. 46 */ 47 if ( ! isset( $content_width ) ) 48 $content_width = 640; 49 50 if ( ! function_exists( 'twentyten_setup' ) ): 51 /** 52 * Sets up theme defaults and registers support for various WordPress features. 53 * 54 * Note that this function is hooked into the after_setup_theme hook, which runs 55 * before the init hook. The init hook is too late for some features, such as indicating 56 * support post thumbnails. 57 * 58 * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's 59 * functions.php file. 60 * 61 * @uses add_theme_support() To add support for post thumbnails and automatic feed links. 62 * @uses register_nav_menus() To add support for navigation menus. 63 * @uses add_custom_background() To add support for a custom background. 64 * @uses add_editor_style() To style the visual editor. 65 * @uses load_theme_textdomain() For translation/localization support. 66 * @uses add_custom_image_header() To add support for a custom header. 67 * @uses register_default_headers() To register the default custom header images provided with the theme. 68 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 69 * 70 * @since Twenty Ten 1.0 71 */ 72 function twentyten_setup() { 73 74 // This theme styles the visual editor with editor-style.css to match the theme style. 75 add_editor_style(); 76 77 // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories. 78 add_theme_support( 'post-formats', array( 'aside', 'gallery' ) ); 79 80 // This theme uses post thumbnails 81 add_theme_support( 'post-thumbnails' ); 82 83 // Add default posts and comments RSS feed links to head 84 add_theme_support( 'automatic-feed-links' ); 85 86 // Make theme available for translation 87 // Translations can be filed in the /languages/ directory 88 load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' ); 89 90 $locale = get_locale(); 91 $locale_file = TEMPLATEPATH . "/languages/$locale.php"; 92 if ( is_readable( $locale_file ) ) 93 require_once( $locale_file ); 94 95 // This theme uses wp_nav_menu() in one location. 96 register_nav_menus( array( 97 'primary' => __( 'Primary Navigation', 'twentyten' ), 98 ) ); 99 100 // This theme allows users to set a custom background 101 add_custom_background(); 102 103 // Your changeable header business starts here 104 if ( ! defined( 'HEADER_TEXTCOLOR' ) ) 105 define( 'HEADER_TEXTCOLOR', '' ); 106 107 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI. 108 if ( ! defined( 'HEADER_IMAGE' ) ) 109 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' ); 110 111 // The height and width of your custom header. You can hook into the theme's own filters to change these values. 112 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. 113 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); 114 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); 115 116 // We'll be using post thumbnails for custom header images on posts and pages. 117 // We want them to be 940 pixels wide by 198 pixels tall. 118 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 119 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 120 121 // Don't support text inside the header image. 122 if ( ! defined( 'NO_HEADER_TEXT' ) ) 123 define( 'NO_HEADER_TEXT', true ); 124 125 // Add a way for the custom header to be styled in the admin panel that controls 126 // custom headers. See twentyten_admin_header_style(), below. 127 add_custom_image_header( '', 'twentyten_admin_header_style' ); 128 129 // ... and thus ends the changeable header business. 130 131 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 132 register_default_headers( array( 133 'berries' => array( 134 'url' => '%s/images/headers/berries.jpg', 135 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', 136 /* translators: header image description */ 137 'description' => __( 'Berries', 'twentyten' ) 138 ), 139 'cherryblossom' => array( 140 'url' => '%s/images/headers/cherryblossoms.jpg', 141 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', 142 /* translators: header image description */ 143 'description' => __( 'Cherry Blossoms', 'twentyten' ) 144 ), 145 'concave' => array( 146 'url' => '%s/images/headers/concave.jpg', 147 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', 148 /* translators: header image description */ 149 'description' => __( 'Concave', 'twentyten' ) 150 ), 151 'fern' => array( 152 'url' => '%s/images/headers/fern.jpg', 153 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', 154 /* translators: header image description */ 155 'description' => __( 'Fern', 'twentyten' ) 156 ), 157 'forestfloor' => array( 158 'url' => '%s/images/headers/forestfloor.jpg', 159 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', 160 /* translators: header image description */ 161 'description' => __( 'Forest Floor', 'twentyten' ) 162 ), 163 'inkwell' => array( 164 'url' => '%s/images/headers/inkwell.jpg', 165 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', 166 /* translators: header image description */ 167 'description' => __( 'Inkwell', 'twentyten' ) 168 ), 169 'path' => array( 170 'url' => '%s/images/headers/path.jpg', 171 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 172 /* translators: header image description */ 173 'description' => __( 'Path', 'twentyten' ) 174 ), 175 'sunset' => array( 176 'url' => '%s/images/headers/sunset.jpg', 177 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 178 /* translators: header image description */ 179 'description' => __( 'Sunset', 'twentyten' ) 180 ) 181 ) ); 182 } 183 /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */ 184 add_action( 'after_setup_theme', 'twentyten_setup' ); 185 endif; 186 187 if ( ! function_exists( 'twentyten_admin_header_style' ) ) : 188 /** 189 * Styles the header image displayed on the Appearance > Header admin panel. 190 * 191 * Referenced via add_custom_image_header() in twentyten_setup(). 192 * 193 * @since Twenty Ten 1.0 194 */ 195 function twentyten_admin_header_style() { 196 ?> 197 <style type="text/css"> 198 /* Shows the same border as on front end */ 199 #headimg { 200 border-bottom: 1px solid #000; 201 border-top: 4px solid #000; 202 } 203 /* If NO_HEADER_TEXT is false, you would style the text with these selectors: 204 #headimg #name { } 205 #headimg #desc { } 206 */ 207 </style> 208 <?php 209 } 210 endif; 211 212 if ( !function_exists( 'twentyten_page_menu_args' ) ) : 213 /** 214 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. 215 * 216 * To override this in a child theme, remove the filter and optionally add 217 * your own function tied to the wp_page_menu_args filter hook. 218 * 219 * @since Twenty Ten 1.0 220 */ 221 function twentyten_page_menu_args( $args ) { 222 $args['show_home'] = true; 223 return $args; 224 } 225 add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' ); 226 endif; 227 228 if ( !function_exists( 'twentyten_excerpt_length' ) ) : 229 /** 230 * Sets the post excerpt length to 40 characters. 231 * 232 * To override this length in a child theme, remove the filter and add your own 233 * function tied to the excerpt_length filter hook. 234 * 235 * @since Twenty Ten 1.0 236 * @return int 237 */ 238 function twentyten_excerpt_length( $length ) { 239 return 40; 240 } 241 add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 242 endif; 243 244 if ( !function_exists( 'twentyten_continue_reading_link' ) ) : 245 /** 246 * Returns a "Continue Reading" link for excerpts 247 * 248 * @since Twenty Ten 1.0 249 * @return string "Continue Reading" link 250 */ 251 function twentyten_continue_reading_link() { 252 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>'; 253 } 254 endif; 255 256 if ( !function_exists( 'twentyten_auto_excerpt_more' ) ) : 257 /** 258 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link(). 259 * 260 * To override this in a child theme, remove the filter and add your own 261 * function tied to the excerpt_more filter hook. 262 * 263 * @since Twenty Ten 1.0 264 * @return string An ellipsis 265 */ 266 function twentyten_auto_excerpt_more( $more ) { 267 return ' …' . twentyten_continue_reading_link(); 268 } 269 add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' ); 270 endif; 271 272 if ( !function_exists( 'twentyten_custom_excerpt_more' ) ) : 273 /** 274 * Adds a pretty "Continue Reading" link to custom post excerpts. 275 * 276 * To override this link in a child theme, remove the filter and add your own 277 * function tied to the get_the_excerpt filter hook. 278 * 279 * @since Twenty Ten 1.0 280 * @return string Excerpt with a pretty "Continue Reading" link 281 */ 282 function twentyten_custom_excerpt_more( $output ) { 283 if ( has_excerpt() && ! is_attachment() ) { 284 $output .= twentyten_continue_reading_link(); 285 } 286 return $output; 287 } 288 add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' ); 289 endif; 290 291 /** 292 * Remove inline styles printed when the gallery shortcode is used. 293 * 294 * Galleries are styled by the theme in Twenty Ten's style.css. This is just 295 * a simple filter call that tells WordPress to not use the default styles. 296 * 297 * @since Twenty Ten 1.2 298 */ 299 add_filter( 'use_default_gallery_style', '__return_false' ); 300 301 if ( !function_exists( 'twentyten_remove_gallery_css' ) ) : 302 /** 303 * Deprecated way to remove inline styles printed when the gallery shortcode is used. 304 * 305 * This function is no longer needed or used. Use the use_default_gallery_style 306 * filter instead, as seen above. 307 * 308 * @since Twenty Ten 1.0 309 * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1 310 * 311 * @return string The gallery style filter, with the styles themselves removed. 312 */ 313 function twentyten_remove_gallery_css( $css ) { 314 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css ); 315 } 316 // Backwards compatibility with WordPress 3.0. 317 if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) ) 318 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' ); 319 endif; 320 321 if ( ! function_exists( 'twentyten_comment' ) ) : 322 /** 323 * Template for comments and pingbacks. 324 * 325 * To override this walker in a child theme without modifying the comments template 326 * simply create your own twentyten_comment(), and that function will be used instead. 327 * 328 * Used as a callback by wp_list_comments() for displaying the comments. 329 * 330 * @since Twenty Ten 1.0 331 */ 332 function twentyten_comment( $comment, $args, $depth ) { 333 $GLOBALS['comment'] = $comment; 334 switch ( $comment->comment_type ) : 335 case '' : 336 ?> 337 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 338 <div id="comment-<?php comment_ID(); ?>"> 339 <div class="comment-author vcard"> 340 <?php echo get_avatar( $comment, 40 ); ?> 341 <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> 342 </div><!-- .comment-author .vcard --> 343 <?php if ( $comment->comment_approved == '0' ) : ?> 344 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em> 345 <br /> 346 <?php endif; ?> 347 348 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 349 <?php 350 /* translators: 1: date, 2: time */ 351 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); 352 ?> 353 </div><!-- .comment-meta .commentmetadata --> 354 355 <div class="comment-body"><?php comment_text(); ?></div> 356 357 <div class="reply"> 358 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> 359 </div><!-- .reply --> 360 </div><!-- #comment-## --> 361 362 <?php 363 break; 364 case 'pingback' : 365 case 'trackback' : 366 ?> 367 <li class="post pingback"> 368 <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p> 369 <?php 370 break; 371 endswitch; 372 } 373 endif; 374 375 if ( !function_exists( 'twentyten_widgets_init' ) ) : 376 /** 377 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer. 378 * 379 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own 380 * function tied to the init hook. 381 * 382 * @since Twenty Ten 1.0 383 * @uses register_sidebar 384 */ 385 function twentyten_widgets_init() { 386 // Area 1, located at the top of the sidebar. 387 register_sidebar( array( 388 'name' => __( 'Primary Widget Area', 'twentyten' ), 389 'id' => 'primary-widget-area', 390 'description' => __( 'The primary widget area', 'twentyten' ), 391 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 392 'after_widget' => '</li>', 393 'before_title' => '<h3 class="widget-title">', 394 'after_title' => '</h3>', 395 ) ); 396 397 // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. 398 register_sidebar( array( 399 'name' => __( 'Secondary Widget Area', 'twentyten' ), 400 'id' => 'secondary-widget-area', 401 'description' => __( 'The secondary widget area', 'twentyten' ), 402 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 403 'after_widget' => '</li>', 404 'before_title' => '<h3 class="widget-title">', 405 'after_title' => '</h3>', 406 ) ); 407 408 // Area 3, located in the footer. Empty by default. 409 register_sidebar( array( 410 'name' => __( 'First Footer Widget Area', 'twentyten' ), 411 'id' => 'first-footer-widget-area', 412 'description' => __( 'The first footer widget area', 'twentyten' ), 413 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 414 'after_widget' => '</li>', 415 'before_title' => '<h3 class="widget-title">', 416 'after_title' => '</h3>', 417 ) ); 418 419 // Area 4, located in the footer. Empty by default. 420 register_sidebar( array( 421 'name' => __( 'Second Footer Widget Area', 'twentyten' ), 422 'id' => 'second-footer-widget-area', 423 'description' => __( 'The second footer widget area', 'twentyten' ), 424 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 425 'after_widget' => '</li>', 426 'before_title' => '<h3 class="widget-title">', 427 'after_title' => '</h3>', 428 ) ); 429 430 // Area 5, located in the footer. Empty by default. 431 register_sidebar( array( 432 'name' => __( 'Third Footer Widget Area', 'twentyten' ), 433 'id' => 'third-footer-widget-area', 434 'description' => __( 'The third footer widget area', 'twentyten' ), 435 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 436 'after_widget' => '</li>', 437 'before_title' => '<h3 class="widget-title">', 438 'after_title' => '</h3>', 439 ) ); 440 441 // Area 6, located in the footer. Empty by default. 442 register_sidebar( array( 443 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ), 444 'id' => 'fourth-footer-widget-area', 445 'description' => __( 'The fourth footer widget area', 'twentyten' ), 446 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 447 'after_widget' => '</li>', 448 'before_title' => '<h3 class="widget-title">', 449 'after_title' => '</h3>', 450 ) ); 451 } 452 /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */ 453 add_action( 'widgets_init', 'twentyten_widgets_init' ); 454 endif; 455 456 if ( !function_exists( 'twentyten_remove_recent_comments_style' ) ) : 457 /** 458 * Removes the default styles that are packaged with the Recent Comments widget. 459 * 460 * To override this in a child theme, remove the filter and optionally add your own 461 * function tied to the widgets_init action hook. 462 * 463 * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1 464 * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles, 465 * but they won't have any effect on the widget in default Twenty Ten styling. 466 * 467 * @since Twenty Ten 1.0 468 */ 469 function twentyten_remove_recent_comments_style() { 470 add_filter( 'show_recent_comments_widget_style', '__return_false' ); 471 } 472 add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' ); 473 endif; 474 475 if ( ! function_exists( 'twentyten_posted_on' ) ) : 476 /** 477 * Prints HTML with meta information for the current post-date/time and author. 478 * 479 * @since Twenty Ten 1.0 480 */ 481 function twentyten_posted_on() { 482 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), 483 'meta-prep meta-prep-author', 484 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', 485 get_permalink(), 486 esc_attr( get_the_time() ), 487 get_the_date() 488 ), 489 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', 490 get_author_posts_url( get_the_author_meta( 'ID' ) ), 491 sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ), 492 get_the_author() 493 ) 494 ); 495 } 496 endif; 497 498 if ( ! function_exists( 'twentyten_posted_in' ) ) : 499 /** 500 * Prints HTML with meta information for the current post (category, tags and permalink). 501 * 502 * @since Twenty Ten 1.0 503 */ 504 function twentyten_posted_in() { 505 // Retrieves tag list of current post, separated by commas. 506 $tag_list = get_the_tag_list( '', ', ' ); 507 if ( $tag_list ) { 508 $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 509 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) { 510 $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 55 511 } else { 56 if ( bbp_add_user_favorite( $user_id, $topic->ID ) ) 57 die( '1' ); 512 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 58 513 } 59 60 die( '0' ); 61 } 62 63 /** 64 * Subscribe/Unsubscribe a user from a topic 65 * 66 * @since bbPress (r2668) 67 * 68 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 69 * @uses bbp_get_current_user_id() To get the current user id 70 * @uses current_user_can() To check if the current user can edit the user 71 * @uses bbp_get_topic() To get the topic 72 * @uses check_ajax_referer() To verify the nonce & check the referer 73 * @uses bbp_is_user_subscribed() To check if the topic is in user's 74 * subscriptions 75 * @uses bbp_remove_user_subscriptions() To remove the topic from user's 76 * subscriptions 77 * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions 78 */ 79 function bbp_twentyten_dim_subscription () { 80 if ( !bbp_is_subscriptions_active() ) 81 return; 82 83 $user_id = bbp_get_current_user_id(); 84 $id = intval( $_POST['id'] ); 85 86 if ( !current_user_can( 'edit_user', $user_id ) ) 87 die( '-1' ); 88 89 if ( !$topic = bbp_get_topic( $id ) ) 90 die( '0' ); 91 92 check_ajax_referer( "toggle-subscription_$topic->ID" ); 93 94 if ( bbp_is_user_subscribed( $user_id, $topic->ID ) ) { 95 if ( bbp_remove_user_subscription( $user_id, $topic->ID ) ) 96 die( '1' ); 97 } else { 98 if ( bbp_add_user_subscription( $user_id, $topic->ID ) ) 99 die( '1' ); 100 } 101 102 die( '0' ); 103 } 104 105 /** 106 * Enqueue the required Javascript files 107 * 108 * @since bbPress (r2652) 109 * 110 * @uses bbp_is_topic() To check if it's the topic page 111 * @uses get_stylesheet_directory_uri() To get the stylesheet directory uri 112 * @uses bbp_is_user_profile_edit() To check if it's the profile edit page 113 * @uses wp_enqueue_script() To enqueue the scripts 114 */ 115 function bbp_twentyten_enqueue_scripts () { 116 if ( bbp_is_topic() ) 117 wp_enqueue_script( 'bbp_topic', get_stylesheet_directory_uri() . '/js/topic.js', array( 'wp-lists' ), '20101202' ); 118 119 if ( bbp_is_user_profile_edit() ) 120 wp_enqueue_script( 'user-profile' ); 121 } 122 123 /** 124 * Put some scripts in the header, like AJAX url for wp-lists 125 * 126 * @since bbPress (r2652) 127 * 128 * @uses bbp_is_topic() To check if it's the topic page 129 * @uses admin_url() To get the admin url 130 * @uses bbp_is_user_profile_edit() To check if it's the profile edit page 131 */ 132 function bbp_twentyten_scripts () { 133 if ( bbp_is_topic() ) : ?> 134 135 <script type='text/javascript'> 136 /* <![CDATA[ */ 137 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>'; 138 /* ]]> */ 139 </script> 140 141 <?php elseif ( bbp_is_user_profile_edit() ) : ?> 142 143 <script type="text/javascript" charset="utf-8"> 144 if ( window.location.hash == '#password' ) { 145 document.getElementById('pass1').focus(); 146 } 147 </script> 148 149 <?php 150 endif; 151 } 152 153 /** 154 * Load localizations for topic script. 155 * 156 * These localizations require information that may not be loaded even by init. 157 * 158 * @since bbPress (r2652) 159 * 160 * @uses bbp_is_topic() To check if it's the topic page 161 * @uses bbp_get_current_user_id() To get the current user id 162 * @uses bbp_get_topic_id() To get the topic id 163 * @uses bbp_get_favorites_permalink() To get the favorites permalink 164 * @uses bbp_is_user_favorite() To check if the topic is in user's favorites 165 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 166 * @uses bbp_is_user_subscribed() To check if the user is subscribed to topic 167 * @uses bbp_get_topic_permalink() To get the topic permalink 168 * @uses wp_localize_script() To localize the script 169 */ 170 function bbp_twentyten_topic_script_localization () { 171 if ( !bbp_is_topic() ) 172 return; 173 174 $user_id = bbp_get_current_user_id(); 175 176 $localizations = array( 177 'currentUserId' => $user_id, 178 'topicId' => bbp_get_topic_id(), 179 'favoritesLink' => bbp_get_favorites_permalink( $user_id ), 180 'isFav' => (int) bbp_is_user_favorite( $user_id ), 181 'favLinkYes' => __( 'favorites', 'bbpress' ), 182 'favLinkNo' => __( '?', 'bbpress' ), 183 'favYes' => __( 'This topic is one of your %favLinkYes% [%favDel%]', 'bbpress' ), 184 'favNo' => __( '%favAdd% (%favLinkNo%)', 'bbpress' ), 185 'favDel' => __( '×', 'bbpress' ), 186 'favAdd' => __( 'Add this topic to your favorites', 'bbpress' ) 514 // Prints the string, replacing the placeholders. 515 printf( 516 $posted_in, 517 get_the_category_list( ', ' ), 518 $tag_list, 519 get_permalink(), 520 the_title_attribute( 'echo=0' ) 187 521 ); 188 189 if ( bbp_is_subscriptions_active() ) { 190 $localizations['subsActive'] = 1; 191 $localizations['isSubscribed'] = (int) bbp_is_user_subscribed( $user_id ); 192 $localizations['subsSub'] = __( 'Subscribe', 'bbpress' ); 193 $localizations['subsUns'] = __( 'Unsubscribe', 'bbpress' ); 194 $localizations['subsLink'] = bbp_get_topic_permalink(); 195 } else { 196 $localizations['subsActive'] = 0; 197 } 198 199 wp_localize_script( 'bbp_topic', 'bbpTopicJS', $localizations ); 200 } 201 202 // Actions 203 add_action( 'init', 'bbp_twentyten_enqueue_styles' ); 204 add_action( 'wp_ajax_dim-favorite', 'bbp_twentyten_dim_favorite' ); 205 add_action( 'wp_ajax_dim-subscription', 'bbp_twentyten_dim_subscription' ); 206 add_action( 'wp_enqueue_scripts', 'bbp_twentyten_enqueue_scripts' ); 207 add_filter( 'wp_head', 'bbp_twentyten_scripts', -1 ); 208 add_filter( 'wp_enqueue_scripts', 'bbp_twentyten_topic_script_localization' ); 522 } 523 endif; 524 525 // Include bbPress theme functions 526 include( get_template_directory() . '/bbpress/functions.php' ); 209 527 210 528 ?>
Note:
See TracChangeset
for help on using the changeset viewer.