Skip to content

Commit

Permalink
Merge pull request #101 from uploadcare/feature/download-improve
Browse files Browse the repository at this point in the history
Downloading images independently of the current project to Uploadcare.
  • Loading branch information
rsedykh committed Mar 22, 2024
2 parents 2797430 + 3898030 commit e1ffbaa
Show file tree
Hide file tree
Showing 36 changed files with 9,681 additions and 9,791 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Deploy to WordPress.org
on:
workflow_dispatch:
push:
tags:
- "*"
Expand All @@ -13,7 +14,7 @@ jobs:
php-versions: [ "7.4" ]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install dependencies
uses: php-actions/composer@v6
with:
Expand All @@ -22,17 +23,17 @@ jobs:
version: 2.x
- name: Install npm dependencies
run: |
curl -sS https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
echo "deb https://deb.nodesource.com/node_17.x focal main" | sudo tee /etc/apt/sources.list.d/nodesource.list
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install -y nodejs yarn
sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install -y nodejs yarn
sudo npm install -g node-gyp
yarn --version
yarn && yarn run build
rm -rf node_modules
- name: Upload Action Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: uploadcare-wp
path: .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
vendor
node_modules
compiled-js/*
.phpunit.result.cache
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,43 @@ All notable changes to this project will be documented in this file.
The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.1.0] — 2024-03-20

Fixed:
* Fixed behaviour when uploading and downloading current images to and from Uploadcare storage.
* Autotests support.

Compatibility:
* Tested in WordPress up to version 6.4.3


## [3.0.11] — 2023-11-14

Fixed:
* Corrected the URL to the "upload with Uploadcare" button icon.

Compatibility:
* Tested in WordPress up to version 6.4.


## [3.0.10] — 2022-12-14

* Fixed PHP 7.4 support.


## [3.0.9] — 2022-12-14

* Added PHP 8.1 support.
* Bumped minimal PHP version to 7.4.
* Masked secret key in plugin settings for additional security.
* Updated Uploadcare widget.


## [3.0.8] — 2022-01-24

* Removed types from method (bug fix for https://wordpress.org/support/topic/fatal-error-3-0-7/).


## [3.0.7] — 2021-08-20

* Changed plugin responsive images default mechanism to leverage default WordPress "srcset" behavior improved with our smart image quality and auto format features.
Expand All @@ -28,39 +50,46 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Created console utility to transfer all files at once.
* Minor bug fixes and improvements.


## [3.0.6] — 2021-05-26

* Fixed an issue with missing UUIDs for previously uploaded images, which led to an error while rendering images.
* Various fixes and improvements.


## [3.0.5] — 2021-04-07

* Now you can copy your WordPress Media Library to Uploadcare cloud storage. Files in Media Library don’t get removed.
* Image source URLs in posts don’t change. However, when a post is rendered, images get delivered with Uploadcare CDN powered by Adaptive Delivery technology.


## [3.0.4] — 2021-03-09

* Added placeholder for Uploadcare Image caption.
* Fixed update process from 2.7.x to 3.x.x.
* Various other fixes.


## [3.0.3] — 2021-02-16

* Fixed upload button position on "Add media" page.
* Refactored code for better performance and control.
* Now you can use Uploadcare Image Editor to modify images from Media Library.


## [3.0.2] — 2021-01-13

* Plugin as class.
* Composer autoload.
* Unit-tests for most classes and methods.


## [3.0.1] — 2020-12-25

* Fixed issue with plugin activation to prevent malfunction when PHP DOMDocument class is disabled.
* Various small improvements.


## [3.0.0] — 2020-12-25

* Brand new version, rewritten from scratch.
Expand All @@ -70,6 +99,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Updated Settings page.
* Removed "uploadcare" shortcode that allowed your readers to upload files.


## [2.7.2] — 2020-05-13

### Fixed
Expand Down
88 changes: 42 additions & 46 deletions admin/MediaDataLoader.php
Original file line number Diff line number Diff line change
@@ -1,114 +1,110 @@
<?php declare(strict_types=1);
<?php declare( strict_types=1 );

class MediaDataLoader
{
class MediaDataLoader {
public const POST_PER_PAGE = 20;

public function loadMedia(int $page = 1, int $postPerPage = null): iterable
{
$params = $this->imagesQueryParams($page, $postPerPage ?? self::POST_PER_PAGE);
public function loadMedia( int $page = 1, int $postPerPage = null ): iterable {
$params = $this->imagesQueryParams( $page, $postPerPage ?? self::POST_PER_PAGE );

return $this->query($params);
return $this->query( $params );
}

public function loadMediaForPost(int $postId): iterable
{
$parameters = $this->imagesQueryParams(1, -1);
public function loadMediaForPost( int $postId ): iterable {
$parameters = $this->imagesQueryParams( 1, - 1 );
$parameters['post_parent'] = $postId;

return $this->query($parameters);
return $this->query( $parameters );
}

public function countMediaForPost(int $postId): array
{
$parameters = $this->imagesQueryParams(1, -1);
public function countMediaForPost( int $postId ): array {
$parameters = $this->imagesQueryParams( 1, - 1 );
$parameters['post_parent'] = $postId;
$totalCount = (new \WP_Query($parameters))->found_posts;
$totalCount = ( new \WP_Query( $parameters ) )->found_posts;

$parameters['meta_query'] = [
'relation' => 'AND',
[
'key' => 'uploadcare_uuid',
'key' => 'uploadcare_uuid',
'compare' => 'EXISTS',
],
[
'key' => 'uploadcare_uuid',
'value' => null,
'key' => 'uploadcare_uuid',
'value' => null,
'compare' => '!=',
],
];
$ucCount = (new \WP_Query($parameters))->found_posts;
$ucCount = ( new \WP_Query( $parameters ) )->found_posts;

return [
'total' => $totalCount,
'total' => $totalCount,
'uploadcare' => $ucCount,
];
}

protected function query(array $params): iterable
{
$query = new \WP_Query($params);
protected function query( array $params ): iterable {
$query = new \WP_Query( $params );
$result = [];

if (!$query->have_posts()) {
if ( ! $query->have_posts() ) {
return $result;
}

foreach ($query->posts as $post) {
foreach ( $query->posts as $post ) {
$result[] = $post;
}

return $result;
}

public function countImageType(bool $local = false): int
{
$parameters = $this->imagesQueryParams(1, -1);
$metaQuery = [
public function countImageType( bool $local = false ): int {
$parameters = $this->imagesQueryParams( 1, - 1 );
$metaQuery = [
'relation' => 'AND',
[
'key' => 'uploadcare_uuid',
'key' => 'uploadcare_uuid',
'compare' => 'EXISTS',
],
[
'key' => 'uploadcare_uuid',
'value' => null,
'key' => 'uploadcare_uuid',
'value' => null,
'compare' => '!=',
],
];

if ($local === true) {
if ( $local === true ) {
$metaQuery = [
'relation' => 'OR',
[
'key' => 'uploadcare_uuid',
'key' => 'uploadcare_uuid',
'compare' => 'NOT EXISTS',
'value' => '',
'value' => '',
],
[
'key' => 'uploadcare_uuid',
'value' => null,
'key' => 'uploadcare_uuid',
'value' => null,
'compare' => '=',
],
];
}
$parameters['meta_query'] = $metaQuery;

return (new \WP_Query($parameters))->found_posts;
return ( new \WP_Query( $parameters ) )->found_posts;
}

public function getCount(): int
{
return (new \WP_Query(['post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => -1]))->found_posts;
public function getCount(): int {
return ( new \WP_Query( [ 'post_type' => 'attachment',
'post_status' => 'any',
'posts_per_page' => - 1
] ) )->found_posts;
}

protected function imagesQueryParams(int $page, int $postPerPage): array
{
protected function imagesQueryParams( int $page, int $postPerPage ): array {
return [
'post_type' => 'attachment',
'post_type' => 'attachment',
'posts_per_page' => $postPerPage,
'paged' => $page,
'post_status' => 'any',
'paged' => $page,
'post_status' => 'any',
];
}
}

Loading

0 comments on commit e1ffbaa

Please sign in to comment.