Skip to content

Commit

Permalink
update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheu committed Aug 13, 2015
1 parent 8623799 commit 45a7a51
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
11 changes: 7 additions & 4 deletions inc/class-mexp-resource-space-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ public function request( array $request ) {
$item->set_id( $clean_data['id'] );
$item->set_url( $clean_data['url'] );

$clean_data['thumbnail'] = add_query_arg( array(
'action' => 'pj_rs_proxy_resource',
'src' => urlencode( $dirty_data['thumbnail'] ),
), admin_url( 'admin-ajax.php' ) );
// Proxy image requests.
if ( defined( 'PJ_RESOURCE_SPACE_PROXY_THUMBNAILS' ) && PJ_RESOURCE_SPACE_PROXY_THUMBNAILS ) {
$clean_data['thumbnail'] = add_query_arg( array(
'action' => 'pj_rs_proxy_resource',
'src' => urlencode( $dirty_data['thumbnail'] ),
), admin_url( 'admin-ajax.php' ) );
}

$item->set_thumbnail( $clean_data['thumbnail'] );

Expand Down
4 changes: 2 additions & 2 deletions inc/class-resource-space-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setup_actions() {

add_action( 'admin_notices', function() { ?>
<div class="error">
<p><?php _e( 'You must define the resource space domain and API key in your wp-config.php. See readme for more details.', 'resourcespace' ); ?></p>
<p><?php esc_html_e( 'You must define the resource space domain and API key in your wp-config.php. See readme for more details.', 'resourcespace' ); ?></p>
</div>
<?php } );

Expand Down Expand Up @@ -76,7 +76,7 @@ function ajax_query_attachments_args( $query ) {
array(
'key' => 'resource_space',
'compare' => 'EXISTS',
)
),
);
}

Expand Down
29 changes: 15 additions & 14 deletions inc/class-resource-space-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function ajax_get_image() {
'key' => $key,
'search' => $resource_id,
'prettyfieldnames' => 1,
'previewsize' => 'sit',
'original' => true,
), $url );

$request_args = array( 'headers' => array() );
Expand All @@ -61,12 +61,17 @@ function ajax_get_image() {
wp_send_json_error( __( 'Unable to query API', 'resourcespace' ) );
}

if ( count( $data ) < 1 ) {
wp_send_json_error( __( 'Resource not found', 'resourcespace' ) );
}

// All good, continue
$file = get_temp_dir() . sanitize_file_name( $data[0]->Original_filename );

$downloadurl = $data[0]->preview;
$file = get_temp_dir() . sanitize_file_name( $data[0]->Original_filename );
// TODO test. Advice from Kirill was to use the users cookie.
// Hopefully it isn't required as this isn't as robust as using basic auth.
$response = wp_remote_get( $data[0]->original_link, $request_args );

$response = wp_remote_get( $downloadurl, $request_args );
if ( 200 == wp_remote_retrieve_response_code( $response ) ) {

file_put_contents( $file, wp_remote_retrieve_body( $response ) );
Expand All @@ -79,26 +84,22 @@ function ajax_get_image() {

$wp_filetype = wp_check_filetype( $filename, null );

date_default_timezone_set( 'Europe/London' );
$d = new DateTime();

$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => 0,
'post_title' => $data[0]->{'Légende'},
'post_content' => 'Downloaded ' . $d->format( 'd/m/Y \a\t H:i:s' ),
'post_status' => 'inherit'
'post_content' => 'Downloaded ' . current_time( 'd/m/Y \a\t H:i:s' ),
'post_status' => 'inherit',
);

$attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id );

if ( ! is_wp_error( $attachment_id ) ) {
require_once( ABSPATH . "wp-admin" . '/includes/image.php' );

/* Add some attachment data */
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
$attachment_data['image_meta']['created_timestamp'] = $d->format( 'Y-m-d H:i:s' );
//$attachment_data['image_meta']['copyright'] = 'Yelster ' . $d->format('Y');
require_once( trailingslashit( ABSPATH ) . 'wp-admin/includes/image.php' );

$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
$attachment_data['image_meta']['created_timestamp'] = current_time( 'Y-m-d H:i:s', true );

wp_update_attachment_metadata( $attachment_id, $attachment_data );

Expand Down
9 changes: 7 additions & 2 deletions js/mexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@
}).done( function( response ) {

if ( ! response.success ) {
alert( response.data );

if ( 'data' in response ) {
alert( response.data );
} else {
alert( 'Failed to import image.' );
}

return;
}

Expand All @@ -121,7 +127,6 @@

// Allow overriding insert callback.
if ( self.frame.options.resourceSpaceInsertCallback ) {

callback = self.frame.options.resourceSpaceInsertCallback
}

Expand Down
9 changes: 9 additions & 0 deletions js/resource-space-vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@

}, 1 );

// Slightly hcky workaround because for some reason the load more
// button doesn't exist when the event callback is attached.
$('#resource-space-loadmore').on('click', function(e) {
var view = wp.media.frames.resourceSpaceFrame.views.get('.media-frame-content' );
if ( view.length ) {
view[0].paginate(e);
}
} );

}, this );

// Create the toolbar.
Expand Down
6 changes: 5 additions & 1 deletion resourcespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
define( 'PJ_RESOURCE_SPACE_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'PJ_RESOURCE_SPACE_PLUGIN_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );

defined( 'PJ_RESOURCE_SPACE_RESULTS_PER_PAGE' ) or define( 'PJ_RESOURCE_SPACE_RESULTS_PER_PAGE', 20 );
defined( 'PJ_RESOURCE_SPACE_RESULTS_PER_PAGE' ) or define( 'PJ_RESOURCE_SPACE_RESULTS_PER_PAGE', 10 );

if ( ! defined( 'PJ_RESOURCE_SPACE_PROXY_THUMBNAILS' ) ) {
define( 'PJ_RESOURCE_SPACE_PROXY_THUMBNAILS', defined( 'PJ_RESOURCE_SPACE_AUTHP' ) );
}

if ( ! class_exists( 'MEXP_Service' ) ) {
wp_die( __( 'Media Explorer plugin must be enabled.', 'resourcespace' ) );
Expand Down
6 changes: 3 additions & 3 deletions templates/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<div class="wrap">

<h2 class="page-title">
Stock Images
<a href="#" id="resource-space-add-new" class="add-new-h2"><?php _e( 'Add new', 'resourcespace' ); ?></a>
<?php esc_html_e( 'Stock Images', 'resourcespace' ); ?>
<a href="#" id="resource-space-add-new" class="add-new-h2"><?php esc_html_e( 'Add new', 'resourcespace' ); ?></a>
</h2>

<div id="resource-space-new-images" style="display: none;">
<h3><?php _e( 'Recently Imported Stock Images', 'resourcespace' ); ?></h3>
<h3><?php esc_html_e( 'Recently Imported Stock Images', 'resourcespace' ); ?></h3>
</div>

<div class="wrap" id="resource-space-images" data-search="<?php _admin_search_query() ?>">
Expand Down

0 comments on commit 45a7a51

Please sign in to comment.