Changeset 4709
- Timestamp:
- 07/18/2011 10:43:22 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-functions.php
r4674 r4709 117 117 * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's id 118 118 * @param int $total_items The total number of notifications to format 119 * @param str $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise 119 * @param str $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise 120 120 */ 121 121 function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { … … 139 139 break; 140 140 } 141 141 142 142 if ( 'string' == $format ) { 143 143 $return = apply_filters( $filter, '<a href="' . $at_mention_link . '" title="' . $at_mention_title . '">' . $text . '</a>', $at_mention_link, (int)$total_items, $activity_id, $poster_user_id ); … … 994 994 } 995 995 996 /** Embeds *******************************************************************/ 997 998 /** 999 * Grabs the activity ID and attempts to retrieve the oEmbed cache (if it exists) 1000 * during the activity loop. If no cache and link is embeddable, cache it. 1001 * 1002 * @see BP_Embed 1003 * @see bp_embed_activity_cache() 1004 * @see bp_embed_activity_save_cache() 1005 * @package BuddyPress Activity 1006 * @since 1.3 1007 */ 1008 function bp_activity_embed() { 1009 add_filter( 'embed_post_id', 'bp_get_activity_id' ); 1010 add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 ); 1011 add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 ); 1012 } 1013 add_action( 'activity_loop_start', 'bp_activity_embed' ); 1014 1015 /** 1016 * Wrapper function for {@link bp_activity_get_meta()}. 1017 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. 1018 * 1019 * @package BuddyPress Activity 1020 * @since 1.3 1021 */ 1022 function bp_embed_activity_cache( $cache, $id, $cachekey ) { 1023 return bp_activity_get_meta( $id, $cachekey ); 1024 } 1025 1026 /** 1027 * Wrapper function for {@link bp_activity_update_meta()}. 1028 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. 1029 * 1030 * @package BuddyPress Activity 1031 * @since 1.3 1032 */ 1033 function bp_embed_activity_save_cache( $cache, $cachekey, $id ) { 1034 bp_activity_update_meta( $id, $cachekey, $cache ); 1035 } 996 1036 ?> -
trunk/bp-core/bp-core-classes.php
r4678 r4709 1083 1083 } 1084 1084 1085 /** 1086 * BP_Embed 1087 * 1088 * Extends WP_Embed class for use with BuddyPress. 1089 * 1090 * @package BuddyPress Core 1091 * @since 1.3 1092 * @see WP_Embed 1093 */ 1094 class BP_Embed extends WP_Embed { 1095 /** 1096 * Constructor 1097 * 1098 * @global unknown $wp_embed 1099 */ 1100 function __construct() { 1101 global $wp_embed; 1102 1103 // Make sure we populate the WP_Embed handlers array. 1104 // These are providers that use a regex callback on the URL in question. 1105 // Do not confuse with oEmbed providers, which require an external ping. 1106 // Used in WP_Embed::shortcode() 1107 $this->handlers = $wp_embed->handlers; 1108 1109 if ( bp_use_embed_in_activity() ) { 1110 add_filter( 'bp_get_activity_content_body', array( &$this, 'autoembed' ), 8 ); 1111 add_filter( 'bp_get_activity_content_body', array( &$this, 'run_shortcode' ), 7 ); 1112 } 1113 1114 if ( bp_use_embed_in_activity_replies() ) { 1115 add_filter( 'bp_get_activity_content', array( &$this, 'autoembed' ), 8 ); 1116 add_filter( 'bp_get_activity_content', array( &$this, 'run_shortcode' ), 7 ); 1117 } 1118 1119 if ( bp_use_embed_in_forum_posts() ) { 1120 add_filter( 'bp_get_the_topic_post_content', array( &$this, 'autoembed' ), 8 ); 1121 add_filter( 'bp_get_the_topic_post_content', array( &$this, 'run_shortcode' ), 7 ); 1122 } 1123 } 1124 1125 /** 1126 * The {@link do_shortcode()} callback function. 1127 * 1128 * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. 1129 * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false. 1130 * If none of the regex matches and it's enabled, then the URL will be passed to {@link BP_Embed::parse_oembed()} for oEmbed parsing. 1131 * 1132 * @uses wp_parse_args() 1133 * @uses wp_embed_defaults() 1134 * @uses current_user_can() 1135 * @uses _wp_oembed_get_object() 1136 * @uses WP_Embed::maybe_make_link() 1137 * 1138 * @param array $attr Shortcode attributes. 1139 * @param string $url The URL attempting to be embeded. 1140 * @return string The embed HTML on success, otherwise the original URL. 1141 */ 1142 function shortcode( $attr, $url = '' ) { 1143 if ( empty( $url ) ) 1144 return ''; 1145 1146 $rawattr = $attr; 1147 $attr = wp_parse_args( $attr, wp_embed_defaults() ); 1148 1149 // kses converts & into & and we need to undo this 1150 // See http://core.trac.wordpress.org/ticket/11311 1151 $url = str_replace( '&', '&', $url ); 1152 1153 // Look for known internal handlers 1154 ksort( $this->handlers ); 1155 foreach ( $this->handlers as $priority => $handlers ) { 1156 foreach ( $handlers as $id => $handler ) { 1157 if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { 1158 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) 1159 return apply_filters( 'embed_handler_html', $return, $url, $attr ); 1160 } 1161 } 1162 } 1163 1164 // Get object ID 1165 $id = apply_filters( 'embed_post_id', $id ); 1166 1167 // Is oEmbed discovery on? 1168 $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && current_user_can( 'unfiltered_html' ) ); 1169 1170 // Set up a new WP oEmbed object to check URL with registered oEmbed providers 1171 require_once( ABSPATH . WPINC . '/class-oembed.php' ); 1172 $oembed_obj = _wp_oembed_get_object(); 1173 1174 // If oEmbed discovery is true, skip oEmbed provider check 1175 $is_oembed_link = false; 1176 if ( !$attr['discover'] ) { 1177 foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) { 1178 $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i'; 1179 1180 if ( preg_match( $regex, $url ) ) 1181 $is_oembed_link = true; 1182 } 1183 1184 // If url doesn't match a WP oEmbed provider, stop parsing 1185 if ( !$is_oembed_link ) 1186 return $this->maybe_make_link( $url ); 1187 } 1188 1189 return $this->parse_oembed( $id, $url, $attr, $rawattr ); 1190 } 1191 1192 /** 1193 * Base function so BP components / plugins can parse links to be embedded. 1194 * View an example to add support in {@link bp_activity_embed()}. 1195 * 1196 * @uses apply_filters() Filters cache. 1197 * @uses do_action() To save cache. 1198 * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success. 1199 * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure. 1200 * @param int $id ID to do the caching for. 1201 * @param string $url The URL attempting to be embedded. 1202 * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}. 1203 * @param array $rawattr Untouched shortcode attributes from {@link WP_Embed::shortcode()}. 1204 * @return string The embed HTML on success, otherwise the original URL. 1205 */ 1206 function parse_oembed( $id, $url, $attr, $rawattr ) { 1207 if ( $id ) { 1208 // Setup the cachekey 1209 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 1210 1211 // Let components / plugins grab their cache 1212 $cache = ''; 1213 $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr ); 1214 1215 // Grab cache and return it if available 1216 if ( !empty( $cache ) ) { 1217 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr ); 1218 1219 // If no cache, ping the oEmbed provider and cache the result 1220 } else { 1221 $html = wp_oembed_get( $url, $attr ); 1222 $cache = ( $html ) ? $html : $url; 1223 1224 // Let components / plugins save their cache 1225 do_action( 'bp_embed_update_cache', $cache, $cachekey, $id ); 1226 1227 // If there was a result, return it 1228 if ( $html ) 1229 return apply_filters( 'bp_embed_oembed_html', $html, $url, $attr, $rawattr ); 1230 } 1231 } 1232 1233 // Still unknown 1234 return $this->maybe_make_link( $url ); 1235 } 1236 } 1085 1237 ?> -
trunk/bp-core/bp-core-functions.php
r4678 r4709 19 19 function bp_get_option( $option_name, $default = '' ) { 20 20 $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default ); 21 21 22 22 return apply_filters( 'bp_get_option', $value ); 23 23 } … … 79 79 function bp_core_get_page_meta() { 80 80 $page_ids = bp_get_option( 'bp-pages' ); 81 81 82 82 // Upgrading from an earlier version of BP pre-1.3 83 if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) { 83 if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) { 84 84 $page_blog_id = bp_is_multiblog_mode() ? get_current_blog_id() : bp_get_root_blog_id(); 85 85 … … 90 90 } 91 91 } 92 92 93 93 return apply_filters( 'bp_core_get_page_meta', $page_ids ); 94 94 } … … 698 698 function bp_core_record_activity() { 699 699 global $bp; 700 700 701 701 if ( !is_user_logged_in() ) 702 702 return false; 703 703 704 704 $user_id = $bp->loggedin_user->id; 705 705 706 706 if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) ) 707 707 return false; … … 912 912 } 913 913 add_action( 'bp_init', 'bp_core_add_ajax_hook' ); 914 915 /** 916 * Initializes {@link BP_Embed} after everything is loaded. 917 * 918 * @global object $bp BuddyPress global settings 919 * @package BuddyPress Core 920 * @since 1.3 921 */ 922 function bp_embed_init() { 923 global $bp; 924 925 if ( empty( $bp->embed ) ) 926 $bp->embed = new BP_Embed(); 927 } 928 add_action( 'bp_init', 'bp_embed_init' ); 914 929 915 930 /** … … 1075 1090 */ 1076 1091 function bp_is_root_blog( $blog_id = 0 ) { 1077 1078 1092 // Assume false 1079 1093 $is_root_blog = false; … … 1119 1133 1120 1134 define( 'BP_ROOT_BLOG', $root_blog_id ); 1121 1135 1122 1136 // Root blog is defined 1123 1137 } else { … … 1221 1235 * 1222 1236 * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter 1223 * @return bool False when compatibility mode is disabled (default); true when enabled 1237 * @return bool False when compatibility mode is disabled (default); true when enabled 1224 1238 */ 1225 1239 function bp_is_username_compatibility_mode() { … … 1232 1246 * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WP Multisite. "Multiblog" is 1233 1247 * a BP setup that allows BP content to be viewed in the theme, and with the URL, of every blog 1234 * on the network. Thus, instead of having all 'boonebgorges' links go to 1248 * on the network. Thus, instead of having all 'boonebgorges' links go to 1235 1249 * http://example.com/members/boonebgorges 1236 1250 * on the root blog, each blog will have its own version of the same profile content, eg … … 1245 1259 * 1246 1260 * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter 1247 * @return bool False when multiblog mode is disabled (default); true when enabled 1261 * @return bool False when multiblog mode is disabled (default); true when enabled 1248 1262 */ 1249 1263 function bp_is_multiblog_mode() { … … 1264 1278 * 1265 1279 * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter 1266 * @return bool False when WP Admin Bar support is disabled (default); true when enabled 1280 * @return bool False when WP Admin Bar support is disabled (default); true when enabled 1267 1281 */ 1268 1282 function bp_use_wp_admin_bar() { 1269 1283 return apply_filters( 'bp_use_wp_admin_bar', defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR ); 1284 } 1285 1286 /** 1287 * Are oembeds allowed in activity items? 1288 * 1289 * @return bool False when activity embed support is disabled; true when enabled (default) 1290 * @since 1.3 1291 */ 1292 function bp_use_embed_in_activity() { 1293 return apply_filters( 'bp_use_oembed_in_activity', !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) || !BP_EMBED_DISABLE_ACTIVITY ); 1294 } 1295 1296 /** 1297 * Are oembeds allwoed in acitivity replies? 1298 * 1299 * @return bool False when activity replies embed support is disabled; true when enabled (default) 1300 * @since 1.3 1301 */ 1302 function bp_use_embed_in_activity_replies() { 1303 return apply_filters( 'bp_use_embed_in_activity_replies', !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) || !BP_EMBED_DISABLE_ACTIVITY_REPLIES ); 1304 } 1305 1306 /** 1307 * Are oembeds allowed on forum posts? 1308 * 1309 * @return bool False when form post embed support is disabled; true when enabled (default) 1310 * @since 1.3 1311 */ 1312 function bp_use_embed_in_forum_posts() { 1313 return apply_filters( 'bp_use_embed_in_forum_posts', !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) || !BP_EMBED_DISABLE_FORUM_POSTS ); 1270 1314 } 1271 1315 … … 1373 1417 do_action( 'bp_do_404', $redirect ); 1374 1418 1375 $wp_query->set_404(); 1376 status_header( 404 ); 1419 $wp_query->set_404(); 1420 status_header( 404 ); 1377 1421 nocache_headers(); 1378 1422 -
trunk/bp-forums/bp-forums-functions.php
r4658 r4709 515 515 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' ); 516 516 517 518 /** Embeds *******************************************************************/ 519 520 /** 521 * Grabs the topic post ID and attempts to retrieve the oEmbed cache (if it exists) 522 * during the forum topic loop. If no cache and link is embeddable, cache it. 523 * 524 * @see BP_Embed 525 * @see bp_embed_forum_cache() 526 * @see bp_embed_forum_save_cache() 527 * @package BuddyPress_Forums 528 * @since 1.3 529 */ 530 function bp_forums_embed() { 531 add_filter( 'embed_post_id', 'bp_get_the_topic_post_id' ); 532 add_filter( 'bp_embed_get_cache', 'bp_embed_forum_cache', 10, 3 ); 533 add_action( 'bp_embed_update_cache', 'bp_embed_forum_save_cache', 10, 3 ); 534 } 535 add_action( 'topic_loop_start', 'bp_forums_embed' ); 536 537 /** 538 * Wrapper function for {@link bb_get_postmeta()}. 539 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}. 540 * 541 * @package BuddyPress_Forums 542 * @since 1.3 543 */ 544 function bp_embed_forum_cache( $cache, $id, $cachekey ) { 545 return bb_get_postmeta( $id, $cachekey ); 546 } 547 548 /** 549 * Wrapper function for {@link bb_update_postmeta()}. 550 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}. 551 * 552 * @package BuddyPress_Forums 553 * @since 1.3 554 */ 555 function bp_embed_forum_save_cache( $cache, $cachekey, $id ) { 556 bb_update_postmeta( $id, $cachekey, $cache ); 557 } 517 558 ?>
Note: See TracChangeset
for help on using the changeset viewer.