/** * @group activity_action * @group bp_blogs_format_activity_action_new_blog_post */ public function test_bp_blogs_format_activity_action_new_blog_post_ms_rootblog() { if (!is_multisite()) { return; } $u = $this->factory->user->create(); $p = $this->factory->post->create(array('post_author' => $u)); $a = $this->factory->activity->create(array('component' => buddypress()->blogs->id, 'type' => 'new_blog_post', 'user_id' => $u, 'item_id' => 1, 'secondary_item_id' => $p)); $a_obj = new BP_Activity_Activity($a); $user_link = bp_core_get_userlink($u); $blog_url = get_home_url(); $post_url = add_query_arg('p', $p, trailingslashit($blog_url)); $post_title = bp_activity_get_meta($a, 'post_title'); $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; $expected = sprintf('%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . bp_blogs_get_blogmeta($a_obj->item_id, 'name') . '</a>'); $this->assertSame($expected, $a_obj->action); }
/** * Action handler when a follow blogs button is clicked. * * Handles both following and unfollowing a blog. */ public static function action_handler() { if (empty($_GET['blog_id']) || !is_user_logged_in()) { return; } $action = false; if (!empty($_GET['bpfb-follow']) || !empty($_GET['bpfb-unfollow'])) { $nonce = !empty($_GET['bpfb-follow']) ? $_GET['bpfb-follow'] : $_GET['bpfb-unfollow']; $action = !empty($_GET['bpfb-follow']) ? 'follow' : 'unfollow'; $save = !empty($_GET['bpfb-follow']) ? 'bp_follow_start_following' : 'bp_follow_stop_following'; } if (!$action) { return; } if (!wp_verify_nonce($nonce, "bp_follow_blog_{$action}")) { return; } if (!$save(array('leader_id' => (int) $_GET['blog_id'], 'follower_id' => bp_loggedin_user_id(), 'follow_type' => 'blogs'))) { if ('follow' == $action) { $message = __('You are already following that blog.', 'bp-follow'); } else { $message = __('You are not following that blog.', 'bp-follow'); } bp_core_add_message($message, 'error'); // success on follow action } else { $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name'); // blog has never been recorded into BP; record it now if ('' === $blog_name && apply_filters('bp_follow_blogs_record_blog', true, (int) $_GET['blog_id'])) { // get the admin of the blog $admin = get_users(array('blog_id' => get_current_blog_id(), 'role' => 'administrator', 'orderby' => 'ID', 'number' => 1, 'fields' => array('ID'))); // record the blog $record_site = bp_blogs_record_blog((int) $_GET['blog_id'], $admin[0]->ID, true); // now refetch the blog name from blogmeta if (false !== $record_site) { $blog_name = bp_blogs_get_blogmeta((int) $_GET['blog_id'], 'name'); } } if ('follow' == $action) { if (!empty($blog_name)) { $message = sprintf(__('You are now following the site, %s.', 'bp-follow'), $blog_name); } else { $message = __('You are now following that site.', 'bp-follow'); } } else { if (!empty($blog_name)) { $message = sprintf(__('You are no longer following the site, %s.', 'bp-follow'), $blog_name); } else { $message = __('You are no longer following that site.', 'bp-follow'); } } bp_core_add_message($message); } // it's possible that wp_get_referer() returns false, so let's fallback to the displayed user's page $redirect = wp_get_referer() ? wp_get_referer() : bp_displayed_user_domain() . bp_get_blogs_slug() . '/' . constant('BP_FOLLOW_BLOGS_USER_FOLLOWING_SLUG') . '/'; bp_core_redirect($redirect); }
/** * Utility function to set up some variables for use in the activity loop. * * Grabs the blog's comment depth and the post's open comment status options * for later use in the activity and activity comment loops. * * This is to prevent having to requery these items later on. * * @since BuddyPress (2.0.0) * * @see bp_blogs_disable_activity_commenting() * @see bp_blogs_setup_comment_loop_globals_on_ajax() * * @param object $activity The BP_Activity_Activity object */ function bp_blogs_setup_activity_loop_globals( $activity ) { if ( ! is_object( $activity ) ) { return; } // parent not a blog post? stop now! if ( 'new_blog_post' !== $activity->type ) { return; } if ( empty( $activity->id ) ) { return; } // if we've already done this before, stop now! if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) { return; } $allow_comments = bp_blogs_comments_open( $activity ); $thread_depth = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' ); // initialize a local object so we won't have to query this again in the // comment loop if ( empty( buddypress()->blogs->allow_comments ) ) { buddypress()->blogs->allow_comments = array(); } if ( empty( buddypress()->blogs->thread_depth ) ) { buddypress()->blogs->thread_depth = array(); } // cache comment settings in the buddypress() singleton to reference later in // the activity comment loop // @see bp_blogs_disable_activity_replies() // // thread_depth is keyed by activity ID instead of blog ID because when we're // in a comment loop, we don't have access to the blog ID... // should probably object cache these values instead... buddypress()->blogs->allow_comments[ $activity->id ] = $allow_comments; buddypress()->blogs->thread_depth[ $activity->id ] = $thread_depth; }
function dwqa_replace_activity_meta() { global $activities_template; $blog_url = bp_blogs_get_blogmeta($activity->item_id, 'url'); $blog_name = bp_blogs_get_blogmeta($activity->item_id, 'name'); if (empty($blog_url) || empty($blog_name)) { $blog_url = get_home_url($activity->item_id); $blog_name = get_blog_option($activity->item_id, 'blogname'); bp_blogs_update_blogmeta($activity->item_id, 'url', $blog_url); bp_blogs_update_blogmeta($activity->item_id, 'name', $blog_name); } $post_url = add_query_arg('p', $activities_template->activity->secondary_item_id, trailingslashit($blog_url)); $post_title = bp_activity_get_meta($activities_template->activity->id, 'post_title'); if (empty($post_title)) { $post = get_post($activities_template->activity->secondary_item_id); if (is_a($post, 'WP_Post')) { $post_title = $post->post_title; bp_activity_update_meta($activities_template->activity->id, 'post_title', $post_title); } } $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; $user_link = bp_core_get_userlink($activities_template->activity->user_id); if ($activities_template->activity->type == 'new_question') { $action = sprintf(__('%1$s asked a new question: %2$s', 'dwqa'), $user_link, $post_link); } elseif ($activities_template->activity->type == 'new_answer') { $action = sprintf(__('%1$s answered the question: %2$s', 'dwqa'), $user_link, $post_link); } elseif ($activities_template->activity->type == 'comment_question') { $action = sprintf(__('%1$s commented on the question: %2$s', 'dwqa'), $user_link, $post_link); } elseif ($activities_template->activity->type == 'comment_answer') { $action = sprintf(__('%1$s commented on the answer at: %2$s', 'dwqa'), $user_link, $post_link); } else { $action = $activities_template->activity->action; } // Strip any legacy time since placeholders from BP 1.0-1.1 $content = str_replace('<span class="time-since">%s</span>', '', $content); // Insert the time since. $time_since = apply_filters_ref_array('bp_activity_time_since', array('<span class="time-since">' . bp_core_time_since($activities_template->activity->date_recorded) . '</span>', &$activities_template->activity)); // Insert the permalink if (!bp_is_single_activity()) { $content = apply_filters_ref_array('bp_activity_permalink', array(sprintf('%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink($activities_template->activity->id, $activities_template->activity), esc_attr__('View Discussion', 'buddypress'), $time_since), &$activities_template->activity)); } else { $content .= str_pad($time_since, strlen($time_since) + 2, ' ', STR_PAD_BOTH); } echo $action . ' ' . $content; // echo 'abc'; // echo $activities_template->activity->content; }
/** * @group blogmeta * @group bp_blogs_update_blogmeta */ public function test_bp_blogs_update_blogmeta_existing_no_change() { bp_blogs_update_blogmeta(1, 'foo', 'bar'); $this->assertSame('bar', bp_blogs_get_blogmeta(1, 'foo')); $this->assertFalse(bp_blogs_update_blogmeta(1, 'foo', 'bar')); }
/** * Get a blog's avatar. * * At the moment, blog avatars are simply the user avatars of the blog * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize. * * @since 2.4.0 Introduced `$title` argument. * * @see bp_core_fetch_avatar() For a description of arguments and * return values. * * @param array|string $args { * Arguments are listed here with an explanation of their defaults. * For more information about the arguments, see * {@link bp_core_fetch_avatar()}. * @type string $alt Default: 'Profile picture of site author [user name]'. * @type string $class Default: 'avatar'. * @type string $title Default: 'Profile picture of site author [user name]'. * @type string $type Default: 'full'. * @type int|bool $width Default: false. * @type int|bool $height Default: false. * @type bool $id Currently unused. * @type bool $no_grav Default: true. * } * @return string User avatar string. */ function bp_get_blog_avatar($args = '') { global $blogs_template; // Bail if avatars are turned off // @todo Should we maybe still filter this? if (!buddypress()->avatar->show_avatars) { return false; } $author_displayname = bp_core_get_user_displayname($blogs_template->blog->admin_user_id); // Parse the arguments. $r = bp_parse_args($args, array('type' => 'full', 'width' => false, 'height' => false, 'class' => 'avatar', 'title' => sprintf(__('Profile picture of site author %s', 'buddypress'), esc_attr($author_displayname)), 'id' => false, 'alt' => sprintf(__('Profile picture of site author %s', 'buddypress'), esc_attr($author_displayname)), 'no_grav' => true)); // Use site icon if available. $avatar = ''; if (bp_is_active('blogs', 'site-icon') && function_exists('has_site_icon')) { $site_icon = bp_blogs_get_blogmeta(bp_get_blog_id(), "site_icon_url_{$r['type']}"); // Never attempted to fetch site icon before; do it now! if ('' === $site_icon) { switch_to_blog(bp_get_blog_id()); // Fetch the other size first. if ('full' === $r['type']) { $size = bp_core_avatar_thumb_width(); $save_size = 'thumb'; } else { $size = bp_core_avatar_full_width(); $save_size = 'full'; } $site_icon = get_site_icon_url($size); // Empty site icons get saved as integer 0. if (empty($site_icon)) { $site_icon = 0; } // Sync site icon for other size to blogmeta. bp_blogs_update_blogmeta(bp_get_blog_id(), "site_icon_url_{$save_size}", $site_icon); // Now, fetch the size we want. if (0 !== $site_icon) { $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); $site_icon = get_site_icon_url($size); } // Sync site icon to blogmeta. bp_blogs_update_blogmeta(bp_get_blog_id(), "site_icon_url_{$r['type']}", $site_icon); restore_current_blog(); } // We have a site icon. if (!is_numeric($site_icon)) { if (empty($r['width']) && !isset($size)) { $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); } else { $size = (int) $r['width']; } $avatar = sprintf('<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" title="%4$s" />', esc_url($site_icon), esc_attr("{$r['class']} avatar-{$size}"), esc_attr($size), sprintf(esc_attr__('Site icon for %s', 'buddypress'), bp_get_blog_name())); } } // Fallback to user ID avatar. if ('' === $avatar) { $avatar = bp_core_fetch_avatar(array('item_id' => $blogs_template->blog->admin_user_id, 'title' => $r['title'], 'type' => $r['type'], 'alt' => $r['alt'], 'css_id' => $r['id'], 'class' => $r['class'], 'width' => $r['width'], 'height' => $r['height'])); } /** * In future BuddyPress versions you will be able to set the avatar for a blog. * Right now you can use a filter with the ID of the blog to change it if you wish. * By default it will return the avatar for the primary blog admin. * * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version. * Use the 'bp_get_blog_avatar' filter instead. */ $avatar = apply_filters('bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar); /** * Filters a blog's avatar. * * @since 1.5.0 * * @param string $avatar Formatted HTML <img> element, or raw avatar * URL based on $html arg. * @param int $blog_id ID of the blog whose avatar is being displayed. * @param array $r Array of arguments used when fetching avatar. */ return apply_filters('bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r); }
/** * action for listing post type comment. * * @since 1.0.0 * @package GeoDirectory_BuddyPress_Integration * * @param string $action BuddyPress Constructed activity action. * @param object $activity BuddyPress Activity data object. * @return mixed|void Modified Action. */ function geodir_buddypress_new_listing_comment_activity($action, $activity) { $posy_info = NULL; switch_to_blog($activity->item_id); $comment = get_comment($activity->secondary_item_id); $posy_info = !empty($comment->comment_post_ID) ? get_post($comment->comment_post_ID) : NULL; $post_type = !empty($posy_info) ? $posy_info->post_type : ''; restore_current_blog(); $gd_post_types = geodir_get_posttypes('array'); if (!empty($post_type) && array_key_exists($post_type, $gd_post_types)) { $blog_url = bp_blogs_get_blogmeta($activity->item_id, 'url'); $blog_name = bp_blogs_get_blogmeta($activity->item_id, 'name'); if (empty($blog_url) || empty($blog_name)) { $blog_url = get_home_url($activity->item_id); $blog_name = get_blog_option($activity->item_id, 'blogname'); bp_blogs_update_blogmeta($activity->item_id, 'url', $blog_url); bp_blogs_update_blogmeta($activity->item_id, 'name', $blog_name); } $post_url = bp_activity_get_meta($activity->id, 'post_url'); $post_title = bp_activity_get_meta($activity->id, 'post_title'); // Should only be empty at the time of post creation if (empty($post_url) || empty($post_title)) { if (!empty($comment->comment_post_ID)) { $post_url = esc_url(add_query_arg('p', $comment->comment_post_ID, trailingslashit($blog_url))); bp_activity_update_meta($activity->id, 'post_url', $post_url); if (is_a($posy_info, 'WP_Post')) { $post_title = $post->post_title; bp_activity_update_meta($activity->id, 'post_title', $post_title); } } } $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; $user_link = bp_core_get_userlink($activity->user_id); $post_type_name = __(strtolower($gd_post_types[$post_type]['labels']['singular_name']), GDBUDDYPRESS_TEXTDOMAIN); if (is_multisite()) { $action = sprintf(__('%1$s commented on the %2$s, %3$s, on the site %4$s', GDBUDDYPRESS_TEXTDOMAIN), $user_link, $post_type_name, $post_link, '<a href="' . esc_url($blog_url) . '">' . esc_html($blog_name) . '</a>'); } else { $action = sprintf(__('%1$s commented on the %2$s, %3$s', GDBUDDYPRESS_TEXTDOMAIN), $user_link, $post_type_name, $post_link); } } return apply_filters('geodir_buddypress_new_listing_comment_activity', $action, $activity, $post_type); }
function bp_get_the_site_blog_last_active() { global $site_blogs_template; return apply_filters('bp_the_site_blog_last_active', bp_core_get_last_activity(bp_blogs_get_blogmeta($site_blogs_template->blog->blog_id, 'last_activity'), __('active %s ago', 'buddypress'))); }
/** * @group update_blog_details */ public function test_update_blog_details_should_purge_blogmeta_cache() { if (!is_multisite()) { return; } $u = $this->factory->user->create(); $b1 = $this->factory->blog->create(); bp_blogs_record_blog($b1, $u, true); // prime cache bp_blogs_get_blogmeta($b1, 'url'); $this->assertNotEmpty(wp_cache_get($b1, 'blog_meta')); // updating blog details should purge cache update_blog_details($b1, array('domain' => 'awesome.com')); // assert cache is purged $this->assertEmpty(wp_cache_get($b1, 'blog_meta')); }