Skip to content

Commit

Permalink
Merge branch 'develop' into issue-309
Browse files Browse the repository at this point in the history
Conflicts:
	classes/connector.php
	connectors/settings.php
  • Loading branch information
frankiejarrett committed Mar 10, 2014
2 parents 9891d30 + fe7c98a commit c9567f5
Show file tree
Hide file tree
Showing 26 changed files with 448 additions and 278 deletions.
17 changes: 13 additions & 4 deletions classes/connector.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

abstract class WP_Stream_Connector {

/**
* Name/slug of the context
*
* @var string
*/
public static $name = null;

/**
* Actions this context is hooked to
*
* @var array
*/
public static $actions = array();

/**
* Previous Stream entry in same request
*
* @var int
*/
public static $prev_stream = null;
Expand Down Expand Up @@ -45,7 +49,7 @@ public static function callback() {
$class = get_called_class();
$callback = array( $class, 'callback_' . str_replace( '-', '_', $action ) );

//For the sake of testing, trigger an action with the name of the callback
// For the sake of testing, trigger an action with the name of the callback
if ( defined( 'STREAM_TESTS' ) ) {
/**
* Action fires during testing to test the current callback
Expand All @@ -55,7 +59,7 @@ public static function callback() {
do_action( 'stream_test_' . $callback[1] );
}

//Call the real function
// Call the real function
if ( is_callable( $callback ) ) {
return call_user_func_array( $callback, func_get_args() );
}
Expand Down Expand Up @@ -86,7 +90,7 @@ public static function action_links( $links, $record ) {
* @return void
*/
public static function log( $message, $args, $object_id, $contexts, $user_id = null ) {
//Prevent inserting Excluded Context & Actions
// Prevent inserting Excluded Context & Actions
foreach ( $contexts as $context => $action ) {
if ( ! WP_Stream_Connectors::is_logging_enabled( 'contexts', $context ) ) {
unset( $contexts[ $context ] );
Expand All @@ -96,9 +100,11 @@ public static function log( $message, $args, $object_id, $contexts, $user_id = n
}
}
}

if ( count( $contexts ) == 0 ){
return ;
}

$class = get_called_class();

return WP_Stream_Log::get_instance()->log(
Expand All @@ -108,7 +114,7 @@ public static function log( $message, $args, $object_id, $contexts, $user_id = n
$object_id,
$contexts,
$user_id
);
);
}

/**
Expand All @@ -122,14 +128,17 @@ public static function log( $message, $args, $object_id, $contexts, $user_id = n
*/
public static function delayed_log( $handle ) {
$args = func_get_args();

array_shift( $args );

self::$delayed[ $handle ] = $args;

add_action( 'shutdown', array( __CLASS__, 'delayed_log_commit' ) );
}

/**
* Commit delayed logs saved by @delayed_log
*
* @return void
*/
public static function delayed_log_commit() {
Expand Down
10 changes: 7 additions & 3 deletions connectors/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ class WP_Stream_Connector_Comments extends WP_Stream_Connector {

/**
* Context name
*
* @var string
*/
public static $name = 'comments';

/**
* Actions registered for this context
*
* @var array
*/
public static $actions = array(
Expand Down Expand Up @@ -76,13 +78,14 @@ public static function get_context_labels() {
* @return array Action links
*/
public static function action_links( $links, $record ) {

if ( $record->object_id ) {
if ( $comment = get_comment( $record->object_id ) ) {
$del_nonce = wp_create_nonce( "delete-comment_$comment->comment_ID" );
$del_nonce = wp_create_nonce( "delete-comment_$comment->comment_ID" );
$approve_nonce = wp_create_nonce( "approve-comment_$comment->comment_ID" );

$links[ __( 'Edit', 'stream' ) ] = admin_url( "comment.php?action=editcomment&c=$comment->comment_ID" );
if ( 1 == $comment->comment_approved ) {

if ( 1 === $comment->comment_approved ) {
$links[ __( 'Unapprove', 'stream' ) ] = admin_url(
sprintf(
'comment.php?action=unapprovecomment&c=%s&_wpnonce=%s',
Expand All @@ -101,6 +104,7 @@ public static function action_links( $links, $record ) {
}
}
}

return $links;
}

Expand Down
67 changes: 42 additions & 25 deletions connectors/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ class WP_Stream_Connector_Installer extends WP_Stream_Connector {

/**
* Context name
*
* @var string
*/
public static $name = 'installer';

/**
* Actions registered for this context
*
* @var array
*/
public static $actions = array(
Expand Down Expand Up @@ -71,7 +73,7 @@ public static function get_context_labels() {
* @return array Action links
*/
public static function action_links( $links, $record ) {
if ( 'wordpress' == $record->context && 'updated' == $record->action ) {
if ( 'wordpress' === $record->context && 'updated' === $record->action ) {
global $wp_version;
$version = get_stream_meta( $record->ID, 'new_version', true );
if ( $version === $wp_version ) {
Expand Down Expand Up @@ -110,10 +112,10 @@ public static function callback_upgrader_process_complete( $upgrader, $extra ) {
return;
}

if ( $action == 'install' ) {
if ( 'install' === $action ) {
$from = $upgrader->skin->options['type'];
if ( $from == 'upload' ) {
if ( $type == 'plugin' ) {
if ( 'upload' === $from ) {
if ( 'plugin' === $type ) {
$cached_plugins = wp_cache_get( 'plugins', 'plugins' );
$plugin_data = $cached_plugins['/'.$upgrader->result['destination_name']];
if ( $plugin_data ) {
Expand All @@ -124,7 +126,7 @@ public static function callback_upgrader_process_complete( $upgrader, $extra ) {
$slug = $upgrader->result['destination_name'];
$name = $plugin_data['Name'];
$version = $plugin_data['Version'];
} elseif ( $type == 'theme' ) {
} elseif ( 'theme' === $type ) {
$slug = $upgrader->result['destination_name'];
$theme_data = wp_get_theme( $slug );
if ( empty( $theme_data ) ) {
Expand All @@ -144,9 +146,9 @@ public static function callback_upgrader_process_complete( $upgrader, $extra ) {
'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version',
'stream'
);
} elseif ( $action == 'update' ) {
if ( $type == 'plugin' ) {
if ( isset( $extra['bulk'] ) && $extra['bulk'] == true ) {
} elseif ( 'update' === $action ) {
if ( 'plugin' === $type ) {
if ( isset( $extra['bulk'] ) && true == $extra['bulk'] ) {
$slugs = $extra['plugins'];
} else {
$slugs = array( $upgrader->skin->plugin );
Expand All @@ -158,12 +160,12 @@ public static function callback_upgrader_process_complete( $upgrader, $extra ) {
$logs[] = array(
'name' => $plugin_data['Name'],
'version' => $plugin_data['Version'],
'old_version' => $plugins[$slug]['Version'],
'old_version' => $plugins[ $slug ]['Version'],
);
}
}
elseif ( $type == 'theme' ) {
if ( isset( $extra['bulk'] ) && $extra['bulk'] == true ) {
elseif ( 'theme' === $type ) {
if ( isset( $extra['bulk'] ) && true == $extra['bulk'] ) {
$slugs = $extra['themes'];
} else {
$slugs = array( $upgrader->skin->theme );
Expand Down Expand Up @@ -201,17 +203,16 @@ public static function callback_upgrader_process_complete( $upgrader, $extra ) {
$message,
compact( 'type', 'name', 'version', 'slug', 'success', 'error', 'from' , 'old_version' ),
null,
array(
$context => $action,
)
array( $context => $action )
);
}
}

public static function callback_activate_plugin( $slug, $network_wide ) {
$plugins = get_plugins();
$name = $plugins[$slug]['Name'];
$name = $plugins[ $slug ]['Name'];
$network_wide = $network_wide ? __( 'network wide', 'stream' ) : null;

self::log(
_x(
'"%1$s" plugin activated %2$s',
Expand All @@ -226,8 +227,9 @@ public static function callback_activate_plugin( $slug, $network_wide ) {

public static function callback_deactivate_plugin( $slug, $network_wide ) {
$plugins = get_plugins();
$name = $plugins[$slug]['Name'];
$name = $plugins[ $slug ]['Name'];
$network_wide = $network_wide ? __( 'network wide', 'stream' ) : null;

self::log(
_x(
'"%1$s" plugin deactivated %2$s',
Expand All @@ -242,6 +244,7 @@ public static function callback_deactivate_plugin( $slug, $network_wide ) {

public static function callback_switch_theme( $name, $theme ) {
$stylesheet = $theme->get_stylesheet();

self::log(
__( '"%s" theme activated', 'stream' ),
compact( 'name' ),
Expand All @@ -252,11 +255,14 @@ public static function callback_switch_theme( $name, $theme ) {

public static function callback_delete_site_transient_update_themes() {
$stylesheet = wp_stream_filter_input( INPUT_GET, 'stylesheet' );
if ( wp_stream_filter_input( INPUT_GET, 'action' ) != 'delete' || ! $stylesheet ) {

if ( 'delete' !== wp_stream_filter_input( INPUT_GET, 'action' ) || ! $stylesheet ) {
return;
}

$theme = $GLOBALS['theme'];
$name = $theme['Name'];

self::log(
__( '"%s" theme deleted', 'stream' ),
compact( 'name' ),
Expand All @@ -267,33 +273,41 @@ public static function callback_delete_site_transient_update_themes() {

public static function callback_pre_option_uninstall_plugins() {
global $plugins;
if ( wp_stream_filter_input( INPUT_GET, 'action' ) != 'delete-selected' && wp_stream_filter_input( INPUT_POST, 'action2' ) != 'delete-selected' ) {

if ( 'delete-selected' !== wp_stream_filter_input( INPUT_GET, 'action' ) && 'delete-selected' !== wp_stream_filter_input( INPUT_POST, 'action2' ) ) {
return false;
}

$_plugins = get_plugins();

foreach ( $plugins as $plugin ) {
$plugins_to_delete[$plugin] = $_plugins[$plugin];
$plugins_to_delete[ $plugin ] = $_plugins[ $plugin ];
}

update_option( 'wp_stream_plugins_to_delete', $plugins_to_delete );

return false;
}

public static function callback_pre_set_site_transient_update_plugins( $value ) {
if ( ! wp_stream_filter_input( INPUT_POST, 'verify-delete' ) || ! ( $plugins_to_delete = get_option( 'wp_stream_plugins_to_delete' ) ) ) {
return $value;
}

foreach ( $plugins_to_delete as $plugin => $data ) {
$name = $data['Name'];
$name = $data['Name'];
$network_wide = $data['Network'] ? __( 'network wide', 'stream' ) : '';

self::log(
__( '"%s" plugin deleted', 'stream' ),
compact( 'name', 'plugin', 'network_wide' ),
null,
array( 'plugins' => 'deleted' )
);
}

delete_option( 'wp_stream_plugins_to_delete' );

return $value;
}

Expand All @@ -305,23 +319,24 @@ public static function callback_wp_redirect( $location ) {
$type = $match[1];

list( $url, $query ) = explode( '?', $location );

$query = wp_parse_args( $query );
$file = $query['file'];

if ( empty( $query['file'] ) ) {
return $location;
}

if ( $type == 'theme' ) {
if ( 'theme' === $type ) {
if ( empty( $query['updated'] ) ) {
return $location;
}
$theme = wp_get_theme( $query['theme'] );
$name = $theme['Name'];
}
elseif ( $type == 'plugin' ) {
elseif ( 'plugin' === $type ) {
global $plugin, $plugins;
$data = $plugins[$plugin];
$data = $plugins[ $plugin ];
$name = $data['Name'];
}

Expand All @@ -341,13 +356,16 @@ public static function callback_wp_redirect( $location ) {

public static function callback__core_updated_successfully( $new_version ) {
global $pagenow, $wp_version;

$old_version = $wp_version;
$auto_updated = ( $pagenow != 'update-core.php' );
$auto_updated = ( 'update-core.php' !== $pagenow );

if ( $auto_updated ) {
$message = __( 'WordPress auto-updated to %s', 'stream' );
} else {
$message = __( 'WordPress updated to %s', 'stream' );
}

self::log(
$message,
compact( 'new_version', 'old_version', 'auto_updated' ),
Expand All @@ -356,5 +374,4 @@ public static function callback__core_updated_successfully( $new_version ) {
);
}


}
Loading

0 comments on commit c9567f5

Please sign in to comment.