Skip to content

Commit a15f5bd

Browse files
committed
Removed redundant checkPurchasedItemUpdateAvailable() methods, that can be handled by the controller
Removed redundant checkPurchasedItemUpdateAvailable() methods, that can be handled by the controller
1 parent 77243fb commit a15f5bd

File tree

11 files changed

+59
-71
lines changed

11 files changed

+59
-71
lines changed

Libraries/EnvatoAPIManager.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,6 @@ public function getItemName($paramEnvatoItemId)
290290
return $itemName;
291291
}
292292

293-
public function checkPurchasedItemUpdateAvailable($paramEnvatoItemId, $paramInstalledVersion)
294-
{
295-
$updateAvailable = FALSE;
296-
$itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId);
297-
if(isset($itemDetails['version']) && version_compare($paramInstalledVersion, $itemDetails['version'], '<'))
298-
{
299-
$updateAvailable = TRUE;
300-
}
301-
302-
return $updateAvailable;
303-
}
304-
305293
public function getAvailableVersion($paramEnvatoItemId)
306294
{
307295
$itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
**Tested up to:** 4.8
1212

13-
**Stable tag:** 1.0
13+
**Stable tag:** 1.1
1414

1515
**License:** MIT License
1616

Test/EnvatoAPIManagerTest.php

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,7 @@
1010
* @copyright KestutisIT
1111
* @license MIT License
1212
*/
13-
14-
// Enable or disable this test. If not testing at the moment - disable the test
15-
$testEnabled = TRUE;
16-
if(!$testEnabled)
17-
{
18-
die('Test is disabled');
19-
}
20-
21-
// Require Php 5.4 or newer
22-
if (version_compare(phpversion(), '5.4.0', '<'))
23-
{
24-
die('Php 5.4 or newer is required. Please upgrade your Php version first.');
25-
}
26-
27-
// Start a session
28-
// Note: Requires Php 5.4+
29-
if(session_status() !== PHP_SESSION_ACTIVE)
30-
{
31-
session_start();
32-
}
33-
34-
$wpBlogHeaderFilePath = '../';
35-
36-
define('WP_USE_THEMES', FALSE); // This is a test class, so we don't need to load
37-
require_once($wpBlogHeaderFilePath.'wp-blog-header.php'); // Note: adapt to match your path
38-
require_once(ABSPATH . '/Libraries/EnvatoAPIManager.php');
13+
defined( 'ABSPATH' ) or die( 'No script kiddies, please!' );
3914

4015
if(isset($_POST['envato_check']))
4116
{
@@ -157,21 +132,23 @@
157132

158133

159134
// 3. Status of Purchased Plugin ID
160-
$pluginUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetPluginId, $sanitizedInstalledPluginVersion);
135+
$availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId);
136+
$pluginUpdateAvailable = version_compare($sanitizedInstalledPluginVersion, $availablePluginVersion, '<');
161137
// View vars
162138
$targetPluginId = intval($sanitizedTargetPluginId); // Ready for print
163139
$installedPluginVersion = esc_html($sanitizedInstalledPluginVersion); // Ready for print
164140
$nameOfTargetPluginId = esc_html($objToolkit->getItemName($sanitizedTargetPluginId));
165-
$availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId);
141+
// It will return the download link only if the update is available, and it is not yet exceeded downloads limit
166142
$pluginUpdateDownloadUrl = $pluginUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetPluginId) : '';
167143

168144
// 4. Status of Purchased Theme ID
169-
$themeUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetThemeId, $sanitizedInstalledThemeVersion);
145+
$availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId);
146+
$themeUpdateAvailable = version_compare($sanitizedInstalledThemeVersion, $availableThemeVersion, '<');
170147
// View vars
171148
$targetThemeId = intval($sanitizedTargetThemeId); // Ready for print
172149
$installedThemeVersion = esc_html($sanitizedInstalledThemeVersion); // Ready for print
173150
$nameOfTargetThemeId = esc_html($objToolkit->getItemName($sanitizedTargetThemeId));
174-
$availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId);
151+
// It will return the download link only if the update is available, and it is not yet exceeded downloads limit
175152
$themeUpdateDownloadUrl = $themeUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetThemeId) : '';
176153

