Ticket #2707: 2707.006.2.patch
File 2707.006.2.patch, 14.5 KB (added by , 13 years ago) |
---|
-
buddypress/bp-core/bp-core-classes.php
1082 1082 } 1083 1083 } 1084 1084 1085 ?> 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 /** 1097 * PHP4 constructor 1098 */ 1099 function BP_Embed() { 1100 return $this->__construct(); 1101 } 1102 1103 /** 1104 * PHP5 constructor 1105 */ 1106 function __construct() { 1107 global $wp_embed; 1108 1109 // Make sure we populate the WP_Embed handlers array. 1110 // These are providers that use a regex callback on the URL in question. 1111 // Do not confuse with oEmbed providers, which require an external ping. 1112 // Used in WP_Embed::shortcode() 1113 $this->handlers = $wp_embed->handlers; 1114 1115 if( !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) ) { 1116 add_filter( 'bp_get_activity_content_body', array( &$this, 'autoembed' ), 8 ); 1117 add_filter( 'bp_get_activity_content_body', array( &$this, 'run_shortcode' ), 7 ); 1118 } 1119 1120 if( !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) ) { 1121 add_filter( 'bp_get_activity_content', array( &$this, 'autoembed' ), 8 ); 1122 add_filter( 'bp_get_activity_content', array( &$this, 'run_shortcode' ), 7 ); 1123 } 1124 1125 if( !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) ) { 1126 add_filter( 'bp_get_the_topic_post_content', array( &$this, 'autoembed' ), 8 ); 1127 add_filter( 'bp_get_the_topic_post_content', array( &$this, 'run_shortcode' ), 7 ); 1128 } 1129 } 1130 1131 /** 1132 * The {@link do_shortcode()} callback function. 1133 * 1134 * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. 1135 * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false. 1136 * 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. 1137 * 1138 * @uses wp_parse_args() 1139 * @uses wp_embed_defaults() 1140 * @uses author_can() 1141 * @uses _wp_oembed_get_object() 1142 * @uses WP_Embed::maybe_make_link() 1143 * 1144 * @param array $attr Shortcode attributes. 1145 * @param string $url The URL attempting to be embeded. 1146 * @return string The embed HTML on success, otherwise the original URL. 1147 */ 1148 function shortcode( $attr, $url = '' ) { 1149 1150 if ( empty( $url ) ) 1151 return ''; 1152 1153 $rawattr = $attr; 1154 $attr = wp_parse_args( $attr, wp_embed_defaults() ); 1155 1156 // kses converts & into & and we need to undo this 1157 // See http://core.trac.wordpress.org/ticket/11311 1158 $url = str_replace( '&', '&', $url ); 1159 1160 // Look for known internal handlers 1161 ksort( $this->handlers ); 1162 foreach ( $this->handlers as $priority => $handlers ) { 1163 foreach ( $handlers as $id => $handler ) { 1164 if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { 1165 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) 1166 return apply_filters( 'embed_handler_html', $return, $url, $attr ); 1167 } 1168 } 1169 } 1170 1171 // Get object ID 1172 $id = apply_filters( 'embed_post_id', $id ); 1173 1174 // Is oEmbed discovery on? 1175 $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && author_can( $id, 'unfiltered_html' ) ); 1176 1177 // Set up a new WP oEmbed object to check URL with registered oEmbed providers 1178 require_once( ABSPATH . WPINC . '/class-oembed.php' ); 1179 $oembed_obj = _wp_oembed_get_object(); 1180 1181 // If oEmbed discovery is true, skip oEmbed provider check 1182 $is_oembed_link = false; 1183 if ( !$attr['discover'] ) { 1184 foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) { 1185 $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i'; 1186 1187 if ( preg_match( $regex, $url ) ) 1188 $is_oembed_link = true; 1189 } 1190 1191 // If url doesn't match a WP oEmbed provider, stop parsing 1192 if ( !$is_oembed_link ) 1193 return $this->maybe_make_link( $url ); 1194 } 1195 1196 return $this->parse_oembed( $id, $url, $attr, $rawattr ); 1197 } 1198 1199 /** 1200 * Base function so BP components / plugins can parse links to be embedded. 1201 * View an example to add support in {@link bp_activity_embed()}. 1202 * 1203 * @uses apply_filters() Filters cache. 1204 * @uses do_action() To save cache. 1205 * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success. 1206 * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure. 1207 * @param int $id ID to do the caching for. 1208 * @param string $url The URL attempting to be embedded. 1209 * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}. 1210 * @param array $rawattr Untouched shortcode attributes from {@link WP_Embed::shortcode()}. 1211 * @return string The embed HTML on success, otherwise the original URL. 1212 */ 1213 function parse_oembed( $id, $url, $attr, $rawattr ) { 1214 1215 if ( $id ) { 1216 1217 // Setup the cachekey 1218 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 1219 1220 // Let components / plugins grab their cache 1221 $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr ); 1222 1223 // Grab cache and return it if available 1224 if ( !empty( $cache ) ) { 1225 return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $rawattr ); 1226 } 1227 // If no cache, ping the oEmbed provider and cache the result 1228 else { 1229 $html = wp_oembed_get( $url, $attr ); 1230 $cache = ( $html ) ? $html : $url; 1231 1232 // Let components / plugins save their cache 1233 do_action( 'bp_embed_update_cache', $cache, $cachekey, $id ); 1234 1235 // If there was a result, return it 1236 if ( $html ) 1237 return apply_filters( 'bp_embed_oembed_html', $html, $url, $attr, $rawattr ); 1238 } 1239 } 1240 1241 // Still unknown 1242 return $this->maybe_make_link( $url ); 1243 } 1244 } 1245 1246 ?> 1247 No newline at end of file -
buddypress/bp-core/bp-core-functions.php
18 18 */ 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 } 24 24 … … 78 78 */ 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 86 86 if ( isset( $ms_page_ids[$page_blog_id] ) ) { … … 89 89 bp_update_option( 'bp-pages', $page_ids ); 90 90 } 91 91 } 92 92 93 93 return apply_filters( 'bp_core_get_page_meta', $page_ids ); 94 94 } 95 95 … … 681 681 */ 682 682 function bp_core_record_activity() { 683 683 global $bp; 684 684 685 685 if ( !is_user_logged_in() ) 686 686 return false; 687 687 688 688 $user_id = $bp->loggedin_user->id; 689 689 690 690 if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) ) 691 691 return false; 692 692 … … 897 897 add_action( 'bp_init', 'bp_core_add_ajax_hook' ); 898 898 899 899 /** 900 * Initializes {@link BP_Embed} after everything is loaded. 901 * 902 * @package BuddyPress Core 903 * @since 1.3 904 */ 905 function bp_embed_init() { 906 $bp_embed = new BP_Embed(); 907 } 908 add_action( 'bp_init', 'bp_embed_init' ); 909 910 /** 900 911 * When switching from single to multisite we need to copy blog options to 901 912 * site options. 902 913 * … … 1058 1069 * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id(). 1059 1070 */ 1060 1071 function bp_is_root_blog( $blog_id = 0 ) { 1061 1072 1062 1073 // Assume false 1063 1074 $is_root_blog = false; 1064 1075 … … 1102 1113 } 1103 1114 1104 1115 define( 'BP_ROOT_BLOG', $root_blog_id ); 1105 1116 1106 1117 // Root blog is defined 1107 1118 } else { 1108 1119 $root_blog_id = BP_ROOT_BLOG; … … 1204 1215 * @since 1.3 1205 1216 * 1206 1217 * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter 1207 * @return bool False when compatibility mode is disabled (default); true when enabled 1218 * @return bool False when compatibility mode is disabled (default); true when enabled 1208 1219 */ 1209 1220 function bp_is_username_compatibility_mode() { 1210 1221 return apply_filters( 'bp_is_username_compatibility_mode', defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) && BP_ENABLE_USERNAME_COMPATIBILITY_MODE ); … … 1215 1226 * 1216 1227 * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WP Multisite. "Multiblog" is 1217 1228 * a BP setup that allows BP content to be viewed in the theme, and with the URL, of every blog 1218 * on the network. Thus, instead of having all 'boonebgorges' links go to 1229 * on the network. Thus, instead of having all 'boonebgorges' links go to 1219 1230 * http://example.com/members/boonebgorges 1220 1231 * on the root blog, each blog will have its own version of the same profile content, eg 1221 1232 * http://site2.example.com/members/boonebgorges (for subdomains) … … 1228 1239 * @since 1.3 1229 1240 * 1230 1241 * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter 1231 * @return bool False when multiblog mode is disabled (default); true when enabled 1242 * @return bool False when multiblog mode is disabled (default); true when enabled 1232 1243 */ 1233 1244 function bp_is_multiblog_mode() { 1234 1245 return apply_filters( 'bp_is_multiblog_mode', is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ); … … 1247 1258 * @since 1.3 1248 1259 * 1249 1260 * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter 1250 * @return bool False when WP Admin Bar support is disabled (default); true when enabled 1261 * @return bool False when WP Admin Bar support is disabled (default); true when enabled 1251 1262 */ 1252 1263 function bp_use_wp_admin_bar() { 1253 1264 return apply_filters( 'bp_use_wp_admin_bar', defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR ); … … 1316 1327 1317 1328 do_action( 'bp_do_404', $redirect ); 1318 1329 1319 $wp_query->set_404(); 1320 status_header( 404 ); 1330 $wp_query->set_404(); 1331 status_header( 404 ); 1321 1332 nocache_headers(); 1322 1333 1323 1334 if ( 'remove_canonical_direct' == $redirect ) -
buddypress/bp-activity/bp-activity-functions.php
116 116 * @param int $item_id The activity id 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' ) { 122 122 global $bp; … … 138 138 } 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 ); 144 144 } else { … … 989 989 return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches ); 990 990 } 991 991 992 ?> 992 /** Embeds *******************************************************************/ 993 994 /** 995 * Grabs the activity ID and attempts to retrieve the oEmbed cache (if it exists) 996 * during the activity loop. If no cache and link is embeddable, cache it. 997 * 998 * @see BP_Embed 999 * @see bp_embed_activity_cache() 1000 * @see bp_embed_activity_save_cache() 1001 * @package BuddyPress Activity 1002 * @since 1.3 1003 */ 1004 function bp_activity_embed() { 1005 add_filter( 'embed_post_id', 'bp_get_activity_id' ); 1006 add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 ); 1007 add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 ); 1008 } 1009 add_action( 'activity_loop_start', 'bp_activity_embed' ); 1010 1011 /** 1012 * Wrapper function for {@link bp_activity_get_meta()}. 1013 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. 1014 * 1015 * @package BuddyPress Activity 1016 * @since 1.3 1017 */ 1018 function bp_embed_activity_cache( $cache, $id, $cachekey ) { 1019 return bp_activity_get_meta( $id, $cachekey ); 1020 } 1021 1022 /** 1023 * Wrapper function for {@link bp_activity_update_meta()}. 1024 * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. 1025 * 1026 * @package BuddyPress Activity 1027 * @since 1.3 1028 */ 1029 function bp_embed_activity_save_cache( $cache, $cachekey, $id ) { 1030 bp_activity_update_meta( $id, $cachekey, $cache ); 1031 } 1032 1033 ?> 1034 No newline at end of file -
buddypress/bp-forums/bp-forums-functions.php
514 514 add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' ); 515 515 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' ); 516 516 517 ?> 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 } 558 559 ?> 560 No newline at end of file