Version Description
- Fix: WordPress coding standards.
Download this release
Release Info
Developer | keywordrush |
Plugin | Content Egg |
Version | 5.4.0 |
Comparing to | |
See all releases |
Code changes from version 5.3.0 to 5.4.0
- application/Installer.php +2 -2
- application/LocalRedirect.php +7 -4
- application/Plugin.php +1 -1
- application/PriceAlert.php +27 -18
- application/PriceMoversWidget.php +7 -3
- application/ProductSearch.php +1 -1
- application/ProductSearchWidget.php +1 -1
- application/WooIntegrator.php +6 -2
- application/admin/AdminNotice.php +4 -4
- application/admin/AutoblogController.php +29 -33
- application/admin/EggMetabox.php +20 -10
- application/admin/GeneralConfig.php +7 -7
- application/admin/ImportExportController.php +2 -3
- application/admin/MyListTable.php +5 -6
- application/admin/PluginAdmin.php +2 -2
- application/admin/PrefillController.php +13 -18
- application/admin/ProductController.php +2 -2
- application/admin/ProductTable.php +5 -5
- application/admin/ToolsController.php +11 -8
- application/admin/views/_metabox_autoblog.php +107 -107
- application/admin/views/_metabox_results.php +17 -17
- application/admin/views/_metabox_search_results.php +5 -5
- application/admin/views/_metabox_search_results_images.php +2 -3
- application/admin/views/_promo_box.php +10 -10
- application/admin/views/ae_integration.php +5 -5
- application/admin/views/autoblog_edit.php +10 -10
- application/admin/views/autoblog_index.php +5 -6
- application/admin/views/import_export.php +8 -8
- application/admin/views/metabox_general.php +7 -8
- application/admin/views/metabox_module.php +33 -33
- application/admin/views/module_index.php +12 -12
- application/admin/views/module_settings.php +21 -21
- application/admin/views/prefill.php +36 -36
- application/admin/views/product_index.php +7 -7
- application/admin/views/settings.php +3 -3
- application/components/AffiliateFeedParserModule.php +581 -587
- application/components/AffiliateFeedParserModuleConfig.php +70 -72
- application/components/AffiliateParserModule.php +66 -66
- application/components/AffiliateParserModuleConfig.php +46 -49
- application/components/BlockTemplateManager.php +69 -73
- application/components/CEWidget.php +63 -20
- application/components/Config.php +415 -410
- application/components/Content.php +9 -9
- application/components/ContentCoupon.php +7 -7
- application/components/ContentManager.php +647 -638
- application/components/ContentProduct.php +28 -28
- application/components/Cpa.php +203 -199
- application/components/ExternalFeaturedImage.php +280 -265
- application/components/ExtraData.php +19 -22
- application/components/FeaturedImage.php +150 -143
- application/components/LinkHandler.php +384 -364
- application/components/Module.php +240 -259
- application/components/ModuleApi.php +89 -86
- application/components/ModuleConfig.php +38 -46
- application/components/ModuleManager.php +411 -413
- application/components/ModuleTemplateManager.php +81 -81
- application/components/ParserModule.php +181 -196
- application/components/ParserModuleConfig.php +108 -110
- application/components/ReviewNotice.php +96 -82
- application/components/Scheduler.php +20 -22
- application/components/Shortcoded.php +33 -37
- application/components/TemplateManager.php +237 -235
- application/components/VirtualPage.php +145 -149
- application/components/WidgetTemplateManager.php +46 -50
- application/components/iScheduler.php +3 -3
- application/helpers/AdminHelper.php +135 -138
- application/helpers/ArrayHelper.php +85 -91
- application/helpers/CurrencyHelper.php +693 -700
- application/helpers/FileHelper.php +33 -33
- application/helpers/FormValidator.php +398 -405
- application/helpers/ImageHelper.php +100 -91
- application/helpers/InputHelper.php +0 -33
- application/helpers/TemplateHelper.php +1299 -1280
- application/helpers/TextHelper.php +1206 -682
- application/libs/KeywordDensity.php +97 -109
- application/libs/ParserClient.php +191 -202
- application/libs/RestClient.php +216 -236
- application/libs/WpHttpClient.php +419 -445
- application/libs/admitad/AdmitadProducts.php +43 -43
- application/libs/affilinet/AffilinetCoupons.php +77 -80
- application/libs/amazon/AmazonProduct.php +365 -359
- application/libs/bing/BingSearch.php +105 -101
- application/libs/bing/CognitiveSearch.php +54 -57
- application/libs/cj/CjLinksRest.php +35 -35
- application/libs/gdeslon/GdeSlonApi.php +68 -67
- application/libs/google/CustomSearchApi.php +42 -42
- application/libs/google/FreebaseRest.php +114 -112
- application/libs/google/YouTubeSearch.php +56 -57
- application/libs/pixabay/PixabaySearch.php +39 -42
- application/libs/rss/RssParser.php +44 -42
- application/libs/skimlinks/SkimlinksMerchant.php +34 -35
- application/libs/viglink/ViglinkApi.php +52 -52
- application/models/AutoblogModel.php +545 -562
- application/models/FeedProductModel.php +65 -65
- application/models/Model.php +250 -257
- application/models/PriceAlertModel.php +52 -54
- application/models/PriceHistoryModel.php +235 -226
- application/models/ProductModel.php +151 -161
- application/modules/AE/AEConfig.php +84 -84
- application/modules/AE/AEModule.php +288 -307
- application/modules/AE/ExtraDataAE.php +5 -5
- application/modules/AE/templates/data_grid.php +3 -3
- application/modules/AE/templates/data_item.php +3 -3
- application/modules/AE/templates/data_item_simple.php +3 -3
- application/modules/AE/templates/data_list.php +3 -3
- application/modules/AE/templates/data_price_tracker_alert.php +3 -3
- application/modules/AdmitadProducts/AdmitadProductsConfig.php +138 -139
- application/modules/AdmitadProducts/AdmitadProductsModule.php +177 -183
- application/modules/AdmitadProducts/ExtraDataAdmitadProducts.php +6 -6
- application/modules/AdmitadProducts/templates/data_grid.php +3 -3
- application/modules/AdmitadProducts/templates/data_item.php +3 -3
- application/modules/AdmitadProducts/templates/data_list.php +3 -3
- application/modules/AdmitadProducts/templates/data_price_tracker_alert.php +3 -3
- application/modules/AdmitadProducts/views/search_panel.php +7 -3
- application/modules/AffilinetCoupons/AffilinetCouponsConfig.php +156 -156
- application/modules/AffilinetCoupons/AffilinetCouponsModule.php +148 -151
- application/modules/AffilinetCoupons/ExtraDataAffilinetCoupons.php +9 -9
- application/modules/AffilinetCoupons/templates/data_coupons.php +3 -3
- application/modules/AffilinetCoupons/views/search_panel.php +3 -3
- application/modules/Amazon/AmazonConfig.php +362 -317
application/Installer.php
CHANGED
@@ -95,7 +95,7 @@ class Installer {
|
|
95 |
unset($_GET['activate']);
|
96 |
\deactivate_plugins(\plugin_basename(\ContentEgg\PLUGIN_FILE));
|
97 |
$e = sprintf('<div class="error"><p>%1$s</p><p><em>%2$s</em> ' . 'cannot be installed!' . '</p></div>', join('</p><p>', $errors), $name[0]);
|
98 |
-
\wp_die($e);
|
99 |
}
|
100 |
|
101 |
public static function uninstall()
|
@@ -173,7 +173,7 @@ class Installer {
|
|
173 |
if (\get_option(Plugin::slug . '_do_activation_redirect', false))
|
174 |
{
|
175 |
\delete_option(Plugin::slug . '_do_activation_redirect');
|
176 |
-
\
|
177 |
}
|
178 |
}
|
179 |
|
95 |
unset($_GET['activate']);
|
96 |
\deactivate_plugins(\plugin_basename(\ContentEgg\PLUGIN_FILE));
|
97 |
$e = sprintf('<div class="error"><p>%1$s</p><p><em>%2$s</em> ' . 'cannot be installed!' . '</p></div>', join('</p><p>', $errors), $name[0]);
|
98 |
+
\wp_die(wp_kses_post($e));
|
99 |
}
|
100 |
|
101 |
public static function uninstall()
|
173 |
if (\get_option(Plugin::slug . '_do_activation_redirect', false))
|
174 |
{
|
175 |
\delete_option(Plugin::slug . '_do_activation_redirect');
|
176 |
+
\wp_safe_redirect(\get_admin_url(\get_current_blog_id(), 'admin.php?page=' . Plugin::slug));
|
177 |
}
|
178 |
}
|
179 |
|
application/LocalRedirect.php
CHANGED
@@ -6,7 +6,6 @@ defined('\ABSPATH') || exit;
|
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
-
use ContentEgg\application\helpers\InputHelper;
|
10 |
use ContentEgg\application\helpers\TextHelper;
|
11 |
use ContentEgg\application\admin\GeneralConfig;
|
12 |
|
@@ -51,8 +50,12 @@ class LocalRedirect {
|
|
51 |
$goce = $match[1];
|
52 |
else
|
53 |
$goce = '';
|
54 |
-
}
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
|
57 |
if (!$goce)
|
58 |
return;
|
@@ -69,7 +72,7 @@ class LocalRedirect {
|
|
69 |
|
70 |
$code = (int) \apply_filters('cegg_local_redirect_code', 301);
|
71 |
|
72 |
-
\wp_redirect(
|
73 |
exit;
|
74 |
}
|
75 |
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
|
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
use ContentEgg\application\admin\GeneralConfig;
|
11 |
|
50 |
$goce = $match[1];
|
51 |
else
|
52 |
$goce = '';
|
53 |
+
} elseif (isset($_GET[self::getPrefix()]))
|
54 |
+
{
|
55 |
+
$goce = sanitize_text_field(wp_unslash($_GET[self::getPrefix()]));
|
56 |
+
}
|
57 |
+
else
|
58 |
+
return;
|
59 |
|
60 |
if (!$goce)
|
61 |
return;
|
72 |
|
73 |
$code = (int) \apply_filters('cegg_local_redirect_code', 301);
|
74 |
|
75 |
+
\wp_redirect(wp_sanitize_redirect($url), $code); // phpcs:ignore
|
76 |
exit;
|
77 |
}
|
78 |
|
application/Plugin.php
CHANGED
@@ -17,7 +17,7 @@ use ContentEgg\application\components\ExternalFeaturedImage;
|
|
17 |
*/
|
18 |
class Plugin {
|
19 |
|
20 |
-
const version = '5.
|
21 |
const db_version = 54;
|
22 |
const wp_requires = '4.6.1';
|
23 |
const slug = 'content-egg';
|
17 |
*/
|
18 |
class Plugin {
|
19 |
|
20 |
+
const version = '5.4.0';
|
21 |
const db_version = 54;
|
22 |
const wp_requires = '4.6.1';
|
23 |
const slug = 'content-egg';
|
application/PriceAlert.php
CHANGED
@@ -5,7 +5,6 @@ namespace ContentEgg\application;
|
|
5 |
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\models\PriceAlertModel;
|
8 |
-
use ContentEgg\application\helpers\InputHelper;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
use ContentEgg\application\models\PriceHistoryModel;
|
11 |
use ContentEgg\application\components\ContentManager;
|
@@ -17,7 +16,7 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
17 |
*
|
18 |
* @author keywordrush.com <support@keywordrush.com>
|
19 |
* @link https://www.keywordrush.com
|
20 |
-
* @copyright Copyright ©
|
21 |
*/
|
22 |
class PriceAlert {
|
23 |
|
@@ -65,15 +64,15 @@ class PriceAlert {
|
|
65 |
|
66 |
public function ajaxTrackProduct()
|
67 |
{
|
68 |
-
if (!isset($_POST['nonce']) || !\wp_verify_nonce($_POST['nonce'], 'cegg-price-alert'))
|
69 |
die('Invalid nonce');
|
70 |
|
71 |
-
$module_id = TextHelper::clear(
|
72 |
-
$unique_id = TextHelper::clearId(
|
73 |
-
$price = (float) TextHelper::parsePriceAmount(
|
74 |
-
$post_id = (
|
75 |
-
$email = strtolower(
|
76 |
-
$accepted = (
|
77 |
|
78 |
if (!$module_id || !$unique_id || !$post_id)
|
79 |
die('Invalid params');
|
@@ -169,7 +168,7 @@ class PriceAlert {
|
|
169 |
}
|
170 |
|
171 |
$body .= $this->getEmailSignature();
|
172 |
-
|
173 |
self::mail($email, $subject, $body);
|
174 |
}
|
175 |
|
@@ -199,8 +198,9 @@ class PriceAlert {
|
|
199 |
|
200 |
public function subscriptionManager()
|
201 |
{
|
202 |
-
|
203 |
-
|
|
|
204 |
|
205 |
switch ($action)
|
206 |
{
|
@@ -220,8 +220,11 @@ class PriceAlert {
|
|
220 |
|
221 |
private function actionValidateEmail()
|
222 |
{
|
223 |
-
|
224 |
-
|
|
|
|
|
|
|
225 |
|
226 |
$where = array(
|
227 |
'email = %s AND activkey = %s AND status = %d',
|
@@ -239,8 +242,11 @@ class PriceAlert {
|
|
239 |
|
240 |
private function actionUnsubscribeAll()
|
241 |
{
|
242 |
-
|
243 |
-
|
|
|
|
|
|
|
244 |
|
245 |
$where = array(
|
246 |
'email = %s AND activkey = %s',
|
@@ -256,8 +262,11 @@ class PriceAlert {
|
|
256 |
|
257 |
private function actionDeleteSubscription()
|
258 |
{
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
261 |
|
262 |
$where = array(
|
263 |
'email = %s AND activkey = %s',
|
5 |
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\models\PriceAlertModel;
|
|
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
9 |
use ContentEgg\application\models\PriceHistoryModel;
|
10 |
use ContentEgg\application\components\ContentManager;
|
16 |
*
|
17 |
* @author keywordrush.com <support@keywordrush.com>
|
18 |
* @link https://www.keywordrush.com
|
19 |
+
* @copyright Copyright © 2022 keywordrush.com
|
20 |
*/
|
21 |
class PriceAlert {
|
22 |
|
64 |
|
65 |
public function ajaxTrackProduct()
|
66 |
{
|
67 |
+
if (!isset($_POST['nonce']) || !\wp_verify_nonce(sanitize_key($_POST['nonce']), 'cegg-price-alert'))
|
68 |
die('Invalid nonce');
|
69 |
|
70 |
+
$module_id = isset($_POST['module_id']) ? TextHelper::clear(sanitize_text_field(wp_unslash($_POST['module_id']))) : null;
|
71 |
+
$unique_id = isset($_POST['unique_id']) ? TextHelper::clearId(sanitize_text_field(wp_unslash($_POST['unique_id']))) : null;
|
72 |
+
$price = isset($_POST['price']) ? (float) TextHelper::parsePriceAmount(sanitize_text_field(wp_unslash($_POST['price']))) : null;
|
73 |
+
$post_id = isset($_POST['post_id']) ? intval(wp_unslash($_POST['post_id'])) : null;
|
74 |
+
$email = isset($_POST['email']) ? strtolower(sanitize_email(wp_unslash($_POST['email']))) : null;
|
75 |
+
$accepted = isset($_POST['accepted']) ? boolval(wp_unslash($_POST['accepted'])) : null;
|
76 |
|
77 |
if (!$module_id || !$unique_id || !$post_id)
|
78 |
die('Invalid params');
|
168 |
}
|
169 |
|
170 |
$body .= $this->getEmailSignature();
|
171 |
+
|
172 |
self::mail($email, $subject, $body);
|
173 |
}
|
174 |
|
198 |
|
199 |
public function subscriptionManager()
|
200 |
{
|
201 |
+
$action = isset($_GET['ceggaction']) ? sanitize_key(wp_unslash($_GET['ceggaction'])) : '';
|
202 |
+
if (!$action)
|
203 |
+
return;
|
204 |
|
205 |
switch ($action)
|
206 |
{
|
220 |
|
221 |
private function actionValidateEmail()
|
222 |
{
|
223 |
+
$email = isset($_GET['email']) ? strtolower(sanitize_email(wp_unslash($_GET['email']))) : '';
|
224 |
+
$key = isset($_GET['key']) ? TextHelper::clear(sanitize_text_field(wp_unslash($_GET['key']))) : '';
|
225 |
+
|
226 |
+
if (!$email || !$key)
|
227 |
+
return;
|
228 |
|
229 |
$where = array(
|
230 |
'email = %s AND activkey = %s AND status = %d',
|
242 |
|
243 |
private function actionUnsubscribeAll()
|
244 |
{
|
245 |
+
$email = isset($_GET['email']) ? strtolower(sanitize_email(wp_unslash($_GET['email']))) : '';
|
246 |
+
$key = isset($_GET['key']) ? TextHelper::clear(sanitize_text_field(wp_unslash($_GET['key']))) : '';
|
247 |
+
|
248 |
+
if (!$email || !$key)
|
249 |
+
return;
|
250 |
|
251 |
$where = array(
|
252 |
'email = %s AND activkey = %s',
|
262 |
|
263 |
private function actionDeleteSubscription()
|
264 |
{
|
265 |
+
$email = isset($_GET['email']) ? strtolower(sanitize_email(wp_unslash($_GET['email']))) : '';
|
266 |
+
$key = isset($_GET['key']) ? TextHelper::clear(sanitize_text_field(wp_unslash($_GET['key']))) : '';
|
267 |
+
|
268 |
+
if (!$email || !$key)
|
269 |
+
return;
|
270 |
|
271 |
$where = array(
|
272 |
'email = %s AND activkey = %s',
|
application/PriceMoversWidget.php
CHANGED
@@ -17,8 +17,8 @@ use ContentEgg\application\components\ContentProduct;
|
|
17 |
* PriceMoversWidget class file
|
18 |
*
|
19 |
* @author keywordrush.com <support@keywordrush.com>
|
20 |
-
* @link
|
21 |
-
* @copyright Copyright ©
|
22 |
*/
|
23 |
class PriceMoversWidget extends CEWidget {
|
24 |
|
@@ -52,8 +52,11 @@ class PriceMoversWidget extends CEWidget {
|
|
52 |
|
53 |
public function settings($force = false)
|
54 |
{
|
|
|
55 |
if (!$force && (empty($GLOBALS['pagenow']) || ($GLOBALS['pagenow'] != 'widgets.php' && $GLOBALS['pagenow'] != 'admin-ajax.php')))
|
56 |
return array();
|
|
|
|
|
57 |
|
58 |
return
|
59 |
array(
|
@@ -127,13 +130,14 @@ class PriceMoversWidget extends CEWidget {
|
|
127 |
if (!$tpl_manager->isTemplateExists($instance['template']))
|
128 |
return;
|
129 |
|
130 |
-
echo $tpl_manager->render($instance['template'], array('items' => $items, 'is_shortcode' => false, 'btn_text' => ''));
|
131 |
|
132 |
$this->afterWidget($args, $instance);
|
133 |
}
|
134 |
|
135 |
private function getItems(array $instance)
|
136 |
{
|
|
|
137 |
$cache_key = $this->getCacheKey($instance);
|
138 |
$items = $this->getCache($cache_key);
|
139 |
if ($items === null)
|
17 |
* PriceMoversWidget class file
|
18 |
*
|
19 |
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link https://www.keywordrush.com
|
21 |
+
* @copyright Copyright © 2022 keywordrush.com
|
22 |
*/
|
23 |
class PriceMoversWidget extends CEWidget {
|
24 |
|
52 |
|
53 |
public function settings($force = false)
|
54 |
{
|
55 |
+
/*
|
56 |
if (!$force && (empty($GLOBALS['pagenow']) || ($GLOBALS['pagenow'] != 'widgets.php' && $GLOBALS['pagenow'] != 'admin-ajax.php')))
|
57 |
return array();
|
58 |
+
*
|
59 |
+
*/
|
60 |
|
61 |
return
|
62 |
array(
|
130 |
if (!$tpl_manager->isTemplateExists($instance['template']))
|
131 |
return;
|
132 |
|
133 |
+
echo $tpl_manager->render($instance['template'], array('items' => $items, 'is_shortcode' => false, 'btn_text' => '')); // phpcs:ignore
|
134 |
|
135 |
$this->afterWidget($args, $instance);
|
136 |
}
|
137 |
|
138 |
private function getItems(array $instance)
|
139 |
{
|
140 |
+
|
141 |
$cache_key = $this->getCacheKey($instance);
|
142 |
$items = $this->getCache($cache_key);
|
143 |
if ($items === null)
|
application/ProductSearch.php
CHANGED
@@ -51,7 +51,7 @@ class ProductSearch extends VirtualPage {
|
|
51 |
|
52 |
public static function viewSearchFrom($atts, $content = "")
|
53 |
{
|
54 |
-
echo ProductSearchWidget::getSearchForm();
|
55 |
}
|
56 |
|
57 |
public function getSlug()
|
51 |
|
52 |
public static function viewSearchFrom($atts, $content = "")
|
53 |
{
|
54 |
+
echo ProductSearchWidget::getSearchForm(); // phpcs:ignore
|
55 |
}
|
56 |
|
57 |
public function getSlug()
|
application/ProductSearchWidget.php
CHANGED
@@ -55,7 +55,7 @@ class ProductSearchWidget extends CEWidget {
|
|
55 |
$this->beforeWidget($args, $instance);
|
56 |
|
57 |
// Use current theme search form if it exists
|
58 |
-
echo self::getSearchForm();
|
59 |
|
60 |
$this->afterWidget($args, $instance);
|
61 |
}
|
55 |
$this->beforeWidget($args, $instance);
|
56 |
|
57 |
// Use current theme search form if it exists
|
58 |
+
echo self::getSearchForm(); // phpcs:ignore
|
59 |
|
60 |
$this->afterWidget($args, $instance);
|
61 |
}
|
application/WooIntegrator.php
CHANGED
@@ -543,7 +543,9 @@ class WooIntegrator {
|
|
543 |
|
544 |
$date = TemplateHelper::dateFormatFromGmt($item['last_update'], true);
|
545 |
|
546 |
-
echo '<span class="price_updated">'
|
|
|
|
|
547 |
}
|
548 |
}
|
549 |
|
@@ -562,7 +564,9 @@ class WooIntegrator {
|
|
562 |
if (empty($item['extra']['pricePerUnitDisplay']))
|
563 |
return;
|
564 |
|
565 |
-
echo '<div class="cegg_price_per_unit">'
|
|
|
|
|
566 |
}
|
567 |
}
|
568 |
|
543 |
|
544 |
$date = TemplateHelper::dateFormatFromGmt($item['last_update'], true);
|
545 |
|
546 |
+
echo '<span class="price_updated">';
|
547 |
+
echo esc_html(sprintf(Translator::__('Last updated on %s'), $date));
|
548 |
+
echo '</span>';
|
549 |
}
|
550 |
}
|
551 |
|
564 |
if (empty($item['extra']['pricePerUnitDisplay']))
|
565 |
return;
|
566 |
|
567 |
+
echo '<div class="cegg_price_per_unit">';
|
568 |
+
echo esc_html(sprintf(Translator::__('Price per unit: %s'), $item['extra']['pricePerUnitDisplay']));
|
569 |
+
echo '</div>';
|
570 |
}
|
571 |
}
|
572 |
|
application/admin/AdminNotice.php
CHANGED
@@ -52,7 +52,7 @@ class AdminNotice {
|
|
52 |
public function getMessage($message_id = null)
|
53 |
{
|
54 |
if (!$message_id && !empty($_GET[self::GET_NOTICE_PARAM]))
|
55 |
-
$message_id = $_GET[self::GET_NOTICE_PARAM];
|
56 |
else
|
57 |
return '';
|
58 |
|
@@ -64,7 +64,7 @@ class AdminNotice {
|
|
64 |
|
65 |
if (!empty($_GET[self::GET_ID_PARAM]))
|
66 |
{
|
67 |
-
$id = (
|
68 |
$message = str_replace('%%ID%%', $id, $message);
|
69 |
}
|
70 |
|
@@ -79,11 +79,11 @@ class AdminNotice {
|
|
79 |
$level = 'info';
|
80 |
if (!empty($_GET[self::GET_LEVEL_PARAM]))
|
81 |
{
|
82 |
-
$level = $_GET[self::GET_LEVEL_PARAM];
|
83 |
if (!in_array($level, array('error', 'warning', 'info', 'success')))
|
84 |
$level = 'info';
|
85 |
}
|
86 |
-
echo '<div class="notice notice-' . $level . ' is-dismissible"><p>' . $this->getMessage() . '</p></div>';
|
87 |
}
|
88 |
|
89 |
public static function add2Url($url, $message, $level = null, $id = null)
|
52 |
public function getMessage($message_id = null)
|
53 |
{
|
54 |
if (!$message_id && !empty($_GET[self::GET_NOTICE_PARAM]))
|
55 |
+
$message_id = sanitize_key(wp_unslash($_GET[self::GET_NOTICE_PARAM]));
|
56 |
else
|
57 |
return '';
|
58 |
|
64 |
|
65 |
if (!empty($_GET[self::GET_ID_PARAM]))
|
66 |
{
|
67 |
+
$id = intval(wp_unslash($_GET[self::GET_ID_PARAM]));
|
68 |
$message = str_replace('%%ID%%', $id, $message);
|
69 |
}
|
70 |
|
79 |
$level = 'info';
|
80 |
if (!empty($_GET[self::GET_LEVEL_PARAM]))
|
81 |
{
|
82 |
+
$level = sanitize_key(wp_unslash($_GET[self::GET_LEVEL_PARAM]));
|
83 |
if (!in_array($level, array('error', 'warning', 'info', 'success')))
|
84 |
$level = 'info';
|
85 |
}
|
86 |
+
echo '<div class="notice notice-' . esc_attr($level) . ' is-dismissible"><p>' . wp_kses_post($this->getMessage()) . '</p></div>';
|
87 |
}
|
88 |
|
89 |
public static function add2Url($url, $message, $level = null, $id = null)
|
application/admin/AutoblogController.php
CHANGED
@@ -81,7 +81,7 @@ class AutoblogController {
|
|
81 |
|
82 |
public function actionIndex()
|
83 |
{
|
84 |
-
if (!empty($_GET['action']) && $_GET['action'] == 'run')
|
85 |
{
|
86 |
@set_time_limit(180);
|
87 |
AutoblogModel::model()->run((int) $_GET['id']);
|
@@ -99,8 +99,6 @@ class AutoblogController {
|
|
99 |
else
|
100 |
$batch = false;
|
101 |
|
102 |
-
$_POST = array_map('stripslashes_deep', $_POST);
|
103 |
-
|
104 |
$default = array(
|
105 |
'id' => 0,
|
106 |
'name' => '',
|
@@ -130,34 +128,34 @@ class AutoblogController {
|
|
130 |
$message = '';
|
131 |
$notice = '';
|
132 |
|
133 |
-
if (!empty($_POST['nonce']) && \wp_verify_nonce($_POST['nonce'], basename(__FILE__)) && !empty($_POST['item']))
|
134 |
{
|
|
|
135 |
$item = array();
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
$item['product_condition'] = $_POST['item']['product_condition'];
|
161 |
|
162 |
$redirect_url = \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog');
|
163 |
if ($batch)
|
@@ -181,7 +179,7 @@ class AutoblogController {
|
|
181 |
}
|
182 |
|
183 |
// redirect to table list
|
184 |
-
\
|
185 |
exit;
|
186 |
} else
|
187 |
{
|
@@ -262,15 +260,13 @@ class AutoblogController {
|
|
262 |
if (empty($_FILES['item']['name']) || empty($_FILES['item']['name']['keywords_file']))
|
263 |
return false;
|
264 |
|
265 |
-
$file_name = $_FILES['item']['name']['keywords_file'];
|
266 |
-
$file_path = $_FILES['item']['tmp_name']['keywords_file'];
|
267 |
|
268 |
// Get the file type of the upload
|
269 |
$supported_types = array('text/csv', 'text/plain');
|
270 |
$arr_file_type = \wp_check_filetype(basename($file_name));
|
271 |
$uploaded_type = $arr_file_type['type'];
|
272 |
|
273 |
-
// Check if the type is supported. If not, throw an error.
|
274 |
if (!in_array($uploaded_type, $supported_types))
|
275 |
return false;
|
276 |
|
81 |
|
82 |
public function actionIndex()
|
83 |
{
|
84 |
+
if (!empty($_GET['action']) && $_GET['action'] == 'run' && !empty($_GET['id']))
|
85 |
{
|
86 |
@set_time_limit(180);
|
87 |
AutoblogModel::model()->run((int) $_GET['id']);
|
99 |
else
|
100 |
$batch = false;
|
101 |
|
|
|
|
|
102 |
$default = array(
|
103 |
'id' => 0,
|
104 |
'name' => '',
|
128 |
$message = '';
|
129 |
$notice = '';
|
130 |
|
131 |
+
if (!empty($_POST['nonce']) && \wp_verify_nonce(sanitize_key($_POST['nonce']), basename(__FILE__)) && !empty($_POST['item']))
|
132 |
{
|
133 |
+
$pitem = isset( $_POST['item'] ) ? wp_unslash( $_POST['item'] ) : array(); // phpcs:ignore
|
134 |
$item = array();
|
135 |
+
$item['id'] = isset($pitem['id']) ? absint ($pitem['id']) : 0;
|
136 |
+
$item['name'] = isset($pitem['name']) ? \sanitize_text_field($pitem['name']) : '';
|
137 |
+
$item['status'] = isset($pitem['status']) ? absint($pitem['status']) : '';
|
138 |
+
$item['keywords_per_run'] = isset($pitem['keywords_per_run']) ? absint($pitem['keywords_per_run']) : 1;
|
139 |
+
$item['run_frequency'] = isset($pitem['run_frequency']) ? absint($pitem['run_frequency']) : '';
|
140 |
+
$item['post_status'] = isset($pitem['post_status']) ? absint($pitem['post_status']) : '';
|
141 |
+
$item['user_id'] = isset($pitem['user_id']) ? absint($pitem['user_id']) : '';
|
142 |
+
$item['template_body'] = isset($pitem['template_body']) ? \wp_kses_post($pitem['template_body']) : '';
|
143 |
+
$item['template_title'] = isset($pitem['template_title']) ? trim(\sanitize_text_field($pitem['template_title'])) : '';
|
144 |
+
$item['post_type'] = isset($pitem['post_type']) ? sanitize_key($pitem['post_type']) : null;
|
145 |
+
$item['category'] = isset($pitem['category']) ? intval( $pitem['category']) : null;
|
146 |
+
$item['include_modules'] = isset($pitem['include_modules']) ? array_map('sanitize_text_field', $pitem['include_modules']) : array();
|
147 |
+
$item['exclude_modules'] = isset($pitem['exclude_modules']) ? array_map('sanitize_text_field', $pitem['exclude_modules']) : array();
|
148 |
+
$item['required_modules'] = isset($pitem['required_modules']) ? array_map('sanitize_text_field', $pitem['required_modules']) : array();
|
149 |
+
$item['autoupdate_modules'] = isset($pitem['autoupdate_modules']) ? array_map('sanitize_text_field', $pitem['autoupdate_modules']) : array();
|
150 |
+
$item['min_modules_count'] = isset($pitem['min_modules_count']) ? absint($pitem['min_modules_count']) : '';
|
151 |
+
$item['keywords'] = isset($pitem['keywords']) ? array_map('sanitize_text_field', explode("\r\n", $pitem['keywords'])) : null;
|
152 |
+
$item['custom_field_names'] = isset($pitem['custom_field_names']) ? array_map('sanitize_key', $pitem['custom_field_names']) : array();
|
153 |
+
$item['custom_field_values'] = isset($pitem['custom_field_values']) ? array_map('sanitize_text_field', $pitem['custom_field_values']) : array();
|
154 |
+
$item['main_product'] = isset($pitem['main_product']) ? sanitize_key($pitem['main_product']) : 'min_price';
|
155 |
+
$item['tags'] = isset($pitem['tags']) ? sanitize_text_field(TextHelper::commaList($pitem['tags'])) : '';
|
156 |
+
$item['config'] = isset($pitem['config']) ? $pitem['config'] : '';
|
157 |
+
$item['product_condition'] = isset($pitem['product_condition']) ? sanitize_text_field($pitem['product_condition']) : '';
|
158 |
+
|
|
|
159 |
|
160 |
$redirect_url = \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog');
|
161 |
if ($batch)
|
179 |
}
|
180 |
|
181 |
// redirect to table list
|
182 |
+
\wp_safe_redirect($redirect_url);
|
183 |
exit;
|
184 |
} else
|
185 |
{
|
260 |
if (empty($_FILES['item']['name']) || empty($_FILES['item']['name']['keywords_file']))
|
261 |
return false;
|
262 |
|
263 |
+
$file_name = sanitize_text_field(wp_unslash($_FILES['item']['name']['keywords_file']));
|
|
|
264 |
|
265 |
// Get the file type of the upload
|
266 |
$supported_types = array('text/csv', 'text/plain');
|
267 |
$arr_file_type = \wp_check_filetype(basename($file_name));
|
268 |
$uploaded_type = $arr_file_type['type'];
|
269 |
|
|
|
270 |
if (!in_array($uploaded_type, $supported_types))
|
271 |
return false;
|
272 |
|
application/admin/EggMetabox.php
CHANGED
@@ -5,7 +5,6 @@ namespace ContentEgg\application\admin;
|
|
5 |
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
-
use ContentEgg\application\helpers\InputHelper;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
use ContentEgg\application\components\ContentManager;
|
11 |
use ContentEgg\application\components\ContentProduct;
|
@@ -19,7 +18,7 @@ use ContentEgg\application\Plugin;
|
|
19 |
*
|
20 |
* @author keywordrush.com <support@keywordrush.com>
|
21 |
* @link https://www.keywordrush.com
|
22 |
-
* @copyright Copyright ©
|
23 |
*/
|
24 |
class EggMetabox {
|
25 |
|
@@ -29,7 +28,7 @@ class EggMetabox {
|
|
29 |
{
|
30 |
if (Plugin::isActivated() && LManager::isNulled())
|
31 |
return;
|
32 |
-
|
33 |
\add_action('add_meta_boxes', array($this, 'addMetabox'));
|
34 |
\add_action('save_post', array($this, 'saveMeta'));
|
35 |
}
|
@@ -83,7 +82,7 @@ class EggMetabox {
|
|
83 |
$modules = ModuleManager::getInstance()->getModules(true);
|
84 |
$module_ids = \apply_filters('content_egg_metabox_modules', array_keys($modules));
|
85 |
$modules = array_intersect_key($modules, array_flip($module_ids));
|
86 |
-
|
87 |
foreach ($modules as $module)
|
88 |
{
|
89 |
$module->enqueueScripts();
|
@@ -95,7 +94,7 @@ class EggMetabox {
|
|
95 |
|
96 |
public function renderBlankMetabox($post)
|
97 |
{
|
98 |
-
|
99 |
}
|
100 |
|
101 |
private function metadataInit()
|
@@ -236,8 +235,7 @@ class EggMetabox {
|
|
236 |
|
237 |
\check_admin_referer('contentegg_metabox', 'contentegg_nonce');
|
238 |
|
239 |
-
|
240 |
-
if ($_POST['post_type'] == 'page')
|
241 |
{
|
242 |
if (!current_user_can('edit_page', $post_id))
|
243 |
return;
|
@@ -254,8 +252,15 @@ class EggMetabox {
|
|
254 |
$stripslashes = true;
|
255 |
|
256 |
// keywords for automatic updates
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
foreach ($keywords as $module_id => $keyword)
|
260 |
{
|
261 |
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
@@ -281,13 +286,18 @@ class EggMetabox {
|
|
281 |
}
|
282 |
|
283 |
// save content data
|
284 |
-
|
|
|
|
|
|
|
|
|
285 |
if (!is_array($content))
|
286 |
return;
|
287 |
|
288 |
$i = 0;
|
289 |
foreach ($content as $module_id => $data)
|
290 |
{
|
|
|
291 |
$i++;
|
292 |
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
293 |
continue;
|
5 |
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
|
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
9 |
use ContentEgg\application\components\ContentManager;
|
10 |
use ContentEgg\application\components\ContentProduct;
|
18 |
*
|
19 |
* @author keywordrush.com <support@keywordrush.com>
|
20 |
* @link https://www.keywordrush.com
|
21 |
+
* @copyright Copyright © 2022 keywordrush.com
|
22 |
*/
|
23 |
class EggMetabox {
|
24 |
|
28 |
{
|
29 |
if (Plugin::isActivated() && LManager::isNulled())
|
30 |
return;
|
31 |
+
|
32 |
\add_action('add_meta_boxes', array($this, 'addMetabox'));
|
33 |
\add_action('save_post', array($this, 'saveMeta'));
|
34 |
}
|
82 |
$modules = ModuleManager::getInstance()->getModules(true);
|
83 |
$module_ids = \apply_filters('content_egg_metabox_modules', array_keys($modules));
|
84 |
$modules = array_intersect_key($modules, array_flip($module_ids));
|
85 |
+
|
86 |
foreach ($modules as $module)
|
87 |
{
|
88 |
$module->enqueueScripts();
|
94 |
|
95 |
public function renderBlankMetabox($post)
|
96 |
{
|
97 |
+
esc_attr_e('Configure and activate modules of Content Egg plugin', 'content-egg');
|
98 |
}
|
99 |
|
100 |
private function metadataInit()
|
235 |
|
236 |
\check_admin_referer('contentegg_metabox', 'contentegg_nonce');
|
237 |
|
238 |
+
if (isset($_POST['post_type']) && $_POST['post_type'] == 'page')
|
|
|
239 |
{
|
240 |
if (!current_user_can('edit_page', $post_id))
|
241 |
return;
|
252 |
$stripslashes = true;
|
253 |
|
254 |
// keywords for automatic updates
|
255 |
+
if (isset($_POST['cegg_updateKeywords']))
|
256 |
+
{
|
257 |
+
$keywords = sanitize_text_field(wp_unslash($_POST['cegg_updateKeywords']));
|
258 |
+
}
|
259 |
+
if (isset($_POST['cegg_updateParams']))
|
260 |
+
{
|
261 |
+
$update_params = sanitize_text_field(wp_unslash($_POST['cegg_updateParams']));
|
262 |
+
}
|
263 |
+
|
264 |
foreach ($keywords as $module_id => $keyword)
|
265 |
{
|
266 |
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
286 |
}
|
287 |
|
288 |
// save content data
|
289 |
+
if (isset($_POST['cegg_data']))
|
290 |
+
$content = wp_unslash($_POST['cegg_data']); // phpcs:ignore
|
291 |
+
else
|
292 |
+
$content = array();
|
293 |
+
|
294 |
if (!is_array($content))
|
295 |
return;
|
296 |
|
297 |
$i = 0;
|
298 |
foreach ($content as $module_id => $data)
|
299 |
{
|
300 |
+
$module_id = sanitize_text_field($module_id);
|
301 |
$i++;
|
302 |
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
303 |
continue;
|
application/admin/GeneralConfig.php
CHANGED
@@ -590,10 +590,10 @@ class GeneralConfig extends Config {
|
|
590 |
$value = isset($args['value'][$i]['value']) ? $args['value'][$i]['value'] : '';
|
591 |
|
592 |
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
593 |
-
. \esc_attr($args['name']) . '][' . $i . '][name]" value="'
|
594 |
. \esc_attr($name) . '" class="text" placeholder="' . \esc_attr(__('Domain name', 'content-egg')) . '" type="text"/>';
|
595 |
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
596 |
-
. \esc_attr($args['name']) . '][' . $i . '][value]" value="'
|
597 |
. \esc_attr($value) . '" class="regular-text ltr" placeholder="' . \esc_attr(__('Logo URL', 'content-egg')) . '" type="text"/>';
|
598 |
}
|
599 |
|
@@ -612,7 +612,7 @@ class GeneralConfig extends Config {
|
|
612 |
echo '</div>';
|
613 |
}
|
614 |
if ($args['description'])
|
615 |
-
echo '<p class="description">' . $args['description'] . '</p>';
|
616 |
}
|
617 |
|
618 |
public function formatLogoFields($values)
|
@@ -667,7 +667,7 @@ class GeneralConfig extends Config {
|
|
667 |
echo '</div>';
|
668 |
}
|
669 |
if ($args['description'])
|
670 |
-
echo '<p class="description">' . $args['description'] . '</p>';
|
671 |
}
|
672 |
|
673 |
public function frontendTextsSanitize($values)
|
@@ -687,11 +687,11 @@ class GeneralConfig extends Config {
|
|
687 |
$value = isset($args['value'][$i]['shop_info']) ? $args['value'][$i]['shop_info'] : '';
|
688 |
|
689 |
echo '<input style="margin-bottom: 5px;" name="' . \esc_attr($args['option_name']) . '['
|
690 |
-
. \esc_attr($args['name']) . '][' . $i . '][name]" value="'
|
691 |
. \esc_attr($name) . '" class="regular-text ltr" placeholder="' . \esc_attr(__('Domain name', 'content-egg')) . '" type="text"/>';
|
692 |
|
693 |
echo '<textarea rows="2" name="' . \esc_attr($args['option_name']) . '['
|
694 |
-
. \esc_attr($args['name']) . '][' . $i . '][shop_info]" value="'
|
695 |
. \esc_attr($value) . '" class="large-text code" placeholder="' . \esc_attr(__('Shop info', 'content-egg')) . '" type="text">' . \esc_html($value) . '</textarea>';
|
696 |
}
|
697 |
|
@@ -710,7 +710,7 @@ class GeneralConfig extends Config {
|
|
710 |
echo '</div>';
|
711 |
}
|
712 |
if ($args['description'])
|
713 |
-
echo '<p class="description">' . $args['description']
|
714 |
}
|
715 |
|
716 |
public function formatMerchantFields($values)
|
590 |
$value = isset($args['value'][$i]['value']) ? $args['value'][$i]['value'] : '';
|
591 |
|
592 |
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
593 |
+
. \esc_attr($args['name']) . '][' . esc_attr($i) . '][name]" value="'
|
594 |
. \esc_attr($name) . '" class="text" placeholder="' . \esc_attr(__('Domain name', 'content-egg')) . '" type="text"/>';
|
595 |
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
596 |
+
. \esc_attr($args['name']) . '][' . esc_attr($i) . '][value]" value="'
|
597 |
. \esc_attr($value) . '" class="regular-text ltr" placeholder="' . \esc_attr(__('Logo URL', 'content-egg')) . '" type="text"/>';
|
598 |
}
|
599 |
|
612 |
echo '</div>';
|
613 |
}
|
614 |
if ($args['description'])
|
615 |
+
echo '<p class="description">' . esc_html($args['description']) . '</p>';
|
616 |
}
|
617 |
|
618 |
public function formatLogoFields($values)
|
667 |
echo '</div>';
|
668 |
}
|
669 |
if ($args['description'])
|
670 |
+
echo '<p class="description">' . esc_html($args['description']) . '</p>';
|
671 |
}
|
672 |
|
673 |
public function frontendTextsSanitize($values)
|
687 |
$value = isset($args['value'][$i]['shop_info']) ? $args['value'][$i]['shop_info'] : '';
|
688 |
|
689 |
echo '<input style="margin-bottom: 5px;" name="' . \esc_attr($args['option_name']) . '['
|
690 |
+
. \esc_attr($args['name']) . '][' . esc_attr($i) . '][name]" value="'
|
691 |
. \esc_attr($name) . '" class="regular-text ltr" placeholder="' . \esc_attr(__('Domain name', 'content-egg')) . '" type="text"/>';
|
692 |
|
693 |
echo '<textarea rows="2" name="' . \esc_attr($args['option_name']) . '['
|
694 |
+
. \esc_attr($args['name']) . '][' . esc_attr($i) . '][shop_info]" value="'
|
695 |
. \esc_attr($value) . '" class="large-text code" placeholder="' . \esc_attr(__('Shop info', 'content-egg')) . '" type="text">' . \esc_html($value) . '</textarea>';
|
696 |
}
|
697 |
|
710 |
echo '</div>';
|
711 |
}
|
712 |
if ($args['description'])
|
713 |
+
echo '<p class="description">' . esc_html($args['description']). '</p>';
|
714 |
}
|
715 |
|
716 |
public function formatMerchantFields($values)
|
application/admin/ImportExportController.php
CHANGED
@@ -30,7 +30,6 @@ class ImportExportController {
|
|
30 |
|
31 |
public function actionIndex()
|
32 |
{
|
33 |
-
$_POST = array_map('stripslashes_deep', $_POST);
|
34 |
$message = '';
|
35 |
$notice = '';
|
36 |
|
@@ -40,9 +39,9 @@ class ImportExportController {
|
|
40 |
// modules
|
41 |
$all_options = array_merge($all_options, ModuleManager::getInstance()->getOptionsList());
|
42 |
|
43 |
-
if (!empty($_POST['nonce']) && \wp_verify_nonce($_POST['nonce'], basename(__FILE__)) && !empty($_POST['import_str']))
|
44 |
{
|
45 |
-
$import = json_decode($_POST['import_str'], true);
|
46 |
if ($import)
|
47 |
{
|
48 |
foreach ($import as $option => $values)
|
30 |
|
31 |
public function actionIndex()
|
32 |
{
|
|
|
33 |
$message = '';
|
34 |
$notice = '';
|
35 |
|
39 |
// modules
|
40 |
$all_options = array_merge($all_options, ModuleManager::getInstance()->getOptionsList());
|
41 |
|
42 |
+
if (!empty($_POST['nonce']) && \wp_verify_nonce(sanitize_key($_POST['nonce']), basename(__FILE__)) && !empty($_POST['import_str']))
|
43 |
{
|
44 |
+
$import = json_decode(sanitize_text_field(wp_unslash($_POST['import_str'])), true);
|
45 |
if ($import)
|
46 |
{
|
47 |
foreach ($import as $option => $values)
|
application/admin/MyListTable.php
CHANGED
@@ -7,6 +7,7 @@ defined('\ABSPATH') || exit;
|
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\models\Model;
|
9 |
use ContentEgg\application\helpers\TemplateHelper;
|
|
|
10 |
|
11 |
/**
|
12 |
* MyListTable class file
|
@@ -65,8 +66,8 @@ class MyListTable extends \WP_List_Table {
|
|
65 |
$this->process_bulk_action();
|
66 |
|
67 |
$paged = isset($_REQUEST['paged']) ? max(0, intval($_REQUEST['paged']) - 1) : 0;
|
68 |
-
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? $_REQUEST['orderby'] : $this->default_orderby();
|
69 |
-
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
|
70 |
|
71 |
$params = array(
|
72 |
'select' => 'SQL_CALC_FOUND_ROWS *',
|
@@ -146,11 +147,9 @@ class MyListTable extends \WP_List_Table {
|
|
146 |
|
147 |
function process_bulk_action()
|
148 |
{
|
149 |
-
if ($this->current_action() === 'delete')
|
150 |
{
|
151 |
-
$ids =
|
152 |
-
if (!is_array($ids))
|
153 |
-
$ids = (array) $ids;
|
154 |
foreach ($ids as $id)
|
155 |
{
|
156 |
$id = (int) $id;
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\models\Model;
|
9 |
use ContentEgg\application\helpers\TemplateHelper;
|
10 |
+
use function ContentEgg\prnx;
|
11 |
|
12 |
/**
|
13 |
* MyListTable class file
|
66 |
$this->process_bulk_action();
|
67 |
|
68 |
$paged = isset($_REQUEST['paged']) ? max(0, intval($_REQUEST['paged']) - 1) : 0;
|
69 |
+
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? sanitize_text_field(wp_unslash($_REQUEST['orderby'])) : $this->default_orderby();
|
70 |
+
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? sanitize_key($_REQUEST['order']) : 'desc';
|
71 |
|
72 |
$params = array(
|
73 |
'select' => 'SQL_CALC_FOUND_ROWS *',
|
147 |
|
148 |
function process_bulk_action()
|
149 |
{
|
150 |
+
if ($this->current_action() === 'delete' && !empty($_REQUEST['id']))
|
151 |
{
|
152 |
+
$ids = array_map('intval', (array)$_REQUEST['id']);
|
|
|
|
|
153 |
foreach ($ids as $id)
|
154 |
{
|
155 |
$id = (int) $id;
|
application/admin/PluginAdmin.php
CHANGED
@@ -19,7 +19,7 @@ use ContentEgg\application\ModuleUpdateScheduler;
|
|
19 |
*
|
20 |
* @author keywordrush.com <support@keywordrush.com>
|
21 |
* @link https://www.keywordrush.com
|
22 |
-
* @copyright Copyright ©
|
23 |
*/
|
24 |
class PluginAdmin {
|
25 |
|
@@ -91,7 +91,7 @@ class PluginAdmin {
|
|
91 |
if ($GLOBALS['pagenow'] != 'admin.php' || empty($_GET['page']))
|
92 |
return;
|
93 |
|
94 |
-
$page_pats = explode('-', $_GET['page']);
|
95 |
|
96 |
if (count($page_pats) < 2 || $page_pats[0] . '-' . $page_pats[1] != 'content-egg')
|
97 |
return;
|
19 |
*
|
20 |
* @author keywordrush.com <support@keywordrush.com>
|
21 |
* @link https://www.keywordrush.com
|
22 |
+
* @copyright Copyright © 2022 keywordrush.com
|
23 |
*/
|
24 |
class PluginAdmin {
|
25 |
|
91 |
if ($GLOBALS['pagenow'] != 'admin.php' || empty($_GET['page']))
|
92 |
return;
|
93 |
|
94 |
+
$page_pats = explode('-', sanitize_key(wp_unslash($_GET['page'])));
|
95 |
|
96 |
if (count($page_pats) < 2 || $page_pats[0] . '-' . $page_pats[1] != 'content-egg')
|
97 |
return;
|
application/admin/PrefillController.php
CHANGED
@@ -7,7 +7,6 @@ defined('\ABSPATH') || exit;
|
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
-
use ContentEgg\application\helpers\InputHelper;
|
11 |
use ContentEgg\application\components\ContentManager;
|
12 |
use ContentEgg\application\libs\KeywordDensity;
|
13 |
use ContentEgg\application\models\AutoblogModel;
|
@@ -88,20 +87,17 @@ class PrefillController {
|
|
88 |
if (empty($_POST['post_id']))
|
89 |
throw new \Exception("Post ID is undefined.");
|
90 |
|
91 |
-
$module_id = TextHelper::clear($_POST['module_id']);
|
92 |
-
$post_id = (
|
93 |
-
$keyword_source =
|
94 |
-
$autoupdate =
|
95 |
-
$autoupdate = filter_var($autoupdate, FILTER_VALIDATE_BOOLEAN);
|
96 |
-
$keyword_count = (
|
97 |
-
$minus_words = TextHelper::commaList(
|
98 |
-
$custom_field_names =
|
99 |
-
$custom_field_values =
|
|
|
100 |
|
101 |
-
if ($minus_words)
|
102 |
-
$minus_words = explode(',', $minus_words);
|
103 |
-
$custom_field = InputHelper::post('custom_field', '');
|
104 |
-
$custom_field = TextHelper::clear($custom_field);
|
105 |
|
106 |
$parser = ModuleManager::getInstance()->parserFactory($module_id);
|
107 |
if (!$parser->isActive())
|
@@ -124,6 +120,7 @@ class PrefillController {
|
|
124 |
|
125 |
if ($minus_words)
|
126 |
{
|
|
|
127 |
$keyword = trim(str_replace($minus_words, '', $keyword));
|
128 |
$keyword = preg_replace("/\s+/ui", ' ', $keyword);
|
129 |
}
|
@@ -227,16 +224,15 @@ class PrefillController {
|
|
227 |
return '';
|
228 |
|
229 |
$keyword = \get_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, true);
|
230 |
-
|
231 |
} elseif (substr($keyword_source, 0, 5) == '_ean_')
|
232 |
{
|
233 |
$module_id = substr($keyword_source, 5);
|
234 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
235 |
return '';
|
236 |
-
|
237 |
if (!$data = ContentManager::getViewData($module_id, $post_id))
|
238 |
return '';
|
239 |
-
|
240 |
foreach ($data as $d)
|
241 |
{
|
242 |
if (!empty($d['ean']))
|
@@ -244,7 +240,6 @@ class PrefillController {
|
|
244 |
$keyword = $d['ean'];
|
245 |
break;
|
246 |
}
|
247 |
-
|
248 |
}
|
249 |
}
|
250 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
|
|
10 |
use ContentEgg\application\components\ContentManager;
|
11 |
use ContentEgg\application\libs\KeywordDensity;
|
12 |
use ContentEgg\application\models\AutoblogModel;
|
87 |
if (empty($_POST['post_id']))
|
88 |
throw new \Exception("Post ID is undefined.");
|
89 |
|
90 |
+
$module_id = TextHelper::clear(sanitize_text_field(wp_unslash($_POST['module_id'])));
|
91 |
+
$post_id = intval($_POST['post_id']);
|
92 |
+
$keyword_source = isset($_POST['keyword_source']) ? sanitize_text_field(wp_unslash($_POST['keyword_source'])) : '';
|
93 |
+
$autoupdate = isset($_POST['autoupdate']) ? sanitize_text_field(wp_unslash($_POST['autoupdate'])) : false;
|
94 |
+
$autoupdate = filter_var($autoupdate, FILTER_VALIDATE_BOOLEAN);
|
95 |
+
$keyword_count = isset($_POST['keyword_count']) ? intval(wp_unslash($_POST['keyword_count'])) : 5;
|
96 |
+
$minus_words = isset($_POST['minus_words']) ? TextHelper::commaList(sanitize_text_field(wp_unslash($_POST['minus_words']))) : '';
|
97 |
+
$custom_field_names = isset($_POST['custom_field_names']) ? array_map('sanitize_text_field', wp_unslash($_POST['custom_field_names'])) : array();
|
98 |
+
$custom_field_values = isset($_POST['custom_field_values']) ? array_map('sanitize_text_field', wp_unslash($_POST['custom_field_values'])) : array();
|
99 |
+
$custom_field = isset($_POST['custom_field']) ? sanitize_key(wp_unslash($_POST['custom_field'])) : '';
|
100 |
|
|
|
|
|
|
|
|
|
101 |
|
102 |
$parser = ModuleManager::getInstance()->parserFactory($module_id);
|
103 |
if (!$parser->isActive())
|
120 |
|
121 |
if ($minus_words)
|
122 |
{
|
123 |
+
$minus_words = explode(',', $minus_words);
|
124 |
$keyword = trim(str_replace($minus_words, '', $keyword));
|
125 |
$keyword = preg_replace("/\s+/ui", ' ', $keyword);
|
126 |
}
|
224 |
return '';
|
225 |
|
226 |
$keyword = \get_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, true);
|
|
|
227 |
} elseif (substr($keyword_source, 0, 5) == '_ean_')
|
228 |
{
|
229 |
$module_id = substr($keyword_source, 5);
|
230 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
231 |
return '';
|
232 |
+
|
233 |
if (!$data = ContentManager::getViewData($module_id, $post_id))
|
234 |
return '';
|
235 |
+
|
236 |
foreach ($data as $d)
|
237 |
{
|
238 |
if (!empty($d['ean']))
|
240 |
$keyword = $d['ean'];
|
241 |
break;
|
242 |
}
|
|
|
243 |
}
|
244 |
}
|
245 |
|
application/admin/ProductController.php
CHANGED
@@ -30,9 +30,9 @@ class ProductController {
|
|
30 |
global $pagenow;
|
31 |
|
32 |
// If we're on an admin page with the referer passed in the QS, prevent it nesting and becoming too long.
|
33 |
-
if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'content-egg-product' && !empty($_GET['_wp_http_referer']))
|
34 |
{
|
35 |
-
\
|
36 |
exit;
|
37 |
}
|
38 |
}
|
30 |
global $pagenow;
|
31 |
|
32 |
// If we're on an admin page with the referer passed in the QS, prevent it nesting and becoming too long.
|
33 |
+
if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'content-egg-product' && !empty($_GET['_wp_http_referer']) && isset($_SERVER['REQUEST_URI'] ))
|
34 |
{
|
35 |
+
\wp_safe_redirect(\remove_query_arg(array('_wp_http_referer', '_wpnonce'), esc_url_raw(\wp_unslash($_SERVER['REQUEST_URI']))));
|
36 |
exit;
|
37 |
}
|
38 |
}
|
application/admin/ProductTable.php
CHANGED
@@ -91,10 +91,10 @@ class ProductTable extends MyListTable {
|
|
91 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
92 |
return;
|
93 |
$module = ModuleManager::getInstance()->factory($item['module_id']);
|
94 |
-
$output = '<strong>' . $module->getName() . '</strong>';
|
95 |
|
96 |
if (!$module->isActive())
|
97 |
-
$output .= '<br><mark class="inactive">' . __('inactive', 'content egg') . '</mark>';
|
98 |
|
99 |
return $output;
|
100 |
}
|
@@ -156,7 +156,7 @@ class ProductTable extends MyListTable {
|
|
156 |
private function print_modules_dropdown()
|
157 |
{
|
158 |
$modules = ModuleManager::getInstance()->getAffiliteModulesList(true);
|
159 |
-
$selected_module_id = !empty($_GET['module_id']) ? TextHelper::clear(\wp_unslash($_GET['module_id'])) : '';
|
160 |
|
161 |
echo '<select name="module_id" id="dropdown_module_id"><option value="">' . \esc_html__('Filter by module', 'content-egg') . '</option>';
|
162 |
foreach ($modules as $module_id => $module_name)
|
@@ -175,7 +175,7 @@ class ProductTable extends MyListTable {
|
|
175 |
// search
|
176 |
if (!empty($_REQUEST['s']))
|
177 |
{
|
178 |
-
$s = trim($_REQUEST['s']);
|
179 |
if ($where)
|
180 |
$where .= ' AND ';
|
181 |
|
@@ -225,7 +225,7 @@ class ProductTable extends MyListTable {
|
|
225 |
foreach ($statuses as $status_id => $status_name)
|
226 |
{
|
227 |
$total = ProductModel::model()->count('stock_status = ' . (int) $status_id);
|
228 |
-
$class = (isset($_REQUEST['stock_status']) && $_REQUEST['stock_status'] !== '' && \sanitize_text_field($_REQUEST['stock_status']) == $status_id) ? ' class="current"' : '';
|
229 |
$status_links[$status_id] = '<a href="' . $admin_url . '&stock_status=' . (int) $status_id . '"' . $class . '>' . \esc_html($status_name);
|
230 |
$status_links[$status_id] .= sprintf(' <span class="count">(%s)</span></a>', \number_format_i18n($total));
|
231 |
}
|
91 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
92 |
return;
|
93 |
$module = ModuleManager::getInstance()->factory($item['module_id']);
|
94 |
+
$output = '<strong>' . esc_html($module->getName()) . '</strong>';
|
95 |
|
96 |
if (!$module->isActive())
|
97 |
+
$output .= '<br><mark class="inactive">' . esc_html(__('inactive', 'content egg')) . '</mark>';
|
98 |
|
99 |
return $output;
|
100 |
}
|
156 |
private function print_modules_dropdown()
|
157 |
{
|
158 |
$modules = ModuleManager::getInstance()->getAffiliteModulesList(true);
|
159 |
+
$selected_module_id = !empty($_GET['module_id']) ? TextHelper::clear(sanitize_text_field( \wp_unslash($_GET['module_id']))) : '';
|
160 |
|
161 |
echo '<select name="module_id" id="dropdown_module_id"><option value="">' . \esc_html__('Filter by module', 'content-egg') . '</option>';
|
162 |
foreach ($modules as $module_id => $module_name)
|
175 |
// search
|
176 |
if (!empty($_REQUEST['s']))
|
177 |
{
|
178 |
+
$s = trim(sanitize_text_field(wp_unslash($_REQUEST['s'])));
|
179 |
if ($where)
|
180 |
$where .= ' AND ';
|
181 |
|
225 |
foreach ($statuses as $status_id => $status_name)
|
226 |
{
|
227 |
$total = ProductModel::model()->count('stock_status = ' . (int) $status_id);
|
228 |
+
$class = (isset($_REQUEST['stock_status']) && $_REQUEST['stock_status'] !== '' && \sanitize_text_field(wp_unslash($_REQUEST['stock_status'])) == $status_id) ? ' class="current"' : '';
|
229 |
$status_links[$status_id] = '<a href="' . $admin_url . '&stock_status=' . (int) $status_id . '"' . $class . '>' . \esc_html($status_name);
|
230 |
$status_links[$status_id] .= sprintf(' <span class="count">(%s)</span></a>', \number_format_i18n($total));
|
231 |
}
|
application/admin/ToolsController.php
CHANGED
@@ -9,7 +9,6 @@ use ContentEgg\application\helpers\FileHelper;
|
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
use ContentEgg\application\components\ContentManager;
|
11 |
use ContentEgg\application\components\ModuleManager;
|
12 |
-
use ContentEgg\application\helpers\InputHelper;
|
13 |
|
14 |
/**
|
15 |
* ToolsController class file
|
@@ -88,7 +87,7 @@ class ToolsController {
|
|
88 |
}
|
89 |
$filename = 'subscribers-' . date('d-m-Y') . '.csv';
|
90 |
FileHelper::sendDownloadHeaders($filename);
|
91 |
-
echo FileHelper::array2Csv($csv_arr);
|
92 |
exit;
|
93 |
}
|
94 |
|
@@ -98,7 +97,7 @@ class ToolsController {
|
|
98 |
die('You do not have permission to view this page.');
|
99 |
|
100 |
if (isset($_GET['module']))
|
101 |
-
$module_id = TextHelper::clear(\sanitize_text_field($_GET['module']));
|
102 |
else
|
103 |
die('Module param can not be empty.');
|
104 |
|
@@ -133,7 +132,7 @@ class ToolsController {
|
|
133 |
}
|
134 |
$filename = $module_id . '-data-' . date('d-m-Y') . '.csv';
|
135 |
FileHelper::sendDownloadHeaders($filename);
|
136 |
-
echo FileHelper::array2Csv($csv_arr);
|
137 |
exit;
|
138 |
}
|
139 |
|
@@ -143,15 +142,18 @@ class ToolsController {
|
|
143 |
die('You do not have permission to view this page.');
|
144 |
|
145 |
if (isset($_GET['module']))
|
146 |
-
$module_id = TextHelper::clear(\sanitize_text_field($_GET['module']));
|
147 |
else
|
148 |
die('Module param can not be empty.');
|
149 |
|
150 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
151 |
die('The module does not exist.');
|
152 |
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
155 |
$module = ModuleManager::getInstance()->factory($module_id);
|
156 |
$model = $module->getProductModel();
|
157 |
|
@@ -164,7 +166,8 @@ class ToolsController {
|
|
164 |
|
165 |
$filename = $module->getName() . '-' . $field . '-' . date('d-m-Y') . '.txt';
|
166 |
FileHelper::sendDownloadHeaders($filename);
|
167 |
-
|
|
|
168 |
exit;
|
169 |
}
|
170 |
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
use ContentEgg\application\components\ContentManager;
|
11 |
use ContentEgg\application\components\ModuleManager;
|
|
|
12 |
|
13 |
/**
|
14 |
* ToolsController class file
|
87 |
}
|
88 |
$filename = 'subscribers-' . date('d-m-Y') . '.csv';
|
89 |
FileHelper::sendDownloadHeaders($filename);
|
90 |
+
echo FileHelper::array2Csv($csv_arr); // phpcs:ignore
|
91 |
exit;
|
92 |
}
|
93 |
|
97 |
die('You do not have permission to view this page.');
|
98 |
|
99 |
if (isset($_GET['module']))
|
100 |
+
$module_id = TextHelper::clear(\sanitize_text_field(wp_unslash($_GET['module'])));
|
101 |
else
|
102 |
die('Module param can not be empty.');
|
103 |
|
132 |
}
|
133 |
$filename = $module_id . '-data-' . date('d-m-Y') . '.csv';
|
134 |
FileHelper::sendDownloadHeaders($filename);
|
135 |
+
echo FileHelper::array2Csv($csv_arr); // phpcs:ignore
|
136 |
exit;
|
137 |
}
|
138 |
|
142 |
die('You do not have permission to view this page.');
|
143 |
|
144 |
if (isset($_GET['module']))
|
145 |
+
$module_id = TextHelper::clear(\sanitize_text_field(wp_unslash($_GET['module'])));
|
146 |
else
|
147 |
die('Module param can not be empty.');
|
148 |
|
149 |
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
150 |
die('The module does not exist.');
|
151 |
|
152 |
+
if (!empty($_GET['field']))
|
153 |
+
$field = sanitize_key(wp_unslash($_GET['field']));
|
154 |
+
else
|
155 |
+
$field = 'url';
|
156 |
+
|
157 |
$module = ModuleManager::getInstance()->factory($module_id);
|
158 |
$model = $module->getProductModel();
|
159 |
|
166 |
|
167 |
$filename = $module->getName() . '-' . $field . '-' . date('d-m-Y') . '.txt';
|
168 |
FileHelper::sendDownloadHeaders($filename);
|
169 |
+
$results = array_map('sanitize_text_field', $results);
|
170 |
+
echo join("\r\n", $results); // phpcs:ignore
|
171 |
exit;
|
172 |
}
|
173 |
|
application/admin/views/_metabox_autoblog.php
CHANGED
@@ -9,47 +9,47 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
9 |
|
10 |
<tr class="form-field">
|
11 |
<th valign="top" scope="row">
|
12 |
-
<label for="name"><?php
|
13 |
</th>
|
14 |
<td>
|
15 |
<input id="name" name="item[name]" type="text" value="<?php echo esc_attr($item['name']) ?>"
|
16 |
-
size="50" class="code" placeholder="<?php
|
17 |
</td>
|
18 |
</tr>
|
19 |
|
20 |
<tr class="form-field">
|
21 |
<th valign="top" scope="row">
|
22 |
-
<label for="status"><?php
|
23 |
</th>
|
24 |
<td>
|
25 |
<select id="status" name="item[status]">
|
26 |
-
<option value="1"<?php if ($item['status']) echo ' selected="selected"'; ?>><?php
|
27 |
-
<option value="0"<?php if (!$item['status']) echo ' selected="selected"'; ?>><?php
|
28 |
</select>
|
29 |
</td>
|
30 |
</tr>
|
31 |
|
32 |
<tr class="form-field">
|
33 |
<th valign="top" scope="row">
|
34 |
-
<label for="run_frequency"><?php
|
35 |
</th>
|
36 |
<td>
|
37 |
<select id="run_frequency" name="item[run_frequency]">
|
38 |
-
<option value="3600"<?php if ($item['run_frequency'] == 3600) echo ' selected="selected"'; ?>><?php
|
39 |
-
<option value="17280"<?php if ($item['run_frequency'] == 17280) echo ' selected="selected"'; ?>><?php
|
40 |
-
<option value="43200"<?php if ($item['run_frequency'] == 43200) echo ' selected="selected"'; ?>><?php
|
41 |
-
<option value="86400"<?php if ($item['run_frequency'] == 86400) echo ' selected="selected"'; ?>><?php
|
42 |
-
<option value="259200"<?php if ($item['run_frequency'] == 259200) echo ' selected="selected"'; ?>><?php
|
43 |
-
<option value="604800"<?php if ($item['run_frequency'] == 604800) echo ' selected="selected"'; ?>><?php
|
44 |
-
<option value="1209600"<?php if ($item['run_frequency'] == 1209600) echo ' selected="selected"'; ?>><?php
|
45 |
</select>
|
46 |
-
<p class="description"><?php
|
47 |
</td>
|
48 |
</tr>
|
49 |
<?php if (!$batch): ?>
|
50 |
<tr class="form-field">
|
51 |
<th valign="top" scope="row">
|
52 |
-
<label for="keywords"><?php
|
53 |
</th>
|
54 |
<td>
|
55 |
|
@@ -57,25 +57,25 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
57 |
<tr>
|
58 |
<td valign="top" style="vertical-align: top;" width="50%">
|
59 |
<div style="margin-bottom: 10px;">
|
60 |
-
<button id="tool_capitalise" title="<?php
|
61 |
-
<button href="#" id="tool_upper_first" title="<?php
|
62 |
-
<button href="#" id="tool_sort" title="<?php
|
63 |
-
<button href="#" id="tool_add_minus" title="<?php
|
64 |
-
<button href="#" id="tool_del_minus" title="<?php
|
65 |
-
<button href="#" id="tool_delete" title="<?php
|
66 |
</div>
|
67 |
<textarea rows="28" id="keywords" name="item[keywords]" class="small-text"><?php echo esc_html($item['keywords']) ?></textarea>
|
68 |
<div>
|
69 |
-
<?php
|
70 |
</div>
|
71 |
</td>
|
72 |
<td valign="top" style="vertical-align: top;">
|
73 |
<div id="cegg-parsers-tabs">
|
74 |
<ul>
|
75 |
-
<li><a href="#fragment-1"><?php
|
76 |
<?php /*
|
77 |
-
<li><a href="#fragment-2"><?php
|
78 |
-
<li><a href="#fragment-3"><?php
|
79 |
*
|
80 |
*/
|
81 |
?>
|
@@ -87,11 +87,11 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
87 |
<input id="sug_google" name="sug_radio" value="sug_google" type="radio" checked="checked"><label for="sug_google">Google</label>
|
88 |
<input id="sug_amazon" name="sug_radio" value="sug_amazon" type="radio"><label for="sug_amazon">Amazon</label>
|
89 |
<?php if (\ContentEgg\application\admin\GeneralConfig::getInstance()->option('lang') == 'ru'): ?>
|
90 |
-
<input id="sug_yandex" name="sug_radio" value="sug_yandex" type="radio"><label for="sug_yandex"><?php
|
91 |
-
<input id="sug_market" name="sug_radio" value="sug_market" type="radio"><label for="sug_market"><?php
|
92 |
<?php endif; ?>
|
93 |
</div>
|
94 |
-
<input type="text" id="sug_query" placeholder="<?php
|
95 |
<select multiple="multiple" id="sug_keywords" style="width: 98%" size="23"></select>
|
96 |
</div>
|
97 |
<?php /*
|
@@ -118,7 +118,7 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
118 |
<option value='most-wished-for'>Most Wished For</option>
|
119 |
<option value='most-gifted'>Most Gifted</option>
|
120 |
</select>
|
121 |
-
<button id="trend_goods" type="button"><?php
|
122 |
|
123 |
</div>
|
124 |
<select multiple="multiple" id="goods_keywords" style="width: 98%" size="24"></select>
|
@@ -133,13 +133,13 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
133 |
</tr>
|
134 |
</table>
|
135 |
<p class="">
|
136 |
-
<?php
|
137 |
-
<?php
|
138 |
-
<?php
|
139 |
-
<?php
|
140 |
</p>
|
141 |
<p class="">
|
142 |
-
<?php
|
143 |
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
144 |
</p>
|
145 |
|
@@ -149,7 +149,7 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
149 |
<?php if ($batch): ?>
|
150 |
<tr class="form-field">
|
151 |
<th valign="top" scope="row">
|
152 |
-
<label for="keywords_file"><?php
|
153 |
</th>
|
154 |
|
155 |
<td>
|
@@ -157,10 +157,10 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
157 |
|
158 |
<p class="description">
|
159 |
|
160 |
-
<?php
|
161 |
<br>
|
162 |
<br>
|
163 |
-
<b>1. <?php
|
164 |
<br>
|
165 |
<code>category 1;keyword 1<br>
|
166 |
category 1;keyword 2<br>
|
@@ -169,15 +169,15 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
169 |
...
|
170 |
</code>
|
171 |
<br>
|
172 |
-
<?php
|
173 |
-
<?php
|
174 |
<br><br>
|
175 |
-
<b>2. <?php
|
176 |
-
<?php
|
177 |
<br>
|
178 |
-
<?php
|
179 |
<br><br>
|
180 |
-
<?php
|
181 |
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
182 |
|
183 |
</p>
|
@@ -188,86 +188,86 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
188 |
|
189 |
<tr class="form-field">
|
190 |
<th valign="top" scope="row">
|
191 |
-
<label for="keywords_per_run"><?php
|
192 |
</th>
|
193 |
<td>
|
194 |
<input id="keywords_per_run" name="item[keywords_per_run]" value="<?php echo esc_attr($item['keywords_per_run']) ?>"
|
195 |
type="number" class="small-text">
|
196 |
-
<p class="description"><?php
|
197 |
</td>
|
198 |
</tr>
|
199 |
<tr class="form-field">
|
200 |
<th valign="top" scope="row">
|
201 |
-
<label for="template_title"><?php
|
202 |
</th>
|
203 |
<td>
|
204 |
|
205 |
<input id="template_title" name="item[template_title]" value="<?php echo esc_attr($item['template_title']) ?>"
|
206 |
type="text" class="regular-text ltr">
|
207 |
<p class="description">
|
208 |
-
<?php
|
209 |
-
<?php
|
210 |
-
<?php
|
211 |
-
<?php
|
212 |
</p>
|
213 |
</td>
|
214 |
</tr>
|
215 |
|
216 |
<tr class="form-field">
|
217 |
<th valign="top" scope="row">
|
218 |
-
<label for="template_body"><?php
|
219 |
</th>
|
220 |
<td>
|
221 |
|
222 |
<textarea rows="4" id="template_body" name="item[template_body]"><?php echo esc_html($item['template_body']) ?></textarea>
|
223 |
<p class="description">
|
224 |
-
<?php
|
225 |
[content-egg module=Amazon template=grid]<br>
|
226 |
-
<?php
|
227 |
|
228 |
</p>
|
229 |
</td>
|
230 |
</tr>
|
231 |
<tr class="form-field">
|
232 |
<th valign="top" scope="row">
|
233 |
-
<label for="include_modules"><?php
|
234 |
</th>
|
235 |
<td>
|
236 |
<div class="cegg-checkboxgroup">
|
237 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
238 |
<div class="cegg-checkbox">
|
239 |
-
<label><input <?php if (in_array($module->getId(), $item['include_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[include_modules][]" /><?php echo $module->getName(); ?></label>
|
240 |
</div>
|
241 |
<?php endforeach; ?>
|
242 |
</div>
|
243 |
<p class="description">
|
244 |
-
<?php
|
245 |
-
<?php
|
246 |
</p>
|
247 |
</td>
|
248 |
</tr>
|
249 |
|
250 |
<tr class="form-field">
|
251 |
<th valign="top" scope="row">
|
252 |
-
<label for="exclude_modules"><?php
|
253 |
</th>
|
254 |
<td>
|
255 |
<div class="cegg-checkboxgroup">
|
256 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
257 |
<div class="cegg-checkbox">
|
258 |
-
<label><input <?php if (in_array($module->getId(), $item['exclude_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[exclude_modules][]" /><?php echo $module->getName(); ?></label>
|
259 |
</div>
|
260 |
<?php endforeach; ?>
|
261 |
</div>
|
262 |
<p class="description">
|
263 |
-
<?php
|
264 |
</p>
|
265 |
</td>
|
266 |
</tr>
|
267 |
|
268 |
<tr class="form-field">
|
269 |
<th valign="top" scope="row">
|
270 |
-
<label for="post_status"><?php
|
271 |
</th>
|
272 |
<td>
|
273 |
<select id="post_status" name="item[post_status]">
|
@@ -279,7 +279,7 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
279 |
|
280 |
<tr class="form-field">
|
281 |
<th valign="top" scope="row">
|
282 |
-
<label for="post_type"><?php
|
283 |
</th>
|
284 |
<td>
|
285 |
<?php
|
@@ -288,8 +288,8 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
288 |
unset($post_types['attachment']);
|
289 |
?>
|
290 |
<select id="post_type" name="item[post_type]">
|
291 |
-
<?php foreach ($post_types as $
|
292 |
-
<option value="<?php echo \esc_attr($
|
293 |
<?php endforeach; ?>
|
294 |
</select>
|
295 |
</td>
|
@@ -297,14 +297,14 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
297 |
|
298 |
<tr class="form-field">
|
299 |
<th valign="top" scope="row">
|
300 |
-
<label for="category"><?php
|
301 |
</th>
|
302 |
<td>
|
303 |
<?php $categories = AdminHelper::getCategoryList(); ?>
|
304 |
|
305 |
<select name="item[category]" id="category">
|
306 |
<?php if ($batch): ?>
|
307 |
-
<option value="-1" <?php \selected($item['category'], -1); ?>>[ <?php
|
308 |
<?php endif; ?>
|
309 |
<?php foreach ($categories as $c_id => $c_name): ?>
|
310 |
<option value="<?php echo \esc_attr($c_id); ?>" <?php \selected($item['category'], $c_id); ?>>
|
@@ -315,9 +315,9 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
315 |
|
316 |
|
317 |
<p class="description">
|
318 |
-
<?php
|
319 |
<?php if ($batch): ?>
|
320 |
-
<?php
|
321 |
<?php endif; ?>
|
322 |
</p>
|
323 |
</td>
|
@@ -325,135 +325,135 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
325 |
|
326 |
<tr class="form-field">
|
327 |
<th valign="top" scope="row">
|
328 |
-
<label for="user_id"><?php
|
329 |
</th>
|
330 |
<td>
|
331 |
<?php
|
332 |
\wp_dropdown_users(array('name' => 'item[user_id]',
|
333 |
'capability' => array('edit_posts'), 'id' => 'user_id', 'selected' => $item['user_id']));
|
334 |
?>
|
335 |
-
<p class="description"><?php
|
336 |
</td>
|
337 |
</tr>
|
338 |
<tr class="form-field">
|
339 |
<th valign="top" scope="row">
|
340 |
-
<label for="dynamic_categories"><?php
|
341 |
</th>
|
342 |
<td>
|
343 |
<select id="post_status" name="item[config][dynamic_categories]">
|
344 |
-
<option value="0"<?php if ($item['config']['dynamic_categories'] == 0) echo ' selected="selected"'; ?>><?php
|
345 |
-
<option value="1"<?php if ($item['config']['dynamic_categories'] == 1) echo ' selected="selected"'; ?>><?php
|
346 |
-
<option value="2"<?php if ($item['config']['dynamic_categories'] == 2) echo ' selected="selected"'; ?>><?php
|
347 |
</select>
|
348 |
-
<p class="description"><?php
|
349 |
</td>
|
350 |
</tr>
|
351 |
|
352 |
<tr class="form-field">
|
353 |
<th valign="top" scope="row">
|
354 |
-
<label for="min_modules_count"><?php
|
355 |
</th>
|
356 |
<td>
|
357 |
<input id="min_modules_count" name="item[min_modules_count]" value="<?php echo esc_attr($item['min_modules_count']) ?>"
|
358 |
type="number" class="small-text">
|
359 |
-
<p class="description"><?php
|
360 |
</td>
|
361 |
</tr>
|
362 |
|
363 |
<tr class="form-field">
|
364 |
<th valign="top" scope="row">
|
365 |
-
<label for="min_comment_count"><?php
|
366 |
</th>
|
367 |
<td>
|
368 |
<input id="min_modules_count" name="item[config][min_comments_count]" value="<?php echo esc_attr($item['config']['min_comments_count']) ?>"
|
369 |
type="number" class="small-text">
|
370 |
-
<p class="description"><?php
|
371 |
</td>
|
372 |
</tr>
|
373 |
|
374 |
<tr class="form-field">
|
375 |
<th valign="top" scope="row">
|
376 |
-
<label for="autoupdate_modules"><?php
|
377 |
</th>
|
378 |
<td>
|
379 |
<div class="cegg-checkboxgroup">
|
380 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
381 |
<div class="cegg-checkbox">
|
382 |
-
<label><input <?php if (in_array($module->getId(), $item['autoupdate_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[autoupdate_modules][]" /><?php echo $module->getName(); ?></label>
|
383 |
</div>
|
384 |
<?php endforeach; ?>
|
385 |
</div>
|
386 |
<p class="description">
|
387 |
-
<?php
|
388 |
</p>
|
389 |
</td>
|
390 |
</tr>
|
391 |
<tr class="form-field">
|
392 |
<th valign="top" scope="row">
|
393 |
-
<label for="required_modules"><?php
|
394 |
</th>
|
395 |
<td>
|
396 |
<div class="cegg-checkboxgroup">
|
397 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
398 |
<div class="cegg-checkbox">
|
399 |
-
<label><input <?php if (in_array($module->getId(), $item['required_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[required_modules][]" /><?php echo $module->getName(); ?></label>
|
400 |
</div>
|
401 |
<?php endforeach; ?>
|
402 |
</div>
|
403 |
<p class="description">
|
404 |
-
<?php
|
405 |
</p>
|
406 |
</td>
|
407 |
</tr>
|
408 |
|
409 |
<tr class="form-field">
|
410 |
<th valign="top" scope="row">
|
411 |
-
<label for="main_product"><?php
|
412 |
</th>
|
413 |
<td>
|
414 |
<select id="main_product" name="item[main_product]">
|
415 |
-
<option value="min_price"<?php if ($item['main_product'] == 'min_price') echo ' selected="selected"'; ?>><?php
|
416 |
-
<option value="max_price"<?php if ($item['main_product'] == 'max_price') echo ' selected="selected"'; ?>><?php
|
417 |
-
<option value="random"<?php if ($item['main_product'] == 'random') echo ' selected="selected"'; ?>><?php
|
418 |
</select>
|
419 |
<p class="description">
|
420 |
-
<?php
|
421 |
-
<?php
|
422 |
</p>
|
423 |
</td>
|
424 |
</tr>
|
425 |
|
426 |
<tr class="form-field">
|
427 |
<th valign="top" scope="row">
|
428 |
-
<label for="tags"><?php
|
429 |
</th>
|
430 |
<td>
|
431 |
|
432 |
<input id="tags" name="item[tags]" value="<?php echo esc_attr($item['tags']) ?>"
|
433 |
type="text" class="regular-text ltr">
|
434 |
<p class="description">
|
435 |
-
<?php
|
436 |
-
<?php
|
437 |
</p>
|
438 |
</td>
|
439 |
</tr>
|
440 |
|
441 |
<tr class="form-field">
|
442 |
<th valign="top" scope="row">
|
443 |
-
<label for="status"><?php
|
444 |
</th>
|
445 |
<td>
|
446 |
<select id="product_condition" name="item[product_condition]">
|
447 |
-
<option value=""<?php if (!empty($item['product_condition'])) echo ' selected="selected"'; ?>><?php
|
448 |
-
<option value="new"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new') echo ' selected="selected"'; ?>><?php
|
449 |
-
<option value="used"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'used') echo ' selected="selected"'; ?>><?php
|
450 |
-
<option value="refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'refurbished') echo ' selected="selected"'; ?>><?php
|
451 |
-
<option value="new_other"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new_other') echo ' selected="selected"'; ?>><?php
|
452 |
-
<option value="seller_refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'seller_refurbished') echo ' selected="selected"'; ?>><?php
|
453 |
-
<option value="for_parts"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'for_parts') echo ' selected="selected"'; ?>><?php
|
454 |
</select>
|
455 |
<p class="description">
|
456 |
-
<?php
|
457 |
</p>
|
458 |
|
459 |
</td>
|
@@ -461,21 +461,21 @@ use ContentEgg\application\helpers\AdminHelper;
|
|
461 |
|
462 |
<tr class="form-field">
|
463 |
<th valign="top" scope="row">
|
464 |
-
<label for="custom_fields"><?php
|
465 |
</th>
|
466 |
<td>
|
467 |
<div style="width: 50%;float:left;">
|
468 |
<?php for ($i = 0; $i < count($item['custom_field_names']); $i++): ?>
|
469 |
-
<input type="text" value="<?php echo esc_attr($item['custom_field_names'][$i]); ?>" name="item[custom_field_names][]" placeholder="<?php
|
470 |
<?php endfor; ?>
|
471 |
</div>
|
472 |
<div style="width: 50%;float:left;">
|
473 |
<?php for ($i = 0; $i < count($item['custom_field_values']); $i++): ?>
|
474 |
-
<input value="<?php echo esc_attr($item['custom_field_values'][$i]); ?>" type="text" name="item[custom_field_values][]" placeholder="<?php
|
475 |
<?php endfor; ?>
|
476 |
</div>
|
477 |
<p class="description">
|
478 |
-
<?php
|
479 |
</p>
|
480 |
</td>
|
481 |
</tr>
|
9 |
|
10 |
<tr class="form-field">
|
11 |
<th valign="top" scope="row">
|
12 |
+
<label for="name"><?php esc_html_e('Name', 'content-egg'); ?></label>
|
13 |
</th>
|
14 |
<td>
|
15 |
<input id="name" name="item[name]" type="text" value="<?php echo esc_attr($item['name']) ?>"
|
16 |
+
size="50" class="code" placeholder="<?php esc_html_e('Name for autoblogging (optional)', 'content-egg'); ?>">
|
17 |
</td>
|
18 |
</tr>
|
19 |
|
20 |
<tr class="form-field">
|
21 |
<th valign="top" scope="row">
|
22 |
+
<label for="status"><?php esc_html_e('Task status', 'content-egg'); ?></label>
|
23 |
</th>
|
24 |
<td>
|
25 |
<select id="status" name="item[status]">
|
26 |
+
<option value="1"<?php if ($item['status']) echo ' selected="selected"'; ?>><?php esc_html_e('Enabled', 'content-egg'); ?></option>
|
27 |
+
<option value="0"<?php if (!$item['status']) echo ' selected="selected"'; ?>><?php esc_html_e('Disabled', 'content-egg'); ?></option>
|
28 |
</select>
|
29 |
</td>
|
30 |
</tr>
|
31 |
|
32 |
<tr class="form-field">
|
33 |
<th valign="top" scope="row">
|
34 |
+
<label for="run_frequency"><?php esc_html_e('Recurrency', 'content-egg'); ?></label>
|
35 |
</th>
|
36 |
<td>
|
37 |
<select id="run_frequency" name="item[run_frequency]">
|
38 |
+
<option value="3600"<?php if ($item['run_frequency'] == 3600) echo ' selected="selected"'; ?>><?php esc_html_e('Every hour', 'content-egg'); ?></option>
|
39 |
+
<option value="17280"<?php if ($item['run_frequency'] == 17280) echo ' selected="selected"'; ?>><?php esc_html_e('5 times in a day', 'content-egg'); ?></option>
|
40 |
+
<option value="43200"<?php if ($item['run_frequency'] == 43200) echo ' selected="selected"'; ?>><?php esc_html_e('Twice daily', 'content-egg'); ?></option>
|
41 |
+
<option value="86400"<?php if ($item['run_frequency'] == 86400) echo ' selected="selected"'; ?>><?php esc_html_e('Once a day', 'content-egg'); ?></option>
|
42 |
+
<option value="259200"<?php if ($item['run_frequency'] == 259200) echo ' selected="selected"'; ?>><?php esc_html_e('Each three days', 'content-egg'); ?></option>
|
43 |
+
<option value="604800"<?php if ($item['run_frequency'] == 604800) echo ' selected="selected"'; ?>><?php esc_html_e('Once a week', 'content-egg'); ?></option>
|
44 |
+
<option value="1209600"<?php if ($item['run_frequency'] == 1209600) echo ' selected="selected"'; ?>><?php esc_html_e('Once in 2 weeks', 'content-egg'); ?></option>
|
45 |
</select>
|
46 |
+
<p class="description"><?php esc_html_e('How often autoblogging will run this task.', 'content-egg'); ?></p>
|
47 |
</td>
|
48 |
</tr>
|
49 |
<?php if (!$batch): ?>
|
50 |
<tr class="form-field">
|
51 |
<th valign="top" scope="row">
|
52 |
+
<label for="keywords"><?php esc_html_e('Keywords', 'content-egg'); ?></label>
|
53 |
</th>
|
54 |
<td>
|
55 |
|
57 |
<tr>
|
58 |
<td valign="top" style="vertical-align: top;" width="50%">
|
59 |
<div style="margin-bottom: 10px;">
|
60 |
+
<button id="tool_capitalise" title="<?php esc_html_e('Uppercase First Letter for Each Word', 'content-egg'); ?>"><span class="ui-icon ui-icon-arrowthick-1-n"></span></button>
|
61 |
+
<button href="#" id="tool_upper_first" title="<?php esc_html_e('Uppercase first letter', 'content-egg'); ?>"><span class="ui-icon ui-icon-carat-1-n"></span></button>
|
62 |
+
<button href="#" id="tool_sort" title="<?php esc_html_e('Sort with alpha order', 'content-egg'); ?>"><span class="ui-icon ui-icon-arrow-1-s"></span></button>
|
63 |
+
<button href="#" id="tool_add_minus" title="<?php esc_html_e('All words are inactive', 'content-egg'); ?>"><span class="ui-icon ui-icon-minus"></span></button>
|
64 |
+
<button href="#" id="tool_del_minus" title="<?php esc_html_e('All words are active', 'content-egg'); ?>"><span class="ui-icon ui-icon-plus"></span></button>
|
65 |
+
<button href="#" id="tool_delete" title="<?php esc_html_e('Clear list', 'content-egg'); ?>"><span class="ui-icon ui-icon-closethick"></span></button>
|
66 |
</div>
|
67 |
<textarea rows="28" id="keywords" name="item[keywords]" class="small-text"><?php echo esc_html($item['keywords']) ?></textarea>
|
68 |
<div>
|
69 |
+
<?php esc_html_e('Total', 'content-egg'); ?>: <b><span id="k_count">0</span></b>
|
70 |
</div>
|
71 |
</td>
|
72 |
<td valign="top" style="vertical-align: top;">
|
73 |
<div id="cegg-parsers-tabs">
|
74 |
<ul>
|
75 |
+
<li><a href="#fragment-1"><?php esc_html_e('Hints', 'content-egg'); ?></a></li>
|
76 |
<?php /*
|
77 |
+
<li><a href="#fragment-2"><?php esc_html_e('Trends', 'content-egg'); ?></a></a></li>
|
78 |
+
<li><a href="#fragment-3"><?php esc_html_e('Products', 'content-egg'); ?></a></a></li>
|
79 |
*
|
80 |
*/
|
81 |
?>
|
87 |
<input id="sug_google" name="sug_radio" value="sug_google" type="radio" checked="checked"><label for="sug_google">Google</label>
|
88 |
<input id="sug_amazon" name="sug_radio" value="sug_amazon" type="radio"><label for="sug_amazon">Amazon</label>
|
89 |
<?php if (\ContentEgg\application\admin\GeneralConfig::getInstance()->option('lang') == 'ru'): ?>
|
90 |
+
<input id="sug_yandex" name="sug_radio" value="sug_yandex" type="radio"><label for="sug_yandex"><?php esc_html_e('Yandex', 'content-egg'); ?></label>
|
91 |
+
<input id="sug_market" name="sug_radio" value="sug_market" type="radio"><label for="sug_market"><?php esc_html_e('Yandex.Market', 'content-egg'); ?></label>
|
92 |
<?php endif; ?>
|
93 |
</div>
|
94 |
+
<input type="text" id="sug_query" placeholder="<?php esc_html_e('Start enter keyword', 'content-egg'); ?>" />
|
95 |
<select multiple="multiple" id="sug_keywords" style="width: 98%" size="23"></select>
|
96 |
</div>
|
97 |
<?php /*
|
118 |
<option value='most-wished-for'>Most Wished For</option>
|
119 |
<option value='most-gifted'>Most Gifted</option>
|
120 |
</select>
|
121 |
+
<button id="trend_goods" type="button"><?php esc_html_e('Load...', 'content-egg'); ?></button>
|
122 |
|
123 |
</div>
|
124 |
<select multiple="multiple" id="goods_keywords" style="width: 98%" size="24"></select>
|
133 |
</tr>
|
134 |
</table>
|
135 |
<p class="">
|
136 |
+
<?php esc_html_e('Each keyword from separate line.', 'content-egg'); ?>
|
137 |
+
<?php esc_html_e('One keyword is one post.', 'content-egg'); ?>
|
138 |
+
<?php esc_html_e('Handled keywords are marked by [brackets].', 'content-egg'); ?>
|
139 |
+
<?php esc_html_e('When all keywords will be processed, task will stop.', 'content-egg'); ?>
|
140 |
</p>
|
141 |
<p class="">
|
142 |
+
<?php esc_html_e('You can also use separate keywords for some modules:', 'content-egg'); ?><br>
|
143 |
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
144 |
</p>
|
145 |
|
149 |
<?php if ($batch): ?>
|
150 |
<tr class="form-field">
|
151 |
<th valign="top" scope="row">
|
152 |
+
<label for="keywords_file"><?php esc_html_e('Keywords', 'content-egg'); ?></label>
|
153 |
</th>
|
154 |
|
155 |
<td>
|
157 |
|
158 |
<p class="description">
|
159 |
|
160 |
+
<?php esc_html_e('Two format are supported: ', 'content-egg'); ?>
|
161 |
<br>
|
162 |
<br>
|
163 |
+
<b>1. <?php esc_html_e('CSV files in format:', 'content-egg'); ?></b>
|
164 |
<br>
|
165 |
<code>category 1;keyword 1<br>
|
166 |
category 1;keyword 2<br>
|
169 |
...
|
170 |
</code>
|
171 |
<br>
|
172 |
+
<?php esc_html_e('Divider - ";"', 'content-egg'); ?><br>
|
173 |
+
<?php esc_html_e('For each category will be created separate task for autoblog.', 'content-egg'); ?>
|
174 |
<br><br>
|
175 |
+
<b>2. <?php esc_html_e('TXT files:', 'content-egg'); ?></b><br>
|
176 |
+
<?php esc_html_e('Simple text file with list of keywords (each word from separate line).', 'content-egg'); ?>
|
177 |
<br>
|
178 |
+
<?php esc_html_e('File must be in UTF-8', 'content-egg'); ?>
|
179 |
<br><br>
|
180 |
+
<?php esc_html_e('You can also use separate keywords for some modules:', 'content-egg'); ?><br>
|
181 |
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
182 |
|
183 |
</p>
|
188 |
|
189 |
<tr class="form-field">
|
190 |
<th valign="top" scope="row">
|
191 |
+
<label for="keywords_per_run"><?php esc_html_e('Process keywords', 'content-egg'); ?></label>
|
192 |
</th>
|
193 |
<td>
|
194 |
<input id="keywords_per_run" name="item[keywords_per_run]" value="<?php echo esc_attr($item['keywords_per_run']) ?>"
|
195 |
type="number" class="small-text">
|
196 |
+
<p class="description"><?php esc_html_e('How many keywords to process at a time.', 'content-egg'); ?></p>
|
197 |
</td>
|
198 |
</tr>
|
199 |
<tr class="form-field">
|
200 |
<th valign="top" scope="row">
|
201 |
+
<label for="template_title"><?php esc_html_e('Post title template ', 'content-egg'); ?></label>
|
202 |
</th>
|
203 |
<td>
|
204 |
|
205 |
<input id="template_title" name="item[template_title]" value="<?php echo esc_attr($item['template_title']) ?>"
|
206 |
type="text" class="regular-text ltr">
|
207 |
<p class="description">
|
208 |
+
<?php esc_html_e('Use tags:', 'content-egg'); ?> %KEYWORD%, %KEYWORD.ModuleID%, %PRODUCT.title%, %PRODUCT.price%, %PRODUCT.merchant%, %PRODUCT.domain%, %PRODUCT.manufacturer%,...<br>
|
209 |
+
<?php esc_html_e('For display data of plugin use special tags, for example:', 'content-egg'); ?> %Amazon.title%.<br>
|
210 |
+
<?php esc_html_e('You also can set index number for access to data of plugin', 'content-egg'); ?> %Amazon.0.price%.<br>
|
211 |
+
<?php esc_html_e('You can use spin syntax with synonyms, for example, {Discount|Sale|Cheap}.', 'content-egg'); ?>
|
212 |
</p>
|
213 |
</td>
|
214 |
</tr>
|
215 |
|
216 |
<tr class="form-field">
|
217 |
<th valign="top" scope="row">
|
218 |
+
<label for="template_body"><?php esc_html_e('Post body template ', 'content-egg'); ?></label>
|
219 |
</th>
|
220 |
<td>
|
221 |
|
222 |
<textarea rows="4" id="template_body" name="item[template_body]"><?php echo esc_html($item['template_body']) ?></textarea>
|
223 |
<p class="description">
|
224 |
+
<?php esc_html_e('You can use CE shortcodes like:', 'content-egg'); ?>
|
225 |
[content-egg module=Amazon template=grid]<br>
|
226 |
+
<?php esc_html_e('Spin syntax and all tags from title template, will also work here.', 'content-egg'); ?><br>
|
227 |
|
228 |
</p>
|
229 |
</td>
|
230 |
</tr>
|
231 |
<tr class="form-field">
|
232 |
<th valign="top" scope="row">
|
233 |
+
<label for="include_modules"><?php esc_html_e('Only selected modules', 'content-egg'); ?></label>
|
234 |
</th>
|
235 |
<td>
|
236 |
<div class="cegg-checkboxgroup">
|
237 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
238 |
<div class="cegg-checkbox">
|
239 |
+
<label><input <?php if (in_array($module->getId(), $item['include_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[include_modules][]" /><?php echo esc_html($module->getName()); ?></label>
|
240 |
</div>
|
241 |
<?php endforeach; ?>
|
242 |
</div>
|
243 |
<p class="description">
|
244 |
+
<?php esc_html_e('Run only selected modules for this task.', 'content-egg'); ?>
|
245 |
+
<?php esc_html_e('If you don\'t select any modules, all active modules will be used.', 'content-egg'); ?>
|
246 |
</p>
|
247 |
</td>
|
248 |
</tr>
|
249 |
|
250 |
<tr class="form-field">
|
251 |
<th valign="top" scope="row">
|
252 |
+
<label for="exclude_modules"><?php esc_html_e('Exclude modules', 'content-egg'); ?></label>
|
253 |
</th>
|
254 |
<td>
|
255 |
<div class="cegg-checkboxgroup">
|
256 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
257 |
<div class="cegg-checkbox">
|
258 |
+
<label><input <?php if (in_array($module->getId(), $item['exclude_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[exclude_modules][]" /><?php echo esc_html($module->getName()); ?></label>
|
259 |
</div>
|
260 |
<?php endforeach; ?>
|
261 |
</div>
|
262 |
<p class="description">
|
263 |
+
<?php esc_html_e('Chosen modules will not run in this configuration. ', 'content-egg'); ?>
|
264 |
</p>
|
265 |
</td>
|
266 |
</tr>
|
267 |
|
268 |
<tr class="form-field">
|
269 |
<th valign="top" scope="row">
|
270 |
+
<label for="post_status"><?php esc_html_e('Post status', 'content-egg'); ?></label>
|
271 |
</th>
|
272 |
<td>
|
273 |
<select id="post_status" name="item[post_status]">
|
279 |
|
280 |
<tr class="form-field">
|
281 |
<th valign="top" scope="row">
|
282 |
+
<label for="post_type"><?php esc_html_e('Post type', 'content-egg'); ?></label>
|
283 |
</th>
|
284 |
<td>
|
285 |
<?php
|
288 |
unset($post_types['attachment']);
|
289 |
?>
|
290 |
<select id="post_type" name="item[post_type]">
|
291 |
+
<?php foreach ($post_types as $pt): ?>
|
292 |
+
<option value="<?php echo \esc_attr($pt); ?>"<?php if ($item['post_type'] == $pt) echo ' selected="selected"'; ?>><?php echo \esc_html($pt); ?></option>
|
293 |
<?php endforeach; ?>
|
294 |
</select>
|
295 |
</td>
|
297 |
|
298 |
<tr class="form-field">
|
299 |
<th valign="top" scope="row">
|
300 |
+
<label for="category"><?php esc_html_e('Category ', 'content-egg'); ?></label>
|
301 |
</th>
|
302 |
<td>
|
303 |
<?php $categories = AdminHelper::getCategoryList(); ?>
|
304 |
|
305 |
<select name="item[category]" id="category">
|
306 |
<?php if ($batch): ?>
|
307 |
+
<option value="-1" <?php \selected($item['category'], -1); ?>>[ <?php esc_html_e('Create Automatically', 'content-egg'); ?> ]</option>
|
308 |
<?php endif; ?>
|
309 |
<?php foreach ($categories as $c_id => $c_name): ?>
|
310 |
<option value="<?php echo \esc_attr($c_id); ?>" <?php \selected($item['category'], $c_id); ?>>
|
315 |
|
316 |
|
317 |
<p class="description">
|
318 |
+
<?php esc_html_e('Default category.', 'content-egg'); ?>
|
319 |
<?php if ($batch): ?>
|
320 |
+
<?php esc_html_e('"Create Automatically" means, that categories will be created based on data of CSV file with keywords and categories.', 'content-egg'); ?>
|
321 |
<?php endif; ?>
|
322 |
</p>
|
323 |
</td>
|
325 |
|
326 |
<tr class="form-field">
|
327 |
<th valign="top" scope="row">
|
328 |
+
<label for="user_id"><?php esc_html_e('User', 'content-egg'); ?></label>
|
329 |
</th>
|
330 |
<td>
|
331 |
<?php
|
332 |
\wp_dropdown_users(array('name' => 'item[user_id]',
|
333 |
'capability' => array('edit_posts'), 'id' => 'user_id', 'selected' => $item['user_id']));
|
334 |
?>
|
335 |
+
<p class="description"><?php esc_html_e('This user will be author of posts.', 'content-egg'); ?></p>
|
336 |
</td>
|
337 |
</tr>
|
338 |
<tr class="form-field">
|
339 |
<th valign="top" scope="row">
|
340 |
+
<label for="dynamic_categories"><?php esc_html_e('Dynamic categories', 'content-egg'); ?></label>
|
341 |
</th>
|
342 |
<td>
|
343 |
<select id="post_status" name="item[config][dynamic_categories]">
|
344 |
+
<option value="0"<?php if ($item['config']['dynamic_categories'] == 0) echo ' selected="selected"'; ?>><?php esc_html_e('Do not create', 'content-egg'); ?></option>
|
345 |
+
<option value="1"<?php if ($item['config']['dynamic_categories'] == 1) echo ' selected="selected"'; ?>><?php esc_html_e('Create category', 'content-egg'); ?></option>
|
346 |
+
<option value="2"<?php if ($item['config']['dynamic_categories'] == 2) echo ' selected="selected"'; ?>><?php esc_html_e('Create nested categories', 'content-egg'); ?></option>
|
347 |
</select>
|
348 |
+
<p class="description"><?php esc_html_e('Create a category automatically, if the main product has a category data.', 'content-egg'); ?></p>
|
349 |
</td>
|
350 |
</tr>
|
351 |
|
352 |
<tr class="form-field">
|
353 |
<th valign="top" scope="row">
|
354 |
+
<label for="min_modules_count"><?php esc_html_e('Minimum modules required', 'content-egg'); ?></label>
|
355 |
</th>
|
356 |
<td>
|
357 |
<input id="min_modules_count" name="item[min_modules_count]" value="<?php echo esc_attr($item['min_modules_count']) ?>"
|
358 |
type="number" class="small-text">
|
359 |
+
<p class="description"><?php esc_html_e('Post will not be published if no content for such number of modules.', 'content-egg'); ?></p>
|
360 |
</td>
|
361 |
</tr>
|
362 |
|
363 |
<tr class="form-field">
|
364 |
<th valign="top" scope="row">
|
365 |
+
<label for="min_comment_count"><?php esc_html_e('Minimum reviews required', 'content-egg'); ?></label>
|
366 |
</th>
|
367 |
<td>
|
368 |
<input id="min_modules_count" name="item[config][min_comments_count]" value="<?php echo esc_attr($item['config']['min_comments_count']) ?>"
|
369 |
type="number" class="small-text">
|
370 |
+
<p class="description"><?php esc_html_e('Post will not be published if there are no user reviews. This option works only for AE modules.', 'content-egg'); ?></p>
|
371 |
</td>
|
372 |
</tr>
|
373 |
|
374 |
<tr class="form-field">
|
375 |
<th valign="top" scope="row">
|
376 |
+
<label for="autoupdate_modules"><?php esc_html_e('Update by keyword', 'content-egg'); ?></label>
|
377 |
</th>
|
378 |
<td>
|
379 |
<div class="cegg-checkboxgroup">
|
380 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
381 |
<div class="cegg-checkbox">
|
382 |
+
<label><input <?php if (in_array($module->getId(), $item['autoupdate_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[autoupdate_modules][]" /><?php echo esc_html($module->getName()); ?></label>
|
383 |
</div>
|
384 |
<?php endforeach; ?>
|
385 |
</div>
|
386 |
<p class="description">
|
387 |
+
<?php esc_html_e('For selected modules, the current keyword will be used as a keyword for autoupdate. Data of the module will be updated periodically In accordance with the configuration of the lifetime of the cache.', 'content-egg'); ?>
|
388 |
</p>
|
389 |
</td>
|
390 |
</tr>
|
391 |
<tr class="form-field">
|
392 |
<th valign="top" scope="row">
|
393 |
+
<label for="required_modules"><?php esc_html_e('Required modules', 'content-egg'); ?></label>
|
394 |
</th>
|
395 |
<td>
|
396 |
<div class="cegg-checkboxgroup">
|
397 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
398 |
<div class="cegg-checkbox">
|
399 |
+
<label><input <?php if (in_array($module->getId(), $item['required_modules'])) echo 'checked'; ?> value="<?php echo esc_attr($module->getId()); ?>" type="checkbox" name="item[required_modules][]" /><?php echo esc_html($module->getName()); ?></label>
|
400 |
</div>
|
401 |
<?php endforeach; ?>
|
402 |
</div>
|
403 |
<p class="description">
|
404 |
+
<?php esc_html_e('Post will not be publicized if no results for these modules.', 'content-egg'); ?>
|
405 |
</p>
|
406 |
</td>
|
407 |
</tr>
|
408 |
|
409 |
<tr class="form-field">
|
410 |
<th valign="top" scope="row">
|
411 |
+
<label for="main_product"><?php esc_html_e('Main product', 'content-egg'); ?></label>
|
412 |
</th>
|
413 |
<td>
|
414 |
<select id="main_product" name="item[main_product]">
|
415 |
+
<option value="min_price"<?php if ($item['main_product'] == 'min_price') echo ' selected="selected"'; ?>><?php esc_html_e('Minimum price', 'content-egg'); ?></option>
|
416 |
+
<option value="max_price"<?php if ($item['main_product'] == 'max_price') echo ' selected="selected"'; ?>><?php esc_html_e('Maximum price', 'content-egg'); ?></option>
|
417 |
+
<option value="random"<?php if ($item['main_product'] == 'random') echo ' selected="selected"'; ?>><?php esc_html_e('Random', 'content-egg'); ?></option>
|
418 |
</select>
|
419 |
<p class="description">
|
420 |
+
<?php esc_html_e('How to choose "main" product?', 'content-egg'); ?>
|
421 |
+
<?php esc_html_e('Then you can use tags:', 'content-egg'); ?> %PRODUCT.title%, %PRODUCT.price%, %PRODUCT.merchant%, %PRODUCT.domain%, %PRODUCT.manufacturer%,...
|
422 |
</p>
|
423 |
</td>
|
424 |
</tr>
|
425 |
|
426 |
<tr class="form-field">
|
427 |
<th valign="top" scope="row">
|
428 |
+
<label for="tags"><?php esc_html_e('Tags', 'content-egg'); ?></label>
|
429 |
</th>
|
430 |
<td>
|
431 |
|
432 |
<input id="tags" name="item[tags]" value="<?php echo esc_attr($item['tags']) ?>"
|
433 |
type="text" class="regular-text ltr">
|
434 |
<p class="description">
|
435 |
+
<?php esc_html_e('Comma separated list of tags.', 'content-egg'); ?>
|
436 |
+
<?php esc_html_e('Spin syntax and also all tags from title template, will also work here.', 'content-egg'); ?><br>
|
437 |
</p>
|
438 |
</td>
|
439 |
</tr>
|
440 |
|
441 |
<tr class="form-field">
|
442 |
<th valign="top" scope="row">
|
443 |
+
<label for="status"><?php esc_html_e('Product condition', 'content-egg'); ?></label>
|
444 |
</th>
|
445 |
<td>
|
446 |
<select id="product_condition" name="item[product_condition]">
|
447 |
+
<option value=""<?php if (!empty($item['product_condition'])) echo ' selected="selected"'; ?>><?php esc_attr_e('Any', 'content-egg'); ?></option>
|
448 |
+
<option value="new"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new') echo ' selected="selected"'; ?>><?php esc_attr_e('New', 'content-egg'); ?></option>
|
449 |
+
<option value="used"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'used') echo ' selected="selected"'; ?>><?php esc_attr_e('Used', 'content-egg'); ?></option>
|
450 |
+
<option value="refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'refurbished') echo ' selected="selected"'; ?>><?php esc_attr_e('Refurbished', 'content-egg'); ?></option>
|
451 |
+
<option value="new_other"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new_other') echo ' selected="selected"'; ?>><?php esc_attr_e('Open box, no signs (Ebay only)', 'content-egg'); ?></option>
|
452 |
+
<option value="seller_refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'seller_refurbished') echo ' selected="selected"'; ?>><?php esc_attr_e('Seller refurbished (Ebay only)', 'content-egg'); ?></option>
|
453 |
+
<option value="for_parts"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'for_parts') echo ' selected="selected"'; ?>><?php esc_attr_e('For parts or not working (Ebay only)', 'content-egg'); ?></option>
|
454 |
</select>
|
455 |
<p class="description">
|
456 |
+
<?php esc_html_e('This parameter is supported only by the following modules: Amazon, Ebay', 'content-egg'); ?>
|
457 |
</p>
|
458 |
|
459 |
</td>
|
461 |
|
462 |
<tr class="form-field">
|
463 |
<th valign="top" scope="row">
|
464 |
+
<label for="custom_fields"><?php esc_html_e('Add custom fields', 'content-egg'); ?></label>
|
465 |
</th>
|
466 |
<td>
|
467 |
<div style="width: 50%;float:left;">
|
468 |
<?php for ($i = 0; $i < count($item['custom_field_names']); $i++): ?>
|
469 |
+
<input type="text" value="<?php echo esc_attr($item['custom_field_names'][$i]); ?>" name="item[custom_field_names][]" placeholder="<?php esc_html_e('Custom Field', 'content-egg'); ?> <?php echo esc_html($i + 1); ?>" id="custom_fields" />
|
470 |
<?php endfor; ?>
|
471 |
</div>
|
472 |
<div style="width: 50%;float:left;">
|
473 |
<?php for ($i = 0; $i < count($item['custom_field_values']); $i++): ?>
|
474 |
+
<input value="<?php echo esc_attr($item['custom_field_values'][$i]); ?>" type="text" name="item[custom_field_values][]" placeholder="<?php esc_html_e('Value', 'content-egg'); ?> <?php echo esc_html($i + 1); ?>" />
|
475 |
<?php endfor; ?>
|
476 |
</div>
|
477 |
<p class="description">
|
478 |
+
<?php esc_html_e('Spin syntax and also all tags from title template, will also work here.', 'content-egg'); ?><br>
|
479 |
</p>
|
480 |
</td>
|
481 |
</tr>
|
application/admin/views/_metabox_results.php
CHANGED
@@ -8,14 +8,14 @@ $is_woo = (\get_post_type($GLOBALS['post']->ID) == 'product') ? true : false;
|
|
8 |
$isAffiliateParser = $module->isAffiliateParser();
|
9 |
?>
|
10 |
|
11 |
-
<div class="data_results" ng-if="models.<?php echo $module_id; ?>.added.length" id="<?php echo \esc_attr($module->getId()); ?>">
|
12 |
-
<div ui-sortable="{ 'ui-floating': true }" ng-model="models.<?php echo $module_id; ?>.added" class="row">
|
13 |
-
<div class="col-md-12 added_data" ng-repeat="data in models.<?php echo $module_id; ?>.added">
|
14 |
<div class="row" style="padding:0;margin:0;padding-bottom:10px;" id="{{'<?php echo \esc_attr($module->getId()); ?>' + '-' + data.unique_id}}">
|
15 |
<div class="col-md-1 text-center" ng-if="data.img">
|
16 |
|
17 |
<?php if ($isAffiliateParser): ?>
|
18 |
-
<img ng-src="{{data.img}}" class="img-responsive" style="max-height:75px;" ng-click="buildShortcode('<?php echo $module_id; ?>', selectedTemplate_<?php echo $module_id; ?>, selectedGroup_<?php echo $module_id; ?>, data.unique_id);" />
|
19 |
<?php else: ?>
|
20 |
<img ng-src="{{data.img}}" class="img-responsive" style="max-height:75px;" />
|
21 |
<?php endif; ?>
|
@@ -26,20 +26,20 @@ $isAffiliateParser = $module->isAffiliateParser();
|
|
26 |
</div>
|
27 |
<div ng-class="data.img ? 'col-md-9' : 'col-md-10'">
|
28 |
|
29 |
-
<input type="text" placeholder="<?php
|
30 |
<?php if ($isAffiliateParser): ?>
|
31 |
-
<input type="text" placeholder="<?php
|
32 |
-
<input type="text" placeholder="<?php
|
33 |
-
<input type="text" placeholder="<?php
|
34 |
<?php endif; ?>
|
35 |
-
<textarea type="text" placeholder="<?php
|
36 |
|
37 |
<?php if ($is_woo && $isAffiliateParser): ?>
|
38 |
-
<label><input ng-true-value="'true'" type="checkbox" ng-model="data.woo_sync" name="woo_sync" ng-change="wooRadioChange(data.unique_id, 'woo_sync')"> <?php
|
39 |
|
40 |
-
<label ng-show="data.features.length"><input ng-true-value="'true'" type="checkbox" ng-model="data.woo_attr" name="woo_attr" ng-change="wooRadioChange(data.unique_id, 'woo_attr')"> <?php
|
41 |
<?php elseif ($isAffiliateParser): ?>
|
42 |
-
<small class="text-muted" ng-show="data.features.length"><?php
|
43 |
<?php endif; ?>
|
44 |
|
45 |
<a ng-show="data.features.length" ng-init="isFeaturesCollapsed = true" ng-click="isFeaturesCollapsed = !isFeaturesCollapsed" aria-label="Edit">
|
@@ -69,24 +69,24 @@ $isAffiliateParser = $module->isAffiliateParser();
|
|
69 |
|
70 |
<div ng-show="productGroups.length" style="padding-bottom:8px;">
|
71 |
<select ng-model="data.group">
|
72 |
-
<option value="">- <?php
|
73 |
<option ng-repeat="group in productGroups" ng-value="group">{{group}}</option>
|
74 |
</select>
|
75 |
</div>
|
76 |
<div>
|
77 |
-
<span ng-show="data.domain"><img src="https://www.google.com/s2/favicons?domain={{data.domain}}"> {{data.domain}}</span><span ng-hide="data.domain"><?php
|
78 |
-
<a title="<?php esc_attr(
|
79 |
<i class="glyphicon glyphicon-share"></i>
|
80 |
</a>
|
81 |
</div>
|
82 |
<div style="padding:4px 0 8px 0;margin:0;">
|
83 |
<span class="text-muted">
|
84 |
-
<span ng-show="data.last_update"><i class="glyphicon glyphicon-time"></i> <abbr title="<?php
|
85 |
<mark ng-show="data.stock_status == -1 || data.stock_status == 1" ng-class="{'outofstock': data.stock_status == -1, 'instock': data.stock_status == 1}">{{data.stock_status| stockStatus}}</mark>
|
86 |
</span>
|
87 |
</div>
|
88 |
<?php endif; ?>
|
89 |
-
<div style="padding:0;margin:0;"><a style="color:#D03300;" ng-click="delete(data, '<?php echo $module_id; ?>')"><i class="glyphicon glyphicon-remove"></i> <?php
|
90 |
|
91 |
</div>
|
92 |
</div>
|
8 |
$isAffiliateParser = $module->isAffiliateParser();
|
9 |
?>
|
10 |
|
11 |
+
<div class="data_results" ng-if="models.<?php echo esc_attr($module_id); ?>.added.length" id="<?php echo \esc_attr($module->getId()); ?>">
|
12 |
+
<div ui-sortable="{ 'ui-floating': true }" ng-model="models.<?php echo esc_attr($module_id); ?>.added" class="row">
|
13 |
+
<div class="col-md-12 added_data" ng-repeat="data in models.<?php echo esc_attr($module_id); ?>.added">
|
14 |
<div class="row" style="padding:0;margin:0;padding-bottom:10px;" id="{{'<?php echo \esc_attr($module->getId()); ?>' + '-' + data.unique_id}}">
|
15 |
<div class="col-md-1 text-center" ng-if="data.img">
|
16 |
|
17 |
<?php if ($isAffiliateParser): ?>
|
18 |
+
<img ng-src="{{data.img}}" class="img-responsive" style="max-height:75px;" ng-click="buildShortcode('<?php echo esc_attr($module_id); ?>', selectedTemplate_<?php echo esc_attr($module_id); ?>, selectedGroup_<?php echo esc_attr($module_id); ?>, data.unique_id);" />
|
19 |
<?php else: ?>
|
20 |
<img ng-src="{{data.img}}" class="img-responsive" style="max-height:75px;" />
|
21 |
<?php endif; ?>
|
26 |
</div>
|
27 |
<div ng-class="data.img ? 'col-md-9' : 'col-md-10'">
|
28 |
|
29 |
+
<input type="text" placeholder="<?php esc_html_e('Title', 'content-egg'); ?>" ng-model="data.title" class="<?php echo esc_attr($isAffiliateParser) ? 'col-md-6' : 'col-md-12'; ?>" style="margin-bottom: 5px;">
|
30 |
<?php if ($isAffiliateParser): ?>
|
31 |
+
<input type="text" placeholder="<?php esc_html_e('Merchant name', 'content-egg'); ?>" ng-model="data.merchant" class="col-md-2" style="margin-bottom: 5px;">
|
32 |
+
<input type="text" placeholder="<?php esc_html_e('Domain', 'content-egg'); ?>" ng-model="data.domain" class="col-md-3" style="margin-bottom: 5px;">
|
33 |
+
<input type="text" placeholder="<?php esc_html_e('Price', 'content-egg'); ?>" ng-model="data.price" class="col-md-1" style="margin-bottom: 5px;">
|
34 |
<?php endif; ?>
|
35 |
+
<textarea type="text" placeholder="<?php esc_html_e('Description', 'content-egg'); ?>" rows="1" ng-model="data.description" class="col-sm-12"></textarea>
|
36 |
|
37 |
<?php if ($is_woo && $isAffiliateParser): ?>
|
38 |
+
<label><input ng-true-value="'true'" type="checkbox" ng-model="data.woo_sync" name="woo_sync" ng-change="wooRadioChange(data.unique_id, 'woo_sync')"> <?php esc_html_e('Woo synchronization', 'content-egg'); ?></label>
|
39 |
|
40 |
+
<label ng-show="data.features.length"><input ng-true-value="'true'" type="checkbox" ng-model="data.woo_attr" name="woo_attr" ng-change="wooRadioChange(data.unique_id, 'woo_attr')"> <?php esc_html_e('Woo attributes', 'content-egg'); ?> ({{data.features.length}})</label>
|
41 |
<?php elseif ($isAffiliateParser): ?>
|
42 |
+
<small class="text-muted" ng-show="data.features.length"><?php esc_html_e('Attributes:', 'content-egg'); ?> {{data.features.length}}</small>
|
43 |
<?php endif; ?>
|
44 |
|
45 |
<a ng-show="data.features.length" ng-init="isFeaturesCollapsed = true" ng-click="isFeaturesCollapsed = !isFeaturesCollapsed" aria-label="Edit">
|
69 |
|
70 |
<div ng-show="productGroups.length" style="padding-bottom:8px;">
|
71 |
<select ng-model="data.group">
|
72 |
+
<option value="">- <?php esc_html_e('Product group', 'content-egg'); ?> -</option>
|
73 |
<option ng-repeat="group in productGroups" ng-value="group">{{group}}</option>
|
74 |
</select>
|
75 |
</div>
|
76 |
<div>
|
77 |
+
<span ng-show="data.domain"><img src="https://www.google.com/s2/favicons?domain={{data.domain}}"> {{data.domain}}</span><span ng-hide="data.domain"><?php esc_html_e('Go to ', 'content-egg'); ?></span>
|
78 |
+
<a title="<?php echo esc_attr( __('Go to', 'content-egg')); ?>" href="{{data.url}}" target="_blank">
|
79 |
<i class="glyphicon glyphicon-share"></i>
|
80 |
</a>
|
81 |
</div>
|
82 |
<div style="padding:4px 0 8px 0;margin:0;">
|
83 |
<span class="text-muted">
|
84 |
+
<span ng-show="data.last_update"><i class="glyphicon glyphicon-time"></i> <abbr title="<?php esc_html_e('Last updated:', 'content-egg'); ?> {{data.last_update * 1000| date:'medium'}}">{{data.last_update * 1000| date:'shortDate'}}</abbr></span>
|
85 |
<mark ng-show="data.stock_status == -1 || data.stock_status == 1" ng-class="{'outofstock': data.stock_status == -1, 'instock': data.stock_status == 1}">{{data.stock_status| stockStatus}}</mark>
|
86 |
</span>
|
87 |
</div>
|
88 |
<?php endif; ?>
|
89 |
+
<div style="padding:0;margin:0;"><a style="color:#D03300;" ng-click="delete(data, '<?php echo esc_attr($module_id); ?>')"><i class="glyphicon glyphicon-remove"></i> <?php esc_html_e('Remove', 'content-egg'); ?></a></div>
|
90 |
|
91 |
</div>
|
92 |
</div>
|
application/admin/views/_metabox_search_results.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
-
<div class="search_results" ng-show="models.<?php echo $module_id; ?>.results.length > 0 && !models.<?php echo $module_id; ?>.processing && !models.<?php echo $module_id; ?>.error">
|
3 |
<div class="row search_results_row" ng-class="{
|
4 |
-
'result_added' : result.added}" ng-click="add(result, '<?php echo $module_id; ?>')" repeat-done ng-repeat="result in models.<?php echo $module_id; ?>.results">
|
5 |
<div class="col-md-1" ng-if="result.img">
|
6 |
<img style="max-height: 80px;" ng-src="{{result.img}}" class="img-thumbnail" />
|
7 |
</div>
|
@@ -11,8 +11,8 @@
|
|
11 |
<p>
|
12 |
<span ng-show="result.price"><b>{{result.currencyCode}}</b> <strike ng-show="result.priceOld">{{result.priceOld}}</strike> <b>{{result.price}}</b></span>
|
13 |
<span ng-show="result.domain" class="text-muted"> <img src="https://www.google.com/s2/favicons?domain={{result.domain}}"> {{result.domain}}</span>
|
14 |
-
<span ng-show="result.features.length"> <small class="text-muted"><?php
|
15 |
-
<span ng-show="result.ean"> <small class="text-muted"><?php
|
16 |
<?php if ($module_id == 'Amazon' || $module_id == 'AmazonNoApi' || $module_id == 'Ebay2'): ?>
|
17 |
<span class="text-muted">
|
18 |
<br>
|
@@ -24,7 +24,7 @@
|
|
24 |
|
25 |
</p>
|
26 |
<div ng-show="result.code">
|
27 |
-
<?php
|
28 |
- <span ng-show="result.startDate">{{result.startDate * 1000|date:'mediumDate'}} - {{result.endDate * 1000|date:'mediumDate'}}</span>
|
29 |
</div>
|
30 |
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div class="search_results" ng-show="models.<?php echo esc_attr($module_id); ?>.results.length > 0 && !models.<?php echo esc_attr($module_id); ?>.processing && !models.<?php echo esc_attr($module_id); ?>.error">
|
3 |
<div class="row search_results_row" ng-class="{
|
4 |
+
'result_added' : result.added}" ng-click="add(result, '<?php echo esc_attr($module_id); ?>')" repeat-done ng-repeat="result in models.<?php echo esc_attr($module_id); ?>.results">
|
5 |
<div class="col-md-1" ng-if="result.img">
|
6 |
<img style="max-height: 80px;" ng-src="{{result.img}}" class="img-thumbnail" />
|
7 |
</div>
|
11 |
<p>
|
12 |
<span ng-show="result.price"><b>{{result.currencyCode}}</b> <strike ng-show="result.priceOld">{{result.priceOld}}</strike> <b>{{result.price}}</b></span>
|
13 |
<span ng-show="result.domain" class="text-muted"> <img src="https://www.google.com/s2/favicons?domain={{result.domain}}"> {{result.domain}}</span>
|
14 |
+
<span ng-show="result.features.length"> <small class="text-muted"><?php esc_html_e('Attributes:', 'content-egg'); ?> {{result.features.length}}</small></span>
|
15 |
+
<span ng-show="result.ean"> <small class="text-muted"><?php esc_html_e('EAN:', 'content-egg'); ?> {{result.ean}}</small></span>
|
16 |
<?php if ($module_id == 'Amazon' || $module_id == 'AmazonNoApi' || $module_id == 'Ebay2'): ?>
|
17 |
<span class="text-muted">
|
18 |
<br>
|
24 |
|
25 |
</p>
|
26 |
<div ng-show="result.code">
|
27 |
+
<?php esc_html_e('Coupon code:', 'content-egg'); ?> <em>{{result.code}}</em>
|
28 |
- <span ng-show="result.startDate">{{result.startDate * 1000|date:'mediumDate'}} - {{result.endDate * 1000|date:'mediumDate'}}</span>
|
29 |
</div>
|
30 |
|
application/admin/views/_metabox_search_results_images.php
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
-
<div class="search_results" ng-show="models.<?php echo $module_id; ?>.results.length > 0 && !models.<?php echo $module_id; ?>.processing">
|
3 |
<div justified-gallery="{rowHeight: 160}">
|
4 |
-
<a ng-class="{
|
5 |
-
'result_added' : result.added}" ng-click="add(result, '<?php echo $module_id; ?>')" repeat-done ng-repeat="result in models.<?php echo $module_id; ?>.results">
|
6 |
<img alt="{{result.title}}" ng-src="{{result.img}}"/>
|
7 |
</a>
|
8 |
</div>
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div class="search_results" ng-show="models.<?php echo esc_attr($module_id); ?>.results.length > 0 && !models.<?php echo esc_attr($module_id); ?>.processing">
|
3 |
<div justified-gallery="{rowHeight: 160}">
|
4 |
+
<a ng-class="{'result_added' : result.added}" ng-click="add(result, '<?php echo esc_attr($module_id); ?>')" repeat-done ng-repeat="result in models.<?php echo esc_attr($module_id); ?>.results">
|
|
|
5 |
<img alt="{{result.title}}" ng-src="{{result.img}}"/>
|
6 |
</a>
|
7 |
</div>
|
application/admin/views/_promo_box.php
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
<div class="cegg-box" style="margin-top: 95px;">
|
7 |
|
8 |
<div class="cegg-box-container">
|
9 |
-
<img src="<?php echo \ContentEgg\PLUGIN_RES; ?>/img/external-importer-pro.jpg" alt="
|
10 |
<a target="_blank" href="https://www.youtube.com/watch?v=GiUZF1U3bYM" class="cegg-box-icon" title="User Profile">
|
11 |
<span class="dashicons dashicons-video-alt3"></span>
|
12 |
</a>
|
@@ -31,7 +31,7 @@
|
|
31 |
/*
|
32 |
<?php if (\ContentEgg\application\Plugin::isFree()): ?>
|
33 |
<div class="cegg-box" style="margin-top: 95px;">
|
34 |
-
<h2><?php
|
35 |
|
36 |
<a href="<?php echo ContentEgg\application\Plugin::pluginSiteUrl(); ?>">
|
37 |
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/ce_pro_header.png" class="cegg-imgcenter" />
|
@@ -41,7 +41,7 @@
|
|
41 |
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/ce_pro_coupon.png" class="cegg-imgcenter" />
|
42 |
</a>
|
43 |
|
44 |
-
<h4><?php
|
45 |
<p>
|
46 |
<a target="_blank" class="button-cegg-banner" href="<?php echo ContentEgg\application\Plugin::pluginSiteUrl(); ?>">Get it now!</a>
|
47 |
</p>
|
@@ -53,10 +53,10 @@
|
|
53 |
|
54 |
<?php /*
|
55 |
<div class="cegg-box" style="margin-top: 15px;">
|
56 |
-
<?php
|
57 |
-
<?php
|
58 |
</div>
|
59 |
-
*
|
60 |
*/
|
61 |
?>
|
62 |
<?php // endif; ?>
|
@@ -64,11 +64,11 @@
|
|
64 |
|
65 |
<?php if (\ContentEgg\application\Plugin::isEnvato()): ?>
|
66 |
<div class="cegg-box" style="margin-top: 95px;">
|
67 |
-
<h2><?php
|
68 |
-
<p><?php
|
69 |
-
<p><?php
|
70 |
<p>
|
71 |
-
<a class="button-cegg-banner" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-lic'); ?>"><?php
|
72 |
</p>
|
73 |
</div>
|
74 |
<?php endif; ?>
|
6 |
<div class="cegg-box" style="margin-top: 95px;">
|
7 |
|
8 |
<div class="cegg-box-container">
|
9 |
+
<img src="<?php echo esc_attr(\ContentEgg\PLUGIN_RES); ?>/img/external-importer-pro.jpg" alt="Logo" class="cegg-box-image">
|
10 |
<a target="_blank" href="https://www.youtube.com/watch?v=GiUZF1U3bYM" class="cegg-box-icon" title="User Profile">
|
11 |
<span class="dashicons dashicons-video-alt3"></span>
|
12 |
</a>
|
31 |
/*
|
32 |
<?php if (\ContentEgg\application\Plugin::isFree()): ?>
|
33 |
<div class="cegg-box" style="margin-top: 95px;">
|
34 |
+
<h2><?php esc_html_e('Maximum profit with minimum efforts', 'content-egg'); ?></h2>
|
35 |
|
36 |
<a href="<?php echo ContentEgg\application\Plugin::pluginSiteUrl(); ?>">
|
37 |
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/ce_pro_header.png" class="cegg-imgcenter" />
|
41 |
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/ce_pro_coupon.png" class="cegg-imgcenter" />
|
42 |
</a>
|
43 |
|
44 |
+
<h4><?php esc_html_e('Many additional modules and extended functions.', 'content-egg'); ?></h4>
|
45 |
<p>
|
46 |
<a target="_blank" class="button-cegg-banner" href="<?php echo ContentEgg\application\Plugin::pluginSiteUrl(); ?>">Get it now!</a>
|
47 |
</p>
|
53 |
|
54 |
<?php /*
|
55 |
<div class="cegg-box" style="margin-top: 15px;">
|
56 |
+
<?php esc_html_e('Thank you for using Content Egg!', 'content-egg'); ?><br>
|
57 |
+
<?php esc_html_e('If you have a moment, please leave a <a href="https://wordpress.org/support/plugin/content-egg/reviews/?rate=5#new-post>review</a>', 'content-egg'); ?>
|
58 |
</div>
|
59 |
+
*
|
60 |
*/
|
61 |
?>
|
62 |
<?php // endif; ?>
|
64 |
|
65 |
<?php if (\ContentEgg\application\Plugin::isEnvato()): ?>
|
66 |
<div class="cegg-box" style="margin-top: 95px;">
|
67 |
+
<h2><?php esc_html_e('Activate plugin', 'content-egg'); ?></h2>
|
68 |
+
<p><?php esc_html_e('In order to receive all benefits of Contennt Egg, you need to activate your copy of the plugin.', 'content-egg'); ?></p>
|
69 |
+
<p><?php esc_html_e('By activating Contennt Egg license you will unlock premium options - direct plugin updates, access to user panel and official support.', 'content-egg'); ?></p>
|
70 |
<p>
|
71 |
+
<a class="button-cegg-banner" href="<?php echo esc_url(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-lic')); ?>"><?php esc_html_e('Go to ', 'content-egg'); ?></a>
|
72 |
</p>
|
73 |
</div>
|
74 |
<?php endif; ?>
|
application/admin/views/ae_integration.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<div class="cegg-maincol">
|
4 |
<?php endif; ?>
|
5 |
<div class="wrap">
|
6 |
-
<h2><?php
|
7 |
<?php settings_errors(); ?>
|
8 |
|
9 |
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
@@ -19,16 +19,16 @@
|
|
19 |
<p>
|
20 |
You can activate AE parsers as separate modules for Content Egg.
|
21 |
</p>
|
22 |
-
<a target="_blank" href="https://ce-docs.keywordrush.com/modules/affiliate-egg-integration"><?php
|
23 |
<?php endif; ?>
|
24 |
|
25 |
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
26 |
-
<
|
27 |
-
<b><?php
|
28 |
<ol>
|
29 |
<li><?php echo sprintf(__('Install and activate <a target="_blank" href="%s">Affiliate Egg Pro</a>', 'content-egg'), 'https://www.keywordrush.com/affiliateegg'); ?></li>
|
30 |
</ol>
|
31 |
-
</
|
32 |
<?php else: ?>
|
33 |
<form action="options.php" method="POST">
|
34 |
<?php settings_fields($page_slug); ?>
|
3 |
<div class="cegg-maincol">
|
4 |
<?php endif; ?>
|
5 |
<div class="wrap">
|
6 |
+
<h2><?php esc_html_e('Integration with Affiliate Egg', 'content-egg') ?></h2>
|
7 |
<?php settings_errors(); ?>
|
8 |
|
9 |
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
19 |
<p>
|
20 |
You can activate AE parsers as separate modules for Content Egg.
|
21 |
</p>
|
22 |
+
<a target="_blank" href="https://ce-docs.keywordrush.com/modules/affiliate-egg-integration"><?php esc_html_e('Read more...', 'content-egg'); ?></a>
|
23 |
<?php endif; ?>
|
24 |
|
25 |
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
26 |
+
<div>
|
27 |
+
<b><?php esc_html_e('Follow these steps to get started', 'content-egg'); ?>:</b>
|
28 |
<ol>
|
29 |
<li><?php echo sprintf(__('Install and activate <a target="_blank" href="%s">Affiliate Egg Pro</a>', 'content-egg'), 'https://www.keywordrush.com/affiliateegg'); ?></li>
|
30 |
</ol>
|
31 |
+
</div>
|
32 |
<?php else: ?>
|
33 |
<form action="options.php" method="POST">
|
34 |
<?php settings_fields($page_slug); ?>
|
application/admin/views/autoblog_edit.php
CHANGED
@@ -5,31 +5,31 @@
|
|
5 |
<div class="wrap">
|
6 |
<h2>
|
7 |
<?php if ($item['id']): ?>
|
8 |
-
<?php
|
9 |
<?php else: ?>
|
10 |
-
<?php
|
11 |
<?php if ($batch): ?>
|
12 |
-
- <?php
|
13 |
<?php endif; ?>
|
14 |
<?php endif; ?>
|
15 |
<?php if (!$batch && !$item['id']): ?>
|
16 |
-
<a class="add-new-h2 button-primary" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit--batch'); ?>"><?php
|
17 |
<?php endif; ?>
|
18 |
-
<a class="add-new-h2" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog'); ?>"><?php
|
19 |
</h2>
|
20 |
|
21 |
<?php if (!empty($notice)): ?>
|
22 |
-
<div id="notice" class="error"><p><?php echo $notice ?></p></div>
|
23 |
<?php endif; ?>
|
24 |
<?php if (!empty($message)): ?>
|
25 |
-
<div id="message" class="updated"><p><?php echo $message ?></p></div>
|
26 |
<?php endif; ?>
|
27 |
|
28 |
<div id="poststuff">
|
29 |
<p>
|
30 |
</p>
|
31 |
</div>
|
32 |
-
<form action="<?php echo add_query_arg('noheader', 'true'); ?>" id="form" method="POST"<?php if ($batch) echo ' enctype="multipart/form-data" accept-charset="utf-8"'; ?>>
|
33 |
<input type="hidden" name="nonce" value="<?php echo \esc_attr($nonce); ?>"/>
|
34 |
<input type="hidden" name="item[id]" value="<?php echo \esc_attr($item['id']); ?>"/>
|
35 |
<div class="metabox-holder" id="poststuff">
|
@@ -37,9 +37,9 @@
|
|
37 |
<div id="post-body-content">
|
38 |
<?php $item['batch'] = $batch; ?>
|
39 |
<?php do_meta_boxes('autoblog_create', 'normal', $item); ?>
|
40 |
-
<input type="submit" value="<?php
|
41 |
|
42 |
-
<?php if ($batch): ?><em><?php
|
43 |
|
44 |
</div>
|
45 |
</div>
|
5 |
<div class="wrap">
|
6 |
<h2>
|
7 |
<?php if ($item['id']): ?>
|
8 |
+
<?php esc_html_e('Edit autoblogging', 'content-egg'); ?>
|
9 |
<?php else: ?>
|
10 |
+
<?php esc_html_e('Add autoblogging', 'content-egg'); ?>
|
11 |
<?php if ($batch): ?>
|
12 |
+
- <?php esc_html_e('bulk adding', 'content-egg'); ?>
|
13 |
<?php endif; ?>
|
14 |
<?php endif; ?>
|
15 |
<?php if (!$batch && !$item['id']): ?>
|
16 |
+
<a class="add-new-h2 button-primary" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit--batch')); ?>"><?php esc_html_e('Bulk adding', 'content-egg'); ?></a>
|
17 |
<?php endif; ?>
|
18 |
+
<a class="add-new-h2" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-autoblog')); ?>"><?php esc_html_e('Back to list', 'content-egg'); ?></a>
|
19 |
</h2>
|
20 |
|
21 |
<?php if (!empty($notice)): ?>
|
22 |
+
<div id="notice" class="error"><p><?php echo esc_html($notice) ?></p></div>
|
23 |
<?php endif; ?>
|
24 |
<?php if (!empty($message)): ?>
|
25 |
+
<div id="message" class="updated"><p><?php echo esc_html($message) ?></p></div>
|
26 |
<?php endif; ?>
|
27 |
|
28 |
<div id="poststuff">
|
29 |
<p>
|
30 |
</p>
|
31 |
</div>
|
32 |
+
<form action="<?php echo esc_url_raw(add_query_arg('noheader', 'true')); ?>" id="form" method="POST"<?php if ($batch) echo ' enctype="multipart/form-data" accept-charset="utf-8"'; ?>>
|
33 |
<input type="hidden" name="nonce" value="<?php echo \esc_attr($nonce); ?>"/>
|
34 |
<input type="hidden" name="item[id]" value="<?php echo \esc_attr($item['id']); ?>"/>
|
35 |
<div class="metabox-holder" id="poststuff">
|
37 |
<div id="post-body-content">
|
38 |
<?php $item['batch'] = $batch; ?>
|
39 |
<?php do_meta_boxes('autoblog_create', 'normal', $item); ?>
|
40 |
+
<input type="submit" value="<?php esc_html_e('Save', 'content-egg'); ?>" id="autoblog_submit" class="button-primary" name="submit">
|
41 |
|
42 |
+
<?php if ($batch): ?><em><?php esc_html_e('Don\'t close page until process finishes. Be patient, can have some time.', 'content-egg'); ?></em><?php endif; ?>
|
43 |
|
44 |
</div>
|
45 |
</div>
|
application/admin/views/autoblog_index.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
-
<h2><?php
|
4 |
<p>
|
5 |
-
<img src="<?php echo \ContentEgg\PLUGIN_RES; ?>/img/egg_waiting.gif" />
|
6 |
</p>
|
7 |
</div>
|
8 |
<script type="text/javascript">
|
@@ -35,14 +35,13 @@ if ($table->current_action() == 'run')
|
|
35 |
<div class="wrap">
|
36 |
|
37 |
<h2>
|
38 |
-
<?php
|
39 |
-
<a class="add-new-h2" href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit'); ?>"><?php
|
40 |
</h2>
|
41 |
-
<?php echo $message; ?>
|
42 |
|
43 |
<div id="poststuff">
|
44 |
<p>
|
45 |
-
<?php _e('You can create automatic creating of posts with autoblogging', 'content-egg'); ?>
|
46 |
</p>
|
47 |
</div>
|
48 |
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
+
<h2><?php esc_html_e('Working... Please wait...', 'content-egg'); ?></h2>
|
4 |
<p>
|
5 |
+
<img src="<?php echo esc_url_raw(\ContentEgg\PLUGIN_RES); ?>/img/egg_waiting.gif" />
|
6 |
</p>
|
7 |
</div>
|
8 |
<script type="text/javascript">
|
35 |
<div class="wrap">
|
36 |
|
37 |
<h2>
|
38 |
+
<?php esc_html_e('Autoblogging', 'content-egg'); ?>
|
39 |
+
<a class="add-new-h2" href="<?php echo esc_url_raw(get_admin_url(get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit')); ?>"><?php esc_html_e('Add autoblogging', 'content-egg'); ?></a>
|
40 |
</h2>
|
41 |
+
<?php echo wp_kses_post($message); ?>
|
42 |
|
43 |
<div id="poststuff">
|
44 |
<p>
|
|
|
45 |
</p>
|
46 |
</div>
|
47 |
|
application/admin/views/import_export.php
CHANGED
@@ -4,14 +4,14 @@
|
|
4 |
<?php endif; ?>
|
5 |
<div class="wrap">
|
6 |
<h2>
|
7 |
-
<?php
|
8 |
</h2>
|
9 |
|
10 |
<?php if (!empty($notice)): ?>
|
11 |
-
<div id="notice" class="error"><p><?php echo $notice ?></p></div>
|
12 |
<?php endif; ?>
|
13 |
<?php if (!empty($message)): ?>
|
14 |
-
<div id="message" class="updated"><p><?php echo $message ?></p></div>
|
15 |
<?php endif; ?>
|
16 |
|
17 |
<div id="poststuff">
|
@@ -19,18 +19,18 @@
|
|
19 |
</p>
|
20 |
</div>
|
21 |
|
22 |
-
<h3><?php
|
23 |
-
<p><?php
|
24 |
<textarea rows="8" cols="70" onclick="this.focus();
|
25 |
this.select()" readonly="readonly"><?php echo esc_html($export_str); ?></textarea>
|
26 |
|
27 |
<br><br>
|
28 |
-
<h3><?php
|
29 |
-
<p><?php
|
30 |
<form id="form" method="POST">
|
31 |
<input type="hidden" name="nonce" value="<?php echo \esc_attr($nonce); ?>"/>
|
32 |
<textarea name="import_str" rows="8" cols="70"></textarea>
|
33 |
-
<p><input type="submit" value="<?php
|
34 |
</form>
|
35 |
</div>
|
36 |
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
4 |
<?php endif; ?>
|
5 |
<div class="wrap">
|
6 |
<h2>
|
7 |
+
<?php esc_html_e('Export/Import of settings', 'content-egg'); ?>
|
8 |
</h2>
|
9 |
|
10 |
<?php if (!empty($notice)): ?>
|
11 |
+
<div id="notice" class="error"><p><?php echo esc_html($notice); ?></p></div>
|
12 |
<?php endif; ?>
|
13 |
<?php if (!empty($message)): ?>
|
14 |
+
<div id="message" class="updated"><p><?php echo esc_html($message); ?></p></div>
|
15 |
<?php endif; ?>
|
16 |
|
17 |
<div id="poststuff">
|
19 |
</p>
|
20 |
</div>
|
21 |
|
22 |
+
<h3><?php esc_html_e('Save settings', 'content-egg'); ?></h3>
|
23 |
+
<p><?php esc_html_e('To import all settings, copy field value (Ctrl + C on Win) and make import on new site', 'content-egg'); ?></p>
|
24 |
<textarea rows="8" cols="70" onclick="this.focus();
|
25 |
this.select()" readonly="readonly"><?php echo esc_html($export_str); ?></textarea>
|
26 |
|
27 |
<br><br>
|
28 |
+
<h3><?php esc_html_e('Load settings', 'content-egg'); ?></h3>
|
29 |
+
<p><?php esc_html_e('Copy settings from another site and click on "Import".', 'content-egg'); ?></p>
|
30 |
<form id="form" method="POST">
|
31 |
<input type="hidden" name="nonce" value="<?php echo \esc_attr($nonce); ?>"/>
|
32 |
<textarea name="import_str" rows="8" cols="70"></textarea>
|
33 |
+
<p><input type="submit" value="<?php esc_html_e('Import', 'content-egg'); ?>" id="config_submit" class="button-primary" name="submit"></p>
|
34 |
</form>
|
35 |
</div>
|
36 |
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
application/admin/views/metabox_general.php
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<?php \wp_nonce_field('contentegg_metabox', 'contentegg_nonce'); ?>
|
3 |
|
4 |
-
|
5 |
<div class="row">
|
6 |
<div class="col-sm-9 col-lg-5">
|
7 |
|
8 |
<div class="input-group">
|
9 |
-
<input ng-disabled="processCounter" type="text" ng-model="global_keywords" select-on-click on-enter="global_findAll()" class="form-control" placeholder="<?php
|
10 |
<div class="input-group-btn">
|
11 |
<button ng-disabled='processCounter || !global_keywords' ng-click="global_findAll()" type="button" class="btn btn-info" aria-label="Find ">
|
12 |
-
<?php
|
13 |
</button>
|
14 |
-
<button ng-show='!processCounter && global_isSearchResults()' ng-click="global_addAll()" type="button" class="btn btn-default"><?php
|
15 |
-
<button ng-show='global_isAddedResults()' ng-click="global_deleteAll()" ng-confirm-click="<?php
|
16 |
|
17 |
</div>
|
18 |
</div>
|
@@ -21,7 +20,7 @@
|
|
21 |
|
22 |
<div class="col-sm-3 col-lg-2">
|
23 |
<div class="input-group">
|
24 |
-
<input type="text" ng-model="newProductGroup" select-on-click on-enter="addProductGroup()" class="form-control input-sm" placeholder="<?php
|
25 |
<div class="input-group-btn">
|
26 |
<button ng-disabled="!newProductGroup" ng-click="addProductGroup()" type="button" class="btn btn-success btn-sm" aria-label="Add">
|
27 |
+
|
@@ -38,13 +37,13 @@
|
|
38 |
$templates = $tpl_manager->getTemplatesList(true);
|
39 |
?>
|
40 |
<input class="input-sm col-sm-6 col-lg-5 col-lg-4 shortcode-input" ng-model="blockShortcode" select-on-click readonly type="text" />
|
41 |
-
<select class="input-sm col-sm-3 col-lg-3" ng-init="blockShortcodeBuillder.template = '<?php echo key($templates); ?>'; buildBlockShortcode();" ng-model="blockShortcodeBuillder.template" ng-change="buildBlockShortcode();">
|
42 |
<?php foreach ($templates as $id => $name): ?>
|
43 |
<option value="<?php echo esc_attr($id); ?>"><?php echo esc_html($name); ?></option>
|
44 |
<?php endforeach; ?>
|
45 |
</select>
|
46 |
<select ng-show="productGroups.length" class="input-sm col-sm-2" ng-model="blockShortcodeBuillder.group" ng-change="buildBlockShortcode();">
|
47 |
-
<option value="">- <?php
|
48 |
<option ng-repeat="group in productGroups" value="{{group}}">{{group}}</option>
|
49 |
</select>
|
50 |
<input class="input-sm col-sm-1" ng-model="blockShortcodeBuillder.next" ng-change="buildBlockShortcode();" placeholder="Next" type="number" step="1" />
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<?php \wp_nonce_field('contentegg_metabox', 'contentegg_nonce'); ?>
|
3 |
|
|
|
4 |
<div class="row">
|
5 |
<div class="col-sm-9 col-lg-5">
|
6 |
|
7 |
<div class="input-group">
|
8 |
+
<input ng-disabled="processCounter" type="text" ng-model="global_keywords" select-on-click on-enter="global_findAll()" class="form-control" placeholder="<?php esc_html_e('Keyword to search', 'content-egg'); ?>" aria-label="<?php esc_html_e('Keyword to search', 'content-egg'); ?>">
|
9 |
<div class="input-group-btn">
|
10 |
<button ng-disabled='processCounter || !global_keywords' ng-click="global_findAll()" type="button" class="btn btn-info" aria-label="Find ">
|
11 |
+
<?php esc_html_e('Find all', 'content-egg'); ?>
|
12 |
</button>
|
13 |
+
<button ng-show='!processCounter && global_isSearchResults()' ng-click="global_addAll()" type="button" class="btn btn-default"><?php esc_html_e('Add all', 'content-egg'); ?></button>
|
14 |
+
<button ng-show='global_isAddedResults()' ng-click="global_deleteAll()" ng-confirm-click="<?php esc_html_e('Are you sure you want to delete the results of all modules?', 'content-egg'); ?>" type="button" class="btn btn-default"><?php esc_html_e('Remove all', 'content-egg'); ?></button>
|
15 |
|
16 |
</div>
|
17 |
</div>
|
20 |
|
21 |
<div class="col-sm-3 col-lg-2">
|
22 |
<div class="input-group">
|
23 |
+
<input type="text" ng-model="newProductGroup" select-on-click on-enter="addProductGroup()" class="form-control input-sm" placeholder="<?php esc_html_e('Add product group', 'content-egg'); ?>" aria-label="<?php esc_html_e('Add product group', 'content-egg'); ?>">
|
24 |
<div class="input-group-btn">
|
25 |
<button ng-disabled="!newProductGroup" ng-click="addProductGroup()" type="button" class="btn btn-success btn-sm" aria-label="Add">
|
26 |
+
|
37 |
$templates = $tpl_manager->getTemplatesList(true);
|
38 |
?>
|
39 |
<input class="input-sm col-sm-6 col-lg-5 col-lg-4 shortcode-input" ng-model="blockShortcode" select-on-click readonly type="text" />
|
40 |
+
<select class="input-sm col-sm-3 col-lg-3" ng-init="blockShortcodeBuillder.template = '<?php echo esc_attr(key($templates)); ?>'; buildBlockShortcode();" ng-model="blockShortcodeBuillder.template" ng-change="buildBlockShortcode();">
|
41 |
<?php foreach ($templates as $id => $name): ?>
|
42 |
<option value="<?php echo esc_attr($id); ?>"><?php echo esc_html($name); ?></option>
|
43 |
<?php endforeach; ?>
|
44 |
</select>
|
45 |
<select ng-show="productGroups.length" class="input-sm col-sm-2" ng-model="blockShortcodeBuillder.group" ng-change="buildBlockShortcode();">
|
46 |
+
<option value="">- <?php esc_html_e('Groups', 'content-egg'); ?> ({{productGroups.length}}) -</option>
|
47 |
<option ng-repeat="group in productGroups" value="{{group}}">{{group}}</option>
|
48 |
</select>
|
49 |
<input class="input-sm col-sm-1" ng-model="blockShortcodeBuillder.next" ng-change="buildBlockShortcode();" placeholder="Next" type="number" step="1" />
|
application/admin/views/metabox_module.php
CHANGED
@@ -1,104 +1,104 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
-
<div ng-controllerTMP="<?php echo $module_id; ?>Controller" ng-init="indextab_<?php echo $module_id; ?> = activeResultTabs.<?php echo $module_id; ?> ? 0 : 1">
|
3 |
-
<input type="hidden" name="cegg_data[<?php echo $module_id; ?>]" ng-value="models.<?php echo $module_id; ?>.added | json" />
|
4 |
-
<input type="hidden" name="cegg_updateKeywords[<?php echo $module_id; ?>]" ng-value="updateKeywords.<?php echo $module_id; ?>" />
|
5 |
-
<input type="hidden" name="cegg_updateParams[<?php echo $module_id; ?>]" ng-value="updateParams.<?php echo $module_id; ?>| json" />
|
6 |
|
7 |
-
<uib-tabset active=
|
8 |
<uib-tab>
|
9 |
<uib-tab-heading>
|
10 |
-
<strong><?php echo $module->getName(); ?></strong>
|
11 |
-
<span ng-show="models.<?php echo $module_id; ?>.added.length" class="label" ng-class="{
|
12 |
-
'label-danger':models.<?php echo $module_id; ?>.added_changed, 'label-default':!models.<?php echo $module_id; ?>.added_changed}">{{models.<?php echo $module_id; ?>.added.length}}</span>
|
13 |
</uib-tab-heading>
|
14 |
|
15 |
<div class="data_panel">
|
16 |
|
17 |
<div clas="row">
|
18 |
<div class="col-md-12 col-lg-6">
|
19 |
-
<input class="input-sm col-sm-6 shortcode-input" ng-model="shortcodes.<?php
|
20 |
<?php
|
21 |
$tpl_manager = ContentEgg\application\components\ModuleTemplateManager::getInstance($module_id);
|
22 |
$templates = $tpl_manager->getTemplatesList(true);
|
23 |
?>
|
24 |
<?php if ($templates): ?>
|
25 |
-
<select class="input-sm col-sm-4" ng-model="selectedTemplate_<?php
|
26 |
-
<option value="">← <?php
|
27 |
<?php foreach ($templates as $id => $name): ?>
|
28 |
<option value="<?php echo esc_attr($id); ?>"><?php echo esc_html($name); ?></option>
|
29 |
<?php endforeach; ?>
|
30 |
-
</select>
|
31 |
<?php endif; ?>
|
32 |
-
<select ng-show="productGroups.length" class="input-sm col-sm-2" ng-model="selectedGroup_<?php
|
33 |
-
<option value="">← <?php
|
34 |
-
<option ng-repeat="group in productGroups" value="{{group}}">{{group}}</option>
|
35 |
</select>
|
36 |
|
37 |
</div>
|
38 |
|
39 |
<div class="col-md-11 col-lg-5">
|
40 |
<?php if ($module->isAffiliateParser()): ?>
|
41 |
-
<input class="input-sm col-md-4 col-sm-12" id="updateKeyword_<?php
|
42 |
<?php $module->renderUpdatePanel(); ?>
|
43 |
<?php endif; ?>
|
44 |
</div>
|
45 |
<div class="col-md-1 col-lg-1 text-right">
|
46 |
-
<a class='btn btn-default btn-sm' ng-click="deleteAll('<?php
|
47 |
</div>
|
48 |
</div>
|
49 |
</div>
|
50 |
<div class="clearfix"></div>
|
51 |
-
<p ng-show="!models.<?php
|
52 |
<?php $module->renderResults(); ?>
|
53 |
</uib-tab>
|
54 |
|
55 |
-
<uib-tab heading="<?php
|
56 |
<div class="search_panel">
|
57 |
<div clas="row">
|
58 |
<div class="col-md-11 col-lg-5">
|
59 |
|
60 |
-
<div class="input-group" ng-show="!models.<?php
|
61 |
<?php $module->isUrlSearchAllowed() ? $placeholder = __('Keyword or Product URL', 'content-egg') : $placeholder = __('Keyword to search', 'content-egg'); ?>
|
62 |
-
<input type="text" select-on-click ng-model="keywords.<?php
|
63 |
<div class="input-group-btn">
|
64 |
-
<button title="<?php echo esc_html(__('Find', 'content-egg')); ?>" ng-disabled="!keywords.<?php
|
65 |
<span class="glyphicon glyphicon-search"></span>
|
66 |
</button>
|
67 |
<?php if ($module->isAffiliateParser()): ?>
|
68 |
-
<button title="<?php echo esc_html(__('Add keyword for autoupdate', 'content-egg')); ?>" ng-disabled="!keywords.<?php
|
69 |
<span class="glyphicon glyphicon-save"></span>
|
70 |
</button>
|
71 |
-
<?php endif; ?>
|
72 |
</div>
|
73 |
</div>
|
74 |
|
75 |
<?php if ($module->isFeedModule() && $module->isImportTime()): ?>
|
76 |
-
<img ng-show="models.<?php
|
77 |
-
<span ng-show="models.<?php
|
78 |
-
<?php
|
79 |
<?php //_e('It may take a minute or two.', 'content-egg');?>
|
80 |
</span>
|
81 |
<?php else: ?>
|
82 |
-
<img ng-show="models.<?php
|
83 |
<?php endif; ?>
|
84 |
|
85 |
</div>
|
86 |
<div class="col-md-12 col-lg-6">
|
87 |
-
<div ng-show="!models.<?php
|
88 |
<?php $module->renderSearchPanel(); ?>
|
89 |
</div>
|
90 |
</div>
|
91 |
<div class="col-sm-1 text-right">
|
92 |
-
<a class='btn btn-default btn-sm' ng-click="addAll('<?php
|
93 |
</div>
|
94 |
</div>
|
95 |
</div>
|
96 |
-
<div class="clearfix"></div>
|
97 |
|
98 |
<?php $module->renderSearchResults(); ?>
|
99 |
|
100 |
-
<p ng-show="!models.<?php
|
101 |
-
<p ng-show="models.<?php
|
102 |
</uib-tab>
|
103 |
</uib-tabset>
|
104 |
<div class="row">
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div ng-controllerTMP="<?php echo esc_attr($module_id); ?>Controller" ng-init="indextab_<?php echo esc_attr($module_id); ?> = activeResultTabs.<?php echo esc_attr($module_id); ?> ? 0 : 1">
|
3 |
+
<input type="hidden" name="cegg_data[<?php echo esc_attr($module_id); ?>]" ng-value="models.<?php echo esc_attr($module_id); ?>.added | json" />
|
4 |
+
<input type="hidden" name="cegg_updateKeywords[<?php echo esc_attr($module_id); ?>]" ng-value="updateKeywords.<?php echo esc_attr($module_id); ?>" />
|
5 |
+
<input type="hidden" name="cegg_updateParams[<?php echo esc_attr($module_id); ?>]" ng-value="updateParams.<?php echo esc_attr($module_id); ?>| json" />
|
6 |
|
7 |
+
<uib-tabset active="indextab_<?php echo esc_attr($module_id); ?>">
|
8 |
<uib-tab>
|
9 |
<uib-tab-heading>
|
10 |
+
<strong><?php echo esc_html($module->getName()); ?></strong>
|
11 |
+
<span ng-show="models.<?php echo esc_attr($module_id); ?>.added.length" class="label" ng-class="{
|
12 |
+
'label-danger':models.<?php echo esc_attr($module_id); ?>.added_changed, 'label-default':!models.<?php echo esc_attr($module_id); ?>.added_changed}">{{models.<?php echo esc_attr($module_id); ?>.added.length}}</span>
|
13 |
</uib-tab-heading>
|
14 |
|
15 |
<div class="data_panel">
|
16 |
|
17 |
<div clas="row">
|
18 |
<div class="col-md-12 col-lg-6">
|
19 |
+
<input class="input-sm col-sm-6 shortcode-input" ng-model="shortcodes.<?php echo esc_attr($module_id); ?>" select-on-click readonly type="text" />
|
20 |
<?php
|
21 |
$tpl_manager = ContentEgg\application\components\ModuleTemplateManager::getInstance($module_id);
|
22 |
$templates = $tpl_manager->getTemplatesList(true);
|
23 |
?>
|
24 |
<?php if ($templates): ?>
|
25 |
+
<select class="input-sm col-sm-4" ng-model="selectedTemplate_<?php echo esc_attr($module_id); ?>" ng-change="buildShortcode('<?php echo esc_attr($module_id); ?>', selectedTemplate_<?php echo esc_attr($module_id); ?>, selectedGroup_<?php echo esc_attr($module_id); ?>);">
|
26 |
+
<option value="">← <?php esc_html_e('Shortcode Template', 'content-egg'); ?></option>
|
27 |
<?php foreach ($templates as $id => $name): ?>
|
28 |
<option value="<?php echo esc_attr($id); ?>"><?php echo esc_html($name); ?></option>
|
29 |
<?php endforeach; ?>
|
30 |
+
</select>
|
31 |
<?php endif; ?>
|
32 |
+
<select ng-show="productGroups.length" class="input-sm col-sm-2" ng-model="selectedGroup_<?php echo esc_attr($module_id); ?>" ng-change="buildShortcode('<?php echo esc_attr($module_id); ?>', selectedTemplate_<?php echo esc_attr($module_id); ?>, selectedGroup_<?php echo esc_attr($module_id); ?>);">
|
33 |
+
<option value="">← <?php esc_html_e('Group', 'content-egg'); ?></option>
|
34 |
+
<option ng-repeat="group in productGroups" value="{{group}}">{{group}}</option>
|
35 |
</select>
|
36 |
|
37 |
</div>
|
38 |
|
39 |
<div class="col-md-11 col-lg-5">
|
40 |
<?php if ($module->isAffiliateParser()): ?>
|
41 |
+
<input class="input-sm col-md-4 col-sm-12" id="updateKeyword_<?php echo esc_attr($module_id); ?>" type="text" ng-model="updateKeywords.<?php echo esc_attr($module_id); ?>" placeholder="<?php esc_html_e('Keyword for update', 'content-egg'); ?>" title="<?php esc_html_e('Keyword for automatic update', 'content-egg'); ?>" />
|
42 |
<?php $module->renderUpdatePanel(); ?>
|
43 |
<?php endif; ?>
|
44 |
</div>
|
45 |
<div class="col-md-1 col-lg-1 text-right">
|
46 |
+
<a class='btn btn-default btn-sm' ng-click="deleteAll('<?php echo esc_attr($module_id); ?>')" ng-confirm-click="<?php esc_html_e('Are you sure you want to delete all results?', 'content-egg'); ?>" ng-show='models.<?php echo esc_attr($module_id); ?>.added.length'><?php esc_html_e('Remove all', 'content-egg'); ?></a>
|
47 |
</div>
|
48 |
</div>
|
49 |
</div>
|
50 |
<div class="clearfix"></div>
|
51 |
+
<p ng-show="!models.<?php echo esc_attr($module_id); ?>.added.length && !models.<?php echo esc_attr($module_id); ?>.processing" class="bg-warning text-center"><br><?php esc_html_e('No data found...', 'content-egg'); ?><br><br></p>
|
52 |
<?php $module->renderResults(); ?>
|
53 |
</uib-tab>
|
54 |
|
55 |
+
<uib-tab heading="<?php esc_html_e('Search', 'content-egg'); ?>">
|
56 |
<div class="search_panel">
|
57 |
<div clas="row">
|
58 |
<div class="col-md-11 col-lg-5">
|
59 |
|
60 |
+
<div class="input-group" ng-show="!models.<?php echo esc_attr($module_id); ?>.processing">
|
61 |
<?php $module->isUrlSearchAllowed() ? $placeholder = __('Keyword or Product URL', 'content-egg') : $placeholder = __('Keyword to search', 'content-egg'); ?>
|
62 |
+
<input type="text" select-on-click ng-model="keywords.<?php echo esc_attr($module_id); ?>" on-enter="find('<?php echo esc_attr($module_id); ?>')" class="form-control" placeholder="<?php echo \esc_attr($placeholder); ?>" />
|
63 |
<div class="input-group-btn">
|
64 |
+
<button title="<?php echo esc_html(__('Find', 'content-egg')); ?>" ng-disabled="!keywords.<?php echo esc_attr($module_id); ?>" ng-click="find('<?php echo esc_attr($module_id); ?>')" type="button" class="btn btn-info" aria-label="Find">
|
65 |
<span class="glyphicon glyphicon-search"></span>
|
66 |
</button>
|
67 |
<?php if ($module->isAffiliateParser()): ?>
|
68 |
+
<button title="<?php echo esc_html(__('Add keyword for autoupdate', 'content-egg')); ?>" ng-disabled="!keywords.<?php echo esc_attr($module_id); ?>" ng-click="setUpdateKeyword('<?php echo esc_attr($module_id); ?>')" type="button" class="btn btn-info">
|
69 |
<span class="glyphicon glyphicon-save"></span>
|
70 |
</button>
|
71 |
+
<?php endif; ?>
|
72 |
</div>
|
73 |
</div>
|
74 |
|
75 |
<?php if ($module->isFeedModule() && $module->isImportTime()): ?>
|
76 |
+
<img ng-show="models.<?php echo esc_attr($module_id); ?>.processing" src="<?php echo esc_url(\ContentEgg\PLUGIN_RES) . '/img/importing.gif' ?>" />
|
77 |
+
<span ng-show="models.<?php echo esc_attr($module_id); ?>.processing">
|
78 |
+
<?php esc_html_e('Loading data feed... Please wait...', 'content-egg'); ?>
|
79 |
<?php //_e('It may take a minute or two.', 'content-egg');?>
|
80 |
</span>
|
81 |
<?php else: ?>
|
82 |
+
<img ng-show="models.<?php echo esc_attr($module_id); ?>.processing" src="<?php echo esc_url(\ContentEgg\PLUGIN_RES) . '/img/loader.gif' ?>" />
|
83 |
<?php endif; ?>
|
84 |
|
85 |
</div>
|
86 |
<div class="col-md-12 col-lg-6">
|
87 |
+
<div ng-show="!models.<?php echo esc_attr($module_id); ?>.processing">
|
88 |
<?php $module->renderSearchPanel(); ?>
|
89 |
</div>
|
90 |
</div>
|
91 |
<div class="col-sm-1 text-right">
|
92 |
+
<a class='btn btn-default btn-sm' ng-click="addAll('<?php echo esc_attr($module_id); ?>')" ng-show='models.<?php echo esc_attr($module_id); ?>.results.length > 0 && !models.<?php echo esc_attr($module_id); ?>.processing'><?php esc_html_e('Add all', 'content-egg'); ?></a>
|
93 |
</div>
|
94 |
</div>
|
95 |
</div>
|
96 |
+
<div class="clearfix"></div>
|
97 |
|
98 |
<?php $module->renderSearchResults(); ?>
|
99 |
|
100 |
+
<p ng-show="!models.<?php echo esc_attr($module_id); ?>.processing && models.<?php echo esc_attr($module_id); ?>.loaded && models.<?php echo esc_attr($module_id); ?>.results.length == 0" class="bg-warning text-center"><br><?php esc_html_e('Not found...', 'content-egg'); ?><br><br></p>
|
101 |
+
<p ng-show="models.<?php echo esc_attr($module_id); ?>.error && !models.<?php echo esc_attr($module_id); ?>.processing" class="bg-danger text-center"><br><?php esc_html_e('Error:', 'content-egg'); ?> {{models.<?php echo esc_attr($module_id); ?>.error}}<br><br></p>
|
102 |
</uib-tab>
|
103 |
</uib-tabset>
|
104 |
<div class="row">
|
application/admin/views/module_index.php
CHANGED
@@ -9,11 +9,11 @@ function _cegg_print_module_item(array $modules)
|
|
9 |
echo '<a href="?page=' . \esc_attr($module->getConfigInstance()->page_slug()) . '" class = "list-group-item">';
|
10 |
echo \esc_html($module->getName());
|
11 |
if ($module->isActive() && !$module->isDeprecated())
|
12 |
-
echo '<span class="label label-success">' . __('Active', 'content-egg') . '</span>';
|
13 |
if ($module->isDeprecated())
|
14 |
-
echo '<span class="label label-warning">' . __('Deprecated', 'content-egg') . '</span>';
|
15 |
if ($module->isNew() && !$module->isFeedParser())
|
16 |
-
echo '<span class="label label-info">' . __('New', 'content-egg') . '</span>';
|
17 |
echo '</a>';
|
18 |
}
|
19 |
}
|
@@ -27,19 +27,19 @@ function _cegg_print_module_item(array $modules)
|
|
27 |
<div class="wrap">
|
28 |
|
29 |
<h2>
|
30 |
-
<?php
|
31 |
-
<span class="egg-label egg-label-pro">pro <small>v<?php echo \ContentEgg\application\Plugin::version(); ?></small></span>
|
32 |
</h2>
|
33 |
|
34 |
|
35 |
<h2 class="nav-tab-wrapper">
|
36 |
-
<a href="?page=content-egg-modules" class="nav-tab<?php if (!empty($_GET['page']) && $_GET['page'] == 'content-egg-modules') echo ' nav-tab-active'; ?>">
|
37 |
<span class="dashicons dashicons-menu-alt3"></span>
|
38 |
</a>
|
39 |
<?php foreach (ContentEgg\application\components\ModuleManager::getInstance()->getConfigurableModules(true) as $m): ?>
|
40 |
<?php if ($m->isDeprecated() && !$m->isActive()) continue; ?>
|
41 |
<?php $c = $m->getConfigInstance(); ?>
|
42 |
-
<a href="?page=<?php echo \esc_attr($c->page_slug()); ?>" class="nav-tab<?php if (!empty($_GET['page']) && $_GET['page'] == $c->page_slug()) echo ' nav-tab-active'; ?>">
|
43 |
<span<?php if ($m->isDeprecated()): ?> style="color: darkgray;"<?php endif; ?>>
|
44 |
<?php echo \esc_html($m->getName()); ?>
|
45 |
</span>
|
@@ -53,7 +53,7 @@ function _cegg_print_module_item(array $modules)
|
|
53 |
<div class="col-md-4 col-xs-12">
|
54 |
|
55 |
<div class="panel panel-default">
|
56 |
-
<div class="panel-heading"><h3 class="panel-title"><?php
|
57 |
<div class="list-group">
|
58 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getProductModules()); ?>
|
59 |
</div>
|
@@ -64,7 +64,7 @@ function _cegg_print_module_item(array $modules)
|
|
64 |
|
65 |
<?php if ($modules = \ContentEgg\application\helpers\AdminHelper::getAeProductModules()): ?>
|
66 |
<div class="panel panel-default">
|
67 |
-
<div class="panel-heading"><h3 class="panel-title"><?php
|
68 |
<div class="list-group">
|
69 |
<?php _cegg_print_module_item($modules); ?>
|
70 |
</div>
|
@@ -72,14 +72,14 @@ function _cegg_print_module_item(array $modules)
|
|
72 |
<?php endif; ?>
|
73 |
|
74 |
<div class="panel panel-default">
|
75 |
-
<div class="panel-heading"><h3 class="panel-title"><?php
|
76 |
<div class="list-group">
|
77 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getFeedProductModules()); ?>
|
78 |
</div>
|
79 |
</div>
|
80 |
|
81 |
<div class="panel panel-default">
|
82 |
-
<div class="panel-heading"><h3 class="panel-title"><?php
|
83 |
<div class="list-group">
|
84 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getCouponModules()); ?>
|
85 |
</div>
|
@@ -90,7 +90,7 @@ function _cegg_print_module_item(array $modules)
|
|
90 |
<div class="col-md-4 col-xs-12">
|
91 |
|
92 |
<div class="panel panel-default">
|
93 |
-
<div class="panel-heading"><h3 class="panel-title"><?php
|
94 |
<div class="list-group">
|
95 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getContentModules()); ?>
|
96 |
</div>
|
9 |
echo '<a href="?page=' . \esc_attr($module->getConfigInstance()->page_slug()) . '" class = "list-group-item">';
|
10 |
echo \esc_html($module->getName());
|
11 |
if ($module->isActive() && !$module->isDeprecated())
|
12 |
+
echo '<span class="label label-success">' . esc_html(__('Active', 'content-egg')) . '</span>';
|
13 |
if ($module->isDeprecated())
|
14 |
+
echo '<span class="label label-warning">' . esc_html(__('Deprecated', 'content-egg')) . '</span>';
|
15 |
if ($module->isNew() && !$module->isFeedParser())
|
16 |
+
echo '<span class="label label-info">' . esc_html(__('New', 'content-egg')) . '</span>';
|
17 |
echo '</a>';
|
18 |
}
|
19 |
}
|
27 |
<div class="wrap">
|
28 |
|
29 |
<h2>
|
30 |
+
<?php esc_html_e('Module Settings', 'content-egg'); ?>
|
31 |
+
<span class="egg-label egg-label-pro">pro <small>v<?php echo esc_html(\ContentEgg\application\Plugin::version()); ?></small></span>
|
32 |
</h2>
|
33 |
|
34 |
|
35 |
<h2 class="nav-tab-wrapper">
|
36 |
+
<a href="?page=content-egg-modules" class="nav-tab<?php if (!empty($_GET['page']) && sanitize_key(wp_unslash($_GET['page'])) == 'content-egg-modules') echo ' nav-tab-active'; ?>">
|
37 |
<span class="dashicons dashicons-menu-alt3"></span>
|
38 |
</a>
|
39 |
<?php foreach (ContentEgg\application\components\ModuleManager::getInstance()->getConfigurableModules(true) as $m): ?>
|
40 |
<?php if ($m->isDeprecated() && !$m->isActive()) continue; ?>
|
41 |
<?php $c = $m->getConfigInstance(); ?>
|
42 |
+
<a href="?page=<?php echo \esc_attr($c->page_slug()); ?>" class="nav-tab<?php if (!empty($_GET['page']) && sanitize_key(wp_unslash($_GET['page'])) == $c->page_slug()) echo ' nav-tab-active'; ?>">
|
43 |
<span<?php if ($m->isDeprecated()): ?> style="color: darkgray;"<?php endif; ?>>
|
44 |
<?php echo \esc_html($m->getName()); ?>
|
45 |
</span>
|
53 |
<div class="col-md-4 col-xs-12">
|
54 |
|
55 |
<div class="panel panel-default">
|
56 |
+
<div class="panel-heading"><h3 class="panel-title"><?php esc_html_e('Product modules', 'content-egg'); ?></h3></div>
|
57 |
<div class="list-group">
|
58 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getProductModules()); ?>
|
59 |
</div>
|
64 |
|
65 |
<?php if ($modules = \ContentEgg\application\helpers\AdminHelper::getAeProductModules()): ?>
|
66 |
<div class="panel panel-default">
|
67 |
+
<div class="panel-heading"><h3 class="panel-title"><?php esc_html_e('Affiliate Egg modules', 'content-egg'); ?></h3></div>
|
68 |
<div class="list-group">
|
69 |
<?php _cegg_print_module_item($modules); ?>
|
70 |
</div>
|
72 |
<?php endif; ?>
|
73 |
|
74 |
<div class="panel panel-default">
|
75 |
+
<div class="panel-heading"><h3 class="panel-title"><?php esc_html_e('Feed modules', 'content-egg'); ?></h3></div>
|
76 |
<div class="list-group">
|
77 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getFeedProductModules()); ?>
|
78 |
</div>
|
79 |
</div>
|
80 |
|
81 |
<div class="panel panel-default">
|
82 |
+
<div class="panel-heading"><h3 class="panel-title"><?php esc_html_e('Coupon modules', 'content-egg'); ?></h3></div>
|
83 |
<div class="list-group">
|
84 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getCouponModules()); ?>
|
85 |
</div>
|
90 |
<div class="col-md-4 col-xs-12">
|
91 |
|
92 |
<div class="panel panel-default">
|
93 |
+
<div class="panel-heading"><h3 class="panel-title"><?php esc_html_e('Content modules', 'content-egg'); ?></h3></div>
|
94 |
<div class="list-group">
|
95 |
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getContentModules()); ?>
|
96 |
</div>
|
application/admin/views/module_settings.php
CHANGED
@@ -5,8 +5,8 @@
|
|
5 |
<?php endif; ?>
|
6 |
<div class="wrap">
|
7 |
<h2>
|
8 |
-
<?php
|
9 |
-
<span class="egg-label egg-label-pro">pro <small>v<?php echo \ContentEgg\application\Plugin::version(); ?></small></span>
|
10 |
</h2>
|
11 |
|
12 |
<h2 class="nav-tab-wrapper">
|
@@ -29,28 +29,28 @@
|
|
29 |
|
30 |
<h3>
|
31 |
<?php if ($module->isFeedParser() && !$module->isActive()): ?>
|
32 |
-
<?php
|
33 |
<?php else: ?>
|
34 |
<?php echo \esc_html(sprintf(__('%s Settings', 'content-egg'), $module->getName())); ?>
|
35 |
<?php endif; ?>
|
36 |
-
<?php if ($docs_uri = $module->getDocsUri()) echo sprintf('<a target="_blank" class="page-title-action" href="%s">' . __('Documentation', 'content-egg') . '</a>', $docs_uri); ?>
|
37 |
</h3>
|
38 |
|
39 |
<?php if ($module->isDeprecated()): ?>
|
40 |
<div class="cegg-warning">
|
41 |
|
42 |
<?php if ($module->getId() == 'Amazon'): ?>
|
43 |
-
<?php
|
44 |
<?php echo sprintf(__('Amazon PA-API v4 <a target="_blank" href="%s"> is deprecated</a>.', 'content-egg'), 'https://webservices.amazon.com/paapi5/documentation/faq.html'); ?>
|
45 |
<?php echo sprintf(__('Only <a target="_blank" href="%s">Content Egg Pro</a> has support for the new PA-API v5.', 'content-egg'), 'https://www.keywordrush.com/contentegg/pricing'); ?>
|
46 |
-
<?php
|
47 |
<?php endif; ?>
|
48 |
|
49 |
<?php if ($module->getId() != 'Amazon'): ?>
|
50 |
<strong>
|
51 |
-
<?php
|
52 |
-
<?php
|
53 |
-
(<a target="_blank" href="<?php echo \ContentEgg\application\Plugin::pluginDocsUrl(); ?>/modules/deprecatedmodules"><?php
|
54 |
</strong>
|
55 |
<?php endif; ?>
|
56 |
</div>
|
@@ -59,11 +59,11 @@
|
|
59 |
<?php if (!empty($module) && $requirements = $module->requirements()): ?>
|
60 |
<div class="cegg-warning">
|
61 |
<strong>
|
62 |
-
<?php echo
|
63 |
-
<?php
|
64 |
-
<?php
|
65 |
<ul>
|
66 |
-
<li><?php echo join('</li><li>', $requirements) ?></li>
|
67 |
</ul>
|
68 |
|
69 |
</strong>
|
@@ -85,29 +85,29 @@
|
|
85 |
<div>
|
86 |
<?php
|
87 |
if (!empty($description))
|
88 |
-
echo '<p>' . $description . '</p>';
|
89 |
?>
|
90 |
|
91 |
<?php if (!empty($module) && $module->isFeedModule()): ?>
|
92 |
<?php if ($last_date = $module->getLastImportDateReadable()): ?>
|
93 |
<?php $prod_count = $module->getProductCount(); ?>
|
94 |
-
<li><?php echo sprintf(__('Last feed import: %s.', 'content-egg'), $last_date); ?></li>
|
95 |
-
<li><?php echo sprintf(__('Total products: %d.', 'content-egg'), $prod_count); ?></li>
|
96 |
<?php endif; ?>
|
97 |
-
<li title="<?php echo \esc_attr(__('Your unzipped feed must be smaller than this.', 'content-egg')); ?>"><?php echo sprintf(__('WordPress memory limit: %s', 'content-egg'), \WP_MAX_MEMORY_LIMIT); ?>
|
98 |
(<a href="https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php" target="_blank">?</a>)
|
99 |
</li>
|
100 |
<?php if ($last_error = $module->getLastImportError()): ?>
|
101 |
-
<li style="color: red;"><?php echo sprintf(__('Last error: %s', 'content-egg'), $last_error); ?></li>
|
102 |
<?php endif; ?>
|
103 |
|
104 |
<?php if ($last_date && $prod_count): ?>
|
105 |
<hr /><br />
|
106 |
-
<div><a target="_blank" class="page-title-action" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=url&module=' . urlencode($module->getId())); ?>"><?php
|
107 |
<br />
|
108 |
-
<div><a target="_blank" class="page-title-action" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=ean&module=' . urlencode($module->getId())); ?>"><?php
|
109 |
<br />
|
110 |
-
<div><a target="_blank" class="page-title-action" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=ean_dublicate&module=' . urlencode($module->getId())); ?>"><?php
|
111 |
<?php endif; ?>
|
112 |
|
113 |
<?php endif; ?>
|
5 |
<?php endif; ?>
|
6 |
<div class="wrap">
|
7 |
<h2>
|
8 |
+
<?php esc_html_e('Module Settings', 'content-egg'); ?>
|
9 |
+
<span class="egg-label egg-label-pro">pro <small>v<?php echo esc_html(\ContentEgg\application\Plugin::version()); ?></small></span>
|
10 |
</h2>
|
11 |
|
12 |
<h2 class="nav-tab-wrapper">
|
29 |
|
30 |
<h3>
|
31 |
<?php if ($module->isFeedParser() && !$module->isActive()): ?>
|
32 |
+
<?php esc_html_e('Add new feed module', 'content-egg'); ?>
|
33 |
<?php else: ?>
|
34 |
<?php echo \esc_html(sprintf(__('%s Settings', 'content-egg'), $module->getName())); ?>
|
35 |
<?php endif; ?>
|
36 |
+
<?php if ($docs_uri = $module->getDocsUri()) echo sprintf('<a target="_blank" class="page-title-action" href="%s">' . esc_html(__('Documentation', 'content-egg')) . '</a>', esc_url_raw($docs_uri)); ?>
|
37 |
</h3>
|
38 |
|
39 |
<?php if ($module->isDeprecated()): ?>
|
40 |
<div class="cegg-warning">
|
41 |
|
42 |
<?php if ($module->getId() == 'Amazon'): ?>
|
43 |
+
<?php esc_html_e('WARNING:', 'content-egg'); ?>
|
44 |
<?php echo sprintf(__('Amazon PA-API v4 <a target="_blank" href="%s"> is deprecated</a>.', 'content-egg'), 'https://webservices.amazon.com/paapi5/documentation/faq.html'); ?>
|
45 |
<?php echo sprintf(__('Only <a target="_blank" href="%s">Content Egg Pro</a> has support for the new PA-API v5.', 'content-egg'), 'https://www.keywordrush.com/contentegg/pricing'); ?>
|
46 |
+
<?php esc_html_e('Please', 'content-egg'); ?> <a target="_blank" href="https://ce-docs.keywordrush.com/modules/affiliate/amazon#why-amazon-module-is-not-available-in-ce-free-version"><?php esc_html_e('read more...', 'content-egg'); ?></a>
|
47 |
<?php endif; ?>
|
48 |
|
49 |
<?php if ($module->getId() != 'Amazon'): ?>
|
50 |
<strong>
|
51 |
+
<?php esc_html_e('WARNING:', 'content-egg'); ?>
|
52 |
+
<?php esc_html_e('This module is deprecated', 'content-egg'); ?>
|
53 |
+
(<a target="_blank" href="<?php echo esc_url_raw(\ContentEgg\application\Plugin::pluginDocsUrl()); ?>/modules/deprecatedmodules"><?php esc_html_e('what does this mean', 'content-egg'); ?></a>).
|
54 |
</strong>
|
55 |
<?php endif; ?>
|
56 |
</div>
|
59 |
<?php if (!empty($module) && $requirements = $module->requirements()): ?>
|
60 |
<div class="cegg-warning">
|
61 |
<strong>
|
62 |
+
<?php echo esc_html_e('WARNING:', 'content-egg'); ?>
|
63 |
+
<?php esc_html_e('This module cannot be activated!', 'content-egg') ?>
|
64 |
+
<?php esc_html_e('Please fix the following error(s):', 'content-egg') ?>
|
65 |
<ul>
|
66 |
+
<li><?php echo wp_kses_post(join('</li><li>', $requirements)); ?></li>
|
67 |
</ul>
|
68 |
|
69 |
</strong>
|
85 |
<div>
|
86 |
<?php
|
87 |
if (!empty($description))
|
88 |
+
echo '<p>' . wp_kses_post($description) . '</p>';
|
89 |
?>
|
90 |
|
91 |
<?php if (!empty($module) && $module->isFeedModule()): ?>
|
92 |
<?php if ($last_date = $module->getLastImportDateReadable()): ?>
|
93 |
<?php $prod_count = $module->getProductCount(); ?>
|
94 |
+
<li><?php echo esc_html(sprintf(__('Last feed import: %s.', 'content-egg'), $last_date)); ?></li>
|
95 |
+
<li><?php echo esc_html(sprintf(__('Total products: %d.', 'content-egg'), $prod_count)); ?></li>
|
96 |
<?php endif; ?>
|
97 |
+
<li title="<?php echo \esc_attr(__('Your unzipped feed must be smaller than this.', 'content-egg')); ?>"><?php echo esc_html(sprintf(__('WordPress memory limit: %s', 'content-egg'), \WP_MAX_MEMORY_LIMIT)); ?>
|
98 |
(<a href="https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php" target="_blank">?</a>)
|
99 |
</li>
|
100 |
<?php if ($last_error = $module->getLastImportError()): ?>
|
101 |
+
<li style="color: red;"><?php echo esc_html(sprintf(__('Last error: %s', 'content-egg'), $last_error)); ?></li>
|
102 |
<?php endif; ?>
|
103 |
|
104 |
<?php if ($last_date && $prod_count): ?>
|
105 |
<hr /><br />
|
106 |
+
<div><a target="_blank" class="page-title-action" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=url&module=' . urlencode($module->getId()))); ?>"><?php esc_html_e('Export product URLs', 'content-egg') ?></a></div>
|
107 |
<br />
|
108 |
+
<div><a target="_blank" class="page-title-action" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=ean&module=' . urlencode($module->getId()))); ?>"><?php esc_html_e('Export product EANs', 'content-egg') ?></a></div>
|
109 |
<br />
|
110 |
+
<div><a target="_blank" class="page-title-action" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=feed-export&field=ean_dublicate&module=' . urlencode($module->getId()))); ?>"><?php esc_html_e('Export duplicate EANs', 'content-egg') ?></a></div>
|
111 |
<?php endif; ?>
|
112 |
|
113 |
<?php endif; ?>
|
application/admin/views/prefill.php
CHANGED
@@ -9,15 +9,15 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
9 |
<?php endif; ?>
|
10 |
<div class="wrap">
|
11 |
<h2>
|
12 |
-
<?php
|
13 |
</h2>
|
14 |
<p>
|
15 |
-
<?php
|
16 |
-
<?php
|
17 |
</p>
|
18 |
<table class="form-table">
|
19 |
<tr>
|
20 |
-
<th scope="row"><label for="module_id"><?php
|
21 |
<td>
|
22 |
<select id="delay">
|
23 |
<option value="1000">1</option>
|
@@ -36,81 +36,81 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
36 |
<option value="0">0</option>
|
37 |
|
38 |
</select>
|
39 |
-
<p class="description"><?php
|
40 |
|
41 |
</td>
|
42 |
</tr>
|
43 |
<tr>
|
44 |
-
<th scope="row"><label for="module_id"><?php
|
45 |
<td>
|
46 |
<select id="module_id">
|
47 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
48 |
-
<option value="<?php echo $module->getId(); ?>"><?php echo esc_html($module->getName()); ?></option>
|
49 |
<?php endforeach; ?>
|
50 |
</select>
|
51 |
</td>
|
52 |
</tr>
|
53 |
<tr>
|
54 |
-
<th scope="row"><label for="keyword_source"><?php
|
55 |
<td>
|
56 |
<select id="keyword_source">
|
57 |
-
<option value="_title"><?php
|
58 |
-
<option value="_density"><?php
|
59 |
-
<option value="_tags"><?php
|
60 |
-
<option value="_custom_field"><?php
|
61 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
62 |
-
<option value="_keyword_<?php echo $module->getId(); ?>"><?php echo \esc_html($module->getName() . ': ' . __('autoupdate keyword', 'content-egg')); ?> </option>
|
63 |
<?php endforeach; ?>
|
64 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
65 |
-
<option value="_ean_<?php echo $module->getId(); ?>"><?php echo \esc_html($module->getName() . ': ' . __('EAN', 'content-egg')); ?> </option>
|
66 |
<?php endforeach; ?>
|
67 |
</select>
|
68 |
-
<input style="display: none;" id="custom_field" type="text" class="regular-text" placeholder="<?php
|
69 |
</td>
|
70 |
</tr>
|
71 |
|
72 |
<tr>
|
73 |
-
<th scope="row"><label for="autoupdate"><?php
|
74 |
<td>
|
75 |
-
<label><input id="autoupdate" type="checkbox" value="1"> <?php
|
76 |
-
<p class="description"><?php
|
77 |
</td>
|
78 |
</tr>
|
79 |
|
80 |
<tr>
|
81 |
-
<th scope="row"><label for="keyword_count"><?php
|
82 |
<td>
|
83 |
<select id="keyword_count">
|
84 |
<?php for ($i = 1; $i <= 10; $i++): ?>
|
85 |
-
<option value="<?php echo $i; ?>"<?php if ($i == 5) echo ' selected="selected"'; ?>><?php echo $i; ?></option>
|
86 |
<?php endfor; ?>
|
87 |
</select>
|
88 |
-
<p class="description"><?php
|
89 |
</td>
|
90 |
</tr>
|
91 |
|
92 |
<tr>
|
93 |
-
<th scope="row"><label for="minus_words"><?php
|
94 |
<td>
|
95 |
<input id="minus_words" type="text" class="regular-text">
|
96 |
-
<p class="description"><?php
|
97 |
</td>
|
98 |
</tr>
|
99 |
|
100 |
<tr>
|
101 |
-
<th scope="row"><label for="post_type"><?php
|
102 |
<td>
|
103 |
<select id="post_type" multiple="multiple">
|
104 |
<?php foreach (GeneralConfig::getInstance()->option('post_types') as $post_type): ?>
|
105 |
<option value="<?php echo \esc_attr($post_type); ?>" selected="selected"><?php echo \esc_attr($post_type); ?></option>
|
106 |
<?php endforeach; ?>
|
107 |
</select>
|
108 |
-
<p class="description"><?php
|
109 |
</td>
|
110 |
</tr>
|
111 |
|
112 |
<tr>
|
113 |
-
<th scope="row"><label for="post_status"><?php
|
114 |
<td>
|
115 |
<?php
|
116 |
$post_statuses = array_merge(get_post_statuses(), array('future' => __('Future')));
|
@@ -128,30 +128,30 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
128 |
</tr>
|
129 |
|
130 |
<tr>
|
131 |
-
<th scope="row"><label for="custom_fields"><?php
|
132 |
<td>
|
133 |
<?php for ($i = 0; $i < 5; $i++): ?>
|
134 |
-
<input type="text" name="custom_field_names[]" placeholder="<?php echo sprintf(__('Custom Field %d', 'content-egg'), $i + 1); ?>" id="custom_fields" class="regular-text" />
|
135 |
-
<input type="text" name="custom_field_values[]" placeholder="<?php echo sprintf(__('Value %d', 'content-egg'), $i + 1); ?>" class="regular-text" /><br>
|
136 |
<?php endfor; ?>
|
137 |
<?php $tags = '%KEYWORD%, %RANDOM(10,50)%, %PRODUCT.title%, %PRODUCT.price%, ...'; ?>
|
138 |
-
<p class="description"><?php echo sprintf(__('You can use tags: %s.', 'content-egg'), $tags); ?></p>
|
139 |
</td>
|
140 |
</tr>
|
141 |
|
142 |
</table>
|
143 |
|
144 |
<div id="progressbar" name="progressbar"></div>
|
145 |
-
<div><?php
|
146 |
|
147 |
<div>
|
148 |
<br>
|
149 |
-
<button class="button-primary" type="button" id="start_prefill"><?php
|
150 |
-
<button class="button-primary" type="button" id="start_prefill_begin"><?php
|
151 |
-
<button class="button-secondary" type="button" id="stop_prefill" disabled><?php
|
152 |
|
153 |
-
<span id="ajaxWaiting__" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
154 |
-
<span id="ajaxBusy" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
155 |
|
156 |
|
157 |
</div>
|
9 |
<?php endif; ?>
|
10 |
<div class="wrap">
|
11 |
<h2>
|
12 |
+
<?php esc_html_e('Fill', 'content-egg'); ?>
|
13 |
</h2>
|
14 |
<p>
|
15 |
+
<?php esc_html_e('This extension will fill module\'s data for all existed posts.', 'content-egg'); ?>
|
16 |
+
<?php esc_html_e('All existing data and keywords will not be erased or overwritten.', 'content-egg'); ?>
|
17 |
</p>
|
18 |
<table class="form-table">
|
19 |
<tr>
|
20 |
+
<th scope="row"><label for="module_id"><?php esc_html_e('Delay', 'content-egg'); ?></label></th>
|
21 |
<td>
|
22 |
<select id="delay">
|
23 |
<option value="1000">1</option>
|
36 |
<option value="0">0</option>
|
37 |
|
38 |
</select>
|
39 |
+
<p class="description"><?php esc_html_e('Delay in seconds between each post prefill.', 'content-egg'); ?></p>
|
40 |
|
41 |
</td>
|
42 |
</tr>
|
43 |
<tr>
|
44 |
+
<th scope="row"><label for="module_id"><?php esc_html_e('Add data for module', 'content-egg'); ?></label></th>
|
45 |
<td>
|
46 |
<select id="module_id">
|
47 |
<?php foreach (ModuleManager::getInstance()->getParserModules(true) as $module): ?>
|
48 |
+
<option value="<?php echo esc_attr($module->getId()); ?>"><?php echo esc_html($module->getName()); ?></option>
|
49 |
<?php endforeach; ?>
|
50 |
</select>
|
51 |
</td>
|
52 |
</tr>
|
53 |
<tr>
|
54 |
+
<th scope="row"><label for="keyword_source"><?php esc_html_e('Keyword source', 'content-egg'); ?></label></th>
|
55 |
<td>
|
56 |
<select id="keyword_source">
|
57 |
+
<option value="_title"><?php esc_html_e('Post title', 'content-egg'); ?></option>
|
58 |
+
<option value="_density"><?php esc_html_e('Keyword density', 'content-egg'); ?></option>
|
59 |
+
<option value="_tags"><?php esc_html_e('Post tags', 'content-egg'); ?></option>
|
60 |
+
<option value="_custom_field"><?php esc_html_e('Arbitrary custom field', 'content-egg'); ?></option>
|
61 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
62 |
+
<option value="_keyword_<?php echo esc_attr($module->getId()); ?>"><?php echo \esc_html($module->getName() . ': ' . __('autoupdate keyword', 'content-egg')); ?> </option>
|
63 |
<?php endforeach; ?>
|
64 |
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module): ?>
|
65 |
+
<option value="_ean_<?php echo esc_attr($module->getId()); ?>"><?php echo \esc_html($module->getName() . ': ' . __('EAN', 'content-egg')); ?> </option>
|
66 |
<?php endforeach; ?>
|
67 |
</select>
|
68 |
+
<input style="display: none;" id="custom_field" type="text" class="regular-text" placeholder="<?php esc_html_e('Set the name of a custom field', 'content-egg'); ?>">
|
69 |
</td>
|
70 |
</tr>
|
71 |
|
72 |
<tr>
|
73 |
+
<th scope="row"><label for="autoupdate"><?php esc_html_e('Autoupdate', 'content-egg'); ?></label></th>
|
74 |
<td>
|
75 |
+
<label><input id="autoupdate" type="checkbox" value="1"> <?php esc_html_e('Add Keyword for the automatic update', 'content-egg'); ?></label>
|
76 |
+
<p class="description"><?php esc_html_e('Only for those modules, which have autoupdate function.', 'content-egg'); ?></p>
|
77 |
</td>
|
78 |
</tr>
|
79 |
|
80 |
<tr>
|
81 |
+
<th scope="row"><label for="keyword_count"><?php esc_html_e('Number of words', 'content-egg'); ?></label></th>
|
82 |
<td>
|
83 |
<select id="keyword_count">
|
84 |
<?php for ($i = 1; $i <= 10; $i++): ?>
|
85 |
+
<option value="<?php echo esc_attr($i); ?>"<?php if ($i == 5) echo ' selected="selected"'; ?>><?php echo esc_html($i); ?></option>
|
86 |
<?php endfor; ?>
|
87 |
</select>
|
88 |
+
<p class="description"><?php esc_html_e('Maximum words for one search query.', 'content-egg'); ?></p>
|
89 |
</td>
|
90 |
</tr>
|
91 |
|
92 |
<tr>
|
93 |
+
<th scope="row"><label for="minus_words"><?php esc_html_e('"Minus" words', 'content-egg'); ?></label></th>
|
94 |
<td>
|
95 |
<input id="minus_words" type="text" class="regular-text">
|
96 |
+
<p class="description"><?php esc_html_e('Remove these words from keyword. You can set several minus words/phrases with commas.', 'content-egg'); ?></p>
|
97 |
</td>
|
98 |
</tr>
|
99 |
|
100 |
<tr>
|
101 |
+
<th scope="row"><label for="post_type"><?php esc_html_e('Post type', 'content-egg'); ?></label></th>
|
102 |
<td>
|
103 |
<select id="post_type" multiple="multiple">
|
104 |
<?php foreach (GeneralConfig::getInstance()->option('post_types') as $post_type): ?>
|
105 |
<option value="<?php echo \esc_attr($post_type); ?>" selected="selected"><?php echo \esc_attr($post_type); ?></option>
|
106 |
<?php endforeach; ?>
|
107 |
</select>
|
108 |
+
<p class="description"><?php esc_html_e('You can set all supported post types in General settings -> Post Types.', 'content-egg'); ?></p>
|
109 |
</td>
|
110 |
</tr>
|
111 |
|
112 |
<tr>
|
113 |
+
<th scope="row"><label for="post_status"><?php esc_html_e('Post status', 'content-egg'); ?></label></th>
|
114 |
<td>
|
115 |
<?php
|
116 |
$post_statuses = array_merge(get_post_statuses(), array('future' => __('Future')));
|
128 |
</tr>
|
129 |
|
130 |
<tr>
|
131 |
+
<th scope="row"><label for="custom_fields"><?php esc_html_e('Add custom fields', 'content-egg'); ?></label></th>
|
132 |
<td>
|
133 |
<?php for ($i = 0; $i < 5; $i++): ?>
|
134 |
+
<input type="text" name="custom_field_names[]" placeholder="<?php echo esc_attr(sprintf(__('Custom Field %d', 'content-egg'), $i + 1)); ?>" id="custom_fields" class="regular-text" />
|
135 |
+
<input type="text" name="custom_field_values[]" placeholder="<?php echo esc_attr(sprintf(__('Value %d', 'content-egg'), $i + 1)); ?>" class="regular-text" /><br>
|
136 |
<?php endfor; ?>
|
137 |
<?php $tags = '%KEYWORD%, %RANDOM(10,50)%, %PRODUCT.title%, %PRODUCT.price%, ...'; ?>
|
138 |
+
<p class="description"><?php echo esc_html(sprintf(__('You can use tags: %s.', 'content-egg'), $tags)); ?></p>
|
139 |
</td>
|
140 |
</tr>
|
141 |
|
142 |
</table>
|
143 |
|
144 |
<div id="progressbar" name="progressbar"></div>
|
145 |
+
<div><?php esc_html_e('Total posts', 'content-egg'); ?>: <b><span id="post_ids_total"></span></b></div>
|
146 |
|
147 |
<div>
|
148 |
<br>
|
149 |
+
<button class="button-primary" type="button" id="start_prefill"><?php esc_html_e('Start', 'content-egg'); ?></button>
|
150 |
+
<button class="button-primary" type="button" id="start_prefill_begin"><?php esc_html_e('Restart', 'content-egg'); ?></button>
|
151 |
+
<button class="button-secondary" type="button" id="stop_prefill" disabled><?php esc_html_e('Stop', 'content-egg'); ?></button>
|
152 |
|
153 |
+
<span id="ajaxWaiting__" style="display:none;"><img src="<?php echo esc_url_raw(\ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif'); ?>" /></span>
|
154 |
+
<span id="ajaxBusy" style="display:none;"><img src="<?php echo esc_url_raw(\ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif'); ?>" /></span>
|
155 |
|
156 |
|
157 |
</div>
|
application/admin/views/product_index.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
-
<h2><?php
|
4 |
<p>
|
5 |
-
<img src="<?php echo \ContentEgg\PLUGIN_RES; ?>/img/egg_waiting.gif" />
|
6 |
</p>
|
7 |
</div>
|
8 |
<script type="text/javascript">
|
@@ -24,18 +24,18 @@ $message = '';
|
|
24 |
|
25 |
<div class="wrap">
|
26 |
<h1 class="wp-heading-inline">
|
27 |
-
<?php
|
28 |
</h1>
|
29 |
-
<a id="btn_scan_products" href="<?php echo \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-product&action=scan'); ?>" class="page-title-action"><?php
|
30 |
-
<small><?php echo sprintf(__('Last scanned: %s', 'content-egg'), $last_scaned_str); ?></small>
|
31 |
|
32 |
-
<?php echo $message; ?>
|
33 |
|
34 |
|
35 |
<form id="cegg-products-table" method="GET">
|
36 |
<input type="hidden" name="page" value="content-egg-product"/>
|
37 |
<?php if (isset($_REQUEST['stock_status'])): ?>
|
38 |
-
<input type="hidden" name="stock_status" value="<?php echo \esc_attr(\sanitize_text_field($_REQUEST['stock_status'])); ?>"/>
|
39 |
<?php endif; ?>
|
40 |
<?php $table->views(); ?>
|
41 |
<?php $table->search_box(__('Search products', 'content-egg'), 'key'); ?>
|
1 |
<?php defined('\ABSPATH') || exit; ?>
|
2 |
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
+
<h2><?php esc_html_e('Scanning... Please wait...', 'content-egg'); ?></h2>
|
4 |
<p>
|
5 |
+
<img src="<?php echo esc_url_raw(\ContentEgg\PLUGIN_RES); ?>/img/egg_waiting.gif"; />
|
6 |
</p>
|
7 |
</div>
|
8 |
<script type="text/javascript">
|
24 |
|
25 |
<div class="wrap">
|
26 |
<h1 class="wp-heading-inline">
|
27 |
+
<?php esc_html_e('Products', 'content-egg'); ?>
|
28 |
</h1>
|
29 |
+
<a id="btn_scan_products" href="<?php echo esc_url_raw(\get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-product&action=scan')); ?>" class="page-title-action"><?php esc_html_e('Scan Products', 'content-egg'); ?></a>
|
30 |
+
<small><?php echo esc_html(sprintf(__('Last scanned: %s', 'content-egg'), $last_scaned_str)); ?></small>
|
31 |
|
32 |
+
<?php echo wp_kses_post($message); ?>
|
33 |
|
34 |
|
35 |
<form id="cegg-products-table" method="GET">
|
36 |
<input type="hidden" name="page" value="content-egg-product"/>
|
37 |
<?php if (isset($_REQUEST['stock_status'])): ?>
|
38 |
+
<input type="hidden" name="stock_status" value="<?php echo \esc_attr(\sanitize_text_field(wp_unslash($_REQUEST['stock_status']))); ?>"/>
|
39 |
<?php endif; ?>
|
40 |
<?php $table->views(); ?>
|
41 |
<?php $table->search_box(__('Search products', 'content-egg'), 'key'); ?>
|
application/admin/views/settings.php
CHANGED
@@ -5,11 +5,11 @@
|
|
5 |
<?php endif; ?>
|
6 |
<div class="wrap">
|
7 |
<h2>
|
8 |
-
<?php
|
9 |
<?php if (\ContentEgg\application\Plugin::isPro()): ?>
|
10 |
-
<span class="egg-label egg-label-pro">pro <small>v<?php echo \ContentEgg\application\Plugin::version(); ?></small></span>
|
11 |
<?php else: ?>
|
12 |
-
<a target="_blank" class="page-title-action" href="<?php echo \ContentEgg\application\Plugin::pluginSiteUrl(); ?>">Go PRO</a>
|
13 |
<?php endif; ?>
|
14 |
</h2>
|
15 |
|
5 |
<?php endif; ?>
|
6 |
<div class="wrap">
|
7 |
<h2>
|
8 |
+
<?php esc_html_e('Content Egg Settings', 'content-egg'); ?>
|
9 |
<?php if (\ContentEgg\application\Plugin::isPro()): ?>
|
10 |
+
<span class="egg-label egg-label-pro">pro <small>v<?php echo esc_html(\ContentEgg\application\Plugin::version()); ?></small></span>
|
11 |
<?php else: ?>
|
12 |
+
<a target="_blank" class="page-title-action" href="<?php echo esc_url_raw(\ContentEgg\application\Plugin::pluginSiteUrl()); ?>">Go PRO</a>
|
13 |
<?php endif; ?>
|
14 |
</h2>
|
15 |
|
application/components/AffiliateFeedParserModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TemplateHelper;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
@@ -17,591 +17,585 @@ use ContentEgg\application\helpers\TextHelper;
|
|
17 |
*/
|
18 |
abstract class AffiliateFeedParserModule extends AffiliateParserModule {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
$mapping = $this->config('mapping');
|
601 |
-
if (!empty($mapping['product node']))
|
602 |
-
return $mapping['product node'];
|
603 |
-
else
|
604 |
-
return false;
|
605 |
-
}
|
606 |
|
607 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TemplateHelper;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
17 |
*/
|
18 |
abstract class AffiliateFeedParserModule extends AffiliateParserModule {
|
19 |
|
20 |
+
const TRANSIENT_LAST_IMPORT_DATE = 'cegg_products_last_import_';
|
21 |
+
const PRODUCTS_TTL = 43200;
|
22 |
+
const MULTIPLE_INSERT_ROWS = 50;
|
23 |
+
const IMPORT_TIME_LIMT = 600;
|
24 |
+
const DATAFEED_DIR_NAME = 'cegg-datafeeds';
|
25 |
+
const TRANSIENT_LAST_IMPORT_ERROR = 'cegg_last_import_error_';
|
26 |
+
|
27 |
+
protected $rmdir;
|
28 |
+
protected $product_model;
|
29 |
+
|
30 |
+
abstract public function getProductModel();
|
31 |
+
|
32 |
+
abstract public function getFeedUrl();
|
33 |
+
|
34 |
+
abstract protected function feedProductPrepare( array $data );
|
35 |
+
|
36 |
+
public function __construct( $module_id = null ) {
|
37 |
+
parent::__construct( $module_id );
|
38 |
+
$this->product_model = $this->getProductModel();
|
39 |
+
|
40 |
+
// download feed in background
|
41 |
+
\add_action( 'cegg_' . $this->getId() . '_init_products', array( get_called_class(), 'initProducts' ), 10, 1 );
|
42 |
+
}
|
43 |
+
|
44 |
+
public static function initProducts( $module_id ) {
|
45 |
+
$m = ModuleManager::factory( $module_id );
|
46 |
+
|
47 |
+
try {
|
48 |
+
$m->maybeImportProducts();
|
49 |
+
} catch ( \Exception $e ) {
|
50 |
+
$error = $e->getMessage();
|
51 |
+
if ( ! strstr( $error, 'Product import is in progress' ) ) {
|
52 |
+
$m->setLastImportError( $error );
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
public function requirements() {
|
58 |
+
$required_version = '5.6.4';
|
59 |
+
$mysql_version = $this->product_model->getDb()->get_var( 'SELECT VERSION();' );
|
60 |
+
$errors = array();
|
61 |
+
|
62 |
+
if ( version_compare( $required_version, $mysql_version, '>' ) ) {
|
63 |
+
$errors[] = sprintf( 'You are using MySQL %s. This module requires at least <strong>MySQL %s</strong>.', $mysql_version, $required_version );
|
64 |
+
}
|
65 |
+
|
66 |
+
return $errors;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function isZippedFeed() {
|
70 |
+
return false;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function maybeCreateProductTable() {
|
74 |
+
if ( ! $this->product_model->isTableExists() ) {
|
75 |
+
$this->dbDelta();
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
protected function dbDelta() {
|
80 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
81 |
+
|
82 |
+
$sql = $this->product_model->getDump();
|
83 |
+
dbDelta( $sql );
|
84 |
+
}
|
85 |
+
|
86 |
+
public function getLastImportDate() {
|
87 |
+
return \get_transient( self::TRANSIENT_LAST_IMPORT_DATE . $this->getId() );
|
88 |
+
}
|
89 |
+
|
90 |
+
public function getLastImportError() {
|
91 |
+
return \get_transient( self::TRANSIENT_LAST_IMPORT_ERROR . $this->getId() );
|
92 |
+
}
|
93 |
+
|
94 |
+
public function setLastImportDate( $time = null ) {
|
95 |
+
if ( $time === null ) {
|
96 |
+
$time = time();
|
97 |
+
}
|
98 |
+
\set_transient( self::TRANSIENT_LAST_IMPORT_DATE . $this->getId(), $time );
|
99 |
+
}
|
100 |
+
|
101 |
+
public function setLastImportError( $error ) {
|
102 |
+
\set_transient( self::TRANSIENT_LAST_IMPORT_ERROR . $this->getId(), $error );
|
103 |
+
}
|
104 |
+
|
105 |
+
public function maybeImportProducts() {
|
106 |
+
$last_export = $this->getLastImportDate();
|
107 |
+
|
108 |
+
// product import is in progress?
|
109 |
+
if ( $last_export && $last_export < 0 ) {
|
110 |
+
if ( time() + $last_export > static::IMPORT_TIME_LIMT ) {
|
111 |
+
$last_export = 0;
|
112 |
+
} else {
|
113 |
+
throw new \Exception( 'Product import is in progress. Try later.' );
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
if ( $this->isImportTime() ) {
|
118 |
+
// set in progress flag
|
119 |
+
$this->deleteTemporaryFiles();
|
120 |
+
$this->setLastImportDate( time() * - 1 );
|
121 |
+
$this->maybeCreateProductTable();
|
122 |
+
|
123 |
+
if ( ! $this->product_model->isTableExists() ) {
|
124 |
+
throw new \Exception( sprintf( 'Table %s does not exist', $this->product_model->tableName() ) );
|
125 |
+
}
|
126 |
+
|
127 |
+
$this->importProducts( $this->getFeedUrl() );
|
128 |
+
|
129 |
+
return true;
|
130 |
+
}
|
131 |
+
|
132 |
+
return false;
|
133 |
+
}
|
134 |
+
|
135 |
+
public static function getProductsTtl() {
|
136 |
+
return \apply_filters( 'cegg_feed_products_ttl', self::PRODUCTS_TTL );
|
137 |
+
}
|
138 |
+
|
139 |
+
public function isImportTime() {
|
140 |
+
$last_export = $this->getLastImportDate();
|
141 |
+
if ( ! $last_export || ( time() - $last_export > self::getProductsTtl() ) ) {
|
142 |
+
return true;
|
143 |
+
} else {
|
144 |
+
return false;
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
public function importProducts( $feed_url ) {
|
149 |
+
@set_time_limit( static::IMPORT_TIME_LIMT );
|
150 |
+
\wp_raise_memory_limit();
|
151 |
+
$this->setLastImportError( '' );
|
152 |
+
register_shutdown_function( array( $this, 'fatalHandler' ) );
|
153 |
+
|
154 |
+
$this->product_model->truncateTable();
|
155 |
+
$file = $this->downlodFeed( $feed_url );
|
156 |
+
$this->processFeed( $file );
|
157 |
+
|
158 |
+
$this->setLastImportDate();
|
159 |
+
|
160 |
+
@unlink( $file );
|
161 |
+
if ( $this->rmdir ) {
|
162 |
+
@rmdir( $this->rmdir );
|
163 |
+
$this->rmdir = null;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
protected function downlodFeed( $feed_url ) {
|
168 |
+
if ( ! function_exists( '\download_url' ) ) {
|
169 |
+
require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
|
170 |
+
}
|
171 |
+
|
172 |
+
$tmp = \download_url( $feed_url, 900 );
|
173 |
+
if ( \is_wp_error( $tmp ) ) {
|
174 |
+
$this->setLastImportDate( 0 );
|
175 |
+
throw new \Exception( sprintf( 'Feed URL could not be downloaded: %s.', $tmp->get_error_message() ) );
|
176 |
+
}
|
177 |
+
|
178 |
+
if ( ! $this->isZippedFeed() ) {
|
179 |
+
return $tmp;
|
180 |
+
} else {
|
181 |
+
return $this->unzipFeed( $tmp );
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
protected function unzipFeed( $file ) {
|
186 |
+
if ( ! function_exists( '\unzip_file' ) ) {
|
187 |
+
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
188 |
+
}
|
189 |
+
|
190 |
+
// unzip_file function requires the Filesystem API to be initialized
|
191 |
+
global $wp_filesystem;
|
192 |
+
if ( ! $wp_filesystem ) {
|
193 |
+
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
194 |
+
\WP_Filesystem();
|
195 |
+
}
|
196 |
+
|
197 |
+
$to = trailingslashit( $this->getDatafeedDir() ) . basename( $file ) . '-unzipped-dir';
|
198 |
+
if ( ! $to ) {
|
199 |
+
throw new \Exception( 'Temporary directory does not exist.' );
|
200 |
+
}
|
201 |
+
|
202 |
+
$result = \unzip_file( $file, $to );
|
203 |
+
@unlink( $file );
|
204 |
+
if ( \is_wp_error( $result ) ) {
|
205 |
+
$this->setLastImportDate( 0 );
|
206 |
+
throw new \Exception( sprintf( 'Unable to unzip feed archive: %s.', $result->get_error_message() ) );
|
207 |
+
}
|
208 |
+
|
209 |
+
$scanned = array_values( array_diff( scandir( $to ), array( '..', '.' ) ) );
|
210 |
+
if ( ! $scanned || ! isset( $scanned[0] ) ) {
|
211 |
+
$this->setLastImportDate( 0 );
|
212 |
+
throw new \Exception( 'Unable to find unziped feed.' );
|
213 |
+
}
|
214 |
+
|
215 |
+
$this->rmdir = $to;
|
216 |
+
|
217 |
+
return $to . DIRECTORY_SEPARATOR . $scanned[0];
|
218 |
+
}
|
219 |
+
|
220 |
+
protected function processFeed( $file ) {
|
221 |
+
$format = $this->config( 'feed_format', 'csv' );
|
222 |
+
if ( $format == 'xml' ) {
|
223 |
+
$this->processFeedXml( $file );
|
224 |
+
} elseif ( $format == 'json' ) {
|
225 |
+
$this->processFeedJson( $file );
|
226 |
+
} else {
|
227 |
+
$this->processFeedCsv( $file );
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
protected function processFeedCsv( $file ) {
|
232 |
+
$encoding = $this->config( 'encoding', 'UTF-8' );
|
233 |
+
|
234 |
+
$handle = fopen( $file, "r" );
|
235 |
+
$fields = array();
|
236 |
+
$products = array();
|
237 |
+
|
238 |
+
$delimer = $this->detectCsvDelimiter( $file );
|
239 |
+
$in_stock_only = $this->config( 'in_stock', false );
|
240 |
+
$i = 0;
|
241 |
+
while ( ( $data = fgetcsv( $handle, 0, $delimer ) ) !== false ) {
|
242 |
+
if ( $encoding == 'ISO-8859-1' ) {
|
243 |
+
$data = array_map( 'utf8_encode', $data );
|
244 |
+
}
|
245 |
+
|
246 |
+
if ( ! $fields ) {
|
247 |
+
$data = str_replace( "\xEF\xBB\xBF", '', $data );
|
248 |
+
}
|
249 |
+
|
250 |
+
$data = array_map( function ( $item ) {
|
251 |
+
return trim( $item, ' \'"' );
|
252 |
+
}, $data );
|
253 |
+
|
254 |
+
if ( ! $fields ) {
|
255 |
+
$fields = $data;
|
256 |
+
continue;
|
257 |
+
}
|
258 |
+
|
259 |
+
if ( count( $fields ) != count( $data ) ) {
|
260 |
+
continue;
|
261 |
+
}
|
262 |
+
|
263 |
+
$data = array_combine( $fields, $data );
|
264 |
+
|
265 |
+
try {
|
266 |
+
$product = $this->feedProductPrepare( $data );
|
267 |
+
} catch ( \Exception $e ) {
|
268 |
+
if ( $i > 10 ) {
|
269 |
+
continue;
|
270 |
+
}
|
271 |
+
$this->setLastImportError( $e->getMessage() );
|
272 |
+
fclose( $handle );
|
273 |
+
|
274 |
+
return;
|
275 |
+
}
|
276 |
+
|
277 |
+
if ( ! $product ) {
|
278 |
+
continue;
|
279 |
+
}
|
280 |
+
|
281 |
+
if ( ! empty( $product['ean'] ) ) {
|
282 |
+
$product['ean'] = TextHelper::fixEan( $product['ean'] );
|
283 |
+
}
|
284 |
+
|
285 |
+
if ( $in_stock_only && $product['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
286 |
+
continue;
|
287 |
+
}
|
288 |
+
|
289 |
+
$products[] = $product;
|
290 |
+
$i ++;
|
291 |
+
if ( $i % static::MULTIPLE_INSERT_ROWS == 0 ) {
|
292 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
293 |
+
$products = array();
|
294 |
+
}
|
295 |
+
}
|
296 |
+
if ( $products ) {
|
297 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
protected function processFeedXml( $file ) {
|
302 |
+
$uniqueNode = $this->getProductNode();
|
303 |
+
if ( ! $uniqueNode ) {
|
304 |
+
$uniqueNode = 'offer';
|
305 |
+
}
|
306 |
+
|
307 |
+
$streamer = \ContentEgg\application\vendor\XmlStringStreamer\XmlStringStreamer::createUniqueNodeParser( $file, array( 'uniqueNode' => $uniqueNode ) );
|
308 |
+
$in_stock_only = $this->config( 'in_stock', false );
|
309 |
+
$i = 0;
|
310 |
+
$products = array();
|
311 |
+
|
312 |
+
libxml_use_internal_errors( true );
|
313 |
+
|
314 |
+
$encoding = $this->config( 'encoding', 'UTF-8' );
|
315 |
+
|
316 |
+
while ( $node_string = $streamer->getNode() ) {
|
317 |
+
if ( $encoding != 'UTF-8' ) {
|
318 |
+
$node_string = iconv( $encoding, 'UTF-8//TRANSLIT//IGNORE', $node_string );
|
319 |
+
}
|
320 |
+
|
321 |
+
$node = simplexml_load_string( $node_string );
|
322 |
+
if ( $node === false ) {
|
323 |
+
$err_mess = 'Cannot load xml source.';
|
324 |
+
|
325 |
+
if ( $error = libxml_get_last_error() ) {
|
326 |
+
$err_mess .= $error->message;
|
327 |
+
}
|
328 |
+
|
329 |
+
$this->setLastImportError( $err_mess );
|
330 |
+
|
331 |
+
return;
|
332 |
+
}
|
333 |
+
|
334 |
+
$data = $this->mapXmlData( $node );
|
335 |
+
|
336 |
+
try {
|
337 |
+
$product = $this->feedProductPrepare( $data );
|
338 |
+
} catch ( \Exception $e ) {
|
339 |
+
if ( $i > 10 ) {
|
340 |
+
continue;
|
341 |
+
}
|
342 |
+
|
343 |
+
$this->setLastImportError( $e->getMessage() );
|
344 |
+
|
345 |
+
return;
|
346 |
+
}
|
347 |
+
|
348 |
+
if ( ! $product ) {
|
349 |
+
continue;
|
350 |
+
}
|
351 |
+
|
352 |
+
if ( ! empty( $product['ean'] ) ) {
|
353 |
+
$product['ean'] = TextHelper::fixEan( $product['ean'] );
|
354 |
+
}
|
355 |
+
|
356 |
+
if ( $in_stock_only && $product['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
357 |
+
continue;
|
358 |
+
}
|
359 |
+
|
360 |
+
$products[] = $product;
|
361 |
+
$i ++;
|
362 |
+
if ( $i % static::MULTIPLE_INSERT_ROWS == 0 ) {
|
363 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
364 |
+
$products = array();
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
if ( $i == 0 ) {
|
369 |
+
$this->setLastImportError( 'Product node not found.' );
|
370 |
+
}
|
371 |
+
|
372 |
+
if ( $products ) {
|
373 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
+
protected function processFeedJson( $file ) {
|
378 |
+
$encoding = $this->config( 'encoding', 'UTF-8' );
|
379 |
+
$in_stock_only = $this->config( 'in_stock', false );
|
380 |
+
|
381 |
+
$json = file_get_contents( $file );
|
382 |
+
$json_arr = json_decode( $json, true );
|
383 |
+
|
384 |
+
if ( ! $json_arr ) {
|
385 |
+
$this->setLastImportError( trim( 'Cannot decode JSON source. ' . json_last_error_msg() ) );
|
386 |
+
|
387 |
+
return;
|
388 |
+
}
|
389 |
+
|
390 |
+
$node = $this->getProductNode();
|
391 |
+
|
392 |
+
if ( ! $node && is_array( $json_arr ) ) {
|
393 |
+
$node = 'offer';
|
394 |
+
$json_arr = array( $node => $json_arr );
|
395 |
+
}
|
396 |
+
|
397 |
+
if ( ! isset( $json_arr[ $node ] ) || ! is_array( $json_arr[ $node ] ) ) {
|
398 |
+
$this->setLastImportError( 'The product node "' . \esc_html( $node ) . '" does not exist.' );
|
399 |
+
|
400 |
+
return;
|
401 |
+
}
|
402 |
+
|
403 |
+
$i = 0;
|
404 |
+
foreach ( $json_arr[ $node ] as $data ) {
|
405 |
+
if ( $encoding == 'ISO-8859-1' ) {
|
406 |
+
$data = array_map( 'utf8_encode', $data );
|
407 |
+
}
|
408 |
+
|
409 |
+
try {
|
410 |
+
$product = $this->feedProductPrepare( $data );
|
411 |
+
} catch ( \Exception $e ) {
|
412 |
+
if ( $i > 10 ) {
|
413 |
+
continue;
|
414 |
+
}
|
415 |
+
$this->setLastImportError( $e->getMessage() );
|
416 |
+
|
417 |
+
return;
|
418 |
+
}
|
419 |
+
|
420 |
+
if ( ! $product ) {
|
421 |
+
continue;
|
422 |
+
}
|
423 |
+
|
424 |
+
if ( ! empty( $product['ean'] ) ) {
|
425 |
+
$product['ean'] = TextHelper::fixEan( $product['ean'] );
|
426 |
+
}
|
427 |
+
|
428 |
+
if ( $in_stock_only && $product['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
429 |
+
continue;
|
430 |
+
}
|
431 |
+
|
432 |
+
$products[] = $product;
|
433 |
+
$i ++;
|
434 |
+
if ( $i % static::MULTIPLE_INSERT_ROWS == 0 ) {
|
435 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
436 |
+
$products = array();
|
437 |
+
}
|
438 |
+
$i ++;
|
439 |
+
}
|
440 |
+
if ( $products ) {
|
441 |
+
$this->product_model->multipleInsert( $products, static::MULTIPLE_INSERT_ROWS );
|
442 |
+
}
|
443 |
+
}
|
444 |
+
|
445 |
+
protected function mapXmlData( $node ) {
|
446 |
+
$data = array();
|
447 |
+
$mapping = $this->config( 'mapping' );
|
448 |
+
$fields = array_values( $mapping );
|
449 |
+
$attributes = $node->attributes();
|
450 |
+
foreach ( $fields as $field ) {
|
451 |
+
if ( isset( $attributes[ $field ] ) ) {
|
452 |
+
$data[ $field ] = (string) $attributes[ $field ];
|
453 |
+
} elseif ( isset( $node->{$field} ) ) {
|
454 |
+
$data[ $field ] = (string) $node->{$field};
|
455 |
+
} else {
|
456 |
+
continue;
|
457 |
+
}
|
458 |
+
}
|
459 |
+
|
460 |
+
return $data;
|
461 |
+
}
|
462 |
+
|
463 |
+
public function getLastImportDateReadable() {
|
464 |
+
$last_import = $this->getLastImportDate();
|
465 |
+
|
466 |
+
if ( empty( $last_import ) ) {
|
467 |
+
return '';
|
468 |
+
}
|
469 |
+
|
470 |
+
if ( $last_import < 0 ) {
|
471 |
+
return __( 'Product import is in progress', 'content-egg' );
|
472 |
+
}
|
473 |
+
|
474 |
+
if ( time() - $last_import <= 43200 ) {
|
475 |
+
return sprintf( __( '%s ago', '%s = human-readable time difference', 'content-egg' ), \human_time_diff( $last_import, time() ) );
|
476 |
+
}
|
477 |
+
|
478 |
+
return TemplateHelper::dateFormatFromGmt( $last_import, true );
|
479 |
+
}
|
480 |
+
|
481 |
+
public function getProductCount() {
|
482 |
+
return $this->product_model->count();
|
483 |
+
}
|
484 |
+
|
485 |
+
protected function getDatafeedDir() {
|
486 |
+
$upload_dir = \wp_upload_dir();
|
487 |
+
$datafeed_dir = $upload_dir['basedir'] . '/' . static::DATAFEED_DIR_NAME;
|
488 |
+
|
489 |
+
if ( is_dir( $datafeed_dir ) ) {
|
490 |
+
return $datafeed_dir;
|
491 |
+
}
|
492 |
+
|
493 |
+
$files = array(
|
494 |
+
array(
|
495 |
+
'file' => 'index.html',
|
496 |
+
'content' => '',
|
497 |
+
),
|
498 |
+
array(
|
499 |
+
'file' => '.htaccess',
|
500 |
+
'content' => 'deny from all',
|
501 |
+
),
|
502 |
+
);
|
503 |
+
|
504 |
+
foreach ( $files as $file ) {
|
505 |
+
if ( \wp_mkdir_p( $datafeed_dir ) && ! file_exists( trailingslashit( $datafeed_dir ) . $file['file'] ) ) {
|
506 |
+
if ( $file_handle = @fopen( trailingslashit( $datafeed_dir ) . $file['file'], 'w' ) ) {
|
507 |
+
fwrite( $file_handle, $file['content'] );
|
508 |
+
fclose( $file_handle );
|
509 |
+
}
|
510 |
+
}
|
511 |
+
}
|
512 |
+
|
513 |
+
if ( ! is_dir( $datafeed_dir ) ) {
|
514 |
+
throw new \Exception( 'Can not create temporary directory for datafeed.' );
|
515 |
+
}
|
516 |
+
|
517 |
+
return $datafeed_dir;
|
518 |
+
}
|
519 |
+
|
520 |
+
protected function detectCsvDelimiter( $file ) {
|
521 |
+
$delimiters = array(
|
522 |
+
';' => 0,
|
523 |
+
',' => 0,
|
524 |
+
"\t" => 0,
|
525 |
+
"|" => 0
|
526 |
+
);
|
527 |
+
|
528 |
+
$handle = fopen( $file, "r" );
|
529 |
+
$firstLine = fgets( $handle );
|
530 |
+
fclose( $handle );
|
531 |
+
foreach ( $delimiters as $delimiter => &$count ) {
|
532 |
+
$count = count( str_getcsv( $firstLine, $delimiter ) );
|
533 |
+
}
|
534 |
+
|
535 |
+
return array_search( max( $delimiters ), $delimiters );
|
536 |
+
}
|
537 |
+
|
538 |
+
public function fatalHandler() {
|
539 |
+
if ( ! $error = error_get_last() ) {
|
540 |
+
return;
|
541 |
+
}
|
542 |
+
|
543 |
+
if ( ! isset( $error['file'] ) || ! strpos( $error['file'], 'AffiliateFeedParserModule.php' ) ) {
|
544 |
+
return;
|
545 |
+
}
|
546 |
+
|
547 |
+
$message = $error['message'];
|
548 |
+
if ( strstr( $message, 'Allowed memory size' ) ) {
|
549 |
+
$message .= '. ' . sprintf( __( 'Your data feed is too large and cannot be imported. Use a smaller feed or increase <a target="_blank" href="%s">WP_MAX_MEMORY_LIMIT</a>.', 'content-egg' ), 'https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php' );
|
550 |
+
}
|
551 |
+
|
552 |
+
$this->setLastImportError( $message );
|
553 |
+
}
|
554 |
+
|
555 |
+
public function deleteTemporaryFiles() {
|
556 |
+
$dir = trailingslashit( $this->getDatafeedDir() );
|
557 |
+
$parts = explode( '/', $dir );
|
558 |
+
if ( $parts[ count( $parts ) - 2 ] !== self::DATAFEED_DIR_NAME ) {
|
559 |
+
throw new \Exception( 'Unexpected error while cleaning temporary directory.' );
|
560 |
+
|
561 |
+
return;
|
562 |
+
}
|
563 |
+
|
564 |
+
$scanned = array_values( array_diff( scandir( $dir ), array( '..', '.', 'index.html', '.htaccess' ) ) );
|
565 |
+
if ( ! $scanned ) {
|
566 |
+
return;
|
567 |
+
}
|
568 |
+
|
569 |
+
global $wp_filesystem;
|
570 |
+
if ( ! $wp_filesystem ) {
|
571 |
+
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
572 |
+
\WP_Filesystem();
|
573 |
+
}
|
574 |
+
|
575 |
+
foreach ( $scanned as $s ) {
|
576 |
+
$path = $dir . $s;
|
577 |
+
|
578 |
+
if ( is_dir( $path ) && ! preg_match( '/-unzipped-dir$/', $path ) ) {
|
579 |
+
continue;
|
580 |
+
}
|
581 |
+
|
582 |
+
if ( is_file( $path ) && pathinfo( $path, PATHINFO_EXTENSION ) !== 'csv' ) {
|
583 |
+
continue;
|
584 |
+
}
|
585 |
+
|
586 |
+
if ( $wp_filesystem->exists( $path ) && time() - filemtime( $path ) > 3600 ) {
|
587 |
+
$wp_filesystem->delete( $path, true );
|
588 |
+
}
|
589 |
+
}
|
590 |
+
}
|
591 |
+
|
592 |
+
public function getProductNode() {
|
593 |
+
$mapping = $this->config( 'mapping' );
|
594 |
+
if ( ! empty( $mapping['product node'] ) ) {
|
595 |
+
return $mapping['product node'];
|
596 |
+
} else {
|
597 |
+
return false;
|
598 |
+
}
|
599 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
|
601 |
}
|
application/components/AffiliateFeedParserModuleConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
@@ -13,83 +13,81 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class AffiliateFeedParserModuleConfig extends AffiliateParserModuleConfig {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
$this->getModuleInstance()->setLastImportError('');
|
83 |
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
}
|
91 |
|
92 |
-
|
93 |
-
|
94 |
|
95 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
13 |
*/
|
14 |
abstract class AffiliateFeedParserModuleConfig extends AffiliateParserModuleConfig {
|
15 |
|
16 |
+
public function options() {
|
17 |
+
$options = array_merge( parent::options(), array(
|
18 |
+
'entries_per_page' => array(
|
19 |
+
'title' => __( 'Results', 'content-egg' ),
|
20 |
+
'description' => __( 'Number of results for one search query.', 'content-egg' ),
|
21 |
+
'callback' => array( $this, 'render_input' ),
|
22 |
+
'default' => 10,
|
23 |
+
'validator' => array(
|
24 |
+
'trim',
|
25 |
+
'absint',
|
26 |
+
array(
|
27 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
28 |
+
'arg' => 100,
|
29 |
+
'message' => sprintf( __( 'The field "%s" can not be more than %d.', 'content-egg' ), 'Results', 100 ),
|
30 |
+
),
|
31 |
+
),
|
32 |
+
),
|
33 |
+
'entries_per_page_update' => array(
|
34 |
+
'title' => __( 'Results for updates', 'content-egg' ),
|
35 |
+
'description' => __( 'Number of results for automatic updates and autoblogging.', 'content-egg' ),
|
36 |
+
'callback' => array( $this, 'render_input' ),
|
37 |
+
'default' => 6,
|
38 |
+
'validator' => array(
|
39 |
+
'trim',
|
40 |
+
'absint',
|
41 |
+
array(
|
42 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
43 |
+
'arg' => 100,
|
44 |
+
'message' => sprintf( __( 'The field "%s" can not be more than %d.', 'content-egg' ), 'Results', 100 ),
|
45 |
+
),
|
46 |
+
),
|
47 |
+
),
|
48 |
+
'partial_url_match' => array(
|
49 |
+
'title' => __( 'Search partial URL', 'content-egg' ),
|
50 |
+
'description' => __( 'Partial URL match', 'content-egg' )
|
51 |
+
. '<p class="description">' . __( 'You can use part of a URL to search for products by URL.', 'content-egg' ) . '</p>',
|
52 |
+
'callback' => array( $this, 'render_checkbox' ),
|
53 |
+
'default' => true,
|
54 |
+
'section' => 'default',
|
55 |
+
),
|
56 |
+
'save_img' => array(
|
57 |
+
'title' => __( 'Save images', 'content-egg' ),
|
58 |
+
'description' => __( 'Save images on server', 'content-egg' ),
|
59 |
+
'callback' => array( $this, 'render_checkbox' ),
|
60 |
+
'default' => false,
|
61 |
+
'section' => 'default',
|
62 |
+
)
|
63 |
+
) );
|
64 |
|
65 |
+
$options['update_mode']['dropdown_options'] = array(
|
66 |
+
'cron' => __( 'Cron', 'content-egg' ) . ' (' . __( 'recommended', 'content-egg' ) . ')',
|
67 |
+
'visit' => __( 'Page view', 'content-egg' ),
|
68 |
+
'visit_cron' => __( 'Page view + Cron', 'content-egg' ),
|
69 |
+
);
|
70 |
|
71 |
+
$options['update_mode']['default'] = 'cron';
|
72 |
+
$options['update_mode']['validator'][] = array(
|
73 |
+
'call' => array( $this, 'emptyLastImportDate' ),
|
74 |
+
);
|
75 |
|
76 |
+
return $options;
|
77 |
+
}
|
78 |
|
79 |
+
public function emptyLastImportDate() {
|
80 |
+
$this->getModuleInstance()->setLastImportDate( 0 );
|
81 |
+
$this->getModuleInstance()->setLastImportError( '' );
|
|
|
82 |
|
83 |
+
// download feed in background
|
84 |
+
$hook = 'cegg_' . $this->getModuleId() . '_init_products';
|
85 |
|
86 |
+
if ( $this->option( 'is_active' ) && ! \wp_next_scheduled( $hook ) ) {
|
87 |
+
\wp_schedule_single_event( time() + 1, $hook, array( 'module_id' => $this->getModuleId() ) );
|
88 |
+
}
|
|
|
89 |
|
90 |
+
return true;
|
91 |
+
}
|
92 |
|
93 |
}
|
application/components/AffiliateParserModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
@@ -15,70 +15,70 @@ use ContentEgg\application\helpers\TextHelper;
|
|
15 |
*/
|
16 |
abstract class AffiliateParserModule extends ParserModule {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
|
84 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
15 |
*/
|
16 |
abstract class AffiliateParserModule extends ParserModule {
|
17 |
|
18 |
+
final public function isAffiliateParser() {
|
19 |
+
return true;
|
20 |
+
}
|
21 |
+
|
22 |
+
public function isCouponParser() {
|
23 |
+
if ( strpos( $this->getName(), 'Coupon' ) !== false || $this->getName() == 'CJ Links' ) {
|
24 |
+
return true;
|
25 |
+
} else {
|
26 |
+
return false;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
public function isProductParser() {
|
31 |
+
return ! $this->isCouponParser();
|
32 |
+
}
|
33 |
+
|
34 |
+
public function isAeParser() {
|
35 |
+
if ( $this->getIdStatic() == 'AE' ) {
|
36 |
+
return true;
|
37 |
+
} else {
|
38 |
+
return false;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
public function isItemsUpdateAvailable() {
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function doRequestItems( array $items ) {
|
47 |
+
throw new \Exception( 'doRequestItems method not implemented yet' );
|
48 |
+
}
|
49 |
+
|
50 |
+
public function presavePrepare( $data, $post_id ) {
|
51 |
+
$data = parent::presavePrepare( $data, $post_id );
|
52 |
+
foreach ( $data as $key => $item ) {
|
53 |
+
$data[ $key ]['percentageSaved'] = 0;
|
54 |
+
if ( ! isset( $data[ $key ]['priceOld'] ) ) {
|
55 |
+
$data[ $key ]['priceOld'] = $item['priceOld'] = 0;
|
56 |
+
}
|
57 |
+
if ( ! empty( $item['priceOld'] ) && $item['priceOld'] <= $item['price'] ) {
|
58 |
+
$data[ $key ]['priceOld'] = 0;
|
59 |
+
}
|
60 |
+
|
61 |
+
if ( ! isset( $data[ $key ]['priceOld'] ) ) {
|
62 |
+
$data[ $key ]['priceOld'] = 0;
|
63 |
+
}
|
64 |
+
if ( $data[ $key ]['priceOld'] && $data[ $key ]['price'] && $data[ $key ]['price'] < $data[ $key ]['priceOld'] ) {
|
65 |
+
$data[ $key ]['percentageSaved'] = floor( ( (float) $data[ $key ]['priceOld'] - (float) $data[ $key ]['price'] ) / (float) $data[ $key ]['priceOld'] * 100 );
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( empty( $data[ $key ]['currency'] ) && ! empty( $item['currencyCode'] ) ) {
|
69 |
+
$data[ $key ]['currency'] = TextHelper::currencyTyping( $item['currencyCode'] );
|
70 |
+
}
|
71 |
+
|
72 |
+
if ( ! empty( $data[ $key ]['domain'] ) ) {
|
73 |
+
$data[ $key ]['merchant'] = \apply_filters( 'content_egg_custom_merchant', $data[ $key ]['merchant'], $data[ $key ]['domain'] );
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
return $data;
|
78 |
+
}
|
79 |
+
|
80 |
+
public function renderUpdatePanel() {
|
81 |
+
|
82 |
+
}
|
83 |
|
84 |
}
|
application/components/AffiliateParserModuleConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
@@ -13,54 +13,51 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class AffiliateParserModuleConfig extends ParserModuleConfig {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
);
|
62 |
-
}
|
63 |
-
|
64 |
|
65 |
|
66 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
13 |
*/
|
14 |
abstract class AffiliateParserModuleConfig extends ParserModuleConfig {
|
15 |
|
16 |
+
public function options() {
|
17 |
+
$options = array(
|
18 |
+
'ttl' => array(
|
19 |
+
'title' => __( 'Update by keyword', 'content-egg' ),
|
20 |
+
'description' => __( 'Lifetime of cache in seconds, after this period products will be updated if you set keyword for updating. 0 - never update', 'content-egg' ),
|
21 |
+
'callback' => array( $this, 'render_input' ),
|
22 |
+
'default' => 2592000,
|
23 |
+
'validator' => array(
|
24 |
+
'trim',
|
25 |
+
'absint',
|
26 |
+
),
|
27 |
+
'section' => 'default',
|
28 |
+
),
|
29 |
+
);
|
30 |
+
|
31 |
+
if ( $this->getModuleInstance()->isItemsUpdateAvailable() ) {
|
32 |
+
$options['ttl_items'] = array(
|
33 |
+
'title' => __( 'Price update', 'content-egg' ),
|
34 |
+
'description' => __( 'Time in seconds for updating prices, availability, etc. 0 - never update', 'content-egg' ),
|
35 |
+
'callback' => array( $this, 'render_input' ),
|
36 |
+
'default' => 604800,
|
37 |
+
'validator' => array(
|
38 |
+
'trim',
|
39 |
+
'absint',
|
40 |
+
),
|
41 |
+
'section' => 'default',
|
42 |
+
);
|
43 |
+
}
|
44 |
+
$options['update_mode'] = array(
|
45 |
+
'title' => __( 'Update mode', 'content-egg' ),
|
46 |
+
'description' => '',
|
47 |
+
'callback' => array( $this, 'render_dropdown' ),
|
48 |
+
'dropdown_options' => array(
|
49 |
+
'visit' => __( 'Page view', 'content-egg' ),
|
50 |
+
'cron' => __( 'Cron', 'content-egg' ),
|
51 |
+
'visit_cron' => __( 'Page view + Cron', 'content-egg' ),
|
52 |
+
),
|
53 |
+
'default' => 'visit',
|
54 |
+
);
|
55 |
+
|
56 |
+
return
|
57 |
+
array_merge(
|
58 |
+
parent::options(), $options
|
59 |
+
);
|
60 |
+
}
|
|
|
|
|
|
|
61 |
|
62 |
|
63 |
}
|
application/components/BlockTemplateManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* BlockTemplateManager class file
|
@@ -13,77 +13,73 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class BlockTemplateManager extends TemplateManager {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
return $file;
|
85 |
-
else
|
86 |
-
return false;
|
87 |
-
}
|
88 |
|
89 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* BlockTemplateManager class file
|
13 |
*/
|
14 |
class BlockTemplateManager extends TemplateManager {
|
15 |
|
16 |
+
const TEMPLATE_DIR = 'templates';
|
17 |
+
const CUSTOM_TEMPLATE_DIR = 'content-egg-templates';
|
18 |
+
const TEMPLATE_PREFIX = 'block_';
|
19 |
+
|
20 |
+
private $module_id;
|
21 |
+
private static $instance = null;
|
22 |
+
|
23 |
+
public static function getInstance() {
|
24 |
+
if ( self::$instance === null ) {
|
25 |
+
self::$instance = new self;
|
26 |
+
}
|
27 |
+
|
28 |
+
return self::$instance;
|
29 |
+
}
|
30 |
+
|
31 |
+
private function __construct() {
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public function getTempatePrefix() {
|
36 |
+
return self::TEMPLATE_PREFIX;
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getTempateDir() {
|
40 |
+
return \ContentEgg\PLUGIN_PATH . self::TEMPLATE_DIR;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getCustomTempateDirs() {
|
44 |
+
return array(
|
45 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, //child theme
|
46 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, // theme
|
47 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR,
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
public function getModuleId() {
|
52 |
+
return $this->module_id;
|
53 |
+
}
|
54 |
+
|
55 |
+
public function getTemplatesList( $short_mode = false ) {
|
56 |
+
$templates = parent::getTemplatesList( $short_mode );
|
57 |
+
$templates = \apply_filters( 'content_egg_block_templates', $templates );
|
58 |
+
|
59 |
+
return $templates;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function render( $view_name, array $_data = array() ) {
|
63 |
+
if ( ! self::isCustomTemplate( $view_name ) ) {
|
64 |
+
$this->enqueueProductsStyle();
|
65 |
+
}
|
66 |
+
|
67 |
+
return parent::render( $view_name, $_data );
|
68 |
+
}
|
69 |
+
|
70 |
+
public function getPartialViewPath( $view_name, $block = false ) {
|
71 |
+
$file = parent::getPartialViewPath( $view_name, $block );
|
72 |
+
if ( $file ) {
|
73 |
+
return $file;
|
74 |
+
}
|
75 |
+
|
76 |
+
// allow render general block templates as partial
|
77 |
+
$file = $this->getViewPath( $view_name );
|
78 |
+
if ( $file ) {
|
79 |
+
return $file;
|
80 |
+
} else {
|
81 |
+
return false;
|
82 |
+
}
|
83 |
+
}
|
|
|
|
|
|
|
|
|
84 |
|
85 |
}
|
application/components/CEWidget.php
CHANGED
@@ -8,8 +8,8 @@ defined('\ABSPATH') || exit;
|
|
8 |
* ProductSearchWidget class file
|
9 |
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
-
* @link
|
12 |
-
* @copyright Copyright ©
|
13 |
*/
|
14 |
abstract class CEWidget extends \WP_Widget {
|
15 |
|
@@ -21,7 +21,7 @@ abstract class CEWidget extends \WP_Widget {
|
|
21 |
|
22 |
public function __construct()
|
23 |
{
|
24 |
-
\add_action('widgets_init', function() {
|
25 |
\register_widget(get_called_class());
|
26 |
});
|
27 |
|
@@ -32,7 +32,10 @@ abstract class CEWidget extends \WP_Widget {
|
|
32 |
$this->settings = $this->settings();
|
33 |
|
34 |
parent::__construct(
|
35 |
-
$this->slug, \esc_html($this->name), array(
|
|
|
|
|
|
|
36 |
);
|
37 |
|
38 |
\add_action('save_post', array($this, 'flushСache'));
|
@@ -57,10 +60,14 @@ abstract class CEWidget extends \WP_Widget {
|
|
57 |
public function setCache($data, $key = 0, $expire = 0)
|
58 |
{
|
59 |
if (!$key)
|
|
|
60 |
$key = 0;
|
|
|
61 |
$cache = \wp_cache_get($this->slug, 'widget');
|
62 |
if (!$cache || !is_array($cache))
|
|
|
63 |
$cache = array();
|
|
|
64 |
$cache[$key] = $data;
|
65 |
\wp_cache_set($this->slug, $cache, 'widget', $expire);
|
66 |
}
|
@@ -69,16 +76,23 @@ abstract class CEWidget extends \WP_Widget {
|
|
69 |
{
|
70 |
$cache = \wp_cache_get($this->slug, 'widget');
|
71 |
if (!$key)
|
|
|
72 |
$key = 0;
|
|
|
73 |
$cache = \wp_cache_get($this->slug, 'widget');
|
74 |
|
75 |
if (!$cache || !is_array($cache))
|
|
|
76 |
$cache = array();
|
|
|
77 |
|
78 |
if (isset($cache[$key]))
|
|
|
79 |
return $cache[$key];
|
80 |
-
else
|
|
|
81 |
return null;
|
|
|
82 |
}
|
83 |
|
84 |
public function flushСache()
|
@@ -91,7 +105,9 @@ abstract class CEWidget extends \WP_Widget {
|
|
91 |
$instance = array();
|
92 |
|
93 |
if (!$this->settings || !is_array($this->settings))
|
|
|
94 |
return array();
|
|
|
95 |
|
96 |
foreach ($this->settings as $key => $setting)
|
97 |
{
|
@@ -100,9 +116,13 @@ abstract class CEWidget extends \WP_Widget {
|
|
100 |
case 'number':
|
101 |
$instance[$key] = absint($new_instance[$key]);
|
102 |
if (isset($setting['min']) && $instance[$key] < $setting['min'])
|
|
|
103 |
$instance[$key] = $setting['min'];
|
|
|
104 |
if (isset($setting['max']) && $instance[$key] > $setting['max'])
|
|
|
105 |
$instance[$key] = $setting['max'];
|
|
|
106 |
break;
|
107 |
case 'textarea':
|
108 |
$instance[$key] = \wp_kses(trim(\wp_unslash($new_instance[$key])), \wp_kses_allowed_html('post'));
|
@@ -111,19 +131,23 @@ abstract class CEWidget extends \WP_Widget {
|
|
111 |
$instance[$key] = empty($new_instance[$key]) ? 0 : 1;
|
112 |
break;
|
113 |
default:
|
114 |
-
$instance[$key] = (!empty($new_instance[$key])) ? \sanitize_text_field($new_instance[$key]) : '';
|
115 |
break;
|
116 |
}
|
117 |
}
|
118 |
|
119 |
$this->flushСache();
|
|
|
120 |
return $instance;
|
121 |
}
|
122 |
|
123 |
public function form($instance)
|
124 |
{
|
125 |
if (!$this->settings || !is_array($this->settings))
|
|
|
126 |
return array();
|
|
|
|
|
127 |
foreach ($this->settings as $key => $setting)
|
128 |
{
|
129 |
$value = isset($instance[$key]) ? $instance[$key] : $setting['default'];
|
@@ -132,8 +156,13 @@ abstract class CEWidget extends \WP_Widget {
|
|
132 |
case 'number' :
|
133 |
?>
|
134 |
<p>
|
135 |
-
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']);
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
137 |
</p>
|
138 |
<?php
|
139 |
break;
|
@@ -141,9 +170,11 @@ abstract class CEWidget extends \WP_Widget {
|
|
141 |
case 'select' :
|
142 |
?>
|
143 |
<p>
|
144 |
-
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']);
|
145 |
-
|
146 |
-
|
|
|
|
|
147 |
<option value="<?php echo \esc_attr($option_key); ?>" <?php \selected($option_key, $value); ?>><?php echo \esc_html($option_value); ?></option>
|
148 |
<?php endforeach; ?>
|
149 |
</select>
|
@@ -154,9 +185,13 @@ abstract class CEWidget extends \WP_Widget {
|
|
154 |
case 'textarea' :
|
155 |
?>
|
156 |
<p>
|
157 |
-
<label for="<?php echo $this->get_field_id($key); ?>"><?php echo $setting['title'];
|
158 |
-
|
159 |
-
<?php
|
|
|
|
|
|
|
|
|
160 |
<small><?php echo esc_html($setting['desc']); ?></small>
|
161 |
<?php endif; ?>
|
162 |
</p>
|
@@ -166,7 +201,9 @@ abstract class CEWidget extends \WP_Widget {
|
|
166 |
case 'checkbox' :
|
167 |
?>
|
168 |
<p>
|
169 |
-
<input class="checkbox" id="<?php echo \esc_attr($this->get_field_id($key)); ?>"
|
|
|
|
|
170 |
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?></label>
|
171 |
</p>
|
172 |
<?php
|
@@ -174,8 +211,11 @@ abstract class CEWidget extends \WP_Widget {
|
|
174 |
default :
|
175 |
?>
|
176 |
<p>
|
177 |
-
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']);
|
178 |
-
|
|
|
|
|
|
|
179 |
</p>
|
180 |
<?php
|
181 |
break;
|
@@ -186,14 +226,17 @@ abstract class CEWidget extends \WP_Widget {
|
|
186 |
public function beforeWidget($args, $instance)
|
187 |
{
|
188 |
$title = \apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
189 |
-
echo $args['before_widget'];
|
190 |
if ($title)
|
191 |
-
|
|
|
|
|
192 |
}
|
193 |
|
194 |
public function afterWidget($args, $instance)
|
195 |
{
|
196 |
-
|
|
|
197 |
}
|
198 |
|
199 |
}
|
8 |
* ProductSearchWidget class file
|
9 |
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link https://www.keywordrush.com
|
12 |
+
* @copyright Copyright © 2022 keywordrush.com
|
13 |
*/
|
14 |
abstract class CEWidget extends \WP_Widget {
|
15 |
|
21 |
|
22 |
public function __construct()
|
23 |
{
|
24 |
+
\add_action('widgets_init', function () {
|
25 |
\register_widget(get_called_class());
|
26 |
});
|
27 |
|
32 |
$this->settings = $this->settings();
|
33 |
|
34 |
parent::__construct(
|
35 |
+
$this->slug, \esc_html($this->name), array(
|
36 |
+
'description' => \esc_html($this->description),
|
37 |
+
'classname' => $this->classname
|
38 |
+
)
|
39 |
);
|
40 |
|
41 |
\add_action('save_post', array($this, 'flushСache'));
|
60 |
public function setCache($data, $key = 0, $expire = 0)
|
61 |
{
|
62 |
if (!$key)
|
63 |
+
{
|
64 |
$key = 0;
|
65 |
+
}
|
66 |
$cache = \wp_cache_get($this->slug, 'widget');
|
67 |
if (!$cache || !is_array($cache))
|
68 |
+
{
|
69 |
$cache = array();
|
70 |
+
}
|
71 |
$cache[$key] = $data;
|
72 |
\wp_cache_set($this->slug, $cache, 'widget', $expire);
|
73 |
}
|
76 |
{
|
77 |
$cache = \wp_cache_get($this->slug, 'widget');
|
78 |
if (!$key)
|
79 |
+
{
|
80 |
$key = 0;
|
81 |
+
}
|
82 |
$cache = \wp_cache_get($this->slug, 'widget');
|
83 |
|
84 |
if (!$cache || !is_array($cache))
|
85 |
+
{
|
86 |
$cache = array();
|
87 |
+
}
|
88 |
|
89 |
if (isset($cache[$key]))
|
90 |
+
{
|
91 |
return $cache[$key];
|
92 |
+
} else
|
93 |
+
{
|
94 |
return null;
|
95 |
+
}
|
96 |
}
|
97 |
|
98 |
public function flushСache()
|
105 |
$instance = array();
|
106 |
|
107 |
if (!$this->settings || !is_array($this->settings))
|
108 |
+
{
|
109 |
return array();
|
110 |
+
}
|
111 |
|
112 |
foreach ($this->settings as $key => $setting)
|
113 |
{
|
116 |
case 'number':
|
117 |
$instance[$key] = absint($new_instance[$key]);
|
118 |
if (isset($setting['min']) && $instance[$key] < $setting['min'])
|
119 |
+
{
|
120 |
$instance[$key] = $setting['min'];
|
121 |
+
}
|
122 |
if (isset($setting['max']) && $instance[$key] > $setting['max'])
|
123 |
+
{
|
124 |
$instance[$key] = $setting['max'];
|
125 |
+
}
|
126 |
break;
|
127 |
case 'textarea':
|
128 |
$instance[$key] = \wp_kses(trim(\wp_unslash($new_instance[$key])), \wp_kses_allowed_html('post'));
|
131 |
$instance[$key] = empty($new_instance[$key]) ? 0 : 1;
|
132 |
break;
|
133 |
default:
|
134 |
+
$instance[$key] = (!empty($new_instance[$key]) ) ? \sanitize_text_field($new_instance[$key]) : '';
|
135 |
break;
|
136 |
}
|
137 |
}
|
138 |
|
139 |
$this->flushСache();
|
140 |
+
|
141 |
return $instance;
|
142 |
}
|
143 |
|
144 |
public function form($instance)
|
145 |
{
|
146 |
if (!$this->settings || !is_array($this->settings))
|
147 |
+
{
|
148 |
return array();
|
149 |
+
}
|
150 |
+
|
151 |
foreach ($this->settings as $key => $setting)
|
152 |
{
|
153 |
$value = isset($instance[$key]) ? $instance[$key] : $setting['default'];
|
156 |
case 'number' :
|
157 |
?>
|
158 |
<p>
|
159 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>
|
160 |
+
:</label>
|
161 |
+
<input class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>"
|
162 |
+
name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="number"
|
163 |
+
min="<?php echo \esc_attr($setting['min']); ?>"
|
164 |
+
max="<?php echo \esc_attr($setting['max']); ?>"
|
165 |
+
value="<?php echo \esc_attr($value); ?>"/>
|
166 |
</p>
|
167 |
<?php
|
168 |
break;
|
170 |
case 'select' :
|
171 |
?>
|
172 |
<p>
|
173 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>
|
174 |
+
:</label>
|
175 |
+
<select class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>"
|
176 |
+
name="<?php echo \esc_attr($this->get_field_name($key)); ?>">
|
177 |
+
<?php foreach ($setting['options'] as $option_key => $option_value) : ?>
|
178 |
<option value="<?php echo \esc_attr($option_key); ?>" <?php \selected($option_key, $value); ?>><?php echo \esc_html($option_value); ?></option>
|
179 |
<?php endforeach; ?>
|
180 |
</select>
|
185 |
case 'textarea' :
|
186 |
?>
|
187 |
<p>
|
188 |
+
<label for="<?php echo esc_attr($this->get_field_id($key)); ?>"><?php echo esc_html($setting['title']); ?>
|
189 |
+
:</label>
|
190 |
+
<textarea class="widefat <?php echo esc_attr($class); ?>"
|
191 |
+
id="<?php echo esc_attr($this->get_field_id($key)); ?>"
|
192 |
+
name="<?php echo esc_attr($this->get_field_name($key)); ?>" cols="20"
|
193 |
+
rows="3"><?php echo esc_textarea($value); ?></textarea>
|
194 |
+
<?php if (isset($setting['desc'])) : ?>
|
195 |
<small><?php echo esc_html($setting['desc']); ?></small>
|
196 |
<?php endif; ?>
|
197 |
</p>
|
201 |
case 'checkbox' :
|
202 |
?>
|
203 |
<p>
|
204 |
+
<input class="checkbox" id="<?php echo \esc_attr($this->get_field_id($key)); ?>"
|
205 |
+
name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="checkbox"
|
206 |
+
value="1" <?php checked($value, 1); ?> />
|
207 |
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?></label>
|
208 |
</p>
|
209 |
<?php
|
211 |
default :
|
212 |
?>
|
213 |
<p>
|
214 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>
|
215 |
+
:</label>
|
216 |
+
<input class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>"
|
217 |
+
name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="text"
|
218 |
+
value="<?php echo \esc_attr($value); ?>">
|
219 |
</p>
|
220 |
<?php
|
221 |
break;
|
226 |
public function beforeWidget($args, $instance)
|
227 |
{
|
228 |
$title = \apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
229 |
+
echo wp_kses_post($args['before_widget']);
|
230 |
if ($title)
|
231 |
+
{
|
232 |
+
echo wp_kses_post($args['before_title'] . $title . $args['after_title']);
|
233 |
+
}
|
234 |
}
|
235 |
|
236 |
public function afterWidget($args, $instance)
|
237 |
{
|
238 |
+
|
239 |
+
echo wp_kses_post($args['after_widget']);
|
240 |
}
|
241 |
|
242 |
}
|
application/components/Config.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Config class file
|
@@ -11,416 +11,421 @@ defined('\ABSPATH') || exit;
|
|
11 |
* @link https://www.keywordrush.com
|
12 |
* @copyright Copyright © 2022 keywordrush.com
|
13 |
*/
|
|
|
14 |
abstract class Config {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
|
|
|
|
|
|
|
|
425 |
|
426 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Config class file
|
11 |
* @link https://www.keywordrush.com
|
12 |
* @copyright Copyright © 2022 keywordrush.com
|
13 |
*/
|
14 |
+
|
15 |
abstract class Config {
|
16 |
|
17 |
+
protected $page_slug;
|
18 |
+
protected $option_name;
|
19 |
+
protected $option_values = array();
|
20 |
+
protected $options = array();
|
21 |
+
protected $input = array();
|
22 |
+
protected $out = array();
|
23 |
+
private static $_instances = array();
|
24 |
+
|
25 |
+
public static function getInstance( $id = null ) {
|
26 |
+
$class = get_called_class();
|
27 |
+
if ( $id ) {
|
28 |
+
$instance_id = $id;
|
29 |
+
} else {
|
30 |
+
$instance_id = $class;
|
31 |
+
}
|
32 |
+
|
33 |
+
if ( ! isset( self::$_instances[ $instance_id ] ) ) {
|
34 |
+
self::$_instances[ $instance_id ] = new $class( $id );
|
35 |
+
}
|
36 |
+
|
37 |
+
return self::$_instances[ $instance_id ];
|
38 |
+
}
|
39 |
+
|
40 |
+
protected function __construct() {
|
41 |
+
$values = \get_option( $this->option_name() );
|
42 |
+
// prevent call validators twice for first time. Settings API bug?
|
43 |
+
if ( $values === false ) {
|
44 |
+
\add_option( $this->option_name(), '' );
|
45 |
+
}
|
46 |
+
|
47 |
+
$this->option_name = $this->option_name();
|
48 |
+
$this->options = $this->options();
|
49 |
+
$this->option_values = $values;
|
50 |
+
$this->page_slug = $this->page_slug();
|
51 |
+
}
|
52 |
+
|
53 |
+
public function option( $opt_name, $default = null ) {
|
54 |
+
if ( $default !== null && ! $this->option_exists( $opt_name ) ) {
|
55 |
+
return $default;
|
56 |
+
}
|
57 |
+
|
58 |
+
return $this->get_current( $opt_name );
|
59 |
+
}
|
60 |
+
|
61 |
+
public function adminInit() {
|
62 |
+
global $pagenow;
|
63 |
+
\add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
64 |
+
|
65 |
+
if ( $pagenow == 'options.php' || ( ! empty( $_GET['page'] ) && sanitize_text_field(wp_unslash($_GET['page'])) == $this->page_slug ) ) {
|
66 |
+
\add_action( 'admin_init', array( $this, 'register_settings' ) );
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
abstract public function page_slug();
|
71 |
+
|
72 |
+
abstract public function option_name();
|
73 |
+
|
74 |
+
abstract protected function options();
|
75 |
+
|
76 |
+
abstract public function add_admin_menu();
|
77 |
+
|
78 |
+
public function get_page_slug() {
|
79 |
+
return $this->page_slug;
|
80 |
+
}
|
81 |
+
|
82 |
+
protected function get_default( $option ) {
|
83 |
+
if ( isset( $this->options[ $option ] ) && isset( $this->options[ $option ]['default'] ) ) {
|
84 |
+
return $this->options[ $option ]['default'];
|
85 |
+
} else {
|
86 |
+
return '';
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
protected function get_validator( $option ) {
|
91 |
+
if ( isset( $this->options[ $option ] ) && isset( $this->options[ $option ]['validator'] ) ) {
|
92 |
+
return $this->options[ $option ]['validator'];
|
93 |
+
} else {
|
94 |
+
return null;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
protected function get_current( $option ) {
|
99 |
+
if ( isset( $this->option_values[ $option ] ) ) {
|
100 |
+
return $this->option_values[ $option ];
|
101 |
+
} elseif ( $this->option_values && $this->is_checkbox( $option ) ) {
|
102 |
+
return false;
|
103 |
+
} else {
|
104 |
+
return $this->get_default( $option );
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
public function register_settings() {
|
109 |
+
\register_setting(
|
110 |
+
$this->page_slug, // group, used for settings_fields()
|
111 |
+
$this->option_name, // option name, used as key in database
|
112 |
+
array( $this, 'validate' ) // validation callback
|
113 |
+
);
|
114 |
+
|
115 |
+
// reinit options for later plugin binding
|
116 |
+
$this->options = $this->options();
|
117 |
+
|
118 |
+
$sections = array();
|
119 |
+
|
120 |
+
foreach ( $this->options as $id => $field ) {
|
121 |
+
if ( empty( $field['title'] ) ) {
|
122 |
+
$field['title'] = '';
|
123 |
+
}
|
124 |
+
if ( empty( $field['description'] ) ) {
|
125 |
+
$field['description'] = '';
|
126 |
+
}
|
127 |
+
$params = array(
|
128 |
+
'name' => $id, // value for 'name' attribute
|
129 |
+
'title' => $field['title'],
|
130 |
+
'description' => $field['description'],
|
131 |
+
'value' => $this->get_current( $id ),
|
132 |
+
'option_name' => $this->option_name,
|
133 |
+
'label_for' => 'label-' . $id,
|
134 |
+
);
|
135 |
+
if ( ! empty( $field['dropdown_options'] ) ) {
|
136 |
+
$params['dropdown_options'] = $field['dropdown_options'];
|
137 |
+
}
|
138 |
+
if ( ! empty( $field['checkbox_options'] ) ) {
|
139 |
+
$params['checkbox_options'] = $field['checkbox_options'];
|
140 |
+
}
|
141 |
+
|
142 |
+
if ( ! empty( $field['render_after'] ) ) {
|
143 |
+
$params['render_after'] = $field['render_after'];
|
144 |
+
}
|
145 |
+
if ( empty( $field['section'] ) ) {
|
146 |
+
$field['section'] = 'default';
|
147 |
+
}
|
148 |
+
|
149 |
+
// section
|
150 |
+
if ( ! isset( $sections[ $field['section'] ] ) ) {
|
151 |
+
if ( $field['section'] == 'default' ) {
|
152 |
+
$section_title = '';
|
153 |
+
} else {
|
154 |
+
$section_title = $field['section'];
|
155 |
+
}
|
156 |
+
|
157 |
+
\add_settings_section( \sanitize_text_field( $field['section'] ), $section_title, null, $this->page_slug );
|
158 |
+
$sections[ $field['section'] ] = $field['section'];
|
159 |
+
}
|
160 |
+
|
161 |
+
\add_settings_field(
|
162 |
+
$id, $field['title'], $field['callback'], $this->page_slug, // menu slug
|
163 |
+
$field['section'], $params
|
164 |
+
);
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
public function render_input( $args ) {
|
169 |
+
if ( ! empty( $args['class'] ) ) {
|
170 |
+
$class = $args['class'];
|
171 |
+
} else {
|
172 |
+
$class = 'regular-text ltr';
|
173 |
+
}
|
174 |
+
if ( ! empty( $args['type'] ) ) {
|
175 |
+
$type = $args['type'];
|
176 |
+
} else {
|
177 |
+
$type = 'text';
|
178 |
+
}
|
179 |
+
echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $args['option_name'] ) . '[' . esc_attr( $args['name'] ) . ']" id="' . esc_attr( $args['label_for'] ) . '" value="' . esc_attr( $args['value'] ) . '" class="' . esc_attr( $class ) . '" />';
|
180 |
+
if ( ! empty( $args['render_after'] ) ) {
|
181 |
+
echo wp_kses_post($args['render_after']);
|
182 |
+
}
|
183 |
+
if ( $args['description'] ) {
|
184 |
+
echo '<p class="description">' . wp_kses_post($args['description']) . '</p>';
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
+
public function render_textarea( $args ) {
|
189 |
+
echo '<textarea name="' . esc_attr( $args['option_name'] ) . '['
|
190 |
+
. esc_attr( $args['name'] ) . ']" id="'
|
191 |
+
. esc_attr( $args['label_for'] ) . '" rows="2" class="large-text code">' . esc_html( $args['value'] ) . '</textarea>';
|
192 |
+
if ( ! empty( $args['render_after'] ) ) {
|
193 |
+
echo wp_kses_post($args['render_after']);
|
194 |
+
}
|
195 |
+
if ( $args['description'] ) {
|
196 |
+
echo '<p class="description">' . wp_kses_post($args['description']) . '</p>';
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
public function render_checkbox( $args ) {
|
201 |
+
if ( (bool) $args['value'] ) {
|
202 |
+
$checked = ' checked="checked" ';
|
203 |
+
} else {
|
204 |
+
$checked = '';
|
205 |
+
}
|
206 |
+
echo '<label for="' . esc_attr( $args['label_for'] ) . '">';
|
207 |
+
echo '<input type="checkbox" name="' . esc_attr( $args['option_name'] ) . '['
|
208 |
+
. esc_attr( $args['name'] ) . ']" id="'
|
209 |
+
. esc_attr( $args['label_for'] ) . '"';
|
210 |
+
if ($checked)
|
211 |
+
echo ' checked="checked" ';
|
212 |
+
echo ' value="1" />';
|
213 |
+
if ( $args['description'] ) {
|
214 |
+
echo ' ' . wp_kses_post($args['description']);
|
215 |
+
}
|
216 |
+
echo '</label>';
|
217 |
+
}
|
218 |
+
|
219 |
+
public function render_dropdown( $args ) {
|
220 |
+
echo '<select name="' . esc_attr( $args['option_name'] ) . '['
|
221 |
+
. esc_attr( $args['name'] ) . ']" id="'
|
222 |
+
. esc_attr( $args['label_for'] ) . '" value="'
|
223 |
+
. esc_attr( $args['value'] ) . '" >';
|
224 |
+
foreach ( $args['dropdown_options'] as $option_value => $option_name ) {
|
225 |
+
if ( $option_value === $args['value'] ) {
|
226 |
+
$selected = ' selected="selected" ';
|
227 |
+
} else {
|
228 |
+
$selected = '';
|
229 |
+
}
|
230 |
+
echo '<option value="' . esc_attr( $option_value ) . '"';
|
231 |
+
if ($selected)
|
232 |
+
echo ' selected="selected" ';
|
233 |
+
echo '>';
|
234 |
+
echo esc_html( $option_name ) . '</option>';
|
235 |
+
}
|
236 |
+
echo '</select>';
|
237 |
+
|
238 |
+
if ( ! empty( $args['render_after'] ) ) {
|
239 |
+
echo wp_kses_post($args['render_after']);
|
240 |
+
}
|
241 |
+
if ( $args['description'] ) {
|
242 |
+
echo '<p class="description">' . wp_kses_post($args['description']). '</p>';
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
public function render_checkbox_list( $args ) {
|
247 |
+
if ( empty( $args['checkbox_options'] ) ) {
|
248 |
+
echo '-';
|
249 |
+
|
250 |
+
return;
|
251 |
+
}
|
252 |
+
|
253 |
+
echo '<div class="cegg-checkboxgroup">';
|
254 |
+
|
255 |
+
if ( $args['checkbox_options'] && is_array( $args['checkbox_options'] ) ) {
|
256 |
+
foreach ( $args['checkbox_options'] as $value => $name ) {
|
257 |
+
if ( in_array( $value, $args['value'] ) ) {
|
258 |
+
$checked = ' checked="checked" ';
|
259 |
+
} else {
|
260 |
+
$checked = '';
|
261 |
+
}
|
262 |
+
|
263 |
+
echo '<div class="cegg-checkbox">';
|
264 |
+
echo '<label for="' . esc_attr( $args['label_for'] . '-' . $value ) . '">';
|
265 |
+
echo '<input type="checkbox" name="' . esc_attr( $args['option_name'] ) . '['
|
266 |
+
. esc_attr( $args['name'] ) . '][' . esc_attr( $value ) . ']" id="'
|
267 |
+
. esc_attr( $args['label_for'] . '-' . $value ), '"';
|
268 |
+
if ($checked)
|
269 |
+
echo ' checked="checked" ';
|
270 |
+
echo ' value="' . esc_attr( $value ) . '" />';
|
271 |
+
echo esc_html( $name );
|
272 |
+
echo '</label>';
|
273 |
+
echo '</div>';
|
274 |
+
}
|
275 |
+
}
|
276 |
+
echo '</div>';
|
277 |
+
if ( $args['description'] ) {
|
278 |
+
echo '<p class="description">' . wp_kses_post($args['description']) . '</p>';
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
public function render_hidden( $args ) {
|
283 |
+
echo '<input type="hidden" name="' . esc_attr( $args['option_name'] ) . '['
|
284 |
+
. esc_attr( $args['name'] ) . '] value="'
|
285 |
+
. esc_attr( $args['value'] ) . '" />';
|
286 |
+
}
|
287 |
+
|
288 |
+
public function render_color_picker( $args ) {
|
289 |
+
echo '<input name="' . esc_attr( $args['option_name'] ) . '['
|
290 |
+
. esc_attr( $args['name'] ) . ']" id="'
|
291 |
+
. esc_attr( $args['label_for'] ) . '" value="'
|
292 |
+
. esc_attr( $args['value'] ) . '" />';
|
293 |
+
if ( ! empty( $args['render_after'] ) ) {
|
294 |
+
echo wp_kses_post($args['render_after']);
|
295 |
+
}
|
296 |
+
if ( $args['description'] ) {
|
297 |
+
echo '<p class="description">' . wp_kses_post($args['description']) . '</p>';
|
298 |
+
}
|
299 |
+
\wp_enqueue_style( 'wp-color-picker' );
|
300 |
+
\wp_enqueue_script( 'wp-color-picker', \admin_url( 'js/color-picker.min.js' ) );
|
301 |
+
echo '<script type="text/javascript">' . "jQuery(document).ready(function($){jQuery('#" . esc_attr( $args['label_for'] ) . "').wpColorPicker();});" . '</script>';
|
302 |
+
}
|
303 |
+
|
304 |
+
public function option_exists( $option ) {
|
305 |
+
if ( array_key_exists( $option, $this->options ) ) {
|
306 |
+
return true;
|
307 |
+
} else {
|
308 |
+
return false;
|
309 |
+
}
|
310 |
+
}
|
311 |
+
|
312 |
+
public function validate( $input ) {
|
313 |
+
$this->input = $input;
|
314 |
+
|
315 |
+
if ( ! is_array( $this->input ) ) {
|
316 |
+
return;
|
317 |
+
}
|
318 |
+
|
319 |
+
foreach ( $this->input as $option => $value ) {
|
320 |
+
if ( ! $this->option_exists( $option ) ) {
|
321 |
+
continue;
|
322 |
+
}
|
323 |
+
|
324 |
+
if ( ! is_array( $value ) ) {
|
325 |
+
$value = trim( $value );
|
326 |
+
}
|
327 |
+
if ( $validator = $this->get_validator( $option ) ) {
|
328 |
+
if ( ! is_array( $validator ) ) {
|
329 |
+
continue;
|
330 |
+
}
|
331 |
+
foreach ( $validator as $v ) {
|
332 |
+
if ( ! is_array( $v ) ) {
|
333 |
+
if ( $v == 'allow_empty' ) {
|
334 |
+
if ( $value === '' ) {
|
335 |
+
break;
|
336 |
+
} else {
|
337 |
+
continue;
|
338 |
+
}
|
339 |
+
}
|
340 |
+
|
341 |
+
// filter
|
342 |
+
$value = call_user_func( $v, $value );
|
343 |
+
} else {
|
344 |
+
// check 'when' condition
|
345 |
+
if ( ! empty( $v['when'] ) ) {
|
346 |
+
$when_value = $this->get_submitted_value( $v['when'] );
|
347 |
+
if ( ! $when_value ) {
|
348 |
+
continue;
|
349 |
+
}
|
350 |
+
}
|
351 |
+
|
352 |
+
if ( ! empty( $v['type'] ) && $v['type'] == 'filter' ) {
|
353 |
+
// filter
|
354 |
+
$value = call_user_func( $v['call'], $value );
|
355 |
+
} else {
|
356 |
+
// validator
|
357 |
+
if ( empty( $v['arg'] ) ) {
|
358 |
+
$res = call_user_func( $v['call'], $value );
|
359 |
+
} else {
|
360 |
+
$res = call_user_func( $v['call'], $value, $v['arg'] );
|
361 |
+
}
|
362 |
+
if ( ! $res ) {
|
363 |
+
\add_settings_error( $option, $option, $v['message'] );
|
364 |
+
$value = $this->get_current( $option );
|
365 |
+
if ( ! empty( $v['when'] ) ) {
|
366 |
+
$this->out[ $v['when'] ] = $this->get_current( $v['when'] );
|
367 |
+
}
|
368 |
+
break;
|
369 |
+
}
|
370 |
+
} // .validator
|
371 |
+
}
|
372 |
+
}
|
373 |
+
}
|
374 |
+
$this->out[ $option ] = $value;
|
375 |
+
}
|
376 |
+
|
377 |
+
return $this->out;
|
378 |
+
}
|
379 |
+
|
380 |
+
public function is_checkbox( $option ) {
|
381 |
+
if ( $this->options[ $option ]['callback'][1] == 'render_checkbox' ) {
|
382 |
+
return true;
|
383 |
+
} else {
|
384 |
+
return false;
|
385 |
+
}
|
386 |
+
}
|
387 |
+
|
388 |
+
/**
|
389 |
+
* Current submitted value
|
390 |
+
*/
|
391 |
+
public function get_submitted_value( $option, $input = array(), $out = array() ) {
|
392 |
+
if ( ! $input ) {
|
393 |
+
$input = $this->input;
|
394 |
+
}
|
395 |
+
if ( ! $out ) {
|
396 |
+
$out = $this->out;
|
397 |
+
}
|
398 |
+
|
399 |
+
if ( ! $this->option_exists( $option ) ) {
|
400 |
+
throw new \Exception( 'Options "' . $option . '" does not exists.' );
|
401 |
+
}
|
402 |
+
|
403 |
+
if ( ! isset( $input[ $option ] ) && $this->is_checkbox( $option ) ) {
|
404 |
+
return false;
|
405 |
+
}
|
406 |
+
|
407 |
+
if ( ! isset( $input[ $option ] ) ) {
|
408 |
+
throw new \Exception( 'Options "' . $option . '" does not exists.' );
|
409 |
+
}
|
410 |
+
|
411 |
+
if ( isset( $out[ $option ] ) ) {
|
412 |
+
return $out[ $option ];
|
413 |
+
} else {
|
414 |
+
return $input[ $option ];
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
public function getOptionsList() {
|
419 |
+
return array_keys( $this->options() );
|
420 |
+
}
|
421 |
+
|
422 |
+
public function getOptionValues() {
|
423 |
+
$result = array();
|
424 |
+
foreach ( $this->getOptionsList() as $option_name ) {
|
425 |
+
$result[ $option_name ] = $this->get_current( $option_name );
|
426 |
+
}
|
427 |
+
|
428 |
+
return $result;
|
429 |
+
}
|
430 |
|
431 |
}
|
application/components/Content.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Content class file
|
@@ -13,13 +13,13 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class Content {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Content class file
|
13 |
*/
|
14 |
class Content {
|
15 |
|
16 |
+
public $unique_id;
|
17 |
+
public $title;
|
18 |
+
public $description;
|
19 |
+
public $img;
|
20 |
+
public $url;
|
21 |
+
//public $redirect;
|
22 |
+
public $last_update;
|
23 |
+
public $extra;
|
24 |
|
25 |
}
|
application/components/ContentCoupon.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ContentCoupon class file
|
@@ -13,11 +13,11 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class ContentCoupon extends Content {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ContentCoupon class file
|
13 |
*/
|
14 |
class ContentCoupon extends Content {
|
15 |
|
16 |
+
public $code;
|
17 |
+
public $startDate;
|
18 |
+
public $endDate;
|
19 |
+
public $domain;
|
20 |
+
public $merchant;
|
21 |
+
public $logo;
|
22 |
|
23 |
}
|
application/components/ContentManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\ImageHelper;
|
8 |
use ContentEgg\application\helpers\ArrayHelper;
|
@@ -22,642 +22,651 @@ use ContentEgg\application\helpers\TextHelper;
|
|
22 |
*/
|
23 |
class ContentManager {
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
662 |
|
663 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\ImageHelper;
|
8 |
use ContentEgg\application\helpers\ArrayHelper;
|
22 |
*/
|
23 |
class ContentManager {
|
24 |
|
25 |
+
const META_PREFIX_DATA = '_cegg_data_';
|
26 |
+
const META_PREFIX_LAST_ITEMS_UPDATE = '_cegg_last_update_';
|
27 |
+
const META_PREFIX_KEYWORD = '_cegg_keyword';
|
28 |
+
const META_PREFIX_UPDATE_PARAMS = '_cegg_update_params';
|
29 |
+
const META_PREFIX_LAST_BYKEYWORD_UPDATE = '_cegg_last_bykeyword_update';
|
30 |
+
|
31 |
+
private static $_view_data = array();
|
32 |
+
|
33 |
+
public static function saveData( array $data, $module_id, $post_id, $is_last_iteration = true ) {
|
34 |
+
if ( ! $data ) {
|
35 |
+
self::deleteData( $module_id, $post_id, $is_last_iteration );
|
36 |
+
return;
|
37 |
+
}
|
38 |
+
|
39 |
+
$data = self::dataPresavePrepare( $data, $module_id, $post_id );
|
40 |
+
$old_data = ContentManager::getData( $post_id, $module_id );
|
41 |
+
|
42 |
+
$outdated = array();
|
43 |
+
$data_changed = true;
|
44 |
+
if ( $old_data ) {
|
45 |
+
$outdated = array_diff_key( $old_data, $data );
|
46 |
+
$new = array_diff_key( $data, $old_data );
|
47 |
+
|
48 |
+
if ( ! $outdated && ! $new ) {
|
49 |
+
$data_changed = false;
|
50 |
+
}
|
51 |
+
/*
|
52 |
+
* we need force data update because title or description can be edited manually or items price update
|
53 |
+
*/
|
54 |
+
}
|
55 |
+
|
56 |
+
// save data
|
57 |
+
\update_post_meta( $post_id, self::META_PREFIX_DATA . $module_id, $data );
|
58 |
+
self::clearData( $outdated );
|
59 |
+
|
60 |
+
// touch last update time only if data changed?
|
61 |
+
if ( $data_changed ) {
|
62 |
+
self::touchUpdateTime( $post_id, $module_id );
|
63 |
+
}
|
64 |
+
|
65 |
+
// save price history
|
66 |
+
if ( GeneralConfig::getInstance()->option( 'price_history_days' ) ) {
|
67 |
+
PriceHistoryModel::model()->saveData( $data, $module_id, $post_id );
|
68 |
+
// ...and send price alerts
|
69 |
+
if ( GeneralConfig::getInstance()->option( 'price_alert_enabled' ) ) {
|
70 |
+
PriceAlert::getInstance()->sendAlerts( $data, $module_id, $post_id );
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
self::resetViewDataCache( $module_id, $post_id );
|
75 |
+
|
76 |
+
\do_action( 'content_egg_save_data', $data, $module_id, $post_id, $is_last_iteration );
|
77 |
+
}
|
78 |
+
|
79 |
+
public static function dataPresavePrepare( array $data, $module_id, $post_id ) {
|
80 |
+
foreach ( $data as $i => $d ) {
|
81 |
+
if ( is_object( $d ) ) {
|
82 |
+
$data[ $i ] = ArrayHelper::object2Array( $d );
|
83 |
+
}
|
84 |
+
}
|
85 |
+
$data = self::setIds( $data );
|
86 |
+
// Sanitize content for allowed HTML tags and more.
|
87 |
+
array_walk_recursive( $data, array( 'self', 'sanitizeData' ) );
|
88 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
89 |
+
$data = $module->presavePrepare( $data, $post_id );
|
90 |
+
|
91 |
+
return $data;
|
92 |
+
}
|
93 |
+
|
94 |
+
public static function deleteData( $module_id, $post_id, $is_last_iteration = true ) {
|
95 |
+
$data = ContentManager::getData( $post_id, $module_id );
|
96 |
+
if ( ! $data ) {
|
97 |
+
// last chance to fire last_iteration hook
|
98 |
+
\do_action( 'content_egg_save_data', array(), $module_id, $post_id, $is_last_iteration );
|
99 |
+
|
100 |
+
return;
|
101 |
+
}
|
102 |
+
|
103 |
+
\delete_post_meta( $post_id, self::META_PREFIX_DATA . $module_id );
|
104 |
+
\delete_post_meta( $post_id, self::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id );
|
105 |
+
\delete_post_meta( $post_id, self::META_PREFIX_LAST_ITEMS_UPDATE . $module_id );
|
106 |
+
|
107 |
+
self::clearData( $data );
|
108 |
+
self::resetViewDataCache( $module_id, $post_id );
|
109 |
+
|
110 |
+
\do_action( 'content_egg_save_data', array(), $module_id, $post_id, $is_last_iteration );
|
111 |
+
}
|
112 |
+
|
113 |
+
private static function clearData( $data ) {
|
114 |
+
// delete old img files if needed
|
115 |
+
foreach ( $data as $d ) {
|
116 |
+
if ( empty( $d['img_file'] ) ) {
|
117 |
+
continue;
|
118 |
+
}
|
119 |
+
$img_file = ImageHelper::getFullImgPath( $d['img_file'] );
|
120 |
+
|
121 |
+
if ( is_file( $img_file ) ) {
|
122 |
+
@unlink( $img_file );
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
|
127 |
+
private static function setIds( $data ) {
|
128 |
+
$results = array();
|
129 |
+
foreach ( $data as $d ) {
|
130 |
+
$results[ $d['unique_id'] ] = $d;
|
131 |
+
}
|
132 |
+
|
133 |
+
return $results;
|
134 |
+
}
|
135 |
+
|
136 |
+
public static function touchUpdateTime( $post_id, $module_id, $touch_items = true ) {
|
137 |
+
$time = time();
|
138 |
+
\update_post_meta( $post_id, self::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id, $time );
|
139 |
+
if ( $touch_items ) {
|
140 |
+
self::touchUpdateItemsTime( $post_id, $module_id, $time );
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
public static function touchUpdateItemsTime( $post_id, $module_id, $time = null ) {
|
145 |
+
if ( ! $time ) {
|
146 |
+
$time = time();
|
147 |
+
}
|
148 |
+
\update_post_meta( $post_id, self::META_PREFIX_LAST_ITEMS_UPDATE . $module_id, $time );
|
149 |
+
}
|
150 |
+
|
151 |
+
private static function sanitizeData( &$data, $key ) {
|
152 |
+
if ( in_array( (string) $key, array( 'img', 'url', 'IFrameURL', 'orig_url' ) ) ) {
|
153 |
+
if ( $key == 'img' ) {
|
154 |
+
$data = \esc_url_raw( $data );
|
155 |
+
} else {
|
156 |
+
$data = \wp_sanitize_redirect( $data );
|
157 |
+
$data = filter_var( $data, FILTER_SANITIZE_URL );
|
158 |
+
}
|
159 |
+
} elseif ( $key === 'description' ) {
|
160 |
+
$data = TextHelper::sanitizeHtml( $data );
|
161 |
+
} elseif ( $key === 'linkHtml' ) {
|
162 |
+
$data = wp_kses_post($data);
|
163 |
+
}
|
164 |
+
elseif ( $key === 'title' ) {
|
165 |
+
$data = \sanitize_text_field( $data );
|
166 |
+
} elseif ( $key === 'last_update' && ! $data ) {
|
167 |
+
$data = time();
|
168 |
+
} elseif ( $key === 'ean' && $data ) {
|
169 |
+
$data = TextHelper::fixEan( sanitize_text_field($data ));
|
170 |
+
} else {
|
171 |
+
$data = wp_strip_all_tags( $data );
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
public static function isDataExists( $post_id, $module_id ) {
|
176 |
+
if ( \get_post_meta( $post_id, ContentManager::META_PREFIX_DATA . $module_id, true ) ) {
|
177 |
+
return true;
|
178 |
+
} else {
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
public static function getData( $post_id, $module_id ) {
|
184 |
+
$data = self::fixData( \get_post_meta( $post_id, ContentManager::META_PREFIX_DATA . $module_id, true ), $module_id );
|
185 |
+
if ( ! $data ) {
|
186 |
+
$data = array();
|
187 |
+
}
|
188 |
+
|
189 |
+
return $data;
|
190 |
+
}
|
191 |
+
|
192 |
+
public static function fixData( $data, $module_id ) {
|
193 |
+
if ( ! $data || ! is_array( $data ) ) {
|
194 |
+
return $data;
|
195 |
+
}
|
196 |
+
|
197 |
+
return $data;
|
198 |
+
}
|
199 |
+
|
200 |
+
public static function getViewData( $module_id, $post_id, $params = array() ) {
|
201 |
+
$data_id = $post_id . '-' . $module_id;
|
202 |
+
if ( ! isset( self::$_view_data[ $data_id ] ) ) {
|
203 |
+
$data = self::getData( $post_id, $module_id );
|
204 |
+
$data = self::dataPreviewPrepare( $data, $module_id, $post_id, $params );
|
205 |
+
|
206 |
+
self::$_view_data[ $data_id ] = $data;
|
207 |
+
}
|
208 |
+
|
209 |
+
$data = self::$_view_data[ $data_id ];
|
210 |
+
|
211 |
+
|
212 |
+
foreach ( $data as $key => $d ) {
|
213 |
+
if ( ! $key ) {
|
214 |
+
unset( $data[ $key ] );
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
// out of stock products
|
219 |
+
$outofstock_product = GeneralConfig::getInstance()->option( 'outofstock_product' );
|
220 |
+
//@see: ModuleViewer::getData for hide_product filter
|
221 |
+
if ( $outofstock_product == 'hide_price' ) {
|
222 |
+
foreach ( $data as $key => $d ) {
|
223 |
+
if ( isset( $d['stock_status'] ) && $d['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
224 |
+
$data[ $key ]['price'] = 0;
|
225 |
+
$data[ $key ]['priceOld'] = 0;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
// locale filter
|
231 |
+
if ( ! empty( $params['locale'] ) ) {
|
232 |
+
if ( strstr( $module_id, 'Amazon' ) && $params['locale'] == 'GB' ) {
|
233 |
+
$params['locale'] = 'UK';
|
234 |
+
}
|
235 |
+
|
236 |
+
foreach ( $data as $key => $d ) {
|
237 |
+
if ( ! isset( $d['extra']['locale'] ) ) {
|
238 |
+
continue;
|
239 |
+
}
|
240 |
+
|
241 |
+
$product_locale = $d['extra']['locale'];
|
242 |
+
|
243 |
+
if ( $module_id == 'Ebay2' ) {
|
244 |
+
$product_locale = str_replace( 'EBAY_', '', $product_locale );
|
245 |
+
}
|
246 |
+
|
247 |
+
if ( strtolower( $product_locale ) != strtolower( $params['locale'] ) ) {
|
248 |
+
unset( $data[ $key ] );
|
249 |
+
}
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
// convert all prices to one currency
|
254 |
+
if ( ! empty( $params['currency'] ) ) {
|
255 |
+
foreach ( $data as $key => $d ) {
|
256 |
+
$rate = CurrencyHelper::getCurrencyRate( $d['currencyCode'], $params['currency'] );
|
257 |
+
if ( ! $rate ) {
|
258 |
+
continue;
|
259 |
+
}
|
260 |
+
|
261 |
+
if ( ! empty( $d['price'] ) ) {
|
262 |
+
$data[ $key ]['price'] = $d['price'] * $rate;
|
263 |
+
$data[ $key ]['currencyCode'] = $params['currency'];
|
264 |
+
}
|
265 |
+
if ( ! empty( $d['priceOld'] ) ) {
|
266 |
+
$data[ $key ]['priceOld'] = $d['priceOld'] * $rate;
|
267 |
+
}
|
268 |
+
}
|
269 |
+
}
|
270 |
+
|
271 |
+
// add_query_arg
|
272 |
+
if ( ! empty( $params['add_query_arg'] ) ) {
|
273 |
+
foreach ( $data as $key => $d ) {
|
274 |
+
if ( isset( $d['url'] ) ) {
|
275 |
+
$data[ $key ]['url'] = \add_query_arg( $params['add_query_arg'], $data[ $key ]['url'] );
|
276 |
+
}
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
return $data;
|
281 |
+
}
|
282 |
+
|
283 |
+
public static function resetViewDataCache( $module_id = null, $post_id = null ) {
|
284 |
+
if ( $module_id && $post_id ) {
|
285 |
+
$data_id = $post_id . '-' . $module_id;
|
286 |
+
if ( isset( self::$_view_data[ $data_id ] ) ) {
|
287 |
+
unset( self::$_view_data[ $data_id ] );
|
288 |
+
}
|
289 |
+
} else {
|
290 |
+
self::$_view_data = array();
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
public static function dataPreviewPrepare( array $data, $module_id, $post_id, $params = array() ) {
|
295 |
+
$is_ssl = \is_ssl();
|
296 |
+
//$http_home_url = str_replace('https://', 'http://', \home_url('/'));
|
297 |
+
foreach ( $data as $key => $d ) {
|
298 |
+
if ( empty( $data[ $key ]['extra'] ) || ! is_array( $data[ $key ]['extra'] ) ) {
|
299 |
+
$data[ $key ]['extra'] = array();
|
300 |
+
}
|
301 |
+
|
302 |
+
// domain fix && logo
|
303 |
+
if ( empty( $d['extra']['domain'] ) && isset( $d['domain'] ) ) {
|
304 |
+
$data[ $key ]['extra']['domain'] = $d['domain'];
|
305 |
+
} elseif ( empty( $d['domain'] ) && isset( $d['extra']['domain'] ) ) {
|
306 |
+
$data[ $key ]['domain'] = $d['extra']['domain'];
|
307 |
+
}
|
308 |
+
if ( empty( $d['extra']['logo'] ) && isset( $d['logo'] ) ) {
|
309 |
+
$data[ $key ]['extra']['logo'] = $d['logo'];
|
310 |
+
} elseif ( empty( $d['logo'] ) && isset( $d['extra']['logo'] ) ) {
|
311 |
+
$data[ $key ]['logo'] = $d['extra']['logo'];
|
312 |
+
}
|
313 |
+
|
314 |
+
// https fix for all images
|
315 |
+
if ( $is_ssl && isset( $data[ $key ]['img'] ) ) {
|
316 |
+
$data[ $key ]['img'] = str_replace( 'http://', '//', $d['img'] );
|
317 |
+
}
|
318 |
+
|
319 |
+
if ( isset( $d['percentageSaved'] ) ) {
|
320 |
+
$d['percentageSaved'] = (float) $d['percentageSaved'];
|
321 |
+
if ( ! $d['percentageSaved'] || $d['percentageSaved'] < 0 || $d['percentageSaved'] >= 100 ) {
|
322 |
+
$d['percentageSaved'] = 0;
|
323 |
+
}
|
324 |
+
$data[ $key ]['percentageSaved'] = round( $d['percentageSaved'] );
|
325 |
+
}
|
326 |
+
|
327 |
+
if ( empty( $d['rating'] ) && isset( $d['extra']['data']['rating'] ) ) {
|
328 |
+
$data[ $key ]['rating'] = $d['extra']['data']['rating'];
|
329 |
+
}
|
330 |
+
|
331 |
+
if ( isset( $data[ $key ]['rating'] ) ) {
|
332 |
+
$data[ $key ]['rating'] = (float) $data[ $key ]['rating'];
|
333 |
+
if ( $data[ $key ]['rating'] < 0 || $data[ $key ]['rating'] > 5 ) {
|
334 |
+
$data[ $key ]['rating'] = 0;
|
335 |
+
}
|
336 |
+
$data[ $key ]['rating'] = round( ( $data[ $key ]['rating'] * 2 ) / 2 );
|
337 |
+
}
|
338 |
+
|
339 |
+
$data[ $key ]['post_id'] = $post_id;
|
340 |
+
$data[ $key ]['module_id'] = $module_id;
|
341 |
+
}
|
342 |
+
|
343 |
+
// local redirect & other
|
344 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
345 |
+
if ( $module->isParser() ) {
|
346 |
+
$data = $module->viewDataPrepare( $data );
|
347 |
+
}
|
348 |
+
|
349 |
+
return \apply_filters( 'cegg_view_data_prepare', $data, $module_id, $post_id, $params );
|
350 |
+
}
|
351 |
+
|
352 |
+
public static function getProductbyUniqueId( $unique_id, $module_id, $post_id, $params = array() ) {
|
353 |
+
$data = self::getViewData( $module_id, $post_id, $params );
|
354 |
+
if ( ! $data ) {
|
355 |
+
return null;
|
356 |
+
}
|
357 |
+
|
358 |
+
if ( isset( $data[ $unique_id ] ) ) {
|
359 |
+
return $data[ $unique_id ];
|
360 |
+
}
|
361 |
+
|
362 |
+
foreach ( $data as $id => $d ) {
|
363 |
+
if ( $unique_id == TextHelper::clearId( $id ) ) {
|
364 |
+
return $data[ $id ];
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
return null;
|
369 |
+
}
|
370 |
+
|
371 |
+
public static function updateByKeyword( $post_id, $module_id ) {
|
372 |
+
$keyword = \get_post_meta( $post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, true );
|
373 |
+
$keyword = \apply_filters( 'cegg_keyword_update', $keyword, $post_id, $module_id );
|
374 |
+
|
375 |
+
if ( ! $keyword ) {
|
376 |
+
return;
|
377 |
+
}
|
378 |
+
|
379 |
+
$updateParams = \get_post_meta( $post_id, ContentManager::META_PREFIX_UPDATE_PARAMS . $module_id, true );
|
380 |
+
if ( ! $updateParams ) {
|
381 |
+
$updateParams = array();
|
382 |
+
}
|
383 |
+
|
384 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
385 |
+
|
386 |
+
// update time in any case...
|
387 |
+
ContentManager::touchUpdateTime( $post_id, $module_id, false );
|
388 |
+
|
389 |
+
try {
|
390 |
+
$data = $module->doMultipleRequests( $keyword, $updateParams, true );
|
391 |
+
|
392 |
+
// nodata!
|
393 |
+
if ( ! $data ) {
|
394 |
+
\do_action( 'cegg_keyword_update_no_data', $post_id, $module_id );
|
395 |
+
|
396 |
+
return;
|
397 |
+
}
|
398 |
+
} catch ( \Exception $e ) {
|
399 |
+
// error
|
400 |
+
return;
|
401 |
+
}
|
402 |
+
|
403 |
+
$data = array_map( array( 'self', 'object2Array' ), $data );
|
404 |
+
ContentManager::saveData( $data, $module_id, $post_id );
|
405 |
+
}
|
406 |
+
|
407 |
+
public static function updateItems( $post_id, $module_id ) {
|
408 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
409 |
+
if ( ! $module->isItemsUpdateAvailable() ) {
|
410 |
+
return;
|
411 |
+
}
|
412 |
+
|
413 |
+
$items = ContentManager::getData( $post_id, $module_id );
|
414 |
+
|
415 |
+
if ( ! $items ) {
|
416 |
+
return;
|
417 |
+
}
|
418 |
+
|
419 |
+
try {
|
420 |
+
$updated_data = $module->doRequestItems( $items );
|
421 |
+
} catch ( \Exception $e ) {
|
422 |
+
// error
|
423 |
+
ContentManager::touchUpdateItemsTime( $post_id, $module_id );
|
424 |
+
|
425 |
+
return;
|
426 |
+
}
|
427 |
+
|
428 |
+
$time = time();
|
429 |
+
foreach ( $updated_data as $key => $data ) {
|
430 |
+
$updated_data[ $key ]['last_update'] = $time;
|
431 |
+
}
|
432 |
+
|
433 |
+
// save & update time
|
434 |
+
ContentManager::saveData( $updated_data, $module_id, $post_id );
|
435 |
+
ContentManager::touchUpdateItemsTime( $post_id, $module_id );
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Full depth recursive conversion to array
|
440 |
+
*
|
441 |
+
* @param type $object
|
442 |
+
*
|
443 |
+
* @return array
|
444 |
+
*/
|
445 |
+
public static function object2Array( $object ) {
|
446 |
+
return json_decode( json_encode( $object ), true );
|
447 |
+
}
|
448 |
+
|
449 |
+
public static function getNormalizedReviews( $data ) {
|
450 |
+
$struct = array(
|
451 |
+
'summary' => '',
|
452 |
+
'comment' => '',
|
453 |
+
'rating' => '',
|
454 |
+
'name' => '',
|
455 |
+
'date' => '',
|
456 |
+
'pros' => '',
|
457 |
+
'cons' => '',
|
458 |
+
'review' => '',
|
459 |
+
'parent_id' => '',
|
460 |
+
);
|
461 |
+
|
462 |
+
$reviews = array();
|
463 |
+
foreach ( $data as $item ) {
|
464 |
+
if ( is_object( $item ) ) {
|
465 |
+
$item = ContentManager::object2Array( $item );
|
466 |
+
}
|
467 |
+
|
468 |
+
// AE modules & walmart
|
469 |
+
if ( ! empty( $item['extra']['comments'] ) ) {
|
470 |
+
foreach ( $item['extra']['comments'] as $r ) {
|
471 |
+
$review = $struct;
|
472 |
+
$review['comment'] = $r['comment'];
|
473 |
+
if ( ! empty( $r['name'] ) ) {
|
474 |
+
$review['name'] = $r['name'];
|
475 |
+
}
|
476 |
+
if ( ! empty( $r['date'] ) ) {
|
477 |
+
$review['date'] = $r['date'];
|
478 |
+
}
|
479 |
+
if ( ! empty( $r['review'] ) ) {
|
480 |
+
$review['review'] = $r['review'];
|
481 |
+
}
|
482 |
+
if ( ! empty( $r['rating'] ) ) {
|
483 |
+
$review['rating'] = $r['rating'];
|
484 |
+
}
|
485 |
+
if ( ! empty( $r['pros'] ) ) {
|
486 |
+
$review['pros'] = $r['pros'];
|
487 |
+
}
|
488 |
+
if ( ! empty( $r['cons'] ) ) {
|
489 |
+
$review['cons'] = $r['cons'];
|
490 |
+
}
|
491 |
+
if ( isset( $r['parent_id'] ) ) {
|
492 |
+
$review['parent_id'] = (int) $r['parent_id'];
|
493 |
+
}
|
494 |
+
|
495 |
+
$reviews[] = $review;
|
496 |
+
}
|
497 |
+
} // Ozon
|
498 |
+
elseif ( ! empty( $item['extra']['Reviews'] ) ) {
|
499 |
+
foreach ( $item['extra']['Reviews'] as $r ) {
|
500 |
+
$review = $struct;
|
501 |
+
$review['summary'] = $r->Title;
|
502 |
+
$review['date'] = $r->Date;
|
503 |
+
$review['rating'] = $r->Rate;
|
504 |
+
$review['comment'] = $r->Comment;
|
505 |
+
$review['name'] = $r->FIO;
|
506 |
+
$reviews[] = $review;
|
507 |
+
}
|
508 |
+
}
|
509 |
+
}
|
510 |
+
|
511 |
+
foreach ( $reviews as $i => $review ) {
|
512 |
+
if ( ! $review['comment'] ) {
|
513 |
+
if ( $review['review'] ) {
|
514 |
+
$review['comment'] = $review['review'];
|
515 |
+
}
|
516 |
+
if ( $review['pros'] ) {
|
517 |
+
$review['comment'] .= "\r\n" . __( 'Pros:', 'content-egg-tpl' ) . $review['pros'];
|
518 |
+
}
|
519 |
+
if ( $review['cons'] ) {
|
520 |
+
$review['comment'] .= "\r\n" . __( 'Cons:', 'content-egg-tpl' ) . $review['cons'];
|
521 |
+
}
|
522 |
+
$review['comment'] = trim( $review['comment'] );
|
523 |
+
$reviews[ $i ] = $review;
|
524 |
+
}
|
525 |
+
}
|
526 |
+
|
527 |
+
return $reviews;
|
528 |
+
}
|
529 |
+
|
530 |
+
public static function removeReviews( $data ) {
|
531 |
+
foreach ( $data as $i => $item ) {
|
532 |
+
if ( ! empty( $item['extra']['comments'] ) ) {
|
533 |
+
$data[ $i ]['extra']['comments'] = array();
|
534 |
+
} elseif ( ! empty( $item['extra']['Reviews'] ) ) {
|
535 |
+
$data[ $i ]['extra']['Reviews'] = array();
|
536 |
+
}
|
537 |
+
}
|
538 |
+
|
539 |
+
return $data;
|
540 |
+
}
|
541 |
+
|
542 |
+
public static function saveReviewsAsComments( $post_id, array $normalized_comments ) {
|
543 |
+
$comment_data = array(
|
544 |
+
'comment_post_ID' => $post_id,
|
545 |
+
'comment_author_email' => '',
|
546 |
+
'comment_author_url' => '',
|
547 |
+
'comment_type' => '',
|
548 |
+
'comment_parent' => 0,
|
549 |
+
'user_id' => 0,
|
550 |
+
'comment_approved' => 1,
|
551 |
+
);
|
552 |
+
|
553 |
+
$is_rehub_theme = ( in_array( basename( \get_template_directory() ), array(
|
554 |
+
'rehub',
|
555 |
+
'rehub-theme'
|
556 |
+
) ) ) ? true : false;
|
557 |
+
$rehub_post_type = \get_post_meta( $post_id, 'rehub_framework_post_type', true );
|
558 |
+
|
559 |
+
if ( $rehub_post_type && $rehub_post_type == 'review' ) {
|
560 |
+
$is_review_post_type = true;
|
561 |
+
} else {
|
562 |
+
$is_review_post_type = false;
|
563 |
+
}
|
564 |
+
|
565 |
+
if ( \get_post_type( $post_id ) == 'product' ) {
|
566 |
+
$is_woo_product = true;
|
567 |
+
$comment_data['comment_type'] = 'review';
|
568 |
+
} else {
|
569 |
+
$is_woo_product = false;
|
570 |
+
}
|
571 |
+
|
572 |
+
$comments_keys_map = array();
|
573 |
+
|
574 |
+
foreach ( $normalized_comments as $i => $comment ) {
|
575 |
+
$comment_pros = '';
|
576 |
+
$comment_cons = '';
|
577 |
+
$comment_rating = 0;
|
578 |
+
|
579 |
+
// rehub comment meta
|
580 |
+
if ( $is_rehub_theme && $is_review_post_type && ! empty( $comment['review'] ) ) {
|
581 |
+
$comment_content = $comment['review'];
|
582 |
+
} else {
|
583 |
+
$comment_content = $comment['comment'];
|
584 |
+
}
|
585 |
+
|
586 |
+
$comment_data['comment_content'] = \wp_kses( $comment_content, 'default' );
|
587 |
+
if ( ! empty( $comment['name'] ) ) {
|
588 |
+
$comment_data['comment_author'] = $comment['name'];
|
589 |
+
}
|
590 |
+
|
591 |
+
if ( ! empty( $comment['date'] ) ) {
|
592 |
+
$comment_data['comment_date'] = date( 'Y-m-d H:i:s', $comment['date'] );
|
593 |
+
}
|
594 |
+
|
595 |
+
if ( isset( $comment['parent_id'] ) && is_numeric( $comment['parent_id'] ) && isset( $comments_keys_map[ $comment['parent_id'] ] ) ) {
|
596 |
+
$comment_data['comment_parent'] = $comments_keys_map[ $comment['parent_id'] ];
|
597 |
+
} else {
|
598 |
+
$comment_data['comment_parent'] = 0;
|
599 |
+
}
|
600 |
+
|
601 |
+
$comment_id = \wp_insert_comment( $comment_data );
|
602 |
+
|
603 |
+
//$comment_id = \wp_new_comment($comment_data);
|
604 |
+
$comments_keys_map[ $i ] = $comment_id;
|
605 |
+
|
606 |
+
if ( $is_rehub_theme && $is_review_post_type ) {
|
607 |
+
if ( ! empty( $comment['pros'] ) ) {
|
608 |
+
\add_comment_meta( $comment_id, 'pros_review', $comment['pros'] );
|
609 |
+
}
|
610 |
+
if ( ! empty( $comment['cons'] ) ) {
|
611 |
+
\add_comment_meta( $comment_id, 'cons_review', $comment['cons'] );
|
612 |
+
}
|
613 |
+
if ( ! empty( $comment['rating'] ) ) {
|
614 |
+
$rating_value = $comment['rating'] * 2;
|
615 |
+
\add_comment_meta( $comment_id, 'user_average', $rating_value );
|
616 |
+
\add_comment_meta( $comment_id, 'user_criteria', array(
|
617 |
+
array(
|
618 |
+
'name' => __( 'Rating', 'content-egg-tpl' ),
|
619 |
+
'value' => $rating_value
|
620 |
+
)
|
621 |
+
) );
|
622 |
+
}
|
623 |
+
\add_comment_meta( $comment_id, 'counted', 0 );
|
624 |
+
// calculate rating
|
625 |
+
if ( function_exists( 'add_comment_rates' ) ) {
|
626 |
+
\add_comment_rates( $comment_id );
|
627 |
+
}
|
628 |
+
}
|
629 |
+
|
630 |
+
if ( $is_woo_product && ! empty( $comment['rating'] ) && $comment['rating'] > 0 && $comment['rating'] <= 5 ) {
|
631 |
+
\add_comment_meta( $comment_id, 'rating', $comment['rating'], true );
|
632 |
+
}
|
633 |
+
}
|
634 |
+
|
635 |
+
if ( $is_woo_product ) {
|
636 |
+
\update_post_meta( $post_id, '_wc_review_count', count( $normalized_comments ) );
|
637 |
+
}
|
638 |
+
|
639 |
+
if ( $is_woo_product && class_exists( '\WC_Comments' ) ) {
|
640 |
+
\WC_Comments::clear_transients( $post_id );
|
641 |
+
}
|
642 |
+
}
|
643 |
+
|
644 |
+
public static function getMainProduct( $modules_data, $main_product_selector = 'min_price' ) {
|
645 |
+
$all_items = array();
|
646 |
+
foreach ( $modules_data as $module_id => $items ) {
|
647 |
+
foreach ( $items as $item ) {
|
648 |
+
$item = ArrayHelper::object2Array( $item );
|
649 |
+
$item['module_id'] = $module_id;
|
650 |
+
$all_items[] = $item;
|
651 |
+
}
|
652 |
+
}
|
653 |
+
|
654 |
+
if ( ! $all_items ) {
|
655 |
+
return null;
|
656 |
+
}
|
657 |
+
if ( $main_product_selector == 'random' ) {
|
658 |
+
return $all_items[ array_rand( $all_items ) ];
|
659 |
+
}
|
660 |
+
|
661 |
+
if ( $main_product_selector == 'max_price' ) {
|
662 |
+
$order = 'desc';
|
663 |
+
} else {
|
664 |
+
$order = 'asc';
|
665 |
+
}
|
666 |
+
|
667 |
+
$sorted = TemplateHelper::sortByPrice( $all_items, $order );
|
668 |
+
|
669 |
+
return $sorted[0];
|
670 |
+
}
|
671 |
|
672 |
}
|
application/components/ContentProduct.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ContentProduct class file
|
@@ -13,33 +13,33 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class ContentProduct extends Content {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ContentProduct class file
|
13 |
*/
|
14 |
class ContentProduct extends Content {
|
15 |
|
16 |
+
const STOCK_STATUS_IN_STOCK = 1;
|
17 |
+
const STOCK_STATUS_OUT_OF_STOCK = - 1;
|
18 |
+
const STOCK_STATUS_UNKNOWN = 0;
|
19 |
|
20 |
+
public $price;
|
21 |
+
public $priceOld;
|
22 |
+
public $percentageSaved;
|
23 |
+
public $currency;
|
24 |
+
public $currencyCode;
|
25 |
+
public $manufacturer;
|
26 |
+
public $category;
|
27 |
+
public $categoryPath = array();
|
28 |
+
public $merchant;
|
29 |
+
public $logo;
|
30 |
+
public $domain;
|
31 |
+
public $rating;
|
32 |
+
public $reviewsCount;
|
33 |
+
public $availability;
|
34 |
+
public $orig_url;
|
35 |
+
public $ean;
|
36 |
+
public $upc;
|
37 |
+
public $sku;
|
38 |
+
public $isbn;
|
39 |
+
public $woo_sync;
|
40 |
+
public $woo_attr;
|
41 |
+
public $features = array();
|
42 |
+
public $stock_status;
|
43 |
+
public $group;
|
44 |
|
45 |
}
|
application/components/Cpa.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Cpa class file
|
@@ -13,203 +13,207 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class Cpa {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
214 |
|
215 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Cpa class file
|
13 |
*/
|
14 |
class Cpa {
|
15 |
|
16 |
+
const CPA_ADMITAD = 'admitad';
|
17 |
+
const CPA_GDESLON = 'gdeslon';
|
18 |
+
const CPA_ACTIONPAY = 'actionpay';
|
19 |
+
const CPA_CITYADS = 'cityads';
|
20 |
+
const CPA_SHOPOZZ = 'shopozz';
|
21 |
+
const CPA_SHOPOTAM = 'shopotam';
|
22 |
+
const CPA_EPNBZ = 'epnbz';
|
23 |
+
const CPA_SALESDOUBLER = 'salesdoubler';
|
24 |
+
const CPA_RAKUTEN_LINKSHARE = 'rakuten';
|
25 |
+
|
26 |
+
private static $cpa = array(
|
27 |
+
Cpa::CPA_ADMITAD => array(
|
28 |
+
'uri' => 'https://www.admitad.com/ru/promo/?ref=770f943d83',
|
29 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=admitad.ru',
|
30 |
+
'name' => 'Admitad'
|
31 |
+
),
|
32 |
+
Cpa::CPA_GDESLON => array(
|
33 |
+
'uri' => 'http://gdeslon.ru?welcome_token=TPWB4d6UbMDVFJ2u',
|
34 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=gdeslon.ru',
|
35 |
+
'name' => 'Где Слон?'
|
36 |
+
),
|
37 |
+
Cpa::CPA_ACTIONPAY => array(
|
38 |
+
'uri' => 'http://actionpay.ru/ref:NzI2MzEzOTA2Nzcz',
|
39 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=actionpay.ru',
|
40 |
+
'name' => 'Actionpay'
|
41 |
+
),
|
42 |
+
Cpa::CPA_CITYADS => array(
|
43 |
+
'uri' => 'http://cityads.ru/?ref=db07c7e1',
|
44 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=cityads.ru',
|
45 |
+
'name' => 'CityAds'
|
46 |
+
),
|
47 |
+
Cpa::CPA_SHOPOZZ => array(
|
48 |
+
'uri' => 'http://shopozz.ru/affiliate/?src=e77c7b588569860fddcbe6e3d528295d',
|
49 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=shopozz.ru',
|
50 |
+
'name' => 'Shopozz'
|
51 |
+
),
|
52 |
+
Cpa::CPA_SHOPOTAM => array(
|
53 |
+
'uri' => 'https://shopotam.ru/?puebtdid=866987',
|
54 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=shopotam.ru',
|
55 |
+
'name' => 'Shopotam'
|
56 |
+
),
|
57 |
+
Cpa::CPA_EPNBZ => array(
|
58 |
+
'uri' => 'https://epn.bz/?i=6cb6d',
|
59 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=epn.bz',
|
60 |
+
'name' => 'Epn.bz'
|
61 |
+
),
|
62 |
+
Cpa::CPA_SALESDOUBLER => array(
|
63 |
+
'uri' => 'https://www.salesdoubler.com.ua/affiliate/signup/?ref=30170',
|
64 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=salesdoubler.com.ua',
|
65 |
+
'name' => 'Salesdoubler'
|
66 |
+
),
|
67 |
+
Cpa::CPA_RAKUTEN_LINKSHARE => array(
|
68 |
+
'uri' => 'https://signup.linkshare.com/publishers/registration/landing',
|
69 |
+
'ico' => 'https://www.google.com/s2/favicons?domain=salesdoubler.com.ua',
|
70 |
+
'name' => 'Rakuten Linkshare'
|
71 |
+
),
|
72 |
+
);
|
73 |
+
|
74 |
+
static public function deeplinkPrepare( $deeplink ) {
|
75 |
+
// multiple deeplink
|
76 |
+
if ( strstr( $deeplink, ';' ) ) {
|
77 |
+
return $deeplink;
|
78 |
+
}
|
79 |
+
|
80 |
+
$cpa = array(
|
81 |
+
'ad.admitad.com' => 'ulp',
|
82 |
+
'modato.ru' => 'ulp', // lamoda admitad?
|
83 |
+
'f.gdeslon.ru' => 'goto',
|
84 |
+
'cityadspix.com' => 'url',
|
85 |
+
'www.cityads.ru' => 'url',
|
86 |
+
'epnclick.ru' => 'to',
|
87 |
+
'alipromo.com' => 'to', //epn.bz
|
88 |
+
//'click.linksynergy.com' => 'murl',
|
89 |
+
//'click.linksynergy.com' => 'RD_PARM1',
|
90 |
+
);
|
91 |
+
|
92 |
+
$p = parse_url( $deeplink );
|
93 |
+
|
94 |
+
if ( $p === false || empty( $p['host'] ) ) {
|
95 |
+
return $deeplink;
|
96 |
+
}
|
97 |
+
|
98 |
+
$host = $p['host'];
|
99 |
+
|
100 |
+
if ( $host == 'n.actionpay.ru' ) {
|
101 |
+
return str_replace( 'url=example.com', 'url=', $deeplink );
|
102 |
+
}
|
103 |
+
|
104 |
+
if ( array_key_exists( $host, $cpa ) ) {
|
105 |
+
$param = $cpa[ $host ];
|
106 |
+
if ( ! empty( $p['query'] ) ) {
|
107 |
+
parse_str( $p['query'], $query );
|
108 |
+
} else {
|
109 |
+
$query = array();
|
110 |
+
}
|
111 |
+
if ( isset( $query[ $param ] ) ) {
|
112 |
+
unset( $query[ $param ] );
|
113 |
+
}
|
114 |
+
$url = $p['scheme'] . '://' . $p['host'] . $p['path'] . '?';
|
115 |
+
if ( $query ) {
|
116 |
+
$url .= http_build_query( $query ) . '&';
|
117 |
+
}
|
118 |
+
$url .= $param . '=';
|
119 |
+
|
120 |
+
return $url;
|
121 |
+
}
|
122 |
+
|
123 |
+
return $deeplink;
|
124 |
+
}
|
125 |
+
|
126 |
+
static public function getCpaString( $shop_id ) {
|
127 |
+
$shop = ShopManager::getInstance()->getItem( $shop_id );
|
128 |
+
if ( empty( $shop->cpa ) ) {
|
129 |
+
return '';
|
130 |
+
}
|
131 |
+
$str = '';
|
132 |
+
foreach ( $shop->cpa as $cpa ) {
|
133 |
+
$str .= '<a target="_blank" href="' . self::getCpaLink( $cpa ) . '">';
|
134 |
+
$str .= '<img src="' . self::getCpaIco( $cpa ) . '" title="' . self::getCpaName( $cpa ) . '" />';
|
135 |
+
$str .= '</a> ';
|
136 |
+
}
|
137 |
+
|
138 |
+
return $str;
|
139 |
+
}
|
140 |
+
|
141 |
+
static public function getCpaLink( $cpa ) {
|
142 |
+
if ( ! empty( self::$cpa[ $cpa ] ) ) {
|
143 |
+
return self::$cpa[ $cpa ]['uri'];
|
144 |
+
} else {
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
static public function getCpaIco( $cpa ) {
|
150 |
+
if ( ! empty( self::$cpa[ $cpa ] ) ) {
|
151 |
+
return self::$cpa[ $cpa ]['ico'];
|
152 |
+
} else {
|
153 |
+
return false;
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
static public function getCpaName( $cpa ) {
|
158 |
+
if ( ! empty( self::$cpa[ $cpa ] ) ) {
|
159 |
+
return self::$cpa[ $cpa ]['name'];
|
160 |
+
} else {
|
161 |
+
return false;
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
static public function deeplinkSetSubid( $deeplink, $subid, $priority = 0 ) {
|
166 |
+
|
167 |
+
$cpa = array(
|
168 |
+
'ad.admitad.com' => 'subid',
|
169 |
+
'modato.ru' => 'subid', // lamoda admitad?
|
170 |
+
'f.gdeslon.ru' => 'sub_id',
|
171 |
+
'cityadspix.com' => 'sa',
|
172 |
+
'www.cityads.ru' => 'sa',
|
173 |
+
'epnclick.ru' => 'sub',
|
174 |
+
'click.linksynergy.com' => 'subid',
|
175 |
+
);
|
176 |
+
|
177 |
+
$p = parse_url( $deeplink );
|
178 |
+
if ( $p === false || ! isset( $p['host'] ) ) {
|
179 |
+
return $deeplink;
|
180 |
+
}
|
181 |
+
|
182 |
+
$host = $p['host'];
|
183 |
+
|
184 |
+
//actionpay передает subid через path, остальные через query
|
185 |
+
if ( $host == 'n.actionpay.ru' ) {
|
186 |
+
return str_replace( '/subaccount', '/' . $subid, $deeplink );
|
187 |
+
}
|
188 |
+
|
189 |
+
|
190 |
+
if ( array_key_exists( $host, $cpa ) ) {
|
191 |
+
$param = $cpa[ $host ];
|
192 |
+
if ( ! empty( $p['query'] ) ) {
|
193 |
+
parse_str( $p['query'], $query );
|
194 |
+
} else {
|
195 |
+
$query = array();
|
196 |
+
}
|
197 |
+
|
198 |
+
$url = $p['scheme'] . '://' . $p['host'] . $p['path'] . '?';
|
199 |
+
|
200 |
+
if ( ! isset( $query[ $param ] ) || $query[ $param ] == '' || $priority == 1 ) {
|
201 |
+
unset( $query[ $param ] );
|
202 |
+
$url .= $param . '=' . $subid . '&';
|
203 |
+
}
|
204 |
+
|
205 |
+
if ( $query ) {
|
206 |
+
$url .= http_build_query( $query );
|
207 |
+
}
|
208 |
+
|
209 |
+
return $url;
|
210 |
+
}
|
211 |
+
|
212 |
+
return $deeplink;
|
213 |
+
}
|
214 |
+
|
215 |
+
public static function getCpaIds() {
|
216 |
+
return array_keys( self::$cpa );
|
217 |
+
}
|
218 |
|
219 |
}
|
application/components/ExternalFeaturedImage.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
use ContentEgg\application\components\FeaturedImage;
|
@@ -16,269 +16,284 @@ use ContentEgg\application\components\FeaturedImage;
|
|
16 |
*/
|
17 |
class ExternalFeaturedImage {
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
use ContentEgg\application\components\FeaturedImage;
|
16 |
*/
|
17 |
class ExternalFeaturedImage {
|
18 |
|
19 |
+
const EXTERNAL_URL_META = '_cegg_thumbnail_external';
|
20 |
+
const FAKE_INT_START = '99999';
|
21 |
+
|
22 |
+
public static function initAction() {
|
23 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'disabled' ) {
|
24 |
+
return;
|
25 |
+
}
|
26 |
+
|
27 |
+
\add_filter( 'get_post_metadata', array( __CLASS__, 'getFakeThumbnailId' ), 10, 4 );
|
28 |
+
|
29 |
+
if ( \is_admin() ) {
|
30 |
+
\add_filter( 'admin_post_thumbnail_html', array( __CLASS__, 'adminThumbnail' ) );
|
31 |
+
}
|
32 |
+
|
33 |
+
\add_filter( 'wp_get_attachment_image_src', array( __CLASS__, 'replaceImageSrc' ), 10, 4 );
|
34 |
+
\add_filter( 'woocommerce_product_get_image_id', array( __CLASS__, 'getFakeImageId' ), 99, 2 );
|
35 |
+
\add_filter( 'post_thumbnail_html', array( __CLASS__, 'replaceThumbnail' ), 10, 5 );
|
36 |
+
\add_action( 'wpseo_add_opengraph_images', array( __CLASS__, 'addOpengraphImage' ) );
|
37 |
+
\add_action( 'woocommerce_structured_data_product', array( __CLASS__, 'addStructuredDataProduct' ), 10, 2 );
|
38 |
+
\add_action( 'content_egg_save_data', array( __CLASS__, 'setImage' ), 13, 4 );
|
39 |
+
}
|
40 |
+
|
41 |
+
private static function generateFakeId( $post_id ) {
|
42 |
+
$max_len = strlen( strval( PHP_INT_MAX ) ) - 1;
|
43 |
+
$post_id_len = strlen( strval( $post_id ) );
|
44 |
+
|
45 |
+
$fake_id = self::FAKE_INT_START;
|
46 |
+
$fake_id .= str_repeat( '0', $max_len - $post_id_len - strlen( $fake_id ) );
|
47 |
+
$fake_id .= $post_id;
|
48 |
+
|
49 |
+
return $fake_id;
|
50 |
+
}
|
51 |
+
|
52 |
+
private static function getRealId( $post_id ) {
|
53 |
+
if ( strlen( strval( $post_id ) ) != strlen( strval( PHP_INT_MAX ) ) - 1 ) {
|
54 |
+
return false;
|
55 |
+
}
|
56 |
+
|
57 |
+
if ( substr( (string) $post_id, 0, strlen( self::FAKE_INT_START ) ) != self::FAKE_INT_START ) {
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
|
61 |
+
return (int) substr_replace( (string) $post_id, '', 0, strlen( self::FAKE_INT_START ) );
|
62 |
+
}
|
63 |
+
|
64 |
+
public static function setImage( $data, $module_id, $post_id, $is_last_iteration ) {
|
65 |
+
if ( \get_post_type( $post_id ) == 'product' ) {
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( ! $is_last_iteration ) {
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
|
73 |
+
self::setExternalFeaturedImage( $post_id );
|
74 |
+
}
|
75 |
+
|
76 |
+
public static function setExternalFeaturedImage( $post_id, $item = null ) {
|
77 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'enabled_internal_priority' && self::hasInternalImage( $post_id ) ) {
|
78 |
+
return false;
|
79 |
+
}
|
80 |
+
|
81 |
+
if ( ! $item ) {
|
82 |
+
$data = FeaturedImage::getData( $post_id );
|
83 |
+
if ( ! $data ) {
|
84 |
+
return;
|
85 |
+
}
|
86 |
+
$item = $data[0];
|
87 |
+
}
|
88 |
+
if ( empty( $item['img'] ) ) {
|
89 |
+
return;
|
90 |
+
}
|
91 |
+
|
92 |
+
$img_url = $item['img'];
|
93 |
+
|
94 |
+
return self::updateExternalMeta( $img_url, $post_id );
|
95 |
+
}
|
96 |
+
|
97 |
+
public static function updateExternalMeta( $url, $post_id ) {
|
98 |
+
$old = \get_post_meta( $post_id, self::EXTERNAL_URL_META, true );
|
99 |
+
if ( $old && $old['url'] == $url ) {
|
100 |
+
return true;
|
101 |
+
}
|
102 |
+
|
103 |
+
$save = array();
|
104 |
+
$save['url'] = $url;
|
105 |
+
|
106 |
+
$width = $height = 0;
|
107 |
+
if ( ini_get( 'allow_url_fopen' ) ) {
|
108 |
+
list( $width, $height ) = @getimagesize( $url );
|
109 |
+
}
|
110 |
+
$save['width'] = $width;
|
111 |
+
$save['height'] = $height;
|
112 |
+
|
113 |
+
return \update_post_meta( $post_id, self::EXTERNAL_URL_META, $save );
|
114 |
+
}
|
115 |
+
|
116 |
+
public static function adminThumbnail( $html ) {
|
117 |
+
global $post;
|
118 |
+
if ( empty( $post ) || ! $external_img = \get_post_meta( $post->ID, self::EXTERNAL_URL_META, true ) ) {
|
119 |
+
return $html;
|
120 |
+
}
|
121 |
+
|
122 |
+
if ( empty( $external_img['url'] ) ) {
|
123 |
+
return $html;
|
124 |
+
}
|
125 |
+
|
126 |
+
$html .= '<div><img class="size-post-thumbnail" src="' . \esc_url( $external_img['url'] ) . '">';
|
127 |
+
$html .= '<p class="howto">' . __( 'External featured image', 'content-egg' ) . '</p></div>';
|
128 |
+
|
129 |
+
return $html;
|
130 |
+
}
|
131 |
+
|
132 |
+
public static function getFakeImageId( $value, $product ) {
|
133 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'enabled_internal_priority' && self::hasInternalImage( $product->get_id() ) ) {
|
134 |
+
return $value;
|
135 |
+
}
|
136 |
+
|
137 |
+
$product_id = $product->get_id();
|
138 |
+
if ( \get_post_meta( $product_id, self::EXTERNAL_URL_META, true ) ) {
|
139 |
+
return self::generateFakeId( $product_id );
|
140 |
+
} else {
|
141 |
+
return $value;
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
public static function getFakeThumbnailId( $value, $object_id, $meta_key, $single ) {
|
146 |
+
if ( $meta_key != '_thumbnail_id' ) {
|
147 |
+
return $value;
|
148 |
+
}
|
149 |
+
|
150 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'enabled_internal_priority' && self::hasInternalImage( $object_id ) ) {
|
151 |
+
return $value;
|
152 |
+
}
|
153 |
+
|
154 |
+
if ( \get_post_meta( $object_id, self::EXTERNAL_URL_META, true ) ) {
|
155 |
+
return self::generateFakeId( $object_id );
|
156 |
+
} else {
|
157 |
+
return $value;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
public static function replaceImageSrc( $image, $attachment_id, $size, $icon ) {
|
162 |
+
if ( ! $post_id = self::getRealId( $attachment_id ) ) {
|
163 |
+
return $image;
|
164 |
+
}
|
165 |
+
|
166 |
+
if ( ! $external_img = \get_post_meta( $post_id, self::EXTERNAL_URL_META, true ) ) {
|
167 |
+
return $image;
|
168 |
+
}
|
169 |
+
|
170 |
+
$external_url = $external_img['url'];
|
171 |
+
|
172 |
+
if ( $image_size = self::getImageSize( $size ) ) {
|
173 |
+
return array( $external_url, $image_size['width'], $image_size['height'], $image_size['crop'] );
|
174 |
+
} else {
|
175 |
+
if ( ! empty( $external_img['width'] ) ) {
|
176 |
+
$width = $external_img['width'];
|
177 |
+
} else {
|
178 |
+
$width = 800;
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( ! empty( $external_img['height'] ) ) {
|
182 |
+
$height = $external_img['height'];
|
183 |
+
} else {
|
184 |
+
$height = 600;
|
185 |
+
}
|
186 |
+
|
187 |
+
return array( $external_url, $width, $height, false );
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
public static function getImageSize( $size ) {
|
192 |
+
if ( is_array( $size ) ) {
|
193 |
+
return array(
|
194 |
+
'width' => isset( $size[0] ) ? $size[0] : null,
|
195 |
+
'height' => isset( $size[1] ) ? $size[1] : null,
|
196 |
+
'crop' => isset( $size[2] ) ? $size[2] : null,
|
197 |
+
);
|
198 |
+
}
|
199 |
+
|
200 |
+
global $_wp_additional_image_sizes;
|
201 |
+
if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
|
202 |
+
return $_wp_additional_image_sizes[ $size ];
|
203 |
+
}
|
204 |
+
|
205 |
+
$default = array( 'thumbnail', 'medium', 'medium_large', 'large' );
|
206 |
+
if ( in_array( $size, $default ) ) {
|
207 |
+
return array(
|
208 |
+
'width' => \get_option( "{$size}_size_w" ),
|
209 |
+
'height' => \get_option( "{$size}_size_h" ),
|
210 |
+
'crop' => \get_option( "{$size}_crop" ),
|
211 |
+
);
|
212 |
+
}
|
213 |
+
|
214 |
+
return array();
|
215 |
+
}
|
216 |
+
|
217 |
+
public static function replaceThumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
|
218 |
+
if ( ! $external_img = \get_post_meta( $post_id, self::EXTERNAL_URL_META, true ) ) {
|
219 |
+
return $html;
|
220 |
+
}
|
221 |
+
|
222 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'enabled_internal_priority' && self::hasInternalImage( $post_id ) ) {
|
223 |
+
return $html;
|
224 |
+
}
|
225 |
+
|
226 |
+
$url = $external_img['url'];
|
227 |
+
$alt = \get_post_field( 'post_title', $post_id );
|
228 |
+
$class = 'cegg-external-img wp-post-image';
|
229 |
+
$attr = array( 'alt' => $alt, 'class' => $class );
|
230 |
+
//$attr = \apply_filters('wp_get_attachment_image_attributes', $attr, $size);
|
231 |
+
$attr = array_map( 'esc_attr', $attr );
|
232 |
+
$html = sprintf( '<img src="%s"', esc_url( $url ) );
|
233 |
+
foreach ( $attr as $name => $value ) {
|
234 |
+
$html .= " $name=" . '"' . $value . '"';
|
235 |
+
}
|
236 |
+
$html .= ' />';
|
237 |
+
|
238 |
+
return $html;
|
239 |
+
}
|
240 |
+
|
241 |
+
public static function hasInternalImage( $object_id ) {
|
242 |
+
$meta_type = 'post';
|
243 |
+
$meta_key = '_thumbnail_id';
|
244 |
+
|
245 |
+
$meta_cache = \wp_cache_get( $object_id, $meta_type . '_meta' );
|
246 |
+
if ( ! $meta_cache ) {
|
247 |
+
$meta_cache = \update_meta_cache( $meta_type, array( $object_id ) );
|
248 |
+
$meta_cache = $meta_cache[ $object_id ];
|
249 |
+
}
|
250 |
+
|
251 |
+
if ( isset( $meta_cache[ $meta_key ] ) ) {
|
252 |
+
$meta_value = $meta_cache[ $meta_key ][0];
|
253 |
+
} else {
|
254 |
+
$meta_value = false;
|
255 |
+
}
|
256 |
+
|
257 |
+
if ( $meta_value ) {
|
258 |
+
return true;
|
259 |
+
} else {
|
260 |
+
return false;
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
public static function getExternalUrl( $post_id ) {
|
265 |
+
$external_img = \get_post_meta( $post_id, self::EXTERNAL_URL_META, true );
|
266 |
+
if ( ! $external_img || empty( $external_img['url'] ) ) {
|
267 |
+
return false;
|
268 |
+
} else {
|
269 |
+
return $external_img['url'];
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
public static function addOpengraphImage( $object ) {
|
274 |
+
if ( ! $post_id = \get_the_ID() ) {
|
275 |
+
return;
|
276 |
+
}
|
277 |
+
|
278 |
+
if ( ! $external_url = self::getExternalUrl( $post_id ) ) {
|
279 |
+
return;
|
280 |
+
}
|
281 |
+
|
282 |
+
$object->add_image( $external_url );
|
283 |
+
}
|
284 |
+
|
285 |
+
public static function addStructuredDataProduct( $markup, $product ) {
|
286 |
+
if ( ! empty( $markup['image'] ) ) {
|
287 |
+
return $markup;
|
288 |
+
}
|
289 |
+
|
290 |
+
if ( ! $external_url = self::getExternalUrl( $product->get_id() ) ) {
|
291 |
+
return $markup;
|
292 |
+
}
|
293 |
+
|
294 |
+
$markup['image'] = $external_url;
|
295 |
+
|
296 |
+
return $markup;
|
297 |
+
}
|
298 |
|
299 |
}
|
application/components/ExtraData.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ExtraData class file
|
@@ -13,28 +13,25 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class ExtraData {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
$object_or_array[$key] = $d;
|
34 |
-
}
|
35 |
-
}
|
36 |
|
37 |
-
|
38 |
-
|
39 |
|
40 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ExtraData class file
|
13 |
*/
|
14 |
class ExtraData {
|
15 |
|
16 |
+
public $date;
|
17 |
+
public $author;
|
18 |
+
public $source;
|
19 |
+
public $domain;
|
20 |
+
public $pricePerUnitDisplay;
|
21 |
|
22 |
+
public static function fillAttributes( $object_or_array, array $data ) {
|
23 |
+
foreach ( $data as $key => $d ) {
|
24 |
+
if ( is_object( $object_or_array ) && property_exists( $object_or_array, $key ) ) {
|
25 |
+
if ( is_array( $d ) && ! is_array( $object_or_array->$key ) ) {
|
26 |
+
continue;
|
27 |
+
} //?
|
28 |
+
$object_or_array->$key = $d;
|
29 |
+
} elseif ( is_array( $object_or_array ) ) {
|
30 |
+
$object_or_array[ $key ] = $d;
|
31 |
+
}
|
32 |
+
}
|
|
|
|
|
|
|
33 |
|
34 |
+
return $object_or_array;
|
35 |
+
}
|
36 |
|
37 |
}
|
application/components/FeaturedImage.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\components\ContentManager;
|
@@ -19,147 +19,154 @@ use ContentEgg\application\components\ExternalFeaturedImage;
|
|
19 |
*/
|
20 |
class FeaturedImage {
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\components\ContentManager;
|
19 |
*/
|
20 |
class FeaturedImage {
|
21 |
|
22 |
+
public function __construct() {
|
23 |
+
if ( \is_admin() ) {
|
24 |
+
$this->adminInit();
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
public function adminInit() {
|
29 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) != 'disabled' ) {
|
30 |
+
return;
|
31 |
+
}
|
32 |
+
|
33 |
+
// priority 11 - after meta save
|
34 |
+
\add_action( 'save_post', array( $this, 'setImage' ), 11, 2 );
|
35 |
+
}
|
36 |
+
|
37 |
+
public static function doAction( $post_id, $item = null ) {
|
38 |
+
if ( GeneralConfig::getInstance()->option( 'external_featured_images' ) == 'disabled' ) {
|
39 |
+
if ( ! \has_post_thumbnail( $post_id ) ) {
|
40 |
+
FeaturedImage::setFeaturedImage( $post_id, $item );
|
41 |
+
}
|
42 |
+
} else {
|
43 |
+
ExternalFeaturedImage::setExternalFeaturedImage( $post_id, $item );
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
public function setImage( $post_id ) {
|
48 |
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
+
|
52 |
+
if ( \get_post_status( $post_id ) == 'auto-draft' || \wp_is_post_revision( $post_id ) ) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
+
|
56 |
+
if ( \has_post_thumbnail( $post_id ) ) {
|
57 |
+
return;
|
58 |
+
}
|
59 |
+
|
60 |
+
self::setFeaturedImage( $post_id );
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function setFeaturedImage( $post_id, $item = null ) {
|
64 |
+
if ( $item ) {
|
65 |
+
$data = array( $item );
|
66 |
+
} else {
|
67 |
+
$data = self::getData( $post_id );
|
68 |
+
}
|
69 |
+
|
70 |
+
foreach ( $data as $d ) {
|
71 |
+
if ( ! $img_file = self::getImgFile( $d ) ) {
|
72 |
+
continue;
|
73 |
+
}
|
74 |
+
|
75 |
+
return self::attachThumbnail( $img_file, $post_id, $d['title'] );
|
76 |
+
}
|
77 |
+
|
78 |
+
return false;
|
79 |
+
}
|
80 |
+
|
81 |
+
public static function getData( $post_id ) {
|
82 |
+
$modules_ids = ModuleManager::getInstance()->getParserModulesIdList();
|
83 |
+
$data = array();
|
84 |
+
foreach ( $modules_ids as $module_id ) {
|
85 |
+
$module = ModuleManager::factory( $module_id );
|
86 |
+
if ( ! $featured_image = $module->config( 'featured_image', false ) ) {
|
87 |
+
continue;
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( ! $d = ContentManager::getData( $post_id, $module->getId() ) ) {
|
91 |
+
continue;
|
92 |
+
}
|
93 |
+
|
94 |
+
if ( $featured_image == 'second' && isset( $d[1] ) ) {
|
95 |
+
unset( $d[0] );
|
96 |
+
} elseif ( $featured_image == 'last' ) {
|
97 |
+
$d = array_reverse( $d );
|
98 |
+
} elseif ( $featured_image == 'rand' ) {
|
99 |
+
shuffle( $d );
|
100 |
+
}
|
101 |
+
|
102 |
+
$data = array_merge( $data, $d );
|
103 |
+
}
|
104 |
+
|
105 |
+
foreach ( $data as $i => $d ) {
|
106 |
+
if ( empty( $d['img'] ) ) {
|
107 |
+
unset( $data[ $i ] );
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
return array_values( $data );
|
112 |
+
}
|
113 |
+
|
114 |
+
public static function getImgFile( $item ) {
|
115 |
+
if ( empty( $item['img'] ) ) {
|
116 |
+
return false;
|
117 |
+
}
|
118 |
+
|
119 |
+
// already saved? dublicate image file
|
120 |
+
if ( isset( $item['img_file'] ) && $item['img_file'] ) {
|
121 |
+
$img_file = ImageHelper::getFullImgPath( $item['img_file'] );
|
122 |
+
if ( ! is_file( $img_file ) ) {
|
123 |
+
return false;
|
124 |
+
}
|
125 |
+
|
126 |
+
$uploads = \wp_upload_dir();
|
127 |
+
$dublicate_name = \wp_unique_filename( $uploads['path'], basename( $item['img_file'] ) );
|
128 |
+
$dublicate_file = $uploads['path'] . '/' . $dublicate_name;
|
129 |
+
|
130 |
+
if ( ! copy( $img_file, $dublicate_file ) ) {
|
131 |
+
return false;
|
132 |
+
}
|
133 |
+
|
134 |
+
return $dublicate_file;
|
135 |
+
} else {
|
136 |
+
// save image localy
|
137 |
+
$file_name = ImageHelper::saveImgLocaly( $item['img'], $item['title'] );
|
138 |
+
if ( ! $file_name ) {
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
$uploads = \wp_upload_dir();
|
142 |
+
$image = ltrim( trailingslashit( $uploads['subdir'] ), '\/' ) . $file_name;
|
143 |
+
|
144 |
+
return ImageHelper::getFullImgPath( $image );
|
145 |
+
}
|
146 |
+
|
147 |
+
return $img_file;
|
148 |
+
}
|
149 |
+
|
150 |
+
public static function attachThumbnail( $img_file, $post_id, $title = '' ) {
|
151 |
+
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
152 |
+
|
153 |
+
$title = \sanitize_text_field( $title );
|
154 |
+
$filetype = \wp_check_filetype( basename( $img_file ), null );
|
155 |
+
$attachment = array(
|
156 |
+
'guid' => $img_file,
|
157 |
+
'post_mime_type' => $filetype['type'],
|
158 |
+
'post_title' => $title,
|
159 |
+
'post_content' => '',
|
160 |
+
'post_status' => 'inherit'
|
161 |
+
);
|
162 |
+
$attach_id = \wp_insert_attachment( $attachment, $img_file, $post_id );
|
163 |
+
$attach_data = \wp_generate_attachment_metadata( $attach_id, $img_file );
|
164 |
+
\wp_update_attachment_metadata( $attach_id, $attach_data );
|
165 |
+
if ( $title ) {
|
166 |
+
\update_post_meta( $attach_id, '_wp_attachment_image_alt', $title );
|
167 |
+
}
|
168 |
+
|
169 |
+
return \set_post_thumbnail( $post_id, $attach_id );
|
170 |
+
}
|
171 |
|
172 |
}
|
application/components/LinkHandler.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
@@ -15,368 +15,388 @@ use ContentEgg\application\helpers\TextHelper;
|
|
15 |
*/
|
16 |
class LinkHandler {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
|
382 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
15 |
*/
|
16 |
class LinkHandler {
|
17 |
|
18 |
+
private static $instance = null;
|
19 |
+
|
20 |
+
public static function getInstance() {
|
21 |
+
if ( self::$instance == null ) {
|
22 |
+
self::$instance = new self;
|
23 |
+
}
|
24 |
+
|
25 |
+
return self::$instance;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Deeplink & more...
|
30 |
+
*/
|
31 |
+
public static function createAffUrl( $url, $deeplink, $item = array(), $subid = '' ) {
|
32 |
+
// custom filter
|
33 |
+
$filtered = \apply_filters( 'cegg_create_affiliate_link', $url, $deeplink );
|
34 |
+
if ( $filtered != $url ) {
|
35 |
+
return $url;
|
36 |
+
}
|
37 |
+
|
38 |
+
// profitshare fix. return if url already created
|
39 |
+
if ( ! empty( $item['url'] ) && strstr( $item['url'], '/l.profitshare.ro/' ) ) {
|
40 |
+
return $item['url'];
|
41 |
+
}
|
42 |
+
// lomadee fix. return if url already created
|
43 |
+
if ( ! empty( $item['url'] ) && strstr( $item['url'], '/redir.lomadee.com/' ) && ! strstr( $item['url'], 'https://redir.lomadee.com/v2/deeplink?url=' ) ) {
|
44 |
+
return $item['url'];
|
45 |
+
}
|
46 |
+
// coupang fix. return if url already created
|
47 |
+
if ( ! empty( $item['url'] ) && strstr( $item['url'], 'https://coupa.ng/' ) ) {
|
48 |
+
return $item['url'];
|
49 |
+
}
|
50 |
+
|
51 |
+
$deeplink = self::getMultiDeeplink( $deeplink, $url );
|
52 |
+
|
53 |
+
if ( ! $deeplink ) {
|
54 |
+
$result = $url;
|
55 |
+
} elseif ( substr( trim( $deeplink ), 0, 7 ) == '[regex]' ) {
|
56 |
+
// regex preg_replace
|
57 |
+
$result = self::getRegexReplace( $url, $deeplink );
|
58 |
+
} elseif ( substr( trim( $deeplink ), 0, 13 ) == '[profitshare]' ) {
|
59 |
+
// ProfitShare link creator
|
60 |
+
$result = self::getProfitshareLink( $url, $deeplink, $item );
|
61 |
+
} elseif ( substr( trim( $deeplink ), 0, 9 ) == '[lomadee]' ) {
|
62 |
+
// Lomadee link creator
|
63 |
+
$result = self::getLomadeeLink( $url, $deeplink, $item );
|
64 |
+
} elseif ( substr( trim( $deeplink ), 0, 13 ) == '[trovaprezzi]' ) {
|
65 |
+
// Trovaprezzi link creator
|
66 |
+
$result = self::getTrovaprezziLink( $url, $deeplink, $item );
|
67 |
+
} elseif ( substr( trim( $deeplink ), 0, 9 ) == '[coupang]' ) {
|
68 |
+
// Coupang link creator
|
69 |
+
$result = self::getCoupangLink( $url, $deeplink, $item );
|
70 |
+
} elseif ( strstr( $deeplink, '{{' ) && strstr( $deeplink, '}}' ) ) {
|
71 |
+
// template deeplink
|
72 |
+
$result = self::getUrlTemplate( $url, $deeplink, $item );
|
73 |
+
} elseif ( ! preg_match( '/^https?:\/\//i', $deeplink ) ) {
|
74 |
+
// url with tail
|
75 |
+
$result = self::getUrlWithTail( $url, $deeplink );
|
76 |
+
} else {
|
77 |
+
$result = $deeplink . urlencode( $url );
|
78 |
+
}
|
79 |
+
if ( $subid ) {
|
80 |
+
$result = self::getUrlWithTail( $result, $subid );
|
81 |
+
}
|
82 |
+
|
83 |
+
return $result;
|
84 |
+
}
|
85 |
+
|
86 |
+
public static function getUrlWithTail( $url, $tail ) {
|
87 |
+
// replace params in URL
|
88 |
+
parse_str( $tail, $vars );
|
89 |
+
if ( count( $vars ) == 1 && strstr( $tail, '=' ) ) {
|
90 |
+
return \add_query_arg( $vars, $url );
|
91 |
+
}
|
92 |
+
|
93 |
+
$tail = preg_replace( '/^[?&]/', '', $tail );
|
94 |
+
|
95 |
+
$query = parse_url( $url, PHP_URL_QUERY );
|
96 |
+
if ( $query ) {
|
97 |
+
$url .= '&';
|
98 |
+
} else {
|
99 |
+
$url .= '?';
|
100 |
+
}
|
101 |
+
|
102 |
+
parse_str( $tail, $tail_array );
|
103 |
+
$url .= http_build_query( $tail_array );
|
104 |
+
|
105 |
+
return $url;
|
106 |
+
}
|
107 |
+
|
108 |
+
public static function getUrlTemplate( $url, $template, $item = array() ) {
|
109 |
+
$template = str_replace( '{{url}}', $url, $template );
|
110 |
+
$template = str_replace( '{{url_encoded}}', urlencode( $url ), $template );
|
111 |
+
$template = str_replace( '{{url_base64}}', base64_encode( $url ), $template );
|
112 |
+
global $post;
|
113 |
+
|
114 |
+
if ( $item ) {
|
115 |
+
if ( isset( $item['post_id'] ) ) {
|
116 |
+
$post_id = $item['post_id'];
|
117 |
+
} elseif ( ! empty( $post ) ) {
|
118 |
+
$post_id = $post->ID;
|
119 |
+
} else {
|
120 |
+
$post_id = 0;
|
121 |
+
}
|
122 |
+
$template = str_replace( '{{post_id}}', urlencode( $post_id ), $template );
|
123 |
+
|
124 |
+
if ( ! empty( $item['unique_id'] ) ) {
|
125 |
+
$template = str_replace( '{{item_unique_id}}', urlencode( $item['unique_id'] ), $template );
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
if ( ! empty( $post ) ) {
|
130 |
+
$author_id = $post->post_author;
|
131 |
+
$user = \get_user_by( 'ID', $author_id );
|
132 |
+
$author_login = $user ? $user->data->user_login : '';
|
133 |
+
$template = str_replace( '{{author_id}}', urlencode( $author_id ), $template );
|
134 |
+
$template = str_replace( '{{author_login}}', urlencode( $author_login ), $template );
|
135 |
+
}
|
136 |
+
|
137 |
+
return $template;
|
138 |
+
}
|
139 |
+
|
140 |
+
public static function getRegexReplace( $url, $regex ) {
|
141 |
+
$regex = trim( $regex );
|
142 |
+
|
143 |
+
$parts = explode( '][', $regex );
|
144 |
+
if ( count( $parts ) != 3 ) {
|
145 |
+
return $url;
|
146 |
+
}
|
147 |
+
|
148 |
+
$pattern = $parts[1];
|
149 |
+
//$replacement = rtrim($parts[2], ']');
|
150 |
+
$replacement = substr( $parts[2], 0, - 1 );
|
151 |
+
|
152 |
+
// null character allows a premature regex end and "/../e" injection
|
153 |
+
if ( strpos( $pattern, chr( 0 ) ) !== false || ! trim( $pattern ) ) {
|
154 |
+
return $url;
|
155 |
+
}
|
156 |
+
|
157 |
+
if ( $result = @preg_replace( $pattern, $replacement, $url ) ) {
|
158 |
+
return $result;
|
159 |
+
} else {
|
160 |
+
return $url;
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
public static function getProfitshareLink( $url, $regex, $item = array() ) {
|
165 |
+
$regex = trim( $regex );
|
166 |
+
$parts = explode( '][', $regex );
|
167 |
+
if ( count( $parts ) != 3 ) {
|
168 |
+
return $url;
|
169 |
+
}
|
170 |
+
|
171 |
+
$api_user = $parts[1];
|
172 |
+
$api_key = rtrim( $parts[2], ']' );
|
173 |
+
|
174 |
+
$api_url = 'http://api.profitshare.ro/affiliate-links/?';
|
175 |
+
$query_string = '';
|
176 |
+
|
177 |
+
$spider = curl_init();
|
178 |
+
curl_setopt( $spider, CURLOPT_HEADER, false );
|
179 |
+
curl_setopt( $spider, CURLOPT_URL, $api_url . $query_string );
|
180 |
+
curl_setopt( $spider, CURLOPT_CONNECTTIMEOUT, 60 );
|
181 |
+
curl_setopt( $spider, CURLOPT_TIMEOUT, 30 );
|
182 |
+
curl_setopt( $spider, CURLOPT_RETURNTRANSFER, true );
|
183 |
+
curl_setopt( $spider, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
|
184 |
+
curl_setopt( $spider, CURLOPT_USERAGENT, 'Content Egg WP Plugin (https://www.keywordrush.com/contentegg)' );
|
185 |
+
|
186 |
+
$data = array();
|
187 |
+
$name = 'CE:' . TextHelper::getHostName( $url );
|
188 |
+
if ( ! empty( $item['title'] ) ) {
|
189 |
+
$name .= ' ' . $item['title'];
|
190 |
+
}
|
191 |
+
$data[] = array(
|
192 |
+
'name' => $name,
|
193 |
+
'url' => $url
|
194 |
+
);
|
195 |
+
|
196 |
+
curl_setopt( $spider, CURLOPT_POST, true );
|
197 |
+
curl_setopt( $spider, CURLOPT_POSTFIELDS, http_build_query( $data ) );
|
198 |
+
|
199 |
+
$profitshare_login = array( 'api_user' => $api_user, 'api_key' => $api_key, );
|
200 |
+
$date = gmdate( 'D, d M Y H:i:s T', time() );
|
201 |
+
$signature_string = 'POSTaffiliate-links/?' . $query_string . '/' . $profitshare_login['api_user'] . $date;
|
202 |
+
$auth = hash_hmac( 'sha1', $signature_string, $profitshare_login['api_key'] );
|
203 |
+
|
204 |
+
$extra_headers = array(
|
205 |
+
"Date: {$date}",
|
206 |
+
"X-PS-Client: {$profitshare_login['api_user']}",
|
207 |
+
"X-PS-Accept: json",
|
208 |
+
"X-PS-Auth: {$auth}"
|
209 |
+
);
|
210 |
+
|
211 |
+
curl_setopt( $spider, CURLOPT_HTTPHEADER, $extra_headers );
|
212 |
+
|
213 |
+
$output = curl_exec( $spider );
|
214 |
+
if ( ! $output ) {
|
215 |
+
return $url;
|
216 |
+
}
|
217 |
+
|
218 |
+
$result = json_decode( $output, true );
|
219 |
+
|
220 |
+
if ( ! $result ) {
|
221 |
+
return $url;
|
222 |
+
}
|
223 |
+
if ( isset( $result['result'][0]['ps_url'] ) ) {
|
224 |
+
return $result['result'][0]['ps_url'];
|
225 |
+
} else {
|
226 |
+
return $url;
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
public static function getLomadeeLink( $url, $regex, $item = array() ) {
|
231 |
+
$regex = trim( $regex );
|
232 |
+
$parts = explode( '][', $regex );
|
233 |
+
if ( count( $parts ) != 2 ) {
|
234 |
+
return $url;
|
235 |
+
}
|
236 |
+
|
237 |
+
$sourceId = rtrim( $parts[1], ']' );
|
238 |
+
$api_url = 'https://api.lomadee.com/v2/15071999399311f734bd1/deeplink/_create?sourceId=' . urlencode( $sourceId ) . '&url=' . urlencode( $url );
|
239 |
+
|
240 |
+
$response = \wp_remote_get( $api_url );
|
241 |
+
if ( \is_wp_error( $response ) ) {
|
242 |
+
return $url;
|
243 |
+
}
|
244 |
+
$response_code = (int) \wp_remote_retrieve_response_code( $response );
|
245 |
+
if ( $response_code != 200 ) {
|
246 |
+
return $url;
|
247 |
+
}
|
248 |
+
$output = \wp_remote_retrieve_body( $response );
|
249 |
+
$result = json_decode( $output, true );
|
250 |
+
if ( ! $result ) {
|
251 |
+
return $url;
|
252 |
+
}
|
253 |
+
if ( isset( $result['deeplinks'][0]['deeplink'] ) ) {
|
254 |
+
return $result['deeplinks'][0]['deeplink'];
|
255 |
+
} else {
|
256 |
+
return $url;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
public static function getTrovaprezziLink( $url, $regex, $item = array() ) {
|
261 |
+
/**
|
262 |
+
* Note: tracking links include a token in order to ensure that offers are updated as much as possible.
|
263 |
+
* This token expires in 12 hours! Therefore you need to set your script to update your feed at least
|
264 |
+
* once each 11 hours , in order to guarantee the correct click tracking!
|
265 |
+
*/
|
266 |
+
|
267 |
+
if ( strstr( $item['url'], 'splash?impression' ) && time() - $item['last_update'] < 111 * 3600 ) {
|
268 |
+
return $item['url'];
|
269 |
+
}
|
270 |
+
|
271 |
+
$regex = trim( $regex );
|
272 |
+
$parts = explode( '][', $regex );
|
273 |
+
if ( count( $parts ) != 2 ) {
|
274 |
+
return $url;
|
275 |
+
}
|
276 |
+
|
277 |
+
/*
|
278 |
+
$path = parse_url($url, PHP_URL_PATH);
|
279 |
+
$path = trim($path, "/");
|
280 |
+
$path = preg_replace('/\.aspx$/', '', $path);
|
281 |
+
$path = explode('/', $path);
|
282 |
+
$path = end($path);
|
283 |
+
$path = explode('-', $path);
|
284 |
+
$path = end($path);
|
285 |
+
$keyword = $path;
|
286 |
+
*
|
287 |
+
*/
|
288 |
+
|
289 |
+
$keyword = $item['title'];
|
290 |
+
$keyword = strtolower( $keyword );
|
291 |
+
$keyword = str_replace( ' ', '_', $keyword );
|
292 |
+
|
293 |
+
$partnerId = rtrim( $parts[1], ']' );
|
294 |
+
$api_url = 'https://quickshop.shoppydoo.it/' . urlencode( $partnerId ) . '/' . urlencode( $keyword ) . '.aspx?format=json&sort=price';
|
295 |
+
|
296 |
+
$response = \wp_remote_get( $api_url );
|
297 |
+
if ( \is_wp_error( $response ) ) {
|
298 |
+
return $url;
|
299 |
+
}
|
300 |
+
$response_code = (int) \wp_remote_retrieve_response_code( $response );
|
301 |
+
if ( $response_code != 200 ) {
|
302 |
+
return $url;
|
303 |
+
}
|
304 |
+
$output = \wp_remote_retrieve_body( $response );
|
305 |
+
$result = json_decode( $output, true );
|
306 |
+
if ( ! $result ) {
|
307 |
+
return $url;
|
308 |
+
}
|
309 |
+
if ( isset( $result['offers'][0]['url'] ) ) {
|
310 |
+
return $result['offers'][0]['url'];
|
311 |
+
} else {
|
312 |
+
return $url;
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
public static function getCoupangLink( $url, $regex, $item = array() ) {
|
317 |
+
|
318 |
+
$regex = trim( $regex );
|
319 |
+
$parts = explode( '][', $regex );
|
320 |
+
if ( count( $parts ) != 3 ) {
|
321 |
+
return $url;
|
322 |
+
}
|
323 |
+
|
324 |
+
$ACCESS_KEY = $parts[1];
|
325 |
+
$SECRET_KEY = rtrim( $parts[2], ']' );
|
326 |
+
|
327 |
+
//date_default_timezone_set("GMT+0");
|
328 |
+
|
329 |
+
$datetime = date( "ymd" ) . 'T' . date( "His" ) . 'Z';
|
330 |
+
$method = "POST";
|
331 |
+
$path = "/v2/providers/affiliate_open_api/apis/openapi/v1/deeplink";
|
332 |
+
$message = $datetime . $method . str_replace( "?", "", $path );
|
333 |
+
$algorithm = "HmacSHA256";
|
334 |
+
|
335 |
+
$signature = hash_hmac( 'sha256', $message, $SECRET_KEY );
|
336 |
+
|
337 |
+
$authorization = "CEA algorithm=HmacSHA256, access-key=" . $ACCESS_KEY . ", signed-date=" . $datetime . ", signature=" . $signature;
|
338 |
+
|
339 |
+
$rurl = 'https://api-gateway.coupang.com' . $path;
|
340 |
+
|
341 |
+
$strjson = '{"coupangUrls": ["' . $url . '"]}';
|
342 |
+
|
343 |
+
$curl = curl_init();
|
344 |
+
curl_setopt( $curl, CURLOPT_URL, $rurl );
|
345 |
+
curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, $method );
|
346 |
+
curl_setopt( $curl, CURLOPT_HTTPHEADER, array(
|
347 |
+
"Content-Type: application/json;charset=UTF-8",
|
348 |
+
"Authorization:" . $authorization
|
349 |
+
) );
|
350 |
+
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
|
351 |
+
curl_setopt( $curl, CURLOPT_POSTFIELDS, $strjson );
|
352 |
+
$output = curl_exec( $curl );
|
353 |
+
|
354 |
+
if ( ! $output ) {
|
355 |
+
return $url;
|
356 |
+
}
|
357 |
+
|
358 |
+
$result = json_decode( $output, true );
|
359 |
+
|
360 |
+
if ( ! $result ) {
|
361 |
+
return $url;
|
362 |
+
}
|
363 |
+
if ( isset( $result['data'][0]['shortenUrl'] ) ) {
|
364 |
+
return $result['data'][0]['shortenUrl'];
|
365 |
+
} else {
|
366 |
+
return $url;
|
367 |
+
}
|
368 |
+
}
|
369 |
+
|
370 |
+
public static function getMultiDeeplink( $deeplink, $url ) {
|
371 |
+
if ( ! strstr( $deeplink, ';' ) ) {
|
372 |
+
return $deeplink;
|
373 |
+
}
|
374 |
+
|
375 |
+
$url_host = TextHelper::urlHost( $url );
|
376 |
+
$deeplink_array = str_getcsv( $deeplink, ';' );
|
377 |
+
$default = '';
|
378 |
+
foreach ( $deeplink_array as $da ) {
|
379 |
+
$parts = explode( ':', $da, 2 );
|
380 |
+
|
381 |
+
// default deeplink
|
382 |
+
if ( count( $parts ) == 1 ) {
|
383 |
+
$default = trim( $da );
|
384 |
+
} elseif ( count( $parts ) == 2 ) {
|
385 |
+
if ( ! $default ) {
|
386 |
+
$default = trim( $parts[1] );
|
387 |
+
}
|
388 |
+
|
389 |
+
$host = $parts[0];
|
390 |
+
$host = preg_replace( '/^https?:\/\//', '', $host );
|
391 |
+
$host = preg_replace( '/^www\./', '', $host );
|
392 |
+
|
393 |
+
if ( $host == $url_host ) {
|
394 |
+
return trim( $parts[1] );
|
395 |
+
}
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
return $default;
|
400 |
+
}
|
401 |
|
402 |
}
|
application/components/Module.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
@@ -18,263 +18,244 @@ use ContentEgg\application\Plugin;
|
|
18 |
*/
|
19 |
abstract class Module {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
else
|
261 |
-
return false;
|
262 |
-
}
|
263 |
-
|
264 |
-
public static function getIdStatic()
|
265 |
-
{
|
266 |
-
$parts = explode('\\', get_called_class());
|
267 |
-
return $parts[count($parts) - 2];
|
268 |
-
}
|
269 |
-
|
270 |
-
public function getStatusText()
|
271 |
-
{
|
272 |
-
if ($this->isActive() && $this->isDeprecated())
|
273 |
-
return 'deprecated';
|
274 |
-
elseif ($this->isActive())
|
275 |
-
return 'active';
|
276 |
-
else
|
277 |
-
return 'inactive';
|
278 |
-
}
|
279 |
|
280 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
18 |
*/
|
19 |
abstract class Module {
|
20 |
|
21 |
+
private $id;
|
22 |
+
private $dir;
|
23 |
+
protected $is_active;
|
24 |
+
protected $name;
|
25 |
+
protected $api_agreement;
|
26 |
+
protected $docs_uri;
|
27 |
+
protected $description;
|
28 |
+
private $is_custom;
|
29 |
+
private $is_configurable;
|
30 |
+
|
31 |
+
public function __construct( $module_id = null ) {
|
32 |
+
if ( $module_id ) {
|
33 |
+
$this->id = $module_id;
|
34 |
+
} else {
|
35 |
+
$this->id = static::getIdStatic();
|
36 |
+
}
|
37 |
+
|
38 |
+
$info = $this->info();
|
39 |
+
if ( ! empty( $info['name'] ) ) {
|
40 |
+
$this->name = $info['name'];
|
41 |
+
} else {
|
42 |
+
$this->name = $this->id;
|
43 |
+
}
|
44 |
+
if ( ! empty( $info['api_agreement'] ) ) {
|
45 |
+
$this->api_agreement = $info['api_agreement'];
|
46 |
+
}
|
47 |
+
if ( ! empty( $info['description'] ) ) {
|
48 |
+
$this->description = $info['description'];
|
49 |
+
}
|
50 |
+
if ( ! empty( $info['docs_uri'] ) ) {
|
51 |
+
$this->docs_uri = $info['docs_uri'];
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
public function info() {
|
56 |
+
return array();
|
57 |
+
}
|
58 |
+
|
59 |
+
final public function getId() {
|
60 |
+
return $this->id;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function getName() {
|
64 |
+
return $this->name;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getDir() {
|
68 |
+
if ( $this->dir === null ) {
|
69 |
+
$rc = new \ReflectionClass( get_class( $this ) );
|
70 |
+
$this->dir = dirname( $rc->getFileName() ) . DIRECTORY_SEPARATOR;
|
71 |
+
}
|
72 |
+
|
73 |
+
return $this->dir;
|
74 |
+
}
|
75 |
+
|
76 |
+
public function isActive() {
|
77 |
+
if ( $this->is_active === null ) {
|
78 |
+
// @todo
|
79 |
+
$this->is_active = true;
|
80 |
+
}
|
81 |
+
|
82 |
+
return $this->is_active;
|
83 |
+
}
|
84 |
+
|
85 |
+
final public function isCustom() {
|
86 |
+
if ( $this->is_custom === null ) {
|
87 |
+
// @todo
|
88 |
+
$this->is_custom = false;
|
89 |
+
}
|
90 |
+
|
91 |
+
return $this->is_custom;
|
92 |
+
}
|
93 |
+
|
94 |
+
public function isDeprecated() {
|
95 |
+
return false;
|
96 |
+
}
|
97 |
+
|
98 |
+
public function isConfigurable() {
|
99 |
+
if ( $this->is_configurable === null ) {
|
100 |
+
if ( is_file( $this->getDir() . $this->getMyPathId() . 'Config.php' ) ) {
|
101 |
+
$this->is_configurable = true;
|
102 |
+
} else {
|
103 |
+
$this->is_configurable = false;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
return $this->is_configurable;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function isFree() {
|
111 |
+
return false;
|
112 |
+
}
|
113 |
+
|
114 |
+
public function renderResults() {
|
115 |
+
|
116 |
+
}
|
117 |
+
|
118 |
+
public function renderSearchResults() {
|
119 |
+
|
120 |
+
}
|
121 |
+
|
122 |
+
public function renderSearchPanel() {
|
123 |
+
|
124 |
+
}
|
125 |
+
|
126 |
+
public function enqueueScripts() {
|
127 |
+
|
128 |
+
}
|
129 |
+
|
130 |
+
public function presavePrepare( $data, $post_id ) {
|
131 |
+
return $data;
|
132 |
+
}
|
133 |
+
|
134 |
+
public function getConfigInstance() {
|
135 |
+
return ModuleManager::configFactory( $this->getId() );
|
136 |
+
}
|
137 |
+
|
138 |
+
public function config( $opt_name, $default = null ) {
|
139 |
+
if ( ! $this->getConfigInstance()->option_exists( $opt_name ) ) {
|
140 |
+
return $default;
|
141 |
+
} else {
|
142 |
+
return $this->getConfigInstance()->option( $opt_name );
|
143 |
+
}
|
144 |
+
}
|
145 |
+
|
146 |
+
public function render( $view_name, $_data = null ) {
|
147 |
+
if ( is_array( $_data ) ) {
|
148 |
+
extract( $_data, EXTR_PREFIX_SAME, 'data' );
|
149 |
+
} else {
|
150 |
+
$data = $_data;
|
151 |
+
}
|
152 |
+
|
153 |
+
if ( ModuleManager::isCustomModule( $this->getId() ) ) {
|
154 |
+
$base = \WP_CONTENT_DIR . '/' . \ContentEgg\CUSTOM_MODULES_DIR . '/';
|
155 |
+
} else {
|
156 |
+
$base = \ContentEgg\PLUGIN_PATH . 'application/modules/';
|
157 |
+
}
|
158 |
+
|
159 |
+
include $base . $this->getMyPathId() . '/views/' . TextHelper::clear( $view_name ) . '.php';
|
160 |
+
}
|
161 |
+
|
162 |
+
public function getJsUri() {
|
163 |
+
return \plugins_url( '\application\modules\\' . $this->getMyPathId() . '\js', \ContentEgg\PLUGIN_FILE );
|
164 |
+
}
|
165 |
+
|
166 |
+
public function getApiAgreement() {
|
167 |
+
return $this->api_agreement;
|
168 |
+
}
|
169 |
+
|
170 |
+
public function getDocsUri() {
|
171 |
+
return $this->docs_uri;
|
172 |
+
}
|
173 |
+
|
174 |
+
public function getDescription() {
|
175 |
+
return $this->description;
|
176 |
+
}
|
177 |
+
|
178 |
+
public function isAffiliateParser() {
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
|
182 |
+
public function isParser() {
|
183 |
+
return false;
|
184 |
+
}
|
185 |
+
|
186 |
+
public function getMyPathId() {
|
187 |
+
return self::getPathId( $this->getId() );
|
188 |
+
}
|
189 |
+
|
190 |
+
public function getMyShortId() {
|
191 |
+
return self::getShortId( $this->getId() );
|
192 |
+
}
|
193 |
+
|
194 |
+
public static function getPathId( $module_id ) {
|
195 |
+
// AE or Feed module?
|
196 |
+
$parts = explode( '__', $module_id );
|
197 |
+
|
198 |
+
return $parts[0];
|
199 |
+
}
|
200 |
+
|
201 |
+
public function getShortId( $module_id ) {
|
202 |
+
// AE or Feed module?
|
203 |
+
$parts = explode( '__', $module_id );
|
204 |
+
if ( count( $parts ) == 2 ) {
|
205 |
+
return $parts[1];
|
206 |
+
} else {
|
207 |
+
return $module_id;
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
public function renderMetaboxModule() {
|
212 |
+
PluginAdmin::render( 'metabox_module', array( 'module_id' => $this->getId(), 'module' => $this ) );
|
213 |
+
}
|
214 |
+
|
215 |
+
public function releaseVersion() {
|
216 |
+
return '';
|
217 |
+
}
|
218 |
+
|
219 |
+
public function isNew() {
|
220 |
+
if ( ! $module_version = $this->releaseVersion() ) {
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
$module_version = join( '.', array_slice( explode( '.', $module_version ), 0, 2 ) );
|
225 |
+
$plugin_version = join( '.', array_slice( explode( '.', Plugin::version() ), 0, 2 ) );
|
226 |
+
if ( $module_version == $plugin_version ) {
|
227 |
+
return true;
|
228 |
+
} else {
|
229 |
+
return false;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
public function requirements() {
|
234 |
+
return '';
|
235 |
+
}
|
236 |
+
|
237 |
+
public function isFeedModule() {
|
238 |
+
if ( $this instanceof \ContentEgg\application\components\AffiliateFeedParserModule ) {
|
239 |
+
return true;
|
240 |
+
} else {
|
241 |
+
return false;
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
public static function getIdStatic() {
|
246 |
+
$parts = explode( '\\', get_called_class() );
|
247 |
+
|
248 |
+
return $parts[ count( $parts ) - 2 ];
|
249 |
+
}
|
250 |
+
|
251 |
+
public function getStatusText() {
|
252 |
+
if ( $this->isActive() && $this->isDeprecated() ) {
|
253 |
+
return 'deprecated';
|
254 |
+
} elseif ( $this->isActive() ) {
|
255 |
+
return 'active';
|
256 |
+
} else {
|
257 |
+
return 'inactive';
|
258 |
+
}
|
259 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
}
|
application/components/ModuleApi.php
CHANGED
@@ -2,12 +2,11 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
10 |
-
use ContentEgg\application\helpers\InputHelper;
|
11 |
|
12 |
/**
|
13 |
* ModuleApi class file
|
@@ -18,89 +17,93 @@ use ContentEgg\application\helpers\InputHelper;
|
|
18 |
*/
|
19 |
class ModuleApi {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
105 |
|
106 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
use ContentEgg\application\helpers\TextHelper;
|
|
|
10 |
|
11 |
/**
|
12 |
* ModuleApi class file
|
17 |
*/
|
18 |
class ModuleApi {
|
19 |
|
20 |
+
const API_BASE = '-module-api';
|
21 |
+
|
22 |
+
public function __construct() {
|
23 |
+
\add_action( 'wp_ajax_content-egg-module-api', array( $this, 'addApiEntry' ) );
|
24 |
+
}
|
25 |
+
|
26 |
+
public static function apiBase() {
|
27 |
+
return Plugin::slug . self::API_BASE;
|
28 |
+
}
|
29 |
+
|
30 |
+
public function addApiEntry() {
|
31 |
+
if ( ! \current_user_can( 'edit_posts' ) ) {
|
32 |
+
throw new \Exception( "Access denied." );
|
33 |
+
}
|
34 |
+
|
35 |
+
\check_ajax_referer( 'contentegg-metabox', '_contentegg_nonce' );
|
36 |
+
|
37 |
+
if ( empty( $_POST['module'] ) ) {
|
38 |
+
die( "Module is undefined." );
|
39 |
+
}
|
40 |
+
|
41 |
+
$module_id = TextHelper::clear(sanitize_text_field( wp_unslash($_POST['module']) ));
|
42 |
+
$parser = ModuleManager::getInstance()->parserFactory( $module_id );
|
43 |
+
|
44 |
+
if (!$parser || ! $parser->isActive() ) {
|
45 |
+
die( "Parser module " . esc_html($parser->getId()) . " is inactive." );
|
46 |
+
}
|
47 |
+
|
48 |
+
if (isset($_POST['query']))
|
49 |
+
$query = sanitize_text_field(wp_unslash($_POST['query']));
|
50 |
+
else
|
51 |
+
$query = '';
|
52 |
+
|
53 |
+
$query = json_decode( $query, true );
|
54 |
+
|
55 |
+
if ( ! $query ) {
|
56 |
+
die( "Error: 'query' parameter cannot be empty." );
|
57 |
+
}
|
58 |
+
|
59 |
+
if ( empty( $query['keyword'] ) ) {
|
60 |
+
die( "Error: 'keyword' parameter cannot be empty." );
|
61 |
+
}
|
62 |
+
|
63 |
+
if ( $query['keyword'][0] == '[' || filter_var( $query['keyword'], FILTER_VALIDATE_URL ) ) {
|
64 |
+
$keyword = filter_var( $query['keyword'], FILTER_SANITIZE_URL );
|
65 |
+
} else {
|
66 |
+
$keyword = TextHelper::clear_utf8( $query['keyword'] );
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( ! $keyword ) {
|
70 |
+
die( "Error: 'keyword' parameter cannot be empty." );
|
71 |
+
}
|
72 |
+
|
73 |
+
try {
|
74 |
+
$data = $parser->doMultipleRequests( $keyword, $query );
|
75 |
+
foreach ( $data as $key => $item ) {
|
76 |
+
if ( ! $item->unique_id ) {
|
77 |
+
throw new \Exception( 'Item data "unique_id" must be specified.' );
|
78 |
+
}
|
79 |
+
|
80 |
+
if ( $item->description ) {
|
81 |
+
if ( ! TextHelper::isHtmlTagDetected( $item->description ) ) {
|
82 |
+
$item->description = TextHelper::br2nl( $item->description );
|
83 |
+
}
|
84 |
+
|
85 |
+
$item->description = TextHelper::removeExtraBreaks( $item->description );
|
86 |
+
}
|
87 |
+
|
88 |
+
if ( property_exists( $item, 'price' ) ) {
|
89 |
+
if ( ! (float) $item->price ) {
|
90 |
+
$item->price = 0;
|
91 |
+
$item->priceOld = 0;
|
92 |
+
} elseif ( ! (float) $item->priceOld ) {
|
93 |
+
$item->priceOld = 0;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
}
|
97 |
+
$this->formatJson( array( 'results' => $data, 'error' => '' ) );
|
98 |
+
} catch ( \Exception $e ) {
|
99 |
+
$this->formatJson( array( 'error' => $e->getMessage() ) );
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
public function formatJson( $data ) {
|
104 |
+
header( 'Content-Type: application/json; charset=UTF-8' );
|
105 |
+
echo json_encode( $data );
|
106 |
+
\wp_die();
|
107 |
+
}
|
108 |
|
109 |
}
|
application/components/ModuleConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\admin\PluginAdmin;
|
@@ -16,59 +16,51 @@ use ContentEgg\application\admin\PluginAdmin;
|
|
16 |
*/
|
17 |
abstract class ModuleConfig extends Config {
|
18 |
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
}
|
31 |
-
parent::__construct();
|
32 |
-
}
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
}
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
}
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
}
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
}
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
}
|
73 |
|
74 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\admin\PluginAdmin;
|
16 |
*/
|
17 |
abstract class ModuleConfig extends Config {
|
18 |
|
19 |
+
protected $module_id;
|
20 |
|
21 |
+
protected function __construct( $module_id = null ) {
|
22 |
+
if ( $module_id ) {
|
23 |
+
$this->module_id = $module_id;
|
24 |
+
} else {
|
25 |
+
$parts = explode( '\\', get_class( $this ) );
|
26 |
+
$this->module_id = $parts[ count( $parts ) - 2 ];
|
27 |
+
}
|
28 |
+
parent::__construct();
|
29 |
+
}
|
|
|
|
|
|
|
30 |
|
31 |
+
public function getModuleId() {
|
32 |
+
return $this->module_id;
|
33 |
+
}
|
|
|
34 |
|
35 |
+
public function getModuleName() {
|
36 |
+
return $this->getModuleInstance()->getName();
|
37 |
+
}
|
|
|
38 |
|
39 |
+
public function getModuleInstance() {
|
40 |
+
return ModuleManager::factory( $this->getModuleId() );
|
41 |
+
}
|
|
|
42 |
|
43 |
+
public function page_slug() {
|
44 |
+
return 'content-egg-modules--' . $this->getModuleId();
|
45 |
+
}
|
|
|
46 |
|
47 |
+
public function option_name() {
|
48 |
+
return Plugin::slug() . '_' . $this->getModuleId();
|
49 |
+
}
|
|
|
50 |
|
51 |
+
public function add_admin_menu() {
|
52 |
+
\add_submenu_page( 'options.php', $this->getModuleName() . ' ' . __( 'settings', 'content-egg' ) . ' ‹ Content Egg', '', 'manage_options', $this->page_slug(), array(
|
53 |
+
$this,
|
54 |
+
'settings_page'
|
55 |
+
) );
|
56 |
+
}
|
57 |
|
58 |
+
public function settings_page() {
|
59 |
+
PluginAdmin::render( 'module_settings', array( 'module' => $this->getModuleInstance(), 'config' => $this ) );
|
60 |
+
}
|
|
|
61 |
|
62 |
+
public function options() {
|
63 |
+
return array();
|
64 |
+
}
|
|
|
65 |
|
66 |
}
|
application/components/ModuleManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use \ContentEgg\application\Plugin;
|
8 |
use \ContentEgg\application\helpers\TextHelper;
|
@@ -17,417 +17,415 @@ use \ContentEgg\application\admin\AeIntegrationConfig;
|
|
17 |
*/
|
18 |
class ModuleManager {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
return $results;
|
431 |
-
}
|
432 |
|
433 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use \ContentEgg\application\Plugin;
|
8 |
use \ContentEgg\application\helpers\TextHelper;
|
17 |
*/
|
18 |
class ModuleManager {
|
19 |
|
20 |
+
const DEFAULT_MODULES_DIR = 'application/modules';
|
21 |
+
const AE_MODULES_PREFIX = 'AE';
|
22 |
+
const FEED_MODULES_PREFIX = 'Feed';
|
23 |
+
const MAX_NUM_FEED_MODULES = 25;
|
24 |
+
|
25 |
+
private static $modules = array();
|
26 |
+
private static $active_modules = array();
|
27 |
+
private static $configs = array();
|
28 |
+
private static $instance = null;
|
29 |
+
// hidden system modules
|
30 |
+
private static $hidden_modules = array( 'AE', 'Feed' );
|
31 |
+
private static $custom_modules = array();
|
32 |
+
|
33 |
+
public static function getInstance() {
|
34 |
+
if ( self::$instance == null ) {
|
35 |
+
self::$instance = new self;
|
36 |
+
}
|
37 |
+
|
38 |
+
return self::$instance;
|
39 |
+
}
|
40 |
+
|
41 |
+
private function __construct() {
|
42 |
+
$this->initModules();
|
43 |
+
}
|
44 |
+
|
45 |
+
public function adminInit() {
|
46 |
+
foreach ( $this->getConfigurableModules() as $module ) {
|
47 |
+
$config = self::configFactory( $module->getId() );
|
48 |
+
$config->adminInit();
|
49 |
+
}
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Highlight the proper submenu item
|
54 |
+
*/
|
55 |
+
public function highlightAdminMenu( $parent_file ) {
|
56 |
+
global $plugin_page;
|
57 |
+
|
58 |
+
if ( substr( $plugin_page, 0, strlen( Plugin::slug() ) ) !== Plugin::slug() ) {
|
59 |
+
return $parent_file;
|
60 |
+
}
|
61 |
+
|
62 |
+
if ( $parent_file == 'options.php' && $plugin_page == 'content-egg-settings-affiliate' ) {
|
63 |
+
$plugin_page = 'content-egg-settings-affiliate';
|
64 |
+
}
|
65 |
+
|
66 |
+
return $parent_file;
|
67 |
+
}
|
68 |
+
|
69 |
+
private function initModules() {
|
70 |
+
$modules_ids = $this->scanForDefaultModules();
|
71 |
+
|
72 |
+
if ( defined( '\CONTENT_EGG_CUSTOM_MODULES' ) && \CONTENT_EGG_CUSTOM_MODULES ) {
|
73 |
+
$modules_ids = array_merge( $modules_ids, $this->scanForCustomModules() );
|
74 |
+
}
|
75 |
+
|
76 |
+
sort( $modules_ids );
|
77 |
+
|
78 |
+
$feed_modules_ids = $this->getFeedModules();
|
79 |
+
natsort( $feed_modules_ids );
|
80 |
+
|
81 |
+
$ae_modules_ids = $this->getAffEggModules();
|
82 |
+
sort( $ae_modules_ids );
|
83 |
+
|
84 |
+
$modules_ids = array_merge( $modules_ids, $feed_modules_ids, $ae_modules_ids );
|
85 |
+
$modules_ids = \apply_filters( 'content_egg_modules', $modules_ids );
|
86 |
+
|
87 |
+
// create modules
|
88 |
+
foreach ( $modules_ids as $module_id ) {
|
89 |
+
// create module
|
90 |
+
self::factory( $module_id );
|
91 |
+
}
|
92 |
+
|
93 |
+
// fill active modules
|
94 |
+
foreach ( self::$modules as $module ) {
|
95 |
+
if ( $module->isActive() ) {
|
96 |
+
self::$active_modules[ $module->getId() ] = $module;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
private function scanForDefaultModules() {
|
102 |
+
$path = \ContentEgg\PLUGIN_PATH . self::DEFAULT_MODULES_DIR . DIRECTORY_SEPARATOR;
|
103 |
+
|
104 |
+
return $this->scanForModules( $path );
|
105 |
+
}
|
106 |
+
|
107 |
+
private function scanForCustomModules() {
|
108 |
+
$path = \WP_CONTENT_DIR . DIRECTORY_SEPARATOR . \ContentEgg\CUSTOM_MODULES_DIR . DIRECTORY_SEPARATOR;
|
109 |
+
if ( ! is_dir( $path ) ) {
|
110 |
+
return array();
|
111 |
+
}
|
112 |
+
|
113 |
+
self::$custom_modules = $this->scanForModules( $path );
|
114 |
+
|
115 |
+
return self::$custom_modules;
|
116 |
+
}
|
117 |
+
|
118 |
+
private function scanForModules( $path ) {
|
119 |
+
$folder_handle = @opendir( $path );
|
120 |
+
if ( $folder_handle === false ) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
|
124 |
+
$founded_modules = array();
|
125 |
+
|
126 |
+
while ( ( $m_dir = readdir( $folder_handle ) ) !== false ) {
|
127 |
+
if ( $m_dir == '.' || $m_dir == '..' ) {
|
128 |
+
continue;
|
129 |
+
}
|
130 |
+
$module_path = $path . $m_dir;
|
131 |
+
if ( ! is_dir( $module_path ) ) {
|
132 |
+
continue;
|
133 |
+
}
|
134 |
+
|
135 |
+
$module_id = $m_dir;
|
136 |
+
if ( in_array( $module_id, self::$hidden_modules ) ) {
|
137 |
+
continue;
|
138 |
+
}
|
139 |
+
|
140 |
+
$founded_modules[] = TextHelper::clear( $module_id );
|
141 |
+
}
|
142 |
+
closedir( $folder_handle );
|
143 |
+
|
144 |
+
return $founded_modules;
|
145 |
+
}
|
146 |
+
|
147 |
+
private function getAffEggModules() {
|
148 |
+
if ( ! AeIntegrationConfig::isAEIntegrationPosible() ) {
|
149 |
+
return array();
|
150 |
+
}
|
151 |
+
|
152 |
+
$module_ids = AeIntegrationConfig::getInstance()->option( 'modules' );
|
153 |
+
if ( ! $module_ids ) {
|
154 |
+
return array();
|
155 |
+
}
|
156 |
+
$result = array();
|
157 |
+
foreach ( $module_ids as $module_id ) {
|
158 |
+
$result[] = self::AE_MODULES_PREFIX . '__' . $module_id;
|
159 |
+
}
|
160 |
+
|
161 |
+
return $result;
|
162 |
+
}
|
163 |
+
|
164 |
+
private function getFeedModules() {
|
165 |
+
$result = array();
|
166 |
+
|
167 |
+
for ( $i = 1; $i <= self::MAX_NUM_FEED_MODULES; $i ++ ) {
|
168 |
+
if ( get_option( 'content-egg_Feed__' . $i ) ) {
|
169 |
+
$result[] = self::FEED_MODULES_PREFIX . '__' . $i;
|
170 |
+
} else {
|
171 |
+
break;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( Plugin::isFree() ) {
|
176 |
+
$max = 3;
|
177 |
+
} else {
|
178 |
+
$max = self::MAX_NUM_FEED_MODULES;
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( count( $result ) < $max ) {
|
182 |
+
$num = count( $result ) + 1;
|
183 |
+
$result[] = self::FEED_MODULES_PREFIX . '__' . $num;
|
184 |
+
}
|
185 |
+
|
186 |
+
return $result;
|
187 |
+
}
|
188 |
+
|
189 |
+
public static function isCustomModule( $module_id ) {
|
190 |
+
if ( in_array( $module_id, self::$custom_modules ) ) {
|
191 |
+
return true;
|
192 |
+
} else {
|
193 |
+
return false;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
public static function factory( $module_id ) {
|
198 |
+
if ( ! isset( self::$modules[ $module_id ] ) ) {
|
199 |
+
$path_prefix = Module::getPathId( $module_id );
|
200 |
+
if ( self::isCustomModule( $module_id ) ) {
|
201 |
+
$module_class = "\\ContentEggCustomModule\\" . $path_prefix . "\\" . $path_prefix . 'Module';
|
202 |
+
} else {
|
203 |
+
$module_class = "\\ContentEgg\\application\\modules\\" . $path_prefix . "\\" . $path_prefix . 'Module';
|
204 |
+
}
|
205 |
+
|
206 |
+
if ( class_exists( $module_class, true ) === false ) {
|
207 |
+
throw new \Exception( "Unable to load module class: '{$module_class}'." );
|
208 |
+
}
|
209 |
+
|
210 |
+
$module = new $module_class( $module_id );
|
211 |
+
|
212 |
+
if ( ! ( $module instanceof \ContentEgg\application\components\Module ) ) {
|
213 |
+
throw new \Exception( "The module '{$module_id}' must inherit from Module." );
|
214 |
+
}
|
215 |
+
|
216 |
+
if ( Plugin::isFree() && ! $module->isFree() ) {
|
217 |
+
return false;
|
218 |
+
}
|
219 |
+
|
220 |
+
self::$modules[ $module_id ] = $module;
|
221 |
+
}
|
222 |
+
|
223 |
+
return self::$modules[ $module_id ];
|
224 |
+
}
|
225 |
+
|
226 |
+
public static function parserFactory( $module_id ) {
|
227 |
+
$module = self::factory( $module_id );
|
228 |
+
if ( ! ( $module instanceof \ContentEgg\application\components\ParserModule ) ) {
|
229 |
+
throw new \Exception( "The parser module '{$module_id}' must inherit from ParserModule." );
|
230 |
+
}
|
231 |
+
|
232 |
+
return $module;
|
233 |
+
}
|
234 |
+
|
235 |
+
public static function configFactory( $module_id ) {
|
236 |
+
if ( ! isset( self::$configs[ $module_id ] ) ) {
|
237 |
+
$path_prefix = Module::getPathId( $module_id );
|
238 |
+
|
239 |
+
if ( self::isCustomModule( $module_id ) ) {
|
240 |
+
$config_class = "\\ContentEggCustomModule\\" . $path_prefix . "\\" . $path_prefix . 'Config';
|
241 |
+
} else {
|
242 |
+
$config_class = "\\ContentEgg\\application\\modules\\" . $path_prefix . "\\" . $path_prefix . 'Config';
|
243 |
+
}
|
244 |
+
|
245 |
+
if ( class_exists( $config_class, true ) === false ) {
|
246 |
+
throw new \Exception( "Unable to load module config class: '{$config_class}'." );
|
247 |
+
}
|
248 |
+
|
249 |
+
$config = $config_class::getInstance( $module_id );
|
250 |
+
|
251 |
+
if ( self::factory( $module_id )->isParser() ) {
|
252 |
+
if ( ! ( $config instanceof \ContentEgg\application\components\ParserModuleConfig ) ) {
|
253 |
+
throw new \Exception( "The parser module config '{$config_class}' must inherit from ParserModuleConfig." );
|
254 |
+
}
|
255 |
+
} else {
|
256 |
+
if ( ! ( $config instanceof \ContentEgg\application\components\ModuleConfig ) ) {
|
257 |
+
throw new \Exception( "The module config '{$config_class}' must inherit from ModuleConfig." );
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
self::$configs[ $module_id ] = $config;
|
262 |
+
}
|
263 |
+
|
264 |
+
return self::$configs[ $module_id ];
|
265 |
+
}
|
266 |
+
|
267 |
+
public function getModules( $only_active = false ) {
|
268 |
+
if ( $only_active ) {
|
269 |
+
return self::$active_modules;
|
270 |
+
} else {
|
271 |
+
return self::$modules;
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
public function getModulesIdList( $only_active = false ) {
|
276 |
+
return array_keys( $this->getModules( $only_active ) );
|
277 |
+
}
|
278 |
+
|
279 |
+
public function getParserModules( $only_active = false ) {
|
280 |
+
$modules = $this->getModules( $only_active );
|
281 |
+
$parsers = array();
|
282 |
+
foreach ( $modules as $module ) {
|
283 |
+
if ( $module->isParser() ) {
|
284 |
+
$parsers[ $module->getId() ] = $module;
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
return $parsers;
|
289 |
+
}
|
290 |
+
|
291 |
+
public function getAffiliateParsers( $only_active = false, $only_product = false ) {
|
292 |
+
$modules = $this->getModules( $only_active );
|
293 |
+
$parsers = array();
|
294 |
+
foreach ( $modules as $module ) {
|
295 |
+
if ( $only_product && strstr( $module->getId(), 'Coupons' ) ) {
|
296 |
+
continue;
|
297 |
+
}
|
298 |
+
|
299 |
+
if ( ! $module->isAffiliateParser() ) {
|
300 |
+
continue;
|
301 |
+
}
|
302 |
+
|
303 |
+
$parsers[ $module->getId() ] = $module;
|
304 |
+
}
|
305 |
+
|
306 |
+
return $parsers;
|
307 |
+
}
|
308 |
+
|
309 |
+
public function getParserModulesIdList( $only_active = false ) {
|
310 |
+
return array_keys( $this->getParserModules( $only_active ) );
|
311 |
+
}
|
312 |
+
|
313 |
+
public function getParserModulesByTypes( $types, $only_active = true ) {
|
314 |
+
if ( $types == 'ALL' ) {
|
315 |
+
$types = null;
|
316 |
+
}
|
317 |
+
|
318 |
+
if ( $types && ! is_array( $types ) ) {
|
319 |
+
$types = array( $types );
|
320 |
+
}
|
321 |
+
$res = array();
|
322 |
+
foreach ( $this->getParserModules( $only_active ) as $module ) {
|
323 |
+
if ( $types && ! in_array( $module->getParserType(), $types ) ) {
|
324 |
+
continue;
|
325 |
+
}
|
326 |
+
$res[ $module->getId() ] = $module;
|
327 |
+
}
|
328 |
+
|
329 |
+
return $res;
|
330 |
+
}
|
331 |
+
|
332 |
+
public function getParserModuleIdsByTypes( $types, $only_active = true ) {
|
333 |
+
return array_keys( $this->getParserModulesByTypes( $types, $only_active ) );
|
334 |
+
}
|
335 |
+
|
336 |
+
public function getConfigurableModules( $active_only = false ) {
|
337 |
+
$result = array();
|
338 |
+
foreach ( $this->getModules( $active_only ) as $module ) {
|
339 |
+
if ( $module->isConfigurable() ) {
|
340 |
+
$result[] = $module;
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
return $result;
|
345 |
+
}
|
346 |
+
|
347 |
+
public function moduleExists( $module_id ) {
|
348 |
+
if ( isset( self::$modules[ $module_id ] ) ) {
|
349 |
+
return true;
|
350 |
+
} else {
|
351 |
+
return false;
|
352 |
+
}
|
353 |
+
}
|
354 |
+
|
355 |
+
public function isModuleActive( $module_id ) {
|
356 |
+
if ( isset( self::$active_modules[ $module_id ] ) ) {
|
357 |
+
return true;
|
358 |
+
} else {
|
359 |
+
return false;
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
public function getOptionsList() {
|
364 |
+
$options = array();
|
365 |
+
foreach ( $this->getConfigurableModules() as $module ) {
|
366 |
+
$config = $module->getConfigInstance();
|
367 |
+
$options[ $config->option_name() ] = $config->getOptionValues();
|
368 |
+
//$opt_name = $module->getConfigInstance()->option_name();
|
369 |
+
//$options[$opt_name] = \get_option($opt_name);
|
370 |
+
}
|
371 |
+
|
372 |
+
return $options;
|
373 |
+
}
|
374 |
+
|
375 |
+
public function getItemsUpdateModuleIds() {
|
376 |
+
$result = array();
|
377 |
+
foreach ( $this->getAffiliateParsers( true ) as $module ) {
|
378 |
+
if ( ! $module->isItemsUpdateAvailable() || ! $module->config( 'ttl_items' ) ) {
|
379 |
+
continue;
|
380 |
+
}
|
381 |
+
|
382 |
+
if ( $module->config( 'update_mode' ) == 'cron' || $module->config( 'update_mode' ) == 'visit_cron' ) {
|
383 |
+
$result[] = $module->getId();
|
384 |
+
}
|
385 |
+
}
|
386 |
+
|
387 |
+
return $result;
|
388 |
+
}
|
389 |
+
|
390 |
+
public function getByKeywordUpdateModuleIds() {
|
391 |
+
$result = array();
|
392 |
+
foreach ( $this->getAffiliateParsers( true ) as $module ) {
|
393 |
+
if ( ! $module->config( 'ttl' ) ) {
|
394 |
+
continue;
|
395 |
+
}
|
396 |
+
|
397 |
+
if ( $module->config( 'update_mode' ) == 'cron' || $module->config( 'update_mode' ) == 'visit_cron' ) {
|
398 |
+
$result[] = $module->getId();
|
399 |
+
}
|
400 |
+
}
|
401 |
+
|
402 |
+
return $result;
|
403 |
+
}
|
404 |
+
|
405 |
+
public function getAffiliteModulesList( $only_active = true ) {
|
406 |
+
$results = array();
|
407 |
+
$modules = ModuleManager::getInstance()->getAffiliateParsers( $only_active );
|
408 |
+
$feeds = array();
|
409 |
+
foreach ( $modules as $module_id => $module ) {
|
410 |
+
/*
|
411 |
+
if ($module->isFeedParser())
|
412 |
+
$feeds[$module_id] = $module->getName();
|
413 |
+
else
|
414 |
+
*
|
415 |
+
*/
|
416 |
+
$results[ $module_id ] = $module->getName();
|
417 |
+
}
|
418 |
+
|
419 |
+
/*
|
420 |
+
if ($feeds)
|
421 |
+
{
|
422 |
+
array_pop($feeds);
|
423 |
+
$results = array_merge($results, $feeds);
|
424 |
+
}
|
425 |
+
*
|
426 |
+
*/
|
427 |
+
|
428 |
+
return $results;
|
429 |
+
}
|
|
|
|
|
430 |
|
431 |
}
|
application/components/ModuleTemplateManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
@@ -16,85 +16,85 @@ use ContentEgg\application\components\ModuleManager;
|
|
16 |
*/
|
17 |
class ModuleTemplateManager extends TemplateManager {
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
16 |
*/
|
17 |
class ModuleTemplateManager extends TemplateManager {
|
18 |
|
19 |
+
const TEMPLATE_DIR = 'templates';
|
20 |
+
const CUSTOM_TEMPLATE_DIR = 'content-egg-templates';
|
21 |
+
const TEMPLATE_PREFIX = 'data_';
|
22 |
+
|
23 |
+
private $module_id;
|
24 |
+
private static $instances = array();
|
25 |
+
|
26 |
+
public static function getInstance( $module_id ) {
|
27 |
+
if ( ! isset( self::$instances[ $module_id ] ) ) {
|
28 |
+
self::$instances[ $module_id ] = new self( $module_id );
|
29 |
+
}
|
30 |
+
|
31 |
+
return self::$instances[ $module_id ];
|
32 |
+
}
|
33 |
+
|
34 |
+
private function __construct( $module_id ) {
|
35 |
+
$this->module_id = $module_id;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getTempatePrefix() {
|
39 |
+
return self::TEMPLATE_PREFIX;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function getTempateDir() {
|
43 |
+
$path_id = Module::getPathId( $this->module_id );
|
44 |
+
if ( ModuleManager::isCustomModule( $this->module_id ) ) {
|
45 |
+
$path = \WP_CONTENT_DIR . '/' . \ContentEgg\CUSTOM_MODULES_DIR . '/' . $path_id . '/' . self::TEMPLATE_DIR;
|
46 |
+
} else {
|
47 |
+
$path = \ContentEgg\PLUGIN_PATH . 'application/modules/' . $path_id . '/' . self::TEMPLATE_DIR;
|
48 |
+
}
|
49 |
+
|
50 |
+
return $path;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function getCustomTempateDirs() {
|
54 |
+
return array(
|
55 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId( $this->module_id ),
|
56 |
+
//child theme
|
57 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId( $this->module_id ),
|
58 |
+
// theme
|
59 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId( $this->module_id ),
|
60 |
+
);
|
61 |
+
}
|
62 |
+
|
63 |
+
public function getModuleId() {
|
64 |
+
return $this->module_id;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getTemplatesList( $short_mode = false ) {
|
68 |
+
$templates = parent::getTemplatesList( $short_mode );
|
69 |
+
$templates = \apply_filters( 'content_egg_module_templates', $templates, $this->getModuleId() );
|
70 |
+
|
71 |
+
return $templates;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function render( $view_name, array $_data = array() ) {
|
75 |
+
if ( ! self::isCustomTemplate( $view_name ) ) {
|
76 |
+
$this->enqueueProductsStyle();
|
77 |
+
}
|
78 |
+
|
79 |
+
return parent::render( $view_name, $_data );
|
80 |
+
}
|
81 |
+
|
82 |
+
public function renderPartialModule( $view_name, $module_ids = array(), $data = array() ) {
|
83 |
+
if ( ! $module_ids ) {
|
84 |
+
$module_ids = array();
|
85 |
+
}
|
86 |
+
|
87 |
+
if ( ! is_array( $module_ids ) ) {
|
88 |
+
$module_ids = array( $module_ids );
|
89 |
+
}
|
90 |
+
|
91 |
+
$current_module_id = $this->module_id;
|
92 |
+
if ( $module_ids && ! in_array( $current_module_id, $module_ids ) ) {
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
|
96 |
+
$view_path = $this->getTempateDir() . DIRECTORY_SEPARATOR . TextHelper::clear( $view_name ) . '.php';
|
97 |
+
$this->renderPath( $view_path, $data );
|
98 |
+
}
|
99 |
|
100 |
}
|
application/components/ParserModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\ImageHelper;
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
@@ -19,199 +19,184 @@ use ContentEgg\application\Plugin;
|
|
19 |
*/
|
20 |
abstract class ParserModule extends Module {
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
if ($item->unique_id == $result->unique_id)
|
203 |
-
{
|
204 |
-
$dup = true;
|
205 |
-
break;
|
206 |
-
}
|
207 |
-
}
|
208 |
-
|
209 |
-
if (!$dup)
|
210 |
-
$results[] = $item;
|
211 |
-
|
212 |
-
}
|
213 |
-
|
214 |
-
return $results;
|
215 |
-
}
|
216 |
-
|
217 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\ImageHelper;
|
8 |
use ContentEgg\application\helpers\TextHelper;
|
19 |
*/
|
20 |
abstract class ParserModule extends Module {
|
21 |
|
22 |
+
const PARSER_TYPE_CONTENT = 'CONTENT';
|
23 |
+
const PARSER_TYPE_PRODUCT = 'PRODUCT';
|
24 |
+
const PARSER_TYPE_COUPON = 'COUPON';
|
25 |
+
const PARSER_TYPE_IMAGE = 'IMAGE';
|
26 |
+
const PARSER_TYPE_VIDEO = 'VIDEO';
|
27 |
+
const PARSER_TYPE_OTHER = 'OTHER';
|
28 |
+
|
29 |
+
abstract public function doRequest( $keyword, $query_params = array(), $is_autoupdate = false );
|
30 |
+
|
31 |
+
abstract public function getParserType();
|
32 |
+
|
33 |
+
public function isActive() {
|
34 |
+
if ( $this->is_active === null ) {
|
35 |
+
if ( $this->getConfigInstance()->option( 'is_active' ) ) {
|
36 |
+
$this->is_active = true;
|
37 |
+
} else {
|
38 |
+
$this->is_active = false;
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
return $this->is_active;
|
43 |
+
}
|
44 |
+
|
45 |
+
final public function isParser() {
|
46 |
+
return true;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function isUrlSearchAllowed() {
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function presavePrepare( $data, $post_id ) {
|
54 |
+
global $post;
|
55 |
+
$data = parent::presavePrepare( $data, $post_id );
|
56 |
+
|
57 |
+
// do not save images for revisions & search results
|
58 |
+
if ( ( $post && wp_is_post_revision( $post_id ) ) || $post_id < 0 ) {
|
59 |
+
return $data;
|
60 |
+
}
|
61 |
+
|
62 |
+
$old_data = ContentManager::getData( $post_id, $this->getId() );
|
63 |
+
|
64 |
+
foreach ( $data as $key => $item ) {
|
65 |
+
// fill domain
|
66 |
+
if ( empty( $item['domain'] ) ) {
|
67 |
+
if ( ! empty( $item['orig_url'] ) ) {
|
68 |
+
$url = $item['orig_url'];
|
69 |
+
} elseif ( ! empty( $item['img'] ) ) {
|
70 |
+
$url = $item['img'];
|
71 |
+
} else {
|
72 |
+
$url = $item['url'];
|
73 |
+
}
|
74 |
+
|
75 |
+
if ( $url ) {
|
76 |
+
$domain = TextHelper::getHostName( $url );
|
77 |
+
if ( ! in_array( $domain, array( 'buscape.com.br', 'avlws.com' ) ) ) {
|
78 |
+
$data[ $key ]['domain'] = $item['domain'] = $domain;
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
// save img
|
83 |
+
if ( $this->config( 'save_img' ) && ! wp_is_post_revision( $post_id ) ) {
|
84 |
+
// check old_data also. need for fix behavior with "preview changes" button and by keyword update
|
85 |
+
if ( isset( $old_data[ $key ] ) && ! empty( $old_data[ $key ]['img_file'] ) && file_exists( ImageHelper::getFullImgPath( $old_data[ $key ]['img_file'] ) ) ) {
|
86 |
+
// image exists
|
87 |
+
$item['img'] = $old_data[ $key ]['img'];
|
88 |
+
$item['img_file'] = $old_data[ $key ]['img_file'];
|
89 |
+
} elseif ( $item['img'] && empty( $item['img_file'] ) ) {
|
90 |
+
$local_img_name = ImageHelper::saveImgLocaly( $item['img'], $item['title'] );
|
91 |
+
if ( $local_img_name ) {
|
92 |
+
$uploads = \wp_upload_dir();
|
93 |
+
$item['img'] = $uploads['url'] . '/' . $local_img_name;
|
94 |
+
$item['img_file'] = ltrim( trailingslashit( $uploads['subdir'] ), '\/' ) . $local_img_name;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
$data[ $key ] = $item;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
return $data;
|
102 |
+
}
|
103 |
+
|
104 |
+
public static function getFullImgPath( $img_path ) {
|
105 |
+
$uploads = \wp_upload_dir();
|
106 |
+
|
107 |
+
return trailingslashit( $uploads['basedir'] ) . $img_path;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function defaultTemplateName() {
|
111 |
+
return 'data_simple';
|
112 |
+
}
|
113 |
+
|
114 |
+
public function viewDataPrepare( $data ) {
|
115 |
+
// cashback integration
|
116 |
+
if ( GeneralConfig::getInstance()->option( 'cashback_integration' ) == 'enabled' && class_exists( '\CashbackTracker\application\Plugin' ) ) {
|
117 |
+
foreach ( $data as $key => $d ) {
|
118 |
+
$data[ $key ]['url'] = \CashbackTracker\application\components\DeeplinkGenerator::maybeAddTracking( $d['url'] );
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
// local redirect
|
123 |
+
if ( $this->config( 'set_local_redirect' ) ) {
|
124 |
+
foreach ( $data as $key => $d ) {
|
125 |
+
if ( isset( $d['url'] ) ) {
|
126 |
+
$data[ $key ]['aff_url'] = $d['url'];
|
127 |
+
} // url without redirect
|
128 |
+
|
129 |
+
$data[ $key ]['url'] = LocalRedirect::createRedirectUrl( $d );
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
return $data;
|
134 |
+
}
|
135 |
+
|
136 |
+
public function getAccessToken( $force = false ) {
|
137 |
+
$transient_name = Plugin::slug() . '-' . $this->getId() . '-access_token';
|
138 |
+
$token = \get_transient( $transient_name );
|
139 |
+
if ( ! $token || $force ) {
|
140 |
+
try {
|
141 |
+
list( $token, $expires_in ) = $this->requestAccessToken();
|
142 |
+
} catch ( \Exception $e ) {
|
143 |
+
return false;
|
144 |
+
}
|
145 |
+
\set_transient( $transient_name, $token, (int) $expires_in );
|
146 |
+
}
|
147 |
+
|
148 |
+
return $token;
|
149 |
+
}
|
150 |
+
|
151 |
+
public function isFeedParser() {
|
152 |
+
if ( $this->getIdStatic() == ModuleManager::FEED_MODULES_PREFIX ) {
|
153 |
+
return true;
|
154 |
+
} else {
|
155 |
+
return false;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
public function doMultipleRequests( $keyword, $query_params = array(), $is_autoupdate = false ) {
|
160 |
+
if ( ! \apply_filters( 'cegg_disable_multiple_keywords', false ) ) {
|
161 |
+
$keywords = explode( ',', $keyword, 10 );
|
162 |
+
} else {
|
163 |
+
$keywords = array( $keyword );
|
164 |
+
}
|
165 |
+
|
166 |
+
$keywords = array_map( 'trim', $keywords );
|
167 |
+
|
168 |
+
$results = array();
|
169 |
+
foreach ( $keywords as $i => $keyword ) {
|
170 |
+
if ( $i && $this->getId() == 'Amazon' ) {
|
171 |
+
sleep( 1 );
|
172 |
+
}
|
173 |
+
|
174 |
+
$results = array_merge( $results, $this->doRequest( $keyword, $query_params, $is_autoupdate ) );
|
175 |
+
}
|
176 |
+
|
177 |
+
$results = self::filterDuplicateItems( $results );
|
178 |
+
|
179 |
+
return $results;
|
180 |
+
}
|
181 |
+
|
182 |
+
private static function filterDuplicateItems( array $items ) {
|
183 |
+
$results = array();
|
184 |
+
foreach ( $items as $item ) {
|
185 |
+
$dup = false;
|
186 |
+
foreach ( $results as $result ) {
|
187 |
+
if ( $item->unique_id == $result->unique_id ) {
|
188 |
+
$dup = true;
|
189 |
+
break;
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
if ( ! $dup ) {
|
194 |
+
$results[] = $item;
|
195 |
+
}
|
196 |
+
|
197 |
+
}
|
198 |
+
|
199 |
+
return $results;
|
200 |
+
}
|
201 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
application/components/ParserModuleConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
@@ -13,119 +13,117 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class ParserModuleConfig extends ModuleConfig {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
'
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
'
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
);
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
public function checkRequirements($value)
|
101 |
-
{
|
102 |
-
if ($requirements = $this->getModuleInstance()->requirements())
|
103 |
-
return false;
|
104 |
-
else
|
105 |
-
return true;
|
106 |
-
}
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
if (strpos($option['title'], '*'))
|
115 |
-
$keys[] = $key;
|
116 |
-
|
117 |
-
$options[$key]['title'] = str_replace('**', '', $option['title']);
|
118 |
-
}
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
unset($options[$key]);
|
125 |
-
}
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserModuleConfig abstract class file
|
13 |
*/
|
14 |
abstract class ParserModuleConfig extends ModuleConfig {
|
15 |
|
16 |
+
public function options() {
|
17 |
+
$tpl_manager = ModuleTemplateManager::getInstance( $this->module_id );
|
18 |
+
$options = array(
|
19 |
+
'is_active' => array(
|
20 |
+
'title' => __( 'Enable module', 'content-egg' ),
|
21 |
+
'description' => '',
|
22 |
+
'callback' => array( $this, 'render_checkbox' ),
|
23 |
+
'default' => 0,
|
24 |
+
'section' => 'default',
|
25 |
+
'validator' => array(
|
26 |
+
array(
|
27 |
+
'call' => array( $this, 'checkRequirements' ),
|
28 |
+
'message' => __( 'Could not activate.', 'content-egg' ),
|
29 |
+
),
|
30 |
+
),
|
31 |
+
),
|
32 |
+
'embed_at' => array(
|
33 |
+
'title' => __( 'Auto-embedding', 'content-egg' ),
|
34 |
+
'callback' => array( $this, 'render_dropdown' ),
|
35 |
+
'dropdown_options' => array(
|
36 |
+
'shortcode' => __( 'Shortcodes only', 'content-egg' ),
|
37 |
+
'post_bottom' => __( 'At the end of the post', 'content-egg' ),
|
38 |
+
'post_top' => __( 'At the beginning of the post', 'content-egg' ),
|
39 |
+
),
|
40 |
+
'default' => 'shortcode',
|
41 |
+
'section' => 'default',
|
42 |
+
),
|
43 |
+
'priority' => array(
|
44 |
+
'title' => __( 'Priority', 'content-egg' ),
|
45 |
+
'description' => __( 'Priority sets order of modules in post. 0 - is the most highest priority.', 'content-egg' ) . ' ' .
|
46 |
+
__( 'Also it applied to price sorting.', 'content-egg' ),
|
47 |
+
'callback' => array( $this, 'render_input' ),
|
48 |
+
'default' => 10,
|
49 |
+
'validator' => array(
|
50 |
+
'trim',
|
51 |
+
'absint',
|
52 |
+
),
|
53 |
+
'section' => 'default',
|
54 |
+
),
|
55 |
+
'template' => array(
|
56 |
+
'title' => __( 'Template', 'content-egg' ),
|
57 |
+
'description' => __( 'Default template', 'content-egg' ),
|
58 |
+
'callback' => array( $this, 'render_dropdown' ),
|
59 |
+
'dropdown_options' => $tpl_manager->getTemplatesList(),
|
60 |
+
'default' => $this->getModuleInstance()->defaultTemplateName(),
|
61 |
+
'section' => 'default',
|
62 |
+
),
|
63 |
+
'tpl_title' => array(
|
64 |
+
'title' => __( 'Title', 'content-egg' ),
|
65 |
+
'description' => __( 'Templates may use title on data output.', 'content-egg' ),
|
66 |
+
'callback' => array( $this, 'render_input' ),
|
67 |
+
'default' => '',
|
68 |
+
'validator' => array(
|
69 |
+
'trim',
|
70 |
+
),
|
71 |
+
'section' => 'default',
|
72 |
+
),
|
73 |
+
'featured_image' => array(
|
74 |
+
'title' => 'Featured image',
|
75 |
+
'description' => __( 'Automatically set Featured image for post', 'content-egg' ),
|
76 |
+
'callback' => array( $this, 'render_dropdown' ),
|
77 |
+
'dropdown_options' => array(
|
78 |
+
'' => __( 'Don\'t set', 'content-egg' ),
|
79 |
+
'first' => __( 'First image', 'content-egg' ),
|
80 |
+
'second' => __( 'Second image', 'content-egg' ),
|
81 |
+
'rand' => __( 'Random image', 'content-egg' ),
|
82 |
+
'last' => __( 'Last image', 'content-egg' ),
|
83 |
+
),
|
84 |
+
'default' => '',
|
85 |
+
'section' => 'default',
|
86 |
+
),
|
87 |
+
'set_local_redirect' => array(
|
88 |
+
'title' => __( 'Redirect', 'content-egg' ),
|
89 |
+
'description' => __( 'Make links with local 301 redirect', 'content-egg' ),
|
90 |
+
'callback' => array( $this, 'render_checkbox' ),
|
91 |
+
'default' => 0,
|
92 |
+
'section' => 'default',
|
93 |
+
),
|
94 |
+
);
|
|
|
95 |
|
96 |
+
return array_merge( parent::options(), $options );
|
97 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
public function checkRequirements( $value ) {
|
100 |
+
if ( $requirements = $this->getModuleInstance()->requirements() ) {
|
101 |
+
return false;
|
102 |
+
} else {
|
103 |
+
return true;
|
104 |
+
}
|
105 |
+
}
|
106 |
|
107 |
+
protected static function moveRequiredUp( array $options ) {
|
108 |
+
$keys = array( 'is_active' );
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
+
foreach ( $options as $key => $option ) {
|
111 |
+
if ( strpos( $option['title'], '*' ) ) {
|
112 |
+
$keys[] = $key;
|
113 |
+
}
|
|
|
|
|
114 |
|
115 |
+
$options[ $key ]['title'] = str_replace( '**', '', $option['title'] );
|
116 |
+
}
|
117 |
+
|
118 |
+
$res = array();
|
119 |
+
foreach ( $keys as $key ) {
|
120 |
+
$res[ $key ] = $options[ $key ];
|
121 |
+
unset( $options[ $key ] );
|
122 |
+
}
|
123 |
+
|
124 |
+
$res = array_merge( $res, $options );
|
125 |
+
|
126 |
+
return $res;
|
127 |
+
}
|
128 |
|
129 |
}
|
application/components/ReviewNotice.php
CHANGED
@@ -2,13 +2,13 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\models\ProductModel;
|
9 |
|
10 |
/**
|
11 |
-
*
|
12 |
*
|
13 |
* @author keywordrush.com <support@keywordrush.com>
|
14 |
* @link https://www.keywordrush.com
|
@@ -16,85 +16,99 @@ use ContentEgg\application\models\ProductModel;
|
|
16 |
*/
|
17 |
class ReviewNotice {
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\Plugin;
|
8 |
use ContentEgg\application\models\ProductModel;
|
9 |
|
10 |
/**
|
11 |
+
* ReviewNotice class file
|
12 |
*
|
13 |
* @author keywordrush.com <support@keywordrush.com>
|
14 |
* @link https://www.keywordrush.com
|
16 |
*/
|
17 |
class ReviewNotice {
|
18 |
|
19 |
+
private static $instance = null;
|
20 |
+
|
21 |
+
const MIN_PRODUCTS_TRIGGER = 100;
|
22 |
+
const PRODUC_COUNT_TTL = 86400;
|
23 |
+
|
24 |
+
public static function getInstance() {
|
25 |
+
if ( self::$instance == null ) {
|
26 |
+
self::$instance = new self;
|
27 |
+
}
|
28 |
+
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
public function adminInit() {
|
33 |
+
\add_action( 'admin_notices', array( $this, 'displayNotice' ) );
|
34 |
+
$this->hideNotice();
|
35 |
+
}
|
36 |
+
|
37 |
+
public function displayNotice() {
|
38 |
+
|
39 |
+
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
|
40 |
+
return;
|
41 |
+
}
|
42 |
+
|
43 |
+
if ( \get_transient( 'cegg_hide_notice_review_products_trigger' ) ) {
|
44 |
+
return;
|
45 |
+
}
|
46 |
+
|
47 |
+
$last_sync = ProductModel::model()->getLastSync();
|
48 |
+
if ( ! $last_sync || time() - $last_sync > self::PRODUC_COUNT_TTL ) {
|
49 |
+
ProductModel::model()->maybeScanProducts();
|
50 |
+
}
|
51 |
+
|
52 |
+
$total = ProductModel::model()->count();
|
53 |
+
if ( $total < self::MIN_PRODUCTS_TRIGGER ) {
|
54 |
+
return;
|
55 |
+
}
|
56 |
+
|
57 |
+
$rate_url = 'https://wordpress.org/support/plugin/' . Plugin::getSlug() . '/reviews/?filter=5#new-post';
|
58 |
+
$page_url = \get_admin_url( \get_current_blog_id(), 'admin.php?page=content-egg-product' );
|
59 |
+
|
60 |
+
$hide_notice_uri = \add_query_arg( array(
|
61 |
+
'cegg_hide_notice' => 'review_products_trigger',
|
62 |
+
'_cegg_notice_nonce' => \wp_create_nonce( 'hide_notice' )
|
63 |
+
), esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
|
64 |
+
|
65 |
+
$this->addInlineCss();
|
66 |
+
echo '<div class="notice notice-success egg-notice"><p>';
|
67 |
+
echo '<img src=" ' . esc_url_raw( \ContentEgg\PLUGIN_RES ) . '/img/logo.png' . '" width="40" />';
|
68 |
+
echo '<b>' . 'Congrats, you have <a href="' . esc_url_raw( $page_url ) . '">' . esc_html( $total ) . ' products</a> added with %s' . esc_html( Plugin::getName() ) . '</b>';
|
69 |
+
echo '<br>';
|
70 |
+
echo ' ' . 'We would very much appreciate if you could quickly rate the plugin on WP.';
|
71 |
+
echo ' ' . 'Just to help us spread the word and boost our motivation.';
|
72 |
+
echo '<br><em> - ' . sprintf( 'Your %s team', 'Keywordrush' ), '</em>';
|
73 |
+
echo '<br>';
|
74 |
+
echo sprintf( '<a style="color:#00a32a;font-weight:bold;" target="_blank" href="%s">★ %s</a>', esc_url_raw( $rate_url ), 'Give it a 5-star rating' );
|
75 |
+
echo ' | ';
|
76 |
+
echo sprintf( '<a href="%s">%s</a>', esc_url_raw( $hide_notice_uri ), '✕ ' . 'Dismiss this notice' );
|
77 |
+
|
78 |
+
echo '</p></div>';
|
79 |
+
}
|
80 |
+
|
81 |
+
public function hideNotice() {
|
82 |
+
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
|
83 |
+
return;
|
84 |
+
}
|
85 |
+
|
86 |
+
if ( ! isset( $_GET['cegg_hide_notice'] ) ) {
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( ! isset( $_GET['_cegg_notice_nonce'] ) || ! \wp_verify_nonce( sanitize_key( $_GET['_cegg_notice_nonce'] ), 'hide_notice' ) ) {
|
91 |
+
return;
|
92 |
+
}
|
93 |
+
|
94 |
+
$notice = \sanitize_text_field( wp_unslash( $_GET['cegg_hide_notice'] ) );
|
95 |
+
|
96 |
+
if ( ! in_array( $notice, array( 'review_products_trigger' ) ) ) {
|
97 |
+
return;
|
98 |
+
}
|
99 |
+
|
100 |
+
$expiration = 0;
|
101 |
+
\set_transient( 'cegg_hide_notice_' . $notice, time(), $expiration );
|
102 |
+
|
103 |
+
\wp_safe_redirect( \remove_query_arg( array(
|
104 |
+
'cegg_hide_notice',
|
105 |
+
'_cegg_notice_nonce'
|
106 |
+
), esc_url_raw( \wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) );
|
107 |
+
exit;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function addInlineCss() {
|
111 |
+
echo '<style>.egg-notice a.egg-notice-close {position:static;float:right;top:0;right0;padding:0;margin-top:-20px;line-height:1.23076923;text-decoration:none;}.egg-notice a.egg-notice-close::before{position: relative;top: 18px;left: -20px;}.egg-notice img {float:left;width:40px;padding-right:12px;}</style>';
|
112 |
+
}
|
113 |
|
114 |
}
|
application/components/Scheduler.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Scheduler class file
|
@@ -13,26 +13,24 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class Scheduler implements iScheduler {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
\wp_clear_scheduled_hook(static::getCronTag());
|
36 |
-
}
|
37 |
|
38 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Scheduler class file
|
13 |
*/
|
14 |
abstract class Scheduler implements iScheduler {
|
15 |
|
16 |
+
public static function initAction() {
|
17 |
+
\add_action( static::getCronTag(), array( get_called_class(), 'run' ) );
|
18 |
+
}
|
19 |
+
|
20 |
+
public static function addScheduleEvent( $recurrence = 'hourly', $timestamp = null ) {
|
21 |
+
if ( ! \wp_next_scheduled( static::getCronTag() ) ) {
|
22 |
+
if ( ! $timestamp ) {
|
23 |
+
$timestamp = time();
|
24 |
+
}
|
25 |
+
|
26 |
+
\wp_schedule_event( $timestamp, $recurrence, static::getCronTag() );
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
public static function clearScheduleEvent() {
|
31 |
+
if ( \wp_next_scheduled( static::getCronTag() ) ) {
|
32 |
+
\wp_clear_scheduled_hook( static::getCronTag() );
|
33 |
+
}
|
34 |
+
}
|
|
|
|
|
35 |
|
36 |
}
|
application/components/Shortcoded.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Shortcoded class file
|
@@ -13,41 +13,37 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class Shortcoded {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
return true;
|
49 |
-
else
|
50 |
-
return false;
|
51 |
-
}
|
52 |
|
53 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Shortcoded class file
|
13 |
*/
|
14 |
class Shortcoded {
|
15 |
|
16 |
+
private static $instances = array();
|
17 |
+
private static $shortcoded_module_ids = array();
|
18 |
+
private $post_id;
|
19 |
+
|
20 |
+
public static function getInstance( $post_id ) {
|
21 |
+
if ( ! isset( self::$instances[ $post_id ] ) ) {
|
22 |
+
self::$instances[ $post_id ] = new self( $post_id );
|
23 |
+
self::$shortcoded_module_ids[ $post_id ] = array();
|
24 |
+
}
|
25 |
+
|
26 |
+
return self::$instances[ $post_id ];
|
27 |
+
}
|
28 |
+
|
29 |
+
private function __construct( $post_id ) {
|
30 |
+
$this->post_id = $post_id;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getShortcodedModuleIds() {
|
34 |
+
return self::$shortcoded_module_ids[ $this->post_id ];
|
35 |
+
}
|
36 |
+
|
37 |
+
public function setShortcodedModule( $module_id ) {
|
38 |
+
self::$shortcoded_module_ids[ $this->post_id ][ $module_id ] = $module_id;
|
39 |
+
}
|
40 |
+
|
41 |
+
public function isShortcoded( $module_id ) {
|
42 |
+
if ( isset( self::$shortcoded_module_ids[ $this->post_id ][ $module_id ] ) ) {
|
43 |
+
return true;
|
44 |
+
} else {
|
45 |
+
return false;
|
46 |
+
}
|
47 |
+
}
|
|
|
|
|
|
|
|
|
48 |
|
49 |
}
|
application/components/TemplateManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
use ContentEgg\application\admin\GeneralConfig;
|
@@ -17,239 +17,241 @@ use ContentEgg\application\helpers\TemplateHelper;
|
|
17 |
*/
|
18 |
abstract class TemplateManager {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
254 |
|
255 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
use ContentEgg\application\admin\GeneralConfig;
|
17 |
*/
|
18 |
abstract class TemplateManager {
|
19 |
|
20 |
+
private $templates = null;
|
21 |
+
private $last_render_data;
|
22 |
+
private static $product_style_enqueued = false;
|
23 |
+
|
24 |
+
abstract public function getTempatePrefix();
|
25 |
+
|
26 |
+
abstract public function getTempateDir();
|
27 |
+
|
28 |
+
abstract public function getCustomTempateDirs();
|
29 |
+
|
30 |
+
public function getTemplatesList( $short_mode = false ) {
|
31 |
+
$prefix = $this->getTempatePrefix();
|
32 |
+
if ( $this->templates === null ) {
|
33 |
+
$templates = array();
|
34 |
+
foreach ( $this->getCustomTempateDirs() as $custom_name => $dir ) {
|
35 |
+
$templates = array_merge( $templates, $this->scanTemplates( $dir, $prefix, $custom_name ) );
|
36 |
+
}
|
37 |
+
$templates = array_merge( $templates, $this->scanTemplates( $this->getTempateDir(), $prefix, false ) );
|
38 |
+
$this->templates = $templates;
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( $short_mode ) {
|
42 |
+
$list = array();
|
43 |
+
foreach ( $this->templates as $id => $name ) {
|
44 |
+
$custom = '';
|
45 |
+
if ( self::isCustomTemplate( $id ) ) {
|
46 |
+
$parts = explode( '/', $id );
|
47 |
+
$custom = 'custom/';
|
48 |
+
$id = $parts[1];
|
49 |
+
}
|
50 |
+
|
51 |
+
// del prefix
|
52 |
+
$list[ $custom . substr( $id, strlen( $prefix ) ) ] = $name;
|
53 |
+
}
|
54 |
+
|
55 |
+
return $list;
|
56 |
+
}
|
57 |
+
|
58 |
+
return $this->templates;
|
59 |
+
}
|
60 |
+
|
61 |
+
private function scanTemplates( $path, $prefix, $custom_name = false ) {
|
62 |
+
if ( $custom_name && ! is_dir( $path ) ) {
|
63 |
+
return array();
|
64 |
+
}
|
65 |
+
|
66 |
+
$tpl_files = glob( $path . '/' . $prefix . '*.php' );
|
67 |
+
if ( ! $tpl_files ) {
|
68 |
+
return array();
|
69 |
+
}
|
70 |
+
|
71 |
+
$templates = array();
|
72 |
+
foreach ( $tpl_files as $file ) {
|
73 |
+
$template_id = basename( $file, '.php' );
|
74 |
+
if ( $custom_name ) {
|
75 |
+
$template_id = 'custom/' . $template_id;
|
76 |
+
}
|
77 |
+
|
78 |
+
$data = \get_file_data( $file, array( 'name' => 'Name' ) );
|
79 |
+
if ( $data && ! empty( $data['name'] ) ) {
|
80 |
+
$templates[ $template_id ] = sanitize_text_field( $data['name'] );
|
81 |
+
} else {
|
82 |
+
$templates[ $template_id ] = $template_id;
|
83 |
+
}
|
84 |
+
if ( $custom_name ) {
|
85 |
+
$templates[ $template_id ] .= ' [' . esc_attr( __( $custom_name, 'content-egg' ) ) . ']';
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
return $templates;
|
90 |
+
}
|
91 |
+
|
92 |
+
public function render( $view_name, array $_data = array() ) {
|
93 |
+
$file = $this->getViewPath( $view_name );
|
94 |
+
if ( ! $file ) {
|
95 |
+
return '';
|
96 |
+
}
|
97 |
+
|
98 |
+
$this->last_render_data = $_data;
|
99 |
+
extract( $_data, EXTR_PREFIX_SAME, 'data' );
|
100 |
+
|
101 |
+
ob_start();
|
102 |
+
ob_implicit_flush( false );
|
103 |
+
include $file;
|
104 |
+
$res = ob_get_clean();
|
105 |
+
|
106 |
+
return $res;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function renderPartial( $view_name, array $_data = array() ) {
|
110 |
+
$file = $this->getPartialViewPath( $view_name, false );
|
111 |
+
if ( ! $file ) {
|
112 |
+
return '';
|
113 |
+
}
|
114 |
+
$this->renderPath( $file, $_data );
|
115 |
+
}
|
116 |
+
|
117 |
+
public function renderBlock( $view_name, array $data = array() ) {
|
118 |
+
$file = $this->getPartialViewPath( $view_name, true );
|
119 |
+
if ( ! $file ) {
|
120 |
+
return '';
|
121 |
+
}
|
122 |
+
$this->renderPath( $file, $data );
|
123 |
+
}
|
124 |
+
|
125 |
+
protected function renderPath( $view_path, $_data = array() ) {
|
126 |
+
if ( ! is_file( $view_path ) || ! is_readable( $view_path ) ) {
|
127 |
+
throw new \Exception( 'View file "' . $view_path . '" does not exist.' );
|
128 |
+
}
|
129 |
+
|
130 |
+
$_data = array_merge( $this->last_render_data, $_data );
|
131 |
+
extract( $_data, EXTR_PREFIX_SAME, 'data' );
|
132 |
+
include $view_path;
|
133 |
+
}
|
134 |
+
|
135 |
+
public function getPartialViewPath( $view_name, $block = false ) {
|
136 |
+
$view_name = str_replace( '.', '', $view_name );
|
137 |
+
$file = \ContentEgg\PLUGIN_PATH . 'application/templates/';
|
138 |
+
if ( $block ) {
|
139 |
+
$file .= 'blocks/';
|
140 |
+
} else {
|
141 |
+
$file .= $this->getTempatePrefix();
|
142 |
+
}
|
143 |
+
$file .= TextHelper::clear( $view_name ) . '.php';
|
144 |
+
if ( is_file( $file ) && is_readable( $file ) ) {
|
145 |
+
return $file;
|
146 |
+
} else {
|
147 |
+
return false;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
public function getViewPath( $view_name ) {
|
152 |
+
$view_name = str_replace( '.', '', $view_name );
|
153 |
+
if ( self::isCustomTemplate( $view_name ) ) {
|
154 |
+
$view_name = substr( $view_name, 7 );
|
155 |
+
foreach ( $this->getCustomTempateDirs() as $custom_prefix => $custom_dir ) {
|
156 |
+
$tpl_path = $custom_dir;
|
157 |
+
$file = $tpl_path . DIRECTORY_SEPARATOR . TextHelper::clear( $view_name ) . '.php';
|
158 |
+
if ( is_file( $file ) && is_readable( $file ) ) {
|
159 |
+
return $file;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
return false;
|
164 |
+
} else {
|
165 |
+
$tpl_path = $this->getTempateDir();
|
166 |
+
$file = $tpl_path . DIRECTORY_SEPARATOR . TextHelper::clear( $view_name ) . '.php';
|
167 |
+
if ( is_file( $file ) && is_readable( $file ) ) {
|
168 |
+
return $file;
|
169 |
+
} else {
|
170 |
+
return false;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
public function getFullTemplateId( $short_id ) {
|
176 |
+
$prefix = $this->getTempatePrefix();
|
177 |
+
$custom = '';
|
178 |
+
if ( self::isCustomTemplate( $short_id ) ) {
|
179 |
+
$parts = explode( '/', $short_id );
|
180 |
+
$custom = 'custom/';
|
181 |
+
$id = $parts[1];
|
182 |
+
} else {
|
183 |
+
$id = $short_id;
|
184 |
+
}
|
185 |
+
|
186 |
+
// check _data prefix
|
187 |
+
if ( substr( $id, 0, strlen( $prefix ) ) != $prefix ) {
|
188 |
+
$id = $prefix . $id;
|
189 |
+
}
|
190 |
+
|
191 |
+
return $custom . $id;
|
192 |
+
}
|
193 |
+
|
194 |
+
public static function isCustomTemplate( $template_id ) {
|
195 |
+
if ( substr( $template_id, 0, 7 ) == 'custom/' ) {
|
196 |
+
return true;
|
197 |
+
} else {
|
198 |
+
return false;
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
public function isTemplateExists( $tpl ) {
|
203 |
+
return array_key_exists( $tpl, $this->getTemplatesList() );
|
204 |
+
}
|
205 |
+
|
206 |
+
public function prepareShortcodeTempate( $template ) {
|
207 |
+
if ( self::isCustomTemplate( $template ) ) {
|
208 |
+
$is_custom = true;
|
209 |
+
// del 'custom/' prefix
|
210 |
+
$template = substr( $template, 7 );
|
211 |
+
} else {
|
212 |
+
$is_custom = false;
|
213 |
+
}
|
214 |
+
|
215 |
+
$template = TextHelper::clear( $template );
|
216 |
+
if ( $is_custom ) {
|
217 |
+
$template = 'custom/' . $template;
|
218 |
+
}
|
219 |
+
if ( $template ) {
|
220 |
+
$template = $this->getFullTemplateId( $template );
|
221 |
+
}
|
222 |
+
|
223 |
+
return $template;
|
224 |
+
}
|
225 |
+
|
226 |
+
public function enqueueProductsStyle() {
|
227 |
+
if ( self::$product_style_enqueued ) {
|
228 |
+
return;
|
229 |
+
}
|
230 |
+
|
231 |
+
\wp_enqueue_style( 'egg-bootstrap' );
|
232 |
+
\wp_enqueue_style( 'egg-products' );
|
233 |
+
|
234 |
+
if ( GeneralConfig::isShopInfoAvailable() ) {
|
235 |
+
\wp_enqueue_script( 'bootstrap-popover' );
|
236 |
+
}
|
237 |
+
|
238 |
+
if ( ! $background = \wp_strip_all_tags( GeneralConfig::getInstance()->option( 'button_color' ) ) ) {
|
239 |
+
$background = '#dc3545';
|
240 |
+
}
|
241 |
+
|
242 |
+
if ( ! $price_color = \wp_strip_all_tags( GeneralConfig::getInstance()->option( 'price_color' ) ) ) {
|
243 |
+
$price_color = '#dc3545';
|
244 |
+
}
|
245 |
+
|
246 |
+
$border = TemplateHelper::adjustBrightness( $background, - 0.05 );
|
247 |
+
$background_hover = TemplateHelper::adjustBrightness( $background, - 0.15 );
|
248 |
+
$border_hover = TemplateHelper::adjustBrightness( $background_hover, - 0.05 );
|
249 |
+
|
250 |
+
$custom_css = '.cegg-price-color {color: ' . $price_color . ';} .egg-container .btn-danger {background-color: ' . $background . ' !important;border-color: ' . $border . ' !important;} .egg-container .btn-danger:hover,.egg-container .btn-danger:focus,.egg-container .btn-danger:active {background-color: ' . $background_hover . ' !important;border-color: ' . $border_hover . ' !important;}';
|
251 |
+
|
252 |
+
\wp_add_inline_style( 'egg-products', $custom_css );
|
253 |
+
self::$product_style_enqueued = true;
|
254 |
+
}
|
255 |
+
|
256 |
|
257 |
}
|
application/components/VirtualPage.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* VirtualPage abstract class file
|
@@ -13,153 +13,149 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class VirtualPage {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
$templates = array_merge(array($template), $templates);
|
161 |
-
\locate_template($templates, true);
|
162 |
-
exit;
|
163 |
-
}
|
164 |
|
165 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* VirtualPage abstract class file
|
13 |
*/
|
14 |
abstract class VirtualPage {
|
15 |
|
16 |
+
private static $created = false;
|
17 |
+
|
18 |
+
public function __construct() {
|
19 |
+
\add_action( 'parse_request', array( $this, 'sniffRequests' ) );
|
20 |
+
}
|
21 |
+
|
22 |
+
public static function initAction() {
|
23 |
+
$class = get_called_class();
|
24 |
+
new $class;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Page slug
|
29 |
+
*/
|
30 |
+
abstract function getSlug();
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Page body
|
34 |
+
*/
|
35 |
+
abstract function getBody();
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Page title
|
39 |
+
*/
|
40 |
+
abstract function getTitle();
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Custom page template
|
44 |
+
*/
|
45 |
+
public function getTemplate() {
|
46 |
+
return '';
|
47 |
+
}
|
48 |
+
|
49 |
+
public function sniffRequests( $wp ) {
|
50 |
+
if (empty($_SERVER['REQUEST_URI']))
|
51 |
+
return;
|
52 |
+
|
53 |
+
if ( isset( $wp->query_vars['pagename'] ) ) {
|
54 |
+
$page = $wp->query_vars['pagename'];
|
55 |
+
} elseif ( \get_option( 'permalink_structure' ) ) {
|
56 |
+
$home_path = parse_url( \home_url( '/' ), PHP_URL_PATH );
|
57 |
+
$page = preg_replace( "#^" . preg_quote( $home_path ) . "#", '', esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) );
|
58 |
+
$page = parse_url( $page, PHP_URL_PATH );
|
59 |
+
$page = trim( $page, '/' );
|
60 |
+
} else {
|
61 |
+
return;
|
62 |
+
}
|
63 |
+
|
64 |
+
if ( $page && $page == $this->getSlug() ) {
|
65 |
+
$this->handleRequest( $wp->query_vars );
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
protected function handleRequest( $query_vars = array() ) {
|
70 |
+
\add_action( 'template_redirect', array( $this, 'renderTemplate' ) );
|
71 |
+
\add_filter( 'the_posts', array( $this, 'createDummyPage' ) );
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Modified version of Virtual_Themed_Pages_BC class
|
76 |
+
* @link: https://gist.github.com/brianoz/9105004
|
77 |
+
*/
|
78 |
+
public function createDummyPage( $posts ) {
|
79 |
+
if ( self::$created ) {
|
80 |
+
return $posts;
|
81 |
+
}
|
82 |
+
|
83 |
+
/*
|
84 |
+
if ($posts)
|
85 |
+
return $posts;
|
86 |
+
*
|
87 |
+
*/
|
88 |
+
|
89 |
+
// have to create a dummy post as otherwise many templates
|
90 |
+
// don't call the_content filter
|
91 |
+
global $wp, $wp_query;
|
92 |
+
|
93 |
+
//create a fake post intance
|
94 |
+
$p = new \stdClass;
|
95 |
+
// fill $p with everything a page in the database would have
|
96 |
+
$p->ID = - 1;
|
97 |
+
$p->post_author = 1;
|
98 |
+
$p->post_date = current_time( 'mysql' );
|
99 |
+
$p->post_date_gmt = current_time( 'mysql', 1 );
|
100 |
+
$p->post_content = $this->getBody();
|
101 |
+
$p->post_title = $this->getTitle();
|
102 |
+
$p->post_excerpt = '';
|
103 |
+
$p->post_status = 'publish';
|
104 |
+
$p->ping_status = 'closed';
|
105 |
+
$p->post_password = '';
|
106 |
+
$p->post_name = $this->getSlug(); // slug
|
107 |
+
$p->to_ping = '';
|
108 |
+
$p->pinged = '';
|
109 |
+
$p->modified = $p->post_date;
|
110 |
+
$p->modified_gmt = $p->post_date_gmt;
|
111 |
+
$p->post_content_filtered = '';
|
112 |
+
$p->post_parent = 0;
|
113 |
+
$p->guid = \get_home_url( '/' . $p->post_name ); // use url instead?
|
114 |
+
$p->menu_order = 0;
|
115 |
+
$p->post_type = 'page';
|
116 |
+
$p->post_mime_type = '';
|
117 |
+
$p->comment_status = 'closed';
|
118 |
+
$p->comment_count = 0;
|
119 |
+
$p->filter = 'raw'; // How to sanitize post fields. Accepts 'raw', 'edit', 'db', or 'display'.
|
120 |
+
$p->ancestors = array(); // 3.6
|
121 |
+
//$p = new \WP_Post($p); // ??
|
122 |
+
//$GLOBALS['post'] = $p;
|
123 |
+
// reset wp_query properties to simulate a found page
|
124 |
+
$wp_query->is_page = true;
|
125 |
+
$wp_query->is_singular = true;
|
126 |
+
$wp_query->is_home = false;
|
127 |
+
$wp_query->is_archive = false;
|
128 |
+
$wp_query->is_category = false;
|
129 |
+
unset( $wp_query->query['error'] );
|
130 |
+
$wp->query = array();
|
131 |
+
$wp_query->query_vars['error'] = '';
|
132 |
+
$wp_query->is_404 = false;
|
133 |
+
$wp_query->found_posts = 1;
|
134 |
+
$wp_query->comment_count = 0;
|
135 |
+
// -1 for current_comment displays comment if not logged in!
|
136 |
+
$wp_query->current_comment = null;
|
137 |
+
$wp_query->is_singular = 1;
|
138 |
+
$wp_query->post = $p;
|
139 |
+
$wp_query->posts = array( $p );
|
140 |
+
$wp_query->queried_object = $p;
|
141 |
+
$wp_query->queried_object_id = $p->ID;
|
142 |
+
$wp_query->current_post = $p->ID;
|
143 |
+
$wp_query->post_count = 1;
|
144 |
+
$wp_query->is_attachment = false;
|
145 |
+
|
146 |
+
self::$created = true;
|
147 |
+
|
148 |
+
return array( $p );
|
149 |
+
}
|
150 |
+
|
151 |
+
public function renderTemplate() {
|
152 |
+
$templates = array( 'page.php', 'index.php' );
|
153 |
+
$template = $this->getTemplate();
|
154 |
+
if ( $template ) {
|
155 |
+
$templates = array_merge( array( $template ), $templates );
|
156 |
+
}
|
157 |
+
\locate_template( $templates, true );
|
158 |
+
exit;
|
159 |
+
}
|
|
|
|
|
|
|
|
|
160 |
|
161 |
}
|
application/components/WidgetTemplateManager.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* WidgetTemplateManager class file
|
@@ -13,54 +13,50 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class WidgetTemplateManager extends TemplateManager {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
if (!self::isCustomTemplate($view_name))
|
62 |
-
$this->enqueueProductsStyle();
|
63 |
-
return parent::render($view_name, $_data);
|
64 |
-
}
|
65 |
|
66 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* WidgetTemplateManager class file
|
13 |
*/
|
14 |
class WidgetTemplateManager extends TemplateManager {
|
15 |
|
16 |
+
const TEMPLATE_DIR = 'templates';
|
17 |
+
const CUSTOM_TEMPLATE_DIR = 'content-egg-templates';
|
18 |
+
const TEMPLATE_PREFIX = 'wdgt_';
|
19 |
+
|
20 |
+
protected $widget_slug;
|
21 |
+
protected $widget_short_slug;
|
22 |
+
private static $_instances = array();
|
23 |
+
|
24 |
+
public static function getInstance( $widget_slug ) {
|
25 |
+
if ( ! isset( self::$_instances[ $widget_slug ] ) ) {
|
26 |
+
$class = get_called_class();
|
27 |
+
self::$_instances[ $widget_slug ] = new $class( $widget_slug );
|
28 |
+
}
|
29 |
+
|
30 |
+
return self::$_instances[ $widget_slug ];
|
31 |
+
}
|
32 |
+
|
33 |
+
private function __construct( $widget_slug ) {
|
34 |
+
$this->widget_slug = $widget_slug;
|
35 |
+
$this->widget_short_slug = preg_replace( '/^cegg_/', '', $this->widget_slug );
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getTempatePrefix() {
|
39 |
+
return self::TEMPLATE_PREFIX . $this->widget_short_slug . '_';
|
40 |
+
}
|
41 |
+
|
42 |
+
public function getTempateDir() {
|
43 |
+
return \ContentEgg\PLUGIN_PATH . self::TEMPLATE_DIR;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function getCustomTempateDirs() {
|
47 |
+
return array(
|
48 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, //child theme
|
49 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, // theme
|
50 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR,
|
51 |
+
);
|
52 |
+
}
|
53 |
+
|
54 |
+
public function render( $view_name, array $_data = array() ) {
|
55 |
+
if ( ! self::isCustomTemplate( $view_name ) ) {
|
56 |
+
$this->enqueueProductsStyle();
|
57 |
+
}
|
58 |
+
|
59 |
+
return parent::render( $view_name, $_data );
|
60 |
+
}
|
|
|
|
|
|
|
|
|
61 |
|
62 |
}
|
application/components/iScheduler.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Scheduler interface file
|
@@ -13,7 +13,7 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
interface iScheduler {
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
}
|
2 |
|
3 |
namespace ContentEgg\application\components;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Scheduler interface file
|
13 |
*/
|
14 |
interface iScheduler {
|
15 |
|
16 |
+
public static function getCronTag();
|
17 |
|
18 |
+
public static function run();
|
19 |
}
|
application/helpers/AdminHelper.php
CHANGED
@@ -2,155 +2,152 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
|
10 |
/**
|
11 |
* AdminHelper class file
|
12 |
-
*
|
13 |
* @author keywordrush.com <support@keywordrush.com>
|
14 |
* @link http://www.keywordrush.com/
|
15 |
* @copyright Copyright © 2017 keywordrush.com
|
16 |
-
*
|
17 |
*/
|
18 |
class AdminHelper {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
return $results;
|
154 |
-
}
|
155 |
|
156 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
9 |
|
10 |
/**
|
11 |
* AdminHelper class file
|
12 |
+
*
|
13 |
* @author keywordrush.com <support@keywordrush.com>
|
14 |
* @link http://www.keywordrush.com/
|
15 |
* @copyright Copyright © 2017 keywordrush.com
|
16 |
+
*
|
17 |
*/
|
18 |
class AdminHelper {
|
19 |
|
20 |
+
public static function getCategoryList() {
|
21 |
+
$taxonomy = array( 'category' );
|
22 |
+
|
23 |
+
// @todo: widget is initialized before woo? taxonomy does not exist
|
24 |
+
if ( in_array( 'product', GeneralConfig::getInstance()->option( 'post_types' ) ) && \taxonomy_exists( 'product_cat' ) ) {
|
25 |
+
$taxonomy[] = 'product_cat';
|
26 |
+
}
|
27 |
+
|
28 |
+
$cat_args = array( 'taxonomy' => $taxonomy, 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => false );
|
29 |
+
$categories = \get_terms( $cat_args );
|
30 |
+
|
31 |
+
$results = array();
|
32 |
+
foreach ( $categories as $key => $category ) {
|
33 |
+
$results[ $category->term_id ] = $category->name;
|
34 |
+
if ( $category->taxonomy == 'product_cat' ) {
|
35 |
+
$results[ $category->term_id ] .= ' [product]';
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
return $results;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Tabs as sections
|
44 |
+
*/
|
45 |
+
public static function doTabsSections( $page ) {
|
46 |
+
global $wp_settings_sections, $wp_settings_fields;
|
47 |
+
|
48 |
+
if ( ! isset( $wp_settings_sections[ $page ] ) ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
+
|
52 |
+
echo '<div id="cegg-tabs">';
|
53 |
+
echo '<ul>';
|
54 |
+
$i = 1;
|
55 |
+
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
|
56 |
+
echo '<li><a href="#tabs-' . esc_attr($i) . '">' . esc_html($section['title']) . '</a></li>';
|
57 |
+
$i ++;
|
58 |
+
}
|
59 |
+
echo '</ul>';
|
60 |
+
$i = 1;
|
61 |
+
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
|
62 |
+
echo '<div id="tabs-' . esc_attr($i) . '">';
|
63 |
+
echo '<table class="form-table" role="presentation">';
|
64 |
+
\do_settings_fields( $page, $section['id'] );
|
65 |
+
echo '</table>';
|
66 |
+
echo '</div>';
|
67 |
+
$i ++;
|
68 |
+
}
|
69 |
+
echo '</div>';
|
70 |
+
echo '<script type="text/javascript">' . 'jQuery(document).ready(function($){$(\'#cegg-tabs\').tabs();});' . '</script>';
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function getProductModules() {
|
74 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
75 |
+
$results = array();
|
76 |
+
foreach ( $modules as $module ) {
|
77 |
+
if ( $module->isDeprecated() && ! $module->isActive() ) {
|
78 |
+
continue;
|
79 |
+
}
|
80 |
+
|
81 |
+
if ( $module->isAffiliateParser() && $module->isProductParser() && ! $module->isAeParser() && ! $module->isFeedParser() ) {
|
82 |
+
$results[] = $module;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
return $results;
|
87 |
+
}
|
88 |
+
|
89 |
+
public static function getAeProductModules() {
|
90 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
91 |
+
$results = array();
|
92 |
+
foreach ( $modules as $module ) {
|
93 |
+
if ( $module->isDeprecated() && ! $module->isActive() ) {
|
94 |
+
continue;
|
95 |
+
}
|
96 |
+
|
97 |
+
if ( $module->isAffiliateParser() && $module->isProductParser() && $module->isAeParser() ) {
|
98 |
+
$results[] = $module;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
return $results;
|
103 |
+
}
|
104 |
+
|
105 |
+
public static function getFeedProductModules() {
|
106 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
107 |
+
$results = array();
|
108 |
+
foreach ( $modules as $module ) {
|
109 |
+
if ( $module->isDeprecated() && ! $module->isActive() ) {
|
110 |
+
continue;
|
111 |
+
}
|
112 |
+
|
113 |
+
if ( $module->isAffiliateParser() && $module->isProductParser() && $module->isFeedParser() ) {
|
114 |
+
$results[] = $module;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
return $results;
|
119 |
+
}
|
120 |
+
|
121 |
+
public static function getCouponModules() {
|
122 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
123 |
+
$results = array();
|
124 |
+
foreach ( $modules as $module ) {
|
125 |
+
if ( $module->isDeprecated() && ! $module->isActive() ) {
|
126 |
+
continue;
|
127 |
+
}
|
128 |
+
|
129 |
+
if ( $module->isAffiliateParser() && $module->isCouponParser() ) {
|
130 |
+
$results[] = $module;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
return $results;
|
135 |
+
}
|
136 |
+
|
137 |
+
public static function getContentModules() {
|
138 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
139 |
+
$results = array();
|
140 |
+
foreach ( $modules as $module ) {
|
141 |
+
if ( $module->isDeprecated() && ! $module->isActive() ) {
|
142 |
+
continue;
|
143 |
+
}
|
144 |
+
|
145 |
+
if ( ! $module->isAffiliateParser() ) {
|
146 |
+
$results[] = $module;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
return $results;
|
151 |
+
}
|
|
|
|
|
|
|
152 |
|
153 |
}
|
application/helpers/ArrayHelper.php
CHANGED
@@ -2,111 +2,105 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ArrayHelper class file
|
9 |
-
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link http://www.keywordrush.com/
|
12 |
* @copyright Copyright © 2015 keywordrush.com
|
13 |
-
*
|
14 |
*/
|
15 |
class ArrayHelper {
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
} else if (!array_key_exists($key, $array2) || $array2[$key] !== $value)
|
37 |
-
{
|
38 |
-
$difference[$key] = $value;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
return $difference;
|
42 |
-
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
* @param type $object
|
47 |
-
* @return array
|
48 |
-
*/
|
49 |
-
public static function object2Array($object)
|
50 |
-
{
|
51 |
-
return json_decode(json_encode($object), true);
|
52 |
-
}
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
return $array;
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
}
|
69 |
-
array_multisort($data, $order1, $keys, $order2, $array);
|
70 |
-
return $array;
|
71 |
-
}
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
$first = reset($array);
|
79 |
-
$max_key = key($array);
|
80 |
-
$max_value = $first[$key_name];
|
81 |
-
foreach ($array as $k => $v)
|
82 |
-
{
|
83 |
-
if ($zero_ignore && !(float) $v[$key_name])
|
84 |
-
continue;
|
85 |
-
if ((float) $v[$key_name] > (float) $max_value)
|
86 |
-
{
|
87 |
-
$max_value = $v[$key_name];
|
88 |
-
$max_key = $k;
|
89 |
-
}
|
90 |
-
}
|
91 |
-
return $max_key;
|
92 |
-
}
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ArrayHelper class file
|
9 |
+
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link http://www.keywordrush.com/
|
12 |
* @copyright Copyright © 2015 keywordrush.com
|
13 |
+
*
|
14 |
*/
|
15 |
class ArrayHelper {
|
16 |
|
17 |
+
/**
|
18 |
+
* @link: http://php.net/manual/ru/function.array-diff-assoc.php#111675
|
19 |
+
*/
|
20 |
+
public static function array_diff_assoc_recursive( $array1, $array2 ) {
|
21 |
+
$difference = array();
|
22 |
+
foreach ( $array1 as $key => $value ) {
|
23 |
+
if ( is_array( $value ) ) {
|
24 |
+
if ( ! isset( $array2[ $key ] ) || ! is_array( $array2[ $key ] ) ) {
|
25 |
+
$difference[ $key ] = $value;
|
26 |
+
} else {
|
27 |
+
$new_diff = array_diff_assoc_recursive( $value, $array2[ $key ] );
|
28 |
+
if ( ! empty( $new_diff ) ) {
|
29 |
+
$difference[ $key ] = $new_diff;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
} else if ( ! array_key_exists( $key, $array2 ) || $array2[ $key ] !== $value ) {
|
33 |
+
$difference[ $key ] = $value;
|
34 |
+
}
|
35 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
return $difference;
|
38 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
/**
|
41 |
+
* Full depth recursive conversion to array
|
42 |
+
*
|
43 |
+
* @param type $object
|
44 |
+
*
|
45 |
+
* @return array
|
46 |
+
*/
|
47 |
+
public static function object2Array( $object ) {
|
48 |
+
return json_decode( json_encode( $object ), true );
|
49 |
+
}
|
50 |
|
51 |
+
public static function array2Object( array $a ) {
|
52 |
+
return json_decode( json_encode( $a ), false );
|
53 |
+
}
|
|
|
54 |
|
55 |
+
public static function asortStable( array $array, $order1 = SORT_ASC, $order2 = SORT_ASC ) {
|
56 |
+
if ( ! $array ) {
|
57 |
+
return $array;
|
58 |
+
}
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
foreach ( $array as $key => $value ) {
|
61 |
+
$keys[] = $key;
|
62 |
+
$data[] = $value;
|
63 |
+
}
|
64 |
+
array_multisort( $data, $order1, $keys, $order2, $array );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
return $array;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Hightest value of an associative array
|
71 |
+
*/
|
72 |
+
public static function getMaxKeyAssoc( $array, $key_name, $zero_ignore = false ) {
|
73 |
+
$first = reset( $array );
|
74 |
+
$max_key = key( $array );
|
75 |
+
$max_value = $first[ $key_name ];
|
76 |
+
foreach ( $array as $k => $v ) {
|
77 |
+
if ( $zero_ignore && ! (float) $v[ $key_name ] ) {
|
78 |
+
continue;
|
79 |
+
}
|
80 |
+
if ( (float) $v[ $key_name ] > (float) $max_value ) {
|
81 |
+
$max_value = $v[ $key_name ];
|
82 |
+
$max_key = $k;
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
return $max_key;
|
87 |
+
}
|
88 |
+
|
89 |
+
public static function getMinKeyAssoc( $array, $key_name, $zero_ignore = false ) {
|
90 |
+
$first = reset( $array );
|
91 |
+
$min_key = key( $array );
|
92 |
+
$min_value = $first[ $key_name ];
|
93 |
+
foreach ( $array as $k => $v ) {
|
94 |
+
if ( $zero_ignore && ! (float) $v[ $key_name ] ) {
|
95 |
+
continue;
|
96 |
+
}
|
97 |
+
if ( (float) $v[ $key_name ] < (float) $min_value ) {
|
98 |
+
$min_value = $v[ $key_name ];
|
99 |
+
$min_key = $k;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
return $min_key;
|
104 |
+
}
|
105 |
|
106 |
}
|
application/helpers/CurrencyHelper.php
CHANGED
@@ -2,715 +2,708 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Currency class file
|
9 |
-
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link https://www.keywordrush.com
|
12 |
* @copyright Copyright © 2022 keywordrush.com
|
13 |
-
*
|
14 |
*/
|
15 |
class CurrencyHelper {
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
'decimal_sep' => '.',
|
546 |
-
'num_decimals' => 2,
|
547 |
-
'name' => 'Norske kroner',
|
548 |
-
),
|
549 |
'NZD' => array(
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
}
|
713 |
-
return self::$currencyRates[$transient_name];
|
714 |
-
}
|
715 |
|
716 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Currency class file
|
9 |
+
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link https://www.keywordrush.com
|
12 |
* @copyright Copyright © 2022 keywordrush.com
|
13 |
+
*
|
14 |
*/
|
15 |
class CurrencyHelper {
|
16 |
|
17 |
+
private $locale;
|
18 |
+
protected $currencies = array();
|
19 |
+
protected $locales = array();
|
20 |
+
private static $instance = null;
|
21 |
+
private static $currencyRates = array();
|
22 |
+
|
23 |
+
public static function getInstance( $locale = null ) {
|
24 |
+
if ( self::$instance === null ) {
|
25 |
+
self::$instance = new CurrencyHelper( $locale );
|
26 |
+
}
|
27 |
+
|
28 |
+
return self::$instance;
|
29 |
+
}
|
30 |
+
|
31 |
+
private function __construct( $locale ) {
|
32 |
+
$this->setLocale( $locale );
|
33 |
+
$this->currencies = self::currencies();
|
34 |
+
$this->locales = self::locales();
|
35 |
+
}
|
36 |
+
|
37 |
+
public static function locales() {
|
38 |
+
return array(
|
39 |
+
'en' => array(
|
40 |
+
'thousand_sep' => ',',
|
41 |
+
'decimal_sep' => '.',
|
42 |
+
),
|
43 |
+
'nl' => array(
|
44 |
+
'thousand_sep' => '.',
|
45 |
+
'decimal_sep' => ',',
|
46 |
+
),
|
47 |
+
'be' => array(
|
48 |
+
'thousand_sep' => ' ',
|
49 |
+
'decimal_sep' => ',',
|
50 |
+
),
|
51 |
+
'de' => array(
|
52 |
+
'thousand_sep' => '.',
|
53 |
+
'decimal_sep' => ',',
|
54 |
+
),
|
55 |
+
'es' => array(
|
56 |
+
'thousand_sep' => '.',
|
57 |
+
'decimal_sep' => ',',
|
58 |
+
),
|
59 |
+
'fr' => array(
|
60 |
+
'thousand_sep' => ' ',
|
61 |
+
'decimal_sep' => ',',
|
62 |
+
),
|
63 |
+
'it' => array(
|
64 |
+
'thousand_sep' => '.',
|
65 |
+
'decimal_sep' => ',',
|
66 |
+
),
|
67 |
+
'ru' => array(
|
68 |
+
'thousand_sep' => ' ',
|
69 |
+
'decimal_sep' => ',',
|
70 |
+
),
|
71 |
+
'uk' => array(
|
72 |
+
'thousand_sep' => ' ',
|
73 |
+
'decimal_sep' => ',',
|
74 |
+
),
|
75 |
+
);
|
76 |
+
}
|
77 |
+
|
78 |
+
public static function currencies() {
|
79 |
+
return array(
|
80 |
+
'USD' => array(
|
81 |
+
'currency_symbol' => '$',
|
82 |
+
'currency_pos' => 'left',
|
83 |
+
'thousand_sep' => ',',
|
84 |
+
'decimal_sep' => '.',
|
85 |
+
'num_decimals' => 2,
|
86 |
+
'name' => 'United States dollar',
|
87 |
+
),
|
88 |
+
'EUR' => array(
|
89 |
+
'currency_symbol' => '€',
|
90 |
+
'currency_pos' => array(
|
91 |
+
'nl' => 'left',
|
92 |
+
'be' => 'left',
|
93 |
+
'de' => 'right',
|
94 |
+
'es' => 'right',
|
95 |
+
'fr' => 'right',
|
96 |
+
'it' => 'right',
|
97 |
+
'fi' => 'right',
|
98 |
+
'sk' => 'right',
|
99 |
+
),
|
100 |
+
'thousand_sep' => '.',
|
101 |
+
'decimal_sep' => ',',
|
102 |
+
'num_decimals' => 2,
|
103 |
+
'name' => 'Euro',
|
104 |
+
),
|
105 |
+
'CAD' => array(
|
106 |
+
'currency_symbol' => 'C $',
|
107 |
+
'currency_pos' => 'left',
|
108 |
+
'thousand_sep' => ',',
|
109 |
+
'decimal_sep' => '.',
|
110 |
+
'num_decimals' => 2,
|
111 |
+
'name' => 'Canadian dollar',
|
112 |
+
),
|
113 |
+
'GBP' => array(
|
114 |
+
'currency_symbol' => '£',
|
115 |
+
'currency_pos' => 'left',
|
116 |
+
'thousand_sep' => ',',
|
117 |
+
'decimal_sep' => '.',
|
118 |
+
'num_decimals' => 2,
|
119 |
+
'name' => 'British pound',
|
120 |
+
),
|
121 |
+
'JPY' => array(
|
122 |
+
'currency_symbol' => '¥',
|
123 |
+
'currency_pos' => 'left',
|
124 |
+
'thousand_sep' => ',',
|
125 |
+
'decimal_sep' => '.',
|
126 |
+
'num_decimals' => 0,
|
127 |
+
'name' => 'Japanese yen',
|
128 |
+
),
|
129 |
+
'CNY' => array(
|
130 |
+
'currency_symbol' => '¥',
|
131 |
+
'currency_pos' => 'left',
|
132 |
+
'thousand_sep' => ',',
|
133 |
+
'decimal_sep' => '.',
|
134 |
+
'num_decimals' => 2,
|
135 |
+
'name' => 'Chinese yuan',
|
136 |
+
),
|
137 |
+
'RUB' => array(
|
138 |
+
'currency_symbol' => 'руб.',
|
139 |
+
'currency_pos' => 'right_space',
|
140 |
+
'thousand_sep' => ' ',
|
141 |
+
'decimal_sep' => ',',
|
142 |
+
'num_decimals' => 0,
|
143 |
+
'name' => 'Russian ruble',
|
144 |
+
),
|
145 |
+
'RUR' => array(
|
146 |
+
'currency_symbol' => 'руб.',
|
147 |
+
'currency_pos' => 'right_space',
|
148 |
+
'thousand_sep' => ' ',
|
149 |
+
'decimal_sep' => ',',
|
150 |
+
'num_decimals' => 0,
|
151 |
+
'name' => 'Russian ruble',
|
152 |
+
),
|
153 |
+
'UAH' => array(
|
154 |
+
'currency_symbol' => 'грн.',
|
155 |
+
'currency_pos' => 'right_space',
|
156 |
+
'thousand_sep' => ' ',
|
157 |
+
'decimal_sep' => ',',
|
158 |
+
'num_decimals' => 0,
|
159 |
+
'name' => 'Ukrainian hryvnia',
|
160 |
+
),
|
161 |
+
'INR' => array(
|
162 |
+
'currency_symbol' => 'Rs.',
|
163 |
+
'currency_pos' => 'left_space',
|
164 |
+
'thousand_sep' => ',',
|
165 |
+
'decimal_sep' => '.',
|
166 |
+
'num_decimals' => 0,
|
167 |
+
'name' => 'Indian Rupee',
|
168 |
+
),
|
169 |
+
'AUD' => array(
|
170 |
+
'currency_symbol' => 'AU $',
|
171 |
+
'currency_pos' => 'left',
|
172 |
+
'thousand_sep' => ',',
|
173 |
+
'decimal_sep' => '.',
|
174 |
+
'num_decimals' => 2,
|
175 |
+
'name' => 'Australian dollar',
|
176 |
+
),
|
177 |
+
'VND' => array(
|
178 |
+
'currency_symbol' => '₫',
|
179 |
+
'currency_pos' => 'right',
|
180 |
+
'thousand_sep' => '.',
|
181 |
+
'decimal_sep' => ',',
|
182 |
+
'num_decimals' => 0,
|
183 |
+
'name' => 'Vietnamese dong',
|
184 |
+
),
|
185 |
+
'BRL' => array(
|
186 |
+
'currency_symbol' => 'R$',
|
187 |
+
'currency_pos' => 'left_space',
|
188 |
+
'thousand_sep' => '.',
|
189 |
+
'decimal_sep' => ',',
|
190 |
+
'num_decimals' => 2,
|
191 |
+
'name' => 'Brazilian real',
|
192 |
+
),
|
193 |
+
'TND' => array(
|
194 |
+
'currency_symbol' => 'DT',
|
195 |
+
'currency_pos' => 'right',
|
196 |
+
'thousand_sep' => ' ',
|
197 |
+
'decimal_sep' => '.',
|
198 |
+
'num_decimals' => 3,
|
199 |
+
'name' => 'Tunisian dinar',
|
200 |
+
),
|
201 |
+
'NGN' => array(
|
202 |
+
'currency_symbol' => '₦',
|
203 |
+
'currency_pos' => 'left',
|
204 |
+
'thousand_sep' => ',',
|
205 |
+
'decimal_sep' => '.',
|
206 |
+
'num_decimals' => 2,
|
207 |
+
'name' => 'Nigerian naira',
|
208 |
+
),
|
209 |
+
'MXN' => array(
|
210 |
+
'currency_symbol' => '$',
|
211 |
+
'currency_pos' => 'left',
|
212 |
+
'thousand_sep' => ',',
|
213 |
+
'decimal_sep' => '.',
|
214 |
+
'num_decimals' => 2,
|
215 |
+
'name' => 'Mexican peso',
|
216 |
+
),
|
217 |
+
'MDL' => array(
|
218 |
+
'currency_symbol' => 'lei',
|
219 |
+
'currency_pos' => 'right_space',
|
220 |
+
'thousand_sep' => ',',
|
221 |
+
'decimal_sep' => '.',
|
222 |
+
'num_decimals' => 2,
|
223 |
+
'name' => 'Moldovan leu',
|
224 |
+
),
|
225 |
+
'KRW' => array(
|
226 |
+
'currency_symbol' => '₩',
|
227 |
+
'currency_pos' => 'left',
|
228 |
+
'thousand_sep' => ',',
|
229 |
+
'decimal_sep' => '.',
|
230 |
+
'num_decimals' => 0,
|
231 |
+
'name' => 'South Korean won',
|
232 |
+
),
|
233 |
+
'THB' => array(
|
234 |
+
'currency_symbol' => '฿',
|
235 |
+
'currency_pos' => 'left_space',
|
236 |
+
'thousand_sep' => ',',
|
237 |
+
'decimal_sep' => '.',
|
238 |
+
'num_decimals' => 0,
|
239 |
+
'name' => 'Thai baht',
|
240 |
+
),
|
241 |
+
'RON' => array(
|
242 |
+
'currency_symbol' => 'Lei',
|
243 |
+
'currency_pos' => 'right_space',
|
244 |
+
'thousand_sep' => '.',
|
245 |
+
'decimal_sep' => ',',
|
246 |
+
'num_decimals' => 2,
|
247 |
+
'name' => 'Romanian Leu',
|
248 |
+
),
|
249 |
+
'EGP' => array(
|
250 |
+
'currency_symbol' => 'EGP',
|
251 |
+
'currency_pos' => 'right_space',
|
252 |
+
'thousand_sep' => ',',
|
253 |
+
'decimal_sep' => '.',
|
254 |
+
'num_decimals' => 0,
|
255 |
+
'name' => 'Egypt Pound',
|
256 |
+
),
|
257 |
+
'KWD' => array(
|
258 |
+
'currency_symbol' => 'KD',
|
259 |
+
'currency_pos' => 'right_space',
|
260 |
+
'thousand_sep' => ',',
|
261 |
+
'decimal_sep' => '.',
|
262 |
+
'num_decimals' => 3,
|
263 |
+
'name' => 'Kuwaiti dinar',
|
264 |
+
),
|
265 |
+
'TRY' => array(
|
266 |
+
'currency_symbol' => 'TL',
|
267 |
+
'currency_pos' => 'right_space',
|
268 |
+
'thousand_sep' => '.',
|
269 |
+
'decimal_sep' => ',',
|
270 |
+
'num_decimals' => 2,
|
271 |
+
'name' => 'Turkish Lira',
|
272 |
+
),
|
273 |
+
'IDR' => array(
|
274 |
+
'currency_symbol' => 'Rp',
|
275 |
+
'currency_pos' => 'left_space',
|
276 |
+
'thousand_sep' => '.',
|
277 |
+
'decimal_sep' => ',',
|
278 |
+
'num_decimals' => 0,
|
279 |
+
'name' => 'Indonesian Rupiah',
|
280 |
+
),
|
281 |
+
'PKR' => array(
|
282 |
+
'currency_symbol' => 'PKR.',
|
283 |
+
'currency_pos' => 'left',
|
284 |
+
'thousand_sep' => ',',
|
285 |
+
'decimal_sep' => '.',
|
286 |
+
'num_decimals' => 0,
|
287 |
+
'name' => 'Pakistani Rupee',
|
288 |
+
),
|
289 |
+
'HKD' => array(
|
290 |
+
'currency_symbol' => 'HKD$',
|
291 |
+
'currency_pos' => 'left',
|
292 |
+
'thousand_sep' => ',',
|
293 |
+
'decimal_sep' => '.',
|
294 |
+
'num_decimals' => 2,
|
295 |
+
'name' => 'Hong Kong dollar',
|
296 |
+
),
|
297 |
+
'ILS' => array(
|
298 |
+
'currency_symbol' => '₪',
|
299 |
+
'currency_pos' => 'left',
|
300 |
+
'thousand_sep' => ',',
|
301 |
+
'decimal_sep' => '.',
|
302 |
+
'num_decimals' => 2,
|
303 |
+
'name' => 'Israeli Shekel',
|
304 |
+
),
|
305 |
+
'AED' => array(
|
306 |
+
'currency_symbol' => 'AED',
|
307 |
+
'currency_pos' => 'right_space',
|
308 |
+
'thousand_sep' => ',',
|
309 |
+
'decimal_sep' => '.',
|
310 |
+
'num_decimals' => 2,
|
311 |
+
'name' => 'UAE Dirham',
|
312 |
+
),
|
313 |
+
'SAR' => array(
|
314 |
+
'currency_symbol' => 'SAR',
|
315 |
+
'currency_pos' => 'right_space',
|
316 |
+
'thousand_sep' => ',',
|
317 |
+
'decimal_sep' => '.',
|
318 |
+
'num_decimals' => 2,
|
319 |
+
'name' => 'Saudi Riyal',
|
320 |
+
),
|
321 |
+
'SGD' => array(
|
322 |
+
'currency_symbol' => 'S$',
|
323 |
+
'currency_pos' => 'left',
|
324 |
+
'thousand_sep' => ',',
|
325 |
+
'decimal_sep' => '.',
|
326 |
+
'num_decimals' => 2,
|
327 |
+
'name' => 'Singapore dollar',
|
328 |
+
),
|
329 |
+
'HUF' => array(
|
330 |
+
'currency_symbol' => 'Ft',
|
331 |
+
'currency_pos' => 'right_space',
|
332 |
+
'thousand_sep' => '.',
|
333 |
+
'decimal_sep' => ',',
|
334 |
+
'num_decimals' => 0,
|
335 |
+
'name' => 'Hungarian forint',
|
336 |
+
),
|
337 |
+
'PLN' => array(
|
338 |
+
'currency_symbol' => 'zł',
|
339 |
+
'currency_pos' => 'right_space',
|
340 |
+
'thousand_sep' => '',
|
341 |
+
'decimal_sep' => ',',
|
342 |
+
'num_decimals' => 2,
|
343 |
+
'name' => 'Polish Zloty',
|
344 |
+
),
|
345 |
+
'CZK' => array(
|
346 |
+
'currency_symbol' => 'Kč',
|
347 |
+
'currency_pos' => 'right_space',
|
348 |
+
'thousand_sep' => ' ',
|
349 |
+
'decimal_sep' => ',',
|
350 |
+
'num_decimals' => 0,
|
351 |
+
'name' => 'Czech koruna',
|
352 |
+
),
|
353 |
+
'MYR' => array(
|
354 |
+
'currency_symbol' => 'RM',
|
355 |
+
'currency_pos' => 'left',
|
356 |
+
'thousand_sep' => ',',
|
357 |
+
'decimal_sep' => '.',
|
358 |
+
'num_decimals' => 2,
|
359 |
+
'name' => 'Malaysia Ringgit',
|
360 |
+
),
|
361 |
+
'PCT' => array(
|
362 |
+
'currency_symbol' => '%',
|
363 |
+
'currency_pos' => 'right',
|
364 |
+
'thousand_sep' => '',
|
365 |
+
'decimal_sep' => '.',
|
366 |
+
'num_decimals' => 1,
|
367 |
+
'name' => 'Percentage',
|
368 |
+
),
|
369 |
+
'CLP' => array(
|
370 |
+
'currency_symbol' => '$',
|
371 |
+
'currency_pos' => 'left',
|
372 |
+
'thousand_sep' => '.',
|
373 |
+
'decimal_sep' => ',',
|
374 |
+
'num_decimals' => 0,
|
375 |
+
'name' => 'Peso Chileno',
|
376 |
+
),
|
377 |
+
'DKK' => array(
|
378 |
+
'currency_symbol' => 'DKK',
|
379 |
+
'currency_pos' => 'left_space',
|
380 |
+
'thousand_sep' => '.',
|
381 |
+
'decimal_sep' => ',',
|
382 |
+
'num_decimals' => 2,
|
383 |
+
'name' => 'Danske Kroner',
|
384 |
+
),
|
385 |
+
'KES' => array(
|
386 |
+
'currency_symbol' => 'KSh',
|
387 |
+
'currency_pos' => 'left_space',
|
388 |
+
'thousand_sep' => ',',
|
389 |
+
'decimal_sep' => '.',
|
390 |
+
'num_decimals' => 2,
|
391 |
+
'name' => 'Kenyan Shilling',
|
392 |
+
),
|
393 |
+
'HRK' => array(
|
394 |
+
'currency_symbol' => 'kn',
|
395 |
+
'currency_pos' => 'right_space',
|
396 |
+
'thousand_sep' => '.',
|
397 |
+
'decimal_sep' => ',',
|
398 |
+
'num_decimals' => 2,
|
399 |
+
'name' => 'Croatian Kuna',
|
400 |
+
),
|
401 |
+
'PEN' => array(
|
402 |
+
'currency_symbol' => 'S/',
|
403 |
+
'currency_pos' => 'left',
|
404 |
+
'thousand_sep' => ',',
|
405 |
+
'decimal_sep' => '.',
|
406 |
+
'num_decimals' => 2,
|
407 |
+
'name' => 'Peruvian sol',
|
408 |
+
),
|
409 |
+
'DOP' => array(
|
410 |
+
'currency_symbol' => 'RD$',
|
411 |
+
'currency_pos' => 'left',
|
412 |
+
'thousand_sep' => ',',
|
413 |
+
'decimal_sep' => '.',
|
414 |
+
'num_decimals' => 2,
|
415 |
+
'name' => 'Dominican Peso',
|
416 |
+
),
|
417 |
+
'UYU' => array(
|
418 |
+
'currency_symbol' => 'U$S',
|
419 |
+
'currency_pos' => 'left',
|
420 |
+
'thousand_sep' => '.',
|
421 |
+
'decimal_sep' => ',',
|
422 |
+
'num_decimals' => 2,
|
423 |
+
'name' => 'Uruguayan Peso',
|
424 |
+
),
|
425 |
+
'NIO' => array(
|
426 |
+
'currency_symbol' => 'C$',
|
427 |
+
'currency_pos' => 'left',
|
428 |
+
'thousand_sep' => ',',
|
429 |
+
'decimal_sep' => '.',
|
430 |
+
'num_decimals' => 2,
|
431 |
+
'name' => 'Nicaraguan Córdoba',
|
432 |
+
),
|
433 |
+
'PAB' => array(
|
434 |
+
'currency_symbol' => 'B/.',
|
435 |
+
'currency_pos' => 'left',
|
436 |
+
'thousand_sep' => '.',
|
437 |
+
'decimal_sep' => ',',
|
438 |
+
'num_decimals' => 2,
|
439 |
+
'name' => 'Panamanian Balboa',
|
440 |
+
),
|
441 |
+
'SVC' => array(
|
442 |
+
'currency_symbol' => '$',
|
443 |
+
'currency_pos' => 'left',
|
444 |
+
'thousand_sep' => ',',
|
445 |
+
'decimal_sep' => '.',
|
446 |
+
'num_decimals' => 2,
|
447 |
+
'name' => 'Salvadoran Colón',
|
448 |
+
),
|
449 |
+
'GTQ' => array(
|
450 |
+
'currency_symbol' => 'Q',
|
451 |
+
'currency_pos' => 'left',
|
452 |
+
'thousand_sep' => ',',
|
453 |
+
'decimal_sep' => '.',
|
454 |
+
'num_decimals' => 2,
|
455 |
+
'name' => 'Guatemalan Quetzal',
|
456 |
+
),
|
457 |
+
'HNL' => array(
|
458 |
+
'currency_symbol' => 'L',
|
459 |
+
'currency_pos' => 'left',
|
460 |
+
'thousand_sep' => ',',
|
461 |
+
'decimal_sep' => '.',
|
462 |
+
'num_decimals' => 2,
|
463 |
+
'name' => 'Honduran Lempira',
|
464 |
+
),
|
465 |
+
'JMD' => array(
|
466 |
+
'currency_symbol' => 'JM$',
|
467 |
+
'currency_pos' => 'left',
|
468 |
+
'thousand_sep' => ',',
|
469 |
+
'decimal_sep' => '.',
|
470 |
+
'num_decimals' => 2,
|
471 |
+
'name' => 'Jamaican Dollar',
|
472 |
+
),
|
473 |
+
'CRC' => array(
|
474 |
+
'currency_symbol' => '₡',
|
475 |
+
'currency_pos' => 'left',
|
476 |
+
'thousand_sep' => ',',
|
477 |
+
'decimal_sep' => '.',
|
478 |
+
'num_decimals' => 2,
|
479 |
+
'name' => 'Costa Rican Colón',
|
480 |
+
),
|
481 |
+
'ARS' => array(
|
482 |
+
'currency_symbol' => '$',
|
483 |
+
'currency_pos' => 'left',
|
484 |
+
'thousand_sep' => '.',
|
485 |
+
'decimal_sep' => ',',
|
486 |
+
'num_decimals' => 2,
|
487 |
+
'name' => 'Argentine Peso',
|
488 |
+
),
|
489 |
+
'BOB' => array(
|
490 |
+
'currency_symbol' => 'Bs',
|
491 |
+
'currency_pos' => 'left',
|
492 |
+
'thousand_sep' => '.',
|
493 |
+
'decimal_sep' => ',',
|
494 |
+
'num_decimals' => 2,
|
495 |
+
'name' => 'Bolivian Boliviano',
|
496 |
+
),
|
497 |
+
'COP' => array(
|
498 |
+
'currency_symbol' => '$',
|
499 |
+
'currency_pos' => 'left',
|
500 |
+
'thousand_sep' => '.',
|
501 |
+
'decimal_sep' => ',',
|
502 |
+
'num_decimals' => 2,
|
503 |
+
'name' => 'Colombian Peso',
|
504 |
+
),
|
505 |
+
'XOF' => array(
|
506 |
+
'currency_symbol' => 'FCFA',
|
507 |
+
'currency_pos' => 'left_space',
|
508 |
+
'thousand_sep' => ',',
|
509 |
+
'decimal_sep' => '.',
|
510 |
+
'num_decimals' => 0,
|
511 |
+
'name' => 'CFA Franc',
|
512 |
+
),
|
513 |
+
'SEK' => array(
|
514 |
+
'currency_symbol' => 'kr',
|
515 |
+
'currency_pos' => 'right_space',
|
516 |
+
'thousand_sep' => ' ',
|
517 |
+
'decimal_sep' => '.',
|
518 |
+
'num_decimals' => 0,
|
519 |
+
'name' => 'Swedish Krona',
|
520 |
+
),
|
521 |
+
'PHP' => array(
|
522 |
+
'currency_symbol' => '₱',
|
523 |
+
'currency_pos' => 'left',
|
524 |
+
'thousand_sep' => ',',
|
525 |
+
'decimal_sep' => '.',
|
526 |
+
'num_decimals' => 0,
|
527 |
+
'name' => 'Philippine Peso',
|
528 |
+
),
|
529 |
+
'JOD' => array(
|
530 |
+
'currency_symbol' => 'JOD',
|
531 |
+
'currency_pos' => 'right',
|
532 |
+
'thousand_sep' => ',',
|
533 |
+
'decimal_sep' => '.',
|
534 |
+
'num_decimals' => 2,
|
535 |
+
'name' => 'Jordanian Dinar',
|
536 |
+
),
|
537 |
+
'NOK' => array(
|
538 |
+
'currency_symbol' => 'NOK',
|
539 |
+
'currency_pos' => 'left',
|
540 |
+
'thousand_sep' => ',',
|
541 |
+
'decimal_sep' => '.',
|
542 |
+
'num_decimals' => 2,
|
543 |
+
'name' => 'Norske kroner',
|
544 |
+
),
|
|
|
|
|
|
|
|
|
545 |
'NZD' => array(
|
546 |
+
'currency_symbol' => 'NZ $',
|
547 |
+
'currency_pos' => 'left',
|
548 |
+
'thousand_sep' => ',',
|
549 |
+
'decimal_sep' => '.',
|
550 |
+
'num_decimals' => 2,
|
551 |
+
'name' => 'New Zealand dollar',
|
552 |
+
),
|
553 |
+
|
554 |
+
);
|
555 |
+
}
|
556 |
+
|
557 |
+
public function setLocale( $locale ) {
|
558 |
+
$this->locale = $locale;
|
559 |
+
}
|
560 |
+
|
561 |
+
public function getLocale() {
|
562 |
+
return $this->locale;
|
563 |
+
}
|
564 |
+
|
565 |
+
private function getValue( $currency, $key, $default = null ) {
|
566 |
+
if ( isset( $this->currencies[ $currency ] ) && isset( $this->currencies[ $currency ][ $key ] ) ) {
|
567 |
+
$value = $this->currencies[ $currency ][ $key ];
|
568 |
+
} else {
|
569 |
+
$value = null;
|
570 |
+
}
|
571 |
+
|
572 |
+
if ( ! is_null( $value ) && is_scalar( $value ) && $currency == 'MXN' ) {
|
573 |
+
return $value;
|
574 |
+
}
|
575 |
+
|
576 |
+
if ( is_array( $value ) && isset( $value[ $this->locale ] ) ) {
|
577 |
+
return $value[ $this->locale ];
|
578 |
+
} elseif ( isset( $this->locales[ $this->locale ] ) && isset( $this->locales[ $this->locale ][ $key ] ) ) {
|
579 |
+
return $this->locales[ $this->locale ][ $key ];
|
580 |
+
} elseif ( is_array( $value ) ) {
|
581 |
+
return reset( $value );
|
582 |
+
} // first value
|
583 |
+
elseif ( is_scalar( $value ) && ! is_null( $value ) ) {
|
584 |
+
return $value;
|
585 |
+
} else {
|
586 |
+
return $default;
|
587 |
+
}
|
588 |
+
}
|
589 |
+
|
590 |
+
public function currencyFormat( $amount, $currency, $thousand_sep = null, $decimal_sep = null, $before_symbol = '', $after_symbol = '' ) {
|
591 |
+
$amount = $this->numberFormat( $amount, $currency, $thousand_sep, $decimal_sep );
|
592 |
+
$symbol = \apply_filters( 'cegg_currency_symbol', $this->getSymbol( $currency ), $currency );
|
593 |
+
$currency_pos = $this->getCurrencyPos( $currency );
|
594 |
+
$symbol = $before_symbol . $symbol . $after_symbol;
|
595 |
+
switch ( $currency_pos ) {
|
596 |
+
case 'left_space':
|
597 |
+
return $symbol . ' ' . $amount;
|
598 |
+
case 'left':
|
599 |
+
return $symbol . $amount;
|
600 |
+
case 'right_space':
|
601 |
+
return $amount . ' ' . $symbol;
|
602 |
+
case 'right':
|
603 |
+
return $amount . $symbol;
|
604 |
+
default:
|
605 |
+
return $symbol . ' ' . $amount;
|
606 |
+
}
|
607 |
+
}
|
608 |
+
|
609 |
+
public function getCurrencyPos( $currency, $default = 'left_space' ) {
|
610 |
+
return $this->getValue( $currency, 'currency_pos', $default );
|
611 |
+
}
|
612 |
+
|
613 |
+
public function getSymbol( $currency ) {
|
614 |
+
return $this->getValue( $currency, 'currency_symbol', $currency );
|
615 |
+
}
|
616 |
+
|
617 |
+
public function getName( $currency ) {
|
618 |
+
return $this->getValue( $currency, 'name', $currency );
|
619 |
+
}
|
620 |
+
|
621 |
+
public function numberFormat( $number, $currency, $thousand_sep = null, $decimal_sep = null, $num_decimals = null ) {
|
622 |
+
if ( ! $thousand_sep ) {
|
623 |
+
$thousand_sep = $this->getValue( $currency, 'thousand_sep', ',' );
|
624 |
+
}
|
625 |
+
if ( ! $decimal_sep ) {
|
626 |
+
$decimal_sep = $this->getValue( $currency, 'decimal_sep', '.' );
|
627 |
+
}
|
628 |
+
if ( ! $num_decimals ) {
|
629 |
+
$num_decimals = $this->getValue( $currency, 'num_decimals', 2 );
|
630 |
+
}
|
631 |
+
|
632 |
+
return number_format( (float) $number, absint( $num_decimals ), $decimal_sep, $thousand_sep );
|
633 |
+
}
|
634 |
+
|
635 |
+
public static function getCurrenciesList() {
|
636 |
+
$list = array_keys( self::currencies() );
|
637 |
+
sort( $list );
|
638 |
+
|
639 |
+
return $list;
|
640 |
+
}
|
641 |
+
|
642 |
+
/**
|
643 |
+
* @link: http://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html#dev
|
644 |
+
*/
|
645 |
+
public static function queryCurrencyRateEcb( $from, $to, $force = false ) {
|
646 |
+
$transient_name = 'cegg-currency-rates-ecb';
|
647 |
+
$rates = \get_transient( $transient_name );
|
648 |
+
|
649 |
+
if ( $rates === false || $force ) {
|
650 |
+
$url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
|
651 |
+
$params = array(
|
652 |
+
'timeout' => 15,
|
653 |
+
'user-agent' => 'Content Egg WP Plugin (https://www.keywordrush.com/contentegg)'
|
654 |
+
);
|
655 |
+
$response = \wp_remote_get( $url, $params );
|
656 |
+
$rates = array();
|
657 |
+
if ( $response && ! \is_wp_error( $response ) ) {
|
658 |
+
$results = TextHelper::unserialize_xml( \wp_remote_retrieve_body( $response ) );
|
659 |
+
if ( ! isset( $results['Cube']['Cube']['Cube'] ) ) {
|
660 |
+
return 0;
|
661 |
+
}
|
662 |
+
foreach ( $results['Cube']['Cube']['Cube'] as $r ) {
|
663 |
+
$rates[ $r['@attributes']['currency'] ] = (float) $r['@attributes']['rate'];
|
664 |
+
}
|
665 |
+
}
|
666 |
+
\set_transient( $transient_name, $rates, 6 * 3600 );
|
667 |
+
}
|
668 |
+
|
669 |
+
if ( $from == 'EUR' && isset( $rates[ $to ] ) ) {
|
670 |
+
return $rates[ $to ];
|
671 |
+
} elseif ( $to == 'EUR' && isset( $rates[ $from ] ) ) {
|
672 |
+
return 1 / $rates[ $from ];
|
673 |
+
} elseif ( isset( $rates[ $from ] ) && isset( $rates[ $to ] ) ) {
|
674 |
+
return $rates[ $to ] / $rates[ $from ];
|
675 |
+
} else {
|
676 |
+
return 0;
|
677 |
+
}
|
678 |
+
}
|
679 |
+
|
680 |
+
public static function queryCurrencyRate( $from, $to ) {
|
681 |
+
return self::queryCurrencyRateEcb( $from, $to );
|
682 |
+
}
|
683 |
+
|
684 |
+
public static function getCurrencyRate( $from, $to ) {
|
685 |
+
if ( $from == 'RUR' ) {
|
686 |
+
$from = 'RUB';
|
687 |
+
}
|
688 |
+
if ( $to == 'RUR' ) {
|
689 |
+
$to = 'RUB';
|
690 |
+
}
|
691 |
+
|
692 |
+
if ( $rate = \apply_filters( 'content_egg_currency_rate', 0, $from, $to ) ) {
|
693 |
+
return $rate;
|
694 |
+
}
|
695 |
+
|
696 |
+
$transient_name = 'currency-rate-' . $from . $to;
|
697 |
+
if ( ! isset( self::$currencyRates[ $transient_name ] ) ) {
|
698 |
+
$rate = \get_transient( $transient_name );
|
699 |
+
if ( $rate === false ) {
|
700 |
+
$rate = self::queryCurrencyRate( $from, $to );
|
701 |
+
\set_transient( $transient_name, $rate, 24 * 3600 );
|
702 |
+
}
|
703 |
+
self::$currencyRates[ $transient_name ] = $rate;
|
704 |
+
}
|
705 |
+
|
706 |
+
return self::$currencyRates[ $transient_name ];
|
707 |
+
}
|
|
|
|
|
|
|
708 |
|
709 |
}
|
application/helpers/FileHelper.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* TextHelper class file
|
@@ -13,37 +13,37 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class FileHelper {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* TextHelper class file
|
13 |
*/
|
14 |
class FileHelper {
|
15 |
|
16 |
+
public static function array2Csv( array $array ) {
|
17 |
+
if ( ob_get_length() > 0 ) {
|
18 |
+
ob_clean();
|
19 |
+
}
|
20 |
+
|
21 |
+
if ( ! $array ) {
|
22 |
+
return '';
|
23 |
+
}
|
24 |
+
ob_start();
|
25 |
+
$df = fopen( "php://output", 'w' );
|
26 |
+
fputcsv( $df, array_keys( reset( $array ) ) );
|
27 |
+
foreach ( $array as $row ) {
|
28 |
+
fputcsv( $df, $row );
|
29 |
+
}
|
30 |
+
fclose( $df );
|
31 |
+
|
32 |
+
return ob_get_clean();
|
33 |
+
}
|
34 |
+
|
35 |
+
public static function sendDownloadHeaders( $filename ) {
|
36 |
+
$now = gmdate( "D, d M Y H:i:s" );
|
37 |
+
header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
|
38 |
+
header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
|
39 |
+
header( "Last-Modified: {$now} GMT" );
|
40 |
+
|
41 |
+
header( "Content-Type: application/force-download" );
|
42 |
+
header( "Content-Type: application/octet-stream" );
|
43 |
+
header( "Content-Type: application/download" );
|
44 |
+
|
45 |
+
header( "Content-Disposition: attachment;filename={$filename}" );
|
46 |
+
header( "Content-Transfer-Encoding: binary" );
|
47 |
+
}
|
48 |
|
49 |
}
|
application/helpers/FormValidator.php
CHANGED
@@ -2,17 +2,17 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
/**
|
7 |
* FormValidator class file
|
8 |
-
*
|
9 |
* Modified version of: CodeIgniter CI_Form_validation
|
10 |
*
|
11 |
* @author keywordrush.com <support@keywordrush.com>
|
12 |
* @link http://www.keywordrush.com/
|
13 |
* @copyright Copyright © 2014 keywordrush.com
|
14 |
-
*
|
15 |
-
*
|
16 |
*/
|
17 |
/**
|
18 |
* CodeIgniter
|
@@ -31,416 +31,409 @@ defined('\ABSPATH') || exit;
|
|
31 |
* through the world wide web, please send an email to
|
32 |
* licensing@ellislab.com so we can send you a copy immediately.
|
33 |
*
|
34 |
-
* @package
|
35 |
-
* @author
|
36 |
-
* @copyright
|
37 |
-
* @license
|
38 |
-
* @link
|
39 |
-
* @since
|
40 |
* @filesource
|
41 |
*/
|
42 |
-
if (!defined('MB_ENABLED'))
|
43 |
-
{
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
}
|
49 |
|
50 |
class FormValidator {
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
*/
|
431 |
-
public static function encode_php_tags($str)
|
432 |
-
{
|
433 |
-
return str_replace(array('<?', '?>'), array('<?', '?>'), $str);
|
434 |
-
}
|
435 |
|
436 |
}
|
437 |
|
438 |
-
if (!function_exists('affegg_intval_bool'))
|
439 |
-
{
|
440 |
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
}
|
445 |
|
446 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
/**
|
7 |
* FormValidator class file
|
8 |
+
*
|
9 |
* Modified version of: CodeIgniter CI_Form_validation
|
10 |
*
|
11 |
* @author keywordrush.com <support@keywordrush.com>
|
12 |
* @link http://www.keywordrush.com/
|
13 |
* @copyright Copyright © 2014 keywordrush.com
|
14 |
+
*
|
15 |
+
*
|
16 |
*/
|
17 |
/**
|
18 |
* CodeIgniter
|
31 |
* through the world wide web, please send an email to
|
32 |
* licensing@ellislab.com so we can send you a copy immediately.
|
33 |
*
|
34 |
+
* @package CodeIgniter
|
35 |
+
* @author EllisLab Dev Team
|
36 |
+
* @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
|
37 |
+
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
38 |
+
* @link http://codeigniter.com
|
39 |
+
* @since Version 1.0
|
40 |
* @filesource
|
41 |
*/
|
42 |
+
if ( ! defined( 'MB_ENABLED' ) ) {
|
43 |
+
if ( extension_loaded( 'mbstring' ) ) {
|
44 |
+
define( 'MB_ENABLED', true );
|
45 |
+
} else {
|
46 |
+
define( 'MB_ENABLED', false );
|
47 |
+
}
|
48 |
}
|
49 |
|
50 |
class FormValidator {
|
51 |
|
52 |
+
/**
|
53 |
+
* Required
|
54 |
+
*
|
55 |
+
* @param string
|
56 |
+
*
|
57 |
+
* @return bool
|
58 |
+
*/
|
59 |
+
public static function required( $str ) {
|
60 |
+
return is_array( $str ) ? (bool) count( $str ) : ( trim( $str ) !== '' );
|
61 |
+
}
|
62 |
+
|
63 |
+
// --------------------------------------------------------------------
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Performs a Regular Expression match test.
|
67 |
+
*
|
68 |
+
* @param string
|
69 |
+
* @param string regex
|
70 |
+
*
|
71 |
+
* @return bool
|
72 |
+
*/
|
73 |
+
public static function regex_match( $str, $regex ) {
|
74 |
+
return (bool) preg_match( $regex, $str );
|
75 |
+
}
|
76 |
+
|
77 |
+
// --------------------------------------------------------------------
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Minimum Length
|
81 |
+
*
|
82 |
+
* @param string
|
83 |
+
* @param string
|
84 |
+
*
|
85 |
+
* @return bool
|
86 |
+
*/
|
87 |
+
public static function min_length( $str, $val ) {
|
88 |
+
if ( ! is_numeric( $val ) ) {
|
89 |
+
return false;
|
90 |
+
} else {
|
91 |
+
$val = (int) $val;
|
92 |
+
}
|
93 |
+
|
94 |
+
return ( MB_ENABLED === true ) ? ( $val <= mb_strlen( $str ) ) : ( $val <= strlen( $str ) );
|
95 |
+
}
|
96 |
+
|
97 |
+
// --------------------------------------------------------------------
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Max Length
|
101 |
+
*
|
102 |
+
* @param string
|
103 |
+
* @param string
|
104 |
+
*
|
105 |
+
* @return bool
|
106 |
+
*/
|
107 |
+
public static function max_length( $str, $val ) {
|
108 |
+
if ( ! is_numeric( $val ) ) {
|
109 |
+
return false;
|
110 |
+
} else {
|
111 |
+
$val = (int) $val;
|
112 |
+
}
|
113 |
+
|
114 |
+
return ( MB_ENABLED === true ) ? ( $val >= mb_strlen( $str ) ) : ( $val >= strlen( $str ) );
|
115 |
+
}
|
116 |
+
|
117 |
+
// --------------------------------------------------------------------
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Exact Length
|
121 |
+
*
|
122 |
+
* @param string
|
123 |
+
* @param string
|
124 |
+
*
|
125 |
+
* @return bool
|
126 |
+
*/
|
127 |
+
public static function exact_length( $str, $val ) {
|
128 |
+
if ( ! is_numeric( $val ) ) {
|
129 |
+
return false;
|
130 |
+
} else {
|
131 |
+
$val = (int) $val;
|
132 |
+
}
|
133 |
+
|
134 |
+
return ( MB_ENABLED === true ) ? ( mb_strlen( $str ) === $val ) : ( strlen( $str ) === $val );
|
135 |
+
}
|
136 |
+
|
137 |
+
// --------------------------------------------------------------------
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Valid URL
|
141 |
+
*
|
142 |
+
* @param string $str
|
143 |
+
*
|
144 |
+
* @return bool
|
145 |
+
*/
|
146 |
+
public static function valid_url( $str ) {
|
147 |
+
if ( empty( $str ) ) {
|
148 |
+
return false;
|
149 |
+
}
|
150 |
+
|
151 |
+
$pattern = '/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i';
|
152 |
+
|
153 |
+
if ( is_string( $str ) && strlen( $str ) < 2000 ) {
|
154 |
+
if ( preg_match( $pattern, $str ) ) {
|
155 |
+
return true;
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
return false;
|
160 |
+
|
161 |
+
/*
|
162 |
+
if (empty($str))
|
163 |
+
{
|
164 |
+
return FALSE;
|
165 |
+
} elseif (preg_match('/^(?:([^:]*)\:)?\/\/(.+)$/', $str, $matches))
|
166 |
+
{
|
167 |
+
if (empty($matches[2]))
|
168 |
+
{
|
169 |
+
return FALSE;
|
170 |
+
} elseif (!in_array($matches[1], array('http', 'https'), TRUE))
|
171 |
+
{
|
172 |
+
return FALSE;
|
173 |
+
}
|
174 |
+
|
175 |
+
$str = $matches[2];
|
176 |
+
}
|
177 |
+
|
178 |
+
$str = 'http://' . $str;
|
179 |
+
|
180 |
+
// There's a bug affecting PHP 5.2.13, 5.3.2 that considers the
|
181 |
+
// underscore to be a valid hostname character instead of a dash.
|
182 |
+
// Reference: https://bugs.php.net/bug.php?id=51192
|
183 |
+
if (version_compare(PHP_VERSION, '5.2.13', '==') === 0 OR version_compare(PHP_VERSION, '5.3.2', '==') === 0)
|
184 |
+
{
|
185 |
+
sscanf($str, 'http://%[^/]', $host);
|
186 |
+
$str = substr_replace($str, strtr($host, array('_' => '-', '-' => '_')), 7, strlen($host));
|
187 |
+
}
|
188 |
+
|
189 |
+
return (filter_var($str, FILTER_VALIDATE_URL) !== FALSE);
|
190 |
+
*
|
191 |
+
*/
|
192 |
+
}
|
193 |
+
|
194 |
+
// --------------------------------------------------------------------
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Valid Email
|
198 |
+
*
|
199 |
+
* @param string
|
200 |
+
*
|
201 |
+
* @return bool
|
202 |
+
*/
|
203 |
+
public static function valid_email( $str ) {
|
204 |
+
return (bool) filter_var( $str, FILTER_VALIDATE_EMAIL );
|
205 |
+
}
|
206 |
+
|
207 |
+
// --------------------------------------------------------------------
|
208 |
+
// --------------------------------------------------------------------
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Alpha
|
212 |
+
*
|
213 |
+
* @param string
|
214 |
+
*
|
215 |
+
* @return bool
|
216 |
+
*/
|
217 |
+
public static function alpha( $str ) {
|
218 |
+
return ctype_alpha( $str );
|
219 |
+
}
|
220 |
+
|
221 |
+
// --------------------------------------------------------------------
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Alpha-numeric
|
225 |
+
*
|
226 |
+
* @param string
|
227 |
+
*
|
228 |
+
* @return bool
|
229 |
+
*/
|
230 |
+
public static function alpha_numeric( $str ) {
|
231 |
+
return ctype_alnum( (string) $str );
|
232 |
+
}
|
233 |
+
|
234 |
+
// --------------------------------------------------------------------
|
235 |
+
|
236 |
+
/**
|
237 |
+
* Alpha-numeric w/ spaces
|
238 |
+
*
|
239 |
+
* @param string
|
240 |
+
*
|
241 |
+
* @return bool
|
242 |
+
*/
|
243 |
+
public static function alpha_numeric_spaces( $str ) {
|
244 |
+
return (bool) preg_match( '/^[A-Z0-9 ]+$/i', $str );
|
245 |
+
}
|
246 |
+
|
247 |
+
// --------------------------------------------------------------------
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Alpha-numeric with underscores and dashes
|
251 |
+
*
|
252 |
+
* @param string
|
253 |
+
*
|
254 |
+
* @return bool
|
255 |
+
*/
|
256 |
+
public static function alpha_dash( $str ) {
|
257 |
+
return (bool) preg_match( '/^[a-z0-9_-]+$/i', $str );
|
258 |
+
}
|
259 |
+
|
260 |
+
// --------------------------------------------------------------------
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Numeric
|
264 |
+
*
|
265 |
+
* @param string
|
266 |
+
*
|
267 |
+
* @return bool
|
268 |
+
*/
|
269 |
+
public static function numeric( $str ) {
|
270 |
+
return (bool) preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str );
|
271 |
+
}
|
272 |
+
|
273 |
+
// --------------------------------------------------------------------
|
274 |
+
|
275 |
+
/**
|
276 |
+
* Integer
|
277 |
+
*
|
278 |
+
* @param string
|
279 |
+
*
|
280 |
+
* @return bool
|
281 |
+
*/
|
282 |
+
public static function integer( $str ) {
|
283 |
+
return (bool) preg_match( '/^[\-+]?[0-9]+$/', $str );
|
284 |
+
}
|
285 |
+
|
286 |
+
// --------------------------------------------------------------------
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Decimal number
|
290 |
+
*
|
291 |
+
* @param string
|
292 |
+
*
|
293 |
+
* @return bool
|
294 |
+
*/
|
295 |
+
public static function decimal( $str ) {
|
296 |
+
return (bool) preg_match( '/^[\-+]?[0-9]+\.[0-9]+$/', $str );
|
297 |
+
}
|
298 |
+
|
299 |
+
// --------------------------------------------------------------------
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Greater than
|
303 |
+
*
|
304 |
+
* @param string
|
305 |
+
* @param int
|
306 |
+
*
|
307 |
+
* @return bool
|
308 |
+
*/
|
309 |
+
public static function greater_than( $str, $min ) {
|
310 |
+
return is_numeric( $str ) ? ( $str > $min ) : false;
|
311 |
+
}
|
312 |
+
|
313 |
+
// --------------------------------------------------------------------
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Equal to or Greater than
|
317 |
+
*
|
318 |
+
* @param string
|
319 |
+
* @param int
|
320 |
+
*
|
321 |
+
* @return bool
|
322 |
+
*/
|
323 |
+
public static function greater_than_equal_to( $str, $min ) {
|
324 |
+
return is_numeric( $str ) ? ( $str >= $min ) : false;
|
325 |
+
}
|
326 |
+
|
327 |
+
// --------------------------------------------------------------------
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Less than
|
331 |
+
*
|
332 |
+
* @param string
|
333 |
+
* @param int
|
334 |
+
*
|
335 |
+
* @return bool
|
336 |
+
*/
|
337 |
+
public static function less_than( $str, $max ) {
|
338 |
+
return is_numeric( $str ) ? ( $str < $max ) : false;
|
339 |
+
}
|
340 |
+
|
341 |
+
// --------------------------------------------------------------------
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Equal to or Less than
|
345 |
+
*
|
346 |
+
* @param string
|
347 |
+
* @param int
|
348 |
+
*
|
349 |
+
* @return bool
|
350 |
+
*/
|
351 |
+
public static function less_than_equal_to( $str, $max ) {
|
352 |
+
return is_numeric( $str ) ? ( $str <= $max ) : false;
|
353 |
+
}
|
354 |
+
|
355 |
+
// --------------------------------------------------------------------
|
356 |
+
|
357 |
+
/**
|
358 |
+
* Is a Natural number (0,1,2,3, etc.)
|
359 |
+
*
|
360 |
+
* @param string
|
361 |
+
*
|
362 |
+
* @return bool
|
363 |
+
*/
|
364 |
+
public static function is_natural( $str ) {
|
365 |
+
return ctype_digit( (string) $str );
|
366 |
+
}
|
367 |
+
|
368 |
+
// --------------------------------------------------------------------
|
369 |
+
|
370 |
+
/**
|
371 |
+
* Is a Natural number, but not a zero (1,2,3, etc.)
|
372 |
+
*
|
373 |
+
* @param string
|
374 |
+
*
|
375 |
+
* @return bool
|
376 |
+
*/
|
377 |
+
public static function is_natural_no_zero( $str ) {
|
378 |
+
return ( $str != 0 && ctype_digit( (string) $str ) );
|
379 |
+
}
|
380 |
+
|
381 |
+
// --------------------------------------------------------------------
|
382 |
+
|
383 |
+
/**
|
384 |
+
* Valid Base64
|
385 |
+
*
|
386 |
+
* Tests a string for characters outside of the Base64 alphabet
|
387 |
+
* as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
|
388 |
+
*
|
389 |
+
* @param string
|
390 |
+
*
|
391 |
+
* @return bool
|
392 |
+
*/
|
393 |
+
public static function valid_base64( $str ) {
|
394 |
+
return ( base64_encode( base64_decode( $str ) ) === $str );
|
395 |
+
}
|
396 |
+
|
397 |
+
// --------------------------------------------------------------------
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Prep URL
|
401 |
+
*
|
402 |
+
* @param string
|
403 |
+
*
|
404 |
+
* @return string
|
405 |
+
*/
|
406 |
+
public static function prep_url( $str = '' ) {
|
407 |
+
if ( $str === 'http://' or $str === '' ) {
|
408 |
+
return '';
|
409 |
+
}
|
410 |
+
|
411 |
+
if ( strpos( $str, 'http://' ) !== 0 && strpos( $str, 'https://' ) !== 0 ) {
|
412 |
+
return 'http://' . $str;
|
413 |
+
}
|
414 |
+
|
415 |
+
return $str;
|
416 |
+
}
|
417 |
+
|
418 |
+
// --------------------------------------------------------------------
|
419 |
+
|
420 |
+
/**
|
421 |
+
* Convert PHP tags to entities
|
422 |
+
*
|
423 |
+
* @param string
|
424 |
+
*
|
425 |
+
* @return string
|
426 |
+
*/
|
427 |
+
public static function encode_php_tags( $str ) {
|
428 |
+
return str_replace( array( '<?', '?>' ), array( '<?', '?>' ), $str );
|
429 |
+
}
|
|
|
|
|
|
|
|
|
|
|
430 |
|
431 |
}
|
432 |
|
433 |
+
if ( ! function_exists( 'affegg_intval_bool' ) ) {
|
|
|
434 |
|
435 |
+
function affegg_intval_bool( $str ) {
|
436 |
+
return intval( (bool) $str );
|
437 |
+
}
|
|
|
438 |
|
439 |
}
|
application/helpers/ImageHelper.php
CHANGED
@@ -2,105 +2,114 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ImageHelper class file
|
9 |
-
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link http://www.keywordrush.com/
|
12 |
* @copyright Copyright © 2015 keywordrush.com
|
13 |
-
*
|
14 |
*/
|
15 |
class ImageHelper {
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ImageHelper class file
|
9 |
+
*
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link http://www.keywordrush.com/
|
12 |
* @copyright Copyright © 2015 keywordrush.com
|
13 |
+
*
|
14 |
*/
|
15 |
class ImageHelper {
|
16 |
|
17 |
+
const DOWNLOAD_TIMEOUT = 5;
|
18 |
+
const USERAGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15';
|
19 |
+
|
20 |
+
public static function saveImgLocaly( $img_uri, $title = '', $check_image_type = true ) {
|
21 |
+
$newfilename = TextHelper::truncate( $title );
|
22 |
+
$newfilename = TextHelper::rus2latin( $newfilename );
|
23 |
+
$newfilename = preg_replace( '/[^a-zA-Z0-9\-]/', '', $newfilename );
|
24 |
+
$newfilename = strtolower( $newfilename );
|
25 |
+
if ( ! $newfilename ) {
|
26 |
+
$newfilename = time();
|
27 |
+
}
|
28 |
+
|
29 |
+
$uploads = \wp_upload_dir();
|
30 |
+
|
31 |
+
if ( $newfilename = self::downloadImg( $img_uri, $uploads['path'], $newfilename, null, $check_image_type ) ) {
|
32 |
+
return $newfilename;
|
33 |
+
} else {
|
34 |
+
return false;
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
public static function downloadImg( $img_uri, $save_dir, $file_name, $file_ext = null, $check_image_type = true ) {
|
39 |
+
$response = \wp_remote_get( $img_uri, array( 'timeout' => self::DOWNLOAD_TIMEOUT,
|
40 |
+
'redirection' => 1,
|
41 |
+
'sslverify' => false,
|
42 |
+
'user-agent' => self::USERAGENT
|
43 |
+
) );
|
44 |
+
if ( \is_wp_error( $response ) || (int) \wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
45 |
+
return false;
|
46 |
+
}
|
47 |
+
|
48 |
+
if ( $file_ext === null ) {
|
49 |
+
$img_path = parse_url( $img_uri, PHP_URL_PATH );
|
50 |
+
$file_ext = pathinfo( basename( $img_path ), PATHINFO_EXTENSION );
|
51 |
+
if ( ! $file_ext || $file_ext == 'aspx' || $file_ext == 'image' ) {
|
52 |
+
$headers = \wp_remote_retrieve_headers( $response );
|
53 |
+
if ( empty( $headers['content-type'] ) ) {
|
54 |
+
return false;
|
55 |
+
}
|
56 |
+
$types = array_search( $headers['content-type'], \wp_get_mime_types() );
|
57 |
+
if ( ! $types ) {
|
58 |
+
return false;
|
59 |
+
}
|
60 |
+
|
61 |
+
$exts = explode( '|', $types );
|
62 |
+
$file_ext = $exts[0];
|
63 |
+
}
|
64 |
+
}
|
65 |
+
if ( $file_ext ) {
|
66 |
+
$file_name .= '.' . $file_ext;
|
67 |
+
}
|
68 |
+
|
69 |
+
$file_name = \wp_unique_filename( $save_dir, $file_name );
|
70 |
+
|
71 |
+
if ( $check_image_type ) {
|
72 |
+
$filetype = \wp_check_filetype( $file_name, null );
|
73 |
+
if ( substr( $filetype['type'], 0, 5 ) != 'image' ) {
|
74 |
+
return false;
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
$image_string = \wp_remote_retrieve_body( $response );
|
79 |
+
$file_path = \trailingslashit( $save_dir ) . $file_name;
|
80 |
+
if ( ! file_put_contents( $file_path, $image_string ) ) {
|
81 |
+
return false;
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( $check_image_type && ! self::isImage( $file_path ) ) {
|
85 |
+
@unlink( $file_path );
|
86 |
+
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
if ( ! defined( 'FS_CHMOD_FILE' ) ) {
|
90 |
+
define( 'FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
|
91 |
+
}
|
92 |
+
@chmod( $file_path, FS_CHMOD_FILE );
|
93 |
+
|
94 |
+
return $file_name;
|
95 |
+
}
|
96 |
+
|
97 |
+
public static function isImage( $path ) {
|
98 |
+
if ( ! $a = getimagesize( $path ) ) {
|
99 |
+
return false;
|
100 |
+
}
|
101 |
+
$image_type = $a[2];
|
102 |
+
if ( in_array( $image_type, array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP ) ) ) {
|
103 |
+
return true;
|
104 |
+
} else {
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
public static function getFullImgPath( $img_path ) {
|
110 |
+
$uploads = \wp_upload_dir();
|
111 |
+
|
112 |
+
return trailingslashit( $uploads['basedir'] ) . $img_path;
|
113 |
+
}
|
114 |
|
115 |
}
|
application/helpers/InputHelper.php
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
-
|
7 |
-
/**
|
8 |
-
* InputHelper class file
|
9 |
-
*
|
10 |
-
* @author keywordrush.com <support@keywordrush.com>
|
11 |
-
* @link http://www.keywordrush.com/
|
12 |
-
* @copyright Copyright © 2015 keywordrush.com
|
13 |
-
*
|
14 |
-
*/
|
15 |
-
class InputHelper {
|
16 |
-
|
17 |
-
public static function get($var, $default = null, $stripslashes = false)
|
18 |
-
{
|
19 |
-
if (!isset($_GET[$var]))
|
20 |
-
return $default;
|
21 |
-
else
|
22 |
-
return $stripslashes ? \stripslashes_deep($_GET[$var]) : $_GET[$var];
|
23 |
-
}
|
24 |
-
|
25 |
-
public static function post($var, $default = null, $stripslashes = false)
|
26 |
-
{
|
27 |
-
if (!isset($_POST[$var]))
|
28 |
-
return $default;
|
29 |
-
else
|
30 |
-
return $stripslashes ? \stripslashes_deep($_POST[$var]) : $_POST[$var];
|
31 |
-
}
|
32 |
-
|
33 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/helpers/TemplateHelper.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\models\PriceHistoryModel;
|
@@ -22,1291 +22,1310 @@ use ContentEgg\application\Translator;
|
|
22 |
* @copyright Copyright © 2021 keywordrush.com
|
23 |
*
|
24 |
*/
|
|
|
|
|
25 |
class TemplateHelper {
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
public static function priceChangesProducts($limit = 5)
|
309 |
-
{
|
310 |
-
$params = array(
|
311 |
//'select' => 'DISTINCT unique_id',
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
// find products
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
|
356 |
//add last known price to the chart
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
{
|
380 |
// morris.js
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
1263 |
-
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
1270 |
-
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
1279 |
-
|
1280 |
-
|
1281 |
-
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
1292 |
-
|
1293 |
-
|
1294 |
-
|
1295 |
-
|
1296 |
-
|
1297 |
-
|
1298 |
-
|
1299 |
-
|
1300 |
-
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1311 |
|
1312 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\models\PriceHistoryModel;
|
22 |
* @copyright Copyright © 2021 keywordrush.com
|
23 |
*
|
24 |
*/
|
25 |
+
|
26 |
+
|
27 |
class TemplateHelper {
|
28 |
|
29 |
+
const MERHANT_LOGO_DIR = 'ce-logos';
|
30 |
+
const IMG_SMALL = 'small';
|
31 |
+
const IMG_MEDIUM = 'medium';
|
32 |
+
const IMG_LARGE = 'large';
|
33 |
+
const IMG_ORIGINAL = 'original';
|
34 |
+
|
35 |
+
static $global_id = 0;
|
36 |
+
static $logos = null;
|
37 |
+
static $shop_info = null;
|
38 |
+
|
39 |
+
public static function formatPriceCurrency( $price, $currencyCode, $before_symbol = '', $after_symbol = '' ) {
|
40 |
+
$decimal_sep = __( 'number_format_decimal_point', 'content-egg-tpl' );
|
41 |
+
$thousand_sep = __( 'number_format_thousands_sep', 'content-egg-tpl' );
|
42 |
+
if ( $decimal_sep == 'number_format_decimal_point' ) {
|
43 |
+
$decimal_sep = null;
|
44 |
+
}
|
45 |
+
if ( $thousand_sep == 'number_format_thousands_sep' ) {
|
46 |
+
$thousand_sep = null;
|
47 |
+
}
|
48 |
+
|
49 |
+
return CurrencyHelper::getInstance()->currencyFormat( $price, $currencyCode, $thousand_sep, $decimal_sep, $before_symbol, $after_symbol );
|
50 |
+
}
|
51 |
+
|
52 |
+
public static function currencyTyping( $c ) {
|
53 |
+
return CurrencyHelper::getInstance()->getSymbol( $c );
|
54 |
+
}
|
55 |
+
|
56 |
+
/*
|
57 |
+
* @deprecated
|
58 |
+
*/
|
59 |
+
|
60 |
+
public static function number_format_i18n( $number, $decimals = 0, $currency = null ) {
|
61 |
+
$decimal_sep = __( 'number_format_decimal_point', 'content-egg-tpl' );
|
62 |
+
$thousand_sep = __( 'number_format_thousands_sep', 'content-egg-tpl' );
|
63 |
+
if ( $decimal_sep == 'number_format_decimal_point' ) {
|
64 |
+
$decimal_sep = null;
|
65 |
+
}
|
66 |
+
if ( $thousand_sep == 'number_format_thousands_sep' ) {
|
67 |
+
$thousand_sep = null;
|
68 |
+
}
|
69 |
+
|
70 |
+
return CurrencyHelper::getInstance()->numberFormat( $number, $currency, $thousand_sep, $decimal_sep, $decimals );
|
71 |
+
}
|
72 |
+
|
73 |
+
/*
|
74 |
+
* @deprecated
|
75 |
+
*/
|
76 |
+
|
77 |
+
public static function price_format_i18n( $number, $currency = null ) {
|
78 |
+
return self::number_format_i18n( $number, $decimal = null, $currency );
|
79 |
+
}
|
80 |
+
|
81 |
+
public static function truncate( $string, $length = 80, $etc = '...', $charset = 'UTF-8', $break_words = false, $middle = false ) {
|
82 |
+
if ( $length == 0 ) {
|
83 |
+
return '';
|
84 |
+
}
|
85 |
+
|
86 |
+
if ( mb_strlen( $string, 'UTF-8' ) > $length ) {
|
87 |
+
$length -= min( $length, mb_strlen( $etc, 'UTF-8' ) );
|
88 |
+
if ( ! $break_words && ! $middle ) {
|
89 |
+
$string = preg_replace( '/\s+?(\S+)?$/', '', mb_substr( $string, 0, $length + 1, $charset ) );
|
90 |
+
}
|
91 |
+
if ( ! $middle ) {
|
92 |
+
return mb_substr( $string, 0, $length, $charset ) . $etc;
|
93 |
+
} else {
|
94 |
+
return mb_substr( $string, 0, $length / 2, $charset ) . $etc . mb_substr( $string, - $length / 2, $charset );
|
95 |
+
}
|
96 |
+
} else {
|
97 |
+
return $string;
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
static public function getTimeLeft( $end_time_gmt, $return_array = false ) {
|
102 |
+
$current_time = strtotime( gmdate( "M d Y H:i:s" ) );
|
103 |
+
$timeleft = strtotime( $end_time_gmt ) - $current_time;
|
104 |
+
if ( $timeleft < 0 ) {
|
105 |
+
return '';
|
106 |
+
}
|
107 |
+
|
108 |
+
$days_left = floor( $timeleft / 86400 );
|
109 |
+
$hours_left = floor( ( $timeleft - $days_left * 86400 ) / 3600 );
|
110 |
+
$min_left = floor( ( $timeleft - $days_left * 86400 - $hours_left * 3600 ) / 60 );
|
111 |
+
if ( $return_array ) {
|
112 |
+
return array(
|
113 |
+
'days' => $days_left,
|
114 |
+
'hours' => $hours_left,
|
115 |
+
'min' => $min_left,
|
116 |
+
);
|
117 |
+
}
|
118 |
+
|
119 |
+
if ( $days_left ) {
|
120 |
+
return $days_left . __( 'd', 'content-egg-tpl' ) . ' ';
|
121 |
+
} elseif ( $hours_left ) {
|
122 |
+
return $hours_left . __( 'h', 'content-egg-tpl' ) . ' ';
|
123 |
+
} elseif ( $min_left ) {
|
124 |
+
return $min_left . __( 'm', 'content-egg-tpl' );
|
125 |
+
} else {
|
126 |
+
return '<1' . __( 'm', 'content-egg-tpl' );
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
public static function filterData( $data, $field_name, $field_values, $extra = false, $inverse = false ) {
|
131 |
+
$results = array();
|
132 |
+
foreach ( $data as $key => $d ) {
|
133 |
+
if ( $extra ) {
|
134 |
+
if ( ! isset( $d['extra'] ) || ! isset( $d['extra'][ $field_name ] ) ) {
|
135 |
+
continue;
|
136 |
+
}
|
137 |
+
$value = $d['extra'][ $field_name ];
|
138 |
+
} else {
|
139 |
+
if ( ! isset( $d[ $field_name ] ) ) {
|
140 |
+
continue;
|
141 |
+
}
|
142 |
+
$value = $d[ $field_name ];
|
143 |
+
}
|
144 |
+
if ( ! is_array( $field_values ) ) {
|
145 |
+
$field_values = array( $field_values );
|
146 |
+
}
|
147 |
+
|
148 |
+
if ( ! $inverse && in_array( $value, $field_values ) ) {
|
149 |
+
$results[ $key ] = $d;
|
150 |
+
} elseif ( $inverse && ! in_array( $value, $field_values ) ) {
|
151 |
+
$results[ $key ] = $d;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
return $results;
|
156 |
+
}
|
157 |
+
|
158 |
+
public static function formatDatetime( $datetime, $type = 'mysql', $separator = ' ' ) {
|
159 |
+
if ( 'mysql' == $type ) {
|
160 |
+
return mysql2date( get_option( 'date_format' ), $datetime ) . $separator . mysql2date( get_option( 'time_format' ), $datetime );
|
161 |
+
} else {
|
162 |
+
return date_i18n( get_option( 'date_format' ), $datetime ) . $separator . date_i18n( get_option( 'time_format' ), $datetime );
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
public static function formatDate( $timestamp, $gmt = false ) {
|
167 |
+
return date_i18n( get_option( 'date_format' ), $timestamp, $gmt );
|
168 |
+
}
|
169 |
+
|
170 |
+
public static function splitAttributeName( $attribute ) {
|
171 |
+
return trim( preg_replace( '/([A-Z])([a-z])/', ' $1$2', $attribute ) );
|
172 |
+
}
|
173 |
+
|
174 |
+
public static function getAmazonLink( $itemLinks, $description ) {
|
175 |
+
// api 5 fix
|
176 |
+
if ( ! is_array( $itemLinks ) || ! $itemLinks ) {
|
177 |
+
return '';
|
178 |
+
}
|
179 |
+
|
180 |
+
foreach ( $itemLinks as $link ) {
|
181 |
+
if ( $link['Description'] == $description ) {
|
182 |
+
return $link['URL'];
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
return false;
|
187 |
+
}
|
188 |
+
|
189 |
+
public static function getLastUpdate( $module_id, $post_id = null ) {
|
190 |
+
if ( ! $post_id ) {
|
191 |
+
global $post;
|
192 |
+
$post_id = $post->ID;
|
193 |
+
}
|
194 |
+
$res = \get_post_meta( $post_id, ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module_id, true );
|
195 |
+
if ( ! $res ) {
|
196 |
+
$res = time();
|
197 |
+
}
|
198 |
+
|
199 |
+
return $res;
|
200 |
+
}
|
201 |
+
|
202 |
+
public static function dateFormatFromGmt( $timestamp, $time = true ) {
|
203 |
+
$format = \get_option( 'date_format' );
|
204 |
+
if ( $time ) {
|
205 |
+
$format .= ' ' . \get_option( 'time_format' );
|
206 |
+
}
|
207 |
+
|
208 |
+
// last update date stored in gmt, convert into local time
|
209 |
+
$timestamp = strtotime( \get_date_from_gmt( date( 'Y-m-d H:i:s', $timestamp ) ) );
|
210 |
+
|
211 |
+
return \date_i18n( $format, $timestamp );
|
212 |
+
}
|
213 |
+
|
214 |
+
public static function getLastUpdateFormattedAmazon( array $data, $time = true ) {
|
215 |
+
if ( isset( $data['Amazon'] ) ) {
|
216 |
+
$item = current( $data['Amazon'] );
|
217 |
+
} elseif ( isset( $data['AmazonNoApi'] ) ) {
|
218 |
+
$item = current( $data['AmazonNoApi'] );
|
219 |
+
} else {
|
220 |
+
return false;
|
221 |
+
}
|
222 |
+
|
223 |
+
if ( empty( $item['last_update'] ) ) {
|
224 |
+
return false;
|
225 |
+
}
|
226 |
+
|
227 |
+
$last_update = $item['last_update'];
|
228 |
+
|
229 |
+
return self::dateFormatFromGmt( $last_update, $time );
|
230 |
+
}
|
231 |
+
|
232 |
+
public static function getLastUpdateFormatted( $module_id, $post_id = null, $time = true ) {
|
233 |
+
if ( ! $post_id || $post_id === true ) // $post_id === true - fix func params...
|
234 |
+
{
|
235 |
+
global $post;
|
236 |
+
$post_id = $post->ID;
|
237 |
+
}
|
238 |
+
|
239 |
+
$last_update = self::getLastUpdate( $module_id, $post_id );
|
240 |
+
|
241 |
+
return self::dateFormatFromGmt( $last_update, $time );
|
242 |
+
}
|
243 |
+
|
244 |
+
public static function filterDataByType( $data, $type ) {
|
245 |
+
$results = array();
|
246 |
+
foreach ( $data as $module_id => $items ) {
|
247 |
+
$module = \ContentEgg\application\components\ModuleManager::getInstance()->factory( $module_id );
|
248 |
+
if ( $module->getParserType() == $type ) {
|
249 |
+
$results[ $module_id ] = $items;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
return $results;
|
254 |
+
}
|
255 |
+
|
256 |
+
public static function filterDataByModule( $data, $module_ids ) {
|
257 |
+
if ( ! is_array( $module_ids ) ) {
|
258 |
+
$module_ids = array( $module_ids );
|
259 |
+
}
|
260 |
+
$results = array();
|
261 |
+
|
262 |
+
foreach ( $data as $module_id => $items ) {
|
263 |
+
if ( in_array( $module_id, $module_ids ) ) {
|
264 |
+
$results[ $module_id ] = $items;
|
265 |
+
}
|
266 |
+
}
|
267 |
+
|
268 |
+
return $results;
|
269 |
+
}
|
270 |
+
|
271 |
+
public static function priceHistoryPrices( $unique_id, $plugin_id, $limit = 5 ) {
|
272 |
+
$prices = PriceHistoryModel::model()->getLastPrices( $unique_id, $plugin_id, $limit );
|
273 |
+
$results = array();
|
274 |
+
foreach ( $prices as $price ) {
|
275 |
+
$results[] = array(
|
276 |
+
'date' => strtotime( $price['create_date'] ),
|
277 |
+
'price' => $price['price'],
|
278 |
+
);
|
279 |
+
}
|
280 |
+
|
281 |
+
return $results;
|
282 |
+
}
|
283 |
+
|
284 |
+
public static function priceHistoryMax( $unique_id, $module_id ) {
|
285 |
+
if ( ! $price = PriceHistoryModel::model()->getMaxPrice( $unique_id, $module_id ) ) {
|
286 |
+
return null;
|
287 |
+
}
|
288 |
+
|
289 |
+
return array( 'price' => $price['price'], 'date' => strtotime( $price['create_date'] ) );
|
290 |
+
}
|
291 |
+
|
292 |
+
public static function priceHistoryMin( $unique_id, $module_id ) {
|
293 |
+
if ( ! $price = PriceHistoryModel::model()->getMinPrice( $unique_id, $module_id ) ) {
|
294 |
+
return null;
|
295 |
+
}
|
296 |
+
|
297 |
+
return array( 'price' => $price['price'], 'date' => strtotime( $price['create_date'] ) );
|
298 |
+
}
|
299 |
+
|
300 |
+
public static function priceHistorySinceDate( $unique_id, $module_id ) {
|
301 |
+
if ( ! $date = PriceHistoryModel::model()->getFirstDateValue( $unique_id, $module_id ) ) {
|
302 |
+
return null;
|
303 |
+
}
|
304 |
+
|
305 |
+
return strtotime( $date );
|
306 |
+
}
|
307 |
+
|
308 |
+
public static function priceChangesProducts( $limit = 5 ) {
|
309 |
+
$params = array(
|
|
|
|
|
|
|
310 |
//'select' => 'DISTINCT unique_id',
|
311 |
+
'order' => 'create_date DESC',
|
312 |
+
'where' => 'post_id IS NOT NULL',
|
313 |
+
'group' => 'unique_id',
|
314 |
+
'limit' => $limit,
|
315 |
+
);
|
316 |
+
$prices = PriceHistoryModel::model()->findAll( $params );
|
317 |
+
$products = array();
|
318 |
// find products
|
319 |
+
foreach ( $prices as $price ) {
|
320 |
+
if ( $prod = ContentManager::getProductbyUniqueId( $price['unique_id'], $price['module_id'], $price['post_id'] ) ) {
|
321 |
+
$products[] = $prod;
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
return $products;
|
326 |
+
}
|
327 |
+
|
328 |
+
public static function priceHistoryMorrisChart( $unique_id, $module_id, $days = 180, array $options = array(), $htmlOptions = array() ) {
|
329 |
+
$where = PriceHistoryModel::model()->prepareWhere(
|
330 |
+
( array( 'unique_id = %s AND module_id = %s', array( $unique_id, $module_id ) ) ), false );
|
331 |
+
$params = array(
|
332 |
+
'select' => 'date(create_date) as date, price as price',
|
333 |
+
'where' => $where . ' AND TIMESTAMPDIFF( DAY, create_date, "' . \current_time( 'mysql' ) . '") <= ' . $days,
|
334 |
+
//'group' => 'date',
|
335 |
+
'order' => 'date ASC'
|
336 |
+
);
|
337 |
+
$results = PriceHistoryModel::model()->findAll( $params );
|
338 |
+
$results = array_reverse( $results );
|
339 |
+
$prices = array();
|
340 |
+
/**
|
341 |
+
* php fix for selecting non-aggregate columns
|
342 |
+
* @see: https://stackoverflow.com/questions/1066453/mysql-group-by-and-order-by
|
343 |
+
*/
|
344 |
+
foreach ( $results as $key => $r ) {
|
345 |
+
if ( $key > 0 && $results[ $key - 1 ]['date'] == $r['date'] ) {
|
346 |
+
continue;
|
347 |
+
}
|
348 |
+
$price = array(
|
349 |
+
'date' => $r['date'],
|
350 |
+
'price' => $r['price'],
|
351 |
+
);
|
352 |
+
$prices[] = $price;
|
353 |
+
}
|
354 |
|
355 |
//add last known price to the chart
|
356 |
+
/*
|
357 |
+
$price = array(
|
358 |
+
'date' => $r['date'],
|
359 |
+
'price' => $r['price'],
|
360 |
+
);
|
361 |
+
$prices[] = $price;
|
362 |
+
*
|
363 |
+
*/
|
364 |
+
$data = array(
|
365 |
+
'chartType' => 'Area',
|
366 |
+
'data' => $prices,
|
367 |
+
'xkey' => 'date',
|
368 |
+
'ykeys' => array( 'price' ),
|
369 |
+
'labels' => array( Translator::__( 'Price' ) ),
|
370 |
+
);
|
371 |
+
$options = array_merge( $data, $options );
|
372 |
+
|
373 |
+
$id = $module_id . '-' . $unique_id . '-chart' . rand( 0, 10000 );
|
374 |
+
self::viewMorrisChart( $id, $options, $htmlOptions );
|
375 |
+
}
|
376 |
+
|
377 |
+
public static function viewMorrisChart( $id, array $options, $htmlOptions = array( 'style' => 'height: 250px;' ) ) {
|
|
|
378 |
// morris.js
|
379 |
+
\wp_enqueue_style( 'morrisjs' );
|
380 |
+
\wp_enqueue_script( 'morrisjs' );
|
381 |
+
|
382 |
+
if ( ! empty( $options['chartType'] ) && in_array( $options['chartType'], array(
|
383 |
+
'Line',
|
384 |
+
'Area',
|
385 |
+
'Donut',
|
386 |
+
'Bar'
|
387 |
+
) ) ) {
|
388 |
+
$chartType = $options['chartType'];
|
389 |
+
unset( $options['chartType'] );
|
390 |
+
} else {
|
391 |
+
$chartType = 'Line';
|
392 |
+
}
|
393 |
+
$options['element'] = $id;
|
394 |
+
|
395 |
+
$html_attr = '';
|
396 |
+
foreach ( $htmlOptions as $name => $value ) {
|
397 |
+
$html_attr .= ' ' . esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
|
398 |
+
}
|
399 |
+
|
400 |
+
|
401 |
+
echo '<div style="direction: ltr;" id="' . esc_attr( $id ) . '"' . $html_attr . '></div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
402 |
+
echo '<script>';
|
403 |
+
echo 'jQuery(document).ready(function($) {';
|
404 |
+
echo 'new Morris.' . esc_html($chartType) . '(' . json_encode( $options ) . ')';
|
405 |
+
echo '})';
|
406 |
+
echo '</script>';
|
407 |
+
}
|
408 |
+
|
409 |
+
public static function isPriceAlertAllowed( $unique_id = null, $module_id = null ) {
|
410 |
+
return \ContentEgg\application\PriceAlert::isPriceAlertAllowed( $unique_id, $module_id );
|
411 |
+
}
|
412 |
+
|
413 |
+
public static function getCurrencyPos( $currency ) {
|
414 |
+
return CurrencyHelper::getInstance()->getCurrencyPos( $currency );
|
415 |
+
}
|
416 |
+
|
417 |
+
public static function getCurrencySymbol( $currency ) {
|
418 |
+
return CurrencyHelper::getInstance()->getSymbol( $currency );
|
419 |
+
}
|
420 |
+
|
421 |
+
public static function getCurrencyName( $currency ) {
|
422 |
+
return CurrencyHelper::getInstance()->getName( $currency );
|
423 |
+
}
|
424 |
+
|
425 |
+
public static function getCustomLogo( $domain ) {
|
426 |
+
if ( self::$logos === null ) {
|
427 |
+
$logos = GeneralConfig::getInstance()->option( 'logos' );
|
428 |
+
if ( ! $logos ) {
|
429 |
+
$logos = array();
|
430 |
+
}
|
431 |
+
foreach ( $logos as $logo ) {
|
432 |
+
self::$logos[ $logo['name'] ] = $logo['value'];
|
433 |
+
}
|
434 |
+
}
|
435 |
+
|
436 |
+
if ( isset( self::$logos[ $domain ] ) ) {
|
437 |
+
return self::$logos[ $domain ];
|
438 |
+
} else {
|
439 |
+
return false;
|
440 |
+
}
|
441 |
+
}
|
442 |
+
|
443 |
+
private static function getMerchantImageUrl( array $item, $prefix = '', $remote_url = null, $blank_on_error = false ) {
|
444 |
+
$default_ext = 'png'; // ???
|
445 |
+
|
446 |
+
if ( ! strpos( $remote_url, 'www.google.com/s2/favicons?domain' ) ) {
|
447 |
+
// custom logos for Offer module
|
448 |
+
if ( isset( $item['module_id'] ) && $item['module_id'] == 'Offer' && ! empty( $item['logo'] ) ) {
|
449 |
+
return $item['logo'];
|
450 |
+
}
|
451 |
+
|
452 |
+
// custom logos
|
453 |
+
if ( isset( $item['domain'] ) && $custom_logo = self::getCustomLogo( $item['domain'] ) ) {
|
454 |
+
return $custom_logo;
|
455 |
+
}
|
456 |
+
}
|
457 |
+
|
458 |
+
if ( ! empty( $item['domain'] ) ) {
|
459 |
+
$logo_file_name = $item['domain'];
|
460 |
+
} elseif ( ! empty( $item['logo'] ) ) {
|
461 |
+
$logo_file_name = md5( $item['logo'] );
|
462 |
+
} else {
|
463 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
464 |
+
}
|
465 |
+
|
466 |
+
$logo_file_name = str_replace( '.', '-', $logo_file_name );
|
467 |
+
$logo_file_name .= '.' . $default_ext;
|
468 |
+
$logo_file_name = $prefix . $logo_file_name;
|
469 |
+
|
470 |
+
// check in distrib
|
471 |
+
if ( file_exists( \ContentEgg\PLUGIN_PATH . 'res/logos/' . $logo_file_name ) ) {
|
472 |
+
return \ContentEgg\PLUGIN_RES . '/logos/' . $logo_file_name;
|
473 |
+
}
|
474 |
+
|
475 |
+
$uploads = \wp_upload_dir();
|
476 |
+
if ( ! $logo_dir = self::getMerchantLogoDir() ) {
|
477 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
478 |
+
}
|
479 |
+
$logo_file = \trailingslashit( $logo_dir ) . $logo_file_name;
|
480 |
+
$logo_url = $uploads['baseurl'] . '/' . self::MERHANT_LOGO_DIR . '/' . $logo_file_name;
|
481 |
+
|
482 |
+
// logo exists
|
483 |
+
if ( file_exists( $logo_file ) ) {
|
484 |
+
return $logo_url;
|
485 |
+
}
|
486 |
+
|
487 |
+
// download
|
488 |
+
if ( ! $remote_url ) {
|
489 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
490 |
+
}
|
491 |
+
if ( $logo_file_name = ImageHelper::downloadImg( $remote_url, $logo_dir, $logo_file_name, '', true ) ) {
|
492 |
+
return $uploads['baseurl'] . '/' . self::MERHANT_LOGO_DIR . '/' . $logo_file_name;
|
493 |
+
} else {
|
494 |
+
// save blank to prevent new requests
|
495 |
+
copy( \ContentEgg\PLUGIN_PATH . 'res/img/blank.gif', $logo_file );
|
496 |
+
|
497 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
+
public static function getMerhantLogoUrl( array $item, $blank_on_error = false ) {
|
502 |
+
$prefix = '';
|
503 |
+
if ( ! empty( $item['module_id'] ) ) {
|
504 |
+
$parser = ModuleManager::getInstance()->parserFactory( $item['module_id'] );
|
505 |
+
if ( $parser->getConfigInstance()->option_exists( 'show_large_logos' ) && ! filter_var( $parser->config( 'show_large_logos' ), FILTER_VALIDATE_BOOLEAN ) ) {
|
506 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
507 |
+
}
|
508 |
+
}
|
509 |
+
|
510 |
+
if ( ! empty( $item['logo'] ) ) {
|
511 |
+
$remote_url = $item['logo'];
|
512 |
+
} elseif ( ! empty( $item['domain'] ) ) {
|
513 |
+
$item['domain'] = preg_replace( '/^https:\/\//', '', $item['domain'] );
|
514 |
+
$remote_url = 'https://logo.clearbit.com/' . urlencode( $item['domain'] ) . '?size=128';
|
515 |
+
} else {
|
516 |
+
$remote_url = '';
|
517 |
+
}
|
518 |
+
|
519 |
+
return self::getMerchantImageUrl( $item, $prefix, $remote_url, $blank_on_error );
|
520 |
+
}
|
521 |
+
|
522 |
+
public static function getMerhantIconUrl( array $item, $blank_on_error = false ) {
|
523 |
+
$prefix = 'icon_';
|
524 |
+
if ( ! empty( $item['module_id'] ) ) {
|
525 |
+
$parser = ModuleManager::getInstance()->parserFactory( $item['module_id'] );
|
526 |
+
if ( $parser->getConfigInstance()->option_exists( 'show_small_logos' ) && ! filter_var( $parser->config( 'show_small_logos' ), FILTER_VALIDATE_BOOLEAN ) ) {
|
527 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
528 |
+
}
|
529 |
+
}
|
530 |
+
|
531 |
+
$item['domain'] = preg_replace( '/^https:\/\//', '', $item['domain'] );
|
532 |
+
$remote_url = 'https://www.google.com/s2/favicons?domain=' . urlencode( $item['domain'] );
|
533 |
+
|
534 |
+
return self::getMerchantImageUrl( $item, $prefix, $remote_url, $blank_on_error );
|
535 |
+
}
|
536 |
+
|
537 |
+
public static function getMerchantName( array $item, $print = false ) {
|
538 |
+
return self::getMerhantName( $item, $print );
|
539 |
+
}
|
540 |
+
|
541 |
+
public static function getMerhantName( array $item, $print = false ) {
|
542 |
+
if ( ! empty( $item['domain'] ) ) {
|
543 |
+
$name = ucfirst( $item['domain'] );
|
544 |
+
|
545 |
+
if ( $name == 'Aliexpress.com' ) {
|
546 |
+
$name = 'Aliexpress';
|
547 |
+
} elseif ( $name == 'Flipkart.com' ) {
|
548 |
+
$name = 'Flipkart';
|
549 |
+
} elseif ( $name == 'Ebay.com' ) {
|
550 |
+
$name = 'eBay';
|
551 |
+
} //it's should be ONLY "eBay" without ".com"
|
552 |
+
elseif ( strstr( $name, 'Ebay.' ) ) {
|
553 |
+
$name = $name = 'eBay';
|
554 |
+
}
|
555 |
+
} elseif ( ! empty( $item['merchant'] ) ) {
|
556 |
+
$name = $item['merchant'];
|
557 |
+
} else {
|
558 |
+
$name = '';
|
559 |
+
}
|
560 |
+
|
561 |
+
if ( $print ) {
|
562 |
+
echo \esc_html( $name );
|
563 |
+
} else {
|
564 |
+
return $name;
|
565 |
+
}
|
566 |
+
}
|
567 |
+
|
568 |
+
public static function getMerchantLogoDir() {
|
569 |
+
$uploads = \wp_upload_dir();
|
570 |
+
$logo_dir = \trailingslashit( $uploads['basedir'] ) . self::MERHANT_LOGO_DIR;
|
571 |
+
if ( is_dir( $logo_dir ) ) {
|
572 |
+
return $logo_dir;
|
573 |
+
}
|
574 |
+
|
575 |
+
if ( \wp_mkdir_p( $logo_dir ) ) {
|
576 |
+
return $logo_dir;
|
577 |
+
} else {
|
578 |
+
return false;
|
579 |
+
}
|
580 |
+
}
|
581 |
+
|
582 |
+
public static function getBlankImg() {
|
583 |
+
return \ContentEgg\PLUGIN_RES . '/img/blank.gif';
|
584 |
+
}
|
585 |
+
|
586 |
+
public static function mergeData( array $data ) {
|
587 |
+
foreach ( $data as $module_id => $items ) {
|
588 |
+
foreach ( $items as $item_ar ) {
|
589 |
+
$item_ar['module_id'] = $module_id;
|
590 |
+
$all_items[] = $item_ar;
|
591 |
+
}
|
592 |
+
}
|
593 |
+
|
594 |
+
return $all_items;
|
595 |
+
}
|
596 |
+
|
597 |
+
public static function getMaxPriceItem( array $data ) {
|
598 |
+
return $data[ ArrayHelper::getMaxKeyAssoc( $data, 'price', true ) ];
|
599 |
+
}
|
600 |
+
|
601 |
+
public static function getMinPriceItem( array $data ) {
|
602 |
+
return $data[ ArrayHelper::getMinKeyAssoc( $data, 'price', true ) ];
|
603 |
+
}
|
604 |
+
|
605 |
+
public static function getCommonCurrencyCode( $data ) {
|
606 |
+
$first = reset( $data );
|
607 |
+
$currency = $first['currencyCode'];
|
608 |
+
foreach ( $data as $d ) {
|
609 |
+
if ( ! empty( $d['currencyCode'] ) && $d['currencyCode'] != $currency ) {
|
610 |
+
return false;
|
611 |
+
}
|
612 |
+
}
|
613 |
+
|
614 |
+
return $currency;
|
615 |
+
}
|
616 |
+
|
617 |
+
public static function getShopsList( $data ) {
|
618 |
+
$list = array();
|
619 |
+
foreach ( $data as $d ) {
|
620 |
+
if ( ! isset( $list[ $d['domain'] ] ) ) {
|
621 |
+
if ( ! empty( $d['merchant'] ) ) {
|
622 |
+
$list[ $d['domain'] ] = $d['merchant'];
|
623 |
+
} else {
|
624 |
+
$list[ $d['domain'] ] = self::getNameFromDomain( $d['domain'] );
|
625 |
+
}
|
626 |
+
}
|
627 |
+
}
|
628 |
+
|
629 |
+
return $list;
|
630 |
+
}
|
631 |
+
|
632 |
+
public static function getNameFromDomain( $domain ) {
|
633 |
+
$parts = explode( '.', $domain );
|
634 |
+
$merchant = $parts[0];
|
635 |
+
if ( $merchant == 'ebay' ) {
|
636 |
+
return 'eBay';
|
637 |
+
}
|
638 |
+
|
639 |
+
return ucfirst( $merchant );
|
640 |
+
}
|
641 |
+
|
642 |
+
public static function sortByPrice( array $data, $order = 'asc', $field = 'price' ) {
|
643 |
+
if ( ! in_array( $order, array( 'asc', 'desc' ) ) ) {
|
644 |
+
$order = 'asc';
|
645 |
+
}
|
646 |
+
|
647 |
+
if ( ! in_array( $field, array( 'price', 'discount' ) ) ) {
|
648 |
+
$field = 'price';
|
649 |
+
}
|
650 |
+
|
651 |
+
// convert all prices to one currency
|
652 |
+
$currency_codes = array();
|
653 |
+
foreach ( $data as $d ) {
|
654 |
+
if ( empty( $d['currencyCode'] ) ) {
|
655 |
+
continue;
|
656 |
+
}
|
657 |
+
|
658 |
+
if ( ! isset( $currency_codes[ $d['currencyCode'] ] ) ) {
|
659 |
+
$currency_codes[ $d['currencyCode'] ] = 1;
|
660 |
+
} else {
|
661 |
+
$currency_codes[ $d['currencyCode'] ] ++;
|
662 |
+
}
|
663 |
+
}
|
664 |
+
arsort( $currency_codes );
|
665 |
+
$base_currency = key( $currency_codes );
|
666 |
+
foreach ( $data as $key => $d ) {
|
667 |
+
$rate = 1;
|
668 |
+
if ( ! empty( $d['currencyCode'] ) && $d['currencyCode'] != $base_currency ) {
|
669 |
+
$rate = CurrencyHelper::getCurrencyRate( $d['currencyCode'], $base_currency );
|
670 |
+
}
|
671 |
+
if ( ! $rate ) {
|
672 |
+
$rate = 1;
|
673 |
+
}
|
674 |
+
|
675 |
+
if ( isset( $d['price'] ) ) {
|
676 |
+
if ( $field == 'discount' ) {
|
677 |
+
if ( ! empty( $d['priceOld'] ) ) {
|
678 |
+
$data[ $key ]['converted_price'] = (float) ( $d['priceOld'] - $d['price'] ) * $rate;
|
679 |
+
} else {
|
680 |
+
$data[ $key ]['converted_price'] = 0.00001;
|
681 |
+
}
|
682 |
+
} else {
|
683 |
+
$data[ $key ]['converted_price'] = (float) $d['price'] * $rate;
|
684 |
+
}
|
685 |
+
} else {
|
686 |
+
$data[ $key ]['converted_price'] = 0;
|
687 |
+
$data[ $key ]['price'] = 0;
|
688 |
+
if ( $field == 'discount' ) {
|
689 |
+
$data[ $key ]['converted_price'] = 99999999999;
|
690 |
+
}
|
691 |
+
}
|
692 |
+
if ( isset( $d['stock_status'] ) && $d['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
693 |
+
if ( $field == 'discount' ) {
|
694 |
+
$data[ $key ]['converted_price'] = - 1;
|
695 |
+
} else {
|
696 |
+
$data[ $key ]['converted_price'] = 0;
|
697 |
+
}
|
698 |
+
}
|
699 |
+
}
|
700 |
+
|
701 |
+
// modules priority
|
702 |
+
$modules_priority = array();
|
703 |
+
foreach ( $data as $d ) {
|
704 |
+
$module_id = $d['module_id'];
|
705 |
+
|
706 |
+
if ( isset( $modules_priority[ $module_id ] ) ) {
|
707 |
+
continue;
|
708 |
+
}
|
709 |
+
if ( ! ModuleManager::getInstance()->moduleExists( $module_id ) ) {
|
710 |
+
continue;
|
711 |
+
}
|
712 |
+
|
713 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
714 |
+
$modules_priority[ $module_id ] = (int) $module->config( 'priority' );
|
715 |
+
}
|
716 |
+
|
717 |
+
// sort by price and priority
|
718 |
+
usort( $data, function ( $a, $b ) use ( $modules_priority ) {
|
719 |
+
|
720 |
+
if ( ! $a['price'] && ! $b['price'] ) {
|
721 |
+
return $modules_priority[ $a['module_id'] ] - $modules_priority[ $b['module_id'] ];
|
722 |
+
}
|
723 |
+
|
724 |
+
if ( ! $a['converted_price'] ) {
|
725 |
+
return 1;
|
726 |
+
}
|
727 |
+
|
728 |
+
if ( ! $b['converted_price'] ) {
|
729 |
+
return - 1;
|
730 |
+
}
|
731 |
+
|
732 |
+
if ( $a['converted_price'] == $b['converted_price'] ) {
|
733 |
+
return $modules_priority[ $a['module_id'] ] - $modules_priority[ $b['module_id'] ];
|
734 |
+
}
|
735 |
+
|
736 |
+
if ( $modules_priority[ $a['module_id'] ] != $modules_priority[ $b['module_id'] ] ) {
|
737 |
+
if ( $a['converted_price'] >= 30 && $b['converted_price'] >= 30 && abs( $a['converted_price'] - $b['converted_price'] ) < 1 ) {
|
738 |
+
return $modules_priority[ $a['module_id'] ] - $modules_priority[ $b['module_id'] ];
|
739 |
+
}
|
740 |
+
}
|
741 |
+
|
742 |
+
return ( $a['converted_price'] < $b['converted_price'] ) ? - 1 : 1;
|
743 |
+
} );
|
744 |
+
|
745 |
+
if ( $order == 'desc' ) {
|
746 |
+
$data = array_reverse( $data );
|
747 |
+
}
|
748 |
+
|
749 |
+
return $data;
|
750 |
+
}
|
751 |
+
|
752 |
+
public static function sortAllByPrice( array $data, $order = 'asc', $field = 'price' ) {
|
753 |
+
return TemplateHelper::sortByPrice( self::mergeAll( $data ), $order, $field );
|
754 |
+
}
|
755 |
+
|
756 |
+
public static function mergeAll( array $data ) {
|
757 |
+
$all_items = array();
|
758 |
+
foreach ( $data as $module_id => $items ) {
|
759 |
+
foreach ( $items as $item_ar ) {
|
760 |
+
$item_ar['module_id'] = $module_id;
|
761 |
+
$all_items[] = $item_ar;
|
762 |
+
}
|
763 |
+
}
|
764 |
+
|
765 |
+
return $all_items;
|
766 |
+
}
|
767 |
+
|
768 |
+
public static function buyNowBtnText( $print = true, array $item = array(), $forced_text = '' ) {
|
769 |
+
return self::btnText( 'btn_text_buy_now', __( 'BUY NOW', 'content-egg-tpl' ), $print, $item, $forced_text );
|
770 |
+
}
|
771 |
+
|
772 |
+
public static function couponBtnText( $print = true, array $item = array(), $forced_text = '' ) {
|
773 |
+
return self::btnText( 'btn_text_coupon', __( 'Shop Sale', 'content-egg-tpl' ), $print, $item, $forced_text );
|
774 |
+
}
|
775 |
+
|
776 |
+
public static function getCurrentUserEmail() {
|
777 |
+
if ( ! $current_user = wp_get_current_user() ) {
|
778 |
+
return '';
|
779 |
+
}
|
780 |
+
|
781 |
+
return $current_user->user_email;
|
782 |
+
}
|
783 |
+
|
784 |
+
public static function getDaysAgo( $ptime ) {
|
785 |
+
$etime = current_time( 'timestamp' ) - $ptime;
|
786 |
+
if ( $etime < 1 ) {
|
787 |
+
return '';
|
788 |
+
}
|
789 |
+
$d = $etime / ( 24 * 60 * 60 );
|
790 |
+
|
791 |
+
if ( $d < 1 ) {
|
792 |
+
return Translator::__( 'today' );
|
793 |
+
}
|
794 |
+
$d = ceil( $d );
|
795 |
+
|
796 |
+
if ( $d > 1 ) {
|
797 |
+
return sprintf( Translator::__( '%d days ago' ), $d );
|
798 |
+
} else {
|
799 |
+
return sprintf( Translator::__( '%d day ago' ), $d );
|
800 |
+
}
|
801 |
+
}
|
802 |
+
|
803 |
+
public static function getAmazonDisclaimer() {
|
804 |
+
if ( $d = GeneralConfig::getInstance()->option( 'disclaimer_text' ) ) {
|
805 |
+
return $d;
|
806 |
+
} else {
|
807 |
+
return __( 'As an Amazon associate I earn from qualifying purchases.', 'content-egg-tpl' ) . ' ' . __( 'Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply to the purchase of this product.', 'content-egg-tpl' );
|
808 |
+
}
|
809 |
+
}
|
810 |
+
|
811 |
+
public static function printAmazonDisclaimer() {
|
812 |
+
echo '<i class="egg-ico-info-circle cegg-disclaimer" ' . self::buildTagParams( array( 'title' => self::getAmazonDisclaimer() ) ) . '></i>'; // phpcs:ignore
|
813 |
+
}
|
814 |
+
|
815 |
+
public static function btnText( $option_name, $default, $print = true, array $item = array(), $forced_text = '' ) {
|
816 |
+
if ( $forced_text ) {
|
817 |
+
$text = $forced_text;
|
818 |
+
} else {
|
819 |
+
$text = GeneralConfig::getInstance()->option( $option_name );
|
820 |
+
if ( ! $text ) {
|
821 |
+
$text = $default;
|
822 |
+
}
|
823 |
+
}
|
824 |
+
|
825 |
+
$text = self::replacePatterns( $text, $item );
|
826 |
+
|
827 |
+
if ( ! $print ) {
|
828 |
+
return $text;
|
829 |
+
}
|
830 |
+
|
831 |
+
echo \esc_attr($text);
|
832 |
+
}
|
833 |
+
|
834 |
+
private static function replacePatterns( $template, array $item ) {
|
835 |
+
if ( ! $item ) {
|
836 |
+
return $template;
|
837 |
+
}
|
838 |
+
if ( ! preg_match_all( '/%[a-zA-Z0-9_\.\,\(\)]+%/', $template, $matches ) ) {
|
839 |
+
return $template;
|
840 |
+
}
|
841 |
+
|
842 |
+
$replace = array();
|
843 |
+
foreach ( $matches[0] as $pattern ) {
|
844 |
+
if ( stristr( $pattern, '%PRICE%' ) ) {
|
845 |
+
if ( ! empty( $item['price'] ) && $item['currencyCode'] ) {
|
846 |
+
$replace[ $pattern ] = TemplateHelper::formatPriceCurrency( $item['price'], $item['currencyCode'] );
|
847 |
+
} else {
|
848 |
+
$replace[ $pattern ] = '';
|
849 |
+
}
|
850 |
+
continue;
|
851 |
+
}
|
852 |
+
if ( stristr( $pattern, '%MERCHANT%' ) ) {
|
853 |
+
if ( $merchant = TemplateHelper::getMerhantName( $item ) ) {
|
854 |
+
$replace[ $pattern ] = $merchant;
|
855 |
+
} else {
|
856 |
+
$replace[ $pattern ] = '';
|
857 |
+
}
|
858 |
+
continue;
|
859 |
+
}
|
860 |
+
if ( stristr( $pattern, '%DOMAIN%' ) ) {
|
861 |
+
if ( ! empty( $item['domain'] ) ) {
|
862 |
+
$replace[ $pattern ] = $item['domain'];
|
863 |
+
} else {
|
864 |
+
$replace[ $pattern ] = TemplateHelper::getMerhantName( $item );
|
865 |
+
}
|
866 |
+
continue;
|
867 |
+
}
|
868 |
+
if ( stristr( $pattern, '%STOCK_STATUS%' ) ) {
|
869 |
+
$replace[ $pattern ] = TemplateHelper::getStockStatusStr( $item );
|
870 |
+
continue;
|
871 |
+
}
|
872 |
+
}
|
873 |
+
|
874 |
+
return str_ireplace( array_keys( $replace ), array_values( $replace ), $template );
|
875 |
+
}
|
876 |
+
|
877 |
+
public static function getStockStatusClass( array $item ) {
|
878 |
+
if ( ! isset( $item['stock_status'] ) ) {
|
879 |
+
return '';
|
880 |
+
}
|
881 |
+
|
882 |
+
if ( $item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK ) {
|
883 |
+
return 'instock';
|
884 |
+
} elseif ( $item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
885 |
+
return 'outofstock';
|
886 |
+
} elseif ( $item['stock_status'] == ContentProduct::STOCK_STATUS_UNKNOWN ) {
|
887 |
+
return 'unknown';
|
888 |
+
} else {
|
889 |
+
return '';
|
890 |
+
}
|
891 |
+
}
|
892 |
+
|
893 |
+
public static function getStockStatusStr( array $item ) {
|
894 |
+
if ( ! isset( $item['stock_status'] ) ) {
|
895 |
+
return '';
|
896 |
+
}
|
897 |
+
|
898 |
+
$show_status = GeneralConfig::getInstance()->option( 'show_stock_status' );
|
899 |
+
if ( $show_status == 'hide_status' ) {
|
900 |
+
return '';
|
901 |
+
} elseif ( $show_status == 'show_outofstock' && $item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK ) {
|
902 |
+
return '';
|
903 |
+
} elseif ( $show_status == 'show_instock' && $item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
904 |
+
return '';
|
905 |
+
}
|
906 |
+
|
907 |
+
if ( $item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK ) {
|
908 |
+
return TemplateHelper::__( 'in stock' );
|
909 |
+
} elseif ( $item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK ) {
|
910 |
+
return TemplateHelper::__( 'out of stock' );
|
911 |
+
} else {
|
912 |
+
return '';
|
913 |
+
}
|
914 |
+
}
|
915 |
+
|
916 |
+
public static function getPrivacyUrl() {
|
917 |
+
if ( $id = \get_option( 'wp_page_for_privacy_policy', '' ) ) {
|
918 |
+
return \get_permalink( $id );
|
919 |
+
} else {
|
920 |
+
return '';
|
921 |
+
}
|
922 |
+
}
|
923 |
+
|
924 |
+
public static function getGroupsList( array $all_items, $sort_groups = array() ) {
|
925 |
+
if ( ! isset( $all_items[0] ) ) {
|
926 |
+
$all_items = TemplateHelper::sortAllByPrice( $all_items );
|
927 |
+
}
|
928 |
+
|
929 |
+
$groups = array_unique( array_column( $all_items, 'group' ) );
|
930 |
+
$groups = array_filter( $groups );
|
931 |
+
$groups = array_values( $groups );
|
932 |
+
|
933 |
+
if ( $sort_groups ) {
|
934 |
+
$res = array();
|
935 |
+
foreach ( $sort_groups as $g ) {
|
936 |
+
if ( in_array( $g, $groups ) ) {
|
937 |
+
$res[] = $g;
|
938 |
+
}
|
939 |
+
}
|
940 |
+
|
941 |
+
return $res;
|
942 |
+
} else {
|
943 |
+
natsort( $groups );
|
944 |
+
|
945 |
+
return $groups;
|
946 |
+
}
|
947 |
+
}
|
948 |
+
|
949 |
+
public static function filterByGroup( array $data, $group ) {
|
950 |
+
$res = array();
|
951 |
+
foreach ( $data as $plugin_id => $d ) {
|
952 |
+
$r = array_filter( $d, function ( $data ) use ( $group ) {
|
953 |
+
return isset( $data ) && $data['group'] == $group;
|
954 |
+
} );
|
955 |
+
if ( $r ) {
|
956 |
+
$res[ $plugin_id ] = $r;
|
957 |
+
}
|
958 |
+
}
|
959 |
+
|
960 |
+
return $res;
|
961 |
+
}
|
962 |
+
|
963 |
+
public static function generateGlobalId( $prefix ) {
|
964 |
+
return $prefix . self::$global_id ++;
|
965 |
+
}
|
966 |
+
|
967 |
+
public static function isModuleDataExist( $items, $module_id ) {
|
968 |
+
foreach ( $items as $item ) {
|
969 |
+
if ( isset( $item['module_id'] ) && $item['module_id'] == $module_id ) {
|
970 |
+
return true;
|
971 |
+
} else {
|
972 |
+
return false;
|
973 |
+
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
|
977 |
+
public static function isCashbackTrakerActive() {
|
978 |
+
if ( class_exists( '\CashbackTracker\application\Plugin' ) ) {
|
979 |
+
return true;
|
980 |
+
} else {
|
981 |
+
return false;
|
982 |
+
}
|
983 |
+
}
|
984 |
+
|
985 |
+
public static function getCashbackStr( array $product ) {
|
986 |
+
if ( GeneralConfig::getInstance()->option( 'cashback_integration' ) != 'enabled' ) {
|
987 |
+
return '';
|
988 |
+
}
|
989 |
+
|
990 |
+
if ( ! self::isCashbackTrakerActive() ) {
|
991 |
+
return '';
|
992 |
+
}
|
993 |
+
|
994 |
+
return \CashbackTracker\application\components\DeeplinkGenerator::getCashbackStrByUrl( $product['url'] );
|
995 |
+
}
|
996 |
+
|
997 |
+
public static function hideParamPrepare( $hide ) {
|
998 |
+
if ( ! $hide ) {
|
999 |
+
return array();
|
1000 |
+
}
|
1001 |
+
|
1002 |
+
$allowed_hide = array(
|
1003 |
+
'price',
|
1004 |
+
'priceOld',
|
1005 |
+
'domain',
|
1006 |
+
'rating',
|
1007 |
+
'title',
|
1008 |
+
'stock_status',
|
1009 |
+
'img',
|
1010 |
+
'merchant',
|
1011 |
+
'description'
|
1012 |
+
);
|
1013 |
+
$hide = TextHelper::getArrayFromCommaList( $hide );
|
1014 |
+
if ( in_array( 'price', $hide ) && ! in_array( 'priceOld', $hide ) ) {
|
1015 |
+
$hide[] = 'priceOld';
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
return array_intersect( $hide, $allowed_hide );
|
1019 |
+
}
|
1020 |
+
|
1021 |
+
public static function printRel( $echo = true ) {
|
1022 |
+
if ( ! $rel = self::getRelValue() ) {
|
1023 |
+
return;
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
$res = ' rel="' . \esc_attr( $rel ) . '"';
|
1027 |
+
if ( $echo ) {
|
1028 |
+
echo $res; // phpcs:ignore
|
1029 |
+
} else {
|
1030 |
+
return $res;
|
1031 |
+
}
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
public static function getRelValue() {
|
1035 |
+
$rel = GeneralConfig::getInstance()->option( 'rel_attribute' );
|
1036 |
+
|
1037 |
+
return join( ' ', $rel );
|
1038 |
+
}
|
1039 |
+
|
1040 |
+
public static function printRating( array $item, $size = 'default' ) {
|
1041 |
+
if ( ! $item['rating'] ) {
|
1042 |
+
return;
|
1043 |
+
}
|
1044 |
+
if ( ! in_array( $size, array( 'small', 'big', 'default' ) ) ) {
|
1045 |
+
$size = 'default';
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
$rating = $item['rating'] * 20;
|
1049 |
+
echo '<span class="egg-stars-container egg-stars-' . esc_attr($size) . ' egg-stars-' . esc_attr($rating) . '">★★★★★</span>';
|
1050 |
+
}
|
1051 |
+
|
1052 |
+
public static function getButtonColor() {
|
1053 |
+
if ( ! $color = \wp_strip_all_tags( GeneralConfig::getInstance()->option( 'button_color' ) ) ) {
|
1054 |
+
$color = '#d9534f';
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
return $color;
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
public static function getPriceColor() {
|
1061 |
+
if ( ! $color = \wp_strip_all_tags( GeneralConfig::getInstance()->option( 'price_color' ) ) ) {
|
1062 |
+
$color = '#dc3545';
|
1063 |
+
}
|
1064 |
+
|
1065 |
+
return $color;
|
1066 |
+
}
|
1067 |
+
|
1068 |
+
public static function getButtonColorHower() {
|
1069 |
+
return TemplateHelper::adjustBrightness( TemplateHelper::getButtonColor(), - 0.15 );
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
public static function adjustBrightness( $hexCode, $adjustPercent ) {
|
1073 |
+
$hexCode = ltrim( $hexCode, '#' );
|
1074 |
+
|
1075 |
+
if ( strlen( $hexCode ) == 3 ) {
|
1076 |
+
$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
$hexCode = array_map( 'hexdec', str_split( $hexCode, 2 ) );
|
1080 |
+
|
1081 |
+
foreach ( $hexCode as & $color ) {
|
1082 |
+
$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
|
1083 |
+
$adjustAmount = ceil( $adjustableLimit * $adjustPercent );
|
1084 |
+
|
1085 |
+
$color = str_pad( dechex( $color + $adjustAmount ), 2, '0', STR_PAD_LEFT );
|
1086 |
+
}
|
1087 |
+
|
1088 |
+
return '#' . implode( $hexCode );
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
public static function findAmazonLocales( array $items ) {
|
1092 |
+
$locales = array();
|
1093 |
+
foreach ( $items as $item ) {
|
1094 |
+
if ( ! isset( $item['extra']['locale'] ) ) {
|
1095 |
+
continue;
|
1096 |
+
}
|
1097 |
+
if ( ! in_array( $item['extra']['locale'], $locales ) ) {
|
1098 |
+
$locales[] = $item['extra']['locale'];
|
1099 |
+
}
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
return $locales;
|
1103 |
+
}
|
1104 |
+
|
1105 |
+
/*
|
1106 |
+
* @link: https://webservices.amazon.com/paapi5/documentation/add-to-cart-form.html
|
1107 |
+
*/
|
1108 |
+
|
1109 |
+
public static function generateAddAllToCartUrl( array $items, $locale ) {
|
1110 |
+
$url = 'https://www.' . AmazonLocales::getDomain( $locale ) . '/gp/aws/cart/add.html?';
|
1111 |
+
|
1112 |
+
$i = 1;
|
1113 |
+
foreach ( $items as $item ) {
|
1114 |
+
if ( ! isset( $item['extra']['locale'] ) || $item['extra']['locale'] != $locale ) {
|
1115 |
+
continue;
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
if ( $i > 1 ) {
|
1119 |
+
$url .= '&';
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
$url .= 'ASIN.' . $i . '=' . $item['extra']['ASIN'] . '&Quantity.' . $i . '=1';
|
1123 |
+
$i ++;
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
$url .= '&AssociateTag=' . self::getAssociateTagForAmazonLocale( $locale, $item['module_id'] );
|
1127 |
+
|
1128 |
+
return $url;
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
public static function getAssociateTagForAmazonLocale( $locale, $module_id = 'Amazon' ) {
|
1132 |
+
if ( $module_id == 'AmazonNoApi' ) {
|
1133 |
+
$module = ModuleManager::factory( 'AmazonNoApi' );
|
1134 |
+
} else {
|
1135 |
+
$module = ModuleManager::factory( 'Amazon' );
|
1136 |
+
}
|
1137 |
+
|
1138 |
+
return $module->getAssociateTagForLocale( $locale );
|
1139 |
+
}
|
1140 |
+
|
1141 |
+
public static function __( $str ) {
|
1142 |
+
return Translator::translate( $str );
|
1143 |
+
}
|
1144 |
+
|
1145 |
+
public static function esc_html_e( $str ) {
|
1146 |
+
echo esc_html(Translator::translate( $str ));
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
public static function displayImage( array $item, $max_width, $max_height, array $params = array() ) {
|
1150 |
+
if ( ! isset( $item['img'] ) ) {
|
1151 |
+
return;
|
1152 |
+
}
|
1153 |
+
|
1154 |
+
$params['src'] = self::getOptimizedImage( $item, $max_width, $max_height );
|
1155 |
+
|
1156 |
+
if ( isset( $item['title'] ) ) {
|
1157 |
+
$params['alt'] = $item['title'];
|
1158 |
+
}
|
1159 |
+
|
1160 |
+
if ( $sizes = self::getImageSizesRatio( $item, $max_width, $max_height ) ) {
|
1161 |
+
$params = array_merge( $params, $sizes );
|
1162 |
+
}
|
1163 |
+
|
1164 |
+
echo '<img ' . self::buildTagParams( $params ) . ' />'; // phpcs:ignore
|
1165 |
+
}
|
1166 |
+
|
1167 |
+
public static function buildTagParams( $params = array() ) {
|
1168 |
+
$res = '';
|
1169 |
+
$i = 0;
|
1170 |
+
foreach ( $params as $key => $value ) {
|
1171 |
+
if ( $i > 0 ) {
|
1172 |
+
$res .= ' ';
|
1173 |
+
}
|
1174 |
+
$res .= \esc_attr( $key ) . '="' . \esc_attr( $value ) . '"';
|
1175 |
+
$i ++;
|
1176 |
+
}
|
1177 |
+
|
1178 |
+
return $res;
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
public static function getImageSizesRatio( array $item, $max_width, $max_height ) {
|
1182 |
+
if ( $item['module_id'] == 'Amazon' && strpos( $item['img'], 'https://m.media-amazon.com' ) !== false ) {
|
1183 |
+
if ( ! isset( $item['extra']['primaryImages'] ) ) {
|
1184 |
+
return array();
|
1185 |
+
}
|
1186 |
+
|
1187 |
+
$width = $item['extra']['primaryImages']['Large']['Width'];
|
1188 |
+
$height = $item['extra']['primaryImages']['Large']['Height'];
|
1189 |
+
|
1190 |
+
if ( ! $max_width ) {
|
1191 |
+
$max_width = $width;
|
1192 |
+
}
|
1193 |
+
if ( ! $max_height ) {
|
1194 |
+
$max_height = $height;
|
1195 |
+
}
|
1196 |
+
|
1197 |
+
$ratio = $width / $height;
|
1198 |
+
|
1199 |
+
if ( $ratio > 1 && $width > $max_width ) {
|
1200 |
+
return array( 'width' => round( $max_width ), 'height' => round( $max_width / $ratio ) );
|
1201 |
+
} else {
|
1202 |
+
return array( 'width' => round( $max_height * $ratio ), 'height' => round( $max_height ) );
|
1203 |
+
}
|
1204 |
+
}
|
1205 |
+
|
1206 |
+
return array();
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
public static function getOptimizedImage( array $item, $max_width, $max_height ) {
|
1210 |
+
|
1211 |
+
if ( $item['module_id'] == 'Amazon' && strpos( $item['img'], 'https://m.media-amazon.com' ) !== false ) {
|
1212 |
+
if ( ! isset( $item['extra']['primaryImages'] ) ) {
|
1213 |
+
return $item['img'];
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
if ( $max_height <= 160 ) {
|
1217 |
+
return $item['extra']['primaryImages']['Medium']['URL'];
|
1218 |
+
} elseif ( $max_height <= 75 ) {
|
1219 |
+
return $item['extra']['primaryImages']['Small']['URL'];
|
1220 |
+
} else {
|
1221 |
+
return $item['img'];
|
1222 |
+
}
|
1223 |
+
}
|
1224 |
+
|
1225 |
+
return $item['img'];
|
1226 |
+
}
|
1227 |
+
|
1228 |
+
public static function generateStaticRatings( $count, $post_id = null ) {
|
1229 |
+
if ( ! $post_id ) {
|
1230 |
+
global $post;
|
1231 |
+
if ( ! empty( $post->ID ) ) {
|
1232 |
+
$post_id = $post->ID;
|
1233 |
+
} else {
|
1234 |
+
$post_id = $count;
|
1235 |
+
}
|
1236 |
+
}
|
1237 |
+
|
1238 |
+
$ratings = array();
|
1239 |
+
mt_srand( $post_id );
|
1240 |
+
$rating = 10;
|
1241 |
+
for ( $i = 0; $i < $count; $i ++ ) {
|
1242 |
+
if ( $i <= 3 ) {
|
1243 |
+
$rand = mt_rand( 0, 6 ) / 10;
|
1244 |
+
} elseif ( $count > 9 && $i > 4 ) {
|
1245 |
+
$rand = mt_rand( 0, 3 ) / 10;
|
1246 |
+
} elseif ( $i > 8 ) {
|
1247 |
+
$rand = mt_rand( 0, 4 ) / 10;
|
1248 |
+
} else {
|
1249 |
+
$rand = mt_rand( 0, 10 ) / 10;
|
1250 |
+
}
|
1251 |
+
|
1252 |
+
$rating = round( $rating - $rand, 2 );
|
1253 |
+
$ratings[] = $rating;
|
1254 |
+
}
|
1255 |
+
|
1256 |
+
return $ratings;
|
1257 |
+
}
|
1258 |
+
|
1259 |
+
public static function printProgressRing( $value ) {
|
1260 |
+
if ( $value <= 0 ) {
|
1261 |
+
return;
|
1262 |
+
}
|
1263 |
+
|
1264 |
+
$p = round( $value * 100 / 10 );
|
1265 |
+
$r1 = round( $p * 314 / 100 );
|
1266 |
+
$r2 = 314 - $r1;
|
1267 |
+
|
1268 |
+
echo '<svg width="75" height="75" viewBox="0 0 120 120"><circle cx="60" cy="60" r="50" fill="none" stroke="#E1E1E1" stroke-width="12"/><circle cx="60" cy="60" r="50" transform="rotate(-90 60 60)" fill="none" stroke-dashoffset="314" stroke-dasharray="314" stroke="dodgerblue" stroke-width="12" ><animate attributeName="stroke-dasharray" dur="3s" values="0,314;' . esc_attr($r1) . ',' . esc_attr($r2) . '" fill="freeze" /></circle><text x="60" y="63" fill="black" text-anchor="middle" dy="7" font-size="27">' . esc_html($value) . '</text></svg>';
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
public static function getChance( $position, $max = 1 ) {
|
1272 |
+
global $post;
|
1273 |
+
if ( ! empty( $post->ID ) ) {
|
1274 |
+
$post_id = $post->ID;
|
1275 |
+
} else {
|
1276 |
+
$post_id = time();
|
1277 |
+
}
|
1278 |
+
mt_srand( $post_id + $position );
|
1279 |
+
|
1280 |
+
return mt_rand( 0, 1 );
|
1281 |
+
}
|
1282 |
+
|
1283 |
+
public static function getShopInfo( array $item ) {
|
1284 |
+
if ( ! isset( $item['domain'] ) ) {
|
1285 |
+
return;
|
1286 |
+
}
|
1287 |
+
|
1288 |
+
$domain = $item['domain'];
|
1289 |
+
|
1290 |
+
if ( self::$shop_info === null ) {
|
1291 |
+
$merchants = GeneralConfig::getInstance()->option( 'merchants' );
|
1292 |
+
if ( ! $merchants ) {
|
1293 |
+
$merchants = array();
|
1294 |
+
}
|
1295 |
+
foreach ( $merchants as $merchant ) {
|
1296 |
+
self::$shop_info[ $merchant['name'] ] = $merchant['shop_info'];
|
1297 |
+
}
|
1298 |
+
}
|
1299 |
+
|
1300 |
+
if ( isset( self::$shop_info[ $domain ] ) ) {
|
1301 |
+
return self::$shop_info[ $domain ];
|
1302 |
+
} else {
|
1303 |
+
return '';
|
1304 |
+
}
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
public static function printShopInfo( array $item, array $p = array() ) {
|
1308 |
+
if ( ! $shop_info = self::getShopInfo( $item ) ) {
|
1309 |
+
return;
|
1310 |
+
}
|
1311 |
+
|
1312 |
+
$params = array(
|
1313 |
+
'data-toggle' => 'cegg-popover',
|
1314 |
+
'data-html' => 'true',
|
1315 |
+
'data-placement' => 'left',
|
1316 |
+
'data-title' => self::getMerhantName( $item ),
|
1317 |
+
'data-content' => $shop_info,
|
1318 |
+
'tabindex' => '0',
|
1319 |
+
'data-trigger' => 'focus',
|
1320 |
+
);
|
1321 |
+
|
1322 |
+
$params = array_merge( $params, $p );
|
1323 |
+
|
1324 |
+
self::displayInfoIcon( $params );
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
public static function displayInfoIcon( $params = array() ) {
|
1328 |
+
echo '<i class="egg-ico-info-circle" ' . self::buildTagParams( $params ) . '></i>'; // phpcs:ignore
|
1329 |
+
}
|
1330 |
|
1331 |
}
|
application/helpers/TextHelper.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* TextHelper class file
|
@@ -13,686 +13,1210 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
class TextHelper {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
//$new_str = preg_replace_callback('/\{([^{}]*)\}/uim', array('TextHelper', 'get_random'), $str);
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
}
|
2 |
|
3 |
namespace ContentEgg\application\helpers;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* TextHelper class file
|
13 |
*/
|
14 |
class TextHelper {
|
15 |
|
16 |
+
public static function truncate( $string, $length = 80, $etc = '...', $charset = 'UTF-8', $break_words = false, $middle = false ) {
|
17 |
+
if ( $length == 0 ) {
|
18 |
+
return '';
|
19 |
+
}
|
20 |
+
|
21 |
+
if ( mb_strlen( $string, 'UTF-8' ) > $length ) {
|
22 |
+
$length -= min( $length, mb_strlen( $etc, 'UTF-8' ) );
|
23 |
+
if ( ! $break_words && ! $middle ) {
|
24 |
+
$string = preg_replace( '/\s+?(\S+)?$/', '', mb_substr( $string, 0, $length + 1, $charset ) );
|
25 |
+
}
|
26 |
+
if ( ! $middle ) {
|
27 |
+
return mb_substr( $string, 0, $length, $charset ) . $etc;
|
28 |
+
} else {
|
29 |
+
return mb_substr( $string, 0, $length / 2, $charset ) . $etc . mb_substr( $string, - $length / 2, $charset );
|
30 |
+
}
|
31 |
+
} else {
|
32 |
+
return $string;
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Truncates text.
|
38 |
+
* Modified version of cakephp truncate.
|
39 |
+
*
|
40 |
+
* Cuts a string to the length of $length and replaces the last characters
|
41 |
+
* with the ellipsis if the text is longer than length.
|
42 |
+
*
|
43 |
+
* ### Options:
|
44 |
+
*
|
45 |
+
* - `ellipsis` Will be used as Ending and appended to the trimmed string (`ending` is deprecated)
|
46 |
+
* - `exact` If false, $text will not be cut mid-word
|
47 |
+
* - `html` If true, HTML tags would be handled correctly
|
48 |
+
*
|
49 |
+
* @param string $text String to truncate.
|
50 |
+
* @param int $length Length of returned string, including ellipsis.
|
51 |
+
* @param array $options An array of html attributes and options.
|
52 |
+
*
|
53 |
+
* @return string Trimmed string.
|
54 |
+
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
|
55 |
+
*/
|
56 |
+
public static function truncateHtml( $text, $length = 100, $options = array() ) {
|
57 |
+
$defaults = array(
|
58 |
+
'ellipsis' => '...',
|
59 |
+
'exact' => false,
|
60 |
+
'html' => true
|
61 |
+
);
|
62 |
+
if ( isset( $options['ending'] ) ) {
|
63 |
+
$defaults['ellipsis'] = $options['ending'];
|
64 |
+
} elseif ( ! empty( $options['html'] ) ) {
|
65 |
+
$defaults['ellipsis'] = "\xe2\x80\xa6";
|
66 |
+
}
|
67 |
+
$options += $defaults;
|
68 |
+
extract( $options );
|
69 |
+
|
70 |
+
if ( ! function_exists( 'mb_strlen' ) ) {
|
71 |
+
class_exists( 'Multibyte' );
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( $html ) {
|
75 |
+
if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ), 'UTF-8' ) <= $length ) {
|
76 |
+
return $text;
|
77 |
+
}
|
78 |
+
$totalLength = mb_strlen( strip_tags( $ellipsis ), 'UTF-8' );
|
79 |
+
$openTags = array();
|
80 |
+
$truncate = '';
|
81 |
+
|
82 |
+
preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER );
|
83 |
+
foreach ( $tags as $tag ) {
|
84 |
+
if ( ! preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) {
|
85 |
+
if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) {
|
86 |
+
array_unshift( $openTags, $tag[2] );
|
87 |
+
} elseif ( preg_match( '/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
|
88 |
+
$pos = array_search( $closeTag[1], $openTags );
|
89 |
+
if ( $pos !== false ) {
|
90 |
+
array_splice( $openTags, $pos, 1 );
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
94 |
+
$truncate .= $tag[1];
|
95 |
+
|
96 |
+
$contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ), 'UTF-8' );
|
97 |
+
if ( $contentLength + $totalLength > $length ) {
|
98 |
+
$left = $length - $totalLength;
|
99 |
+
$entitiesLength = 0;
|
100 |
+
if ( preg_match_all( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE ) ) {
|
101 |
+
foreach ( $entities[0] as $entity ) {
|
102 |
+
if ( $entity[1] + 1 - $entitiesLength <= $left ) {
|
103 |
+
$left --;
|
104 |
+
$entitiesLength += mb_strlen( $entity[0], 'UTF-8' );
|
105 |
+
} else {
|
106 |
+
break;
|
107 |
+
}
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
$truncate .= mb_substr( $tag[3], 0, $left + $entitiesLength, 'UTF-8' );
|
112 |
+
break;
|
113 |
+
} else {
|
114 |
+
$truncate .= $tag[3];
|
115 |
+
$totalLength += $contentLength;
|
116 |
+
}
|
117 |
+
if ( $totalLength >= $length ) {
|
118 |
+
break;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
} else {
|
122 |
+
if ( mb_strlen( $text, 'UTF-8' ) <= $length ) {
|
123 |
+
return $text;
|
124 |
+
}
|
125 |
+
$truncate = mb_substr( $text, 0, $length - mb_strlen( $ellipsis, 'UTF-8' ), 'UTF-8' );
|
126 |
+
}
|
127 |
+
if ( ! $exact ) {
|
128 |
+
$spacepos = mb_strrpos( $truncate, ' ', 0, 'UTF-8' );
|
129 |
+
if ( $html ) {
|
130 |
+
$truncateCheck = mb_substr( $truncate, 0, $spacepos, 'UTF-8' );
|
131 |
+
$lastOpenTag = mb_strrpos( $truncateCheck, '<', 0, 'UTF-8' );
|
132 |
+
$lastCloseTag = mb_strrpos( $truncateCheck, '>', 0, 'UTF-8' );
|
133 |
+
if ( $lastOpenTag > $lastCloseTag ) {
|
134 |
+
preg_match_all( '/<[\w]+[^>]*>/s', $truncate, $lastTagMatches );
|
135 |
+
$lastTag = array_pop( $lastTagMatches[0] );
|
136 |
+
$spacepos = mb_strrpos( $truncate, $lastTag, 0, 'UTF-8' ) + mb_strlen( $lastTag, 'UTF-8' );
|
137 |
+
}
|
138 |
+
$bits = mb_substr( $truncate, $spacepos, null, 'UTF-8' );
|
139 |
+
preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER );
|
140 |
+
if ( ! empty( $droppedTags ) ) {
|
141 |
+
if ( ! empty( $openTags ) ) {
|
142 |
+
foreach ( $droppedTags as $closingTag ) {
|
143 |
+
if ( ! in_array( $closingTag[1], $openTags ) ) {
|
144 |
+
array_unshift( $openTags, $closingTag[1] );
|
145 |
+
}
|
146 |
+
}
|
147 |
+
} else {
|
148 |
+
foreach ( $droppedTags as $closingTag ) {
|
149 |
+
$openTags[] = $closingTag[1];
|
150 |
+
}
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
$truncate = mb_substr( $truncate, 0, $spacepos, 'UTF-8' );
|
155 |
+
}
|
156 |
+
$truncate .= $ellipsis;
|
157 |
+
|
158 |
+
if ( $html ) {
|
159 |
+
foreach ( $openTags as $tag ) {
|
160 |
+
$truncate .= '</' . $tag . '>';
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
return $truncate;
|
165 |
+
}
|
166 |
+
|
167 |
+
static function rus2latin( $str ) {
|
168 |
+
$iso = array(
|
169 |
+
"Є" => "YE",
|
170 |
+
"І" => "I",
|
171 |
+
"Ѓ" => "G",
|
172 |
+
"і" => "i",
|
173 |
+
"№" => "#",
|
174 |
+
"є" => "ye",
|
175 |
+
"ѓ" => "g",
|
176 |
+
"А" => "A",
|
177 |
+
"Б" => "B",
|
178 |
+
"В" => "V",
|
179 |
+
"Г" => "G",
|
180 |
+
"Д" => "D",
|
181 |
+
"Е" => "E",
|
182 |
+
"Ё" => "YO",
|
183 |
+
"Ж" => "ZH",
|
184 |
+
"З" => "Z",
|
185 |
+
"И" => "I",
|
186 |
+
"Й" => "J",
|
187 |
+
"К" => "K",
|
188 |
+
"Л" => "L",
|
189 |
+
"М" => "M",
|
190 |
+
"Н" => "N",
|
191 |
+
"О" => "O",
|
192 |
+
"П" => "P",
|
193 |
+
"Р" => "R",
|
194 |
+
"С" => "S",
|
195 |
+
"Т" => "T",
|
196 |
+
"У" => "U",
|
197 |
+
"Ф" => "F",
|
198 |
+
"Х" => "X",
|
199 |
+
"Ц" => "C",
|
200 |
+
"Ч" => "CH",
|
201 |
+
"Ш" => "SH",
|
202 |
+
"Щ" => "SHH",
|
203 |
+
"Ъ" => "'",
|
204 |
+
"Ы" => "Y",
|
205 |
+
"Ь" => "",
|
206 |
+
"Э" => "E",
|
207 |
+
"Ю" => "YU",
|
208 |
+
"Я" => "YA",
|
209 |
+
"а" => "a",
|
210 |
+
"б" => "b",
|
211 |
+
"в" => "v",
|
212 |
+
"г" => "g",
|
213 |
+
"д" => "d",
|
214 |
+
"е" => "e",
|
215 |
+
"ё" => "yo",
|
216 |
+
"ж" => "zh",
|
217 |
+
"з" => "z",
|
218 |
+
"и" => "i",
|
219 |
+
"й" => "j",
|
220 |
+
"к" => "k",
|
221 |
+
"л" => "l",
|
222 |
+
"м" => "m",
|
223 |
+
"н" => "n",
|
224 |
+
"о" => "o",
|
225 |
+
"п" => "p",
|
226 |
+
"р" => "r",
|
227 |
+
"с" => "s",
|
228 |
+
"т" => "t",
|
229 |
+
"у" => "u",
|
230 |
+
"ф" => "f",
|
231 |
+
"х" => "x",
|
232 |
+
"ц" => "c",
|
233 |
+
"ч" => "ch",
|
234 |
+
"ш" => "sh",
|
235 |
+
"щ" => "shh",
|
236 |
+
"ъ" => "",
|
237 |
+
"ы" => "y",
|
238 |
+
"ь" => "",
|
239 |
+
"э" => "e",
|
240 |
+
"ю" => "yu",
|
241 |
+
"я" => "ya",
|
242 |
+
"'" => "",
|
243 |
+
"\"" => "",
|
244 |
+
" " => "-"
|
245 |
+
);
|
246 |
+
|
247 |
+
return strtr( $str, $iso );
|
248 |
+
}
|
249 |
+
|
250 |
+
public static function clear( $str ) {
|
251 |
+
return preg_replace( '/[^a-zA-Z0-9_]/', '', $str );
|
252 |
+
}
|
253 |
+
|
254 |
+
public static function clearId( $str ) {
|
255 |
+
return preg_replace( '/[^a-zA-Z0-9_\-~\.@]/', '', $str );
|
256 |
+
}
|
257 |
+
|
258 |
+
public static function clear_utf8( $str ) {
|
259 |
+
$str = str_replace( '/', ' ', $str );
|
260 |
+
$str = preg_replace( "/[^\pL\s\d\-\.\+_\,]+/ui", '', $str );
|
261 |
+
$str = preg_replace( "/\s+/ui", ' ', $str );
|
262 |
+
|
263 |
+
return $str;
|
264 |
+
}
|
265 |
+
|
266 |
+
private static function get_random( $matches ) {
|
267 |
+
$rand = array_rand( $split = explode( "|", $matches[1] ) );
|
268 |
+
|
269 |
+
return $split[ $rand ];
|
270 |
+
}
|
271 |
+
|
272 |
+
public static function spin( $str ) {
|
273 |
//$new_str = preg_replace_callback('/\{([^{}]*)\}/uim', array('TextHelper', 'get_random'), $str);
|
274 |
+
$new_str = preg_replace_callback(
|
275 |
+
'/\{([^{}]*)\}/uim', function ( $matches ) {
|
276 |
+
$rand = array_rand( $split = explode( "|", $matches[1] ) );
|
277 |
+
|
278 |
+
return $split[ $rand ];
|
279 |
+
}
|
280 |
+
, $str );
|
281 |
+
if ( $new_str !== $str ) {
|
282 |
+
$str = TextHelper::spin( $new_str );
|
283 |
+
}
|
284 |
+
|
285 |
+
return $str;
|
286 |
+
}
|
287 |
+
|
288 |
+
/* bool/array unserialize_xml ( string $input [ , callback $callback ] )
|
289 |
+
* Unserializes an XML string, returning a multi-dimensional associative array, optionally runs a callback on all non-array data
|
290 |
+
* Returns false on all failure
|
291 |
+
* Notes:
|
292 |
+
* Root XML tags are stripped
|
293 |
+
* Due to its recursive nature, unserialize_xml() will also support SimpleXMLElement objects and arrays as input
|
294 |
+
* Uses simplexml_load_string() for XML parsing, see SimpleXML documentation for more info
|
295 |
+
*/
|
296 |
+
|
297 |
+
static public function unserialize_xml( $input, $callback = null, $recurse = false ) {
|
298 |
+
//Отключение ошибок libxml
|
299 |
+
libxml_use_internal_errors( false );
|
300 |
+
|
301 |
+
// Get input, loading an xml string with simplexml if its the top level of recursion
|
302 |
+
$data = ( ( ! $recurse ) && is_string( $input ) ) ? @simplexml_load_string( $input, '\SimpleXMLElement', LIBXML_NOCDATA ) : $input;
|
303 |
+
|
304 |
+
// Convert SimpleXMLElements to array
|
305 |
+
if ( $data instanceof \SimpleXMLElement ) {
|
306 |
+
$data = (array) $data;
|
307 |
+
}
|
308 |
+
|
309 |
+
// Recurse into arrays
|
310 |
+
if ( is_array( $data ) ) {
|
311 |
+
foreach ( $data as &$item ) {
|
312 |
+
$item = self::unserialize_xml( $item, $callback, true );
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
// Run callback and return
|
317 |
+
return ( ! is_array( $data ) && is_callable( $callback ) ) ? call_user_func( $callback, $data ) : $data;
|
318 |
+
}
|
319 |
+
|
320 |
+
static public function br2nl( $str ) {
|
321 |
+
return str_ireplace( array( "<br />", "<br>", "<br/>" ), "\r\n", $str );
|
322 |
+
}
|
323 |
+
|
324 |
+
static public function nl2br( $str ) {
|
325 |
+
return str_replace( array( "\r\n", "\r", "\n" ), "<br />", $str );
|
326 |
+
}
|
327 |
+
|
328 |
+
static public function removeExtraBreaks( $str ) {
|
329 |
+
return trim( preg_replace( "/(\r\n)+/i", "\r\n", $str ) );
|
330 |
+
}
|
331 |
+
|
332 |
+
static public function removeExtraBr( $str ) {
|
333 |
+
return preg_replace( '#<br[^>]*>(\s*<br[^>]*>)+#', '<br />', $str );
|
334 |
+
}
|
335 |
+
|
336 |
+
/**
|
337 |
+
* 10.55 -> 1055 & 1055 -> 10.55
|
338 |
+
*/
|
339 |
+
static public function pricePenniesDenomination( $p, $to_int = true ) {
|
340 |
+
if ( $to_int ) {
|
341 |
+
$p = (int) number_format( $p, 2, '', '' );
|
342 |
+
} else {
|
343 |
+
if ( strlen( $p ) == 2 ) // Under $1
|
344 |
+
{
|
345 |
+
$p = '00' . $p;
|
346 |
+
}
|
347 |
+
$p = number_format( preg_replace( "/(\d+)(\d{2}$)/msi", '${1}.${2}', $p ), 2, '.', '' );
|
348 |
+
}
|
349 |
+
|
350 |
+
return $p;
|
351 |
+
}
|
352 |
+
|
353 |
+
static public function currencyTyping( $c ) {
|
354 |
+
return TemplateHelper::currencyTyping( $c );
|
355 |
+
}
|
356 |
+
|
357 |
+
public static function safeHtml( $html, $type ) {
|
358 |
+
$allowed = array(
|
359 |
+
'p' => array(),
|
360 |
+
'h1' => array(),
|
361 |
+
'h2' => array(),
|
362 |
+
'h3' => array(),
|
363 |
+
'h4' => array(),
|
364 |
+
'h5' => array(),
|
365 |
+
'b' => array(),
|
366 |
+
'i' => array(),
|
367 |
+
'strong' => array(),
|
368 |
+
'em' => array(),
|
369 |
+
'ul' => array(),
|
370 |
+
'ol' => array(),
|
371 |
+
'li' => array(),
|
372 |
+
'br' => array(),
|
373 |
+
'hr' => array(),
|
374 |
+
'em' => array(),
|
375 |
+
'mark' => array(),
|
376 |
+
);
|
377 |
+
switch ( $type ) {
|
378 |
+
case 'allow_all':
|
379 |
+
return $html;
|
380 |
+
// Безопасный HTML
|
381 |
+
case 'safe_html':
|
382 |
+
return \wp_kses_post( $html );
|
383 |
+
// Разрешенные HTML теги
|
384 |
+
case 'allowed_tags':
|
385 |
+
return \wp_kses( $html, $allowed );
|
386 |
+
default:
|
387 |
+
// @todo: add safe strip_tags
|
388 |
+
return strip_tags( $html );
|
389 |
+
}
|
390 |
+
}
|
391 |
+
|
392 |
+
public static function commaList( $str, $input_delimer = ',', $return_delimer = ',' ) {
|
393 |
+
$parts = explode( $input_delimer, $str );
|
394 |
+
$parts = array_map( 'trim', $parts );
|
395 |
+
|
396 |
+
return join( $return_delimer, $parts );
|
397 |
+
}
|
398 |
+
|
399 |
+
public static function prepareKeywords( array $keywords ) {
|
400 |
+
$result = array();
|
401 |
+
foreach ( $keywords as $keyword ) {
|
402 |
+
$keyword = \sanitize_text_field( $keyword );
|
403 |
+
$keyword = trim( $keyword );
|
404 |
+
if ( ! $keyword ) {
|
405 |
+
continue;
|
406 |
+
}
|
407 |
+
$result[] = $keyword;
|
408 |
+
}
|
409 |
+
|
410 |
+
return $result;
|
411 |
+
}
|
412 |
+
|
413 |
+
public static function parsePriceAmount( $money ) {
|
414 |
+
if ( is_float( $money ) || is_int( $money ) ) {
|
415 |
+
return $money;
|
416 |
+
}
|
417 |
+
$cleanString = preg_replace( '/([^0-9\.,])/i', '', $money );
|
418 |
+
$onlyNumbersString = preg_replace( '/([^0-9])/i', '', $money );
|
419 |
+
|
420 |
+
$separatorsCountToBeErased = strlen( $cleanString ) - strlen( $onlyNumbersString ) - 1;
|
421 |
+
|
422 |
+
$stringWithCommaOrDot = preg_replace( '/([,\.])/', '', $cleanString, $separatorsCountToBeErased );
|
423 |
+
$removedThousendSeparator = preg_replace( '/(\.|,)(?=[0-9]{3,}$)/', '', $stringWithCommaOrDot );
|
424 |
+
|
425 |
+
return (float) str_replace( ',', '.', $removedThousendSeparator );
|
426 |
+
}
|
427 |
+
|
428 |
+
public static function parseCurrencyCode( $money ) {
|
429 |
+
$currencies = array(
|
430 |
+
'$' => 'USD',
|
431 |
+
'£' => 'GBP',
|
432 |
+
'EUR' => 'EUR',
|
433 |
+
'₹' => 'INR',
|
434 |
+
'Rs.' => 'INR',
|
435 |
+
'€' => 'EUR',
|
436 |
+
'руб' => 'RUR',
|
437 |
+
'грн' => 'UAH'
|
438 |
+
);
|
439 |
+
foreach ( $currencies as $symbol => $code ) {
|
440 |
+
if ( strstr( $money, $symbol ) ) {
|
441 |
+
return $code;
|
442 |
+
}
|
443 |
+
}
|
444 |
+
|
445 |
+
return null;
|
446 |
+
}
|
447 |
+
|
448 |
+
public static function randomPassword( $len = 8 ) {
|
449 |
+
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
450 |
+
$pass = array();
|
451 |
+
$alphaLength = strlen( $alphabet ) - 1;
|
452 |
+
for ( $i = 0; $i < $len; $i ++ ) {
|
453 |
+
$n = rand( 0, $alphaLength );
|
454 |
+
$pass[] = $alphabet[ $n ];
|
455 |
+
}
|
456 |
+
|
457 |
+
return implode( $pass );
|
458 |
+
}
|
459 |
+
|
460 |
+
public static function getHostName( $url ) {
|
461 |
+
$url = trim( $url );
|
462 |
+
|
463 |
+
return TextHelper::getDomainWithoutSubdomain( strtolower( str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) ) ) );
|
464 |
+
}
|
465 |
+
|
466 |
+
public static function isValidDomainName( $domain ) {
|
467 |
+
return preg_match( '/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $domain );
|
468 |
+
}
|
469 |
+
|
470 |
+
public static function findOriginalDomain( $url ) {
|
471 |
+
if ( ! $query = parse_url( $url, PHP_URL_QUERY ) ) {
|
472 |
+
return '';
|
473 |
+
}
|
474 |
+
parse_str( $query, $params );
|
475 |
+
foreach ( $params as $param ) {
|
476 |
+
if ( filter_var( $param, FILTER_VALIDATE_URL ) ) {
|
477 |
+
return TextHelper::getHostName( $param );
|
478 |
+
}
|
479 |
+
}
|
480 |
+
}
|
481 |
+
|
482 |
+
public static function parseOriginalUrl( $url, $go_param ) {
|
483 |
+
$url = html_entity_decode( $url );
|
484 |
+
if ( ! $query = parse_url( $url, PHP_URL_QUERY ) ) {
|
485 |
+
return '';
|
486 |
+
}
|
487 |
+
parse_str( $query, $arr );
|
488 |
+
if ( isset( $arr[ $go_param ] ) ) {
|
489 |
+
return $arr[ $go_param ];
|
490 |
+
} else {
|
491 |
+
return '';
|
492 |
+
}
|
493 |
+
}
|
494 |
+
|
495 |
+
public static function parseDomain( $url, $go_param ) {
|
496 |
+
if ( ! $url = TextHelper::parseOriginalUrl( $url, $go_param ) ) {
|
497 |
+
return '';
|
498 |
+
}
|
499 |
+
|
500 |
+
return TextHelper::getHostName( $url );
|
501 |
+
}
|
502 |
+
|
503 |
+
public static function getDomainWithoutSubdomain( $domain ) {
|
504 |
+
if ( preg_match( '/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,7})$/i', $domain, $regs ) ) {
|
505 |
+
return $regs['domain'];
|
506 |
+
}
|
507 |
+
|
508 |
+
return $domain;
|
509 |
+
}
|
510 |
+
|
511 |
+
public static function getRandomFromCommaList( $str ) {
|
512 |
+
$str = TextHelper::commaList( $str );
|
513 |
+
$arr = explode( ",", $str );
|
514 |
+
|
515 |
+
return $arr[ array_rand( $arr ) ];
|
516 |
+
}
|
517 |
+
|
518 |
+
public static function getArrayFromCommaList( $str ) {
|
519 |
+
return explode( ",", TextHelper::commaList( $str ) );
|
520 |
+
}
|
521 |
+
|
522 |
+
/**
|
523 |
+
* Verify a correct EAN13 structure
|
524 |
+
*/
|
525 |
+
public static function isEan( $barcode ) {
|
526 |
+
$barcode = self::fixEan( $barcode );
|
527 |
+
|
528 |
+
if ( ! preg_match( "/^[0-9]{13}$/", $barcode ) ) {
|
529 |
+
return false;
|
530 |
+
}
|
531 |
+
|
532 |
+
$digits = (string) $barcode;
|
533 |
+
$even_sum = $digits[1] + $digits[3] + $digits[5] +
|
534 |
+
$digits[7] + $digits[9] + $digits[11];
|
535 |
+
$even_sum_three = $even_sum * 3;
|
536 |
+
$odd_sum = $digits[0] + $digits[2] + $digits[4] +
|
537 |
+
$digits[6] + $digits[8] + $digits[10];
|
538 |
+
$total_sum = $even_sum_three + $odd_sum;
|
539 |
+
$next_ten = ( ceil( $total_sum / 10 ) ) * 10;
|
540 |
+
$check_digit = $next_ten - $total_sum;
|
541 |
+
if ( $check_digit == $digits[12] ) {
|
542 |
+
return true;
|
543 |
+
}
|
544 |
+
|
545 |
+
return false;
|
546 |
+
}
|
547 |
+
|
548 |
+
public static function fixEan( $barcode ) {
|
549 |
+
if ( strlen( $barcode == 13 ) ) {
|
550 |
+
return $barcode;
|
551 |
+
}
|
552 |
+
|
553 |
+
$barcode = ltrim( $barcode, '0' );
|
554 |
+
$barcode = str_pad( $barcode, 13, '0', STR_PAD_LEFT );
|
555 |
+
|
556 |
+
return $barcode;
|
557 |
+
}
|
558 |
+
|
559 |
+
/**
|
560 |
+
* Is valid amazon ASIN
|
561 |
+
*/
|
562 |
+
public static function isAsin( $str ) {
|
563 |
+
if ( preg_match( '/B[0-9]{2}[0-9A-Z]{7}|[0-9]{9}(X|0-9])|[0-9]{10}/', $str ) ) {
|
564 |
+
return true;
|
565 |
+
} else {
|
566 |
+
return false;
|
567 |
+
}
|
568 |
+
}
|
569 |
+
|
570 |
+
public static function splitAsins( $str ) {
|
571 |
+
$asins = explode( ',', TextHelper::commaList( $str, ' ', ',' ) );
|
572 |
+
$res = array();
|
573 |
+
foreach ( $asins as $asin ) {
|
574 |
+
if ( self::isAsin( $asin ) ) {
|
575 |
+
$res[] = $asin;
|
576 |
+
}
|
577 |
+
}
|
578 |
+
|
579 |
+
return $res;
|
580 |
+
}
|
581 |
+
|
582 |
+
public static function ratingPrepare( $rating, $min_rating = 1, $max_rating = 5 ) {
|
583 |
+
$rating = (float) $rating;
|
584 |
+
$rating = abs( round( $rating ) );
|
585 |
+
if ( $rating < $min_rating || $rating > $max_rating ) {
|
586 |
+
return null;
|
587 |
+
} else {
|
588 |
+
return $rating;
|
589 |
+
}
|
590 |
+
}
|
591 |
+
|
592 |
+
public static function sluggable( $string ) {
|
593 |
+
$cyrylicFrom = array(
|
594 |
+
'Є',
|
595 |
+
'І',
|
596 |
+
'Ѓ',
|
597 |
+
'і',
|
598 |
+
'є',
|
599 |
+
'ѓ',
|
600 |
+
'А',
|
601 |
+
'Б',
|
602 |
+
'В',
|
603 |
+
'Г',
|
604 |
+
'Д',
|
605 |
+
'Е',
|
606 |
+
'Ё',
|
607 |
+
'Ж',
|
608 |
+
'З',
|
609 |
+
'И',
|
610 |
+
'Й',
|
611 |
+
'К',
|
612 |
+
'Л',
|
613 |
+
'М',
|
614 |
+
'Н',
|
615 |
+
'О',
|
616 |
+
'П',
|
617 |
+
'Р',
|
618 |
+
'С',
|
619 |
+
'Т',
|
620 |
+
'У',
|
621 |
+
'Ф',
|
622 |
+
'Х',
|
623 |
+
'Ц',
|
624 |
+
'Ч',
|
625 |
+
'Ш',
|
626 |
+
'Щ',
|
627 |
+
'Ъ',
|
628 |
+
'Ы',
|
629 |
+
'Ь',
|
630 |
+
'Э',
|
631 |
+
'Ю',
|
632 |
+
'Я',
|
633 |
+
'а',
|
634 |
+
'б',
|
635 |
+
'в',
|
636 |
+
'г',
|
637 |
+
'д',
|
638 |
+
'е',
|
639 |
+
'ё',
|
640 |
+
'ж',
|
641 |
+
'з',
|
642 |
+
'и',
|
643 |
+
'й',
|
644 |
+
'к',
|
645 |
+
'л',
|
646 |
+
'м',
|
647 |
+
'н',
|
648 |
+
'о',
|
649 |
+
'п',
|
650 |
+
'р',
|
651 |
+
'с',
|
652 |
+
'т',
|
653 |
+
'у',
|
654 |
+
'ф',
|
655 |
+
'х',
|
656 |
+
'ц',
|
657 |
+
'ч',
|
658 |
+
'ш',
|
659 |
+
'щ',
|
660 |
+
'ъ',
|
661 |
+
'ы',
|
662 |
+
'ь',
|
663 |
+
'э',
|
664 |
+
'ю',
|
665 |
+
'я'
|
666 |
+
);
|
667 |
+
$cyrylicTo = array(
|
668 |
+
'YE',
|
669 |
+
'I',
|
670 |
+
'G',
|
671 |
+
'i',
|
672 |
+
'ye',
|
673 |
+
'g',
|
674 |
+
'A',
|
675 |
+
'B',
|
676 |
+
'V',
|
677 |
+
'G',
|
678 |
+
'D',
|
679 |
+
'E',
|
680 |
+
'YO',
|
681 |
+
'ZH',
|
682 |
+
'Z',
|
683 |
+
'I',
|
684 |
+
'J',
|
685 |
+
'K',
|
686 |
+
'L',
|
687 |
+
'M',
|
688 |
+
'N',
|
689 |
+
'O',
|
690 |
+
'P',
|
691 |
+
'R',
|
692 |
+
'S',
|
693 |
+
'T',
|
694 |
+
'U',
|
695 |
+
'F',
|
696 |
+
'X',
|
697 |
+
'C',
|
698 |
+
'CH',
|
699 |
+
'SH',
|
700 |
+
'SHH',
|
701 |
+
'',
|
702 |
+
'Y',
|
703 |
+
'',
|
704 |
+
'E',
|
705 |
+
'YU',
|
706 |
+
'YA',
|
707 |
+
'a',
|
708 |
+
'b',
|
709 |
+
'v',
|
710 |
+
'g',
|
711 |
+
'd',
|
712 |
+
'e',
|
713 |
+
'yo',
|
714 |
+
'zh',
|
715 |
+
'z',
|
716 |
+
'i',
|
717 |
+
'j',
|
718 |
+
'k',
|
719 |
+
'l',
|
720 |
+
'm',
|
721 |
+
'n',
|
722 |
+
'o',
|
723 |
+
'p',
|
724 |
+
'r',
|
725 |
+
's',
|
726 |
+
't',
|
727 |
+
'u',
|
728 |
+
'f',
|
729 |
+
'x',
|
730 |
+
'c',
|
731 |
+
'ch',
|
732 |
+
'sh',
|
733 |
+
'shh',
|
734 |
+
'',
|
735 |
+
'y',
|
736 |
+
'',
|
737 |
+
'e',
|
738 |
+
'yu',
|
739 |
+
'ya'
|
740 |
+
);
|
741 |
+
$from = array(
|
742 |
+
"Á",
|
743 |
+
"À",
|
744 |
+
"Â",
|
745 |
+
"Ä",
|
746 |
+
"Ă",
|
747 |
+
"Ā",
|
748 |
+
"Ã",
|
749 |
+
"Å",
|
750 |
+
"Ą",
|
751 |
+
"Æ",
|
752 |
+
"Ć",
|
753 |
+
"Ċ",
|
754 |
+
"Ĉ",
|
755 |
+
"Č",
|
756 |
+
"Ç",
|
757 |
+
"Ď",
|
758 |
+
"Đ",
|
759 |
+
"Ð",
|
760 |
+
"É",
|
761 |
+
"È",
|
762 |
+
"Ė",
|
763 |
+
"Ê",
|
764 |
+
"Ë",
|
765 |
+
"Ě",
|
766 |
+
"Ē",
|
767 |
+
"Ę",
|
768 |
+
"Ə",
|
769 |
+
"Ġ",
|
770 |
+
"Ĝ",
|
771 |
+
"Ğ",
|
772 |
+
"Ģ",
|
773 |
+
"á",
|
774 |
+
"à",
|
775 |
+
"â",
|
776 |
+
"ä",
|
777 |
+
"ă",
|
778 |
+
"ā",
|
779 |
+
"ã",
|
780 |
+
"å",
|
781 |
+
"ą",
|
782 |
+
"æ",
|
783 |
+
"ć",
|
784 |
+
"ċ",
|
785 |
+
"ĉ",
|
786 |
+
"č",
|
787 |
+
"ç",
|
788 |
+
"ď",
|
789 |
+
"đ",
|
790 |
+
"ð",
|
791 |
+
"é",
|
792 |
+
"è",
|
793 |
+
"ė",
|
794 |
+
"ê",
|
795 |
+
"ë",
|
796 |
+
"ě",
|
797 |
+
"ē",
|
798 |
+
"ę",
|
799 |
+
"ə",
|
800 |
+
"ġ",
|
801 |
+
"ĝ",
|
802 |
+
"ğ",
|
803 |
+
"ģ",
|
804 |
+
"Ĥ",
|
805 |
+
"Ħ",
|
806 |
+
"I",
|
807 |
+
"Í",
|
808 |
+
"Ì",
|
809 |
+
"İ",
|
810 |
+
"Î",
|
811 |
+
"Ï",
|
812 |
+
"Ī",
|
813 |
+
"Į",
|
814 |
+
"IJ",
|
815 |
+
"Ĵ",
|
816 |
+
"Ķ",
|
817 |
+
"Ļ",
|
818 |
+
"Ł",
|
819 |
+
"Ń",
|
820 |
+
"Ň",
|
821 |
+
"Ñ",
|
822 |
+
"Ņ",
|
823 |
+
"Ó",
|
824 |
+
"Ò",
|
825 |
+
"Ô",
|
826 |
+
"Ö",
|
827 |
+
"Õ",
|
828 |
+
"Ő",
|
829 |
+
"Ø",
|
830 |
+
"Ơ",
|
831 |
+
"Œ",
|
832 |
+
"ĥ",
|
833 |
+
"ħ",
|
834 |
+
"ı",
|
835 |
+
"í",
|
836 |
+
"ì",
|
837 |
+
"i",
|
838 |
+
"î",
|
839 |
+
"ï",
|
840 |
+
"ī",
|
841 |
+
"į",
|
842 |
+
"ij",
|
843 |
+
"ĵ",
|
844 |
+
"ķ",
|
845 |
+
"ļ",
|
846 |
+
"ł",
|
847 |
+
"ń",
|
848 |
+
"ň",
|
849 |
+
"ñ",
|
850 |
+
"ņ",
|
851 |
+
"ó",
|
852 |
+
"ò",
|
853 |
+
"ô",
|
854 |
+
"ö",
|
855 |
+
"õ",
|
856 |
+
"ő",
|
857 |
+
"ø",
|
858 |
+
"ơ",
|
859 |
+
"œ",
|
860 |
+
"Ŕ",
|
861 |
+
"Ř",
|
862 |
+
"Ś",
|
863 |
+
"Ŝ",
|
864 |
+
"Š",
|
865 |
+
"Ş",
|
866 |
+
"Ť",
|
867 |
+
"Ţ",
|
868 |
+
"Þ",
|
869 |
+
"Ú",
|
870 |
+
"Ù",
|
871 |
+
"Û",
|
872 |
+
"Ü",
|
873 |
+
"Ŭ",
|
874 |
+
"Ū",
|
875 |
+
"Ů",
|
876 |
+
"Ų",
|
877 |
+
"Ű",
|
878 |
+
"Ư",
|
879 |
+
"Ŵ",
|
880 |
+
"Ý",
|
881 |
+
"Ŷ",
|
882 |
+
"Ÿ",
|
883 |
+
"Ź",
|
884 |
+
"Ż",
|
885 |
+
"Ž",
|
886 |
+
"ŕ",
|
887 |
+
"ř",
|
888 |
+
"ś",
|
889 |
+
"ŝ",
|
890 |
+
"š",
|
891 |
+
"ş",
|
892 |
+
"ß",
|
893 |
+
"ť",
|
894 |
+
"ţ",
|
895 |
+
"þ",
|
896 |
+
"ú",
|
897 |
+
"ù",
|
898 |
+
"û",
|
899 |
+
"ü",
|
900 |
+
"ŭ",
|
901 |
+
"ū",
|
902 |
+
"ů",
|
903 |
+
"ų",
|
904 |
+
"ű",
|
905 |
+
"ư",
|
906 |
+
"ŵ",
|
907 |
+
"ý",
|
908 |
+
"ŷ",
|
909 |
+
"ÿ",
|
910 |
+
"ź",
|
911 |
+
"ż",
|
912 |
+
"ž"
|
913 |
+
);
|
914 |
+
$to = array(
|
915 |
+
"A",
|
916 |
+
"A",
|
917 |
+
"A",
|
918 |
+
"A",
|
919 |
+
"A",
|
920 |
+
"A",
|
921 |
+
"A",
|
922 |
+
"A",
|
923 |
+
"A",
|
924 |
+
"AE",
|
925 |
+
"C",
|
926 |
+
"C",
|
927 |
+
"C",
|
928 |
+
"C",
|
929 |
+
"C",
|
930 |
+
"D",
|
931 |
+
"D",
|
932 |
+
"D",
|
933 |
+
"E",
|
934 |
+
"E",
|
935 |
+
"E",
|
936 |
+
"E",
|
937 |
+
"E",
|
938 |
+
"E",
|
939 |
+
"E",
|
940 |
+
"E",
|
941 |
+
"G",
|
942 |
+
"G",
|
943 |
+
"G",
|
944 |
+
"G",
|
945 |
+
"G",
|
946 |
+
"a",
|
947 |
+
"a",
|
948 |
+
"a",
|
949 |
+
"a",
|
950 |
+
"a",
|
951 |
+
"a",
|
952 |
+
"a",
|
953 |
+
"a",
|
954 |
+
"a",
|
955 |
+
"ae",
|
956 |
+
"c",
|
957 |
+
"c",
|
958 |
+
"c",
|
959 |
+
"c",
|
960 |
+
"c",
|
961 |
+
"d",
|
962 |
+
"d",
|
963 |
+
"d",
|
964 |
+
"e",
|
965 |
+
"e",
|
966 |
+
"e",
|
967 |
+
"e",
|
968 |
+
"e",
|
969 |
+
"e",
|
970 |
+
"e",
|
971 |
+
"e",
|
972 |
+
"g",
|
973 |
+
"g",
|
974 |
+
"g",
|
975 |
+
"g",
|
976 |
+
"g",
|
977 |
+
"H",
|
978 |
+
"H",
|
979 |
+
"I",
|
980 |
+
"I",
|
981 |
+
"I",
|
982 |
+
"I",
|
983 |
+
"I",
|
984 |
+
"I",
|
985 |
+
"I",
|
986 |
+
"I",
|
987 |
+
"IJ",
|
988 |
+
"J",
|
989 |
+
"K",
|
990 |
+
"L",
|
991 |
+
"L",
|
992 |
+
"N",
|
993 |
+
"N",
|
994 |
+
"N",
|
995 |
+
"N",
|
996 |
+
"O",
|
997 |
+
"O",
|
998 |
+
"O",
|
999 |
+
"O",
|
1000 |
+
"O",
|
1001 |
+
"O",
|
1002 |
+
"O",
|
1003 |
+
"O",
|
1004 |
+
"CE",
|
1005 |
+
"h",
|
1006 |
+
"h",
|
1007 |
+
"i",
|
1008 |
+
"i",
|
1009 |
+
"i",
|
1010 |
+
"i",
|
1011 |
+
"i",
|
1012 |
+
"i",
|
1013 |
+
"i",
|
1014 |
+
"i",
|
1015 |
+
"ij",
|
1016 |
+
"j",
|
1017 |
+
"k",
|
1018 |
+
"l",
|
1019 |
+
"l",
|
1020 |
+
"n",
|
1021 |
+
"n",
|
1022 |
+
"n",
|
1023 |
+
"n",
|
1024 |
+
"o",
|
1025 |
+
"o",
|
1026 |
+
"o",
|
1027 |
+
"o",
|
1028 |
+
"o",
|
1029 |
+
"o",
|
1030 |
+
"o",
|
1031 |
+
"o",
|
1032 |
+
"o",
|
1033 |
+
"R",
|
1034 |
+
"R",
|
1035 |
+
"S",
|
1036 |
+
"S",
|
1037 |
+
"S",
|
1038 |
+
"S",
|
1039 |
+
"T",
|
1040 |
+
"T",
|
1041 |
+
"T",
|
1042 |
+
"U",
|
1043 |
+
"U",
|
1044 |
+
"U",
|
1045 |
+
"U",
|
1046 |
+
"U",
|
1047 |
+
"U",
|
1048 |
+
"U",
|
1049 |
+
"U",
|
1050 |
+
"U",
|
1051 |
+
"U",
|
1052 |
+
"W",
|
1053 |
+
"Y",
|
1054 |
+
"Y",
|
1055 |
+
"Y",
|
1056 |
+
"Z",
|
1057 |
+
"Z",
|
1058 |
+
"Z",
|
1059 |
+
"r",
|
1060 |
+
"r",
|
1061 |
+
"s",
|
1062 |
+
"s",
|
1063 |
+
"s",
|
1064 |
+
"s",
|
1065 |
+
"B",
|
1066 |
+
"t",
|
1067 |
+
"t",
|
1068 |
+
"b",
|
1069 |
+
"u",
|
1070 |
+
"u",
|
1071 |
+
"u",
|
1072 |
+
"u",
|
1073 |
+
"u",
|
1074 |
+
"u",
|
1075 |
+
"u",
|
1076 |
+
"u",
|
1077 |
+
"u",
|
1078 |
+
"u",
|
1079 |
+
"w",
|
1080 |
+
"y",
|
1081 |
+
"y",
|
1082 |
+
"y",
|
1083 |
+
"z",
|
1084 |
+
"z",
|
1085 |
+
"z"
|
1086 |
+
);
|
1087 |
+
$from = array_merge( $from, $cyrylicFrom );
|
1088 |
+
$to = array_merge( $to, $cyrylicTo );
|
1089 |
+
$string = str_replace( $from, $to, $string );
|
1090 |
+
|
1091 |
+
if ( function_exists( 'iconv' ) ) {
|
1092 |
+
$string = iconv( 'UTF-8', 'UTF-8//TRANSLIT//IGNORE', $string );
|
1093 |
+
}
|
1094 |
+
$string = preg_replace( "/[^A-Za-z0-9'_\-\.]/", '-', $string );
|
1095 |
+
$string = preg_replace( '/\-+/', '-', $string );
|
1096 |
+
$string = preg_replace( '/^-+/', '', $string );
|
1097 |
+
$string = preg_replace( '/-+$/', '', $string );
|
1098 |
+
|
1099 |
+
return $string;
|
1100 |
+
}
|
1101 |
+
|
1102 |
+
public static function addUrlParam( $url, $param_name, $param_value, $replace = true ) {
|
1103 |
+
$url_parts = parse_url( $url );
|
1104 |
+
if ( isset( $url_parts['query'] ) ) {
|
1105 |
+
$query = $url_parts['query'];
|
1106 |
+
} else {
|
1107 |
+
$query = '';
|
1108 |
+
}
|
1109 |
+
parse_str( $query, $query_array );
|
1110 |
+
if ( ! isset( $query_array[ $param_name ] ) && ! $replace ) {
|
1111 |
+
return $url;
|
1112 |
+
}
|
1113 |
+
if ( isset( $query_array[ $param_name ] ) && $query_array[ $param_name ] == $param_value ) {
|
1114 |
+
return $url;
|
1115 |
+
}
|
1116 |
+
|
1117 |
+
$query_array[ $param_name ] = $param_value;
|
1118 |
+
|
1119 |
+
return $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'] . '?' . http_build_query( $query_array );
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
public static function removeUrlParam( $url, $param_name ) {
|
1123 |
+
$url_parts = parse_url( $url );
|
1124 |
+
if ( isset( $url_parts['query'] ) ) {
|
1125 |
+
$query = $url_parts['query'];
|
1126 |
+
} else {
|
1127 |
+
$query = '';
|
1128 |
+
}
|
1129 |
+
parse_str( $query, $query_array );
|
1130 |
+
if ( ! isset( $query_array[ $param_name ] ) ) {
|
1131 |
+
return $url;
|
1132 |
+
}
|
1133 |
+
|
1134 |
+
unset( $query_array[ $param_name ] );
|
1135 |
+
|
1136 |
+
return $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'] . '?' . http_build_query( $query_array );
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
public static function getParamFromPath( $path, $param ) {
|
1140 |
+
$parts = explode( '/', $path );
|
1141 |
+
$position = array_search( $param, $parts );
|
1142 |
+
|
1143 |
+
if ( $position !== false && array_key_exists( $position + 1, $parts ) ) {
|
1144 |
+
return $parts[ $position + 1 ];
|
1145 |
+
} else {
|
1146 |
+
return false;
|
1147 |
+
}
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
public static function getUrlWithoutDomain( $url ) {
|
1151 |
+
if ( ! $parts = parse_url( $url ) ) {
|
1152 |
+
return false;
|
1153 |
+
}
|
1154 |
+
$res = '';
|
1155 |
+
if ( isset( $parts['path'] ) ) {
|
1156 |
+
$res .= $parts['path'];
|
1157 |
+
}
|
1158 |
+
if ( isset( $parts['query'] ) ) {
|
1159 |
+
$res .= '?' . $parts['query'];
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
return $res;
|
1163 |
+
}
|
1164 |
+
|
1165 |
+
public static function urlHost( $url ) {
|
1166 |
+
return strtolower( preg_replace( '/^www\./', '', parse_url( strtolower( trim( $url ) ), PHP_URL_HOST ) ) );
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
public static function sanitizeHtml( $string ) {
|
1170 |
+
$allowed_html = array(
|
1171 |
+
'abbr' => array(),
|
1172 |
+
'br' => array(),
|
1173 |
+
'blockquote' => array(),
|
1174 |
+
'cite' => array(),
|
1175 |
+
'code' => array(),
|
1176 |
+
'del' => array(),
|
1177 |
+
'em' => array(),
|
1178 |
+
'strong' => array(),
|
1179 |
+
'pre' => array(),
|
1180 |
+
'i' => array(),
|
1181 |
+
'p' => array(),
|
1182 |
+
'b' => array(),
|
1183 |
+
'ul' => array(),
|
1184 |
+
'ol' => array(),
|
1185 |
+
'li' => array(),
|
1186 |
+
'strike' => array(),
|
1187 |
+
's' => array(),
|
1188 |
+
'table' => array(),
|
1189 |
+
'tr' => array(),
|
1190 |
+
'td' => array(),
|
1191 |
+
'th' => array(),
|
1192 |
+
'span' => array( 'class' => array() ),
|
1193 |
+
'mark' => array(),
|
1194 |
+
);
|
1195 |
+
|
1196 |
+
return \wp_kses( $string, $allowed_html );
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
public static function isHtmlTagDetected( $string ) {
|
1200 |
+
if ( $string != strip_tags( $string ) ) {
|
1201 |
+
return true;
|
1202 |
+
} else {
|
1203 |
+
return false;
|
1204 |
+
}
|
1205 |
+
}
|
1206 |
+
|
1207 |
+
public static function findOriginalUrl( $url ) {
|
1208 |
+
if ( ! $query = parse_url( $url, PHP_URL_QUERY ) ) {
|
1209 |
+
return '';
|
1210 |
+
}
|
1211 |
+
|
1212 |
+
parse_str( $query, $params );
|
1213 |
+
foreach ( $params as $param ) {
|
1214 |
+
if ( filter_var( $param, FILTER_VALIDATE_URL ) ) {
|
1215 |
+
return $param;
|
1216 |
+
}
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
return false;
|
1220 |
+
}
|
1221 |
+
|
1222 |
}
|
application/libs/KeywordDensity.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\stopwords\StopWords;
|
8 |
|
@@ -18,113 +18,101 @@ use ContentEgg\application\libs\stopwords\StopWords;
|
|
18 |
*/
|
19 |
class KeywordDensity {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
if ($this->stemmer_normalisation)
|
119 |
-
{
|
120 |
-
$stemmer = $this->getStemmer();
|
121 |
-
if ($stemmer)
|
122 |
-
{
|
123 |
-
$word = $stemmer->stem($word);
|
124 |
-
}
|
125 |
-
}
|
126 |
-
|
127 |
-
return $word;
|
128 |
-
}
|
129 |
|
130 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\stopwords\StopWords;
|
8 |
|
18 |
*/
|
19 |
class KeywordDensity {
|
20 |
|
21 |
+
private $stemmer_normalisation = false;
|
22 |
+
private $lang = 'en'; //en|ru|fr|de|...
|
23 |
+
private $text = '';
|
24 |
+
private $words = array();
|
25 |
+
private $stemmer = null; // stemmer instance
|
26 |
+
private $stop_words = null;
|
27 |
+
private $words_rank = null;
|
28 |
+
|
29 |
+
public function __construct( $lang = 'en' ) {
|
30 |
+
$this->lang = $lang;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getStemmer() {
|
34 |
+
if ( $this->stemmer == null ) {
|
35 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'stemmer' . DIRECTORY_SEPARATOR . 'Stemmer.php';
|
36 |
+
if ( Stemmer::isLangAvailable( $this->lang ) ) {
|
37 |
+
$this->stemmer = new Stemmer( $this->lang );
|
38 |
+
} else {
|
39 |
+
$this->stemmer = false;
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
return $this->stemmer;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function SetStemmer( $stemmer ) {
|
47 |
+
$this->stemmer = $stemmer;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getStopWords() {
|
51 |
+
if ( $this->stop_words == null ) {
|
52 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'stopwords' . DIRECTORY_SEPARATOR . 'StopWords.php';
|
53 |
+
if ( StopWords::isLangAvailable( $this->lang ) ) {
|
54 |
+
$sw = new StopWords( $this->lang );
|
55 |
+
$this->stop_words = $sw->words( $this->lang );
|
56 |
+
} else {
|
57 |
+
$this->stop_words = array();
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
return $this->stop_words;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function setText( $text ) {
|
65 |
+
$this->text = strip_tags( $text );
|
66 |
+
$this->words = null;
|
67 |
+
}
|
68 |
+
|
69 |
+
public function setStemmerNormalisatiom( $value ) {
|
70 |
+
$this->stemmer_normalisation = (bool) $value;
|
71 |
+
}
|
72 |
+
|
73 |
+
public function getPopularWords( $max = null ) {
|
74 |
+
$this->splitWords();
|
75 |
+
$this->words_rank = array_count_values( $this->words );
|
76 |
+
arsort( $this->words_rank );
|
77 |
+
if ( $max ) {
|
78 |
+
return array_keys( array_slice( $this->words_rank, 0, $max ) );
|
79 |
+
} else {
|
80 |
+
return array_keys( $this->words_rank );
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
private function splitWords() {
|
85 |
+
$this->words = array();
|
86 |
+
preg_match_all( "/\pL+/ui", $this->text, $m );
|
87 |
+
foreach ( $m[0] as $word ) {
|
88 |
+
$word = $this->prepareWord( $word );
|
89 |
+
if ( ! $word ) {
|
90 |
+
continue;
|
91 |
+
}
|
92 |
+
|
93 |
+
$this->words[] = $word;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
public function prepareWord( $word ) {
|
98 |
+
$word = mb_strtolower( $word, 'UTF-8' );
|
99 |
+
|
100 |
+
if ( in_array( $word, $this->getStopWords() ) ) {
|
101 |
+
return false;
|
102 |
+
}
|
103 |
+
|
104 |
+
if ( ! ctype_digit( $word ) && mb_strlen( $word, 'UTF-8' ) <= 1 ) {
|
105 |
+
return false;
|
106 |
+
}
|
107 |
+
|
108 |
+
if ( $this->stemmer_normalisation ) {
|
109 |
+
$stemmer = $this->getStemmer();
|
110 |
+
if ( $stemmer ) {
|
111 |
+
$word = $stemmer->stem( $word );
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
return $word;
|
116 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
}
|
application/libs/ParserClient.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserClient class file
|
@@ -14,206 +14,195 @@ defined('\ABSPATH') || exit;
|
|
14 |
*/
|
15 |
class ParserClient {
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
{
|
208 |
-
$innerHTML = '';
|
209 |
-
$children = $tag->childNodes;
|
210 |
-
foreach ($children as $child)
|
211 |
-
{
|
212 |
-
$tmp_doc = new \DOMDocument();
|
213 |
-
$tmp_doc->appendChild($tmp_doc->importNode($child, true));
|
214 |
-
$innerHTML .= $tmp_doc->saveHTML();
|
215 |
-
}
|
216 |
-
return trim($innerHTML);
|
217 |
-
}
|
218 |
|
219 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* ParserClient class file
|
14 |
*/
|
15 |
class ParserClient {
|
16 |
|
17 |
+
protected $charset = 'utf-8';
|
18 |
+
protected $xpath;
|
19 |
+
protected $url;
|
20 |
+
protected static $_httpClient = null;
|
21 |
+
|
22 |
+
public function __construct( $url = null ) {
|
23 |
+
if ( $url ) {
|
24 |
+
$this->setUrl( $url );
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
public function setUrl( $url ) {
|
29 |
+
$this->url = $url;
|
30 |
+
$this->xpath = null;
|
31 |
+
$this->loadXPath( $url );
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getUrl() {
|
35 |
+
return $this->url;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getCharset() {
|
39 |
+
return $this->charset;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Gets the HTTP client object.
|
44 |
+
*/
|
45 |
+
public static function getHttpClient( $opts = array() ) {
|
46 |
+
$_opts = array(
|
47 |
+
'sslverify' => false,
|
48 |
+
'redirection' => 3,
|
49 |
+
'timeout' => 10,
|
50 |
+
'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:86.0) Gecko/20100101 Firefox/86.0',
|
51 |
+
);
|
52 |
+
if ( $opts ) {
|
53 |
+
$_opts = $opts + $_opts;
|
54 |
+
}
|
55 |
+
|
56 |
+
if ( self::$_httpClient == null ) {
|
57 |
+
//Get WP http client
|
58 |
+
self::$_httpClient = new WpHttpClient();
|
59 |
+
self::$_httpClient->setHeaders( 'Accept-Charset', 'ISO-8859-1,utf-8' );
|
60 |
+
self::$_httpClient->setUserAgent( $_opts['user-agent'] );
|
61 |
+
self::$_httpClient->setRedirection( $_opts['redirection'] );
|
62 |
+
self::$_httpClient->setTimeout( $_opts['timeout'] );
|
63 |
+
self::$_httpClient->setSslVerify( $_opts['sslverify'] );
|
64 |
+
}
|
65 |
+
|
66 |
+
return self::$_httpClient;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Sets the HTTP client object to use for retrieving the feeds. If none
|
71 |
+
* is set, the default Http_Client will be used.
|
72 |
+
*/
|
73 |
+
public static function setHttpClient( $httpClient ) {
|
74 |
+
self::$_httpClient = $httpClient;
|
75 |
+
}
|
76 |
+
|
77 |
+
public function loadXPath( $url, $query = null ) {
|
78 |
+
$this->xpath = $this->getXPath( $url, $query );
|
79 |
+
}
|
80 |
+
|
81 |
+
public function getXPath( $url, $query = null ) {
|
82 |
+
return $xpath = new \DomXPath( $this->getDom( $url, $query ) );
|
83 |
+
}
|
84 |
+
|
85 |
+
public function getDom( $url, $query = null ) {
|
86 |
+
$dom = new \DomDocument();
|
87 |
+
$dom->preserveWhiteSpace = false;
|
88 |
+
libxml_use_internal_errors( true );
|
89 |
+
if ( ! $dom->loadHTML( $this->restGet( $url, $query ) ) ) {
|
90 |
+
throw new \Exception( 'Can\'t load DOM Document.' );
|
91 |
+
}
|
92 |
+
|
93 |
+
return $dom;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function restGet( $uri, $query = null ) {
|
97 |
+
$client = self::getHttpClient();
|
98 |
+
$client->resetParameters();
|
99 |
+
$client->setUri( $uri );
|
100 |
+
if ( $query ) {
|
101 |
+
$client->setParameterGet( $query );
|
102 |
+
}
|
103 |
+
$body = $this->getResult( $client->request( 'GET' ) );
|
104 |
+
|
105 |
+
return $this->decodeCharset( $body );
|
106 |
+
}
|
107 |
+
|
108 |
+
protected function getResult( $response ) {
|
109 |
+
if ( \is_wp_error( $response ) ) {
|
110 |
+
$error_mess = "HTTP request fails: " . $response->get_error_code() . " - " . $response->get_error_message() . '.';
|
111 |
+
throw new \Exception( $error_mess );
|
112 |
+
}
|
113 |
+
|
114 |
+
$response_code = (int) \wp_remote_retrieve_response_code( $response );
|
115 |
+
|
116 |
+
if ( $response_code != 200 ) {
|
117 |
+
$response_message = \wp_remote_retrieve_response_message( $response );
|
118 |
+
$error_mess = "HTTP request status fails: " . $response_code . " - " . $response_message . '.';
|
119 |
+
throw new \Exception( $error_mess, $response_code );
|
120 |
+
}
|
121 |
+
|
122 |
+
return \wp_remote_retrieve_body( $response );
|
123 |
+
}
|
124 |
+
|
125 |
+
public function decodeCharset( $str ) {
|
126 |
+
$encoding_hint = '<?xml encoding="UTF-8">';
|
127 |
+
|
128 |
+
if ( strtolower( $this->charset ) != 'utf-8' ) {
|
129 |
+
$str = $encoding_hint . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $str;
|
130 |
+
|
131 |
+
return iconv( $this->charset, 'utf-8', $str );
|
132 |
+
} else {
|
133 |
+
return $encoding_hint . $str;
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
public function xpathScalar( $path, $return_child = false ) {
|
138 |
+
if ( is_array( $path ) ) {
|
139 |
+
return $this->xpathScalarMulty( $path, $return_child );
|
140 |
+
}
|
141 |
+
|
142 |
+
$res = $this->xpath->query( $path );
|
143 |
+
if ( $res && $res->length > 0 ) {
|
144 |
+
if ( $return_child ) {
|
145 |
+
foreach ( $res as $tag ) {
|
146 |
+
return $this->xpathReturnChild( $tag );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
return trim( strip_tags( $res->item( 0 )->nodeValue ) );
|
151 |
+
} else {
|
152 |
+
return null;
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
public function xpathScalarMulty( array $paths, $return_child = false ) {
|
157 |
+
foreach ( $paths as $path ) {
|
158 |
+
if ( $r = $this->xpathScalar( $path, $return_child ) ) {
|
159 |
+
return $r;
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
return $r;
|
164 |
+
}
|
165 |
+
|
166 |
+
public function xpathArray( $path, $return_child = false ) {
|
167 |
+
if ( is_array( $path ) ) {
|
168 |
+
return $this->xpathArrayMulty( $path, $return_child );
|
169 |
+
}
|
170 |
+
|
171 |
+
$res = $this->xpath->query( $path );
|
172 |
+
$return = array();
|
173 |
+
if ( $res && $res->length > 0 ) {
|
174 |
+
foreach ( $res as $tag ) {
|
175 |
+
if ( $return_child ) {
|
176 |
+
$return[] = $this->xpathReturnChild( $tag );
|
177 |
+
} else {
|
178 |
+
$return[] = trim( strip_tags( $tag->nodeValue ) );
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
return $return;
|
184 |
+
}
|
185 |
+
|
186 |
+
public function xpathArrayMulty( array $paths, $return_child = false ) {
|
187 |
+
foreach ( $paths as $path ) {
|
188 |
+
if ( $r = $this->xpathArray( $path, $return_child ) ) {
|
189 |
+
return $r;
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
return $r;
|
194 |
+
}
|
195 |
+
|
196 |
+
protected function xpathReturnChild( $tag ) {
|
197 |
+
$innerHTML = '';
|
198 |
+
$children = $tag->childNodes;
|
199 |
+
foreach ( $children as $child ) {
|
200 |
+
$tmp_doc = new \DOMDocument();
|
201 |
+
$tmp_doc->appendChild( $tmp_doc->importNode( $child, true ) );
|
202 |
+
$innerHTML .= $tmp_doc->saveHTML();
|
203 |
+
}
|
204 |
+
|
205 |
+
return trim( $innerHTML );
|
206 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
}
|
application/libs/RestClient.php
CHANGED
@@ -16,239 +16,219 @@ use ContentEgg\application\helpers\TextHelper;
|
|
16 |
*/
|
17 |
class RestClient {
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
break;
|
233 |
-
case 'xml':
|
234 |
-
case 'rss':
|
235 |
-
case 'atom':
|
236 |
-
$res = TextHelper::unserialize_xml($response);
|
237 |
-
break;
|
238 |
-
default :
|
239 |
-
$res = $response;
|
240 |
-
}
|
241 |
-
if (is_array($res))
|
242 |
-
array_walk_recursive($res, array($this, '_fixUtf8'));
|
243 |
-
elseif (is_scalar($res))
|
244 |
-
$this->_fixUtf8($res);
|
245 |
-
|
246 |
-
return $res;
|
247 |
-
}
|
248 |
-
|
249 |
-
protected function _fixUtf8(&$text)
|
250 |
-
{
|
251 |
-
$regex = '/
|
252 |
(
|
253 |
(?: [\x00-\x7F] # single-byte sequences 0xxxxxxx
|
254 |
| [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx
|
@@ -256,11 +236,11 @@ class RestClient {
|
|
256 |
| [\xE1-\xEC][\x80-\xBF]{2}
|
257 |
| \xED[\x80-\x9F][\x80-\xBF]
|
258 |
| [\xEE-\xEF][\x80-\xBF]{2}';
|
259 |
-
|
260 |
)
|
261 |
| . # anything else
|
262 |
/x';
|
263 |
-
|
264 |
-
|
265 |
|
266 |
}
|
16 |
*/
|
17 |
class RestClient {
|
18 |
|
19 |
+
protected static $timeout = 15; //sec
|
20 |
+
protected static $useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Firefox/93.0';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Endpoint uri of this web service
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
protected $_uri = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var String Return Type
|
30 |
+
*/
|
31 |
+
protected $_responseType = null;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @var array Response Format Types
|
35 |
+
*/
|
36 |
+
protected $_responseTypes = array();
|
37 |
+
protected $_custom_header = array();
|
38 |
+
protected static $_httpClient = null;
|
39 |
+
|
40 |
+
public function __construct( $uri = null ) {
|
41 |
+
if ( ! empty( $uri ) ) {
|
42 |
+
$this->setUri( $uri );
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Set responseType
|
48 |
+
*/
|
49 |
+
public function setResponseType( $responseType = 'json' ) {
|
50 |
+
if ( ! in_array( $responseType, $this->_responseTypes, true ) ) {
|
51 |
+
throw new \Exception( 'Invalid Response Type' );
|
52 |
+
}
|
53 |
+
$this->_responseType = $responseType;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Retrieve responseType
|
58 |
+
*/
|
59 |
+
public function getResponseType() {
|
60 |
+
return $this->_responseType;
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Sets the HTTP client object to use for retrieving the feeds. If none
|
65 |
+
* is set, the default Http_Client will be used.
|
66 |
+
*/
|
67 |
+
public static function setHttpClient( $httpClient ) {
|
68 |
+
self::$_httpClient = $httpClient;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Gets the HTTP client object.
|
73 |
+
*/
|
74 |
+
public static function getHttpClient( $opts = array() ) {
|
75 |
+
$_opts = array(
|
76 |
+
'sslverify' => false,
|
77 |
+
'redirection' => 5,
|
78 |
+
'timeout' => static::$timeout,
|
79 |
+
'user-agent' => static::$useragent,
|
80 |
+
);
|
81 |
+
if ( $opts ) {
|
82 |
+
$_opts = $opts + $_opts;
|
83 |
+
}
|
84 |
+
|
85 |
+
if ( self::$_httpClient == null ) {
|
86 |
+
//Get WP http client
|
87 |
+
self::$_httpClient = new WpHttpClient();
|
88 |
+
self::$_httpClient->setHeaders( 'Accept-Charset', 'ISO-8859-1,utf-8' );
|
89 |
+
self::$_httpClient->setRedirection( $_opts['redirection'] );
|
90 |
+
self::$_httpClient->setTimeout( $_opts['timeout'] );
|
91 |
+
self::$_httpClient->setSslVerify( $_opts['sslverify'] );
|
92 |
+
self::$_httpClient->setUserAgent( $_opts['user-agent'] );
|
93 |
+
}
|
94 |
+
|
95 |
+
return self::$_httpClient;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Set the URI to use in the request
|
100 |
+
*/
|
101 |
+
public function setUri( $uri ) {
|
102 |
+
$this->_uri = $uri;
|
103 |
+
}
|
104 |
+
|
105 |
+
public function getUri() {
|
106 |
+
return $this->_uri;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function setCustomHeaders( $headers = array() ) {
|
110 |
+
$this->_custom_header = $headers;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function addCustomHeaders( $headers = array() ) {
|
114 |
+
$this->_custom_header = array_merge( $this->_custom_header, $headers );
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Performs an HTTP GET request
|
119 |
+
*
|
120 |
+
* @param string $path
|
121 |
+
* @param array $query Array of GET parameters
|
122 |
+
*/
|
123 |
+
public function restGet( $path, array $query = null ) {
|
124 |
+
$this->_prepareRest( $path );
|
125 |
+
$client = self::getHttpClient();
|
126 |
+
$client->setParameterGet( $query );
|
127 |
+
|
128 |
+
return $this->_getResult( $client->request( 'GET' ) );
|
129 |
+
}
|
130 |
+
|
131 |
+
private function _prepareRest( $path ) {
|
132 |
+
|
133 |
+
if ( strstr( $path, 'http://' ) || strstr( $path, 'https://' ) ) {
|
134 |
+
$uri = $path;
|
135 |
+
} else {
|
136 |
+
$uri = $this->getUri();
|
137 |
+
if ( $path && $path[0] != '/' && $uri[ strlen( $uri ) - 1 ] != '/' ) {
|
138 |
+
$path = '/' . $path;
|
139 |
+
}
|
140 |
+
$uri = $uri . $path;
|
141 |
+
}
|
142 |
+
|
143 |
+
$client = self::getHttpClient();
|
144 |
+
|
145 |
+
$client->resetParameters();
|
146 |
+
$client->setUri( $uri );
|
147 |
+
|
148 |
+
foreach ( $this->_custom_header as $header => $value ) {
|
149 |
+
$client->setHeaders( $header, $value );
|
150 |
+
}
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Performs an HTTP POST request
|
155 |
+
*
|
156 |
+
* @param string $path
|
157 |
+
* @param mixed $data Raw data to send
|
158 |
+
* @param string $enctype
|
159 |
+
*/
|
160 |
+
public function restPost( $path, $data = null, $enctype = null, $opts = array() ) {
|
161 |
+
$this->_prepareRest( $path );
|
162 |
+
$client = self::getHttpClient( $opts );
|
163 |
+
if ( is_string( $data ) ) {
|
164 |
+
$client->setRawData( $data, $enctype );
|
165 |
+
} elseif ( is_array( $data ) || is_object( $data ) ) {
|
166 |
+
$client->setParameterPost( (array) $data );
|
167 |
+
}
|
168 |
+
|
169 |
+
return $this->_getResult( $client->request( 'POST' ) );
|
170 |
+
}
|
171 |
+
|
172 |
+
final public function get( $path, array $query = null ) {
|
173 |
+
return $this->restGet( $path, $query );
|
174 |
+
}
|
175 |
+
|
176 |
+
protected function _getResult( $response ) {
|
177 |
+
if ( \is_wp_error( $response ) ) {
|
178 |
+
$error_mess = "HTTP request fails: " . $response->get_error_code() . " - " . $response->get_error_message() . '.';
|
179 |
+
throw new \Exception( $error_mess );
|
180 |
+
}
|
181 |
+
|
182 |
+
$this->myErrorHandler( $response );
|
183 |
+
|
184 |
+
return \wp_remote_retrieve_body( $response );
|
185 |
+
}
|
186 |
+
|
187 |
+
protected function myErrorHandler( $response ) {
|
188 |
+
$response_code = (int) \wp_remote_retrieve_response_code( $response );
|
189 |
+
if ( $response_code != 200 && $response_code != 206 ) {
|
190 |
+
$response_message = \wp_remote_retrieve_response_message( $response );
|
191 |
+
$error_mess = "HTTP request status fails: " . $response_code . " - " . $response_message . '.';
|
192 |
+
$error_mess .= ' Server replay: ' . \wp_remote_retrieve_body( $response );
|
193 |
+
throw new \Exception( $error_mess, $response_code );
|
194 |
+
}
|
195 |
+
}
|
196 |
+
|
197 |
+
protected function _decodeResponse( $response, $responseType = null ) {
|
198 |
+
if ( $responseType == null ) {
|
199 |
+
$responseType = $this->_responseType;
|
200 |
+
}
|
201 |
+
|
202 |
+
switch ( $responseType ) {
|
203 |
+
case 'php':
|
204 |
+
case 'php_serial':
|
205 |
+
$res = @unserialize( $response );
|
206 |
+
if ( $res === false ) {
|
207 |
+
throw new \Exception( 'Response serialization error.' );
|
208 |
+
}
|
209 |
+
break;
|
210 |
+
case 'json':
|
211 |
+
$res = json_decode( $response, true );
|
212 |
+
break;
|
213 |
+
case 'xml':
|
214 |
+
case 'rss':
|
215 |
+
case 'atom':
|
216 |
+
$res = TextHelper::unserialize_xml( $response );
|
217 |
+
break;
|
218 |
+
default :
|
219 |
+
$res = $response;
|
220 |
+
}
|
221 |
+
if ( is_array( $res ) ) {
|
222 |
+
array_walk_recursive( $res, array( $this, '_fixUtf8' ) );
|
223 |
+
} elseif ( is_scalar( $res ) ) {
|
224 |
+
$this->_fixUtf8( $res );
|
225 |
+
}
|
226 |
+
|
227 |
+
return $res;
|
228 |
+
}
|
229 |
+
|
230 |
+
protected function _fixUtf8( &$text ) {
|
231 |
+
$regex = '/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
(
|
233 |
(?: [\x00-\x7F] # single-byte sequences 0xxxxxxx
|
234 |
| [\xC2-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx
|
236 |
| [\xE1-\xEC][\x80-\xBF]{2}
|
237 |
| \xED[\x80-\x9F][\x80-\xBF]
|
238 |
| [\xEE-\xEF][\x80-\xBF]{2}';
|
239 |
+
$regex .= '){1,40} # ...one or more times
|
240 |
)
|
241 |
| . # anything else
|
242 |
/x';
|
243 |
+
$text = preg_replace( $regex, '$1', $text );
|
244 |
+
}
|
245 |
|
246 |
}
|
application/libs/WpHttpClient.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* WpHttpClient class file
|
@@ -17,449 +17,423 @@ defined('\ABSPATH') || exit;
|
|
17 |
*/
|
18 |
class WpHttpClient {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
$allowed_headers = array('accept-charset');
|
439 |
-
foreach ($this->headers as $header => $val)
|
440 |
-
{
|
441 |
-
if (!in_array($header, $allowed_headers))
|
442 |
-
unset($this->headers[$header]);
|
443 |
-
}
|
444 |
-
}
|
445 |
-
|
446 |
-
/**
|
447 |
-
* Get the last HTTP request as string
|
448 |
-
*/
|
449 |
-
/*
|
450 |
-
public function getLastRequest()
|
451 |
-
{
|
452 |
-
return $this->last_request;
|
453 |
-
}
|
454 |
-
*
|
455 |
-
*/
|
456 |
-
|
457 |
-
/**
|
458 |
-
* Get the last HTTP response received by this client
|
459 |
-
*/
|
460 |
-
public function getLastResponse()
|
461 |
-
{
|
462 |
-
return $this->last_response;
|
463 |
-
}
|
464 |
|
465 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* WpHttpClient class file
|
17 |
*/
|
18 |
class WpHttpClient {
|
19 |
|
20 |
+
/**
|
21 |
+
* HTTP request methods
|
22 |
+
*/
|
23 |
+
const GET = 'GET';
|
24 |
+
const POST = 'POST';
|
25 |
+
const PUT = 'PUT';
|
26 |
+
const HEAD = 'HEAD';
|
27 |
+
const DELETE = 'DELETE';
|
28 |
+
const TRACE = 'TRACE';
|
29 |
+
const OPTIONS = 'OPTIONS';
|
30 |
+
const CONNECT = 'CONNECT';
|
31 |
+
|
32 |
+
/**
|
33 |
+
* POST data encoding methods
|
34 |
+
*/
|
35 |
+
const ENC_URLENCODED = 'application/x-www-form-urlencoded';
|
36 |
+
const ENC_FORMDATA = 'multipart/form-data';
|
37 |
+
|
38 |
+
private $timeout;
|
39 |
+
private $sslverify;
|
40 |
+
private $useragent;
|
41 |
+
private $redirection;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Request URI
|
45 |
+
*/
|
46 |
+
protected $uri;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Associative array of request headers
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
+
protected $headers = array();
|
54 |
+
|
55 |
+
/**
|
56 |
+
* HTTP request method
|
57 |
+
*
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
+
protected $method = self::GET;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Associative array of GET parameters
|
64 |
+
*
|
65 |
+
* @var array
|
66 |
+
*/
|
67 |
+
protected $paramsGet = array();
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Assiciative array of POST parameters
|
71 |
+
*
|
72 |
+
* @var array
|
73 |
+
*/
|
74 |
+
protected $paramsPost = array();
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Request body content type (for POST requests)
|
78 |
+
*
|
79 |
+
* @var string
|
80 |
+
*/
|
81 |
+
protected $enctype = null;
|
82 |
+
|
83 |
+
/**
|
84 |
+
* The raw post data to send. Could be set by setRawData($data, $enctype).
|
85 |
+
*
|
86 |
+
* @var string
|
87 |
+
*/
|
88 |
+
protected $raw_post_data = null;
|
89 |
+
|
90 |
+
/**
|
91 |
+
* The last HTTP response received by the client
|
92 |
+
*
|
93 |
+
* @var EHttpResponse
|
94 |
+
*/
|
95 |
+
protected $last_response = null;
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Set the URI for the next request
|
99 |
+
*/
|
100 |
+
public function setUri( $uri ) {
|
101 |
+
$this->uri = $uri;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Get the URI for the next request
|
106 |
+
*/
|
107 |
+
public function getUri( $as_string = false ) {
|
108 |
+
return $this->uri;
|
109 |
+
}
|
110 |
+
|
111 |
+
public function setHeaders( $name, $value = null ) {
|
112 |
+
// If we got an array, go recusive!
|
113 |
+
if ( is_array( $name ) ) {
|
114 |
+
foreach ( $name as $k => $v ) {
|
115 |
+
if ( is_string( $k ) ) {
|
116 |
+
$this->setHeaders( $k, $v );
|
117 |
+
} else {
|
118 |
+
$this->setHeaders( $v, null );
|
119 |
+
}
|
120 |
+
}
|
121 |
+
} else {
|
122 |
+
// Check if $name needs to be split
|
123 |
+
if ( $value === null && ( strpos( $name, ':' ) > 0 ) ) {
|
124 |
+
list( $name, $value ) = explode( ':', $name, 2 );
|
125 |
+
}
|
126 |
+
|
127 |
+
// Make sure the name is valid if we are in strict mode
|
128 |
+
/*
|
129 |
+
if (!preg_match('/^[a-zA-Z0-9-]+$/', $name))
|
130 |
+
{
|
131 |
+
throw new \Exception("{$name} is not a valid HTTP header name");
|
132 |
+
}
|
133 |
+
*
|
134 |
+
*/
|
135 |
+
|
136 |
+
$normalized_name = strtolower( $name );
|
137 |
+
|
138 |
+
// If $value is null or false, unset the header
|
139 |
+
if ( $value === null || $value === false ) {
|
140 |
+
unset( $this->headers[ $normalized_name ] );
|
141 |
+
} else {
|
142 |
+
// Header names are storred lowercase internally.
|
143 |
+
if ( is_string( $value ) ) {
|
144 |
+
$value = trim( $value );
|
145 |
+
}
|
146 |
+
$this->headers[ $normalized_name ] = array( $name, $value );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Get the value of a specific header
|
153 |
+
*
|
154 |
+
* Note that if the header has more than one value, an array
|
155 |
+
* will be returned.
|
156 |
+
*
|
157 |
+
* @param string $key
|
158 |
+
*
|
159 |
+
* @return string|array|null The header value or null if it is not set
|
160 |
+
*/
|
161 |
+
public function getHeader( $key ) {
|
162 |
+
$key = strtolower( $key );
|
163 |
+
if ( isset( $this->headers[ $key ] ) ) {
|
164 |
+
return $this->headers[ $key ][1];
|
165 |
+
} else {
|
166 |
+
return null;
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Set the next request's method
|
172 |
+
*/
|
173 |
+
public function setMethod( $method = self::GET ) {
|
174 |
+
|
175 |
+
if ( $method !== self::GET && $method !== self::POST ) {
|
176 |
+
throw new \Exception( 'Only GET and POST methods avalible.' );
|
177 |
+
}
|
178 |
+
|
179 |
+
$this->method = $method;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Set a GET parameter for the request. Wrapper around _setParameter
|
184 |
+
*
|
185 |
+
* @param string|array $name
|
186 |
+
* @param string $value
|
187 |
+
*
|
188 |
+
* @return EHttpClient
|
189 |
+
*/
|
190 |
+
public function setParameterGet( $name, $value = null ) {
|
191 |
+
if ( is_array( $name ) ) {
|
192 |
+
foreach ( $name as $k => $v ) {
|
193 |
+
$this->_setParameter( 'GET', $k, $v );
|
194 |
+
}
|
195 |
+
} else {
|
196 |
+
$this->_setParameter( 'GET', $name, $value );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Set a POST parameter for the request. Wrapper around _setParameter
|
202 |
+
*
|
203 |
+
* @param string|array $name
|
204 |
+
* @param string $value
|
205 |
+
*/
|
206 |
+
public function setParameterPost( $name, $value = null ) {
|
207 |
+
if ( is_array( $name ) ) {
|
208 |
+
foreach ( $name as $k => $v ) {
|
209 |
+
$this->_setParameter( 'POST', $k, $v );
|
210 |
+
}
|
211 |
+
} else {
|
212 |
+
$this->_setParameter( 'POST', $name, $value );
|
213 |
+
}
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Set a GET or POST parameter - used by SetParameterGet and SetParameterPost
|
218 |
+
*
|
219 |
+
* @param string $type GET or POST
|
220 |
+
* @param string $name
|
221 |
+
* @param string $value
|
222 |
+
*
|
223 |
+
* @return null
|
224 |
+
*/
|
225 |
+
protected function _setParameter( $type, $name, $value ) {
|
226 |
+
$parray = array();
|
227 |
+
$type = strtolower( $type );
|
228 |
+
switch ( $type ) {
|
229 |
+
case 'get':
|
230 |
+
$parray = &$this->paramsGet;
|
231 |
+
break;
|
232 |
+
case 'post':
|
233 |
+
$parray = &$this->paramsPost;
|
234 |
+
break;
|
235 |
+
}
|
236 |
+
|
237 |
+
if ( $value === null ) {
|
238 |
+
if ( isset( $parray[ $name ] ) ) {
|
239 |
+
unset( $parray[ $name ] );
|
240 |
+
}
|
241 |
+
} else {
|
242 |
+
$parray[ $name ] = $value;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
public function setTimeout( $value ) {
|
247 |
+
$this->timeout = $value;
|
248 |
+
}
|
249 |
+
|
250 |
+
public function setSslVerify( $value ) {
|
251 |
+
$this->sslverify = $value;
|
252 |
+
}
|
253 |
+
|
254 |
+
public function setUserAgent( $value ) {
|
255 |
+
$this->useragent = $value;
|
256 |
+
}
|
257 |
+
|
258 |
+
public function setRedirection( $value ) {
|
259 |
+
$this->redirection = $value;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Prepare the request body (for POST and PUT requests)
|
264 |
+
*
|
265 |
+
* @return string
|
266 |
+
*/
|
267 |
+
protected function _prepareBody() {
|
268 |
+
// According to RFC2616, a TRACE request should not have a body.
|
269 |
+
if ( $this->method == self::TRACE ) {
|
270 |
+
return '';
|
271 |
+
}
|
272 |
+
|
273 |
+
// If we have raw_post_data set, just use it as the body.
|
274 |
+
if ( isset( $this->raw_post_data ) ) {
|
275 |
+
$this->setHeaders( 'Content-length', strlen( $this->raw_post_data ) );
|
276 |
+
|
277 |
+
return $this->raw_post_data;
|
278 |
+
}
|
279 |
+
|
280 |
+
$body = '';
|
281 |
+
|
282 |
+
// If we have POST parameters, encode and add them to the body
|
283 |
+
if ( count( $this->paramsPost ) > 0 ) {
|
284 |
+
|
285 |
+
// Encode body as application/x-www-form-urlencoded
|
286 |
+
$this->setHeaders( 'Content-type', self::ENC_URLENCODED );
|
287 |
+
$body = http_build_query( $this->paramsPost, '', '&' );
|
288 |
+
}
|
289 |
+
|
290 |
+
// Set the content-length if we have a body or if request is POST/PUT
|
291 |
+
if ( $body || $this->method == self::POST || $this->method == self::PUT ) {
|
292 |
+
$this->setHeaders( 'Content-length', strlen( $body ) );
|
293 |
+
}
|
294 |
+
|
295 |
+
return $body;
|
296 |
+
}
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Prepare the request headers
|
300 |
+
*
|
301 |
+
* @return array
|
302 |
+
*/
|
303 |
+
protected function _prepareHeaders() {
|
304 |
+
$headers = array();
|
305 |
+
// Set the host header
|
306 |
+
if ( ! isset( $this->headers['host'] ) ) {
|
307 |
+
$host = parse_url( $this->uri, PHP_URL_HOST );
|
308 |
+
$headers['Host'] = "{$host}";
|
309 |
+
}
|
310 |
+
|
311 |
+
// Set the connection header
|
312 |
+
if ( ! isset( $this->headers['connection'] ) ) {
|
313 |
+
$headers['Connection'] = "close";
|
314 |
+
}
|
315 |
+
|
316 |
+
// Set the Accept-encoding header if not set - depending on whether
|
317 |
+
// zlib is available or not.
|
318 |
+
if ( ! isset( $this->headers['accept-encoding'] ) ) {
|
319 |
+
if ( function_exists( 'gzinflate' ) ) {
|
320 |
+
$headers['Accept-encoding'] = 'gzip, deflate';
|
321 |
+
} else {
|
322 |
+
$headers['Accept-encoding'] = 'identity';
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
+
// Set the content-type header
|
327 |
+
if ( $this->method == self::POST &&
|
328 |
+
( ! isset( $this->headers['content-type'] ) && isset( $this->enctype ) ) ) {
|
329 |
+
|
330 |
+
$headers['Content-type'] = "{$this->enctype}";
|
331 |
+
}
|
332 |
+
|
333 |
+
// Add all other user defined headers
|
334 |
+
foreach ( $this->headers as $header ) {
|
335 |
+
list( $name, $value ) = $header;
|
336 |
+
if ( is_array( $value ) ) {
|
337 |
+
$value = implode( ', ', $value );
|
338 |
+
}
|
339 |
+
|
340 |
+
$headers[ $name ] = $value;
|
341 |
+
}
|
342 |
+
|
343 |
+
return $headers;
|
344 |
+
}
|
345 |
+
|
346 |
+
protected function _prepareParams() {
|
347 |
+
$options = array();
|
348 |
+
$options['method'] = $this->method;
|
349 |
+
|
350 |
+
if ( $this->timeout !== null ) {
|
351 |
+
$options['timeout'] = $this->timeout;
|
352 |
+
}
|
353 |
+
if ( $this->sslverify !== null ) {
|
354 |
+
$options['sslverify'] = $this->sslverify;
|
355 |
+
}
|
356 |
+
if ( $this->useragent !== null ) {
|
357 |
+
$options['user-agent'] = $this->useragent;
|
358 |
+
}
|
359 |
+
if ( $this->redirection !== null ) {
|
360 |
+
$options['redirection'] = $this->redirection;
|
361 |
+
}
|
362 |
+
|
363 |
+
$options['headers'] = $this->_prepareHeaders();
|
364 |
+
$options['body'] = $this->_prepareBody();
|
365 |
+
|
366 |
+
return $options;
|
367 |
+
}
|
368 |
+
|
369 |
+
public function request( $method = null ) {
|
370 |
+
if ( ! $this->uri ) {
|
371 |
+
throw new \Exception( 'No valid URI has been passed to the client' );
|
372 |
+
}
|
373 |
+
|
374 |
+
if ( $method ) {
|
375 |
+
$this->setMethod( $method );
|
376 |
+
}
|
377 |
+
|
378 |
+
// Add the additional GET parameters to uri
|
379 |
+
if ( ! empty( $this->paramsGet ) ) {
|
380 |
+
$query = parse_url( $this->uri, PHP_URL_QUERY );
|
381 |
+
if ( ! empty( $query ) ) {
|
382 |
+
$this->uri .= '&';
|
383 |
+
} else {
|
384 |
+
$this->uri .= '?';
|
385 |
+
}
|
386 |
+
$this->uri .= http_build_query( $this->paramsGet, null, '&' );
|
387 |
+
}
|
388 |
+
|
389 |
+
$this->last_response = \wp_remote_request( $this->uri, $this->_prepareParams() );
|
390 |
+
|
391 |
+
return $this->last_response;
|
392 |
+
}
|
393 |
+
|
394 |
+
public function setRawData( $data, $enctype = null ) {
|
395 |
+
$this->raw_post_data = $data;
|
396 |
+
//$this->setEncType($enctype);
|
397 |
+
}
|
398 |
+
|
399 |
+
/**
|
400 |
+
* Clear all GET and POST parameters
|
401 |
+
*
|
402 |
+
* Should be used to reset the request parameters if the client is
|
403 |
+
* used for several concurrent requests.
|
404 |
+
*
|
405 |
+
*/
|
406 |
+
public function resetParameters() {
|
407 |
+
// Reset parameter data
|
408 |
+
$this->paramsGet = array();
|
409 |
+
$this->paramsPost = array();
|
410 |
+
$this->raw_post_data = null;
|
411 |
+
|
412 |
+
// Reset headers
|
413 |
+
$allowed_headers = array( 'accept-charset' );
|
414 |
+
foreach ( $this->headers as $header => $val ) {
|
415 |
+
if ( ! in_array( $header, $allowed_headers ) ) {
|
416 |
+
unset( $this->headers[ $header ] );
|
417 |
+
}
|
418 |
+
}
|
419 |
+
}
|
420 |
+
|
421 |
+
/**
|
422 |
+
* Get the last HTTP request as string
|
423 |
+
*/
|
424 |
+
/*
|
425 |
+
public function getLastRequest()
|
426 |
+
{
|
427 |
+
return $this->last_request;
|
428 |
+
}
|
429 |
+
*
|
430 |
+
*/
|
431 |
+
|
432 |
+
/**
|
433 |
+
* Get the last HTTP response received by this client
|
434 |
+
*/
|
435 |
+
public function getLastResponse() {
|
436 |
+
return $this->last_response;
|
437 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
438 |
|
439 |
}
|
application/libs/admitad/AdmitadProducts.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\admitad;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,51 +12,51 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2016 keywordrush.com
|
15 |
-
*
|
16 |
*/
|
17 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
18 |
|
19 |
class AdmitadProducts extends RestClient {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\admitad;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2016 keywordrush.com
|
15 |
+
*
|
16 |
*/
|
17 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
18 |
|
19 |
class AdmitadProducts extends RestClient {
|
20 |
|
21 |
+
const API_URI_BASE = 'http://185.58.206.88/wp';
|
22 |
+
|
23 |
+
/**
|
24 |
+
* @var array Response Format Types
|
25 |
+
*/
|
26 |
+
protected $_responseTypes = array(
|
27 |
+
'php',
|
28 |
+
);
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Constructor
|
32 |
+
*
|
33 |
+
* @param string $responseType
|
34 |
+
*/
|
35 |
+
public function __construct() {
|
36 |
+
$this->setResponseType( 'php' );
|
37 |
+
$this->setUri( self::API_URI_BASE );
|
38 |
+
}
|
39 |
+
|
40 |
+
public function search( $keyword, array $options ) {
|
41 |
+
$options['q'] = $keyword;
|
42 |
+
//"vendor" => $vendor,
|
43 |
+
//"offset" => $offset,
|
44 |
+
$response = $this->restGet( '/index.php', $options );
|
45 |
+
|
46 |
+
return $this->_decodeResponse( $response );
|
47 |
+
}
|
48 |
+
|
49 |
+
public function update( array $items ) {
|
50 |
+
$response = $this->restGet( '/up.php', array( "items" => $items ) );
|
51 |
+
|
52 |
+
return $this->_decodeResponse( $response );
|
53 |
+
}
|
54 |
+
|
55 |
+
public function restGet( $path, array $query = null ) {
|
56 |
+
$query['plugin'] = \ContentEgg\application\Plugin::slug();
|
57 |
+
$this->setCustomHeaders( array( 'Referer' => parse_url( \site_url(), PHP_URL_HOST ) ) );
|
58 |
+
|
59 |
+
return parent::restGet( $path, $query );
|
60 |
+
}
|
61 |
|
62 |
}
|
application/libs/affilinet/AffilinetCoupons.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\affilinet;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -16,87 +16,84 @@ use ContentEgg\application\libs\RestClient;
|
|
16 |
* @link: http://publisher.affili.net/Solutions/Webservices_Webservices.aspx?nr=1&pnp=54#Voucher
|
17 |
* @link: http://publisher.affili.net/HtmlContent/de/downloads/Web%20Services/Documentation_SearchVoucherCodes.pdf
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class AffilinetCoupons extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
{
|
99 |
-
throw new \Exception('This method not implemented yet.');
|
100 |
-
}
|
101 |
|
102 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\affilinet;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
16 |
* @link: http://publisher.affili.net/Solutions/Webservices_Webservices.aspx?nr=1&pnp=54#Voucher
|
17 |
* @link: http://publisher.affili.net/HtmlContent/de/downloads/Web%20Services/Documentation_SearchVoucherCodes.pdf
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class AffilinetCoupons extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://publisher-webservices.affili.net/Publisher/Inbox.asmx';
|
24 |
+
|
25 |
+
protected $password;
|
26 |
+
protected $publisher_id;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array Response Format Types
|
30 |
+
*/
|
31 |
+
protected $_responseTypes = array(
|
32 |
+
'xml',
|
33 |
+
);
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Constructor
|
37 |
+
*
|
38 |
+
* @param string $responseType
|
39 |
+
*/
|
40 |
+
public function __construct( $password, $publisher_id ) {
|
41 |
+
$this->setPassword( $password );
|
42 |
+
$this->setPublisherId( $publisher_id );
|
43 |
+
$this->setResponseType( 'xml' );
|
44 |
+
$this->setUri( self::API_URI_BASE );
|
45 |
+
}
|
46 |
+
|
47 |
+
public function setPassword( $password ) {
|
48 |
+
$this->password = $password;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function setPublisherId( $publisher_id ) {
|
52 |
+
$this->publisher_id = $publisher_id;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @link: http://publisher.affili.net/Solutions/Webservices_Webservices.aspx?nr=1&pnp=54#Voucher
|
57 |
+
*/
|
58 |
+
public function search( $keywords, array $options ) {
|
59 |
+
$options['PublisherId'] = $this->publisher_id;
|
60 |
+
$options['Password'] = $this->password;
|
61 |
+
$options['Query'] = $keywords;
|
62 |
+
|
63 |
+
// All fields are required
|
64 |
+
$defaults = array(
|
65 |
+
'ProgramId' => - 1,
|
66 |
+
'VoucherCode' => '',
|
67 |
+
'VoucherCodeContent' => - 1,
|
68 |
+
'StartDate' => '',
|
69 |
+
'EndDate' => '',
|
70 |
+
'VoucherType' => - 1,
|
71 |
+
'PartnershipStatus' => 0,
|
72 |
+
'MinimumOrderValue' => - 1,
|
73 |
+
'CustomerRestriction' => 0,
|
74 |
+
'ExclusivesOnly' => 'false',
|
75 |
+
'CurrentPage' => 1,
|
76 |
+
'PageSize' => 10,
|
77 |
+
'OrderBy' => 1,
|
78 |
+
'SortDesc' => 'true',
|
79 |
+
);
|
80 |
+
|
81 |
+
foreach ( $defaults as $key => $value ) {
|
82 |
+
if ( ! isset( $options[ $key ] ) || $options[ $key ] === '' ) {
|
83 |
+
$options[ $key ] = $value;
|
84 |
+
}
|
85 |
+
}
|
86 |
+
$response = $this->restGet( '/SearchVoucherCodes', $options );
|
87 |
+
|
88 |
+
return $this->_decodeResponse( $response );
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @link: http://publisher.affili.net/HtmlContent/de/downloads/Web%20Services/Documentation_GetPrograms.pdf
|
93 |
+
* @todo
|
94 |
+
*/
|
95 |
+
public function getPrograms() {
|
96 |
+
throw new \Exception( 'This method not implemented yet.' );
|
97 |
+
}
|
|
|
|
|
|
|
98 |
|
99 |
}
|
application/libs/amazon/AmazonProduct.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\amazon;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -58,363 +58,369 @@ use ContentEgg\application\libs\RestClient;
|
|
58 |
*/
|
59 |
class AmazonProduct extends RestClient {
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\amazon;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
58 |
*/
|
59 |
class AmazonProduct extends RestClient {
|
60 |
|
61 |
+
const API_VERSION = '2011-08-01';
|
62 |
+
|
63 |
+
private $_access_key_id;
|
64 |
+
private $_secret_access_key;
|
65 |
+
private $_associate_tag;
|
66 |
+
private $_timestamp = null;
|
67 |
+
private $_locale;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @var array Response Format Types
|
71 |
+
*/
|
72 |
+
protected $_responseTypes = array(
|
73 |
+
'xml',
|
74 |
+
);
|
75 |
+
|
76 |
+
//private static $_httpClient;
|
77 |
+
|
78 |
+
public function __construct( $access_key_id, $secret_access_key, $associate_tag ) {
|
79 |
+
$this->_access_key_id = $access_key_id;
|
80 |
+
$this->_secret_access_key = $secret_access_key;
|
81 |
+
$this->setAssociateTag( $associate_tag );
|
82 |
+
$this->setLocale( 'us' );
|
83 |
+
$this->setResponseType( 'xml' );
|
84 |
+
}
|
85 |
+
|
86 |
+
public function setAssociateTag( $associate_tag ) {
|
87 |
+
$this->_associate_tag = $associate_tag;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Sets the locale passed when making a query to Amazon
|
92 |
+
* Currently us, uk, de, jp, fr, ca, cn, it, es are supported
|
93 |
+
*
|
94 |
+
* @param string $locale The new locale to use
|
95 |
+
*
|
96 |
+
* @link: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Locales.html
|
97 |
+
*/
|
98 |
+
public function setLocale( $locale ) {
|
99 |
+
// не все urls соответствуют документации
|
100 |
+
// @link: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AnatomyOfaRESTRequest.html
|
101 |
+
$urls = array(
|
102 |
+
'us' => 'http://ecs.amazonaws.com/onca/xml',
|
103 |
+
'uk' => 'http://ecs.amazonaws.co.uk/onca/xml',
|
104 |
+
'de' => 'http://ecs.amazonaws.de/onca/xml',
|
105 |
+
'jp' => 'http://webservices.amazon.co.jp/onca/xml',
|
106 |
+
'cn' => 'http://webservices.amazon.cn/onca/xml',
|
107 |
+
'fr' => 'http://ecs.amazonaws.fr/onca/xml',
|
108 |
+
'it' => 'http://webservices.amazon.it/onca/xml',
|
109 |
+
'es' => 'http://webservices.amazon.es/onca/xml',
|
110 |
+
'ca' => 'http://ecs.amazonaws.ca/onca/xml',
|
111 |
+
'br' => 'http://webservices.amazon.com.br/onca/xml',
|
112 |
+
'in' => 'http://webservices.amazon.in/onca/xml',
|
113 |
+
'mx' => 'http://webservices.amazon.com.mx/onca/xml',
|
114 |
+
'au' => 'http://webservices.amazon.com.au/onca/xml',
|
115 |
+
);
|
116 |
+
if ( ! isset( $urls[ $locale ] ) ) {
|
117 |
+
throw new \Exception( 'Invalid amazon locale' );
|
118 |
+
}
|
119 |
+
$this->_locale = $locale;
|
120 |
+
$this->setUri( $urls[ $locale ] );
|
121 |
+
|
122 |
+
return true;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Sets a timestamp (for debugging)
|
127 |
+
*
|
128 |
+
* @param integer $time A timestamp
|
129 |
+
*/
|
130 |
+
public function setTimestamp( $time ) {
|
131 |
+
$this->_timestamp = $time;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Searches for products
|
136 |
+
*
|
137 |
+
* Example:
|
138 |
+
* <code>
|
139 |
+
* <?php
|
140 |
+
* $amazon = new Services_Amazon('[your Access Key ID here]', '[your Secret Access key here]');
|
141 |
+
* $options = array();
|
142 |
+
* $options['Keywords'] = 'sushi';
|
143 |
+
* $options['Sort'] = 'salesrank';
|
144 |
+
* $options['ResponseGroup'] = 'ItemIds,ItemAttributes,Images';
|
145 |
+
* $result = $amazon->ItemSearch('Books', $options);
|
146 |
+
* ?>
|
147 |
+
* </code>
|
148 |
+
*
|
149 |
+
* @access public
|
150 |
+
*
|
151 |
+
* @param string $search_index A search index
|
152 |
+
* @param array $options The optional parameters
|
153 |
+
*
|
154 |
+
* @return array The array of information returned by the query
|
155 |
+
*/
|
156 |
+
public function ItemSearch( $search_index, $options = array() ) {
|
157 |
+
$params = $options;
|
158 |
+
$params['Operation'] = 'ItemSearch';
|
159 |
+
$params['SearchIndex'] = $search_index;
|
160 |
+
|
161 |
+
$response = $this->signedGet( '', $params );
|
162 |
+
$decoded = $this->_decodeResponse( $response );
|
163 |
+
|
164 |
+
return $this->_parseResult( $decoded );
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Retrieves information for products
|
169 |
+
*
|
170 |
+
* Example:
|
171 |
+
* <code>
|
172 |
+
* <?php
|
173 |
+
* $amazon = new Services_Amazon('[your Access Key ID here]', '[your Secret Access key here]');
|
174 |
+
* $options = array();
|
175 |
+
* $options['ResponseGroup'] = 'Large';
|
176 |
+
* $result = $amazon->ItemLookup('[ASIN(s)]', $options);
|
177 |
+
* ?>
|
178 |
+
* </code>
|
179 |
+
*
|
180 |
+
* @access public
|
181 |
+
*
|
182 |
+
* @param string $item_id Product IDs
|
183 |
+
* @param array $options The optional parameters
|
184 |
+
*
|
185 |
+
* @return array The array of information returned by the query
|
186 |
+
* @see ItemSearch()
|
187 |
+
*/
|
188 |
+
function ItemLookup( $item_id, $options = array() ) {
|
189 |
+
$params = $options;
|
190 |
+
$params['Operation'] = 'ItemLookup';
|
191 |
+
if ( is_array( $item_id ) ) {
|
192 |
+
$item_id = implode( ',', $item_id );
|
193 |
+
}
|
194 |
+
// One or more (up to ten) positive integers that uniquely identify an item.
|
195 |
+
// The meaning of the number is specified by IdType.
|
196 |
+
$params['ItemId'] = $item_id;
|
197 |
+
|
198 |
+
$response = $this->signedGet( '', $params );
|
199 |
+
$decoded = $this->_decodeResponse( $response );
|
200 |
+
|
201 |
+
return $this->_parseResult( $decoded );
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* Encode URL according to RFC 3986
|
206 |
+
*
|
207 |
+
* @param string $str UTF-8 string
|
208 |
+
*
|
209 |
+
* @return string Encoded string
|
210 |
+
*/
|
211 |
+
private function _urlencode( $str ) {
|
212 |
+
return str_replace( '%7E', '~', rawurlencode( $str ) );
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Create an HMAC-SHA256
|
217 |
+
*
|
218 |
+
* @param string $string_to_sign
|
219 |
+
* @param string $secret_access_key
|
220 |
+
*
|
221 |
+
* @return string hash
|
222 |
+
*/
|
223 |
+
private function _hash( $string_to_sign, $secret_access_key ) {
|
224 |
+
if ( function_exists( 'hash_hmac' ) ) {
|
225 |
+
return hash_hmac( 'sha256', $string_to_sign, $secret_access_key, true );
|
226 |
+
} elseif ( function_exists( 'mhash' ) ) {
|
227 |
+
return mhash( MHASH_SHA256, $string_to_sign, $secret_access_key );
|
228 |
+
} else {
|
229 |
+
throw new \Exception( 'hash_hmac or mhash function is required.' );
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Builds a URL
|
235 |
+
*
|
236 |
+
* @access private
|
237 |
+
*
|
238 |
+
* @param array $params
|
239 |
+
*
|
240 |
+
* @return string URL
|
241 |
+
*/
|
242 |
+
function _buildUrl( $params ) {
|
243 |
+
$params['Service'] = 'AWSECommerceService';
|
244 |
+
$params['AWSAccessKeyId'] = $this->_access_key_id;
|
245 |
+
if ( ! empty( $this->_associate_tag ) ) {
|
246 |
+
$params['AssociateTag'] = $this->_associate_tag;
|
247 |
+
}
|
248 |
+
$params['Timestamp'] = gmdate( 'Y-m-d\TH:i:s\Z', is_null( $this->_timestamp ) ? time() : $this->_timestamp );
|
249 |
+
$params['Version'] = self::API_VERSION;
|
250 |
+
|
251 |
+
// sort parameters
|
252 |
+
ksort( $params );
|
253 |
+
|
254 |
+
// create a canonical string
|
255 |
+
$canonical_string = '';
|
256 |
+
foreach ( $params as $k => $v ) {
|
257 |
+
$canonical_string .= '&' . $this->_urlencode( $k ) . '=' . $this->_urlencode( $v );
|
258 |
+
}
|
259 |
+
$canonical_string = substr( $canonical_string, 1 );
|
260 |
+
|
261 |
+
// create a signature for request
|
262 |
+
$parsed_url = parse_url( $this->getUri() );
|
263 |
+
$string_to_sign = "GET\n{$parsed_url['host']}\n{$parsed_url['path']}\n{$canonical_string}";
|
264 |
+
$signature = $this->_hash( $string_to_sign, $this->_secret_access_key );
|
265 |
+
$signature = base64_encode( $signature );
|
266 |
+
|
267 |
+
// create a signed url
|
268 |
+
$url = $this->getUri() . '?' . $canonical_string . '&Signature=' . $this->_urlencode( $signature );
|
269 |
+
|
270 |
+
return $url;
|
271 |
+
}
|
272 |
+
|
273 |
+
public function signedGet( $path, array $query = null ) {
|
274 |
+
$url = $this->_buildUrl( $query );
|
275 |
+
|
276 |
+
return $this->restGet( $url, $query );
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Parses raw XML result
|
281 |
+
*
|
282 |
+
* @param string $raw_result
|
283 |
+
*
|
284 |
+
* @return array amazon items.
|
285 |
+
*/
|
286 |
+
private function _parseResult( $data ) {
|
287 |
+
// Обработка ошибки
|
288 |
+
if ( isset( $data['Items']['Request']['Errors']['Error'] ) ) {
|
289 |
+
$err_message = 'Unknown error';
|
290 |
+
$errors = $data['Items']['Request']['Errors']['Error'];
|
291 |
+
if ( isset( $errors['Message'] ) ) {
|
292 |
+
$err_message = $errors['Message'];
|
293 |
+
}
|
294 |
+
|
295 |
+
throw new \Exception( $err_message );
|
296 |
+
}
|
297 |
+
|
298 |
+
if ( ! isset( $data['Items']['Item'] ) ) {
|
299 |
+
return array();
|
300 |
+
}
|
301 |
+
if ( ! isset( $data['Items']['Item'][0] ) && isset( $data['Items']['Item']['ASIN'] ) ) {
|
302 |
+
$data['Items']['Item'] = array( $data['Items']['Item'] );
|
303 |
+
}
|
304 |
+
|
305 |
+
return $data;
|
306 |
+
}
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Amazon customer reviews parser
|
310 |
+
*
|
311 |
+
* @param string $url iframe reviews url
|
312 |
+
*/
|
313 |
+
public function parseCustomerReviews( $url, $locale = 'us' ) {
|
314 |
+
try {
|
315 |
+
$html = $this->restGet( $url );
|
316 |
+
} catch ( \Exception $e ) {
|
317 |
+
return array();
|
318 |
+
}
|
319 |
+
if ( ! $html ) {
|
320 |
+
return array();
|
321 |
+
}
|
322 |
+
|
323 |
+
// Исправим кодировку
|
324 |
+
// US, UK - ISO-8859-1
|
325 |
+
// DE, FR, CA - ISO-8859-15
|
326 |
+
// JP - Shift_JIS
|
327 |
+
if ( $locale == "jp" && function_exists( 'iconv' ) ) {
|
328 |
+
$html = iconv( "Shift_JIS", "utf-8", $html );
|
329 |
+
} else {
|
330 |
+
$html = utf8_encode( $html );
|
331 |
+
}
|
332 |
+
|
333 |
+
if ( strstr( $html, 'There are no customer reviews for this item' ) ) {
|
334 |
+
return array();
|
335 |
+
}
|
336 |
+
$result = array();
|
337 |
+
|
338 |
+
// Сначала парсим общую информацию по обзорам
|
339 |
+
$totalreviews = $avarage_rating = 0;
|
340 |
+
preg_match( "/=\"crIFrameHeaderLeftColumn.+?=\"crIFrameHeaderHistogram/msi", $html, $header_html );
|
341 |
+
if ( $header_html ) {
|
342 |
+
$header_html = $header_html[0];
|
343 |
+
|
344 |
+
//prnx($header_html);
|
345 |
+
// Total Reviews
|
346 |
+
preg_match( '/>([\d,]+)\s.+?\)<\/span>/', $header_html, $matches );
|
347 |
+
$totalreviews = $matches ? $matches[1] : 0;
|
348 |
+
|
349 |
+
// Avarage Rating
|
350 |
+
preg_match( '/<img.+?alt="(\d\.\d).+?"/', $header_html, $matches );
|
351 |
+
$avarage_rating = $matches ? $matches[1] : 0;
|
352 |
+
unset( $header_html );
|
353 |
+
}
|
354 |
+
$result['AverageRating'] = $avarage_rating;
|
355 |
+
$result['TotalReviews'] = $totalreviews;
|
356 |
+
|
357 |
+
// Парсим блоки с Review
|
358 |
+
preg_match_all( "/<\!\-\-\sBOUNDARY\s\-\->(.+?)<div\sstyle=\"padding-top:\s10px;\sclear:\sboth;\swidth:\s100%;\">/msi", $html, $matches );
|
359 |
+
unset( $html );
|
360 |
+
if ( ! $matches ) {
|
361 |
+
return array();
|
362 |
+
}
|
363 |
+
|
364 |
+
$reviews = array();
|
365 |
+
$i = 0;
|
366 |
+
foreach ( $matches[1] as $review_blok ) {
|
367 |
+
$reviews[ $i ] = array();
|
368 |
+
|
369 |
+
// Reviews Content
|
370 |
+
preg_match( "/class=\"reviewText\">(.+?)<\/div>/msi", $review_blok, $matches );
|
371 |
+
if ( ! $matches ) {
|
372 |
+
preg_match( "/^.+<\/div>?(.+?)\z/msi", $review_blok, $matches );
|
373 |
+
}
|
374 |
+
if ( ! $matches ) {
|
375 |
+
continue;
|
376 |
+
}
|
377 |
+
$content = '';
|
378 |
+
$content = $matches[1];
|
379 |
+
$content = preg_replace( "/<a.+?<\/a>/", "", $content );
|
380 |
+
$content = trim( strip_tags( $content ) );
|
381 |
+
$content = preg_replace( "/\r/", " ", $content );
|
382 |
+
$content = preg_replace( "/\n/", " ", $content );
|
383 |
+
if ( ! $content ) {
|
384 |
+
continue;
|
385 |
+
}
|
386 |
+
$reviews[ $i ]['Content'] = $content;
|
387 |
+
|
388 |
+
// Reviews Summary & Date
|
389 |
+
preg_match( "/<b>(.+)<\/b>,\s<nobr>(.+)<\/nobr>/", $review_blok, $matches );
|
390 |
+
if ( $matches ) {
|
391 |
+
$reviews[ $i ]['Summary'] = trim( strip_tags( $matches[1] ) ); //Summary
|
392 |
+
$reviews[ $i ]['Date'] = strtotime( trim( strip_tags( $matches[2] ) ) ); //Date
|
393 |
+
if ( ! $reviews[ $i ]['Date'] ) {
|
394 |
+
$reviews[ $i ]['Date'] = time();
|
395 |
+
}
|
396 |
+
} else {
|
397 |
+
$reviews[ $i ]['Summary'] = '';
|
398 |
+
$reviews[ $i ]['Date'] = time();
|
399 |
+
}
|
400 |
+
|
401 |
+
// Customer Name
|
402 |
+
preg_match( "/<span.+?>(.+?)<\/span><\/a>/", $review_blok, $matches );
|
403 |
+
if ( $matches ) {
|
404 |
+
$reviews[ $i ]['Name'] = trim( strip_tags( $matches[1] ) );
|
405 |
+
} else {
|
406 |
+
$reviews[ $i ]['Name'] = '';
|
407 |
+
}
|
408 |
+
|
409 |
+
// Rating
|
410 |
+
preg_match( '/<img.+?alt="(\d\.\d).+?"/', $review_blok, $matches );
|
411 |
+
if ( $matches ) {
|
412 |
+
$reviews[ $i ]['Rating'] = trim( strip_tags( $matches[1] ) );
|
413 |
+
} else {
|
414 |
+
$reviews[ $i ]['Rating'] = 4.0;
|
415 |
+
}
|
416 |
+
|
417 |
+
$i ++;
|
418 |
+
}
|
419 |
+
unset( $matches );
|
420 |
+
$result['Reviews'] = $reviews;
|
421 |
+
|
422 |
+
//prnx($result);
|
423 |
+
return $result;
|
424 |
+
}
|
425 |
|
426 |
}
|
application/libs/bing/BingSearch.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\bing;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,112 +12,116 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2015 keywordrush.com
|
15 |
-
*
|
16 |
* @link: https://msdn.microsoft.com/en-us/library/dd251056.aspx
|
17 |
* @link: https://onedrive.live.com/view.aspx?resid=9C9479871FBFA822!112&app=Word&authkey=!ANNnJQREB0kDC04
|
18 |
*
|
19 |
*/
|
20 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
21 |
|
22 |
class BingSearch extends RestClient {
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
122 |
|
123 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\bing;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2015 keywordrush.com
|
15 |
+
*
|
16 |
* @link: https://msdn.microsoft.com/en-us/library/dd251056.aspx
|
17 |
* @link: https://onedrive.live.com/view.aspx?resid=9C9479871FBFA822!112&app=Word&authkey=!ANNnJQREB0kDC04
|
18 |
*
|
19 |
*/
|
20 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
21 |
|
22 |
class BingSearch extends RestClient {
|
23 |
|
24 |
+
const API_URI_BASE = 'https://api.datamarket.azure.com';
|
25 |
+
|
26 |
+
private $accountKey = null;
|
27 |
+
private $serviceOperation = 'Web';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @var array Response Format Types
|
31 |
+
*/
|
32 |
+
protected $_responseTypes = array(
|
33 |
+
'json'
|
34 |
+
);
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Constructor
|
38 |
+
*/
|
39 |
+
public function __construct( $accountKey, $responseType = 'json' ) {
|
40 |
+
$this->setAccountKey( $accountKey );
|
41 |
+
$this->setResponseType( $responseType );
|
42 |
+
$this->setUri( self::API_URI_BASE );
|
43 |
+
}
|
44 |
+
|
45 |
+
public function setAccountKey( $accountKey ) {
|
46 |
+
$this->accountKey = $accountKey;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function getAccountKey() {
|
50 |
+
return $this->accountKey;
|
51 |
+
}
|
52 |
+
|
53 |
+
public function setServiceOperation( $serviceOperation = 'Web' ) {
|
54 |
+
//@todo: Composite Service Operation
|
55 |
+
if ( ! in_array( $serviceOperation, array(
|
56 |
+
'Web',
|
57 |
+
'Image',
|
58 |
+
'News',
|
59 |
+
'RelatedSearch',
|
60 |
+
'SpellingSuggestion',
|
61 |
+
'Video'
|
62 |
+
) ) ) {
|
63 |
+
throw new \Exception( 'Wrong Service Operation param.' );
|
64 |
+
}
|
65 |
+
$this->serviceOperation = $serviceOperation;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function getServiceOperation() {
|
69 |
+
return $this->serviceOperation;
|
70 |
+
}
|
71 |
+
|
72 |
+
public function search( $query, $source = 'Web', array $params = array() ) {
|
73 |
+
$this->setServiceOperation( $source );
|
74 |
+
|
75 |
+
$_query = array();
|
76 |
+
$_query['Query'] = $query;
|
77 |
+
// Specifies the format of the OData response. Current options are Atom (for XML) or JSON.
|
78 |
+
$_query['$format'] = $this->getResponseType();
|
79 |
+
foreach ( $params as $key => $param ) {
|
80 |
+
switch ( $key ) {
|
81 |
+
case '$top': // Specifies the number of results to return.
|
82 |
+
$_query[ $key ] = ( (int) $param > 50 ) ? 50 : (int) $param;
|
83 |
+
break;
|
84 |
+
case '$skip': // Specifies the offset requested for the starting point of results returned.
|
85 |
+
$_query[ $key ] = ( (int) $param > 1000 ) ? 1000 : (int) $param;
|
86 |
+
break;
|
87 |
+
|
88 |
+
case 'Market':
|
89 |
+
$_query[ $key ] = $param;
|
90 |
+
break;
|
91 |
+
case 'Adult':
|
92 |
+
$_query[ $key ] = ( ! in_array( $param, array(
|
93 |
+
'Off',
|
94 |
+
'Moderate',
|
95 |
+
'Strict'
|
96 |
+
) ) ) ? 'Moderate' : $param;
|
97 |
+
break;
|
98 |
+
case 'ImageFilters':
|
99 |
+
// format: &Image.Filters=Color:Monochrome&Image.Filters=Style:Photo
|
100 |
+
$_query[ $key ] = $param;
|
101 |
+
break;
|
102 |
+
case 'NewsSortBy': //for News
|
103 |
+
case 'NewsCategory': //for News
|
104 |
+
case 'WebFileType': //for Web
|
105 |
+
$_query[ $key ] = $param;
|
106 |
+
break;
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
$add_url = '';
|
111 |
+
|
112 |
+
foreach ( $_query as $k => $q ) {
|
113 |
+
if ( ! strstr( $k, '$' ) ) {
|
114 |
+
$_query[ $k ] = "'" . $q . "'";
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
//$add_url = "?ImageFilters='Style:Photo'&ImageFilters='Size:Small'";
|
119 |
+
// Bing API Basic Authorization
|
120 |
+
$this->setCustomHeaders( array( 'Authorization' => 'Basic ' . base64_encode( $this->getAccountKey() . ":" . $this->getAccountKey() ) ) );
|
121 |
+
|
122 |
+
$response = $this->restGet( '/Bing/Search/' . $this->getServiceOperation() . $add_url, $_query );
|
123 |
+
|
124 |
+
return $this->_decodeResponse( $response );
|
125 |
+
}
|
126 |
|
127 |
}
|
application/libs/bing/CognitiveSearch.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\bing;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,67 +12,64 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2021 keywordrush.com
|
15 |
-
*
|
16 |
* @link: https://www.microsoft.com/en-us/bing/apis/bing-image-search-api
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CognitiveSearch extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
$this->setCustomHeaders(array('Ocp-Apim-Subscription-Key' => $this->getSubscriptionKey()));
|
75 |
-
return parent::restGet($path, $query);
|
76 |
-
}
|
77 |
|
78 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\bing;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2021 keywordrush.com
|
15 |
+
*
|
16 |
* @link: https://www.microsoft.com/en-us/bing/apis/bing-image-search-api
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CognitiveSearch extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://api.bing.microsoft.com/v7.0';
|
24 |
+
|
25 |
+
private $subscription_key = null;
|
26 |
+
protected $_responseTypes = array(
|
27 |
+
'json'
|
28 |
+
);
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Constructor
|
32 |
+
*/
|
33 |
+
public function __construct( $subscription_key ) {
|
34 |
+
$this->setSubscriptionKey( $subscription_key );
|
35 |
+
$this->setUri( self::API_URI_BASE );
|
36 |
+
$this->setResponseType( 'json' );
|
37 |
+
}
|
38 |
+
|
39 |
+
public function setSubscriptionKey( $subscription_key ) {
|
40 |
+
$this->subscription_key = $subscription_key;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function getSubscriptionKey() {
|
44 |
+
return $this->subscription_key;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Image Search API
|
49 |
+
* @link: https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference
|
50 |
+
*/
|
51 |
+
public function images( $query, $params = array() ) {
|
52 |
+
$params['q'] = $query;
|
53 |
+
$response = $this->restGet( '/images/search', $params );
|
54 |
+
|
55 |
+
return $this->_decodeResponse( $response );
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Autosuggest API
|
60 |
+
* @link: https://msdn.microsoft.com/en-us/library/mt711406.aspx
|
61 |
+
*/
|
62 |
+
public function autosuggest( $query, $params = array() ) {
|
63 |
+
$params['q'] = $query;
|
64 |
+
$response = $this->restGet( '/suggestions', $params );
|
65 |
+
|
66 |
+
return $this->_decodeResponse( $response );
|
67 |
+
}
|
68 |
+
|
69 |
+
public function restGet( $path, array $query = null ) {
|
70 |
+
$this->setCustomHeaders( array( 'Ocp-Apim-Subscription-Key' => $this->getSubscriptionKey() ) );
|
71 |
+
|
72 |
+
return parent::restGet( $path, $query );
|
73 |
+
}
|
|
|
|
|
|
|
74 |
|
75 |
}
|
application/libs/cj/CjLinksRest.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\cj;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -11,45 +11,45 @@ use ContentEgg\application\libs\RestClient;
|
|
11 |
*
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
-
* @copyright Copyright © 2017 keywordrush.com
|
15 |
-
*
|
16 |
* @link: http://cjsupport.custhelp.com/app/answers/detail/a_id/1552/kw/api
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CjLinksRest extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\cj;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
11 |
*
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
+
* @copyright Copyright © 2017 keywordrush.com
|
15 |
+
*
|
16 |
* @link: http://cjsupport.custhelp.com/app/answers/detail/a_id/1552/kw/api
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CjLinksRest extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://linksearch.api.cj.com/v2';
|
24 |
+
|
25 |
+
private $access_token;
|
26 |
+
private $dev_key;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array Response Format Types
|
30 |
+
*/
|
31 |
+
protected $_responseTypes = array(
|
32 |
+
'xml',
|
33 |
+
);
|
34 |
+
|
35 |
+
public function __construct( $access_token, $dev_key = '', $responseType = 'xml' ) {
|
36 |
+
$this->setResponseType( $responseType );
|
37 |
+
$this->setUri( self::API_URI_BASE );
|
38 |
+
$this->access_token = $access_token;
|
39 |
+
$this->dev_key = $dev_key;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function search( $query, array $params = array() ) {
|
43 |
+
$params['keywords'] = $query;
|
44 |
+
if ( $this->access_token ) {
|
45 |
+
$this->setCustomHeaders( array( 'Authorization' => 'Bearer ' . $this->access_token ) );
|
46 |
+
} else {
|
47 |
+
$this->setCustomHeaders( array( 'Authorization' => $this->dev_key ) );
|
48 |
+
}
|
49 |
+
|
50 |
+
$response = $this->restGet( '/link-search', $params );
|
51 |
+
|
52 |
+
return $this->_decodeResponse( $response );
|
53 |
+
}
|
54 |
|
55 |
}
|
application/libs/gdeslon/GdeSlonApi.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\gdeslon;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -15,74 +15,75 @@ use ContentEgg\application\libs\RestClient;
|
|
15 |
*
|
16 |
* @link: https://www.gdeslon.ru/affiliate-examples/xml-api
|
17 |
*/
|
18 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
19 |
|
20 |
class GdeSlonApi extends RestClient {
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
87 |
|
88 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\gdeslon;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
15 |
*
|
16 |
* @link: https://www.gdeslon.ru/affiliate-examples/xml-api
|
17 |
*/
|
18 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
19 |
|
20 |
class GdeSlonApi extends RestClient {
|
21 |
|
22 |
+
const API_URI_BASE = 'http://api.gdeslon.ru';
|
23 |
+
|
24 |
+
protected $_api_key;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @var array Response Format Types
|
28 |
+
*/
|
29 |
+
protected $_responseTypes = array(
|
30 |
+
'xml',
|
31 |
+
);
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Constructor
|
35 |
+
*
|
36 |
+
* @param string $responseType
|
37 |
+
*/
|
38 |
+
public function __construct( $api_key ) {
|
39 |
+
$this->setApiKey( $api_key );
|
40 |
+
$this->setResponseType( 'xml' );
|
41 |
+
$this->setUri( self::API_URI_BASE );
|
42 |
+
}
|
43 |
+
|
44 |
+
public function setApiKey( $api_key ) {
|
45 |
+
$this->_api_key = $api_key;
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getApiKey() {
|
49 |
+
return $this->_api_key;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Products
|
54 |
+
*/
|
55 |
+
public function search( $keywords, array $options ) {
|
56 |
+
$options['q'] = $keywords;
|
57 |
+
$options['_gs_at'] = $this->getApiKey();
|
58 |
+
if ( ! empty( $options['m'] ) && is_array( $options['m'] ) ) {
|
59 |
+
$options['m'] = join( ',', $options['m'] );
|
60 |
+
}
|
61 |
+
if ( ! empty( $options['tid'] ) && is_array( $options['tid'] ) ) {
|
62 |
+
$options['tid'] = join( ',', $options['tid'] );
|
63 |
+
}
|
64 |
+
$response = $this->restGet( '/api/search.xml', $options );
|
65 |
+
|
66 |
+
return $this->_decodeResponse( $response );
|
67 |
+
}
|
68 |
+
|
69 |
+
public function product( $product_id ) {
|
70 |
+
if ( is_array( $product_id ) ) {
|
71 |
+
$product_id = join( ',', $product_id );
|
72 |
+
}
|
73 |
+
|
74 |
+
$options = array();
|
75 |
+
$options['articles'] = $product_id;
|
76 |
+
$options['_gs_at'] = $this->getApiKey();
|
77 |
+
|
78 |
+
$response = $this->restGet( '/api/search.xml', $options );
|
79 |
+
|
80 |
+
return $this->_decodeResponse( $response );
|
81 |
+
}
|
82 |
+
|
83 |
+
public function getMerhants() {
|
84 |
+
$response = $this->restGet( '/merchants.json' );
|
85 |
+
|
86 |
+
return json_decode( $response, true );
|
87 |
+
}
|
88 |
|
89 |
}
|
application/libs/google/CustomSearchApi.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,52 +12,52 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
-
*
|
16 |
* @link: https://developers.google.com/custom-search/json-api/v1/overview
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CustomSearchApi extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
+
*
|
16 |
* @link: https://developers.google.com/custom-search/json-api/v1/overview
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class CustomSearchApi extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://www.googleapis.com/customsearch/v1';
|
24 |
+
|
25 |
+
protected $cx;
|
26 |
+
protected $key;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array Response Format Types
|
30 |
+
*/
|
31 |
+
protected $_responseTypes = array(
|
32 |
+
'atom',
|
33 |
+
'json',
|
34 |
+
);
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Constructor
|
38 |
+
*
|
39 |
+
* @param string $responseType
|
40 |
+
*/
|
41 |
+
public function __construct( $cx, $key, $responseType = 'json' ) {
|
42 |
+
$this->cx = $cx;
|
43 |
+
$this->key = $key;
|
44 |
+
$this->setResponseType( $responseType );
|
45 |
+
$this->setUri( self::API_URI_BASE );
|
46 |
+
}
|
47 |
+
|
48 |
+
public function images( $query, array $options = array() ) {
|
49 |
+
$options['q'] = $query;
|
50 |
+
$options['searchType'] = 'image';
|
51 |
+
$response = $this->restGet( '', $options );
|
52 |
+
|
53 |
+
return $this->_decodeResponse( $response );
|
54 |
+
}
|
55 |
+
|
56 |
+
public function restGet( $path, array $query = null ) {
|
57 |
+
$query['cx'] = $this->cx;
|
58 |
+
$query['key'] = $this->key;
|
59 |
+
|
60 |
+
return parent::restGet( $path, $query );
|
61 |
+
}
|
62 |
|
63 |
}
|
application/libs/google/FreebaseRest.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -17,119 +17,121 @@ use ContentEgg\application\libs\RestClient;
|
|
17 |
* FreebaseRest класс для работы с Freebase API.
|
18 |
* @link: https://developers.google.com/freebase/index
|
19 |
*/
|
20 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
21 |
|
22 |
class FreebaseRest extends RestClient {
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
134 |
|
135 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
17 |
* FreebaseRest класс для работы с Freebase API.
|
18 |
* @link: https://developers.google.com/freebase/index
|
19 |
*/
|
20 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
21 |
|
22 |
class FreebaseRest extends RestClient {
|
23 |
|
24 |
+
const API_URI_BASE = 'https://www.googleapis.com/freebase/v1';
|
25 |
+
|
26 |
+
private $apiKey;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* @var array Response Format Types
|
30 |
+
*/
|
31 |
+
protected $_responseTypes = array(
|
32 |
+
'json',
|
33 |
+
);
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Constructor
|
37 |
+
*
|
38 |
+
* @param string API Key
|
39 |
+
* @param string $responseType
|
40 |
+
*/
|
41 |
+
public function __construct( $key ) {
|
42 |
+
$this->setUri( self::API_URI_BASE );
|
43 |
+
$this->setApiKey( $key );
|
44 |
+
$this->setResponseType( 'json' );
|
45 |
+
}
|
46 |
+
|
47 |
+
public function setApiKey( $key ) {
|
48 |
+
$this->apiKey = $key;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Freebase Search API
|
53 |
+
* @link: https://developers.google.com/freebase/v1/search
|
54 |
+
*
|
55 |
+
* @param string $query
|
56 |
+
* @param array $params
|
57 |
+
*/
|
58 |
+
public function search( $query, $params ) {
|
59 |
+
$_query = array();
|
60 |
+
$_query['query'] = $query;
|
61 |
+
$_query['key'] = $this->apiKey;
|
62 |
+
foreach ( $params as $key => $param ) {
|
63 |
+
switch ( $key ) {
|
64 |
+
case 'lang':
|
65 |
+
case 'filter':
|
66 |
+
$_query[ $key ] = $param;
|
67 |
+
break;
|
68 |
+
case 'limit':
|
69 |
+
case 'start':
|
70 |
+
$_query[ $key ] = ( (int) $param > 100 ) ? 100 : (int) $param;
|
71 |
+
break;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
$response = $this->restGet( '/search', $_query );
|
75 |
+
|
76 |
+
return $this->_decodeResponse( $response );
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Freebase Topic API
|
81 |
+
* @link: https://developers.google.com/freebase/v1/topic-overview
|
82 |
+
*
|
83 |
+
* @param string $topic_id Topic ID
|
84 |
+
* @param string $filter
|
85 |
+
*/
|
86 |
+
public function topic( $topic_id, $lang = null, $filter = null ) {
|
87 |
+
$_query = array();
|
88 |
+
$_query['key'] = $this->apiKey;
|
89 |
+
if ( $lang ) {
|
90 |
+
$_query['lang'] = $lang;
|
91 |
+
}
|
92 |
+
if ( $filter ) {
|
93 |
+
$_query['filter'] = $filter;
|
94 |
+
}
|
95 |
+
$response = $this->restGet( '/topic' . $topic_id, $_query );
|
96 |
+
|
97 |
+
return $this->_decodeResponse( $response );
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Сначала находит ID топиков, а потом запрашивает подробную
|
102 |
+
* инфу по каждому топику.
|
103 |
+
*
|
104 |
+
* @param string $query
|
105 |
+
* @param array $params
|
106 |
+
* @param string $filter
|
107 |
+
*/
|
108 |
+
public function fullSearch( $query, $params, $filter = null ) {
|
109 |
+
|
110 |
+
$results = $this->search( $query, $params );
|
111 |
+
if ( empty( $results['result'] ) ) {
|
112 |
+
return array();
|
113 |
+
}
|
114 |
+
|
115 |
+
$data = array();
|
116 |
+
foreach ( $results['result'] as $res ) {
|
117 |
+
if ( empty( $res['mid'] ) ) {
|
118 |
+
continue;
|
119 |
+
}
|
120 |
+
try {
|
121 |
+
if ( ! empty( $params['lang'] ) ) {
|
122 |
+
$lang = $params['lang'];
|
123 |
+
} else {
|
124 |
+
$lang = null;
|
125 |
+
}
|
126 |
+
$topic = $this->topic( $res['mid'], $lang, $filter );
|
127 |
+
} catch ( Exception $e ) {
|
128 |
+
// Не получили инфу по топику. Пропускаем?
|
129 |
+
continue;
|
130 |
+
}
|
131 |
+
$data[] = $topic;
|
132 |
+
}
|
133 |
+
|
134 |
+
return $data;
|
135 |
+
}
|
136 |
|
137 |
}
|
application/libs/google/YouTubeSearch.php
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
defined( '\ABSPATH' ) || exit;
|
|
|
5 |
use ContentEgg\application\libs\RestClient;
|
6 |
|
7 |
/**
|
@@ -10,73 +11,71 @@ use ContentEgg\application\libs\RestClient;
|
|
10 |
* @author keywordrush.com <support@keywordrush.com>
|
11 |
* @link http://www.keywordrush.com/
|
12 |
* @copyright Copyright © 2015 keywordrush.com
|
13 |
-
*
|
14 |
* @link: https://developers.google.com/youtube/v3/docs/search/list
|
15 |
*
|
16 |
*/
|
17 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
18 |
|
19 |
class YouTubeSearch extends RestClient {
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$this->setResponseType($responseType);
|
38 |
-
$this->setUri(self::API_URI_BASE);
|
39 |
-
}
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
$_query['q'] = $query;
|
45 |
-
$_query['part'] = 'snippet';
|
46 |
-
$_query['videoEmbeddable'] = 'true';
|
47 |
-
$_query['type'] = 'video';
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
switch ($key)
|
56 |
-
{
|
57 |
-
case 'relevanceLanguage':
|
58 |
-
case 'order':
|
59 |
-
//case 'format':
|
60 |
-
case 'key':
|
61 |
-
case 'part':
|
62 |
-
case 'safeSearch':
|
63 |
-
case 'channelId':
|
64 |
-
case 'videoEmbeddable':
|
65 |
-
case 'type':
|
66 |
-
case 'videoLicense':
|
67 |
-
$_query[$key] = $param;
|
68 |
-
break;
|
69 |
-
case 'maxResults':
|
70 |
-
case 'pageToken':
|
71 |
-
$_query[$key] = ((int) $param > 50) ? 50 : (int) $param;
|
72 |
-
break;
|
73 |
-
case 'strict':
|
74 |
-
$_query[$key] = ((bool) $param) ? true : false;
|
75 |
-
break;
|
76 |
-
}
|
77 |
-
}
|
78 |
-
$response = $this->restGet('/search', $_query);
|
79 |
-
return $this->_decodeResponse($response);
|
80 |
-
}
|
81 |
|
82 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\google;
|
4 |
defined( '\ABSPATH' ) || exit;
|
5 |
+
|
6 |
use ContentEgg\application\libs\RestClient;
|
7 |
|
8 |
/**
|
11 |
* @author keywordrush.com <support@keywordrush.com>
|
12 |
* @link http://www.keywordrush.com/
|
13 |
* @copyright Copyright © 2015 keywordrush.com
|
14 |
+
*
|
15 |
* @link: https://developers.google.com/youtube/v3/docs/search/list
|
16 |
*
|
17 |
*/
|
18 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
19 |
|
20 |
class YouTubeSearch extends RestClient {
|
21 |
|
22 |
+
const API_URI_BASE = 'https://www.googleapis.com/youtube/v3';
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @var array Response Format Types
|
26 |
+
*/
|
27 |
+
protected $_responseTypes = array(
|
28 |
+
'atom',
|
29 |
+
'json',
|
30 |
+
);
|
31 |
|
32 |
+
/**
|
33 |
+
* Constructor
|
34 |
+
*
|
35 |
+
* @param string $responseType
|
36 |
+
*/
|
37 |
+
public function __construct( $responseType = 'json' ) {
|
38 |
+
$this->setResponseType( $responseType );
|
39 |
+
$this->setUri( self::API_URI_BASE );
|
40 |
+
}
|
41 |
|
42 |
+
public function search( $query, array $params = array() ) {
|
43 |
+
$_query = array();
|
44 |
+
$_query['q'] = $query;
|
45 |
+
$_query['part'] = 'snippet';
|
46 |
+
$_query['videoEmbeddable'] = 'true';
|
47 |
+
$_query['type'] = 'video';
|
|
|
|
|
|
|
48 |
|
49 |
+
// Разработчики обычно добавляют &format=5 в свои запросы, чтобы ограничить
|
50 |
+
// результаты теми видео, которые могут быть встроены в их сайты.
|
51 |
+
//$params['format'] = 5;
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
foreach ( $params as $key => $param ) {
|
54 |
+
switch ( $key ) {
|
55 |
+
case 'relevanceLanguage':
|
56 |
+
case 'order':
|
57 |
+
//case 'format':
|
58 |
+
case 'key':
|
59 |
+
case 'part':
|
60 |
+
case 'safeSearch':
|
61 |
+
case 'channelId':
|
62 |
+
case 'videoEmbeddable':
|
63 |
+
case 'type':
|
64 |
+
case 'videoLicense':
|
65 |
+
$_query[ $key ] = $param;
|
66 |
+
break;
|
67 |
+
case 'maxResults':
|
68 |
+
case 'pageToken':
|
69 |
+
$_query[ $key ] = ( (int) $param > 50 ) ? 50 : (int) $param;
|
70 |
+
break;
|
71 |
+
case 'strict':
|
72 |
+
$_query[ $key ] = ( (bool) $param ) ? true : false;
|
73 |
+
break;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
$response = $this->restGet( '/search', $_query );
|
77 |
|
78 |
+
return $this->_decodeResponse( $response );
|
79 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
}
|
application/libs/pixabay/PixabaySearch.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\pixabay;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,52 +12,49 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2016 keywordrush.com
|
15 |
-
*
|
16 |
* @link: https://pixabay.com/api/docs/
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class PixabaySearch extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
$response = $this->restGet('/api', $params);
|
60 |
-
return $this->_decodeResponse($response);
|
61 |
-
}
|
62 |
|
63 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\pixabay;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2016 keywordrush.com
|
15 |
+
*
|
16 |
* @link: https://pixabay.com/api/docs/
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class PixabaySearch extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://pixabay.com';
|
24 |
+
|
25 |
+
private $accountKey = null;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var array Response Format Types
|
29 |
+
*/
|
30 |
+
protected $_responseTypes = array(
|
31 |
+
'json'
|
32 |
+
);
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Constructor
|
36 |
+
*/
|
37 |
+
public function __construct( $accountKey, $responseType = 'json' ) {
|
38 |
+
$this->setAccountKey( $accountKey );
|
39 |
+
$this->setResponseType( $responseType );
|
40 |
+
$this->setUri( self::API_URI_BASE );
|
41 |
+
}
|
42 |
+
|
43 |
+
public function setAccountKey( $accountKey ) {
|
44 |
+
$this->accountKey = $accountKey;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getAccountKey() {
|
48 |
+
return $this->accountKey;
|
49 |
+
}
|
50 |
+
|
51 |
+
public function search( $query, array $params = array() ) {
|
52 |
+
$params['q'] = $query;
|
53 |
+
$params['key'] = $this->getAccountKey();
|
54 |
+
|
55 |
+
$response = $this->restGet( '/api', $params );
|
56 |
+
|
57 |
+
return $this->_decodeResponse( $response );
|
58 |
+
}
|
|
|
|
|
|
|
59 |
|
60 |
}
|
application/libs/rss/RssParser.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\rss;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -14,49 +14,51 @@ use ContentEgg\application\libs\RestClient;
|
|
14 |
* @copyright Copyright © 2015 keywordrush.com
|
15 |
*
|
16 |
*/
|
17 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
18 |
|
19 |
class RssParser extends RestClient {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
|
62 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\rss;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
14 |
* @copyright Copyright © 2015 keywordrush.com
|
15 |
*
|
16 |
*/
|
17 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
18 |
|
19 |
class RssParser extends RestClient {
|
20 |
|
21 |
+
/**
|
22 |
+
* @var array Response Format Types
|
23 |
+
*/
|
24 |
+
protected $_responseTypes = array(
|
25 |
+
'xml'
|
26 |
+
);
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Constructor
|
30 |
+
*
|
31 |
+
* @param string $responseType
|
32 |
+
*/
|
33 |
+
public function __construct() {
|
34 |
+
$this->setResponseType( 'xml' );
|
35 |
+
}
|
36 |
+
|
37 |
+
public function search( $query, $uri ) {
|
38 |
+
$uri = str_replace( '%KEYWORD%', rawurlencode( $query ), $uri );
|
39 |
+
$uri = str_replace( '%KEY-WORD%', urlencode( str_replace( ' ', '-', $query ) ), $uri );
|
40 |
+
$uri = str_replace( '%KEY+WORD%', urlencode( str_replace( ' ', '+', $query ) ), $uri );
|
41 |
+
|
42 |
+
$url_parts = @parse_url( $uri );
|
43 |
+
if ( isset( $url_parts['scheme'] ) && isset( $url_parts['host'] ) ) {
|
44 |
+
$uri = $url_parts['scheme'] . '://' . $url_parts['host'];
|
45 |
+
$this->setUri( $uri );
|
46 |
+
} else {
|
47 |
+
throw new \Exception( 'No valid URI scheme was provided. ' );
|
48 |
+
}
|
49 |
+
|
50 |
+
|
51 |
+
$path = '';
|
52 |
+
if ( isset( $url_parts['path'] ) ) {
|
53 |
+
$path = $url_parts['path'];
|
54 |
+
}
|
55 |
+
if ( isset( $url_parts['query'] ) ) {
|
56 |
+
$path .= '?' . $url_parts['query'];
|
57 |
+
}
|
58 |
+
|
59 |
+
$response = $this->restGet( $path );
|
60 |
+
|
61 |
+
return $this->_decodeResponse( $response );
|
62 |
+
}
|
63 |
|
64 |
}
|
application/libs/skimlinks/SkimlinksMerchant.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\skimlinks;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,45 +12,44 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
-
* Skimlinks Merchant API
|
16 |
* @link: http://developers.skimlinks.com/merchant.html
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class SkimlinksMerchant extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
|
56 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\skimlinks;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
+
* Skimlinks Merchant API
|
16 |
* @link: http://developers.skimlinks.com/merchant.html
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class SkimlinksMerchant extends RestClient {
|
22 |
|
23 |
+
const API_URI_BASE = 'https://merchants.skimapis.com/v3';
|
24 |
+
|
25 |
+
private $apikey;
|
26 |
+
private $account_type;
|
27 |
+
private $account_id;
|
28 |
+
protected $_responseTypes = array(
|
29 |
+
'json',
|
30 |
+
);
|
31 |
+
|
32 |
+
public function __construct( $apikey, $account_id, $account_type = 'publisher_admin' ) {
|
33 |
+
$this->apikey = $apikey;
|
34 |
+
$this->account_id = $account_id;
|
35 |
+
$this->account_type = $account_type;
|
36 |
+
$this->setUri( self::API_URI_BASE );
|
37 |
+
$this->setResponseType( 'json' );
|
38 |
+
}
|
39 |
+
|
40 |
+
public function search( $query, array $params ) {
|
41 |
+
$params['search'] = $query;
|
42 |
+
$response = $this->restGet( '/offers', $params );
|
43 |
+
|
44 |
+
return $this->_decodeResponse( $response );
|
45 |
+
}
|
46 |
+
|
47 |
+
public function restGet( $path, array $query = null ) {
|
48 |
+
$query['apikey'] = $this->apikey;
|
49 |
+
$query['account_id'] = $this->account_id;
|
50 |
+
$query['account_type'] = $this->account_type;
|
51 |
+
|
52 |
+
return parent::restGet( $path, $query );
|
53 |
+
}
|
|
|
54 |
|
55 |
}
|
application/libs/viglink/ViglinkApi.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\libs\viglink;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
@@ -12,62 +12,62 @@ use ContentEgg\application\libs\RestClient;
|
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
-
*
|
16 |
* @link: https://viglink-developer-center.readme.io/
|
17 |
*
|
18 |
*/
|
19 |
-
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class ViglinkApi extends RestClient {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
}
|
2 |
|
3 |
namespace ContentEgg\application\libs\viglink;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\libs\RestClient;
|
8 |
|
12 |
* @author keywordrush.com <support@keywordrush.com>
|
13 |
* @link http://www.keywordrush.com/
|
14 |
* @copyright Copyright © 2017 keywordrush.com
|
15 |
+
*
|
16 |
* @link: https://viglink-developer-center.readme.io/
|
17 |
*
|
18 |
*/
|
19 |
+
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'RestClient.php';
|
20 |
|
21 |
class ViglinkApi extends RestClient {
|
22 |
|
23 |
+
protected static $timeout = 40; //sec
|
24 |
+
|
25 |
+
const API_URI_BASE = 'https://rest.viglink.com/api';
|
26 |
+
|
27 |
+
protected $apiKey;
|
28 |
+
protected $secretKey;
|
29 |
+
protected $_responseTypes = array(
|
30 |
+
'json',
|
31 |
+
'xml'
|
32 |
+
);
|
33 |
+
|
34 |
+
public function __construct( $apiKey, $secretKey, $response_type = 'json' ) {
|
35 |
+
$this->apiKey = $apiKey;
|
36 |
+
$this->secretKey = $secretKey;
|
37 |
+
$this->setResponseType( $response_type );
|
38 |
+
$this->setUri( self::API_URI_BASE );
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Product Search
|
43 |
+
* @link: https://viglink-developer-center.readme.io/docs/product-search
|
44 |
+
*/
|
45 |
+
public function search( $keyword, array $options ) {
|
46 |
+
$options['query'] = $keyword;
|
47 |
+
$response = $this->restGet( '/product/search', $options );
|
48 |
+
|
49 |
+
return $this->_decodeResponse( $response );
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Get back the metadata about an product (Product URL) with this endpoint.
|
54 |
+
* @link: https://viglink-developer-center.readme.io/docs/metadata
|
55 |
+
*/
|
56 |
+
public function getMetadata( $url ) {
|
57 |
+
$options['url'] = $url;
|
58 |
+
$response = $this->restGet( '/product/metadata', $options );
|
59 |
+
|
60 |
+
return $this->_decodeResponse( $response );
|
61 |
+
}
|
62 |
+
|
63 |
+
public function restGet( $path, array $query = null ) {
|
64 |
+
if ( ! $query ) {
|
65 |
+
$query = array();
|
66 |
+
}
|
67 |
+
$query['apiKey'] = $this->apiKey;
|
68 |
+
$this->setCustomHeaders( array( 'Authorization' => 'secret ' . $this->secretKey ) );
|
69 |
+
|
70 |
+
return parent::restGet( $path, $query );
|
71 |
+
}
|
72 |
|
73 |
}
|
application/models/AutoblogModel.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\components\ContentManager;
|
@@ -20,17 +20,15 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
20 |
*/
|
21 |
class AutoblogModel extends Model {
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
|
30 |
-
|
31 |
-
{
|
32 |
|
33 |
-
|
34 |
id int(11) unsigned NOT NULL auto_increment,
|
35 |
create_date datetime NOT NULL,
|
36 |
last_run datetime NOT NULL default '0000-00-00 00:00:00',
|
@@ -61,558 +59,543 @@ class AutoblogModel extends Model {
|
|
61 |
PRIMARY KEY (id),
|
62 |
KEY last_run (status,last_run,run_frequency)
|
63 |
) $this->charset_collate;";
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
$parent = 0;
|
603 |
-
foreach ($categoryPath as $category)
|
604 |
-
{
|
605 |
-
$category = \sanitize_text_field($category);
|
606 |
-
if (!$ids = \term_exists($category, 'product_cat', $parent))
|
607 |
-
{
|
608 |
-
$ids = \wp_insert_term($category, 'product_cat', array('parent' => $parent));
|
609 |
-
if (\is_wp_error($ids))
|
610 |
-
return false;
|
611 |
-
}
|
612 |
-
|
613 |
-
$parent = $ids['term_id'];
|
614 |
-
}
|
615 |
-
return $parent;
|
616 |
-
}
|
617 |
|
618 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ModuleManager;
|
8 |
use ContentEgg\application\components\ContentManager;
|
20 |
*/
|
21 |
class AutoblogModel extends Model {
|
22 |
|
23 |
+
const INACTIVATE_AFTER_ERR_COUNT = 5;
|
24 |
|
25 |
+
public function tableName() {
|
26 |
+
return $this->getDb()->prefix . 'cegg_autoblog';
|
27 |
+
}
|
|
|
28 |
|
29 |
+
public function getDump() {
|
|
|
30 |
|
31 |
+
return "CREATE TABLE " . $this->tableName() . " (
|
32 |
id int(11) unsigned NOT NULL auto_increment,
|
33 |
create_date datetime NOT NULL,
|
34 |
last_run datetime NOT NULL default '0000-00-00 00:00:00',
|
59 |
PRIMARY KEY (id),
|
60 |
KEY last_run (status,last_run,run_frequency)
|
61 |
) $this->charset_collate;";
|
62 |
+
}
|
63 |
+
|
64 |
+
public static function model( $className = __CLASS__ ) {
|
65 |
+
return parent::model( $className );
|
66 |
+
}
|
67 |
+
|
68 |
+
public function attributeLabels() {
|
69 |
+
return array(
|
70 |
+
'id' => 'ID',
|
71 |
+
'name' => __( 'Name', 'content-egg' ),
|
72 |
+
'create_date' => __( 'Date of creation', 'content-egg' ),
|
73 |
+
'last_run' => __( 'Last work', 'content-egg' ),
|
74 |
+
'status' => __( 'Status', 'content-egg' ),
|
75 |
+
'post_count' => __( 'Total posts', 'content-egg' ),
|
76 |
+
'last_error' => __( 'Last error', 'content-egg' ),
|
77 |
+
'keywords' => __( 'Keywords', 'content-egg' ),
|
78 |
+
);
|
79 |
+
}
|
80 |
+
|
81 |
+
public function save( array $item ) {
|
82 |
+
$item['id'] = (int) $item['id'];
|
83 |
+
|
84 |
+
$serialized_fileds = array(
|
85 |
+
'keywords',
|
86 |
+
'include_modules',
|
87 |
+
'exclude_modules',
|
88 |
+
'required_modules',
|
89 |
+
'autoupdate_modules',
|
90 |
+
'custom_field_names',
|
91 |
+
'custom_field_values',
|
92 |
+
'config',
|
93 |
+
);
|
94 |
+
foreach ( $serialized_fileds as $field ) {
|
95 |
+
if ( isset( $item[ $field ] ) && is_array( $item[ $field ] ) ) {
|
96 |
+
$item[ $field ] = serialize( $item[ $field ] );
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
if ( ! $item['id'] ) {
|
101 |
+
$item['id'] = null;
|
102 |
+
$item['create_date'] = \current_time( 'mysql' );
|
103 |
+
$this->getDb()->insert( $this->tableName(), $item );
|
104 |
+
|
105 |
+
return $this->getDb()->insert_id;
|
106 |
+
} else {
|
107 |
+
$this->getDb()->update( $this->tableName(), $item, array( 'id' => $item['id'] ) );
|
108 |
+
|
109 |
+
return $item['id'];
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
public function run( $id ) {
|
114 |
+
$autoblog = self::model()->findByPk( $id );
|
115 |
+
if ( ! $autoblog ) {
|
116 |
+
return false;
|
117 |
+
}
|
118 |
+
|
119 |
+
$autoblog['include_modules'] = unserialize( $autoblog['include_modules'] );
|
120 |
+
$autoblog['exclude_modules'] = unserialize( $autoblog['exclude_modules'] );
|
121 |
+
$autoblog['required_modules'] = unserialize( $autoblog['required_modules'] );
|
122 |
+
$autoblog['keywords'] = unserialize( $autoblog['keywords'] );
|
123 |
+
$autoblog['autoupdate_modules'] = unserialize( $autoblog['autoupdate_modules'] );
|
124 |
+
$autoblog['custom_field_names'] = unserialize( $autoblog['custom_field_names'] );
|
125 |
+
$autoblog['custom_field_values'] = unserialize( $autoblog['custom_field_values'] );
|
126 |
+
$autoblog['config'] = unserialize( $autoblog['config'] );
|
127 |
+
|
128 |
+
$autoblog_save = array();
|
129 |
+
$autoblog_save['id'] = $autoblog['id'];
|
130 |
+
$autoblog_save['last_run'] = \current_time( 'mysql' );
|
131 |
+
|
132 |
+
// next keyword exists?
|
133 |
+
$keyword_id = self::getNextKeywordId( $autoblog['keywords'] );
|
134 |
+
if ( $keyword_id === false ) {
|
135 |
+
$autoblog_save['status'] = 0;
|
136 |
+
$this->save( $autoblog_save );
|
137 |
+
|
138 |
+
return false;
|
139 |
+
}
|
140 |
+
|
141 |
+
// pre save autoblog
|
142 |
+
$this->save( $autoblog_save );
|
143 |
+
|
144 |
+
$keywords_per_run = (int) $autoblog['keywords_per_run'];
|
145 |
+
if ( $keywords_per_run < 1 ) {
|
146 |
+
$keywords_per_run = 1;
|
147 |
+
}
|
148 |
+
|
149 |
+
// create posts
|
150 |
+
for ( $i = 0; $i < $keywords_per_run; $i ++ ) {
|
151 |
+
if ( $i ) {
|
152 |
+
sleep( 1 );
|
153 |
+
}
|
154 |
+
|
155 |
+
$keyword = $autoblog['keywords'][ $keyword_id ];
|
156 |
+
|
157 |
+
$post_id = null;
|
158 |
+
try {
|
159 |
+
$post_id = $this->createPost( $keyword, $autoblog );
|
160 |
+
} catch ( \Exception $e ) {
|
161 |
+
$error_mess = TemplateHelper::formatDatetime( time(), 'timestamp' );
|
162 |
+
if ( strlen( $keyword ) < 100 ) {
|
163 |
+
$error_mess .= ' [' . $keyword . ']';
|
164 |
+
}
|
165 |
+
$error_mess .= ' - ';
|
166 |
+
$autoblog['last_error'] = $error_mess . $e->getMessage();
|
167 |
+
}
|
168 |
+
|
169 |
+
if ( $post_id ) {
|
170 |
+
$autoblog['post_count'] ++;
|
171 |
+
}
|
172 |
+
$autoblog['keywords'][ $keyword_id ] = self::markKeywordInactive( $keyword );
|
173 |
+
$keyword_id = self::getNextKeywordId( $autoblog['keywords'] );
|
174 |
+
if ( $keyword_id === false ) {
|
175 |
+
$autoblog['status'] = 0;
|
176 |
+
break;
|
177 |
+
}
|
178 |
+
} //.for
|
179 |
+
|
180 |
+
$autoblog['last_run'] = \current_time( 'mysql' );
|
181 |
+
$this->save( $autoblog );
|
182 |
+
|
183 |
+
return true;
|
184 |
+
}
|
185 |
+
|
186 |
+
public function createPost( $keyword, $autoblog ) {
|
187 |
+
$module_ids = ModuleManager::getInstance()->getParserModulesIdList( true );
|
188 |
+
if ( $autoblog['include_modules'] ) {
|
189 |
+
$module_ids = array_intersect( $module_ids, $autoblog['include_modules'] );
|
190 |
+
}
|
191 |
+
if ( $autoblog['exclude_modules'] ) {
|
192 |
+
$module_ids = array_diff( $module_ids, $autoblog['exclude_modules'] );
|
193 |
+
}
|
194 |
+
|
195 |
+
// copy module_ids to keys
|
196 |
+
$module_ids = array_combine( $module_ids, $module_ids );
|
197 |
+
|
198 |
+
// run required modules first
|
199 |
+
if ( $autoblog['required_modules'] ) {
|
200 |
+
foreach ( $autoblog['required_modules'] as $required_module ) {
|
201 |
+
// module not found?
|
202 |
+
if ( ! isset( $module_ids[ $required_module ] ) ) {
|
203 |
+
throw new \Exception( sprintf( __( 'Required module %s will not run. The module is not configured or deleted.', 'content-egg' ), $required_module ) );
|
204 |
+
}
|
205 |
+
|
206 |
+
unset( $module_ids[ $required_module ] );
|
207 |
+
$module_ids = array( $required_module => $required_module ) + $module_ids;
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
// module keywords
|
212 |
+
$keyword_arr = str_getcsv( $keyword, ';' );
|
213 |
+
$keyword = '';
|
214 |
+
$tmp_module_keywords = array();
|
215 |
+
|
216 |
+
foreach ( $keyword_arr as $k ) {
|
217 |
+
$k_parts = explode( ':', $k, 2 );
|
218 |
+
// main keyword
|
219 |
+
if ( count( $k_parts ) == 1 && ! $keyword ) {
|
220 |
+
$keyword = trim( $k );
|
221 |
+
} elseif ( count( $k_parts ) == 2 ) {
|
222 |
+
$module_id = trim( $k_parts[0] );
|
223 |
+
$module_id = str_replace( ' ', '', $module_id ); // name -> id
|
224 |
+
if ( ! ModuleManager::getInstance()->moduleExists( $module_id ) ) {
|
225 |
+
$keyword = trim( $k );
|
226 |
+
continue;
|
227 |
+
}
|
228 |
+
$tmp_module_keywords[ $module_id ] = trim( $k_parts[1] );
|
229 |
+
} else {
|
230 |
+
continue;
|
231 |
+
} //error
|
232 |
+
}
|
233 |
+
|
234 |
+
// main keyword not set?
|
235 |
+
if ( ! $keyword ) {
|
236 |
+
$keyword = reset( $tmp_module_keywords );
|
237 |
+
} // first
|
238 |
+
$module_keywords = array();
|
239 |
+
foreach ( $module_ids as $module_id ) {
|
240 |
+
if ( isset( $tmp_module_keywords[ $module_id ] ) ) {
|
241 |
+
$module_keywords[ $module_id ] = $tmp_module_keywords[ $module_id ];
|
242 |
+
} else {
|
243 |
+
$module_keywords[ $module_id ] = $keyword;
|
244 |
+
}
|
245 |
+
}
|
246 |
+
// .module keywords
|
247 |
+
|
248 |
+
$modules_data = array();
|
249 |
+
$count = count( $module_ids ) - 1;
|
250 |
+
foreach ( $module_ids as $module_id ) {
|
251 |
+
$module = ModuleManager::getInstance()->factory( $module_id );
|
252 |
+
try {
|
253 |
+
$data = $module->doMultipleRequests( $module_keywords[ $module_id ], $autoblog, true );
|
254 |
+
} catch ( \Exception $e ) {
|
255 |
+
// error
|
256 |
+
$data = null;
|
257 |
+
}
|
258 |
+
if ( $data ) {
|
259 |
+
foreach ( $data as $i => $d ) {
|
260 |
+
$data[ $i ]->keyword = $module_keywords[ $module_id ];
|
261 |
+
}
|
262 |
+
$modules_data[ $module->getId() ] = $data;
|
263 |
+
} elseif ( $autoblog['required_modules'] && in_array( $module_id, $autoblog['required_modules'] ) ) {
|
264 |
+
throw new \Exception( sprintf( __( 'Data was not found for required module %s.', 'content-egg' ), $module_id ) );
|
265 |
+
}
|
266 |
+
|
267 |
+
// check min count modules
|
268 |
+
if ( $autoblog['min_modules_count'] ) {
|
269 |
+
if ( count( $modules_data ) + $count < $autoblog['min_modules_count'] ) {
|
270 |
+
throw new \Exception( sprintf( __( 'It does not reach the desired amount of data. Minimum required modules: %d.', 'content-egg' ), $autoblog['min_modules_count'] ) );
|
271 |
+
}
|
272 |
+
}
|
273 |
+
$count --;
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( ! empty( $autoblog['config']['min_comments_count'] ) ) {
|
277 |
+
$comments_count = 0;
|
278 |
+
foreach ( $modules_data as $module_id => $data ) {
|
279 |
+
foreach ( $data as $d ) {
|
280 |
+
$comments_count += count( ContentManager::getNormalizedReviews( $data ) );
|
281 |
+
}
|
282 |
+
}
|
283 |
+
if ( $comments_count < (int) $autoblog['config']['min_comments_count'] ) {
|
284 |
+
throw new \Exception( sprintf( __( 'Total reviews found: %d. Minimum reviews required: %d.', 'content-egg' ), $comments_count, $autoblog['config']['min_comments_count'] ) );
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
// main product
|
289 |
+
$main_product = ContentManager::getMainProduct( $modules_data, $autoblog['main_product'] );
|
290 |
+
|
291 |
+
// set main product for woo sync
|
292 |
+
$product_sync = GeneralConfig::getInstance()->option( 'woocommerce_product_sync' );
|
293 |
+
$woocommerce_modules = GeneralConfig::getInstance()->option( 'woocommerce_modules' );
|
294 |
+
|
295 |
+
if ( $autoblog['post_type'] == 'product' && ( $product_sync == 'manually' || ! array_intersect_key( $modules_data, $woocommerce_modules ) ) && $main_product ) {
|
296 |
+
foreach ( $modules_data[ $main_product['module_id'] ] as $i => $product ) {
|
297 |
+
if ( $product->unique_id == $main_product['unique_id'] && $product instanceof \ContentEgg\application\components\ContentProduct ) {
|
298 |
+
$modules_data[ $main_product['module_id'] ][ $i ]->woo_sync = true;
|
299 |
+
if ( GeneralConfig::getInstance()->option( 'woocommerce_attributes_sync' ) ) {
|
300 |
+
$modules_data[ $main_product['module_id'] ][ $i ]->woo_attr = true;
|
301 |
+
}
|
302 |
+
break;
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
$title = AutoblogModel::buildTemplate( $autoblog['template_title'], $modules_data, $keyword, $module_keywords, $main_product );
|
308 |
+
$title = \wp_strip_all_tags( $title );
|
309 |
+
if ( ! $title ) {
|
310 |
+
$title = $keyword;
|
311 |
+
}
|
312 |
+
$body = AutoblogModel::buildTemplate( $autoblog['template_body'], $modules_data, $keyword, $module_keywords, $main_product );
|
313 |
+
if ( (bool) $autoblog['post_status'] ) {
|
314 |
+
$post_status = 'publish';
|
315 |
+
} else {
|
316 |
+
$post_status = 'pending';
|
317 |
+
}
|
318 |
+
|
319 |
+
// custom fields
|
320 |
+
$meta_input = array();
|
321 |
+
if ( $autoblog['custom_field_names'] ) {
|
322 |
+
foreach ( $autoblog['custom_field_names'] as $i => $custom_field ) {
|
323 |
+
$cf_value = $autoblog['custom_field_values'][ $i ];
|
324 |
+
if ( \is_serialized( $cf_value ) ) {
|
325 |
+
$cf_value = @unserialize( $cf_value );
|
326 |
+
} else {
|
327 |
+
$cf_value = AutoblogModel::buildTemplate( $cf_value, $modules_data, $keyword, $module_keywords, $main_product );
|
328 |
+
}
|
329 |
+
|
330 |
+
$meta_input[ $custom_field ] = $cf_value;
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
//tags
|
335 |
+
if ( $autoblog['tags'] ) {
|
336 |
+
$tags_input = AutoblogModel::buildTemplate( $autoblog['tags'], $modules_data, $keyword, $module_keywords, $main_product );
|
337 |
+
} else {
|
338 |
+
$tags_input = '';
|
339 |
+
}
|
340 |
+
|
341 |
+
// create category
|
342 |
+
if ( ! empty( $autoblog['config']['dynamic_categories'] ) && $autoblog['config']['dynamic_categories'] == 2 && $main_product['categoryPath'] ) {
|
343 |
+
if ( $autoblog['post_type'] == 'product' ) {
|
344 |
+
$categ_id = self::createWooNestedCategories( $main_product['categoryPath'] );
|
345 |
+
} else {
|
346 |
+
$categ_id = self::createNestedCategories( $main_product['categoryPath'] );
|
347 |
+
}
|
348 |
+
} elseif ( ! empty( $autoblog['config']['dynamic_categories'] ) && $autoblog['config']['dynamic_categories'] && $main_product['category'] ) {
|
349 |
+
if ( $autoblog['post_type'] == 'product' ) {
|
350 |
+
$categ_id = self::createWooCategory( $main_product['category'] );
|
351 |
+
} else {
|
352 |
+
$categ_id = self::createCategory( $main_product['category'] );
|
353 |
+
}
|
354 |
+
} else {
|
355 |
+
$categ_id = $autoblog['category'];
|
356 |
+
}
|
357 |
+
|
358 |
+
if ( ! $categ_id ) {
|
359 |
+
$categ_id = $autoblog['category'];
|
360 |
+
}
|
361 |
+
$categ_id = (int) $categ_id;
|
362 |
+
|
363 |
+
// create post
|
364 |
+
$post = array(
|
365 |
+
'ID' => null,
|
366 |
+
'post_title' => $title,
|
367 |
+
'post_content' => $body,
|
368 |
+
'post_status' => $post_status,
|
369 |
+
'post_author' => $autoblog['user_id'],
|
370 |
+
'post_category' => array( $categ_id ),
|
371 |
+
'post_type' => $autoblog['post_type'],
|
372 |
+
'meta_input' => $meta_input,
|
373 |
+
'tags_input' => $tags_input,
|
374 |
+
);
|
375 |
+
|
376 |
+
if ( ! $post_id = \wp_insert_post( $post ) ) {
|
377 |
+
throw new \Exception( sprintf( __( 'Post can\'t be created. Unknown error.', 'content-egg' ), $autoblog['min_modules_count'] ) );
|
378 |
+
}
|
379 |
+
|
380 |
+
// woocommerce product
|
381 |
+
if ( \get_post_type( $post_id ) == 'product' ) {
|
382 |
+
// external by default
|
383 |
+
//\wp_set_object_terms($post_id, 'external', 'product_type');
|
384 |
+
$classname = \WC_Product_Factory::get_product_classname( $post_id, 'external' );
|
385 |
+
$product = new $classname( $post_id );
|
386 |
+
$product->save();
|
387 |
+
|
388 |
+
if ( \term_exists( $categ_id, 'product_cat' ) ) {
|
389 |
+
\wp_set_object_terms( $post_id, (int) $categ_id, 'product_cat' );
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( $tags_input ) {
|
393 |
+
\wp_set_object_terms( $post_id, explode( ',', $tags_input ), 'product_tag' );
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
|
398 |
+
// save modules data & keyword for autoupdate
|
399 |
+
$i = 0;
|
400 |
+
foreach ( $modules_data as $module_id => $data ) {
|
401 |
+
$i ++;
|
402 |
+
$autoupdate_keyword = \sanitize_text_field( $module_keywords[ $module_id ] );
|
403 |
+
if ( $i == count( $modules_data ) ) {
|
404 |
+
$last_iteration = true;
|
405 |
+
} else {
|
406 |
+
$last_iteration = false;
|
407 |
+
}
|
408 |
+
ContentManager::saveData( $data, $module_id, $post_id, $last_iteration );
|
409 |
+
if ( in_array( $module_id, $autoblog['autoupdate_modules'] ) && $autoupdate_keyword ) {
|
410 |
+
\update_post_meta( $post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, $autoupdate_keyword );
|
411 |
+
}
|
412 |
+
}
|
413 |
+
|
414 |
+
\do_action( 'cegg_autoblog_post_create', $post_id );
|
415 |
+
|
416 |
+
// set featured image. external or internal
|
417 |
+
FeaturedImage::doAction( $post_id );
|
418 |
+
|
419 |
+
return $post_id;
|
420 |
+
}
|
421 |
+
|
422 |
+
public static function buildTemplate( $template, array $modules_data, $keyword, $module_keywords = array(), $main_product = null ) {
|
423 |
+
if ( ! $template ) {
|
424 |
+
return $template;
|
425 |
+
}
|
426 |
+
|
427 |
+
$template = TextHelper::spin( $template );
|
428 |
+
if ( ! preg_match_all( '/%[a-zA-Z0-9_\.\,\(\)]+%/', $template, $matches ) ) {
|
429 |
+
return $template;
|
430 |
+
}
|
431 |
+
|
432 |
+
$replace = array();
|
433 |
+
foreach ( $matches[0] as $pattern ) {
|
434 |
+
// random
|
435 |
+
if ( stristr( $pattern, '%RANDOM' ) ) {
|
436 |
+
preg_match( '/%RANDOM\((\d+),(\d+)\)%/', $pattern, $rmatches );
|
437 |
+
if ( $rmatches ) {
|
438 |
+
$replace[ $pattern ] = rand( (int) $rmatches[1], (int) $rmatches[2] );
|
439 |
+
} else {
|
440 |
+
$replace[ $pattern ] = rand( 0, 9999999 );
|
441 |
+
}
|
442 |
+
continue;
|
443 |
+
}
|
444 |
+
|
445 |
+
// keyword
|
446 |
+
if ( stristr( $pattern, '%KEYWORD%' ) ) {
|
447 |
+
$replace[ $pattern ] = $keyword;
|
448 |
+
continue;
|
449 |
+
}
|
450 |
+
|
451 |
+
|
452 |
+
// module keyword
|
453 |
+
if ( stristr( $pattern, '%KEYWORD.' ) ) {
|
454 |
+
$pattern_parts = explode( '.', $pattern );
|
455 |
+
$module_id = rtrim( $pattern_parts[1], '%' );
|
456 |
+
$module_id = str_replace( ' ', '', $module_id ); // name -> id
|
457 |
+
if ( isset( $module_keywords[ $module_id ] ) ) {
|
458 |
+
$replace[ $pattern ] = $module_keywords[ $module_id ];
|
459 |
+
} else {
|
460 |
+
$replace[ $pattern ] = '';
|
461 |
+
}
|
462 |
+
continue;
|
463 |
+
}
|
464 |
+
|
465 |
+
// main product
|
466 |
+
if ( stristr( $pattern, '%PRODUCT.' ) ) {
|
467 |
+
if ( ! $main_product ) {
|
468 |
+
$replace[ $pattern ] = '';
|
469 |
+
continue;
|
470 |
+
}
|
471 |
+
|
472 |
+
$pattern_parts = explode( '.', $pattern );
|
473 |
+
$var_name = $pattern_parts[1];
|
474 |
+
$var_name = rtrim( $var_name, '%' );
|
475 |
+
|
476 |
+
if ( isset( $main_product[ $var_name ] ) ) {
|
477 |
+
$replace[ $pattern ] = $main_product[ $var_name ];
|
478 |
+
} else {
|
479 |
+
$replace[ $pattern ] = '';
|
480 |
+
}
|
481 |
+
continue;
|
482 |
+
}
|
483 |
+
|
484 |
+
// module data
|
485 |
+
$pattern_parts = explode( '.', $pattern );
|
486 |
+
if ( count( $pattern_parts ) == 3 ) {
|
487 |
+
$index = (int) $pattern_parts[1]; // Amazon.0.title
|
488 |
+
$var_name = $pattern_parts[2];
|
489 |
+
} elseif ( count( $pattern_parts ) == 2 ) {
|
490 |
+
$index = 0; // Amazon.title
|
491 |
+
$var_name = $pattern_parts[1];
|
492 |
+
} else {
|
493 |
+
$replace[ $pattern ] = '';
|
494 |
+
continue;
|
495 |
+
}
|
496 |
+
$module_id = ltrim( $pattern_parts[0], '%' );
|
497 |
+
$var_name = rtrim( $var_name, '%' );
|
498 |
+
|
499 |
+
if ( array_key_exists( $module_id, $modules_data ) && isset( $modules_data[ $module_id ][ $index ] ) && property_exists( $modules_data[ $module_id ][ $index ], $var_name ) ) {
|
500 |
+
$replace[ $pattern ] = $modules_data[ $module_id ][ $index ]->$var_name;
|
501 |
+
} else {
|
502 |
+
$replace[ $pattern ] = '';
|
503 |
+
}
|
504 |
+
}
|
505 |
+
|
506 |
+
return str_ireplace( array_keys( $replace ), array_values( $replace ), $template );
|
507 |
+
}
|
508 |
+
|
509 |
+
public static function getNextKeywordId( array $keywords ) {
|
510 |
+
foreach ( $keywords as $id => $keyword ) {
|
511 |
+
if ( self::isActiveKeyword( $keyword ) ) {
|
512 |
+
return $id;
|
513 |
+
}
|
514 |
+
}
|
515 |
+
|
516 |
+
return false;
|
517 |
+
}
|
518 |
+
|
519 |
+
public static function isInactiveKeyword( $keyword ) {
|
520 |
+
if ( $keyword[0] == '[' ) {
|
521 |
+
return true;
|
522 |
+
} else {
|
523 |
+
return false;
|
524 |
+
}
|
525 |
+
}
|
526 |
+
|
527 |
+
public static function isActiveKeyword( $keyword ) {
|
528 |
+
return ! self::isInactiveKeyword( $keyword );
|
529 |
+
}
|
530 |
+
|
531 |
+
public static function markKeywordInactive( $keyword ) {
|
532 |
+
return '[' . $keyword . ']';
|
533 |
+
}
|
534 |
+
|
535 |
+
public static function isActiveAutoblogs() {
|
536 |
+
$total_autoblogs = AutoblogModel::model()->count( 'status = 1' );
|
537 |
+
if ( $total_autoblogs ) {
|
538 |
+
return true;
|
539 |
+
} else {
|
540 |
+
return false;
|
541 |
+
}
|
542 |
+
}
|
543 |
+
|
544 |
+
public static function createCategory( $category ) {
|
545 |
+
if ( ! is_array( $category ) ) {
|
546 |
+
$category = array( $category );
|
547 |
+
}
|
548 |
+
|
549 |
+
return self::createNestedCategories( $category );
|
550 |
+
}
|
551 |
+
|
552 |
+
static public function createNestedCategories( array $categoryPath ) {
|
553 |
+
// exists?
|
554 |
+
$last = end( $categoryPath );
|
555 |
+
if ( $eid = get_cat_ID( $last ) ) {
|
556 |
+
return $eid;
|
557 |
+
}
|
558 |
+
|
559 |
+
if ( ! function_exists( '\wp_create_category' ) ) {
|
560 |
+
require_once( \ABSPATH . 'wp-admin/includes/taxonomy.php' );
|
561 |
+
}
|
562 |
+
|
563 |
+
$parent = 0;
|
564 |
+
foreach ( $categoryPath as $category ) {
|
565 |
+
// If the category already exists, it is not duplicated.
|
566 |
+
// The ID of the original existing category is returned without error.
|
567 |
+
if ( ! $id = \wp_create_category( $category, $parent ) ) {
|
568 |
+
return $id;
|
569 |
+
}
|
570 |
+
$parent = $id;
|
571 |
+
}
|
572 |
+
|
573 |
+
return $id;
|
574 |
+
}
|
575 |
+
|
576 |
+
public static function createWooCategory( $category ) {
|
577 |
+
if ( ! is_array( $category ) ) {
|
578 |
+
$category = array( $category );
|
579 |
+
}
|
580 |
+
|
581 |
+
return self::createWooNestedCategories( $category );
|
582 |
+
}
|
583 |
+
|
584 |
+
public static function createWooNestedCategories( array $categoryPath ) {
|
585 |
+
$parent = 0;
|
586 |
+
foreach ( $categoryPath as $category ) {
|
587 |
+
$category = \sanitize_text_field( $category );
|
588 |
+
if ( ! $ids = \term_exists( $category, 'product_cat', $parent ) ) {
|
589 |
+
$ids = \wp_insert_term( $category, 'product_cat', array( 'parent' => $parent ) );
|
590 |
+
if ( \is_wp_error( $ids ) ) {
|
591 |
+
return false;
|
592 |
+
}
|
593 |
+
}
|
594 |
+
|
595 |
+
$parent = $ids['term_id'];
|
596 |
+
}
|
597 |
+
|
598 |
+
return $parent;
|
599 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
|
601 |
}
|
application/models/FeedProductModel.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
@@ -15,9 +15,8 @@ use ContentEgg\application\helpers\TextHelper;
|
|
15 |
*/
|
16 |
abstract class FeedProductModel extends Model {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
return "CREATE TABLE " . $this->tableName() . " (
|
21 |
id bigint(20) unsigned NOT NULL,
|
22 |
stock_status tinyint(1) DEFAULT 0,
|
23 |
price float(12,2) DEFAULT NULL,
|
@@ -32,66 +31,67 @@ abstract class FeedProductModel extends Model {
|
|
32 |
KEY price (price),
|
33 |
FULLTEXT (title)
|
34 |
) $this->charset_collate;";
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
|
97 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
15 |
*/
|
16 |
abstract class FeedProductModel extends Model {
|
17 |
|
18 |
+
public function getDump() {
|
19 |
+
return "CREATE TABLE " . $this->tableName() . " (
|
|
|
20 |
id bigint(20) unsigned NOT NULL,
|
21 |
stock_status tinyint(1) DEFAULT 0,
|
22 |
price float(12,2) DEFAULT NULL,
|
31 |
KEY price (price),
|
32 |
FULLTEXT (title)
|
33 |
) $this->charset_collate;";
|
34 |
+
}
|
35 |
+
|
36 |
+
public function searchByUrl( $url, $partial_match = false, $limit = 1 ) {
|
37 |
+
$like = $this->getDb()->esc_like( $url );
|
38 |
+
if ( $partial_match ) {
|
39 |
+
$like .= '%';
|
40 |
+
}
|
41 |
+
|
42 |
+
if ( ! $partial_match ) {
|
43 |
+
$limit = 1;
|
44 |
+
}
|
45 |
+
|
46 |
+
$sql = $this->getDb()->prepare( 'SELECT * FROM ' . $this->tableName() . ' WHERE orig_url LIKE %s LIMIT %d', $like, $limit );
|
47 |
+
|
48 |
+
return $this->getDb()->get_results( $sql, \ARRAY_A );
|
49 |
+
}
|
50 |
+
|
51 |
+
public function searchByEan( $ean, $limit = 10 ) {
|
52 |
+
$ean = TextHelper::fixEan( $ean );
|
53 |
+
$sql = $this->getDb()->prepare( 'SELECT * FROM ' . $this->tableName() . ' WHERE ean = %s LIMIT %d', $ean, $limit );
|
54 |
+
|
55 |
+
return $this->getDb()->get_results( $sql, \ARRAY_A );
|
56 |
+
}
|
57 |
+
|
58 |
+
public function searchByKeyword( $keyword, $limit = 10, $options = array() ) {
|
59 |
+
$where = '';
|
60 |
+
if ( ! empty( $options['price_min'] ) ) {
|
61 |
+
$where = $this->getDb()->prepare( 'price >= %d', $options['price_min'] );
|
62 |
+
}
|
63 |
+
|
64 |
+
if ( ! empty( $options['price_max'] ) ) {
|
65 |
+
if ( $where ) {
|
66 |
+
$where .= ' AND ';
|
67 |
+
}
|
68 |
+
$where .= $this->getDb()->prepare( 'price <= %d', $options['price_max'] );
|
69 |
+
}
|
70 |
+
if ( $where ) {
|
71 |
+
$where = ' AND ' . $where;
|
72 |
+
}
|
73 |
+
|
74 |
+
$sql = $this->getDb()->prepare( 'SELECT * FROM ' . $this->tableName() . ' WHERE MATCH (title) AGAINST (%s)' . $where . ' LIMIT %d', $keyword, $limit );
|
75 |
+
|
76 |
+
return $this->getDb()->get_results( $sql, \ARRAY_A );
|
77 |
+
}
|
78 |
+
|
79 |
+
public function searchById( $id ) {
|
80 |
+
$sql = $this->getDb()->prepare( 'SELECT * FROM ' . $this->tableName() . ' WHERE id = %s LIMIT 1', $id );
|
81 |
+
|
82 |
+
return $this->getDb()->get_row( $sql, \ARRAY_A );
|
83 |
+
}
|
84 |
+
|
85 |
+
public function getAllUrls() {
|
86 |
+
return $this->getDb()->get_col( 'SELECT orig_url FROM ' . $this->tableName() );
|
87 |
+
}
|
88 |
+
|
89 |
+
public function getEans() {
|
90 |
+
return $this->getDb()->get_col( 'SELECT ean FROM ' . $this->tableName() . ' WHERE ean != ""' );
|
91 |
+
}
|
92 |
+
|
93 |
+
public function getDublicateEans() {
|
94 |
+
return $this->getDb()->get_col( 'SELECT ean, COUNT(*) c FROM ' . $this->tableName() . ' WHERE ean != "" GROUP BY ean HAVING c > 1' );
|
95 |
+
}
|
96 |
|
97 |
}
|
application/models/Model.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
/**
|
8 |
* Model class file
|
@@ -13,261 +13,254 @@ defined('\ABSPATH') || exit;
|
|
13 |
*/
|
14 |
abstract class Model {
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
$query .= $this->getDb()->prepare($placeholder, $items[$j]) . ', ';
|
266 |
-
}
|
267 |
-
$query = rtrim($query, " ,") . ';';
|
268 |
-
$this->getDb()->query($query);
|
269 |
-
}
|
270 |
-
}
|
271 |
-
|
272 |
|
273 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
/**
|
8 |
* Model class file
|
13 |
*/
|
14 |
abstract class Model {
|
15 |
|
16 |
+
public static $db;
|
17 |
+
private static $models = array();
|
18 |
+
protected $charset_collate = '';
|
19 |
+
|
20 |
+
abstract public function tableName();
|
21 |
+
|
22 |
+
abstract public function getDump();
|
23 |
+
|
24 |
+
public function __construct() {
|
25 |
+
if ( ! empty( $this->getDb()->charset ) ) {
|
26 |
+
$this->charset_collate = 'DEFAULT CHARACTER SET ' . $this->getDb()->charset;
|
27 |
+
}
|
28 |
+
if ( ! empty( $this->getDb()->collate ) ) {
|
29 |
+
$this->charset_collate .= ' COLLATE ' . $this->getDb()->collate;
|
30 |
+
}
|
31 |
+
if ( ! $this->charset_collate ) {
|
32 |
+
$this->charset_collate = '';
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
public function attributeLabels() {
|
37 |
+
return array();
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getDb() {
|
41 |
+
if ( self::$db !== null ) {
|
42 |
+
return self::$db;
|
43 |
+
} else {
|
44 |
+
self::$db = $GLOBALS['wpdb'];
|
45 |
+
|
46 |
+
return self::$db;
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
public static function model( $className = __CLASS__ ) {
|
51 |
+
if ( isset( self::$models[ $className ] ) ) {
|
52 |
+
return self::$models[ $className ];
|
53 |
+
} else {
|
54 |
+
return self::$models[ $className ] = new $className;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getAttributeLabel( $attribute ) {
|
59 |
+
$labels = $this->attributeLabels();
|
60 |
+
if ( isset( $labels[ $attribute ] ) ) {
|
61 |
+
return $labels[ $attribute ];
|
62 |
+
} else {
|
63 |
+
return $this->generateAttributeLabel( $attribute );
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
public function generateAttributeLabel( $name ) {
|
68 |
+
return ucwords( trim( strtolower( str_replace( array(
|
69 |
+
'-',
|
70 |
+
'_',
|
71 |
+
'.'
|
72 |
+
), ' ', preg_replace( '/(?<![A-Z])[A-Z]/', ' \0', $name ) ) ) ) );
|
73 |
+
}
|
74 |
+
|
75 |
+
public function find( array $params ) {
|
76 |
+
return $this->getDb()->get_row( $this->prepareFindSql( $params ), \ARRAY_A );
|
77 |
+
}
|
78 |
+
|
79 |
+
public function findAll( array $params ) {
|
80 |
+
return $this->getDb()->get_results( $this->prepareFindSql( $params ), \ARRAY_A );
|
81 |
+
}
|
82 |
+
|
83 |
+
private function prepareFindSql( array $params ) {
|
84 |
+
$values = array();
|
85 |
+
$sql = 'SELECT ';
|
86 |
+
|
87 |
+
if ( ! empty( $params['select'] ) ) {
|
88 |
+
$sql .= $params['select'];
|
89 |
+
} else {
|
90 |
+
$sql .= ' *';
|
91 |
+
}
|
92 |
+
$sql .= ' FROM ' . $this->tableName();
|
93 |
+
if ( $params ) {
|
94 |
+
if ( ! empty( $params['where'] ) ) {
|
95 |
+
if ( is_array( $params['where'] ) && isset( $params['where'][0] ) && isset( $params['where'][1] ) ) {
|
96 |
+
$sql .= ' WHERE ' . $params['where'][0];
|
97 |
+
$values += $params['where'][1];
|
98 |
+
} elseif ( ! is_array( $params['where'] ) ) {
|
99 |
+
$sql .= ' WHERE ' . $params['where'];
|
100 |
+
}
|
101 |
+
}
|
102 |
+
if ( ! empty( $params['group'] ) ) {
|
103 |
+
$sql .= ' GROUP BY ' . $params['group'];
|
104 |
+
}
|
105 |
+
if ( ! empty( $params['order'] ) ) {
|
106 |
+
$sql .= ' ORDER BY ' . $params['order'];
|
107 |
+
}
|
108 |
+
if ( ! empty( $params['limit'] ) ) {
|
109 |
+
$sql .= ' LIMIT %d';
|
110 |
+
$values[] = $params['limit'];
|
111 |
+
}
|
112 |
+
if ( ! empty( $params['offset'] ) ) {
|
113 |
+
$sql .= ' OFFSET %d';
|
114 |
+
$values[] = $params['offset'];
|
115 |
+
}
|
116 |
+
|
117 |
+
if ( $values ) {
|
118 |
+
$sql = $this->getDb()->prepare( $sql, $values );
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
return $sql;
|
123 |
+
}
|
124 |
+
|
125 |
+
public function findByPk( $id ) {
|
126 |
+
return $this->getDb()->get_row( $this->getDb()->prepare( 'SELECT * FROM ' . $this->tableName() . ' WHERE id = %d', $id ), ARRAY_A );
|
127 |
+
}
|
128 |
+
|
129 |
+
public function delete( $id ) {
|
130 |
+
return $this->getDb()->delete( $this->tableName(), array( 'id' => $id ), array( '%d' ) );
|
131 |
+
}
|
132 |
+
|
133 |
+
public function deleteAll( $where ) {
|
134 |
+
$values = array();
|
135 |
+
$sql = 'DELETE FROM ' . $this->tableName();
|
136 |
+
$sql .= $this->prepareWhere( $where );
|
137 |
+
|
138 |
+
return $this->getDb()->query( $sql );
|
139 |
+
}
|
140 |
+
|
141 |
+
public function count( $where = null ) {
|
142 |
+
$sql = "SELECT COUNT(*) FROM " . $this->tableName();
|
143 |
+
if ( $where ) {
|
144 |
+
$sql .= $this->prepareWhere( $where );
|
145 |
+
}
|
146 |
+
|
147 |
+
return $this->getDb()->get_var( $sql );
|
148 |
+
}
|
149 |
+
|
150 |
+
public function max( $colum, $where = null ) {
|
151 |
+
$sql = "SELECT MAX(" . $colum . ") FROM " . $this->tableName();
|
152 |
+
if ( $where ) {
|
153 |
+
$sql .= $this->prepareWhere( $where );
|
154 |
+
}
|
155 |
+
|
156 |
+
return $this->getDb()->get_var( $sql );
|
157 |
+
}
|
158 |
+
|
159 |
+
public function min( $colum, $where = null ) {
|
160 |
+
$sql = "SELECT MIN(" . $colum . ") FROM " . $this->tableName();
|
161 |
+
if ( $where ) {
|
162 |
+
$sql .= $this->prepareWhere( $where );
|
163 |
+
}
|
164 |
+
|
165 |
+
return $this->getDb()->get_var( $sql );
|
166 |
+
}
|
167 |
+
|
168 |
+
public function avg( $colum, $where = null ) {
|
169 |
+
$sql = "SELECT AVG(" . $colum . ") FROM " . $this->tableName();
|
170 |
+
if ( $where ) {
|
171 |
+
$sql .= $this->prepareWhere( $where );
|
172 |
+
}
|
173 |
+
|
174 |
+
return $this->getDb()->get_var( $sql );
|
175 |
+
}
|
176 |
+
|
177 |
+
public function prepareWhere( $where, $winclude = true ) {
|
178 |
+
if ( $winclude ) {
|
179 |
+
$sql = ' WHERE ';
|
180 |
+
} else {
|
181 |
+
$sql = '';
|
182 |
+
}
|
183 |
+
$values = array();
|
184 |
+
if ( is_array( $where ) && isset( $where[0] ) && isset( $where[1] ) ) {
|
185 |
+
$sql .= $where[0];
|
186 |
+
$values += $where[1];
|
187 |
+
} elseif ( is_string( $where ) ) {
|
188 |
+
$sql .= $where;
|
189 |
+
} else {
|
190 |
+
throw new \Exception( 'Wrong WHERE params.' );
|
191 |
+
}
|
192 |
+
if ( $values ) {
|
193 |
+
$sql = $this->getDb()->prepare( $sql, $values );
|
194 |
+
}
|
195 |
+
|
196 |
+
return $sql;
|
197 |
+
}
|
198 |
+
|
199 |
+
public function save( array $item ) {
|
200 |
+
$item['id'] = (int) $item['id'];
|
201 |
+
if ( ! $item['id'] ) {
|
202 |
+
$item['id'] = null;
|
203 |
+
$this->getDb()->insert( $this->tableName(), $item );
|
204 |
+
|
205 |
+
return $this->getDb()->insert_id;
|
206 |
+
} else {
|
207 |
+
$this->getDb()->update( $this->tableName(), $item, array( 'id' => $item['id'] ) );
|
208 |
+
|
209 |
+
return $item['id'];
|
210 |
+
}
|
211 |
+
}
|
212 |
+
|
213 |
+
public function insert( array $item ) {
|
214 |
+
return $this->getDb()->insert( $this->tableName(), $item );
|
215 |
+
}
|
216 |
+
|
217 |
+
public function cleanOld( $days, $optimize = true, $date_field = 'create_date' ) {
|
218 |
+
$this->deleteAll( 'TIMESTAMPDIFF( DAY, ' . $date_field . ', "' . \current_time( 'mysql' ) . '") > ' . $days );
|
219 |
+
if ( $optimize ) {
|
220 |
+
$this->optimizeTable();
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
public function optimizeTable() {
|
225 |
+
$this->getDb()->query( 'OPTIMIZE TABLE ' . $this->tableName() );
|
226 |
+
}
|
227 |
+
|
228 |
+
public function truncateTable() {
|
229 |
+
$this->getDb()->query( 'TRUNCATE TABLE ' . $this->tableName() );
|
230 |
+
}
|
231 |
+
|
232 |
+
public function isTableExists() {
|
233 |
+
$query = $this->getDb()->prepare( 'SHOW TABLES LIKE %s', $this->getDb()->esc_like( $this->tableName() ) );
|
234 |
+
|
235 |
+
if ( $this->getDb()->get_var( $query ) == $this->tableName() ) {
|
236 |
+
return true;
|
237 |
+
} else {
|
238 |
+
return false;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
public function multipleInsert( array $items, $per_request = 200 ) {
|
243 |
+
$fields = array_keys( reset( $items ) );
|
244 |
+
$sql = 'INSERT INTO ' . $this->tableName() . ' (' . join( ',', $fields ) . ') VALUES ';
|
245 |
+
$placeholder = str_repeat( '%s, ', count( $fields ) );
|
246 |
+
$placeholder = '(' . rtrim( $placeholder, " ," ) . ')';
|
247 |
+
|
248 |
+
reset( $items );
|
249 |
+
$request_count = ceil( count( $items ) / $per_request );
|
250 |
+
for ( $i = 0; $i < $request_count; $i ++ ) {
|
251 |
+
$query = $sql;
|
252 |
+
$values = array();
|
253 |
+
$place_holders = array();
|
254 |
+
for ( $j = $i * $per_request; $j < $i * $per_request + $per_request; $j ++ ) {
|
255 |
+
if ( ! isset( $items[ $j ] ) ) {
|
256 |
+
break;
|
257 |
+
}
|
258 |
+
$query .= $this->getDb()->prepare( $placeholder, $items[ $j ] ) . ', ';
|
259 |
+
}
|
260 |
+
$query = rtrim( $query, " ," ) . ';';
|
261 |
+
$this->getDb()->query( $query );
|
262 |
+
}
|
263 |
+
}
|
264 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
}
|
application/models/PriceAlertModel.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
@@ -15,19 +15,17 @@ use ContentEgg\application\helpers\TextHelper;
|
|
15 |
*/
|
16 |
class PriceAlertModel extends Model {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
return "CREATE TABLE " . $this->tableName() . " (
|
31 |
id bigint(20) unsigned NOT NULL auto_increment,
|
32 |
unique_id varchar(255) NOT NULL,
|
33 |
module_id varchar(255) NOT NULL,
|
@@ -43,53 +41,53 @@ class PriceAlertModel extends Model {
|
|
43 |
KEY uid (unique_id(80),module_id(30)),
|
44 |
KEY status (status)
|
45 |
) $this->charset_collate;";
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
}
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
$this->deleteAll('status = ' . self::STATUS_DELETED . ' AND TIMESTAMPDIFF( DAY, ' . $date_field . ', "' . \current_time('mysql') . '") > ' . $days);
|
67 |
-
if ($optimize)
|
68 |
-
$this->optimizeTable();
|
69 |
-
}
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
return $statuses[$id];
|
82 |
-
else
|
83 |
-
return null;
|
84 |
-
}
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\helpers\TextHelper;
|
8 |
|
15 |
*/
|
16 |
class PriceAlertModel extends Model {
|
17 |
|
18 |
+
const STATUS_INACTIVE = 0;
|
19 |
+
const STATUS_ACTIVE = 1;
|
20 |
+
const STATUS_DELETED = 3;
|
21 |
+
const CLEAN_DELETED_DAYS = 180;
|
22 |
|
23 |
+
public function tableName() {
|
24 |
+
return $this->getDb()->prefix . 'cegg_price_alert';
|
25 |
+
}
|
|
|
26 |
|
27 |
+
public function getDump() {
|
28 |
+
return "CREATE TABLE " . $this->tableName() . " (
|
|
|
29 |
id bigint(20) unsigned NOT NULL auto_increment,
|
30 |
unique_id varchar(255) NOT NULL,
|
31 |
module_id varchar(255) NOT NULL,
|
41 |
KEY uid (unique_id(80),module_id(30)),
|
42 |
KEY status (status)
|
43 |
) $this->charset_collate;";
|
44 |
+
}
|
45 |
|
46 |
+
public static function model( $className = __CLASS__ ) {
|
47 |
+
return parent::model( $className );
|
48 |
+
}
|
|
|
49 |
|
50 |
+
public function save( array $item ) {
|
51 |
+
if ( empty( $item['create_date'] ) ) {
|
52 |
+
$item['create_date'] = \current_time( 'mysql' );
|
53 |
+
}
|
54 |
+
if ( ! isset( $item['status'] ) ) {
|
55 |
+
$item['status'] = self::STATUS_INACTIVE;
|
56 |
+
}
|
57 |
+
if ( ! isset( $item['activkey'] ) ) {
|
58 |
+
$item['activkey'] = TextHelper::randomPassword( 16 );
|
59 |
+
}
|
60 |
|
61 |
+
return parent::save( $item );
|
62 |
+
}
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
public function cleanOld( $days, $optimize = true, $date_field = 'complet_date' ) {
|
65 |
+
$this->deleteAll( 'status = ' . self::STATUS_DELETED . ' AND TIMESTAMPDIFF( DAY, ' . $date_field . ', "' . \current_time( 'mysql' ) . '") > ' . $days );
|
66 |
+
if ( $optimize ) {
|
67 |
+
$this->optimizeTable();
|
68 |
+
}
|
69 |
+
}
|
70 |
|
71 |
+
public function unsubscribeAll( $email ) {
|
72 |
+
$sql = 'DELETE FROM ' . $this->tableName() . ' WHERE email = %s AND status != %d';
|
73 |
+
$this->getDb()->query( $this->getDb()->prepare( $sql, $email, self::STATUS_DELETED ) );
|
74 |
+
}
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
public static function getStatus( $id ) {
|
77 |
+
$statuses = self::getStatuses();
|
78 |
+
if ( isset( $statuses[ $id ] ) ) {
|
79 |
+
return $statuses[ $id ];
|
80 |
+
} else {
|
81 |
+
return null;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
public static function getStatuses() {
|
86 |
+
return array(
|
87 |
+
self::STATUS_INACTIVE => 'INACTIVE',
|
88 |
+
self::STATUS_ACTIVE => 'ACTIVE',
|
89 |
+
self::STATUS_DELETED => 'DELETED',
|
90 |
+
);
|
91 |
+
}
|
92 |
|
93 |
}
|
application/models/PriceHistoryModel.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
|
@@ -15,15 +15,13 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
15 |
*/
|
16 |
class PriceHistoryModel extends Model {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
}
|
22 |
|
23 |
-
|
24 |
-
{
|
25 |
|
26 |
-
|
27 |
unique_id varchar(255) NOT NULL,
|
28 |
module_id varchar(255) NOT NULL,
|
29 |
create_date datetime NOT NULL,
|
@@ -38,184 +36,194 @@ class PriceHistoryModel extends Model {
|
|
38 |
KEY price_old (price_old),
|
39 |
KEY is_latest (is_latest)
|
40 |
) $this->charset_collate;";
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
FROM ' . $this->tableName() . ' t
|
88 |
WHERE price=(SELECT MAX(price) FROM ' . $this->tableName() . ' WHERE unique_id = %s AND module_id = %s AND ' . $where . ')
|
89 |
AND unique_id = %s AND module_id = %s AND ' . $where;
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
SELECT
|
220 |
MAX(p_last.create_date) as last_date,
|
221 |
p_last.unique_id,
|
@@ -235,40 +243,40 @@ class PriceHistoryModel extends Model {
|
|
235 |
GROUP BY unique_id
|
236 |
ORDER BY `change` ' . $order . '
|
237 |
LIMIT ' . $params['limit'];
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
SELECT
|
273 |
price_history.*, ' . $change . ' as pchange
|
274 |
FROM ' . $this->tableName() . ' as price_history
|
@@ -279,15 +287,16 @@ class PriceHistoryModel extends Model {
|
|
279 |
GROUP BY unique_id
|
280 |
ORDER BY pchange ' . $order . '
|
281 |
LIMIT ' . $limit;
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
|
|
292 |
|
293 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\GeneralConfig;
|
8 |
|
15 |
*/
|
16 |
class PriceHistoryModel extends Model {
|
17 |
|
18 |
+
public function tableName() {
|
19 |
+
return $this->getDb()->prefix . 'cegg_price_history';
|
20 |
+
}
|
|
|
21 |
|
22 |
+
public function getDump() {
|
|
|
23 |
|
24 |
+
return "CREATE TABLE " . $this->tableName() . " (
|
25 |
unique_id varchar(255) NOT NULL,
|
26 |
module_id varchar(255) NOT NULL,
|
27 |
create_date datetime NOT NULL,
|
36 |
KEY price_old (price_old),
|
37 |
KEY is_latest (is_latest)
|
38 |
) $this->charset_collate;";
|
39 |
+
}
|
40 |
+
|
41 |
+
public static function model( $className = __CLASS__ ) {
|
42 |
+
return parent::model( $className );
|
43 |
+
}
|
44 |
+
|
45 |
+
public function save( array $item ) {
|
46 |
+
$item['is_latest'] = 1;
|
47 |
+
if ( empty( $item['create_date'] ) ) {
|
48 |
+
$item['create_date'] = current_time( 'mysql' );
|
49 |
+
}
|
50 |
+
|
51 |
+
if ( empty( $item['price_old'] ) ) {
|
52 |
+
$old_data = $this->getOldPrice( $item['unique_id'], $item['module_id'] );
|
53 |
+
if ( $old_data ) {
|
54 |
+
$item['price_old'] = $old_data['price'];
|
55 |
+
$item['price_old_date'] = $old_data['create_date'];
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
$this->getDb()->update( $this->tableName(), array( 'is_latest' => 0 ), array(
|
60 |
+
'unique_id' => $item['unique_id'],
|
61 |
+
'module_id' => $item['module_id']
|
62 |
+
) );
|
63 |
+
$this->getDb()->insert( $this->tableName(), $item );
|
64 |
+
|
65 |
+
\do_action( 'content_egg_price_history_save', $item );
|
66 |
+
|
67 |
+
return true;
|
68 |
+
}
|
69 |
+
|
70 |
+
private function getOldPrice( $unique_id, $module_id ) {
|
71 |
+
// price known date
|
72 |
+
$price_drops_days = (int) GeneralConfig::getInstance()->option( 'price_drops_days' );
|
73 |
+
$sql = 'SELECT create_date FROM ' . $this->tableName() . ' WHERE unique_id = %s AND module_id = %s AND create_date <= NOW() - INTERVAL %d DAY ORDER BY create_date DESC LIMIT 1';
|
74 |
+
$sql = $this->getDb()->prepare( $sql, array( $unique_id, $module_id, $price_drops_days ) );
|
75 |
+
$known_date = $this->getDb()->get_var( $sql );
|
76 |
+
|
77 |
+
$where = '';
|
78 |
+
if ( $known_date ) {
|
79 |
+
$where = $this->getDb()->prepare( 'create_date > %s', array( $known_date ) );
|
80 |
+
} else {
|
81 |
+
$where = $this->getDb()->prepare( 'create_date >= NOW() - INTERVAL %d DAY', array( $price_drops_days ) );
|
82 |
+
}
|
83 |
+
|
84 |
+
$sql = 'SELECT t.*
|
85 |
FROM ' . $this->tableName() . ' t
|
86 |
WHERE price=(SELECT MAX(price) FROM ' . $this->tableName() . ' WHERE unique_id = %s AND module_id = %s AND ' . $where . ')
|
87 |
AND unique_id = %s AND module_id = %s AND ' . $where;
|
88 |
|
89 |
+
$sql = $this->getDb()->prepare( $sql, array( $unique_id, $module_id, $unique_id, $module_id ) );
|
90 |
+
$old_data = $this->getDb()->get_row( $sql, \ARRAY_A );
|
91 |
+
|
92 |
+
return $old_data;
|
93 |
+
}
|
94 |
+
|
95 |
+
public function getLastPriceValue( $unique_id, $module_id, $offset = null ) {
|
96 |
+
$params = array(
|
97 |
+
'select' => 'price',
|
98 |
+
'where' => array( 'unique_id = %s AND module_id = %s', array( $unique_id, $module_id ) ),
|
99 |
+
'order' => 'create_date DESC',
|
100 |
+
'limit' => 1
|
101 |
+
);
|
102 |
+
if ( $offset ) {
|
103 |
+
$params['offset'] = $offset;
|
104 |
+
}
|
105 |
+
$row = $this->find( $params );
|
106 |
+
if ( ! $row ) {
|
107 |
+
return null;
|
108 |
+
}
|
109 |
+
|
110 |
+
return $row['price'];
|
111 |
+
}
|
112 |
+
|
113 |
+
public function getPreviousPriceValue( $unique_id, $module_id ) {
|
114 |
+
return $this->getLastPriceValue( $unique_id, $module_id, 1 );
|
115 |
+
}
|
116 |
+
|
117 |
+
public function getFirstDateValue( $unique_id, $module_id ) {
|
118 |
+
$params = array(
|
119 |
+
'select' => 'create_date',
|
120 |
+
'where' => array( 'unique_id = %s AND module_id = %s', array( $unique_id, $module_id ) ),
|
121 |
+
'order' => 'create_date ASC',
|
122 |
+
'limit' => 1
|
123 |
+
);
|
124 |
+
$row = $this->find( $params );
|
125 |
+
if ( ! $row ) {
|
126 |
+
return null;
|
127 |
+
}
|
128 |
+
|
129 |
+
return $row['create_date'];
|
130 |
+
}
|
131 |
+
|
132 |
+
public function getLastPrices( $unique_id, $module_id, $limit = 5 ) {
|
133 |
+
$params = array(
|
134 |
+
'where' => array( 'unique_id = %s AND module_id = %s', array( $unique_id, $module_id ) ),
|
135 |
+
'order' => 'create_date DESC',
|
136 |
+
'limit' => $limit,
|
137 |
+
);
|
138 |
+
|
139 |
+
return $this->findAll( $params );
|
140 |
+
}
|
141 |
+
|
142 |
+
public function getMaxPrice( $unique_id, $module_id ) {
|
143 |
+
$where = $this->prepareWhere( ( array(
|
144 |
+
'unique_id = %s AND module_id = %s',
|
145 |
+
array( $unique_id, $module_id )
|
146 |
+
) ) );
|
147 |
+
$sql = 'SELECT t.* FROM ' . $this->tableName() . ' t';
|
148 |
+
$sql .= ' JOIN (SELECT unique_id, MAX(price) maxPrice FROM ' . $this->tableName() . $where . ') t2 ON t.price = t2.maxPrice AND t.unique_id = t2.unique_id;';
|
149 |
+
|
150 |
+
return $this->getDb()->get_row( $sql, \ARRAY_A );
|
151 |
+
}
|
152 |
+
|
153 |
+
public function getMinPrice( $unique_id, $module_id ) {
|
154 |
+
$where = $this->prepareWhere( ( array(
|
155 |
+
'unique_id = %s AND module_id = %s',
|
156 |
+
array( $unique_id, $module_id )
|
157 |
+
) ) );
|
158 |
+
$sql = 'SELECT t.* FROM ' . $this->tableName() . ' t';
|
159 |
+
$sql .= ' JOIN (SELECT unique_id, MIN(price) minPrice FROM ' . $this->tableName() . $where . ') t2 ON t.price = t2.minPrice AND t.unique_id = t2.unique_id;';
|
160 |
+
|
161 |
+
return $this->getDb()->get_row( $sql, \ARRAY_A );
|
162 |
+
}
|
163 |
+
|
164 |
+
public function saveData( array $data, $module_id, $post_id = null ) {
|
165 |
+
if ( ! $post_id ) {
|
166 |
+
global $post;
|
167 |
+
if ( ! empty( $post ) ) {
|
168 |
+
$post_id = $post->ID;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
$saved = 0;
|
172 |
+
foreach ( $data as $key => $d ) {
|
173 |
+
if ( empty( $d['unique_id'] ) || empty( $d['price'] ) ) {
|
174 |
+
continue;
|
175 |
+
}
|
176 |
+
|
177 |
+
$latest_price = $this->getLastPriceValue( $d['unique_id'], $module_id );
|
178 |
+
|
179 |
+
// price changed?
|
180 |
+
if ( $latest_price && (float) $latest_price == (float) $d['price'] ) {
|
181 |
+
continue;
|
182 |
+
}
|
183 |
+
|
184 |
+
$save = array(
|
185 |
+
'unique_id' => $d['unique_id'],
|
186 |
+
'module_id' => $module_id,
|
187 |
+
'price' => $d['price'],
|
188 |
+
'post_id' => $post_id,
|
189 |
+
);
|
190 |
+
$this->save( $save );
|
191 |
+
$saved ++;
|
192 |
+
}
|
193 |
+
|
194 |
+
// clean up & optimize
|
195 |
+
if ( $saved && rand( 1, 10 ) == 10 ) {
|
196 |
+
$this->cleanOld( (int) GeneralConfig::getInstance()->option( 'price_history_days' ) );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
public function getPriceMoversOld( array $params = array() ) {
|
201 |
+
|
202 |
+
$defaults = array(
|
203 |
+
'time_period' => 7,
|
204 |
+
'limit' => 5,
|
205 |
+
'drop_type' => 'absolute',
|
206 |
+
'direction' => 'drops',
|
207 |
+
);
|
208 |
+
$params = \wp_parse_args( $params, $defaults );
|
209 |
+
|
210 |
+
$params['time_period'] = (int) $params['time_period'];
|
211 |
+
$params['limit'] = (int) $params['limit'];
|
212 |
+
|
213 |
+
if ( $params['direction'] == 'drops' ) {
|
214 |
+
$order = 'DESC';
|
215 |
+
} else {
|
216 |
+
$order = 'ASC';
|
217 |
+
}
|
218 |
+
|
219 |
+
if ( $params['drop_type'] == 'relative' ) {
|
220 |
+
$change = '(100 - (p_last.price * 100) / p_prev.price)';
|
221 |
+
} //relative
|
222 |
+
else {
|
223 |
+
$change = '(p_prev.price - p_last.price)';
|
224 |
+
} // absolute
|
225 |
+
|
226 |
+
$sql = '
|
227 |
SELECT
|
228 |
MAX(p_last.create_date) as last_date,
|
229 |
p_last.unique_id,
|
243 |
GROUP BY unique_id
|
244 |
ORDER BY `change` ' . $order . '
|
245 |
LIMIT ' . $params['limit'];
|
246 |
+
|
247 |
+
return $this->getDb()->get_results( $sql, \ARRAY_A );
|
248 |
+
}
|
249 |
+
|
250 |
+
public function getPriceMovers( array $params = array(), $double_limit = false ) {
|
251 |
+
$defaults = array(
|
252 |
+
'limit' => 5,
|
253 |
+
'last_update' => 7,
|
254 |
+
'drop_type' => 'absolute',
|
255 |
+
'direction' => 'drops',
|
256 |
+
);
|
257 |
+
$params = \wp_parse_args( $params, $defaults );
|
258 |
+
$params['limit'] = (int) $params['limit'];
|
259 |
+
$params['last_update'] = (int) $params['last_update'];
|
260 |
+
if ( $params['direction'] == 'drops' ) {
|
261 |
+
$order = 'DESC';
|
262 |
+
$direction_where = 'price_old - price >= 0';
|
263 |
+
} else {
|
264 |
+
$order = 'ASC';
|
265 |
+
$direction_where = 'price_old - price <= 0';
|
266 |
+
}
|
267 |
+
|
268 |
+
$limit = $params['limit'];
|
269 |
+
if ( $double_limit ) {
|
270 |
+
$limit *= 2;
|
271 |
+
}
|
272 |
+
|
273 |
+
if ( $params['drop_type'] == 'relative' ) {
|
274 |
+
$change = '(100 - (price * 100) / price_old)';
|
275 |
+
} else {
|
276 |
+
$change = '(price_old - price)';
|
277 |
+
} // absolute
|
278 |
+
|
279 |
+
$sql = '
|
280 |
SELECT
|
281 |
price_history.*, ' . $change . ' as pchange
|
282 |
FROM ' . $this->tableName() . ' as price_history
|
287 |
GROUP BY unique_id
|
288 |
ORDER BY pchange ' . $order . '
|
289 |
LIMIT ' . $limit;
|
290 |
+
$results = $this->getDb()->get_results( $sql, \ARRAY_A );
|
291 |
+
|
292 |
+
$return = array();
|
293 |
+
foreach ( $results as $i => $r ) {
|
294 |
+
if ( \get_post_status( $r['post_id'] ) == 'publish' ) {
|
295 |
+
$return[] = $r;
|
296 |
+
}
|
297 |
+
}
|
298 |
+
|
299 |
+
return $return;
|
300 |
+
}
|
301 |
|
302 |
}
|
application/models/ProductModel.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
@@ -17,18 +17,16 @@ use ContentEgg\application\components\ContentProduct;
|
|
17 |
*/
|
18 |
class ProductModel extends Model {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
}
|
27 |
|
28 |
-
|
29 |
-
{
|
30 |
|
31 |
-
|
32 |
id int(11) unsigned NOT NULL auto_increment,
|
33 |
unique_id varchar(255) NOT NULL,
|
34 |
module_id varchar(255) NOT NULL,
|
@@ -48,156 +46,148 @@ class ProductModel extends Model {
|
|
48 |
KEY uid (unique_id(80),module_id(30)),
|
49 |
KEY post_id (post_id)
|
50 |
) $this->charset_collate;";
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
static public function getStockStatus($status_id)
|
195 |
-
{
|
196 |
-
$statuses = ProductModel::getStockStatuses();
|
197 |
-
if (isset($status[$status_id]))
|
198 |
-
return $status[$status_id];
|
199 |
-
else
|
200 |
-
return null;
|
201 |
-
}
|
202 |
|
203 |
}
|
2 |
|
3 |
namespace ContentEgg\application\models;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ContentManager;
|
8 |
use ContentEgg\application\components\ModuleManager;
|
17 |
*/
|
18 |
class ProductModel extends Model {
|
19 |
|
20 |
+
const TRANSIENT_LAST_SYNC_DATE = 'cegg_products_last_sync';
|
21 |
+
const PRODUCTS_TTL = 3600;
|
22 |
|
23 |
+
public function tableName() {
|
24 |
+
return $this->getDb()->prefix . 'cegg_product';
|
25 |
+
}
|
|
|
26 |
|
27 |
+
public function getDump() {
|
|
|
28 |
|
29 |
+
return "CREATE TABLE " . $this->tableName() . " (
|
30 |
id int(11) unsigned NOT NULL auto_increment,
|
31 |
unique_id varchar(255) NOT NULL,
|
32 |
module_id varchar(255) NOT NULL,
|
46 |
KEY uid (unique_id(80),module_id(30)),
|
47 |
KEY post_id (post_id)
|
48 |
) $this->charset_collate;";
|
49 |
+
}
|
50 |
+
|
51 |
+
public static function model( $className = __CLASS__ ) {
|
52 |
+
return parent::model( $className );
|
53 |
+
}
|
54 |
+
|
55 |
+
public function attributeLabels() {
|
56 |
+
return array(
|
57 |
+
'id' => 'ID',
|
58 |
+
'title' => __( 'Title', 'content-egg' ),
|
59 |
+
'stock_status' => __( 'Stock', 'content-egg' ),
|
60 |
+
'price' => __( 'Price', 'content-egg' ),
|
61 |
+
);
|
62 |
+
}
|
63 |
+
|
64 |
+
public function scanProducts() {
|
65 |
+
$per_page = 100;
|
66 |
+
$meta_keys = $this->getCeMetaKeys();
|
67 |
+
$sql_part = $this->getDb()->postmeta . ' WHERE meta_key IN (' . join( ',', $meta_keys ) . ') LIMIT ' . $per_page;
|
68 |
+
$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM ' . $sql_part;
|
69 |
+
$products = $this->getDb()->get_results( $sql );
|
70 |
+
$total = (int) $this->getDb()->get_var( 'SELECT FOUND_ROWS();' );
|
71 |
+
$this->processProducts( $products );
|
72 |
+
|
73 |
+
for ( $page = 2; $page <= ceil( $total / $per_page ); $page ++ ) {
|
74 |
+
$offset = ( $page - 1 ) * $per_page;
|
75 |
+
$sql = 'SELECT * FROM ' . $sql_part . ' OFFSET ' . $offset;
|
76 |
+
$this->processProducts( $this->getDb()->get_results( $sql ) );
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
private function getCeMetaKeys() {
|
81 |
+
$module_ids = array_keys( ModuleManager::getInstance()->getAffiliateParsers( true, true ) );
|
82 |
+
$meta_keys = array();
|
83 |
+
foreach ( $module_ids as $module_id ) {
|
84 |
+
$meta_keys[] = "'" . \esc_sql( ContentManager::META_PREFIX_DATA . $module_id ) . "'";
|
85 |
+
}
|
86 |
+
|
87 |
+
return $meta_keys;
|
88 |
+
}
|
89 |
+
|
90 |
+
public function maybeScanProducts( $forced = false ) {
|
91 |
+
if ( ! $this->getLastSync() || $forced ) {
|
92 |
+
$this->truncateTable();
|
93 |
+
ProductModel::model()->scanProducts();
|
94 |
+
\set_transient( self::TRANSIENT_LAST_SYNC_DATE, time(), self::PRODUCTS_TTL );
|
95 |
+
|
96 |
+
return true;
|
97 |
+
}
|
98 |
+
|
99 |
+
return false;
|
100 |
+
}
|
101 |
+
|
102 |
+
public function getLastSync() {
|
103 |
+
return \get_transient( self::TRANSIENT_LAST_SYNC_DATE );
|
104 |
+
}
|
105 |
+
|
106 |
+
private function processProducts( array $metas ) {
|
107 |
+
$all_products = array();
|
108 |
+
foreach ( $metas as $meta ) {
|
109 |
+
if ( ! $data = @unserialize( $meta->meta_value ) ) {
|
110 |
+
continue;
|
111 |
+
}
|
112 |
+
|
113 |
+
// corrupted data?
|
114 |
+
if ( ! is_array( $data ) ) {
|
115 |
+
continue;
|
116 |
+
}
|
117 |
+
|
118 |
+
$all_products = array_merge( $all_products, $this->processModuleData( $data, $meta ) );
|
119 |
+
}
|
120 |
+
if ( $all_products ) {
|
121 |
+
$this->multipleInsert( $all_products );
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
private function processModuleData( array $data, $meta ) {
|
126 |
+
$products = array();
|
127 |
+
foreach ( $data as $unique_id => $d ) {
|
128 |
+
if ( ! $unique_id ) {
|
129 |
+
continue;
|
130 |
+
}
|
131 |
+
|
132 |
+
$product = array(
|
133 |
+
'last_update' => '',
|
134 |
+
'stock_status' => ContentProduct::STOCK_STATUS_UNKNOWN,
|
135 |
+
'price' => 0,
|
136 |
+
'price_old' => 0,
|
137 |
+
'currency_code' => '',
|
138 |
+
'title' => '',
|
139 |
+
'img' => '',
|
140 |
+
'url' => '',
|
141 |
+
);
|
142 |
+
foreach ( $product as $k => $v ) {
|
143 |
+
if ( isset( $d[ $k ] ) ) {
|
144 |
+
$product[ $k ] = $d[ $k ];
|
145 |
+
} elseif ( strstr( $k, '_' ) ) {
|
146 |
+
$pieces = explode( '_', $k );
|
147 |
+
for ( $i = 1; $i < count( $pieces ); $i ++ ) {
|
148 |
+
$pieces[ $i ] = ucfirst( $pieces[ $i ] );
|
149 |
+
}
|
150 |
+
$kd = join( '', $pieces );
|
151 |
+
if ( isset( $d[ $kd ] ) ) {
|
152 |
+
$product[ $k ] = $d[ $kd ];
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
if ( $product['last_update'] ) {
|
158 |
+
$product['last_update'] = date( "Y-m-d H:i:s", $product['last_update'] );
|
159 |
+
} else {
|
160 |
+
$product['last_update'] = null;
|
161 |
+
}
|
162 |
+
|
163 |
+
$product['id'] = null;
|
164 |
+
$product['create_date'] = \current_time( 'mysql' );
|
165 |
+
$product['unique_id'] = $d['unique_id'];
|
166 |
+
$product['module_id'] = str_replace( ContentManager::META_PREFIX_DATA, '', $meta->meta_key );
|
167 |
+
$product['meta_id'] = $meta->meta_id;
|
168 |
+
$product['post_id'] = $meta->post_id;
|
169 |
+
|
170 |
+
$products[] = $product;
|
171 |
+
}
|
172 |
+
|
173 |
+
return $products;
|
174 |
+
}
|
175 |
+
|
176 |
+
static public function getStockStatuses() {
|
177 |
+
return array(
|
178 |
+
ContentProduct::STOCK_STATUS_IN_STOCK => __( 'In stock', 'content-egg' ),
|
179 |
+
ContentProduct::STOCK_STATUS_OUT_OF_STOCK => __( 'Out of stock', 'content-egg' ),
|
180 |
+
ContentProduct::STOCK_STATUS_UNKNOWN => __( 'Unknown', 'content-egg' ),
|
181 |
+
);
|
182 |
+
}
|
183 |
+
|
184 |
+
static public function getStockStatus( $status_id ) {
|
185 |
+
$statuses = ProductModel::getStockStatuses();
|
186 |
+
if ( isset( $status[ $status_id ] ) ) {
|
187 |
+
return $status[ $status_id ];
|
188 |
+
} else {
|
189 |
+
return null;
|
190 |
+
}
|
191 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
}
|
application/modules/AE/AEConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
@@ -15,89 +15,89 @@ use ContentEgg\application\components\AffiliateParserModuleConfig;
|
|
15 |
*/
|
16 |
class AEConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
'
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
'
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
);
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
|
103 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
15 |
*/
|
16 |
class AEConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
+
public function options() {
|
19 |
+
$options = array(
|
20 |
+
'deeplink' => array(
|
21 |
+
'title' => __( 'Affiliate link', 'content-egg' ),
|
22 |
+
'description' => __( 'Set Deeplink for one of CPA-networks. For direct affiliate programs you can use parameter as <em>partner_id=12345</em>, or make link as template, for example, <em>{{url}}/partner_id-12345/</em>. Another example is https://ad.admitad.com/g/g8f0qmlavfa/?ulp={{url_encoded}}. {{url}} and {{url_encoded}} - will be replaced by product url. If product url is after affiliate url - use {{url_encoded}}', 'content-egg' ),
|
23 |
+
'callback' => array( $this, 'render_input' ),
|
24 |
+
'default' => '',
|
25 |
+
'validator' => array(
|
26 |
+
'trim',
|
27 |
+
),
|
28 |
+
'section' => 'default',
|
29 |
+
),
|
30 |
+
'entries_per_page' => array(
|
31 |
+
'title' => __( 'Results', 'content-egg' ),
|
32 |
+
'description' => __( 'Number of results for one search query.', 'content-egg' ),
|
33 |
+
'callback' => array( $this, 'render_input' ),
|
34 |
+
'default' => 3,
|
35 |
+
'validator' => array(
|
36 |
+
'trim',
|
37 |
+
'absint',
|
38 |
+
array(
|
39 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
40 |
+
'arg' => 50,
|
41 |
+
'message' => __( 'The field "Results" can not be more than 50.', 'content-egg' ),
|
42 |
+
),
|
43 |
+
),
|
44 |
+
'section' => 'default',
|
45 |
+
),
|
46 |
+
'entries_per_page_update' => array(
|
47 |
+
'title' => __( 'Results for updates and autoblogging', 'content-egg' ),
|
48 |
+
'description' => __( 'Number of results for automatic updates and autoblogging.', 'content-egg' ),
|
49 |
+
'callback' => array( $this, 'render_input' ),
|
50 |
+
'default' => 3,
|
51 |
+
'validator' => array(
|
52 |
+
'trim',
|
53 |
+
'absint',
|
54 |
+
array(
|
55 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
56 |
+
'arg' => 50,
|
57 |
+
'message' => __( 'The field "Results" can not be more than 50.', 'content-egg' ),
|
58 |
+
),
|
59 |
+
),
|
60 |
+
'section' => 'default',
|
61 |
+
),
|
62 |
+
'reviews_as_comments' => array(
|
63 |
+
'title' => __( 'Reviews as post comments', 'content-egg' ),
|
64 |
+
'description' => __( 'Save user reviews as post comments.', 'content-egg' ),
|
65 |
+
'callback' => array( $this, 'render_checkbox' ),
|
66 |
+
'default' => false,
|
67 |
+
'section' => 'default',
|
68 |
+
),
|
69 |
+
'save_img' => array(
|
70 |
+
'title' => __( 'Save images', 'content-egg' ),
|
71 |
+
'description' => __( 'Save images on local server.', 'content-egg' ),
|
72 |
+
'callback' => array( $this, 'render_checkbox' ),
|
73 |
+
'default' => false,
|
74 |
+
'section' => 'default',
|
75 |
+
),
|
76 |
+
'show_small_logos' => array(
|
77 |
+
'title' => __( 'Small logos', 'content-egg' ),
|
78 |
+
'callback' => array( $this, 'render_dropdown' ),
|
79 |
+
'dropdown_options' => array(
|
80 |
+
'true' => __( 'Show small logos', 'content-egg' ),
|
81 |
+
'false' => __( 'Hide small logos', 'content-egg' ),
|
82 |
+
),
|
83 |
+
'default' => 'true',
|
84 |
+
),
|
85 |
+
'show_large_logos' => array(
|
86 |
+
'title' => __( 'Large logos', 'content-egg' ),
|
87 |
+
'callback' => array( $this, 'render_dropdown' ),
|
88 |
+
'dropdown_options' => array(
|
89 |
+
'true' => __( 'Show large logos', 'content-egg' ),
|
90 |
+
'false' => __( 'Hide large logos', 'content-egg' ),
|
91 |
+
),
|
92 |
+
'default' => 'true',
|
93 |
+
),
|
94 |
+
);
|
|
|
95 |
|
96 |
+
$parent = parent::options();
|
97 |
+
$parent['ttl']['default'] = 4320000;
|
98 |
+
$parent['ttl_items']['default'] = 2592000;
|
99 |
+
|
100 |
+
return array_merge( $parent, $options );
|
101 |
+
}
|
102 |
|
103 |
}
|
application/modules/AE/AEModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\AeIntegrationConfig;
|
8 |
use ContentEgg\application\components\AffiliateParserModule;
|
@@ -22,311 +22,292 @@ use \Keywordrush\AffiliateEgg\ParserManager;
|
|
22 |
*/
|
23 |
class AEModule extends AffiliateParserModule {
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
public function viewDataPrepare($data)
|
313 |
-
{
|
314 |
-
$deeplink = $this->config('deeplink');
|
315 |
-
foreach ($data as $key => $d)
|
316 |
-
{
|
317 |
-
$data[$key]['url'] = LinkHandler::createAffUrl($d['orig_url'], $deeplink, $d);
|
318 |
-
}
|
319 |
-
return parent::viewDataPrepare($data);
|
320 |
-
}
|
321 |
-
|
322 |
-
public function renderResults()
|
323 |
-
{
|
324 |
-
PluginAdmin::render('_metabox_results', array('module_id' => $this->getId()));
|
325 |
-
}
|
326 |
-
|
327 |
-
public function renderSearchResults()
|
328 |
-
{
|
329 |
-
PluginAdmin::render('_metabox_search_results', array('module_id' => $this->getId()));
|
330 |
-
}
|
331 |
|
332 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\admin\AeIntegrationConfig;
|
8 |
use ContentEgg\application\components\AffiliateParserModule;
|
22 |
*/
|
23 |
class AEModule extends AffiliateParserModule {
|
24 |
|
25 |
+
public function __construct( $module_id = null ) {
|
26 |
+
if ( ! AeIntegrationConfig::isAEIntegrationPosible() ) {
|
27 |
+
throw new \Exception( 'The required Affiliate Egg plugin is not installed.' );
|
28 |
+
}
|
29 |
+
|
30 |
+
parent::__construct( $module_id );
|
31 |
+
}
|
32 |
+
|
33 |
+
public function info() {
|
34 |
+
$name = \Keywordrush\AffiliateEgg\ShopManager::getInstance()->getShopName( $this->getMyShortId() );
|
35 |
+
$uri = $this->getShopHost();
|
36 |
+
$shop = \Keywordrush\AffiliateEgg\ShopManager::getInstance()->getItem( $this->getMyShortId() );
|
37 |
+
if ( method_exists( $shop, 'isDeprecated' ) && $shop->isDeprecated() ) {
|
38 |
+
$name .= ' (deprecated)';
|
39 |
+
}
|
40 |
+
|
41 |
+
return array(
|
42 |
+
'name' => 'AE:' . $name,
|
43 |
+
'description' => sprintf( __( 'Affiliate Egg parser for %s', 'content-egg' ), $uri ),
|
44 |
+
'docs_uri' => 'https://ce-docs.keywordrush.com/modules/affiliate-egg-integration#avoid-getting-blocked',
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
public function getShopHost() {
|
49 |
+
$uri = \Keywordrush\AffiliateEgg\ShopManager::getInstance()->getShopUri( $this->getMyShortId() );
|
50 |
+
$uri = str_replace( 'http://', '', $uri );
|
51 |
+
$uri = str_replace( 'https://', '', $uri );
|
52 |
+
$uri = str_replace( 'www.', '', $uri );
|
53 |
+
$uri = strtolower( $uri );
|
54 |
+
$uri = trim( $uri, "/" );
|
55 |
+
|
56 |
+
return $uri;
|
57 |
+
}
|
58 |
+
|
59 |
+
public function getParserType() {
|
60 |
+
return self::PARSER_TYPE_PRODUCT;
|
61 |
+
}
|
62 |
+
|
63 |
+
public function defaultTemplateName() {
|
64 |
+
return 'data_grid';
|
65 |
+
}
|
66 |
+
|
67 |
+
public function isItemsUpdateAvailable() {
|
68 |
+
return true;
|
69 |
+
}
|
70 |
+
|
71 |
+
public function isFree() {
|
72 |
+
return true;
|
73 |
+
}
|
74 |
+
|
75 |
+
public function isUrlSearchAllowed() {
|
76 |
+
return true;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function doRequest( $keyword, $query_params = array(), $is_autoupdate = false ) {
|
80 |
+
if ( $is_autoupdate ) {
|
81 |
+
$entries_per_page = $this->config( 'entries_per_page_update' );
|
82 |
+
} else {
|
83 |
+
$entries_per_page = $this->config( 'entries_per_page' );
|
84 |
+
}
|
85 |
+
|
86 |
+
$results = array();
|
87 |
+
|
88 |
+
$is_url_passed = false;
|
89 |
+
$is_catalog_url_passed = false;
|
90 |
+
// Catalog url?
|
91 |
+
if ( $keyword[0] == '[' && preg_match( '/^\[catalog(.*?)\](.+)/', $keyword, $matches ) ) {
|
92 |
+
$catalog_default = array(
|
93 |
+
'limit' => $entries_per_page,
|
94 |
+
);
|
95 |
+
if ( $matches[1] ) {
|
96 |
+
$catalog_atts = \shortcode_atts( $catalog_default, \shortcode_parse_atts( $matches[1] ) );
|
97 |
+
} else {
|
98 |
+
$catalog_atts = $catalog_default;
|
99 |
+
}
|
100 |
+
$keyword = trim( $matches[2] );
|
101 |
+
$entries_per_page = (int) $catalog_atts['limit'];
|
102 |
+
$is_catalog_url_passed = true;
|
103 |
+
}
|
104 |
+
|
105 |
+
// 1. Url passed?
|
106 |
+
$is_url_passed = filter_var( $keyword, FILTER_VALIDATE_URL ) && TextHelper::getDomainWithoutSubdomain( $this->getShopHost() ) == TextHelper::getHostName( $keyword );
|
107 |
+
|
108 |
+
try {
|
109 |
+
if ( $is_url_passed ) {
|
110 |
+
$url = $keyword;
|
111 |
+
// parse product by url
|
112 |
+
if ( ! $is_catalog_url_passed ) {
|
113 |
+
$results[] = ParserManager::getInstance()->parseProduct( $url );
|
114 |
+
if ( $results ) {
|
115 |
+
return $this->prepareResults( $results );
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
// try parse catalog
|
120 |
+
$product_urls = ParserManager::getInstance()->parseCatalog( $url, $entries_per_page );
|
121 |
+
if ( ! $product_urls ) {
|
122 |
+
return array();
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
// 2. Parse catalog
|
127 |
+
if ( ! $is_url_passed ) {
|
128 |
+
$product_urls = ParserManager::getInstance()->parseSearchCatalog( $this->getMyShortId(), $keyword, $entries_per_page );
|
129 |
+
if ( ! $product_urls || ! is_array( $product_urls ) ) {
|
130 |
+
return array();
|
131 |
+
}
|
132 |
+
}
|
133 |
+
} catch ( \Exception $e ) {
|
134 |
+
$code = $e->getCode();
|
135 |
+
$message = $e->getMessage();
|
136 |
+
if ( in_array( $code, array( 503, 403 ) ) ) {
|
137 |
+
$message .= '. For more information please refer to https://ce-docs.keywordrush.com/modules/affiliate-egg-integration#avoid-getting-blocked';
|
138 |
+
}
|
139 |
+
|
140 |
+
throw new \Exception( $message, $code );
|
141 |
+
}
|
142 |
+
|
143 |
+
// 3. Parse products
|
144 |
+
$product_sleep = \Keywordrush\AffiliateEgg\GeneralConfig::getInstance()->option( 'product_sleep' );
|
145 |
+
foreach ( $product_urls as $key => $url ) {
|
146 |
+
try {
|
147 |
+
$results[] = ParserManager::getInstance()->parseProduct( $url );
|
148 |
+
} catch ( \Exception $e ) {
|
149 |
+
continue;
|
150 |
+
}
|
151 |
+
|
152 |
+
// sleep
|
153 |
+
if ( $product_sleep && $key < count( $product_urls ) - 1 ) {
|
154 |
+
usleep( $product_sleep );
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
return $this->prepareResults( $results );
|
159 |
+
}
|
160 |
+
|
161 |
+
private function prepareResults( $results ) {
|
162 |
+
$data = array();
|
163 |
+
$deeplink = $this->config( 'deeplink' );
|
164 |
+
|
165 |
+
foreach ( $results as $key => $r ) {
|
166 |
+
$content = new ContentProduct;
|
167 |
+
$content->unique_id = md5( $r['orig_url'] );
|
168 |
+
|
169 |
+
$content->orig_url = $r['orig_url'];
|
170 |
+
$content->domain = TextHelper::getHostName( $r['orig_url'] );
|
171 |
+
//$content->merchant = TemplateHelper::getNameFromDomain($content->domain);
|
172 |
+
$content->img = $r['img'];
|
173 |
+
$content->title = $r['title'];
|
174 |
+
$content->description = $r['description'];
|
175 |
+
$content->price = $r['price'];
|
176 |
+
$content->priceOld = $r['old_price'];
|
177 |
+
$content->currencyCode = $r['currency'];
|
178 |
+
$content->currency = TextHelper::currencyTyping( $content->currencyCode );
|
179 |
+
$content->manufacturer = $r['manufacturer'];
|
180 |
+
$content->availability = $r['in_stock'];
|
181 |
+
if ( $r['in_stock'] ) {
|
182 |
+
$content->stock_status = ContentProduct::STOCK_STATUS_IN_STOCK;
|
183 |
+
} else {
|
184 |
+
$content->stock_status = ContentProduct::STOCK_STATUS_OUT_OF_STOCK;
|
185 |
+
}
|
186 |
+
|
187 |
+
$content->url = LinkHandler::createAffUrl( $r['orig_url'], $deeplink, (array) $content );
|
188 |
+
$content->extra = new ExtraDataAE;
|
189 |
+
|
190 |
+
if ( isset( $r['extra']['rating'] ) ) {
|
191 |
+
$content->rating = $r['extra']['rating'];
|
192 |
+
unset( $r['extra']['rating'] );
|
193 |
+
}
|
194 |
+
|
195 |
+
if ( isset( $r['extra']['features'] ) ) {
|
196 |
+
foreach ( $r['extra']['features'] as $f ) {
|
197 |
+
$feature = array(
|
198 |
+
'name' => $f['name'],
|
199 |
+
'value' => $f['value'],
|
200 |
+
);
|
201 |
+
$content->features[] = $feature;
|
202 |
+
}
|
203 |
+
unset( $r['extra']['features'] );
|
204 |
+
}
|
205 |
+
if ( isset( $r['extra']['comments'] ) ) {
|
206 |
+
$content->extra->comments = $r['extra']['comments'];
|
207 |
+
unset( $r['extra']['comments'] );
|
208 |
+
}
|
209 |
+
if ( isset( $r['extra']['images'] ) ) {
|
210 |
+
$content->extra->images = $r['extra']['images'];
|
211 |
+
unset( $r['extra']['images'] );
|
212 |
+
}
|
213 |
+
if ( isset( $r['extra']['category'] ) ) {
|
214 |
+
$content->category = $r['extra']['category'];
|
215 |
+
unset( $r['extra']['category'] );
|
216 |
+
}
|
217 |
+
|
218 |
+
if ( isset( $r['extra']['categoryPath'] ) ) {
|
219 |
+
$content->categoryPath = $r['extra']['categoryPath'];
|
220 |
+
unset( $r['extra']['categoryPath'] );
|
221 |
+
}
|
222 |
+
|
223 |
+
$content->extra->data = $r['extra'];
|
224 |
+
|
225 |
+
$data[] = $content;
|
226 |
+
}
|
227 |
+
|
228 |
+
return $data;
|
229 |
+
}
|
230 |
+
|
231 |
+
public function doRequestItems( array $items ) {
|
232 |
+
$key = 0;
|
233 |
+
$product_sleep = \Keywordrush\AffiliateEgg\GeneralConfig::getInstance()->option( 'product_update_sleep' );
|
234 |
+
foreach ( $items as $i => $item ) {
|
235 |
+
if ( $product_sleep && $key > 0 ) {
|
236 |
+
usleep( $product_sleep );
|
237 |
+
}
|
238 |
+
$key ++;
|
239 |
+
|
240 |
+
try {
|
241 |
+
$r = ParserManager::getInstance()->parseProduct( $item['orig_url'] );
|
242 |
+
} catch ( \Exception $e ) {
|
243 |
+
if ( $e->getCode() == 404 || $e->getCode() == 410 ) {
|
244 |
+
$items[ $i ]['stock_status'] = ContentProduct::STOCK_STATUS_OUT_OF_STOCK;
|
245 |
+
$items[ $i ]['availability'] = $items[ $i ]['stock_status'];
|
246 |
+
}
|
247 |
+
continue;
|
248 |
+
}
|
249 |
+
|
250 |
+
$items[ $i ]['price'] = $r['price'];
|
251 |
+
$items[ $i ]['priceOld'] = $r['old_price'];
|
252 |
+
$items[ $i ]['currencyCode'] = $r['currency'];
|
253 |
+
$items[ $i ]['currency'] = TextHelper::currencyTyping( $items[ $i ]['currencyCode'] );
|
254 |
+
$items[ $i ]['availability'] = $r['in_stock'];
|
255 |
+
if ( $r['in_stock'] ) {
|
256 |
+
$items[ $i ]['stock_status'] = ContentProduct::STOCK_STATUS_IN_STOCK;
|
257 |
+
} else {
|
258 |
+
$items[ $i ]['stock_status'] = ContentProduct::STOCK_STATUS_OUT_OF_STOCK;
|
259 |
+
}
|
260 |
+
if ( isset( $r['rating'] ) ) {
|
261 |
+
$items[ $i ]['rating'] = $r['rating'];
|
262 |
+
}
|
263 |
+
|
264 |
+
// update url if deeplink changed
|
265 |
+
$items[ $i ]['url'] = LinkHandler::createAffUrl( $r['orig_url'], $this->config( 'deeplink' ), $item );
|
266 |
+
|
267 |
+
// update image (amazon)
|
268 |
+
if ( ! $this->config( 'save_img' ) && $r['img'] ) {
|
269 |
+
$items[ $i ]['img'] = $r['img'];
|
270 |
+
}
|
271 |
+
|
272 |
+
$items[ $i ] = \apply_filters( 'cegg_ae_module_product_update', $items[ $i ], $r );
|
273 |
+
}
|
274 |
+
|
275 |
+
return $items;
|
276 |
+
}
|
277 |
+
|
278 |
+
public function presavePrepare( $data, $post_id ) {
|
279 |
+
$data = parent::presavePrepare( $data, $post_id );
|
280 |
+
|
281 |
+
if ( $post_id > 0 && $this->config( 'reviews_as_comments' ) ) {
|
282 |
+
// get reviews from module data
|
283 |
+
$comments = ContentManager::getNormalizedReviews( $data );
|
284 |
+
if ( $comments ) {
|
285 |
+
// save reviews as post comments
|
286 |
+
ContentManager::saveReviewsAsComments( $post_id, $comments );
|
287 |
+
|
288 |
+
// remove reviews from module data
|
289 |
+
$data = ContentManager::removeReviews( $data );
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
return $data;
|
294 |
+
}
|
295 |
+
|
296 |
+
public function viewDataPrepare( $data ) {
|
297 |
+
$deeplink = $this->config( 'deeplink' );
|
298 |
+
foreach ( $data as $key => $d ) {
|
299 |
+
$data[ $key ]['url'] = LinkHandler::createAffUrl( $d['orig_url'], $deeplink, $d );
|
300 |
+
}
|
301 |
+
|
302 |
+
return parent::viewDataPrepare( $data );
|
303 |
+
}
|
304 |
+
|
305 |
+
public function renderResults() {
|
306 |
+
PluginAdmin::render( '_metabox_results', array( 'module_id' => $this->getId() ) );
|
307 |
+
}
|
308 |
+
|
309 |
+
public function renderSearchResults() {
|
310 |
+
PluginAdmin::render( '_metabox_search_results', array( 'module_id' => $this->getId() ) );
|
311 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
}
|
application/modules/AE/ExtraDataAE.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
@@ -15,9 +15,9 @@ use ContentEgg\application\components\ExtraData;
|
|
15 |
*/
|
16 |
class ExtraDataAE extends ExtraData {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AE;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
15 |
*/
|
16 |
class ExtraDataAE extends ExtraData {
|
17 |
|
18 |
+
public $features = array();
|
19 |
+
public $comments = array();
|
20 |
+
public $images = array();
|
21 |
+
public $data = array();
|
22 |
|
23 |
}
|
application/modules/AE/templates/data_grid.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Grid
|
6 |
*/
|
7 |
|
8 |
-
__('Grid', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('grid');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Grid
|
6 |
*/
|
7 |
|
8 |
+
__( 'Grid', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'grid' );
|
application/modules/AE/templates/data_item.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Product card
|
6 |
*/
|
7 |
|
8 |
-
__('Product card', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('item');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Product card
|
6 |
*/
|
7 |
|
8 |
+
__( 'Product card', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'item' );
|
application/modules/AE/templates/data_item_simple.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
|
5 |
/*
|
6 |
Name: Product card (no features)
|
7 |
*/
|
8 |
|
9 |
-
__('Product card (no features)', 'content-egg');
|
10 |
-
$this->renderPartial('item_simple');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
|
5 |
/*
|
6 |
Name: Product card (no features)
|
7 |
*/
|
8 |
|
9 |
+
__( 'Product card (no features)', 'content-egg' );
|
10 |
+
$this->renderPartial( 'item_simple' );
|
application/modules/AE/templates/data_list.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: List
|
6 |
*/
|
7 |
-
__('List', 'content-egg-tpl');
|
8 |
|
9 |
-
$this->renderPartial('list');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: List
|
6 |
*/
|
7 |
+
__( 'List', 'content-egg-tpl' );
|
8 |
|
9 |
+
$this->renderPartial( 'list' );
|
application/modules/AE/templates/data_price_tracker_alert.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Price tracker & alert
|
6 |
*/
|
7 |
|
8 |
-
__('Price tracker & alert', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('price_tracker_alert');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Price tracker & alert
|
6 |
*/
|
7 |
|
8 |
+
__( 'Price tracker & alert', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'price_tracker_alert' );
|
application/modules/AdmitadProducts/AdmitadProductsConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
@@ -15,145 +15,144 @@ use ContentEgg\application\components\AffiliateParserModuleConfig;
|
|
15 |
*/
|
16 |
class AdmitadProductsConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
);
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
|
156 |
-
|
157 |
-
|
158 |
|
159 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
15 |
*/
|
16 |
class AdmitadProductsConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
+
public function options() {
|
19 |
+
$optiosn = array(
|
20 |
+
'offer_id' => array(
|
21 |
+
'title' => __( 'Offer ID', 'content-egg' ) . ' ' . '<span class="cegg_required">*</span>',
|
22 |
+
'description' => __( 'You can work only with offers, which are available on <a target="_blank" href="https://www.admitadgoods.ru/offers.php">this page</a>.', 'content-egg' )
|
23 |
+
. ' ' . __( 'You can find offer ID in URL, when you click on offer logo.', 'content-egg' ),
|
24 |
+
'callback' => array( $this, 'render_input' ),
|
25 |
+
'default' => '',
|
26 |
+
'validator' => array(
|
27 |
+
'trim',
|
28 |
+
array(
|
29 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
30 |
+
'when' => 'is_active',
|
31 |
+
'message' => __( 'The "Offer ID" can not be empty', 'content-egg' ),
|
32 |
+
),
|
33 |
+
),
|
34 |
+
'section' => 'default',
|
35 |
+
),
|
36 |
+
'deeplink' => array(
|
37 |
+
'title' => 'Deeplink' . ' ' . '<span class="cegg_required">*</span>',
|
38 |
+
'description' => __( 'Deeplink of offer.', 'content-egg' )
|
39 |
+
. ' ' . __( '<a target="_blank" href="http://www.keywordrush.com/en/docs/content-egg/DeeplinkSettings.html">Manual</a> for deeplink settings for different CPA-networks.', 'content-egg' ),
|
40 |
+
'callback' => array( $this, 'render_input' ),
|
41 |
+
'default' => '',
|
42 |
+
'validator' => array(
|
43 |
+
'trim',
|
44 |
+
array(
|
45 |
+
'call' => array( '\ContentEgg\application\components\Cpa', 'deeplinkPrepare' ),
|
46 |
+
'type' => 'filter'
|
47 |
+
),
|
48 |
+
array(
|
49 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
50 |
+
'when' => 'is_active',
|
51 |
+
'message' => __( 'The "Deeplink" can not be empty.', 'content-egg' ),
|
52 |
+
),
|
53 |
+
),
|
54 |
+
'section' => 'default',
|
55 |
+
),
|
56 |
+
'entries_per_page' => array(
|
57 |
+
'title' => __( 'Results', 'content-egg' ),
|
58 |
+
'description' => __( 'Number of results for one search query.', 'content-egg' ),
|
59 |
+
'callback' => array( $this, 'render_input' ),
|
60 |
+
'default' => 20,
|
61 |
+
'validator' => array(
|
62 |
+
'trim',
|
63 |
+
'absint',
|
64 |
+
array(
|
65 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
66 |
+
'arg' => 20,
|
67 |
+
'message' => __( 'Field "Results" can not be more than 20.', 'content-egg' ),
|
68 |
+
),
|
69 |
+
),
|
70 |
+
'section' => 'default',
|
71 |
+
),
|
72 |
+
'entries_per_page_update' => array(
|
73 |
+
'title' => __( 'Results for updates and autoblogging', 'content-egg' ),
|
74 |
+
'description' => __( 'Number of results for automatic updates and autoblogging.', 'content-egg' ),
|
75 |
+
'callback' => array( $this, 'render_input' ),
|
76 |
+
'default' => 6,
|
77 |
+
'validator' => array(
|
78 |
+
'trim',
|
79 |
+
'absint',
|
80 |
+
array(
|
81 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
82 |
+
'arg' => 20,
|
83 |
+
'message' => __( 'Field "Results for autoupdating" can not be more than 20.', 'content-egg' ),
|
84 |
+
),
|
85 |
+
),
|
86 |
+
'section' => 'default',
|
87 |
+
),
|
88 |
+
'only_sale' => array(
|
89 |
+
'title' => __( 'Discount', 'content-egg' ),
|
90 |
+
'description' => __( 'Only products with discount.', 'content-egg' ),
|
91 |
+
'callback' => array( $this, 'render_checkbox' ),
|
92 |
+
'default' => false,
|
93 |
+
'section' => 'default',
|
94 |
+
),
|
95 |
+
'price_from' => array(
|
96 |
+
'title' => __( 'Minimal price', 'content-egg' ),
|
97 |
+
'description' => '',
|
98 |
+
'callback' => array( $this, 'render_input' ),
|
99 |
+
'default' => '',
|
100 |
+
'validator' => array(
|
101 |
+
'trim',
|
102 |
+
),
|
103 |
+
'metaboxInit' => true,
|
104 |
+
),
|
105 |
+
'price_to' => array(
|
106 |
+
'title' => __( 'Maximal price', 'content-egg' ),
|
107 |
+
'description' => '',
|
108 |
+
'callback' => array( $this, 'render_input' ),
|
109 |
+
'default' => '',
|
110 |
+
'validator' => array(
|
111 |
+
'trim',
|
112 |
+
),
|
113 |
+
'metaboxInit' => true,
|
114 |
+
),
|
115 |
+
'save_img' => array(
|
116 |
+
'title' => __( 'Save images', 'content-egg' ),
|
117 |
+
'description' => __( 'Save images on server', 'content-egg' ),
|
118 |
+
'callback' => array( $this, 'render_checkbox' ),
|
119 |
+
'default' => false,
|
120 |
+
'section' => 'default',
|
121 |
+
),
|
122 |
+
'description_size' => array(
|
123 |
+
'title' => __( 'Trim description', 'content-egg' ),
|
124 |
+
'description' => __( 'Description size in characters (0 - do not cut)', 'content-egg' ),
|
125 |
+
'callback' => array( $this, 'render_input' ),
|
126 |
+
'default' => '300',
|
127 |
+
'validator' => array(
|
128 |
+
'trim',
|
129 |
+
'absint',
|
130 |
+
),
|
131 |
+
'section' => 'default',
|
132 |
+
),
|
133 |
+
);
|
|
|
134 |
|
135 |
+
$parent = parent::options();
|
136 |
+
$parent['ttl_items']['validator'] = array(
|
137 |
+
'trim',
|
138 |
+
'absint',
|
139 |
+
array(
|
140 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'greater_than' ),
|
141 |
+
'arg' => 86400,
|
142 |
+
'message' => sprintf( __( 'The field "%s" can not be less than %d.', 'content-egg' ), __( 'Update products', 'content-egg' ), 86400 ),
|
143 |
+
),
|
144 |
+
);
|
145 |
+
$parent['ttl']['validator'] = array(
|
146 |
+
'trim',
|
147 |
+
'absint',
|
148 |
+
array(
|
149 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'greater_than' ),
|
150 |
+
'arg' => 259200,
|
151 |
+
'message' => sprintf( __( 'The field "%s" can not be less than %d.', 'content-egg' ), __( 'Automatic update', 'content-egg' ), 259200 ),
|
152 |
+
),
|
153 |
+
);
|
154 |
|
155 |
+
return array_merge( $parent, $optiosn );
|
156 |
+
}
|
157 |
|
158 |
}
|
application/modules/AdmitadProducts/AdmitadProductsModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModule;
|
8 |
use ContentEgg\application\libs\admitad\AdmitadProducts;
|
@@ -20,187 +20,181 @@ use ContentEgg\application\components\LinkHandler;
|
|
20 |
*/
|
21 |
class AdmitadProductsModule extends AffiliateParserModule {
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
}
|
200 |
-
|
201 |
-
public function renderSearchPanel()
|
202 |
-
{
|
203 |
-
$this->render('search_panel', array('module_id' => $this->getId()));
|
204 |
-
}
|
205 |
|
206 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModule;
|
8 |
use ContentEgg\application\libs\admitad\AdmitadProducts;
|
20 |
*/
|
21 |
class AdmitadProductsModule extends AffiliateParserModule {
|
22 |
|
23 |
+
public function info() {
|
24 |
+
return array(
|
25 |
+
'name' => 'Admitad Products',
|
26 |
+
'description' => sprintf( __( 'Add products from %s.', 'content-egg' ), '<a href="http://www.keywordrush.com/go/admitad">Admitad</a>' ) . ' ' . __( 'You must get approve for each program separately.', 'content-egg' )
|
27 |
+
);
|
28 |
+
}
|
29 |
+
|
30 |
+
public function isDeprecated() {
|
31 |
+
return true;
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getParserType() {
|
35 |
+
return self::PARSER_TYPE_PRODUCT;
|
36 |
+
}
|
37 |
+
|
38 |
+
public function defaultTemplateName() {
|
39 |
+
return 'data_item';
|
40 |
+
}
|
41 |
+
|
42 |
+
public function isItemsUpdateAvailable() {
|
43 |
+
return true;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function isFree() {
|
47 |
+
return true;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function doRequest( $keyword, $query_params = array(), $is_autoupdate = false ) {
|
51 |
+
throw new \Exception( 'This module is deprecated. Admitad API was closed.' );
|
52 |
+
|
53 |
+
$options = array();
|
54 |
+
|
55 |
+
$offer_id = (int) $this->config( 'offer_id' );
|
56 |
+
$options['offer_id'] = $offer_id;
|
57 |
+
|
58 |
+
if ( $this->config( 'only_sale' ) ) {
|
59 |
+
$options['only_sale'] = 1;
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
if ( ! empty( $query_params['price_from'] ) ) {
|
64 |
+
$options['price_from'] = $query_params['price_from'];
|
65 |
+
} elseif ( $this->config( 'price_from' ) ) {
|
66 |
+
$options['price_from'] = (int) $this->config( 'price_from' );
|
67 |
+
}
|
68 |
+
|
69 |
+
if ( ! empty( $query_params['price_to'] ) ) {
|
70 |
+
$options['price_to'] = $query_params['price_to'];
|
71 |
+
} elseif ( $this->config( 'price_to' ) ) {
|
72 |
+
$options['price_to'] = (int) $this->config( 'price_to' );
|
73 |
+
}
|
74 |
+
|
75 |
+
$client = new AdmitadProducts();
|
76 |
+
$results = $client->search( $keyword, $options );
|
77 |
+
|
78 |
+
if ( ! is_array( $results ) || ! isset( $results['items'] ) ) {
|
79 |
+
return array();
|
80 |
+
}
|
81 |
+
if ( $is_autoupdate ) {
|
82 |
+
$limit = $this->config( 'entries_per_page_update' );
|
83 |
+
} else {
|
84 |
+
$limit = $this->config( 'entries_per_page' );
|
85 |
+
}
|
86 |
+
$results = array_slice( $results['items'], 0, $limit );
|
87 |
+
|
88 |
+
return $this->prepareResults( $results, $offer_id );
|
89 |
+
}
|
90 |
+
|
91 |
+
public function prepareResults( $results, $offer_id ) {
|
92 |
+
$data = array();
|
93 |
+
|
94 |
+
foreach ( $results as $key => $r ) {
|
95 |
+
$content = new ContentProduct;
|
96 |
+
$content->unique_id = $offer_id . '-' . $r['id_item'];
|
97 |
+
$content->category = $r['categoryId'];
|
98 |
+
$content->currencyCode = $r['currencyId'];
|
99 |
+
$content->currency = TextHelper::currencyTyping( $content->currencyCode );
|
100 |
+
$content->title = $r['name'];
|
101 |
+
$content->priceOld = (float) $r['oldprice'];
|
102 |
+
$content->price = (float) $r['price'];
|
103 |
+
$content->img = $r['picture'];
|
104 |
+
$content->manufacturer = $r['vendor'];
|
105 |
+
|
106 |
+
if ( ! $orig_url = TextHelper::parseOriginalUrl( $r['url'], 'ulp' ) ) {
|
107 |
+
continue;
|
108 |
+
}
|
109 |
+
$content->orig_url = $orig_url;
|
110 |
+
$content->domain = TextHelper::parseDomain( $r['url'], 'ulp' );
|
111 |
+
|
112 |
+
$content->url = LinkHandler::createAffUrl( $content->orig_url, $this->config( 'deeplink' ), null, 'i=13' );
|
113 |
+
|
114 |
+
$content->description = $r['description'];
|
115 |
+
if ( $max_size = $this->config( 'description_size' ) ) {
|
116 |
+
$content->description = TextHelper::truncate( $content->description, $max_size );
|
117 |
+
}
|
118 |
+
|
119 |
+
$content->extra = new ExtraDataAdmitadProducts;
|
120 |
+
$content->extra->offer_id = $offer_id;
|
121 |
+
$content->extra->id_item = $r['id_item'];
|
122 |
+
ExtraDataAdmitadProducts::fillAttributes( $content->extra, $r );
|
123 |
+
|
124 |
+
if ( ! $content->extra->param ) {
|
125 |
+
$content->extra->param = array();
|
126 |
+
}
|
127 |
+
|
128 |
+
foreach ( $content->extra->param as $f_name => $f_value ) {
|
129 |
+
$feature = array(
|
130 |
+
'name' => $f_name,
|
131 |
+
'value' => $f_value,
|
132 |
+
);
|
133 |
+
$content->features[] = $feature;
|
134 |
+
}
|
135 |
+
|
136 |
+
$data[] = $content;
|
137 |
+
}
|
138 |
+
|
139 |
+
return $data;
|
140 |
+
}
|
141 |
+
|
142 |
+
public function doRequestItems( array $items ) {
|
143 |
+
throw new \Exception( 'This module is deprecated. Admitad API was closed.' );
|
144 |
+
|
145 |
+
$productsToUpdate = array();
|
146 |
+
foreach ( $items as $item ) {
|
147 |
+
if ( empty( $item['extra']['offer_id'] ) || empty( $item['extra']['id_item'] ) || empty( $item['extra']['id'] ) ) {
|
148 |
+
continue;
|
149 |
+
}
|
150 |
+
$productsToUpdate[ $item['extra']['offer_id'] ][] = $item['extra']['id_item'];
|
151 |
+
}
|
152 |
+
|
153 |
+
$client = new AdmitadProducts();
|
154 |
+
$results = $client->update( $productsToUpdate );
|
155 |
+
if ( ! is_array( $results ) || ! isset( $results[0]['id_item'] ) ) {
|
156 |
+
throw new \Exception( 'doRequestItems request error.' );
|
157 |
+
}
|
158 |
+
|
159 |
+
// assign new price
|
160 |
+
foreach ( $results as $r ) {
|
161 |
+
foreach ( $items as $key => $item ) {
|
162 |
+
if ( (int) $item['extra']['id_item'] == (int) $r['id_item'] ) {
|
163 |
+
$items[ $key ]['priceOld'] = (float) $r['oldprice'];
|
164 |
+
$items[ $key ]['price'] = (float) $r['price'];
|
165 |
+
break;
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
return $items;
|
171 |
+
}
|
172 |
+
|
173 |
+
public function renderResults() {
|
174 |
+
PluginAdmin::render( '_metabox_results', array( 'module_id' => $this->getId() ) );
|
175 |
+
}
|
176 |
+
|
177 |
+
public function renderSearchResults() {
|
178 |
+
PluginAdmin::render( '_metabox_search_results', array( 'module_id' => $this->getId() ) );
|
179 |
+
}
|
180 |
+
|
181 |
+
public function viewDataPrepare( $data ) {
|
182 |
+
$deeplink = $this->config( 'deeplink' );
|
183 |
+
foreach ( $data as $key => $d ) {
|
184 |
+
/**
|
185 |
+
* &i=13 подставить
|
186 |
+
* это метка адмитада чтоб понимать что с плагина действия
|
187 |
+
*/
|
188 |
+
if ( $deeplink && $d['orig_url'] ) {
|
189 |
+
$data[ $key ]['url'] = LinkHandler::createAffUrl( $d['orig_url'], $deeplink, $d, 'i=13' );
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
return parent::viewDataPrepare( $data );
|
194 |
+
}
|
195 |
+
|
196 |
+
public function renderSearchPanel() {
|
197 |
+
$this->render( 'search_panel', array( 'module_id' => $this->getId() ) );
|
198 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
}
|
application/modules/AdmitadProducts/ExtraDataAdmitadProducts.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
@@ -15,10 +15,10 @@ use ContentEgg\application\components\ExtraData;
|
|
15 |
*/
|
16 |
class ExtraDataAdmitadProducts extends ExtraData {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AdmitadProducts;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
15 |
*/
|
16 |
class ExtraDataAdmitadProducts extends ExtraData {
|
17 |
|
18 |
+
public $offer_id;
|
19 |
+
public $id_item;
|
20 |
+
public $model;
|
21 |
+
public $param = array();
|
22 |
+
public $id;
|
23 |
|
24 |
}
|
application/modules/AdmitadProducts/templates/data_grid.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Grid
|
6 |
*/
|
7 |
|
8 |
-
__('Grid', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('grid');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Grid
|
6 |
*/
|
7 |
|
8 |
+
__( 'Grid', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'grid' );
|
application/modules/AdmitadProducts/templates/data_item.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Product card
|
6 |
*/
|
7 |
|
8 |
-
__('Product card', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('item');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Product card
|
6 |
*/
|
7 |
|
8 |
+
__( 'Product card', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'item' );
|
application/modules/AdmitadProducts/templates/data_list.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: List
|
6 |
*/
|
7 |
-
__('List', 'content-egg-tpl');
|
8 |
|
9 |
-
$this->renderPartial('list');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: List
|
6 |
*/
|
7 |
+
__( 'List', 'content-egg-tpl' );
|
8 |
|
9 |
+
$this->renderPartial( 'list' );
|
application/modules/AdmitadProducts/templates/data_price_tracker_alert.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Price tracker & alert
|
6 |
*/
|
7 |
|
8 |
-
__('Price tracker & alert', 'content-egg-tpl');
|
9 |
|
10 |
-
$this->renderPartial('price_tracker_alert');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Price tracker & alert
|
6 |
*/
|
7 |
|
8 |
+
__( 'Price tracker & alert', 'content-egg-tpl' );
|
9 |
|
10 |
+
$this->renderPartial( 'price_tracker_alert' );
|
application/modules/AdmitadProducts/views/search_panel.php
CHANGED
@@ -1,3 +1,7 @@
|
|
1 |
-
<?php defined('\ABSPATH') || exit; ?>
|
2 |
-
<input type="text" class="input-sm col-md-4" ng-model="query_params.<?php echo $module_id; ?>.price_from"
|
3 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php defined( '\ABSPATH' ) || exit; ?>
|
2 |
+
<input type="text" class="input-sm col-md-4" ng-model="query_params.<?php echo esc_attr($module_id); ?>.price_from"
|
3 |
+
ng-init="query_params.<?php echo esc_attr($module_id); ?>.price_from = ''"
|
4 |
+
placeholder="<?php esc_html_e( 'Min. price', 'content-egg' ); ?>"/>
|
5 |
+
<input type="text" class="input-sm col-md-4" ng-model="query_params.<?php echo esc_attr($module_id); ?>.price_to"
|
6 |
+
ng-init="query_params.<?php echo esc_attr($module_id); ?>.price_to = ''"
|
7 |
+
placeholder="<?php esc_html_e( 'Max. price', 'content-egg' ); ?>"/>
|
application/modules/AffilinetCoupons/AffilinetCouponsConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
@@ -15,160 +15,160 @@ use ContentEgg\application\components\AffiliateParserModuleConfig;
|
|
15 |
*/
|
16 |
class AffilinetCouponsConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
|
174 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
|
15 |
*/
|
16 |
class AffilinetCouponsConfig extends AffiliateParserModuleConfig {
|
17 |
|
18 |
+
public function options() {
|
19 |
+
$optiosn = array(
|
20 |
+
'PublisherId' => array(
|
21 |
+
'title' => 'Publisher ID <span class="cegg_required">*</span>',
|
22 |
+
'description' => __( 'Publisher ID - your login in affili.net.', 'content-egg' ),
|
23 |
+
'callback' => array( $this, 'render_input' ),
|
24 |
+
'default' => '',
|
25 |
+
'validator' => array(
|
26 |
+
'trim',
|
27 |
+
array(
|
28 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
29 |
+
'when' => 'is_active',
|
30 |
+
'message' => __( 'The field "Publisher ID" can not be empty.', 'content-egg' ),
|
31 |
+
),
|
32 |
+
),
|
33 |
+
'section' => 'default',
|
34 |
+
),
|
35 |
+
'service_password' => array(
|
36 |
+
'title' => 'Publisher Webservice Password <span class="cegg_required">*</span>',
|
37 |
+
'description' => __( 'Publisher Webservice access key. You can get it <a href="https://publisher.affili.net/Account/techSettingsPublisherWS.aspx">here</a>.', 'content-egg' ),
|
38 |
+
'callback' => array( $this, 'render_input' ),
|
39 |
+
'default' => '',
|
40 |
+
'validator' => array(
|
41 |
+
'trim',
|
42 |
+
array(
|
43 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
44 |
+
'when' => 'is_active',
|
45 |
+
'message' => __( 'The field "Publisher Webservice Password" can not be empty.', 'content-egg' ),
|
46 |
+
),
|
47 |
+
),
|
48 |
+
'section' => 'default',
|
49 |
+
),
|
50 |
+
'entries_per_page' => array(
|
51 |
+
'title' => __( 'Results', 'content-egg' ),
|
52 |
+
'description' => __( 'Number of results for one search query.', 'content-egg' ),
|
53 |
+
'callback' => array( $this, 'render_input' ),
|
54 |
+
'default' => 10,
|
55 |
+
'validator' => array(
|
56 |
+
'trim',
|
57 |
+
'absint',
|
58 |
+
),
|
59 |
+
'section' => 'default',
|
60 |
+
),
|
61 |
+
'entries_per_page_update' => array(
|
62 |
+
'title' => __( 'Results for updates and autoblogging', 'content-egg' ),
|
63 |
+
'description' => __( 'Number of results for automatic updates and autoblogging.', 'content-egg' ),
|
64 |
+
'callback' => array( $this, 'render_input' ),
|
65 |
+
'default' => 3,
|
66 |
+
'validator' => array(
|
67 |
+
'trim',
|
68 |
+
'absint',
|
69 |
+
),
|
70 |
+
'section' => 'default',
|
71 |
+
),
|
72 |
+
'ProgramId' => array(
|
73 |
+
'title' => 'Program ID',
|
74 |
+
'description' => 'Only vouchers of this program are returned.',
|
75 |
+
'callback' => array( $this, 'render_input' ),
|
76 |
+
'default' => '',
|
77 |
+
'validator' => array(
|
78 |
+
'trim',
|
79 |
+
),
|
80 |
+
'section' => 'default',
|
81 |
+
),
|
82 |
+
'VoucherCodeContent' => array(
|
83 |
+
'title' => 'Voucher code',
|
84 |
+
'description' => 'Vouchers can come with or without an actual voucher code. If they don’t have a voucher code, then the customer gets the benefit automatically. With this parameter, you can limit the results to only those vouchers, which have a voucher code, or those, which don’t have a voucher code.',
|
85 |
+
'callback' => array( $this, 'render_dropdown' ),
|
86 |
+
'dropdown_options' => array(
|
87 |
+
'0.' => 'Any',
|
88 |
+
'1.' => 'Empty',
|
89 |
+
'2.' => 'Filled',
|
90 |
+
),
|
91 |
+
'default' => '0.',
|
92 |
+
'section' => 'default',
|
93 |
+
'metaboxInit' => true,
|
94 |
+
),
|
95 |
+
'VoucherType' => array(
|
96 |
+
'title' => 'Voucher type',
|
97 |
+
'description' => '',
|
98 |
+
'callback' => array( $this, 'render_dropdown' ),
|
99 |
+
'dropdown_options' => array(
|
100 |
+
'-1.' => 'Any',
|
101 |
+
'0.' => 'All products',
|
102 |
+
'1.' => 'Specific products',
|
103 |
+
'2.' => 'Multi buy discount',
|
104 |
+
'3.' => 'Free shipping',
|
105 |
+
'4.' => 'Free product',
|
106 |
+
'5.' => 'Competition',
|
107 |
+
),
|
108 |
+
'default' => '0.',
|
109 |
+
'section' => 'default',
|
110 |
+
'metaboxInit' => true,
|
111 |
+
),
|
112 |
+
'MinimumOrderValue' => array(
|
113 |
+
'title' => 'Minimum order value',
|
114 |
+
'description' => 'Many vouchers can only be used on shopping baskets, which exceed a certain minimum value. When you set this parameter, only those vouchers are returned, which have a minimum order value configured and whose minimum order value don’t exceed this amount.',
|
115 |
+
'callback' => array( $this, 'render_input' ),
|
116 |
+
'default' => '',
|
117 |
+
'validator' => array(
|
118 |
+
'trim',
|
119 |
+
),
|
120 |
+
'section' => 'default',
|
121 |
+
),
|
122 |
+
'CustomerRestriction' => array(
|
123 |
+
'title' => 'Customer restriction',
|
124 |
+
'description' => 'Some vouchers can only be used by new customers. With this parameter you can restrict the results to either get only those vouchers, which all customers can use, or those vouchers, which only new customers can use.',
|
125 |
+
'callback' => array( $this, 'render_dropdown' ),
|
126 |
+
'dropdown_options' => array(
|
127 |
+
'0.' => 'No restrictions',
|
128 |
+
'1.' => 'All customers',
|
129 |
+
'2.' => 'Only new customers',
|
130 |
+
),
|
131 |
+
'default' => '0.',
|
132 |
+
'section' => 'default',
|
133 |
+
),
|
134 |
+
'ExclusivesOnly' => array(
|
135 |
+
'title' => 'Exclusives only',
|
136 |
+
'description' => 'Restrict the returned vouchers to exclusives only.',
|
137 |
+
'callback' => array( $this, 'render_checkbox' ),
|
138 |
+
'default' => false,
|
139 |
+
'section' => 'default',
|
140 |
+
),
|
141 |
+
'OrderBy' => array(
|
142 |
+
'title' => 'Sort',
|
143 |
+
'description' => 'Specifies the logic that shall be applied to the list of shops which is specified in Shop IDs. If you choose "Exclude", then products are not returned, if they come from any of the shops specified in Shop IDs.',
|
144 |
+
'callback' => array( $this, 'render_dropdown' ),
|
145 |
+
'dropdown_options' => array(
|
146 |
+
'0.' => 'ID',
|
147 |
+
'1.' => 'Program ID',
|
148 |
+
'2.' => 'Title',
|
149 |
+
'3.' => 'Last change date',
|
150 |
+
'4.' => 'Start date',
|
151 |
+
'5.' => 'End date',
|
152 |
+
),
|
153 |
+
'default' => '0.',
|
154 |
+
'section' => 'default',
|
155 |
+
),
|
156 |
+
'SortDesc' => array(
|
157 |
+
'title' => 'Sort order',
|
158 |
+
'description' => '',
|
159 |
+
'callback' => array( $this, 'render_dropdown' ),
|
160 |
+
'dropdown_options' => array(
|
161 |
+
'false' => 'Ascending',
|
162 |
+
'true' => 'Descending',
|
163 |
+
),
|
164 |
+
'default' => 'true',
|
165 |
+
'section' => 'default',
|
166 |
+
),
|
167 |
+
);
|
168 |
+
$parent = parent::options();
|
169 |
+
unset( $parent['featured_image'] );
|
170 |
+
|
171 |
+
return array_merge( $parent, $optiosn );
|
172 |
+
}
|
173 |
|
174 |
}
|
application/modules/AffilinetCoupons/AffilinetCouponsModule.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModule;
|
8 |
use ContentEgg\application\libs\affilinet\AffilinetCoupons;
|
@@ -18,155 +18,152 @@ use ContentEgg\application\admin\PluginAdmin;
|
|
18 |
*/
|
19 |
class AffilinetCouponsModule extends AffiliateParserModule {
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
{
|
169 |
-
$this->render('search_panel', array('module_id' => $this->getId()));
|
170 |
-
}
|
171 |
|
172 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModule;
|
8 |
use ContentEgg\application\libs\affilinet\AffilinetCoupons;
|
18 |
*/
|
19 |
class AffilinetCouponsModule extends AffiliateParserModule {
|
20 |
|
21 |
+
private $api_client = null;
|
22 |
+
|
23 |
+
public function info() {
|
24 |
+
return array(
|
25 |
+
'name' => 'Affilinet Coupons',
|
26 |
+
'description' => __( 'Adds coupons from Affili.net. You must have approval from each program separately.', 'content-egg' ),
|
27 |
+
);
|
28 |
+
}
|
29 |
+
|
30 |
+
public function isDeprecated() {
|
31 |
+
return true;
|
32 |
+
}
|
33 |
+
|
34 |
+
public function defaultTemplateName() {
|
35 |
+
return 'coupons';
|
36 |
+
}
|
37 |
+
|
38 |
+
public function getParserType() {
|
39 |
+
return self::PARSER_TYPE_COUPON;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function isFree() {
|
43 |
+
return true;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function doRequest( $keyword, $query_params = array(), $is_autoupdate = false ) {
|
47 |
+
$options = array();
|
48 |
+
|
49 |
+
if ( $is_autoupdate ) {
|
50 |
+
$options['PageSize'] = $this->config( 'entries_per_page_update' );
|
51 |
+
} else {
|
52 |
+
$options['PageSize'] = $this->config( 'entries_per_page' );
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
if ( isset( $query_params['VoucherType'] ) ) {
|
57 |
+
$options['VoucherType'] = (int) $query_params['VoucherType'];
|
58 |
+
} else {
|
59 |
+
$options['VoucherType'] = (int) $this->config( 'VoucherType' );
|
60 |
+
}
|
61 |
+
if ( isset( $query_params['VoucherCodeContent'] ) ) {
|
62 |
+
$options['VoucherCodeContent'] = (int) $query_params['VoucherCodeContent'];
|
63 |
+
} else {
|
64 |
+
$options['VoucherCodeContent'] = (int) $this->config( 'VoucherCodeContent' );
|
65 |
+
}
|
66 |
+
|
67 |
+
$fields = array( 'ProgramId', 'MinimumOrderValue', 'SortDesc' );
|
68 |
+
foreach ( $fields as $field ) {
|
69 |
+
$options[ $field ] = $this->config( $field );
|
70 |
+
}
|
71 |
+
$fields = array( 'OrderBy', 'CustomerRestriction' );
|
72 |
+
foreach ( $fields as $field ) {
|
73 |
+
$options[ $field ] = (int) $this->config( $field );
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
$options['ExclusivesOnly'] = var_export( (bool) $this->config( 'ExclusivesOnly' ), true );
|
78 |
+
|
79 |
+
// 0 = NoRestriction, 1 = Accepted, Waiting, DeclinedOrDeleted, NoPartnership
|
80 |
+
$options['PartnershipStatus'] = 1;
|
81 |
+
$results = $this->getApiClient()->search( $keyword, $options );
|
82 |
+
|
83 |
+
if ( ! is_array( $results ) || ! isset( $results['VoucherCodeCollection']['VoucherCodeItem'] ) ) {
|
84 |
+
return array();
|
85 |
+
}
|
86 |
+
|
87 |
+
if ( ! isset( $results['VoucherCodeCollection']['VoucherCodeItem'][0] ) && isset( $results['VoucherCodeCollection']['VoucherCodeItem']['Id'] ) ) {
|
88 |
+
$results['VoucherCodeCollection']['VoucherCodeItem'] = array( $results['VoucherCodeCollection']['VoucherCodeItem'] );
|
89 |
+
}
|
90 |
+
|
91 |
+
return $this->prepareResults( $results['VoucherCodeCollection']['VoucherCodeItem'] );
|
92 |
+
}
|
93 |
+
|
94 |
+
private function prepareResults( $results ) {
|
95 |
+
$data = array();
|
96 |
+
|
97 |
+
foreach ( $results as $key => $r ) {
|
98 |
+
$content = new ContentCoupon;
|
99 |
+
$content->unique_id = $r['Id'];
|
100 |
+
$content->title = $r['Title'];
|
101 |
+
$content->img = 'http://logos.affili.net/120x40/' . $r['ProgramId'] . '.gif';
|
102 |
+
if ( $r['Code'] ) {
|
103 |
+
$content->code = $r['Code'];
|
104 |
+
}
|
105 |
+
if ( $r['Description'] ) {
|
106 |
+
$content->description = $r['Description'];
|
107 |
+
}
|
108 |
+
if ( $r['StartDate'] ) {
|
109 |
+
$content->startDate = strtotime( $r['StartDate'] );
|
110 |
+
}
|
111 |
+
if ( $r['EndDate'] ) {
|
112 |
+
$content->endDate = strtotime( $r['EndDate'] );
|
113 |
+
}
|
114 |
+
|
115 |
+
// parse link code html
|
116 |
+
$doc = new \DOMDocument();
|
117 |
+
@$doc->loadHTML( $r['IntegrationCode'] );
|
118 |
+
if ( $images = $doc->getElementsByTagName( 'img' ) ) {
|
119 |
+
// pixel img?
|
120 |
+
if ( $images->item( 0 )->getAttribute( 'height' ) != 1 ) {
|
121 |
+
$content->img = $images->item( 0 )->getAttribute( 'src' );
|
122 |
+
}
|
123 |
+
}
|
124 |
+
if ( $links = $doc->getElementsByTagName( 'a' ) ) {
|
125 |
+
$content->url = trim( $links->item( 0 )->getAttribute( 'href' ) );
|
126 |
+
if ( \is_ssl() ) {
|
127 |
+
$content->url = preg_replace( '/^http/', 'https', $content->url );
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
$content->extra = new ExtraDataAffilinetCoupons;
|
132 |
+
$content->extra->ProgramId = $r['ProgramId'];
|
133 |
+
$content->extra->VoucherType = $r['VoucherTypes']['VoucherType'];
|
134 |
+
$content->extra->LastChangeDate = strtotime( $r['LastChangeDate'] );
|
135 |
+
$content->extra->IntegrationCode = $r['IntegrationCode'];
|
136 |
+
$content->extra->IsExclusive = (bool) $r['IsExclusive'];
|
137 |
+
|
138 |
+
if ( (float) $r['MinimumOrderValue'] ) {
|
139 |
+
$content->extra->IsExclusive = (float) $r['MinimumOrderValue'];
|
140 |
+
}
|
141 |
+
$content->extra->CustomerRestriction = $r['CustomerRestriction'];
|
142 |
+
|
143 |
+
$data[] = $content;
|
144 |
+
}
|
145 |
+
|
146 |
+
return $data;
|
147 |
+
}
|
148 |
+
|
149 |
+
private function getApiClient() {
|
150 |
+
if ( $this->api_client === null ) {
|
151 |
+
$this->api_client = new AffilinetCoupons( $this->config( 'service_password' ), $this->config( 'PublisherId' ) );
|
152 |
+
}
|
153 |
+
|
154 |
+
return $this->api_client;
|
155 |
+
}
|
156 |
+
|
157 |
+
public function renderResults() {
|
158 |
+
PluginAdmin::render( '_metabox_results', array( 'module_id' => $this->getId() ) );
|
159 |
+
}
|
160 |
+
|
161 |
+
public function renderSearchResults() {
|
162 |
+
PluginAdmin::render( '_metabox_search_results', array( 'module_id' => $this->getId() ) );
|
163 |
+
}
|
164 |
+
|
165 |
+
public function renderSearchPanel() {
|
166 |
+
$this->render( 'search_panel', array( 'module_id' => $this->getId() ) );
|
167 |
+
}
|
|
|
|
|
|
|
168 |
|
169 |
}
|
application/modules/AffilinetCoupons/ExtraDataAffilinetCoupons.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
@@ -15,13 +15,13 @@ use ContentEgg\application\components\ExtraData;
|
|
15 |
*/
|
16 |
class ExtraDataAffilinetCoupons extends ExtraData {
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
}
|
2 |
|
3 |
namespace ContentEgg\application\modules\AffilinetCoupons;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\ExtraData;
|
8 |
|
15 |
*/
|
16 |
class ExtraDataAffilinetCoupons extends ExtraData {
|
17 |
|
18 |
+
public $ProgramId;
|
19 |
+
public $VoucherType;
|
20 |
+
public $LastChangeDate;
|
21 |
+
public $IntegrationCode;
|
22 |
+
public $IsExclusive;
|
23 |
+
public $MinimumOrderValue;
|
24 |
+
public $CustomerRestriction;
|
25 |
+
public $logo;
|
26 |
|
27 |
}
|
application/modules/AffilinetCoupons/templates/data_coupons.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
defined('\ABSPATH') || exit;
|
4 |
/*
|
5 |
Name: Coupons
|
6 |
*/
|
7 |
-
__('Coupons', 'content-egg-tpl');
|
8 |
|
9 |
|
10 |
-
$this->renderPartial('coupon');
|
1 |
<?php
|
2 |
|
3 |
+
defined( '\ABSPATH' ) || exit;
|
4 |
/*
|
5 |
Name: Coupons
|
6 |
*/
|
7 |
+
__( 'Coupons', 'content-egg-tpl' );
|
8 |
|
9 |
|
10 |
+
$this->renderPartial( 'coupon' );
|
application/modules/AffilinetCoupons/views/search_panel.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
<?php defined('\ABSPATH') || exit; ?>
|
2 |
-
<select class="col-md-4 input-sm" ng-model="query_params.<?php echo $module_id; ?>.VoucherType">
|
3 |
<option value="-1.">Any voucher type</option>
|
4 |
<option value="0.">All products</option>
|
5 |
<option value="1.">Specific products</option>
|
@@ -8,7 +8,7 @@
|
|
8 |
<option value="4.">Free product</option>
|
9 |
<option value="5.">Competition</option>
|
10 |
</select>
|
11 |
-
<select class="col-md-4 input-sm" ng-model="query_params.<?php echo $module_id; ?>.VoucherCodeContent">
|
12 |
<option value="0.">Any code content</option>
|
13 |
<option value="1.">Empty</option>
|
14 |
<option value="2.">Filled</option>
|
1 |
+
<?php defined( '\ABSPATH' ) || exit; ?>
|
2 |
+
<select class="col-md-4 input-sm" ng-model="query_params.<?php echo esc_attr($module_id); ?>.VoucherType">
|
3 |
<option value="-1.">Any voucher type</option>
|
4 |
<option value="0.">All products</option>
|
5 |
<option value="1.">Specific products</option>
|
8 |
<option value="4.">Free product</option>
|
9 |
<option value="5.">Competition</option>
|
10 |
</select>
|
11 |
+
<select class="col-md-4 input-sm" ng-model="query_params.<?php echo esc_attr($module_id); ?>.VoucherCodeContent">
|
12 |
<option value="0.">Any code content</option>
|
13 |
<option value="1.">Empty</option>
|
14 |
<option value="2.">Filled</option>
|
application/modules/Amazon/AmazonConfig.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
namespace ContentEgg\application\modules\Amazon;
|
4 |
|
5 |
-
defined('\ABSPATH') || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
use ContentEgg\application\admin\GeneralConfig;
|
@@ -16,354 +16,411 @@ use ContentEgg\application\admin\GeneralConfig;
|
|
16 |
*/
|
17 |
class AmazonConfig extends AffiliateParserModuleConfig {
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
'locale'
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
}
|
302 |
|
303 |
-
|
304 |
-
|
305 |
-
return array_merge($parent, $options);
|
306 |
-
}
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
return array('us' => 'US', 'uk' => 'UK', 'de' => 'DE', 'jp' => 'JP', 'cn' => 'CN', 'fr' => 'FR', 'it' => 'IT', 'es' => 'ES', 'ca' => 'CA', 'br' => 'BR', 'in' => 'IN', 'mx' => 'MX', 'au' => 'AU');
|
311 |
-
}
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
-
|
318 |
-
|
319 |
-
$lang = GeneralConfig::getInstance()->option('lang');
|
320 |
-
if (array_key_exists($lang, self::getLocalesList()))
|
321 |
-
return $lang;
|
322 |
-
else
|
323 |
-
return 'us';
|
324 |
-
*
|
325 |
-
*/
|
326 |
-
}
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
-
|
334 |
-
|
|
|
335 |
|
336 |
-
foreach ($locales as $locale => $name)
|
337 |
-
{
|
338 |
-
if ($locale == $default)
|
339 |
-
continue;
|
340 |
-
if (self::getInstance()->option('associate_tag_' . $locale))
|
341 |
-
$active[$locale] = $name;
|
342 |
-
|
2 |
|
3 |
namespace ContentEgg\application\modules\Amazon;
|
4 |
|
5 |
+
defined( '\ABSPATH' ) || exit;
|
6 |
|
7 |
use ContentEgg\application\components\AffiliateParserModuleConfig;
|
8 |
use ContentEgg\application\admin\GeneralConfig;
|
16 |
*/
|
17 |
class AmazonConfig extends AffiliateParserModuleConfig {
|
18 |
|
19 |
+
public function options() {
|
20 |
+
$options = array(
|
21 |
+
'access_key_id' => array(
|
22 |
+
'title' => 'Access Key ID <span class="cegg_required">*</span>',
|
23 |
+
'description' => __( 'Your Access Key ID which uniquely identifies you.', 'content-egg' ),
|
24 |
+
'callback' => array( $this, 'render_input' ),
|
25 |
+
'default' => '',
|
26 |
+
'validator' => array(
|
27 |
+
'trim',
|
28 |
+
array(
|
29 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
30 |
+
'when' => 'is_active',
|
31 |
+
'message' => __( 'The "Access Key ID" can not be empty', 'content-egg' ),
|
32 |
+
),
|
33 |
+
),
|
34 |
+
'section' => 'default',
|
35 |
+
),
|
36 |
+
'secret_access_key' => array(
|
37 |
+
'title' => 'Secret Access Key <span class="cegg_required">*</span>',
|
38 |
+
'description' => __( 'A key that is used in conjunction with the Access Key ID to cryptographically sign an API request. To retrieve your Access Key ID or Secret Access Key, refer to <a target="_blank" href="https://docs.aws.amazon.com/AWSECommerceService/latest/DG/becomingDev.html">Becoming Product Advertising API Developer</a>.', 'content-egg' ),
|
39 |
+
'callback' => array( $this, 'render_input' ),
|
40 |
+
'default' => '',
|
41 |
+
'validator' => array(
|
42 |
+
'trim',
|
43 |
+
array(
|
44 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
45 |
+
'when' => 'is_active',
|
46 |
+
'message' => __( 'The "Secret Access Key" can not be empty.', 'content-egg' ),
|
47 |
+
),
|
48 |
+
),
|
49 |
+
'section' => 'default',
|
50 |
+
),
|
51 |
+
'associate_tag' => array(
|
52 |
+
'title' => __( 'Default Associate Tag', 'content-egg' ) . ' <span class="cegg_required">*</span>',
|
53 |
+
'description' => __( 'An alphanumeric token that uniquely identifies you as an Associate. To obtain an Associate Tag, refer to <a target="_blank" href="https://docs.aws.amazon.com/AWSECommerceService/latest/DG/becomingAssociate.html">Becoming an Associate</a>.', 'content-egg' ),
|
54 |
+
'callback' => array( $this, 'render_input' ),
|
55 |
+
'default' => '',
|
56 |
+
'validator' => array(
|
57 |
+
'trim',
|
58 |
+
array(
|
59 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'required' ),
|
60 |
+
'when' => 'is_active',
|
61 |
+
'message' => __( 'The "Tracking ID" can not be empty.', 'content-egg' ),
|
62 |
+
),
|
63 |
+
),
|
64 |
+
'section' => 'default',
|
65 |
+
'metaboxInit' => true,
|
66 |
+
),
|
67 |
+
'forced_urls_update' => array(
|
68 |
+
'title' => __( 'Forced links update', 'content-egg' ),
|
69 |
+
'description' => __( 'Override/update existing links with new Tracking ID.', 'content-egg' ),
|
70 |
+
'callback' => array( $this, 'render_checkbox' ),
|
71 |
+
'default' => false,
|
72 |
+
'section' => 'default',
|
73 |
+
),
|
74 |
+
'locale' => array(
|
75 |
+
'title' => __( 'Default locale', 'content-egg' ),
|
76 |
+
'description' => __( 'The branch/locale of Amazon. Each branch requires a separate registration in certain affiliate program.', 'content-egg' ),
|
77 |
+
'callback' => array( $this, 'render_dropdown' ),
|
78 |
+
'dropdown_options' => self::getLocalesList(),
|
79 |
+
'default' => self::getDefaultLocale(),
|
80 |
+
'section' => 'default',
|
81 |
+
),
|
82 |
+
'entries_per_page' => array(
|
83 |
+
'title' => __( 'Results', 'content-egg' ),
|
84 |
+
'description' => __( 'Number of results for one search query.', 'content-egg' ) . ' ' .
|
85 |
+
__( 'It needs a bit more time to get more than 10 results in one request', 'content-egg' ),
|
86 |
+
'callback' => array( $this, 'render_input' ),
|
87 |
+
'default' => 10,
|
88 |
+
'validator' => array(
|
89 |
+
'trim',
|
90 |
+
'absint',
|
91 |
+
array(
|
92 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
93 |
+
'arg' => 50,
|
94 |
+
// The value you specified for ItemPage is invalid. Valid values must be between 1 and 5.
|
95 |
+
'message' => __( 'The field "Results" can not be more than 50.', 'content-egg' ),
|
96 |
+
),
|
97 |
+
),
|
98 |
+
'section' => 'default',
|
99 |
+
),
|
100 |
+
'entries_per_page_update' => array(
|
101 |
+
'title' => __( 'Results for updates and autoblogging', 'content-egg' ),
|
102 |
+
'description' => __( 'Number of results for automatic updates and autoblogging.', 'content-egg' ) . ' ' .
|
103 |
+
__( 'It needs a bit more time to get more than 10 results in one request', 'content-egg' ),
|
104 |
+
'callback' => array( $this, 'render_input' ),
|
105 |
+
'default' => 3,
|
106 |
+
'validator' => array(
|
107 |
+
'trim',
|
108 |
+
'absint',
|
109 |
+
array(
|
110 |
+
'call' => array( '\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to' ),
|
111 |
+
'arg' => 50,
|
112 |
+
'message' => __( 'The field "Results" can not be more than 50.', 'content-egg' ),
|
113 |
+
),
|
114 |
+
),
|
115 |
+
'section' => 'default',
|
116 |
+
),
|
117 |
+
'link_type' => array(
|
118 |
+
'title' => __( 'Link type', 'content-egg' ),
|
119 |
+
'description' => __( 'Type of partner links. Know more about amazon <a target="_blank" href="https://affiliate-program.amazon.com/gp/associates/help/t2/a11">90 day cookie</a>.', 'content-egg' ),
|
120 |
+
'callback' => array( $this, 'render_dropdown' ),
|
121 |
+
'dropdown_options' => array(
|
122 |
+
'product' => 'Product page',
|
123 |
+
'add_to_cart' => 'Add to cart',
|
124 |
+
),
|
125 |
+
'default' => 'product',
|
126 |
+
'section' => 'default',
|
127 |
+
),
|
128 |
+
'search_index' => array(
|
129 |
+
'title' => __( 'Categories for search', 'content-egg' ),
|
130 |
+
'description' => __( 'The list of categories for US Amazon. For local branches some of categories may be not available. If you do not set category for searching, no other filtering options in addition to searching for the keyword (for example, the minimal price or sorting) will not working. ', 'content-egg' )
|
131 |
+
. ' ' . __( 'Search by EAN require a Category to be specified.', 'content-egg' ),
|
132 |
+
'callback' => array( $this, 'render_dropdown' ),
|
133 |
+
'dropdown_options' => array(
|
134 |
+
'All' => '[ All ]',
|
135 |
+
'Blended' => '[ Blended ]',
|
136 |
+
'Music' => '[ Music ]',
|
137 |
+
'Video' => '[ Video ]',
|
138 |
+
'Apparel' => 'Apparel',
|
139 |
+
'Automotive' => 'Automotive',
|
140 |
+
'Baby' => 'Baby',
|
141 |
+
'Beauty' => 'Beauty',
|
142 |
+
'Books' => 'Books',
|
143 |
+
'Classical' => 'Classical',
|
144 |
+
'DigitalMusic' => 'DigitalMusic',
|
145 |
+
'DVD' => 'DVD',
|
146 |
+
'Electronics' => 'Electronics',
|
147 |
+
'GourmetFood' => 'GourmetFood',
|
148 |
+
'Grocery' => 'Grocery',
|
149 |
+
'HealthPersonalCare' => 'HealthPersonalCare',
|
150 |
+
'HomeGarden' => 'HomeGarden',
|
151 |
+
'Industrial' => 'Industrial',
|
152 |
+
'Jewelry' => 'Jewelry',
|
153 |
+
'KindleStore' => 'KindleStore',
|
154 |
+
'Kitchen' => 'Kitchen',
|
155 |
+
'Magazines' => 'Magazines',
|
156 |
+
'Merchants' => 'Merchants',
|
157 |
+
'Miscellaneous' => 'Miscellaneous',
|
158 |
+
'MP3Downloads' => 'MP3Downloads',
|
159 |
+
'MusicalInstruments' => 'MusicalInstruments',
|
160 |
+
'MusicTracks' => 'MusicTracks',
|
161 |
+
'OfficeProducts' => 'OfficeProducts',
|
162 |
+
'OutdoorLiving' => 'OutdoorLiving',
|
163 |
+
'PCHardware' => 'PCHardware',
|
164 |
+
'PetSupplies' => 'PetSupplies',
|
165 |
+
'Photo' => 'Photo',
|
166 |
+
'Shoes' => 'Shoes',
|
167 |
+
'Software' => 'Software',
|
168 |
+
'SportingGoods' => 'SportingGoods',
|
169 |
+
'Tools' => 'Tools',
|
170 |
+
'Toys' => 'Toys',
|
171 |
+
'UnboxVideo' => 'UnboxVideo',
|
172 |
+
'VHS' => 'VHS',
|
173 |
+
'VideoGames' => 'VideoGames',
|
174 |
+
'Watches' => 'Watches',
|
175 |
+
'Wireless' => 'Wireless',
|
176 |
+
'WirelessAccessories' => 'WirelessAccessories'
|
177 |
+
),
|
178 |
+
'default' => 'All',
|
179 |
+
'section' => 'default',
|
180 |
+
),
|
181 |
+
'sort' => array(
|
182 |
+
'title' => __( 'Sorting order', 'content-egg' ),
|
183 |
+
'description' => __( 'Sorting variants depend on locale and chosed category. List of all available values you can find <a href="http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?APPNDX_SortValuesArticle.html">here</a>.', 'content-egg' ),
|
184 |
+
'callback' => array( $this, 'render_input' ),
|
185 |
+
'default' => '',
|
186 |
+
'validator' => array(
|
187 |
+
'trim',
|
188 |
+
),
|
189 |
+
'section' => 'default',
|
190 |
+
),
|
191 |
+
'brouse_node' => array(
|
192 |
+
'title' => __( 'Brouse node', 'content-egg' ),
|
193 |
+
'description' => __( 'Integer ID "node" on Amazon. The search will be made only in this "node".', 'content-egg' ),
|
194 |
+
'callback' => array( $this, 'render_input' ),
|
195 |
+
'default' => '',
|
196 |
+
'validator' => array(
|
197 |
+
'trim',
|
198 |
+
),
|
199 |
+
'section' => 'default',
|
200 |
+
),
|
201 |
+
'title' => array(
|
202 |
+
'title' => __( 'Search in title', 'content-egg' ),
|
203 |
+
'description' => __( 'The search will produce only by product name.', 'content-egg' ),
|
204 |
+
'callback' => array( $this, 'render_checkbox' ),
|
205 |
+
'default' => false,
|
206 |
+
'section' => 'default',
|
207 |
+
),
|
208 |
+
'merchant_id' => array(
|
209 |
+
'title' => __( 'Only Amazon', 'content-egg' ),
|
210 |
+
'description' => __( 'Select products that are selling by Amazon. Other sellers are excluded from the search.', 'content-egg' ),
|
211 |
+
'callback' => array( $this, 'render_checkbox' ),
|
212 |
+
'default' => false,
|
213 |
+
'section' => 'default',
|
214 |
+
),
|
215 |
+
'minimum_price' => array(
|
216 |
+
'title' => __( 'Minimal price', 'content-egg' ),
|
217 |
+
'description' => __( 'Example, 8.99', 'content-egg' ),
|
218 |
+
'callback' => array( $this, 'render_input' ),
|
219 |
+
'default' => '',
|
220 |
+
'validator' => array(
|
221 |
+
'trim',
|
222 |
+
),
|
223 |
+
'metaboxInit' => true,
|
224 |
+
),
|
225 |
+
'maximum_price' => array(
|
226 |
+
'title' => __( 'Maximal price', 'content-egg' ),
|
227 |
+
'description' => __( 'Example, 98.50', 'content-egg' ),
|
228 |
+
'callback' => array( $this, 'render_input' ),
|
229 |
+
'default' => '',
|
230 |
+
'validator' => array(
|
231 |
+
'trim',
|
232 |
+
),
|
233 |
+
'metaboxInit' => true,
|
234 |
+
),
|
235 |
+
'min_percentage_off' => array(
|
236 |
+
'title' => __( 'Minimal discount', 'content-egg' ),
|
237 |
+
'description' => __( 'Choose products with discount. You must set category of product. Note, that this option works not for all categories.', 'content-egg' ),
|
238 |
+
'callback' => array( $this, 'render_dropdown' ),
|
239 |
+
'dropdown_options' => array(
|
240 |
+
'' => __( 'Any', 'content-egg' ),
|
241 |
+
'5%' => '5%',
|
242 |
+
'10%' => '10%',
|
243 |
+
'15%' => '15%',
|
244 |
+
'20%' => '20%',
|
245 |
+
'25%' => '25%',
|
246 |
+
'30%' => '30%',
|
247 |
+
'35%' => '35%',
|
248 |
+
'40%' => '40%',
|
249 |
+
'45%' => '45%',
|
250 |
+
'50%' => '50%',
|
251 |
+
'60%' => '60%',
|
252 |
+
'70%' => '70%',
|
253 |
+
'80%' => '80%',
|
254 |
+
'90%' => '90%',
|
255 |
+
'95%' => '95%',
|
256 |
+
),
|
257 |
+
'default' => '',
|
258 |
+
'section' => 'default',
|
259 |
+
'metaboxInit' => true,
|
260 |
+
),
|
261 |
+
'customer_reviews' => array(
|
262 |
+
'title' => __( 'Customer reviews', 'content-egg' ),
|
263 |
+
'description' => __( 'Get user reviews. Reviews will be in iframe. Iframe url is valid only 24 hours, please, use autoupdating function with less than 24 hour to keep actual url.', 'content-egg' ),
|
264 |
+
'callback' => array( $this, 'render_checkbox' ),
|
265 |
+
'default' => false,
|
266 |
+
'section' => 'default',
|
267 |
+
),
|
268 |
+
'truncate_reviews_at' => array(
|
269 |
+
'title' => __( 'Cut reviews', 'content-egg' ),
|
270 |
+
'description' => __( 'Number of characters for one review. 0 - the maximal length of the text.', 'content-egg' ),
|
271 |
+
'callback' => array( $this, 'render_input' ),
|
272 |
+
'default' => 500,
|
273 |
+
'validator' => array(
|
274 |
+
'trim',
|
275 |
+
'absint',
|
276 |
+
),
|
277 |
+
'section' => 'default',
|
278 |
+
),
|
279 |
+
'editorial_reviews' => array(
|
280 |
+
'title' => __( 'Parse description', 'content-egg' ),
|
281 |
+
'description' => __( 'Parse description of products from seller', 'content-egg' ),
|
282 |
+
'callback' => array( $this, 'render_checkbox' ),
|
283 |
+
'default' => false,
|
284 |
+
'section' => 'default',
|
285 |
+
),
|
286 |
+
'editorial_reviews_type' => array(
|
287 |
+
'title' => __( 'Type of description', 'content-egg' ),
|
288 |
+
'description' => '',
|
289 |
+
'callback' => array( $this, 'render_dropdown' ),
|
290 |
+
'dropdown_options' => array(
|
291 |
+
'allow_all' => __( 'Like on Amazon', 'content-egg' ),
|
292 |
+
'safe_html' => __( 'Safe HTML', 'content-egg' ),
|
293 |
+
'allowed_tags' => __( 'Only allowed HTML tags', 'content-egg' ),
|
294 |
+
'text' => __( 'Text only', 'content-egg' ),
|
295 |
+
),
|
296 |
+
'default' => 'All',
|
297 |
+
'section' => 'default',
|
298 |
+
),
|
299 |
+
'editorial_reviews_size' => array(
|
300 |
+
'title' => __( 'Size of description', 'content-egg' ),
|
301 |
+
'description' => __( 'The maximum size of the item description. 0 - do not cut.', 'content-egg' ),
|
302 |
+
'callback' => array( $this, 'render_input' ),
|
303 |
+
'default' => 1000,
|
304 |
+
'validator' => array(
|
305 |
+
'trim',
|
306 |
+
'absint',
|
307 |
+
),
|
308 |
+
'section' => 'default',
|
309 |
+
),
|
310 |
+
'https_img' => array(
|
311 |
+
'title' => __( 'Use images with https', 'content-egg' ),
|
312 |
+
'description' => __( 'Rewrite url of images with https. Use it if you have SSL on your domain', 'content-egg' ),
|
313 |
+
'callback' => array( $this, 'render_checkbox' ),
|
314 |
+
'default' => false,
|
315 |
+
'section' => 'default',
|
316 |
+
),
|
317 |
+
'save_img' => array(
|
318 |
+
'title' => __( 'Save images', 'content-egg' ),
|
319 |
+
'description' => __( 'Save images on server', 'content-egg' ) . ' ' . __( 'Enabling this option violates rules of API.', 'content-egg' ),
|
320 |
+
'callback' => array( $this, 'render_checkbox' ),
|
321 |
+
'default' => false,
|
322 |
+
'section' => 'default',
|
323 |
+
),
|
324 |
+
'show_small_logos' => array(
|
325 |
+
'title' => __( 'Small logos', 'content-egg' ),
|
326 |
+
'description' => __( 'Show small logos', 'content-egg' ) . '<p class="description">' . sprintf( __( 'Read more: <a target="_blank" href="%s">Amazon brand usage guidelines</a>.', 'content-egg' ), 'https://advertising.amazon.com/ad-specs/en/policy/brand-usage' ) . '</p>',
|
327 |
+
'callback' => array( $this, 'render_checkbox' ),
|
328 |
+
'default' => false,
|
329 |
+
'section' => 'default',
|
330 |
+
),
|
331 |
+
);
|
332 |
|
333 |
+
foreach ( self::getLocalesList() as $locale_id => $locale_name ) {
|
334 |
+
$options[ 'associate_tag_' . $locale_id ] = array(
|
335 |
+
'title' => sprintf( __( 'Associate Tag for %s locale', 'content-egg' ), $locale_name ),
|
336 |
+
'description' => __( 'Type here your tracking ID for this locale if you need multiple locale parsing', 'content-egg' ),
|
337 |
+
'callback' => array( $this, 'render_input' ),
|
338 |
+
'default' => '',
|
339 |
+
'validator' => array(
|
340 |
+
'trim',
|
341 |
+
),
|
342 |
+
'metaboxInit' => true,
|
343 |
+
);
|
344 |
+
}
|
|
|
345 |
|
346 |
+
$parent = parent::options();
|
347 |
+
$parent['ttl_items']['default'] = 86400;
|
|
|
|
|
348 |
|
349 |
+
return array_merge( $parent, $options );
|
350 |
+
}
|
|
|
|
|
351 |
|
352 |
+
public static function getLocalesList() {
|
353 |
+
return array(
|
354 |
+
'us' => 'US',
|
355 |
+
'uk' => 'UK',
|
356 |
+
'de' => 'DE',
|
357 |
+
'jp' => 'JP',
|
358 |
+
'cn' => 'CN',
|
359 |
+
'fr' => 'FR',
|
360 |
+
'it' => 'IT',
|
361 |
+
'es' => 'ES',
|
362 |
+
'ca' => 'CA',
|
363 |
+
'br' => 'BR',
|
364 |
+
'in' => 'IN',
|
365 |
+
'mx' => 'MX',
|
366 |
+
'au' => 'AU'
|
367 |
+
);
|
368 |
+
}
|
369 |
|
370 |
+
public static function getDefaultLocale() {
|
371 |
+
return 'us';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
|
373 |
+
// @todo: Fix error: Maximum function nesting level of '100' reached, aborting!
|
374 |
+
/*
|
375 |
+
$lang = GeneralConfig::getInstance()->option('lang');
|
376 |
+
if (array_key_exists($lang, self::getLocalesList()))
|
377 |
+
return $lang;
|
378 |
+
else
|
379 |
+
return 'us';
|
380 |
+
*
|
381 |
+
*/
|
382 |
+
}
|
383 |
|
384 |
+
public static function getActiveLocalesList() {
|
385 |
+
$locales = self::getLocalesList();
|
386 |
+
$active = array();
|
387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|