Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"automattic/vipwpcs": "^2.2",
"automattic/vipwpcs": "dev-develop",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpcompatibility/phpcompatibility-wp": "dev-master",
"phpcompatibility/php-compatibility": "dev-develop as 9.99.99"
},
"config": {
Expand Down
129 changes: 69 additions & 60 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions php/cache/class-cache-point.php
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,13 @@ public function query_cached_items( $urls ) {
foreach ( $indexes as $key ) {
$url = $urls[ $key ];

if ( ! isset( $meta[ self::META_KEYS['cached_urls'] ][ $url ] )
|| $url === $meta[ self::META_KEYS['cached_urls'] ][ $url ]
&& $meta[ self::META_KEYS['last_updated'] ] < time() - MINUTE_IN_SECONDS * 10 ) {
if (
! isset( $meta[ self::META_KEYS['cached_urls'] ][ $url ] )
|| (
$url === $meta[ self::META_KEYS['cached_urls'] ][ $url ]
&& $meta[ self::META_KEYS['last_updated'] ] < time() - MINUTE_IN_SECONDS * 10
)
) {
// Send to upload prep.
$this->prepare_for_sync( $post->ID );
$meta[ self::META_KEYS['cached_urls'] ][ $url ] = $url;
Expand Down Expand Up @@ -972,6 +976,6 @@ protected function register_post_type() {
'rewrite' => false,
'capability_type' => 'page',
);
$this->post_type = register_post_type( self::POST_TYPE_SLUG, $args );
$this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral
}
}
2 changes: 1 addition & 1 deletion php/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ protected function register_post_type() {
'rewrite' => false,
'capability_type' => 'page',
);
$this->post_type = register_post_type( self::POST_TYPE_SLUG, $args );
$this->post_type = register_post_type( self::POST_TYPE_SLUG, $args ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral
}

/**
Expand Down
10 changes: 7 additions & 3 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public function maybe_file_exist_in_url( $url ) {
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
return false;
}
// phpcs:disable WordPress.WP.AlternativeFunctions
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_exec( $ch );
Expand All @@ -368,6 +369,7 @@ public function maybe_file_exist_in_url( $url ) {
}

curl_close( $ch );
// phpcs:enable

return $status;
}
Expand Down Expand Up @@ -990,8 +992,8 @@ public function get_transformations( $attachment_id, $transformations = array(),
*/
public function get_crop_transformations( $attachment_id, $size ) {
static $transformations = array();
$size_dim = $size['width'] . 'x' . $size['height'];
$key = $attachment_id . $size_dim;
$size_dim = $size['width'] . 'x' . $size['height'];
$key = $attachment_id . $size_dim;
if ( empty( $transformations[ $key ] ) ) {

if ( empty( $size['transformation'] ) ) {
Expand Down Expand Up @@ -3033,13 +3035,15 @@ public function apply_media_library_filters( $query ) {
if ( SYNC::META_KEYS['unsynced'] === $request ) {
global $wpdb;
$wpdb->cld_table = Utils::get_relationship_table();
$result = $wpdb->get_col( "SELECT post_id FROM $wpdb->cld_table WHERE public_id IS NULL" );
$result = $wpdb->get_col( "SELECT post_id FROM $wpdb->cld_table WHERE public_id IS NULL" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching

// phpcs:disable WordPressVIPMinimum.Hooks.PreGetPosts.PreGetPosts
if ( ! empty( $result ) ) {
$query->set( 'post__in', $result );
} else {
$query->set( 'post__in', array( 0 ) );
}
// phpcs:enable
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion php/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function get_settings_page_structure() {

foreach ( $parts as $slug => $part ) {
if ( file_exists( $this->dir_path . "ui-definitions/settings-{$slug}.php" ) ) {
$parts[ $slug ] = include $this->dir_path . "ui-definitions/settings-{$slug}.php";
$parts[ $slug ] = include $this->dir_path . "ui-definitions/settings-{$slug}.php"; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
}
}

Expand Down
2 changes: 1 addition & 1 deletion php/class-report.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static function( &$row ) {
"SELECT * FROM {$wpdb->cld_table} WHERE post_id = %d;",
$post->ID
);
$relationship = $wpdb->get_row( $prepare ); // phpcs:ignore WordPress.DB.PreparedSQL
$relationship = $wpdb->get_row( $prepare ); // phpcs:ignore WordPress.DB.PreparedSQL,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching

ksort( $attachment );
ksort( $meta );
Expand Down
2 changes: 1 addition & 1 deletion php/class-string-replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function init_debug( $template ) {
if ( defined( 'CLD_DEBUG' ) && true === CLD_DEBUG && ! Utils::get_sanitized_text( '_bypass' ) ) {
$this->context = 'view';
ob_start();
include $template;
include $template; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
$html = ob_get_clean();
echo $this->replace_strings( $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$template = $this->plugin->template_path . 'blank-template.php';
Expand Down
26 changes: 25 additions & 1 deletion php/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public static function pathinfo( $path, $flags = 15 ) {
*
* @see wp-includes/formatting.php
*/
$path = str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) );
$path = str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode

$pathinfo = pathinfo( $path, $flags );

Expand Down Expand Up @@ -914,4 +914,28 @@ public static function get_registered_sizes( $attachment_id = null ) {
*/
return apply_filters( 'cloudinary_registered_sizes', $all_sizes );
}

/**
* Get the attachment ID from the attachment URL.
*
* @param string $url The attachment URL.
*
* @return int
*/
public static function attachment_url_to_postid( $url ) {
$key = "postid_{$url}";

if ( function_exists( 'wpcom_vip_attachment_url_to_postid' ) ) {
$attachment_id = wpcom_vip_attachment_url_to_postid( $url );
} else {
$attachment_id = wp_cache_get( $key, 'cloudinary' );
}

if ( empty( $attachment_id ) ) {
$attachment_id = attachment_url_to_postid( $url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.attachment_url_to_postid_attachment_url_to_postid
wp_cache_set( $key, $attachment_id, 'cloudinary' );
}

return $attachment_id;
}
}
2 changes: 1 addition & 1 deletion php/connect/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ protected static function get_hostname( $upload_prefix ) {
$hostname = $upload_prefix;

if ( filter_var( $upload_prefix, FILTER_VALIDATE_URL ) ) {
$hostname = parse_url( $upload_prefix, PHP_URL_HOST );
$hostname = wp_parse_url( $upload_prefix, PHP_URL_HOST );
}

return $hostname;
Expand Down
2 changes: 1 addition & 1 deletion php/media/class-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public function filter_video_embeds( $html, $id, $attachment ) {
public function pre_filter_rest_content( $response, $post, $request ) {
$context = $request->get_param( 'context' );
if ( 'edit' === $context ) {
$data = $response->get_data();
$data = $response->get_data();
// Handle meta if missing due to custom-fields not being supported.
if ( ! isset( $data['meta'] ) ) {
$data['meta'] = $request->get_param( 'meta' );
Expand Down
2 changes: 1 addition & 1 deletion php/media/class-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function enqueue_admin_scripts() {
* @return array
*/
private function get_asset() {
$asset = require $this->plugin->dir_path . 'js/gallery.asset.php';
$asset = require $this->plugin->dir_path . 'js/gallery.asset.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable

$asset['dependencies'] = array_filter(
$asset['dependencies'],
Expand Down
8 changes: 4 additions & 4 deletions php/media/class-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function filter_video_shortcode( $html, $attr ) {
);
foreach ( $supported_formats as $format ) {
if ( ! empty( $attr[ $format ] ) ) {
$attr['id'] = attachment_url_to_postid( $attr[ $format ] );
$attr['id'] = Utils::attachment_url_to_postid( $attr[ $format ] );
break;
}
}
Expand Down Expand Up @@ -279,8 +279,8 @@ public function filter_video_block_pre_render( $block, $source_block ) {
if ( ! empty( $attributes['poster'] ) ) {
// Maybe local URL.
if ( ! $this->media->is_cloudinary_url( $attributes['poster'] ) ) {
$post_id = attachment_url_to_postid( $attributes['poster'] );
$url = $this->media->cloudinary_url( $post_id );
$post_id = Utils::attachment_url_to_postid( $attributes['poster'] );
$url = $this->media->cloudinary_url( $post_id );
if ( $url ) {
$content = str_replace( $attributes['poster'], $url, $content );
}
Expand Down Expand Up @@ -367,7 +367,7 @@ protected function build_video_embed( $attachment_id, $attributes = array(), $ov

// Maybe poster is a local URL.
if ( empty( $poster_id ) ) {
$post_id = attachment_url_to_postid( $attributes['poster'] );
$post_id = Utils::attachment_url_to_postid( $attributes['poster'] );
$poster_id = $this->media->get_public_id( $post_id );
}

Expand Down
2 changes: 1 addition & 1 deletion php/relate/class-relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static function get_ids_by_public_id( $public_id ) {
global $wpdb;

$table_name = Utils::get_relationship_table();
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$table_name} WHERE public_id = %s", $public_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$table_name} WHERE public_id = %s", $public_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching

return array_map( 'intval', $ids );
}
Expand Down
2 changes: 1 addition & 1 deletion php/sync/class-download-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function import_asset( $attachment_id, $file_path, $transformations = nul
$http_class = ABSPATH . WPINC . '/class-wp-http.php';
}
if ( ! class_exists( 'WP_Http' ) ) {
require_once $http_class;
require_once $http_class; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
}
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
Expand Down
13 changes: 7 additions & 6 deletions php/sync/class-sync-queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ public function build_queue() {
} while ( $query->have_posts() );

$threads = $this->add_to_queue( $ids );
$queue = array();
$queue['total'] = array_sum( $threads );
$queue['threads'] = array_keys( $threads );
$queue['started'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
Expand Down Expand Up @@ -611,7 +612,7 @@ public function start_queue( $type = 'queue' ) {
* @return bool
*/
public function is_autosync_thread( $thread ) {
return in_array( $thread, $this->autosync_threads );
return in_array( $thread, $this->autosync_threads, true );
}

/**
Expand Down Expand Up @@ -828,17 +829,17 @@ public function get_threads( $type = 'queue' ) {
*/
public function add_to_queue( array $attachment_ids, $type = 'queue' ) {

$been_synced = array_filter( $attachment_ids, array( $this->sync, 'been_synced' ) );
$new_items = array_diff( $attachment_ids, $been_synced );
$threads = $this->get_threads( $type );
$new_thread = array_shift( $threads );
$been_synced = array_filter( $attachment_ids, array( $this->sync, 'been_synced' ) );
$new_items = array_diff( $attachment_ids, $been_synced );
$threads = $this->get_threads( $type );
$new_thread = array_shift( $threads );
$active_threads = array();
if ( ! empty( $new_items ) ) {
$this->add_to_thread_queue( $new_thread, $new_items );
$active_threads[ $new_thread ] = count( $new_items );
}

$attachment_ids = $been_synced;
$active_threads = array();
if ( ! empty( $attachment_ids ) ) {
$chunk_size = ceil( count( $attachment_ids ) / count( $threads ) );
$chunks = array_chunk( $attachment_ids, $chunk_size );
Expand Down
7 changes: 4 additions & 3 deletions php/traits/trait-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,12 @@ protected function maybe_do_export( $unsynced_attachments, $errored_attachments
* @return void
*/
protected function export_csv( $data, $type ) {
$filename = sanitize_file_name( 'cloudinary-' . $type . '-' . time() . '.csv' );
$fp = fopen( $filename, 'wb+' );
$upload = wp_get_upload_dir();
$filename = trailingslashit( $upload['path'] ) . sanitize_file_name( 'cloudinary-' . $type . '-' . time() . '.csv' );
$fp = fopen( $filename, 'wb+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen

foreach ( $data as $fields ) {
fputcsv( $fp, $fields );
fputcsv( $fp, $fields ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fputcsv
}

fclose( $fp );
Expand Down
2 changes: 1 addition & 1 deletion php/ui/component/class-info-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function div( $struct ) {
*/
protected function wrap( $struct ) {
$struct = parent::wrap( $struct );
unset( $struct['attributes']['class'][ array_search( 'has-heading', $struct['attributes']['class'] ) ] );
unset( $struct['attributes']['class'][ array_search( 'has-heading', $struct['attributes']['class'], true ) ] );

return $struct;
}
Expand Down
2 changes: 1 addition & 1 deletion php/ui/component/class-notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function wrap( $struct ) {
* @return array
*/
protected function icon( $struct ) {
$struct['element'] = 'span';
$struct['element'] = 'span';
$struct['attributes']['class'] = array( 'cld-ui-icon' );
if ( $this->setting->has_param( 'icon' ) ) {
$struct['attributes']['class'][] = $this->setting->get_param( 'icon' );
Expand Down
4 changes: 2 additions & 2 deletions php/ui/component/class-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ protected function build_body() {
*/
protected function body_row( $slug, $row ) {
$next_colspan = 1;

$columns = array();
$columns = array();
$previous = null;
foreach ( $this->columns as $column ) {

$col_slug = $slug . '_' . $column;
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<arg name="extensions" value="php" />
<arg name="colors" />
<arg value="s" /><!-- Show sniff codes in all reports. -->
<arg name="severity" value="3" /><!-- Match WPVIP requirements. -->

<!-- Includes WordPress-Core, WordPress-Docs and WordPress-Extra rulesets. -->
<rule ref="WordPress" />
Expand Down
2 changes: 1 addition & 1 deletion ui-definitions/components/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<span class="spinner"></span>
</span>
</div>
<?php require $cloudinary->dir_path . 'php/templates/connection-string.php'; ?>
<?php require $cloudinary->dir_path . 'php/templates/connection-string.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable ?>
</div>
</div>
<div class="cld-wizard-content cld-wizard-optimize hidden" id="tab-3">
Expand Down
2 changes: 1 addition & 1 deletion ui-definitions/settings-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
'type' => 'text',
'slug' => 'image_freeform',
'title' => __( 'Additional image transformations', 'cloudinary' ),
'default' => '',
'default' => '',
'tooltip_text' => sprintf(
// translators: The link to transformation reference.
__(
Expand Down
8 changes: 4 additions & 4 deletions ui-definitions/settings-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@
'priority' => 5,
'requires_connection' => true,
'sidebar' => true,
'settings' => include $this->dir_path . 'ui-definitions/settings-image.php',
'settings' => include $this->dir_path . 'ui-definitions/settings-image.php', // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
),
'video_settings' => array(
'page_title' => __( 'Video settings', 'cloudinary' ),
'menu_title' => __( 'Video settings', 'cloudinary' ),
'priority' => 5,
'requires_connection' => true,
'sidebar' => true,
'settings' => include $this->dir_path . 'ui-definitions/settings-video.php',
'settings' => include $this->dir_path . 'ui-definitions/settings-video.php', // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
),
'lazy_loading' => array(),
'responsive' => array(
Expand Down Expand Up @@ -433,14 +433,14 @@
'section' => 'wizard',
'slug' => 'wizard',
),
'debug' => array(
'debug' => array(
'section' => 'debug',
'slug' => 'debug',
array(
'type' => 'panel',
'title' => __( 'Debug log', 'cloudinary' ),
array(
'type' => 'debug',
'type' => 'debug',
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion ui-definitions/settings-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
'type' => 'text',
'slug' => 'video_freeform',
'title' => __( 'Additional video transformations', 'cloudinary' ),
'default' => '',
'default' => '',
'tooltip_text' => sprintf(
// translators: The link to transformation reference.
__(
Expand Down