Skip to content

Commit

Permalink
Removed redundant checkPurchasedItemUpdateAvailable() methods, that c…
Browse files Browse the repository at this point in the history
…an be handled by the controller

Removed redundant checkPurchasedItemUpdateAvailable() methods, that can
be handled by the controller
  • Loading branch information
kkMatt committed Jun 21, 2017
1 parent 77243fb commit a15f5bd
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 71 deletions.
12 changes: 0 additions & 12 deletions Libraries/EnvatoAPIManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

**Tested up to:** 4.8

**Stable tag:** 1.0
**Stable tag:** 1.1

**License:** MIT License

Expand Down
39 changes: 8 additions & 31 deletions Test/EnvatoAPIManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
{
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand Down
37 changes: 37 additions & 0 deletions Test/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Envato Toolkit test intro file
*
* @note - This test works only if you have WordPress installed, and you can point to working WordPress install 'wp-blog-header.php' site
* @package EnvatoToolkit Test
* @author KestutisIT
* @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();
}

define('WP_USE_THEMES', FALSE); // This is a test class, so we don't need to load
require_once('../wp-blog-header.php'); // Note: adapt to match your path
require_once(ABSPATH . '/Libraries/EnvatoAPIManager.php');

// Load the test controller
require_once('EnvatoAPIManagerTest.php');
4 changes: 2 additions & 2 deletions Test/template.TestResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<li>Plugin Update Available: <?php print($pluginUpdateAvailable ? 'Yes' : 'No'); ?></li>
<li>Installed Plugin Version: <?php print($installedPluginVersion); ?></li>
<li>Available Plugin Version: <?php print($availablePluginVersion); ?></li>
<?php if($pluginUpdateAvailable): ?>
<?php if($pluginUpdateDownloadUrl != ''): ?>
<li>Plugin Update Download URL:
<a href="<?php print($pluginUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
</li>
Expand All @@ -152,7 +152,7 @@
<li>Theme Update Available: <?php print($themeUpdateAvailable ? 'Yes' : 'No'); ?></li>
<li>Installed Theme Version: <?php print($installedThemeVersion); ?></li>
<li>Available Theme Version: <?php print($availableThemeVersion); ?></li>
<?php if($themeUpdateAvailable): ?>
<?php if($themeUpdateDownloadUrl != ''): ?>
<li>Theme Update Download URL:
<a href="<?php print($themeUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<li>Plugin Update Available: <?php print($pluginUpdateAvailable ? 'Yes' : 'No'); ?></li>
<li>Installed Plugin Version: <?php print($installedPluginVersion); ?></li>
<li>Available Plugin Version: <?php print($availablePluginVersion); ?></li>
<?php if($pluginUpdateAvailable): ?>
<?php if($pluginUpdateDownloadUrl != ''): ?>
<li>Plugin Update Download URL:
<a href="<?php print($pluginUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
</li>
Expand All @@ -102,7 +102,7 @@
<li>Theme Update Available: <?php print($themeUpdateAvailable ? 'Yes' : 'No'); ?></li>
<li>Installed Theme Version: <?php print($installedThemeVersion); ?></li>
<li>Available Theme Version: <?php print($availableThemeVersion); ?></li>
<?php if($themeUpdateAvailable): ?>
<?php if($themeUpdateDownloadUrl != ''): ?>
<li>Theme Update Download URL:
<a href="<?php print($themeUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
</li>
Expand Down
4 changes: 0 additions & 4 deletions WordPress Plugin/EnvatoToolkit/changelog.txt

This file was deleted.

2 changes: 1 addition & 1 deletion WordPress Plugin/EnvatoToolkit/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a15f5bd

Please sign in to comment.