Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit 4552f71d0fb33a2409b92306ee38ae12842be6bf
Showing with 444 additions and 0 deletions.
  1. +51 −0 _inc/js/bp-activity-ajax.js
  2. +73 −0 admin/bp-activity-ajax-admin.php
  3. +63 −0 bp-activity-ajax-loader.php
  4. +110 −0 bp-activity-ajax-process.php
  5. +56 −0 bp-activity-ajax.php
  6. +91 −0 readme.txt
@@ -0,0 +1,51 @@
+jQuery(document).ready( function() {
+
+ if ( jQuery("input#_wpnonce_activity_filter") && jQuery("input#date_recorded") ) {
+
+ var gid = '';
+ var uid = '';
+ var ca = '';
+
+ setInterval(function() {
+
+ if ( jQuery("input#gid").val() )
+ gid = jQuery("input#gid").val();
+
+ if ( jQuery("input#uid").val() )
+ uid = jQuery("input#uid").val();
+
+ if ( jQuery("input#ca").val() )
+ ca = jQuery("input#ca").val();
+
+ jQuery.post( ajaxurl, {
+ action: 'bpactivity_ajax',
+ timeout: 1500,
+ cache: false,
+ '_wpnonce' : jQuery("input#_wpnonce_activity_filter").val(),
+ 'cookie': encodeURIComponent(document.cookie),
+ 'gid' : gid,
+ 'uid' : uid,
+ 'ca' : ca,
+ 'checkdate' : jQuery("input#date_recorded").val(),
+ 'checkobject': 'activity',
+ },
+ function( data ) {
+
+ if ( data && parseInt( data ) > 0 ) {
+
+ if (jQuery('#activity-stream li').first().attr( 'id' ) == 'activity-' + data ) {
+ } else {
+ jQuery('#activity-notifier').attr("href", window.location.href);
+ jQuery('#activity-notifier').slideDown();
+ }
+
+ }
+
+ });
+
+ return false;
+ }, BPAA.streamajaxtimeout ); // timeout polling
+
+ }
+
+});
@@ -0,0 +1,73 @@
+<?php
+
+function etivite_bp_activity_ajax_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_ajax_admin') ) {
+
+ $new = array();
+
+ if( isset( $_POST['ab_activity_ajax_time'] ) && !empty( $_POST['ab_activity_ajax_time'] ) && $_POST['ab_activity_ajax_time'] > 5000 ) {
+ $new['ajaxtimeout'] = $_POST['ab_activity_ajax_time'];
+ } else {
+ $new['ajaxtimeout'] = 60000;
+ }
+
+ update_option( 'etivite_bp_activity_ajax', $new );
+
+ $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-ajax-settings' ) : admin_url( 'admin.php?page=bp-activity-ajax-settings' );
+
+ $data = get_option( 'etivite_bp_activity_ajax', array( 'ajaxtimeout' => 60000 ) );
+
+?>
+ <div class="wrap">
+ <h2><?php _e( 'Activity Ajax Notifier Admin', 'bp-activity-ajax' ); ?></h2>
+
+ <?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-activity-ajax' ) . "</p></div>"; endif; ?>
+
+ <form action="<?php echo $url_base; ?>" name="bp-activity-ajax-settings-form" id="bp-activity-ajax-settings-form" method="post">
+
+ <h5><?php _e( 'Ajax Polling Timeout', 'bp-activity-ajax' ); ?></h5>
+
+ <table class="form-table">
+ <th><label for="ab_activity_ajax_time"><?php _e( "Time length (milliseconds):", 'bp-activity-ajax' ) ?></label> </th>
+ <td><input type="text" name="ab_activity_ajax_time" id="ab_activity_ajax_time" value="<?php echo $data['ajaxtimeout']; ?>"/></td>
+ </table>
+
+ <p class="description">Default polling time between new activity checks is 1 second (60000 milliseconds) min: 5000 ms</p>
+
+ <?php wp_nonce_field( 'etivite_bp_activity_ajax_admin' ); ?>
+
+ <p class="submit"><input type="submit" name="submit" value="<?php _e('Save Settings','bp-activity-ajax') ?>"/></p>
+
+ </form>
+
+ <h3>About:</h3>
+ <div id="plugin-about" style="margin-left:15px;">
+
+ <p>
+ <a href="http://etivite.com/wordpress-plugins/buddypress-activity-stream-ajax-notifier/">BuddyPress Activity Stream Ajax Notifier - 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> <a href="https://plus.google.com/114440793706284941584">+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,63 @@
+<?php
+/*
+Plugin Name: BuddyPress Activity Stream Ajax Notifier
+Plugin URI: http://wordpress.org/extend/plugins/buddypress-activity-stream-ajax-notifier/
+Description: Adds a timed ajax notification when the activity stream has an update.
+Author: rich @etivite
+Author URI: http://etivite.com
+License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
+Version: 0.1.2
+Text Domain: bp-activity-ajax
+Network: true
+*/
+
+function etivite_bp_activity_ajax_init() {
+ global $bp;
+
+ if ( !is_user_logged_in() )
+ return;
+
+ if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
+ load_textdomain( 'bp-activity-ajax', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
+
+ require( dirname( __FILE__ ) . '/bp-activity-ajax-process.php' );
+
+ require( dirname( __FILE__ ) . '/bp-activity-ajax.php' );
+
+ add_action( bp_core_admin_hook(), 'etivite_bp_activity_ajax_admin_add_admin_menu' );
+
+}
+add_action( 'bp_include', 'etivite_bp_activity_ajax_init', 88 );
+//add_action( 'bp_init', 'etivite_bp_activity_ajax_init', 88 );
+
+//add admin_menu page
+function etivite_bp_activity_ajax_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-ajax-admin.php' );
+
+ add_submenu_page( 'bp-general-settings', __( 'Activity Notifier', 'bp-activity-ajax' ), __( 'Activity Notifier', 'bp-activity-ajax' ), 'manage_options', 'bp-activity-ajax-settings', 'etivite_bp_activity_ajax_admin' );
+}
+
+/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
+function etivite_bp_activity_ajax_admin_add_action_link( $links, $file ) {
+ if ( 'buddypress-activity-stream-ajax-notifier/bp-activity-ajax-loader.php' != $file )
+ return $links;
+
+ if ( function_exists( 'bp_core_do_network_admin' ) ) {
+ $settings_url = add_query_arg( 'page', 'bp-activity-ajax-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ } else {
+ $settings_url = add_query_arg( 'page', 'bp-activity-ajax-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ }
+
+ $settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-ajax' ) . '</a>';
+ array_unshift( $links, $settings_link );
+
+ return $links;
+}
+add_filter( 'plugin_action_links', 'etivite_bp_activity_ajax_admin_add_action_link', 10, 2 );
+?>
@@ -0,0 +1,110 @@
+<?php
+function etivite_bp_activity_ajax_process_ajax() {
+ if ( $_POST['checkobject'] == 'activity' )
+ etivite_bp_activity_ajax_process_ajax_check_newactivity();
+
+ die();
+}
+add_action( 'wp_ajax_bpactivity_ajax', 'etivite_bp_activity_ajax_process_ajax' );
+
+function etivite_bp_activity_ajax_process_ajax_check_newactivity() {
+ global $bp;
+
+ if ( !is_user_logged_in() )
+ die();
+
+ check_ajax_referer("activity_filter");
+
+ $object = $_POST['checkobject'];
+ $_BP_COOKIE = &$_COOKIE;
+ $qs = false;
+
+
+ //hijack the system
+ if ( isset($_POST['gid'] ) && !empty($_POST['gid']) ) {
+ $bp->groups->current_group = new BP_Groups_Group( (int)$_POST['gid'] );
+ $object = 'groups';
+ }
+ if ( isset($_POST['uid'] ) && !empty($_POST['uid']) ) {
+ $bp->displayed_user->id = (int)$_POST['uid'];
+ $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
+ }
+ if ( isset($_POST['ca'] ) && !empty($_POST['ca']) )
+ $bp->current_action = $_POST['ca'];
+
+
+ /* If page and search_terms have been passed via the AJAX post request, use those */
+ if ( !empty( $_BP_COOKIE['bp-' . $object . '-page'] ) )
+ die();
+
+ if ( !empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
+ $qs[] = 'type=' . $_BP_COOKIE['bp-' . $object . '-filter'];
+ $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter']; // Activity stream filtering on action
+ }
+
+ if ( !empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
+ if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
+ $qs[] = 'user_id=' . $user_id;
+ $qs[] = 'scope=just-me';
+ }
+ if ( 'personal' != $_BP_COOKIE['bp-' . $object . '-scope'] && 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && empty( $bp->displayed_user->id ) )
+ $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope']; // Activity stream scope only on activity directory.
+ }
+
+ if ( !empty( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) )
+ $qs[] = 'search_terms=' . $_BP_COOKIE['bp-' . $object . '-search-terms'];
+
+ $qs[] = 'max=1';
+ //$qs[] = 'object='. $object;
+
+ /* Now pass the querystring to override default values. */
+ $query_string = empty( $qs ) ? '' : join( '&', (array)$qs );
+
+ //pass it into a query - grab date_created stuff and compare to posted date
+ if ( bp_has_activities( $query_string ) ) {
+
+ if ( etivite_bp_activity_ajax_check_activity_date_recorded( $_POST['checkdate'] ) ) {
+ echo etivite_bp_activity_ajax_get_activity_id();
+ } else {
+ echo '-1';
+ }
+ } else {
+ echo '-1';
+ }
+
+}
+
+function etivite_bp_activity_ajax_get_activity_id() {
+ global $activities_template;
+
+ if ( !$activities_template->activities )
+ return 0;
+
+ return $activities_template->activities[0]->id;
+}
+
+function etivite_bp_activity_ajax_get_activity_date_recorded() {
+ global $activities_template;
+
+ if ( !$activities_template->activities )
+ return 0;
+
+ return $activities_template->activities[0]->date_recorded;
+}
+
+function etivite_bp_activity_ajax_check_activity_date_recorded( $ajax_date_recorded ) {
+ global $activities_template;
+
+ if ( !$ajax_date_recorded )
+ return false;
+
+ if ( !$activities_template->activities )
+ return false;
+
+ if ( strtotime( $activities_template->activities[0]->date_recorded ) > $ajax_date_recorded )
+ return true;
+
+ return false;
+}
+?>
@@ -0,0 +1,56 @@
+<?php
+function etivite_bp_activity_ajax_after_activity_loop() {
+ global $bp;
+
+ echo '<form method="post" id="activity-loop-ajax" name="activity-loop-ajax" action="">';
+ echo '<input type="hidden" value="'. strtotime( etivite_bp_activity_ajax_get_activity_date_recorded() ) .'" name="date_recorded" id="date_recorded">';
+
+ if ( !empty( $bp->groups->current_group ) )
+ echo '<input type="hidden" value="'. $bp->groups->current_group->id .'" name="gid" id="gid">';
+
+ if ( $bp->displayed_user->id )
+ echo '<input type="hidden" value="'. $bp->displayed_user->id .'" name="uid" id="uid">';
+
+ if ( 'just-me' == $bp->current_action || 'friends' == $bp->current_action || 'groups' == $bp->current_action || 'favorites' == $bp->current_action || 'mentions' == $bp->current_action )
+ echo '<input type="hidden" value="'. $bp->current_action .'" name="ca" id="ca">';
+
+ echo '</form>';
+}
+add_action( 'bp_after_activity_loop', 'etivite_bp_activity_ajax_after_activity_loop', 50 );
+
+function etivite_bp_activity_ajax_notifier() {
+ global $bp;
+
+ if ( !is_user_logged_in() )
+ return;
+
+ echo '<div class="info" id="activity-notifier" style="display: none;"><a href="" id="activity-notifier-link" style="display:block">'. __('New activity update. Refresh the page.', 'bp-activity-ajax') .'</a></div>';
+}
+add_action( 'bp_before_activity_loop', 'etivite_bp_activity_ajax_notifier', 50 );
+
+function etivite_bp_activity_ajax_head() {
+ echo '<style>#activity-notifier { margin-top:10px; margin-bottom:15px; } #activity-notifier-link { background-color:#E3F1FA; border-color:#C6E4F2; border-style:solid; border-width:1px 0; color:#222222 !important; padding:0.5em 1em; text-shadow:0 1px 1px rgba(255, 255, 255, 0.5); }</style>';
+}
+add_action( 'bp_head', 'etivite_bp_activity_ajax_head', 50 );
+
+
+function etivite_bp_activity_ajax_enqueue_scripts() {
+ global $bp;
+
+ if ( !bp_is_current_action( $bp->activity->slug ) && !bp_is_activity_front_page() && !bp_is_activity_component() && !bp_is_group_activity() && !bp_is_group_home() )
+ return;
+
+ $version = '20111013';
+ $data = get_option( 'etivite_bp_activity_ajax', array( 'ajaxtimeout' => 60000 ) );
+
+ wp_enqueue_script( 'etivite_bp_activity_ajax_notifier', WP_PLUGIN_URL .'/'. basename( dirname( __FILE__ ) ). '/_inc/js/bp-activity-ajax.js', array( 'jquery' ), $version );
+
+ $params = array(
+ 'streamajaxtimeout' => $data['ajaxtimeout']
+ );
+
+ wp_localize_script( 'etivite_bp_activity_ajax_notifier', 'BPAA', $params );
+}
+add_action( 'wp_enqueue_scripts', 'etivite_bp_activity_ajax_enqueue_scripts' );
+
+?>
Oops, something went wrong.

0 comments on commit 4552f71

Please sign in to comment.