Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit 895e69e8bbd914e243737b79687cdc3d62350e97
Showing with 266 additions and 0 deletions.
  1. +5 −0 admin/bp-activity-atgroups-admin.php
  2. +85 −0 bp-activity-atgroups-loader.php
  3. +125 −0 bp-activity-atgroups.php
  4. +51 −0 readme.txt
@@ -0,0 +1,5 @@
<?php
//something
?>
@@ -0,0 +1,85 @@
<?php
/*
Plugin Name: BuddyPress Activity Stream AtGroups
Plugin URI: http://wordpress.org/extend/plugins/buddypress-activity-stream-atgroups/
Description: Enable @(group_slug) linking and =(group_slug) updates within activity stream content
Author: rich @etiviti
Author URI: http://etivite.com
License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
Version: 0.1.0
Text Domain: bp-activity-atgroups
Network: true
*/
//ability to select different 'regex triggers'
//mention count/search activity page
function etivite_bp_activity_atgroups_init() {
if ( !bp_is_active( 'activity' ) && bp_is_active( 'groups' ) )
return;
if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
load_textdomain( 'bp-activity-atgroups', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
require( dirname( __FILE__ ) . '/bp-activity-atgroups.php' );
$data = maybe_unserialize( get_option( 'etivite_bp_activity_atgroups' ) );
if ( $data['postit'] ) {
add_filter( 'bp_activity_before_save', 'etivite_bp_activity_atgroups_postit_filter_updates' );
}
if ( $data['mention'] ) {
add_filter( 'bp_activity_after_save', 'etivite_bp_activity_atgroups_at_name_filter_updates' );
add_filter( 'pre_comment_content', 'etivite_bp_activity_atgroups_at_name_filter' );
add_filter( 'group_forum_topic_text_before_save', 'etivite_bp_activity_atgroups_at_name_filter' );
add_filter( 'group_forum_post_text_before_save', 'etivite_bp_activity_atgroups_at_name_filter' );
add_filter( 'bp_get_activity_content_body', 'etivite_bp_activity_atgroups_at_name_filter' );
}
add_action( bp_core_admin_hook(), 'etivite_bp_activity_atgroups_admin_add_admin_menu' );
}
add_action( 'bp_include', 'etivite_bp_activity_atgroups_init', 88 );
//add_action( 'bp_init', 'etivite_bp_activity_atgroups_init', 88 );
//add admin_menu page
function etivite_bp_activity_atgroups_admin_add_admin_menu() {
global $bp;
if ( !is_super_admin() )
return false;
//Add the component's administration tab under the "BuddyPress" menu for site administrators
//require ( dirname( __FILE__ ) . '/admin/bp-activity-atgroups-admin.php' );
//add_submenu_page( 'bp-general-settings', __( 'Activity AtGroups Admin', 'bp-activity-atgroups' ), __( 'Activity AtGroups', 'bp-activity-atgroups' ), 'manage_options', 'bp-activity-atgroups-settings', 'etivite_bp_activity_atgroups_admin' );
//set up defaults
$new = Array();
$new['postit'] = true;
$new['mention'] = true;
add_option( 'etivite_bp_activity_atgroups', $new );
}
/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
function etivite_bp_activity_atgroups_admin_add_action_link( $links, $file ) {
if ( 'buddypress-activity-stream-atgroups/bp-activity-atgroups-loader.php' != $file )
return $links;
if ( function_exists( 'bp_core_do_network_admin' ) ) {
$settings_url = add_query_arg( 'page', 'bp-activity-atgroups-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
} else {
$settings_url = add_query_arg( 'page', 'bp-activity-atgroups-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
}
$settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-atgroups' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'etivite_bp_activity_atgroups_admin_add_action_link', 10, 2 );
?>
@@ -0,0 +1,125 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function etivite_bp_activity_atgroups_find_group_mentions( $content ) {
$pattern = '/[@][\(]+([A-Za-z0-9-_\.@]+)[\)]/';
preg_match_all( $pattern, $content, $usernames );
// Make sure there's only one instance of each username
if ( !$usernames = array_unique( $usernames[1] ) )
return false;
return $usernames;
}
function etivite_bp_activity_atgroups_at_name_filter( $content, $activity_id = 0 ) {
$groupnames = etivite_bp_activity_atgroups_find_group_mentions( $content );
foreach( (array)$groupnames as $groupname ) {
$group_id = BP_Groups_Group::group_exists( $groupname );
if ( empty( $group_id ) )
continue;
$content = preg_replace( '/[@][\(]'. $groupname .'\b[\)]/', "<a href='" . bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $groupname . '/' . "' rel='nofollow'>@($groupname)</a>", $content );
}
return $content;
}
function etivite_bp_activity_atgroups_at_name_filter_updates( $activity ) {
// Only run this function once for a given activity item
remove_filter( 'bp_activity_after_save', 'etivite_bp_activity_atgroups_at_name_filter_updates' );
// Run the content through the linking filter, making sure to increment mention count
$activity->content = etivite_bp_activity_atgroups_at_name_filter( $activity->content, $activity->id );
// Resave the activity with the new content
$activity->save();
}
function etivite_bp_activity_atgroups_postit_filter_updates( $activity ) {
global $bp;
//bail if activity already exists
if ( $activity->id )
return;
//only care about activity updates
if ( $activity->type != 'activity_update' )
return;
//discard if already a group update
if ( !empty( $activity->item_id ) )
return;
// Only run this function once for a given activity item
remove_filter( 'bp_activity_before_save', 'etivite_bp_activity_atgroups_postit_filter_updates' );
$content = $activity->content;
$pattern = '/[=][\(]+([A-Za-z0-9-_\.@]+)[\)]/';
preg_match_all( $pattern, $content, $groupnames );
//no match, no care
if ( !$groupnames[1] )
return;
//Make sure there's only one instance of each username
if ( !$groupnames = array_unique( $groupnames[1] ) )
return;
//find the pushto group - log the first valid instance
foreach( (array)$groupnames as $groupname ) {
$group_id = BP_Groups_Group::group_exists( $groupname );
if ( empty( $group_id ) )
continue;
//if match - push it for later
if ( empty( $first_group_id ) )
$first_group_id = $group_id;
$activity->content = preg_replace( '/[=][\(]'. $groupname .'\b[\)]/', "<a href='" . bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $groupname . '/' . "' rel='nofollow'>@($groupname)</a>", $content );
}
//mimic the stream and update functions from core from this point on...
if ( empty( $activity->content ) || !strlen( trim( $activity->content ) ) || empty( $activity->user_id ) || empty( $first_group_id ) )
return;
//failsafe is something went fubar
if ( !$bp->groups->current_group = new BP_Groups_Group( $first_group_id ) )
return;
// Be sure the user is a member of the group before posting.
if ( !is_super_admin() && !groups_is_user_member( $user_id, $first_group_id ) )
return;
// If the group is not public, hide the activity sitewide.
if ( isset( $bp->groups->current_group->status ) && 'public' == $bp->groups->current_group->status )
$hide_sitewide = false;
else
$hide_sitewide = true;
$activity_action = sprintf( __( '%1$s posted an update in the group %2$s', 'buddypress'), bp_core_get_userlink( $activity->user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
$activity->action = apply_filters( 'groups_activity_new_update_action', $activity_action );
$activity->content = apply_filters( 'groups_activity_new_update_content', $activity->content );
$activity->item_id = $first_group_id;
$activity->component = $bp->groups->id;
$activity->primary_link = '';
$activity->secondary_item_id = false;
$activity->recorded_time = bp_core_current_time();
$activity->hide_sitewide = $hide_sitewide;
//make it believe
groups_update_groupmeta( $first_group_id, 'last_activity', bp_core_current_time() );
}
?>
@@ -0,0 +1,51 @@
=== Plugin Name ===
Contributors: nuprn1, etivite
Donate link: http://etivite.com/wordpress-plugins/donate/
Tags: buddypress, activity stream, activity, groups
Requires at least: PHP 5.2, WordPress 3.2.1, BuddyPress 1.5.1
Tested up to: PHP 5.2.x, WordPress 3.2.1, BuddyPress 1.5.1
Stable tag: 0.1.0
This plugin will link @(group_slug) syntax to group home page and/or use =(group_slug) to post an update to group
== Description ==
This plugin will link @(group_slug) syntax to group home page and/or use =(group_slug) to post an update to group
future plans:
* own pattern matching
* admin page to disable atmention and postto
= Related Links: =
* <a href="http://etivite.com" title="Plugin Demo Site">Author's Site</a>
* <a href="http://etivite.com/wordpress-plugins/buddypress-activity-stream-atgroups/">BuddyPress Activity Stream @(Groups) - About Page</a>
* <a href="http://etivite.com/api-hooks/">BuddyPress and bbPress Developer Hook and Filter API Reference</a>
* <a href="http://twitter.com/etivite">@etivite</a> <a href="https://plus.google.com/114440793706284941584?rel=author">etivite+</a>
== Installation ==
1. Upload the full directory into your wp-content/plugins directory
2. Activate the plugin at the plugin administration page
== Frequently Asked Questions ==
= What pattern is matched? =
* Metnions: @(group_slug)
* Post Update to group: =(group_slug)
= My question isn't answered here =
Please contact me on http://etivite.com
== Changelog ==
= 0.1.0 =
* First version
== Extra Configuration ==

0 comments on commit 895e69e

Please sign in to comment.