Changeset 2659
- Timestamp:
- 11/29/2010 02:43:33 AM (14 years ago)
- Location:
- branches/plugin
- Files:
-
- 2 added
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-functions.php
r2652 r2659 1 1 <?php 2 3 /**4 * bbp_has_access()5 *6 * Make sure user can perform special tasks7 *8 * @package bbPress9 * @subpackage Functions10 * @since bbPress (r2464)11 *12 * @uses is_super_admin ()13 * @uses apply_filters14 *15 * @todo bbPress port of existing roles/caps16 * @return bool $has_access17 */18 function bbp_has_access () {19 20 if ( is_super_admin () )21 $has_access = true;22 else23 $has_access = false;24 25 return apply_filters( 'bbp_has_access', $has_access );26 }27 28 /**29 * bbp_allow_anonymous ()30 *31 * Returns true|false if anonymous topic creation and replies are allowed32 *33 * @since bbPress (r2596)34 * @return bool35 */36 function bbp_allow_anonymous () {37 return apply_filters( 'bbp_allow_anonymous', get_option( 'bbp_allow_anonymous', false ) );38 }39 2 40 3 /** … … 365 328 366 329 /** 367 * bbp_ dim_favorite()368 * 369 * Add or remove a topic from a user'sfavorites330 * bbp_remove_topic_from_all_favorites () 331 * 332 * Remove a deleted topic from all users' favorites 370 333 * 371 334 * @package bbPress … … 373 336 * @since bbPress (r2652) 374 337 * 375 * @return void376 */377 function bbp_dim_favorite () {378 global $current_user;379 380 wp_get_current_user();381 382 $user_id = $current_user->ID;383 $id = intval( $_POST['id'] );384 385 if ( !$topic = get_post( $id ) )386 die( '0' );387 388 if ( !current_user_can( 'edit_user', $user_id ) )389 die( '-1' );390 391 check_ajax_referer( "toggle-favorite_$topic->ID" );392 393 if ( bbp_is_user_favorite( $user_id, $topic->ID ) ) {394 if ( bbp_remove_user_favorite( $user_id, $topic->ID ) )395 die( '1' );396 } else {397 if ( bbp_add_user_favorite( $user_id, $topic->ID ) )398 die( '1' );399 }400 401 die( '0' );402 403 }404 add_action( 'wp_ajax_dim-favorite', 'bbp_dim_favorite' );405 406 /**407 * bbp_remove_topic_from_all_favorites ()408 *409 * Remove a deleted topic from all users' favorites410 *411 * @package bbPress412 * @subpackage Template Tags413 * @since bbPress (r2652)414 *415 338 * @param int $topic_id Topic ID to remove 416 339 * @return void … … 419 342 global $wpdb; 420 343 421 if ( $ ids = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_favorites' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ) )422 foreach ( $ ids as $id)423 bbp_remove_user_favorite( $ id, $topic_id );424 } 425 add_action( 'trash_post', 'bbp_remove_topic_from_all_favorites' );344 if ( $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_favorites' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ) ) 345 foreach ( $users as $user ) 346 bbp_remove_user_favorite( $user, $topic_id ); 347 } 348 add_action( 'trash_post', 'bbp_remove_topic_from_all_favorites' ); 426 349 add_action( 'delete_post', 'bbp_remove_topic_from_all_favorites' ); 427 350 428 /**429 * bbp_enqueue_topic_script ()430 *431 * Enqueue the topic page Javascript file432 *433 * @package bbPress434 * @subpackage Template Tags435 * @since bbPress (r2652)436 *437 * @return void438 */439 function bbp_enqueue_topic_script () {440 if ( !bbp_is_topic() )441 return;442 443 global $bbp;444 445 wp_enqueue_script( 'bbp_topic', $bbp->plugin_url . 'bbp-includes/js/topic.js', array( 'wp-lists' ), '20101124' );446 }447 add_filter( 'wp_enqueue_scripts', 'bbp_enqueue_topic_script' );448 449 /**450 * bbp_scripts ()451 *452 * Put some scripts in the header, like AJAX url for wp-lists453 *454 * @package bbPress455 * @subpackage Template Tags456 * @since bbPress (r2652)457 *458 * @return void459 */460 function bbp_scripts () {461 if ( !bbp_is_topic() )462 return;463 464 echo "<script type='text/javascript'>465 /* <![CDATA[ */466 var ajaxurl = '" . admin_url( 'admin-ajax.php' ) . "';467 /* ]]> */468 </script>\n";469 }470 add_filter( 'wp_head', 'bbp_scripts', -1 );471 472 /**473 * bbp_topic_script_localization ()474 *475 * Load localizations for topic script.476 *477 * These localizations require information that may not be loaded even by init.478 *479 * @package bbPress480 * @subpackage Template Tags481 * @since bbPress (r2652)482 *483 * @return void484 */485 function bbp_topic_script_localization () {486 if ( !bbp_is_topic() )487 return;488 489 global $current_user;490 491 wp_get_current_user();492 $user_id = $current_user->ID;493 494 wp_localize_script( 'bbp_topic', 'bbpTopicJS', array(495 'currentUserId' => $user_id,496 'topicId' => bbp_get_topic_id(),497 'favoritesLink' => bbp_get_favorites_link( $user_id ),498 'isFav' => (int) bbp_is_user_favorite( $user_id ),499 'favLinkYes' => __( 'favorites', 'bbpress' ),500 'favLinkNo' => __( '?', 'bbpress' ),501 'favYes' => __( 'This topic is one of your %favLinkYes% [%favDel%]', 'bbpress' ),502 'favNo' => __( '%favAdd% (%favLinkNo%)', 'bbpress' ),503 'favDel' => __( '×', 'bbpress' ),504 'favAdd' => __( 'Add this topic to your favorites', 'bbpress' )505 ));506 }507 add_filter( 'wp_enqueue_scripts', 'bbp_topic_script_localization' );508 509 351 ?> -
branches/plugin/bbp-includes/bbp-template.php
r2657 r2659 2637 2637 wp_get_current_user(); 2638 2638 2639 if ( !$user_id && !$user_id = $current_user->ID ) 2640 return; 2641 2642 $topic = get_post( bbp_get_topic_id() ); 2643 2644 if ( empty( $add ) || !is_array( $add ) ) 2645 $add = array( 'mid' => __( 'Add this topic to your favorites', 'bbpress' ), 'post' => __( ' (%?%)', 'bbpress' ) ); 2646 2647 if ( empty( $rem ) || !is_array( $rem ) ) 2648 $rem = array( 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ), 'mid' => __( '×', 'bbpress' ), 'post' => __( ']', 'bbpress' ) ); 2639 if ( empty( $user_id ) && !$user_id = $current_user->ID ) 2640 return false; 2649 2641 2650 2642 if ( !current_user_can( 'edit_user', (int) $user_id ) ) 2651 2643 return false; 2652 2644 2653 $url = esc_url( bbp_get_favorites_link( $user_id ) ); 2654 2655 if ( bbp_is_user_favorite( $user_id, $topic->ID ) ) { 2645 if ( !$topic_id = bbp_get_topic_id() ) 2646 return false; 2647 2648 if ( empty( $add ) || !is_array( $add ) ) { 2649 $add = array( 2650 'mid' => __( 'Add this topic to your favorites', 'bbpress' ), 2651 'post' => __( ' (%?%)', 'bbpress' ) 2652 ); 2653 $url = esc_url( bbp_get_topic_permalink( $topic_id ) ); 2654 } 2655 2656 if ( empty( $rem ) || !is_array( $rem ) ) { 2657 $rem = array( 2658 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ), 2659 'mid' => __( '×', 'bbpress' ), 2660 'post' => __( ']', 'bbpress' ) 2661 ); 2662 $url = esc_url( bbp_get_favorites_link( $user_id ) ); 2663 } 2664 2665 if ( bbp_is_user_favorite( $user_id, $topic_id ) ) { 2656 2666 $rem = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $rem ); 2657 $favs = array( 'fav' => '0', 'topic_id' => $topic ->ID);2667 $favs = array( 'fav' => '0', 'topic_id' => $topic_id ); 2658 2668 $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : ''; 2659 2669 $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' ); … … 2661 2671 } else { 2662 2672 $add = preg_replace( '|%(.+)%|', "<a href='$url'>$1</a>", $add ); 2663 $favs = array( 'fav' => '1', 'topic_id' => $topic ->ID);2673 $favs = array( 'fav' => '1', 'topic_id' => $topic_id ); 2664 2674 $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : ''; 2665 2675 $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' ); … … 2667 2677 } 2668 2678 2669 $url = esc_url( wp_nonce_url( add_query_arg( $favs, bbp_get_ favorites_link( $user_id ) ), 'toggle-favorite_' . $topic->ID) );2670 2671 return apply_filters( 'bbp_get_user_favorites_link', "<span id='favorite-toggle'><span id='favorite-$topic ->ID'>$pre<a href='$url' class='dim:favorite-toggle:favorite-$topic->ID:is-favorite'>$mid</a>$post</span></span>" );2679 $url = esc_url( wp_nonce_url( add_query_arg( $favs, bbp_get_topic_permalink( $topic_id ) ), 'toggle-favorite_' . $topic_id ) ); 2680 2681 return apply_filters( 'bbp_get_user_favorites_link', "<span id='favorite-toggle'><span id='favorite-$topic_id'>$pre<a href='$url' class='dim:favorite-toggle:favorite-$topic_id:is-favorite'>$mid</a>$post</span></span>" ); 2672 2682 } 2673 2683 -
branches/plugin/bbp-includes/bbp-users.php
r2652 r2659 1 1 <?php 2 2 3 /* Favorites */ 3 /** 4 * bbp_has_access() 5 * 6 * Make sure user can perform special tasks 7 * 8 * @package bbPress 9 * @subpackage Functions 10 * @since bbPress (r2464) 11 * 12 * @uses is_super_admin () 13 * @uses apply_filters 14 * 15 * @todo bbPress port of existing roles/caps 16 * @return bool $has_access 17 */ 18 function bbp_has_access () { 19 20 if ( is_super_admin () ) 21 $has_access = true; 22 else 23 $has_access = false; 24 25 return apply_filters( 'bbp_has_access', $has_access ); 26 } 27 28 /** 29 * bbp_allow_anonymous () 30 * 31 * Returns true|false if anonymous topic creation and replies are allowed 32 * 33 * @since bbPress (r2596) 34 * @return bool 35 */ 36 function bbp_allow_anonymous () { 37 return apply_filters( 'bbp_allow_anonymous', get_option( 'bbp_allow_anonymous', false ) ); 38 } 39 40 /** START - Favorites *********************************************************/ 4 41 5 42 /** … … 15 52 * @return array|bool Results if user has favorites, otherwise false 16 53 */ 17 function bbp_get_user_favorites_topic_ids ( $user_id ) {18 if ( !$user_id)54 function bbp_get_user_favorites_topic_ids ( $user_id = 0 ) { 55 if ( empty( $user_id ) ) 19 56 return; 20 57 … … 43 80 * @return array|bool Results if user has favorites, otherwise false 44 81 */ 45 function bbp_get_user_favorites ( $user_id ) { 82 function bbp_get_user_favorites ( $user_id = 0 ) { 83 if ( empty( $user_id ) ) 84 return; 85 46 86 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 47 87 … … 68 108 */ 69 109 function bbp_is_user_favorite ( $user_id = 0, $topic_id = 0 ) { 70 if ( !$user_id ) { 71 global $current_user; 110 global $post, $current_user; 111 112 if ( empty( $user_id ) ) { 72 113 wp_get_current_user(); 73 114 $user_id = $current_user->ID; 74 115 } 75 116 76 if ( !$user_id)117 if ( empty( $user_id ) ) 77 118 return false; 78 119 79 120 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 80 121 81 if ( $topic_id) {122 if ( !empty( $topic_id ) ) { 82 123 $post = get_post( $topic_id ); 83 124 $topic_id = $post->ID; 84 125 } elseif ( !$topic_id = bbp_get_topic_id() ) { 85 global $post; 86 if ( !$post ) 126 if ( empty( $post ) ) 87 127 return false; 88 128 … … 90 130 } 91 131 92 if ( !$favorites || !$topic_id)132 if ( empty( $favorites ) || empty( $topic_id ) ) 93 133 return false; 94 134 95 135 if ( isset( $favorites ) ) 96 136 return in_array( $topic_id, $favorites ); 97 137 98 138 return false; … … 112 152 * @return bool True 113 153 */ 114 function bbp_add_user_favorite ( $user_id, $topic_id ) { 115 $user_id = (int) $user_id; 116 $topic_id = (int) $topic_id; 154 function bbp_add_user_favorite ( $user_id = 0, $topic_id = 0 ) { 155 if ( empty( $user_id ) || empty( $topic_id ) ) 156 return false; 157 117 158 $favorites = (array) bbp_get_user_favorites_topic_ids( $user_id ); 118 159 $topic = get_post( $topic_id ); 119 160 120 if ( !$favorites || !$topic)161 if ( empty( $favorites ) || empty( $topic ) ) 121 162 return false; 122 163 … … 129 170 130 171 do_action( 'bbp_add_user_favorite', $user_id, $topic_id ); 172 131 173 return true; 132 174 } … … 146 188 */ 147 189 function bbp_remove_user_favorite ( $user_id, $topic_id ) { 148 $user_id = (int) $user_id; 149 $topic_id = (int) $topic_id; 150 $favorites = (array) bbp_get_user_favorites_topic_ids( $user_id ); 151 152 if ( !$favorites || !$topic_id ) 190 if ( empty( $user_id ) || empty( $topic_id ) ) 191 return false; 192 193 if ( !$favorites = (array) bbp_get_user_favorites_topic_ids( $user_id ) ) 153 194 return false; 154 195 … … 156 197 array_splice( $favorites, $pos, 1 ); 157 198 $favorites = array_filter( $favorites ); 199 158 200 if ( !empty( $favorites ) ) { 159 201 $favorites = implode( ',', $favorites ); … … 165 207 166 208 do_action( 'bbp_remove_user_favorite', $user_id, $topic_id ); 209 167 210 return true; 168 211 } 212 213 /** END - Favorites ***********************************************************/ 214 215 ?> -
branches/plugin/bbp-themes/bbp-twentyten/single-bbp_topic.php
r2652 r2659 21 21 <?php bbp_topic_tag_list(); ?> 22 22 23 <?php bbp_user_favorites_link(); ?>24 25 23 <div id="ajax-response"></div> 26 24 … … 29 27 <tr> 30 28 <th><?php _e( 'Creator', 'bbpress' ); ?></th> 31 <th><?php _e( 'Topic', 'bbpress' ); ?></th> 29 <th> 30 <?php _e( 'Topic', 'bbpress' ); ?> 31 <?php bbp_user_favorites_link(); ?> 32 </th> 32 33 </tr> 33 34 </thead> -
branches/plugin/bbp-themes/bbp-twentyten/style.css
r2638 r2659 1332 1332 background-color: #f5f5f5; 1333 1333 } 1334 table.bbp-forums th span, table.bbp-topics th span, 1335 table.bbp-topic th span, table.bbp-replies th span { 1336 float: right; 1337 } 1334 1338 table.bbp-forums tfoot td, table.bbp-topics tfoot td, 1335 1339 table.bbp-topic tfoot td, table.bbp-replies tfoot td { 1336 1340 background-color: #fafafa; 1341 color: #888; 1342 font-size: 12px; 1343 font-weight: bold; 1344 font-family: 'Helvetica Neue', Arial, Helvetica, 'Nimbus Sans L', sans-serif; 1337 1345 } 1338 1346
Note: See TracChangeset
for help on using the changeset viewer.