Ticket #5610: 5610.patch
| File 5610.patch, 14.1 KB (added by , 12 years ago) |
|---|
-
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 507387e..507c433 100644
function bp_activity_total_favorites_for_user( $user_id = 0 ) { 567 567 return BP_Activity_Activity::total_favorite_count( $user_id ); 568 568 } 569 569 570 /** 571 * Retrieve the favorite count for an activity 572 * 573 * @since BuddyPress (?) 574 * 575 * @uses bp_activity_get_meta() 576 * 577 * @param int $activity_id activity id. 578 * @return int Total favorite count for the activity. 579 */ 580 function bp_activity_get_favorites_count( $activity_id = 0 ) { 581 $retval = 0; 582 583 if ( empty( $activity_id ) ){ 584 return $retval; 585 } 586 587 return (int) bp_activity_get_meta( $activity_id, 'favorite_count' ); 588 } 589 570 590 /** Meta *********************************************************************/ 571 591 572 592 /** -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 0a7ceeb..17fbc4d 100644
function bp_activity_comment_permalink() { 2339 2339 * 2340 2340 * @uses bp_get_activity_favorite_link() 2341 2341 */ 2342 function bp_activity_favorite_link( ) {2343 echo bp_get_activity_favorite_link( );2342 function bp_activity_favorite_link( $activity_id = 0 ) { 2343 echo bp_get_activity_favorite_link( $activity_id ); 2344 2344 } 2345 2345 2346 2346 /** … … function bp_activity_favorite_link() { 2356 2356 * 2357 2357 * @return string The activity favorite link. 2358 2358 */ 2359 function bp_get_activity_favorite_link( ) {2359 function bp_get_activity_favorite_link( $activity_id = 0 ) { 2360 2360 global $activities_template; 2361 return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) ); 2361 2362 if ( empty( $activity_id ) ) { 2363 $activity_id = $activities_template->activity->id; 2364 } 2365 2366 $root_url = trailingslashit( bp_get_root_domain() ); 2367 2368 return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( $root_url . bp_get_activity_root_slug() . '/favorite/' . $activity_id . '/', 'mark_favorite' ) ); 2362 2369 } 2363 2370 2364 2371 /** -
src/bp-blogs/bp-blogs-favorites.php
diff --git src/bp-blogs/bp-blogs-favorites.php src/bp-blogs/bp-blogs-favorites.php index e69de29..b51507b 100644
1 <?php 2 // Exit if accessed directly 3 if ( ! defined( 'ABSPATH' ) ) exit; 4 5 if ( ! class_exists( 'BP_Blogs_Favorites' ) ) : 6 /** 7 * Load Favorites in blog posts. 8 * 9 * @package BuddyPress 10 * @subpackage blogsFavorites 11 * 12 * @since BuddyPress (?) 13 */ 14 class BP_Blogs_Favorites { 15 16 /** 17 * Setup Blog favorites. 18 * 19 * @access public 20 * @since BuddyPress (?) 21 * 22 * @uses buddypress() to get BuddyPress main instance. 23 */ 24 public static function register_favorites() { 25 // Bail if setting is not enabled 26 if ( ! bp_is_activity_favorite_post_active() ) { 27 return; 28 } 29 30 // Bail if blog is not trackable, meaning they won't be any activity about posts 31 if( ! bp_blogs_is_blog_trackable( get_current_blog_id(), bp_loggedin_user_id() ) ) { 32 return; 33 } 34 35 // Bail if favorite is disable 36 if ( ! bp_activity_can_favorite() ) { 37 return; 38 } 39 40 $bp = buddypress(); 41 42 if( empty( $bp->blogs->favorites ) ) { 43 $bp->blogs->favorites = new self; 44 } 45 46 return $bp->blogs->favorites; 47 } 48 49 /** 50 * Constructor method. 51 * 52 * @access public 53 * @since BuddyPress (?) 54 */ 55 public function __construct() { 56 $this->setup_globals(); 57 $this->setup_actions(); 58 } 59 60 /** 61 * Set preferences. 62 * 63 * @access public 64 * @since BuddyPress (?) 65 */ 66 public function setup_globals() { 67 $this->css_url = trailingslashit( buddypress()->plugin_url . 'bp-blogs/css' ); 68 $this->preferences = apply_filters( 'bp_blogs_favorites_preferences', array( 69 'use_dashicons' => true, 70 'filter_content' => true, 71 ) ); 72 } 73 74 /** 75 * Set actions and filters. 76 * 77 * @access private 78 * @since BuddyPress (?) 79 */ 80 private function setup_actions() { 81 82 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 83 84 if ( ! empty( $this->preferences['filter_content'] ) ) { 85 add_action( 'wp_head', array( $this, 'add_content_filter'), 1000 ); 86 add_action( 'wp_footer', array( $this, 'remove_content_filter'), 0 ); 87 } 88 89 } 90 91 /** 92 * Add some specific styling for favorites. 93 * 94 * @access public 95 * @since BuddyPress (?) 96 */ 97 public function enqueue_styles() { 98 $deps = array(); 99 100 if ( ! empty( $this->preferences['use_dashicons'] ) ) { 101 $deps = array( 'dashicons' ); 102 } 103 104 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 105 106 $css = $this->css_url . "favorite{$min}.css"; 107 $css = apply_filters( 'bp_blogs_favorite_css', $css ); 108 wp_enqueue_style( 'bp-blogs-css', $css, $deps, bp_get_version() ); 109 } 110 111 /** 112 * Add Filter to content. 113 * 114 * @access public 115 * @since BuddyPress (?) 116 */ 117 public function add_content_filter() { 118 add_filter( 'the_content', array( $this, 'append_favorites' ), 10, 1 ); 119 } 120 121 /** 122 * Remove Filter to content. 123 * 124 * @access public 125 * @since BuddyPress (?) 126 */ 127 public function remove_content_filter() { 128 remove_filter( 'the_content', array( $this, 'append_favorites' ), 10, 1 ); 129 } 130 131 /** 132 * Append favorites to post content. 133 * 134 * @access public 135 * @since BuddyPress (?) 136 */ 137 public function append_favorites( $content = '' ) { 138 $post_id = get_the_ID(); 139 140 if ( empty( $post_id ) ){ 141 return $content; 142 } 143 144 if ( 'post' != get_post_type( $post_id ) ) { 145 return $content; 146 } 147 148 $append = self::get_favorites( $post_id ); 149 150 if ( empty( $append ) ) { 151 return $content; 152 } 153 154 return $content . $append; 155 } 156 157 /** 158 * Return favorite output 159 * 160 * @access public 161 * @static 162 * @since BuddyPress (?) 163 */ 164 public static function get_favorites( $post_id = 0, $user_id = 0 ) { 165 $bp = buddypress(); 166 167 // Fetch the activity id for this post 168 $activity_id = bp_activity_get_activity_id( array( 169 'component' => buddypress()->blogs->id, 170 'type' => 'new_blog_post', 171 'item_id' => get_current_blog_id(), 172 'secondary_item_id' => $post_id, 173 ) ); 174 175 if ( empty( $activity_id ) ) { 176 return false; 177 } 178 179 if ( empty( $user_id ) ) { 180 $user_id = bp_loggedin_user_id(); 181 } 182 183 $fav_count = bp_activity_get_favorites_count( $activity_id ); 184 $wrapper_class = array( 'bp-favorite-post' ); 185 $link_href = '#'; 186 $link_title = ''; 187 188 if ( ! empty( $user_id ) ) { 189 $user_favorites = (array) bp_activity_get_user_favorites( $user_id ); 190 191 if( in_array( $activity_id, $user_favorites ) ) { 192 $wrapper_class[] = 'favorited'; 193 $link_href = trailingslashit( bp_core_get_user_domain( $user_id ) . $bp->activity->slug . '/favorites' ); 194 $link_title = __( 'View Favorites', 'buddypress' ); 195 } else { 196 $link_href = bp_get_activity_favorite_link( $activity_id ); 197 $link_title = __( 'Add Favorite', 'buddypress' ); 198 199 } 200 } 201 202 $link_text = sprintf( __( 'Favorite <span class="count">%s</span>', 'buddypress' ), $fav_count ); 203 if ( ! empty( $bp->blogs->favorites->preferences['use_dashicons'] ) ) { 204 $link_text = sprintf( _x( '<span class="count">%s</span>', 'blogs post favorite', 'buddypress' ), $fav_count ); 205 $wrapper_class[] = 'use-dashicons'; 206 } 207 208 return bp_get_button( 209 array( 210 'id' => 'favorite_post', 211 'component' => $bp->blogs->id, 212 'must_be_logged_in' => true, 213 'link_href' => $link_href, 214 'link_title' => $link_title, 215 'link_text' => $link_text, 216 'wrapper_id' => 'favorite-' . $activity_id, 217 'wrapper_class' => join( ' ', $wrapper_class ), 218 ) 219 ); 220 221 } 222 223 } 224 endif; // class_exists check 225 226 // Load the BP Members admin 227 add_action( 'bp_init', array( 'BP_Blogs_Favorites', 'register_favorites' ) ); -
src/bp-blogs/bp-blogs-loader.php
diff --git src/bp-blogs/bp-blogs-loader.php src/bp-blogs/bp-blogs-loader.php index 89cf2a1..ba6ad4c 100644
class BP_Blogs_Component extends BP_Component { 96 96 'buddybar' 97 97 ); 98 98 99 if ( bp_is_active( 'activity' ) ) 100 $includes[] = 'favorites'; 101 99 102 if ( is_multisite() ) 100 103 $includes[] = 'widgets'; 101 104 -
src/bp-blogs/bp-blogs-template.php
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php index 7115bcf..1fc0fd3 100644
function bp_blogs_get_profile_stats( $args = '' ) { 1330 1330 // Filter and return 1331 1331 return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r ); 1332 1332 } 1333 1334 /** 1335 * Display Favorite button if blog post is defined. 1336 * 1337 * Use do_action( 'bp_blogs_favorite_post' ) in your template 1338 * to control where the button will be displayed. You'll also 1339 * need to filter 'bp_blogs_favorites_preferences' to deactivate 1340 * the filter applied to content by default. 1341 * 1342 * @uses bp_blogs_get_favorite_button() 1343 * @param int $post_id See 1344 */ 1345 function bp_blogs_favorite_button( $post_id = 0 ) { 1346 echo bp_blogs_get_favorite_button( $post_id ); 1347 } 1348 add_action( 'bp_blogs_favorite_post', 'bp_blogs_favorite_button', 10, 1 ); 1349 1350 /** 1351 * Return Favorite button if blog post is defined. 1352 * 1353 * @uses bp_blogs_favorite_button [description] 1354 * @param int $post_id 1355 * @return string html output 1356 */ 1357 function bp_blogs_get_favorite_button( $post_id = 0 ) { 1358 $bp = buddypress(); 1359 1360 if ( empty( $post_id ) ) { 1361 $post_id = get_the_ID(); 1362 } 1363 1364 if ( empty( $bp->blogs->favorites ) ) { 1365 return; 1366 } 1367 1368 if ( ! empty( $bp->blogs->favorites->preferences['filter_content'] ) ) { 1369 return; 1370 } 1371 1372 return apply_filters( 'bp_blogs_get_favorite_button', BP_Blogs_Favorites::get_favorites( $post_id ) , $post_id ); 1373 } -
src/bp-blogs/css/favorite.css
diff --git src/bp-blogs/css/favorite.css src/bp-blogs/css/favorite.css index e69de29..c770e81 100644
1 div.bp-favorite-post a { 2 background: #fff; /* Old browsers */ 3 border: 1px solid #ccc; 4 color: #777; 5 font-size: .8rem; 6 cursor: pointer; 7 outline: none; 8 padding: 4px 10px; 9 text-align: center; 10 text-decoration: none; 11 } 12 div.bp-favorite-post a:hover { 13 background: #ededed; 14 border: 1px solid #bbb; 15 color: #555; 16 outline: none; 17 text-decoration: none; 18 } 19 20 div.bp-favorite-post a span { 21 background: #999; 22 color: #fff; 23 font-size: 90%; 24 margin-left: 2px; 25 padding: 0 5px; 26 } 27 div.bp-favorite-post a:hover span { 28 background: #555; 29 color: #fff; 30 } 31 32 .bp-favorite-post.use-dashicons a::before{ 33 font-family: 'dashicons'; 34 speak: none; 35 font-style: normal; 36 font-weight: normal; 37 font-variant: normal; 38 text-transform: none; 39 line-height: 1; 40 /* Better Font Rendering =========== */ 41 -webkit-font-smoothing: antialiased; 42 -moz-osx-font-smoothing: grayscale; 43 content:"\f154"; 44 margin-right:5px; 45 } 46 47 .bp-favorite-post.use-dashicons.favorited a::before { 48 content:"\f155"; 49 } -
src/bp-core/admin/bp-core-settings.php
diff --git src/bp-core/admin/bp-core-settings.php src/bp-core/admin/bp-core-settings.php index e112df7..57bc387 100644
function bp_admin_setting_callback_heartbeat() { 118 118 } 119 119 120 120 /** 121 * Allow new_blog_post activity to be favorited directly from post. 122 * 123 * @since BuddyPress (?) 124 */ 125 function bp_admin_setting_callback_favorite_blogpost() { 126 ?> 127 128 <input id="_bp_enable_blogpost_favorite" name="_bp_enable_blogpost_favorite" type="checkbox" value="1" <?php checked( bp_is_activity_favorite_post_active( true ) ); ?> /> 129 <label for="_bp_enable_blogpost_favorite"><?php _e( 'Allow posts activities to be directly favorited from the post itself', 'buddypress' ); ?></label> 130 131 <?php 132 } 133 134 /** 121 135 * Sanitization for _bp_force_buddyvar 122 136 * 123 137 * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to -
src/bp-core/bp-core-admin.php
diff --git src/bp-core/bp-core-admin.php src/bp-core/bp-core-admin.php index 8942a82..624bd73 100644
class BP_Admin { 390 390 add_settings_field( '_bp_enable_akismet', __( 'Akismet', 'buddypress' ), 'bp_admin_setting_callback_activity_akismet', 'buddypress', 'bp_activity' ); 391 391 register_setting ( 'buddypress', '_bp_enable_akismet', 'intval' ); 392 392 } 393 394 // Favoriting an new_blog_post activity direclty from post 395 if ( bp_is_active( 'blogs' ) ) { 396 add_settings_field( '_bp_enable_blogpost_favorite', __( 'Posts favoriting', 'buddypress' ), 'bp_admin_setting_callback_favorite_blogpost', 'buddypress', 'bp_activity' ); 397 register_setting( 'buddypress', '_bp_enable_blogpost_favorite', 'intval' ); 398 } 393 399 } 394 400 395 401 /** Avatar upload for users or groups ************************************/ -
src/bp-core/bp-core-options.php
diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php index 580ceb1..6307391 100644
function bp_get_default_options() { 81 81 // HeartBeat is on to refresh activities 82 82 '_bp_enable_heartbeat_refresh' => true, 83 83 84 /** Activity Post type favoriting ************************************/ 85 86 // Allow favoriting activity directly from post 87 '_bp_enable_blogpost_favorite' => true, 88 84 89 /** BuddyBar **********************************************************/ 85 90 86 91 // Force the BuddyBar … … function bp_is_activity_heartbeat_active( $default = true ) { 605 610 } 606 611 607 612 /** 613 * Check whether Favoriting a post activity direclty from the post itself is enabled. 614 * 615 * @since BuddyPress (?) 616 * 617 * @uses bp_get_option() To get the Heartbeat option. 618 * 619 * @param bool $default Optional. Fallback value if not found in the database. 620 * Default: true. 621 * @return bool True if option is enabled, otherwise false. 622 */ 623 function bp_is_activity_favorite_post_active( $default = true ) { 624 return (bool) apply_filters( 'bp_is_activity_favorite_post_active', (bool) bp_get_option( '_bp_enable_blogpost_favorite', $default ) ); 625 } 626 627 /** 608 628 * Get the current theme package ID. 609 629 * 610 630 * @since BuddyPress (1.7.0)