177154
// 5. Envato Item Id of Purchased Plugin
@@ -184,7 +161,7 @@
184161
$targetThemeAuthor = esc_html($sanitizedTargetThemeAuthor); // Ready for print
185162
$foundThemeId = $objToolkit->getItemIdByThemeAndAuthorIfPurchased($sanitizedTargetThemeName, $sanitizedTargetThemeAuthor);
186163

187-
$goBackUrl = pathinfo(__FILE__, PATHINFO_FILENAME).'.php';
164+
$goBackUrl = 'index.php';
188165
require('template.TestResults.php');
189166
} else
190167
{

Test/index.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Envato Toolkit test intro file
4+
*
5+
* @note - This test works only if you have WordPress installed, and you can point to working WordPress install 'wp-blog-header.php' site
6+
* @package EnvatoToolkit Test
7+
* @author KestutisIT
8+
* @copyright KestutisIT
9+
* @license MIT License
10+
*/
11+
12+
// Enable or disable this test. If not testing at the moment - disable the test
13+
$testEnabled = TRUE;
14+
if(!$testEnabled)
15+
{
16+
die('Test is disabled');
17+
}
18+
19+
// Require Php 5.4 or newer
20+
if (version_compare(phpversion(), '5.4.0', '<'))
21+
{
22+
die('Php 5.4 or newer is required. Please upgrade your Php version first.');
23+
}
24+
25+
// Start a session
26+
// Note: Requires Php 5.4+
27+
if(session_status() !== PHP_SESSION_ACTIVE)
28+
{
29+
session_start();
30+
}
31+
32+
define('WP_USE_THEMES', FALSE); // This is a test class, so we don't need to load
33+
require_once('../wp-blog-header.php'); // Note: adapt to match your path
34+
require_once(ABSPATH . '/Libraries/EnvatoAPIManager.php');
35+
36+
// Load the test controller
37+
require_once('EnvatoAPIManagerTest.php');

Test/template.TestResults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
<li>Plugin Update Available: <?php print($pluginUpdateAvailable ? 'Yes' : 'No'); ?></li>
136136
<li>Installed Plugin Version: <?php print($installedPluginVersion); ?></li>
137137
<li>Available Plugin Version: <?php print($availablePluginVersion); ?></li>
138-
<?php if($pluginUpdateAvailable): ?>
138+
<?php if($pluginUpdateDownloadUrl != ''): ?>
139139
<li>Plugin Update Download URL:
140140
<a href="<?php print($pluginUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
141141
</li>
@@ -152,7 +152,7 @@
152152
<li>Theme Update Available: <?php print($themeUpdateAvailable ? 'Yes' : 'No'); ?></li>
153153
<li>Installed Theme Version: <?php print($installedThemeVersion); ?></li>
154154
<li>Available Theme Version: <?php print($availableThemeVersion); ?></li>
155-
<?php if($themeUpdateAvailable): ?>
155+
<?php if($themeUpdateDownloadUrl != ''): ?>
156156
<li>Theme Update Download URL:
157157
<a href="<?php print($themeUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
158158
</li>

WordPress Plugin/EnvatoToolkit/Controllers/class.SearchController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,25 @@ public function printContent()
147147
}
148148

149149
// 3. Status of Purchased Plugin ID
150-
$pluginUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetPluginId, $sanitizedInstalledPluginVersion);
150+
$availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId);
151+
$pluginUpdateAvailable = version_compare($sanitizedInstalledPluginVersion, $availablePluginVersion, '<');
151152
// View vars
152153
$view->targetPluginId = intval($sanitizedTargetPluginId); // Ready for print
153154
$view->installedPluginVersion = esc_html($sanitizedInstalledPluginVersion); // Ready for print
154155
$view->nameOfTargetPluginId = esc_html($objToolkit->getItemName($sanitizedTargetPluginId));
156+
$view->availablePluginVersion = $availablePluginVersion;
155157
$view->pluginUpdateAvailable = $pluginUpdateAvailable;
156-
$view->availablePluginVersion = $objToolkit->getAvailableVersion($sanitizedTargetPluginId);
157158
$view->pluginUpdateDownloadUrl = $pluginUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetPluginId) : '';
158159

