Skip to content

Commit

Permalink
Merge branch 'master' into branch-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
George Stephanis committed Oct 29, 2014
2 parents 54c6eb2 + 0908310 commit 99b5f56
Show file tree
Hide file tree
Showing 98 changed files with 207,547 additions and 172,092 deletions.
4 changes: 2 additions & 2 deletions jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: http://wordpress.org/extend/plugins/jetpack/
* Description: Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.
* Author: Automattic
* Version: 3.2-beta5
* Version: 3.2
* Author URI: http://jetpack.me
* License: GPL2+
* Text Domain: jetpack
Expand All @@ -14,7 +14,7 @@

define( 'JETPACK__MINIMUM_WP_VERSION', '3.9' );

define( 'JETPACK__VERSION', '3.2-beta5' );
define( 'JETPACK__VERSION', '3.2' );
define( 'JETPACK_MASTER_USER', true );
define( 'JETPACK__API_VERSION', 1 );
define( 'JETPACK__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand Down
8 changes: 6 additions & 2 deletions json-endpoints/jetpack/class.jetpack-json-api-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {


public function callback( $path = '', $blog_id = 0, $object = null ) {
if ( is_wp_error( $error = $this->validate_call( $blog_id, $this->needed_capabilities, true ) ) ) {
if ( is_wp_error( $error = $this->validate_call( $blog_id, $this->needed_capabilities ) ) ) {
return $error;
}

Expand Down Expand Up @@ -53,7 +53,7 @@ protected function validate_input( $object ) {
* Switches to the blog and checks current user capabilities.
* @return bool|WP_Error a WP_Error object or true if things are good.
*/
protected function validate_call( $_blog_id, $capability, $check_full_management = true ) {
protected function validate_call( $_blog_id, $capability, $check_full_management = null ) {
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $_blog_id ) );
if ( is_wp_error( $blog_id ) ) {
return $blog_id;
Expand All @@ -63,6 +63,10 @@ protected function validate_call( $_blog_id, $capability, $check_full_management
return $error;
}

if ( is_null( $check_full_management ) ) {
$check_full_management = $this->method !== 'GET';
}

if ( $check_full_management && ! Jetpack_Options::get_option( 'json_api_full_management' ) ) {
return new WP_Error( 'unauthorized_full_access', sprintf( __( 'Full management mode is off for this site.' , 'jetpack' ), $capability ), 403 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ class Jetpack_JSON_API_Plugins_Delete_Endpoint extends Jetpack_JSON_API_Plugins_
// POST /sites/%s/plugins/%s/delete
protected $needed_capabilities = 'delete_plugins';
protected $action = 'delete';
protected $download_links = array();

protected function delete() {

if ( is_wp_error( $error = delete_plugins( $this->plugins ) ) ) {
return $error;
};
foreach( $this->plugins as $plugin ) {

if ( Jetpack::is_plugin_active( $plugin ) ) {
$error = $this->log[ $plugin ][] ='You cannot delete a plugin while it is active on the main site.';
continue;
}

$result = delete_plugins ( array( $plugin ) );
if ( is_wp_error( $result ) ) {
$error = $this->log[ $plugin ][] = $result->get_error_message();
} else {
$this->log[ $plugin ][] = 'Plugin deleted';
}
}

if( ! $this->bulk && isset( $error ) ) {
return new WP_Error( 'delete_plugin_error', $error, 400 );
}

return true;
}
Expand Down
37 changes: 31 additions & 6 deletions json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi

static $_response_format = array(
'id' => '(safehtml) The plugin\'s ID',
'slug' => '(safehtml) The plugin\'s .org slug',
'active' => '(boolean) The plugin status.',
'update' => '(object) The plugin update info.',
'name' => '(safehtml) The name of the plugin.',
Expand Down Expand Up @@ -94,22 +95,19 @@ protected function validate_plugins() {
}

protected function format_plugin( $plugin_file, $plugin_data ) {
$autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
$plugin = array();
$plugin['id'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
$plugin['slug'] = $this->get_plugin_slug( $plugin_file );
$plugin['active'] = Jetpack::is_plugin_active( $plugin_file );

$update_plugins = get_site_transient( 'update_plugins' );
$plugin['update'] = ( isset( $update_plugins->response[ $plugin_file ] ) ) ? $update_plugins->response[ $plugin_file ] : null;

$plugin['name'] = $plugin_data['Name'];
$plugin['plugin_url'] = $plugin_data['PluginURI'];
$plugin['version'] = $plugin_data['Version'];
$plugin['description'] = $plugin_data['Description'];
$plugin['author'] = $plugin_data['Author'];
$plugin['author_url'] = $plugin_data['AuthorURI'];
$plugin['network'] = $plugin_data['Network'];
$plugin['autoupdate'] = in_array( $plugin_file, $autoupdate_plugins );
$plugin['update'] = $this->get_plugin_updates( $plugin_file );
$plugin['autoupdate'] = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) );
if ( ! empty ( $this->log[ $plugin_file ] ) ) {
$plugin['log'] = $this->log[ $plugin_file ];
}
Expand Down Expand Up @@ -163,4 +161,31 @@ protected function validate_plugin( $plugin ) {
return true;
}

protected function get_plugin_updates( $plugin_file ) {
$plugin_updates = get_plugin_updates();
if ( isset( $plugin_updates[ $plugin_file ] ) ){
return $plugin_updates[ $plugin_file ]->update;
}
return null;
}

protected function get_plugin_slug( $plugin_file ) {
$update_plugins = get_site_transient( 'update_plugins' );
if ( isset( $update_plugins->no_update ) ) {
if ( isset( $update_plugins->no_update[ $plugin_file ] ) ) {
$slug = $update_plugins->no_update[ $plugin_file ]->slug;
}
}
if ( empty( $slug ) && isset( $update_plugins->response ) ) {
if ( isset( $update_plugins->response[ $plugin_file ] ) ) {
$slug = $update_plugins->response[ $plugin_file ]->slug;
}
}
if ( empty ( $slug) ) {
$slug = $plugin_file;
}

return $slug;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,73 @@ class Jetpack_JSON_API_Plugins_Install_Endpoint extends Jetpack_JSON_API_Plugins
protected $download_links = array();

protected function install() {
foreach ( $this->plugins as $plugin ) {
foreach ( $this->plugins as $index => $slug ) {

$skin = new Automatic_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );

$result = $upgrader->install( $this->download_links[$plugin] );
$result = $upgrader->install( $this->download_links[ $slug ] );

if ( ! $this->bulk && is_wp_error( $result ) ) {
return $result;
}

if ( ! $this->bulk && ! $result ) {
$error = $this->log[ $plugin ]['error'] = __( 'An unknown error occurred during installation', 'jetpack' );
$plugin = $this::get_plugin_id_by_slug( $slug );

if ( ! $plugin ) {
$error = $this->log[ $slug ]['error'] = __( 'There was an error installing your plugin', 'jetpack' );
}

if ( ! $this::is_installed_plugin( $plugin ) ) {
$error = $this->log[ $plugin ]['error'] = __( 'There was an error installing your plugin', 'jetpack' );
if ( ! $this->bulk && ! $result ) {
$error = $this->log[ $slug ]['error'] = __( 'An unknown error occurred during installation', 'jetpack' );
}

$this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages();
}

if ( ! $this->bulk && isset( $error ) ) {
return new WP_Error( 'install_error', $this->log[ $plugin ]['error'], 400 );
return new WP_Error( 'install_error', $this->log[ $slug ]['error'], 400 );
}

// replace the slug with the actual plugin id
$this->plugins[ $index ] = $plugin;

return true;
}

protected function validate_plugins() {
if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ) );
}
foreach( $this->plugins as $index => $plugin ) {
if ( ! preg_match( "/\.php$/", $plugin ) ) {
$plugin = $plugin . '.php';
$this->plugins[ $index ] = $plugin;
}
foreach( $this->plugins as $index => $slug ) {

if ( $this::is_installed_plugin( $plugin ) ) {
// make sure it is not already installed
if ( $this::get_plugin_id_by_slug( $slug ) ) {
return new WP_Error( 'plugin_already_installed', __( 'The plugin is already installed', 'jetpack' ) );
}

$slug = substr( $plugin, 0, strpos( $plugin, '/' ) );
$response = wp_remote_get( "http://api.wordpress.org/plugins/info/1.0/$slug" );
$plugin_data = unserialize( $response['body'] );
if ( is_wp_error( $plugin_data ) ) {
return $plugin_data;
}
$this->download_links[ $plugin ] = $plugin_data->download_link;

$this->download_links[ $slug ] = $plugin_data->download_link;

}
return true;
}

protected static function is_installed_plugin( $plugin ) {
return in_array( $plugin, array_keys( get_plugins() ) );
protected static function get_plugin_id_by_slug( $slug ) {
$plugins = get_plugins();
if( ! is_array( $plugins ) ) {
return false;
}
foreach( $plugins as $id => $plugin_data ) {
if( strpos( $id, $slug ) !== false ) {
return $id;
}
}
return false;
}

}
5 changes: 3 additions & 2 deletions json-endpoints/jetpack/json-api-jetpack-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
'authorization' => 'Bearer YOUR_API_TOKEN'
),
),
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet%2Fakismet/install'
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet/install'
) );

require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-delete-endpoint.php' );
Expand Down Expand Up @@ -313,7 +313,7 @@
'path' => '/sites/%s/plugins/%s/delete',
'path_labels' => array(
'$site' => '(int|string) The site ID, The site domain',
'$plugin' => '(int|string) The plugin slug to install',
'$plugin' => '(int|string) The plugin slug to delete',
),
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
'example_request_data' => array(
Expand Down Expand Up @@ -431,6 +431,7 @@
'translations' => '(int) The total number of translation updates.',
'total' => '(int) The total number of updates.',
'wp_version' => '(safehtml) The wp_version string.',
'jp_version' => '(safehtml) The site Jetpack version.',
),
'example_request_data' => array(
'headers' => array(
Expand Down
Binary file modified languages/jetpack-ar.mo
Binary file not shown.
Loading

0 comments on commit 99b5f56

Please sign in to comment.