From a15f5bdb51202f668da99cdcda48dca960f6f8cb Mon Sep 17 00:00:00 2001 From: Kestutis Matuliauskas Date: Wed, 21 Jun 2017 23:15:53 +0300 Subject: [PATCH] Removed redundant checkPurchasedItemUpdateAvailable() methods, that can be handled by the controller Removed redundant checkPurchasedItemUpdateAvailable() methods, that can be handled by the controller --- Libraries/EnvatoAPIManager.php | 12 ------ README.md | 2 +- Test/EnvatoAPIManagerTest.php | 39 ++++--------------- Test/index.php | 37 ++++++++++++++++++ Test/template.TestResults.php | 4 +- .../Controllers/class.SearchController.php | 10 +++-- .../EnvatoToolkit/EnvatoToolkit.php | 4 +- .../Models/class.EnvatoAPIManager.php | 12 ------ .../Templates/template.SearchResults.php | 4 +- WordPress Plugin/EnvatoToolkit/changelog.txt | 4 -- WordPress Plugin/EnvatoToolkit/readme.txt | 2 +- 11 files changed, 59 insertions(+), 71 deletions(-) create mode 100644 Test/index.php delete mode 100644 WordPress Plugin/EnvatoToolkit/changelog.txt diff --git a/Libraries/EnvatoAPIManager.php b/Libraries/EnvatoAPIManager.php index 7d4c456..e4e2c48 100644 --- a/Libraries/EnvatoAPIManager.php +++ b/Libraries/EnvatoAPIManager.php @@ -290,18 +290,6 @@ public function getItemName($paramEnvatoItemId) return $itemName; } - public function checkPurchasedItemUpdateAvailable($paramEnvatoItemId, $paramInstalledVersion) - { - $updateAvailable = FALSE; - $itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId); - if(isset($itemDetails['version']) && version_compare($paramInstalledVersion, $itemDetails['version'], '<')) - { - $updateAvailable = TRUE; - } - - return $updateAvailable; - } - public function getAvailableVersion($paramEnvatoItemId) { $itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId); diff --git a/README.md b/README.md index 8437017..2dbdb10 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ **Tested up to:** 4.8 -**Stable tag:** 1.0 +**Stable tag:** 1.1 **License:** MIT License diff --git a/Test/EnvatoAPIManagerTest.php b/Test/EnvatoAPIManagerTest.php index b89598c..473159e 100644 --- a/Test/EnvatoAPIManagerTest.php +++ b/Test/EnvatoAPIManagerTest.php @@ -10,32 +10,7 @@ * @copyright KestutisIT * @license MIT License */ - -// Enable or disable this test. If not testing at the moment - disable the test -$testEnabled = TRUE; -if(!$testEnabled) -{ - die('Test is disabled'); -} - -// Require Php 5.4 or newer -if (version_compare(phpversion(), '5.4.0', '<')) -{ - die('Php 5.4 or newer is required. Please upgrade your Php version first.'); -} - -// Start a session -// Note: Requires Php 5.4+ -if(session_status() !== PHP_SESSION_ACTIVE) -{ - session_start(); -} - -$wpBlogHeaderFilePath = '../'; - -define('WP_USE_THEMES', FALSE); // This is a test class, so we don't need to load -require_once($wpBlogHeaderFilePath.'wp-blog-header.php'); // Note: adapt to match your path -require_once(ABSPATH . '/Libraries/EnvatoAPIManager.php'); +defined( 'ABSPATH' ) or die( 'No script kiddies, please!' ); if(isset($_POST['envato_check'])) { @@ -157,21 +132,23 @@ // 3. Status of Purchased Plugin ID - $pluginUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetPluginId, $sanitizedInstalledPluginVersion); + $availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId); + $pluginUpdateAvailable = version_compare($sanitizedInstalledPluginVersion, $availablePluginVersion, '<'); // View vars $targetPluginId = intval($sanitizedTargetPluginId); // Ready for print $installedPluginVersion = esc_html($sanitizedInstalledPluginVersion); // Ready for print $nameOfTargetPluginId = esc_html($objToolkit->getItemName($sanitizedTargetPluginId)); - $availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId); + // It will return the download link only if the update is available, and it is not yet exceeded downloads limit $pluginUpdateDownloadUrl = $pluginUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetPluginId) : ''; // 4. Status of Purchased Theme ID - $themeUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetThemeId, $sanitizedInstalledThemeVersion); + $availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId); + $themeUpdateAvailable = version_compare($sanitizedInstalledThemeVersion, $availableThemeVersion, '<'); // View vars $targetThemeId = intval($sanitizedTargetThemeId); // Ready for print $installedThemeVersion = esc_html($sanitizedInstalledThemeVersion); // Ready for print $nameOfTargetThemeId = esc_html($objToolkit->getItemName($sanitizedTargetThemeId)); - $availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId); + // It will return the download link only if the update is available, and it is not yet exceeded downloads limit $themeUpdateDownloadUrl = $themeUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetThemeId) : ''; // 5. Envato Item Id of Purchased Plugin @@ -184,7 +161,7 @@ $targetThemeAuthor = esc_html($sanitizedTargetThemeAuthor); // Ready for print $foundThemeId = $objToolkit->getItemIdByThemeAndAuthorIfPurchased($sanitizedTargetThemeName, $sanitizedTargetThemeAuthor); - $goBackUrl = pathinfo(__FILE__, PATHINFO_FILENAME).'.php'; + $goBackUrl = 'index.php'; require('template.TestResults.php'); } else { diff --git a/Test/index.php b/Test/index.php new file mode 100644 index 0000000..06009a2 --- /dev/null +++ b/Test/index.php @@ -0,0 +1,37 @@ +Plugin Update Available:
  • Installed Plugin Version:
  • Available Plugin Version:
  • - +
  • Plugin Update Download URL: Download newest version
  • @@ -152,7 +152,7 @@
  • Theme Update Available:
  • Installed Theme Version:
  • Available Theme Version:
  • - +
  • Theme Update Download URL: Download newest version
  • diff --git a/WordPress Plugin/EnvatoToolkit/Controllers/class.SearchController.php b/WordPress Plugin/EnvatoToolkit/Controllers/class.SearchController.php index 9619ea1..631e2b1 100644 --- a/WordPress Plugin/EnvatoToolkit/Controllers/class.SearchController.php +++ b/WordPress Plugin/EnvatoToolkit/Controllers/class.SearchController.php @@ -147,23 +147,25 @@ public function printContent() } // 3. Status of Purchased Plugin ID - $pluginUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetPluginId, $sanitizedInstalledPluginVersion); + $availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId); + $pluginUpdateAvailable = version_compare($sanitizedInstalledPluginVersion, $availablePluginVersion, '<'); // View vars $view->targetPluginId = intval($sanitizedTargetPluginId); // Ready for print $view->installedPluginVersion = esc_html($sanitizedInstalledPluginVersion); // Ready for print $view->nameOfTargetPluginId = esc_html($objToolkit->getItemName($sanitizedTargetPluginId)); + $view->availablePluginVersion = $availablePluginVersion; $view->pluginUpdateAvailable = $pluginUpdateAvailable; - $view->availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId); $view->pluginUpdateDownloadUrl = $pluginUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetPluginId) : ''; // 4. Status of Purchased Theme ID - $themeUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetThemeId, $sanitizedInstalledThemeVersion); + $availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId); + $themeUpdateAvailable = version_compare($sanitizedInstalledThemeVersion, $availableThemeVersion, '<'); // View vars $view->targetThemeId = intval($sanitizedTargetThemeId); // Ready for print $view->installedThemeVersion = esc_html($sanitizedInstalledThemeVersion); // Ready for print $view->nameOfTargetThemeId = esc_html($objToolkit->getItemName($sanitizedTargetThemeId)); + $view->availableThemeVersion = $availableThemeVersion; $view->themeUpdateAvailable = $themeUpdateAvailable; - $view->availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId); $view->themeUpdateDownloadUrl = $themeUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetThemeId) : ''; // 5. Envato Item Id of Purchased Plugin diff --git a/WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php b/WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php index 584dd39..60b3abc 100644 --- a/WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php +++ b/WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php @@ -3,7 +3,7 @@ * Plugin Name: Envato Toolkit * Plugin URI: http://EnvatoToolkit.com * Description: It is a 3 files library + Visual UI, to validate the purchase codes of your customers, get details about specific Envato user (country, city, total followers, total sales, avatar), get his license purchase and support expiration dates, license type he bought, check for updates of purchased plugins and themes and get the download links for them. Plus - this library has Envato Item Id search feature by providing plugin's or theme's name and author. - * Version: 1.0 + * Version: 1.1 * Author: KestutisIT * Author URI: https://profiles.wordpress.org/KestutisIT * Text Domain: envato-toolkit @@ -20,7 +20,7 @@ // Create an instance of ET configuration model $objETConfiguration = new \EnvatoToolkit\Models\Configuration( - $GLOBALS['wpdb'], get_current_blog_id(), '5.4.0', phpversion(), 4.6, $GLOBALS['wp_version'], 1.0, __FILE__ + $GLOBALS['wpdb'], get_current_blog_id(), '5.4.0', phpversion(), 4.6, $GLOBALS['wp_version'], 1.1, __FILE__ ); // Create an instance of ET main controller diff --git a/WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php b/WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php index 3de39c8..7f6fdff 100644 --- a/WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php +++ b/WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php @@ -288,18 +288,6 @@ public function getItemName($paramEnvatoItemId) return $itemName; } - public function checkPurchasedItemUpdateAvailable($paramEnvatoItemId, $paramInstalledVersion) - { - $updateAvailable = FALSE; - $itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId); - if(isset($itemDetails['version']) && version_compare($paramInstalledVersion, $itemDetails['version'], '<')) - { - $updateAvailable = TRUE; - } - - return $updateAvailable; - } - public function getAvailableVersion($paramEnvatoItemId) { $itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId); diff --git a/WordPress Plugin/EnvatoToolkit/Templates/template.SearchResults.php b/WordPress Plugin/EnvatoToolkit/Templates/template.SearchResults.php index c5bbe6a..ace5b2c 100644 --- a/WordPress Plugin/EnvatoToolkit/Templates/template.SearchResults.php +++ b/WordPress Plugin/EnvatoToolkit/Templates/template.SearchResults.php @@ -85,7 +85,7 @@
  • Plugin Update Available:
  • Installed Plugin Version:
  • Available Plugin Version:
  • - +
  • Plugin Update Download URL: Download newest version
  • @@ -102,7 +102,7 @@
  • Theme Update Available:
  • Installed Theme Version:
  • Available Theme Version:
  • - +
  • Theme Update Download URL: Download newest version
  • diff --git a/WordPress Plugin/EnvatoToolkit/changelog.txt b/WordPress Plugin/EnvatoToolkit/changelog.txt deleted file mode 100644 index 74cb890..0000000 --- a/WordPress Plugin/EnvatoToolkit/changelog.txt +++ /dev/null @@ -1,4 +0,0 @@ -== Changelog == - -= 1.0 = -* Initial release! \ No newline at end of file diff --git a/WordPress Plugin/EnvatoToolkit/readme.txt b/WordPress Plugin/EnvatoToolkit/readme.txt index b8bd021..f9b24c2 100644 --- a/WordPress Plugin/EnvatoToolkit/readme.txt +++ b/WordPress Plugin/EnvatoToolkit/readme.txt @@ -5,7 +5,7 @@ Website link: https://profiles.wordpress.org/KestutisIT Tags: Envato Toolkit, Purchase code validation, update checker, Envato API Requires at least: 4.6 Tested up to: 4.8 -Stable tag: 1.0 +Stable tag: 1.1 License: MIT License License URI: https://opensource.org/licenses/MIT