/** * Add a follow button to the footer. * * Also adds a "Home" link, which links to the activity directory's "Sites I * Follow" tab. * * This UI mimics Tumblr's. */ public function add_follow_button_to_footer() { if (!is_user_logged_in()) { return; } // If blog is not recordable, do not show button if (!bp_blogs_is_blog_recordable(get_current_blog_id(), bp_loggedin_user_id())) { return; } // disable the footer button using this filter if needed if (false === self::show_footer_button()) { return; } // remove inline CSS later... still testing ?> <style type="text/css"> #bpf-blogs-ftr{ position:fixed; bottom:5px; right: 5px; z-index:9999; text-align:right; } #bpf-blogs-ftr a { font: 600 12px/18px "Helvetica Neue","HelveticaNeue",Helvetica,Arial,sans-serif !important; color: #fff !important; text-decoration:none !important; background:rgba(0, 0, 0, 0.48); padding:2px 5px !important; border-radius: 4px; } #bpf-blogs-ftr a:hover { background:rgba(0, 0, 0, 0.42); } #bpf-blogs-ftr a:before { position: relative; top: 3px; font: normal 13px/1 'dashicons'; padding-right:5px; } #bpf-blogs-ftr a.follow:before { content: "\f132"; } #bpf-blogs-ftr a.unfollow:before { content: "\f460"; } #bpf-blogs-ftr a.home:before { content: "\f155"; top: 2px; } </style> <div id="bpf-blogs-ftr"> <?php echo self::get_button(array('leader_id' => get_current_blog_id(), 'wrapper' => false)); ?> <?php $btn_args = apply_filters('bp_follow_blogs_get_sites_button_args', array('class' => 'home', 'link' => bp_loggedin_user_domain() . bp_get_blogs_slug() . '/' . constant('BP_FOLLOW_BLOGS_USER_FOLLOWING_SLUG') . '/', 'text' => _x('Followed Sites', 'Footer button', 'bp-follow'))); if (!empty($btn_args) && is_array($btn_args)) { echo '<a class=' . esc_attr($btn_args['class']) . ' href=' . esc_url($btn_args['link']) . '>'; echo $btn_args['text']; echo '</a>'; } ?> </div> <?php }
/** * 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)); }
/** * 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; defaults to false * @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(); } // 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'); $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 && 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, '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_home_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_home_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)); }
/** * 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)); }