コード例 #1
0
/**
 * Makes BuddyPress aware of a new site so that it can track its activity.
 *
 * @since BuddyPress (1.0)
 * @param int $blog_id
 * @param int $user_id
 * @param $bool $no_activity ; optional.
 * @uses BP_Blogs_Blog
 */
function bp_blogs_record_blog($blog_id, $user_id, $no_activity = false)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    $name = get_blog_option($blog_id, 'blogname');
    $description = get_blog_option($blog_id, 'blogdescription');
    if (empty($name)) {
        return false;
    }
    $recorded_blog = new BP_Blogs_Blog();
    $recorded_blog->user_id = $user_id;
    $recorded_blog->blog_id = $blog_id;
    $recorded_blog_id = $recorded_blog->save();
    $is_recorded = !empty($recorded_blog_id) ? true : false;
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'name', $name);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'description', $description);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'last_activity', bp_core_current_time());
    $is_private = !empty($_POST['blog_public']) && (int) $_POST['blog_public'] ? false : true;
    $is_private = !apply_filters('bp_is_new_blog_public', !$is_private);
    // Only record this activity if the blog is public
    if (!$is_private && !$no_activity) {
        // Record this in activity streams
        bp_blogs_record_activity(array('user_id' => $recorded_blog->user_id, 'action' => apply_filters('bp_blogs_activity_created_blog_action', sprintf(__('%s created the site %s', 'buddypress'), bp_core_get_userlink($recorded_blog->user_id), '<a href="' . get_site_url($recorded_blog->blog_id) . '">' . esc_attr($name) . '</a>'), $recorded_blog, $name, $description), 'primary_link' => apply_filters('bp_blogs_activity_created_blog_primary_link', get_site_url($recorded_blog->blog_id), $recorded_blog->blog_id), 'type' => 'new_blog', 'item_id' => $recorded_blog->blog_id));
    }
    do_action_ref_array('bp_blogs_new_blog', array(&$recorded_blog, $is_private, $is_recorded));
}
コード例 #2
0
/**
 * Make BuddyPress aware of a new site so that it can track its activity.
 *
 * @since BuddyPress (1.0.0)
 *
 * @uses BP_Blogs_Blog
 *
 * @param int $blog_id ID of the blog being recorded.
 * @param int $user_id ID of the user for whom the blog is being recorded.
 * @param bool $no_activity Optional. Whether to skip recording an activity
 *        item about this blog creation. Default: false.
 * @return bool|null Returns false on failure.
 */
function bp_blogs_record_blog($blog_id, $user_id, $no_activity = false)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // If blog is not recordable, do not record the activity.
    if (!bp_blogs_is_blog_recordable($blog_id, $user_id)) {
        return false;
    }
    $name = get_blog_option($blog_id, 'blogname');
    if (empty($name)) {
        return false;
    }
    $url = get_home_url($blog_id);
    $description = get_blog_option($blog_id, 'blogdescription');
    $close_old_posts = get_blog_option($blog_id, 'close_comments_for_old_posts');
    $close_days_old = get_blog_option($blog_id, 'close_comments_days_old');
    $thread_depth = get_blog_option($blog_id, 'thread_comments');
    if (!empty($thread_depth)) {
        $thread_depth = get_blog_option($blog_id, 'thread_comments_depth');
    } else {
        // perhaps filter this?
        $thread_depth = 1;
    }
    $recorded_blog = new BP_Blogs_Blog();
    $recorded_blog->user_id = $user_id;
    $recorded_blog->blog_id = $blog_id;
    $recorded_blog_id = $recorded_blog->save();
    $is_recorded = !empty($recorded_blog_id) ? true : false;
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'url', $url);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'name', $name);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'description', $description);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'last_activity', bp_core_current_time());
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'close_comments_days_old', $close_days_old);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'thread_comments_depth', $thread_depth);
    $is_private = !empty($_POST['blog_public']) && (int) $_POST['blog_public'] ? false : true;
    $is_private = !apply_filters('bp_is_new_blog_public', !$is_private);
    // Only record this activity if the blog is public
    if (!$is_private && !$no_activity && bp_blogs_is_blog_trackable($blog_id, $user_id)) {
        // Record this in activity streams
        bp_blogs_record_activity(array('user_id' => $recorded_blog->user_id, 'primary_link' => apply_filters('bp_blogs_activity_created_blog_primary_link', $url, $recorded_blog->blog_id), 'type' => 'new_blog', 'item_id' => $recorded_blog->blog_id));
    }
    /**
     * Fires after BuddyPress has been made aware of a new site for activity tracking.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference.
     * @param bool          $is_private    Whether or not the current blog being recorded is private.
     * @param bool          $is_recorded   Whether or not the current blog was recorded.
     */
    do_action_ref_array('bp_blogs_new_blog', array(&$recorded_blog, $is_private, $is_recorded));
}
コード例 #3
0
ファイル: activity.php プロジェクト: JeroenNouws/BuddyPress
 /**
  * @group bp_blogs_format_activity_action_new_blog
  */
 public function test_bp_activity_format_activity_action_new_blog_backpat()
 {
     if (!is_multisite()) {
         return;
     }
     add_filter('bp_blogs_activity_created_blog_action', array($this, 'created_blog_passthrough'), 10, 2);
     $b = $this->factory->blog->create();
     $u = $this->factory->user->create();
     $recorded_blog = new BP_Blogs_Blog();
     $recorded_blog->user_id = $u;
     $recorded_blog->blog_id = $b;
     $recorded_blog_id = $recorded_blog->save();
     $a = $this->factory->activity->create(array('component' => buddypress()->blogs->id, 'type' => 'new_blog', 'user_id' => $u, 'item_id' => $b));
     $this->assertEquals($this->userblog_id, $recorded_blog_id);
 }
