-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for non-image uploads when you have the WordPress setting "" tu…
…rned off but no upload path set in Cloud Storage Settings. If you were having problems with videos, PDF's, etc. this should fix it. * Performance fix for sites with huge post tables that were seeing slow page performance. * Fix for IPTC parsing that contains binary data * Fix for a library conflict * Warning that the built-in Dynamic Images functionality will be deprecated in the next major version * Warning about library incompatibility with TranslatePress
- Loading branch information
Showing
140 changed files
with
10,194 additions
and
1,308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
// Copyright (c) 2016 Interfacelab LLC. All rights reserved. | ||
// | ||
// Released under the GPLv3 license | ||
// http://www.gnu.org/licenses/gpl-3.0.html | ||
// | ||
// ********************************************************************** | ||
// This program is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// ********************************************************************** | ||
|
||
namespace ILAB\MediaCloud\Storage; | ||
|
||
/** | ||
* Interface for creating the required tables | ||
*/ | ||
final class StoragePostMap { | ||
const DB_VERSION = '1.0.0'; | ||
const DB_KEY = 'mcloud_post_map_db_version'; | ||
|
||
private static $installed = false; | ||
private static $cache = []; | ||
|
||
/** | ||
* Insures the additional database tables are installed | ||
*/ | ||
public static function init() { | ||
static::verifyInstalled(); | ||
} | ||
|
||
//region Install Database Tables | ||
|
||
protected static function verifyInstalled() { | ||
if (static::$installed === true) { | ||
return true; | ||
} | ||
|
||
$currentVersion = get_site_option(self::DB_KEY); | ||
if (!empty($currentVersion) && version_compare(self::DB_VERSION, $currentVersion, '==')) { | ||
global $wpdb; | ||
|
||
$tableName = $wpdb->base_prefix.'mcloud_post_map'; | ||
$exists = ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName); | ||
if ($exists) { | ||
static::$installed = true; | ||
return true; | ||
} | ||
} | ||
|
||
return static::installMapTable(); | ||
} | ||
|
||
protected static function installMapTable() { | ||
global $wpdb; | ||
|
||
$tableName = $wpdb->base_prefix.'mcloud_post_map'; | ||
$charset = $wpdb->get_charset_collate(); | ||
|
||
$sql = "CREATE TABLE {$tableName} ( | ||
id BIGINT AUTO_INCREMENT, | ||
post_id BIGINT NOT NULL, | ||
post_url VARCHAR(255) NOT NULL, | ||
PRIMARY KEY (id), | ||
KEY post_id(post_id), | ||
KEY post_url(post_url(255)) | ||
) {$charset};"; | ||
|
||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | ||
dbDelta($sql); | ||
|
||
$exists = ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName); | ||
if ($exists) { | ||
update_site_option(self::DB_KEY, self::DB_VERSION); | ||
static::$installed = true; | ||
return true; | ||
} | ||
|
||
static::$installed = false; | ||
return false; | ||
} | ||
|
||
//endregion | ||
|
||
//region Queries | ||
public static function uncachedAttachmentIdFromURL($url, $bucketName) { | ||
global $wpdb; | ||
|
||
$query = $wpdb->prepare("select ID from {$wpdb->posts} where post_type='attachment' and guid = %s order by ID desc limit 1", $url); | ||
$postId = $wpdb->get_var($query); | ||
|
||
if (empty($postId)) { | ||
$parsedUrl = parse_url($url); | ||
$path = ltrim($parsedUrl['path'], '/'); | ||
|
||
if (!empty($bucketName) && (strpos($path, $bucketName) === 0)) { | ||
$path = ltrim(str_replace($bucketName,'', $path),'/'); | ||
} | ||
|
||
$path = apply_filters('media-cloud/glide/clean-path', $path); | ||
|
||
$query = $wpdb->prepare("select ID from {$wpdb->posts} where post_type='attachment' and guid like %s order by ID desc limit 1", '%'.$path); | ||
$postId = $wpdb->get_var($query); | ||
} | ||
|
||
return $postId; | ||
} | ||
|
||
public static function attachmentIdFromURL($postId, $url, $bucketName) { | ||
if (!empty($postId)) { | ||
return $postId; | ||
} | ||
|
||
if (isset(static::$cache[$url])) { | ||
return static::$cache[$url]; | ||
} | ||
|
||
if (!empty(StorageGlobals::cacheLookups())) { | ||
global $wpdb; | ||
|
||
$tableName = $wpdb->base_prefix.'mcloud_post_map'; | ||
|
||
if (static::verifyInstalled()) { | ||
$query = $wpdb->prepare("select post_id from {$tableName} where post_url = %s order by post_id desc limit 1", $url); | ||
$postId = (int)$wpdb->get_var($query); | ||
if (($postId === -1) || !empty($postId)) { | ||
return ($postId === -1) ? null : $postId; | ||
} | ||
} | ||
|
||
$postId = static::uncachedAttachmentIdFromURL($url, $bucketName); | ||
|
||
if (!empty($postId)) { | ||
static::$cache[$url] = $postId; | ||
if (static::$installed === true) { | ||
$wpdb->insert($tableName, ['post_id' => empty($postId) ? -1 : $postId, 'post_url' => $url], ['%d', '%s']); | ||
} | ||
} | ||
|
||
return $postId; | ||
} | ||
|
||
$postId = static::uncachedAttachmentIdFromURL($url, $bucketName); | ||
return $postId; | ||
} | ||
//endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
classes/Utilities/Misc/Symfony/Component/Config/ConfigCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config; | ||
|
||
use ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config\Resource\SelfCheckingResourceChecker; | ||
/** | ||
* ConfigCache caches arbitrary content in files on disk. | ||
* | ||
* When in debug mode, those metadata resources that implement | ||
* \Symfony\Component\Config\Resource\SelfCheckingResourceInterface will | ||
* be used to check cache freshness. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Matthias Pigulla <[email protected]> | ||
*/ | ||
class ConfigCache extends \ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config\ResourceCheckerConfigCache | ||
{ | ||
private $debug; | ||
/** | ||
* @param string $file The absolute cache path | ||
* @param bool $debug Whether debugging is enabled or not | ||
*/ | ||
public function __construct($file, $debug) | ||
{ | ||
$this->debug = (bool) $debug; | ||
$checkers = []; | ||
if (\true === $this->debug) { | ||
$checkers = [new \ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config\Resource\SelfCheckingResourceChecker()]; | ||
} | ||
parent::__construct($file, $checkers); | ||
} | ||
/** | ||
* Checks if the cache is still fresh. | ||
* | ||
* This implementation always returns true when debug is off and the | ||
* cache file exists. | ||
* | ||
* @return bool true if the cache is fresh, false otherwise | ||
*/ | ||
public function isFresh() | ||
{ | ||
if (!$this->debug && \is_file($this->getPath())) { | ||
return \true; | ||
} | ||
return parent::isFresh(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
classes/Utilities/Misc/Symfony/Component/Config/ConfigCacheFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config; | ||
|
||
/** | ||
* Basic implementation of ConfigCacheFactoryInterface that | ||
* creates an instance of the default ConfigCache. | ||
* | ||
* This factory and/or cache <em>do not</em> support cache validation | ||
* by means of ResourceChecker instances (that is, service-based). | ||
* | ||
* @author Matthias Pigulla <[email protected]> | ||
*/ | ||
class ConfigCacheFactory implements \ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config\ConfigCacheFactoryInterface | ||
{ | ||
private $debug; | ||
/** | ||
* @param bool $debug The debug flag to pass to ConfigCache | ||
*/ | ||
public function __construct($debug) | ||
{ | ||
$this->debug = $debug; | ||
} | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function cache($file, $callback) | ||
{ | ||
if (!\is_callable($callback)) { | ||
throw new \InvalidArgumentException(\sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback))); | ||
} | ||
$cache = new \ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config\ConfigCache($file, $this->debug); | ||
if (!$cache->isFresh()) { | ||
\call_user_func($callback, $cache); | ||
} | ||
return $cache; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
classes/Utilities/Misc/Symfony/Component/Config/ConfigCacheFactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace ILAB\MediaCloud\Utilities\Misc\Symfony\Component\Config; | ||
|
||
/** | ||
* Interface for a ConfigCache factory. This factory creates | ||
* an instance of ConfigCacheInterface and initializes the | ||
* cache if necessary. | ||
* | ||
* @author Matthias Pigulla <[email protected]> | ||
*/ | ||
interface ConfigCacheFactoryInterface | ||
{ | ||
/** | ||
* Creates a cache instance and (re-)initializes it if necessary. | ||
* | ||
* @param string $file The absolute cache file path | ||
* @param callable $callable The callable to be executed when the cache needs to be filled (i. e. is not fresh). The cache will be passed as the only parameter to this callback | ||
* | ||
* @return ConfigCacheInterface The cache instance | ||
*/ | ||
public function cache($file, $callable); | ||
} |
Oops, something went wrong.