Browse Source

+ throw exception is guids not appropriated to local site url

* basename extraction support multibyte strings filenames
master
dimti 2 years ago
parent
commit
0e490e3fc6
  1. 17
      src/Actions/Convert/Replacer/PostAttachmentReplacer.php
  2. 6
      src/Actions/Convert/ReplacerService.php
  3. 6
      src/Exceptions/UrlDetectException.php
  4. 5
      src/Models/PostAttachment.php
  5. 10
      src/Support/helpers.php
  6. 1
      wpstudio-media-cloud-transform.php

17
src/Actions/Convert/Replacer/PostAttachmentReplacer.php

@ -1,7 +1,8 @@
<?php namespace WpsMcloud\Actions\Convert\Replacer;
use WpsMcloud\Actions\Convert\ReplacerService;
use WpsMcloud\Models\PostAttachment;
use WpsMcloud\Actions\Convert\ReplacerService;
use WpsMcloud\Exceptions\UrlDetectException;
class PostAttachmentReplacer
{
@ -36,6 +37,20 @@ class PostAttachmentReplacer
$post->getUrl()
);
if ($this->mcloudPostUrl == $post->getUrl()) {
throw new UrlDetectException(
sprintf(<<<EOF
Your site url has manual changed in wp-config and not appropriate with post attachments guids.
Guid: %s
Manual url: %s
EOF,
$post->getUrl(),
$replacer->getUploadsDirBaseUrl()
)
);
}
$this->mcloudPostBaseUrl = trailingslashit(
str_replace($this->post->getBasename(), '', $this->mcloudPostUrl)
);

6
src/Actions/Convert/ReplacerService.php

@ -1,9 +1,9 @@
<?php namespace WpsMcloud\Actions\Convert;
use WpsMcloud\Support\Http;
use WpsMcloud\Support\Counters;
use WpsMcloud\Actions\Convert;
use WpsMcloud\Models\PostAttachment;
use WpsMcloud\Support\Counters;
use WpsMcloud\Support\Http;
class ReplacerService
{
@ -72,7 +72,7 @@ class ReplacerService
$meta['sizes'] = $newSizes;
}
update_post_meta( $post->getId(), '_wp_attachment_metadata', $meta );
$post->setAttachmentMetaData($meta);
Counters::$processedImages++;
}

6
src/Exceptions/UrlDetectException.php

@ -0,0 +1,6 @@
<?php namespace WpsMcloud\Exceptions;
class UrlDetectException extends WpstudioMediaCloudTransformException
{
}

5
src/Models/PostAttachment.php

@ -1,7 +1,5 @@
<?php namespace WpsMcloud\Models;
use JetBrains\PhpStorm\Pure;
class PostAttachment
{
const META_KEY_FLAGGED_AS_404 = '_wp_media_cloud_transform_404';
@ -47,7 +45,7 @@ class PostAttachment
public function getBasename(): string
{
return basename($this->getUrl());
return mb_basename($this->getUrl());
}
public function getPostMimeType(): string
@ -57,7 +55,6 @@ class PostAttachment
public function setAttachmentMetaData(array $meta)
{
update_post_meta($this->getId(), self::META_KEY_ATTACHMENT_METADATA, $meta);
}

10
src/Support/helpers.php

@ -0,0 +1,10 @@
<?php
if (!function_exists('mb_basename')) {
function mb_basename(string $file)
{
$filenameParts = explode('/', $file);
return end($filenameParts);
}
}

1
wpstudio-media-cloud-transform.php

@ -30,6 +30,7 @@ add_action('admin_menu', fn () => add_submenu_page(
//
// $ilabClassLoader = new Composer\Autoload\ClassLoader();
// $ilabLoader->unregister();
include __DIR__ . '/src/Support/helpers.php';
$localVendorAutoloadPath = 'vendor/autoload.php';
$projectVendorAutoloadPath = ABSPATH . 'vendor/autoload.php';

Loading…
Cancel
Save