Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit 97e9b16151cb321ba9782eee94b1509853d5e1e5
Showing with 324 additions and 0 deletions.
  1. +97 −0 admin/bp-activity-block-admin.php
  2. +58 −0 bp-activity-block-loader.php
  3. +63 −0 bp-activity-block.php
  4. +106 −0 readme.txt
@@ -0,0 +1,97 @@
+<?php
+
+function etivite_bp_activity_block_admin_unique_types( ) {
+ global $bp, $wpdb;
+
+ $count = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT a.type FROM {$bp->activity->table_name} a ORDER BY a.date_recorded DESC" ) );
+
+ return $count;
+}
+
+function etivite_bp_activity_block_admin() {
+ global $bp;
+
+ /* If the form has been submitted and the admin referrer checks out, save the settings */
+ if ( isset( $_POST['submit'] ) && check_admin_referer('etivite_bp_activity_block_admin') ) {
+
+ if( isset($_POST['ab_activity_block_types'] ) && !empty($_POST['ab_activity_block_types']) ) {
+
+ $unfiltered_types = explode( ',', $_POST['ab_activity_block_types'] );
+
+ foreach( (array) $unfiltered_types as $type ) {
+ if ( !empty( $type ) )
+ $types[] = trim( $type );
+ }
+
+ if ($types) update_option( 'bp_activity_block_denied_activity_types', $types );
+
+ } else {
+ update_option( 'bp_activity_block_denied_activity_types', '' );
+ }
+
+ $updated = true;
+ }
+
+ // Get the proper URL for submitting the settings form. (Settings API workaround) - boone
+ $url_base = function_exists( 'is_network_admin' ) && is_network_admin() ? network_admin_url( 'admin.php?page=bp-activity-block-settings' ) : admin_url( 'admin.php?page=bp-activity-block-settings' );
+?>
+ <div class="wrap">
+ <h2><?php _e( 'Activity Block Admin', 'bp-activity-block' ); ?></h2>
+
+ <?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-activity-block' ) . "</p></div>"; endif; ?>
+
+ <div id="message" class="updated">WARNING: Using this plugin will block activity stream entries defined by their types from being saved to the database. There is no recovery or reverting. You have been warned. :-) It is advised NOT to block activity_comment and activity_update activities (will cause errors in buddypress)</div>
+
+ <form action="<?php echo $url_base ?>" name="bp-activity-block-settings-form" id="bp-activity-block-settings-form" method="post">
+
+ <h5><?php _e( 'Activity Types Found', 'bp-activity-block' ); ?></h5>
+ <p class="description">This list is pull from the activity table database (previously logged activity) - so you may need to find other types (in bp and plugins)</p>
+
+ <p><?php
+
+ $currenttypes = (array) get_option( 'bp_activity_block_denied_activity_types');
+
+ $uniquetypes = etivite_bp_activity_block_admin_unique_types();
+
+ foreach ($uniquetypes as $types) {
+ if ($types->type != 'activity_comment' && $types->type != 'activity_update' ) echo $types->type .'<br/>';
+ } ?></p>
+
+ <h5><?php _e( 'Activity Types to Exclude', 'bp-activity-block' ); ?></h5>
+
+ <table class="form-table">
+ <th><label for="ab_activity_block_types"><?php _e( "Blocked Activity Types:", 'bp-activity-block' ) ?></label> </th>
+ <td><textarea rows="5" cols="50" name="ab_activity_block_types" id="ab_activity_block_types"><?php echo esc_attr( implode( ', ', $currenttypes ) ) ?></textarea><br/><?php _e( "Seperate types with commas.", 'bp-activity-block' ) ?></td>
+ </table>
+
+ <?php wp_nonce_field( 'etivite_bp_activity_block_admin' ); ?>
+
+ <p class="submit"><input type="submit" name="submit" value="Save Settings"/></p>
+
+ </form>
+
+ <h3>About:</h3>
+ <div id="plugin-about" style="margin-left:15px;">
+
+ <p>
+ <a href="http://etivite.com/wordpress-plugins/buddypress-block-activity-stream-types/">Block Activity Stream Types - About Page</a><br/>
+ </p>
+
+ <div class="plugin-author">
+ <strong>Author:</strong> <a href="http://profiles.wordpress.org/users/etivite/"><img style="height: 24px; width: 24px;" class="photo avatar avatar-24" src="http://www.gravatar.com/avatar/9411db5fee0d772ddb8c5d16a92e44e0?s=24&amp;d=monsterid&amp;r=g" alt=""> rich @etivite</a><br/>
+ <a href="http://twitter.com/etivite">@etivite</a>
+ </div>
+
+ <p>
+ <a href="http://etivite.com">Author's site</a><br/>
+ <a href="http://etivite.com/api-hooks/">Developer Hook and Filter API Reference</a><br/>
+ <a href="http://etivite.com/wordpress-plugins/">WordPress Plugins</a><br/>
+ </p>
+ </div>
+
+
+ </div>
+<?php
+}
+
+?>
@@ -0,0 +1,58 @@
+<?php
+/*
+Plugin Name: BuddyPress Block Activity Stream Types
+Plugin URI: http://wordpress.org/extend/plugins/buddypress-block-activity-stream-types/
+Description: Blocks an activity record (based on types) from being saved to the database
+Author: rich @etivite
+Author URI: http://etivite.com
+License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
+Version: 0.5.2
+Text Domain: bp-activity-block
+Network: true
+*/
+
+function etivite_bp_activity_block_init() {
+
+ if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
+ load_textdomain( 'bp-activity-block', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
+
+ require( dirname( __FILE__ ) . '/bp-activity-block.php' );
+
+ add_action( bp_core_admin_hook(), 'etivite_bp_activity_block_admin_add_admin_menu' );
+
+}
+add_action( 'bp_include', 'etivite_bp_activity_block_init', 88 );
+//add_action( 'bp_init', 'etivite_bp_activity_block_init', 88 );
+
+//add admin_menu page
+function etivite_bp_activity_block_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-block-admin.php' );
+
+ add_submenu_page( 'bp-general-settings', __( 'Activity Block Admin', 'bp-activity-block' ), __( 'Activity Block', 'bp-activity-block' ), 'manage_options', 'bp-activity-block-settings', 'etivite_bp_activity_block_admin' );
+}
+
+
+/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
+function etivite_bp_activity_block_admin_add_action_link( $links, $file ) {
+ if ( 'buddypress-block-activity-stream-types/bp-activity-block-loader.php' != $file )
+ return $links;
+
+ if ( function_exists( 'bp_core_do_network_admin' ) ) {
+ $settings_url = add_query_arg( 'page', 'bp-activity-block-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ } else {
+ $settings_url = add_query_arg( 'page', 'bp-activity-block-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ }
+
+ $settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-block' ) . '</a>';
+ array_unshift( $links, $settings_link );
+
+ return $links;
+}
+add_filter( 'plugin_action_links', 'etivite_bp_activity_block_admin_add_action_link', 10, 2 );
+?>
@@ -0,0 +1,63 @@
+<?php
+if ( !defined( 'ABSPATH' ) ) exit;
+
+//omgwtfbbq
+//the only reason this work is that the activity::save checks for if ( !$this->component || !$this->type ) return false; prior to db insert/update
+//we just scan it for our excluded list and null it out. if there is an id, then we know an update is occuring and just exit.
+
+//we can hook on the type filter and null it out
+function etivite_bp_activity_block_type_before_save( $type, &$a ) {
+ global $bp;
+
+ //if there is an id - we don't care... updating
+ if ( $a->id )
+ return $type;
+
+ //Come and see the violence inherent in the system. Help! Help! I'm being repressed!
+ if ( etivite_bp_activity_block_denied_activity_type_check( $a->type, $a->item_id, $a->secondary_item_id, $a->user_id, $a->component ) ) {
+ $a->type = null;
+ return null;
+ }
+
+ //otherwise continue if nothing happened
+ return $type;
+
+}
+function etivite_bp_activity_block_type_reference_before_save( $type, $a ) {
+ global $bp;
+
+ //if there is an id - we don't care... updating
+ if ( $a->id )
+ return $type;
+
+ //Come and see the violence inherent in the system. Help! Help! I'm being repressed!
+ if ( etivite_bp_activity_block_denied_activity_type_check( $a->type, $a->item_id, $a->secondary_item_id, $a->user_id, $a->component ) ) {
+ $a->type = null;
+ return null;
+ }
+
+ //otherwise continue if nothing happened
+ return $type;
+
+}
+//set this low pri so last to hook in - what if someone else is messing around
+//add_filter('bp_activity_type_before_save', 'etivite_bp_activity_block_type_before_save', 9999, 2);
+
+//php issue with reference to this
+//Warning: Parameter 2 to etivite_bp_activity_block_type_before_save() expected to be a reference, value given in [site]\wp-includes\plugin.php on line 166
+if ( version_compare(phpversion(), '5.3.0', 'ge') ) {
+ add_filter('bp_activity_type_before_save', 'etivite_bp_activity_block_type_reference_before_save', 9999, 2);
+} else {
+ add_filter('bp_activity_type_before_save', 'etivite_bp_activity_block_type_before_save', 9999, 2);
+}
+
+
+function etivite_bp_activity_block_denied_activity_type_check( $type, $item_id, $secondary_item_id, $user_id, $component ) {
+
+ $types = (array) maybe_unserialize( get_option( 'bp_activity_block_denied_activity_types') );
+
+ //return in_array( $type, apply_filters( 'etivite_bp_activity_block_denied_activity_types', $types ) );
+ return apply_filters( 'etivite_bp_activity_block_denied_activity_type_check', in_array( $type, apply_filters( 'etivite_bp_activity_block_denied_activity_types', $types ) ), $type, $item_id, $secondary_item_id, $user_id, $component );
+
+}
+?>
@@ -0,0 +1,106 @@
+=== Plugin Name ===
+Contributors: nuprn1, etivite
+Donate link: http://etivite.com/wordpress-plugins/donate/
+Tags: buddypress, activity stream, activity, block activity
+Requires at least: PHP 5.2, WordPress 3.2.1, BuddyPress 1.5.1
+Tested up to: PHP 5.3.x, WordPress 3.2.1, BuddyPress 1.5.1
+Stable tag: 0.5.2
+
+This plugin will "block" an activity record from being saved to the stream/database. Such as new member registration, joining groups, friendships created.
+
+== Description ==
+
+** IMPORTANT **
+This plugin has been updated for BuddyPress 1.5.1
+
+This plugin will "block" an activity record from being saved to the stream/database. Such as new member registration, joining groups, friendships created.
+
+Please note, this will not allow an activity record to be saved into the database at all. You will need to know the "type" of activity record. It is advised NOT to block activity_comment and activity_update activities (will cause errors in buddypress)
+
+What are activity types? BP Core includes several and plugins may register their own when hooking into the activity_record functions. This plugin will scan the activity table for distinct types already logged but will be ever changing due to new plugins.
+
+= Related Links: =
+
+* <a href="http://etivite.com" title="Plugin Demo Site">Author's Site</a>
+* <a href="http://etivite.com/wordpress-plugins/buddypress-block-activity-stream-types/">BuddyPress Block Activity Stream Types - 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
+3. Adjust settings via the Activity Block admin page
+
+== Frequently Asked Questions ==
+
+= How do I exclude a certain activity types? =
+
+You may scan the bp-core code, plugin code, or attempt to view the types already entered into the database.
+
+= How does it work? =
+
+When bp-core or a plugin attempts to record a new activity - this plugin will block the database insert (by nulling out the type prior to saving - bp_activity_type_before_save )
+
+= I blocked a type but the filter still appears in my theme in the dropdown select box =
+
+Certain types are hardcoded into the theme file bp-default/activity/index.php - you may need to remove the html select option
+
+Some plugins may register the do_action( 'bp_activity_filter_options' ) - there is no way to filter these out automatically and may require editing the plugin's core files - remove the action hook.
+
+= I blocked a type but still see the old activity records =
+
+This plugin does not remove previous logged activity items - you'll need to manually delete these.
+
+= I want to block a certain blog on my network from sending activity stream updates =
+
+You may hook on the filter `bp_activity_block_denied_activity_type_check` which provides all activity level data. From here you can provide your own logic to block an activity record. ie, blog_id
+
+See this forum thread for details: http://etivite.com/groups/buddypress/forum/topic/quick-tip-hooking-block-activity-stream-types-plugin-on-a-granular-level/
+
+= I want to unblock a type and see all the old activity records =
+
+Sorry, since you blocked certain types from the database - nothing was ever saved to begin with.
+
+
+= My question isn't answered here =
+
+Please contact me on http://etivite.com
+
+
+== Changelog ==
+
+= 0.5.2 =
+
+* BUG: php notice on secondary_item_id in filter
+
+= 0.5.1 =
+
+* BUG: fix network admin settings page on multisite
+* FEATURE: support for locale mo files
+
+= 0.5.0 =
+
+* BUG: updated for BuddyPress 1.5.1
+
+= 0.3.0 =
+
+* Feature: New filter hook to allow granular blocking (ie block on a per blog_id)
+
+= 0.2.0 =
+
+* Bug: Invalid reference on PHP 5.3.x
+
+= 0.1.0 =
+
+* First [BETA] version
+
+
+== Upgrade Notice ==
+
+= 0.5.0 =
+* BuddyPress 1.5.1 and higher - required.
+
+== Extra Configuration ==
+
+See this forum thread for details on hooking the type check: http://etivite.com/groups/buddypress/forum/topic/quick-tip-hooking-block-activity-stream-types-plugin-on-a-granular-level/

0 comments on commit 97e9b16

Please sign in to comment.