Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit fd7340dbd37cf21d7647e812221e8c238761a213
Showing with 478 additions and 0 deletions.
  1. +64 −0 admin/bp-activity-edit-admin.php
  2. +57 −0 bp-activity-edit-loader.php
  3. +219 −0 bp-activity-edit.php
  4. +88 −0 readme.txt
  5. +50 −0 templates/activity/activity-edit.php
@@ -0,0 +1,64 @@
<?php
function etivite_bp_edit_activity_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_edit_activity_admin') ) {
if( isset( $_POST['ab_activity_edit_time'] ) && !empty( $_POST['ab_activity_edit_time'] ) ) {
update_option( 'etivite_bp_edit_activity_lock_date', $_POST['ab_activity_edit_time'] );
} else {
update_option( 'etivite_bp_edit_activity_lock_date', '+30 Minutes' );
}
$updated = true;
}
?>
<div class="wrap">
<h2><?php _e( 'Activity Edit Admin', 'bp-activity-edit' ); ?></h2>
<?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-activity-edit' ) . "</p></div>"; endif; ?>
<form action="<?php echo network_admin_url('admin.php?page=bp-activity-edit-settings'); ?>" name="bp-activity-edit-settings-form" id="bp-activity-edit-settings-form" method="post">
<h5><?php _e( 'Activity Edit Timeout', 'bp-activity-edit' ); ?></h5>
<table class="form-table">
<th><label for="ab_activity_edit_time"><?php _e( "Time length:", 'bp-activity-edit' ) ?></label> </th>
<td><input type="text" name="ab_activity_edit_time" id="ab_activity_edit_time" value="<?php echo get_option( 'etivite_bp_edit_activity_lock_date'); ?>"/></td>
</table>
<p class="description">Please Note: Time length uses <a href="http://www.php.net/manual/en/datetime.formats.relative.php">Relative Formats</a>; such as: +30 Minutes +1 Hour +2 Hours +1 week +3 Weeks +1 Month +2 Years</p>
<?php wp_nonce_field( 'etivite_bp_edit_activity_admin' ); ?>
<p class="submit"><input type="submit" name="submit" value="<?php _e('Save Settings','bp-activity-edit') ?>"/></p>
</form>
<h3>About:</h3>
<div id="plugin-about" style="margin-left:15px;">
<p>
<a href="http://etivite.com/wordpress-plugins/buddypress-edit-activity-stream/">BuddyPress Edit Activity Stream 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,57 @@
<?php
/*
Plugin Name: BuddyPress Edit Activity Stream
Plugin URI: http://wordpress.org/extend/plugins/buddypress-edit-activity-stream/
Description: Allow user (set timeout) and admins to edit activity updates
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.1
Text Domain: bp-activity-edit
Network: true
*/
function etivite_bp_edit_activity_init() {
if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
load_textdomain( 'bp-activity-edit', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
require( dirname( __FILE__ ) . '/bp-activity-edit.php' );
add_action( bp_core_admin_hook(), 'etivite_bp_edit_activity_admin_add_admin_menu' );
}
add_action( 'bp_include', 'etivite_bp_edit_activity_init', 88 );
//add_action( 'bp_init', 'etivite_bp_edit_activity_init', 88 );
//add admin_menu page
function etivite_bp_edit_activity_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-edit-admin.php' );
add_submenu_page( 'bp-general-settings', __( 'Activity Edit Admin', 'bp-activity-edit' ), __( 'Activity Edit', 'bp-activity-edit' ), 'manage_options', 'bp-activity-edit-settings', 'etivite_bp_edit_activity_admin' );
}
/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
function etivite_bp_edit_activity_admin_add_action_link( $links, $file ) {
if ( 'buddypress-edit-activity-stream/bp-activity-edit-loader.php' != $file )
return $links;
if ( function_exists( 'bp_core_do_network_admin' ) ) {
$settings_url = add_query_arg( 'page', 'bp-activity-edit-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
} else {
$settings_url = add_query_arg( 'page', 'bp-activity-edit-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
}
$settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-edit' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'etivite_bp_edit_activity_admin_add_action_link', 10, 2 );
?>
@@ -0,0 +1,219 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function etivite_bp_edit_activity_add_edit_link() {
global $bp;
if ( !bp_activity_user_can_delete() )
return;
//not for forums posts/topics - already auto updates on forum edits
if ( 'new_forum_topic' == bp_get_activity_type() || 'new_forum_post' == bp_get_activity_type() )
return;
//not for minor updates... status only
if ( !$bp->loggedin_user->is_super_admin && bp_get_activity_user_id() == $bp->loggedin_user->id && 'activity_update' != bp_get_activity_type() )
return;
//$bp->is_item_admin && $bp->is_single_item
//Come and see the violence inherent in the system. Help! Help! I'm being repressed!
if ( !etivite_bp_edit_activity_check_date_recorded( bp_get_activity_date_recorded() ) )
return;
echo apply_filters( 'etivite_bp_edit_activity_edit_link', '<a rel="nofollow" href="' . $bp->root_domain . '/' . bp_get_activity_slug() . '/edit/' . bp_get_activity_id() . '" class="button item-button bp-secondary-action edit-activity">' . __( 'Edit', 'buddypress' ) . '</a>' );
}
add_action( 'bp_activity_entry_meta', 'etivite_bp_edit_activity_add_edit_link', 1 );
//check if it falls within our set edit time limit
function etivite_bp_edit_activity_check_date_recorded( $date_recorded ) {
global $bp;
if ( !$date_recorded )
return false;
if ( $bp->loggedin_user->is_super_admin )
return true;
//http://www.php.net/manual/en/datetime.formats.relative.php
$lock_date = get_option( 'etivite_bp_edit_activity_lock_date');
if (!$lock_date) $lock_date = '+30 Minutes';
if ( strtotime( bp_core_current_time() ) <= strtotime( $lock_date, strtotime( $date_recorded ) ) )
return true;
return false;
}
function etivite_bp_edit_activity_body_class( $wp_classes ) {
$wp_classes[] = 'activity-permalink';
return $wp_classes;
}
function etivite_bp_edit_activity_action_edit_router() {
global $bp, $activity_edit_template;
// Do not proceed if user is not logged in, not viewing activity, or not posting
if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'edit' ) )
return false;
if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
return false;
$activity_id = $bp->action_variables[0];
/* Get the activity details */
$activity_edit_template = bp_activity_get_specific( array( 'activity_ids' => $activity_id ) );
if ( !$activity = $activity_edit_template['activities'][0] )
bp_core_redirect( $bp->root_domain );
/* Check access */
if ( !$bp->loggedin_user->is_super_admin && $activity->user_id != $bp->loggedin_user->id )
bp_core_redirect( bp_activity_get_permalink( $activity->id ) );
/* Check save */
if ( isset( $_POST['save_changes'] ) ) {
//Come and see the violence inherent in the system. Help! Help! I'm being repressed!
if ( !etivite_bp_edit_activity_check_date_recorded( $activity->date_recorded ) )
bp_core_redirect( bp_activity_get_permalink( $activity->id) );
/* Check the nonce */
check_admin_referer( 'etivite_bp_edit_activity_post'. $activity->id );
if ( !$bp->loggedin_user->is_super_admin )
$new_action = $activity->action;
if ( $bp->loggedin_user->is_super_admin && isset( $_POST['activity_action'] ) && !empty( $_POST['activity_action'] ) )
$new_action = $_POST['activity_action'];
$new_content = $activity->content;
if ( isset( $_POST['activity_content'] ) && !empty( $_POST['activity_content'] ) )
$new_content = $_POST['activity_content'];
$new_atcontent = bp_activity_at_name_filter( $new_content );
$activity_id = bp_activity_add( array( 'id' => $activity->id, 'action' => $new_action, 'content' => apply_filters( 'etivite_bp_edit_activity_action_edit_content', $new_atcontent ), 'component' => $activity->component, 'type' => $activity->type, 'primary_link' => $activity->primary_link, 'user_id' => $activity->user_id, 'item_id' => $activity->item_id, 'secondary_item_id' => $activity->secondary_item_id, 'recorded_time' => $activity->date_recorded, 'hide_sitewide' => $activity->hide_sitewide ) );
//need to update bp_latest_update on profile page - but have to check if this info is there first
if ( $activity_id && $activity->type == 'activity_update' && $activity->component == $bp->activity->id ) {
$profile_status = maybe_unserialize( get_user_meta( $activity->user_id, 'bp_latest_update' ) );
if ( $profile_status && $profile_status['id'] == $activity->id ) {
update_usermeta( $activity->user_id, 'bp_latest_update', array( 'id' => $activity->id, 'content' => wp_filter_kses( $new_content ) ) );
}
}
bp_core_redirect( bp_activity_get_permalink( $activity->id ) );
}
add_filter( 'body_class', 'etivite_bp_edit_activity_body_class', 10, 1 );
/* else edit */
bp_core_load_template( 'activity/activity-edit' );
}
add_action( 'wp', 'etivite_bp_edit_activity_action_edit_router', 3 );
function etivite_bp_edit_activity_load_template_filter( $found_template, $templates ) {
global $bp;
/**
* Only filter the template location when we're on the follow component pages.
*/
if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'edit' )
return $found_template;
foreach ( (array) $templates as $template ) {
if ( file_exists( STYLESHEETPATH . '/' . $template ) )
$filtered_templates[] = STYLESHEETPATH . '/' . $template;
else
$filtered_templates[] = dirname( __FILE__ ) . '/templates/' . $template;
}
$found_template = $filtered_templates[0];
return apply_filters( 'etivite_bp_edit_activity_load_template_filter', $found_template );
}
add_filter( 'bp_located_template', 'etivite_bp_edit_activity_load_template_filter', 10, 2 );
function etivite_bp_edit_action() {
echo etivite_bp_edit_get_action();
}
function etivite_bp_edit_get_action() {
global $bp, $activity_edit_template;
return apply_filters( 'etivite_bp_edit_get_action', $bp->root_domain . '/' . $bp->activity->slug . '/edit/' . $activity_edit_template['activities'][0]->id );
}
function etivite_bp_edit_the_activity() {
global $activity_edit_template;
return $activity_edit_template['activities'][0];
}
function etivite_bp_edit_the_activity_id() {
echo etivite_bp_edit_get_the_activity_id();
}
function etivite_bp_edit_get_the_activity_id() {
global $activity_edit_template;
return apply_filters( 'etivite_bp_edit_get_the_activity_id', $activity_edit_template['activities'][0]->id );
}
function etivite_bp_edit_the_activity_action() {
echo etivite_bp_edit_get_the_activity_action();
}
function etivite_bp_edit_get_the_activity_action() {
global $activity_edit_template;
return apply_filters( 'etivite_bp_edit_get_the_activity_action', esc_attr( $activity_edit_template['activities'][0]->action ) );
}
function etivite_bp_edit_the_activity_content() {
echo etivite_bp_edit_get_the_activity_content();
}
function etivite_bp_edit_get_the_activity_content() {
global $activity_edit_template;
return apply_filters( 'etivite_bp_edit_get_the_activity_content', stripslashes( esc_attr( $activity_edit_template['activities'][0]->content ) ) );
}
function etivite_bp_edit_the_avatar($args) {
echo etivite_bp_edit_get_the_avatar($args);
}
function etivite_bp_edit_get_the_avatar($args) {
global $bp, $activity_edit_template;
$defaults = array(
'type' => 'thumb',
'width' => 100,
'height' => 100,
'class' => 'avatar',
'alt' => __( 'Avatar', 'buddypress' ),
'email' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$item_id = false;
if ( (int)$activity_edit_template['activities'][0]->user_id )
$item_id = $activity_edit_template['activities'][0]->user_id;
else if ( $activity_edit_template['activities'][0]->item_id )
$item_id = $activity_edit_template['activities'][0]->item_id;
$object = 'user';
if ( $bp->groups->id == $activity_edit_template['activities'][0]->component && !(int) $activity_edit_template['activities'][0]->user_id )
$object = 'group';
if ( $bp->blogs->id == $activity_edit_template['activities'][0]->component && !(int) $activity_edit_template['activities'][0]->user_id )
$object = 'blog';
return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height ) ) );
}
?>
Oops, something went wrong.

0 comments on commit fd7340d

Please sign in to comment.