コード例 #4
0
ファイル: bp-blogs.php プロジェクト: alvaropereyra/shrekcms
function bp_blogs_record_blog($blog_id, $user_id)
{
    global $bp;
    if (!$user_id) {
        $user_id = $bp->loggedin_user->id;
    }
    $name = get_blog_option($blog_id, 'blogname');
    $description = get_blog_option($blog_id, 'blogdescription');
    $recorded_blog = new BP_Blogs_Blog();
    $recorded_blog->user_id = $user_id;
    $recorded_blog->blog_id = $blog_id;
    $recorded_blog_id = $recorded_blog->save();
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'name', $name);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'description', $description);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'last_activity', time());
    if ((int) $_POST['blog_public']) {
        $is_private = 0;
    } else {
        $is_private = 1;
    }
    // Record in activity streams
    bp_blogs_record_activity(array('item_id' => $recorded_blog_id, 'component_name' => 'blogs', 'component_action' => 'new_blog', 'is_private' => $is_private, 'user_id' => $recorded_blog->user_id));
    do_action('bp_blogs_new_blog', $recorded_blog, $is_private, $is_recorded);
}
コード例 #5
0
/**
 * Make BuddyPress aware of a new site so that it can track its activity.
 *
 * @since 1.0.0
 *
 * @param int  $blog_id     ID of the blog being recorded.
 * @param int  $user_id     ID of the user for whom the blog is being recorded.
 * @param bool $no_activity Optional. Whether to skip recording an activity
 *                          item about this blog creation. Default: false.
 * @return bool|null Returns false on failure.
 */
function bp_blogs_record_blog($blog_id, $user_id, $no_activity = false)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // If blog is not recordable, do not record the activity.
    if (!bp_blogs_is_blog_recordable($blog_id, $user_id)) {
        return false;
    }
    $name = get_blog_option($blog_id, 'blogname');
    $url = get_home_url($blog_id);
    if (empty($name)) {
        $name = $url;
    }
    $description = get_blog_option($blog_id, 'blogdescription');
    $close_old_posts = get_blog_option($blog_id, 'close_comments_for_old_posts');
    $close_days_old = get_blog_option($blog_id, 'close_comments_days_old');
    $thread_depth = get_blog_option($blog_id, 'thread_comments');
    if (!empty($thread_depth)) {
        $thread_depth = get_blog_option($blog_id, 'thread_comments_depth');
    } else {
        // Perhaps filter this?
        $thread_depth = 1;
    }
    $recorded_blog = new BP_Blogs_Blog();
    $recorded_blog->user_id = $user_id;
    $recorded_blog->blog_id = $blog_id;
    $recorded_blog_id = $recorded_blog->save();
    $is_recorded = !empty($recorded_blog_id) ? true : false;
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'url', $url);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'name', $name);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'description', $description);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'last_activity', bp_core_current_time());
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'close_comments_days_old', $close_days_old);
    bp_blogs_update_blogmeta($recorded_blog->blog_id, 'thread_comments_depth', $thread_depth);
    $is_private = !empty($_POST['blog_public']) && (int) $_POST['blog_public'] ? false : true;
    /**
     * Filters whether or not a new blog is public.
     *
     * @since 1.5.0
     *
     * @param bool $is_private Whether or not blog is public.
     */
    $is_private = !apply_filters('bp_is_new_blog_public', !$is_private);
    /**
     * Fires after BuddyPress has been made aware of a new site for activity tracking.
     *
     * @since 1.0.0
     * @since 2.6.0 Added $no_activity as a parameter.
     *
     * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference.
     * @param bool          $is_private    Whether or not the current blog being recorded is private.
     * @param bool          $is_recorded   Whether or not the current blog was recorded.
     * @param bool          $no_activity   Whether to skip recording an activity item for this blog creation.
     */
    do_action_ref_array('bp_blogs_new_blog', array(&$recorded_blog, $is_private, $is_recorded, $no_activity));
}