159160
// 4. Status of Purchased Theme ID
160-
$themeUpdateAvailable = $objToolkit->checkPurchasedItemUpdateAvailable($sanitizedTargetThemeId, $sanitizedInstalledThemeVersion);
161+
$availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId);
162+
$themeUpdateAvailable = version_compare($sanitizedInstalledThemeVersion, $availableThemeVersion, '<');
161163
// View vars
162164
$view->targetThemeId = intval($sanitizedTargetThemeId); // Ready for print
163165
$view->installedThemeVersion = esc_html($sanitizedInstalledThemeVersion); // Ready for print
164166
$view->nameOfTargetThemeId = esc_html($objToolkit->getItemName($sanitizedTargetThemeId));
167+
$view->availableThemeVersion = $availableThemeVersion;
165168
$view->themeUpdateAvailable = $themeUpdateAvailable;
166-
$view->availableThemeVersion = $objToolkit->getAvailableVersion($sanitizedTargetThemeId);
167169
$view->themeUpdateDownloadUrl = $themeUpdateAvailable ? $objToolkit->getDownloadUrlIfPurchased($sanitizedTargetThemeId) : '';
168170

169171
// 5. Envato Item Id of Purchased Plugin

WordPress Plugin/EnvatoToolkit/EnvatoToolkit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Envato Toolkit
44
* Plugin URI: http://EnvatoToolkit.com
55
* 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.
6-
* Version: 1.0
6+
* Version: 1.1
77
* Author: KestutisIT
88
* Author URI: https://profiles.wordpress.org/KestutisIT
99
* Text Domain: envato-toolkit
@@ -20,7 +20,7 @@
2020

2121
// Create an instance of ET configuration model
2222
$objETConfiguration = new \EnvatoToolkit\Models\Configuration(
23-
$GLOBALS['wpdb'], get_current_blog_id(), '5.4.0', phpversion(), 4.6, $GLOBALS['wp_version'], 1.0, __FILE__
23+
$GLOBALS['wpdb'], get_current_blog_id(), '5.4.0', phpversion(), 4.6, $GLOBALS['wp_version'], 1.1, __FILE__
2424
);
2525

2626
// Create an instance of ET main controller

WordPress Plugin/EnvatoToolkit/Models/class.EnvatoAPIManager.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,6 @@ public function getItemName($paramEnvatoItemId)
288288
return $itemName;
289289
}
290290

291-
public function checkPurchasedItemUpdateAvailable($paramEnvatoItemId, $paramInstalledVersion)
292-
{
293-
$updateAvailable = FALSE;
294-
$itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId);
295-
if(isset($itemDetails['version']) && version_compare($paramInstalledVersion, $itemDetails['version'], '<'))
296-
{
297-
$updateAvailable = TRUE;
298-
}
299-
300-
return $updateAvailable;
301-
}
302-
303291
public function getAvailableVersion($paramEnvatoItemId)
304292
{
305293
$itemDetails = $this->getItemDetailsIfPurchased($paramEnvatoItemId);

WordPress Plugin/EnvatoToolkit/Templates/template.SearchResults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<li>Plugin Update Available: <?php print($pluginUpdateAvailable ? 'Yes' : 'No'); ?></li>
8686
<li>Installed Plugin Version: <?php print($installedPluginVersion); ?></li>
8787
<li>Available Plugin Version: <?php print($availablePluginVersion); ?></li>
88-
<?php if($pluginUpdateAvailable): ?>
88+
<?php if($pluginUpdateDownloadUrl != ''): ?>
8989
<li>Plugin Update Download URL:
9090
<a href="<?php print($pluginUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
9191
</li>
@@ -102,7 +102,7 @@
102102
<li>Theme Update Available: <?php print($themeUpdateAvailable ? 'Yes' : 'No'); ?></li>
103103
<li>Installed Theme Version: <?php print($installedThemeVersion); ?></li>
104104
<li>Available Theme Version: <?php print($availableThemeVersion); ?></li>
105-
<?php if($themeUpdateAvailable): ?>
105+
<?php if($themeUpdateDownloadUrl != ''): ?>
106106
<li>Theme Update Download URL:
107107
<a href="<?php print($themeUpdateDownloadUrl); ?>" target="_blank" title="Download newest version">Download newest version</a>
108108
</li>

WordPress Plugin/EnvatoToolkit/changelog.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)