Version Description
- New: Template settings (price color, stock status, etc.)
- New: Block template: Price comparison card.
- New: Block template: Buttons row.
- New: Block template: Sorted offers list with no prices.
- New: Block template: Text links.
- New: Module template: Product card (no features).
- New: Shortcode parameter: btn_text.
- New: Youtube module: Featured image.
- New: AE modules: Option to hide large logos.
- New: Possibility to create custom modules (feature for developers).
- New: Option: Rel attribute for affiliate links.
- New: Offer module: Custom merchant logos.
- New: General settings: Custom merchant logos.
- New: WooCommerce settings: Show price per unit.
- Improvement: Better mobile templates.
- Improvement: Better desktop templates.
- Improvement: Better module management.
- Improvement: Better plugin settings.
- Improvement: Better widget templates.
- Improvement: Offer module: Set product status to OutOfStock if 404 error.
- Improvement: Some basic HTML tags are allowed in product description.
- Improvement: Offer module: Auto-detection of a real domain in deeplinks.
- Improvement: External featured images: Added support for product structured data.
- Improvement: External featured images: Added support for Yoast schema graph.
- Improvement: Links to new documentation https://ce-docs.keywordrush.com
- Fix: External featured images: WP 5.4+ support.
Download this release
Release Info
Developer | keywordrush |
Plugin | Content Egg |
Version | 5.1.0 |
Comparing to | |
See all releases |
Code changes from version 5.0.0 to 5.1.0
- .htaccess +0 -7
- application/AutoblogScheduler.php +47 -43
- application/BlockShortcode.php +164 -160
- application/EggShortcode.php +126 -122
- application/Installer.php +170 -161
- application/LocalRedirect.php +198 -196
- application/ModuleUpdateScheduler.php +139 -133
- application/ModuleUpdateVisit.php +112 -110
- application/ModuleViewer.php +366 -360
- application/Plugin.php +201 -199
- application/PriceAlert.php +402 -400
- application/PriceMoversWidget.php +228 -225
- application/ProductSearch.php +122 -120
- application/ProductSearchWidget.php +94 -92
- application/WooIntegrator.php +575 -540
- application/admin/AdminNotice.php +99 -97
- application/admin/AeIntegrationConfig.php +84 -75
- application/admin/AutoblogController.php +374 -372
- application/admin/AutoblogTable.php +100 -98
- application/admin/EggMetabox.php +315 -313
- application/admin/GeneralConfig.php +531 -394
- application/admin/ImportExportController.php +73 -71
- application/admin/ModuleSettingsContoller.php +37 -0
- application/admin/MyListTable.php +162 -160
- application/admin/PluginAdmin.php +145 -141
- application/admin/PrefillController.php +250 -248
- application/admin/ProductController.php +66 -64
- application/admin/ProductTable.php +234 -232
- application/admin/ToolsController.php +140 -138
- application/admin/index.php +2 -2
- application/admin/views/_metabox_autoblog.php +488 -476
- application/admin/views/_metabox_results.php +96 -94
- application/admin/views/_metabox_search_results.php +31 -30
- application/admin/views/_metabox_search_results_images.php +9 -7
- application/admin/views/_promo_box.php +75 -46
- application/admin/views/ae_integration.php +37 -38
- application/admin/views/autoblog_edit.php +61 -60
- application/admin/views/autoblog_index.php +51 -51
- application/admin/views/import_export.php +38 -37
- application/admin/views/metabox_general.php +51 -50
- application/admin/views/metabox_module.php +106 -105
- application/admin/views/module_index.php +98 -0
- application/admin/views/module_settings.php +108 -0
- application/admin/views/prefill.php +161 -161
- application/admin/views/product_index.php +48 -47
- application/admin/views/settings.php +26 -137
- application/components/AffiliateFeedParserModule.php +397 -281
- application/components/AffiliateFeedParserModuleConfig.php +87 -33
- application/components/AffiliateParserModule.php +84 -59
- application/components/AffiliateParserModuleConfig.php +66 -61
- application/components/BlockTemplateManager.php +89 -87
- application/components/CEWidget.php +199 -197
- application/components/Config.php +413 -409
- application/components/Content.php +25 -23
- application/components/ContentCoupon.php +23 -21
- application/components/ContentManager.php +617 -590
- application/components/ContentProduct.php +45 -43
- application/components/Cpa.php +215 -213
- application/components/ExternalFeaturedImage.php +284 -238
- application/components/ExtraData.php +40 -37
- application/components/FeaturedImage.php +161 -159
- application/components/LinkHandler.php +369 -298
- application/components/Module.php +280 -253
- application/components/ModuleApi.php +106 -93
- application/components/ModuleConfig.php +74 -77
- application/components/ModuleManager.php +388 -358
- application/components/ModuleTemplateManager.php +100 -91
- application/components/ParserModule.php +143 -141
- application/components/ParserModuleConfig.php +130 -110
- application/components/Scheduler.php +36 -34
- application/components/Shortcoded.php +53 -51
- application/components/TemplateManager.php +252 -233
- application/components/VirtualPage.php +165 -168
- application/components/WidgetTemplateManager.php +66 -64
- application/components/iScheduler.php +19 -17
- application/components/index.php +2 -2
- application/helpers/AdminHelper.php +140 -43
- application/helpers/ArrayHelper.php +112 -110
- application/helpers/CurrencyHelper.php +681 -535
- application/helpers/FileHelper.php +49 -47
- application/helpers/FormValidator.php +445 -440
- application/helpers/ImageHelper.php +106 -104
- application/helpers/InputHelper.php +33 -31
- application/helpers/TemplateHelper.php +697 -914
.htaccess
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
Order Deny,Allow
|
2 |
-
Deny from All
|
3 |
-
|
4 |
-
<FilesMatch ".(js|css|gif|jpe?g|png|woff2|woff|ttf)$">
|
5 |
-
order allow,deny
|
6 |
-
allow from all
|
7 |
-
</FilesMatch>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application/AutoblogScheduler.php
CHANGED
@@ -1,43 +1,47 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
|
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 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\models\AutoblogModel;
|
8 |
+
use ContentEgg\application\components\Scheduler;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* AutoblogScheduler class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link http://www.keywordrush.com/
|
15 |
+
* @copyright Copyright © 2016 keywordrush.com
|
16 |
+
*/
|
17 |
+
class AutoblogScheduler extends Scheduler {
|
18 |
+
|
19 |
+
const CRON_TAG = 'cegg_autoblog_cron';
|
20 |
+
const AUTOBLOG_LIMIT = 5;
|
21 |
+
|
22 |
+
public static function getCronTag()
|
23 |
+
{
|
24 |
+
return self::CRON_TAG;
|
25 |
+
}
|
26 |
+
|
27 |
+
public static function run()
|
28 |
+
{
|
29 |
+
@set_time_limit(1200);
|
30 |
+
$params = array(
|
31 |
+
'select' => 'id',
|
32 |
+
'where' => 'status = 1 AND (last_run IS NULL OR TIMESTAMPDIFF(SECOND, last_run, "' . \current_time('mysql') . '") > run_frequency)',
|
33 |
+
'order' => 'last_run ASC',
|
34 |
+
'limit' => self::AUTOBLOG_LIMIT
|
35 |
+
);
|
36 |
+
|
37 |
+
$autoblogs = AutoblogModel::model()->findAll($params);
|
38 |
+
foreach ($autoblogs as $autoblog)
|
39 |
+
{
|
40 |
+
AutoblogModel::model()->run($autoblog['id']);
|
41 |
+
}
|
42 |
+
|
43 |
+
if (!AutoblogModel::isActiveAutoblogs())
|
44 |
+
AutoblogScheduler::clearScheduleEvent();
|
45 |
+
}
|
46 |
+
|
47 |
+
}
|
application/BlockShortcode.php
CHANGED
@@ -1,160 +1,164 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
*
|
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 |
-
$a['
|
61 |
-
$a['
|
62 |
-
$a['
|
63 |
-
$a['
|
64 |
-
$a['
|
65 |
-
$a['
|
66 |
-
$a['
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
if ($a['
|
73 |
-
$a['
|
74 |
-
if ($a['
|
75 |
-
$a['
|
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 |
-
$a['
|
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 |
-
$module_ids =
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\components\BlockTemplateManager;
|
9 |
+
use ContentEgg\application\helpers\TextHelper;
|
10 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* BlockShortcode class file
|
14 |
+
*
|
15 |
+
* @author keywordrush.com <support@keywordrush.com>
|
16 |
+
* @link http://www.keywordrush.com/
|
17 |
+
* @copyright Copyright © 2015 keywordrush.com
|
18 |
+
*/
|
19 |
+
class BlockShortcode {
|
20 |
+
|
21 |
+
const shortcode = 'content-egg-block';
|
22 |
+
|
23 |
+
private static $instance = null;
|
24 |
+
|
25 |
+
public static function getInstance()
|
26 |
+
{
|
27 |
+
if (self::$instance == null)
|
28 |
+
self::$instance = new self;
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
private function __construct()
|
33 |
+
{
|
34 |
+
\add_shortcode(self::shortcode, array($this, 'viewData'));
|
35 |
+
}
|
36 |
+
|
37 |
+
private function prepareAttr($atts)
|
38 |
+
{
|
39 |
+
$a = \shortcode_atts(array(
|
40 |
+
'modules' => null,
|
41 |
+
'template' => '',
|
42 |
+
'post_id' => 0,
|
43 |
+
'limit' => 0,
|
44 |
+
'offset' => 0,
|
45 |
+
'next' => 0,
|
46 |
+
'title' => '',
|
47 |
+
'cols' => 0,
|
48 |
+
'sort' => '',
|
49 |
+
'order' => '',
|
50 |
+
'currency' => '',
|
51 |
+
'groups' => '',
|
52 |
+
'group' => '',
|
53 |
+
'products' => '',
|
54 |
+
'product' => '',
|
55 |
+
'hide' => '',
|
56 |
+
'show' => '',
|
57 |
+
'btn_text' => '',
|
58 |
+
), $atts);
|
59 |
+
|
60 |
+
$a['next'] = (int) $a['next'];
|
61 |
+
$a['limit'] = (int) $a['limit'];
|
62 |
+
$a['offset'] = (int) $a['offset'];
|
63 |
+
$a['cols'] = (int) $a['cols'];
|
64 |
+
$a['title'] = \sanitize_text_field($a['title']);
|
65 |
+
$a['currency'] = strtoupper(TextHelper::clear($a['currency']));
|
66 |
+
$a['groups'] = \sanitize_text_field($a['groups']);
|
67 |
+
$a['group'] = \sanitize_text_field($a['group']);
|
68 |
+
$a['hide'] = TemplateHelper::hideParamPrepare($a['hide']);
|
69 |
+
$a['show'] = strtolower(TextHelper::clear($a['show']));
|
70 |
+
$a['btn_text'] = wp_strip_all_tags($a['btn_text'], true);
|
71 |
+
|
72 |
+
if ($a['group'] && !$a['groups'])
|
73 |
+
$a['groups'] = $a['group'];
|
74 |
+
if ($a['groups'])
|
75 |
+
$a['groups'] = TextHelper::getArrayFromCommaList($a['groups']);
|
76 |
+
if ($a['product'] && !$a['products'])
|
77 |
+
$a['products'] = $a['product'];
|
78 |
+
if ($a['products'])
|
79 |
+
$a['products'] = TextHelper::getArrayFromCommaList($a['products']);
|
80 |
+
|
81 |
+
$allowed_sort = array('price');
|
82 |
+
$allowed_order = array('asc', 'desc');
|
83 |
+
$a['sort'] = strtolower($a['sort']);
|
84 |
+
$a['order'] = strtolower($a['order']);
|
85 |
+
if (!in_array($a['sort'], $allowed_sort))
|
86 |
+
$a['sort'] = '';
|
87 |
+
if (!in_array($a['order'], $allowed_order))
|
88 |
+
$a['order'] = '';
|
89 |
+
|
90 |
+
if ($a['modules'])
|
91 |
+
{
|
92 |
+
$modules = explode(',', $a['modules']);
|
93 |
+
$module_ids = array();
|
94 |
+
foreach ($modules as $key => $module_id)
|
95 |
+
{
|
96 |
+
$module_id = trim($module_id);
|
97 |
+
if (ModuleManager::getInstance()->isModuleActive($module_id))
|
98 |
+
$module_ids[] = $module_id;
|
99 |
+
}
|
100 |
+
$a['modules'] = $module_ids;
|
101 |
+
} else
|
102 |
+
$a['modules'] = array();
|
103 |
+
|
104 |
+
if ($a['template'])
|
105 |
+
{
|
106 |
+
$a['template'] = BlockTemplateManager::getInstance()->prepareShortcodeTempate($a['template']);
|
107 |
+
}
|
108 |
+
$a['post_id'] = (int) $a['post_id'];
|
109 |
+
return $a;
|
110 |
+
}
|
111 |
+
|
112 |
+
public function viewData($atts, $content = "")
|
113 |
+
{
|
114 |
+
$a = $this->prepareAttr($atts);
|
115 |
+
|
116 |
+
if (empty($a['post_id']))
|
117 |
+
{
|
118 |
+
global $post;
|
119 |
+
$post_id = $post->ID;
|
120 |
+
} else
|
121 |
+
$post_id = $a['post_id'];
|
122 |
+
|
123 |
+
$tpl_manager = BlockTemplateManager::getInstance();
|
124 |
+
if (empty($a['template']) || !$tpl_manager->isTemplateExists($a['template']))
|
125 |
+
return;
|
126 |
+
|
127 |
+
if (!$template_file = $tpl_manager->getViewPath($a['template']))
|
128 |
+
return '';
|
129 |
+
|
130 |
+
// Get supported modules for this tpl
|
131 |
+
$headers = \get_file_data($template_file, array('module_ids' => 'Modules', 'module_types' => 'Module Types', 'shortcoded' => 'Shortcoded'));
|
132 |
+
$supported_module_ids = array();
|
133 |
+
if ($headers && !empty($headers['module_ids']))
|
134 |
+
{
|
135 |
+
$supported_module_ids = explode(',', $headers['module_ids']);
|
136 |
+
$supported_module_ids = array_map('trim', $supported_module_ids);
|
137 |
+
} elseif ($headers && !empty($headers['module_types']))
|
138 |
+
{
|
139 |
+
$module_types = explode(',', $headers['module_types']);
|
140 |
+
$module_types = array_map('trim', $module_types);
|
141 |
+
$supported_module_ids = ModuleManager::getInstance()->getParserModuleIdsByTypes($module_types, true);
|
142 |
+
}
|
143 |
+
|
144 |
+
if ($headers && !empty($headers['shortcoded']))
|
145 |
+
{
|
146 |
+
// convert string to boolean
|
147 |
+
$a['shortcoded'] = filter_var($headers['shortcoded'], FILTER_VALIDATE_BOOLEAN);
|
148 |
+
}
|
149 |
+
|
150 |
+
// Module IDs from shortcode param. Validated.
|
151 |
+
if ($a['modules'])
|
152 |
+
$module_ids = $a['modules'];
|
153 |
+
else
|
154 |
+
$module_ids = ModuleManager::getInstance()->getParserModulesIdList(true);
|
155 |
+
|
156 |
+
if ($supported_module_ids)
|
157 |
+
{
|
158 |
+
$module_ids = array_intersect($module_ids, $supported_module_ids);
|
159 |
+
}
|
160 |
+
|
161 |
+
return ModuleViewer::getInstance()->viewBlockData($module_ids, $post_id, $a);
|
162 |
+
}
|
163 |
+
|
164 |
+
}
|
application/EggShortcode.php
CHANGED
@@ -1,122 +1,126 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
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 |
-
$a['
|
63 |
-
$a['
|
64 |
-
$a['
|
65 |
-
$a['
|
66 |
-
$a['
|
67 |
-
$a['
|
68 |
-
$a['
|
69 |
-
$a['
|
70 |
-
$a['
|
71 |
-
$a['
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
if ($a['
|
77 |
-
$a['
|
78 |
-
if ($a['
|
79 |
-
$a['
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
$a['
|
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 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\components\ModuleTemplateManager;
|
9 |
+
use ContentEgg\application\components\Shortcoded;
|
10 |
+
use ContentEgg\application\helpers\TextHelper;
|
11 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* EggShortcode class file
|
15 |
+
*
|
16 |
+
* @author keywordrush.com <support@keywordrush.com>
|
17 |
+
* @link http://www.keywordrush.com/
|
18 |
+
* @copyright Copyright © 2015 keywordrush.com
|
19 |
+
*/
|
20 |
+
class EggShortcode {
|
21 |
+
|
22 |
+
const shortcode = 'content-egg';
|
23 |
+
|
24 |
+
private static $instance = null;
|
25 |
+
|
26 |
+
public static function getInstance()
|
27 |
+
{
|
28 |
+
if (self::$instance == null)
|
29 |
+
self::$instance = new self;
|
30 |
+
return self::$instance;
|
31 |
+
}
|
32 |
+
|
33 |
+
private function __construct()
|
34 |
+
{
|
35 |
+
\add_shortcode(self::shortcode, array($this, 'viewData'));
|
36 |
+
\add_filter('term_description', 'shortcode_unautop');
|
37 |
+
\add_filter('term_description', 'do_shortcode');
|
38 |
+
}
|
39 |
+
|
40 |
+
private function prepareAttr($atts)
|
41 |
+
{
|
42 |
+
$a = \shortcode_atts(array(
|
43 |
+
'module' => null,
|
44 |
+
'limit' => 0,
|
45 |
+
'offset' => 0,
|
46 |
+
'next' => 0,
|
47 |
+
'template' => '',
|
48 |
+
'locale' => '',
|
49 |
+
'title' => '',
|
50 |
+
'post_id' => 0,
|
51 |
+
'cols' => 0,
|
52 |
+
'currency' => '',
|
53 |
+
'groups' => '',
|
54 |
+
'group' => '',
|
55 |
+
'disable_features' => 0,
|
56 |
+
'products' => '',
|
57 |
+
'product' => '',
|
58 |
+
'hide' => '',
|
59 |
+
'btn_text' => '',
|
60 |
+
), $atts);
|
61 |
+
|
62 |
+
$a['next'] = (int) $a['next'];
|
63 |
+
$a['limit'] = (int) $a['limit'];
|
64 |
+
$a['offset'] = (int) $a['offset'];
|
65 |
+
$a['module'] = TextHelper::clear($a['module']);
|
66 |
+
$a['locale'] = TextHelper::clear($a['locale']);
|
67 |
+
$a['title'] = \sanitize_text_field($a['title']);
|
68 |
+
$a['post_id'] = (int) $a['post_id'];
|
69 |
+
$a['cols'] = (int) $a['cols'];
|
70 |
+
$a['disable_features'] = filter_var($a['disable_features'], FILTER_VALIDATE_BOOLEAN);
|
71 |
+
$a['currency'] = strtoupper(TextHelper::clear($a['currency']));
|
72 |
+
$a['groups'] = \sanitize_text_field($a['groups']);
|
73 |
+
$a['group'] = \sanitize_text_field($a['group']);
|
74 |
+
$a['hide'] = TemplateHelper::hideParamPrepare($a['hide']);
|
75 |
+
$a['btn_text'] = wp_strip_all_tags($a['btn_text'], true);
|
76 |
+
if ($a['group'] && !$a['groups'])
|
77 |
+
$a['groups'] = $a['group'];
|
78 |
+
if ($a['groups'])
|
79 |
+
$a['groups'] = TextHelper::getArrayFromCommaList($a['groups']);
|
80 |
+
if ($a['product'] && !$a['products'])
|
81 |
+
$a['products'] = $a['product'];
|
82 |
+
if ($a['products'])
|
83 |
+
$a['products'] = TextHelper::getArrayFromCommaList($a['products']);
|
84 |
+
|
85 |
+
if ($a['template'] && $a['module'])
|
86 |
+
{
|
87 |
+
$a['template'] = ModuleTemplateManager::getInstance($a['module'])->prepareShortcodeTempate($a['template']);
|
88 |
+
} else
|
89 |
+
$a['template'] = '';
|
90 |
+
return $a;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function viewData($atts, $content = "")
|
94 |
+
{
|
95 |
+
$a = $this->prepareAttr($atts);
|
96 |
+
|
97 |
+
if (empty($a['module']))
|
98 |
+
return;
|
99 |
+
|
100 |
+
if (empty($a['post_id']))
|
101 |
+
{
|
102 |
+
global $post;
|
103 |
+
$post_id = $post->ID;
|
104 |
+
} else
|
105 |
+
$post_id = $a['post_id'];
|
106 |
+
|
107 |
+
$module_id = $a['module'];
|
108 |
+
if (!ModuleManager::getInstance()->isModuleActive($module_id))
|
109 |
+
return;
|
110 |
+
|
111 |
+
Shortcoded::getInstance($post_id)->setShortcodedModule($module_id);
|
112 |
+
return ModuleViewer::getInstance()->viewModuleData($module_id, $post_id, $a);
|
113 |
+
}
|
114 |
+
|
115 |
+
public static function arraySortByColumn(&$arr, $col, $dir = SORT_ASC)
|
116 |
+
{
|
117 |
+
$sort_col = array();
|
118 |
+
foreach ($arr as $key => $row)
|
119 |
+
{
|
120 |
+
$sort_col[$key] = $row[$col];
|
121 |
+
}
|
122 |
+
|
123 |
+
array_multisort($sort_col, $dir, $arr);
|
124 |
+
}
|
125 |
+
|
126 |
+
}
|
application/Installer.php
CHANGED
@@ -1,161 +1,170 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
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 |
-
if (Plugin::
|
108 |
-
\delete_option(
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
self::
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\admin\LicConfig;
|
9 |
+
use ContentEgg\application\models\AutoblogModel;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Installer class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link https://www.keywordrush.com
|
16 |
+
* @copyright Copyright © 2020 keywordrush.com
|
17 |
+
*/
|
18 |
+
class Installer {
|
19 |
+
|
20 |
+
private static $instance = null;
|
21 |
+
|
22 |
+
public static function getInstance()
|
23 |
+
{
|
24 |
+
if (self::$instance == null)
|
25 |
+
self::$instance = new self;
|
26 |
+
|
27 |
+
return self::$instance;
|
28 |
+
}
|
29 |
+
|
30 |
+
private function __construct()
|
31 |
+
{
|
32 |
+
|
33 |
+
if (!empty($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'plugins.php')
|
34 |
+
{
|
35 |
+
\add_action('admin_init', array($this, 'requirements'), 0);
|
36 |
+
}
|
37 |
+
|
38 |
+
\add_action('admin_init', array($this, 'upgrade'));
|
39 |
+
\add_action('admin_init', array($this, 'redirect_after_activation'));
|
40 |
+
}
|
41 |
+
|
42 |
+
static public function dbVesrion()
|
43 |
+
{
|
44 |
+
return Plugin::db_version;
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function activate()
|
48 |
+
{
|
49 |
+
if (!\current_user_can('activate_plugins'))
|
50 |
+
return;
|
51 |
+
|
52 |
+
self::requirements();
|
53 |
+
|
54 |
+
ModuleUpdateScheduler::addScheduleEvent();
|
55 |
+
if (AutoblogModel::isActiveAutoblogs())
|
56 |
+
AutoblogScheduler::addScheduleEvent();
|
57 |
+
\add_option(Plugin::slug . '_do_activation_redirect', true);
|
58 |
+
self::upgradeTables();
|
59 |
+
}
|
60 |
+
|
61 |
+
public static function deactivate()
|
62 |
+
{
|
63 |
+
ModuleUpdateScheduler::clearScheduleEvent();
|
64 |
+
AutoblogScheduler::clearScheduleEvent();
|
65 |
+
}
|
66 |
+
|
67 |
+
public static function requirements()
|
68 |
+
{
|
69 |
+
$php_min_version = '5.3';
|
70 |
+
$extensions = array(
|
71 |
+
'simplexml',
|
72 |
+
'mbstring',
|
73 |
+
'hash',
|
74 |
+
);
|
75 |
+
|
76 |
+
$errors = array();
|
77 |
+
$name = get_file_data(\ContentEgg\PLUGIN_FILE, array('Plugin Name'), 'plugin');
|
78 |
+
|
79 |
+
global $wp_version;
|
80 |
+
if (version_compare(Plugin::wp_requires, $wp_version, '>'))
|
81 |
+
$errors[] = sprintf('You are using Wordpress %s. <em>%s</em> requires at least <strong>Wordpress %s</strong>.', $wp_version, $name[0], Plugin::wp_requires);
|
82 |
+
|
83 |
+
$php_current_version = phpversion();
|
84 |
+
if (version_compare($php_min_version, $php_current_version, '>'))
|
85 |
+
$errors[] = sprintf('PHP is installed on your server %s. <em>%s</em> requires at least <strong>PHP %s</strong>.', $php_current_version, $name[0], $php_min_version);
|
86 |
+
|
87 |
+
foreach ($extensions as $extension)
|
88 |
+
{
|
89 |
+
if (!extension_loaded($extension))
|
90 |
+
$errors[] = sprintf('Requires extension <strong>%s</strong>.', $extension);
|
91 |
+
}
|
92 |
+
if (!$errors)
|
93 |
+
return;
|
94 |
+
unset($_GET['activate']);
|
95 |
+
\deactivate_plugins(\plugin_basename(\ContentEgg\PLUGIN_FILE));
|
96 |
+
$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]);
|
97 |
+
\wp_die($e);
|
98 |
+
}
|
99 |
+
|
100 |
+
public static function uninstall()
|
101 |
+
{
|
102 |
+
global $wpdb;
|
103 |
+
if (!\current_user_can('activate_plugins'))
|
104 |
+
return;
|
105 |
+
|
106 |
+
\delete_option(Plugin::slug . '_db_version');
|
107 |
+
if (Plugin::isEnvato())
|
108 |
+
\delete_option(Plugin::slug . '_env_install');
|
109 |
+
if (Plugin::isPro())
|
110 |
+
\delete_option(LicConfig::getInstance()->option_name());
|
111 |
+
}
|
112 |
+
|
113 |
+
public static function upgrade()
|
114 |
+
{
|
115 |
+
$db_version = \get_option(Plugin::slug . '_db_version');
|
116 |
+
|
117 |
+
if ((int) $db_version >= (int) self::dbVesrion())
|
118 |
+
return;
|
119 |
+
self::upgradeTables();
|
120 |
+
|
121 |
+
if ($db_version < 33)
|
122 |
+
self::upgrade_33();
|
123 |
+
|
124 |
+
if ($db_version < 50)
|
125 |
+
self::upgrade_v50();
|
126 |
+
|
127 |
+
\update_option(Plugin::slug . '_db_version', self::dbVesrion());
|
128 |
+
}
|
129 |
+
|
130 |
+
private static function upgradeTables()
|
131 |
+
{
|
132 |
+
$models = array('AutoblogModel', 'PriceHistoryModel', 'PriceAlertModel', 'ProductModel');
|
133 |
+
$sql = '';
|
134 |
+
foreach ($models as $model)
|
135 |
+
{
|
136 |
+
$m = "\\ContentEgg\\application\\models\\" . $model;
|
137 |
+
$sql .= $m::model()->getDump();
|
138 |
+
$sql .= "\r\n";
|
139 |
+
}
|
140 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
141 |
+
|
142 |
+
dbDelta($sql);
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* v 2.9.0 & 3.6.3
|
147 |
+
* reinit schedule event
|
148 |
+
*/
|
149 |
+
private static function upgrade_33()
|
150 |
+
{
|
151 |
+
ModuleUpdateScheduler::clearScheduleEvent();
|
152 |
+
ModuleUpdateScheduler::addScheduleEvent();
|
153 |
+
}
|
154 |
+
|
155 |
+
private static function upgrade_v50()
|
156 |
+
{
|
157 |
+
global $wpdb;
|
158 |
+
$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'cegg_awin_product');
|
159 |
+
}
|
160 |
+
|
161 |
+
public function redirect_after_activation()
|
162 |
+
{
|
163 |
+
if (\get_option(Plugin::slug . '_do_activation_redirect', false))
|
164 |
+
{
|
165 |
+
\delete_option(Plugin::slug . '_do_activation_redirect');
|
166 |
+
\wp_redirect(\get_admin_url(\get_current_blog_id(), 'admin.php?page=' . Plugin::slug));
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
}
|
application/LocalRedirect.php
CHANGED
@@ -1,196 +1,198 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
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 |
-
$goce =
|
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 |
-
$post_id = $
|
130 |
-
|
131 |
-
$post_id =
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
$path =
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
$path .= self::
|
144 |
-
|
145 |
-
$path
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
$title =
|
165 |
-
$title =
|
166 |
-
$title =
|
167 |
-
$title =
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
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 |
+
|
13 |
+
/**
|
14 |
+
* LocalRedirect class file
|
15 |
+
*
|
16 |
+
* @author keywordrush.com <support@keywordrush.com>
|
17 |
+
* @link http://www.keywordrush.com/
|
18 |
+
* @copyright Copyright © 2017 keywordrush.com
|
19 |
+
*/
|
20 |
+
class LocalRedirect {
|
21 |
+
|
22 |
+
const DEFAULT_REDIRECT_PREFIX = 'go';
|
23 |
+
|
24 |
+
private static $prefix;
|
25 |
+
|
26 |
+
public static function initAction()
|
27 |
+
{
|
28 |
+
\add_action('template_redirect', array(__CLASS__, 'go'));
|
29 |
+
}
|
30 |
+
|
31 |
+
public static function getPrefix()
|
32 |
+
{
|
33 |
+
if (!self::$prefix)
|
34 |
+
{
|
35 |
+
$prefix = GeneralConfig::getInstance()->option('redirect_prefix');
|
36 |
+
$prefix = TextHelper::clear($prefix);
|
37 |
+
if (!$prefix)
|
38 |
+
$prefix = self::DEFAULT_REDIRECT_PREFIX;
|
39 |
+
self::$prefix = $prefix;
|
40 |
+
}
|
41 |
+
|
42 |
+
return self::$prefix;
|
43 |
+
}
|
44 |
+
|
45 |
+
public static function go()
|
46 |
+
{
|
47 |
+
if (\get_option('permalink_structure'))
|
48 |
+
{
|
49 |
+
global $wp;
|
50 |
+
if (preg_match("/" . self::getPrefix() . "\/(.+?)$/", $wp->request, $match))
|
51 |
+
$goce = $match[1];
|
52 |
+
else
|
53 |
+
$goce = '';
|
54 |
+
} else
|
55 |
+
$goce = InputHelper::get(self::getPrefix());
|
56 |
+
|
57 |
+
if (!$goce)
|
58 |
+
return;
|
59 |
+
|
60 |
+
// short url?
|
61 |
+
$url = self::parseShortUrl($goce);
|
62 |
+
|
63 |
+
// long url?
|
64 |
+
if (!$url)
|
65 |
+
$url = self::parseLongUrl($goce);
|
66 |
+
|
67 |
+
if (!$url)
|
68 |
+
return;
|
69 |
+
|
70 |
+
\wp_redirect(esc_url_raw($url), 301);
|
71 |
+
exit;
|
72 |
+
}
|
73 |
+
|
74 |
+
public static function parseShortUrl($goce)
|
75 |
+
{
|
76 |
+
$segments = explode('-', $goce, 2);
|
77 |
+
if (count($segments) != 2)
|
78 |
+
return false;
|
79 |
+
|
80 |
+
$post_id = (int) $segments[0];
|
81 |
+
$unique_id = TextHelper::clearId($segments[1]);
|
82 |
+
|
83 |
+
// post exists?
|
84 |
+
if (!\get_post_status($post_id))
|
85 |
+
return false;
|
86 |
+
|
87 |
+
$module_ids = ModuleManager::getInstance()->getParserModuleIdsByTypes('ALL', true);
|
88 |
+
|
89 |
+
foreach ($module_ids as $module_id)
|
90 |
+
{
|
91 |
+
$parser = ModuleManager::getInstance()->parserFactory($module_id);
|
92 |
+
if (!$parser->config('set_local_redirect'))
|
93 |
+
continue;
|
94 |
+
|
95 |
+
$item = ContentManager::getProductbyUniqueId($unique_id, $module_id, $post_id);
|
96 |
+
if ($item)
|
97 |
+
return $item['aff_url'];
|
98 |
+
else
|
99 |
+
continue;
|
100 |
+
}
|
101 |
+
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
|
105 |
+
public static function parseLongUrl($goce)
|
106 |
+
{
|
107 |
+
$goce_parts = explode('_', $goce);
|
108 |
+
if (count($goce_parts) == 2)
|
109 |
+
{
|
110 |
+
$url = $goce_parts[0];
|
111 |
+
$code = $goce_parts[1];
|
112 |
+
} elseif (count($goce_parts) == 3)
|
113 |
+
{
|
114 |
+
$url = $goce_parts[1];
|
115 |
+
$code = $goce_parts[2];
|
116 |
+
} else
|
117 |
+
return false;
|
118 |
+
|
119 |
+
if ($code != substr(md5($url), 0, 3))
|
120 |
+
return false;
|
121 |
+
return self::base64_url_decode($url);
|
122 |
+
}
|
123 |
+
|
124 |
+
public static function createRedirectUrl(array $item)
|
125 |
+
{
|
126 |
+
global $post;
|
127 |
+
|
128 |
+
if (!empty($item['post_id']))
|
129 |
+
$post_id = $item['post_id'];
|
130 |
+
elseif ($post && $post->ID)
|
131 |
+
$post_id = $post->ID;
|
132 |
+
else
|
133 |
+
$post_id = null;
|
134 |
+
|
135 |
+
$prefix = self::getPrefix();
|
136 |
+
if (\get_option('permalink_structure'))
|
137 |
+
$path = urlencode($prefix) . '/';
|
138 |
+
else
|
139 |
+
$path = '?' . urlencode($prefix) . '=';
|
140 |
+
|
141 |
+
// post_id = -1 for search page
|
142 |
+
if ($post_id && $post_id > 0 && !empty($item['unique_id']))
|
143 |
+
$path .= self::createShortRedirectPath($post_id, $item['unique_id']); // url urlencoded
|
144 |
+
elseif (!empty($item['url']))
|
145 |
+
$path .= self::createLongRedirectPath($item['url']); // url urlencoded
|
146 |
+
else
|
147 |
+
$path = '/';
|
148 |
+
|
149 |
+
return \get_site_url(\get_current_blog_id(), $path);
|
150 |
+
}
|
151 |
+
|
152 |
+
private static function createShortRedirectPath($post_id, $unique_id)
|
153 |
+
{
|
154 |
+
$unique_id = TextHelper::clearId($unique_id);
|
155 |
+
return urlencode($post_id . '-' . $unique_id);
|
156 |
+
}
|
157 |
+
|
158 |
+
private static function createLongRedirectPath($url, $title = '')
|
159 |
+
{
|
160 |
+
$r_url = self::base64_url_encode($url);
|
161 |
+
$secure = substr(md5($r_url), 0, 3);
|
162 |
+
if ($title)
|
163 |
+
{
|
164 |
+
$title = str_replace(' ', '-', trim($title));
|
165 |
+
$title = preg_replace('/[^a-z0-9A-Z\-]/', '', $title);
|
166 |
+
$title = trim($title, '-');
|
167 |
+
$title = explode('-', $title, 4);
|
168 |
+
$title = array_slice($title, 0, 3);
|
169 |
+
$title = join('-', $title);
|
170 |
+
$r_url = urlencode($title) . '_' . $r_url;
|
171 |
+
}
|
172 |
+
$r_url .= '_' . urlencode($secure);
|
173 |
+
return $r_url;
|
174 |
+
}
|
175 |
+
|
176 |
+
/*
|
177 |
+
public static function send404()
|
178 |
+
{
|
179 |
+
global $wp_query;
|
180 |
+
$wp_query->set_404();
|
181 |
+
\status_header(404);
|
182 |
+
include( \get_query_template('404') );
|
183 |
+
exit;
|
184 |
+
}
|
185 |
+
*
|
186 |
+
*/
|
187 |
+
|
188 |
+
public static function base64_url_encode($input)
|
189 |
+
{
|
190 |
+
return strtr(base64_encode($input), '+/=', '-~,');
|
191 |
+
}
|
192 |
+
|
193 |
+
public static function base64_url_decode($input)
|
194 |
+
{
|
195 |
+
return base64_decode(strtr($input, '-~,', '+/='));
|
196 |
+
}
|
197 |
+
|
198 |
+
}
|
application/ModuleUpdateScheduler.php
CHANGED
@@ -1,133 +1,139 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
const
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
//
|
34 |
-
self::
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\Scheduler;
|
8 |
+
use ContentEgg\application\components\ContentManager;
|
9 |
+
use ContentEgg\application\components\ModuleManager;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* ModuleUpdateScheduler class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2016 keywordrush.com
|
17 |
+
*/
|
18 |
+
class ModuleUpdateScheduler extends Scheduler {
|
19 |
+
|
20 |
+
const CRON_TAG = 'cegg_module_updater_cron';
|
21 |
+
const BYKEYWORD_UPDATE_LIMIT_FOR_MODULE = 50;
|
22 |
+
const ITEMS_UPDATE_LIMIT_FOR_MODULE = 50;
|
23 |
+
|
24 |
+
public static function getCronTag()
|
25 |
+
{
|
26 |
+
return self::CRON_TAG;
|
27 |
+
}
|
28 |
+
|
29 |
+
public static function run()
|
30 |
+
{
|
31 |
+
@set_time_limit(2000);
|
32 |
+
|
33 |
+
// 1. By keyword update
|
34 |
+
self::byKeywordUpdate();
|
35 |
+
// 2. Price update
|
36 |
+
self::priceUpdate();
|
37 |
+
}
|
38 |
+
|
39 |
+
private static function byKeywordUpdate()
|
40 |
+
{
|
41 |
+
global $wpdb;
|
42 |
+
|
43 |
+
$module_ids = ModuleManager::getInstance()->getByKeywordUpdateModuleIds();
|
44 |
+
if (!$module_ids)
|
45 |
+
return;
|
46 |
+
|
47 |
+
$time = time();
|
48 |
+
|
49 |
+
shuffle($module_ids);
|
50 |
+
foreach ($module_ids as $module_id)
|
51 |
+
{
|
52 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
53 |
+
$ttl = $module->config('ttl');
|
54 |
+
|
55 |
+
$meta_key_keyword = self::addKeywordPrefix($module_id);
|
56 |
+
$meta_key_last_bykeyword_update = self::addByKeywordUpdatePrefix($module_id);
|
57 |
+
|
58 |
+
$limit = (int) \apply_filters('cegg_update_limit_keyword', self::BYKEYWORD_UPDATE_LIMIT_FOR_MODULE);
|
59 |
+
|
60 |
+
$sql = "SELECT last_bykeyword_update.post_id
|
61 |
+
FROM {$wpdb->postmeta} last_bykeyword_update
|
62 |
+
INNER JOIN {$wpdb->postmeta} keyword
|
63 |
+
ON last_bykeyword_update.post_id = keyword.post_id
|
64 |
+
AND keyword.meta_key = %s
|
65 |
+
WHERE
|
66 |
+
{$time} - last_bykeyword_update.meta_value > {$ttl}
|
67 |
+
AND last_bykeyword_update.meta_key = %s
|
68 |
+
ORDER BY last_bykeyword_update.meta_value ASC
|
69 |
+
LIMIT " . $limit;
|
70 |
+
|
71 |
+
$query = $wpdb->prepare($sql, $meta_key_keyword, $meta_key_last_bykeyword_update);
|
72 |
+
$results = $wpdb->get_results($query);
|
73 |
+
if (!$results)
|
74 |
+
continue;
|
75 |
+
|
76 |
+
// update!
|
77 |
+
foreach ($results as $r)
|
78 |
+
{
|
79 |
+
ContentManager::updateByKeyword($r->post_id, $module_id);
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
private static function priceUpdate()
|
85 |
+
{
|
86 |
+
global $wpdb;
|
87 |
+
|
88 |
+
$module_ids = ModuleManager::getInstance()->getItemsUpdateModuleIds();
|
89 |
+
if (!$module_ids)
|
90 |
+
return;
|
91 |
+
|
92 |
+
$time = time();
|
93 |
+
shuffle($module_ids);
|
94 |
+
|
95 |
+
$limit = (int) \apply_filters('cegg_update_module_limit', self::ITEMS_UPDATE_LIMIT_FOR_MODULE);
|
96 |
+
|
97 |
+
foreach ($module_ids as $module_id)
|
98 |
+
{
|
99 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
100 |
+
$ttl_items = $module->config('ttl_items');
|
101 |
+
$meta_key_last_update = self::addLastItemsUpdatePrefix($module_id);
|
102 |
+
|
103 |
+
$sql = "SELECT last_update.post_id
|
104 |
+
FROM {$wpdb->postmeta} last_update
|
105 |
+
WHERE
|
106 |
+
{$time} - last_update.meta_value > {$ttl_items}
|
107 |
+
AND last_update.meta_key = %s
|
108 |
+
ORDER BY last_update.meta_value ASC
|
109 |
+
LIMIT " . $limit;
|
110 |
+
|
111 |
+
$query = $wpdb->prepare($sql, $meta_key_last_update);
|
112 |
+
$results = $wpdb->get_results($query);
|
113 |
+
if (!$results)
|
114 |
+
continue;
|
115 |
+
|
116 |
+
// update!
|
117 |
+
foreach ($results as $r)
|
118 |
+
{
|
119 |
+
ContentManager::updateItems($r->post_id, $module_id);
|
120 |
+
}
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
public static function addByKeywordUpdatePrefix($module_id)
|
125 |
+
{
|
126 |
+
return ContentManager::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id;
|
127 |
+
}
|
128 |
+
|
129 |
+
public static function addKeywordPrefix($module_id)
|
130 |
+
{
|
131 |
+
return ContentManager::META_PREFIX_KEYWORD . $module_id;
|
132 |
+
}
|
133 |
+
|
134 |
+
public static function addLastItemsUpdatePrefix($module_id)
|
135 |
+
{
|
136 |
+
return ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module_id;
|
137 |
+
}
|
138 |
+
|
139 |
+
}
|
application/ModuleUpdateVisit.php
CHANGED
@@ -1,110 +1,112 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\components\ContentManager;
|
9 |
+
use ContentEgg\application\admin\GeneralConfig;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* ModuleUpdateVisit class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2016 keywordrush.com
|
17 |
+
*/
|
18 |
+
class ModuleUpdateVisit {
|
19 |
+
|
20 |
+
private static $instance = null;
|
21 |
+
|
22 |
+
public static function getInstance()
|
23 |
+
{
|
24 |
+
if (self::$instance == null)
|
25 |
+
self::$instance = new self;
|
26 |
+
|
27 |
+
return self::$instance;
|
28 |
+
}
|
29 |
+
|
30 |
+
private function __construct()
|
31 |
+
{
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public function init()
|
36 |
+
{
|
37 |
+
if (GeneralConfig::getInstance()->option('filter_bots'))
|
38 |
+
{
|
39 |
+
if (!class_exists('\Jaybizzle\CrawlerDetect'))
|
40 |
+
require_once \ContentEgg\PLUGIN_PATH . 'application/vendor/CrawlerDetect.php';
|
41 |
+
|
42 |
+
$CrawlerDetect = new \Jaybizzle\CrawlerDetect\CrawlerDetect();
|
43 |
+
// Check the user agent of the current 'visitor'
|
44 |
+
if ($CrawlerDetect->isCrawler())
|
45 |
+
{
|
46 |
+
// true if crawler user agent detected
|
47 |
+
return;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
// exec before post layout
|
51 |
+
\add_filter('template_redirect', array($this, 'update'), 10);
|
52 |
+
}
|
53 |
+
|
54 |
+
public function update()
|
55 |
+
{
|
56 |
+
if (!is_single() && !is_page())
|
57 |
+
return;
|
58 |
+
|
59 |
+
$this->updateByKeyword();
|
60 |
+
$this->updateItems();
|
61 |
+
}
|
62 |
+
|
63 |
+
private function updateByKeyword()
|
64 |
+
{
|
65 |
+
global $post;
|
66 |
+
|
67 |
+
foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module)
|
68 |
+
{
|
69 |
+
$is_visit_update = in_array($module->config('update_mode'), array('visit', 'visit_cron'));
|
70 |
+
$is_data_exists = ContentManager::isDataExists($post->ID, $module->getId());
|
71 |
+
|
72 |
+
// parse data if not exists in any case
|
73 |
+
if (!$is_visit_update && $is_data_exists)
|
74 |
+
continue;
|
75 |
+
|
76 |
+
$ttl = $module->config('ttl');
|
77 |
+
if (!$ttl && $is_data_exists)
|
78 |
+
continue;
|
79 |
+
|
80 |
+
$keyword = \get_post_meta($post->ID, ContentManager::META_PREFIX_KEYWORD . $module->getId(), true);
|
81 |
+
if (!$keyword)
|
82 |
+
continue;
|
83 |
+
|
84 |
+
$last_update = (int) \get_post_meta($post->ID, ContentManager::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module->getId(), true);
|
85 |
+
if ($last_update && time() - $last_update < $ttl)
|
86 |
+
continue;
|
87 |
+
ContentManager::updateByKeyword($post->ID, $module->getId());
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
private function updateItems()
|
92 |
+
{
|
93 |
+
global $post;
|
94 |
+
foreach (ModuleManager::getInstance()->getAffiliateParsers(true) as $module)
|
95 |
+
{
|
96 |
+
if (!in_array($module->config('update_mode'), array('visit', 'visit_cron')))
|
97 |
+
continue;
|
98 |
+
|
99 |
+
if (!$module->isItemsUpdateAvailable())
|
100 |
+
continue;
|
101 |
+
|
102 |
+
if (!$ttl_items = $module->config('ttl_items'))
|
103 |
+
continue;
|
104 |
+
|
105 |
+
$last_items_update = (int) \get_post_meta($post->ID, ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module->getId(), true);
|
106 |
+
if (!$last_items_update || time() - $last_items_update < $ttl_items)
|
107 |
+
continue;
|
108 |
+
ContentManager::updateItems($post->ID, $module->getId());
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
}
|
application/ModuleViewer.php
CHANGED
@@ -1,360 +1,366 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
use ContentEgg\application\components\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\components\
|
11 |
-
use ContentEgg\application\
|
12 |
-
use ContentEgg\application\components\
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
*
|
18 |
-
*
|
19 |
-
* @
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
private $
|
26 |
-
private $
|
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 |
-
$this->data[$post_id]
|
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 |
-
$post_id =
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
if (
|
98 |
-
continue;
|
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 |
-
$template = $
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
$title = $
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
$cols =
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
$disable_features =
|
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 |
-
if (
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
$
|
296 |
-
|
297 |
-
|
298 |
-
$this->block_data_pointer[$post_id][$template]
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
$this->block_data_pointer[$post_id][$
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\components\ContentManager;
|
9 |
+
use ContentEgg\application\components\ModuleTemplateManager;
|
10 |
+
use ContentEgg\application\components\Shortcoded;
|
11 |
+
use ContentEgg\application\helpers\ArrayHelper;
|
12 |
+
use ContentEgg\application\components\BlockTemplateManager;
|
13 |
+
use ContentEgg\application\admin\GeneralConfig;
|
14 |
+
use ContentEgg\application\components\ContentProduct;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* ModuleViewer class file
|
18 |
+
*
|
19 |
+
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link http://www.keywordrush.com
|
21 |
+
* @copyright Copyright © 2020 keywordrush.com
|
22 |
+
*/
|
23 |
+
class ModuleViewer {
|
24 |
+
|
25 |
+
private static $instance = null;
|
26 |
+
private $module_data_pointer = array();
|
27 |
+
private $block_data_pointer = array();
|
28 |
+
private $data = array();
|
29 |
+
|
30 |
+
public static function getInstance()
|
31 |
+
{
|
32 |
+
if (self::$instance == null)
|
33 |
+
self::$instance = new self;
|
34 |
+
|
35 |
+
return self::$instance;
|
36 |
+
}
|
37 |
+
|
38 |
+
private function __construct()
|
39 |
+
{
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
public function init()
|
44 |
+
{
|
45 |
+
// priority = 12 because do_shortcode() is registered as a default filter on 'the_content' with a priority of 11.
|
46 |
+
\add_filter('the_content', array($this, 'viewData'), 12);
|
47 |
+
}
|
48 |
+
|
49 |
+
public function setData($module_id, $post_id, array $data)
|
50 |
+
{
|
51 |
+
if (!isset($this->data[$post_id]))
|
52 |
+
$this->data[$post_id] = array();
|
53 |
+
$this->data[$post_id][$module_id] = $data;
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getData($module_id, $post_id, $params = array())
|
57 |
+
{
|
58 |
+
if (isset($this->data[$post_id]) && isset($this->data[$post_id][$module_id]))
|
59 |
+
return $this->data[$post_id][$module_id];
|
60 |
+
else
|
61 |
+
{
|
62 |
+
$data = ContentManager::getViewData($module_id, $post_id, $params);
|
63 |
+
$outofstock_product = GeneralConfig::getInstance()->option('outofstock_product');
|
64 |
+
if ($outofstock_product == 'hide_product')
|
65 |
+
{
|
66 |
+
foreach ($data as $key => $d)
|
67 |
+
{
|
68 |
+
if (isset($d['stock_status']) && $d['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
69 |
+
{
|
70 |
+
unset($data[$key]);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
return $data;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
public function viewData($content)
|
80 |
+
{
|
81 |
+
global $post;
|
82 |
+
if ($post)
|
83 |
+
$post_id = $post->ID;
|
84 |
+
else
|
85 |
+
$post_id = -1;
|
86 |
+
|
87 |
+
/*
|
88 |
+
if (!is_single() && !is_page)
|
89 |
+
return $content;
|
90 |
+
*
|
91 |
+
*/
|
92 |
+
$top_modules_priorities = array();
|
93 |
+
$bottom_modules_priorities = array();
|
94 |
+
foreach (ModuleManager::getInstance()->getModules(true) as $module_id => $module)
|
95 |
+
{
|
96 |
+
$embed_at = $module->config('embed_at');
|
97 |
+
if ($embed_at != 'post_bottom' && $embed_at != 'post_top')
|
98 |
+
continue;
|
99 |
+
if (Shortcoded::getInstance($post_id)->isShortcoded($module->getId()))
|
100 |
+
continue;
|
101 |
+
|
102 |
+
$priority = (int) $module->config('priority');
|
103 |
+
if ($embed_at == 'post_top')
|
104 |
+
$top_modules_priorities[$module_id] = $priority;
|
105 |
+
elseif ($embed_at == 'post_bottom')
|
106 |
+
$bottom_modules_priorities[$module_id] = $priority;
|
107 |
+
}
|
108 |
+
|
109 |
+
// sort by priority, keep module_id order
|
110 |
+
$top_modules_priorities = ArrayHelper::asortStable($top_modules_priorities);
|
111 |
+
$bottom_modules_priorities = ArrayHelper::asortStable($bottom_modules_priorities);
|
112 |
+
|
113 |
+
// reverse for corret gluing order
|
114 |
+
$top_modules_priorities = array_reverse($top_modules_priorities, true);
|
115 |
+
foreach ($top_modules_priorities as $module_id => $p)
|
116 |
+
{
|
117 |
+
$content = $this->viewModuleData($module_id, $post_id, array()) . $content;
|
118 |
+
}
|
119 |
+
foreach ($bottom_modules_priorities as $module_id => $p)
|
120 |
+
{
|
121 |
+
$content = $content . $this->viewModuleData($module_id, $post_id, array());
|
122 |
+
}
|
123 |
+
|
124 |
+
return $content;
|
125 |
+
}
|
126 |
+
|
127 |
+
public function viewModuleData($module_id, $post_id = null, $params = array())
|
128 |
+
{
|
129 |
+
if (!$post_id)
|
130 |
+
{
|
131 |
+
global $post;
|
132 |
+
$post_id = $post->ID;
|
133 |
+
}
|
134 |
+
|
135 |
+
$data = $this->getData($module_id, $post_id, $params);
|
136 |
+
if (!$data)
|
137 |
+
return '';
|
138 |
+
|
139 |
+
//groups
|
140 |
+
if (!empty($params['groups']))
|
141 |
+
{
|
142 |
+
foreach ($data as $key => $d)
|
143 |
+
{
|
144 |
+
if (!$d['group'] || !in_array($d['group'], $params['groups']))
|
145 |
+
unset($data[$key]);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
// product IDs
|
150 |
+
if (!empty($params['products']))
|
151 |
+
{
|
152 |
+
foreach ($data as $key => $d)
|
153 |
+
{
|
154 |
+
if (!in_array($d['unique_id'], $params['products']))
|
155 |
+
unset($data[$key]);
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
// hide fields
|
160 |
+
if (!empty($params['hide']))
|
161 |
+
{
|
162 |
+
foreach ($data as $key => $d)
|
163 |
+
{
|
164 |
+
foreach ($params['hide'] as $hide)
|
165 |
+
{
|
166 |
+
if (isset($d[$hide]))
|
167 |
+
$data[$key][$hide] = '';
|
168 |
+
}
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
$module = ModuleManager::factory($module_id);
|
173 |
+
$keyword = \get_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module->getId(), true);
|
174 |
+
|
175 |
+
if (!isset($this->module_data_pointer[$post_id]))
|
176 |
+
$this->module_data_pointer[$post_id] = array();
|
177 |
+
|
178 |
+
// next param
|
179 |
+
if (!empty($params['next']))
|
180 |
+
{
|
181 |
+
if (!isset($this->module_data_pointer[$post_id][$module_id]))
|
182 |
+
$this->module_data_pointer[$post_id][$module_id] = 0;
|
183 |
+
|
184 |
+
$data = array_splice($data, $this->module_data_pointer[$post_id][$module_id], $params['next']);
|
185 |
+
if (count($data) < $params['next'])
|
186 |
+
$params['next'] = count($data);
|
187 |
+
|
188 |
+
$this->module_data_pointer[$post_id][$module_id] += $params['next'];
|
189 |
+
} elseif (!empty($params['limit']))
|
190 |
+
{
|
191 |
+
if (!isset($params['offset']))
|
192 |
+
$params['offset'] = 0;
|
193 |
+
|
194 |
+
$data = array_splice($data, $params['offset'], $params['limit']);
|
195 |
+
$this->module_data_pointer[$post_id][$module_id] = $params['offset'] + $params['limit'];
|
196 |
+
}
|
197 |
+
if (!$data)
|
198 |
+
return;
|
199 |
+
|
200 |
+
// template
|
201 |
+
$tpl_manager = ModuleTemplateManager::getInstance($module_id);
|
202 |
+
if (!empty($params['template']) && $tpl_manager->isTemplateExists($params['template']))
|
203 |
+
$template = $params['template'];
|
204 |
+
else
|
205 |
+
$template = $module->config('template');
|
206 |
+
|
207 |
+
if (!empty($params['title']))
|
208 |
+
$title = $params['title'];
|
209 |
+
else
|
210 |
+
$title = $module->config('tpl_title');
|
211 |
+
|
212 |
+
if (!empty($params['cols']))
|
213 |
+
$cols = $params['cols'];
|
214 |
+
else
|
215 |
+
$cols = 0;
|
216 |
+
|
217 |
+
if (isset($params['disable_features']))
|
218 |
+
$disable_features = $params['disable_features'];
|
219 |
+
else
|
220 |
+
$disable_features = 0;
|
221 |
+
|
222 |
+
if (isset($params['btn_text']))
|
223 |
+
$btn_text = $params['btn_text'];
|
224 |
+
else
|
225 |
+
$btn_text = '';
|
226 |
+
|
227 |
+
return $tpl_manager->render($template, array('items' => $data, 'title' => $title, 'keyword' => $keyword, 'post_id' => $post_id, 'module_id' => $module_id, 'cols' => $cols, 'disable_features' => $disable_features, 'btn_text' => $btn_text));
|
228 |
+
}
|
229 |
+
|
230 |
+
public function viewBlockData(array $module_ids, $post_id = null, $params = array())
|
231 |
+
{
|
232 |
+
if (!$post_id)
|
233 |
+
{
|
234 |
+
global $post;
|
235 |
+
$post_id = $post->ID;
|
236 |
+
}
|
237 |
+
|
238 |
+
// Get modules data
|
239 |
+
$data = array();
|
240 |
+
foreach ($module_ids as $module_id)
|
241 |
+
{
|
242 |
+
$module_data = $this->getData($module_id, $post_id, $params);
|
243 |
+
|
244 |
+
//groups filter
|
245 |
+
if (!empty($params['groups']))
|
246 |
+
{
|
247 |
+
foreach ($module_data as $key => $d)
|
248 |
+
{
|
249 |
+
if (!$d['group'] || !in_array($d['group'], $params['groups']))
|
250 |
+
unset($module_data[$key]);
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
// product IDs filter
|
255 |
+
if (!empty($params['products']))
|
256 |
+
{
|
257 |
+
foreach ($module_data as $key => $d)
|
258 |
+
{
|
259 |
+
if (!in_array($d['unique_id'], $params['products']))
|
260 |
+
unset($module_data[$key]);
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
// hide fields
|
265 |
+
if (!empty($params['hide']))
|
266 |
+
{
|
267 |
+
foreach ($module_data as $key => $d)
|
268 |
+
{
|
269 |
+
foreach ($params['hide'] as $hide)
|
270 |
+
{
|
271 |
+
if (isset($d[$hide]))
|
272 |
+
$module_data[$key][$hide] = '';
|
273 |
+
}
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
if ($module_data)
|
278 |
+
$data[$module_id] = $module_data;
|
279 |
+
|
280 |
+
// shortcoded!
|
281 |
+
if (!isset($params['shortcoded']) || (bool) $params['shortcoded'])
|
282 |
+
Shortcoded::getInstance($post_id)->setShortcodedModule($module_id);
|
283 |
+
}
|
284 |
+
if (!$data)
|
285 |
+
return;
|
286 |
+
|
287 |
+
// template
|
288 |
+
$tpl_manager = BlockTemplateManager::getInstance();
|
289 |
+
if (empty($params['template']) || !$tpl_manager->isTemplateExists($params['template']))
|
290 |
+
return;
|
291 |
+
$template = $params['template'];
|
292 |
+
|
293 |
+
// next, limit, offset
|
294 |
+
if (!isset($this->block_data_pointer[$post_id]))
|
295 |
+
$this->block_data_pointer[$post_id] = array();
|
296 |
+
if (!empty($params['next']))
|
297 |
+
{
|
298 |
+
if (!isset($this->block_data_pointer[$post_id][$template]))
|
299 |
+
$this->block_data_pointer[$post_id][$template] = 0;
|
300 |
+
|
301 |
+
$data = $this->spliceBlockData($data, $this->block_data_pointer[$post_id][$template], $params['next']);
|
302 |
+
$count = $this->countBlockData($data);
|
303 |
+
if ($count < $params['next'])
|
304 |
+
$params['next'] = $count;
|
305 |
+
$this->block_data_pointer[$post_id][$template] += $params['next'];
|
306 |
+
} elseif (!empty($params['limit']))
|
307 |
+
{
|
308 |
+
if (!isset($params['offset']))
|
309 |
+
$params['offset'] = 0;
|
310 |
+
|
311 |
+
$data = $this->spliceBlockData($data, $params['offset'], $params['limit']);
|
312 |
+
$this->block_data_pointer[$post_id][$module_id] = $params['offset'] + $params['limit'];
|
313 |
+
}
|
314 |
+
if (!$data)
|
315 |
+
return;
|
316 |
+
|
317 |
+
if (!empty($params['title']))
|
318 |
+
$title = $params['title'];
|
319 |
+
else
|
320 |
+
$title = '';
|
321 |
+
|
322 |
+
if (!empty($params['cols']))
|
323 |
+
$cols = $params['cols'];
|
324 |
+
else
|
325 |
+
$cols = 0;
|
326 |
+
|
327 |
+
return $tpl_manager->render($params['template'], array('data' => $data, 'post_id' => $post_id, 'params' => $params, 'title' => $title, 'cols' => $cols, 'sort' => $params['sort'], 'order' => $params['order'], 'groups' => $params['groups'], 'btn_text' => $params['btn_text']));
|
328 |
+
}
|
329 |
+
|
330 |
+
private function spliceBlockData($data, $offset, $length)
|
331 |
+
{
|
332 |
+
$results = array();
|
333 |
+
$count = 0;
|
334 |
+
$results_count = 0;
|
335 |
+
foreach ($data as $module_id => $module_data)
|
336 |
+
{
|
337 |
+
$results[$module_id] = array();
|
338 |
+
foreach ($module_data as $key => $data)
|
339 |
+
{
|
340 |
+
if ($count < $offset)
|
341 |
+
{
|
342 |
+
$count++;
|
343 |
+
continue;
|
344 |
+
}
|
345 |
+
|
346 |
+
$results[$module_id][$key] = $data;
|
347 |
+
$count++;
|
348 |
+
$results_count++;
|
349 |
+
if ($results_count >= $length)
|
350 |
+
return $results;
|
351 |
+
}
|
352 |
+
}
|
353 |
+
return $results;
|
354 |
+
}
|
355 |
+
|
356 |
+
private function countBlockData($data)
|
357 |
+
{
|
358 |
+
$count = 0;
|
359 |
+
foreach ($data as $module_id => $module_data)
|
360 |
+
{
|
361 |
+
$count += count($module_data);
|
362 |
+
}
|
363 |
+
return $count;
|
364 |
+
}
|
365 |
+
|
366 |
+
}
|
application/Plugin.php
CHANGED
@@ -1,199 +1,201 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
const
|
21 |
-
const
|
22 |
-
const
|
23 |
-
const
|
24 |
-
const
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
private static $
|
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 |
-
\wp_register_script('
|
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 |
-
self::$is_pro =
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
self::$is_envato =
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
return
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
return
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
return
|
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 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\admin\GeneralConfig;
|
8 |
+
use ContentEgg\application\helpers\CurrencyHelper;
|
9 |
+
use ContentEgg\application\components\ExternalFeaturedImage;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Plugin class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link https://www.keywordrush.com
|
16 |
+
* @copyright Copyright © 2020 keywordrush.com
|
17 |
+
*/
|
18 |
+
class Plugin {
|
19 |
+
|
20 |
+
const version = '5.1.0';
|
21 |
+
const db_version = 51;
|
22 |
+
const wp_requires = '4.6.1';
|
23 |
+
const slug = 'content-egg';
|
24 |
+
const api_base = 'https://www.keywordrush.com/api/v1';
|
25 |
+
const api_base2 = '';
|
26 |
+
const product_id = 302;
|
27 |
+
|
28 |
+
private static $instance = null;
|
29 |
+
private static $is_pro = null;
|
30 |
+
private static $is_envato = null;
|
31 |
+
|
32 |
+
public static function getInstance()
|
33 |
+
{
|
34 |
+
if (self::$instance == null)
|
35 |
+
self::$instance = new self;
|
36 |
+
|
37 |
+
return self::$instance;
|
38 |
+
}
|
39 |
+
|
40 |
+
private function __construct()
|
41 |
+
{
|
42 |
+
$this->loadTextdomain();
|
43 |
+
if (self::isFree() || (self::isPro() && self::isActivated()) || self::isEnvato())
|
44 |
+
{
|
45 |
+
if (!\is_admin())
|
46 |
+
{
|
47 |
+
\add_action('wp_enqueue_scripts', array($this, 'registerScripts'));
|
48 |
+
\add_action('amp_post_template_css', array($this, 'registerAmpStyles'));
|
49 |
+
EggShortcode::getInstance();
|
50 |
+
BlockShortcode::getInstance();
|
51 |
+
ModuleViewer::getInstance()->init();
|
52 |
+
ModuleUpdateVisit::getInstance()->init();
|
53 |
+
LocalRedirect::initAction();
|
54 |
+
CurrencyHelper::getInstance(GeneralConfig::getInstance()->option('lang'));
|
55 |
+
ProductSearch::initAction();
|
56 |
+
}
|
57 |
+
PriceAlert::getInstance()->init();
|
58 |
+
AutoblogScheduler::initAction();
|
59 |
+
ModuleUpdateScheduler::initAction();
|
60 |
+
WooIntegrator::initAction();
|
61 |
+
ExternalFeaturedImage::initAction();
|
62 |
+
new ProductSearchWidget;
|
63 |
+
new PriceMoversWidget;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
public function registerScripts()
|
68 |
+
{
|
69 |
+
\wp_register_style('egg-bootstrap', \ContentEgg\PLUGIN_RES . '/bootstrap/css/egg-bootstrap.min.css');
|
70 |
+
\wp_register_script('bootstrap', \ContentEgg\PLUGIN_RES . '/bootstrap/js/bootstrap.min.js', array('jquery'), null, false);
|
71 |
+
\wp_register_script('bootstrap-tab', \ContentEgg\PLUGIN_RES . '/bootstrap/js/tab.js', array('jquery'), null, false);
|
72 |
+
\wp_register_style('egg-products', \ContentEgg\PLUGIN_RES . '/css/products.css', array(), '' . Plugin::version());
|
73 |
+
\wp_register_script('raphaeljs', \ContentEgg\PLUGIN_RES . '/js/morrisjs/raphael.min.js', array('jquery'));
|
74 |
+
\wp_register_script('morrisjs', \ContentEgg\PLUGIN_RES . '/js/morrisjs/morris.min.js', array('raphaeljs'));
|
75 |
+
\wp_register_style('morrisjs', \ContentEgg\PLUGIN_RES . '/js/morrisjs/morris.min.css');
|
76 |
+
}
|
77 |
+
|
78 |
+
static public function version()
|
79 |
+
{
|
80 |
+
return self::version;
|
81 |
+
}
|
82 |
+
|
83 |
+
static public function slug()
|
84 |
+
{
|
85 |
+
return self::slug;
|
86 |
+
}
|
87 |
+
|
88 |
+
public static function getApiBase()
|
89 |
+
{
|
90 |
+
return self::api_base;
|
91 |
+
}
|
92 |
+
|
93 |
+
public static function isFree()
|
94 |
+
{
|
95 |
+
return !self::isPro();
|
96 |
+
}
|
97 |
+
|
98 |
+
public static function isPro()
|
99 |
+
{
|
100 |
+
if (self::$is_pro === null)
|
101 |
+
{
|
102 |
+
if (class_exists("\\ContentEgg\\application\\Autoupdate", true))
|
103 |
+
self::$is_pro = true;
|
104 |
+
else
|
105 |
+
self::$is_pro = false;
|
106 |
+
}
|
107 |
+
return self::$is_pro;
|
108 |
+
}
|
109 |
+
|
110 |
+
public static function isEnvato()
|
111 |
+
{
|
112 |
+
if (self::$is_envato === null)
|
113 |
+
{
|
114 |
+
if (class_exists("\\ContentEgg\\application\\admin\\EnvatoConfig", true) || \get_option(Plugin::slug . '_env_install'))
|
115 |
+
self::$is_envato = true;
|
116 |
+
else
|
117 |
+
self::$is_envato = false;
|
118 |
+
}
|
119 |
+
return self::$is_envato;
|
120 |
+
}
|
121 |
+
|
122 |
+
public static function isActivated()
|
123 |
+
{
|
124 |
+
if (self::isPro() && \ContentEgg\application\admin\LicConfig::getInstance()->option('license_key'))
|
125 |
+
return true;
|
126 |
+
else
|
127 |
+
return false;
|
128 |
+
}
|
129 |
+
|
130 |
+
public static function isInactiveEnvato()
|
131 |
+
{
|
132 |
+
if (self::isEnvato() && !self::isActivated())
|
133 |
+
return true;
|
134 |
+
else
|
135 |
+
return false;
|
136 |
+
}
|
137 |
+
|
138 |
+
public static function apiRequest($params = array())
|
139 |
+
{
|
140 |
+
$api_urls = array(self::api_base);
|
141 |
+
if (self::api_base2)
|
142 |
+
$api_urls[] = self::api_base2;
|
143 |
+
|
144 |
+
foreach ($api_urls as $api_url)
|
145 |
+
{
|
146 |
+
$response = \wp_remote_post($api_url, $params);
|
147 |
+
if (\is_wp_error($response))
|
148 |
+
continue; // try alternative api uri
|
149 |
+
|
150 |
+
$response_code = (int) \wp_remote_retrieve_response_code($response);
|
151 |
+
if ($response_code == 200)
|
152 |
+
return $response;
|
153 |
+
else
|
154 |
+
return false;
|
155 |
+
}
|
156 |
+
return false;
|
157 |
+
}
|
158 |
+
|
159 |
+
private function loadTextdomain()
|
160 |
+
{
|
161 |
+
// plugin admin
|
162 |
+
\load_plugin_textdomain('content-egg', false, dirname(\plugin_basename(\ContentEgg\PLUGIN_FILE)) . '/languages/');
|
163 |
+
|
164 |
+
// frontend templates
|
165 |
+
$lang = GeneralConfig::getInstance()->option('lang');
|
166 |
+
$mo_files = array();
|
167 |
+
if (defined('LOCO_LANG_DIR'))
|
168 |
+
$mo_files[] = \trailingslashit(LOCO_LANG_DIR) . 'plugins/content-egg-tpl-' . $lang . '.mo'; // loco lang dir
|
169 |
+
$mo_files[] = \trailingslashit(WP_LANG_DIR) . 'plugins/content-egg-tpl-' . $lang . '.mo'; // wp lang dir
|
170 |
+
$mo_files[] = \ContentEgg\PLUGIN_PATH . 'languages/tpl/content-egg-tpl-' . strtoupper($lang) . '.mo'; // plugin lang dir
|
171 |
+
foreach ($mo_files as $mo_file)
|
172 |
+
{
|
173 |
+
if (file_exists($mo_file) && is_readable($mo_file))
|
174 |
+
{
|
175 |
+
if (\load_textdomain('content-egg-tpl', $mo_file))
|
176 |
+
return;
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
public static function getPluginDomain()
|
182 |
+
{
|
183 |
+
return 'https://www.keywordrush.com/';
|
184 |
+
}
|
185 |
+
|
186 |
+
public static function pluginSiteUrl()
|
187 |
+
{
|
188 |
+
return self::getPluginDomain() . 'contentegg';
|
189 |
+
}
|
190 |
+
|
191 |
+
public static function pluginDocsUrl()
|
192 |
+
{
|
193 |
+
return 'https://ce-docs.keywordrush.com';
|
194 |
+
}
|
195 |
+
|
196 |
+
public function registerAmpStyles()
|
197 |
+
{
|
198 |
+
echo '.egg-container table td{padding:0} .egg-container .btn,.egg-container .cegg-price{white-space:nowrap;font-weight:700}.cegg-couponcode,.cegg-gridbox a{text-decoration:none}.egg-container .cegg-gridbox{box-shadow:0 8px 16px -6px #eee;border:1px solid #ddd;margin-bottom:25px;padding:20px}.egg-container .egg-listcontainer .row-products>div{margin-bottom:12px}.egg-container .btn{display:inline-block;padding:7px 14px;margin-bottom:0;font-size:14px;line-height:1.42857143;text-align:center;vertical-align:middle;touch-action:manipulation;cursor:pointer;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px}.egg-container .btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c;text-decoration:none}.egg-container .panel-default{border:1px solid #ddd;padding:20px}.cegg-price-alert-wrap,.cegg-price-tracker-item div[id$=chart]{display:none}.cegg-price-tracker-panel .btn{margin-bottom:6px}.egg-container .cegg-no-top-margin{margin-top:0}.egg-container .cegg-mb5{margin-bottom:5px}.egg-container .cegg-mb10{margin-bottom:10px}.egg-container .cegg-mb15{margin-bottom:15px}.egg-container .cegg-mb20{margin-bottom:20px}.egg-container .cegg-mb25{margin-bottom:25px}.egg-container .cegg-mb30{margin-bottom:30px}.egg-container .cegg-mb35{margin-bottom:35px}.egg-container .cegg-lineh-20{line-height:20px}.egg-container .cegg-mr10{margin-right:10px}.egg-container .cegg-mr5{margin-right:5px}.egg-container .btn.cegg-btn-big{padding:13px 60px;line-height:1;font-size:20px;font-weight:700}.cegg-couponcode{text-align:center;background:#efffda;padding:8px;display:block;border:2px dashed #5cb85c;margin-bottom:12px}.cegg-bordered-box{border:2px solid #ededed;padding:25px}.cegg-price-tracker-item .cegg-price{font-size:22px;font-weight:700}.egg-list-coupons .btn{font-size:16px;font-weight:700;display:block}.cegg-listlogo-title{line-height:18px;font-size:15px}.cegg-list-withlogos .cegg-price,.egg-listcontainer .cegg-price{font-weight:700;font-size:20px;color:#5aaf0b}.egg-container .cegg-list-withlogos .btn{font-weight:700;font-size:15px;padding:8px 16px}.cegg-price-row strike{opacity:.42;font-size:90%}.cegg-list-logo-title{font-weight:700;font-size:17px}.egg-container .cegg-btn-grid .btn{display:block;margin-bottom:10px}#cegg_market .cegg-image-container img{max-height:350px}.cegg-review-block{padding:20px;border:1px solid #eee}.cegg-line-hr{clear:both;border-top:1px solid #eee;height:1px}.amp-wp-article-content .cegg-btn-row amp-img,.amp-wp-article-content .cegg-desc-cell amp-img,.amp-wp-article-content .cegg-price-tracker-panel .cegg-mb5 amp-img,.amp-wp-article-content .producttitle amp-img{display:inline-block;margin:0 4px 0 0;vertical-align:middle}.egg-container .cegg-promotion{top:25px;left:0;position:absolute;z-index:10}.egg-container .cegg-discount{background-color:#eb5e58;border-radius:0 4px 4px 0;color:#fff;display:inline-block;font-size:16px;padding:3px 5px}.cegg-thumb{position:relative}';
|
199 |
+
}
|
200 |
+
|
201 |
+
}
|
application/PriceAlert.php
CHANGED
@@ -1,400 +1,402 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
*
|
17 |
-
*
|
18 |
-
* @
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
private $
|
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 |
-
\add_action('
|
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 |
-
$this->
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
$
|
137 |
-
|
138 |
-
|
139 |
-
'
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
'
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
$
|
150 |
-
|
151 |
-
$body
|
152 |
-
$body .= '
|
153 |
-
$body .= '<p>' .
|
154 |
-
|
155 |
-
$body .=
|
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 |
-
return;
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
$
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
PriceAlertModel::
|
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 |
-
if (GeneralConfig::getInstance()->option('
|
280 |
-
\add_filter('
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
\
|
285 |
-
|
286 |
-
\remove_filter('
|
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 |
-
$body
|
360 |
-
$body .= '<
|
361 |
-
$body .= '<
|
362 |
-
$body .= '<
|
363 |
-
|
364 |
-
$body .= '<li>' . sprintf(__('Price
|
365 |
-
|
366 |
-
$body .= sprintf(__('
|
367 |
-
$body .= '</
|
368 |
-
|
369 |
-
$body .= '
|
370 |
-
|
371 |
-
$body .=
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
PriceAlertModel::
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
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;
|
12 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
13 |
+
use ContentEgg\application\admin\GeneralConfig;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* PriceAlert class file
|
17 |
+
*
|
18 |
+
* @author keywordrush.com <support@keywordrush.com>
|
19 |
+
* @link http://www.keywordrush.com/
|
20 |
+
* @copyright Copyright © 2016 keywordrush.com
|
21 |
+
*/
|
22 |
+
class PriceAlert {
|
23 |
+
|
24 |
+
private static $instance = null;
|
25 |
+
private $tickbox_message;
|
26 |
+
private $tickbox_subject;
|
27 |
+
|
28 |
+
public static function getInstance()
|
29 |
+
{
|
30 |
+
if (self::$instance == null)
|
31 |
+
self::$instance = new self;
|
32 |
+
|
33 |
+
return self::$instance;
|
34 |
+
}
|
35 |
+
|
36 |
+
private function __construct()
|
37 |
+
{
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
public function init()
|
42 |
+
{
|
43 |
+
if (!self::isPriceAlertAllowed())
|
44 |
+
return;
|
45 |
+
|
46 |
+
if (\is_admin())
|
47 |
+
{
|
48 |
+
// anonymous visitors
|
49 |
+
\add_action('wp_ajax_nopriv_start_tracking', array($this, 'ajaxTrackProduct'));
|
50 |
+
// logged in users
|
51 |
+
\add_action('wp_ajax_start_tracking', array($this, 'ajaxTrackProduct'));
|
52 |
+
}
|
53 |
+
\add_action('init', array($this, 'registerJs'));
|
54 |
+
\add_action('template_redirect', array($this, 'subscriptionManager'));
|
55 |
+
}
|
56 |
+
|
57 |
+
public function registerJs()
|
58 |
+
{
|
59 |
+
\wp_enqueue_script('cegg-price-alert', \ContentEgg\PLUGIN_RES . '/js/price_alert.js', array('jquery'));
|
60 |
+
\wp_localize_script('cegg-price-alert', 'ceggPriceAlert', array(
|
61 |
+
'ajaxurl' => \admin_url('admin-ajax.php'),
|
62 |
+
'nonce' => \wp_create_nonce('cegg-price-alert')
|
63 |
+
));
|
64 |
+
}
|
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(InputHelper::post('module_id', null));
|
72 |
+
$unique_id = TextHelper::clearId(InputHelper::post('unique_id', null));
|
73 |
+
$price = (float) TextHelper::parsePriceAmount(InputHelper::post('price', null));
|
74 |
+
$post_id = (int) InputHelper::post('post_id', null);
|
75 |
+
$email = strtolower(TextHelper::clearId(InputHelper::post('email', null)));
|
76 |
+
$accepted = (bool) InputHelper::post('accepted', null);
|
77 |
+
|
78 |
+
if (!$module_id || !$unique_id || !$post_id)
|
79 |
+
die('Invalid params');
|
80 |
+
|
81 |
+
$current = PriceHistoryModel::model()->getLastPrices($unique_id, $module_id, $limit = 1);
|
82 |
+
if (!$current)
|
83 |
+
die('Product not found.');
|
84 |
+
$current = $current[0];
|
85 |
+
|
86 |
+
// find product, check post_id
|
87 |
+
$product = ContentManager::getProductbyUniqueId($current['unique_id'], $current['module_id'], $post_id);
|
88 |
+
if (!$product)
|
89 |
+
die('Product not found.');
|
90 |
+
|
91 |
+
if (!$price || !$email)
|
92 |
+
$this->jsonError(__('All fields are required.', 'content-egg-tpl'));
|
93 |
+
|
94 |
+
if (TemplateHelper::getPrivacyUrl() && !$accepted)
|
95 |
+
$this->jsonError(__('Please indicate that you have read and agree to the Privacy Policy.', 'content-egg-tpl'));
|
96 |
+
|
97 |
+
if (!\is_email($email))
|
98 |
+
$this->jsonError(__('Your email address is invalid.', 'content-egg-tpl'));
|
99 |
+
|
100 |
+
if ($price >= $current['price'])
|
101 |
+
$this->jsonError(__('The price has already been reached.', 'content-egg-tpl'));
|
102 |
+
|
103 |
+
// dublicate?
|
104 |
+
$where = array(
|
105 |
+
'unique_id = %s AND module_id = %s AND email = %s AND status != %d',
|
106 |
+
array($unique_id, $module_id, $email, PriceAlertModel::STATUS_DELETED)
|
107 |
+
);
|
108 |
+
if (PriceAlertModel::model()->find(array('where' => $where)))
|
109 |
+
$this->jsonError(__('You already tracking this product.', 'content-egg-tpl'));
|
110 |
+
|
111 |
+
$alert = array(
|
112 |
+
'unique_id' => $current['unique_id'],
|
113 |
+
'module_id' => $current['module_id'],
|
114 |
+
'post_id' => $post_id,
|
115 |
+
'email' => $email,
|
116 |
+
'price' => $price,
|
117 |
+
'start_price' => $current['price'],
|
118 |
+
'status' => PriceAlertModel::STATUS_INACTIVE,
|
119 |
+
'activkey' => TextHelper::randomPassword(16),
|
120 |
+
);
|
121 |
+
|
122 |
+
// save
|
123 |
+
if (PriceAlertModel::model()->save($alert))
|
124 |
+
{
|
125 |
+
// email
|
126 |
+
$this->sendActivationEmail($email, $product, $alert);
|
127 |
+
$this->jsonResult(__('We are now tracking this product for you. Please verify your email address to be notified of price drops.', 'content-egg-tpl'), 'success');
|
128 |
+
} else
|
129 |
+
$this->jsonError(__('Internal Error. Please notify the administrator.', 'content-egg-tpl'));
|
130 |
+
exit;
|
131 |
+
}
|
132 |
+
|
133 |
+
private function sendActivationEmail($email, $product, $alert)
|
134 |
+
{
|
135 |
+
$subject = sprintf(__('Welcome to %s', 'content-egg-tpl'), \esc_html(\get_bloginfo('name')));
|
136 |
+
$product_title = \esc_html(TextHelper::truncate($product['title']));
|
137 |
+
|
138 |
+
$unsubscribe_url = \add_query_arg(array(
|
139 |
+
'ceggaction' => 'unsubscribe',
|
140 |
+
'email' => urlencode($email),
|
141 |
+
'key' => urlencode($alert['activkey']),
|
142 |
+
), \get_site_url());
|
143 |
+
|
144 |
+
$uri = \add_query_arg(array(
|
145 |
+
'ceggaction' => 'validate',
|
146 |
+
'email' => urlencode($email),
|
147 |
+
'key' => urlencode($alert['activkey']),
|
148 |
+
), \get_permalink($alert['post_id']));
|
149 |
+
$uri .= '#' . urlencode($alert['unique_id']);
|
150 |
+
|
151 |
+
$body = '<p>' . __('Hello,', 'content-egg-tpl') . '<br></p>';
|
152 |
+
$body .= '<p>' . sprintf(__('You have successfully set a price drop alert for %s.', 'content-egg-tpl'), $product_title) . '</p>';
|
153 |
+
$body .= '<p>' . __('We will not send you any price alerts until you verified your email address.', 'content-egg-tpl');
|
154 |
+
$body .= ' ' . sprintf(__('Please open this link to validate your email address:<br> <a href="%s">%s</a>', 'content-egg-tpl'), \esc_url($uri), \esc_url($uri)) . '</p>';
|
155 |
+
$body .= '<p>' . sprintf(__('If you don\'t want to receive any price alerts from us in the future, <a href="%s">please click here</a>.', 'content-egg-tpl'), $unsubscribe_url) . '</p>';
|
156 |
+
|
157 |
+
$body .= $this->getEmailSignature();
|
158 |
+
|
159 |
+
self::mail($email, $subject, $body);
|
160 |
+
}
|
161 |
+
|
162 |
+
private function getEmailSignature()
|
163 |
+
{
|
164 |
+
return "<pre class=\"moz-signature\" cols=\"72\">--\r\n" . sprintf(__('Thank You,', 'content-egg-tpl') . "\r\n" . __('The %s Team', 'content-egg-tpl') . "\r\n%s", \get_bloginfo('name'), get_home_url()) . "</pre>";
|
165 |
+
}
|
166 |
+
|
167 |
+
private function jsonResult($message, $status = 'success')
|
168 |
+
{
|
169 |
+
header("Content-Type: application/json");
|
170 |
+
echo json_encode(array(
|
171 |
+
'status' => $status,
|
172 |
+
'message' => $message
|
173 |
+
));
|
174 |
+
exit;
|
175 |
+
}
|
176 |
+
|
177 |
+
private function jsonError($message)
|
178 |
+
{
|
179 |
+
$this->jsonResult($message, 'error');
|
180 |
+
exit;
|
181 |
+
}
|
182 |
+
|
183 |
+
public function subscriptionManager()
|
184 |
+
{
|
185 |
+
if (!$action = InputHelper::get('ceggaction', null))
|
186 |
+
return;
|
187 |
+
|
188 |
+
switch ($action)
|
189 |
+
{
|
190 |
+
case 'validate':
|
191 |
+
$this->actionValidateEmail();
|
192 |
+
return;
|
193 |
+
case 'unsubscribe':
|
194 |
+
$this->actionUnsubscribeAll();
|
195 |
+
return;
|
196 |
+
case 'delete':
|
197 |
+
$this->actionDeleteSubscription();
|
198 |
+
return;
|
199 |
+
default:
|
200 |
+
return;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
private function actionValidateEmail()
|
205 |
+
{
|
206 |
+
$email = strtolower(TextHelper::clearId(InputHelper::get('email', null)));
|
207 |
+
$key = TextHelper::clear(InputHelper::get('key', null));
|
208 |
+
|
209 |
+
$where = array(
|
210 |
+
'email = %s AND activkey = %s AND status = %d',
|
211 |
+
array($email, $key, PriceAlertModel::STATUS_INACTIVE)
|
212 |
+
);
|
213 |
+
$alert = PriceAlertModel::model()->find(array('where' => $where));
|
214 |
+
if (!$alert)
|
215 |
+
return;
|
216 |
+
$alert['status'] = PriceAlertModel::STATUS_ACTIVE;
|
217 |
+
// save
|
218 |
+
PriceAlertModel::model()->save($alert);
|
219 |
+
// tickbox
|
220 |
+
$this->openTickbox(__('Your email has been verified. We will let you know by email when the Price Drops.', 'content-egg-tpl'), __('Success!', 'content-egg-tpl'));
|
221 |
+
}
|
222 |
+
|
223 |
+
private function actionUnsubscribeAll()
|
224 |
+
{
|
225 |
+
$email = strtolower(TextHelper::clearId(InputHelper::get('email', null)));
|
226 |
+
$key = TextHelper::clear(InputHelper::get('key', null));
|
227 |
+
|
228 |
+
$where = array(
|
229 |
+
'email = %s AND activkey = %s',
|
230 |
+
array($email, $key)
|
231 |
+
);
|
232 |
+
$alert = PriceAlertModel::model()->find(array('where' => $where));
|
233 |
+
if (!$alert)
|
234 |
+
return;
|
235 |
+
|
236 |
+
PriceAlertModel::model()->unsubscribeAll($alert['email']);
|
237 |
+
$this->openTickbox(__('You are now unsubscribed from our Price Alerts via email.', 'content-egg-tpl'), __('Unsubscribed!', 'content-egg-tpl'));
|
238 |
+
}
|
239 |
+
|
240 |
+
private function actionDeleteSubscription()
|
241 |
+
{
|
242 |
+
$email = strtolower(TextHelper::clearId(InputHelper::get('email', null)));
|
243 |
+
$key = TextHelper::clear(InputHelper::get('key', null));
|
244 |
+
|
245 |
+
$where = array(
|
246 |
+
'email = %s AND activkey = %s',
|
247 |
+
array($email, $key)
|
248 |
+
);
|
249 |
+
$alert = PriceAlertModel::model()->find(array('where' => $where));
|
250 |
+
if (!$alert)
|
251 |
+
return;
|
252 |
+
// save
|
253 |
+
PriceAlertModel::model()->delete($alert['id']);
|
254 |
+
// tickbox
|
255 |
+
$this->openTickbox(__('Your subscription has been deleted from our database.', 'content-egg-tpl'), __('Success!', 'content-egg-tpl'));
|
256 |
+
}
|
257 |
+
|
258 |
+
public function openTickbox($message, $subject = "")
|
259 |
+
{
|
260 |
+
$this->tickbox_message = strip_tags($message);
|
261 |
+
$this->tickbox_subject = strip_tags($subject);
|
262 |
+
\add_thickbox();
|
263 |
+
\add_action('wp_footer', array($this, 'tickboxInlineScript'));
|
264 |
+
}
|
265 |
+
|
266 |
+
public function tickboxInlineScript()
|
267 |
+
{
|
268 |
+
echo '<script>
|
269 |
+
jQuery(window).load(function()
|
270 |
+
{
|
271 |
+
jQuery("body").append("<div style=\"display:none;\" id=\"cegg-price-alert-tickbox\"><p>' . \esc_js($this->tickbox_message) . '<div style=\"text-align:center; padding-top: 30px;padding-right: 20px;\"><input value=\"' . esc_js(__(' Ok ', 'content-egg-tpl')) . '\" type=\"button\" onclick=\"javascript:tb_remove()\"></div></p></div>");
|
272 |
+
tb_show("' . esc_js($this->tickbox_subject) . '", "#TB_inline?height=200&width=300&inlineId=cegg-price-alert-tickbox", false);
|
273 |
+
});</script>';
|
274 |
+
}
|
275 |
+
|
276 |
+
public static function mail($to, $subject, $message, $headers = '', $attachments = array())
|
277 |
+
{
|
278 |
+
\add_filter('wp_mail_content_type', array(__CLASS__, 'setMailContentType'));
|
279 |
+
if (GeneralConfig::getInstance()->option('from_email'))
|
280 |
+
\add_filter('wp_mail_from', array(__CLASS__, 'setMailFrom'));
|
281 |
+
if (GeneralConfig::getInstance()->option('from_name'))
|
282 |
+
\add_filter('wp_mail_from_name', array(__CLASS__, 'setMailFromName'));
|
283 |
+
|
284 |
+
\wp_mail($to, $subject, $message, $headers, $attachments);
|
285 |
+
|
286 |
+
\remove_filter('wp_mail_content_type', array(__CLASS__, 'setMailContentType'));
|
287 |
+
\remove_filter('wp_mail_from', array(__CLASS__, 'setMailFrom'));
|
288 |
+
\remove_filter('wp_mail_from_name', array(__CLASS__, 'setMailFromName'));
|
289 |
+
}
|
290 |
+
|
291 |
+
public static function setMailContentType()
|
292 |
+
{
|
293 |
+
return 'text/html';
|
294 |
+
}
|
295 |
+
|
296 |
+
public static function setMailFrom()
|
297 |
+
{
|
298 |
+
return GeneralConfig::getInstance()->option('from_email');
|
299 |
+
}
|
300 |
+
|
301 |
+
public static function setMailFromName()
|
302 |
+
{
|
303 |
+
return GeneralConfig::getInstance()->option('from_name');
|
304 |
+
}
|
305 |
+
|
306 |
+
public function sendAlerts(array $data, $module_id, $post_id)
|
307 |
+
{
|
308 |
+
$total = 0;
|
309 |
+
foreach ($data as $key => $d)
|
310 |
+
{
|
311 |
+
if (empty($d['unique_id']) || empty($d['price']))
|
312 |
+
continue;
|
313 |
+
|
314 |
+
// Price drops?
|
315 |
+
$previous_price = PriceHistoryModel::model()->getPreviousPriceValue($d['unique_id'], $module_id);
|
316 |
+
if (!$previous_price || (float) $previous_price <= (float) $d['price']) //!!!!!
|
317 |
+
continue;
|
318 |
+
|
319 |
+
// Subscribers exist?
|
320 |
+
$params = array(
|
321 |
+
'where' => array('unique_id=%s AND module_id=%s AND status=%d AND price >= %f', array($d['unique_id'], $module_id, PriceAlertModel::STATUS_ACTIVE, $d['price'])),
|
322 |
+
);
|
323 |
+
$subscribers = PriceAlertModel::model()->findAll($params);
|
324 |
+
if (!$subscribers)
|
325 |
+
continue;
|
326 |
+
|
327 |
+
$total += count($total);
|
328 |
+
$this->sendAlertEmails($subscribers, $d, $post_id);
|
329 |
+
}
|
330 |
+
|
331 |
+
// clean up & optimize
|
332 |
+
if ($total && rand(1, 5) == 5)
|
333 |
+
{
|
334 |
+
PriceAlertModel::model()->cleanOld(PriceAlertModel::CLEAN_DELETED_DAYS);
|
335 |
+
}
|
336 |
+
}
|
337 |
+
|
338 |
+
private function sendAlertEmails($alerts, $product, $post_id)
|
339 |
+
{
|
340 |
+
foreach ($alerts as $alert)
|
341 |
+
{
|
342 |
+
$product_title = \esc_html(TextHelper::truncate($product['title']));
|
343 |
+
$subject = sprintf(__('Price alert: "%s"', 'content-egg-tpl'), $product_title);
|
344 |
+
$post_url = \get_permalink($post_id) . '#' . urlencode($product['unique_id']);
|
345 |
+
|
346 |
+
$unsubscribe_url = \add_query_arg(array(
|
347 |
+
'ceggaction' => 'unsubscribe',
|
348 |
+
'email' => urlencode($alert['email']),
|
349 |
+
'key' => urlencode($alert['activkey']),
|
350 |
+
), \get_site_url());
|
351 |
+
|
352 |
+
$desired_price = TemplateHelper::formatPriceCurrency($alert['price'], $product['currencyCode']);
|
353 |
+
$current_price = TemplateHelper::formatPriceCurrency($product['price'], $product['currencyCode']);
|
354 |
+
$start_price = TemplateHelper::formatPriceCurrency($alert['start_price'], $product['currencyCode']);
|
355 |
+
$saved_amount = round($alert['start_price'] - $product['price'], 2);
|
356 |
+
$saved_amount = TemplateHelper::formatPriceCurrency($saved_amount, $product['currencyCode']);
|
357 |
+
$saved_percentage = round(100 - (100 * $product['price']) / $alert['start_price'], 2);
|
358 |
+
|
359 |
+
$body = '<p>' . __('Good news!', 'content-egg-tpl') . '<br></p>';
|
360 |
+
$body .= '<p>' . __('The price target you set for the item has been reached.', 'content-egg-tpl');
|
361 |
+
$body .= '<p>' . sprintf(__('<a href="%s">Save %s (%s%%) on %s</a>', 'content-egg-tpl'), $post_url, $saved_amount, $saved_percentage, $product_title);
|
362 |
+
$body .= '<ul>';
|
363 |
+
$body .= '<li>' . sprintf(__('Desired Price: %s', 'content-egg-tpl'), $desired_price) . '</li>';
|
364 |
+
$body .= '<li>' . sprintf(__('Current Price: <strong>%s</strong>', 'content-egg-tpl'), $current_price)
|
365 |
+
. ' (' . __('as of', 'content-egg-tpl') . ' ' . TemplateHelper::getLastUpdateFormatted($alert['module_id'], $post_id) . ')</li>';
|
366 |
+
$body .= '<li>' . sprintf(__('Price dropped from %s to %s', 'content-egg-tpl'), $start_price, $current_price) . '</li>';
|
367 |
+
$body .= '</ul><br>';
|
368 |
+
$body .= sprintf(__('<a href="%s">More info...</a>', 'content-egg-tpl'), $post_url);
|
369 |
+
$body .= '</p><br>';
|
370 |
+
|
371 |
+
$body .= '<p>' . sprintf(__('This present alert has now expired. You may <a href="%s">create a new alert</a> for this item.', 'content-egg-tpl'), $post_url);
|
372 |
+
$body .= '<br>' . sprintf(__('If you don\'t want to receive any price alerts from us in the future, <a href="%s">please click here</a>.', 'content-egg-tpl'), $unsubscribe_url) . '</p>';
|
373 |
+
$body .= $this->getEmailSignature();
|
374 |
+
|
375 |
+
// send alert email
|
376 |
+
self::mail($alert['email'], $subject, $body);
|
377 |
+
|
378 |
+
// delete alert
|
379 |
+
$alert['status'] = PriceAlertModel::STATUS_DELETED;
|
380 |
+
$alert['complet_date'] = \current_time('mysql');
|
381 |
+
PriceAlertModel::model()->save($alert);
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
public static function isPriceAlertAllowed($unique_id = null, $module_id = null)
|
386 |
+
{
|
387 |
+
if (!GeneralConfig::getInstance()->option('price_history_days'))
|
388 |
+
return false;
|
389 |
+
|
390 |
+
if (!GeneralConfig::getInstance()->option('price_alert_enabled'))
|
391 |
+
return false;
|
392 |
+
//get_option( 'wp_page_for_privacy_policy' )
|
393 |
+
|
394 |
+
if ($unique_id && $module_id)
|
395 |
+
{
|
396 |
+
if (!PriceHistoryModel::model()->getLastPrices($unique_id, $module_id, 1))
|
397 |
+
return false;
|
398 |
+
}
|
399 |
+
return true;
|
400 |
+
}
|
401 |
+
|
402 |
+
}
|
application/PriceMoversWidget.php
CHANGED
@@ -1,225 +1,228 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\components\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
use ContentEgg\application\
|
13 |
-
|
14 |
-
|
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 |
-
$product['
|
157 |
-
$product['
|
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 |
-
$a
|
219 |
-
$a['
|
220 |
-
$a['
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\CEWidget;
|
8 |
+
use ContentEgg\application\models\PriceHistoryModel;
|
9 |
+
use ContentEgg\application\components\WidgetTemplateManager;
|
10 |
+
use ContentEgg\application\components\ContentManager;
|
11 |
+
use ContentEgg\application\components\ModuleManager;
|
12 |
+
use ContentEgg\application\helpers\TextHelper;
|
13 |
+
use ContentEgg\application\admin\GeneralConfig;
|
14 |
+
use ContentEgg\application\components\ContentProduct;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* PriceMoversWidget class file
|
18 |
+
*
|
19 |
+
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link http://www.keywordrush.com/
|
21 |
+
* @copyright Copyright © 2017 keywordrush.com
|
22 |
+
*/
|
23 |
+
class PriceMoversWidget extends CEWidget {
|
24 |
+
|
25 |
+
const shortcode = 'content-egg-price-movers';
|
26 |
+
|
27 |
+
public function __construct()
|
28 |
+
{
|
29 |
+
parent::__construct();
|
30 |
+
$this->addShortcode();
|
31 |
+
}
|
32 |
+
|
33 |
+
public function slug()
|
34 |
+
{
|
35 |
+
return 'cegg_price_movers';
|
36 |
+
}
|
37 |
+
|
38 |
+
public function description()
|
39 |
+
{
|
40 |
+
return __('Products with the biggest price drops.', 'content-egg');
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function name()
|
44 |
+
{
|
45 |
+
return __('CE: Price Movers', 'content-egg');
|
46 |
+
}
|
47 |
+
|
48 |
+
public function classname()
|
49 |
+
{
|
50 |
+
return 'widget cegg_widget_products';
|
51 |
+
}
|
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(
|
60 |
+
'title' => array(
|
61 |
+
'type' => 'text',
|
62 |
+
'default' => __('Price Drops', 'content-egg-tpl'),
|
63 |
+
'title' => __('Title', 'content-egg'),
|
64 |
+
),
|
65 |
+
'limit' => array(
|
66 |
+
'type' => 'number',
|
67 |
+
'min' => 1,
|
68 |
+
'max' => 30,
|
69 |
+
'default' => 5,
|
70 |
+
'title' => __('Number of products to show', 'content-egg'),
|
71 |
+
),
|
72 |
+
'drop_type' => array(
|
73 |
+
'type' => 'select',
|
74 |
+
'default' => 'absolute',
|
75 |
+
'title' => __('Drop type', 'content-egg'),
|
76 |
+
'options' => array(
|
77 |
+
'absolute' => __('Biggest absolute', 'content-egg'),
|
78 |
+
'relative' => __('Biggest relative', 'content-egg'),
|
79 |
+
//'recent' => __('Most recent', 'content-egg'),
|
80 |
+
)
|
81 |
+
),
|
82 |
+
'direction' => array(
|
83 |
+
'type' => 'select',
|
84 |
+
'default' => 'drops',
|
85 |
+
'title' => __('Direction', 'content-egg'),
|
86 |
+
'options' => array(
|
87 |
+
'drops' => __('Price drops', 'content-egg'),
|
88 |
+
'increases' => __('Price increases', 'content-egg'),
|
89 |
+
)
|
90 |
+
),
|
91 |
+
'last_update' => array(
|
92 |
+
'type' => 'select',
|
93 |
+
'default' => 7,
|
94 |
+
'title' => __('Last update', 'content-egg'),
|
95 |
+
'options' => array(
|
96 |
+
1 => __('1 day ago', 'content-egg'),
|
97 |
+
2 => sprintf(__('%d days ago', 'content-egg'), 2),
|
98 |
+
3 => sprintf(__('%d days ago', 'content-egg'), 3),
|
99 |
+
4 => sprintf(__('%d days ago', 'content-egg'), 4),
|
100 |
+
5 => sprintf(__('%d days ago', 'content-egg'), 5),
|
101 |
+
6 => sprintf(__('%d days ago', 'content-egg'), 6),
|
102 |
+
7 => sprintf(__('%d days ago', 'content-egg'), 7),
|
103 |
+
21 => sprintf(__('%d days ago', 'content-egg'), 21),
|
104 |
+
30 => sprintf(__('%d days ago', 'content-egg'), 30),
|
105 |
+
)
|
106 |
+
),
|
107 |
+
'template' => array(
|
108 |
+
'type' => 'select',
|
109 |
+
'default' => 'wdgt_price_movers_grid',
|
110 |
+
'title' => __('Template', 'content-egg'),
|
111 |
+
'options' => WidgetTemplateManager::getInstance($this->slug())->getTemplatesList()
|
112 |
+
),
|
113 |
+
);
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Front-end display of widget.
|
118 |
+
*/
|
119 |
+
public function widget($args, $instance)
|
120 |
+
{
|
121 |
+
$items = $this->getItems($instance);
|
122 |
+
if (!$items)
|
123 |
+
return;
|
124 |
+
|
125 |
+
$this->beforeWidget($args, $instance);
|
126 |
+
$tpl_manager = WidgetTemplateManager::getInstance($this->slug());
|
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)
|
140 |
+
{
|
141 |
+
$products = PriceHistoryModel::model()->getPriceMovers($instance, true);
|
142 |
+
$active_parsers = array_keys(ModuleManager::getInstance()->getAffiliateParsers(true, true));
|
143 |
+
$items = array();
|
144 |
+
$outofstock_product = GeneralConfig::getInstance()->option('outofstock_product');
|
145 |
+
foreach ($products as $product)
|
146 |
+
{
|
147 |
+
if (!in_array($product['module_id'], $active_parsers))
|
148 |
+
continue;
|
149 |
+
$item = ContentManager::getProductbyUniqueId($product['unique_id'], $product['module_id'], $product['post_id'], $instance);
|
150 |
+
if (!$item)
|
151 |
+
continue;
|
152 |
+
|
153 |
+
if ($outofstock_product == 'hide_product' && isset($item['stock_status']) && $item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
154 |
+
continue;
|
155 |
+
|
156 |
+
$product['discount_percent'] = ceil(100 - ($product['price'] * 100) / $product['price_old']);
|
157 |
+
$product['discount_value'] = $product['price_old'] - $product['price'];
|
158 |
+
$product['create_date'] = strtotime($product['create_date']);
|
159 |
+
$product['price_old_date'] = strtotime($product['price_old_date']);
|
160 |
+
$item['_price_movers'] = $product;
|
161 |
+
$items[] = $item;
|
162 |
+
|
163 |
+
if (count($items) >= $instance['limit'])
|
164 |
+
break;
|
165 |
+
}
|
166 |
+
$this->setCache($items, $cache_key, 3600);
|
167 |
+
}
|
168 |
+
return $items;
|
169 |
+
}
|
170 |
+
|
171 |
+
private function getCacheKey(array $instance)
|
172 |
+
{
|
173 |
+
$str = '';
|
174 |
+
foreach ($instance as $k => $v)
|
175 |
+
{
|
176 |
+
if (!is_array($v))
|
177 |
+
$str .= $k . $v;
|
178 |
+
}
|
179 |
+
return md5($str);
|
180 |
+
}
|
181 |
+
|
182 |
+
public function addShortcode()
|
183 |
+
{
|
184 |
+
\add_shortcode(self::shortcode, array($this, 'viewShortcode'));
|
185 |
+
}
|
186 |
+
|
187 |
+
public function viewShortcode($atts, $content = "")
|
188 |
+
{
|
189 |
+
$a = $this->prepareAttr($atts);
|
190 |
+
|
191 |
+
$items = $this->getItems($a);
|
192 |
+
if (!$items)
|
193 |
+
return;
|
194 |
+
|
195 |
+
$tpl_manager = WidgetTemplateManager::getInstance($this->slug());
|
196 |
+
if (empty($a['template']) || !$tpl_manager->isTemplateExists($a['template']))
|
197 |
+
return;
|
198 |
+
|
199 |
+
return $tpl_manager->render($a['template'], array('items' => $items, 'is_shortcode' => true, 'cols' => $a['cols'], 'btn_text' => ''));
|
200 |
+
}
|
201 |
+
|
202 |
+
private function prepareAttr($atts)
|
203 |
+
{
|
204 |
+
$settings = $this->settings(true);
|
205 |
+
|
206 |
+
$defaults = array();
|
207 |
+
foreach ($settings as $name => $setting)
|
208 |
+
{
|
209 |
+
if (isset($setting['default']))
|
210 |
+
$defaults[$name] = $setting['default'];
|
211 |
+
else
|
212 |
+
$defaults[$name] = '';
|
213 |
+
}
|
214 |
+
$defaults['template'] = 'wdgt_price_movers_list';
|
215 |
+
$defaults['cols'] = 0;
|
216 |
+
$defaults['currency'] = '';
|
217 |
+
|
218 |
+
$a = \shortcode_atts($defaults, $atts);
|
219 |
+
$a['limit'] = (int) $a['limit'];
|
220 |
+
$a['cols'] = (int) $a['cols'];
|
221 |
+
$a['last_update'] = (int) $a['last_update'];
|
222 |
+
$a['template'] = \sanitize_text_field($a['template']);
|
223 |
+
$a['currency'] = strtoupper(TextHelper::clear($a['currency']));
|
224 |
+
|
225 |
+
return $a;
|
226 |
+
}
|
227 |
+
|
228 |
+
}
|
application/ProductSearch.php
CHANGED
@@ -1,120 +1,122 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
return
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\VirtualPage;
|
8 |
+
use ContentEgg\application\admin\GeneralConfig;
|
9 |
+
use ContentEgg\application\components\ModuleManager;
|
10 |
+
use ContentEgg\application\helpers\TextHelper;
|
11 |
+
use ContentEgg\application\ModuleViewer;
|
12 |
+
use ContentEgg\application\components\ContentManager;
|
13 |
+
use ContentEgg\application\helpers\InputHelper;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* ProductSearch class file
|
17 |
+
*
|
18 |
+
* @author keywordrush.com <support@keywordrush.com>
|
19 |
+
* @link http://www.keywordrush.com/
|
20 |
+
* @copyright Copyright © 2017 keywordrush.com
|
21 |
+
*/
|
22 |
+
class ProductSearch extends VirtualPage {
|
23 |
+
|
24 |
+
const PAGE_SLUG = 'product-search';
|
25 |
+
const shortcode = 'content-egg-search-form';
|
26 |
+
|
27 |
+
private $keyword;
|
28 |
+
|
29 |
+
public static function initAction()
|
30 |
+
{
|
31 |
+
\add_shortcode(self::shortcode, array(__CLASS__, 'viewSearchFrom'));
|
32 |
+
|
33 |
+
if (!GeneralConfig::getInstance()->option('search_modules'))
|
34 |
+
return;
|
35 |
+
|
36 |
+
new self;
|
37 |
+
//parent::initAction();
|
38 |
+
}
|
39 |
+
|
40 |
+
protected function handleRequest($query_vars = array())
|
41 |
+
{
|
42 |
+
if (empty($query_vars['s']))
|
43 |
+
return;
|
44 |
+
|
45 |
+
$this->keyword = trim(TextHelper::clear_utf8(\sanitize_text_field($query_vars['s'])));
|
46 |
+
if (!$this->keyword)
|
47 |
+
return;
|
48 |
+
|
49 |
+
parent::handleRequest($query_vars);
|
50 |
+
}
|
51 |
+
|
52 |
+
public static function viewSearchFrom($atts, $content = "")
|
53 |
+
{
|
54 |
+
echo ProductSearchWidget::getSearchForm();
|
55 |
+
}
|
56 |
+
|
57 |
+
public function getSlug()
|
58 |
+
{
|
59 |
+
return \apply_filters('cegg_product_search_slug', self::PAGE_SLUG);
|
60 |
+
}
|
61 |
+
|
62 |
+
public static function getPageSlug()
|
63 |
+
{
|
64 |
+
return \apply_filters('cegg_product_search_slug', self::PAGE_SLUG);
|
65 |
+
}
|
66 |
+
|
67 |
+
public function getBody()
|
68 |
+
{
|
69 |
+
// search & add data to ModuleViewer
|
70 |
+
$total = $this->addSearchData();
|
71 |
+
if ($total)
|
72 |
+
return GeneralConfig::getInstance()->option('search_page_tpl');
|
73 |
+
else
|
74 |
+
return __('Sorry. No products found.', 'content-egg-tpl');
|
75 |
+
}
|
76 |
+
|
77 |
+
public function getTemplate()
|
78 |
+
{
|
79 |
+
return 'ce-product-search.php';
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Search and set view data
|
84 |
+
*/
|
85 |
+
private function addSearchData()
|
86 |
+
{
|
87 |
+
$post_id = -1;
|
88 |
+
$module_ids = GeneralConfig::getInstance()->option('search_modules');
|
89 |
+
$total = 0;
|
90 |
+
foreach ($module_ids as $module_id)
|
91 |
+
{
|
92 |
+
$parser = ModuleManager::getInstance()->parserFactory($module_id);
|
93 |
+
if (!$parser->isActive())
|
94 |
+
continue;
|
95 |
+
|
96 |
+
try
|
97 |
+
{
|
98 |
+
$data = $parser->doRequest($this->keyword, array(), true);
|
99 |
+
} catch (\Exception $e)
|
100 |
+
{
|
101 |
+
// error
|
102 |
+
continue;
|
103 |
+
}
|
104 |
+
|
105 |
+
// nodata!
|
106 |
+
if (!$data)
|
107 |
+
continue;
|
108 |
+
|
109 |
+
$data = ContentManager::dataPresavePrepare($data, $module_id, $post_id);
|
110 |
+
$data = ContentManager::dataPreviewPrepare($data, $module_id, $post_id);
|
111 |
+
$total += count($data);
|
112 |
+
ModuleViewer::getInstance()->setData($module_id, $post_id, $data);
|
113 |
+
}
|
114 |
+
return $total;
|
115 |
+
}
|
116 |
+
|
117 |
+
public function getTitle()
|
118 |
+
{
|
119 |
+
return sprintf(__('Search Results for "%s"', 'content-egg-tpl'), $this->keyword);
|
120 |
+
}
|
121 |
+
|
122 |
+
}
|
application/ProductSearchWidget.php
CHANGED
@@ -1,92 +1,94 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
*
|
11 |
-
*
|
12 |
-
* @
|
13 |
-
|
14 |
-
|
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 |
-
$form = preg_replace('
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
return \esc_url(\home_url(
|
90 |
-
|
91 |
-
|
92 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\CEWidget;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* ProductSearchWidget class file
|
11 |
+
*
|
12 |
+
* @author keywordrush.com <support@keywordrush.com>
|
13 |
+
* @link https://www.keywordrush.com/
|
14 |
+
* @copyright Copyright © 2020 keywordrush.com
|
15 |
+
*/
|
16 |
+
class ProductSearchWidget extends CEWidget {
|
17 |
+
|
18 |
+
public function slug()
|
19 |
+
{
|
20 |
+
return 'cegg_product_search';
|
21 |
+
}
|
22 |
+
|
23 |
+
public function description()
|
24 |
+
{
|
25 |
+
return __('A search form for affiliate products.', 'content-egg');
|
26 |
+
}
|
27 |
+
|
28 |
+
protected function name()
|
29 |
+
{
|
30 |
+
return __('CE: Product Search', 'content-egg');
|
31 |
+
}
|
32 |
+
|
33 |
+
public function classname()
|
34 |
+
{
|
35 |
+
return 'widget widget_search';
|
36 |
+
}
|
37 |
+
|
38 |
+
public function settings()
|
39 |
+
{
|
40 |
+
return
|
41 |
+
array(
|
42 |
+
'title' => array(
|
43 |
+
'type' => 'text',
|
44 |
+
'default' => '',
|
45 |
+
'title' => __('Title', 'content-egg'),
|
46 |
+
),
|
47 |
+
);
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Front-end display of widget.
|
52 |
+
*/
|
53 |
+
public function widget($args, $instance)
|
54 |
+
{
|
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 |
+
}
|
62 |
+
|
63 |
+
public static function getSearchForm()
|
64 |
+
{
|
65 |
+
$search_form_template = \locate_template('ce-product-searchform.php');
|
66 |
+
if ($search_form_template)
|
67 |
+
{
|
68 |
+
ob_start();
|
69 |
+
require( $search_form_template );
|
70 |
+
$form = ob_get_clean();
|
71 |
+
} else
|
72 |
+
{
|
73 |
+
// standart wp search from
|
74 |
+
$form = \get_search_form(false);
|
75 |
+
|
76 |
+
if (\get_option('permalink_structure'))
|
77 |
+
$form = preg_replace('/action=["\'].+?["\']/', 'action="' . self::getSearchFormUri() . '"', $form);
|
78 |
+
else
|
79 |
+
$form = preg_replace('/<\/form>/', '<input type="hidden" name="pagename" value="' . \esc_attr(ProductSearch::getPageSlug()) . '"></form>', $form);
|
80 |
+
|
81 |
+
$form = preg_replace('/placeholder=".+?"/', 'placeholder="' . esc_attr(__('Product Search...', 'content-egg-tpl')) . '"', $form);
|
82 |
+
}
|
83 |
+
return $form;
|
84 |
+
}
|
85 |
+
|
86 |
+
public static function getSearchFormUri()
|
87 |
+
{
|
88 |
+
if (\get_option('permalink_structure'))
|
89 |
+
return \esc_url(\home_url(ProductSearch::getPageSlug()));
|
90 |
+
else
|
91 |
+
return \esc_url(\home_url('/'));
|
92 |
+
}
|
93 |
+
|
94 |
+
}
|
application/WooIntegrator.php
CHANGED
@@ -1,540 +1,575 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\components\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\helpers\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
use ContentEgg\application\
|
13 |
-
use ContentEgg\application\
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
*
|
18 |
-
*
|
19 |
-
* @
|
20 |
-
* @
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
\add_action('
|
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 |
-
if (
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
if (
|
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 |
-
if (
|
509 |
-
return;
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ContentManager;
|
8 |
+
use ContentEgg\application\components\FeaturedImage;
|
9 |
+
use ContentEgg\application\helpers\TextHelper;
|
10 |
+
use ContentEgg\application\helpers\CurrencyHelper;
|
11 |
+
use ContentEgg\application\admin\GeneralConfig;
|
12 |
+
use ContentEgg\application\components\ModuleManager;
|
13 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
14 |
+
use ContentEgg\application\components\ContentProduct;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* WooIntegrator class file
|
18 |
+
*
|
19 |
+
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link https://www.keywordrush.com
|
21 |
+
* @copyright Copyright © 2020 keywordrush.com
|
22 |
+
*/
|
23 |
+
class WooIntegrator {
|
24 |
+
|
25 |
+
const META_WOO_SYNC_MODULE_UNIQUE_ID = '_cegg_woo_sync_muid';
|
26 |
+
|
27 |
+
private static $attributes_list;
|
28 |
+
|
29 |
+
public static function initAction()
|
30 |
+
{
|
31 |
+
if (!class_exists('\WooCommerce'))
|
32 |
+
return;
|
33 |
+
|
34 |
+
\add_action('woocommerce_before_single_product', array(__CLASS__, 'touchEmptyPost'), 10);
|
35 |
+
\add_action('content_egg_save_data', array(__CLASS__, 'wooHandler'), 13, 4);
|
36 |
+
|
37 |
+
if (GeneralConfig::getInstance()->option('woocommerce_echo_update_date'))
|
38 |
+
\add_action('woocommerce_single_product_summary', array(__CLASS__, 'echoUpdateDate'), 25);
|
39 |
+
|
40 |
+
if (GeneralConfig::getInstance()->option('woocommerce_echo_price_per_unit'))
|
41 |
+
\add_action('woocommerce_single_product_summary', array(__CLASS__, 'echoPricePerUnit'), 20);
|
42 |
+
|
43 |
+
if (GeneralConfig::getInstance()->option('woocommerce_btn_text'))
|
44 |
+
{
|
45 |
+
\add_filter('woocommerce_product_single_add_to_cart_text', array(__CLASS__, 'customButtonText'), 10, 2);
|
46 |
+
\add_filter('woocommerce_product_add_to_cart_text', array(__CLASS__, 'customButtonText'), 10, 2);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
public static function touchEmptyPost()
|
51 |
+
{
|
52 |
+
global $post;
|
53 |
+
if (!$post->post_content)
|
54 |
+
$post->post_content = apply_filters('the_content', $post->post_content);
|
55 |
+
}
|
56 |
+
|
57 |
+
public static function wooHandler($data, $module_id, $post_id, $is_last_iteration)
|
58 |
+
{
|
59 |
+
if (\get_post_type($post_id) != 'product' || !$product = \wc_get_product($post_id))
|
60 |
+
return;
|
61 |
+
|
62 |
+
if (!$is_last_iteration)
|
63 |
+
return;
|
64 |
+
|
65 |
+
// Get all post data
|
66 |
+
$affiliate_modules = ModuleManager::getInstance()->getAffiliteModulesList(true);
|
67 |
+
$modules_data = array();
|
68 |
+
foreach ($affiliate_modules as $module_id => $module_name)
|
69 |
+
{
|
70 |
+
if (!$data = ContentManager::getViewData($module_id, $post_id))
|
71 |
+
continue;
|
72 |
+
$modules_data[$module_id] = $data;
|
73 |
+
}
|
74 |
+
|
75 |
+
// Check for Manual sync
|
76 |
+
$is_product_sync = false;
|
77 |
+
$is_attr_sync = false;
|
78 |
+
foreach ($modules_data as $module_id => $data)
|
79 |
+
{
|
80 |
+
foreach ($data as $item)
|
81 |
+
{
|
82 |
+
if (!$is_product_sync && !empty($item['woo_sync']))
|
83 |
+
{
|
84 |
+
self::wooSync($item, $module_id, $post_id);
|
85 |
+
$is_product_sync = true;
|
86 |
+
}
|
87 |
+
|
88 |
+
if (!$is_attr_sync && !empty($item['woo_attr']))
|
89 |
+
{
|
90 |
+
self::wooCreateAttr($item, $module_id, $post_id);
|
91 |
+
$is_attr_sync == true;
|
92 |
+
}
|
93 |
+
|
94 |
+
if ($is_product_sync && $is_attr_sync)
|
95 |
+
return;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
if ($is_product_sync)
|
100 |
+
return;
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Automatic sync
|
104 |
+
*/
|
105 |
+
$woocommerce_product_sync = GeneralConfig::getInstance()->option('woocommerce_product_sync');
|
106 |
+
$woocommerce_modules = GeneralConfig::getInstance()->option('woocommerce_modules');
|
107 |
+
if (!$woocommerce_modules || $woocommerce_product_sync == 'manually')
|
108 |
+
return;
|
109 |
+
|
110 |
+
$modules_data = array_intersect_key($modules_data, $woocommerce_modules);
|
111 |
+
if ($item = ContentManager::getMainProduct($modules_data, $woocommerce_product_sync))
|
112 |
+
{
|
113 |
+
self::wooSync($item, $item['module_id'], $post_id);
|
114 |
+
|
115 |
+
// also sync attr if not exist
|
116 |
+
if (!$product->get_attributes() && GeneralConfig::getInstance()->option('woocommerce_attributes_sync'))
|
117 |
+
self::wooCreateAttr($item, $item['module_id'], $post_id);
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
public static function wooSync(array $item, $module_id, $post_id)
|
122 |
+
{
|
123 |
+
if (!$product = \wc_get_product($post_id))
|
124 |
+
return false;
|
125 |
+
|
126 |
+
// set price
|
127 |
+
if (!empty($item['price']))
|
128 |
+
{
|
129 |
+
$currency_rate = 1;
|
130 |
+
$woo_currency = \get_woocommerce_currency();
|
131 |
+
if ($item['currencyCode'] && $item['currencyCode'] != $woo_currency)
|
132 |
+
{
|
133 |
+
$currency_rate = CurrencyHelper::getCurrencyRate($item['currencyCode'], $woo_currency);
|
134 |
+
if (!$currency_rate)
|
135 |
+
$currency_rate = 1;
|
136 |
+
}
|
137 |
+
|
138 |
+
$product->set_price($item['price'] * $currency_rate);
|
139 |
+
if ($item['priceOld'])
|
140 |
+
{
|
141 |
+
if (\apply_filters('cegg_dont_sync_sale_price', false))
|
142 |
+
{
|
143 |
+
$product->set_regular_price($item['price'] * $currency_rate);
|
144 |
+
} else
|
145 |
+
{
|
146 |
+
$product->set_regular_price($item['priceOld'] * $currency_rate);
|
147 |
+
if (!\apply_filters('cegg_dont_touch_sale_price', false))
|
148 |
+
$product->set_sale_price($item['price'] * $currency_rate);
|
149 |
+
}
|
150 |
+
} else
|
151 |
+
{
|
152 |
+
/*
|
153 |
+
* If my initial import from Products filled in all the correct Retail values,
|
154 |
+
* I don’t want them touched. Retail should never really be changed regardless
|
155 |
+
* of the new lowest price.
|
156 |
+
*/
|
157 |
+
if ($product->get_regular_price() && \apply_filters('cegg_dont_touch_retail_price', false))
|
158 |
+
{
|
159 |
+
$product->set_sale_price($item['price'] * $currency_rate);
|
160 |
+
} else
|
161 |
+
{
|
162 |
+
$product->set_regular_price($item['price'] * $currency_rate);
|
163 |
+
if (!\apply_filters('cegg_dont_touch_sale_price', false))
|
164 |
+
$product->set_sale_price(null);
|
165 |
+
}
|
166 |
+
}
|
167 |
+
} else
|
168 |
+
{
|
169 |
+
$product->set_price(null);
|
170 |
+
$product->set_regular_price(null);
|
171 |
+
$product->set_sale_price(null);
|
172 |
+
}
|
173 |
+
|
174 |
+
// External products cannot be stock managed.
|
175 |
+
if ($product->get_type() == 'simple' && isset($item['stock_status']))
|
176 |
+
{
|
177 |
+
if ($item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
178 |
+
$product->set_stock_status('outofstock');
|
179 |
+
else
|
180 |
+
$product->set_stock_status('instock');
|
181 |
+
}
|
182 |
+
|
183 |
+
if ($item['description'] && !\apply_filters('cegg_disable_description_sync', false))
|
184 |
+
{
|
185 |
+
if (\apply_filters('cegg_sync_full_description', false))
|
186 |
+
$product->set_description($item['description']);
|
187 |
+
elseif (!$product->get_short_description() && !\apply_filters('cegg_dont_touch_short_description', false))
|
188 |
+
$product->set_short_description($item['description']);
|
189 |
+
}
|
190 |
+
|
191 |
+
$product->set_date_modified(time());
|
192 |
+
|
193 |
+
// image
|
194 |
+
FeaturedImage::doAction($post_id, $item);
|
195 |
+
|
196 |
+
if ($product->get_type() == 'external' && \apply_filters('cegg_sync_woo_url_allowed', true))
|
197 |
+
$product->set_product_url($item['url']);
|
198 |
+
|
199 |
+
// update meta
|
200 |
+
self::setMetaSyncUniqueId($post_id, $module_id, $item['unique_id']);
|
201 |
+
|
202 |
+
return $product->save();
|
203 |
+
}
|
204 |
+
|
205 |
+
public static function wooCreateAttr(array $item, $module_id, $post_id)
|
206 |
+
{
|
207 |
+
if (empty($item['features']) || !is_array($item['features']))
|
208 |
+
return;
|
209 |
+
|
210 |
+
if (!$product = \wc_get_product($post_id))
|
211 |
+
return false;
|
212 |
+
|
213 |
+
$attributes = $product->get_attributes();
|
214 |
+
$registered_taxonomy_count = 0;
|
215 |
+
$taxonomy_count = 0;
|
216 |
+
foreach ($item['features'] as $feature)
|
217 |
+
{
|
218 |
+
$feature['name'] = \wc_clean($feature['name']);
|
219 |
+
|
220 |
+
if (!\apply_filters('cegg_disable_attributes_modification', false))
|
221 |
+
{
|
222 |
+
$prepared = self::modifyAttribute($feature['name'], $feature['value']);
|
223 |
+
$feature['name'] = $prepared['name'];
|
224 |
+
$feature['value'] = $prepared['value'];
|
225 |
+
}
|
226 |
+
|
227 |
+
$f_name = \wc_clean($feature['name']);
|
228 |
+
$f_slug = self::getSlug($f_name);
|
229 |
+
|
230 |
+
// exists?
|
231 |
+
if (isset($attributes[$f_slug]) || isset($attributes['pa_' . $f_slug]))
|
232 |
+
continue;
|
233 |
+
|
234 |
+
$f_value = \wc_sanitize_term_text_based($feature['value']);
|
235 |
+
$term_ids = array();
|
236 |
+
$taxonomy = '';
|
237 |
+
$prepared = self::isTaxonomyAttribute($f_name, $f_value, $f_slug);
|
238 |
+
if ($prepared)
|
239 |
+
{
|
240 |
+
$taxonomy_count++;
|
241 |
+
$f_name = \wc_clean($prepared['name']);
|
242 |
+
|
243 |
+
// Taxonomy Attribute
|
244 |
+
// @see: class-wc-admin-attributes.php -> process_add_attribute()
|
245 |
+
$attr_data = array(
|
246 |
+
'attribute_label' => $f_name,
|
247 |
+
'attribute_name' => $f_slug,
|
248 |
+
'attribute_type' => 'text',
|
249 |
+
);
|
250 |
+
|
251 |
+
$attr_id = self::createTaxonomyAttribute($attr_data);
|
252 |
+
|
253 |
+
if ($attr_id)
|
254 |
+
{
|
255 |
+
$taxonomy = \wc_attribute_taxonomy_name_by_id($attr_id);
|
256 |
+
|
257 |
+
// Register the taxonomy now so that the import works!
|
258 |
+
if (!\taxonomy_exists($taxonomy))
|
259 |
+
{
|
260 |
+
$taxonomy = TextHelper::truncate($taxonomy, 32, '');
|
261 |
+
\register_taxonomy(
|
262 |
+
$taxonomy, apply_filters('woocommerce_taxonomy_objects_' . $taxonomy, array('product')), apply_filters('woocommerce_taxonomy_args_' . $taxonomy, array(
|
263 |
+
'hierarchical' => true,
|
264 |
+
'show_ui' => false,
|
265 |
+
'query_var' => true,
|
266 |
+
'rewrite' => false,
|
267 |
+
))
|
268 |
+
);
|
269 |
+
$registered_taxonomy_count++;
|
270 |
+
}
|
271 |
+
|
272 |
+
$f_value_array = self::value2Array($f_value);
|
273 |
+
|
274 |
+
// Creates the term and taxonomy relationship if it doesn't already exist.
|
275 |
+
// It may be confusing but the returned array consists of term_taxonomy_ids instead of term_ids.
|
276 |
+
\wp_set_object_terms($product->get_id(), $f_value_array, $taxonomy);
|
277 |
+
|
278 |
+
$term_ids = array();
|
279 |
+
foreach ($f_value_array as $term)
|
280 |
+
{
|
281 |
+
if ($term_info = \term_exists($term, $taxonomy))
|
282 |
+
$term_ids[] = $term_info['term_id'];
|
283 |
+
}
|
284 |
+
$term_ids = array_map('intval', $term_ids);
|
285 |
+
} else
|
286 |
+
$attr_id = 0;
|
287 |
+
} else
|
288 |
+
{
|
289 |
+
// Local Attribute
|
290 |
+
$attr_id = 0;
|
291 |
+
$f_value_array = self::value2Array($f_value);
|
292 |
+
}
|
293 |
+
|
294 |
+
$attribute = new \WC_Product_Attribute();
|
295 |
+
$attribute->set_id($attr_id); // 0 for product level attributes. ID for global attributes.
|
296 |
+
if ($taxonomy)
|
297 |
+
$attribute->set_name($taxonomy);
|
298 |
+
else
|
299 |
+
$attribute->set_name($f_name);
|
300 |
+
// attribute value or array of term ids/names.
|
301 |
+
if ($term_ids)
|
302 |
+
$attribute->set_options($term_ids);
|
303 |
+
else
|
304 |
+
$attribute->set_options($f_value_array);
|
305 |
+
$attribute->set_visible(true); // If visible on frontend.
|
306 |
+
$attributes[] = $attribute;
|
307 |
+
}
|
308 |
+
|
309 |
+
$product->set_attributes($attributes);
|
310 |
+
$res = $product->save();
|
311 |
+
|
312 |
+
if ($taxonomy_count)
|
313 |
+
\flush_rewrite_rules();
|
314 |
+
return $res;
|
315 |
+
}
|
316 |
+
|
317 |
+
public static function createTaxonomyAttribute($attribute)
|
318 |
+
{
|
319 |
+
global $wpdb;
|
320 |
+
|
321 |
+
if (empty($attribute['attribute_label']))
|
322 |
+
return false;
|
323 |
+
|
324 |
+
$attribute['attribute_label'] = \wc_clean($attribute['attribute_label']);
|
325 |
+
|
326 |
+
if (empty($attribute['attribute_name']))
|
327 |
+
$attribute['attribute_name'] = \wc_sanitize_taxonomy_name($attribute['attribute_label']);
|
328 |
+
|
329 |
+
if (empty($attribute['attribute_type']))
|
330 |
+
$attribute['attribute_type'] = 'text';
|
331 |
+
|
332 |
+
if (empty($attribute['attribute_orderby']))
|
333 |
+
$attribute['attribute_orderby'] = 'menu_order';
|
334 |
+
|
335 |
+
// validate slug
|
336 |
+
if (strlen($attribute['attribute_name']) >= 28 || \wc_check_if_attribute_name_is_reserved($attribute['attribute_name']))
|
337 |
+
return false;
|
338 |
+
|
339 |
+
if (\taxonomy_exists(\wc_attribute_taxonomy_name($attribute['attribute_name'])))
|
340 |
+
return \wc_attribute_taxonomy_id_by_name($attribute['attribute_name']);
|
341 |
+
|
342 |
+
// Create the taxonomy
|
343 |
+
$insert = $wpdb->insert($wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute);
|
344 |
+
|
345 |
+
if (\is_wp_error($insert))
|
346 |
+
return false;
|
347 |
+
|
348 |
+
$id = $wpdb->insert_id;
|
349 |
+
|
350 |
+
//\do_action('woocommerce_attribute_added', $id, $attribute);
|
351 |
+
|
352 |
+
\wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules');
|
353 |
+
\delete_transient('wc_attribute_taxonomies');
|
354 |
+
|
355 |
+
return $id;
|
356 |
+
}
|
357 |
+
|
358 |
+
public static function getAttributesList()
|
359 |
+
{
|
360 |
+
if (self::$attributes_list === null)
|
361 |
+
{
|
362 |
+
$attributes_list = GeneralConfig::getInstance()->option('woocommerce_attributes_list');
|
363 |
+
$attributes_list = explode(',', $attributes_list);
|
364 |
+
$attributes_list = array_map('trim', $attributes_list);
|
365 |
+
$attributes_list = array_map('mb_strtolower', $attributes_list);
|
366 |
+
$attributes_list = array_filter($attributes_list);
|
367 |
+
self::$attributes_list = $attributes_list;
|
368 |
+
}
|
369 |
+
return self::$attributes_list;
|
370 |
+
}
|
371 |
+
|
372 |
+
public static function modifyAttribute($name, $value, $slug = '')
|
373 |
+
{
|
374 |
+
$ignore_names = array('model', 'wifi', 'version');
|
375 |
+
foreach ($ignore_names as $in)
|
376 |
+
{
|
377 |
+
if (mb_stristr($name, $in, true, 'utf-8') !== false)
|
378 |
+
return array('name' => $name, 'value' => $value);
|
379 |
+
}
|
380 |
+
|
381 |
+
/**
|
382 |
+
* Modifiers
|
383 |
+
*/
|
384 |
+
// 16 M; 8 GB; 1.5 GB; 8MP; 30 fps; 2 m; 0.5600 kg; 6,37 кг
|
385 |
+
if (preg_match('/^([0-9]*[.,]?[0-9]+)[\s+]?([\p{L}]+)$/u', $value, $matches))
|
386 |
+
{
|
387 |
+
$name = $name . ' (' . $matches[2] . ')';
|
388 |
+
$value = $matches[1];
|
389 |
+
}
|
390 |
+
return array('name' => $name, 'value' => $value);
|
391 |
+
}
|
392 |
+
|
393 |
+
public static function value2Array($value)
|
394 |
+
{
|
395 |
+
// arrays
|
396 |
+
$list = preg_split('/[,|;\/]\s/', $value);
|
397 |
+
$list = array_map('trim', $list);
|
398 |
+
$list = array_map('\wc_sanitize_term_text_based', $list);
|
399 |
+
return $list;
|
400 |
+
}
|
401 |
+
|
402 |
+
public static function isTaxonomyAttribute($name, $value, $slug = '')
|
403 |
+
{
|
404 |
+
/**
|
405 |
+
* Black / white list filter
|
406 |
+
*/
|
407 |
+
$attributes_filter = GeneralConfig::getInstance()->option('woocommerce_attributes_filter');
|
408 |
+
if ($attributes_filter)
|
409 |
+
{
|
410 |
+
if (in_array(mb_strtolower($name, 'utf-8'), self::getAttributesList()) || ($slug && in_array($slug, self::getAttributesList())))
|
411 |
+
$in_list = true;
|
412 |
+
else
|
413 |
+
$in_list = false;
|
414 |
+
|
415 |
+
if ($attributes_filter == 'whitelist' && $in_list)
|
416 |
+
return array('name' => $name, 'value' => $value);
|
417 |
+
elseif ($attributes_filter == 'blacklist' && !$in_list)
|
418 |
+
return array('name' => $name, 'value' => $value);
|
419 |
+
else
|
420 |
+
return false;
|
421 |
+
}
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Default filter
|
425 |
+
*/
|
426 |
+
// ignore names
|
427 |
+
$ignore_names = array('depth', 'height', 'weight', 'package', 'model', 'pack of', 'warranty', 'title', 'of items', 'ean', 'department', 'dimensions', 'network type');
|
428 |
+
foreach ($ignore_names as $in)
|
429 |
+
{
|
430 |
+
if (mb_stristr($name, $in, true, 'utf-8') !== false)
|
431 |
+
return false;
|
432 |
+
}
|
433 |
+
|
434 |
+
if (strstr($name, '(') && strstr($name, ')') && is_numeric($value))
|
435 |
+
{
|
436 |
+
return array('name' => $name, 'value' => $value);
|
437 |
+
}
|
438 |
+
|
439 |
+
// Yes/No/0/1
|
440 |
+
$yes_array = array('yes');
|
441 |
+
foreach ($yes_array as $yes)
|
442 |
+
{
|
443 |
+
if (mb_strtolower($value, 'utf-8') == $yes)
|
444 |
+
return array('name' => $name, 'value' => ucfirst($value));
|
445 |
+
}
|
446 |
+
$no_array = array('no', '0', '-');
|
447 |
+
foreach ($no_array as $no)
|
448 |
+
{
|
449 |
+
if (mb_strtolower($value, 'utf-8') == $no)
|
450 |
+
return false;
|
451 |
+
}
|
452 |
+
|
453 |
+
// arrays
|
454 |
+
$list = preg_split('/[,|;\/]\s/', $value);
|
455 |
+
if (count($list) > 1 && count($list) <= 5)
|
456 |
+
{
|
457 |
+
foreach ($list as $l)
|
458 |
+
{
|
459 |
+
if (mb_strlen($l, 'utf-8') > 20)
|
460 |
+
return false;
|
461 |
+
}
|
462 |
+
return array('name' => $name, 'value' => $value);
|
463 |
+
}
|
464 |
+
|
465 |
+
// short string value
|
466 |
+
if (mb_strlen($value, 'utf-8') < 20)
|
467 |
+
return array('name' => $name, 'value' => $value);
|
468 |
+
|
469 |
+
return false;
|
470 |
+
}
|
471 |
+
|
472 |
+
public static function getSlug($name)
|
473 |
+
{
|
474 |
+
// already exists?
|
475 |
+
$taxonomies = \wc_get_attribute_taxonomies();
|
476 |
+
foreach ($taxonomies as $taxonomie)
|
477 |
+
{
|
478 |
+
if ($taxonomie->attribute_label == $name)
|
479 |
+
return $taxonomie->attribute_name;
|
480 |
+
}
|
481 |
+
|
482 |
+
$slug = strtolower(TextHelper::sluggable($name));
|
483 |
+
if (strlen($slug) >= 28)
|
484 |
+
$slug = substr($slug, 0, 27);
|
485 |
+
$slug = \wc_sanitize_taxonomy_name($slug);
|
486 |
+
return $slug;
|
487 |
+
}
|
488 |
+
|
489 |
+
public static function setMetaSyncUniqueId($post_id, $module_id, $unique_id)
|
490 |
+
{
|
491 |
+
if (!$unique_id)
|
492 |
+
\delete_post_meta($post_id, self::META_WOO_SYNC_MODULE_UNIQUE_ID);
|
493 |
+
else
|
494 |
+
\update_post_meta($post_id, self::META_WOO_SYNC_MODULE_UNIQUE_ID, $module_id . '[&]' . $unique_id);
|
495 |
+
}
|
496 |
+
|
497 |
+
public static function getMetaSyncUniqueId($post_id)
|
498 |
+
{
|
499 |
+
return \get_post_meta($post_id, self::META_WOO_SYNC_MODULE_UNIQUE_ID, true);
|
500 |
+
}
|
501 |
+
|
502 |
+
public static function getSyncItem($post_id)
|
503 |
+
{
|
504 |
+
if (!$muids = self::getMetaSyncUniqueId($post_id))
|
505 |
+
return null;
|
506 |
+
|
507 |
+
$ids = explode('[&]', $muids);
|
508 |
+
if (count($ids) != 2)
|
509 |
+
return null;
|
510 |
+
|
511 |
+
$module_id = $ids[0];
|
512 |
+
$unique_id = $ids[1];
|
513 |
+
|
514 |
+
$item = ContentManager::getProductbyUniqueId($unique_id, $module_id, $post_id);
|
515 |
+
if ($item)
|
516 |
+
$item['module_id'] = $module_id;
|
517 |
+
return $item;
|
518 |
+
}
|
519 |
+
|
520 |
+
public static function echoUpdateDate()
|
521 |
+
{
|
522 |
+
global $post;
|
523 |
+
|
524 |
+
if (!$echo_update_date = GeneralConfig::getInstance()->option('woocommerce_echo_update_date'))
|
525 |
+
return;
|
526 |
+
|
527 |
+
if (\is_product() && $post->ID)
|
528 |
+
{
|
529 |
+
if (!$item = self::getSyncItem($post->ID))
|
530 |
+
return;
|
531 |
+
|
532 |
+
if ($echo_update_date == 'amazon' && ($item['module_id'] != 'Amazon' && !strstr($item['module_id'], 'AE__amazon')))
|
533 |
+
return;
|
534 |
+
|
535 |
+
if (empty($item['last_update']))
|
536 |
+
return;
|
537 |
+
|
538 |
+
|
539 |
+
$date = TemplateHelper::dateFormatFromGmt($item['last_update'], true);
|
540 |
+
|
541 |
+
echo '<span class="price_updated">' . sprintf(__('Last updated on %s', 'content-egg-tpl'), $date) . '</span>';
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
public static function echoPricePerUnit()
|
546 |
+
{
|
547 |
+
global $post;
|
548 |
+
|
549 |
+
if (!$woocommerce_echo_price_per_unit = GeneralConfig::getInstance()->option('woocommerce_echo_price_per_unit'))
|
550 |
+
return;
|
551 |
+
|
552 |
+
if (\is_product() && $post->ID)
|
553 |
+
{
|
554 |
+
if (!$item = self::getSyncItem($post->ID))
|
555 |
+
return;
|
556 |
+
|
557 |
+
if (empty($item['extra']['pricePerUnitDisplay']))
|
558 |
+
return;
|
559 |
+
|
560 |
+
echo '<div class="cegg_price_per_unit">' . sprintf(__('Price per unit: %s', 'content-egg-tpl'), $item['extra']['pricePerUnitDisplay']) . '</div>';
|
561 |
+
}
|
562 |
+
}
|
563 |
+
|
564 |
+
public static function customButtonText($default, $product)
|
565 |
+
{
|
566 |
+
if ($product->get_type() != 'external')
|
567 |
+
return $default;
|
568 |
+
|
569 |
+
if (!$item = self::getSyncItem($product->get_id()))
|
570 |
+
return $default;
|
571 |
+
|
572 |
+
return TemplateHelper::btnText('woocommerce_btn_text', $default, false, $item);
|
573 |
+
}
|
574 |
+
|
575 |
+
}
|
application/admin/AdminNotice.php
CHANGED
@@ -1,97 +1,99 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
const
|
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 |
-
if ($
|
93 |
-
$url = add_query_arg(self::
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* AdminNotice class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2016 keywordrush.com
|
13 |
+
*/
|
14 |
+
class AdminNotice {
|
15 |
+
|
16 |
+
const GET_NOTICE_PARAM = 'egg-notice';
|
17 |
+
const GET_LEVEL_PARAM = 'egg-notice-level';
|
18 |
+
const GET_ID_PARAM = 'egg-notice-id';
|
19 |
+
|
20 |
+
protected static $instance = null;
|
21 |
+
|
22 |
+
public function getMassages()
|
23 |
+
{
|
24 |
+
return array(
|
25 |
+
'autoblog_saved' => __('Task for autoblogging is saved.', 'content-egg') . ' <a href="?page=content-egg-autoblog&action=run&id=%%ID%%">' . __('Run now', 'content-egg') . '</a>',
|
26 |
+
'autoblog_create_error' => __('While saving task error was occurred.', 'content-egg'),
|
27 |
+
'autoblog_csv_file_error' => __('Error while handling file with keywords.', 'content-egg'),
|
28 |
+
'autoblog_batch_created' => __('Tasks for autoblogging are saved.', 'content-egg') . ' %%ID%%.',
|
29 |
+
'license_reset_error' => __('License can\'t be deactivated. Write to support of plugin.', 'content-egg'),
|
30 |
+
'license_reset_success' => __('License was deactivated. You must deactivate and delete plugin from current domain to enable it on another one.', 'content-egg'),
|
31 |
+
);
|
32 |
+
}
|
33 |
+
|
34 |
+
public static function getInstance()
|
35 |
+
{
|
36 |
+
if (self::$instance == null)
|
37 |
+
self::$instance = new self;
|
38 |
+
|
39 |
+
return self::$instance;
|
40 |
+
}
|
41 |
+
|
42 |
+
private function __construct()
|
43 |
+
{
|
44 |
+
//$this->adminInit();
|
45 |
+
}
|
46 |
+
|
47 |
+
public function adminInit()
|
48 |
+
{
|
49 |
+
\add_action('admin_notices', array($this, 'displayNotice'));
|
50 |
+
}
|
51 |
+
|
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 |
+
|
59 |
+
$all = $this->getMassages();
|
60 |
+
if (!array_key_exists($message_id, $all))
|
61 |
+
return '';
|
62 |
+
|
63 |
+
$message = $all[$message_id];
|
64 |
+
|
65 |
+
if (!empty($_GET[self::GET_ID_PARAM]))
|
66 |
+
{
|
67 |
+
$id = (int) $_GET[self::GET_ID_PARAM];
|
68 |
+
$message = str_replace('%%ID%%', $id, $message);
|
69 |
+
}
|
70 |
+
|
71 |
+
return $message;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function displayNotice()
|
75 |
+
{
|
76 |
+
if (empty($_GET[self::GET_NOTICE_PARAM]))
|
77 |
+
return;
|
78 |
+
|
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)
|
90 |
+
{
|
91 |
+
$url = add_query_arg(self::GET_NOTICE_PARAM, $message, $url);
|
92 |
+
if ($level)
|
93 |
+
$url = add_query_arg(self::GET_LEVEL_PARAM, $level, $url);
|
94 |
+
if ($id)
|
95 |
+
$url = add_query_arg(self::GET_ID_PARAM, $id, $url);
|
96 |
+
return $url;
|
97 |
+
}
|
98 |
+
|
99 |
+
}
|
application/admin/AeIntegrationConfig.php
CHANGED
@@ -1,75 +1,84 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\Config;
|
8 |
+
use ContentEgg\application\Plugin;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* AeIntegrationConfig class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link http://www.keywordrush.com/
|
15 |
+
* @copyright Copyright © 2016 keywordrush.com
|
16 |
+
*/
|
17 |
+
class AeIntegrationConfig extends Config {
|
18 |
+
|
19 |
+
const MIN_AE_VERSION = '7.1.0';
|
20 |
+
|
21 |
+
public function page_slug()
|
22 |
+
{
|
23 |
+
return Plugin::slug . '-ae-integration';
|
24 |
+
}
|
25 |
+
|
26 |
+
public function option_name()
|
27 |
+
{
|
28 |
+
return Plugin::slug . '_ae_integration';
|
29 |
+
}
|
30 |
+
|
31 |
+
public function add_admin_menu()
|
32 |
+
{
|
33 |
+
\add_submenu_page(Plugin::slug, __('Affiliate Egg integration', 'content-egg') . ' ‹ Content Egg', __('Affiliate Egg integration', 'content-egg'), 'manage_options', $this->page_slug(), array($this, 'settings_page'));
|
34 |
+
|
35 |
+
if (Plugin::isFree() && !Plugin::isEnvato())
|
36 |
+
{
|
37 |
+
global $submenu;
|
38 |
+
$submenu['content-egg'][] = array('<b style="color: #00C0AC;">Go PRO</b>', 'manage_options', Plugin::pluginSiteUrl());
|
39 |
+
}
|
40 |
+
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function options()
|
44 |
+
{
|
45 |
+
if (!self::isAEIntegrationPosible())
|
46 |
+
return array();
|
47 |
+
|
48 |
+
$aff_egg_modules = \Keywordrush\AffiliateEgg\ShopManager::getInstance()->getSearchableItemsList(true, false, false);
|
49 |
+
return array(
|
50 |
+
'modules' => array(
|
51 |
+
'title' => __('Activate modules', 'content-egg'),
|
52 |
+
'description' => '',
|
53 |
+
'checkbox_options' => $aff_egg_modules,
|
54 |
+
'callback' => array($this, 'render_checkbox_list'),
|
55 |
+
'default' => array(),
|
56 |
+
'section' => 'default',
|
57 |
+
),
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
public function settings_page()
|
62 |
+
{
|
63 |
+
PluginAdmin::render('ae_integration', array('page_slug' => $this->page_slug()));
|
64 |
+
}
|
65 |
+
|
66 |
+
public static function isAEIntegrationPosible()
|
67 |
+
{
|
68 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
69 |
+
|
70 |
+
if (!\is_plugin_active('affiliate-egg/affiliate-egg.php'))
|
71 |
+
return false;
|
72 |
+
|
73 |
+
if (!class_exists('\Keywordrush\AffiliateEgg\ShopManager') || !\Keywordrush\AffiliateEgg\LicConfig::getInstance()->option('license_key'))
|
74 |
+
return false;
|
75 |
+
|
76 |
+
$v = \Keywordrush\AffiliateEgg\AffiliateEgg::version();
|
77 |
+
|
78 |
+
if (version_compare(self::MIN_AE_VERSION, $v, '>'))
|
79 |
+
return false;
|
80 |
+
|
81 |
+
return true;
|
82 |
+
}
|
83 |
+
|
84 |
+
}
|
application/admin/AutoblogController.php
CHANGED
@@ -1,372 +1,374 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
*
|
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 |
-
\wp_enqueue_script('
|
68 |
-
|
69 |
-
\
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
\add_submenu_page(
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
$batch =
|
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 |
-
$item
|
136 |
-
$item['
|
137 |
-
$item['
|
138 |
-
$item['
|
139 |
-
$item['
|
140 |
-
$item['
|
141 |
-
$item['
|
142 |
-
$item['
|
143 |
-
$item['
|
144 |
-
$item['
|
145 |
-
$item['
|
146 |
-
$item['
|
147 |
-
$item['
|
148 |
-
$item['
|
149 |
-
$item['
|
150 |
-
$item['
|
151 |
-
$item['
|
152 |
-
$item['
|
153 |
-
$item['
|
154 |
-
$item['
|
155 |
-
$item['
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
$redirect_url = AdminNotice::add2Url($redirect_url, '
|
168 |
-
|
169 |
-
$redirect_url = AdminNotice::add2Url($redirect_url, '
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
$redirect_url = AdminNotice::add2Url($redirect_url, '
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
$item =
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
$item['
|
217 |
-
$item['
|
218 |
-
$item['
|
219 |
-
$item['
|
220 |
-
$item['
|
221 |
-
$item['
|
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 |
-
return
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
$new_item['name']
|
347 |
-
|
348 |
-
$new_item['
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\models\AutoblogModel;
|
9 |
+
use ContentEgg\application\helpers\TextHelper;
|
10 |
+
use ContentEgg\application\AutoblogScheduler;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* AutoblogController class file
|
14 |
+
*
|
15 |
+
* @author keywordrush.com <support@keywordrush.com>
|
16 |
+
* @link http://www.keywordrush.com/
|
17 |
+
* @copyright Copyright © 2016 keywordrush.com
|
18 |
+
*/
|
19 |
+
class AutoblogController {
|
20 |
+
|
21 |
+
const slug = 'content-egg-autoblog';
|
22 |
+
|
23 |
+
private $amazon_categs = array(
|
24 |
+
'appliances' => 'Appliances',
|
25 |
+
'mobile-apps' => 'Appstore for Android',
|
26 |
+
'arts-crafts' => 'Arts, Crafts & Sewing',
|
27 |
+
'automotive' => 'Automotive',
|
28 |
+
'baby-products' => 'Baby',
|
29 |
+
'beauty' => 'Beauty',
|
30 |
+
'books' => 'Books',
|
31 |
+
'photo' => 'Camera & Photo',
|
32 |
+
'wireless' => 'Cell Phones & Accessories',
|
33 |
+
'apparel' => 'Clothing',
|
34 |
+
'pc' => 'Computers & Accessories',
|
35 |
+
'electronics' => 'Electronics',
|
36 |
+
'gift-cards' => 'Gift Cards Store',
|
37 |
+
'grocery' => 'Grocery & Gourmet Food',
|
38 |
+
'hpc' => 'Health & Personal Care',
|
39 |
+
'home-garden' => 'Home & Kitchen',
|
40 |
+
'hi' => 'Home Improvement',
|
41 |
+
'industrial' => 'Industrial & Scientific',
|
42 |
+
'jewelry' => 'Jewelry',
|
43 |
+
'digital-text' => 'Kindle Store',
|
44 |
+
'kitchen' => 'Kitchen & Dining',
|
45 |
+
'dmusic' => 'MP3 Downloads',
|
46 |
+
'magazines' => 'Magazines',
|
47 |
+
'movies-tv' => 'Movies & TV',
|
48 |
+
'music' => 'Music',
|
49 |
+
'musical-instruments' => 'Musical Instruments',
|
50 |
+
'office-products' => 'Office Products',
|
51 |
+
'lawn-garden' => 'Patio, Lawn & Garden',
|
52 |
+
'pet-supplies' => 'Pet Supplies',
|
53 |
+
'shoes' => 'Shoes',
|
54 |
+
'software' => 'Software',
|
55 |
+
'sporting-goods' => 'Sports & Outdoors',
|
56 |
+
'toys-and-games' => 'Toys & Games',
|
57 |
+
'videogames' => 'Video Games',
|
58 |
+
'watches' => 'Watches',
|
59 |
+
);
|
60 |
+
|
61 |
+
public function __construct()
|
62 |
+
{
|
63 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
64 |
+
|
65 |
+
if ($GLOBALS['pagenow'] == 'admin.php' && !empty($_GET['page']) && $_GET['page'] == 'content-egg-autoblog-edit')
|
66 |
+
{
|
67 |
+
\wp_enqueue_script('contentegg-keywords', \ContentEgg\PLUGIN_RES . '/js/keywords.js', array('jquery'), '1asa' . Plugin::version());
|
68 |
+
// tabs
|
69 |
+
\wp_enqueue_script('jquery-ui-tabs');
|
70 |
+
\wp_enqueue_script('jquery-ui-button');
|
71 |
+
\wp_enqueue_style('contentegg-admin-ui-css', \ContentEgg\PLUGIN_RES . '/css/jquery-ui.min.css', false, Plugin::version());
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
public function add_admin_menu()
|
76 |
+
{
|
77 |
+
\add_submenu_page(Plugin::slug, __('Autoblogging', 'content-egg') . ' ‹ Content Egg', __('Autoblogging', 'content-egg'), 'manage_options', self::slug, array($this, 'actionIndex'));
|
78 |
+
\add_submenu_page(Plugin::slug, __('Add autoblogging', 'content-egg') . ' ‹ Content Egg', __('Add autoblogging', 'content-egg'), 'manage_options', 'content-egg-autoblog-edit', array($this, 'actionUpdate'));
|
79 |
+
\add_submenu_page('options.php', __('Add autoblogging - bulk mode', 'content-egg') . ' ‹ Content Egg', __('Add autoblogging - bulk mode', 'content-egg'), 'manage_options', 'content-egg-autoblog-edit--batch', array($this, 'actionUpdate'));
|
80 |
+
}
|
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']);
|
88 |
+
}
|
89 |
+
\wp_enqueue_script('content-egg-blockUI', \ContentEgg\PLUGIN_RES . '/js/jquery.blockUI.js', array('jquery'));
|
90 |
+
$table = new AutoblogTable(AutoblogModel::model());
|
91 |
+
$table->prepare_items();
|
92 |
+
PluginAdmin::getInstance()->render('autoblog_index', array('table' => $table));
|
93 |
+
}
|
94 |
+
|
95 |
+
public function actionUpdate()
|
96 |
+
{
|
97 |
+
if ($GLOBALS['pagenow'] == 'admin.php' && !empty($_GET['page']) && $_GET['page'] == 'content-egg-autoblog-edit--batch')
|
98 |
+
$batch = true;
|
99 |
+
else
|
100 |
+
$batch = false;
|
101 |
+
|
102 |
+
$_POST = array_map('stripslashes_deep', $_POST);
|
103 |
+
|
104 |
+
$default = array(
|
105 |
+
'id' => 0,
|
106 |
+
'name' => '',
|
107 |
+
'status' => 1,
|
108 |
+
'run_frequency' => 86400,
|
109 |
+
'keywords_per_run' => 1,
|
110 |
+
'post_status' => 1,
|
111 |
+
'user_id' => \get_current_user_id(),
|
112 |
+
'template_body' => '',
|
113 |
+
'template_title' => '%KEYWORD%',
|
114 |
+
'keywords' => array(),
|
115 |
+
'category' => \get_option('default_category'),
|
116 |
+
'include_modules' => array(),
|
117 |
+
'exclude_modules' => array(),
|
118 |
+
'required_modules' => array(),
|
119 |
+
'autoupdate_modules' => array(),
|
120 |
+
'min_modules_count' => 1,
|
121 |
+
'post_type' => 'post',
|
122 |
+
'custom_field_names' => array_fill(0, 8, ''),
|
123 |
+
'custom_field_values' => array_fill(0, 8, ''),
|
124 |
+
'main_product' => 'min_price',
|
125 |
+
'tags' => '',
|
126 |
+
'condition' => '',
|
127 |
+
'config' => array('dynamic_categories' => 0, 'min_comments_count' => 0),
|
128 |
+
);
|
129 |
+
|
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 |
+
$item['id'] = (int) $_POST['item']['id'];
|
137 |
+
$item['name'] = trim(strip_tags($_POST['item']['name']));
|
138 |
+
$item['status'] = absint($_POST['item']['status']);
|
139 |
+
$item['keywords_per_run'] = absint($_POST['item']['keywords_per_run']);
|
140 |
+
$item['run_frequency'] = absint($_POST['item']['run_frequency']);
|
141 |
+
$item['post_status'] = absint($_POST['item']['post_status']);
|
142 |
+
$item['user_id'] = absint($_POST['item']['user_id']);
|
143 |
+
$item['template_body'] = trim(\wp_kses_post($_POST['item']['template_body']));
|
144 |
+
$item['template_title'] = trim(\wp_strip_all_tags($_POST['item']['template_title']));
|
145 |
+
$item['post_type'] = (isset($_POST['item']['post_type'])) ? $_POST['item']['post_type'] : null;
|
146 |
+
$item['category'] = (isset($_POST['item']['category'])) ? (int) $_POST['item']['category'] : null;
|
147 |
+
$item['include_modules'] = (isset($_POST['item']['include_modules'])) ? $_POST['item']['include_modules'] : array();
|
148 |
+
$item['exclude_modules'] = (isset($_POST['item']['exclude_modules'])) ? $_POST['item']['exclude_modules'] : array();
|
149 |
+
$item['required_modules'] = (isset($_POST['item']['required_modules'])) ? $_POST['item']['required_modules'] : array();
|
150 |
+
$item['autoupdate_modules'] = (isset($_POST['item']['autoupdate_modules'])) ? $_POST['item']['autoupdate_modules'] : array();
|
151 |
+
$item['min_modules_count'] = absint($_POST['item']['min_modules_count']);
|
152 |
+
$item['keywords'] = (isset($_POST['item']['keywords'])) ? explode("\r\n", $_POST['item']['keywords']) : null;
|
153 |
+
$item['custom_field_names'] = (isset($_POST['item']['custom_field_names'])) ? $_POST['item']['custom_field_names'] : array();
|
154 |
+
$item['custom_field_values'] = (isset($_POST['item']['custom_field_values'])) ? $_POST['item']['custom_field_values'] : array();
|
155 |
+
$item['main_product'] = (isset($_POST['item']['main_product'])) ? $_POST['item']['main_product'] : 'min_price';
|
156 |
+
$item['tags'] = (isset($_POST['item']['tags'])) ? TextHelper::commaList($_POST['item']['tags']) : '';
|
157 |
+
$item['config'] = $_POST['item']['config'];
|
158 |
+
|
159 |
+
if (isset($_POST['item']['product_condition']))
|
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)
|
164 |
+
{
|
165 |
+
$created_count = $this->createBatchAutoblog($item);
|
166 |
+
if ($created_count === false)
|
167 |
+
$redirect_url = AdminNotice::add2Url($redirect_url, 'autoblog_csv_file_error', 'error');
|
168 |
+
elseif (!$created_count)
|
169 |
+
$redirect_url = AdminNotice::add2Url($redirect_url, 'autoblog_create_error', 'error');
|
170 |
+
else
|
171 |
+
$redirect_url = AdminNotice::add2Url($redirect_url, 'autoblog_batch_created', 'success', $created_count);
|
172 |
+
} else
|
173 |
+
{
|
174 |
+
// single create mode
|
175 |
+
$item['id'] = $this->createAutoblog($item);
|
176 |
+
|
177 |
+
if ($item['id'])
|
178 |
+
$redirect_url = AdminNotice::add2Url($redirect_url, 'autoblog_saved', 'success', $item['id']);
|
179 |
+
else
|
180 |
+
$redirect_url = AdminNotice::add2Url($redirect_url, 'autoblog_create_error', 'error');
|
181 |
+
}
|
182 |
+
|
183 |
+
// redirect to table list
|
184 |
+
\wp_redirect($redirect_url);
|
185 |
+
exit;
|
186 |
+
} else
|
187 |
+
{
|
188 |
+
// view page
|
189 |
+
if (isset($_GET['dublicate_id']))
|
190 |
+
{
|
191 |
+
$dublicate = AutoblogModel::model()->findByPk((int) $_GET['dublicate_id']);
|
192 |
+
if ($dublicate)
|
193 |
+
{
|
194 |
+
foreach ($default as $key => $val)
|
195 |
+
{
|
196 |
+
if (!isset($dublicate))
|
197 |
+
continue;
|
198 |
+
$item[$key] = $dublicate[$key];
|
199 |
+
if (is_array($val))
|
200 |
+
$item[$key] = unserialize($item[$key]);
|
201 |
+
}
|
202 |
+
$item['id'] = null;
|
203 |
+
} else
|
204 |
+
$item = $default;
|
205 |
+
} else
|
206 |
+
$item = $default;
|
207 |
+
if (isset($_GET['id']))
|
208 |
+
{
|
209 |
+
$item = AutoblogModel::model()->findByPk((int) $_GET['id']);
|
210 |
+
if (!$item)
|
211 |
+
{
|
212 |
+
$item = $default;
|
213 |
+
$notice = __('Autoblogging is not found', 'content-egg');
|
214 |
+
} else
|
215 |
+
{
|
216 |
+
$item['keywords'] = unserialize($item['keywords']);
|
217 |
+
$item['include_modules'] = unserialize($item['include_modules']);
|
218 |
+
$item['exclude_modules'] = unserialize($item['exclude_modules']);
|
219 |
+
$item['required_modules'] = unserialize($item['required_modules']);
|
220 |
+
$item['autoupdate_modules'] = unserialize($item['autoupdate_modules']);
|
221 |
+
$item['custom_field_names'] = unserialize($item['custom_field_names']);
|
222 |
+
$item['custom_field_values'] = unserialize($item['custom_field_values']);
|
223 |
+
$item['config'] = unserialize($item['config']);
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
$item['keywords'] = join("\n", $item['keywords']);
|
228 |
+
|
229 |
+
\add_meta_box('autoblog_metabox', 'Autoblog data', array($this, 'metaboxAutoblogCreateHandler'), 'autoblog_create', 'normal', 'default');
|
230 |
+
|
231 |
+
$item['amazon_categs'] = $this->amazon_categs;
|
232 |
+
|
233 |
+
PluginAdmin::getInstance()->render('autoblog_edit', array(
|
234 |
+
'item' => $item,
|
235 |
+
'notice' => $notice,
|
236 |
+
'message' => $message,
|
237 |
+
'nonce' => \wp_create_nonce(basename(__FILE__)),
|
238 |
+
'batch' => $batch
|
239 |
+
));
|
240 |
+
}
|
241 |
+
|
242 |
+
private function createAutoblog($item)
|
243 |
+
{
|
244 |
+
$item['keywords'] = TextHelper::prepareKeywords($item['keywords']);
|
245 |
+
|
246 |
+
// save
|
247 |
+
$item['id'] = AutoblogModel::model()->save($item);
|
248 |
+
|
249 |
+
// add sheduler
|
250 |
+
if ($item['status'])
|
251 |
+
{
|
252 |
+
AutoblogScheduler::addScheduleEvent('hourly', time() + 900);
|
253 |
+
}
|
254 |
+
|
255 |
+
return $item['id'];
|
256 |
+
}
|
257 |
+
|
258 |
+
private function createBatchAutoblog($item)
|
259 |
+
{
|
260 |
+
@set_time_limit(180);
|
261 |
+
|
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 |
+
|
277 |
+
$handle = fopen($file_path, "r");
|
278 |
+
if (!$handle)
|
279 |
+
return false;
|
280 |
+
|
281 |
+
$separator = ';';
|
282 |
+
|
283 |
+
$i = 0;
|
284 |
+
$keywords = array();
|
285 |
+
$category_keywords = array();
|
286 |
+
while (($data = fgetcsv($handle, 1000, $separator)) !== false)
|
287 |
+
{
|
288 |
+
$num = count($data);
|
289 |
+
|
290 |
+
// first line
|
291 |
+
if ($i == 0)
|
292 |
+
{
|
293 |
+
// remove UTF-8 BOM
|
294 |
+
if (substr($data[0], 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf))
|
295 |
+
$data[0] = substr($data[0], 3);
|
296 |
+
|
297 |
+
// only keywords list
|
298 |
+
if ($num == 1 && $item['category'] == -1)
|
299 |
+
{
|
300 |
+
$item['category'] = \get_option('default_category');
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
$data[0] = trim($data[0]);
|
305 |
+
if (!$data[0])
|
306 |
+
continue;
|
307 |
+
|
308 |
+
if ($num == 1)
|
309 |
+
$keywords[] = trim($data[0]);
|
310 |
+
elseif ($num >= 2)
|
311 |
+
$category_keywords[trim($data[0])][] = trim($data[1]);
|
312 |
+
$i++;
|
313 |
+
}
|
314 |
+
fclose($handle);
|
315 |
+
|
316 |
+
// create
|
317 |
+
if ($keywords)
|
318 |
+
{
|
319 |
+
$item['keywords'] = $keywords;
|
320 |
+
$id = $this->createAutoblog($item);
|
321 |
+
if ($id)
|
322 |
+
return 1; //1 count
|
323 |
+
else
|
324 |
+
return false;
|
325 |
+
}
|
326 |
+
|
327 |
+
// create by categ
|
328 |
+
$created_count = 0;
|
329 |
+
if ($category_keywords)
|
330 |
+
{
|
331 |
+
foreach ($category_keywords as $c_name => $keywords)
|
332 |
+
{
|
333 |
+
$c_name = \sanitize_text_field($c_name);
|
334 |
+
$new_item = $item;
|
335 |
+
|
336 |
+
// need create category
|
337 |
+
if ($item['category'] == -1)
|
338 |
+
{
|
339 |
+
// If the category already exists, it is not duplicated.The ID of the original existing category is returned without error.
|
340 |
+
$c_id = \wp_create_category($c_name);
|
341 |
+
if (!$c_id)
|
342 |
+
continue;
|
343 |
+
|
344 |
+
$new_item['category'] = $c_id;
|
345 |
+
}
|
346 |
+
if ($new_item['name'])
|
347 |
+
$new_item['name'] .= ' - ';
|
348 |
+
$new_item['name'] .= $c_name;
|
349 |
+
|
350 |
+
$new_item['keywords'] = $keywords;
|
351 |
+
$a_id = $this->createAutoblog($new_item);
|
352 |
+
if ($a_id)
|
353 |
+
$created_count++;
|
354 |
+
}
|
355 |
+
}
|
356 |
+
return $created_count;
|
357 |
+
}
|
358 |
+
|
359 |
+
/**
|
360 |
+
* This function renders our custom meta box
|
361 |
+
*/
|
362 |
+
public function metaboxAutoblogCreateHandler($item)
|
363 |
+
{
|
364 |
+
if (!isset($item['batch']))
|
365 |
+
$batch = false;
|
366 |
+
else
|
367 |
+
{
|
368 |
+
$batch = (bool) $item['batch'];
|
369 |
+
unset($item['batch']);
|
370 |
+
}
|
371 |
+
PluginAdmin::getInstance()->render('_metabox_autoblog', array('item' => $item, 'batch' => $batch));
|
372 |
+
}
|
373 |
+
|
374 |
+
}
|
application/admin/AutoblogTable.php
CHANGED
@@ -1,98 +1,100 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
*
|
11 |
-
*
|
12 |
-
* @
|
13 |
-
|
14 |
-
|
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 |
-
return '<span style="color:
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\models\AutoblogModel;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* AutoblogTable class file
|
11 |
+
*
|
12 |
+
* @author keywordrush.com <support@keywordrush.com>
|
13 |
+
* @link http://www.keywordrush.com/
|
14 |
+
* @copyright Copyright © 2015 keywordrush.com
|
15 |
+
*/
|
16 |
+
class AutoblogTable extends MyListTable {
|
17 |
+
|
18 |
+
const per_page = 15;
|
19 |
+
|
20 |
+
function get_columns()
|
21 |
+
{
|
22 |
+
$columns = array_merge(
|
23 |
+
array(
|
24 |
+
'cb' => '<input type="checkbox" />',
|
25 |
+
), array(
|
26 |
+
'name' => AutoblogModel::model()->getAttributeLabel('name'),
|
27 |
+
'create_date' => AutoblogModel::model()->getAttributeLabel('create_date'),
|
28 |
+
'last_run' => AutoblogModel::model()->getAttributeLabel('last_run'),
|
29 |
+
'status' => AutoblogModel::model()->getAttributeLabel('status'),
|
30 |
+
'keywords' => AutoblogModel::model()->getAttributeLabel('keywords'),
|
31 |
+
'post_count' => AutoblogModel::model()->getAttributeLabel('post_count'),
|
32 |
+
'last_error' => AutoblogModel::model()->getAttributeLabel('last_error'),
|
33 |
+
)
|
34 |
+
);
|
35 |
+
return $columns;
|
36 |
+
}
|
37 |
+
|
38 |
+
/*
|
39 |
+
function default_orderby()
|
40 |
+
{
|
41 |
+
return 'status';
|
42 |
+
}
|
43 |
+
*
|
44 |
+
*/
|
45 |
+
|
46 |
+
function column_name($item)
|
47 |
+
{
|
48 |
+
if (!trim($item['name']))
|
49 |
+
$item['name'] = __('(no title)', 'content-egg');
|
50 |
+
|
51 |
+
$edit_url = '?page=content-egg-autoblog-edit&id=%d';
|
52 |
+
$dublicate_url = '?page=content-egg-autoblog-edit&dublicate_id=%d';
|
53 |
+
|
54 |
+
$actions = array(
|
55 |
+
'edit' => sprintf('<a href="' . $edit_url . '">%s</a>', $item['id'], __('Edit', 'content-egg')),
|
56 |
+
'run' => sprintf('<a class="run_avtoblogging" href="?page=content-egg-autoblog&action=run&id=%d">%s</a>', $item['id'], __('Run now', 'content-egg')),
|
57 |
+
'dublicate' => sprintf('<a href="' . $dublicate_url . '">%s</a>', $item['id'], __('Duplicate ', 'content-egg')),
|
58 |
+
'delete' => sprintf('<a class="content-egg-delete" href="?page=content-egg-autoblog&action=delete&id=%d">%s</a>', $item['id'], __('Delete', 'content-egg')),
|
59 |
+
);
|
60 |
+
$row_text = sprintf('<strong><a title="' . __('Edit', 'content-egg') . '" class="row-title" href="' . $edit_url . '">' . esc_html($item['name']) . '</a></strong>', $item['id']);
|
61 |
+
return sprintf('%s %s', $row_text, $this->row_actions($actions));
|
62 |
+
}
|
63 |
+
|
64 |
+
function column_status($item)
|
65 |
+
{
|
66 |
+
if ($item['status'])
|
67 |
+
return '<span style="color:green">' . __('Works', 'content-egg') . '</span>';
|
68 |
+
else
|
69 |
+
return '<span style="color:red">' . __('Stoped', 'content-egg') . '</span>';
|
70 |
+
}
|
71 |
+
|
72 |
+
function column_keywords($item)
|
73 |
+
{
|
74 |
+
$item['keywords'] = unserialize($item['keywords']);
|
75 |
+
|
76 |
+
$active = 0;
|
77 |
+
foreach ($item['keywords'] as $keyword)
|
78 |
+
{
|
79 |
+
if (AutoblogModel::isActiveKeyword($keyword))
|
80 |
+
$active++;
|
81 |
+
}
|
82 |
+
|
83 |
+
$abbr_title = __('active:', 'content-egg') . ' ' . $active . ', ' . __('total:', 'content-egg') . ' ' . count($item['keywords']);
|
84 |
+
return '<abbr title="' . esc_attr($abbr_title) . '">' . $active . ' / ' . count($item['keywords']) . '</abbr>';
|
85 |
+
}
|
86 |
+
|
87 |
+
function get_sortable_columns()
|
88 |
+
{
|
89 |
+
$sortable_columns = array(
|
90 |
+
'id' => array('id', true),
|
91 |
+
'name' => array('name', true),
|
92 |
+
'create_date' => array('create_date', true),
|
93 |
+
'last_run' => array('last_run', true),
|
94 |
+
'status' => array('status', true),
|
95 |
+
'post_count' => array('post_count', true)
|
96 |
+
);
|
97 |
+
return $sortable_columns;
|
98 |
+
}
|
99 |
+
|
100 |
+
}
|
application/admin/EggMetabox.php
CHANGED
@@ -1,313 +1,315 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\components\
|
11 |
-
use ContentEgg\application\components\
|
12 |
-
use ContentEgg\application\
|
13 |
-
|
14 |
-
|
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 |
-
$title .= '
|
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 |
-
if (!empty($post_meta[$key]['
|
117 |
-
$post_meta[$key]['
|
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 |
-
\wp_enqueue_script('angular-
|
189 |
-
|
190 |
-
\wp_enqueue_script('
|
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 |
-
$stripslashes =
|
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 |
-
$last_iteration =
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
if ($key == '
|
307 |
-
$data[$i][$key] = (
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
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;
|
12 |
+
use ContentEgg\application\components\ContentCoupon;
|
13 |
+
use ContentEgg\application\components\ExtraData;
|
14 |
+
use ContentEgg\application\Plugin;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* EggMetabox class file
|
18 |
+
*
|
19 |
+
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link http://www.keywordrush.com/
|
21 |
+
* @copyright Copyright © 2016 keywordrush.com
|
22 |
+
*/
|
23 |
+
class EggMetabox {
|
24 |
+
|
25 |
+
private $app_params = array();
|
26 |
+
|
27 |
+
public function __construct()
|
28 |
+
{
|
29 |
+
\add_action('add_meta_boxes', array($this, 'addMetabox'));
|
30 |
+
\add_action('save_post', array($this, 'saveMeta'));
|
31 |
+
}
|
32 |
+
|
33 |
+
private function addAppParam($param, $value)
|
34 |
+
{
|
35 |
+
$this->app_params[$param] = $value;
|
36 |
+
}
|
37 |
+
|
38 |
+
private function getAppParams()
|
39 |
+
{
|
40 |
+
return $this->app_params;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function addMetabox($post_type)
|
44 |
+
{
|
45 |
+
if (!in_array($post_type, GeneralConfig::getInstance()->option('post_types')))
|
46 |
+
return;
|
47 |
+
|
48 |
+
if (!ModuleManager::getInstance()->getModules(true))
|
49 |
+
{
|
50 |
+
\add_meta_box('content_meta_box', 'Content Egg', array($this, 'renderBlankMetabox'), $post_type, 'normal', 'high');
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
$this->modulesOptionsInit();
|
54 |
+
$this->metadataInit();
|
55 |
+
$title = 'Content Egg';
|
56 |
+
if (Plugin::isFree())
|
57 |
+
$title .= ' <a target="_blank" href="' . Plugin::pluginSiteUrl() . '">' . __('Upgrade to PRO Version', 'content-egg') . '</a>';
|
58 |
+
else
|
59 |
+
$title .= ' Pro';
|
60 |
+
|
61 |
+
$title .= ' <a target="_blank" href="' . Plugin::pluginDocsUrl() . '">' . __('user guide', 'content-egg') . '</a>';
|
62 |
+
|
63 |
+
|
64 |
+
\add_meta_box('content_meta_box', $title, array($this, 'renderMetabox'), $post_type, 'normal', 'high');
|
65 |
+
$this->angularInit();
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Render Meta Box content.
|
70 |
+
*
|
71 |
+
* @param WP_Post $post The post object.
|
72 |
+
*/
|
73 |
+
public function renderMetabox($post)
|
74 |
+
{
|
75 |
+
echo '<div ng-app="contentEgg" class="egg-container" id="content-egg" ng-cloak>';
|
76 |
+
echo '<div ng-controller="ContentEggController" class="container-fluid">';
|
77 |
+
|
78 |
+
PluginAdmin::render('metabox_general');
|
79 |
+
|
80 |
+
foreach (ModuleManager::getInstance()->getModules(true) as $module)
|
81 |
+
{
|
82 |
+
$module->enqueueScripts();
|
83 |
+
$module->renderMetaboxModule();
|
84 |
+
}
|
85 |
+
echo '</div>';
|
86 |
+
echo '</div>';
|
87 |
+
}
|
88 |
+
|
89 |
+
public function renderBlankMetabox($post)
|
90 |
+
{
|
91 |
+
_e('Configure and activate modules of Content Egg plugin', 'content-egg');
|
92 |
+
}
|
93 |
+
|
94 |
+
private function metadataInit()
|
95 |
+
{
|
96 |
+
global $post;
|
97 |
+
|
98 |
+
$modules = ModuleManager::getInstance()->getModules(true);
|
99 |
+
|
100 |
+
// modules data
|
101 |
+
$init_data = array();
|
102 |
+
$init_productGroups = array();
|
103 |
+
foreach ($modules as $module)
|
104 |
+
{
|
105 |
+
$post_meta = ContentManager::getData($post->ID, $module->getId());
|
106 |
+
|
107 |
+
if (!$post_meta)
|
108 |
+
continue;
|
109 |
+
foreach ($post_meta as $key => $meta)
|
110 |
+
{
|
111 |
+
if (!empty($meta['description']) && !TextHelper::isHtmlTagDetected($meta['description']))
|
112 |
+
$post_meta[$key]['description'] = TextHelper::br2nl($meta['description']);
|
113 |
+
|
114 |
+
if ($module->getId() == 'Coupon')
|
115 |
+
{
|
116 |
+
if (!empty($post_meta[$key]['startDate']))
|
117 |
+
$post_meta[$key]['startDate'] *= 1000;
|
118 |
+
if (!empty($post_meta[$key]['endDate']))
|
119 |
+
$post_meta[$key]['endDate'] *= 1000;
|
120 |
+
}
|
121 |
+
if (!empty($meta['group']) && !in_array($meta['group'], $init_productGroups))
|
122 |
+
$init_productGroups[] = $meta['group'];
|
123 |
+
}
|
124 |
+
$init_data[$module->getId()] = array_values($post_meta);
|
125 |
+
}
|
126 |
+
$this->addAppParam('initData', $init_data);
|
127 |
+
$this->addAppParam('initProductGroups', $init_productGroups);
|
128 |
+
|
129 |
+
// keywords
|
130 |
+
$init_keywords = array();
|
131 |
+
$init_updateParams = array();
|
132 |
+
foreach ($modules as $module)
|
133 |
+
{
|
134 |
+
if (!$module->isAffiliateParser())
|
135 |
+
continue;
|
136 |
+
$keywords_meta = \get_post_meta($post->ID, ContentManager::META_PREFIX_KEYWORD . $module->getId(), true);
|
137 |
+
if (!$keywords_meta)
|
138 |
+
continue;
|
139 |
+
$init_keywords[$module->getId()] = $keywords_meta;
|
140 |
+
|
141 |
+
$update_params_meta = \get_post_meta($post->ID, ContentManager::META_PREFIX_UPDATE_PARAMS . $module->getId(), true);
|
142 |
+
if (!$update_params_meta)
|
143 |
+
continue;
|
144 |
+
$init_updateParams[$module->getId()] = $update_params_meta;
|
145 |
+
}
|
146 |
+
$this->addAppParam('initKeywords', $init_keywords);
|
147 |
+
$this->addAppParam('initUpdateParams', $init_updateParams);
|
148 |
+
|
149 |
+
// blank content model
|
150 |
+
$content = new ContentProduct;
|
151 |
+
$content->extra = new ExtraData;
|
152 |
+
$this->addAppParam('contentProduct', $content);
|
153 |
+
|
154 |
+
// blank Coupon
|
155 |
+
$coupon = new ContentCoupon;
|
156 |
+
//$content->extra = new ExtraDataC;
|
157 |
+
$this->addAppParam('contentCoupon', $coupon);
|
158 |
+
}
|
159 |
+
|
160 |
+
private function modulesOptionsInit()
|
161 |
+
{
|
162 |
+
$init_options = array();
|
163 |
+
foreach (ModuleManager::getInstance()->getModules(true) as $module)
|
164 |
+
{
|
165 |
+
$init_options[$module->getId()] = array();
|
166 |
+
foreach ($module->getConfigInstance()->options() as $option_name => $option)
|
167 |
+
{
|
168 |
+
if (isset($option['metaboxInit']) && $option['metaboxInit'])
|
169 |
+
{
|
170 |
+
$init_options[$module->getId()][$option_name] = $module->config($option_name);
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
$this->addAppParam('modulesOptions', $init_options);
|
175 |
+
}
|
176 |
+
|
177 |
+
private function angularInit()
|
178 |
+
{
|
179 |
+
// Justified gallery jquery plugin
|
180 |
+
\wp_enqueue_script('justified-gallery', \ContentEgg\PLUGIN_RES . '/justified_gallery/jquery.justifiedGallery.min.js', array('jquery'), Plugin::version);
|
181 |
+
\wp_enqueue_style('justified-gallery', \ContentEgg\PLUGIN_RES . '/justified_gallery/justifiedGallery.min.css');
|
182 |
+
|
183 |
+
// Angular core
|
184 |
+
\wp_enqueue_script('angularjs', \ContentEgg\PLUGIN_RES . '/app/vendor/angular.min.js', array('jquery'), null);
|
185 |
+
|
186 |
+
// ContentEgg angular application
|
187 |
+
\wp_enqueue_style('contentegg-admin', \ContentEgg\PLUGIN_RES . '/css/admin.css');
|
188 |
+
\wp_enqueue_script('angular-ui-bootstrap', \ContentEgg\PLUGIN_RES . '/app/vendor/angular-ui-bootstrap/ui-bootstrap-tpls-2.5.0.min.js', array('angularjs'), Plugin::version);
|
189 |
+
|
190 |
+
\wp_enqueue_script('angular-sortable', \ContentEgg\PLUGIN_RES . '/app/vendor/angular-sortable.js', array('angularjs', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-sortable'), Plugin::version);
|
191 |
+
\wp_register_script('contentegg-metabox-app', \ContentEgg\PLUGIN_RES . '/app/app.js', array('angularjs'), Plugin::version);
|
192 |
+
\wp_enqueue_script('contentegg-metabox-service', \ContentEgg\PLUGIN_RES . '/app/ModuleService.js', array('contentegg-metabox-app'), Plugin::version);
|
193 |
+
|
194 |
+
// Bootstrap
|
195 |
+
\wp_enqueue_style('egg-bootstrap', \ContentEgg\PLUGIN_RES . '/bootstrap/css/egg-bootstrap.css');
|
196 |
+
\wp_enqueue_script('bootstrap', \ContentEgg\PLUGIN_RES . '/bootstrap/js/bootstrap.min.js', array('jquery'), Plugin::version);
|
197 |
+
|
198 |
+
// ContentEgg application params
|
199 |
+
$this->addAppParam('active_modules', ModuleManager::getInstance()->getModulesIdList(true));
|
200 |
+
$this->addAppParam('nonce', \wp_create_nonce('contentegg-metabox'));
|
201 |
+
|
202 |
+
\wp_localize_script('contentegg-metabox-app', 'contentegg_params', $this->getAppParams());
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Save the meta when the post is saved.
|
207 |
+
*
|
208 |
+
* @param int $post_id The ID of the post being saved.
|
209 |
+
*/
|
210 |
+
public function saveMeta($post_id)
|
211 |
+
{
|
212 |
+
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|
213 |
+
return;
|
214 |
+
|
215 |
+
if (!isset($_POST['contentegg_nonce']))
|
216 |
+
return;
|
217 |
+
|
218 |
+
/*
|
219 |
+
* why shouldn't i save metadata when its a revision?
|
220 |
+
*
|
221 |
+
* Apparently *_post_meta functions will automatically change
|
222 |
+
* to parent post id if passed revision post id. So you might modify original post,
|
223 |
+
* thinking you are modifying revision.
|
224 |
+
*
|
225 |
+
if (\wp_is_post_revision($post_id))
|
226 |
+
return;
|
227 |
+
*
|
228 |
+
*/
|
229 |
+
|
230 |
+
\check_admin_referer('contentegg_metabox', 'contentegg_nonce');
|
231 |
+
|
232 |
+
// Check the user's permissions.
|
233 |
+
if ($_POST['post_type'] == 'page')
|
234 |
+
{
|
235 |
+
if (!current_user_can('edit_page', $post_id))
|
236 |
+
return;
|
237 |
+
} else
|
238 |
+
{
|
239 |
+
if (!current_user_can('edit_post', $post_id))
|
240 |
+
return;
|
241 |
+
}
|
242 |
+
|
243 |
+
// need stripslashes? wp bug with revision post type?
|
244 |
+
if (\wp_is_post_revision($post_id))
|
245 |
+
$stripslashes = false;
|
246 |
+
else
|
247 |
+
$stripslashes = true;
|
248 |
+
|
249 |
+
// keywords for automatic updates
|
250 |
+
$keywords = InputHelper::post('cegg_updateKeywords', array(), $stripslashes);
|
251 |
+
$update_params = InputHelper::post('cegg_updateParams', array(), $stripslashes);
|
252 |
+
foreach ($keywords as $module_id => $keyword)
|
253 |
+
{
|
254 |
+
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
255 |
+
continue;
|
256 |
+
|
257 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
258 |
+
if (!$module->isAffiliateParser())
|
259 |
+
continue;
|
260 |
+
|
261 |
+
$keyword = \sanitize_text_field($keyword);
|
262 |
+
if ($keyword)
|
263 |
+
{
|
264 |
+
\update_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, $keyword);
|
265 |
+
if (isset($update_params[$module_id]))
|
266 |
+
{
|
267 |
+
\update_post_meta($post_id, ContentManager::META_PREFIX_UPDATE_PARAMS . $module_id, json_decode($update_params[$module_id], true));
|
268 |
+
}
|
269 |
+
} else
|
270 |
+
{
|
271 |
+
\delete_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module_id);
|
272 |
+
\delete_post_meta($post_id, ContentManager::META_PREFIX_UPDATE_PARAMS . $module_id);
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
// save content data
|
277 |
+
$content = InputHelper::post('cegg_data', array(), $stripslashes);
|
278 |
+
if (!is_array($content))
|
279 |
+
return;
|
280 |
+
|
281 |
+
$i = 0;
|
282 |
+
foreach ($content as $module_id => $data)
|
283 |
+
{
|
284 |
+
$i++;
|
285 |
+
if (!ModuleManager::getInstance()->moduleExists($module_id) || !ModuleManager::getInstance()->isModuleActive($module_id))
|
286 |
+
continue;
|
287 |
+
|
288 |
+
$data = json_decode($data, true);
|
289 |
+
$data = $this->dataPrepare($data);
|
290 |
+
if ($i == count($content))
|
291 |
+
$last_iteration = true;
|
292 |
+
else
|
293 |
+
$last_iteration = false;
|
294 |
+
ContentManager::saveData($data, $module_id, $post_id, $last_iteration);
|
295 |
+
}
|
296 |
+
}
|
297 |
+
|
298 |
+
private function dataPrepare($data)
|
299 |
+
{
|
300 |
+
if (!is_array($data))
|
301 |
+
return array();
|
302 |
+
foreach ($data as $i => $d)
|
303 |
+
{
|
304 |
+
foreach ($d as $key => $value)
|
305 |
+
{
|
306 |
+
if ($key == 'description' && !TextHelper::isHtmlTagDetected($value))
|
307 |
+
$data[$i][$key] = TextHelper::nl2br($value);
|
308 |
+
if ($key == 'price')
|
309 |
+
$data[$i][$key] = (float) $value;
|
310 |
+
}
|
311 |
+
}
|
312 |
+
return $data;
|
313 |
+
}
|
314 |
+
|
315 |
+
}
|
application/admin/GeneralConfig.php
CHANGED
@@ -1,394 +1,531 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
'description'
|
245 |
-
'callback' => array($this, '
|
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 |
-
'description'
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\Config;
|
8 |
+
use ContentEgg\application\Plugin;
|
9 |
+
use ContentEgg\application\admin\PluginAdmin;
|
10 |
+
use ContentEgg\application\models\PriceAlertModel;
|
11 |
+
use ContentEgg\application\components\ModuleManager;
|
12 |
+
use ContentEgg\application\helpers\TextHelper;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* GeneralSettings class file
|
16 |
+
*
|
17 |
+
* @author keywordrush.com <support@keywordrush.com>
|
18 |
+
* @link https://www.keywordrush.com
|
19 |
+
* @copyright Copyright © 2020 keywordrush.com
|
20 |
+
*/
|
21 |
+
class GeneralConfig extends Config {
|
22 |
+
|
23 |
+
private static $affiliate_modules;
|
24 |
+
|
25 |
+
public function page_slug()
|
26 |
+
{
|
27 |
+
return Plugin::slug() . '';
|
28 |
+
}
|
29 |
+
|
30 |
+
public function option_name()
|
31 |
+
{
|
32 |
+
return 'contentegg_options';
|
33 |
+
}
|
34 |
+
|
35 |
+
public function add_admin_menu()
|
36 |
+
{
|
37 |
+
\add_submenu_page(Plugin::slug, __('Settings', 'content-egg') . ' ‹ Content Egg', __('Settings', 'content-egg'), 'manage_options', $this->page_slug, array($this, 'settings_page'));
|
38 |
+
}
|
39 |
+
|
40 |
+
public static function langs()
|
41 |
+
{
|
42 |
+
return array(
|
43 |
+
'ar' => 'Arabic (ar)',
|
44 |
+
'bg' => 'Bulgarian (bg)',
|
45 |
+
'ca' => 'Catalan (ca)',
|
46 |
+
'zh_CN' => 'Chinese (zh_CN)',
|
47 |
+
'zh_TW' => 'Chinese (zh_TW)',
|
48 |
+
'hr' => 'Croatian (hr)',
|
49 |
+
'cs' => 'Czech (cs)',
|
50 |
+
'da' => 'Danish (da)',
|
51 |
+
'nl' => 'Dutch (nl)',
|
52 |
+
'en' => 'English (en)',
|
53 |
+
'et' => 'Estonian (et)',
|
54 |
+
'tl' => 'Filipino (tl)',
|
55 |
+
'fi' => 'Finnish (fi)',
|
56 |
+
'fr' => 'French (fr)',
|
57 |
+
'de' => 'German (de)',
|
58 |
+
'el' => 'Greek (el)',
|
59 |
+
'iw' => 'Hebrew (iw)',
|
60 |
+
'hi' => 'Hindi (hi)',
|
61 |
+
'hu' => 'Hungarian (hu)',
|
62 |
+
'is' => 'Icelandic (is)',
|
63 |
+
'id' => 'Indonesian (id)',
|
64 |
+
'it' => 'Italian (it)',
|
65 |
+
'ja' => 'Japanese (ja)',
|
66 |
+
'ko' => 'Korean (ko)',
|
67 |
+
'lv' => 'Latvian (lv)',
|
68 |
+
'lt' => 'Lithuanian (lt)',
|
69 |
+
'ms' => 'Malay (ms)',
|
70 |
+
'no' => 'Norwegian (no)',
|
71 |
+
'fa' => 'Persian (fa)',
|
72 |
+
'pl' => 'Polish (pl)',
|
73 |
+
'pt' => 'Portuguese (pt)',
|
74 |
+
'br' => 'Portuguese (br)',
|
75 |
+
'ro' => 'Romanian (ro)',
|
76 |
+
'ru' => 'Russian (ru)',
|
77 |
+
'sr' => 'Serbian (sr)',
|
78 |
+
'sk' => 'Slovak (sk)',
|
79 |
+
'sl' => 'Slovenian (sl)',
|
80 |
+
'es' => 'Spanish (es)',
|
81 |
+
'sv' => 'Swedish (sv)',
|
82 |
+
'th' => 'Thai (th)',
|
83 |
+
'tr' => 'Turkish (tr)',
|
84 |
+
'uk' => 'Ukrainian (uk)',
|
85 |
+
'ur' => 'Urdu (ur)',
|
86 |
+
'vi' => 'Vietnamese (vi)',
|
87 |
+
);
|
88 |
+
}
|
89 |
+
|
90 |
+
protected function options()
|
91 |
+
{
|
92 |
+
|
93 |
+
$post_types = get_post_types(array('public' => true), 'names');
|
94 |
+
if (isset($post_types['attachment']))
|
95 |
+
unset($post_types['attachment']);
|
96 |
+
|
97 |
+
$total_price_alerts = PriceAlertModel::model()->count('status = ' . PriceAlertModel::STATUS_ACTIVE);
|
98 |
+
$sent_price_alerts = PriceAlertModel::model()->count('status = ' . PriceAlertModel::STATUS_DELETED
|
99 |
+
. ' AND TIMESTAMPDIFF( DAY, complet_date, "' . \current_time('mysql') . '") <= ' . PriceAlertModel::CLEAN_DELETED_DAYS);
|
100 |
+
|
101 |
+
$export_url = \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-tools&action=subscribers-export');
|
102 |
+
|
103 |
+
return array(
|
104 |
+
'lang' => array(
|
105 |
+
'title' => __('Website language', 'content-egg'),
|
106 |
+
'description' => __('The frontend language.', 'content-egg'),
|
107 |
+
'dropdown_options' => self::langs(),
|
108 |
+
'callback' => array($this, 'render_dropdown'),
|
109 |
+
'default' => self::getDefaultLang(),
|
110 |
+
'section' => __('General settings', 'content-egg'),
|
111 |
+
),
|
112 |
+
'post_types' => array(
|
113 |
+
'title' => 'Post Types',
|
114 |
+
'description' => __('What post types do you want to use for Content Egg?', 'content-egg'),
|
115 |
+
'checkbox_options' => $post_types,
|
116 |
+
'callback' => array($this, 'render_checkbox_list'),
|
117 |
+
'default' => array('post', 'page'),
|
118 |
+
'section' => __('General settings', 'content-egg'),
|
119 |
+
),
|
120 |
+
'cashback_integration' => array(
|
121 |
+
'title' => __('Cashback Tracker integration', 'content-egg'),
|
122 |
+
'description' => sprintf(__('Integration with %s plugin.', 'content-egg'), '<a target="_blanl" href="https://www.keywordrush.com/cashbacktracker">Cashback Tracker</a>') . ' ' .
|
123 |
+
__('Convert all affiliate links to trackable cashback links if possible.', 'content-egg'),
|
124 |
+
'callback' => array($this, 'render_dropdown'),
|
125 |
+
'dropdown_options' => array(
|
126 |
+
'enabled' => __('Enabled', 'content-egg'),
|
127 |
+
'disabled' => __('Disabled', 'content-egg'),
|
128 |
+
),
|
129 |
+
'default' => 'enabled',
|
130 |
+
'section' => __('General settings', 'content-egg'),
|
131 |
+
),
|
132 |
+
'external_featured_images' => array(
|
133 |
+
'title' => __('External featured images', 'content-egg'),
|
134 |
+
'description' => __('Featured images from URL', 'content-egg') .
|
135 |
+
'<p class="description">' . __('', 'content-egg') . '</p>',
|
136 |
+
'callback' => array($this, 'render_dropdown'),
|
137 |
+
'dropdown_options' => array(
|
138 |
+
'disabled' => __('Disabled - internal image is used', 'content-egg'),
|
139 |
+
'enabled_internal_priority' => __('Enabled - internal image has priority', 'content-egg'),
|
140 |
+
'enabled_external_priority' => __('Enabled - external image has priority', 'content-egg'),
|
141 |
+
),
|
142 |
+
'default' => 'disabled',
|
143 |
+
'section' => __('General settings', 'content-egg'),
|
144 |
+
),
|
145 |
+
|
146 |
+
'woocommerce_modules' => array(
|
147 |
+
'title' => __('Modules for synchronization', 'content-egg'),
|
148 |
+
'description' => __('Select modules for automatic synchronization with WooCommerce.', 'content-egg'),
|
149 |
+
'checkbox_options' => self::getAffiliteModulesList(),
|
150 |
+
'callback' => array($this, 'render_checkbox_list'),
|
151 |
+
'default' => array(),
|
152 |
+
'section' => __('WooCommerce', 'content-egg'),
|
153 |
+
),
|
154 |
+
'woocommerce_product_sync' => array(
|
155 |
+
'title' => __('Automatic synchronization', 'content-egg'),
|
156 |
+
'description' => __('How to choose product for automatic synchronization with WooCommerce.', 'content-egg'),
|
157 |
+
'callback' => array($this, 'render_dropdown'),
|
158 |
+
'dropdown_options' => array(
|
159 |
+
'min_price' => __('Minimum price', 'content-egg'),
|
160 |
+
'max_price' => __('Maximum price', 'content-egg'),
|
161 |
+
'random' => __('Random', 'content-egg'),
|
162 |
+
'manually' => __('Manually only', 'content-egg'),
|
163 |
+
),
|
164 |
+
'default' => 'min_price',
|
165 |
+
'section' => __('WooCommerce', 'content-egg'),
|
166 |
+
),
|
167 |
+
'woocommerce_attributes_sync' => array(
|
168 |
+
'title' => __('Attributes synchronization', 'content-egg'),
|
169 |
+
'description' => __('Also synchronize attributes automatically for synchronized product.', 'content-egg'),
|
170 |
+
'callback' => array($this, 'render_checkbox'),
|
171 |
+
'default' => false,
|
172 |
+
'section' => __('WooCommerce', 'content-egg'),
|
173 |
+
),
|
174 |
+
'woocommerce_attributes_filter' => array(
|
175 |
+
'title' => __('Global attributes filter', 'content-egg'),
|
176 |
+
'description' => __('How to create wocommerce attributes when synchronizing. Please, read documentation about them in our docs.', 'content-egg'),
|
177 |
+
'callback' => array($this, 'render_dropdown'),
|
178 |
+
'dropdown_options' => array(
|
179 |
+
'' => __('Default filter', 'content-egg'),
|
180 |
+
'whitelist' => __('Whitelist attribute names', 'content-egg'),
|
181 |
+
'blacklist' => __('Blacklist attribute names', 'content-egg'),
|
182 |
+
),
|
183 |
+
'default' => '',
|
184 |
+
'section' => __('WooCommerce', 'content-egg'),
|
185 |
+
),
|
186 |
+
'woocommerce_attributes_list' => array(
|
187 |
+
'title' => __('Attributes list', 'content-egg'),
|
188 |
+
'description' => __('Black / white list of woocommerce global (filterable) attributes. Enter a comma separated list.', 'content-egg'),
|
189 |
+
'callback' => array($this, 'render_textarea'),
|
190 |
+
'default' => '',
|
191 |
+
'section' => __('WooCommerce', 'content-egg'),
|
192 |
+
),
|
193 |
+
'woocommerce_echo_update_date' => array(
|
194 |
+
'title' => __('Update date', 'content-egg'),
|
195 |
+
'description' => __('Show price update date for WooCommerce products.', 'content-egg'),
|
196 |
+
'callback' => array($this, 'render_dropdown'),
|
197 |
+
'dropdown_options' => array(
|
198 |
+
'' => __('Disabled', 'content-egg'),
|
199 |
+
'amazon' => __('Amazon only', 'content-egg'),
|
200 |
+
'all' => __('All modules', 'content-egg'),
|
201 |
+
),
|
202 |
+
'default' => 'amazon',
|
203 |
+
'section' => __('WooCommerce', 'content-egg'),
|
204 |
+
),
|
205 |
+
'woocommerce_echo_price_per_unit' => array(
|
206 |
+
'title' => __('Price per unit', 'content-egg'),
|
207 |
+
'description' => __('Show price per unit', 'content-egg') .
|
208 |
+
'<p class="description">' .
|
209 |
+
__('This option is available for Amazon and Ebay modules only.', 'content-egg') . '<br>' .
|
210 |
+
'</p>',
|
211 |
+
'callback' => array($this, 'render_checkbox'),
|
212 |
+
'default' => false,
|
213 |
+
'section' => __('WooCommerce', 'content-egg'),
|
214 |
+
),
|
215 |
+
'woocommerce_btn_text' => array(
|
216 |
+
'title' => __('Buy button text', 'content-egg'),
|
217 |
+
'description' => __('Overwrite the button text for external products.', 'content-egg') . ' ' . __('You can use tags: %MERCHANT%, %DOMAIN%, %PRICE%, %STOCK_STATUS%.', 'content-egg'),
|
218 |
+
'callback' => array($this, 'render_input'),
|
219 |
+
'default' => '',
|
220 |
+
'validator' => array(
|
221 |
+
'strip_tags',
|
222 |
+
),
|
223 |
+
'section' => __('WooCommerce', 'content-egg'),
|
224 |
+
),
|
225 |
+
|
226 |
+
'rel_attribute' => array(
|
227 |
+
'title' => 'Rel attribute for affiliate links',
|
228 |
+
'description' => sprintf(__('<a target="_blank" href="%s">Qualify</a> your affiliate links to Google.', 'content-egg'), 'https://support.google.com/webmasters/answer/96569'),
|
229 |
+
'checkbox_options' => array(
|
230 |
+
'nofollow' => 'nofollow',
|
231 |
+
'sponsored' => 'sponsored',
|
232 |
+
'external' => 'external',
|
233 |
+
'noopener' => 'noopener',
|
234 |
+
'noreferrer' => 'noreferrer',
|
235 |
+
'ugc' => 'ugc',
|
236 |
+
),
|
237 |
+
'callback' => array($this, 'render_checkbox_list'),
|
238 |
+
'default' => array('nofollow'),
|
239 |
+
'section' => __('Templates', 'content-egg'),
|
240 |
+
),
|
241 |
+
'filter_bots' => array(
|
242 |
+
'title' => __('Filter bots', 'content-egg'),
|
243 |
+
'description' => __('Bots can\'t activate parsers.', 'content-egg') .
|
244 |
+
'<p class="description">' . __('Updating price and keyword updating is made with page opening. If we determine update by useragent, and page is opened by one of known bots, no parsers will work in this case.', 'content-egg') . '</p>',
|
245 |
+
'callback' => array($this, 'render_checkbox'),
|
246 |
+
'default' => true,
|
247 |
+
'section' => __('General settings', 'content-egg'),
|
248 |
+
),
|
249 |
+
|
250 |
+
|
251 |
+
|
252 |
+
'price_history_days' => array(
|
253 |
+
'title' => __('Price history', 'content-egg'),
|
254 |
+
'description' => __('How long save price history. 0 - deactivate price history.', 'content-egg'),
|
255 |
+
'callback' => array($this, 'render_input'),
|
256 |
+
'default' => 180,
|
257 |
+
'validator' => array(
|
258 |
+
'trim',
|
259 |
+
'absint',
|
260 |
+
array(
|
261 |
+
'call' => array('\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to'),
|
262 |
+
'arg' => 365,
|
263 |
+
'message' => sprintf(__('The field "%s" can\'t be more than %d.', 'content-egg'), __('Price history', 'content-egg'), 365),
|
264 |
+
),
|
265 |
+
),
|
266 |
+
'section' => __('Price alerts', 'content-egg'),
|
267 |
+
),
|
268 |
+
'price_drops_days' => array(
|
269 |
+
'title' => __('Price drops period', 'content-egg'),
|
270 |
+
'description' => __('Used for Price Movers widget.', 'content-egg'),
|
271 |
+
'callback' => array($this, 'render_dropdown'),
|
272 |
+
'dropdown_options' => array(
|
273 |
+
'1.' => __('The last 1 day', 'content-egg'),
|
274 |
+
'2.' => sprintf(__('The last %d days', 'content-egg'), 2),
|
275 |
+
'3.' => sprintf(__('The last %d days', 'content-egg'), 3),
|
276 |
+
'4.' => sprintf(__('The last %d days', 'content-egg'), 4),
|
277 |
+
'5.' => sprintf(__('The last %d days', 'content-egg'), 5),
|
278 |
+
'6.' => sprintf(__('The last %d days', 'content-egg'), 6),
|
279 |
+
'7.' => sprintf(__('The last %d days', 'content-egg'), 7),
|
280 |
+
'21.' => sprintf(__('The last %d days', 'content-egg'), 21),
|
281 |
+
'30.' => sprintf(__('The last %d days', 'content-egg'), 30),
|
282 |
+
'90.' => sprintf(__('The last %d days', 'content-egg'), 90),
|
283 |
+
'180.' => sprintf(__('The last %d days', 'content-egg'), 180),
|
284 |
+
'360.' => sprintf(__('The last %d days', 'content-egg'), 360),
|
285 |
+
),
|
286 |
+
'default' => '30.',
|
287 |
+
'section' => __('Price alerts', 'content-egg'),
|
288 |
+
),
|
289 |
+
'price_alert_enabled' => array(
|
290 |
+
'title' => 'Price alert',
|
291 |
+
'description' => __('Allow visitors to subscribe for price drop alert on email.', 'content-egg') .
|
292 |
+
'<p class="description">' . sprintf(__('Active subscriptions now: <b>%d</b>', 'content-egg'), $total_price_alerts) .
|
293 |
+
'. ' . sprintf(__('Messages are sent for last %d days: <b>%d</b>', 'content-egg'), PriceAlertModel::CLEAN_DELETED_DAYS, $sent_price_alerts) . '.' .
|
294 |
+
' ' . sprintf(__('Export: [ <a href="%s">All</a> | <a href="%s">Active</a> ]', 'content-egg'), $export_url, $export_url . '&active_only=true') . '</p>' .
|
295 |
+
'<p class="description">' .
|
296 |
+
__('"Price history" option must be enabled.', 'content-egg') . '<br>' .
|
297 |
+
__('Recommendation: Go to Settings - Privacy and select Privacy Policy page.', 'content-egg') .
|
298 |
+
'</p>',
|
299 |
+
'callback' => array($this, 'render_checkbox'),
|
300 |
+
'default' => true,
|
301 |
+
'section' => __('Price alerts', 'content-egg'),
|
302 |
+
),
|
303 |
+
'button_color' => array(
|
304 |
+
'title' => __('Button color', 'content-egg'),
|
305 |
+
'description' => __('Button color for default templates.', 'content-egg'),
|
306 |
+
'callback' => array($this, 'render_color_picker'),
|
307 |
+
'default' => '#d9534f',
|
308 |
+
'validator' => array(
|
309 |
+
'trim',
|
310 |
+
),
|
311 |
+
'section' => __('Templates', 'content-egg'),
|
312 |
+
),
|
313 |
+
'price_color' => array(
|
314 |
+
'title' => __('Price color', 'content-egg'),
|
315 |
+
'description' => __('Price color for default templates.', 'content-egg'),
|
316 |
+
'callback' => array($this, 'render_color_picker'),
|
317 |
+
'default' => '#dc3545',
|
318 |
+
'validator' => array(
|
319 |
+
'trim',
|
320 |
+
),
|
321 |
+
'section' => __('Templates', 'content-egg'),
|
322 |
+
),
|
323 |
+
'btn_text_buy_now' => array(
|
324 |
+
'title' => __('Buy now button text', 'content-egg'),
|
325 |
+
'description' => sprintf(__('It will be used instead of "%s".', 'content-egg'), __('Buy Now', 'content-egg-tpl')) . ' ' . __('You can use tags: %MERCHANT%, %DOMAIN%, %PRICE%, %STOCK_STATUS%.', 'content-egg'),
|
326 |
+
'callback' => array($this, 'render_input'),
|
327 |
+
'default' => '',
|
328 |
+
'validator' => array(
|
329 |
+
'strip_tags',
|
330 |
+
),
|
331 |
+
'section' => __('Templates', 'content-egg'),
|
332 |
+
),
|
333 |
+
'btn_text_coupon' => array(
|
334 |
+
'title' => __('Coupon button text', 'content-egg'),
|
335 |
+
'description' => sprintf(__('It will be used instead of "%s".', 'content-egg'), __('Shop Sale', 'content-egg-tpl')),
|
336 |
+
'callback' => array($this, 'render_input'),
|
337 |
+
'default' => '',
|
338 |
+
'validator' => array(
|
339 |
+
'strip_tags',
|
340 |
+
),
|
341 |
+
'section' => __('Templates', 'content-egg'),
|
342 |
+
),
|
343 |
+
'show_stock_status' => array(
|
344 |
+
'title' => __('Stock status', 'content-egg'),
|
345 |
+
'callback' => array($this, 'render_dropdown'),
|
346 |
+
'dropdown_options' => array(
|
347 |
+
'show_status' => __('Show stock status', 'content-egg'),
|
348 |
+
'hide_status' => __('Hide stock status', 'content-egg'),
|
349 |
+
'show_outofstock' => __('Show OutOfStock status only', 'content-egg'),
|
350 |
+
'show_instock' => __('Show InStock status only', 'content-egg'),
|
351 |
+
),
|
352 |
+
'default' => 'show_status',
|
353 |
+
'section' => __('Templates', 'content-egg'),
|
354 |
+
),
|
355 |
+
|
356 |
+
'redirect_prefix' => array(
|
357 |
+
'title' => __('Redirect prefix', 'content-egg'),
|
358 |
+
'description' => __('Custom prefix for local redirect links.', 'content-egg'),
|
359 |
+
'callback' => array($this, 'render_input'),
|
360 |
+
'default' => '',
|
361 |
+
'validator' => array(
|
362 |
+
'trim',
|
363 |
+
'allow_empty',
|
364 |
+
array(
|
365 |
+
'call' => array('\ContentEgg\application\helpers\FormValidator', 'alpha_numeric'),
|
366 |
+
'message' => sprintf(__('The field "%s" can contain only Latin letters and digits.', 'content-egg'), __('Redirect prefix', 'content-egg')),
|
367 |
+
),
|
368 |
+
),
|
369 |
+
'section' => __('General settings', 'content-egg'),
|
370 |
+
),
|
371 |
+
'outofstock_product' => array(
|
372 |
+
'title' => __('Out of Stock products', 'content-egg'),
|
373 |
+
'description' => __('How to deal with Out of Stock products.', 'content-egg'),
|
374 |
+
'callback' => array($this, 'render_dropdown'),
|
375 |
+
'dropdown_options' => array(
|
376 |
+
'' => __('Do nothing', 'content-egg'),
|
377 |
+
'hide_price' => __('Hide price', 'content-egg'),
|
378 |
+
'hide_product' => __('Hide product', 'content-egg'),
|
379 |
+
),
|
380 |
+
'default' => '',
|
381 |
+
'section' => __('General settings', 'content-egg'),
|
382 |
+
),
|
383 |
+
'from_name' => array(
|
384 |
+
'title' => __('From Name', 'content-egg'),
|
385 |
+
'description' => __('This name will appear in the From Name column of emails sent from CE plugin.', 'content-egg'),
|
386 |
+
'callback' => array($this, 'render_input'),
|
387 |
+
'default' => '',
|
388 |
+
'validator' => array(
|
389 |
+
'trim',
|
390 |
+
'allow_empty',
|
391 |
+
),
|
392 |
+
'section' => __('Price alerts', 'content-egg'),
|
393 |
+
),
|
394 |
+
'from_email' => array(
|
395 |
+
'title' => __('From Email', 'content-egg'),
|
396 |
+
'description' => __('Customize the From Email address.', 'content-egg') . ' ' . __('To avoid your email being marked as spam, it is recommended your "from" match your website.', 'content-egg'),
|
397 |
+
'callback' => array($this, 'render_input'),
|
398 |
+
'default' => '',
|
399 |
+
'validator' => array(
|
400 |
+
'trim',
|
401 |
+
'allow_empty',
|
402 |
+
array(
|
403 |
+
'call' => array('\ContentEgg\application\helpers\FormValidator', 'valid_email'),
|
404 |
+
'message' => sprintf(__('Field "%s" filled with wrong data.', 'content-egg'), 'Email'),
|
405 |
+
),
|
406 |
+
),
|
407 |
+
'section' => __('Price alerts', 'content-egg'),
|
408 |
+
),
|
409 |
+
'search_modules' => array(
|
410 |
+
'title' => __('Search modules', 'content-egg'),
|
411 |
+
'description' => __('Select modules to search on frontend.', 'content-egg') . ' ' .
|
412 |
+
__('Do not select more than 1-2 modules.', 'content-egg') . '<br>' .
|
413 |
+
__('Please note, AE modules work slowly and are not recommended for use as search modules.', 'content-egg') . '<br>' .
|
414 |
+
__('Do not forget to add search widget or shorcode [content-egg-search-form].', 'content-egg'),
|
415 |
+
'checkbox_options' => self::getAffiliteModulesList(),
|
416 |
+
'callback' => array($this, 'render_checkbox_list'),
|
417 |
+
'default' => array(),
|
418 |
+
'section' => __('Frontend search', 'content-egg'),
|
419 |
+
),
|
420 |
+
'search_page_tpl' => array(
|
421 |
+
'title' => __('Search page template', 'content-egg'),
|
422 |
+
'description' => __('Template for body of search page.', 'content-egg') . ' ' .
|
423 |
+
__('You can use shortcodes, for example: [content-egg module=Amazon template=grid]', 'content-egg'),
|
424 |
+
'callback' => array($this, 'render_textarea'),
|
425 |
+
'default' => '',
|
426 |
+
'section' => __('Frontend search', 'content-egg'),
|
427 |
+
),
|
428 |
+
|
429 |
+
'logos' => array(
|
430 |
+
'title' => __('Merchant logos', 'external-importer'),
|
431 |
+
'description' => __('You can add your own custom merchant logos.', 'external-importer'),
|
432 |
+
'callback' => array($this, 'render_logo_fields_block'),
|
433 |
+
'validator' => array(
|
434 |
+
array(
|
435 |
+
'call' => array($this, 'formatLogoFields'),
|
436 |
+
'type' => 'filter',
|
437 |
+
),
|
438 |
+
),
|
439 |
+
'default' => array(),
|
440 |
+
'section' => __('Templates', 'content-egg'),
|
441 |
+
),
|
442 |
+
);
|
443 |
+
}
|
444 |
+
|
445 |
+
public static function getDefaultLang()
|
446 |
+
{
|
447 |
+
$locale = \get_locale();
|
448 |
+
$lang = explode('_', $locale);
|
449 |
+
if (array_key_exists($lang[0], self::langs()))
|
450 |
+
return $lang[0];
|
451 |
+
else
|
452 |
+
return 'en';
|
453 |
+
}
|
454 |
+
|
455 |
+
public function settings_page()
|
456 |
+
{
|
457 |
+
\wp_enqueue_script('jquery-ui-tabs');
|
458 |
+
\wp_enqueue_style('contentegg-admin-ui-css', \ContentEgg\PLUGIN_RES . '/css/jquery-ui.min.css', false, \ContentEgg\application\Plugin::version);
|
459 |
+
|
460 |
+
PluginAdmin::render('settings', array('page_slug' => $this->page_slug()));
|
461 |
+
}
|
462 |
+
|
463 |
+
private static function getAffiliteModulesList()
|
464 |
+
{
|
465 |
+
if (self::$affiliate_modules === null)
|
466 |
+
{
|
467 |
+
self::$affiliate_modules = ModuleManager::getInstance()->getAffiliteModulesList(false);
|
468 |
+
}
|
469 |
+
return self::$affiliate_modules;
|
470 |
+
}
|
471 |
+
|
472 |
+
public function render_logo_fields_line($args)
|
473 |
+
{
|
474 |
+
$i = isset($args['_field']) ? $args['_field'] : 0;
|
475 |
+
$name = isset($args['value'][$i]['name']) ? $args['value'][$i]['name'] : '';
|
476 |
+
$value = isset($args['value'][$i]['value']) ? $args['value'][$i]['value'] : '';
|
477 |
+
|
478 |
+
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
479 |
+
. \esc_attr($args['name']) . '][' . $i . '][name]" value="'
|
480 |
+
. \esc_attr($name) . '" class="text" placeholder="' . \esc_attr(__('Domain name', 'external-importer')) . '" type="text"/>';
|
481 |
+
echo '<input name="' . \esc_attr($args['option_name']) . '['
|
482 |
+
. \esc_attr($args['name']) . '][' . $i . '][value]" value="'
|
483 |
+
. \esc_attr($value) . '" class="regular-text ltr" placeholder="' . \esc_attr(__('Logo URL', 'external-importer')) . '" type="text"/>';
|
484 |
+
}
|
485 |
+
|
486 |
+
public function render_logo_fields_block($args)
|
487 |
+
{
|
488 |
+
if (is_array($args['value']))
|
489 |
+
$total = count($args['value']) + 3;
|
490 |
+
else
|
491 |
+
$total = 3;
|
492 |
+
|
493 |
+
for ($i = 0; $i < $total; $i++)
|
494 |
+
{
|
495 |
+
echo '<div style="padding-bottom: 5px;">';
|
496 |
+
$args['_field'] = $i;
|
497 |
+
$this->render_logo_fields_line($args);
|
498 |
+
echo '</div>';
|
499 |
+
}
|
500 |
+
if ($args['description'])
|
501 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
502 |
+
}
|
503 |
+
|
504 |
+
public function formatLogoFields($values)
|
505 |
+
{
|
506 |
+
$results = array();
|
507 |
+
foreach ($values as $k => $value)
|
508 |
+
{
|
509 |
+
$name = trim(\sanitize_text_field($value['name']));
|
510 |
+
if ($host = TextHelper::getHostName($values[$k]['name']))
|
511 |
+
$name = $host;
|
512 |
+
|
513 |
+
$value = trim(\sanitize_text_field($value['value']));
|
514 |
+
|
515 |
+
if (!$name || !$value)
|
516 |
+
continue;
|
517 |
+
|
518 |
+
if (!filter_var($value, FILTER_VALIDATE_URL))
|
519 |
+
continue;
|
520 |
+
|
521 |
+
if (in_array($name, array_column($results, 'name')))
|
522 |
+
continue;
|
523 |
+
|
524 |
+
$result = array('name' => $name, 'value' => $value);
|
525 |
+
$results[] = $result;
|
526 |
+
}
|
527 |
+
|
528 |
+
return $results;
|
529 |
+
}
|
530 |
+
|
531 |
+
}
|
application/admin/ImportExportController.php
CHANGED
@@ -1,71 +1,73 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
$
|
34 |
-
|
35 |
-
$
|
36 |
-
|
37 |
-
$all_options
|
38 |
-
//
|
39 |
-
$all_options =
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\components\ModuleManager;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* ImportExportController class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link http://www.keywordrush.com/
|
15 |
+
* @copyright Copyright © 2016 keywordrush.com
|
16 |
+
*/
|
17 |
+
class ImportExportController {
|
18 |
+
|
19 |
+
const slug = 'content-egg-import-export';
|
20 |
+
|
21 |
+
public function __construct()
|
22 |
+
{
|
23 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
24 |
+
}
|
25 |
+
|
26 |
+
public function add_admin_menu()
|
27 |
+
{
|
28 |
+
\add_submenu_page(Plugin::slug, __('Import/Export', 'content-egg') . ' ‹ Content Egg', __('Import/Export', 'content-egg'), 'manage_options', self::slug, array($this, 'actionIndex'));
|
29 |
+
}
|
30 |
+
|
31 |
+
public function actionIndex()
|
32 |
+
{
|
33 |
+
$_POST = array_map('stripslashes_deep', $_POST);
|
34 |
+
$message = '';
|
35 |
+
$notice = '';
|
36 |
+
|
37 |
+
$all_options = array();
|
38 |
+
// main settings
|
39 |
+
$all_options[GeneralConfig::getInstance()->option_name()] = GeneralConfig::getInstance()->getOptionValues();
|
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)
|
49 |
+
{
|
50 |
+
if (!array_key_exists($option, $all_options))
|
51 |
+
continue;
|
52 |
+
$save = $all_options[$option];
|
53 |
+
foreach ($save as $k => $v)
|
54 |
+
{
|
55 |
+
if (isset($values[$k]))
|
56 |
+
$save[$k] = $values[$k];
|
57 |
+
}
|
58 |
+
\update_option($option, $save);
|
59 |
+
$all_options[$option] = $save;
|
60 |
+
}
|
61 |
+
$message = __('Options were saved.', 'content-egg') . ' <a href="?page=content-egg">' . __('Page of settings', 'content-egg') . '</a>';
|
62 |
+
} else
|
63 |
+
$notice = __('Invalid format.', 'content-egg');
|
64 |
+
}
|
65 |
+
PluginAdmin::getInstance()->render('import_export', array(
|
66 |
+
'export_str' => json_encode($all_options),
|
67 |
+
'notice' => $notice,
|
68 |
+
'message' => $message,
|
69 |
+
'nonce' => \wp_create_nonce(basename(__FILE__)),
|
70 |
+
));
|
71 |
+
}
|
72 |
+
|
73 |
+
}
|
application/admin/ModuleSettingsContoller.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
defined('\ABSPATH') || exit;
|
5 |
+
|
6 |
+
use ContentEgg\application\Plugin;
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* ModuleSettingsContoller class file
|
11 |
+
*
|
12 |
+
* @author keywordrush.com <support@keywordrush.com>
|
13 |
+
* @link https://www.keywordrush.com
|
14 |
+
* @copyright Copyright © 2020 keywordrush.com
|
15 |
+
*/
|
16 |
+
class ModuleSettingsContoller {
|
17 |
+
|
18 |
+
const slug = 'content-egg-modules';
|
19 |
+
|
20 |
+
public function __construct()
|
21 |
+
{
|
22 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
23 |
+
}
|
24 |
+
|
25 |
+
public function add_admin_menu()
|
26 |
+
{
|
27 |
+
\add_submenu_page(Plugin::slug(), __('Modules', 'content-egg') . ' ‹ Content Egg', __('Modules', 'content-egg'), 'manage_options', self::slug, array($this, 'actionIndex'));
|
28 |
+
}
|
29 |
+
|
30 |
+
public function actionIndex()
|
31 |
+
{
|
32 |
+
\wp_enqueue_style('egg-bootstrap', \ContentEgg\PLUGIN_RES . '/bootstrap/css/egg-bootstrap.css');
|
33 |
+
PluginAdmin::getInstance()->render('module_index', array('modules' => ModuleManager::getInstance()->getConfigurableModules()));
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
}
|
application/admin/MyListTable.php
CHANGED
@@ -1,160 +1,162 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
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 |
-
$this->
|
64 |
-
|
65 |
-
$
|
66 |
-
|
67 |
-
$
|
68 |
-
|
69 |
-
$
|
70 |
-
|
71 |
-
|
72 |
-
'
|
73 |
-
'
|
74 |
-
'
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
$this->
|
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 |
-
$time_diff =
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\models\Model;
|
9 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* MyListTable class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2015 keywordrush.com
|
17 |
+
*/
|
18 |
+
if (!class_exists('\WP_List_Table'))
|
19 |
+
{
|
20 |
+
require_once( \ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
21 |
+
}
|
22 |
+
|
23 |
+
class MyListTable extends \WP_List_Table {
|
24 |
+
|
25 |
+
const per_page = 15;
|
26 |
+
|
27 |
+
private $model;
|
28 |
+
|
29 |
+
function __construct(Model $model, array $config = array())
|
30 |
+
{
|
31 |
+
global $status, $page;
|
32 |
+
|
33 |
+
$this->model = $model;
|
34 |
+
parent::__construct(array(
|
35 |
+
'singular' => Plugin::slug . '-table',
|
36 |
+
'plural' => Plugin::slug . '-all-tables',
|
37 |
+
'screen' => get_current_screen()
|
38 |
+
));
|
39 |
+
}
|
40 |
+
|
41 |
+
function default_orderby()
|
42 |
+
{
|
43 |
+
return 'id';
|
44 |
+
}
|
45 |
+
|
46 |
+
protected function getWhereFilters()
|
47 |
+
{
|
48 |
+
return '';
|
49 |
+
}
|
50 |
+
|
51 |
+
function prepare_items()
|
52 |
+
{
|
53 |
+
$doaction = $this->current_action();
|
54 |
+
if ($doaction)
|
55 |
+
{
|
56 |
+
//@todo
|
57 |
+
}
|
58 |
+
|
59 |
+
$columns = $this->get_columns();
|
60 |
+
$where = $this->getWhereFilters();
|
61 |
+
|
62 |
+
$hidden = array();
|
63 |
+
$sortable = $this->get_sortable_columns();
|
64 |
+
$this->_column_headers = array($columns, $hidden, $sortable);
|
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 *',
|
73 |
+
'where' => $where,
|
74 |
+
'limit' => static::per_page,
|
75 |
+
'offset' => $paged * static::per_page,
|
76 |
+
'order' => $orderby . ' ' . $order,
|
77 |
+
);
|
78 |
+
$this->items = $this->model->findAll($params);
|
79 |
+
$total_items = (int) $this->model->getDb()->get_var('SELECT FOUND_ROWS();');
|
80 |
+
|
81 |
+
$this->set_pagination_args(
|
82 |
+
array(
|
83 |
+
'total_items' => $total_items,
|
84 |
+
'per_page' => static::per_page,
|
85 |
+
'total_pages' => ceil($total_items / static::per_page)
|
86 |
+
));
|
87 |
+
}
|
88 |
+
|
89 |
+
function column_default($item, $column_name)
|
90 |
+
{
|
91 |
+
return \esc_html($item[$column_name]);
|
92 |
+
}
|
93 |
+
|
94 |
+
private function view_column_datetime($item, $col_name)
|
95 |
+
{
|
96 |
+
|
97 |
+
if ($item[$col_name] == '0000-00-00 00:00:00')
|
98 |
+
return ' - ';
|
99 |
+
|
100 |
+
$modified_timestamp = strtotime($item[$col_name]);
|
101 |
+
$current_timestamp = current_time('timestamp');
|
102 |
+
$time_diff = $current_timestamp - $modified_timestamp;
|
103 |
+
if ($time_diff >= 0 && $time_diff < DAY_IN_SECONDS)
|
104 |
+
$time_diff = human_time_diff($modified_timestamp, $current_timestamp) . __(' ago', 'content-egg');
|
105 |
+
else
|
106 |
+
$time_diff = TemplateHelper::formatDatetime($item[$col_name], 'mysql', '<br />');
|
107 |
+
|
108 |
+
$readable_time = TemplateHelper::formatDatetime($item[$col_name], 'mysql', ' ');
|
109 |
+
return '<abbr title="' . esc_attr($readable_time) . '">' . $time_diff . '</abbr>';
|
110 |
+
}
|
111 |
+
|
112 |
+
function column_create_date($item)
|
113 |
+
{
|
114 |
+
return $this->view_column_datetime($item, 'create_date');
|
115 |
+
}
|
116 |
+
|
117 |
+
function column_update_date($item)
|
118 |
+
{
|
119 |
+
return $this->view_column_datetime($item, 'update_date');
|
120 |
+
}
|
121 |
+
|
122 |
+
function column_last_check($item)
|
123 |
+
{
|
124 |
+
return $this->view_column_datetime($item, 'last_check');
|
125 |
+
}
|
126 |
+
|
127 |
+
function column_last_run($item)
|
128 |
+
{
|
129 |
+
return $this->view_column_datetime($item, 'last_run');
|
130 |
+
}
|
131 |
+
|
132 |
+
function column_cb($item)
|
133 |
+
{
|
134 |
+
return sprintf(
|
135 |
+
'<input type="checkbox" name="id[]" value="%d" />', $item['id']
|
136 |
+
);
|
137 |
+
}
|
138 |
+
|
139 |
+
function get_bulk_actions()
|
140 |
+
{
|
141 |
+
$actions = array(
|
142 |
+
'delete' => __('Delete', 'content-egg')
|
143 |
+
);
|
144 |
+
return $actions;
|
145 |
+
}
|
146 |
+
|
147 |
+
function process_bulk_action()
|
148 |
+
{
|
149 |
+
if ($this->current_action() === 'delete')
|
150 |
+
{
|
151 |
+
$ids = isset($_GET['id']) ? $_REQUEST['id'] : array();
|
152 |
+
if (!is_array($ids))
|
153 |
+
$ids = (array) $ids;
|
154 |
+
foreach ($ids as $id)
|
155 |
+
{
|
156 |
+
$id = (int) $id;
|
157 |
+
$this->model->delete($id);
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
}
|
application/admin/PluginAdmin.php
CHANGED
@@ -1,141 +1,145 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\components\
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
new
|
51 |
-
new
|
52 |
-
|
53 |
-
new
|
54 |
-
new
|
55 |
-
new
|
56 |
-
new
|
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 |
-
if (
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\helpers\TextHelper;
|
9 |
+
use ContentEgg\application\admin\GeneralConfig;
|
10 |
+
use ContentEgg\application\components\ModuleManager;
|
11 |
+
use ContentEgg\application\components\ModuleApi;
|
12 |
+
use ContentEgg\application\components\FeaturedImage;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* PluginAdmin class file
|
16 |
+
*
|
17 |
+
* @author keywordrush.com <support@keywordrush.com>
|
18 |
+
* @link https://www.keywordrush.com
|
19 |
+
* @copyright Copyright © 2020 keywordrush.com
|
20 |
+
*/
|
21 |
+
class PluginAdmin {
|
22 |
+
|
23 |
+
protected static $instance = null;
|
24 |
+
|
25 |
+
public static function getInstance()
|
26 |
+
{
|
27 |
+
if (self::$instance == null)
|
28 |
+
self::$instance = new self;
|
29 |
+
|
30 |
+
return self::$instance;
|
31 |
+
}
|
32 |
+
|
33 |
+
private function __construct()
|
34 |
+
{
|
35 |
+
if (!\is_admin())
|
36 |
+
die('You are not authorized to perform the requested action.');
|
37 |
+
|
38 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
39 |
+
\add_action('admin_enqueue_scripts', array($this, 'admin_load_scripts'));
|
40 |
+
\add_filter('parent_file', array($this, 'highlight_admin_menu'));
|
41 |
+
|
42 |
+
if (isset($GLOBALS['pagenow']) && $GLOBALS['pagenow'] == 'plugins.php')
|
43 |
+
{
|
44 |
+
\add_filter('plugin_row_meta', array($this, 'add_plugin_row_meta'), 10, 2);
|
45 |
+
}
|
46 |
+
if (Plugin::isFree() || (Plugin::isPro() && Plugin::isActivated()) || Plugin::isEnvato())
|
47 |
+
{
|
48 |
+
GeneralConfig::getInstance()->adminInit();
|
49 |
+
ModuleManager::getInstance()->adminInit();
|
50 |
+
new ModuleSettingsContoller;
|
51 |
+
new ProductController;
|
52 |
+
AdminNotice::getInstance()->adminInit();
|
53 |
+
new EggMetabox;
|
54 |
+
new ModuleApi;
|
55 |
+
new FeaturedImage;
|
56 |
+
new PrefillController;
|
57 |
+
new AutoblogController;
|
58 |
+
new ToolsController;
|
59 |
+
new ImportExportController;
|
60 |
+
AeIntegrationConfig::getInstance()->adminInit();
|
61 |
+
}
|
62 |
+
if (Plugin::isEnvato() && !Plugin::isActivated() && !\get_option(Plugin::slug . '_env_install'))
|
63 |
+
EnvatoConfig::getInstance()->adminInit();
|
64 |
+
elseif (Plugin::isPro())
|
65 |
+
LicConfig::getInstance()->adminInit();
|
66 |
+
if (Plugin::isPro() && Plugin::isActivated())
|
67 |
+
{
|
68 |
+
new \ContentEgg\application\Autoupdate(Plugin::version(), plugin_basename(\ContentEgg\PLUGIN_FILE), Plugin::getApiBase(), Plugin::slug);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
function admin_load_scripts()
|
73 |
+
{
|
74 |
+
if ($GLOBALS['pagenow'] != 'admin.php' || empty($_GET['page']))
|
75 |
+
return;
|
76 |
+
|
77 |
+
$page_pats = explode('-', $_GET['page']);
|
78 |
+
|
79 |
+
if (count($page_pats) < 2 || $page_pats[0] . '-' . $page_pats[1] != 'content-egg')
|
80 |
+
return;
|
81 |
+
|
82 |
+
\wp_enqueue_script('content_egg_common', \ContentEgg\PLUGIN_RES . '/js/common.js', array('jquery'));
|
83 |
+
\wp_localize_script('content_egg_common', 'contenteggL10n', array(
|
84 |
+
'are_you_shure' => __('Are you sure?', 'content-egg'),
|
85 |
+
'sitelang' => GeneralConfig::getInstance()->option('lang'),
|
86 |
+
));
|
87 |
+
|
88 |
+
\wp_enqueue_style('contentegg-admin', \ContentEgg\PLUGIN_RES . '/css/admin.css', null, 'vaa' . Plugin::version());
|
89 |
+
}
|
90 |
+
|
91 |
+
public function add_plugin_row_meta(array $links, $file)
|
92 |
+
{
|
93 |
+
if ($file == plugin_basename(\ContentEgg\PLUGIN_FILE) && (Plugin::isActivated() || Plugin::isFree()))
|
94 |
+
{
|
95 |
+
return array_merge(
|
96 |
+
$links, array(
|
97 |
+
'<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=content-egg">' . __('Settings', 'content-egg') . '</a>',
|
98 |
+
)
|
99 |
+
);
|
100 |
+
}
|
101 |
+
return $links;
|
102 |
+
}
|
103 |
+
|
104 |
+
public function add_admin_menu()
|
105 |
+
{
|
106 |
+
$icon_svg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAUCAYAAABvVQZ0AAAACXBIWXMAAC4jAAAuIwF4pT92AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA1dJREFUeNqNVElMU1EUfQShIIkYNUETBkUIRoNGRUwxYWMUQoxGwSnCBkIUcGRuS39/p99+OkBpy9gCZSodgIImQIACKtGtG+OGhIXRBFmQ4EKjpt77BVILDSzu4v/33rnnnnvuJTRNE/+QQFAQWoGIGCtrSZGeTeMPtDPZVlMpTVHEXFlDpBIJdy/w7RYgjHphHamSy2KSPLaXofPu73unHcthXtdq1Izz882WxnwNJJJSWwG3gOHFhxrVWfJ25Gfcq15vsVadIabpqGqF7MiVTnMVeTfqS+9v02trRYQOYPgfkEpUR14winiy4PFl9LbKdbVCwgJLOZSnFItJQ42APFErUyCR73KnqUIL59uCIW0E2zdpXzzltNrwoX8pGxJggkIde5EsjPgAOJGBNxJ/MPzALFkWY0norGtNXicmcjG1rcj4DxOlOiydcaM9MyiLBMrdBJNBGVKKCgn1utZutDTeD6QfCKaEZNVy2X4y5/5VWs8kM/DNgeEh6pJrbri1Z8a5isD4zYqChxqiuaKGnHBZB9P625o4dhtg9UIROTbSPX56sMOKmjxo0l7Na264nWcOHvkG7e0zDoslcmrwiwKYQWWEKEAbGoTmTTu+3THprmOJicPd49FTjqXoSXvQgEYtHZoY+Ai6vRbIpBFYKseqnFHEhMy6f0D9KagHWgGT7Cb04Dc5kMGp4Vr9SKM6iWAVjDwGL+C47BQySsI1LhfkeK5SxnHMtAIhecwyx8n80J+nauVR5XpndgoZJKUAFN757hl1OYZqASFoOpGUDoc2/75r1F3DsiW7AMOkIM9htEcZyyRpoFxuvtAKsaM9s/Ee27QeyqaDbAV/r+FWyWk3FKOdsJNocu4AfVOoZy+Q92O+gkZNJjp8Y3y2A1LAnGJFPK9zhd/bqtz0GXcBmOCP9L42DW4FAL6EgGqRmBMamWJgl1GGeribMtzl5HldK/A/bGP0NrPhUOMlfl8riwxTXVZbiUZ17t8CEBMVaETRkvACgyb74KT9A2/OvQIbJkEdOOibgOsMi3QsP2GsZzrC61o+MDHwCYz5JnasZwHMuhjpdX49b+8w18GO8wcKumkNUKIJ1vMzsEqmrUWUPNztSRnqcmVZTWXQ+ciW8hpOAipAz788QXuyosK+HQAAAABJRU5ErkJggg==';
|
107 |
+
$title = 'Content Egg';
|
108 |
+
if (Plugin::isPro())
|
109 |
+
$title .= ' Pro';
|
110 |
+
\add_menu_page($title, $title, 'publish_posts', Plugin::slug, null, $icon_svg);
|
111 |
+
|
112 |
+
}
|
113 |
+
|
114 |
+
public static function render($view_name, $_data = null)
|
115 |
+
{
|
116 |
+
if (is_array($_data))
|
117 |
+
extract($_data, EXTR_PREFIX_SAME, 'data');
|
118 |
+
else
|
119 |
+
$data = $_data;
|
120 |
+
|
121 |
+
include \ContentEgg\PLUGIN_PATH . 'application/admin/views/' . TextHelper::clear($view_name) . '.php';
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Highlight menu for hidden submenu item
|
126 |
+
*/
|
127 |
+
function highlight_admin_menu($file)
|
128 |
+
{
|
129 |
+
global $plugin_page;
|
130 |
+
|
131 |
+
// options.php - hidden submenu items
|
132 |
+
if ($file != 'options.php' || substr($plugin_page, 0, strlen(Plugin::slug())) !== Plugin::slug())
|
133 |
+
return $file;
|
134 |
+
|
135 |
+
$page_parts = explode('--', $plugin_page);
|
136 |
+
if (count($page_parts) > 1)
|
137 |
+
{
|
138 |
+
$plugin_page = $page_parts[0];
|
139 |
+
} else
|
140 |
+
$plugin_page = Plugin::slug();
|
141 |
+
|
142 |
+
return $file;
|
143 |
+
}
|
144 |
+
|
145 |
+
}
|
application/admin/PrefillController.php
CHANGED
@@ -1,248 +1,250 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
$post
|
49 |
-
$post['
|
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 |
-
if (empty($_POST['
|
87 |
-
throw new \Exception("
|
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 |
-
$wordlist =
|
232 |
-
$
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
$
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
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 |
+
use ContentEgg\application\components\ContentManager;
|
12 |
+
use ContentEgg\application\libs\KeywordDensity;
|
13 |
+
use ContentEgg\application\models\AutoblogModel;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* PrefillController class file
|
17 |
+
*
|
18 |
+
* @author keywordrush.com <support@keywordrush.com>
|
19 |
+
* @link https://www.keywordrush.com
|
20 |
+
* @copyright Copyright © 2020 keywordrush.com
|
21 |
+
*/
|
22 |
+
class PrefillController {
|
23 |
+
|
24 |
+
const slug = 'content-egg-prefill';
|
25 |
+
|
26 |
+
public function __construct()
|
27 |
+
{
|
28 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
29 |
+
\add_action('wp_ajax_' . self::slug, array($this, 'addApiEntry'));
|
30 |
+
|
31 |
+
if ($GLOBALS['pagenow'] == 'admin.php' && !empty($_GET['page']) && $_GET['page'] == self::slug)
|
32 |
+
{
|
33 |
+
\wp_enqueue_script('contentegg-prefill', \ContentEgg\PLUGIN_RES . '/js/prefill.js', array('jquery'));
|
34 |
+
\wp_enqueue_script('jquery-ui-progressbar', array('jquery-ui-core'));
|
35 |
+
\wp_enqueue_style('contentegg-admin-ui-css', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/smoothness/jquery-ui.css', false, Plugin::version, false);
|
36 |
+
|
37 |
+
$post_statuses = array_merge(get_post_statuses(), array('future' => __('Future')));
|
38 |
+
$post_ids = \get_posts(array(
|
39 |
+
'post_type' => GeneralConfig::getInstance()->option('post_types'),
|
40 |
+
'numberposts' => -1,
|
41 |
+
'post_status' => array_keys($post_statuses),
|
42 |
+
'fields' => 'ids',
|
43 |
+
));
|
44 |
+
|
45 |
+
$posts = array();
|
46 |
+
foreach ($post_ids as $post_id)
|
47 |
+
{
|
48 |
+
$post = array();
|
49 |
+
$post['id'] = $post_id;
|
50 |
+
$post['post_type'] = \get_post_field('post_type', $post_id);
|
51 |
+
$post['post_status'] = \get_post_field('post_status', $post_id);
|
52 |
+
$posts[] = $post;
|
53 |
+
}
|
54 |
+
|
55 |
+
\wp_localize_script('contentegg-prefill', 'content_egg_prefill', array(
|
56 |
+
'posts' => $posts,
|
57 |
+
'nonce' => \wp_create_nonce('contentegg-prefill')
|
58 |
+
));
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
public function add_admin_menu()
|
63 |
+
{
|
64 |
+
\add_submenu_page(Plugin::slug, __('Fill', 'content-egg') . ' ‹ Content Egg', __('Fill', 'content-egg'), 'publish_posts', self::slug, array($this, 'actionIndex'));
|
65 |
+
}
|
66 |
+
|
67 |
+
public function actionIndex()
|
68 |
+
{
|
69 |
+
PluginAdmin::getInstance()->render('prefill', array(
|
70 |
+
//'nonce' => \wp_create_nonce(basename(__FILE__)),
|
71 |
+
));
|
72 |
+
}
|
73 |
+
|
74 |
+
public static function apiBase()
|
75 |
+
{
|
76 |
+
return self::slug;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function addApiEntry()
|
80 |
+
{
|
81 |
+
if (!\current_user_can('edit_posts'))
|
82 |
+
throw new \Exception("Access denied.");
|
83 |
+
|
84 |
+
\check_ajax_referer('contentegg-prefill', 'nonce');
|
85 |
+
|
86 |
+
if (empty($_POST['module_id']))
|
87 |
+
throw new \Exception("Module is undefined.");
|
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 = (int) $_POST['post_id'];
|
93 |
+
$keyword_source = InputHelper::post('keyword_source');
|
94 |
+
$autoupdate = InputHelper::post('autoupdate', false);
|
95 |
+
$autoupdate = filter_var($autoupdate, FILTER_VALIDATE_BOOLEAN);
|
96 |
+
$keyword_count = (int) InputHelper::post('keyword_count');
|
97 |
+
$minus_words = TextHelper::commaList(InputHelper::post('minus_words'));
|
98 |
+
$custom_field_names = InputHelper::post('custom_field_names', array());
|
99 |
+
$custom_field_values = InputHelper::post('custom_field_values', array());
|
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())
|
108 |
+
throw new \Exception("Parser module " . $parser->getId() . " is inactive.");
|
109 |
+
|
110 |
+
if (!$post = \get_post($post_id))
|
111 |
+
throw new \Exception("Post does not exists.");
|
112 |
+
|
113 |
+
$log = 'Post ID: ' . $post->ID;
|
114 |
+
$log .= ' (' . TextHelper::truncate($post->post_title) . ').';
|
115 |
+
|
116 |
+
// data exists?
|
117 |
+
if (ContentManager::isDataExists($post->ID, $parser->getId()))
|
118 |
+
{
|
119 |
+
$log .= ' - ' . __('Data already exist.', 'content-egg');
|
120 |
+
$this->printResult($log);
|
121 |
+
}
|
122 |
+
|
123 |
+
$keyword = $this->getKeyword($post_id, $keyword_source, $keyword_count, $custom_field);
|
124 |
+
|
125 |
+
if ($minus_words)
|
126 |
+
{
|
127 |
+
$keyword = trim(str_replace($minus_words, '', $keyword));
|
128 |
+
$keyword = preg_replace("/\s+/ui", ' ', $keyword);
|
129 |
+
}
|
130 |
+
|
131 |
+
if (!$keyword)
|
132 |
+
$this->printResult($log . ' - ' . __('Impossible to determine a keyword', 'content-egg'));
|
133 |
+
|
134 |
+
$log .= ' Keyword: "' . $keyword . '"';
|
135 |
+
|
136 |
+
// autoupdate keyword
|
137 |
+
if ($autoupdate && $parser->isAffiliateParser())
|
138 |
+
{
|
139 |
+
// exists?
|
140 |
+
if (\get_post_meta($post->ID, ContentManager::META_PREFIX_KEYWORD . $parser->getId(), true))
|
141 |
+
$this->printResult($log . ' - ' . __('Keyword for autoupdate already exists.', 'content-egg'));
|
142 |
+
|
143 |
+
// save & exit...
|
144 |
+
\update_post_meta($post->ID, ContentManager::META_PREFIX_KEYWORD . $parser->getId(), $keyword);
|
145 |
+
//$this->printResult($log . ' - ' . __('Keyword for autoupdate was saved.', 'content-egg'));
|
146 |
+
}
|
147 |
+
|
148 |
+
try
|
149 |
+
{
|
150 |
+
$data = $parser->doRequest($keyword, array(), true);
|
151 |
+
} catch (\Exception $e)
|
152 |
+
{
|
153 |
+
// error
|
154 |
+
$log .= ' - ' . __('Error:', 'content-egg') . ' ' . $e->getMessage();
|
155 |
+
$this->printResult($log);
|
156 |
+
}
|
157 |
+
|
158 |
+
// nodata!
|
159 |
+
if (!$data)
|
160 |
+
{
|
161 |
+
$log .= ' - ' . __('No data found...', 'content-egg');
|
162 |
+
$this->printResult($log);
|
163 |
+
}
|
164 |
+
|
165 |
+
// save
|
166 |
+
ContentManager::saveData($data, $parser->getId(), $post->ID);
|
167 |
+
$log .= ' - ' . __('Data saved:', 'content-egg') . ' ' . count($data) . '.';
|
168 |
+
|
169 |
+
// add custom fields
|
170 |
+
$meta_input = array();
|
171 |
+
if ($custom_field_names && is_array($custom_field_names))
|
172 |
+
{
|
173 |
+
foreach ($custom_field_names as $i => $cf_name)
|
174 |
+
{
|
175 |
+
if (!$cf_name || empty($custom_field_values[$i]))
|
176 |
+
continue;
|
177 |
+
$cf_value = $custom_field_values[$i];
|
178 |
+
if (\is_serialized($cf_value))
|
179 |
+
$cf_value = @unserialize($cf_value);
|
180 |
+
else
|
181 |
+
{
|
182 |
+
$modules_data = array($parser->getId() => $data);
|
183 |
+
$main_product = ContentManager::getMainProduct($modules_data, 'min_price');
|
184 |
+
$cf_value = AutoblogModel::buildTemplate($cf_value, $modules_data, $keyword, array(), $main_product);
|
185 |
+
}
|
186 |
+
\update_post_meta($post->ID, $cf_name, $cf_value);
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
$this->printResult($log);
|
191 |
+
}
|
192 |
+
|
193 |
+
private function printResult($mess)
|
194 |
+
{
|
195 |
+
$res = array();
|
196 |
+
$res['log'] = htmlspecialchars($mess);
|
197 |
+
header('Content-Type: application/json; charset=UTF-8');
|
198 |
+
echo json_encode($res);
|
199 |
+
\wp_die();
|
200 |
+
}
|
201 |
+
|
202 |
+
private function getKeyword($post_id, $keyword_source, $keyword_count, $meta_name = '')
|
203 |
+
{
|
204 |
+
$keyword = '';
|
205 |
+
if ($keyword_source == '_title')
|
206 |
+
{
|
207 |
+
$post = \get_post($post_id);
|
208 |
+
$keyword = $post->post_title;
|
209 |
+
} elseif ($keyword_source == '_tags')
|
210 |
+
{
|
211 |
+
$keyword = join(' ', \wp_get_post_tags($post_id, array('fields' => 'names')));
|
212 |
+
} elseif ($keyword_source == '_density')
|
213 |
+
{
|
214 |
+
$kd = new KeywordDensity(GeneralConfig::getInstance()->option('lang'));
|
215 |
+
$kd->setText($this->getDensText($post_id));
|
216 |
+
$popular = $kd->getPopularWords($keyword_count);
|
217 |
+
$keyword = join(' ', $popular);
|
218 |
+
} elseif ($keyword_source == '_custom_field')
|
219 |
+
{
|
220 |
+
if (!$meta_name)
|
221 |
+
return '';
|
222 |
+
$keyword = \get_post_meta($post_id, $meta_name, true);
|
223 |
+
} elseif (ModuleManager::getInstance()->moduleExists($keyword_source))
|
224 |
+
{
|
225 |
+
$keyword = \get_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $keyword_source, true);
|
226 |
+
}
|
227 |
+
|
228 |
+
if (!filter_var($keyword, FILTER_VALIDATE_URL))
|
229 |
+
{
|
230 |
+
// split into words
|
231 |
+
$wordlist = preg_split('/\W/u', $keyword, 0, PREG_SPLIT_NO_EMPTY);
|
232 |
+
$wordlist = array_unique($wordlist);
|
233 |
+
$wordlist = array_slice($wordlist, 0, $keyword_count);
|
234 |
+
$keyword = join(' ', $wordlist);
|
235 |
+
}
|
236 |
+
|
237 |
+
return $keyword;
|
238 |
+
}
|
239 |
+
|
240 |
+
private function getDensText($post_id)
|
241 |
+
{
|
242 |
+
$post = \get_post($post_id);
|
243 |
+
$text = $post->post_title . ' ' . $post->post_content;
|
244 |
+
|
245 |
+
$pattern = get_shortcode_regex();
|
246 |
+
$text = preg_replace('/' . $pattern . '/s', ' ', $text);
|
247 |
+
return $text;
|
248 |
+
}
|
249 |
+
|
250 |
+
}
|
application/admin/ProductController.php
CHANGED
@@ -1,64 +1,66 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
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 |
-
$forced =
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
$
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
$last_scaned_str =
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\models\ProductModel;
|
9 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* ProductController class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2018 keywordrush.com
|
17 |
+
*/
|
18 |
+
class ProductController {
|
19 |
+
|
20 |
+
const slug = 'content-egg-product';
|
21 |
+
|
22 |
+
public function __construct()
|
23 |
+
{
|
24 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
25 |
+
\add_action('admin_init', array($this, 'remove_http_referer'));
|
26 |
+
}
|
27 |
+
|
28 |
+
public function remove_http_referer()
|
29 |
+
{
|
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 |
+
\wp_redirect(\remove_query_arg(array('_wp_http_referer', '_wpnonce'), \wp_unslash($_SERVER['REQUEST_URI'])));
|
36 |
+
exit;
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
public function add_admin_menu()
|
41 |
+
{
|
42 |
+
\add_submenu_page(Plugin::slug, __('Products', 'content-egg') . ' ‹ Content Egg', __('Products', 'content-egg'), 'manage_options', self::slug, array($this, 'actionIndex'));
|
43 |
+
}
|
44 |
+
|
45 |
+
public function actionIndex()
|
46 |
+
{
|
47 |
+
\wp_enqueue_script('content-egg-blockUI', \ContentEgg\PLUGIN_RES . '/js/jquery.blockUI.js', array('jquery'));
|
48 |
+
|
49 |
+
if (isset($_GET['action']) && $_GET['action'] === 'scan')
|
50 |
+
$forced = true;
|
51 |
+
else
|
52 |
+
$forced = false;
|
53 |
+
ProductModel::model()->maybeScanProducts($forced);
|
54 |
+
$table = new ProductTable(ProductModel::model());
|
55 |
+
$table->prepare_items();
|
56 |
+
|
57 |
+
$last_scaned = ProductModel::model()->getLastSync();
|
58 |
+
if (time() - $last_scaned <= 3600)
|
59 |
+
$last_scaned_str = sprintf(__('%s ago', '%s = human-readable time difference', 'content-egg'), \human_time_diff($last_scaned, time()));
|
60 |
+
else
|
61 |
+
$last_scaned_str = TemplateHelper::dateFormatFromGmt($last_scaned, true);
|
62 |
+
|
63 |
+
PluginAdmin::getInstance()->render('product_index', array('table' => $table, 'last_scaned_str' => $last_scaned_str));
|
64 |
+
}
|
65 |
+
|
66 |
+
}
|
application/admin/ProductTable.php
CHANGED
@@ -1,232 +1,234 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\helpers\
|
9 |
-
use ContentEgg\application\components\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
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 |
-
$title =
|
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 |
-
return '<mark class="
|
80 |
-
elseif ($item['stock_status'] == ContentProduct::
|
81 |
-
return '<
|
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 |
-
$where .=
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\models\ProductModel;
|
8 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
9 |
+
use ContentEgg\application\components\ContentProduct;
|
10 |
+
use ContentEgg\application\helpers\TextHelper;
|
11 |
+
use ContentEgg\application\components\ModuleManager;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* ProductTable class file
|
15 |
+
*
|
16 |
+
* @author keywordrush.com <support@keywordrush.com>
|
17 |
+
* @link http://www.keywordrush.com/
|
18 |
+
* @copyright Copyright © 2018 keywordrush.com
|
19 |
+
*/
|
20 |
+
class ProductTable extends MyListTable {
|
21 |
+
|
22 |
+
const per_page = 15;
|
23 |
+
|
24 |
+
function get_columns()
|
25 |
+
{
|
26 |
+
return
|
27 |
+
array(
|
28 |
+
'img' => '',
|
29 |
+
'title' => ProductModel::model()->getAttributeLabel('title'),
|
30 |
+
'module_id' => __('Module', 'content-egg'),
|
31 |
+
'stock_status' => ProductModel::model()->getAttributeLabel('stock_status'),
|
32 |
+
'price' => ProductModel::model()->getAttributeLabel('price'),
|
33 |
+
'last_update' => ProductModel::model()->getAttributeLabel('last_update'),
|
34 |
+
);
|
35 |
+
}
|
36 |
+
|
37 |
+
/*
|
38 |
+
function default_orderby()
|
39 |
+
{
|
40 |
+
return 'status';
|
41 |
+
}
|
42 |
+
*
|
43 |
+
*/
|
44 |
+
|
45 |
+
function column_img($item)
|
46 |
+
{
|
47 |
+
echo '<a href="' . \esc_url(\get_edit_post_link($item['post_id'])) . '"><img class="attachment-thumbnail size-thumbnail wp-post-image" src="' . \esc_url($item['img']) . '" /></a>';
|
48 |
+
}
|
49 |
+
|
50 |
+
function column_title($item)
|
51 |
+
{
|
52 |
+
if (!trim($item['title']))
|
53 |
+
$title = __('(no title)', 'content-egg');
|
54 |
+
else
|
55 |
+
$title = TextHelper::truncate($item['title'], 80);
|
56 |
+
|
57 |
+
$edit_link = \get_edit_post_link($item['post_id']) . '#' . $item['module_id'] . '-' . $item['unique_id'];
|
58 |
+
$actions = array(
|
59 |
+
'post_id' => sprintf(__('Post ID: %d', 'content-egg'), $item['post_id']),
|
60 |
+
'edit' => sprintf('<a href="%s">%s</a>', \esc_url($edit_link), __('Edit', 'content-egg')),
|
61 |
+
);
|
62 |
+
if ($item['url'])
|
63 |
+
$actions['goto'] = sprintf('<a target="_blank" href="%s">%s</a>', \esc_url($item['url']), __('Go to', 'content-egg'));
|
64 |
+
|
65 |
+
return '<strong><a class="row-title" href="' . \esc_url($edit_link) . '">' . \esc_html($title) . '</a></strong>' .
|
66 |
+
$this->row_actions($actions);
|
67 |
+
}
|
68 |
+
|
69 |
+
function column_price($item)
|
70 |
+
{
|
71 |
+
$res = (float) $item['price_old'] ? '<del>' . \wp_kses_post(TemplateHelper::formatPriceCurrency($item['price_old'], $item['currency_code'])) . '</del>' : '';
|
72 |
+
$res .= (float) $item['price'] ? '<ins>' . \wp_kses_post(TemplateHelper::formatPriceCurrency($item['price'], $item['currency_code'])) . '</ins>' : '<span class="na">–</span>';
|
73 |
+
return $res;
|
74 |
+
}
|
75 |
+
|
76 |
+
function column_stock_status($item)
|
77 |
+
{
|
78 |
+
if ($item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK)
|
79 |
+
return '<mark class="instock">' . __('In stock', 'content-egg') . '</mark>';
|
80 |
+
elseif ($item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
81 |
+
return '<mark class="outofstock">' . __('Out of stock', 'content-egg') . '</mark>';
|
82 |
+
elseif ($item['stock_status'] == ContentProduct::STOCK_STATUS_UNKNOWN)
|
83 |
+
return '<span class="na">–</span>';
|
84 |
+
}
|
85 |
+
|
86 |
+
function column_module_id($item)
|
87 |
+
{
|
88 |
+
$module_id = $item['module_id'];
|
89 |
+
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
90 |
+
return;
|
91 |
+
$module = ModuleManager::getInstance()->factory($item['module_id']);
|
92 |
+
$output = '<strong>' . $module->getName() . '</strong>';
|
93 |
+
|
94 |
+
if (!$module->isActive())
|
95 |
+
$output .= '<br><mark class="inactive">' . __('inactive', 'content egg') . '</mark>';
|
96 |
+
|
97 |
+
return $output;
|
98 |
+
}
|
99 |
+
|
100 |
+
function column_last_update($item)
|
101 |
+
{
|
102 |
+
if (empty($item['last_update']))
|
103 |
+
return '<span class="na">–</span>';
|
104 |
+
|
105 |
+
$last_update_timestamp = strtotime($item['last_update']);
|
106 |
+
$show_date_time = TemplateHelper::dateFormatFromGmt($last_update_timestamp, true);
|
107 |
+
|
108 |
+
// last 24 hours?
|
109 |
+
if ($last_update_timestamp > strtotime('-1 day', \current_time('timestamp', true)))
|
110 |
+
{
|
111 |
+
$show_date = sprintf(
|
112 |
+
__('%s ago', '%s = human-readable time difference', 'content-egg'), \human_time_diff($last_update_timestamp, \current_time('timestamp', true))
|
113 |
+
);
|
114 |
+
} else
|
115 |
+
{
|
116 |
+
$show_date = TemplateHelper::dateFormatFromGmt($last_update_timestamp, false);
|
117 |
+
}
|
118 |
+
return sprintf(
|
119 |
+
'<abbr datetime="%1$s" title="%2$s">%3$s</abbr>', esc_attr($show_date_time), esc_attr($show_date_time), esc_html($show_date)
|
120 |
+
);
|
121 |
+
}
|
122 |
+
|
123 |
+
function get_sortable_columns()
|
124 |
+
{
|
125 |
+
$sortable_columns = array(
|
126 |
+
'price' => array('price', true),
|
127 |
+
'title' => array('title', true),
|
128 |
+
'module_id' => array('module_id', true),
|
129 |
+
'stock_status' => array('stock_status', true),
|
130 |
+
'last_update' => array('last_update', true),
|
131 |
+
);
|
132 |
+
|
133 |
+
return $sortable_columns;
|
134 |
+
}
|
135 |
+
|
136 |
+
function get_bulk_actions()
|
137 |
+
{
|
138 |
+
return array();
|
139 |
+
}
|
140 |
+
|
141 |
+
protected function extra_tablenav($which)
|
142 |
+
{
|
143 |
+
if ($which != 'top')
|
144 |
+
return;
|
145 |
+
|
146 |
+
echo '<div class="alignleft actions">';
|
147 |
+
|
148 |
+
$this->print_modules_dropdown();
|
149 |
+
\submit_button(__('Filter', 'content-egg'), '', 'filter_action', false, array('id' => 'product-query-submit'));
|
150 |
+
|
151 |
+
echo '</div>';
|
152 |
+
}
|
153 |
+
|
154 |
+
private function print_modules_dropdown()
|
155 |
+
{
|
156 |
+
$modules = ModuleManager::getInstance()->getAffiliteModulesList();
|
157 |
+
$selected_module_id = !empty($_GET['module_id']) ? TextHelper::clear(\wp_unslash($_GET['module_id'])) : '';
|
158 |
+
|
159 |
+
echo '<select name="module_id" id="dropdown_module_id"><option value="">' . \esc_html__('Filter by module', 'content-egg') . '</option>';
|
160 |
+
foreach ($modules as $module_id => $module_name)
|
161 |
+
{
|
162 |
+
echo '<option ' . \selected($module_id, $selected_module_id, false) . ' value="' . \esc_attr($module_id) . '">' . \esc_html($module_name) . '</option>';
|
163 |
+
}
|
164 |
+
echo '</select>';
|
165 |
+
}
|
166 |
+
|
167 |
+
protected function getWhereFilters()
|
168 |
+
{
|
169 |
+
global $wpdb;
|
170 |
+
|
171 |
+
$where = '';
|
172 |
+
|
173 |
+
// search
|
174 |
+
if (!empty($_REQUEST['s']))
|
175 |
+
{
|
176 |
+
$s = trim($_REQUEST['s']);
|
177 |
+
if ($where)
|
178 |
+
$where .= ' AND ';
|
179 |
+
|
180 |
+
if (is_numeric($s))
|
181 |
+
$where .= 'post_id = ' . (int) $s;
|
182 |
+
else
|
183 |
+
$where .= $wpdb->prepare('title LIKE %s', '%' . $wpdb->esc_like(\sanitize_text_field($s)) . '%');
|
184 |
+
}
|
185 |
+
|
186 |
+
// filters
|
187 |
+
if (isset($_GET['stock_status']) && $_GET['stock_status'] !== '' && $_GET['stock_status'] !== 'all')
|
188 |
+
{
|
189 |
+
$stock_status = (int) $_GET['stock_status'];
|
190 |
+
|
191 |
+
if (array_key_exists($stock_status, ProductModel::getStockStatuses()))
|
192 |
+
{
|
193 |
+
if ($where)
|
194 |
+
$where .= ' AND ';
|
195 |
+
|
196 |
+
$where .= $wpdb->prepare('stock_status = %d', $stock_status);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
if (isset($_GET['module_id']) && $_GET['module_id'] !== '')
|
201 |
+
{
|
202 |
+
$module_id = TextHelper::clear(\wp_unslash($_GET['module_id']));
|
203 |
+
if (ModuleManager::getInstance()->moduleExists($module_id))
|
204 |
+
{
|
205 |
+
if ($where)
|
206 |
+
$where .= ' AND ';
|
207 |
+
$where .= $wpdb->prepare('module_id = %s', $module_id);
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
return $where;
|
212 |
+
}
|
213 |
+
|
214 |
+
protected function get_views()
|
215 |
+
{
|
216 |
+
$status_links = array();
|
217 |
+
$class = (!isset($_REQUEST['stock_status']) || $_REQUEST['stock_status'] === '' || $_REQUEST['stock_status'] === 'all') ? ' class="current"' : '';
|
218 |
+
$admin_url = \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-product');
|
219 |
+
|
220 |
+
$statuses = ProductModel::getStockStatuses();
|
221 |
+
$total = ProductModel::model()->count();
|
222 |
+
$status_links['all'] = '<a href="' . $admin_url . '&stock_status=all"' . $class . '>' . __('All', 'content-egg') . sprintf(' <span class="count">(%s)</span></a>', \number_format_i18n($total));
|
223 |
+
foreach ($statuses as $status_id => $status_name)
|
224 |
+
{
|
225 |
+
$total = ProductModel::model()->count('stock_status = ' . (int) $status_id);
|
226 |
+
$class = (isset($_REQUEST['stock_status']) && $_REQUEST['stock_status'] !== '' && (int) $_REQUEST['stock_status'] == $status_id) ? ' class="current"' : '';
|
227 |
+
$status_links[$status_id] = '<a href="' . $admin_url . '&stock_status=' . (int) $status_id . '"' . $class . '>' . \esc_html($status_name);
|
228 |
+
$status_links[$status_id] .= sprintf(' <span class="count">(%s)</span></a>', \number_format_i18n($total));
|
229 |
+
}
|
230 |
+
|
231 |
+
return $status_links;
|
232 |
+
}
|
233 |
+
|
234 |
+
}
|
application/admin/ToolsController.php
CHANGED
@@ -1,138 +1,140 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\admin;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
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 |
-
$csv_line
|
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 |
-
$csv_line['
|
125 |
-
$csv_line['
|
126 |
-
$csv_line['
|
127 |
-
$csv_line['
|
128 |
-
$csv_line['
|
129 |
-
$
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\admin;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\models\PriceAlertModel;
|
8 |
+
use ContentEgg\application\helpers\FileHelper;
|
9 |
+
use ContentEgg\application\helpers\TextHelper;
|
10 |
+
use ContentEgg\application\components\ContentManager;
|
11 |
+
use ContentEgg\application\components\ModuleManager;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* ToolsController class file
|
15 |
+
*
|
16 |
+
* @author keywordrush.com <support@keywordrush.com>
|
17 |
+
* @link http://www.keywordrush.com/
|
18 |
+
* @copyright Copyright © 2017 keywordrush.com
|
19 |
+
*/
|
20 |
+
class ToolsController {
|
21 |
+
|
22 |
+
const slug = 'content-egg-tools';
|
23 |
+
|
24 |
+
public function __construct()
|
25 |
+
{
|
26 |
+
\add_action('admin_menu', array($this, 'actionHandler'));
|
27 |
+
}
|
28 |
+
|
29 |
+
public function actionHandler()
|
30 |
+
{
|
31 |
+
if (empty($GLOBALS['pagenow']) || $GLOBALS['pagenow'] != 'admin.php')
|
32 |
+
return;
|
33 |
+
|
34 |
+
if (empty($_GET['page']) || $_GET['page'] != 'content-egg-tools')
|
35 |
+
return;
|
36 |
+
|
37 |
+
if (!empty($_GET['action']) && $_GET['action'] == 'subscribers-export')
|
38 |
+
{
|
39 |
+
$this->actionSubscribersExport();
|
40 |
+
}
|
41 |
+
|
42 |
+
if (!empty($_GET['action']) && $_GET['action'] == 'offer-urls-export')
|
43 |
+
{
|
44 |
+
$this->actionOfferUrlsExport();
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
public function actionSubscribersExport()
|
49 |
+
{
|
50 |
+
if (!\current_user_can('administrator'))
|
51 |
+
die('You do not have permission to view this page.');
|
52 |
+
|
53 |
+
$where = array();
|
54 |
+
if (!empty($_GET['active_only']) && (bool) $_GET['active_only'])
|
55 |
+
$where = array('where' => 'status = ' . PriceAlertModel::STATUS_ACTIVE);
|
56 |
+
$subscribers = $total_price_alerts = PriceAlertModel::model()->findAll($where);
|
57 |
+
|
58 |
+
$csv_arr = array();
|
59 |
+
$ignore_fields = array('activkey', 'email', 'status');
|
60 |
+
foreach ($subscribers as $subscriber)
|
61 |
+
{
|
62 |
+
$csv_line = array();
|
63 |
+
$csv_line['email'] = $subscriber['email'];
|
64 |
+
$csv_line['status'] = PriceAlertModel::getStatus($subscriber['status']);
|
65 |
+
|
66 |
+
foreach ($subscriber as $key => $s)
|
67 |
+
{
|
68 |
+
if (in_array($key, $ignore_fields))
|
69 |
+
continue;
|
70 |
+
$csv_line[$key] = $s;
|
71 |
+
}
|
72 |
+
|
73 |
+
$unsubscribe_all_url = \add_query_arg(array(
|
74 |
+
'ceggaction' => 'unsubscribe',
|
75 |
+
'email' => urlencode($subscriber['email']),
|
76 |
+
'key' => urlencode($subscriber['activkey']),
|
77 |
+
), \get_site_url());
|
78 |
+
$delete_url = \add_query_arg(array(
|
79 |
+
'ceggaction' => 'delete',
|
80 |
+
'email' => urlencode($subscriber['email']),
|
81 |
+
'key' => urlencode($subscriber['activkey']),
|
82 |
+
), \get_site_url());
|
83 |
+
|
84 |
+
$csv_line['unsubscribe_url'] = $unsubscribe_all_url;
|
85 |
+
$csv_line['delete_url'] = $delete_url;
|
86 |
+
|
87 |
+
$csv_arr[] = $csv_line;
|
88 |
+
}
|
89 |
+
$filename = 'subscribers-' . date('d-m-Y') . '.csv';
|
90 |
+
FileHelper::sendDownloadHeaders($filename);
|
91 |
+
echo FileHelper::array2Csv($csv_arr);
|
92 |
+
exit;
|
93 |
+
}
|
94 |
+
|
95 |
+
public function actionOfferUrlsExport()
|
96 |
+
{
|
97 |
+
if (!\current_user_can('administrator'))
|
98 |
+
die('You do not have permission to view this page.');
|
99 |
+
|
100 |
+
if (isset($_GET['module']))
|
101 |
+
$module_id = TextHelper::clear($_GET['module']);
|
102 |
+
else
|
103 |
+
die('Module param can not be empty.');
|
104 |
+
|
105 |
+
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
106 |
+
die('The module does not exist.');
|
107 |
+
|
108 |
+
global $wpdb;
|
109 |
+
|
110 |
+
$sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE "%s"', $wpdb->esc_like(ContentManager::META_PREFIX_DATA . $module_id));
|
111 |
+
|
112 |
+
$results = $wpdb->get_results($sql, \ARRAY_A);
|
113 |
+
|
114 |
+
$csv_arr = array();
|
115 |
+
foreach ($results as $result)
|
116 |
+
{
|
117 |
+
if (!$data = unserialize($result['meta_value']))
|
118 |
+
continue;
|
119 |
+
|
120 |
+
$csv_line = array();
|
121 |
+
$csv_line['post_id'] = $result['post_id'];
|
122 |
+
foreach ($data as $d)
|
123 |
+
{
|
124 |
+
$csv_line['title'] = $d['title'];
|
125 |
+
$csv_line['price'] = $d['price'];
|
126 |
+
$csv_line['priceOld'] = $d['priceOld'];
|
127 |
+
$csv_line['currencyCode'] = $d['currencyCode'];
|
128 |
+
$csv_line['url'] = $d['url'];
|
129 |
+
$csv_line['orig_url'] = $d['orig_url'];
|
130 |
+
$csv_line['img'] = $d['img'];
|
131 |
+
$csv_arr[] = $csv_line;
|
132 |
+
}
|
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 |
+
|
140 |
+
}
|
application/admin/index.php
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
// Silence is golden.
|
1 |
+
<?php
|
2 |
+
|
3 |
// Silence is golden.
|
application/admin/views/_metabox_autoblog.php
CHANGED
@@ -1,476 +1,488 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
use ContentEgg\application\
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
<option value="
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
<option value="
|
40 |
-
<option value="
|
41 |
-
<option value="
|
42 |
-
<option value="
|
43 |
-
<option value="
|
44 |
-
<option value="
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
<button
|
62 |
-
<button href="#" id="
|
63 |
-
<button href="#" id="
|
64 |
-
<button href="#" id="
|
65 |
-
<button href="#" id="
|
66 |
-
|
67 |
-
|
68 |
-
<
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
<li><a href="#fragment-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
</div>
|
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 |
-
<?php _e('
|
162 |
-
|
163 |
-
<br
|
164 |
-
<b>
|
165 |
-
|
166 |
-
<br>
|
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 |
-
<?php
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
</
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
</
|
268 |
-
</td>
|
269 |
-
</tr>
|
270 |
-
|
271 |
-
<tr class="form-field">
|
272 |
-
<th valign="top" scope="row">
|
273 |
-
<label for="
|
274 |
-
</th>
|
275 |
-
<td>
|
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 |
-
<?php
|
323 |
-
|
324 |
-
|
325 |
-
<?php
|
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 |
-
<?php
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
defined('\ABSPATH') || exit;
|
3 |
+
|
4 |
+
use ContentEgg\application\components\ModuleManager;
|
5 |
+
use ContentEgg\application\helpers\AdminHelper;
|
6 |
+
?>
|
7 |
+
<table cellspacing="2" cellpadding="5" style="width: 100%;" class="form-table">
|
8 |
+
<tbody>
|
9 |
+
|
10 |
+
<tr class="form-field">
|
11 |
+
<th valign="top" scope="row">
|
12 |
+
<label for="name"><?php _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 _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 _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 _e('Works', 'content-egg'); ?></option>
|
27 |
+
<option value="0"<?php if (!$item['status']) echo ' selected="selected"'; ?>><?php _e('Stoped', 'content-egg'); ?></option>
|
28 |
+
</select>
|
29 |
+
<p class="description"><?php _e('You can stop autoblogging.', 'content-egg'); ?></p>
|
30 |
+
</td>
|
31 |
+
</tr>
|
32 |
+
|
33 |
+
<tr class="form-field">
|
34 |
+
<th valign="top" scope="row">
|
35 |
+
<label for="run_frequency"><?php _e('Work frequency', 'content-egg'); ?></label>
|
36 |
+
</th>
|
37 |
+
<td>
|
38 |
+
<select id="run_frequency" name="item[run_frequency]">
|
39 |
+
<option value="3600"<?php if ($item['run_frequency'] == 3600) echo ' selected="selected"'; ?>><?php _e('Every hour', 'content-egg'); ?></option>
|
40 |
+
<option value="17280"<?php if ($item['run_frequency'] == 17280) echo ' selected="selected"'; ?>><?php _e('5 times in a day', 'content-egg'); ?></option>
|
41 |
+
<option value="43200"<?php if ($item['run_frequency'] == 43200) echo ' selected="selected"'; ?>><?php _e('Twice daily', 'content-egg'); ?></option>
|
42 |
+
<option value="86400"<?php if ($item['run_frequency'] == 86400) echo ' selected="selected"'; ?>><?php _e('Once a day', 'content-egg'); ?></option>
|
43 |
+
<option value="259200"<?php if ($item['run_frequency'] == 259200) echo ' selected="selected"'; ?>><?php _e('Each three days', 'content-egg'); ?></option>
|
44 |
+
<option value="604800"<?php if ($item['run_frequency'] == 604800) echo ' selected="selected"'; ?>><?php _e('Once a week', 'content-egg'); ?></option>
|
45 |
+
<option value="1209600"<?php if ($item['run_frequency'] == 1209600) echo ' selected="selected"'; ?>><?php _e('Once in 2 weeks', 'content-egg'); ?></option>
|
46 |
+
</select>
|
47 |
+
<p class="description"><?php _e('How often autoblogging will run this task', 'content-egg'); ?></p>
|
48 |
+
</td>
|
49 |
+
</tr>
|
50 |
+
<?php if (!$batch): ?>
|
51 |
+
<tr class="form-field">
|
52 |
+
<th valign="top" scope="row">
|
53 |
+
<label for="keywords"><?php _e('Keywords', 'content-egg'); ?></label>
|
54 |
+
</th>
|
55 |
+
<td>
|
56 |
+
|
57 |
+
<table width='100%'>
|
58 |
+
<tr>
|
59 |
+
<td valign="top" style="vertical-align: top;" width="50%">
|
60 |
+
<div style="margin-bottom: 10px;">
|
61 |
+
<button id="tool_capitalise" title="<?php _e('Uppercase First Letter for Each Word', 'content-egg'); ?>"><span class="ui-icon ui-icon-arrowthick-1-n"></span></button>
|
62 |
+
<button href="#" id="tool_upper_first" title="<?php _e('Uppercase first letter', 'content-egg'); ?>"><span class="ui-icon ui-icon-carat-1-n"></span></button>
|
63 |
+
<button href="#" id="tool_sort" title="<?php _e('Sort with alpha order', 'content-egg'); ?>"><span class="ui-icon ui-icon-arrow-1-s"></span></button>
|
64 |
+
<button href="#" id="tool_add_minus" title="<?php _e('All words are inactive', 'content-egg'); ?>"><span class="ui-icon ui-icon-minus"></span></button>
|
65 |
+
<button href="#" id="tool_del_minus" title="<?php _e('All words are active', 'content-egg'); ?>"><span class="ui-icon ui-icon-plus"></span></button>
|
66 |
+
<button href="#" id="tool_delete" title="<?php _e('Clear list', 'content-egg'); ?>"><span class="ui-icon ui-icon-closethick"></span></button>
|
67 |
+
</div>
|
68 |
+
<textarea rows="28" id="keywords" name="item[keywords]" class="small-text"><?php echo esc_html($item['keywords']) ?></textarea>
|
69 |
+
<div>
|
70 |
+
<?php _e('Total', 'content-egg'); ?>: <b><span id="k_count">0</span></b>
|
71 |
+
</div>
|
72 |
+
</td>
|
73 |
+
<td valign="top" style="vertical-align: top;">
|
74 |
+
<div id="cegg-parsers-tabs">
|
75 |
+
<ul>
|
76 |
+
<li><a href="#fragment-1"><?php _e('Hints', 'content-egg'); ?></a></li>
|
77 |
+
<?php /*
|
78 |
+
<li><a href="#fragment-2"><?php _e('Trends', 'content-egg'); ?></a></a></li>
|
79 |
+
<li><a href="#fragment-3"><?php _e('Products', 'content-egg'); ?></a></a></li>
|
80 |
+
*
|
81 |
+
*/
|
82 |
+
?>
|
83 |
+
</ul>
|
84 |
+
<div id="fragment-1">
|
85 |
+
|
86 |
+
|
87 |
+
<div id="sug_btn_group" class="btn-group" data-toggle="buttons-radio" style="margin-bottom: 10px;">
|
88 |
+
<input id="sug_google" name="sug_radio" value="sug_google" type="radio" checked="checked"><label for="sug_google">Google</label>
|
89 |
+
<input id="sug_amazon" name="sug_radio" value="sug_amazon" type="radio"><label for="sug_amazon">Amazon</label>
|
90 |
+
<?php if (\ContentEgg\application\admin\GeneralConfig::getInstance()->option('lang') == 'ru'): ?>
|
91 |
+
<input id="sug_yandex" name="sug_radio" value="sug_yandex" type="radio"><label for="sug_yandex"><?php _e('Yandex', 'content-egg'); ?></label>
|
92 |
+
<input id="sug_market" name="sug_radio" value="sug_market" type="radio"><label for="sug_market"><?php _e('Yandex.Market', 'content-egg'); ?></label>
|
93 |
+
<?php endif; ?>
|
94 |
+
</div>
|
95 |
+
<input type="text" id="sug_query" placeholder="<?php _e('Start enter keyword', 'content-egg'); ?>" />
|
96 |
+
<select multiple="multiple" id="sug_keywords" style="width: 98%" size="23"></select>
|
97 |
+
</div>
|
98 |
+
<?php /*
|
99 |
+
|
100 |
+
<div id="fragment-2">
|
101 |
+
<div style="margin-bottom: 10px;">
|
102 |
+
<button id="trend_google" type="button">Hot Trends...</button>
|
103 |
+
</div>
|
104 |
+
<select multiple="multiple" id="trend_keywords" style="width: 98%" size="24"></select>
|
105 |
+
</div>
|
106 |
+
<div id="fragment-3">
|
107 |
+
<div style="margin-bottom: 10px;">
|
108 |
+
|
109 |
+
<select id='amazon_categ'>
|
110 |
+
<?php foreach ($item['amazon_categs'] as $ac_value => $ac_name): ?>
|
111 |
+
<option value='<?php echo $ac_value; ?>'><?php echo $ac_name; ?></option>
|
112 |
+
<?php endforeach; ?>
|
113 |
+
</select>
|
114 |
+
<select id='amazon_section'>
|
115 |
+
<option value='bestsellers'>Bestsellers</option>
|
116 |
+
<option value='new-releases'>New Releases</option>
|
117 |
+
<option value='movers-and-shakers'>Movers and Shakers</option>
|
118 |
+
<option value='top-rated'>Top Rated</option>
|
119 |
+
<option value='most-wished-for'>Most Wished For</option>
|
120 |
+
<option value='most-gifted'>Most Gifted</option>
|
121 |
+
</select>
|
122 |
+
<button id="trend_goods" type="button"><?php _e('Load...', 'content-egg'); ?></button>
|
123 |
+
|
124 |
+
</div>
|
125 |
+
<select multiple="multiple" id="goods_keywords" style="width: 98%" size="24"></select>
|
126 |
+
|
127 |
+
|
128 |
+
</div>
|
129 |
+
*
|
130 |
+
*/
|
131 |
+
?>
|
132 |
+
</div>
|
133 |
+
</td>
|
134 |
+
</tr>
|
135 |
+
</table>
|
136 |
+
<p class="">
|
137 |
+
<?php _e('Each keyword from separate line.', 'content-egg'); ?>
|
138 |
+
<?php _e('One keyword is one post.', 'content-egg'); ?>
|
139 |
+
<?php _e('Handled keywords are marked by [brackets].', 'content-egg'); ?>
|
140 |
+
<?php _e('When all keywords will be processed, task will stop.', 'content-egg'); ?>
|
141 |
+
</p>
|
142 |
+
<p class="">
|
143 |
+
<?php _e('You can also use separate keywords for some modules:', 'content-egg'); ?><br>
|
144 |
+
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
145 |
+
</p>
|
146 |
+
|
147 |
+
</td>
|
148 |
+
</tr>
|
149 |
+
<?php endif; ?>
|
150 |
+
<?php if ($batch): ?>
|
151 |
+
<tr class="form-field">
|
152 |
+
<th valign="top" scope="row">
|
153 |
+
<label for="keywords_file"><?php _e('Keywords', 'content-egg'); ?></label>
|
154 |
+
</th>
|
155 |
+
|
156 |
+
<td>
|
157 |
+
<input id="keywords_file" type="file" name="item[keywords_file]" value="" />
|
158 |
+
|
159 |
+
<p class="description">
|
160 |
+
|
161 |
+
<?php _e('Two format are supported: ', 'content-egg'); ?>
|
162 |
+
<br>
|
163 |
+
<br>
|
164 |
+
<b>1. <?php _e('CSV files in format:', 'content-egg'); ?></b>
|
165 |
+
<br>
|
166 |
+
<code>category 1;keyword 1<br>
|
167 |
+
category 1;keyword 2<br>
|
168 |
+
category 2;keyword 3<br>
|
169 |
+
category 2;keyword 4<br>
|
170 |
+
...
|
171 |
+
</code>
|
172 |
+
<br>
|
173 |
+
<?php _e('Divider - ";"', 'content-egg'); ?><br>
|
174 |
+
<?php _e('For each category will be created separate task for autoblog.', 'content-egg'); ?>
|
175 |
+
<br><br>
|
176 |
+
<b>2. <?php _e('TXT files:', 'content-egg'); ?></b><br>
|
177 |
+
<?php _e('Simple text file with list of keywords (each word from separate line).', 'content-egg'); ?>
|
178 |
+
<br>
|
179 |
+
<?php _e('File must be in UTF-8', 'content-egg'); ?>
|
180 |
+
<br><br>
|
181 |
+
<?php _e('You can also use separate keywords for some modules:', 'content-egg'); ?><br>
|
182 |
+
<code>Main Keyword;ModuleId1:Keyword 1;ModuleId2:Keyword 2;</code>
|
183 |
+
|
184 |
+
</p>
|
185 |
+
</td>
|
186 |
+
</tr>
|
187 |
+
|
188 |
+
<?php endif; ?>
|
189 |
+
|
190 |
+
<tr class="form-field">
|
191 |
+
<th valign="top" scope="row">
|
192 |
+
<label for="keywords_per_run"><?php _e('Keywords for handle', 'content-egg'); ?></label>
|
193 |
+
</th>
|
194 |
+
<td>
|
195 |
+
<input id="keywords_per_run" name="item[keywords_per_run]" value="<?php echo esc_attr($item['keywords_per_run']) ?>"
|
196 |
+
type="number" class="small-text">
|
197 |
+
<p class="description"><?php _e('How many keywords to process at once. We don\'t recommend to use more than 5 keywords.', 'content-egg'); ?></p>
|
198 |
+
</td>
|
199 |
+
</tr>
|
200 |
+
<tr class="form-field">
|
201 |
+
<th valign="top" scope="row">
|
202 |
+
<label for="template_title"><?php _e('Title template', 'content-egg'); ?></label>
|
203 |
+
</th>
|
204 |
+
<td>
|
205 |
+
|
206 |
+
<input id="template_title" name="item[template_title]" value="<?php echo esc_attr($item['template_title']) ?>"
|
207 |
+
type="text" class="regular-text ltr">
|
208 |
+
<p class="description">
|
209 |
+
<?php _e('Template for title of post', 'content-egg'); ?>
|
210 |
+
<?php _e('Use tags:', 'content-egg'); ?> %KEYWORD%, %KEYWORD.ModuleID%, %PRODUCT.title%, %PRODUCT.price%, %PRODUCT.merchant%, %PRODUCT.domain%, %PRODUCT.manufacturer%,...<br>
|
211 |
+
<?php _e('For display data of plugin use special tags, for example:', 'content-egg'); ?> %Amazon.title%.<br>
|
212 |
+
<?php _e('You also can set index number for access to data of plugin', 'content-egg'); ?> %Amazon.0.price%.<br>
|
213 |
+
<?php _e('You can use "formulas" with synonyms, of which one will be selected with a random option, for example, {Discount|Sale|Cheap}.', 'content-egg'); ?>
|
214 |
+
</p>
|
215 |
+
</td>
|
216 |
+
</tr>
|
217 |
+
|
218 |
+
<tr class="form-field">
|
219 |
+
<th valign="top" scope="row">
|
220 |
+
<label for="template_body"><?php _e('Template for post.', 'content-egg'); ?></label>
|
221 |
+
</th>
|
222 |
+
<td>
|
223 |
+
|
224 |
+
<textarea rows="4" id="template_body" name="item[template_body]"><?php echo esc_html($item['template_body']) ?></textarea>
|
225 |
+
<p class="description">
|
226 |
+
<?php _e('Template for body of post.', 'content-egg'); ?><br>
|
227 |
+
<?php _e('You can use shortcodes, for example:', 'content-egg'); ?>
|
228 |
+
[content-egg module=Amazon template=grid]<br>
|
229 |
+
<?php _e('"Formulas", and also all tags from title template, will also work here.', 'content-egg'); ?><br>
|
230 |
+
|
231 |
+
</p>
|
232 |
+
</td>
|
233 |
+
</tr>
|
234 |
+
<tr class="form-field">
|
235 |
+
<th valign="top" scope="row">
|
236 |
+
<label for="include_modules"><?php _e('Only selected modules', 'content-egg'); ?></label>
|
237 |
+
</th>
|
238 |
+
<td>
|
239 |
+
<div class="cegg-checkboxgroup">
|
240 |
+
<?php foreach (ModuleManager::getInstance()->getParserModules(false) as $module): ?>
|
241 |
+
<div class="cegg-checkbox">
|
242 |
+
<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>
|
243 |
+
</div>
|
244 |
+
<?php endforeach; ?>
|
245 |
+
</div>
|
246 |
+
<p class="description">
|
247 |
+
<?php _e('Run only selected modules for this task.', 'content-egg'); ?>
|
248 |
+
<?php _e('If you don\'t select any modules, all active modules will be used.', 'content-egg'); ?>
|
249 |
+
</p>
|
250 |
+
</td>
|
251 |
+
</tr>
|
252 |
+
|
253 |
+
<tr class="form-field">
|
254 |
+
<th valign="top" scope="row">
|
255 |
+
<label for="exclude_modules"><?php _e('Exclude modules', 'content-egg'); ?></label>
|
256 |
+
</th>
|
257 |
+
<td>
|
258 |
+
<div class="cegg-checkboxgroup">
|
259 |
+
<?php foreach (ModuleManager::getInstance()->getParserModules(false) as $module): ?>
|
260 |
+
<div class="cegg-checkbox">
|
261 |
+
<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>
|
262 |
+
</div>
|
263 |
+
<?php endforeach; ?>
|
264 |
+
</div>
|
265 |
+
<p class="description">
|
266 |
+
<?php _e('Chosen modules will not run in this configuration. ', 'content-egg'); ?>
|
267 |
+
</p>
|
268 |
+
</td>
|
269 |
+
</tr>
|
270 |
+
|
271 |
+
<tr class="form-field">
|
272 |
+
<th valign="top" scope="row">
|
273 |
+
<label for="post_status"><?php _e('Post status', 'content-egg'); ?></label>
|
274 |
+
</th>
|
275 |
+
<td>
|
276 |
+
<select id="post_status" name="item[post_status]">
|
277 |
+
<option value="1"<?php if ($item['post_status'] == 1) echo ' selected="selected"'; ?>>Publish</option>
|
278 |
+
<option value="0"<?php if ($item['post_status'] == 0) echo ' selected="selected"'; ?>>Pending</option>
|
279 |
+
</select>
|
280 |
+
</td>
|
281 |
+
</tr>
|
282 |
+
|
283 |
+
<tr class="form-field">
|
284 |
+
<th valign="top" scope="row">
|
285 |
+
<label for="post_type"><?php _e('Post type', 'content-egg'); ?></label>
|
286 |
+
</th>
|
287 |
+
<td>
|
288 |
+
<?php
|
289 |
+
$post_types = \get_post_types(array('public' => true), 'names');
|
290 |
+
if (isset($post_types['attachment']))
|
291 |
+
unset($post_types['attachment']);
|
292 |
+
?>
|
293 |
+
<select id="post_type" name="item[post_type]">
|
294 |
+
<?php foreach ($post_types as $post_type): ?>
|
295 |
+
<option value="<?php echo \esc_attr($post_type); ?>"<?php if ($item['post_type'] == $post_type) echo ' selected="selected"'; ?>><?php echo \esc_html($post_type); ?></option>
|
296 |
+
<?php endforeach; ?>
|
297 |
+
</select>
|
298 |
+
</td>
|
299 |
+
</tr>
|
300 |
+
|
301 |
+
<tr class="form-field">
|
302 |
+
<th valign="top" scope="row">
|
303 |
+
<label for="user_id"><?php _e('User', 'content-egg'); ?></label>
|
304 |
+
</th>
|
305 |
+
<td>
|
306 |
+
<?php
|
307 |
+
\wp_dropdown_users(array('name' => 'item[user_id]',
|
308 |
+
'who' => 'authors', 'id' => 'user_id', 'selected' => $item['user_id']));
|
309 |
+
?>
|
310 |
+
<p class="description"><?php _e('This user will be author of posts.', 'content-egg'); ?></p>
|
311 |
+
</td>
|
312 |
+
</tr>
|
313 |
+
|
314 |
+
<tr class="form-field">
|
315 |
+
<th valign="top" scope="row">
|
316 |
+
<label for="category"><?php _e('Category ', 'content-egg'); ?></label>
|
317 |
+
</th>
|
318 |
+
<td>
|
319 |
+
<?php $categories = AdminHelper::getCategoryList(); ?>
|
320 |
+
|
321 |
+
<select name="item[category]" id="category">
|
322 |
+
<?php if ($batch): ?>
|
323 |
+
<option value="-1" <?php \selected($item['category'], -1); ?>>[ <?php _e('Create Automatically', 'content-egg'); ?> ]</option>
|
324 |
+
<?php endif; ?>
|
325 |
+
<?php foreach ($categories as $c_id => $c_name): ?>
|
326 |
+
<option value="<?php echo \esc_attr($c_id); ?>" <?php \selected($item['category'], $c_id); ?>>
|
327 |
+
<?php echo \esc_attr($c_name); ?>
|
328 |
+
</option>
|
329 |
+
<?php endforeach; ?>
|
330 |
+
</select>
|
331 |
+
|
332 |
+
|
333 |
+
<p class="description">
|
334 |
+
<?php _e('Default category for posts.', 'content-egg'); ?>
|
335 |
+
<?php if ($batch): ?>
|
336 |
+
<?php _e('"Create Automatically" means, that categories will be created based on data of CSV file with keywords and categories.', 'content-egg'); ?>
|
337 |
+
<?php endif; ?>
|
338 |
+
</p>
|
339 |
+
</td>
|
340 |
+
</tr>
|
341 |
+
|
342 |
+
<tr class="form-field">
|
343 |
+
<th valign="top" scope="row">
|
344 |
+
<label for="dynamic_categories"><?php _e('Dynamic categories', 'content-egg'); ?></label>
|
345 |
+
</th>
|
346 |
+
<td>
|
347 |
+
<select id="post_status" name="item[config][dynamic_categories]">
|
348 |
+
<option value="0"<?php if ($item['config']['dynamic_categories'] == 0) echo ' selected="selected"'; ?>><?php _e('Do not create', 'content-egg'); ?></option>
|
349 |
+
<option value="1"<?php if ($item['config']['dynamic_categories'] == 1) echo ' selected="selected"'; ?>><?php _e('Create category', 'content-egg'); ?></option>
|
350 |
+
<option value="2"<?php if ($item['config']['dynamic_categories'] == 2) echo ' selected="selected"'; ?>><?php _e('Create nested categories', 'content-egg'); ?></option>
|
351 |
+
</select>
|
352 |
+
<p class="description"><?php _e('Create a category automatically, if the main product has a category data.', 'content-egg'); ?></p>
|
353 |
+
</td>
|
354 |
+
</tr>
|
355 |
+
|
356 |
+
<tr class="form-field">
|
357 |
+
<th valign="top" scope="row">
|
358 |
+
<label for="min_modules_count"><?php _e('Minimum modules required', 'content-egg'); ?></label>
|
359 |
+
</th>
|
360 |
+
<td>
|
361 |
+
<input id="min_modules_count" name="item[min_modules_count]" value="<?php echo esc_attr($item['min_modules_count']) ?>"
|
362 |
+
type="number" class="small-text">
|
363 |
+
<p class="description"><?php _e('Post will not be published if no content for such number of modules.', 'content-egg'); ?></p>
|
364 |
+
</td>
|
365 |
+
</tr>
|
366 |
+
|
367 |
+
<tr class="form-field">
|
368 |
+
<th valign="top" scope="row">
|
369 |
+
<label for="min_comment_count"><?php _e('Minimum reviews required', 'content-egg'); ?></label>
|
370 |
+
</th>
|
371 |
+
<td>
|
372 |
+
<input id="min_modules_count" name="item[config][min_comments_count]" value="<?php echo esc_attr($item['config']['min_comments_count']) ?>"
|
373 |
+
type="number" class="small-text">
|
374 |
+
<p class="description"><?php _e('Post will not be published if there are no user reviews. This option works only for AE modules.', 'content-egg'); ?></p>
|
375 |
+
</td>
|
376 |
+
</tr>
|
377 |
+
|
378 |
+
<tr class="form-field">
|
379 |
+
<th valign="top" scope="row">
|
380 |
+
<label for="autoupdate_modules"><?php _e('Update by keyword', 'content-egg'); ?></label>
|
381 |
+
</th>
|
382 |
+
<td>
|
383 |
+
<div class="cegg-checkboxgroup">
|
384 |
+
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers(false) as $module): ?>
|
385 |
+
<div class="cegg-checkbox">
|
386 |
+
<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>
|
387 |
+
</div>
|
388 |
+
<?php endforeach; ?>
|
389 |
+
</div>
|
390 |
+
<p class="description">
|
391 |
+
<?php _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'); ?>
|
392 |
+
</p>
|
393 |
+
</td>
|
394 |
+
</tr>
|
395 |
+
<tr class="form-field">
|
396 |
+
<th valign="top" scope="row">
|
397 |
+
<label for="required_modules"><?php _e('Required modules', 'content-egg'); ?></label>
|
398 |
+
</th>
|
399 |
+
<td>
|
400 |
+
<div class="cegg-checkboxgroup">
|
401 |
+
<?php foreach (ModuleManager::getInstance()->getParserModules(false) as $module): ?>
|
402 |
+
<div class="cegg-checkbox">
|
403 |
+
<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>
|
404 |
+
</div>
|
405 |
+
<?php endforeach; ?>
|
406 |
+
</div>
|
407 |
+
<p class="description">
|
408 |
+
<?php _e('Post will not be publicized if no results for these modules.', 'content-egg'); ?>
|
409 |
+
</p>
|
410 |
+
</td>
|
411 |
+
</tr>
|
412 |
+
|
413 |
+
<tr class="form-field">
|
414 |
+
<th valign="top" scope="row">
|
415 |
+
<label for="main_product"><?php _e('Main product', 'content-egg'); ?></label>
|
416 |
+
</th>
|
417 |
+
<td>
|
418 |
+
<select id="main_product" name="item[main_product]">
|
419 |
+
<option value="min_price"<?php if ($item['main_product'] == 'min_price') echo ' selected="selected"'; ?>><?php _e('Minimum price', 'content-egg'); ?></option>
|
420 |
+
<option value="max_price"<?php if ($item['main_product'] == 'max_price') echo ' selected="selected"'; ?>><?php _e('Maximum price', 'content-egg'); ?></option>
|
421 |
+
<option value="random"<?php if ($item['main_product'] == 'random') echo ' selected="selected"'; ?>><?php _e('Random', 'content-egg'); ?></option>
|
422 |
+
</select>
|
423 |
+
<p class="description">
|
424 |
+
<?php _e('How to choose "main" product?', 'content-egg'); ?>
|
425 |
+
<?php _e('Then you can use tags:', 'content-egg'); ?> %PRODUCT.title%, %PRODUCT.price%, %PRODUCT.merchant%, %PRODUCT.domain%, %PRODUCT.manufacturer%,...
|
426 |
+
</p>
|
427 |
+
</td>
|
428 |
+
</tr>
|
429 |
+
|
430 |
+
<tr class="form-field">
|
431 |
+
<th valign="top" scope="row">
|
432 |
+
<label for="tags"><?php _e('Tags', 'content-egg'); ?></label>
|
433 |
+
</th>
|
434 |
+
<td>
|
435 |
+
|
436 |
+
<input id="tags" name="item[tags]" value="<?php echo esc_attr($item['tags']) ?>"
|
437 |
+
type="text" class="regular-text ltr">
|
438 |
+
<p class="description">
|
439 |
+
<?php _e('Comma separated list of tags.', 'content-egg'); ?>
|
440 |
+
<?php _e('"Formulas", and also all tags from title template, will also work here.', 'content-egg'); ?><br>
|
441 |
+
</p>
|
442 |
+
</td>
|
443 |
+
</tr>
|
444 |
+
|
445 |
+
<tr class="form-field">
|
446 |
+
<th valign="top" scope="row">
|
447 |
+
<label for="status"><?php _e('Product condition', 'content-egg'); ?></label>
|
448 |
+
</th>
|
449 |
+
<td>
|
450 |
+
<select id="product_condition" name="item[product_condition]">
|
451 |
+
<option value=""<?php if (!empty($item['product_condition'])) echo ' selected="selected"'; ?>><?php echo __('Any', 'content-egg'); ?></option>
|
452 |
+
<option value="new"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new') echo ' selected="selected"'; ?>><?php echo __('New', 'content-egg'); ?></option>
|
453 |
+
<option value="used"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'used') echo ' selected="selected"'; ?>><?php echo __('Used', 'content-egg'); ?></option>
|
454 |
+
<option value="refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'refurbished') echo ' selected="selected"'; ?>><?php echo __('Refurbished', 'content-egg'); ?></option>
|
455 |
+
<option value="new_other"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'new_other') echo ' selected="selected"'; ?>><?php echo __('Open box, no signs (Ebay only)', 'content-egg'); ?></option>
|
456 |
+
<option value="seller_refurbished"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'seller_refurbished') echo ' selected="selected"'; ?>><?php echo __('Seller refurbished (Ebay only)', 'content-egg'); ?></option>
|
457 |
+
<option value="for_parts"<?php if (isset($item['product_condition']) && $item['product_condition'] == 'for_parts') echo ' selected="selected"'; ?>><?php echo __('For parts or not working (Ebay only)', 'content-egg'); ?></option>
|
458 |
+
</select>
|
459 |
+
<p class="description">
|
460 |
+
<?php _e('This parameter is supported only by the following modules: Amazon, Ebay', 'content-egg'); ?>
|
461 |
+
</p>
|
462 |
+
|
463 |
+
</td>
|
464 |
+
</tr>
|
465 |
+
|
466 |
+
<tr class="form-field">
|
467 |
+
<th valign="top" scope="row">
|
468 |
+
<label for="custom_fields"><?php _e('Add custom fields', 'content-egg'); ?></label>
|
469 |
+
</th>
|
470 |
+
<td>
|
471 |
+
<div style="width: 50%;float:left;">
|
472 |
+
<?php for ($i = 0; $i < count($item['custom_field_names']); $i++): ?>
|
473 |
+
<input type="text" value="<?php echo esc_attr($item['custom_field_names'][$i]); ?>" name="item[custom_field_names][]" placeholder="<?php _e('Custom Field', 'content-egg'); ?> <?php echo $i + 1; ?>" id="custom_fields" />
|
474 |
+
<?php endfor; ?>
|
475 |
+
</div>
|
476 |
+
<div style="width: 50%;float:left;">
|
477 |
+
<?php for ($i = 0; $i < count($item['custom_field_values']); $i++): ?>
|
478 |
+
<input value="<?php echo esc_attr($item['custom_field_values'][$i]); ?>" type="text" name="item[custom_field_values][]" placeholder="<?php _e('Value', 'content-egg'); ?> <?php echo $i + 1; ?>" />
|
479 |
+
<?php endfor; ?>
|
480 |
+
</div>
|
481 |
+
<p class="description">
|
482 |
+
<?php _e('"Formulas", and also all tags from title template, will also work here.', 'content-egg'); ?><br>
|
483 |
+
</p>
|
484 |
+
</td>
|
485 |
+
</tr>
|
486 |
+
|
487 |
+
</tbody>
|
488 |
+
</table>
|
application/admin/views/_metabox_results.php
CHANGED
@@ -1,95 +1,97 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
$
|
7 |
-
$
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
<?php
|
30 |
-
|
31 |
-
<input type="text" placeholder="<?php _e('
|
32 |
-
<input type="text" placeholder="<?php _e('
|
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 |
-
<option
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
<
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
<
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
95 |
</div>
|
1 |
+
<?php
|
2 |
+
defined('\ABSPATH') || exit;
|
3 |
+
|
4 |
+
use ContentEgg\application\components\ModuleManager;
|
5 |
+
|
6 |
+
$module = ModuleManager::factory($module_id);
|
7 |
+
$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; ?>
|
22 |
+
|
23 |
+
<small ng-show="data.price">
|
24 |
+
<b>{{data.currencyCode}} {{data.price| number}}</b>
|
25 |
+
</small>
|
26 |
+
</div>
|
27 |
+
<div ng-class="data.img ? 'col-md-9' : 'col-md-10'">
|
28 |
+
|
29 |
+
<input type="text" placeholder="<?php _e('Title', 'content-egg'); ?>" ng-model="data.title" class="<?php echo $isAffiliateParser ? 'col-md-6' : 'col-md-12'; ?>" style="margin-bottom: 5px;">
|
30 |
+
<?php if ($isAffiliateParser): ?>
|
31 |
+
<input type="text" placeholder="<?php _e('Merchant name', 'content-egg'); ?>" ng-model="data.merchant" class="col-md-2" style="margin-bottom: 5px;">
|
32 |
+
<input type="text" placeholder="<?php _e('Domain', 'content-egg'); ?>" ng-model="data.domain" class="col-md-3" style="margin-bottom: 5px;">
|
33 |
+
<input type="text" placeholder="<?php _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 _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 _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 _e('Woo attributes', 'content-egg'); ?> ({{data.features.length}})</label>
|
41 |
+
<?php elseif ($isAffiliateParser): ?>
|
42 |
+
<small class="text-muted" ng-show="data.features.length"><?php _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">
|
46 |
+
<span class="glyphicon glyphicon-edit"></span>
|
47 |
+
</a>
|
48 |
+
|
49 |
+
<div class="row features_wrap" uib-collapse="isFeaturesCollapsed">
|
50 |
+
<div class="col-md-12" ng-repeat="feature in data.features">
|
51 |
+
<div class="col-md-5">
|
52 |
+
<input type="text" ng-model="feature.name" class="input-sm form-control">
|
53 |
+
</div>
|
54 |
+
<div class="col-md-6">
|
55 |
+
<input type="text" ng-model="feature.value" class="input-sm form-control">
|
56 |
+
</div>
|
57 |
+
<div class="col-md-1">
|
58 |
+
<a ng-click="data.features.splice($index, 1)" aria-label="Delete">
|
59 |
+
<span class="glyphicon glyphicon-remove-circle text-danger"></span>
|
60 |
+
</a>
|
61 |
+
</div>
|
62 |
+
</div>
|
63 |
+
</div>
|
64 |
+
|
65 |
+
</div>
|
66 |
+
<div class="col-md-2">
|
67 |
+
|
68 |
+
<?php if ($isAffiliateParser): ?>
|
69 |
+
|
70 |
+
<div ng-show="productGroups.length" style="padding-bottom:8px;">
|
71 |
+
<select ng-model="data.group">
|
72 |
+
<option value="">- <?php _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 _e('Go to ', 'content-egg'); ?></span>
|
78 |
+
<a title="<?php esc_attr(_e('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 _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" ng-class="{
|
86 |
+
'outofstock': data.stock_status == - 1, 'instock': data.stock_status == 1}">{{data.stock_status| stockStatus}}</mark>
|
87 |
+
</span>
|
88 |
+
</div>
|
89 |
+
<?php endif; ?>
|
90 |
+
<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 _e('Remove', 'content-egg'); ?></a></div>
|
91 |
+
|
92 |
+
</div>
|
93 |
+
</div>
|
94 |
+
|
95 |
+
</div>
|
96 |
+
</div>
|
97 |
</div>
|
application/admin/views/_metabox_search_results.php
CHANGED
@@ -1,31 +1,32 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
<
|
10 |
-
<p>
|
11 |
-
|
12 |
-
<span ng-show="result.
|
13 |
-
<span ng-show="result.
|
14 |
-
<span ng-show="result.
|
15 |
-
|
16 |
-
|
17 |
-
<
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
</div>
|
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>
|
8 |
+
<div ng-class="result.img ? 'col-md-11' : 'col-md-12'">
|
9 |
+
<strong ng-show="result.title">{{result.title}}</strong>
|
10 |
+
<p ng-show="result.description">{{result.description| limitTo: 200}}{{result.description.length > 200 ? '…' : ''}}</p>
|
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 _e('Attributes:', 'content-egg'); ?> {{result.features.length}}</small></span>
|
15 |
+
<span ng-show="result.ean"> <small class="text-muted"><?php _e('EAN:', 'content-egg'); ?> {{result.ean}}</small></span>
|
16 |
+
<?php if ($module_id == 'Amazon'): ?>
|
17 |
+
<span class="text-muted">
|
18 |
+
<br>
|
19 |
+
<small class="text-primary" ng-show="result.extra.IsPrimeEligible">PRIME</small>
|
20 |
+
<small class="text-success" ng-show="result.extra.IsEligibleForSuperSaverShipping">Free Shipping<span ng-show="result.extra.IsAmazonFulfilled"> by Amazon</span></small>
|
21 |
+
</span>
|
22 |
+
<?php endif; ?>
|
23 |
+
|
24 |
+
</p>
|
25 |
+
<div ng-show="result.code">
|
26 |
+
<?php _e('Coupon code:', 'content-egg'); ?> <em>{{result.code}}</em>
|
27 |
+
- <span ng-show="result.startDate">{{result.startDate * 1000|date:'mediumDate'}} - {{result.endDate * 1000|date:'mediumDate'}}</span>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
</div>
|
application/admin/views/_metabox_search_results_images.php
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
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>
|
9 |
+
</div>
|
application/admin/views/_promo_box.php
CHANGED
@@ -1,46 +1,75 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
</
|
14 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div class="cegg-rightcol">
|
3 |
+
|
4 |
+
<?php if (\ContentEgg\application\Plugin::isFree()): ?>
|
5 |
+
|
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="Avatar" 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>
|
13 |
+
</div>
|
14 |
+
|
15 |
+
<h2 style="color:#8A2BE2 !important;">External Importer <span class="cegg-box-label">New</span></h2>
|
16 |
+
<p>Automated Import from a Website into WooCommerce.</p>
|
17 |
+
<ul>
|
18 |
+
<li>No API access required</li>
|
19 |
+
<li>No work with CSV data feeds</li>
|
20 |
+
</ul>
|
21 |
+
<p>
|
22 |
+
<a target="_blank" class="button-cegg-banner" href="https://www.keywordrush.com/externalimporter">View...</a>
|
23 |
+
</p>
|
24 |
+
|
25 |
+
|
26 |
+
</div>
|
27 |
+
<?php endif; ?>
|
28 |
+
|
29 |
+
|
30 |
+
<?php
|
31 |
+
/*
|
32 |
+
<?php if (\ContentEgg\application\Plugin::isFree()): ?>
|
33 |
+
<div class="cegg-box" style="margin-top: 95px;">
|
34 |
+
<h2><?php _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" />
|
38 |
+
</a>
|
39 |
+
|
40 |
+
<a href="<?php echo ContentEgg\application\Plugin::pluginSiteUrl(); ?>">
|
41 |
+
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/ce_pro_coupon.png" class="cegg-imgcenter" />
|
42 |
+
</a>
|
43 |
+
|
44 |
+
<h4><?php _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>
|
48 |
+
</div>
|
49 |
+
|
50 |
+
*
|
51 |
+
*/
|
52 |
+
?>
|
53 |
+
|
54 |
+
<?php /*
|
55 |
+
<div class="cegg-box" style="margin-top: 15px;">
|
56 |
+
<?php _e('Thank you for using Content Egg!', 'content-egg'); ?><br>
|
57 |
+
<?php _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; ?>
|
63 |
+
|
64 |
+
|
65 |
+
<?php if (\ContentEgg\application\Plugin::isEnvato()): ?>
|
66 |
+
<div class="cegg-box" style="margin-top: 95px;">
|
67 |
+
<h2><?php _e('Activate plugin', 'content-egg'); ?></h2>
|
68 |
+
<p><?php _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 _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 \get_admin_url(\get_current_blog_id(), 'admin.php?page=content-egg-lic'); ?>"><?php _e('Go to ', 'content-egg'); ?></a>
|
72 |
+
</p>
|
73 |
+
</div>
|
74 |
+
<?php endif; ?>
|
75 |
+
</div>
|
application/admin/views/ae_integration.php
CHANGED
@@ -1,39 +1,38 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
<?php _e('
|
11 |
-
</p>
|
12 |
-
|
13 |
-
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
14 |
-
<p>
|
15 |
-
<?php _e('Here
|
16 |
-
</p>
|
17 |
-
|
18 |
-
<p>
|
19 |
-
<b><?php _e('For first step make next actions:', 'content-egg'); ?></b>
|
20 |
-
<ol>
|
21 |
-
<li><?php _e('Install and activate <a href="
|
22 |
-
|
23 |
-
|
24 |
-
</
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
<?php include('_promo_box.php'); ?>
|
39 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
3 |
+
<div class="cegg-maincol">
|
4 |
+
<?php endif; ?>
|
5 |
+
<div class="wrap">
|
6 |
+
<h2><?php _e('Integration with Affiliate Egg', 'content-egg') ?></h2>
|
7 |
+
<?php settings_errors(); ?>
|
8 |
+
|
9 |
+
<p>
|
10 |
+
<?php _e('You <a href="https://ce-docs.keywordrush.com/integrations/affiliateeggintegration">can activate</a> parsers of <a href="http://www.keywordrush.com/en/affiliateegg">Affiliate Egg</a> as modules of Content Egg.', 'content-egg'); ?>
|
11 |
+
</p>
|
12 |
+
|
13 |
+
<?php if (!ContentEgg\application\admin\AeIntegrationConfig::isAEIntegrationPosible()): ?>
|
14 |
+
<p>
|
15 |
+
<?php _e('Here is the <a href="http://www.keywordrush.com/res/ae_supported_shops.txt">full list</a> of Affiliate Egg supported shops.', 'content-egg'); ?>
|
16 |
+
</p>
|
17 |
+
|
18 |
+
<p>
|
19 |
+
<b><?php _e('For first step make next actions:', 'content-egg'); ?></b>
|
20 |
+
<ol>
|
21 |
+
<li><?php _e('Install and activate <a href="https://www.keywordrush.com/affiliateegg">Affiliate Egg</a>', 'content-egg'); ?></li>
|
22 |
+
</li>
|
23 |
+
</ol>
|
24 |
+
</p>
|
25 |
+
<?php else: ?>
|
26 |
+
<form action="options.php" method="POST">
|
27 |
+
<?php settings_fields($page_slug); ?>
|
28 |
+
<table class="form-table">
|
29 |
+
<?php \do_settings_fields($page_slug, 'default'); ?>
|
30 |
+
</table>
|
31 |
+
<?php submit_button(); ?>
|
32 |
+
</form>
|
33 |
+
<?php endif; ?>
|
34 |
+
</div>
|
35 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
36 |
+
</div>
|
37 |
+
<?php include('_promo_box.php'); ?>
|
|
|
38 |
<?php endif; ?>
|
application/admin/views/autoblog_edit.php
CHANGED
@@ -1,61 +1,62 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
<?php
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
<?php
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
<?php
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
<input type="hidden" name="
|
34 |
-
<
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
<?php
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
3 |
+
<div class="cegg-maincol">
|
4 |
+
<?php endif; ?>
|
5 |
+
<div class="wrap">
|
6 |
+
<h2>
|
7 |
+
<?php if ($item['id']): ?>
|
8 |
+
<?php _e('Edit autoblogging', 'content-egg'); ?>
|
9 |
+
<?php else: ?>
|
10 |
+
<?php _e('Add autoblogging', 'content-egg'); ?>
|
11 |
+
<?php if ($batch): ?>
|
12 |
+
- <?php _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 get_admin_url(get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit--batch'); ?>"><?php _e('Bulk adding', 'content-egg'); ?></a>
|
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 _e('Back to list', 'content-egg'); ?></a>
|
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 $nonce; ?>"/>
|
34 |
+
<input type="hidden" name="item[id]" value="<?php echo $item['id']; ?>"/>
|
35 |
+
<div class="metabox-holder" id="poststuff">
|
36 |
+
<div id="post-body">
|
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 _e('Save', 'content-egg'); ?>" id="autoblog_submit" class="button-primary" name="submit">
|
41 |
+
|
42 |
+
<?php if ($batch): ?><em><?php _e('Don\'t close page until process finishes. Be patient, can have some time.', 'content-egg'); ?></em><?php endif; ?>
|
43 |
+
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
</div>
|
47 |
+
</form>
|
48 |
+
</div>
|
49 |
+
|
50 |
+
<script>
|
51 |
+
jQuery(document).ready(function () {
|
52 |
+
jQuery("#form").submit(function () {
|
53 |
+
jQuery("#autoblog_submit").attr("disabled", true);
|
54 |
+
return true;
|
55 |
+
});
|
56 |
+
});
|
57 |
+
</script>
|
58 |
+
|
59 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
60 |
+
</div>
|
61 |
+
<?php include('_promo_box.php'); ?>
|
62 |
<?php endif; ?>
|
application/admin/views/autoblog_index.php
CHANGED
@@ -1,52 +1,52 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
<
|
4 |
-
|
5 |
-
|
6 |
-
</
|
7 |
-
|
8 |
-
|
9 |
-
$j
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
$message = '';
|
18 |
-
if ($table->current_action() == 'delete' && !empty($_GET['id']))
|
19 |
-
$message = '<div class="updated below-h2" id="message"><p>' . sprintf(__('Deleted tasks for autoblogging: ', 'content-egg') . ' %d', count($_GET['id'])) . '</p></div>';
|
20 |
-
if ($table->current_action() == 'run')
|
21 |
-
$message = '<div class="updated below-h2" id="message"><p>' . __('Autoblogging finished tasks', 'content-egg') . '</p></div>';
|
22 |
-
?>
|
23 |
-
|
24 |
-
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
25 |
-
<div class="cegg-maincol">
|
26 |
-
<?php endif; ?>
|
27 |
-
|
28 |
-
|
29 |
-
<div class="wrap">
|
30 |
-
|
31 |
-
<h2>
|
32 |
-
<?php _e('Autoblogging', 'content-egg'); ?>
|
33 |
-
<a class="add-new-h2" href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit'); ?>"><?php _e('Add autoblogging', 'content-egg'); ?></a>
|
34 |
-
</h2>
|
35 |
-
<?php echo $message; ?>
|
36 |
-
|
37 |
-
<div id="poststuff">
|
38 |
-
<p>
|
39 |
-
<?php _e('You can create automatic creating of posts with autoblogging', 'content-egg'); ?>
|
40 |
-
</p>
|
41 |
-
</div>
|
42 |
-
|
43 |
-
<form id="eggs-table" method="GET">
|
44 |
-
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>"/>
|
45 |
-
<?php $table->display() ?>
|
46 |
-
</form>
|
47 |
-
</div>
|
48 |
-
|
49 |
-
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
50 |
-
</div>
|
51 |
-
<?php include('_promo_box.php'); ?>
|
52 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
+
<h2><?php _e('Working... Please wait...', 'content-egg'); ?></h2>
|
4 |
+
<p>
|
5 |
+
<img src="<?php echo \ContentEgg\PLUGIN_RES; ?>/img/egg_waiting.gif" />
|
6 |
+
</p>
|
7 |
+
</div>
|
8 |
+
<script type="text/javascript">
|
9 |
+
var $j = jQuery.noConflict();
|
10 |
+
$j(document).ready(function () {
|
11 |
+
$j('.run_avtoblogging').click(function () {
|
12 |
+
$j.blockUI({message: $j('#cegg_waiting_products')});
|
13 |
+
});
|
14 |
+
});
|
15 |
+
</script>
|
16 |
+
<?php
|
17 |
+
$message = '';
|
18 |
+
if ($table->current_action() == 'delete' && !empty($_GET['id']))
|
19 |
+
$message = '<div class="updated below-h2" id="message"><p>' . sprintf(__('Deleted tasks for autoblogging: ', 'content-egg') . ' %d', count($_GET['id'])) . '</p></div>';
|
20 |
+
if ($table->current_action() == 'run')
|
21 |
+
$message = '<div class="updated below-h2" id="message"><p>' . __('Autoblogging finished tasks', 'content-egg') . '</p></div>';
|
22 |
+
?>
|
23 |
+
|
24 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
25 |
+
<div class="cegg-maincol">
|
26 |
+
<?php endif; ?>
|
27 |
+
|
28 |
+
|
29 |
+
<div class="wrap">
|
30 |
+
|
31 |
+
<h2>
|
32 |
+
<?php _e('Autoblogging', 'content-egg'); ?>
|
33 |
+
<a class="add-new-h2" href="<?php echo get_admin_url(get_current_blog_id(), 'admin.php?page=content-egg-autoblog-edit'); ?>"><?php _e('Add autoblogging', 'content-egg'); ?></a>
|
34 |
+
</h2>
|
35 |
+
<?php echo $message; ?>
|
36 |
+
|
37 |
+
<div id="poststuff">
|
38 |
+
<p>
|
39 |
+
<?php _e('You can create automatic creating of posts with autoblogging', 'content-egg'); ?>
|
40 |
+
</p>
|
41 |
+
</div>
|
42 |
+
|
43 |
+
<form id="eggs-table" method="GET">
|
44 |
+
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>"/>
|
45 |
+
<?php $table->display() ?>
|
46 |
+
</form>
|
47 |
+
</div>
|
48 |
+
|
49 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
50 |
+
</div>
|
51 |
+
<?php include('_promo_box.php'); ?>
|
52 |
<?php endif; ?>
|
application/admin/views/import_export.php
CHANGED
@@ -1,38 +1,39 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
<?php
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
<
|
23 |
-
<
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
<
|
28 |
-
<
|
29 |
-
<
|
30 |
-
|
31 |
-
<
|
32 |
-
<
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
3 |
+
<div class="cegg-maincol">
|
4 |
+
<?php endif; ?>
|
5 |
+
<div class="wrap">
|
6 |
+
<h2>
|
7 |
+
<?php _e('Export/Import of settings', 'content-egg'); ?>
|
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">
|
18 |
+
<p>
|
19 |
+
</p>
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<h3><?php _e('Save settings', 'content-egg'); ?></h3>
|
23 |
+
<p><?php _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 _e('Load settings', 'content-egg'); ?></h3>
|
29 |
+
<p><?php _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 $nonce; ?>"/>
|
32 |
+
<textarea name="import_str" rows="8" cols="70"></textarea>
|
33 |
+
<p><input type="submit" value="<?php _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()): ?>
|
37 |
+
</div>
|
38 |
+
<?php include('_promo_box.php'); ?>
|
39 |
<?php endif; ?>
|
application/admin/views/metabox_general.php
CHANGED
@@ -1,51 +1,52 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
<
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
<button ng-show='
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
<
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
</div>
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$
|
38 |
-
|
39 |
-
|
40 |
-
<
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
<option
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
</div>
|
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 _e('Keyword to search', 'content-egg'); ?>" aria-label="<?php _e('Keyword to search', 'content-egg'); ?>">
|
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 _e('Find all', 'content-egg'); ?>
|
13 |
+
</button>
|
14 |
+
<button ng-show='!processCounter && global_isSearchResults()' ng-click="global_addAll()" type="button" class="btn btn-default"><?php _e('Add all', 'content-egg'); ?></button>
|
15 |
+
<button ng-show='global_isAddedResults()' ng-click="global_deleteAll()" ng-confirm-click="<?php _e('Are you sure you want to delete the results of all modules?', 'content-egg'); ?>" type="button" class="btn btn-default"><?php _e('Remove all', 'content-egg'); ?></button>
|
16 |
+
|
17 |
+
</div>
|
18 |
+
</div>
|
19 |
+
|
20 |
+
</div>
|
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 _e('Add product group', 'content-egg'); ?>" aria-label="<?php _e('Add product group', 'content-egg'); ?>">
|
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 |
+
+
|
28 |
+
</button>
|
29 |
+
</div>
|
30 |
+
</div>
|
31 |
+
</div>
|
32 |
+
</div>
|
33 |
+
<div class="row">
|
34 |
+
<div class="col-sm-12">
|
35 |
+
|
36 |
+
<?php
|
37 |
+
$tpl_manager = ContentEgg\application\components\BlockTemplateManager::getInstance();
|
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 _e('Groups', 'content-egg'); ?> ({{productGroups.length}}) -</option>
|
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" />
|
51 |
+
</div>
|
52 |
</div>
|
application/admin/views/metabox_module.php
CHANGED
@@ -1,106 +1,107 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
<input type="hidden" name="
|
4 |
-
<input type="hidden" name="
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
<
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
$
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
<?php
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
<option
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
<?php $
|
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 |
-
<?php
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
<p ng-show="models.<?php echo $module_id; ?>.
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
106 |
</div>
|
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='indextab_<?php echo $module_id; ?>'>
|
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 echo $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 $module_id; ?>" ng-change="buildShortcode('<?php echo $module_id; ?>', selectedTemplate_<?php echo $module_id; ?>, selectedGroup_<?php echo $module_id; ?>);">
|
26 |
+
<option value="">← <?php _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 $module_id; ?>" ng-change="buildShortcode('<?php echo $module_id; ?>', selectedTemplate_<?php echo $module_id; ?>, selectedGroup_<?php echo $module_id; ?>);">
|
33 |
+
<option value="">← <?php _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 $module_id; ?>" type="text" ng-model="updateKeywords.<?php echo $module_id; ?>" placeholder="<?php _e('Keyword for update', 'content-egg'); ?>" title="<?php _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 $module_id; ?>')" ng-confirm-click="<?php _e('Are you sure you want to delete all results?', 'content-egg'); ?>" ng-show='models.<?php echo $module_id; ?>.added.length'><?php _e('Remove all', 'content-egg'); ?></a>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
<div class="clearfix"></div>
|
51 |
+
<p ng-show="!models.<?php echo $module_id; ?>.added.length && !models.<?php echo $module_id; ?>.processing" class="bg-warning text-center"><br><?php _e('No data found...', 'content-egg'); ?><br><br></p>
|
52 |
+
<?php $module->renderResults(); ?>
|
53 |
+
</uib-tab>
|
54 |
+
|
55 |
+
<uib-tab heading="<?php _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 $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 $module_id; ?>" on-enter="find('<?php echo $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 $module_id; ?>" ng-click="find('<?php echo $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 $module_id; ?>" ng-click="setUpdateKeyword('<?php echo $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 $module_id; ?>.processing" src="<?php echo \ContentEgg\PLUGIN_RES . '/img/importing.gif' ?>" />
|
77 |
+
<span ng-show="models.<?php echo $module_id; ?>.processing">
|
78 |
+
<?php _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 $module_id; ?>.processing" src="<?php echo \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 $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 $module_id; ?>')" ng-show='models.<?php echo $module_id; ?>.results.length > 0 && !models.<?php echo $module_id; ?>.processing'><?php _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 $module_id; ?>.processing && models.<?php echo $module_id; ?>.loaded && models.<?php echo $module_id; ?>.results.length == 0" class="bg-warning text-center"><br><?php _e('Not found...', 'content-egg'); ?><br><br></p>
|
101 |
+
<p ng-show="models.<?php echo $module_id; ?>.error && !models.<?php echo $module_id; ?>.processing" class="bg-danger text-center"><br><?php _e('Error:', 'content-egg'); ?> {{models.<?php echo $module_id; ?>.error}}<br><br></p>
|
102 |
+
</uib-tab>
|
103 |
+
</uib-tabset>
|
104 |
+
<div class="row">
|
105 |
+
<div class="col-sm-12"><br></div>
|
106 |
+
</div>
|
107 |
</div>
|
application/admin/views/module_index.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
|
3 |
+
<?php
|
4 |
+
|
5 |
+
function _cegg_print_module_item(array $modules)
|
6 |
+
{
|
7 |
+
foreach ($modules as $module)
|
8 |
+
{
|
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())
|
16 |
+
echo '<span class="label label-info">' . __('New', 'content-egg') . '</span>';
|
17 |
+
echo '</a>';
|
18 |
+
}
|
19 |
+
}
|
20 |
+
?>
|
21 |
+
|
22 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
23 |
+
<div class="cegg-maincol">
|
24 |
+
<?php endif; ?>
|
25 |
+
|
26 |
+
|
27 |
+
<div class="wrap">
|
28 |
+
|
29 |
+
<h2><?php _e('Module Settings', 'content-egg'); ?></h2>
|
30 |
+
|
31 |
+
|
32 |
+
<h2 class="nav-tab-wrapper">
|
33 |
+
<a href="?page=content-egg-modules" class="nav-tab<?php if (!empty($_GET['page']) && $_GET['page'] == 'content-egg-modules') echo ' nav-tab-active'; ?>">
|
34 |
+
<span class="dashicons dashicons-menu-alt3"></span>
|
35 |
+
</a>
|
36 |
+
<?php foreach (ContentEgg\application\components\ModuleManager::getInstance()->getConfigurableModules(true) as $m): ?>
|
37 |
+
<?php if ($m->isDeprecated() && !$m->isActive()) continue; ?>
|
38 |
+
<?php $c = $m->getConfigInstance(); ?>
|
39 |
+
<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'; ?>">
|
40 |
+
<span<?php if ($m->isDeprecated()): ?> style="color: darkgray;"<?php endif; ?>>
|
41 |
+
<?php echo \esc_html($m->getName()); ?>
|
42 |
+
</span>
|
43 |
+
</a>
|
44 |
+
<?php endforeach; ?>
|
45 |
+
</h2>
|
46 |
+
|
47 |
+
<br />
|
48 |
+
<div class="egg-container">
|
49 |
+
<div class="row">
|
50 |
+
<div class="col-md-4 col-xs-12">
|
51 |
+
|
52 |
+
<div class="panel panel-default">
|
53 |
+
<div class="panel-heading"><h3 class="panel-title"><?php _e('Product modules', 'content-egg'); ?></h3></div>
|
54 |
+
<div class="list-group">
|
55 |
+
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getProductModules()); ?>
|
56 |
+
</div>
|
57 |
+
</div>
|
58 |
+
|
59 |
+
</div>
|
60 |
+
<div class="col-md-4 col-xs-12">
|
61 |
+
|
62 |
+
<?php if ($modules = \ContentEgg\application\helpers\AdminHelper::getAeProductModules()): ?>
|
63 |
+
<div class="panel panel-default">
|
64 |
+
<div class="panel-heading"><h3 class="panel-title"><?php _e('Affiliate Egg modules', 'content-egg'); ?></h3></div>
|
65 |
+
<div class="list-group">
|
66 |
+
<?php _cegg_print_module_item($modules); ?>
|
67 |
+
</div>
|
68 |
+
</div>
|
69 |
+
<?php endif; ?>
|
70 |
+
|
71 |
+
<div class="panel panel-default">
|
72 |
+
<div class="panel-heading"><h3 class="panel-title"><?php _e('Coupon modules', 'content-egg'); ?></h3></div>
|
73 |
+
<div class="list-group">
|
74 |
+
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getCouponModules()); ?>
|
75 |
+
</div>
|
76 |
+
</div>
|
77 |
+
|
78 |
+
</div>
|
79 |
+
|
80 |
+
<div class="col-md-4 col-xs-12">
|
81 |
+
|
82 |
+
<div class="panel panel-default">
|
83 |
+
<div class="panel-heading"><h3 class="panel-title"><?php _e('Content modules', 'content-egg'); ?></h3></div>
|
84 |
+
<div class="list-group">
|
85 |
+
<?php _cegg_print_module_item(\ContentEgg\application\helpers\AdminHelper::getContentModules()); ?>
|
86 |
+
</div>
|
87 |
+
</div>
|
88 |
+
|
89 |
+
</div>
|
90 |
+
|
91 |
+
</div>
|
92 |
+
</div>
|
93 |
+
</div>
|
94 |
+
|
95 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
96 |
+
</div>
|
97 |
+
<?php include('_promo_box.php'); ?>
|
98 |
+
<?php endif; ?>
|
application/admin/views/module_settings.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
|
3 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
4 |
+
<div class="cegg-maincol">
|
5 |
+
<?php endif; ?>
|
6 |
+
<div class="wrap">
|
7 |
+
<h2><?php _e('Module Settings', 'content-egg'); ?></h2>
|
8 |
+
|
9 |
+
|
10 |
+
<h2 class="nav-tab-wrapper">
|
11 |
+
<a href="?page=content-egg-modules" class="nav-tab<?php if (!empty($_GET['page']) && $_GET['page'] == 'content-egg-modules') echo ' nav-tab-active'; ?>">
|
12 |
+
<span class="dashicons dashicons-menu-alt3"></span>
|
13 |
+
</a>
|
14 |
+
<?php foreach (ContentEgg\application\components\ModuleManager::getInstance()->getConfigurableModules(true) as $m): ?>
|
15 |
+
<?php if ($m->isDeprecated() && !$m->isActive()) continue; ?>
|
16 |
+
<?php $c = $m->getConfigInstance(); ?>
|
17 |
+
<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'; ?>">
|
18 |
+
<span<?php if ($m->isDeprecated()): ?> style="color: darkgray;"<?php endif; ?>>
|
19 |
+
<?php echo \esc_html($m->getName()); ?>
|
20 |
+
</span>
|
21 |
+
</a>
|
22 |
+
<?php endforeach; ?>
|
23 |
+
</h2>
|
24 |
+
|
25 |
+
<div class="cegg-wrap">
|
26 |
+
<div class="cegg-maincol">
|
27 |
+
|
28 |
+
<h3>
|
29 |
+
<?php echo \esc_html(sprintf(__('%s Settings', 'content-egg'), $module->getName())); ?>
|
30 |
+
<?php if ($docs_uri = $module->getDocsUri()) echo sprintf('<a target="_blank" class="page-title-action" href="%s">' . __('Documentation', 'content-egg') . '</a>', $docs_uri); ?>
|
31 |
+
</h3>
|
32 |
+
|
33 |
+
<?php if ($module->isDeprecated()): ?>
|
34 |
+
<div class="cegg-warning">
|
35 |
+
|
36 |
+
<?php if ($module->getId() == 'Amazon'): ?>
|
37 |
+
<?php echo __('WARNING:', 'content-egg'); ?>
|
38 |
+
<?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'); ?>
|
39 |
+
<?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'); ?>
|
40 |
+
<?php echo _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 _e('read more...', 'content-egg'); ?></a>
|
41 |
+
<?php endif; ?>
|
42 |
+
|
43 |
+
<?php if ($module->getId() != 'Amazon'): ?>
|
44 |
+
<strong>
|
45 |
+
<?php echo __('WARNING:', 'content-egg'); ?>
|
46 |
+
<?php echo __('This module is deprecated', 'content-egg'); ?>
|
47 |
+
(<a target="_blank" href="<?php echo \ContentEgg\application\Plugin::pluginDocsUrl(); ?>/modules/deprecatedmodules"><?php _e('what does this mean', 'content-egg'); ?></a>).
|
48 |
+
</strong>
|
49 |
+
<?php endif; ?>
|
50 |
+
</div>
|
51 |
+
<?php endif; ?>
|
52 |
+
|
53 |
+
<?php if (!empty($module) && $requirements = $module->requirements()): ?>
|
54 |
+
<div class="cegg-warning">
|
55 |
+
<strong>
|
56 |
+
<?php echo _e('WARNING:', 'content-egg'); ?>
|
57 |
+
<?php _e('This module cannot be activated!', 'content-egg') ?>
|
58 |
+
<?php _e('Please fix the following error(s):', 'content-egg') ?>
|
59 |
+
<ul>
|
60 |
+
<li><?php echo join('</li><li>', $requirements) ?></li>
|
61 |
+
</ul>
|
62 |
+
|
63 |
+
</strong>
|
64 |
+
</div>
|
65 |
+
<?php endif; ?>
|
66 |
+
|
67 |
+
<?php \settings_errors(); ?>
|
68 |
+
<form action="options.php" method="POST">
|
69 |
+
<?php \settings_fields($config->page_slug()); ?>
|
70 |
+
<table class="form-table">
|
71 |
+
<?php \do_settings_sections($config->page_slug()); ?>
|
72 |
+
</table>
|
73 |
+
<?php \submit_button(); ?>
|
74 |
+
</form>
|
75 |
+
|
76 |
+
</div>
|
77 |
+
|
78 |
+
<div class="cegg-rightcol">
|
79 |
+
<div>
|
80 |
+
<?php
|
81 |
+
if (!empty($description))
|
82 |
+
echo '<p>' . $description . '</p>';
|
83 |
+
?>
|
84 |
+
|
85 |
+
<?php if (!empty($module) && $module->isFeedModule()): ?>
|
86 |
+
<?php if ($last_date = $module->getLastImportDateReadable()): ?>
|
87 |
+
<li><?php echo sprintf(__('Last feed import: %s.'), $last_date); ?></li>
|
88 |
+
<li><?php echo sprintf(__('Total products: %d.'), $module->getProductCount()); ?></li>
|
89 |
+
<?php endif; ?>
|
90 |
+
<li title="<?php echo \esc_attr(__('Your unzipped feed must be smaller than this.', 'content-egg')); ?>"><?php echo sprintf(__('WordPress memory limit: %s'), WP_MAX_MEMORY_LIMIT); ?>
|
91 |
+
(<a href="https://wordpress.org/support/article/editing-wp-config-php/#increasing-memory-allocated-to-php" target="_blank">?</a>)
|
92 |
+
</li>
|
93 |
+
<?php if ($last_error = $module->getLastImportError()): ?>
|
94 |
+
<li style="color: red;"><?php echo sprintf(__('Last error: %s'), $last_error); ?></li>
|
95 |
+
<?php endif; ?>
|
96 |
+
<?php endif; ?>
|
97 |
+
</div>
|
98 |
+
</div>
|
99 |
+
</div>
|
100 |
+
|
101 |
+
|
102 |
+
</div>
|
103 |
+
|
104 |
+
|
105 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
106 |
+
</div>
|
107 |
+
<?php include('_promo_box.php'); ?>
|
108 |
+
<?php endif; ?>
|
application/admin/views/prefill.php
CHANGED
@@ -1,162 +1,162 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
use ContentEgg\application\components\ModuleManager;
|
4 |
-
use ContentEgg\application\admin\GeneralConfig;
|
5 |
-
?>
|
6 |
-
|
7 |
-
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
8 |
-
<div class="cegg-maincol">
|
9 |
-
<?php endif; ?>
|
10 |
-
<div class="wrap">
|
11 |
-
<h2>
|
12 |
-
<?php _e('Fill', 'content-egg'); ?>
|
13 |
-
</h2>
|
14 |
-
<p>
|
15 |
-
<?php _e('This extension will fill module\'s data for all existed posts.', 'content-egg'); ?>
|
16 |
-
<?php _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 _e('Delay', 'content-egg'); ?></label></th>
|
21 |
-
<td>
|
22 |
-
<select id="delay">
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
</select>
|
37 |
-
<p class="description"><?php _e('Delay in seconds between each post prefill.', 'content-egg'); ?></p>
|
38 |
-
|
39 |
-
</td>
|
40 |
-
</tr>
|
41 |
-
<tr>
|
42 |
-
<th scope="row"><label for="module_id"><?php _e('Add data for module', 'content-egg'); ?></label></th>
|
43 |
-
<td>
|
44 |
-
<select id="module_id">
|
45 |
-
<?php foreach (ModuleManager::getInstance()->getParserModules() as $module): ?>
|
46 |
-
<option value="<?php echo $module->getId(); ?>"><?php echo esc_html($module->getName()); ?></option>
|
47 |
-
<?php endforeach; ?>
|
48 |
-
</select>
|
49 |
-
</td>
|
50 |
-
</tr>
|
51 |
-
<tr>
|
52 |
-
<th scope="row"><label for="keyword_source"><?php _e('Keyword source', 'content-egg'); ?></label></th>
|
53 |
-
<td>
|
54 |
-
<select id="keyword_source">
|
55 |
-
<option value="_density"><?php _e('Calculate as base of the density of keywords inside post', 'content-egg'); ?></option>
|
56 |
-
<option value="_title"><?php _e('Title for post', 'content-egg'); ?></option>
|
57 |
-
<option value="_tags"><?php _e('Post tags', 'content-egg'); ?></option>
|
58 |
-
<option value="_custom_field"><?php _e('Arbitrary custom field', 'content-egg'); ?></option>
|
59 |
-
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers() as $module): ?>
|
60 |
-
<option value="<?php echo $module->getId(); ?>"><?php _e('Copy from', 'content-egg'); ?> <?php echo esc_html($module->getName()); ?></option>
|
61 |
-
<?php endforeach; ?>
|
62 |
-
</select>
|
63 |
-
<input style="display: none;" id="custom_field" type="text" class="regular-text" placeholder="<?php _e('Set the name of a custom field', 'content-egg'); ?>">
|
64 |
-
</td>
|
65 |
-
</tr>
|
66 |
-
|
67 |
-
<tr>
|
68 |
-
<th scope="row"><label for="autoupdate"><?php _e('Autoupdate', 'content-egg'); ?></label></th>
|
69 |
-
<td>
|
70 |
-
<label><input id="autoupdate" type="checkbox" value="1"> <?php _e('Add Keyword for the automatic update', 'content-egg'); ?></label>
|
71 |
-
<p class="description"><?php _e('Only for those modules, which have autoupdate function.', 'content-egg'); ?></p>
|
72 |
-
</td>
|
73 |
-
</tr>
|
74 |
-
|
75 |
-
<tr>
|
76 |
-
<th scope="row"><label for="keyword_count"><?php _e('Number of words', 'content-egg'); ?></label></th>
|
77 |
-
<td>
|
78 |
-
<select id="keyword_count">
|
79 |
-
<?php for ($i = 1; $i <= 10; $i++): ?>
|
80 |
-
<option value="<?php echo $i; ?>"<?php if ($i == 5) echo ' selected="selected"'; ?>><?php echo $i; ?></option>
|
81 |
-
<?php endfor; ?>
|
82 |
-
</select>
|
83 |
-
<p class="description"><?php _e('Maximum words for one search query.', 'content-egg'); ?></p>
|
84 |
-
</td>
|
85 |
-
</tr>
|
86 |
-
|
87 |
-
<tr>
|
88 |
-
<th scope="row"><label for="minus_words"><?php _e('"Minus" words', 'content-egg'); ?></label></th>
|
89 |
-
<td>
|
90 |
-
<input id="minus_words" type="text" class="regular-text">
|
91 |
-
<p class="description"><?php _e('Remove these words from keyword. You can set several minus words/phrases with commas.', 'content-egg'); ?></p>
|
92 |
-
</td>
|
93 |
-
</tr>
|
94 |
-
|
95 |
-
<tr>
|
96 |
-
<th scope="row"><label for="post_type"><?php _e('Post type', 'content-egg'); ?></label></th>
|
97 |
-
<td>
|
98 |
-
<select id="post_type" multiple="multiple">
|
99 |
-
<?php foreach (GeneralConfig::getInstance()->option('post_types') as $post_type): ?>
|
100 |
-
<option value="<?php echo \esc_attr($post_type); ?>" selected="selected"><?php echo \esc_attr($post_type); ?></option>
|
101 |
-
<?php endforeach; ?>
|
102 |
-
</select>
|
103 |
-
<p class="description"><?php _e('You can set all supported post types in General settings -> Post Types.', 'content-egg'); ?></p>
|
104 |
-
</td>
|
105 |
-
</tr>
|
106 |
-
|
107 |
-
<tr>
|
108 |
-
<th scope="row"><label for="post_status"><?php _e('Post status', 'content-egg'); ?></label></th>
|
109 |
-
<td>
|
110 |
-
<?php
|
111 |
-
$post_statuses = array_merge(get_post_statuses(), array('future' => __('Future')));
|
112 |
-
$selected_post_statuses = array('publish', 'future');
|
113 |
-
?>
|
114 |
-
<select id="post_status" multiple="multiple" size="5">
|
115 |
-
<?php foreach ($post_statuses as $post_status_value => $post_status_name): ?>
|
116 |
-
<option value="<?php echo \esc_attr($post_status_value); ?>"
|
117 |
-
<?php if (in_array($post_status_value, $selected_post_statuses)): ?>selected="selected"<?php endif; ?>>
|
118 |
-
<?php echo \esc_attr($post_status_name); ?>
|
119 |
-
</option>
|
120 |
-
<?php endforeach; ?>
|
121 |
-
</select>
|
122 |
-
</td>
|
123 |
-
</tr>
|
124 |
-
|
125 |
-
<tr>
|
126 |
-
<th scope="row"><label for="custom_fields"><?php _e('Add custom fields', 'content-egg'); ?></label></th>
|
127 |
-
<td>
|
128 |
-
<?php for ($i = 0; $i < 5; $i++): ?>
|
129 |
-
<input type="text" name="custom_field_names[]" placeholder="<?php echo sprintf(__('Custom Field %d', 'content-egg'), $i + 1); ?>" id="custom_fields" class="regular-text" />
|
130 |
-
<input type="text" name="custom_field_values[]" placeholder="<?php echo sprintf(__('Value %d', 'content-egg'), $i + 1); ?>" class="regular-text" /><br>
|
131 |
-
<?php endfor; ?>
|
132 |
-
<?php $tags = '%KEYWORD%, %RANDOM(10,50)%, %PRODUCT.title%, %PRODUCT.price%, ...'; ?>
|
133 |
-
<p class="description"><?php echo sprintf(__('You can use tags: %s.', 'content-egg'), $tags); ?></p>
|
134 |
-
</td>
|
135 |
-
</tr>
|
136 |
-
|
137 |
-
</table>
|
138 |
-
|
139 |
-
<div id="progressbar" name="progressbar"></div>
|
140 |
-
<div><?php _e('Total posts', 'content-egg'); ?>: <b><span id="post_ids_total"></span></b></div>
|
141 |
-
|
142 |
-
<div>
|
143 |
-
<br>
|
144 |
-
<button class="button-primary" type="button" id="start_prefill"><?php _e('Start', 'content-egg'); ?></button>
|
145 |
-
<button class="button-primary" type="button" id="start_prefill_begin"><?php _e('Start over', 'content-egg'); ?></button>
|
146 |
-
<button class="button-secondary" type="button" id="stop_prefill" disabled><?php _e('Stop', 'content-egg'); ?></button>
|
147 |
-
|
148 |
-
<span id="ajaxWaiting__" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
149 |
-
<span id="ajaxBusy" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
150 |
-
|
151 |
-
|
152 |
-
</div>
|
153 |
-
|
154 |
-
<div class="egg-prefill-log" id="logs"></div>
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
</div>
|
159 |
-
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
160 |
-
</div>
|
161 |
-
<?php include('_promo_box.php'); ?>
|
162 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit;
|
2 |
+
|
3 |
+
use ContentEgg\application\components\ModuleManager;
|
4 |
+
use ContentEgg\application\admin\GeneralConfig;
|
5 |
+
?>
|
6 |
+
|
7 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
8 |
+
<div class="cegg-maincol">
|
9 |
+
<?php endif; ?>
|
10 |
+
<div class="wrap">
|
11 |
+
<h2>
|
12 |
+
<?php _e('Fill', 'content-egg'); ?>
|
13 |
+
</h2>
|
14 |
+
<p>
|
15 |
+
<?php _e('This extension will fill module\'s data for all existed posts.', 'content-egg'); ?>
|
16 |
+
<?php _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 _e('Delay', 'content-egg'); ?></label></th>
|
21 |
+
<td>
|
22 |
+
<select id="delay">
|
23 |
+
<option value="1000">1</option>
|
24 |
+
<option value="2000">2</option>
|
25 |
+
<option value="3000">3</option>
|
26 |
+
<option value="4000">4</option>
|
27 |
+
<option value="5000">5</option>
|
28 |
+
<option value="6000">6</option>
|
29 |
+
<option value="7000">7</option>
|
30 |
+
<option value="8000">8</option>
|
31 |
+
<option value="90000">9</option>
|
32 |
+
<option value="10000">10</option>
|
33 |
+
<option value="15000">15</option>
|
34 |
+
<option value="20000">20</option>
|
35 |
+
<option value="30000">30</option>
|
36 |
+
</select>
|
37 |
+
<p class="description"><?php _e('Delay in seconds between each post prefill.', 'content-egg'); ?></p>
|
38 |
+
|
39 |
+
</td>
|
40 |
+
</tr>
|
41 |
+
<tr>
|
42 |
+
<th scope="row"><label for="module_id"><?php _e('Add data for module', 'content-egg'); ?></label></th>
|
43 |
+
<td>
|
44 |
+
<select id="module_id">
|
45 |
+
<?php foreach (ModuleManager::getInstance()->getParserModules() as $module): ?>
|
46 |
+
<option value="<?php echo $module->getId(); ?>"><?php echo esc_html($module->getName()); ?></option>
|
47 |
+
<?php endforeach; ?>
|
48 |
+
</select>
|
49 |
+
</td>
|
50 |
+
</tr>
|
51 |
+
<tr>
|
52 |
+
<th scope="row"><label for="keyword_source"><?php _e('Keyword source', 'content-egg'); ?></label></th>
|
53 |
+
<td>
|
54 |
+
<select id="keyword_source">
|
55 |
+
<option value="_density"><?php _e('Calculate as base of the density of keywords inside post', 'content-egg'); ?></option>
|
56 |
+
<option value="_title"><?php _e('Title for post', 'content-egg'); ?></option>
|
57 |
+
<option value="_tags"><?php _e('Post tags', 'content-egg'); ?></option>
|
58 |
+
<option value="_custom_field"><?php _e('Arbitrary custom field', 'content-egg'); ?></option>
|
59 |
+
<?php foreach (ModuleManager::getInstance()->getAffiliateParsers() as $module): ?>
|
60 |
+
<option value="<?php echo $module->getId(); ?>"><?php _e('Copy from', 'content-egg'); ?> <?php echo esc_html($module->getName()); ?></option>
|
61 |
+
<?php endforeach; ?>
|
62 |
+
</select>
|
63 |
+
<input style="display: none;" id="custom_field" type="text" class="regular-text" placeholder="<?php _e('Set the name of a custom field', 'content-egg'); ?>">
|
64 |
+
</td>
|
65 |
+
</tr>
|
66 |
+
|
67 |
+
<tr>
|
68 |
+
<th scope="row"><label for="autoupdate"><?php _e('Autoupdate', 'content-egg'); ?></label></th>
|
69 |
+
<td>
|
70 |
+
<label><input id="autoupdate" type="checkbox" value="1"> <?php _e('Add Keyword for the automatic update', 'content-egg'); ?></label>
|
71 |
+
<p class="description"><?php _e('Only for those modules, which have autoupdate function.', 'content-egg'); ?></p>
|
72 |
+
</td>
|
73 |
+
</tr>
|
74 |
+
|
75 |
+
<tr>
|
76 |
+
<th scope="row"><label for="keyword_count"><?php _e('Number of words', 'content-egg'); ?></label></th>
|
77 |
+
<td>
|
78 |
+
<select id="keyword_count">
|
79 |
+
<?php for ($i = 1; $i <= 10; $i++): ?>
|
80 |
+
<option value="<?php echo $i; ?>"<?php if ($i == 5) echo ' selected="selected"'; ?>><?php echo $i; ?></option>
|
81 |
+
<?php endfor; ?>
|
82 |
+
</select>
|
83 |
+
<p class="description"><?php _e('Maximum words for one search query.', 'content-egg'); ?></p>
|
84 |
+
</td>
|
85 |
+
</tr>
|
86 |
+
|
87 |
+
<tr>
|
88 |
+
<th scope="row"><label for="minus_words"><?php _e('"Minus" words', 'content-egg'); ?></label></th>
|
89 |
+
<td>
|
90 |
+
<input id="minus_words" type="text" class="regular-text">
|
91 |
+
<p class="description"><?php _e('Remove these words from keyword. You can set several minus words/phrases with commas.', 'content-egg'); ?></p>
|
92 |
+
</td>
|
93 |
+
</tr>
|
94 |
+
|
95 |
+
<tr>
|
96 |
+
<th scope="row"><label for="post_type"><?php _e('Post type', 'content-egg'); ?></label></th>
|
97 |
+
<td>
|
98 |
+
<select id="post_type" multiple="multiple">
|
99 |
+
<?php foreach (GeneralConfig::getInstance()->option('post_types') as $post_type): ?>
|
100 |
+
<option value="<?php echo \esc_attr($post_type); ?>" selected="selected"><?php echo \esc_attr($post_type); ?></option>
|
101 |
+
<?php endforeach; ?>
|
102 |
+
</select>
|
103 |
+
<p class="description"><?php _e('You can set all supported post types in General settings -> Post Types.', 'content-egg'); ?></p>
|
104 |
+
</td>
|
105 |
+
</tr>
|
106 |
+
|
107 |
+
<tr>
|
108 |
+
<th scope="row"><label for="post_status"><?php _e('Post status', 'content-egg'); ?></label></th>
|
109 |
+
<td>
|
110 |
+
<?php
|
111 |
+
$post_statuses = array_merge(get_post_statuses(), array('future' => __('Future')));
|
112 |
+
$selected_post_statuses = array('publish', 'future');
|
113 |
+
?>
|
114 |
+
<select id="post_status" multiple="multiple" size="5">
|
115 |
+
<?php foreach ($post_statuses as $post_status_value => $post_status_name): ?>
|
116 |
+
<option value="<?php echo \esc_attr($post_status_value); ?>"
|
117 |
+
<?php if (in_array($post_status_value, $selected_post_statuses)): ?>selected="selected"<?php endif; ?>>
|
118 |
+
<?php echo \esc_attr($post_status_name); ?>
|
119 |
+
</option>
|
120 |
+
<?php endforeach; ?>
|
121 |
+
</select>
|
122 |
+
</td>
|
123 |
+
</tr>
|
124 |
+
|
125 |
+
<tr>
|
126 |
+
<th scope="row"><label for="custom_fields"><?php _e('Add custom fields', 'content-egg'); ?></label></th>
|
127 |
+
<td>
|
128 |
+
<?php for ($i = 0; $i < 5; $i++): ?>
|
129 |
+
<input type="text" name="custom_field_names[]" placeholder="<?php echo sprintf(__('Custom Field %d', 'content-egg'), $i + 1); ?>" id="custom_fields" class="regular-text" />
|
130 |
+
<input type="text" name="custom_field_values[]" placeholder="<?php echo sprintf(__('Value %d', 'content-egg'), $i + 1); ?>" class="regular-text" /><br>
|
131 |
+
<?php endfor; ?>
|
132 |
+
<?php $tags = '%KEYWORD%, %RANDOM(10,50)%, %PRODUCT.title%, %PRODUCT.price%, ...'; ?>
|
133 |
+
<p class="description"><?php echo sprintf(__('You can use tags: %s.', 'content-egg'), $tags); ?></p>
|
134 |
+
</td>
|
135 |
+
</tr>
|
136 |
+
|
137 |
+
</table>
|
138 |
+
|
139 |
+
<div id="progressbar" name="progressbar"></div>
|
140 |
+
<div><?php _e('Total posts', 'content-egg'); ?>: <b><span id="post_ids_total"></span></b></div>
|
141 |
+
|
142 |
+
<div>
|
143 |
+
<br>
|
144 |
+
<button class="button-primary" type="button" id="start_prefill"><?php _e('Start', 'content-egg'); ?></button>
|
145 |
+
<button class="button-primary" type="button" id="start_prefill_begin"><?php _e('Start over', 'content-egg'); ?></button>
|
146 |
+
<button class="button-secondary" type="button" id="stop_prefill" disabled><?php _e('Stop', 'content-egg'); ?></button>
|
147 |
+
|
148 |
+
<span id="ajaxWaiting__" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
149 |
+
<span id="ajaxBusy" style="display:none;"><img src="<?php echo \ContentEgg\PLUGIN_RES . '/img/ajax-loader.gif' ?>" /></span>
|
150 |
+
|
151 |
+
|
152 |
+
</div>
|
153 |
+
|
154 |
+
<div class="egg-prefill-log" id="logs"></div>
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
+
</div>
|
159 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
160 |
+
</div>
|
161 |
+
<?php include('_promo_box.php'); ?>
|
162 |
<?php endif; ?>
|
application/admin/views/product_index.php
CHANGED
@@ -1,48 +1,49 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
<
|
4 |
-
|
5 |
-
|
6 |
-
</
|
7 |
-
|
8 |
-
|
9 |
-
$j
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
&
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
<?php
|
37 |
-
|
38 |
-
|
39 |
-
<?php
|
40 |
-
<?php $table->
|
41 |
-
<?php $table->
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
48 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
<div id="cegg_waiting_products" style="display:none; text-align: center;">
|
3 |
+
<h2><?php _e('Scanning... Please wait...', 'content-egg'); ?></h2>
|
4 |
+
<p>
|
5 |
+
<img src="<?php echo \ContentEgg\PLUGIN_RES; ?>/img/egg_waiting.gif" />
|
6 |
+
</p>
|
7 |
+
</div>
|
8 |
+
<script type="text/javascript">
|
9 |
+
var $j = jQuery.noConflict();
|
10 |
+
$j(document).ready(function () {
|
11 |
+
$j('#btn_scan_products').click(function () {
|
12 |
+
$j.blockUI({message: $j('#cegg_waiting_products')});
|
13 |
+
});
|
14 |
+
});
|
15 |
+
</script>
|
16 |
+
|
17 |
+
<?php
|
18 |
+
$message = '';
|
19 |
+
?>
|
20 |
+
|
21 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
22 |
+
<div class="cegg-maincol">
|
23 |
+
<?php endif; ?>
|
24 |
+
|
25 |
+
<div class="wrap">
|
26 |
+
<h1 class="wp-heading-inline">
|
27 |
+
<?php _e('Products', 'content-egg'); ?>
|
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 echo __('Scan Products', 'content-egg'); ?></a>
|
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="<?php echo \esc_attr($_REQUEST['page']); ?>"/>
|
37 |
+
<?php if (isset($_REQUEST['stock_status'])): ?>
|
38 |
+
<input type="hidden" name="stock_status" value="<?php echo \esc_attr($_REQUEST['stock_status']); ?>"/>
|
39 |
+
<?php endif; ?>
|
40 |
+
<?php $table->views(); ?>
|
41 |
+
<?php $table->search_box(__('Search products', 'content-egg'), 'key'); ?>
|
42 |
+
<?php $table->display(); ?>
|
43 |
+
</form>
|
44 |
+
</div>
|
45 |
+
|
46 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
47 |
+
</div>
|
48 |
+
<?php include('_promo_box.php'); ?>
|
49 |
<?php endif; ?>
|
application/admin/views/settings.php
CHANGED
@@ -1,138 +1,27 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
<?php
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
<?php
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
<a href="?page=<?php echo esc_attr($config->page_slug()); ?>"
|
28 |
-
class="nav-tab<?php if (!empty($_GET['page']) && $_GET['page'] == $config->page_slug()) echo ' nav-tab-active'; ?>">
|
29 |
-
|
30 |
-
<?php
|
31 |
-
if ($m->isActive() && $m->isDeprecated())
|
32 |
-
$status = 'deprecated';
|
33 |
-
elseif ($m->isActive())
|
34 |
-
$status = 'active';
|
35 |
-
else
|
36 |
-
$status = 'inactive';
|
37 |
-
?>
|
38 |
-
|
39 |
-
<img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/status-<?php echo $status; ?>.png" />
|
40 |
-
<?php echo esc_html($m->getName()); ?>
|
41 |
-
<?php if ($m->isNew()): ?><img src="<?php echo ContentEgg\PLUGIN_RES; ?>/img/new.png" alt="New" title="New" /><?php endif; ?>
|
42 |
-
</a>
|
43 |
-
<?php endforeach; ?>
|
44 |
-
</h2>
|
45 |
-
|
46 |
-
<div class="ui-sortable meta-box-sortables">
|
47 |
-
<div class="postbox1">
|
48 |
-
<div class="inside">
|
49 |
-
|
50 |
-
<div class="cegg-wrap">
|
51 |
-
|
52 |
-
<div class="cegg-maincol">
|
53 |
-
|
54 |
-
<h3>
|
55 |
-
<?php
|
56 |
-
if (!empty($_GET['page']) && $_GET['page'] == 'content-egg')
|
57 |
-
_e('General settings', 'content-egg');
|
58 |
-
else
|
59 |
-
echo esc_html($header);
|
60 |
-
?>
|
61 |
-
</h3>
|
62 |
-
|
63 |
-
<?php if (!empty($module) && $module->isDeprecated()): ?>
|
64 |
-
<div class="cegg-warning">
|
65 |
-
|
66 |
-
<?php if ($module->getId() == 'Amazon'): ?>
|
67 |
-
<?php echo __('WARNING:', 'content-egg'); ?>
|
68 |
-
<?php echo sprintf(__('Amazon PA-API v4 <a target="_blank" href="%s"> is being deprecated</a> on 31 October 2019.', 'content-egg'), 'https://webservices.amazon.com/paapi5/documentation/faq.html'); ?>
|
69 |
-
<?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'); ?>
|
70 |
-
<?php echo _e('Please', 'content-egg'); ?> <a target="_blank" href="<?php echo \ContentEgg\application\Plugin::pluginDocsUrl(); ?>Amazon.html#amazon_apiv4_deprecated"><?php _e('read more...', 'content-egg'); ?></a>
|
71 |
-
<?php endif; ?>
|
72 |
-
|
73 |
-
<?php if ($module->getId() != 'Amazon'): ?>
|
74 |
-
<strong>
|
75 |
-
<?php echo __('WARNING:', 'content-egg'); ?>
|
76 |
-
<?php echo __('This module is deprecated', 'content-egg'); ?>
|
77 |
-
(<a target="_blank" href="<?php echo \ContentEgg\application\Plugin::pluginDocsUrl(); ?>DeprecatedModules.html"><?php _e('what does this mean', 'content-egg'); ?></a>).
|
78 |
-
</strong>
|
79 |
-
<?php endif; ?>
|
80 |
-
</div>
|
81 |
-
<?php endif; ?>
|
82 |
-
|
83 |
-
<?php if (!empty($module) && $requirements = $module->requirements()): ?>
|
84 |
-
<div class="cegg-warning">
|
85 |
-
<strong>
|
86 |
-
<?php echo _e('WARNING:', 'content-egg'); ?>
|
87 |
-
<?php _e('This module cannot be activated!', 'content-egg') ?>
|
88 |
-
<?php _e('Please fix the following error(s):', 'content-egg') ?>
|
89 |
-
<ul>
|
90 |
-
<li><?php echo join('</li><li>', $requirements) ?></li>
|
91 |
-
</ul>
|
92 |
-
|
93 |
-
</strong>
|
94 |
-
</div>
|
95 |
-
<?php endif; ?>
|
96 |
-
|
97 |
-
<?php settings_errors(); ?>
|
98 |
-
<form action="options.php" method="POST">
|
99 |
-
<?php settings_fields($page_slug); ?>
|
100 |
-
<table class="form-table">
|
101 |
-
<?php //do_settings_fields($page_slug, 'default'); ?>
|
102 |
-
<?php do_settings_sections($page_slug); ?>
|
103 |
-
</table>
|
104 |
-
<?php submit_button(); ?>
|
105 |
-
</form>
|
106 |
-
|
107 |
-
</div>
|
108 |
-
|
109 |
-
<div class="cegg-rightcol">
|
110 |
-
<div>
|
111 |
-
<?php
|
112 |
-
if (!empty($description))
|
113 |
-
echo '<p>' . $description . '</p>';
|
114 |
-
|
115 |
-
if (!empty($api_agreement))
|
116 |
-
echo '<div style="text-align: right;"><small><a href="' . esc_attr($api_agreement) . '" target="_blank">' . __('Conditions', 'content-egg') . '</a></small></div>';
|
117 |
-
?>
|
118 |
-
|
119 |
-
<?php if (!empty($module) && $module->isFeedModule() && $last_date = $module->getLastImportDateReadable()): ?>
|
120 |
-
<ul>
|
121 |
-
<li><?php echo sprintf(__('Last feed import: %s.'), $last_date); ?></li>
|
122 |
-
<li><?php echo sprintf(__('Total products: %d.'), $module->getProductCount()); ?></li>
|
123 |
-
</ul>
|
124 |
-
<?php endif; ?>
|
125 |
-
</div>
|
126 |
-
</div>
|
127 |
-
</div>
|
128 |
-
|
129 |
-
</div>
|
130 |
-
</div>
|
131 |
-
</div>
|
132 |
-
</div>
|
133 |
-
|
134 |
-
|
135 |
-
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
136 |
-
</div>
|
137 |
-
<?php include('_promo_box.php'); ?>
|
138 |
<?php endif; ?>
|
1 |
+
<?php defined('\ABSPATH') || exit; ?>
|
2 |
+
|
3 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
4 |
+
<div class="cegg-maincol">
|
5 |
+
<?php endif; ?>
|
6 |
+
<div class="wrap">
|
7 |
+
<h2>
|
8 |
+
<?php _e('Content Egg Settings', 'content-egg'); ?>
|
9 |
+
<?php if (\ContentEgg\application\Plugin::isPro()): ?>
|
10 |
+
<span class="cegg-pro-label">pro</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 |
+
|
16 |
+
<?php \settings_errors(); ?>
|
17 |
+
<form action="options.php" method="POST">
|
18 |
+
<?php \settings_fields($page_slug); ?>
|
19 |
+
<?php \ContentEgg\application\helpers\AdminHelper::doTabsSections($page_slug); ?>
|
20 |
+
<?php \submit_button(); ?>
|
21 |
+
</form>
|
22 |
+
</div>
|
23 |
+
|
24 |
+
<?php if (\ContentEgg\application\Plugin::isFree() || \ContentEgg\application\Plugin::isInactiveEnvato()): ?>
|
25 |
+
</div>
|
26 |
+
<?php include('_promo_box.php'); ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
<?php endif; ?>
|
application/components/AffiliateFeedParserModule.php
CHANGED
@@ -1,281 +1,397 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
const
|
21 |
-
const
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
abstract
|
31 |
-
|
32 |
-
public function
|
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 |
-
if (
|
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 |
-
$this->
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
$this->
|
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 |
-
protected function
|
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 |
-
if (
|
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 |
-
if (
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
8 |
+
use ContentEgg\application\components\ModuleManager;
|
9 |
+
use ContentEgg\application\helpers\TextHelper;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* AffiliateFeedParserModule abstract class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link https://www.keywordrush.com
|
16 |
+
* @copyright Copyright © 2019 keywordrush.com
|
17 |
+
*/
|
18 |
+
abstract class AffiliateFeedParserModule extends AffiliateParserModule {
|
19 |
+
|
20 |
+
const TRANSIENT_LAST_IMPORT_DATE = 'cegg_products_last_import_';
|
21 |
+
const PRODUCTS_TTL = 86400;
|
22 |
+
const MULTIPLE_INSERT_ROWS = 50;
|
23 |
+
const IMPORT_TIME_LIMT = 300;
|
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 |
+
{
|
38 |
+
parent::__construct($module_id);
|
39 |
+
$this->product_model = $this->getProductModel();
|
40 |
+
|
41 |
+
// download feed in background
|
42 |
+
\add_action('cegg_' . $this->getId() . '_init_products', array(get_called_class(), 'initProducts'));
|
43 |
+
}
|
44 |
+
|
45 |
+
public static function initProducts()
|
46 |
+
{
|
47 |
+
$m = ModuleManager::factory(static::getIdStatic());
|
48 |
+
|
49 |
+
try
|
50 |
+
{
|
51 |
+
$m->maybeImportProducts();
|
52 |
+
} catch (\Exception $e)
|
53 |
+
{
|
54 |
+
$error = $e->getMessage();
|
55 |
+
if (!strstr($error, 'Product import is in progress'))
|
56 |
+
$m->setLastImportError($error);
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
public function requirements()
|
61 |
+
{
|
62 |
+
$required_version = '5.6.4';
|
63 |
+
$mysql_version = $this->product_model->getDb()->get_var('SELECT VERSION();');
|
64 |
+
$errors = array();
|
65 |
+
|
66 |
+
if (version_compare($required_version, $mysql_version, '>'))
|
67 |
+
$errors[] = sprintf('You are using MySQL %s. This module requires at least <strong>MySQL %s</strong>.', $mysql_version, $required_version);
|
68 |
+
|
69 |
+
return $errors;
|
70 |
+
}
|
71 |
+
|
72 |
+
public function isZippedFeed()
|
73 |
+
{
|
74 |
+
return false;
|
75 |
+
}
|
76 |
+
|
77 |
+
public function maybeCreateProductTable()
|
78 |
+
{
|
79 |
+
if (!$this->product_model->isTableExists())
|
80 |
+
$this->dbDelta();
|
81 |
+
}
|
82 |
+
|
83 |
+
protected function dbDelta()
|
84 |
+
{
|
85 |
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
86 |
+
|
87 |
+
$sql = $this->product_model->getDump();
|
88 |
+
dbDelta($sql);
|
89 |
+
}
|
90 |
+
|
91 |
+
public function getLastImportDate()
|
92 |
+
{
|
93 |
+
return \get_transient(self::TRANSIENT_LAST_IMPORT_DATE . $this->getId());
|
94 |
+
}
|
95 |
+
|
96 |
+
public function getLastImportError()
|
97 |
+
{
|
98 |
+
return \get_transient(self::TRANSIENT_LAST_IMPORT_ERROR . $this->getId());
|
99 |
+
}
|
100 |
+
|
101 |
+
public function setLastImportDate($time = null)
|
102 |
+
{
|
103 |
+
if ($time === null)
|
104 |
+
$time = time();
|
105 |
+
\set_transient(self::TRANSIENT_LAST_IMPORT_DATE . $this->getId(), $time);
|
106 |
+
}
|
107 |
+
|
108 |
+
public function setLastImportError($error)
|
109 |
+
{
|
110 |
+
\set_transient(self::TRANSIENT_LAST_IMPORT_ERROR . $this->getId(), $error);
|
111 |
+
}
|
112 |
+
|
113 |
+
public function maybeImportProducts()
|
114 |
+
{
|
115 |
+
$last_export = $this->getLastImportDate();
|
116 |
+
|
117 |
+
// product import is in progress?
|
118 |
+
if ($last_export && $last_export < 0)
|
119 |
+
{
|
120 |
+
if (time() + $last_export > static::IMPORT_TIME_LIMT)
|
121 |
+
$last_export = 0;
|
122 |
+
else
|
123 |
+
throw new \Exception('Product import is in progress. Try later.');
|
124 |
+
}
|
125 |
+
|
126 |
+
if ($this->isImportTime())
|
127 |
+
{
|
128 |
+
// set in progress flag
|
129 |
+
$this->deleteTemporaryFiles();
|
130 |
+
$this->setLastImportDate(time() * -1);
|
131 |
+
$this->maybeCreateProductTable();
|
132 |
+
|
133 |
+
if (!$this->product_model->isTableExists())
|
134 |
+
throw new \Exception(sprintf('Table %s does not exist', $this->product_model->tableName()));
|
135 |
+
|
136 |
+
$this->importProducts($this->getFeedUrl());
|
137 |
+
return true;
|
138 |
+
}
|
139 |
+
return false;
|
140 |
+
}
|
141 |
+
|
142 |
+
public function isImportTime()
|
143 |
+
{
|
144 |
+
$last_export = $this->getLastImportDate();
|
145 |
+
if (!$last_export || (time() - $last_export > self::PRODUCTS_TTL))
|
146 |
+
return true;
|
147 |
+
else
|
148 |
+
return false;
|
149 |
+
}
|
150 |
+
|
151 |
+
public function importProducts($feed_url)
|
152 |
+
{
|
153 |
+
@set_time_limit(static::IMPORT_TIME_LIMT);
|
154 |
+
\wp_raise_memory_limit();
|
155 |
+
$this->setLastImportError('');
|
156 |
+
register_shutdown_function(array($this, 'fatalHandler'));
|
157 |
+
|
158 |
+
$this->product_model->truncateTable();
|
159 |
+
$file = $this->downlodFeed($feed_url);
|
160 |
+
$this->processFeed($file);
|
161 |
+
|
162 |
+
$this->setLastImportDate();
|
163 |
+
|
164 |
+
@unlink($file);
|
165 |
+
if ($this->rmdir)
|
166 |
+
{
|
167 |
+
@rmdir($this->rmdir);
|
168 |
+
$this->rmdir = null;
|
169 |
+
}
|
170 |
+
}
|
171 |
+
|
172 |
+
protected function downlodFeed($feed_url)
|
173 |
+
{
|
174 |
+
if (!function_exists('\download_url'))
|
175 |
+
require_once( ABSPATH . "wp-admin" . '/includes/file.php');
|
176 |
+
|
177 |
+
$tmp = \download_url($feed_url, 900);
|
178 |
+
if (\is_wp_error($tmp))
|
179 |
+
{
|
180 |
+
$this->setLastImportDate(0);
|
181 |
+
throw new \Exception(sprintf('Feed URL could not be downloaded: %s.', $tmp->get_error_message()));
|
182 |
+
}
|
183 |
+
|
184 |
+
if (!$this->isZippedFeed())
|
185 |
+
return $tmp;
|
186 |
+
else
|
187 |
+
return $this->unzipFeed($tmp);
|
188 |
+
}
|
189 |
+
|
190 |
+
protected function unzipFeed($file)
|
191 |
+
{
|
192 |
+
if (!function_exists('\unzip_file'))
|
193 |
+
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
194 |
+
|
195 |
+
// unzip_file function requires the Filesystem API to be initialized
|
196 |
+
global $wp_filesystem;
|
197 |
+
if (!$wp_filesystem)
|
198 |
+
{
|
199 |
+
require_once ( ABSPATH . '/wp-admin/includes/file.php' );
|
200 |
+
\WP_Filesystem();
|
201 |
+
}
|
202 |
+
|
203 |
+
$to = trailingslashit($this->getDatafeedDir()) . basename($file) . '-unzipped-dir';
|
204 |
+
if (!$to)
|
205 |
+
{
|
206 |
+
throw new \Exception('Temporary directory does not exist.');
|
207 |
+
}
|
208 |
+
|
209 |
+
$result = \unzip_file($file, $to);
|
210 |
+
@unlink($file);
|
211 |
+
if (\is_wp_error($result))
|
212 |
+
{
|
213 |
+
$this->setLastImportDate(0);
|
214 |
+
throw new \Exception(sprintf('Unable to unzip feed archive: %s.', $result->get_error_message()));
|
215 |
+
}
|
216 |
+
|
217 |
+
$scanned = array_values(array_diff(scandir($to), array('..', '.')));
|
218 |
+
if (!$scanned || !isset($scanned[0]))
|
219 |
+
{
|
220 |
+
$this->setLastImportDate(0);
|
221 |
+
throw new \Exception('Unable to find unziped feed.');
|
222 |
+
}
|
223 |
+
|
224 |
+
$this->rmdir = $to;
|
225 |
+
return $to . DIRECTORY_SEPARATOR . $scanned[0];
|
226 |
+
}
|
227 |
+
|
228 |
+
protected function processFeed($file)
|
229 |
+
{
|
230 |
+
$handle = fopen($file, "r");
|
231 |
+
$fields = array();
|
232 |
+
$products = array();
|
233 |
+
|
234 |
+
$delimer = $this->detectCsvDelimiter($file);
|
235 |
+
$in_stock_only = $this->config('in_stock', false);
|
236 |
+
$i = 0;
|
237 |
+
while (($data = fgetcsv($handle, 0, $delimer)) !== false)
|
238 |
+
{
|
239 |
+
if (!$fields)
|
240 |
+
{
|
241 |
+
$fields = $data;
|
242 |
+
continue;
|
243 |
+
}
|
244 |
+
if (count($fields) != count($data))
|
245 |
+
continue;
|
246 |
+
$data = array_combine($fields, $data);
|
247 |
+
|
248 |
+
if (!$product = $this->feedProductPrepare($data))
|
249 |
+
continue;
|
250 |
+
if (!empty($product['ean']))
|
251 |
+
$product['ean'] = TextHelper::fixEan($product['ean']);
|
252 |
+
if ($in_stock_only && $product['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
253 |
+
continue;
|
254 |
+
$products[] = $product;
|
255 |
+
$i++;
|
256 |
+
if ($i % static::MULTIPLE_INSERT_ROWS == 0)
|
257 |
+
{
|
258 |
+
$this->product_model->multipleInsert($products, static::MULTIPLE_INSERT_ROWS);
|
259 |
+
$products = array();
|
260 |
+
}
|
261 |
+
}
|
262 |
+
if ($products)
|
263 |
+
$this->product_model->multipleInsert($products, static::MULTIPLE_INSERT_ROWS);
|
264 |
+
|
265 |
+
fclose($handle);
|
266 |
+
}
|
267 |
+
|
268 |
+
public function getLastImportDateReadable()
|
269 |
+
{
|
270 |
+
$last_import = $this->getLastImportDate();
|
271 |
+
|
272 |
+
if (empty($last_import))
|
273 |
+
return '';
|
274 |
+
|
275 |
+
if ($last_import < 0)
|
276 |
+
return __('Product import is in progress.', 'content-egg');
|
277 |
+
|
278 |
+
if (time() - $last_import <= 43200)
|
279 |
+
return sprintf(__('%s ago', '%s = human-readable time difference', 'content-egg'), \human_time_diff($last_import, time()));
|
280 |
+
|
281 |
+
return TemplateHelper::dateFormatFromGmt($last_import, true);
|
282 |
+
}
|
283 |
+
|
284 |
+
public function getProductCount()
|
285 |
+
{
|
286 |
+
return $this->product_model->count();
|
287 |
+
}
|
288 |
+
|
289 |
+
protected function getDatafeedDir()
|
290 |
+
{
|
291 |
+
$upload_dir = \wp_upload_dir();
|
292 |
+
$datafeed_dir = $upload_dir['basedir'] . '/' . static::DATAFEED_DIR_NAME;
|
293 |
+
|
294 |
+
if (is_dir($datafeed_dir))
|
295 |
+
return $datafeed_dir;
|
296 |
+
|
297 |
+
$files = array(
|
298 |
+
array(
|
299 |
+
'file' => 'index.html',
|
300 |
+
'content' => '',
|
301 |
+
),
|
302 |
+
array(
|
303 |
+
'file' => '.htaccess',
|
304 |
+
'content' => 'deny from all',
|
305 |
+
),
|
306 |
+
);
|
307 |
+
|
308 |
+
foreach ($files as $file)
|
309 |
+
{
|
310 |
+
if (\wp_mkdir_p($datafeed_dir) && !file_exists(trailingslashit($datafeed_dir) . $file['file']))
|
311 |
+
{
|
312 |
+
if ($file_handle = @fopen(trailingslashit($datafeed_dir) . $file['file'], 'w'))
|
313 |
+
{
|
314 |
+
fwrite($file_handle, $file['content']);
|
315 |
+
fclose($file_handle);
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
if (!is_dir($datafeed_dir))
|
321 |
+
throw new \Exception('Can not create temporary directory for datafeed.');
|
322 |
+
|
323 |
+
return $datafeed_dir;
|
324 |
+
}
|
325 |
+
|
326 |
+
protected function detectCsvDelimiter($file)
|
327 |
+
{
|
328 |
+
$delimiters = array(
|
329 |
+
';' => 0,
|
330 |
+
',' => 0,
|
331 |
+
"\t" => 0,
|
332 |
+
"|" => 0
|
333 |
+
);
|
334 |
+
|
335 |
+
$handle = fopen($file, "r");
|
336 |
+
$firstLine = fgets($handle);
|
337 |
+
fclose($handle);
|
338 |
+
foreach ($delimiters as $delimiter => &$count)
|
339 |
+
{
|
340 |
+
$count = count(str_getcsv($firstLine, $delimiter));
|
341 |
+
}
|
342 |
+
|
343 |
+
return array_search(max($delimiters), $delimiters);
|
344 |
+
}
|
345 |
+
|
346 |
+
public function fatalHandler()
|
347 |
+
{
|
348 |
+
if (!$error = error_get_last())
|
349 |
+
return;
|
350 |
+
|
351 |
+
if (!isset($error['file']) || !strpos($error['file'], 'AffiliateFeedParserModule.php'))
|
352 |
+
return;
|
353 |
+
|
354 |
+
$message = $error['message'];
|
355 |
+
if (strstr($message, 'Allowed memory size'))
|
356 |
+
$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');
|
357 |
+
|
358 |
+
$this->setLastImportError($message);
|
359 |
+
}
|
360 |
+
|
361 |
+
public function deleteTemporaryFiles()
|
362 |
+
{
|
363 |
+
$dir = trailingslashit($this->getDatafeedDir());
|
364 |
+
$parts = explode('/', $dir);
|
365 |
+
if ($parts[count($parts) - 2] !== self::DATAFEED_DIR_NAME)
|
366 |
+
{
|
367 |
+
throw new \Exception('Unexpected error while cleaning temporary directory.');
|
368 |
+
return;
|
369 |
+
}
|
370 |
+
|
371 |
+
$scanned = array_values(array_diff(scandir($dir), array('..', '.', 'index.html', '.htaccess')));
|
372 |
+
if (!$scanned)
|
373 |
+
return;
|
374 |
+
|
375 |
+
global $wp_filesystem;
|
376 |
+
if (!$wp_filesystem)
|
377 |
+
{
|
378 |
+
require_once ( ABSPATH . '/wp-admin/includes/file.php' );
|
379 |
+
\WP_Filesystem();
|
380 |
+
}
|
381 |
+
|
382 |
+
foreach ($scanned as $s)
|
383 |
+
{
|
384 |
+
$path = $dir . $s;
|
385 |
+
|
386 |
+
if (is_dir($path) && !preg_match('/-unzipped-dir$/', $path))
|
387 |
+
continue;
|
388 |
+
|
389 |
+
if (is_file($path) && pathinfo($path, PATHINFO_EXTENSION) !== 'csv')
|
390 |
+
continue;
|
391 |
+
|
392 |
+
if ($wp_filesystem->exists($path) && time() - filemtime($path) > 3600)
|
393 |
+
$wp_filesystem->delete($path, true);
|
394 |
+
}
|
395 |
+
}
|
396 |
+
|
397 |
+
}
|
application/components/AffiliateFeedParserModuleConfig.php
CHANGED
@@ -1,33 +1,87 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
$options
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ParserModuleConfig abstract class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link https://www.keywordrush.com
|
12 |
+
* @copyright Copyright © 2019 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class AffiliateFeedParserModuleConfig extends AffiliateParserModuleConfig {
|
15 |
+
|
16 |
+
public function options()
|
17 |
+
{
|
18 |
+
$options = array_merge(parent::options(), array(
|
19 |
+
'entries_per_page' => array(
|
20 |
+
'title' => __('Results', 'content-egg'),
|
21 |
+
'description' => __('Number of results for one search query.', 'content-egg'),
|
22 |
+
'callback' => array($this, 'render_input'),
|
23 |
+
'default' => 10,
|
24 |
+
'validator' => array(
|
25 |
+
'trim',
|
26 |
+
'absint',
|
27 |
+
array(
|
28 |
+
'call' => array('\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to'),
|
29 |
+
'arg' => 100,
|
30 |
+
'message' => sprintf(__('The field "%s" can not be more than %d.', 'content-egg'), 'Results', 100),
|
31 |
+
),
|
32 |
+
),
|
33 |
+
),
|
34 |
+
'entries_per_page_update' => array(
|
35 |
+
'title' => __('Results for updates', 'content-egg'),
|
36 |
+
'description' => __('Number of results for automatic updates and autoblogging.', 'content-egg'),
|
37 |
+
'callback' => array($this, 'render_input'),
|
38 |
+
'default' => 6,
|
39 |
+
'validator' => array(
|
40 |
+
'trim',
|
41 |
+
'absint',
|
42 |
+
array(
|
43 |
+
'call' => array('\ContentEgg\application\helpers\FormValidator', 'less_than_equal_to'),
|
44 |
+
'arg' => 100,
|
45 |
+
'message' => sprintf(__('The field "%s" can not be more than %d.', 'content-egg'), 'Results', 100),
|
46 |
+
),
|
47 |
+
),
|
48 |
+
),
|
49 |
+
'partial_url_match' => array(
|
50 |
+
'title' => __('Search partial URL', 'content-egg'),
|
51 |
+
'description' => __('Partial URL match', 'content-egg')
|
52 |
+
. '<p class="description">' . __('You can use part of a URL to search for products by URL.', 'content-egg') . '</p>',
|
53 |
+
'callback' => array($this, 'render_checkbox'),
|
54 |
+
'default' => false,
|
55 |
+
'section' => 'default',
|
56 |
+
),
|
57 |
+
'save_img' => array(
|
58 |
+
'title' => __('Save images', 'content-egg'),
|
59 |
+
'description' => __('Save images on server', 'content-egg'),
|
60 |
+
'callback' => array($this, 'render_checkbox'),
|
61 |
+
'default' => false,
|
62 |
+
'section' => 'default',
|
63 |
+
)));
|
64 |
+
|
65 |
+
$options['update_mode']['dropdown_options'] = array('cron' => __('By schedule (WP cron)', 'content-egg'));
|
66 |
+
$options['update_mode']['default'] = 'cron';
|
67 |
+
$options['update_mode']['validator'][] = array(
|
68 |
+
'call' => array($this, 'emptyLastImportDate'),
|
69 |
+
);
|
70 |
+
|
71 |
+
return $options;
|
72 |
+
}
|
73 |
+
|
74 |
+
public function emptyLastImportDate()
|
75 |
+
{
|
76 |
+
$this->getModuleInstance()->setLastImportDate(0);
|
77 |
+
$this->getModuleInstance()->setLastImportError('');
|
78 |
+
|
79 |
+
// download feed in background
|
80 |
+
$hook = 'cegg_' . $this->getModuleId() . '_init_products';
|
81 |
+
if ($this->option('is_active') && !\wp_next_scheduled($hook))
|
82 |
+
\wp_schedule_single_event(time(), $hook);
|
83 |
+
|
84 |
+
return true;
|
85 |
+
}
|
86 |
+
|
87 |
+
}
|
application/components/AffiliateParserModule.php
CHANGED
@@ -1,59 +1,84 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
*
|
11 |
-
*
|
12 |
-
* @
|
13 |
-
* @
|
14 |
-
|
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 |
-
public function
|
55 |
-
{
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\TextHelper;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* AffiliateParserModule abstract class file
|
11 |
+
*
|
12 |
+
* @author keywordrush.com <support@keywordrush.com>
|
13 |
+
* @link https://www.keywordrush.com
|
14 |
+
* @copyright Copyright © 2020 keywordrush.com
|
15 |
+
*/
|
16 |
+
abstract class AffiliateParserModule extends ParserModule {
|
17 |
+
|
18 |
+
final public function isAffiliateParser()
|
19 |
+
{
|
20 |
+
return true;
|
21 |
+
}
|
22 |
+
|
23 |
+
public function isCouponParser()
|
24 |
+
{
|
25 |
+
if (strpos($this->getName(), 'Coupon') !== false || $this->getName() == 'CJ Links')
|
26 |
+
return true;
|
27 |
+
else
|
28 |
+
return false;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function isProductParser()
|
32 |
+
{
|
33 |
+
return !$this->isCouponParser();
|
34 |
+
}
|
35 |
+
|
36 |
+
public function isAeParser()
|
37 |
+
{
|
38 |
+
if ($this->getIdStatic() == 'AE')
|
39 |
+
return true;
|
40 |
+
else
|
41 |
+
return false;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function isItemsUpdateAvailable()
|
45 |
+
{
|
46 |
+
return false;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function doRequestItems(array $items)
|
50 |
+
{
|
51 |
+
throw new \Exception('doRequestItems method not implemented yet');
|
52 |
+
}
|
53 |
+
|
54 |
+
public function presavePrepare($data, $post_id)
|
55 |
+
{
|
56 |
+
$data = parent::presavePrepare($data, $post_id);
|
57 |
+
foreach ($data as $key => $item)
|
58 |
+
{
|
59 |
+
$data[$key]['percentageSaved'] = 0;
|
60 |
+
if (!isset($data[$key]['priceOld']))
|
61 |
+
$data[$key]['priceOld'] = $item['priceOld'] = 0;
|
62 |
+
if (!empty($item['priceOld']) && $item['priceOld'] <= $item['price'])
|
63 |
+
$data[$key]['priceOld'] = 0;
|
64 |
+
|
65 |
+
if (!isset($data[$key]['priceOld']))
|
66 |
+
$data[$key]['priceOld'] = 0;
|
67 |
+
if ($data[$key]['priceOld'] && $data[$key]['price'] && $data[$key]['price'] < $data[$key]['priceOld'])
|
68 |
+
$data[$key]['percentageSaved'] = floor(((float) $data[$key]['priceOld'] - (float) $data[$key]['price']) / (float) $data[$key]['priceOld'] * 100);
|
69 |
+
|
70 |
+
if (empty($data[$key]['currency']) && !empty($item['currencyCode']))
|
71 |
+
$data[$key]['currency'] = TextHelper::currencyTyping($item['currencyCode']);
|
72 |
+
|
73 |
+
if (!empty($data[$key]['domain']))
|
74 |
+
$data[$key]['merchant'] = \apply_filters('content_egg_custom_merchant', $data[$key]['merchant'], $data[$key]['domain']);
|
75 |
+
}
|
76 |
+
return $data;
|
77 |
+
}
|
78 |
+
|
79 |
+
public function renderUpdatePanel()
|
80 |
+
{
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
}
|
application/components/AffiliateParserModuleConfig.php
CHANGED
@@ -1,61 +1,66 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ParserModuleConfig abstract class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2016 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class AffiliateParserModuleConfig extends ParserModuleConfig {
|
15 |
+
|
16 |
+
public function options()
|
17 |
+
{
|
18 |
+
$options = array(
|
19 |
+
'ttl' => array(
|
20 |
+
'title' => __('Update by keyword', 'content-egg'),
|
21 |
+
'description' => __('Lifetime of cache in seconds, after this period products will be updated if you set keyword for updating. 0 - never update', 'content-egg'),
|
22 |
+
'callback' => array($this, 'render_input'),
|
23 |
+
'default' => 2592000,
|
24 |
+
'validator' => array(
|
25 |
+
'trim',
|
26 |
+
'absint',
|
27 |
+
),
|
28 |
+
'section' => 'default',
|
29 |
+
),
|
30 |
+
);
|
31 |
+
|
32 |
+
if ($this->getModuleInstance()->isItemsUpdateAvailable())
|
33 |
+
{
|
34 |
+
$options['ttl_items'] = array(
|
35 |
+
'title' => __('Price update', 'content-egg'),
|
36 |
+
'description' => __('Time in seconds for updating prices, availability, etc. 0 - never update', 'content-egg'),
|
37 |
+
'callback' => array($this, 'render_input'),
|
38 |
+
'default' => 604800,
|
39 |
+
'validator' => array(
|
40 |
+
'trim',
|
41 |
+
'absint',
|
42 |
+
),
|
43 |
+
'section' => 'default',
|
44 |
+
);
|
45 |
+
}
|
46 |
+
$options['update_mode'] = array(
|
47 |
+
'title' => __('Update mode', 'content-egg'),
|
48 |
+
'description' => '',
|
49 |
+
'callback' => array($this, 'render_dropdown'),
|
50 |
+
'dropdown_options' => array(
|
51 |
+
'visit' => __('By page view', 'content-egg'),
|
52 |
+
'cron' => __('By schedule (WP cron)', 'content-egg'),
|
53 |
+
'visit_cron' => __('By page view and by schedule', 'content-egg'),
|
54 |
+
),
|
55 |
+
'default' => 'visit',
|
56 |
+
);
|
57 |
+
|
58 |
+
return
|
59 |
+
array_merge(
|
60 |
+
parent::options(), $options
|
61 |
+
);
|
62 |
+
}
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
}
|
application/components/BlockTemplateManager.php
CHANGED
@@ -1,87 +1,89 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
const
|
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
|
85 |
-
|
86 |
-
|
87 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* BlockTemplateManager class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
25 |
+
if (self::$instance === null)
|
26 |
+
{
|
27 |
+
self::$instance = new self;
|
28 |
+
}
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
private function __construct()
|
33 |
+
{
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
public function getTempatePrefix()
|
38 |
+
{
|
39 |
+
return self::TEMPLATE_PREFIX;
|
40 |
+
}
|
41 |
+
|
42 |
+
public function getTempateDir()
|
43 |
+
{
|
44 |
+
return \ContentEgg\PLUGIN_PATH . self::TEMPLATE_DIR;
|
45 |
+
}
|
46 |
+
|
47 |
+
public function getCustomTempateDirs()
|
48 |
+
{
|
49 |
+
return array(
|
50 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, //child theme
|
51 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, // theme
|
52 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR,
|
53 |
+
);
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getModuleId()
|
57 |
+
{
|
58 |
+
return $this->module_id;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getTemplatesList($short_mode = false)
|
62 |
+
{
|
63 |
+
$templates = parent::getTemplatesList($short_mode);
|
64 |
+
$templates = \apply_filters('content_egg_block_templates', $templates);
|
65 |
+
return $templates;
|
66 |
+
}
|
67 |
+
|
68 |
+
public function render($view_name, array $_data = array())
|
69 |
+
{
|
70 |
+
if (!self::isCustomTemplate($view_name))
|
71 |
+
$this->enqueueProductsStyle();
|
72 |
+
return parent::render($view_name, $_data);
|
73 |
+
}
|
74 |
+
|
75 |
+
public function getPartialViewPath($view_name, $block = false)
|
76 |
+
{
|
77 |
+
$file = parent::getPartialViewPath($view_name, $block);
|
78 |
+
if ($file)
|
79 |
+
return $file;
|
80 |
+
|
81 |
+
// allow render general block templates as partial
|
82 |
+
$file = $this->getViewPath($view_name);
|
83 |
+
if ($file)
|
84 |
+
return $file;
|
85 |
+
else
|
86 |
+
return false;
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
application/components/CEWidget.php
CHANGED
@@ -1,197 +1,199 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
protected $
|
18 |
-
protected $
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
$this->
|
29 |
-
$this->
|
30 |
-
$this->
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
\add_action('
|
39 |
-
\add_action('
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
abstract public function
|
45 |
-
|
46 |
-
abstract
|
47 |
-
|
48 |
-
abstract
|
49 |
-
|
50 |
-
public function
|
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 |
-
return
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
if (isset($setting['
|
103 |
-
$instance[$key] = $setting['
|
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 |
-
<?php
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
<?php
|
158 |
-
|
159 |
-
<?php
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ProductSearchWidget class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class CEWidget extends \WP_Widget {
|
15 |
+
|
16 |
+
public $name;
|
17 |
+
protected $slug;
|
18 |
+
protected $description;
|
19 |
+
protected $classname;
|
20 |
+
protected $settings;
|
21 |
+
|
22 |
+
public function __construct()
|
23 |
+
{
|
24 |
+
\add_action('widgets_init', function() {
|
25 |
+
\register_widget(get_called_class());
|
26 |
+
});
|
27 |
+
|
28 |
+
$this->slug = $this->slug();
|
29 |
+
$this->name = $this->name();
|
30 |
+
$this->description = $this->description();
|
31 |
+
$this->classname = $this->classname();
|
32 |
+
$this->settings = $this->settings();
|
33 |
+
|
34 |
+
parent::__construct(
|
35 |
+
$this->slug, \esc_html($this->name), array('description' => \esc_html($this->description), 'classname' => $this->classname)
|
36 |
+
);
|
37 |
+
|
38 |
+
\add_action('save_post', array($this, 'flushСache'));
|
39 |
+
\add_action('deleted_post', array($this, 'flushСache'));
|
40 |
+
\add_action('switch_theme', array($this, 'flushСache'));
|
41 |
+
\add_action('content_egg_price_history_save', array($this, 'flushСache'));
|
42 |
+
}
|
43 |
+
|
44 |
+
abstract public function slug();
|
45 |
+
|
46 |
+
abstract public function description();
|
47 |
+
|
48 |
+
abstract protected function name();
|
49 |
+
|
50 |
+
abstract public function classname();
|
51 |
+
|
52 |
+
public function settings()
|
53 |
+
{
|
54 |
+
return array();
|
55 |
+
}
|
56 |
+
|
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 |
+
}
|
67 |
+
|
68 |
+
public function getCache($key = 0)
|
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()
|
85 |
+
{
|
86 |
+
\wp_cache_delete($this->slug, 'widget');
|
87 |
+
}
|
88 |
+
|
89 |
+
public function update($new_instance, $old_instance)
|
90 |
+
{
|
91 |
+
$instance = array();
|
92 |
+
|
93 |
+
if (!$this->settings || !is_array($this->settings))
|
94 |
+
return array();
|
95 |
+
|
96 |
+
foreach ($this->settings as $key => $setting)
|
97 |
+
{
|
98 |
+
switch ($setting['type'])
|
99 |
+
{
|
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'));
|
109 |
+
break;
|
110 |
+
case 'checkbox':
|
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'];
|
130 |
+
switch ($setting['type'])
|
131 |
+
{
|
132 |
+
case 'number' :
|
133 |
+
?>
|
134 |
+
<p>
|
135 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>:</label>
|
136 |
+
<input class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>" name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="number" min="<?php echo \esc_attr($setting['min']); ?>" max="<?php echo \esc_attr($setting['max']); ?>" value="<?php echo \esc_attr($value); ?>" />
|
137 |
+
</p>
|
138 |
+
<?php
|
139 |
+
break;
|
140 |
+
|
141 |
+
case 'select' :
|
142 |
+
?>
|
143 |
+
<p>
|
144 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>:</label>
|
145 |
+
<select class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>" name="<?php echo \esc_attr($this->get_field_name($key)); ?>">
|
146 |
+
<?php foreach ($setting['options'] as $option_key => $option_value) : ?>
|
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>
|
150 |
+
</p>
|
151 |
+
<?php
|
152 |
+
break;
|
153 |
+
|
154 |
+
case 'textarea' :
|
155 |
+
?>
|
156 |
+
<p>
|
157 |
+
<label for="<?php echo $this->get_field_id($key); ?>"><?php echo $setting['title']; ?>:</label>
|
158 |
+
<textarea class="widefat <?php echo esc_attr($class); ?>" id="<?php echo esc_attr($this->get_field_id($key)); ?>" name="<?php echo $this->get_field_name($key); ?>" cols="20" rows="3"><?php echo esc_textarea($value); ?></textarea>
|
159 |
+
<?php if (isset($setting['desc'])) : ?>
|
160 |
+
<small><?php echo esc_html($setting['desc']); ?></small>
|
161 |
+
<?php endif; ?>
|
162 |
+
</p>
|
163 |
+
<?php
|
164 |
+
break;
|
165 |
+
|
166 |
+
case 'checkbox' :
|
167 |
+
?>
|
168 |
+
<p>
|
169 |
+
<input class="checkbox" id="<?php echo \esc_attr($this->get_field_id($key)); ?>" name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="checkbox" value="1" <?php checked($value, 1); ?> />
|
170 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?></label>
|
171 |
+
</p>
|
172 |
+
<?php
|
173 |
+
break;
|
174 |
+
default :
|
175 |
+
?>
|
176 |
+
<p>
|
177 |
+
<label for="<?php echo \esc_attr($this->get_field_id($key)); ?>"><?php echo \esc_attr($setting['title']); ?>:</label>
|
178 |
+
<input class="widefat" id="<?php echo \esc_attr($this->get_field_id($key)); ?>" name="<?php echo \esc_attr($this->get_field_name($key)); ?>" type="text" value="<?php echo \esc_attr($value); ?>">
|
179 |
+
</p>
|
180 |
+
<?php
|
181 |
+
break;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
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 |
+
echo $args['before_title'] . $title . $args['after_title'];
|
192 |
+
}
|
193 |
+
|
194 |
+
public function afterWidget($args, $instance)
|
195 |
+
{
|
196 |
+
echo $args['after_widget'];
|
197 |
+
}
|
198 |
+
|
199 |
+
}
|
application/components/Config.php
CHANGED
@@ -1,409 +1,413 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
protected $
|
17 |
-
protected $
|
18 |
-
protected $
|
19 |
-
protected $
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
$instance_id = $
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
$this->
|
46 |
-
$this->
|
47 |
-
$this->
|
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 |
-
$this->
|
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 |
-
$field['
|
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 |
-
echo
|
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 |
-
if (
|
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 |
-
}
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Config class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class Config {
|
15 |
+
|
16 |
+
protected $page_slug;
|
17 |
+
protected $option_name;
|
18 |
+
protected $option_values = array();
|
19 |
+
protected $options = array();
|
20 |
+
protected $input = array();
|
21 |
+
protected $out = array();
|
22 |
+
private static $_instances = array();
|
23 |
+
|
24 |
+
public static function getInstance($id = null)
|
25 |
+
{
|
26 |
+
$class = get_called_class();
|
27 |
+
if ($id)
|
28 |
+
$instance_id = $id;
|
29 |
+
else
|
30 |
+
$instance_id = $class;
|
31 |
+
|
32 |
+
if (!isset(self::$_instances[$instance_id]))
|
33 |
+
self::$_instances[$instance_id] = new $class($id);
|
34 |
+
|
35 |
+
return self::$_instances[$instance_id];
|
36 |
+
}
|
37 |
+
|
38 |
+
protected function __construct()
|
39 |
+
{
|
40 |
+
$values = \get_option($this->option_name());
|
41 |
+
// prevent call validators twice for first time. Settings API bug?
|
42 |
+
if ($values === false)
|
43 |
+
\add_option($this->option_name(), '');
|
44 |
+
|
45 |
+
$this->option_name = $this->option_name();
|
46 |
+
$this->options = $this->options();
|
47 |
+
$this->option_values = $values;
|
48 |
+
$this->page_slug = $this->page_slug();
|
49 |
+
}
|
50 |
+
|
51 |
+
public function option($opt_name)
|
52 |
+
{
|
53 |
+
return $this->get_current($opt_name);
|
54 |
+
}
|
55 |
+
|
56 |
+
public function adminInit()
|
57 |
+
{
|
58 |
+
global $pagenow;
|
59 |
+
\add_action('admin_menu', array($this, 'add_admin_menu'));
|
60 |
+
|
61 |
+
if ($pagenow == 'options.php' || (!empty($_GET['page']) && $_GET['page'] == $this->page_slug))
|
62 |
+
{
|
63 |
+
\add_action('admin_init', array($this, 'register_settings'));
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
abstract public function page_slug();
|
68 |
+
|
69 |
+
abstract public function option_name();
|
70 |
+
|
71 |
+
abstract protected function options();
|
72 |
+
|
73 |
+
abstract public function add_admin_menu();
|
74 |
+
|
75 |
+
public function get_page_slug()
|
76 |
+
{
|
77 |
+
return $this->page_slug;
|
78 |
+
}
|
79 |
+
|
80 |
+
protected function get_default($option)
|
81 |
+
{
|
82 |
+
if (isset($this->options[$option]) && isset($this->options[$option]['default']))
|
83 |
+
return $this->options[$option]['default'];
|
84 |
+
else
|
85 |
+
return '';
|
86 |
+
}
|
87 |
+
|
88 |
+
protected function get_validator($option)
|
89 |
+
{
|
90 |
+
if (isset($this->options[$option]) && isset($this->options[$option]['validator']))
|
91 |
+
return $this->options[$option]['validator'];
|
92 |
+
else
|
93 |
+
return null;
|
94 |
+
}
|
95 |
+
|
96 |
+
protected function get_current($option)
|
97 |
+
{
|
98 |
+
if (isset($this->option_values[$option]))
|
99 |
+
return $this->option_values[$option];
|
100 |
+
elseif ($this->option_values && $this->is_checkbox($option))
|
101 |
+
{
|
102 |
+
return false;
|
103 |
+
} else
|
104 |
+
return $this->get_default($option);
|
105 |
+
}
|
106 |
+
|
107 |
+
public function register_settings()
|
108 |
+
{
|
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 |
+
{
|
122 |
+
if (empty($field['title']))
|
123 |
+
$field['title'] = '';
|
124 |
+
if (empty($field['description']))
|
125 |
+
$field['description'] = '';
|
126 |
+
$params = array(
|
127 |
+
'name' => $id, // value for 'name' attribute
|
128 |
+
'title' => $field['title'],
|
129 |
+
'description' => $field['description'],
|
130 |
+
'value' => $this->get_current($id),
|
131 |
+
'option_name' => $this->option_name,
|
132 |
+
'label_for' => 'label-' . $id,
|
133 |
+
);
|
134 |
+
if (!empty($field['dropdown_options']))
|
135 |
+
$params['dropdown_options'] = $field['dropdown_options'];
|
136 |
+
if (!empty($field['checkbox_options']))
|
137 |
+
$params['checkbox_options'] = $field['checkbox_options'];
|
138 |
+
|
139 |
+
if (!empty($field['render_after']))
|
140 |
+
$params['render_after'] = $field['render_after'];
|
141 |
+
if (empty($field['section']))
|
142 |
+
$field['section'] = 'default';
|
143 |
+
|
144 |
+
// section
|
145 |
+
if (!isset($sections[$field['section']]))
|
146 |
+
{
|
147 |
+
if ($field['section'] == 'default')
|
148 |
+
$section_title = '';
|
149 |
+
else
|
150 |
+
$section_title = $field['section'];
|
151 |
+
|
152 |
+
\add_settings_section(\sanitize_text_field($field['section']), $section_title, null, $this->page_slug);
|
153 |
+
$sections[$field['section']] = $field['section'];
|
154 |
+
}
|
155 |
+
|
156 |
+
\add_settings_field(
|
157 |
+
$id, $field['title'], $field['callback'], $this->page_slug, // menu slug
|
158 |
+
$field['section'], $params
|
159 |
+
);
|
160 |
+
}
|
161 |
+
}
|
162 |
+
|
163 |
+
public function render_input($args)
|
164 |
+
{
|
165 |
+
if (!empty($args['class']))
|
166 |
+
$class = $args['class'];
|
167 |
+
else
|
168 |
+
$class = 'regular-text ltr';
|
169 |
+
if (!empty($args['type']))
|
170 |
+
$type = $args['type'];
|
171 |
+
else
|
172 |
+
$type = 'text';
|
173 |
+
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) . '" />';
|
174 |
+
if (!empty($args['render_after']))
|
175 |
+
echo $args['render_after'];
|
176 |
+
if ($args['description'])
|
177 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
178 |
+
}
|
179 |
+
|
180 |
+
public function render_textarea($args)
|
181 |
+
{
|
182 |
+
echo '<textarea name="' . esc_attr($args['option_name']) . '['
|
183 |
+
. esc_attr($args['name']) . ']" id="'
|
184 |
+
. esc_attr($args['label_for']) . '" rows="4" class="large-text code">' . esc_html($args['value']) . '</textarea>';
|
185 |
+
if (!empty($args['render_after']))
|
186 |
+
echo $args['render_after'];
|
187 |
+
if ($args['description'])
|
188 |
+
{
|
189 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
190 |
+
}
|
191 |
+
}
|
192 |
+
|
193 |
+
public function render_checkbox($args)
|
194 |
+
{
|
195 |
+
if ((bool) $args['value'])
|
196 |
+
$checked = ' checked="checked" ';
|
197 |
+
else
|
198 |
+
$checked = '';
|
199 |
+
echo '<label for="' . esc_attr($args['label_for']) . '">';
|
200 |
+
echo '<input type="checkbox" name="' . esc_attr($args['option_name']) . '['
|
201 |
+
. esc_attr($args['name']) . ']" id="'
|
202 |
+
. esc_attr($args['label_for']), '"'
|
203 |
+
. $checked . ' value="1" />';
|
204 |
+
if ($args['description'])
|
205 |
+
{
|
206 |
+
echo ' ' . $args['description'];
|
207 |
+
}
|
208 |
+
echo '</label>';
|
209 |
+
}
|
210 |
+
|
211 |
+
public function render_dropdown($args)
|
212 |
+
{
|
213 |
+
echo '<select name="' . esc_attr($args['option_name']) . '['
|
214 |
+
. esc_attr($args['name']) . ']" id="'
|
215 |
+
. esc_attr($args['label_for']) . '" value="'
|
216 |
+
. esc_attr($args['value']) . '" >';
|
217 |
+
foreach ($args['dropdown_options'] as $option_value => $option_name)
|
218 |
+
{
|
219 |
+
if ($option_value === $args['value'])
|
220 |
+
$selected = ' selected="selected" ';
|
221 |
+
else
|
222 |
+
$selected = '';
|
223 |
+
echo '<option value="' . esc_attr($option_value) . '"' . $selected . '>' . esc_html($option_name) . '</option>';
|
224 |
+
}
|
225 |
+
echo '</select>';
|
226 |
+
|
227 |
+
if (!empty($args['render_after']))
|
228 |
+
echo $args['render_after'];
|
229 |
+
if ($args['description'])
|
230 |
+
{
|
231 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
public function render_checkbox_list($args)
|
236 |
+
{
|
237 |
+
echo '<div class="cegg-checkboxgroup">';
|
238 |
+
foreach ($args['checkbox_options'] as $value => $name)
|
239 |
+
{
|
240 |
+
if (in_array($value, $args['value']))
|
241 |
+
$checked = ' checked="checked" ';
|
242 |
+
else
|
243 |
+
$checked = '';
|
244 |
+
|
245 |
+
echo '<div class="cegg-checkbox">';
|
246 |
+
echo '<label for="' . esc_attr($args['label_for'] . '-' . $value) . '">';
|
247 |
+
echo '<input type="checkbox" name="' . esc_attr($args['option_name']) . '['
|
248 |
+
. esc_attr($args['name']) . '][' . esc_attr($value) . ']" id="'
|
249 |
+
. esc_attr($args['label_for'] . '-' . $value), '"'
|
250 |
+
. $checked . ' value="' . esc_attr($value) . '" />';
|
251 |
+
echo esc_html($name);
|
252 |
+
echo '</label>';
|
253 |
+
echo '</div>';
|
254 |
+
}
|
255 |
+
echo '</div>';
|
256 |
+
if ($args['description'])
|
257 |
+
{
|
258 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
259 |
+
}
|
260 |
+
}
|
261 |
+
|
262 |
+
public function render_hidden($args)
|
263 |
+
{
|
264 |
+
echo '<input type="hidden" name="' . esc_attr($args['option_name']) . '['
|
265 |
+
. esc_attr($args['name']) . '] value="'
|
266 |
+
. esc_attr($args['value']) . '" />';
|
267 |
+
}
|
268 |
+
|
269 |
+
public function render_color_picker($args)
|
270 |
+
{
|
271 |
+
echo '<input name="' . esc_attr($args['option_name']) . '['
|
272 |
+
. esc_attr($args['name']) . ']" id="'
|
273 |
+
. esc_attr($args['label_for']) . '" value="'
|
274 |
+
. esc_attr($args['value']) . '" />';
|
275 |
+
if (!empty($args['render_after']))
|
276 |
+
echo $args['render_after'];
|
277 |
+
if ($args['description'])
|
278 |
+
{
|
279 |
+
echo '<p class="description">' . $args['description'] . '</p>';
|
280 |
+
}
|
281 |
+
\wp_enqueue_style('wp-color-picker');
|
282 |
+
\wp_enqueue_script('wp-color-picker', \admin_url('js/color-picker.min.js'));
|
283 |
+
$script = "jQuery(document).ready(function($){jQuery('#" . esc_attr($args['label_for']) . "').wpColorPicker();});";
|
284 |
+
echo '<script type="text/javascript">' . $script . '</script>';
|
285 |
+
}
|
286 |
+
|
287 |
+
public function option_exists($option)
|
288 |
+
{
|
289 |
+
if (array_key_exists($option, $this->options))
|
290 |
+
return true;
|
291 |
+
else
|
292 |
+
return false;
|
293 |
+
}
|
294 |
+
|
295 |
+
public function validate($input)
|
296 |
+
{
|
297 |
+
$this->input = $input;
|
298 |
+
|
299 |
+
if (!is_array($this->input))
|
300 |
+
return;
|
301 |
+
|
302 |
+
foreach ($this->input as $option => $value)
|
303 |
+
{
|
304 |
+
if (!$this->option_exists($option))
|
305 |
+
continue;
|
306 |
+
|
307 |
+
if (!is_array($value))
|
308 |
+
$value = trim($value);
|
309 |
+
if ($validator = $this->get_validator($option))
|
310 |
+
{
|
311 |
+
if (!is_array($validator))
|
312 |
+
continue;
|
313 |
+
foreach ($validator as $v)
|
314 |
+
{
|
315 |
+
if (!is_array($v))
|
316 |
+
{
|
317 |
+
if ($v == 'allow_empty')
|
318 |
+
{
|
319 |
+
if ($value === '')
|
320 |
+
break;
|
321 |
+
else
|
322 |
+
continue;
|
323 |
+
}
|
324 |
+
|
325 |
+
// filter
|
326 |
+
$value = call_user_func($v, $value);
|
327 |
+
} else
|
328 |
+
{
|
329 |
+
// check 'when' condition
|
330 |
+
if (!empty($v['when']))
|
331 |
+
{
|
332 |
+
$when_value = $this->get_submitted_value($v['when']);
|
333 |
+
if (!$when_value)
|
334 |
+
continue;
|
335 |
+
}
|
336 |
+
|
337 |
+
if (!empty($v['type']) && $v['type'] == 'filter')
|
338 |
+
{
|
339 |
+
// filter
|
340 |
+
$value = call_user_func($v['call'], $value);
|
341 |
+
} else
|
342 |
+
{
|
343 |
+
// validator
|
344 |
+
if (empty($v['arg']))
|
345 |
+
$res = call_user_func($v['call'], $value);
|
346 |
+
else
|
347 |
+
$res = call_user_func($v['call'], $value, $v['arg']);
|
348 |
+
if (!$res)
|
349 |
+
{
|
350 |
+
\add_settings_error($option, $option, $v['message']);
|
351 |
+
$value = $this->get_current($option);
|
352 |
+
if (!empty($v['when']))
|
353 |
+
$this->out[$v['when']] = $this->get_current($v['when']);
|
354 |
+
break;
|
355 |
+
}
|
356 |
+
} // .validator
|
357 |
+
}
|
358 |
+
}
|
359 |
+
}
|
360 |
+
$this->out[$option] = $value;
|
361 |
+
}
|
362 |
+
return $this->out;
|
363 |
+
}
|
364 |
+
|
365 |
+
public function is_checkbox($option)
|
366 |
+
{
|
367 |
+
if ($this->options[$option]['callback'][1] == 'render_checkbox')
|
368 |
+
return true;
|
369 |
+
else
|
370 |
+
return false;
|
371 |
+
}
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Current submitted value
|
375 |
+
*/
|
376 |
+
public function get_submitted_value($option, $input = array(), $out = array())
|
377 |
+
{
|
378 |
+
if (!$input)
|
379 |
+
$input = $this->input;
|
380 |
+
if (!$out)
|
381 |
+
$out = $this->out;
|
382 |
+
|
383 |
+
if (!$this->option_exists($option))
|
384 |
+
throw new \Exception('Options "' . $option . '" does not exists.');
|
385 |
+
|
386 |
+
if (!isset($input[$option]) && $this->is_checkbox($option))
|
387 |
+
return false;
|
388 |
+
|
389 |
+
if (!isset($input[$option]))
|
390 |
+
throw new \Exception('Options "' . $option . '" does not exists.');
|
391 |
+
|
392 |
+
if (isset($out[$option]))
|
393 |
+
return $out[$option];
|
394 |
+
else
|
395 |
+
return $input[$option];
|
396 |
+
}
|
397 |
+
|
398 |
+
public function getOptionsList()
|
399 |
+
{
|
400 |
+
return array_keys($this->options());
|
401 |
+
}
|
402 |
+
|
403 |
+
public function getOptionValues()
|
404 |
+
{
|
405 |
+
$result = array();
|
406 |
+
foreach ($this->getOptionsList() as $option_name)
|
407 |
+
{
|
408 |
+
$result[$option_name] = $this->get_current($option_name);
|
409 |
+
}
|
410 |
+
return $result;
|
411 |
+
}
|
412 |
+
|
413 |
+
}
|
application/components/Content.php
CHANGED
@@ -1,23 +1,25 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
public $
|
17 |
-
public $
|
18 |
-
public $
|
19 |
-
|
20 |
-
public $
|
21 |
-
public $
|
22 |
-
|
23 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Content class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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
@@ -1,21 +1,23 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
public $
|
17 |
-
public $
|
18 |
-
public $
|
19 |
-
public $
|
20 |
-
|
21 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ContentCoupon class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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
@@ -1,590 +1,617 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
*
|
18 |
-
*
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
const
|
26 |
-
const
|
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 |
-
self::
|
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 |
-
$data
|
165 |
-
} elseif ($key === '
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
$data =
|
171 |
-
|
172 |
-
$data =
|
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 |
-
$data[$key]['
|
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 |
-
$module = ModuleManager::getInstance()->factory($module_id);
|
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 |
-
$review
|
439 |
-
$review['
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\ImageHelper;
|
8 |
+
use ContentEgg\application\helpers\ArrayHelper;
|
9 |
+
use ContentEgg\application\admin\GeneralConfig;
|
10 |
+
use ContentEgg\application\models\PriceHistoryModel;
|
11 |
+
use ContentEgg\application\PriceAlert;
|
12 |
+
use ContentEgg\application\helpers\CurrencyHelper;
|
13 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
14 |
+
use ContentEgg\application\helpers\TextHelper;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* ContentManager class file
|
18 |
+
*
|
19 |
+
* @author keywordrush.com <support@keywordrush.com>
|
20 |
+
* @link http://www.keywordrush.com/
|
21 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
35 |
+
if (!$data)
|
36 |
+
{
|
37 |
+
self::deleteData($module_id, $post_id, $is_last_iteration);
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
$data = self::dataPresavePrepare($data, $module_id, $post_id);
|
42 |
+
$old_data = ContentManager::getData($post_id, $module_id);
|
43 |
+
|
44 |
+
$outdated = array();
|
45 |
+
$data_changed = true;
|
46 |
+
if ($old_data)
|
47 |
+
{
|
48 |
+
$outdated = array_diff_key($old_data, $data);
|
49 |
+
$new = array_diff_key($data, $old_data);
|
50 |
+
|
51 |
+
if (!$outdated && !$new)
|
52 |
+
$data_changed = false;
|
53 |
+
/*
|
54 |
+
* we need force data update because title or description can be edited manually or items price update
|
55 |
+
*/
|
56 |
+
}
|
57 |
+
|
58 |
+
// save data
|
59 |
+
\update_post_meta($post_id, self::META_PREFIX_DATA . $module_id, $data);
|
60 |
+
self::clearData($outdated);
|
61 |
+
|
62 |
+
// touch last update time only if data changed?
|
63 |
+
if ($data_changed)
|
64 |
+
{
|
65 |
+
self::touchUpdateTime($post_id, $module_id);
|
66 |
+
}
|
67 |
+
|
68 |
+
// save price history
|
69 |
+
if (GeneralConfig::getInstance()->option('price_history_days'))
|
70 |
+
{
|
71 |
+
PriceHistoryModel::model()->saveData($data, $module_id, $post_id);
|
72 |
+
// ...and send price alerts
|
73 |
+
if (GeneralConfig::getInstance()->option('price_alert_enabled'))
|
74 |
+
PriceAlert::getInstance()->sendAlerts($data, $module_id, $post_id);
|
75 |
+
}
|
76 |
+
|
77 |
+
self::resetViewDataCache($module_id, $post_id);
|
78 |
+
|
79 |
+
\do_action('content_egg_save_data', $data, $module_id, $post_id, $is_last_iteration);
|
80 |
+
}
|
81 |
+
|
82 |
+
public static function dataPresavePrepare(array $data, $module_id, $post_id)
|
83 |
+
{
|
84 |
+
foreach ($data as $i => $d)
|
85 |
+
{
|
86 |
+
if (is_object($d))
|
87 |
+
$data[$i] = ArrayHelper::object2Array($d);
|
88 |
+
}
|
89 |
+
$data = self::setIds($data);
|
90 |
+
// Sanitize content for allowed HTML tags and more.
|
91 |
+
array_walk_recursive($data, array('self', 'sanitizeData'));
|
92 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
93 |
+
$data = $module->presavePrepare($data, $post_id);
|
94 |
+
return $data;
|
95 |
+
}
|
96 |
+
|
97 |
+
public static function deleteData($module_id, $post_id, $is_last_iteration = true)
|
98 |
+
{
|
99 |
+
$data = ContentManager::getData($post_id, $module_id);
|
100 |
+
if (!$data)
|
101 |
+
{
|
102 |
+
// last chance to fire last_iteration hook
|
103 |
+
\do_action('content_egg_save_data', array(), $module_id, $post_id, $is_last_iteration);
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
|
107 |
+
\delete_post_meta($post_id, self::META_PREFIX_DATA . $module_id);
|
108 |
+
\delete_post_meta($post_id, self::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id);
|
109 |
+
\delete_post_meta($post_id, self::META_PREFIX_LAST_ITEMS_UPDATE . $module_id);
|
110 |
+
|
111 |
+
self::clearData($data);
|
112 |
+
self::resetViewDataCache($module_id, $post_id);
|
113 |
+
|
114 |
+
\do_action('content_egg_save_data', array(), $module_id, $post_id, $is_last_iteration);
|
115 |
+
}
|
116 |
+
|
117 |
+
private static function clearData($data)
|
118 |
+
{
|
119 |
+
// delete old img files if needed
|
120 |
+
foreach ($data as $d)
|
121 |
+
{
|
122 |
+
if (empty($d['img_file']))
|
123 |
+
continue;
|
124 |
+
$img_file = ImageHelper::getFullImgPath($d['img_file']);
|
125 |
+
|
126 |
+
if (is_file($img_file))
|
127 |
+
@unlink($img_file);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
private static function setIds($data)
|
132 |
+
{
|
133 |
+
$results = array();
|
134 |
+
foreach ($data as $d)
|
135 |
+
{
|
136 |
+
$results[$d['unique_id']] = $d;
|
137 |
+
}
|
138 |
+
return $results;
|
139 |
+
}
|
140 |
+
|
141 |
+
public static function touchUpdateTime($post_id, $module_id, $touch_items = true)
|
142 |
+
{
|
143 |
+
$time = time();
|
144 |
+
\update_post_meta($post_id, self::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id, $time);
|
145 |
+
if ($touch_items)
|
146 |
+
self::touchUpdateItemsTime($post_id, $module_id, $time);
|
147 |
+
}
|
148 |
+
|
149 |
+
public static function touchUpdateItemsTime($post_id, $module_id, $time = null)
|
150 |
+
{
|
151 |
+
if (!$time)
|
152 |
+
$time = time();
|
153 |
+
\update_post_meta($post_id, self::META_PREFIX_LAST_ITEMS_UPDATE . $module_id, $time);
|
154 |
+
}
|
155 |
+
|
156 |
+
private static function sanitizeData(&$data, $key)
|
157 |
+
{
|
158 |
+
if (in_array((string) $key, array('img', 'url', 'IFrameURL', 'orig_url')))
|
159 |
+
{
|
160 |
+
if ($key == 'img')
|
161 |
+
$data = \esc_url_raw($data);
|
162 |
+
else
|
163 |
+
$data = \wp_sanitize_redirect($data);
|
164 |
+
$data = filter_var($data, FILTER_SANITIZE_URL);
|
165 |
+
} elseif ($key === 'description')
|
166 |
+
$data = TextHelper::sanitizeHtml($data);
|
167 |
+
elseif ($key === 'linkHtml')
|
168 |
+
$data; //cj link
|
169 |
+
elseif ($key === 'title')
|
170 |
+
$data = \sanitize_text_field($data);
|
171 |
+
elseif ($key === 'last_update' && !$data)
|
172 |
+
$data = time();
|
173 |
+
elseif ($key === 'ean' && $data)
|
174 |
+
$data = TextHelper::fixEan($data);
|
175 |
+
else
|
176 |
+
$data = \strip_tags($data);
|
177 |
+
}
|
178 |
+
|
179 |
+
public static function isDataExists($post_id, $module_id)
|
180 |
+
{
|
181 |
+
return (bool) \get_post_meta($post_id, self::META_PREFIX_LAST_BYKEYWORD_UPDATE . $module_id, true);
|
182 |
+
}
|
183 |
+
|
184 |
+
public static function getData($post_id, $module_id)
|
185 |
+
{
|
186 |
+
$data = self::fixData(\get_post_meta($post_id, ContentManager::META_PREFIX_DATA . $module_id, true), $module_id);
|
187 |
+
if (!$data)
|
188 |
+
$data = array();
|
189 |
+
return $data;
|
190 |
+
}
|
191 |
+
|
192 |
+
public static function fixData($data, $module_id)
|
193 |
+
{
|
194 |
+
if (!$data || !is_array($data))
|
195 |
+
return $data;
|
196 |
+
|
197 |
+
return $data;
|
198 |
+
}
|
199 |
+
|
200 |
+
public static function getViewData($module_id, $post_id, $params = array())
|
201 |
+
{
|
202 |
+
$data_id = $post_id . '-' . $module_id;
|
203 |
+
if (!isset(self::$_view_data[$data_id]))
|
204 |
+
{
|
205 |
+
$data = self::getData($post_id, $module_id);
|
206 |
+
$data = self::dataPreviewPrepare($data, $module_id, $post_id, $params);
|
207 |
+
|
208 |
+
self::$_view_data[$data_id] = $data;
|
209 |
+
}
|
210 |
+
|
211 |
+
$data = self::$_view_data[$data_id];
|
212 |
+
|
213 |
+
// out of stock products
|
214 |
+
$outofstock_product = GeneralConfig::getInstance()->option('outofstock_product');
|
215 |
+
//@see: ModuleViewer::getData for hide_product filter
|
216 |
+
if ($outofstock_product == 'hide_price')
|
217 |
+
{
|
218 |
+
foreach ($data as $key => $d)
|
219 |
+
{
|
220 |
+
if (isset($d['stock_status']) && $d['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
221 |
+
{
|
222 |
+
$data[$key]['price'] = 0;
|
223 |
+
$data[$key]['priceOld'] = 0;
|
224 |
+
}
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
// locale fix...
|
229 |
+
if (!empty($params['locale']))
|
230 |
+
{
|
231 |
+
foreach ($data as $key => $d)
|
232 |
+
{
|
233 |
+
if (isset($d['extra']['locale']) && strtolower($d['extra']['locale']) != strtolower($params['locale']))
|
234 |
+
unset($data[$key]);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
|
238 |
+
// convert all prices to one currency
|
239 |
+
if (!empty($params['currency']))
|
240 |
+
{
|
241 |
+
foreach ($data as $key => $d)
|
242 |
+
{
|
243 |
+
$rate = CurrencyHelper::getCurrencyRate($d['currencyCode'], $params['currency']);
|
244 |
+
if (!$rate)
|
245 |
+
continue;
|
246 |
+
|
247 |
+
if (!empty($d['price']))
|
248 |
+
{
|
249 |
+
$data[$key]['price'] = $d['price'] * $rate;
|
250 |
+
$data[$key]['currencyCode'] = $params['currency'];
|
251 |
+
}
|
252 |
+
if (!empty($d['priceOld']))
|
253 |
+
{
|
254 |
+
$data[$key]['priceOld'] = $d['priceOld'] * $rate;
|
255 |
+
}
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
return $data;
|
260 |
+
}
|
261 |
+
|
262 |
+
public static function resetViewDataCache($module_id = null, $post_id = null)
|
263 |
+
{
|
264 |
+
if ($module_id && $post_id)
|
265 |
+
{
|
266 |
+
$data_id = $post_id . '-' . $module_id;
|
267 |
+
if (isset(self::$_view_data[$data_id]))
|
268 |
+
unset(self::$_view_data[$data_id]);
|
269 |
+
} else
|
270 |
+
self::$_view_data = array();
|
271 |
+
}
|
272 |
+
|
273 |
+
public static function dataPreviewPrepare(array $data, $module_id, $post_id, $params = array())
|
274 |
+
{
|
275 |
+
$is_ssl = \is_ssl();
|
276 |
+
$http_home_url = str_replace('https://', 'http://', \home_url('/'));
|
277 |
+
foreach ($data as $key => $d)
|
278 |
+
{
|
279 |
+
if (empty($data[$key]['extra']) || !is_array($data[$key]['extra']))
|
280 |
+
$data[$key]['extra'] = array();
|
281 |
+
|
282 |
+
// domain fix && logo
|
283 |
+
if (empty($d['extra']['domain']) && isset($d['domain']))
|
284 |
+
$data[$key]['extra']['domain'] = $d['domain'];
|
285 |
+
elseif (empty($d['domain']) && isset($d['extra']['domain']))
|
286 |
+
$data[$key]['domain'] = $d['extra']['domain'];
|
287 |
+
if (empty($d['extra']['logo']) && isset($d['logo']))
|
288 |
+
$data[$key]['extra']['logo'] = $d['logo'];
|
289 |
+
elseif (empty($d['logo']) && isset($d['extra']['logo']))
|
290 |
+
$data[$key]['logo'] = $d['extra']['logo'];
|
291 |
+
|
292 |
+
// https fix for local images
|
293 |
+
if ($is_ssl && strstr($d['img'], $http_home_url))
|
294 |
+
$data[$key]['img'] = str_replace('http://', '//', $d['img']);
|
295 |
+
|
296 |
+
if (isset($d['percentageSaved']))
|
297 |
+
{
|
298 |
+
$d['percentageSaved'] = (float) $d['percentageSaved'];
|
299 |
+
if (!$d['percentageSaved'] || $d['percentageSaved'] < 0 || $d['percentageSaved'] >= 100)
|
300 |
+
$d['percentageSaved'] = 0;
|
301 |
+
$data[$key]['percentageSaved'] = round($d['percentageSaved']);
|
302 |
+
}
|
303 |
+
|
304 |
+
if (empty($d['rating']) && isset($d['extra']['data']['rating']))
|
305 |
+
$data[$key]['rating'] = $d['extra']['data']['rating'];
|
306 |
+
|
307 |
+
if (isset($data[$key]['rating']))
|
308 |
+
{
|
309 |
+
$data[$key]['rating'] = (float) $data[$key]['rating'];
|
310 |
+
if ($data[$key]['rating'] < 0 || $data[$key]['rating'] > 5)
|
311 |
+
$data[$key]['rating'] = 0;
|
312 |
+
$data[$key]['rating'] = round(($data[$key]['rating'] * 2) / 2);
|
313 |
+
}
|
314 |
+
|
315 |
+
$data[$key]['post_id'] = $post_id;
|
316 |
+
$data[$key]['module_id'] = $module_id;
|
317 |
+
}
|
318 |
+
|
319 |
+
// local redirect & other
|
320 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
321 |
+
if ($module->isParser())
|
322 |
+
$data = $module->viewDataPrepare($data);
|
323 |
+
|
324 |
+
return \apply_filters('cegg_view_data_prepare', $data, $module_id, $post_id, $params);
|
325 |
+
}
|
326 |
+
|
327 |
+
public static function getProductbyUniqueId($unique_id, $module_id, $post_id, $params = array())
|
328 |
+
{
|
329 |
+
$data = self::getViewData($module_id, $post_id, $params);
|
330 |
+
if ($data && isset($data[$unique_id]))
|
331 |
+
return $data[$unique_id];
|
332 |
+
else
|
333 |
+
return null;
|
334 |
+
}
|
335 |
+
|
336 |
+
public static function updateByKeyword($post_id, $module_id)
|
337 |
+
{
|
338 |
+
$keyword = \get_post_meta($post_id, ContentManager::META_PREFIX_KEYWORD . $module_id, true);
|
339 |
+
if (!$keyword)
|
340 |
+
return;
|
341 |
+
|
342 |
+
$updateParams = \get_post_meta($post_id, ContentManager::META_PREFIX_UPDATE_PARAMS . $module_id, true);
|
343 |
+
if (!$updateParams)
|
344 |
+
$updateParams = array();
|
345 |
+
|
346 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
347 |
+
|
348 |
+
// update time in any case...
|
349 |
+
ContentManager::touchUpdateTime($post_id, $module_id, false);
|
350 |
+
|
351 |
+
try
|
352 |
+
{
|
353 |
+
$data = $module->doRequest($keyword, $updateParams, true);
|
354 |
+
|
355 |
+
// nodata!
|
356 |
+
if (!$data)
|
357 |
+
{
|
358 |
+
\do_action('cegg_keyword_update_no_data', $post_id, $module_id);
|
359 |
+
return;
|
360 |
+
}
|
361 |
+
} catch (\Exception $e)
|
362 |
+
{
|
363 |
+
// error
|
364 |
+
return;
|
365 |
+
}
|
366 |
+
|
367 |
+
$data = array_map(array('self', 'object2Array'), $data);
|
368 |
+
ContentManager::saveData($data, $module_id, $post_id);
|
369 |
+
}
|
370 |
+
|
371 |
+
public static function updateItems($post_id, $module_id)
|
372 |
+
{
|
373 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
374 |
+
if (!$module->isItemsUpdateAvailable())
|
375 |
+
return;
|
376 |
+
|
377 |
+
$items = ContentManager::getData($post_id, $module_id);
|
378 |
+
|
379 |
+
if (!$items)
|
380 |
+
return;
|
381 |
+
|
382 |
+
try
|
383 |
+
{
|
384 |
+
$updated_data = $module->doRequestItems($items);
|
385 |
+
} catch (\Exception $e)
|
386 |
+
{
|
387 |
+
// error
|
388 |
+
ContentManager::touchUpdateItemsTime($post_id, $module_id);
|
389 |
+
return;
|
390 |
+
}
|
391 |
+
|
392 |
+
$time = time();
|
393 |
+
foreach ($updated_data as $key => $data)
|
394 |
+
{
|
395 |
+
$updated_data[$key]['last_update'] = $time;
|
396 |
+
}
|
397 |
+
|
398 |
+
// save & update time
|
399 |
+
ContentManager::saveData($updated_data, $module_id, $post_id);
|
400 |
+
ContentManager::touchUpdateItemsTime($post_id, $module_id);
|
401 |
+
}
|
402 |
+
|
403 |
+
/**
|
404 |
+
* Full depth recursive conversion to array
|
405 |
+
* @param type $object
|
406 |
+
* @return array
|
407 |
+
*/
|
408 |
+
public static function object2Array($object)
|
409 |
+
{
|
410 |
+
return json_decode(json_encode($object), true);
|
411 |
+
}
|
412 |
+
|
413 |
+
public static function getNormalizedReviews($data)
|
414 |
+
{
|
415 |
+
$struct = array(
|
416 |
+
'summary' => '',
|
417 |
+
'comment' => '',
|
418 |
+
'rating' => '',
|
419 |
+
'name' => '',
|
420 |
+
'date' => '',
|
421 |
+
'pros' => '',
|
422 |
+
'cons' => '',
|
423 |
+
'review' => '',
|
424 |
+
'parent_id' => '',
|
425 |
+
);
|
426 |
+
|
427 |
+
$reviews = array();
|
428 |
+
foreach ($data as $item)
|
429 |
+
{
|
430 |
+
if (is_object($item))
|
431 |
+
$item = ContentManager::object2Array($item);
|
432 |
+
|
433 |
+
// AE modules & walmart
|
434 |
+
if (!empty($item['extra']['comments']))
|
435 |
+
{
|
436 |
+
foreach ($item['extra']['comments'] as $r)
|
437 |
+
{
|
438 |
+
$review = $struct;
|
439 |
+
$review['comment'] = $r['comment'];
|
440 |
+
if (!empty($r['name']))
|
441 |
+
$review['name'] = $r['name'];
|
442 |
+
if (!empty($r['date']))
|
443 |
+
$review['date'] = $r['date'];
|
444 |
+
if (!empty($r['review']))
|
445 |
+
$review['review'] = $r['review'];
|
446 |
+
if (!empty($r['rating']))
|
447 |
+
$review['rating'] = $r['rating'];
|
448 |
+
if (!empty($r['pros']))
|
449 |
+
$review['pros'] = $r['pros'];
|
450 |
+
if (!empty($r['cons']))
|
451 |
+
$review['cons'] = $r['cons'];
|
452 |
+
if (isset($r['parent_id']))
|
453 |
+
$review['parent_id'] = (int) $r['parent_id'];
|
454 |
+
|
455 |
+
$reviews[] = $review;
|
456 |
+
}
|
457 |
+
}
|
458 |
+
// Ozon
|
459 |
+
elseif (!empty($item['extra']['Reviews']))
|
460 |
+
{
|
461 |
+
foreach ($item['extra']['Reviews'] as $r)
|
462 |
+
{
|
463 |
+
$review = $struct;
|
464 |
+
$review['summary'] = $r->Title;
|
465 |
+
$review['date'] = $r->Date;
|
466 |
+
$review['rating'] = $r->Rate;
|
467 |
+
$review['comment'] = $r->Comment;
|
468 |
+
$review['name'] = $r->FIO;
|
469 |
+
$reviews[] = $review;
|
470 |
+
}
|
471 |
+
}
|
472 |
+
}
|
473 |
+
|
474 |
+
foreach ($reviews as $i => $review)
|
475 |
+
{
|
476 |
+
if (!$review['comment'])
|
477 |
+
{
|
478 |
+
if ($review['review'])
|
479 |
+
$review['comment'] = $review['review'];
|
480 |
+
if ($review['pros'])
|
481 |
+
$review['comment'] .= "\r\n" . __('Pros:', 'content-egg-tpl') . $review['pros'];
|
482 |
+
if ($review['cons'])
|
483 |
+
$review['comment'] .= "\r\n" . __('Cons:', 'content-egg-tpl') . $review['cons'];
|
484 |
+
$review['comment'] = trim($review['comment']);
|
485 |
+
$reviews[$i] = $review;
|
486 |
+
}
|
487 |
+
}
|
488 |
+
return $reviews;
|
489 |
+
}
|
490 |
+
|
491 |
+
public static function removeReviews($data)
|
492 |
+
{
|
493 |
+
foreach ($data as $i => $item)
|
494 |
+
{
|
495 |
+
if (!empty($item['extra']['comments']))
|
496 |
+
$data[$i]['extra']['comments'] = array();
|
497 |
+
elseif (!empty($item['extra']['Reviews']))
|
498 |
+
$data[$i]['extra']['Reviews'] = array();
|
499 |
+
}
|
500 |
+
return $data;
|
501 |
+
}
|
502 |
+
|
503 |
+
public static function saveReviewsAsComments($post_id, array $normalized_comments)
|
504 |
+
{
|
505 |
+
$comment_data = array(
|
506 |
+
'comment_post_ID' => $post_id,
|
507 |
+
'comment_author_email' => '',
|
508 |
+
'comment_author_url' => '',
|
509 |
+
'comment_type' => '',
|
510 |
+
'comment_parent' => 0,
|
511 |
+
'user_id' => 0,
|
512 |
+
'comment_approved' => 1,
|
513 |
+
);
|
514 |
+
|
515 |
+
$is_rehub_theme = (in_array(basename(\get_template_directory()), array('rehub', 'rehub-theme'))) ? true : false;
|
516 |
+
$rehub_post_type = \get_post_meta($post_id, 'rehub_framework_post_type', true);
|
517 |
+
|
518 |
+
if ($rehub_post_type && $rehub_post_type == 'review')
|
519 |
+
$is_review_post_type = true;
|
520 |
+
else
|
521 |
+
$is_review_post_type = false;
|
522 |
+
|
523 |
+
if (\get_post_type($post_id) == 'product')
|
524 |
+
$is_woo_product = true;
|
525 |
+
else
|
526 |
+
$is_woo_product = false;
|
527 |
+
|
528 |
+
$comments_keys_map = array();
|
529 |
+
|
530 |
+
foreach ($normalized_comments as $i => $comment)
|
531 |
+
{
|
532 |
+
$comment_pros = '';
|
533 |
+
$comment_cons = '';
|
534 |
+
$comment_rating = 0;
|
535 |
+
|
536 |
+
// rehub comment meta
|
537 |
+
if ($is_rehub_theme && $is_review_post_type && !empty($comment['review']))
|
538 |
+
$comment_content = $comment['review'];
|
539 |
+
else
|
540 |
+
$comment_content = $comment['comment'];
|
541 |
+
|
542 |
+
$comment_data['comment_content'] = \wp_kses($comment_content, 'default');
|
543 |
+
if (!empty($comment['name']))
|
544 |
+
$comment_data['comment_author'] = $comment['name'];
|
545 |
+
|
546 |
+
if (!empty($comment['date']))
|
547 |
+
$comment_data['comment_date'] = date('Y-m-d H:i:s', $comment['date']);
|
548 |
+
|
549 |
+
if (isset($comment['parent_id']) && is_numeric($comment['parent_id']) && isset($comments_keys_map[$comment['parent_id']]))
|
550 |
+
$comment_data['comment_parent'] = $comments_keys_map[$comment['parent_id']];
|
551 |
+
else
|
552 |
+
$comment_data['comment_parent'] = 0;
|
553 |
+
|
554 |
+
$comment_id = \wp_insert_comment($comment_data);
|
555 |
+
|
556 |
+
//$comment_id = \wp_new_comment($comment_data);
|
557 |
+
$comments_keys_map[$i] = $comment_id;
|
558 |
+
|
559 |
+
if ($is_rehub_theme && $is_review_post_type)
|
560 |
+
{
|
561 |
+
if (!empty($comment['pros']))
|
562 |
+
\add_comment_meta($comment_id, 'pros_review', $comment['pros']);
|
563 |
+
if (!empty($comment['cons']))
|
564 |
+
\add_comment_meta($comment_id, 'cons_review', $comment['cons']);
|
565 |
+
if (!empty($comment['rating']))
|
566 |
+
{
|
567 |
+
$rating_value = $comment['rating'] * 2;
|
568 |
+
\add_comment_meta($comment_id, 'user_average', $rating_value);
|
569 |
+
\add_comment_meta($comment_id, 'user_criteria', array(array('name' => __('Rating', 'content-egg-tpl'), 'value' => $rating_value)));
|
570 |
+
}
|
571 |
+
\add_comment_meta($comment_id, 'counted', 0);
|
572 |
+
// calculate rating
|
573 |
+
if (function_exists('add_comment_rates'))
|
574 |
+
\add_comment_rates($comment_id);
|
575 |
+
}
|
576 |
+
|
577 |
+
if ($is_woo_product && !empty($comment['rating']) && $comment['rating'] > 0 && $comment['rating'] <= 5)
|
578 |
+
{
|
579 |
+
\add_comment_meta($comment_id, 'rating', $comment['rating'], true);
|
580 |
+
}
|
581 |
+
}
|
582 |
+
|
583 |
+
if ($is_woo_product && class_exists('\WC_Comments'))
|
584 |
+
{
|
585 |
+
// Ensure product average rating and review count is kept up to date.
|
586 |
+
\WC_Comments::clear_transients($post_id);
|
587 |
+
}
|
588 |
+
}
|
589 |
+
|
590 |
+
public static function getMainProduct($modules_data, $main_product_selector = 'min_price')
|
591 |
+
{
|
592 |
+
$all_items = array();
|
593 |
+
foreach ($modules_data as $module_id => $items)
|
594 |
+
{
|
595 |
+
foreach ($items as $item)
|
596 |
+
{
|
597 |
+
$item = ArrayHelper::object2Array($item);
|
598 |
+
$item['module_id'] = $module_id;
|
599 |
+
$all_items[] = $item;
|
600 |
+
}
|
601 |
+
}
|
602 |
+
|
603 |
+
if (!$all_items)
|
604 |
+
return null;
|
605 |
+
if ($main_product_selector == 'random')
|
606 |
+
return $all_items[array_rand($all_items)];
|
607 |
+
|
608 |
+
if ($main_product_selector == 'max_price')
|
609 |
+
$order = 'desc';
|
610 |
+
else
|
611 |
+
$order = 'asc';
|
612 |
+
|
613 |
+
$sorted = TemplateHelper::sortByPrice($all_items, $order);
|
614 |
+
return $sorted[0];
|
615 |
+
}
|
616 |
+
|
617 |
+
}
|
application/components/ContentProduct.php
CHANGED
@@ -1,43 +1,45 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
const
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
public $
|
21 |
-
public $
|
22 |
-
public $
|
23 |
-
public $
|
24 |
-
public $
|
25 |
-
public $
|
26 |
-
public $
|
27 |
-
public $
|
28 |
-
public $
|
29 |
-
public $
|
30 |
-
public $
|
31 |
-
public $
|
32 |
-
public $
|
33 |
-
public $
|
34 |
-
public $
|
35 |
-
public $
|
36 |
-
public $
|
37 |
-
public $
|
38 |
-
public $
|
39 |
-
public $
|
40 |
-
public $
|
41 |
-
public $
|
42 |
-
|
43 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ContentProduct class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
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; //primary 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
@@ -1,213 +1,215 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
const
|
17 |
-
const
|
18 |
-
const
|
19 |
-
const
|
20 |
-
const
|
21 |
-
const
|
22 |
-
const
|
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 |
-
$query
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
$
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
$str .= '
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
return
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
return
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
return
|
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 |
-
$query
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Cpa class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
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 |
+
{
|
76 |
+
// multiple deeplink
|
77 |
+
if (strstr($deeplink, ';'))
|
78 |
+
return $deeplink;
|
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 |
+
$host = $p['host'];
|
98 |
+
|
99 |
+
if ($host == 'n.actionpay.ru')
|
100 |
+
{
|
101 |
+
return str_replace('url=example.com', 'url=', $deeplink);
|
102 |
+
}
|
103 |
+
|
104 |
+
if (array_key_exists($host, $cpa))
|
105 |
+
{
|
106 |
+
$param = $cpa[$host];
|
107 |
+
if (!empty($p['query']))
|
108 |
+
parse_str($p['query'], $query);
|
109 |
+
else
|
110 |
+
$query = array();
|
111 |
+
if (isset($query[$param]))
|
112 |
+
unset($query[$param]);
|
113 |
+
$url = $p['scheme'] . '://' . $p['host'] . $p['path'] . '?';
|
114 |
+
if ($query)
|
115 |
+
$url .= http_build_query($query) . '&';
|
116 |
+
$url .= $param . '=';
|
117 |
+
return $url;
|
118 |
+
}
|
119 |
+
return $deeplink;
|
120 |
+
}
|
121 |
+
|
122 |
+
static public function getCpaString($shop_id)
|
123 |
+
{
|
124 |
+
$shop = ShopManager::getInstance()->getItem($shop_id);
|
125 |
+
if (empty($shop->cpa))
|
126 |
+
return '';
|
127 |
+
$str = '';
|
128 |
+
foreach ($shop->cpa as $cpa)
|
129 |
+
{
|
130 |
+
$str .= '<a target="_blank" href="' . self::getCpaLink($cpa) . '">';
|
131 |
+
$str .= '<img src="' . self::getCpaIco($cpa) . '" title="' . self::getCpaName($cpa) . '" />';
|
132 |
+
$str .= '</a> ';
|
133 |
+
}
|
134 |
+
return $str;
|
135 |
+
}
|
136 |
+
|
137 |
+
static public function getCpaLink($cpa)
|
138 |
+
{
|
139 |
+
if (!empty(self::$cpa[$cpa]))
|
140 |
+
return self::$cpa[$cpa]['uri'];
|
141 |
+
else
|
142 |
+
return false;
|
143 |
+
}
|
144 |
+
|
145 |
+
static public function getCpaIco($cpa)
|
146 |
+
{
|
147 |
+
if (!empty(self::$cpa[$cpa]))
|
148 |
+
return self::$cpa[$cpa]['ico'];
|
149 |
+
else
|
150 |
+
return false;
|
151 |
+
}
|
152 |
+
|
153 |
+
static public function getCpaName($cpa)
|
154 |
+
{
|
155 |
+
if (!empty(self::$cpa[$cpa]))
|
156 |
+
return self::$cpa[$cpa]['name'];
|
157 |
+
else
|
158 |
+
return false;
|
159 |
+
}
|
160 |
+
|
161 |
+
static public function deeplinkSetSubid($deeplink, $subid, $priority = 0)
|
162 |
+
{
|
163 |
+
|
164 |
+
$cpa = array(
|
165 |
+
'ad.admitad.com' => 'subid',
|
166 |
+
'modato.ru' => 'subid', // lamoda admitad?
|
167 |
+
'f.gdeslon.ru' => 'sub_id',
|
168 |
+
'cityadspix.com' => 'sa',
|
169 |
+
'www.cityads.ru' => 'sa',
|
170 |
+
'epnclick.ru' => 'sub',
|
171 |
+
'click.linksynergy.com' => 'subid',
|
172 |
+
);
|
173 |
+
|
174 |
+
$p = parse_url($deeplink);
|
175 |
+
if ($p === false || !isset($p['host']))
|
176 |
+
return $deeplink;
|
177 |
+
|
178 |
+
$host = $p['host'];
|
179 |
+
|
180 |
+
//actionpay передает subid через path, остальные через query
|
181 |
+
if ($host == 'n.actionpay.ru')
|
182 |
+
return str_replace('/subaccount', '/' . $subid, $deeplink);
|
183 |
+
|
184 |
+
|
185 |
+
if (array_key_exists($host, $cpa))
|
186 |
+
{
|
187 |
+
$param = $cpa[$host];
|
188 |
+
if (!empty($p['query']))
|
189 |
+
parse_str($p['query'], $query);
|
190 |
+
else
|
191 |
+
$query = array();
|
192 |
+
|
193 |
+
$url = $p['scheme'] . '://' . $p['host'] . $p['path'] . '?';
|
194 |
+
|
195 |
+
if (!isset($query[$param]) || $query[$param] == '' || $priority == 1)
|
196 |
+
{
|
197 |
+
unset($query[$param]);
|
198 |
+
$url .= $param . '=' . $subid . '&';
|
199 |
+
}
|
200 |
+
|
201 |
+
if ($query)
|
202 |
+
$url .= http_build_query($query);
|
203 |
+
|
204 |
+
return $url;
|
205 |
+
}
|
206 |
+
|
207 |
+
return $deeplink;
|
208 |
+
}
|
209 |
+
|
210 |
+
public static function getCpaIds()
|
211 |
+
{
|
212 |
+
return array_keys(self::$cpa);
|
213 |
+
}
|
214 |
+
|
215 |
+
}
|
application/components/ExternalFeaturedImage.php
CHANGED
@@ -1,238 +1,284 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
\add_filter('
|
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 |
-
if (
|
143 |
-
return $
|
144 |
-
|
145 |
-
$
|
146 |
-
|
147 |
-
|
148 |
-
return
|
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 |
-
if (
|
182 |
-
{
|
183 |
-
return array(
|
184 |
-
'width' =>
|
185 |
-
'height' =>
|
186 |
-
'crop' =>
|
187 |
-
);
|
188 |
-
}
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
$html
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\admin\GeneralConfig;
|
8 |
+
use ContentEgg\application\components\FeaturedImage;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* ExternalFeaturedImage class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link https://www.keywordrush.com
|
15 |
+
* @copyright Copyright © 2019 keywordrush.com
|
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 |
+
{
|
24 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'disabled')
|
25 |
+
return;
|
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 |
+
\add_filter('wp_get_attachment_image_src', array(__CLASS__, 'replaceImageSrc'), 10, 4);
|
33 |
+
\add_filter('woocommerce_product_get_image_id', array(__CLASS__, 'getFakeImageId'), 99, 2);
|
34 |
+
\add_filter('post_thumbnail_html', array(__CLASS__, 'replaceThumbnail'), 10, 5);
|
35 |
+
\add_action('wpseo_add_opengraph_images', array(__CLASS__, 'addOpengraphImage'));
|
36 |
+
\add_action('woocommerce_structured_data_product', array(__CLASS__, 'addStructuredDataProduct'), 10, 2);
|
37 |
+
\add_action('content_egg_save_data', array(__CLASS__, 'setImage'), 13, 4);
|
38 |
+
}
|
39 |
+
|
40 |
+
private static function generateFakeId($post_id)
|
41 |
+
{
|
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 |
+
return $fake_id;
|
49 |
+
}
|
50 |
+
|
51 |
+
private static function getRealId($post_id)
|
52 |
+
{
|
53 |
+
if (strlen(strval($post_id)) != strlen(strval(PHP_INT_MAX)) - 1)
|
54 |
+
return false;
|
55 |
+
|
56 |
+
if (substr((string) $post_id, 0, strlen(self::FAKE_INT_START)) != self::FAKE_INT_START)
|
57 |
+
return false;
|
58 |
+
|
59 |
+
return (int) substr_replace((string) $post_id, '', 0, strlen(self::FAKE_INT_START));
|
60 |
+
}
|
61 |
+
|
62 |
+
public static function setImage($data, $module_id, $post_id, $is_last_iteration)
|
63 |
+
{
|
64 |
+
if (\get_post_type($post_id) == 'product')
|
65 |
+
return;
|
66 |
+
|
67 |
+
if (!$is_last_iteration)
|
68 |
+
return;
|
69 |
+
|
70 |
+
self::setExternalFeaturedImage($post_id);
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function setExternalFeaturedImage($post_id, $item = null)
|
74 |
+
{
|
75 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'enabled_internal_priority' && self::hasInternalImage($post_id))
|
76 |
+
return false;
|
77 |
+
|
78 |
+
if (!$item)
|
79 |
+
{
|
80 |
+
$data = FeaturedImage::getData($post_id);
|
81 |
+
if (!$data)
|
82 |
+
return;
|
83 |
+
$item = $data[0];
|
84 |
+
}
|
85 |
+
if (empty($item['img']))
|
86 |
+
return;
|
87 |
+
|
88 |
+
$img_url = $item['img'];
|
89 |
+
return self::updateExternalMeta($img_url, $post_id);
|
90 |
+
}
|
91 |
+
|
92 |
+
public static function updateExternalMeta($url, $post_id)
|
93 |
+
{
|
94 |
+
$old = \get_post_meta($post_id, self::EXTERNAL_URL_META, true);
|
95 |
+
if ($old && $old['url'] == $url)
|
96 |
+
return true;
|
97 |
+
|
98 |
+
$save = array();
|
99 |
+
$save['url'] = $url;
|
100 |
+
|
101 |
+
$width = $height = 0;
|
102 |
+
if (ini_get('allow_url_fopen'))
|
103 |
+
list($width, $height) = @getimagesize($url);
|
104 |
+
$save['width'] = $width;
|
105 |
+
$save['height'] = $height;
|
106 |
+
|
107 |
+
return \update_post_meta($post_id, self::EXTERNAL_URL_META, $save);
|
108 |
+
}
|
109 |
+
|
110 |
+
public static function adminThumbnail($html)
|
111 |
+
{
|
112 |
+
global $post;
|
113 |
+
if (empty($post) || !$external_img = \get_post_meta($post->ID, self::EXTERNAL_URL_META, true))
|
114 |
+
return $html;
|
115 |
+
|
116 |
+
if (empty($external_img['url']))
|
117 |
+
return $html;
|
118 |
+
|
119 |
+
$html .= '<div><img class="size-post-thumbnail" src="' . \esc_url($external_img['url']) . '">';
|
120 |
+
$html .= '<p class="howto">' . __('External featured image', 'content-egg') . '</p></div>';
|
121 |
+
|
122 |
+
return $html;
|
123 |
+
}
|
124 |
+
|
125 |
+
public static function getFakeImageId($value, $product)
|
126 |
+
{
|
127 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'enabled_internal_priority' && self::hasInternalImage($product->get_id()))
|
128 |
+
return $value;
|
129 |
+
|
130 |
+
$product_id = $product->get_id();
|
131 |
+
if (\get_post_meta($product_id, self::EXTERNAL_URL_META, true))
|
132 |
+
return self::generateFakeId($product_id);
|
133 |
+
else
|
134 |
+
return $value;
|
135 |
+
}
|
136 |
+
|
137 |
+
public static function getFakeThumbnailId($value, $object_id, $meta_key, $single)
|
138 |
+
{
|
139 |
+
if ($meta_key != '_thumbnail_id')
|
140 |
+
return $value;
|
141 |
+
|
142 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'enabled_internal_priority' && self::hasInternalImage($object_id))
|
143 |
+
return $value;
|
144 |
+
|
145 |
+
if (\get_post_meta($object_id, self::EXTERNAL_URL_META, true))
|
146 |
+
return self::generateFakeId($object_id);
|
147 |
+
else
|
148 |
+
return $value;
|
149 |
+
}
|
150 |
+
|
151 |
+
public static function replaceImageSrc($image, $attachment_id, $size, $icon)
|
152 |
+
{
|
153 |
+
if (!$post_id = self::getRealId($attachment_id))
|
154 |
+
return $image;
|
155 |
+
|
156 |
+
if (!$external_img = \get_post_meta($post_id, self::EXTERNAL_URL_META, true))
|
157 |
+
return $image;
|
158 |
+
|
159 |
+
$external_url = $external_img['url'];
|
160 |
+
|
161 |
+
if ($image_size = self::getImageSize($size))
|
162 |
+
return array($external_url, $image_size['width'], $image_size['height'], $image_size['crop']);
|
163 |
+
else
|
164 |
+
{
|
165 |
+
if (!empty($external_img['width']))
|
166 |
+
$width = $external_img['width'];
|
167 |
+
else
|
168 |
+
$width = 800;
|
169 |
+
|
170 |
+
if (!empty($external_img['height']))
|
171 |
+
$height = $external_img['height'];
|
172 |
+
else
|
173 |
+
$height = 600;
|
174 |
+
|
175 |
+
return array($external_url, $width, $height, false);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
public static function getImageSize($size)
|
180 |
+
{
|
181 |
+
if (is_array($size))
|
182 |
+
{
|
183 |
+
return array(
|
184 |
+
'width' => isset($size[0]) ? $size[0] : null,
|
185 |
+
'height' => isset($size[1]) ? $size[1] : null,
|
186 |
+
'crop' => isset($size[2]) ? $size[2] : null,
|
187 |
+
);
|
188 |
+
}
|
189 |
+
|
190 |
+
global $_wp_additional_image_sizes;
|
191 |
+
if (isset($_wp_additional_image_sizes[$size]))
|
192 |
+
return $_wp_additional_image_sizes[$size];
|
193 |
+
|
194 |
+
$default = array('thumbnail', 'medium', 'medium_large', 'large');
|
195 |
+
if (in_array($size, $default))
|
196 |
+
{
|
197 |
+
return array(
|
198 |
+
'width' => \get_option("{$size}_size_w"),
|
199 |
+
'height' => \get_option("{$size}_size_h"),
|
200 |
+
'crop' => \get_option("{$size}_crop"),
|
201 |
+
);
|
202 |
+
}
|
203 |
+
return array();
|
204 |
+
}
|
205 |
+
|
206 |
+
public static function replaceThumbnail($html, $post_id, $post_thumbnail_id, $size, $attr)
|
207 |
+
{
|
208 |
+
if (!$external_img = \get_post_meta($post_id, self::EXTERNAL_URL_META, true))
|
209 |
+
return $html;
|
210 |
+
|
211 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'enabled_internal_priority' && self::hasInternalImage($post_id))
|
212 |
+
return $html;
|
213 |
+
|
214 |
+
$url = $external_img['url'];
|
215 |
+
$alt = \get_post_field('post_title', $post_id);
|
216 |
+
$class = 'cegg-external-img wp-post-image';
|
217 |
+
$attr = array('alt' => $alt, 'class' => $class);
|
218 |
+
//$attr = \apply_filters('wp_get_attachment_image_attributes', $attr, $size);
|
219 |
+
$attr = array_map('esc_attr', $attr);
|
220 |
+
$html = sprintf('<img src="%s"', esc_url($url));
|
221 |
+
foreach ($attr as $name => $value)
|
222 |
+
{
|
223 |
+
$html .= " $name=" . '"' . $value . '"';
|
224 |
+
}
|
225 |
+
$html .= ' />';
|
226 |
+
return $html;
|
227 |
+
}
|
228 |
+
|
229 |
+
public static function hasInternalImage($object_id)
|
230 |
+
{
|
231 |
+
$meta_type = 'post';
|
232 |
+
$meta_key = '_thumbnail_id';
|
233 |
+
|
234 |
+
$meta_cache = \wp_cache_get($object_id, $meta_type . '_meta');
|
235 |
+
if (!$meta_cache)
|
236 |
+
{
|
237 |
+
$meta_cache = \update_meta_cache($meta_type, array($object_id));
|
238 |
+
$meta_cache = $meta_cache[$object_id];
|
239 |
+
}
|
240 |
+
|
241 |
+
if (isset($meta_cache[$meta_key]))
|
242 |
+
$meta_value = $meta_cache[$meta_key][0];
|
243 |
+
else
|
244 |
+
$meta_value = false;
|
245 |
+
|
246 |
+
if ($meta_value)
|
247 |
+
return true;
|
248 |
+
else
|
249 |
+
return false;
|
250 |
+
}
|
251 |
+
|
252 |
+
public static function getExternalUrl($post_id)
|
253 |
+
{
|
254 |
+
$external_img = \get_post_meta($post_id, self::EXTERNAL_URL_META, true);
|
255 |
+
if (!$external_img || empty($external_img['url']))
|
256 |
+
return false;
|
257 |
+
else
|
258 |
+
return $external_img['url'];
|
259 |
+
}
|
260 |
+
|
261 |
+
public static function addOpengraphImage($object)
|
262 |
+
{
|
263 |
+
if (!$post_id = \get_the_ID())
|
264 |
+
return;
|
265 |
+
|
266 |
+
if (!$external_url = self::getExternalUrl($post_id))
|
267 |
+
return;
|
268 |
+
|
269 |
+
$object->add_image($external_url);
|
270 |
+
}
|
271 |
+
|
272 |
+
public static function addStructuredDataProduct($markup, $product)
|
273 |
+
{
|
274 |
+
if (!empty($markup['image']))
|
275 |
+
return $markup;
|
276 |
+
|
277 |
+
if (!$external_url = self::getExternalUrl($product->get_id()))
|
278 |
+
return $markup;
|
279 |
+
|
280 |
+
$markup['image'] = $external_url;
|
281 |
+
return $markup;
|
282 |
+
}
|
283 |
+
|
284 |
+
}
|
application/components/ExtraData.php
CHANGED
@@ -1,37 +1,40 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
public $
|
17 |
-
public $
|
18 |
-
|
19 |
-
public
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
$object_or_array
|
31 |
-
}
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ExtraData class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
24 |
+
foreach ($data as $key => $d)
|
25 |
+
{
|
26 |
+
if (is_object($object_or_array) && property_exists($object_or_array, $key))
|
27 |
+
{
|
28 |
+
if (is_array($d) && !is_array($object_or_array->$key))
|
29 |
+
continue; //?
|
30 |
+
$object_or_array->$key = $d;
|
31 |
+
} elseif (is_array($object_or_array))
|
32 |
+
{
|
33 |
+
$object_or_array[$key] = $d;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
return $object_or_array;
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
application/components/FeaturedImage.php
CHANGED
@@ -1,159 +1,161 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
*
|
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 |
-
$data =
|
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 |
-
elseif ($featured_image == '
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\components\ContentManager;
|
9 |
+
use ContentEgg\application\helpers\ImageHelper;
|
10 |
+
use ContentEgg\application\admin\GeneralConfig;
|
11 |
+
use ContentEgg\application\components\ExternalFeaturedImage;
|
12 |
+
|
13 |
+
/**
|
14 |
+
* FeaturedImage class file
|
15 |
+
*
|
16 |
+
* @author keywordrush.com <support@keywordrush.com>
|
17 |
+
* @link http://www.keywordrush.com/
|
18 |
+
* @copyright Copyright © 2015 keywordrush.com
|
19 |
+
*/
|
20 |
+
class FeaturedImage {
|
21 |
+
|
22 |
+
public function __construct()
|
23 |
+
{
|
24 |
+
if (\is_admin())
|
25 |
+
$this->adminInit();
|
26 |
+
}
|
27 |
+
|
28 |
+
public function adminInit()
|
29 |
+
{
|
30 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') != 'disabled')
|
31 |
+
return;
|
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 |
+
{
|
39 |
+
if (GeneralConfig::getInstance()->option('external_featured_images') == 'disabled')
|
40 |
+
{
|
41 |
+
if (!\has_post_thumbnail($post_id))
|
42 |
+
FeaturedImage::setFeaturedImage($post_id, $item);
|
43 |
+
} else
|
44 |
+
ExternalFeaturedImage::setExternalFeaturedImage($post_id, $item);
|
45 |
+
}
|
46 |
+
|
47 |
+
public function setImage($post_id)
|
48 |
+
{
|
49 |
+
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|
50 |
+
return;
|
51 |
+
|
52 |
+
if (\get_post_status($post_id) == 'auto-draft' || \wp_is_post_revision($post_id))
|
53 |
+
return;
|
54 |
+
|
55 |
+
if (\has_post_thumbnail($post_id))
|
56 |
+
return;
|
57 |
+
|
58 |
+
self::setFeaturedImage($post_id);
|
59 |
+
}
|
60 |
+
|
61 |
+
public static function setFeaturedImage($post_id, $item = null)
|
62 |
+
{
|
63 |
+
if ($item)
|
64 |
+
$data = array($item);
|
65 |
+
else
|
66 |
+
$data = self::getData($post_id);
|
67 |
+
|
68 |
+
foreach ($data as $d)
|
69 |
+
{
|
70 |
+
if (!$img_file = self::getImgFile($d))
|
71 |
+
continue;
|
72 |
+
|
73 |
+
return self::attachThumbnail($img_file, $post_id, $d['title']);
|
74 |
+
}
|
75 |
+
return false;
|
76 |
+
}
|
77 |
+
|
78 |
+
public static function getData($post_id)
|
79 |
+
{
|
80 |
+
$modules_ids = ModuleManager::getInstance()->getParserModulesIdList();
|
81 |
+
$data = array();
|
82 |
+
foreach ($modules_ids as $module_id)
|
83 |
+
{
|
84 |
+
$module = ModuleManager::factory($module_id);
|
85 |
+
if (!$featured_image = $module->config('featured_image', false))
|
86 |
+
continue;
|
87 |
+
|
88 |
+
if (!$d = ContentManager::getData($post_id, $module->getId()))
|
89 |
+
continue;
|
90 |
+
|
91 |
+
if ($featured_image == 'second' && isset($d[1]))
|
92 |
+
unset($d[0]);
|
93 |
+
elseif ($featured_image == 'last')
|
94 |
+
$d = array_reverse($d);
|
95 |
+
elseif ($featured_image == 'rand')
|
96 |
+
shuffle($d);
|
97 |
+
|
98 |
+
$data = array_merge($data, $d);
|
99 |
+
}
|
100 |
+
|
101 |
+
foreach ($data as $i => $d)
|
102 |
+
{
|
103 |
+
if (empty($d['img']))
|
104 |
+
unset($data[$i]);
|
105 |
+
}
|
106 |
+
return array_values($data);
|
107 |
+
}
|
108 |
+
|
109 |
+
public static function getImgFile($item)
|
110 |
+
{
|
111 |
+
if (empty($item['img']))
|
112 |
+
return false;
|
113 |
+
|
114 |
+
// already saved? dublicate image file
|
115 |
+
if (isset($item['img_file']) && $item['img_file'])
|
116 |
+
{
|
117 |
+
$img_file = ImageHelper::getFullImgPath($item['img_file']);
|
118 |
+
if (!is_file($img_file))
|
119 |
+
return false;
|
120 |
+
|
121 |
+
$uploads = \wp_upload_dir();
|
122 |
+
$dublicate_name = \wp_unique_filename($uploads['path'], basename($item['img_file']));
|
123 |
+
$dublicate_file = $uploads['path'] . '/' . $dublicate_name;
|
124 |
+
|
125 |
+
if (!copy($img_file, $dublicate_file))
|
126 |
+
return false;
|
127 |
+
|
128 |
+
return $dublicate_file;
|
129 |
+
} else
|
130 |
+
{
|
131 |
+
// save image localy
|
132 |
+
$file_name = ImageHelper::saveImgLocaly($item['img'], $item['title']);
|
133 |
+
if (!$file_name)
|
134 |
+
return false;
|
135 |
+
$uploads = \wp_upload_dir();
|
136 |
+
$image = ltrim(trailingslashit($uploads['subdir']), '\/') . $file_name;
|
137 |
+
return ImageHelper::getFullImgPath($image);
|
138 |
+
}
|
139 |
+
|
140 |
+
return $img_file;
|
141 |
+
}
|
142 |
+
|
143 |
+
public static function attachThumbnail($img_file, $post_id, $title = '')
|
144 |
+
{
|
145 |
+
require_once(ABSPATH . 'wp-admin/includes/image.php');
|
146 |
+
|
147 |
+
$filetype = \wp_check_filetype(basename($img_file), null);
|
148 |
+
$attachment = array(
|
149 |
+
'guid' => $img_file,
|
150 |
+
'post_mime_type' => $filetype['type'],
|
151 |
+
'post_title' => $title,
|
152 |
+
'post_content' => '',
|
153 |
+
'post_status' => 'inherit'
|
154 |
+
);
|
155 |
+
$attach_id = \wp_insert_attachment($attachment, $img_file, $post_id);
|
156 |
+
$attach_data = \wp_generate_attachment_metadata($attach_id, $img_file);
|
157 |
+
\wp_update_attachment_metadata($attach_id, $attach_data);
|
158 |
+
return \set_post_thumbnail($post_id, $attach_id);
|
159 |
+
}
|
160 |
+
|
161 |
+
}
|
application/components/LinkHandler.php
CHANGED
@@ -1,298 +1,369 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
*
|
11 |
-
*
|
12 |
-
* @
|
13 |
-
|
14 |
-
|
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 |
-
if (
|
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 |
-
curl_setopt($spider,
|
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 |
-
if (
|
259 |
-
return $url;
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\TextHelper;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* LinkHandler class file
|
11 |
+
*
|
12 |
+
* @author keywordrush.com <support@keywordrush.com>
|
13 |
+
* @link http://www.keywordrush.com/
|
14 |
+
* @copyright Copyright © 2016 keywordrush.com
|
15 |
+
*/
|
16 |
+
class LinkHandler {
|
17 |
+
|
18 |
+
private static $instance = null;
|
19 |
+
|
20 |
+
public static function getInstance()
|
21 |
+
{
|
22 |
+
if (self::$instance == null)
|
23 |
+
self::$instance = new self;
|
24 |
+
|
25 |
+
return self::$instance;
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Deeplink & more...
|
30 |
+
*/
|
31 |
+
public static function createAffUrl($url, $deeplink, $item = array(), $subid = '')
|
32 |
+
{
|
33 |
+
// custom filter
|
34 |
+
$filtered = \apply_filters('cegg_create_affiliate_link', $url, $deeplink);
|
35 |
+
if ($filtered != $url)
|
36 |
+
return $url;
|
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 |
+
// lomadee fix. return if url already created
|
42 |
+
if (!empty($item['url']) && strstr($item['url'], '/redir.lomadee.com/') && !strstr($item['url'], 'https://redir.lomadee.com/v2/deeplink?url='))
|
43 |
+
return $item['url'];
|
44 |
+
// coupang fix. return if url already created
|
45 |
+
if (!empty($item['url']) && strstr($item['url'], 'https://coupa.ng/'))
|
46 |
+
return $item['url'];
|
47 |
+
|
48 |
+
$deeplink = self::getMultiDeeplink($deeplink, $url);
|
49 |
+
|
50 |
+
if (!$deeplink)
|
51 |
+
{
|
52 |
+
$result = $url;
|
53 |
+
} elseif (substr(trim($deeplink), 0, 7) == '[regex]')
|
54 |
+
{
|
55 |
+
// regex preg_replace
|
56 |
+
$result = self::getRegexReplace($url, $deeplink);
|
57 |
+
} elseif (substr(trim($deeplink), 0, 13) == '[profitshare]')
|
58 |
+
{
|
59 |
+
// ProfitShare link creator
|
60 |
+
$result = self::getProfitshareLink($url, $deeplink, $item);
|
61 |
+
} elseif (substr(trim($deeplink), 0, 9) == '[lomadee]')
|
62 |
+
{
|
63 |
+
// Lomadee link creator
|
64 |
+
$result = self::getLomadeeLink($url, $deeplink, $item);
|
65 |
+
} elseif (substr(trim($deeplink), 0, 13) == '[trovaprezzi]')
|
66 |
+
{
|
67 |
+
// Trovaprezzi link creator
|
68 |
+
$result = self::getTrovaprezziLink($url, $deeplink, $item);
|
69 |
+
} elseif (substr(trim($deeplink), 0, 9) == '[coupang]')
|
70 |
+
{
|
71 |
+
// Coupang link creator
|
72 |
+
$result = self::getCoupangLink($url, $deeplink, $item);
|
73 |
+
} elseif (strstr($deeplink, '{{') && strstr($deeplink, '}}'))
|
74 |
+
{
|
75 |
+
// template deeplink
|
76 |
+
$result = self::getUrlTemplate($url, $deeplink, $item);
|
77 |
+
} elseif (!preg_match('/^https?:\/\//i', $deeplink))
|
78 |
+
{
|
79 |
+
// url with tail
|
80 |
+
$result = self::getUrlWithTail($url, $deeplink);
|
81 |
+
} else
|
82 |
+
{
|
83 |
+
$result = $deeplink . urlencode($url);
|
84 |
+
}
|
85 |
+
if ($subid)
|
86 |
+
{
|
87 |
+
$result = self::getUrlWithTail($result, $subid);
|
88 |
+
}
|
89 |
+
|
90 |
+
return $result;
|
91 |
+
}
|
92 |
+
|
93 |
+
public static function getUrlWithTail($url, $tail)
|
94 |
+
{
|
95 |
+
// replace params in URL
|
96 |
+
parse_str($tail, $vars);
|
97 |
+
if (count($vars) == 1 && strstr($tail, '='))
|
98 |
+
return \add_query_arg($vars, $url);
|
99 |
+
|
100 |
+
$tail = preg_replace('/^[?&]/', '', $tail);
|
101 |
+
|
102 |
+
$query = parse_url($url, PHP_URL_QUERY);
|
103 |
+
if ($query)
|
104 |
+
$url .= '&';
|
105 |
+
else
|
106 |
+
$url .= '?';
|
107 |
+
|
108 |
+
parse_str($tail, $tail_array);
|
109 |
+
$url .= http_build_query($tail_array);
|
110 |
+
return $url;
|
111 |
+
}
|
112 |
+
|
113 |
+
public static function getUrlTemplate($url, $template, $item = array())
|
114 |
+
{
|
115 |
+
$template = str_replace('{{url}}', $url, $template);
|
116 |
+
$template = str_replace('{{url_encoded}}', urlencode($url), $template);
|
117 |
+
$template = str_replace('{{url_base64}}', base64_encode($url), $template);
|
118 |
+
global $post;
|
119 |
+
|
120 |
+
if ($item)
|
121 |
+
{
|
122 |
+
if (isset($item['post_id']))
|
123 |
+
$post_id = $item['post_id'];
|
124 |
+
elseif (!empty($post))
|
125 |
+
$post_id = $post->ID;
|
126 |
+
else
|
127 |
+
$post_id = 0;
|
128 |
+
$template = str_replace('{{post_id}}', urlencode($post_id), $template);
|
129 |
+
|
130 |
+
if (!empty($item['unique_id']))
|
131 |
+
$template = str_replace('{{item_unique_id}}', urlencode($item['unique_id']), $template);
|
132 |
+
}
|
133 |
+
|
134 |
+
if (!empty($post))
|
135 |
+
{
|
136 |
+
$author_id = $post->post_author;
|
137 |
+
$user = \get_user_by('ID', $author_id);
|
138 |
+
$author_login = $user ? $user->data->user_login : '';
|
139 |
+
$template = str_replace('{{author_id}}', urlencode($author_id), $template);
|
140 |
+
$template = str_replace('{{author_login}}', urlencode($author_login), $template);
|
141 |
+
}
|
142 |
+
|
143 |
+
return $template;
|
144 |
+
}
|
145 |
+
|
146 |
+
public static function getRegexReplace($url, $regex)
|
147 |
+
{
|
148 |
+
$regex = trim($regex);
|
149 |
+
|
150 |
+
$parts = explode('][', $regex);
|
151 |
+
if (count($parts) != 3)
|
152 |
+
return $url;
|
153 |
+
|
154 |
+
$pattern = $parts[1];
|
155 |
+
//$replacement = rtrim($parts[2], ']');
|
156 |
+
$replacement = substr($parts[2], 0, -1);
|
157 |
+
|
158 |
+
// null character allows a premature regex end and "/../e" injection
|
159 |
+
if (strpos($pattern, 0) !== false || !trim($pattern))
|
160 |
+
return $url;
|
161 |
+
|
162 |
+
if ($result = @preg_replace($pattern, $replacement, $url))
|
163 |
+
return $result;
|
164 |
+
else
|
165 |
+
return $url;
|
166 |
+
}
|
167 |
+
|
168 |
+
public static function getProfitshareLink($url, $regex, $item = array())
|
169 |
+
{
|
170 |
+
$regex = trim($regex);
|
171 |
+
$parts = explode('][', $regex);
|
172 |
+
if (count($parts) != 3)
|
173 |
+
return $url;
|
174 |
+
|
175 |
+
$api_user = $parts[1];
|
176 |
+
$api_key = rtrim($parts[2], ']');
|
177 |
+
|
178 |
+
$api_url = 'http://api.profitshare.ro/affiliate-links/?';
|
179 |
+
$query_string = '';
|
180 |
+
|
181 |
+
$spider = curl_init();
|
182 |
+
curl_setopt($spider, CURLOPT_HEADER, false);
|
183 |
+
curl_setopt($spider, CURLOPT_URL, $api_url . $query_string);
|
184 |
+
curl_setopt($spider, CURLOPT_CONNECTTIMEOUT, 60);
|
185 |
+
curl_setopt($spider, CURLOPT_TIMEOUT, 30);
|
186 |
+
curl_setopt($spider, CURLOPT_RETURNTRANSFER, true);
|
187 |
+
curl_setopt($spider, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
188 |
+
curl_setopt($spider, CURLOPT_USERAGENT, 'Content Egg WP Plugin (https://www.keywordrush.com/contentegg)');
|
189 |
+
|
190 |
+
$data = array();
|
191 |
+
$name = 'CE:' . TextHelper::getHostName($url);
|
192 |
+
if (!empty($item['title']))
|
193 |
+
$name .= ' ' . $item['title'];
|
194 |
+
$data[] = array(
|
195 |
+
'name' => $name,
|
196 |
+
'url' => $url
|
197 |
+
);
|
198 |
+
|
199 |
+
curl_setopt($spider, CURLOPT_POST, true);
|
200 |
+
curl_setopt($spider, CURLOPT_POSTFIELDS, http_build_query($data));
|
201 |
+
|
202 |
+
$profitshare_login = array('api_user' => $api_user, 'api_key' => $api_key,);
|
203 |
+
$date = gmdate('D, d M Y H:i:s T', time());
|
204 |
+
$signature_string = 'POSTaffiliate-links/?' . $query_string . '/' . $profitshare_login['api_user'] . $date;
|
205 |
+
$auth = hash_hmac('sha1', $signature_string, $profitshare_login['api_key']);
|
206 |
+
|
207 |
+
$extra_headers = array("Date: {$date}", "X-PS-Client: {$profitshare_login['api_user']}", "X-PS-Accept: json", "X-PS-Auth: {$auth}");
|
208 |
+
|
209 |
+
curl_setopt($spider, CURLOPT_HTTPHEADER, $extra_headers);
|
210 |
+
|
211 |
+
$output = curl_exec($spider);
|
212 |
+
if (!$output)
|
213 |
+
return $url;
|
214 |
+
|
215 |
+
$result = json_decode($output, true);
|
216 |
+
|
217 |
+
if (!$result)
|
218 |
+
return $url;
|
219 |
+
if (isset($result['result'][0]['ps_url']))
|
220 |
+
return $result['result'][0]['ps_url'];
|
221 |
+
else
|
222 |
+
return $url;
|
223 |
+
}
|
224 |
+
|
225 |
+
public static function getLomadeeLink($url, $regex, $item = array())
|
226 |
+
{
|
227 |
+
$regex = trim($regex);
|
228 |
+
$parts = explode('][', $regex);
|
229 |
+
if (count($parts) != 2)
|
230 |
+
return $url;
|
231 |
+
|
232 |
+
$sourceId = rtrim($parts[1], ']');
|
233 |
+
$api_url = 'https://api.lomadee.com/v2/15071999399311f734bd1/deeplink/_create?sourceId=' . urlencode($sourceId) . '&url=' . urlencode($url);
|
234 |
+
|
235 |
+
$response = \wp_remote_get($api_url);
|
236 |
+
if (\is_wp_error($response))
|
237 |
+
return $url;
|
238 |
+
$response_code = (int) \wp_remote_retrieve_response_code($response);
|
239 |
+
if ($response_code != 200)
|
240 |
+
return $url;
|
241 |
+
$output = \wp_remote_retrieve_body($response);
|
242 |
+
$result = json_decode($output, true);
|
243 |
+
if (!$result)
|
244 |
+
return $url;
|
245 |
+
if (isset($result['deeplinks'][0]['deeplink']))
|
246 |
+
return $result['deeplinks'][0]['deeplink'];
|
247 |
+
else
|
248 |
+
return $url;
|
249 |
+
}
|
250 |
+
|
251 |
+
public static function getTrovaprezziLink($url, $regex, $item = array())
|
252 |
+
{
|
253 |
+
/**
|
254 |
+
* Note: tracking links include a token in order to ensure that offers are updated as much as possible.
|
255 |
+
* This token expires in 12 hours! Therefore you need to set your script to update your feed at least
|
256 |
+
* once each 11 hours , in order to guarantee the correct click tracking!
|
257 |
+
*/
|
258 |
+
if (time() - $item['last_update'] < 11 * 3600)
|
259 |
+
return $item['url'];
|
260 |
+
|
261 |
+
$regex = trim($regex);
|
262 |
+
$parts = explode('][', $regex);
|
263 |
+
if (count($parts) != 2)
|
264 |
+
return $url;
|
265 |
+
|
266 |
+
$path = parse_url($url, PHP_URL_PATH);
|
267 |
+
$path = trim($path, "/");
|
268 |
+
$path = preg_replace('/\.aspx$/', '', $path);
|
269 |
+
|
270 |
+
$partnerId = rtrim($parts[1], ']');
|
271 |
+
$api_url = 'https://quickshop.shoppydoo.it/' . urlencode($partnerId) . '/' . urlencode($path) . '.aspx?format=json&sort=price';
|
272 |
+
|
273 |
+
$response = \wp_remote_get($api_url);
|
274 |
+
if (\is_wp_error($response))
|
275 |
+
return $url;
|
276 |
+
$response_code = (int) \wp_remote_retrieve_response_code($response);
|
277 |
+
if ($response_code != 200)
|
278 |
+
return $url;
|
279 |
+
$output = \wp_remote_retrieve_body($response);
|
280 |
+
$result = json_decode($output, true);
|
281 |
+
if (!$result)
|
282 |
+
return $url;
|
283 |
+
if (isset($result['offers'][0]['url']))
|
284 |
+
return $result['offers'][0]['url'];
|
285 |
+
else
|
286 |
+
return $url;
|
287 |
+
}
|
288 |
+
|
289 |
+
public static function getCoupangLink($url, $regex, $item = array())
|
290 |
+
{
|
291 |
+
|
292 |
+
$regex = trim($regex);
|
293 |
+
$parts = explode('][', $regex);
|
294 |
+
if (count($parts) != 3)
|
295 |
+
return $url;
|
296 |
+
|
297 |
+
$ACCESS_KEY = $parts[1];
|
298 |
+
$SECRET_KEY = rtrim($parts[2], ']');
|
299 |
+
|
300 |
+
date_default_timezone_set("GMT+0");
|
301 |
+
|
302 |
+
$datetime = date("ymd") . 'T' . date("His") . 'Z';
|
303 |
+
$method = "POST";
|
304 |
+
$path = "/v2/providers/affiliate_open_api/apis/openapi/v1/deeplink";
|
305 |
+
$message = $datetime . $method . str_replace("?", "", $path);
|
306 |
+
$algorithm = "HmacSHA256";
|
307 |
+
|
308 |
+
$signature = hash_hmac('sha256', $message, $SECRET_KEY);
|
309 |
+
|
310 |
+
$authorization = "CEA algorithm=HmacSHA256, access-key=" . $ACCESS_KEY . ", signed-date=" . $datetime . ", signature=" . $signature;
|
311 |
+
|
312 |
+
$rurl = 'https://api-gateway.coupang.com' . $path;
|
313 |
+
|
314 |
+
$strjson = '{"coupangUrls": ["' . $url . '"]}';
|
315 |
+
|
316 |
+
$curl = curl_init();
|
317 |
+
curl_setopt($curl, CURLOPT_URL, $rurl);
|
318 |
+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
319 |
+
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=UTF-8", "Authorization:" . $authorization));
|
320 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
321 |
+
curl_setopt($curl, CURLOPT_POSTFIELDS, $strjson);
|
322 |
+
$output = curl_exec($curl);
|
323 |
+
|
324 |
+
if (!$output)
|
325 |
+
return $url;
|
326 |
+
|
327 |
+
$result = json_decode($output, true);
|
328 |
+
|
329 |
+
if (!$result)
|
330 |
+
return $url;
|
331 |
+
if (isset($result['data'][0]['shortenUrl']))
|
332 |
+
return $result['data'][0]['shortenUrl'];
|
333 |
+
else
|
334 |
+
return $url;
|
335 |
+
}
|
336 |
+
|
337 |
+
public static function getMultiDeeplink($deeplink, $url)
|
338 |
+
{
|
339 |
+
if (!strstr($deeplink, ';'))
|
340 |
+
return $deeplink;
|
341 |
+
|
342 |
+
$url_host = TextHelper::urlHost($url);
|
343 |
+
$deeplink_array = str_getcsv($deeplink, ';');
|
344 |
+
$default = '';
|
345 |
+
foreach ($deeplink_array as $da)
|
346 |
+
{
|
347 |
+
$parts = explode(':', $da, 2);
|
348 |
+
|
349 |
+
// default deeplink
|
350 |
+
if (count($parts) == 1)
|
351 |
+
$default = trim($da);
|
352 |
+
elseif (count($parts) == 2)
|
353 |
+
{
|
354 |
+
if (!$default)
|
355 |
+
$default = trim($parts[1]);
|
356 |
+
|
357 |
+
$host = $parts[0];
|
358 |
+
$host = preg_replace('/^https?:\/\//', '', $host);
|
359 |
+
$host = preg_replace('/^www\./', '', $host);
|
360 |
+
|
361 |
+
if ($host == $url_host)
|
362 |
+
return trim($parts[1]);
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
return $default;
|
367 |
+
}
|
368 |
+
|
369 |
+
}
|
application/components/Module.php
CHANGED
@@ -1,253 +1,280 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
*
|
15 |
-
* @
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
protected $
|
24 |
-
protected $
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
$this->id =
|
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 |
-
return
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ModuleManager;
|
8 |
+
use ContentEgg\application\helpers\TextHelper;
|
9 |
+
use ContentEgg\application\admin\PluginAdmin;
|
10 |
+
use ContentEgg\application\Plugin;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Module abstract class file
|
14 |
+
*
|
15 |
+
* @author keywordrush.com <support@keywordrush.com>
|
16 |
+
* @link http://www.keywordrush.com/
|
17 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
33 |
+
if ($module_id)
|
34 |
+
$this->id = $module_id;
|
35 |
+
else
|
36 |
+
$this->id = static::getIdStatic();
|
37 |
+
|
38 |
+
$info = $this->info();
|
39 |
+
if (!empty($info['name']))
|
40 |
+
$this->name = $info['name'];
|
41 |
+
else
|
42 |
+
$this->name = $this->id;
|
43 |
+
if (!empty($info['api_agreement']))
|
44 |
+
$this->api_agreement = $info['api_agreement'];
|
45 |
+
if (!empty($info['description']))
|
46 |
+
$this->description = $info['description'];
|
47 |
+
if (!empty($info['docs_uri']))
|
48 |
+
$this->docs_uri = $info['docs_uri'];
|
49 |
+
}
|
50 |
+
|
51 |
+
public function info()
|
52 |
+
{
|
53 |
+
return array();
|
54 |
+
}
|
55 |
+
|
56 |
+
final public function getId()
|
57 |
+
{
|
58 |
+
return $this->id;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function getName()
|
62 |
+
{
|
63 |
+
return $this->name;
|
64 |
+
}
|
65 |
+
|
66 |
+
public function getDir()
|
67 |
+
{
|
68 |
+
if ($this->dir === null)
|
69 |
+
{
|
70 |
+
$rc = new \ReflectionClass(get_class($this));
|
71 |
+
$this->dir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
|
72 |
+
}
|
73 |
+
return $this->dir;
|
74 |
+
}
|
75 |
+
|
76 |
+
public function isActive()
|
77 |
+
{
|
78 |
+
if ($this->is_active === null)
|
79 |
+
{
|
80 |
+
// @todo
|
81 |
+
$this->is_active = true;
|
82 |
+
}
|
83 |
+
return $this->is_active;
|
84 |
+
}
|
85 |
+
|
86 |
+
final public function isCustom()
|
87 |
+
{
|
88 |
+
if ($this->is_custom === null)
|
89 |
+
{
|
90 |
+
// @todo
|
91 |
+
$this->is_custom = false;
|
92 |
+
}
|
93 |
+
return $this->is_custom;
|
94 |
+
}
|
95 |
+
|
96 |
+
public function isDeprecated()
|
97 |
+
{
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
|
101 |
+
public function isConfigurable()
|
102 |
+
{
|
103 |
+
if ($this->is_configurable === null)
|
104 |
+
{
|
105 |
+
if (is_file($this->getDir() . $this->getMyPathId() . 'Config.php'))
|
106 |
+
$this->is_configurable = true;
|
107 |
+
else
|
108 |
+
$this->is_configurable = false;
|
109 |
+
}
|
110 |
+
return $this->is_configurable;
|
111 |
+
}
|
112 |
+
|
113 |
+
public function isFree()
|
114 |
+
{
|
115 |
+
return false;
|
116 |
+
}
|
117 |
+
|
118 |
+
public function renderResults()
|
119 |
+
{
|
120 |
+
|
121 |
+
}
|
122 |
+
|
123 |
+
public function renderSearchResults()
|
124 |
+
{
|
125 |
+
|
126 |
+
}
|
127 |
+
|
128 |
+
public function renderSearchPanel()
|
129 |
+
{
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
public function enqueueScripts()
|
134 |
+
{
|
135 |
+
|
136 |
+
}
|
137 |
+
|
138 |
+
public function presavePrepare($data, $post_id)
|
139 |
+
{
|
140 |
+
return $data;
|
141 |
+
}
|
142 |
+
|
143 |
+
public function getConfigInstance()
|
144 |
+
{
|
145 |
+
return ModuleManager::configFactory($this->getId());
|
146 |
+
}
|
147 |
+
|
148 |
+
public function config($opt_name, $default = null)
|
149 |
+
{
|
150 |
+
if (!$this->getConfigInstance()->option_exists($opt_name))
|
151 |
+
return $default;
|
152 |
+
else
|
153 |
+
return $this->getConfigInstance()->option($opt_name);
|
154 |
+
}
|
155 |
+
|
156 |
+
public function render($view_name, $_data = null)
|
157 |
+
{
|
158 |
+
if (is_array($_data))
|
159 |
+
extract($_data, EXTR_PREFIX_SAME, 'data');
|
160 |
+
else
|
161 |
+
$data = $_data;
|
162 |
+
|
163 |
+
if (ModuleManager::isCustomModule($this->getId()))
|
164 |
+
$base = \WP_CONTENT_DIR . '/' . \ContentEgg\CUSTOM_MODULES_DIR . '/';
|
165 |
+
else
|
166 |
+
$base = \ContentEgg\PLUGIN_PATH . 'application/modules/';
|
167 |
+
|
168 |
+
include $base . $this->getMyPathId() . '/views/' . TextHelper::clear($view_name) . '.php';
|
169 |
+
}
|
170 |
+
|
171 |
+
public function getJsUri()
|
172 |
+
{
|
173 |
+
return \plugins_url('\application\modules\\' . $this->getMyPathId() . '\js', \ContentEgg\PLUGIN_FILE);
|
174 |
+
}
|
175 |
+
|
176 |
+
public function getApiAgreement()
|
177 |
+
{
|
178 |
+
return $this->api_agreement;
|
179 |
+
}
|
180 |
+
|
181 |
+
public function getDocsUri()
|
182 |
+
{
|
183 |
+
return $this->docs_uri;
|
184 |
+
}
|
185 |
+
|
186 |
+
public function getDescription()
|
187 |
+
{
|
188 |
+
return $this->description;
|
189 |
+
}
|
190 |
+
|
191 |
+
public function isAffiliateParser()
|
192 |
+
{
|
193 |
+
return false;
|
194 |
+
}
|
195 |
+
|
196 |
+
public function isParser()
|
197 |
+
{
|
198 |
+
return false;
|
199 |
+
}
|
200 |
+
|
201 |
+
public function getMyPathId()
|
202 |
+
{
|
203 |
+
return self::getPathId($this->getId());
|
204 |
+
}
|
205 |
+
|
206 |
+
public function getMyShortId()
|
207 |
+
{
|
208 |
+
return self::getShortId($this->getId());
|
209 |
+
}
|
210 |
+
|
211 |
+
public static function getPathId($module_id)
|
212 |
+
{
|
213 |
+
// AE module?
|
214 |
+
$parts = explode('__', $module_id);
|
215 |
+
return $parts[0];
|
216 |
+
}
|
217 |
+
|
218 |
+
public function getShortId($module_id)
|
219 |
+
{
|
220 |
+
// AE module?
|
221 |
+
$parts = explode('__', $module_id);
|
222 |
+
if (count($parts) == 2)
|
223 |
+
return $parts[1];
|
224 |
+
else
|
225 |
+
return $module_id;
|
226 |
+
}
|
227 |
+
|
228 |
+
public function renderMetaboxModule()
|
229 |
+
{
|
230 |
+
PluginAdmin::render('metabox_module', array('module_id' => $this->getId(), 'module' => $this));
|
231 |
+
}
|
232 |
+
|
233 |
+
public function releaseVersion()
|
234 |
+
{
|
235 |
+
return '';
|
236 |
+
}
|
237 |
+
|
238 |
+
public function isNew()
|
239 |
+
{
|
240 |
+
if (!$module_version = $this->releaseVersion())
|
241 |
+
return false;
|
242 |
+
|
243 |
+
$module_version = join('.', array_slice(explode('.', $module_version), 0, 2));
|
244 |
+
$plugin_version = join('.', array_slice(explode('.', Plugin::version()), 0, 2));
|
245 |
+
if ($module_version == $plugin_version)
|
246 |
+
return true;
|
247 |
+
else
|
248 |
+
return false;
|
249 |
+
}
|
250 |
+
|
251 |
+
public function requirements()
|
252 |
+
{
|
253 |
+
return '';
|
254 |
+
}
|
255 |
+
|
256 |
+
public function isFeedModule()
|
257 |
+
{
|
258 |
+
if ($this instanceof \ContentEgg\application\components\AffiliateFeedParserModule)
|
259 |
+
return true;
|
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 |
+
}
|
application/components/ModuleApi.php
CHANGED
@@ -1,93 +1,106 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
*
|
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 |
-
$query =
|
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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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
|
14 |
+
*
|
15 |
+
* @author keywordrush.com <support@keywordrush.com>
|
16 |
+
* @link http://www.keywordrush.com/
|
17 |
+
* @copyright Copyright © 2015 keywordrush.com
|
18 |
+
*/
|
19 |
+
class ModuleApi {
|
20 |
+
|
21 |
+
const API_BASE = '-module-api';
|
22 |
+
|
23 |
+
public function __construct()
|
24 |
+
{
|
25 |
+
\add_action('wp_ajax_content-egg-module-api', array($this, 'addApiEntry'));
|
26 |
+
}
|
27 |
+
|
28 |
+
public static function apiBase()
|
29 |
+
{
|
30 |
+
return Plugin::slug . self::API_BASE;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function addApiEntry()
|
34 |
+
{
|
35 |
+
if (!\current_user_can('edit_posts'))
|
36 |
+
throw new \Exception("Access denied.");
|
37 |
+
|
38 |
+
\check_ajax_referer('contentegg-metabox', '_contentegg_nonce');
|
39 |
+
|
40 |
+
if (empty($_POST['module']))
|
41 |
+
die("Module is undefined.");
|
42 |
+
|
43 |
+
$module_id = TextHelper::clear($_POST['module']);
|
44 |
+
$parser = ModuleManager::getInstance()->parserFactory($module_id);
|
45 |
+
|
46 |
+
if (!$parser->isActive())
|
47 |
+
die("Parser module " . $parser->getId() . " is inactive.");
|
48 |
+
|
49 |
+
$query = stripslashes(InputHelper::post('query', ''));
|
50 |
+
$query = json_decode($query, true);
|
51 |
+
|
52 |
+
if (!$query)
|
53 |
+
die("Error: 'query' parameter cannot be empty.");
|
54 |
+
|
55 |
+
if (empty($query['keyword']))
|
56 |
+
die("Error: 'keyword' parameter cannot be empty.");
|
57 |
+
|
58 |
+
if ($query['keyword'][0] == '[' || filter_var($query['keyword'], FILTER_VALIDATE_URL))
|
59 |
+
$keyword = filter_var($query['keyword'], FILTER_SANITIZE_URL);
|
60 |
+
else
|
61 |
+
$keyword = TextHelper::clear_utf8($query['keyword']);
|
62 |
+
|
63 |
+
if (!$keyword)
|
64 |
+
die("Error: 'keyword' parameter cannot be empty.");
|
65 |
+
|
66 |
+
try
|
67 |
+
{
|
68 |
+
$data = $parser->doRequest($keyword, $query);
|
69 |
+
foreach ($data as $key => $item)
|
70 |
+
{
|
71 |
+
if (!$item->unique_id)
|
72 |
+
throw new \Exception('Item data "unique_id" must be specified.');
|
73 |
+
|
74 |
+
if ($item->description)
|
75 |
+
{
|
76 |
+
if (!TextHelper::isHtmlTagDetected($item->description))
|
77 |
+
$item->description = TextHelper::br2nl($item->description);
|
78 |
+
|
79 |
+
$item->description = TextHelper::removeExtraBreaks($item->description);
|
80 |
+
}
|
81 |
+
|
82 |
+
if (property_exists($item, 'price'))
|
83 |
+
{
|
84 |
+
if (!(float) $item->price)
|
85 |
+
{
|
86 |
+
$item->price = 0;
|
87 |
+
$item->priceOld = 0;
|
88 |
+
} elseif (!(float) $item->priceOld)
|
89 |
+
$item->priceOld = 0;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
$this->formatJson(array('results' => $data, 'error' => ''));
|
93 |
+
} catch (\Exception $e)
|
94 |
+
{
|
95 |
+
$this->formatJson(array('error' => $e->getMessage()));
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
public function formatJson($data)
|
100 |
+
{
|
101 |
+
header('Content-Type: application/json; charset=UTF-8');
|
102 |
+
echo json_encode($data);
|
103 |
+
\wp_die();
|
104 |
+
}
|
105 |
+
|
106 |
+
}
|
application/components/ModuleConfig.php
CHANGED
@@ -1,77 +1,74 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
protected
|
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 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\Plugin;
|
8 |
+
use ContentEgg\application\admin\PluginAdmin;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* ModuleConfig abstract class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link http://www.keywordrush.com/
|
15 |
+
* @copyright Copyright © 2015 keywordrush.com
|
16 |
+
*/
|
17 |
+
abstract class ModuleConfig extends Config {
|
18 |
+
|
19 |
+
protected $module_id;
|
20 |
+
|
21 |
+
protected function __construct($module_id = null)
|
22 |
+
{
|
23 |
+
if ($module_id)
|
24 |
+
{
|
25 |
+
$this->module_id = $module_id;
|
26 |
+
} else
|
27 |
+
{
|
28 |
+
$parts = explode('\\', get_class($this));
|
29 |
+
$this->module_id = $parts[count($parts) - 2];
|
30 |
+
}
|
31 |
+
parent::__construct();
|
32 |
+
}
|
33 |
+
|
34 |
+
public function getModuleId()
|
35 |
+
{
|
36 |
+
return $this->module_id;
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getModuleName()
|
40 |
+
{
|
41 |
+
return $this->getModuleInstance()->getName();
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getModuleInstance()
|
45 |
+
{
|
46 |
+
return ModuleManager::factory($this->getModuleId());
|
47 |
+
}
|
48 |
+
|
49 |
+
public function page_slug()
|
50 |
+
{
|
51 |
+
return 'content-egg-modules--' . $this->getModuleId();
|
52 |
+
}
|
53 |
+
|
54 |
+
public function option_name()
|
55 |
+
{
|
56 |
+
return Plugin::slug() . '_' . $this->getModuleId();
|
57 |
+
}
|
58 |
+
|
59 |
+
public function add_admin_menu()
|
60 |
+
{
|
61 |
+
\add_submenu_page('options.php', $this->getModuleId() . ' ' . __('settings', 'content-egg') . ' ‹ Content Egg', '', 'manage_options', $this->page_slug(), array($this, 'settings_page'));
|
62 |
+
}
|
63 |
+
|
64 |
+
public function settings_page()
|
65 |
+
{
|
66 |
+
PluginAdmin::render('module_settings', array('module' => $this->getModuleInstance(), 'config' => $this));
|
67 |
+
}
|
68 |
+
|
69 |
+
public function options()
|
70 |
+
{
|
71 |
+
return array();
|
72 |
+
}
|
73 |
+
|
74 |
+
}
|
|
|
|
|
|
application/components/ModuleManager.php
CHANGED
@@ -1,358 +1,388 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use \ContentEgg\application\
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
* @
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
private static $
|
24 |
-
private static $
|
25 |
-
|
26 |
-
private static $
|
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 (
|
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 |
-
if (
|
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 |
-
if (
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use \ContentEgg\application\Plugin;
|
8 |
+
use \ContentEgg\application\helpers\TextHelper;
|
9 |
+
use \ContentEgg\application\admin\AeIntegrationConfig;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* ModuleManager class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2016 keywordrush.com
|
17 |
+
*/
|
18 |
+
class ModuleManager {
|
19 |
+
|
20 |
+
const DEFAULT_MODULES_DIR = 'application/modules';
|
21 |
+
const AE_MODULES_PREFIX = 'AE';
|
22 |
+
|
23 |
+
private static $modules = array();
|
24 |
+
private static $active_modules = array();
|
25 |
+
private static $configs = array();
|
26 |
+
private static $instance = null;
|
27 |
+
// hidden system modules
|
28 |
+
private static $hidden_modules = array('AE');
|
29 |
+
private static $custom_modules = array('AE');
|
30 |
+
|
31 |
+
public static function getInstance()
|
32 |
+
{
|
33 |
+
if (self::$instance == null)
|
34 |
+
self::$instance = new self;
|
35 |
+
|
36 |
+
return self::$instance;
|
37 |
+
}
|
38 |
+
|
39 |
+
private function __construct()
|
40 |
+
{
|
41 |
+
$this->initModules();
|
42 |
+
}
|
43 |
+
|
44 |
+
public function adminInit()
|
45 |
+
{
|
46 |
+
//\add_action('parent_file', array($this, 'highlightAdminMenu'));
|
47 |
+
foreach ($this->getConfigurableModules() as $module)
|
48 |
+
{
|
49 |
+
$config = self::configFactory($module->getId());
|
50 |
+
$config->adminInit();
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Highlight the proper submenu item
|
56 |
+
*/
|
57 |
+
public function highlightAdminMenu($parent_file)
|
58 |
+
{
|
59 |
+
global $plugin_page;
|
60 |
+
|
61 |
+
if (substr($plugin_page, 0, strlen(Plugin::slug())) !== Plugin::slug())
|
62 |
+
return $parent_file;
|
63 |
+
//\ContentEgg\prn($parent_file);
|
64 |
+
//\ContentEgg\prnx($plugin_page);
|
65 |
+
|
66 |
+
if ($parent_file == 'options.php' && $plugin_page == 'content-egg-settings-affiliate')
|
67 |
+
$plugin_page = 'content-egg-settings-affiliate';
|
68 |
+
|
69 |
+
return $parent_file;
|
70 |
+
}
|
71 |
+
|
72 |
+
private function initModules()
|
73 |
+
{
|
74 |
+
$modules_ids = $this->scanForDefaultModules();
|
75 |
+
|
76 |
+
if (defined('\CONTENT_EGG_CUSTOM_MODULES') && \CONTENT_EGG_CUSTOM_MODULES)
|
77 |
+
$modules_ids = array_merge($modules_ids, $this->scanForCustomModules());
|
78 |
+
|
79 |
+
sort($modules_ids);
|
80 |
+
|
81 |
+
$ae_modules_ids = $this->getAffEggModules();
|
82 |
+
sort($ae_modules_ids);
|
83 |
+
|
84 |
+
$modules_ids = array_merge($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 |
+
{
|
90 |
+
// create module
|
91 |
+
self::factory($module_id);
|
92 |
+
}
|
93 |
+
|
94 |
+
// fill active modules
|
95 |
+
foreach (self::$modules as $module)
|
96 |
+
{
|
97 |
+
if ($module->isActive())
|
98 |
+
self::$active_modules[$module->getId()] = $module;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
private function scanForDefaultModules()
|
103 |
+
{
|
104 |
+
$path = \ContentEgg\PLUGIN_PATH . self::DEFAULT_MODULES_DIR . DIRECTORY_SEPARATOR;
|
105 |
+
return $this->scanForModules($path);
|
106 |
+
}
|
107 |
+
|
108 |
+
private function scanForCustomModules()
|
109 |
+
{
|
110 |
+
$path = \WP_CONTENT_DIR . DIRECTORY_SEPARATOR . \ContentEgg\CUSTOM_MODULES_DIR . DIRECTORY_SEPARATOR;
|
111 |
+
if (!is_dir($path))
|
112 |
+
return array();
|
113 |
+
|
114 |
+
self::$custom_modules = $this->scanForModules($path);
|
115 |
+
return self::$custom_modules;
|
116 |
+
}
|
117 |
+
|
118 |
+
private function scanForModules($path)
|
119 |
+
{
|
120 |
+
$folder_handle = @opendir($path);
|
121 |
+
if ($folder_handle === false)
|
122 |
+
return;
|
123 |
+
|
124 |
+
$founded_modules = array();
|
125 |
+
|
126 |
+
while (($m_dir = readdir($folder_handle)) !== false)
|
127 |
+
{
|
128 |
+
if ($m_dir == '.' || $m_dir == '..')
|
129 |
+
continue;
|
130 |
+
$module_path = $path . $m_dir;
|
131 |
+
if (!is_dir($module_path))
|
132 |
+
continue;
|
133 |
+
|
134 |
+
$module_id = $m_dir;
|
135 |
+
if (in_array($module_id, self::$hidden_modules))
|
136 |
+
continue;
|
137 |
+
|
138 |
+
$founded_modules[] = TextHelper::clear($module_id);
|
139 |
+
}
|
140 |
+
closedir($folder_handle);
|
141 |
+
return $founded_modules;
|
142 |
+
}
|
143 |
+
|
144 |
+
private function getAffEggModules()
|
145 |
+
{
|
146 |
+
if (!AeIntegrationConfig::isAEIntegrationPosible())
|
147 |
+
return array();
|
148 |
+
|
149 |
+
$module_ids = AeIntegrationConfig::getInstance()->option('modules');
|
150 |
+
if (!$module_ids)
|
151 |
+
return array();
|
152 |
+
$result = array();
|
153 |
+
foreach ($module_ids as $module_id)
|
154 |
+
{
|
155 |
+
$result[] = self::AE_MODULES_PREFIX . '__' . $module_id;
|
156 |
+
}
|
157 |
+
return $result;
|
158 |
+
}
|
159 |
+
|
160 |
+
public static function isCustomModule($module_id)
|
161 |
+
{
|
162 |
+
if (in_array($module_id, self::$custom_modules))
|
163 |
+
return true;
|
164 |
+
else
|
165 |
+
return false;
|
166 |
+
}
|
167 |
+
|
168 |
+
public static function factory($module_id)
|
169 |
+
{
|
170 |
+
if (!isset(self::$modules[$module_id]))
|
171 |
+
{
|
172 |
+
$path_prefix = Module::getPathId($module_id);
|
173 |
+
if (self::isCustomModule($module_id))
|
174 |
+
$module_class = "\\ContentEggCustomModule\\" . $path_prefix . "\\" . $path_prefix . 'Module';
|
175 |
+
else
|
176 |
+
$module_class = "\\ContentEgg\\application\\modules\\" . $path_prefix . "\\" . $path_prefix . 'Module';
|
177 |
+
|
178 |
+
if (class_exists($module_class, true) === false)
|
179 |
+
throw new \Exception("Unable to load module class: '{$module_class}'.");
|
180 |
+
|
181 |
+
$module = new $module_class($module_id);
|
182 |
+
|
183 |
+
if (!($module instanceof \ContentEgg\application\components\Module))
|
184 |
+
throw new \Exception("The module '{$module_id}' must inherit from Module.");
|
185 |
+
|
186 |
+
if (Plugin::isFree() && !$module->isFree())
|
187 |
+
return false;
|
188 |
+
|
189 |
+
self::$modules[$module_id] = $module;
|
190 |
+
}
|
191 |
+
|
192 |
+
return self::$modules[$module_id];
|
193 |
+
}
|
194 |
+
|
195 |
+
public static function parserFactory($module_id)
|
196 |
+
{
|
197 |
+
$module = self::factory($module_id);
|
198 |
+
if (!($module instanceof \ContentEgg\application\components\ParserModule))
|
199 |
+
throw new \Exception("The parser module '{$module_id}' must inherit from ParserModule.");
|
200 |
+
|
201 |
+
return $module;
|
202 |
+
}
|
203 |
+
|
204 |
+
public static function configFactory($module_id)
|
205 |
+
{
|
206 |
+
if (!isset(self::$configs[$module_id]))
|
207 |
+
{
|
208 |
+
$path_prefix = Module::getPathId($module_id);
|
209 |
+
|
210 |
+
if (self::isCustomModule($module_id))
|
211 |
+
$config_class = "\\ContentEggCustomModule\\" . $path_prefix . "\\" . $path_prefix . 'Config';
|
212 |
+
else
|
213 |
+
$config_class = "\\ContentEgg\\application\\modules\\" . $path_prefix . "\\" . $path_prefix . 'Config';
|
214 |
+
|
215 |
+
if (class_exists($config_class, true) === false)
|
216 |
+
throw new \Exception("Unable to load module config class: '{$config_class}'.");
|
217 |
+
|
218 |
+
$config = $config_class::getInstance($module_id);
|
219 |
+
|
220 |
+
if (self::factory($module_id)->isParser())
|
221 |
+
{
|
222 |
+
if (!($config instanceof \ContentEgg\application\components\ParserModuleConfig))
|
223 |
+
{
|
224 |
+
throw new \Exception("The parser module config '{$config_class}' must inherit from ParserModuleConfig.");
|
225 |
+
}
|
226 |
+
} else
|
227 |
+
{
|
228 |
+
if (!($config instanceof \ContentEgg\application\components\ModuleConfig))
|
229 |
+
{
|
230 |
+
throw new \Exception("The module config '{$config_class}' must inherit from ModuleConfig.");
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
self::$configs[$module_id] = $config;
|
235 |
+
}
|
236 |
+
|
237 |
+
return self::$configs[$module_id];
|
238 |
+
}
|
239 |
+
|
240 |
+
public function getModules($only_active = false)
|
241 |
+
{
|
242 |
+
if ($only_active)
|
243 |
+
return self::$active_modules;
|
244 |
+
else
|
245 |
+
return self::$modules;
|
246 |
+
}
|
247 |
+
|
248 |
+
public function getModulesIdList($only_active = false)
|
249 |
+
{
|
250 |
+
return array_keys($this->getModules($only_active));
|
251 |
+
}
|
252 |
+
|
253 |
+
public function getParserModules($only_active = false)
|
254 |
+
{
|
255 |
+
$modules = $this->getModules($only_active);
|
256 |
+
$parsers = array();
|
257 |
+
foreach ($modules as $module)
|
258 |
+
{
|
259 |
+
if ($module->isParser())
|
260 |
+
$parsers[$module->getId()] = $module;
|
261 |
+
}
|
262 |
+
return $parsers;
|
263 |
+
}
|
264 |
+
|
265 |
+
public function getAffiliateParsers($only_active = false, $only_product = false)
|
266 |
+
{
|
267 |
+
$modules = $this->getModules($only_active);
|
268 |
+
$parsers = array();
|
269 |
+
foreach ($modules as $module)
|
270 |
+
{
|
271 |
+
if ($only_product && strstr($module->getId(), 'Coupons'))
|
272 |
+
continue;
|
273 |
+
|
274 |
+
if (!$module->isAffiliateParser())
|
275 |
+
continue;
|
276 |
+
|
277 |
+
$parsers[$module->getId()] = $module;
|
278 |
+
}
|
279 |
+
return $parsers;
|
280 |
+
}
|
281 |
+
|
282 |
+
public function getParserModulesIdList($only_active = false)
|
283 |
+
{
|
284 |
+
return array_keys($this->getParserModules($only_active));
|
285 |
+
}
|
286 |
+
|
287 |
+
public function getParserModulesByTypes($types, $only_active = true)
|
288 |
+
{
|
289 |
+
if ($types == 'ALL')
|
290 |
+
$types = null;
|
291 |
+
|
292 |
+
if ($types && !is_array($types))
|
293 |
+
$types = array($types);
|
294 |
+
$res = array();
|
295 |
+
foreach ($this->getParserModules($only_active) as $module)
|
296 |
+
{
|
297 |
+
if ($types && !in_array($module->getParserType(), $types))
|
298 |
+
continue;
|
299 |
+
$res[$module->getId()] = $module;
|
300 |
+
}
|
301 |
+
return $res;
|
302 |
+
}
|
303 |
+
|
304 |
+
public function getParserModuleIdsByTypes($types, $only_active = true)
|
305 |
+
{
|
306 |
+
return array_keys($this->getParserModulesByTypes($types, $only_active));
|
307 |
+
}
|
308 |
+
|
309 |
+
public function getConfigurableModules($active_only = false)
|
310 |
+
{
|
311 |
+
$result = array();
|
312 |
+
foreach ($this->getModules($active_only) as $module)
|
313 |
+
{
|
314 |
+
if ($module->isConfigurable())
|
315 |
+
$result[] = $module;
|
316 |
+
}
|
317 |
+
return $result;
|
318 |
+
}
|
319 |
+
|
320 |
+
public function moduleExists($module_id)
|
321 |
+
{
|
322 |
+
if (isset(self::$modules[$module_id]))
|
323 |
+
return true;
|
324 |
+
else
|
325 |
+
return false;
|
326 |
+
}
|
327 |
+
|
328 |
+
public function isModuleActive($module_id)
|
329 |
+
{
|
330 |
+
if (isset(self::$active_modules[$module_id]))
|
331 |
+
return true;
|
332 |
+
else
|
333 |
+
return false;
|
334 |
+
}
|
335 |
+
|
336 |
+
public function getOptionsList()
|
337 |
+
{
|
338 |
+
$options = array();
|
339 |
+
foreach ($this->getConfigurableModules() as $module)
|
340 |
+
{
|
341 |
+
$config = $module->getConfigInstance();
|
342 |
+
$options[$config->option_name()] = $config->getOptionValues();
|
343 |
+
//$opt_name = $module->getConfigInstance()->option_name();
|
344 |
+
//$options[$opt_name] = \get_option($opt_name);
|
345 |
+
}
|
346 |
+
return $options;
|
347 |
+
}
|
348 |
+
|
349 |
+
public function getItemsUpdateModuleIds()
|
350 |
+
{
|
351 |
+
$result = array();
|
352 |
+
foreach ($this->getAffiliateParsers(true) as $module)
|
353 |
+
{
|
354 |
+
if (!$module->isItemsUpdateAvailable() || !$module->config('ttl_items'))
|
355 |
+
continue;
|
356 |
+
|
357 |
+
if ($module->config('update_mode') == 'cron' || $module->config('update_mode') == 'visit_cron')
|
358 |
+
$result[] = $module->getId();
|
359 |
+
}
|
360 |
+
return $result;
|
361 |
+
}
|
362 |
+
|
363 |
+
public function getByKeywordUpdateModuleIds()
|
364 |
+
{
|
365 |
+
$result = array();
|
366 |
+
foreach ($this->getAffiliateParsers(true) as $module)
|
367 |
+
{
|
368 |
+
if (!$module->config('ttl'))
|
369 |
+
continue;
|
370 |
+
|
371 |
+
if ($module->config('update_mode') == 'cron' || $module->config('update_mode') == 'visit_cron')
|
372 |
+
$result[] = $module->getId();
|
373 |
+
}
|
374 |
+
return $result;
|
375 |
+
}
|
376 |
+
|
377 |
+
public function getAffiliteModulesList($only_active = true)
|
378 |
+
{
|
379 |
+
$results = array();
|
380 |
+
$modules = ModuleManager::getInstance()->getAffiliateParsers($only_active);
|
381 |
+
foreach ($modules as $module_id => $module)
|
382 |
+
{
|
383 |
+
$results[$module_id] = $module->getName();
|
384 |
+
}
|
385 |
+
return $results;
|
386 |
+
}
|
387 |
+
|
388 |
+
}
|
application/components/ModuleTemplateManager.php
CHANGED
@@ -1,91 +1,100 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
|
14 |
-
|
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 |
-
public function
|
57 |
-
{
|
58 |
-
return
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\TextHelper;
|
8 |
+
use ContentEgg\application\components\ModuleManager;
|
9 |
+
|
10 |
+
/**
|
11 |
+
* ModuleTemplateManager class file
|
12 |
+
*
|
13 |
+
* @author keywordrush.com <support@keywordrush.com>
|
14 |
+
* @link http://www.keywordrush.com/
|
15 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
28 |
+
if (!isset(self::$instances[$module_id]))
|
29 |
+
{
|
30 |
+
self::$instances[$module_id] = new self($module_id);
|
31 |
+
}
|
32 |
+
return self::$instances[$module_id];
|
33 |
+
}
|
34 |
+
|
35 |
+
private function __construct($module_id)
|
36 |
+
{
|
37 |
+
$this->module_id = $module_id;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getTempatePrefix()
|
41 |
+
{
|
42 |
+
return self::TEMPLATE_PREFIX;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getTempateDir()
|
46 |
+
{
|
47 |
+
$path_id = Module::getPathId($this->module_id);
|
48 |
+
if (ModuleManager::isCustomModule($this->module_id))
|
49 |
+
$path = \WP_CONTENT_DIR . '/' . \ContentEgg\CUSTOM_MODULES_DIR . '/' . $path_id . '/' . self::TEMPLATE_DIR;
|
50 |
+
else
|
51 |
+
$path = \ContentEgg\PLUGIN_PATH . 'application/modules/' . $path_id . '/' . self::TEMPLATE_DIR;
|
52 |
+
|
53 |
+
return $path;
|
54 |
+
}
|
55 |
+
|
56 |
+
public function getCustomTempateDirs()
|
57 |
+
{
|
58 |
+
return array(
|
59 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId($this->module_id), //child theme
|
60 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId($this->module_id), // theme
|
61 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR . '/' . Module::getPathId($this->module_id),
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
public function getModuleId()
|
66 |
+
{
|
67 |
+
return $this->module_id;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function getTemplatesList($short_mode = false)
|
71 |
+
{
|
72 |
+
$templates = parent::getTemplatesList($short_mode);
|
73 |
+
$templates = \apply_filters('content_egg_module_templates', $templates, $this->getModuleId());
|
74 |
+
return $templates;
|
75 |
+
}
|
76 |
+
|
77 |
+
public function render($view_name, array $_data = array())
|
78 |
+
{
|
79 |
+
if (!self::isCustomTemplate($view_name))
|
80 |
+
$this->enqueueProductsStyle();
|
81 |
+
return parent::render($view_name, $_data);
|
82 |
+
}
|
83 |
+
|
84 |
+
public function renderPartialModule($view_name, $module_ids = array(), $data = array())
|
85 |
+
{
|
86 |
+
if (!$module_ids)
|
87 |
+
$module_ids = array();
|
88 |
+
|
89 |
+
if (!is_array($module_ids))
|
90 |
+
$module_ids = array($module_ids);
|
91 |
+
|
92 |
+
$current_module_id = $this->module_id;
|
93 |
+
if ($module_ids && !in_array($current_module_id, $module_ids))
|
94 |
+
return;
|
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
@@ -1,141 +1,143 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
*
|
14 |
-
*
|
15 |
-
* @
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
const
|
22 |
-
const
|
23 |
-
const
|
24 |
-
const
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
abstract public function
|
29 |
-
|
30 |
-
public function
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
$this->is_active =
|
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 |
-
$url = $item['
|
72 |
-
|
73 |
-
$url = $item['
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\ImageHelper;
|
8 |
+
use ContentEgg\application\helpers\TextHelper;
|
9 |
+
use ContentEgg\application\LocalRedirect;
|
10 |
+
use ContentEgg\application\admin\GeneralConfig;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* ParserModule abstract class file
|
14 |
+
*
|
15 |
+
* @author keywordrush.com <support@keywordrush.com>
|
16 |
+
* @link http://www.keywordrush.com/
|
17 |
+
* @copyright Copyright © 2015 keywordrush.com
|
18 |
+
*/
|
19 |
+
abstract class ParserModule extends Module {
|
20 |
+
|
21 |
+
const PARSER_TYPE_CONTENT = 'CONTENT';
|
22 |
+
const PARSER_TYPE_PRODUCT = 'PRODUCT';
|
23 |
+
const PARSER_TYPE_COUPON = 'COUPON';
|
24 |
+
const PARSER_TYPE_IMAGE = 'IMAGE';
|
25 |
+
const PARSER_TYPE_VIDEO = 'VIDEO';
|
26 |
+
const PARSER_TYPE_OTHER = 'OTHER';
|
27 |
+
|
28 |
+
abstract public function doRequest($keyword, $query_params = array(), $is_autoupdate = false);
|
29 |
+
|
30 |
+
abstract public function getParserType();
|
31 |
+
|
32 |
+
public function isActive()
|
33 |
+
{
|
34 |
+
if ($this->is_active === null)
|
35 |
+
{
|
36 |
+
if ($this->getConfigInstance()->option('is_active'))
|
37 |
+
$this->is_active = true;
|
38 |
+
else
|
39 |
+
$this->is_active = false;
|
40 |
+
}
|
41 |
+
return $this->is_active;
|
42 |
+
}
|
43 |
+
|
44 |
+
final public function isParser()
|
45 |
+
{
|
46 |
+
return true;
|
47 |
+
}
|
48 |
+
|
49 |
+
public function isUrlSearchAllowed()
|
50 |
+
{
|
51 |
+
return false;
|
52 |
+
}
|
53 |
+
|
54 |
+
public function presavePrepare($data, $post_id)
|
55 |
+
{
|
56 |
+
global $post;
|
57 |
+
$data = parent::presavePrepare($data, $post_id);
|
58 |
+
|
59 |
+
// do not save images for revisions & search results
|
60 |
+
if (($post && wp_is_post_revision($post_id)) || $post_id < 0)
|
61 |
+
return $data;
|
62 |
+
|
63 |
+
$old_data = ContentManager::getData($post_id, $this->getId());
|
64 |
+
|
65 |
+
foreach ($data as $key => $item)
|
66 |
+
{
|
67 |
+
// fill domain
|
68 |
+
if (empty($item['domain']))
|
69 |
+
{
|
70 |
+
if (!empty($item['orig_url']))
|
71 |
+
$url = $item['orig_url'];
|
72 |
+
elseif (!empty($item['img']))
|
73 |
+
$url = $item['img'];
|
74 |
+
else
|
75 |
+
$url = $item['url'];
|
76 |
+
|
77 |
+
if ($url)
|
78 |
+
{
|
79 |
+
$domain = TextHelper::getHostName($url);
|
80 |
+
if (!in_array($domain, array('buscape.com.br', 'avlws.com')))
|
81 |
+
$data[$key]['domain'] = $item['domain'] = $domain;
|
82 |
+
}
|
83 |
+
}
|
84 |
+
// save img
|
85 |
+
if ($this->config('save_img') && !wp_is_post_revision($post_id))
|
86 |
+
{
|
87 |
+
// check old_data also. need for fix behavior with "preview changes" button and by keyword update
|
88 |
+
if (isset($old_data[$key]) && !empty($old_data[$key]['img_file']) && file_exists(ImageHelper::getFullImgPath($old_data[$key]['img_file'])))
|
89 |
+
{
|
90 |
+
// image exists
|
91 |
+
$item['img'] = $old_data[$key]['img'];
|
92 |
+
$item['img_file'] = $old_data[$key]['img_file'];
|
93 |
+
} elseif ($item['img'] && empty($item['img_file']))
|
94 |
+
{
|
95 |
+
$local_img_name = ImageHelper::saveImgLocaly($item['img'], $item['title']);
|
96 |
+
if ($local_img_name)
|
97 |
+
{
|
98 |
+
$uploads = \wp_upload_dir();
|
99 |
+
$item['img'] = $uploads['url'] . '/' . $local_img_name;
|
100 |
+
$item['img_file'] = ltrim(trailingslashit($uploads['subdir']), '\/') . $local_img_name;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
$data[$key] = $item;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
return $data;
|
107 |
+
}
|
108 |
+
|
109 |
+
public static function getFullImgPath($img_path)
|
110 |
+
{
|
111 |
+
$uploads = \wp_upload_dir();
|
112 |
+
return trailingslashit($uploads['basedir']) . $img_path;
|
113 |
+
}
|
114 |
+
|
115 |
+
public function defaultTemplateName()
|
116 |
+
{
|
117 |
+
return 'data_simple';
|
118 |
+
}
|
119 |
+
|
120 |
+
public function viewDataPrepare($data)
|
121 |
+
{
|
122 |
+
// cashback integration
|
123 |
+
if (GeneralConfig::getInstance()->option('cashback_integration') == 'enabled' && class_exists('\CashbackTracker\application\Plugin'))
|
124 |
+
{
|
125 |
+
foreach ($data as $key => $d)
|
126 |
+
{
|
127 |
+
$data[$key]['url'] = \CashbackTracker\application\components\DeeplinkGenerator::maybeAddTracking($d['url']);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
// local redirect
|
132 |
+
if ($this->config('set_local_redirect'))
|
133 |
+
{
|
134 |
+
foreach ($data as $key => $d)
|
135 |
+
{
|
136 |
+
$data[$key]['aff_url'] = $d['url']; // url without redirect
|
137 |
+
$data[$key]['url'] = LocalRedirect::createRedirectUrl($d);
|
138 |
+
}
|
139 |
+
}
|
140 |
+
return $data;
|
141 |
+
}
|
142 |
+
|
143 |
+
}
|
application/components/ParserModuleConfig.php
CHANGED
@@ -1,110 +1,130 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* ParserModuleConfig abstract class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class ParserModuleConfig extends ModuleConfig {
|
15 |
+
|
16 |
+
public function options()
|
17 |
+
{
|
18 |
+
$tpl_manager = ModuleTemplateManager::getInstance($this->module_id);
|
19 |
+
$options = array(
|
20 |
+
'is_active' => array(
|
21 |
+
'title' => __('Enable module', 'content-egg'),
|
22 |
+
'description' => '',
|
23 |
+
'callback' => array($this, 'render_checkbox'),
|
24 |
+
'default' => 0,
|
25 |
+
'section' => 'default',
|
26 |
+
'validator' => array(
|
27 |
+
array(
|
28 |
+
'call' => array($this, 'checkRequirements'),
|
29 |
+
'message' => __('Could not activate.', 'content-egg'),
|
30 |
+
),
|
31 |
+
),
|
32 |
+
),
|
33 |
+
'embed_at' => array(
|
34 |
+
'title' => __('Add', 'content-egg'),
|
35 |
+
'description' => __('The place for content of module. Shortcodes will work in any place regardless of the setting.', 'content-egg'),
|
36 |
+
'callback' => array($this, 'render_dropdown'),
|
37 |
+
'dropdown_options' => array(
|
38 |
+
'post_bottom' => __('At the end of the post', 'content-egg'),
|
39 |
+
'post_top' => __('At the beginning of the post', 'content-egg'),
|
40 |
+
'shortcode' => __('Shortcodes only', 'content-egg'),
|
41 |
+
),
|
42 |
+
'default' => 'post_bottom',
|
43 |
+
'section' => 'default',
|
44 |
+
),
|
45 |
+
'priority' => array(
|
46 |
+
'title' => __('Priority', 'content-egg'),
|
47 |
+
'description' => __('Priority sets order of modules in post. 0 - is the most highest priority.', 'content-egg') . ' ' .
|
48 |
+
__('Also it applied to price sorting.', 'content-egg'),
|
49 |
+
'callback' => array($this, 'render_input'),
|
50 |
+
'default' => 10,
|
51 |
+
'validator' => array(
|
52 |
+
'trim',
|
53 |
+
'absint',
|
54 |
+
),
|
55 |
+
'section' => 'default',
|
56 |
+
),
|
57 |
+
'template' => array(
|
58 |
+
'title' => __('Template', 'content-egg'),
|
59 |
+
'description' => __('Default template', 'content-egg'),
|
60 |
+
'callback' => array($this, 'render_dropdown'),
|
61 |
+
'dropdown_options' => $tpl_manager->getTemplatesList(),
|
62 |
+
'default' => $this->getModuleInstance()->defaultTemplateName(),
|
63 |
+
'section' => 'default',
|
64 |
+
),
|
65 |
+
'tpl_title' => array(
|
66 |
+
'title' => __('Title', 'content-egg'),
|
67 |
+
'description' => __('Templates may use title on data output.', 'content-egg'),
|
68 |
+
'callback' => array($this, 'render_input'),
|
69 |
+
'default' => '',
|
70 |
+
'validator' => array(
|
71 |
+
'trim',
|
72 |
+
),
|
73 |
+
'section' => 'default',
|
74 |
+
),
|
75 |
+
'featured_image' => array(
|
76 |
+
'title' => 'Featured image',
|
77 |
+
'description' => __('Automatically set Featured image for post', 'content-egg'),
|
78 |
+
'callback' => array($this, 'render_dropdown'),
|
79 |
+
'dropdown_options' => array(
|
80 |
+
'' => __('Don\'t set', 'content-egg'),
|
81 |
+
'first' => __('First image', 'content-egg'),
|
82 |
+
'second' => __('Second image', 'content-egg'),
|
83 |
+
'rand' => __('Random image', 'content-egg'),
|
84 |
+
'last' => __('Last image', 'content-egg'),
|
85 |
+
),
|
86 |
+
'default' => '',
|
87 |
+
'section' => 'default',
|
88 |
+
),
|
89 |
+
'set_local_redirect' => array(
|
90 |
+
'title' => __('Redirect', 'content-egg'),
|
91 |
+
'description' => __('Make links with local 301 redirect', 'content-egg'),
|
92 |
+
'callback' => array($this, 'render_checkbox'),
|
93 |
+
'default' => 0,
|
94 |
+
'section' => 'default',
|
95 |
+
),
|
96 |
+
);
|
97 |
+
|
98 |
+
return array_merge(parent::options(), $options);
|
99 |
+
}
|
100 |
+
|
101 |
+
public function checkRequirements($value)
|
102 |
+
{
|
103 |
+
if ($requirements = $this->getModuleInstance()->requirements())
|
104 |
+
return false;
|
105 |
+
else
|
106 |
+
return true;
|
107 |
+
}
|
108 |
+
|
109 |
+
protected static function moveRequiredUp(array $options)
|
110 |
+
{
|
111 |
+
$keys = array('is_active');
|
112 |
+
|
113 |
+
foreach ($options as $key => $option)
|
114 |
+
{
|
115 |
+
if (strpos($option['title'], '*'))
|
116 |
+
$keys[] = $key;
|
117 |
+
}
|
118 |
+
|
119 |
+
$res = array();
|
120 |
+
foreach ($keys as $key)
|
121 |
+
{
|
122 |
+
$res[$key] = $options[$key];
|
123 |
+
unset($options[$key]);
|
124 |
+
}
|
125 |
+
|
126 |
+
$res = array_merge($res, $options);
|
127 |
+
return $res;
|
128 |
+
}
|
129 |
+
|
130 |
+
}
|
application/components/Scheduler.php
CHANGED
@@ -1,34 +1,36 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Scheduler class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2016 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class Scheduler implements iScheduler {
|
15 |
+
|
16 |
+
public static function initAction()
|
17 |
+
{
|
18 |
+
\add_action(static::getCronTag(), array(get_called_class(), 'run'));
|
19 |
+
}
|
20 |
+
|
21 |
+
public static function addScheduleEvent($recurrence = 'hourly', $timestamp = null)
|
22 |
+
{
|
23 |
+
if (!$timestamp)
|
24 |
+
$timestamp = time();
|
25 |
+
|
26 |
+
if (!\wp_next_scheduled(static::getCronTag()))
|
27 |
+
\wp_schedule_event($timestamp, $recurrence, static::getCronTag());
|
28 |
+
}
|
29 |
+
|
30 |
+
public static function clearScheduleEvent()
|
31 |
+
{
|
32 |
+
if (\wp_next_scheduled(static::getCronTag()))
|
33 |
+
\wp_clear_scheduled_hook(static::getCronTag());
|
34 |
+
}
|
35 |
+
|
36 |
+
}
|
application/components/Shortcoded.php
CHANGED
@@ -1,51 +1,53 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
private $
|
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
|
49 |
-
|
50 |
-
|
51 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Shortcoded class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
22 |
+
if (!isset(self::$instances[$post_id]))
|
23 |
+
{
|
24 |
+
self::$instances[$post_id] = new self($post_id);
|
25 |
+
self::$shortcoded_module_ids[$post_id] = array();
|
26 |
+
}
|
27 |
+
return self::$instances[$post_id];
|
28 |
+
}
|
29 |
+
|
30 |
+
private function __construct($post_id)
|
31 |
+
{
|
32 |
+
$this->post_id = $post_id;
|
33 |
+
}
|
34 |
+
|
35 |
+
public function getShortcodedModuleIds()
|
36 |
+
{
|
37 |
+
return self::$shortcoded_module_ids[$this->post_id];
|
38 |
+
}
|
39 |
+
|
40 |
+
public function setShortcodedModule($module_id)
|
41 |
+
{
|
42 |
+
self::$shortcoded_module_ids[$this->post_id][$module_id] = $module_id;
|
43 |
+
}
|
44 |
+
|
45 |
+
public function isShortcoded($module_id)
|
46 |
+
{
|
47 |
+
if (isset(self::$shortcoded_module_ids[$this->post_id][$module_id]))
|
48 |
+
return true;
|
49 |
+
else
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
application/components/TemplateManager.php
CHANGED
@@ -1,233 +1,252 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
abstract public function
|
25 |
-
|
26 |
-
public function
|
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 |
-
if (
|
69 |
-
return array();
|
70 |
-
|
71 |
-
$
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
$
|
79 |
-
if ($
|
80 |
-
$
|
81 |
-
|
82 |
-
|
83 |
-
if ($
|
84 |
-
$templates[$template_id]
|
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 |
-
$is_custom =
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
$
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\helpers\TextHelper;
|
8 |
+
use ContentEgg\application\admin\GeneralConfig;
|
9 |
+
use ContentEgg\application\helpers\TemplateHelper;
|
10 |
+
|
11 |
+
/**
|
12 |
+
* TemplateManager class file
|
13 |
+
*
|
14 |
+
* @author keywordrush.com <support@keywordrush.com>
|
15 |
+
* @link http://www.keywordrush.com/
|
16 |
+
* @copyright Copyright © 2015 keywordrush.com
|
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 |
+
{
|
32 |
+
$prefix = $this->getTempatePrefix();
|
33 |
+
if ($this->templates === null)
|
34 |
+
{
|
35 |
+
$templates = array();
|
36 |
+
foreach ($this->getCustomTempateDirs() as $custom_name => $dir)
|
37 |
+
{
|
38 |
+
$templates = array_merge($templates, $this->scanTemplates($dir, $prefix, $custom_name));
|
39 |
+
}
|
40 |
+
$templates = array_merge($templates, $this->scanTemplates($this->getTempateDir(), $prefix, false));
|
41 |
+
$this->templates = $templates;
|
42 |
+
}
|
43 |
+
|
44 |
+
if ($short_mode)
|
45 |
+
{
|
46 |
+
$list = array();
|
47 |
+
foreach ($this->templates as $id => $name)
|
48 |
+
{
|
49 |
+
$custom = '';
|
50 |
+
if (self::isCustomTemplate($id))
|
51 |
+
{
|
52 |
+
$parts = explode('/', $id);
|
53 |
+
$custom = 'custom/';
|
54 |
+
$id = $parts[1];
|
55 |
+
}
|
56 |
+
|
57 |
+
// del prefix
|
58 |
+
$list[$custom . substr($id, strlen($prefix))] = $name;
|
59 |
+
}
|
60 |
+
return $list;
|
61 |
+
}
|
62 |
+
|
63 |
+
return $this->templates;
|
64 |
+
}
|
65 |
+
|
66 |
+
private function scanTemplates($path, $prefix, $custom_name = false)
|
67 |
+
{
|
68 |
+
if ($custom_name && !is_dir($path))
|
69 |
+
return array();
|
70 |
+
|
71 |
+
$tpl_files = glob($path . '/' . $prefix . '*.php');
|
72 |
+
if (!$tpl_files)
|
73 |
+
return array();
|
74 |
+
|
75 |
+
$templates = array();
|
76 |
+
foreach ($tpl_files as $file)
|
77 |
+
{
|
78 |
+
$template_id = basename($file, '.php');
|
79 |
+
if ($custom_name)
|
80 |
+
$template_id = 'custom/' . $template_id;
|
81 |
+
|
82 |
+
$data = \get_file_data($file, array('name' => 'Name'));
|
83 |
+
if ($data && !empty($data['name']))
|
84 |
+
$templates[$template_id] = strip_tags($data['name']);
|
85 |
+
else
|
86 |
+
$templates[$template_id] = $template_id;
|
87 |
+
if ($custom_name)
|
88 |
+
$templates[$template_id] .= ' [' . esc_attr(__($custom_name, 'content-egg')) . ']';
|
89 |
+
}
|
90 |
+
return $templates;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function render($view_name, array $_data = array())
|
94 |
+
{
|
95 |
+
$file = $this->getViewPath($view_name);
|
96 |
+
if (!$file)
|
97 |
+
return '';
|
98 |
+
|
99 |
+
$this->last_render_data = $_data;
|
100 |
+
extract($_data, EXTR_PREFIX_SAME, 'data');
|
101 |
+
|
102 |
+
ob_start();
|
103 |
+
ob_implicit_flush(false);
|
104 |
+
include $file;
|
105 |
+
$res = ob_get_clean();
|
106 |
+
return $res;
|
107 |
+
}
|
108 |
+
|
109 |
+
public function renderPartial($view_name, array $_data = array())
|
110 |
+
{
|
111 |
+
$file = $this->getPartialViewPath($view_name, false);
|
112 |
+
if (!$file)
|
113 |
+
return '';
|
114 |
+
$this->renderPath($file, $_data);
|
115 |
+
}
|
116 |
+
|
117 |
+
public function renderBlock($view_name, array $data = array())
|
118 |
+
{
|
119 |
+
$file = $this->getPartialViewPath($view_name, true);
|
120 |
+
if (!$file)
|
121 |
+
return '';
|
122 |
+
$this->renderPath($file, $data);
|
123 |
+
}
|
124 |
+
|
125 |
+
protected function renderPath($view_path, $_data = array())
|
126 |
+
{
|
127 |
+
if (!is_file($view_path) || !is_readable($view_path))
|
128 |
+
throw new \Exception('View file "' . $view_path . '" does not exist.');
|
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 |
+
{
|
137 |
+
$view_name = str_replace('.', '', $view_name);
|
138 |
+
$file = \ContentEgg\PLUGIN_PATH . 'application/templates/';
|
139 |
+
if ($block)
|
140 |
+
$file .= 'blocks/';
|
141 |
+
else
|
142 |
+
$file .= $this->getTempatePrefix();
|
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 |
+
public function getViewPath($view_name)
|
151 |
+
{
|
152 |
+
$view_name = str_replace('.', '', $view_name);
|
153 |
+
if (self::isCustomTemplate($view_name))
|
154 |
+
{
|
155 |
+
$view_name = substr($view_name, 7);
|
156 |
+
foreach ($this->getCustomTempateDirs() as $custom_prefix => $custom_dir)
|
157 |
+
{
|
158 |
+
$tpl_path = $custom_dir;
|
159 |
+
$file = $tpl_path . DIRECTORY_SEPARATOR . TextHelper::clear($view_name) . '.php';
|
160 |
+
if (is_file($file) && is_readable($file))
|
161 |
+
return $file;
|
162 |
+
}
|
163 |
+
return false;
|
164 |
+
} else
|
165 |
+
{
|
166 |
+
$tpl_path = $this->getTempateDir();
|
167 |
+
$file = $tpl_path . DIRECTORY_SEPARATOR . TextHelper::clear($view_name) . '.php';
|
168 |
+
if (is_file($file) && is_readable($file))
|
169 |
+
return $file;
|
170 |
+
else
|
171 |
+
return false;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
public function getFullTemplateId($short_id)
|
176 |
+
{
|
177 |
+
$prefix = $this->getTempatePrefix();
|
178 |
+
$custom = '';
|
179 |
+
if (self::isCustomTemplate($short_id))
|
180 |
+
{
|
181 |
+
$parts = explode('/', $short_id);
|
182 |
+
$custom = 'custom/';
|
183 |
+
$id = $parts[1];
|
184 |
+
} else
|
185 |
+
$id = $short_id;
|
186 |
+
|
187 |
+
// check _data prefix
|
188 |
+
if (substr($id, 0, strlen($prefix)) != $prefix)
|
189 |
+
{
|
190 |
+
$id = $prefix . $id;
|
191 |
+
}
|
192 |
+
return $custom . $id;
|
193 |
+
}
|
194 |
+
|
195 |
+
public static function isCustomTemplate($template_id)
|
196 |
+
{
|
197 |
+
if (substr($template_id, 0, 7) == 'custom/')
|
198 |
+
return true;
|
199 |
+
else
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
|
203 |
+
public function isTemplateExists($tpl)
|
204 |
+
{
|
205 |
+
return array_key_exists($tpl, $this->getTemplatesList());
|
206 |
+
}
|
207 |
+
|
208 |
+
public function prepareShortcodeTempate($template)
|
209 |
+
{
|
210 |
+
if (self::isCustomTemplate($template))
|
211 |
+
{
|
212 |
+
$is_custom = true;
|
213 |
+
// del 'custom/' prefix
|
214 |
+
$template = substr($template, 7);
|
215 |
+
} else
|
216 |
+
$is_custom = false;
|
217 |
+
|
218 |
+
$template = TextHelper::clear($template);
|
219 |
+
if ($is_custom)
|
220 |
+
$template = 'custom/' . $template;
|
221 |
+
if ($template)
|
222 |
+
$template = $this->getFullTemplateId($template);
|
223 |
+
|
224 |
+
return $template;
|
225 |
+
}
|
226 |
+
|
227 |
+
public function enqueueProductsStyle()
|
228 |
+
{
|
229 |
+
if (self::$product_style_enqueued)
|
230 |
+
return;
|
231 |
+
|
232 |
+
\wp_enqueue_style('egg-bootstrap');
|
233 |
+
\wp_enqueue_style('egg-products');
|
234 |
+
|
235 |
+
if (!$background = \wp_strip_all_tags(GeneralConfig::getInstance()->option('button_color')))
|
236 |
+
$background = '#dc3545';
|
237 |
+
|
238 |
+
if (!$price_color = \wp_strip_all_tags(GeneralConfig::getInstance()->option('price_color')))
|
239 |
+
$price_color = '#dc3545';
|
240 |
+
|
241 |
+
$border = TemplateHelper::adjustBrightness($background, -0.05);
|
242 |
+
$background_hover = TemplateHelper::adjustBrightness($background, -0.15);
|
243 |
+
$border_hover = TemplateHelper::adjustBrightness($background_hover, -0.05);
|
244 |
+
|
245 |
+
$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;}';
|
246 |
+
|
247 |
+
\wp_add_inline_style('egg-products', $custom_css);
|
248 |
+
self::$product_style_enqueued = true;
|
249 |
+
}
|
250 |
+
|
251 |
+
|
252 |
+
}
|
application/components/VirtualPage.php
CHANGED
@@ -1,168 +1,165 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
elseif (\get_option('permalink_structure'))
|
58 |
-
{
|
59 |
-
$home_path = parse_url(
|
60 |
-
$page = preg_replace(
|
61 |
-
$page = parse_url($page, PHP_URL_PATH);
|
62 |
-
$page = trim($page, '/');
|
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 |
-
$p
|
100 |
-
|
101 |
-
$p->
|
102 |
-
$p->
|
103 |
-
$p->
|
104 |
-
$p->
|
105 |
-
$p->
|
106 |
-
$p->
|
107 |
-
$p->
|
108 |
-
$p->
|
109 |
-
$p->
|
110 |
-
$p->
|
111 |
-
$p->
|
112 |
-
$p->
|
113 |
-
$p->
|
114 |
-
$p->
|
115 |
-
$p->
|
116 |
-
$p->
|
117 |
-
$p->
|
118 |
-
$p->
|
119 |
-
$p->
|
120 |
-
$p->
|
121 |
-
$p->
|
122 |
-
$p->
|
123 |
-
$p->
|
124 |
-
$p->
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
$wp_query->
|
132 |
-
$wp_query->
|
133 |
-
$wp_query->
|
134 |
-
$
|
135 |
-
$wp_query->
|
136 |
-
|
137 |
-
$
|
138 |
-
$wp_query->
|
139 |
-
|
140 |
-
$wp_query->
|
141 |
-
$wp_query->
|
142 |
-
|
143 |
-
$wp_query->
|
144 |
-
$wp_query->
|
145 |
-
$wp_query->
|
146 |
-
$wp_query->
|
147 |
-
$wp_query->
|
148 |
-
$wp_query->
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
$
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
}
|
167 |
-
|
168 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* VirtualPage abstract class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
13 |
+
*/
|
14 |
+
abstract class VirtualPage {
|
15 |
+
|
16 |
+
private static $created = false;
|
17 |
+
|
18 |
+
public function __construct()
|
19 |
+
{
|
20 |
+
\add_action('parse_request', array($this, 'sniffRequests'));
|
21 |
+
}
|
22 |
+
|
23 |
+
public static function initAction()
|
24 |
+
{
|
25 |
+
$class = get_called_class();
|
26 |
+
new $class;
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Page slug
|
31 |
+
*/
|
32 |
+
abstract function getSlug();
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Page body
|
36 |
+
*/
|
37 |
+
abstract function getBody();
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Page title
|
41 |
+
*/
|
42 |
+
abstract function getTitle();
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Custom page template
|
46 |
+
*/
|
47 |
+
public function getTemplate()
|
48 |
+
{
|
49 |
+
return '';
|
50 |
+
}
|
51 |
+
|
52 |
+
public function sniffRequests($wp)
|
53 |
+
{
|
54 |
+
if (isset($wp->query_vars['pagename']))
|
55 |
+
{
|
56 |
+
$page = $wp->query_vars['pagename'];
|
57 |
+
} elseif (\get_option('permalink_structure'))
|
58 |
+
{
|
59 |
+
$home_path = parse_url(\home_url('/'), PHP_URL_PATH);
|
60 |
+
$page = preg_replace("#^" . preg_quote($home_path) . "#", '', $_SERVER['REQUEST_URI']);
|
61 |
+
$page = parse_url($page, PHP_URL_PATH);
|
62 |
+
$page = trim($page, '/');
|
63 |
+
} else
|
64 |
+
return;
|
65 |
+
|
66 |
+
if ($page && $page == $this->getSlug())
|
67 |
+
{
|
68 |
+
$this->handleRequest($wp->query_vars);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
protected function handleRequest($query_vars = array())
|
73 |
+
{
|
74 |
+
\add_action('template_redirect', array($this, 'renderTemplate'));
|
75 |
+
\add_filter('the_posts', array($this, 'createDummyPage'));
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Modified version of Virtual_Themed_Pages_BC class
|
80 |
+
* @link: https://gist.github.com/brianoz/9105004
|
81 |
+
*/
|
82 |
+
public function createDummyPage($posts)
|
83 |
+
{
|
84 |
+
if (self::$created)
|
85 |
+
return $posts;
|
86 |
+
|
87 |
+
/*
|
88 |
+
if ($posts)
|
89 |
+
return $posts;
|
90 |
+
*
|
91 |
+
*/
|
92 |
+
|
93 |
+
// have to create a dummy post as otherwise many templates
|
94 |
+
// don't call the_content filter
|
95 |
+
global $wp, $wp_query;
|
96 |
+
|
97 |
+
//create a fake post intance
|
98 |
+
$p = new \stdClass;
|
99 |
+
// fill $p with everything a page in the database would have
|
100 |
+
$p->ID = -1;
|
101 |
+
$p->post_author = 1;
|
102 |
+
$p->post_date = current_time('mysql');
|
103 |
+
$p->post_date_gmt = current_time('mysql', 1);
|
104 |
+
$p->post_content = $this->getBody();
|
105 |
+
$p->post_title = $this->getTitle();
|
106 |
+
$p->post_excerpt = '';
|
107 |
+
$p->post_status = 'publish';
|
108 |
+
$p->ping_status = 'closed';
|
109 |
+
$p->post_password = '';
|
110 |
+
$p->post_name = $this->getSlug(); // slug
|
111 |
+
$p->to_ping = '';
|
112 |
+
$p->pinged = '';
|
113 |
+
$p->modified = $p->post_date;
|
114 |
+
$p->modified_gmt = $p->post_date_gmt;
|
115 |
+
$p->post_content_filtered = '';
|
116 |
+
$p->post_parent = 0;
|
117 |
+
$p->guid = \get_home_url('/' . $p->post_name); // use url instead?
|
118 |
+
$p->menu_order = 0;
|
119 |
+
$p->post_type = 'page';
|
120 |
+
$p->post_mime_type = '';
|
121 |
+
$p->comment_status = 'closed';
|
122 |
+
$p->comment_count = 0;
|
123 |
+
$p->filter = 'raw'; // How to sanitize post fields. Accepts 'raw', 'edit', 'db', or 'display'.
|
124 |
+
$p->ancestors = array(); // 3.6
|
125 |
+
//$p = new \WP_Post($p); // ??
|
126 |
+
//$GLOBALS['post'] = $p;
|
127 |
+
// reset wp_query properties to simulate a found page
|
128 |
+
$wp_query->is_page = TRUE;
|
129 |
+
$wp_query->is_singular = TRUE;
|
130 |
+
$wp_query->is_home = FALSE;
|
131 |
+
$wp_query->is_archive = FALSE;
|
132 |
+
$wp_query->is_category = FALSE;
|
133 |
+
unset($wp_query->query['error']);
|
134 |
+
$wp->query = array();
|
135 |
+
$wp_query->query_vars['error'] = '';
|
136 |
+
$wp_query->is_404 = FALSE;
|
137 |
+
$wp_query->found_posts = 1;
|
138 |
+
$wp_query->comment_count = 0;
|
139 |
+
// -1 for current_comment displays comment if not logged in!
|
140 |
+
$wp_query->current_comment = null;
|
141 |
+
$wp_query->is_singular = 1;
|
142 |
+
$wp_query->post = $p;
|
143 |
+
$wp_query->posts = array($p);
|
144 |
+
$wp_query->queried_object = $p;
|
145 |
+
$wp_query->queried_object_id = $p->ID;
|
146 |
+
$wp_query->current_post = $p->ID;
|
147 |
+
$wp_query->post_count = 1;
|
148 |
+
$wp_query->is_attachment = false;
|
149 |
+
|
150 |
+
self::$created = true;
|
151 |
+
|
152 |
+
return array($p);
|
153 |
+
}
|
154 |
+
|
155 |
+
public function renderTemplate()
|
156 |
+
{
|
157 |
+
$templates = array('page.php', 'index.php');
|
158 |
+
$template = $this->getTemplate();
|
159 |
+
if ($template)
|
160 |
+
$templates = array_merge(array($template), $templates);
|
161 |
+
\locate_template($templates, true);
|
162 |
+
exit;
|
163 |
+
}
|
164 |
+
|
165 |
+
}
|
|
|
|
|
|
application/components/WidgetTemplateManager.php
CHANGED
@@ -1,64 +1,66 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
const
|
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 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* WidgetTemplateManager class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
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 |
+
{
|
26 |
+
if (!isset(self::$_instances[$widget_slug]))
|
27 |
+
{
|
28 |
+
$class = get_called_class();
|
29 |
+
self::$_instances[$widget_slug] = new $class($widget_slug);
|
30 |
+
}
|
31 |
+
return self::$_instances[$widget_slug];
|
32 |
+
}
|
33 |
+
|
34 |
+
private function __construct($widget_slug)
|
35 |
+
{
|
36 |
+
$this->widget_slug = $widget_slug;
|
37 |
+
$this->widget_short_slug = preg_replace('/^cegg_/', '', $this->widget_slug);
|
38 |
+
}
|
39 |
+
|
40 |
+
public function getTempatePrefix()
|
41 |
+
{
|
42 |
+
return self::TEMPLATE_PREFIX . $this->widget_short_slug . '_';
|
43 |
+
}
|
44 |
+
|
45 |
+
public function getTempateDir()
|
46 |
+
{
|
47 |
+
return \ContentEgg\PLUGIN_PATH . self::TEMPLATE_DIR;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function getCustomTempateDirs()
|
51 |
+
{
|
52 |
+
return array(
|
53 |
+
'child-theme' => \get_stylesheet_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, //child theme
|
54 |
+
'theme' => \get_template_directory() . '/' . self::CUSTOM_TEMPLATE_DIR, // theme
|
55 |
+
'custom' => \WP_CONTENT_DIR . '/' . self::CUSTOM_TEMPLATE_DIR,
|
56 |
+
);
|
57 |
+
}
|
58 |
+
|
59 |
+
public function render($view_name, array $_data = array())
|
60 |
+
{
|
61 |
+
if (!self::isCustomTemplate($view_name))
|
62 |
+
$this->enqueueProductsStyle();
|
63 |
+
return parent::render($view_name, $_data);
|
64 |
+
}
|
65 |
+
|
66 |
+
}
|
application/components/iScheduler.php
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\components;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
public static function
|
17 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\components;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Scheduler interface file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2016 keywordrush.com
|
13 |
+
*/
|
14 |
+
interface iScheduler {
|
15 |
+
|
16 |
+
public static function getCronTag();
|
17 |
+
|
18 |
+
public static function run();
|
19 |
+
}
|
application/components/index.php
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
// Silence is golden.
|
1 |
+
<?php
|
2 |
+
|
3 |
// Silence is golden.
|
application/helpers/AdminHelper.php
CHANGED
@@ -1,43 +1,140 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
*
|
12 |
-
*
|
13 |
-
* @
|
14 |
-
*
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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 |
+
{
|
22 |
+
$taxonomy = array('category');
|
23 |
+
|
24 |
+
// @todo: widget is initialized before woo? taxonomy does not exist
|
25 |
+
if (in_array('product', GeneralConfig::getInstance()->option('post_types')) && \taxonomy_exists('product_cat'))
|
26 |
+
$taxonomy[] = 'product_cat';
|
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 |
+
{
|
34 |
+
$results[$category->term_id] = $category->name;
|
35 |
+
if ($category->taxonomy == 'product_cat')
|
36 |
+
$results[$category->term_id] .= ' [product]';
|
37 |
+
}
|
38 |
+
|
39 |
+
return $results;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Tabs as sections
|
44 |
+
*/
|
45 |
+
public static function doTabsSections($page)
|
46 |
+
{
|
47 |
+
global $wp_settings_sections, $wp_settings_fields;
|
48 |
+
|
49 |
+
if (!isset($wp_settings_sections[$page]))
|
50 |
+
return;
|
51 |
+
|
52 |
+
echo '<div id="cegg-tabs">';
|
53 |
+
echo '<ul>';
|
54 |
+
$i = 1;
|
55 |
+
foreach ((array) $wp_settings_sections[$page] as $section)
|
56 |
+
{
|
57 |
+
echo '<li><a href="#tabs-' . $i . '">' . $section['title'] . '</a></li>';
|
58 |
+
$i++;
|
59 |
+
}
|
60 |
+
echo '</ul>';
|
61 |
+
$i = 1;
|
62 |
+
foreach ((array) $wp_settings_sections[$page] as $section)
|
63 |
+
{
|
64 |
+
echo '<div id="tabs-' . $i . '">';
|
65 |
+
echo '<table class="form-table" role="presentation">';
|
66 |
+
\do_settings_fields($page, $section['id']);
|
67 |
+
echo '</table>';
|
68 |
+
echo '</div>';
|
69 |
+
$i++;
|
70 |
+
}
|
71 |
+
echo '</div>';
|
72 |
+
$script = 'jQuery(document).ready(function($){$(\'#cegg-tabs\').tabs();});';
|
73 |
+
echo '<script type="text/javascript">' . $script . '</script>';
|
74 |
+
}
|
75 |
+
|
76 |
+
public static function getProductModules()
|
77 |
+
{
|
78 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
79 |
+
$results = array();
|
80 |
+
foreach ($modules as $module)
|
81 |
+
{
|
82 |
+
if ($module->isDeprecated() && !$module->isActive())
|
83 |
+
continue;
|
84 |
+
|
85 |
+
if ($module->isAffiliateParser() && $module->isProductParser() && !$module->isAeParser())
|
86 |
+
$results[] = $module;
|
87 |
+
}
|
88 |
+
|
89 |
+
return $results;
|
90 |
+
}
|
91 |
+
|
92 |
+
public static function getAeProductModules()
|
93 |
+
{
|
94 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
95 |
+
$results = array();
|
96 |
+
foreach ($modules as $module)
|
97 |
+
{
|
98 |
+
if ($module->isDeprecated() && !$module->isActive())
|
99 |
+
continue;
|
100 |
+
|
101 |
+
if ($module->isAffiliateParser() && $module->isProductParser() && $module->isAeParser())
|
102 |
+
$results[] = $module;
|
103 |
+
}
|
104 |
+
|
105 |
+
return $results;
|
106 |
+
}
|
107 |
+
|
108 |
+
public static function getCouponModules()
|
109 |
+
{
|
110 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
111 |
+
$results = array();
|
112 |
+
foreach ($modules as $module)
|
113 |
+
{
|
114 |
+
if ($module->isDeprecated() && !$module->isActive())
|
115 |
+
continue;
|
116 |
+
|
117 |
+
if ($module->isAffiliateParser() && $module->isCouponParser())
|
118 |
+
$results[] = $module;
|
119 |
+
}
|
120 |
+
|
121 |
+
return $results;
|
122 |
+
}
|
123 |
+
|
124 |
+
public static function getContentModules()
|
125 |
+
{
|
126 |
+
$modules = ModuleManager::getInstance()->getConfigurableModules();
|
127 |
+
$results = array();
|
128 |
+
foreach ($modules as $module)
|
129 |
+
{
|
130 |
+
if ($module->isDeprecated() && !$module->isActive())
|
131 |
+
continue;
|
132 |
+
|
133 |
+
if (!$module->isAffiliateParser())
|
134 |
+
$results[] = $module;
|
135 |
+
}
|
136 |
+
|
137 |
+
return $results;
|
138 |
+
}
|
139 |
+
|
140 |
+
}
|
application/helpers/ArrayHelper.php
CHANGED
@@ -1,110 +1,112 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
if ((float) $v[$key_name]
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
$
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
if ((float) $v[$key_name]
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
}
|
|
|
|
1 |
+
<?php
|
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 |
+
{
|
22 |
+
$difference = array();
|
23 |
+
foreach ($array1 as $key => $value)
|
24 |
+
{
|
25 |
+
if (is_array($value))
|
26 |
+
{
|
27 |
+
if (!isset($array2[$key]) || !is_array($array2[$key]))
|
28 |
+
{
|
29 |
+
$difference[$key] = $value;
|
30 |
+
} else
|
31 |
+
{
|
32 |
+
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
|
33 |
+
if (!empty($new_diff))
|
34 |
+
$difference[$key] = $new_diff;
|
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 |
+
* Full depth recursive conversion to array
|
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 |
+
public static function array2Object(array $a)
|
55 |
+
{
|
56 |
+
return json_decode(json_encode($a), false);
|
57 |
+
}
|
58 |
+
|
59 |
+
public static function asortStable(array $array, $order1 = SORT_ASC, $order2 = SORT_ASC)
|
60 |
+
{
|
61 |
+
if (!$array)
|
62 |
+
return $array;
|
63 |
+
|
64 |
+
foreach ($array as $key => $value)
|
65 |
+
{
|
66 |
+
$keys[] = $key;
|
67 |
+
$data[] = $value;
|
68 |
+
}
|
69 |
+
array_multisort($data, $order1, $keys, $order2, $array);
|
70 |
+
return $array;
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Hightest value of an associative array
|
75 |
+
*/
|
76 |
+
public static function getMaxKeyAssoc($array, $key_name, $zero_ignore = false)
|
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 |
+
public static function getMinKeyAssoc($array, $key_name, $zero_ignore = false)
|
95 |
+
{
|
96 |
+
$first = reset($array);
|
97 |
+
$min_key = key($array);
|
98 |
+
$min_value = $first[$key_name];
|
99 |
+
foreach ($array as $k => $v)
|
100 |
+
{
|
101 |
+
if ($zero_ignore && !(float) $v[$key_name])
|
102 |
+
continue;
|
103 |
+
if ((float) $v[$key_name] < (float) $min_value)
|
104 |
+
{
|
105 |
+
$min_value = $v[$key_name];
|
106 |
+
$min_key = $k;
|
107 |
+
}
|
108 |
+
}
|
109 |
+
return $min_key;
|
110 |
+
}
|
111 |
+
|
112 |
+
}
|
application/helpers/CurrencyHelper.php
CHANGED
@@ -1,535 +1,681 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
$this->
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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 http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2016 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 |
+
{
|
25 |
+
if (self::$instance === null)
|
26 |
+
{
|
27 |
+
self::$instance = new CurrencyHelper($locale);
|
28 |
+
}
|
29 |
+
return self::$instance;
|
30 |
+
}
|
31 |
+
|
32 |
+
private function __construct($locale)
|
33 |
+
{
|
34 |
+
$this->setLocale($locale);
|
35 |
+
$this->currencies = self::currencies();
|
36 |
+
$this->locales = self::locales();
|
37 |
+
}
|
38 |
+
|
39 |
+
public static function locales()
|
40 |
+
{
|
41 |
+
return array(
|
42 |
+
'en' => array(
|
43 |
+
'thousand_sep' => ',',
|
44 |
+
'decimal_sep' => '.',
|
45 |
+
),
|
46 |
+
'nl' => array(
|
47 |
+
'thousand_sep' => '.',
|
48 |
+
'decimal_sep' => ',',
|
49 |
+
),
|
50 |
+
'be' => array(
|
51 |
+
'thousand_sep' => ' ',
|
52 |
+
'decimal_sep' => ',',
|
53 |
+
),
|
54 |
+
'de' => array(
|
55 |
+
'thousand_sep' => '.',
|
56 |
+
'decimal_sep' => ',',
|
57 |
+
),
|
58 |
+
'es' => array(
|
59 |
+
'thousand_sep' => '.',
|
60 |
+
'decimal_sep' => ',',
|
61 |
+
),
|
62 |
+
'fr' => array(
|
63 |
+
'thousand_sep' => ' ',
|
64 |
+
'decimal_sep' => ',',
|
65 |
+
),
|
66 |
+
'it' => array(
|
67 |
+
'thousand_sep' => '.',
|
68 |
+
'decimal_sep' => ',',
|
69 |
+
),
|
70 |
+
'ru' => array(
|
71 |
+
'thousand_sep' => ' ',
|
72 |
+
'decimal_sep' => ',',
|
73 |
+
),
|
74 |
+
'uk' => array(
|
75 |
+
'thousand_sep' => ' ',
|
76 |
+
'decimal_sep' => ',',
|
77 |
+
),
|
78 |
+
);
|
79 |
+
}
|
80 |
+
|
81 |
+
public static function currencies()
|
82 |
+
{
|
83 |
+
return array(
|
84 |
+
'USD' => array(
|
85 |
+
'currency_symbol' => '$',
|
86 |
+
'currency_pos' => 'left',
|
87 |
+
'thousand_sep' => ',',
|
88 |
+
'decimal_sep' => '.',
|
89 |
+
'num_decimals' => 2,
|
90 |
+
'name' => 'United States dollar',
|
91 |
+
),
|
92 |
+
'EUR' => array(
|
93 |
+
'currency_symbol' => '€',
|
94 |
+
'currency_pos' => array(
|
95 |
+
'nl' => 'left',
|
96 |
+
'be' => 'left',
|
97 |
+
'de' => 'right',
|
98 |
+
'es' => 'right',
|
99 |
+
'fr' => 'right',
|
100 |
+
'it' => 'right',
|
101 |
+
),
|
102 |
+
'thousand_sep' => '.',
|
103 |
+
'decimal_sep' => ',',
|
104 |
+
'num_decimals' => 2,
|
105 |
+
'name' => 'Euro',
|
106 |
+
),
|
107 |
+
'CAD' => array(
|
108 |
+
'currency_symbol' => 'C $',
|
109 |
+
'currency_pos' => 'left',
|
110 |
+
'thousand_sep' => ',',
|
111 |
+
'decimal_sep' => '.',
|
112 |
+
'num_decimals' => 2,
|
113 |
+
'name' => 'Canadian dollar',
|
114 |
+
),
|
115 |
+
'GBP' => array(
|
116 |
+
'currency_symbol' => '£',
|
117 |
+
'currency_pos' => 'left',
|
118 |
+
'thousand_sep' => ',',
|
119 |
+
'decimal_sep' => '.',
|
120 |
+
'num_decimals' => 2,
|
121 |
+
'name' => 'British pound',
|
122 |
+
),
|
123 |
+
'JPY' => array(
|
124 |
+
'currency_symbol' => '¥',
|
125 |
+
'currency_pos' => 'left',
|
126 |
+
'thousand_sep' => ',',
|
127 |
+
'decimal_sep' => '.',
|
128 |
+
'num_decimals' => 0,
|
129 |
+
'name' => 'Japanese yen',
|
130 |
+
),
|
131 |
+
'CNY' => array(
|
132 |
+
'currency_symbol' => '¥',
|
133 |
+
'currency_pos' => 'left',
|
134 |
+
'thousand_sep' => ',',
|
135 |
+
'decimal_sep' => '.',
|
136 |
+
'num_decimals' => 2,
|
137 |
+
'name' => 'Chinese yuan',
|
138 |
+
),
|
139 |
+
'RUB' => array(
|
140 |
+
'currency_symbol' => 'руб.',
|
141 |
+
'currency_pos' => 'right_space',
|
142 |
+
'thousand_sep' => ' ',
|
143 |
+
'decimal_sep' => ',',
|
144 |
+
'num_decimals' => 0,
|
145 |
+
'name' => 'Russian ruble',
|
146 |
+
),
|
147 |
+
'RUR' => array(
|
148 |
+
'currency_symbol' => 'руб.',
|
149 |
+
'currency_pos' => 'right_space',
|
150 |
+
'thousand_sep' => ' ',
|
151 |
+
'decimal_sep' => ',',
|
152 |
+
'num_decimals' => 0,
|
153 |
+
'name' => 'Russian ruble',
|
154 |
+
),
|
155 |
+
'UAH' => array(
|
156 |
+
'currency_symbol' => 'грн.',
|
157 |
+
'currency_pos' => 'right_space',
|
158 |
+
'thousand_sep' => ' ',
|
159 |
+
'decimal_sep' => ',',
|
160 |
+
'num_decimals' => 0,
|
161 |
+
'name' => 'Ukrainian hryvnia',
|
162 |
+
),
|
163 |
+
'INR' => array(
|
164 |
+
'currency_symbol' => 'Rs.',
|
165 |
+
'currency_pos' => 'left_space',
|
166 |
+
'thousand_sep' => ',',
|
167 |
+
'decimal_sep' => '.',
|
168 |
+
'num_decimals' => 0,
|
169 |
+
'name' => 'Indian Rupee',
|
170 |
+
),
|
171 |
+
'AUD' => array(
|
172 |
+
'currency_symbol' => 'AU $',
|
173 |
+
'currency_pos' => 'left',
|
174 |
+
'thousand_sep' => ',',
|
175 |
+
'decimal_sep' => '.',
|
176 |
+
'num_decimals' => 2,
|
177 |
+
'name' => 'Australian dollar',
|
178 |
+
),
|
179 |
+
'VND' => array(
|
180 |
+
'currency_symbol' => '₫',
|
181 |
+
'currency_pos' => 'right',
|
182 |
+
'thousand_sep' => '.',
|
183 |
+
'decimal_sep' => ',',
|
184 |
+
'num_decimals' => 0,
|
185 |
+
'name' => 'Vietnamese dong',
|
186 |
+
),
|
187 |
+
'BRL' => array(
|
188 |
+
'currency_symbol' => 'R$',
|
189 |
+
'currency_pos' => 'left_space',
|
190 |
+
'thousand_sep' => '.',
|
191 |
+
'decimal_sep' => ',',
|
192 |
+
'num_decimals' => 2,
|
193 |
+
'name' => 'Brazilian real',
|
194 |
+
),
|
195 |
+
'TND' => array(
|
196 |
+
'currency_symbol' => 'DT',
|
197 |
+
'currency_pos' => 'right',
|
198 |
+
'thousand_sep' => ' ',
|
199 |
+
'decimal_sep' => '.',
|
200 |
+
'num_decimals' => 3,
|
201 |
+
'name' => 'Tunisian dinar',
|
202 |
+
),
|
203 |
+
'NGN' => array(
|
204 |
+
'currency_symbol' => '₦',
|
205 |
+
'currency_pos' => 'left',
|
206 |
+
'thousand_sep' => ',',
|
207 |
+
'decimal_sep' => '.',
|
208 |
+
'num_decimals' => 2,
|
209 |
+
'name' => 'Nigerian naira',
|
210 |
+
),
|
211 |
+
'MXN' => array(
|
212 |
+
'currency_symbol' => '$',
|
213 |
+
'currency_pos' => 'left',
|
214 |
+
'thousand_sep' => ',',
|
215 |
+
'decimal_sep' => '.',
|
216 |
+
'num_decimals' => 2,
|
217 |
+
'name' => 'Mexican peso',
|
218 |
+
),
|
219 |
+
'MDL' => array(
|
220 |
+
'currency_symbol' => 'lei',
|
221 |
+
'currency_pos' => 'right_space',
|
222 |
+
'thousand_sep' => ',',
|
223 |
+
'decimal_sep' => '.',
|
224 |
+
'num_decimals' => 2,
|
225 |
+
'name' => 'Moldovan leu',
|
226 |
+
),
|
227 |
+
'KRW' => array(
|
228 |
+
'currency_symbol' => '₩',
|
229 |
+
'currency_pos' => 'left',
|
230 |
+
'thousand_sep' => ',',
|
231 |
+
'decimal_sep' => '.',
|
232 |
+
'num_decimals' => 0,
|
233 |
+
'name' => 'South Korean won',
|
234 |
+
),
|
235 |
+
'THB' => array(
|
236 |
+
'currency_symbol' => '฿',
|
237 |
+
'currency_pos' => 'left_space',
|
238 |
+
'thousand_sep' => ',',
|
239 |
+
'decimal_sep' => '.',
|
240 |
+
'num_decimals' => 0,
|
241 |
+
'name' => 'Thai baht',
|
242 |
+
),
|
243 |
+
'RON' => array(
|
244 |
+
'currency_symbol' => 'Lei',
|
245 |
+
'currency_pos' => 'right_space',
|
246 |
+
'thousand_sep' => '.',
|
247 |
+
'decimal_sep' => ',',
|
248 |
+
'num_decimals' => 2,
|
249 |
+
'name' => 'Romanian Leu',
|
250 |
+
),
|
251 |
+
'EGP' => array(
|
252 |
+
'currency_symbol' => 'EGP',
|
253 |
+
'currency_pos' => 'right_space',
|
254 |
+
'thousand_sep' => ',',
|
255 |
+
'decimal_sep' => '.',
|
256 |
+
'num_decimals' => 0,
|
257 |
+
'name' => 'Egypt Pound',
|
258 |
+
),
|
259 |
+
'KWD' => array(
|
260 |
+
'currency_symbol' => 'KD',
|
261 |
+
'currency_pos' => 'right_space',
|
262 |
+
'thousand_sep' => ',',
|
263 |
+
'decimal_sep' => '.',
|
264 |
+
'num_decimals' => 3,
|
265 |
+
'name' => 'Kuwaiti dinar',
|
266 |
+
),
|
267 |
+
'TRY' => array(
|
268 |
+
'currency_symbol' => 'TL',
|
269 |
+
'currency_pos' => 'right_space',
|
270 |
+
'thousand_sep' => ',',
|
271 |
+
'decimal_sep' => '.',
|
272 |
+
'num_decimals' => 2,
|
273 |
+
'name' => 'Turkish Lira',
|
274 |
+
),
|
275 |
+
'IDR' => array(
|
276 |
+
'currency_symbol' => 'Rp',
|
277 |
+
'currency_pos' => 'left_space',
|
278 |
+
'thousand_sep' => '.',
|
279 |
+
'decimal_sep' => ',',
|
280 |
+
'num_decimals' => 0,
|
281 |
+
'name' => 'Indonesian Rupiah',
|
282 |
+
),
|
283 |
+
'PKR' => array(
|
284 |
+
'currency_symbol' => 'PKR.',
|
285 |
+
'currency_pos' => 'left',
|
286 |
+
'thousand_sep' => ',',
|
287 |
+
'decimal_sep' => '.',
|
288 |
+
'num_decimals' => 0,
|
289 |
+
'name' => 'Pakistani Rupee',
|
290 |
+
),
|
291 |
+
'HKD' => array(
|
292 |
+
'currency_symbol' => 'HKD$',
|
293 |
+
'currency_pos' => 'left',
|
294 |
+
'thousand_sep' => ',',
|
295 |
+
'decimal_sep' => '.',
|
296 |
+
'num_decimals' => 2,
|
297 |
+
'name' => 'Hong Kong dollar',
|
298 |
+
),
|
299 |
+
'ILS' => array(
|
300 |
+
'currency_symbol' => '₪',
|
301 |
+
'currency_pos' => 'left',
|
302 |
+
'thousand_sep' => ',',
|
303 |
+
'decimal_sep' => '.',
|
304 |
+
'num_decimals' => 2,
|
305 |
+
'name' => 'Israeli Shekel',
|
306 |
+
),
|
307 |
+
'AED' => array(
|
308 |
+
'currency_symbol' => 'AED',
|
309 |
+
'currency_pos' => 'right_space',
|
310 |
+
'thousand_sep' => ',',
|
311 |
+
'decimal_sep' => '.',
|
312 |
+
'num_decimals' => 2,
|
313 |
+
'name' => 'UAE Dirham',
|
314 |
+
),
|
315 |
+
'SAR' => array(
|
316 |
+
'currency_symbol' => 'SAR',
|
317 |
+
'currency_pos' => 'right_space',
|
318 |
+
'thousand_sep' => ',',
|
319 |
+
'decimal_sep' => '.',
|
320 |
+
'num_decimals' => 2,
|
321 |
+
'name' => 'Saudi Riyal',
|
322 |
+
),
|
323 |
+
'SGD' => array(
|
324 |
+
'currency_symbol' => 'S$',
|
325 |
+
'currency_pos' => 'left',
|
326 |
+
'thousand_sep' => ',',
|
327 |
+
'decimal_sep' => '.',
|
328 |
+
'num_decimals' => 2,
|
329 |
+
'name' => 'Singapore dollar',
|
330 |
+
),
|
331 |
+
'HUF' => array(
|
332 |
+
'currency_symbol' => 'Ft',
|
333 |
+
'currency_pos' => 'right_space',
|
334 |
+
'thousand_sep' => '.',
|
335 |
+
'decimal_sep' => ',',
|
336 |
+
'num_decimals' => 0,
|
337 |
+
'name' => 'Hungarian forint',
|
338 |
+
),
|
339 |
+
'PLN' => array(
|
340 |
+
'currency_symbol' => 'zł',
|
341 |
+
'currency_pos' => 'right_space',
|
342 |
+
'thousand_sep' => '',
|
343 |
+
'decimal_sep' => ',',
|
344 |
+
'num_decimals' => 2,
|
345 |
+
'name' => 'Polish Zloty',
|
346 |
+
),
|
347 |
+
'CZK' => array(
|
348 |
+
'currency_symbol' => 'Kč',
|
349 |
+
'currency_pos' => 'right_space',
|
350 |
+
'thousand_sep' => ' ',
|
351 |
+
'decimal_sep' => ',',
|
352 |
+
'num_decimals' => 0,
|
353 |
+
'name' => 'Czech koruna',
|
354 |
+
),
|
355 |
+
'MYR' => array(
|
356 |
+
'currency_symbol' => 'RM',
|
357 |
+
'currency_pos' => 'left',
|
358 |
+
'thousand_sep' => ',',
|
359 |
+
'decimal_sep' => '.',
|
360 |
+
'num_decimals' => 2,
|
361 |
+
'name' => 'Malaysia Ringgit',
|
362 |
+
),
|
363 |
+
'PCT' => array(
|
364 |
+
'currency_symbol' => '%',
|
365 |
+
'currency_pos' => 'right',
|
366 |
+
'thousand_sep' => '',
|
367 |
+
'decimal_sep' => '.',
|
368 |
+
'num_decimals' => 1,
|
369 |
+
'name' => 'Percentage',
|
370 |
+
),
|
371 |
+
'CLP' => array(
|
372 |
+
'currency_symbol' => '$',
|
373 |
+
'currency_pos' => 'left',
|
374 |
+
'thousand_sep' => '.',
|
375 |
+
'decimal_sep' => ',',
|
376 |
+
'num_decimals' => 0,
|
377 |
+
'name' => 'Peso Chileno',
|
378 |
+
),
|
379 |
+
'DKK' => array(
|
380 |
+
'currency_symbol' => 'DKK',
|
381 |
+
'currency_pos' => 'left_space',
|
382 |
+
'thousand_sep' => '.',
|
383 |
+
'decimal_sep' => ',',
|
384 |
+
'num_decimals' => 2,
|
385 |
+
'name' => 'Danske Kroner',
|
386 |
+
),
|
387 |
+
'KES' => array(
|
388 |
+
'currency_symbol' => 'KSh',
|
389 |
+
'currency_pos' => 'left_space',
|
390 |
+
'thousand_sep' => ',',
|
391 |
+
'decimal_sep' => '.',
|
392 |
+
'num_decimals' => 2,
|
393 |
+
'name' => 'Kenyan Shilling',
|
394 |
+
),
|
395 |
+
'HRK' => array(
|
396 |
+
'currency_symbol' => 'kn',
|
397 |
+
'currency_pos' => 'right_space',
|
398 |
+
'thousand_sep' => '.',
|
399 |
+
'decimal_sep' => ',',
|
400 |
+
'num_decimals' => 2,
|
401 |
+
'name' => 'Croatian Kuna',
|
402 |
+
),
|
403 |
+
'PEN' => array(
|
404 |
+
'currency_symbol' => 'S/',
|
405 |
+
'currency_pos' => 'left',
|
406 |
+
'thousand_sep' => ',',
|
407 |
+
'decimal_sep' => '.',
|
408 |
+
'num_decimals' => 2,
|
409 |
+
'name' => 'Peruvian sol',
|
410 |
+
),
|
411 |
+
'DOP' => array(
|
412 |
+
'currency_symbol' => 'RD$',
|
413 |
+
'currency_pos' => 'left',
|
414 |
+
'thousand_sep' => ',',
|
415 |
+
'decimal_sep' => '.',
|
416 |
+
'num_decimals' => 2,
|
417 |
+
'name' => 'Dominican Peso',
|
418 |
+
),
|
419 |
+
'UYU' => array(
|
420 |
+
'currency_symbol' => 'U$S',
|
421 |
+
'currency_pos' => 'left',
|
422 |
+
'thousand_sep' => '.',
|
423 |
+
'decimal_sep' => ',',
|
424 |
+
'num_decimals' => 2,
|
425 |
+
'name' => 'Uruguayan Peso',
|
426 |
+
),
|
427 |
+
'NIO' => array(
|
428 |
+
'currency_symbol' => 'C$',
|
429 |
+
'currency_pos' => 'left',
|
430 |
+
'thousand_sep' => ',',
|
431 |
+
'decimal_sep' => '.',
|
432 |
+
'num_decimals' => 2,
|
433 |
+
'name' => 'Nicaraguan Córdoba',
|
434 |
+
),
|
435 |
+
'PAB' => array(
|
436 |
+
'currency_symbol' => 'B/.',
|
437 |
+
'currency_pos' => 'left',
|
438 |
+
'thousand_sep' => '.',
|
439 |
+
'decimal_sep' => ',',
|
440 |
+
'num_decimals' => 2,
|
441 |
+
'name' => 'Panamanian Balboa',
|
442 |
+
),
|
443 |
+
'SVC' => array(
|
444 |
+
'currency_symbol' => '$',
|
445 |
+
'currency_pos' => 'left',
|
446 |
+
'thousand_sep' => ',',
|
447 |
+
'decimal_sep' => '.',
|
448 |
+
'num_decimals' => 2,
|
449 |
+
'name' => 'Salvadoran Colón',
|
450 |
+
),
|
451 |
+
'GTQ' => array(
|
452 |
+
'currency_symbol' => 'Q',
|
453 |
+
'currency_pos' => 'left',
|
454 |
+
'thousand_sep' => ',',
|
455 |
+
'decimal_sep' => '.',
|
456 |
+
'num_decimals' => 2,
|
457 |
+
'name' => 'Guatemalan Quetzal',
|
458 |
+
),
|
459 |
+
'HNL' => array(
|
460 |
+
'currency_symbol' => 'L',
|
461 |
+
'currency_pos' => 'left',
|
462 |
+
'thousand_sep' => ',',
|
463 |
+
'decimal_sep' => '.',
|
464 |
+
'num_decimals' => 2,
|
465 |
+
'name' => 'Honduran Lempira',
|
466 |
+
),
|
467 |
+
'JMD' => array(
|
468 |
+
'currency_symbol' => 'JM$',
|
469 |
+
'currency_pos' => 'left',
|
470 |
+
'thousand_sep' => ',',
|
471 |
+
'decimal_sep' => '.',
|
472 |
+
'num_decimals' => 2,
|
473 |
+
'name' => 'Jamaican Dollar',
|
474 |
+
),
|
475 |
+
'CRC' => array(
|
476 |
+
'currency_symbol' => '₡',
|
477 |
+
'currency_pos' => 'left',
|
478 |
+
'thousand_sep' => ',',
|
479 |
+
'decimal_sep' => '.',
|
480 |
+
'num_decimals' => 2,
|
481 |
+
'name' => 'Costa Rican Colón',
|
482 |
+
),
|
483 |
+
'ARS' => array(
|
484 |
+
'currency_symbol' => '$',
|
485 |
+
'currency_pos' => 'left',
|
486 |
+
'thousand_sep' => '.',
|
487 |
+
'decimal_sep' => ',',
|
488 |
+
'num_decimals' => 2,
|
489 |
+
'name' => 'Argentine Peso',
|
490 |
+
),
|
491 |
+
'BOB' => array(
|
492 |
+
'currency_symbol' => 'Bs',
|
493 |
+
'currency_pos' => 'left',
|
494 |
+
'thousand_sep' => '.',
|
495 |
+
'decimal_sep' => ',',
|
496 |
+
'num_decimals' => 2,
|
497 |
+
'name' => 'Bolivian Boliviano',
|
498 |
+
),
|
499 |
+
'COP' => array(
|
500 |
+
'currency_symbol' => '$',
|
501 |
+
'currency_pos' => 'left',
|
502 |
+
'thousand_sep' => '.',
|
503 |
+
'decimal_sep' => ',',
|
504 |
+
'num_decimals' => 2,
|
505 |
+
'name' => 'Colombian Peso',
|
506 |
+
),
|
507 |
+
'XOF' => array(
|
508 |
+
'currency_symbol' => 'FCFA',
|
509 |
+
'currency_pos' => 'left_space',
|
510 |
+
'thousand_sep' => ',',
|
511 |
+
'decimal_sep' => '.',
|
512 |
+
'num_decimals' => 0,
|
513 |
+
'name' => 'CFA Franc',
|
514 |
+
),
|
515 |
+
'SEK' => array(
|
516 |
+
'currency_symbol' => 'kr',
|
517 |
+
'currency_pos' => 'right_space',
|
518 |
+
'thousand_sep' => ' ',
|
519 |
+
'decimal_sep' => '.',
|
520 |
+
'num_decimals' => 0,
|
521 |
+
'name' => 'Swedish Krona',
|
522 |
+
),
|
523 |
+
);
|
524 |
+
}
|
525 |
+
|
526 |
+
public function setLocale($locale)
|
527 |
+
{
|
528 |
+
$this->locale = $locale;
|
529 |
+
}
|
530 |
+
|
531 |
+
public function getLocale()
|
532 |
+
{
|
533 |
+
return $this->locale;
|
534 |
+
}
|
535 |
+
|
536 |
+
private function getValue($currency, $key, $default = null)
|
537 |
+
{
|
538 |
+
if (isset($this->currencies[$currency]) && isset($this->currencies[$currency][$key]))
|
539 |
+
$value = $this->currencies[$currency][$key];
|
540 |
+
else
|
541 |
+
$value = null;
|
542 |
+
|
543 |
+
if (!is_null($value) && is_scalar($value) && $currency == 'MXN')
|
544 |
+
return $value;
|
545 |
+
|
546 |
+
if (is_array($value) && isset($value[$this->locale]))
|
547 |
+
return $value[$this->locale];
|
548 |
+
elseif (isset($this->locales[$this->locale]) && isset($this->locales[$this->locale][$key]))
|
549 |
+
return $this->locales[$this->locale][$key];
|
550 |
+
elseif (is_array($value))
|
551 |
+
return reset($value); // first value
|
552 |
+
elseif (is_scalar($value) && !is_null($value))
|
553 |
+
return $value;
|
554 |
+
else
|
555 |
+
return $default;
|
556 |
+
}
|
557 |
+
|
558 |
+
public function currencyFormat($amount, $currency, $thousand_sep = null, $decimal_sep = null, $before_symbol = '', $after_symbol = '')
|
559 |
+
{
|
560 |
+
$amount = $this->numberFormat($amount, $currency, $thousand_sep, $decimal_sep);
|
561 |
+
$symbol = \apply_filters('cegg_currency_symbol', $this->getSymbol($currency), $currency);
|
562 |
+
$currency_pos = $this->getCurrencyPos($currency);
|
563 |
+
$symbol = $before_symbol . $symbol . $after_symbol;
|
564 |
+
switch ($currency_pos)
|
565 |
+
{
|
566 |
+
case 'left_space':
|
567 |
+
return $symbol . ' ' . $amount;
|
568 |
+
case 'left':
|
569 |
+
return $symbol . $amount;
|
570 |
+
case 'right_space':
|
571 |
+
return $amount . ' ' . $symbol;
|
572 |
+
case 'right':
|
573 |
+
return $amount . $symbol;
|
574 |
+
default:
|
575 |
+
return $symbol . ' ' . $amount;
|
576 |
+
}
|
577 |
+
}
|
578 |
+
|
579 |
+
public function getCurrencyPos($currency, $default = 'left_space')
|
580 |
+
{
|
581 |
+
return $this->getValue($currency, 'currency_pos', $default);
|
582 |
+
}
|
583 |
+
|
584 |
+
public function getSymbol($currency)
|
585 |
+
{
|
586 |
+
return $this->getValue($currency, 'currency_symbol', $currency);
|
587 |
+
}
|
588 |
+
|
589 |
+
public function getName($currency)
|
590 |
+
{
|
591 |
+
return $this->getValue($currency, 'name', $currency);
|
592 |
+
}
|
593 |
+
|
594 |
+
public function numberFormat($number, $currency, $thousand_sep = null, $decimal_sep = null, $num_decimals = null)
|
595 |
+
{
|
596 |
+
if (!$thousand_sep)
|
597 |
+
$thousand_sep = $this->getValue($currency, 'thousand_sep', ',');
|
598 |
+
if (!$decimal_sep)
|
599 |
+
$decimal_sep = $this->getValue($currency, 'decimal_sep', '.');
|
600 |
+
if (!$num_decimals)
|
601 |
+
$num_decimals = $this->getValue($currency, 'num_decimals', 2);
|
602 |
+
return number_format((float) $number, absint($num_decimals), $decimal_sep, $thousand_sep);
|
603 |
+
}
|
604 |
+
|
605 |
+
public static function getCurrenciesList()
|
606 |
+
{
|
607 |
+
$list = array_keys(self::currencies());
|
608 |
+
sort($list);
|
609 |
+
return $list;
|
610 |
+
}
|
611 |
+
|
612 |
+
/**
|
613 |
+
* @link: http://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html#dev
|
614 |
+
*/
|
615 |
+
public static function queryCurrencyRateEcb($from, $to, $force = false)
|
616 |
+
{
|
617 |
+
$transient_name = 'cegg-currency-rates-ecb';
|
618 |
+
$rates = \get_transient($transient_name);
|
619 |
+
|
620 |
+
if ($rates === false || $force)
|
621 |
+
{
|
622 |
+
$url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
|
623 |
+
$params = array(
|
624 |
+
'timeout' => 15,
|
625 |
+
'user-agent' => 'Content Egg WP Plugin (https://www.keywordrush.com/contentegg)'
|
626 |
+
);
|
627 |
+
$response = \wp_remote_get($url, $params);
|
628 |
+
$rates = array();
|
629 |
+
if ($response && !\is_wp_error($response))
|
630 |
+
{
|
631 |
+
$results = TextHelper::unserialize_xml(\wp_remote_retrieve_body($response));
|
632 |
+
if (!isset($results['Cube']['Cube']['Cube']))
|
633 |
+
return 0;
|
634 |
+
foreach ($results['Cube']['Cube']['Cube'] as $r)
|
635 |
+
{
|
636 |
+
$rates[$r['@attributes']['currency']] = (float) $r['@attributes']['rate'];
|
637 |
+
}
|
638 |
+
}
|
639 |
+
\set_transient($transient_name, $rates, 6 * 3600);
|
640 |
+
}
|
641 |
+
|
642 |
+
if ($from == 'EUR' && isset($rates[$to]))
|
643 |
+
return $rates[$to];
|
644 |
+
elseif ($to == 'EUR' && isset($rates[$from]))
|
645 |
+
return 1 / $rates[$from];
|
646 |
+
elseif (isset($rates[$from]) && isset($rates[$to]))
|
647 |
+
return $rates[$to] / $rates[$from];
|
648 |
+
else
|
649 |
+
return 0;
|
650 |
+
}
|
651 |
+
|
652 |
+
public static function queryCurrencyRate($from, $to)
|
653 |
+
{
|
654 |
+
return self::queryCurrencyRateEcb($from, $to);
|
655 |
+
}
|
656 |
+
|
657 |
+
public static function getCurrencyRate($from, $to)
|
658 |
+
{
|
659 |
+
if ($from == 'RUR')
|
660 |
+
$from = 'RUB';
|
661 |
+
if ($to == 'RUR')
|
662 |
+
$to = 'RUB';
|
663 |
+
|
664 |
+
if ($rate = \apply_filters('content_egg_currency_rate', 0, $from, $to))
|
665 |
+
return $rate;
|
666 |
+
|
667 |
+
$transient_name = 'currency-rate-' . $from . $to;
|
668 |
+
if (!isset(self::$currencyRates[$transient_name]))
|
669 |
+
{
|
670 |
+
$rate = \get_transient($transient_name);
|
671 |
+
if ($rate === false)
|
672 |
+
{
|
673 |
+
$rate = self::queryCurrencyRate($from, $to);
|
674 |
+
\set_transient($transient_name, $rate, 24 * 3600);
|
675 |
+
}
|
676 |
+
self::$currencyRates[$transient_name] = $rate;
|
677 |
+
}
|
678 |
+
return self::$currencyRates[$transient_name];
|
679 |
+
}
|
680 |
+
|
681 |
+
}
|
application/helpers/FileHelper.php
CHANGED
@@ -1,47 +1,49 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
header("
|
38 |
-
|
39 |
-
header("
|
40 |
-
|
41 |
-
header("Content-Type: application/download");
|
42 |
-
|
43 |
-
header("Content-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
}
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\helpers;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
/**
|
8 |
+
* TextHelper class file
|
9 |
+
*
|
10 |
+
* @author keywordrush.com <support@keywordrush.com>
|
11 |
+
* @link http://www.keywordrush.com/
|
12 |
+
* @copyright Copyright © 2017 keywordrush.com
|
13 |
+
*/
|
14 |
+
class FileHelper {
|
15 |
+
|
16 |
+
public static function array2Csv(array $array)
|
17 |
+
{
|
18 |
+
if (ob_get_length() > 0)
|
19 |
+
ob_clean();
|
20 |
+
|
21 |
+
if (!$array)
|
22 |
+
return '';
|
23 |
+
ob_start();
|
24 |
+
$df = fopen("php://output", 'w');
|
25 |
+
fputcsv($df, array_keys(reset($array)));
|
26 |
+
foreach ($array as $row)
|
27 |
+
{
|
28 |
+
fputcsv($df, $row);
|
29 |
+
}
|
30 |
+
fclose($df);
|
31 |
+
return ob_get_clean();
|
32 |
+
}
|
33 |
+
|
34 |
+
public static function sendDownloadHeaders($filename)
|
35 |
+
{
|
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
@@ -1,441 +1,446 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
*
|
8 |
-
*
|
9 |
-
*
|
10 |
-
*
|
11 |
-
* @
|
12 |
-
* @
|
13 |
-
*
|
14 |
-
*
|
15 |
-
|
16 |
-
|
17 |
-
/**
|
18 |
-
* CodeIgniter
|
19 |
-
*
|
20 |
-
* An open source application development framework for PHP 5.2.4 or newer
|
21 |
-
*
|
22 |
-
* NOTICE OF LICENSE
|
23 |
-
*
|
24 |
-
* Licensed under the Open Software License version 3.0
|
25 |
-
*
|
26 |
-
* This source file is subject to the Open Software License (OSL 3.0) that is
|
27 |
-
* bundled with this package in the files license.txt / license.rst. It is
|
28 |
-
* also available through the world wide web at this URL:
|
29 |
-
* http://opensource.org/licenses/OSL-3.0
|
30 |
-
* If you did not receive a copy of the license and are unable to obtain it
|
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 |
-
|
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 |
-
if (
|
411 |
-
{
|
412 |
-
return '
|
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 |
}
|
1 |
+
<?php
|
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
|
19 |
+
*
|
20 |
+
* An open source application development framework for PHP 5.2.4 or newer
|
21 |
+
*
|
22 |
+
* NOTICE OF LICENSE
|
23 |
+
*
|
24 |
+
* Licensed under the Open Software License version 3.0
|
25 |
+
*
|
26 |
+
* This source file is subject to the Open Software License (OSL 3.0) that is
|
27 |
+
* bundled with this package in the files license.txt / license.rst. It is
|
28 |
+
* also available through the world wide web at this URL:
|
29 |
+
* http://opensource.org/licenses/OSL-3.0
|
30 |
+
* If you did not receive a copy of the license and are unable to obtain it
|
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 |
+
{
|
44 |
+
if (extension_loaded('mbstring'))
|
45 |
+
define('MB_ENABLED', TRUE);
|
46 |
+
else
|
47 |
+
define('MB_ENABLED', FALSE);
|
48 |
+
}
|
49 |
+
|
50 |
+
class FormValidator {
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Required
|
54 |
+
*
|
55 |
+
* @param string
|
56 |
+
* @return bool
|
57 |
+
*/
|
58 |
+
public static function required($str)
|
59 |
+
{
|
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 |
+
* @return bool
|
71 |
+
*/
|
72 |
+
public static function regex_match($str, $regex)
|
73 |
+
{
|
74 |
+
return (bool) preg_match($regex, $str);
|
75 |
+
}
|
76 |
+
|
77 |
+
// --------------------------------------------------------------------
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Minimum Length
|
81 |
+
*
|
82 |
+
* @param string
|
83 |
+
* @param string
|
84 |
+
* @return bool
|
85 |
+
*/
|
86 |
+
public static function min_length($str, $val)
|
87 |
+
{
|
88 |
+
if (!is_numeric($val))
|
89 |
+
{
|
90 |
+
return FALSE;
|
91 |
+
} else
|
92 |
+
{
|
93 |
+
$val = (int) $val;
|
94 |
+
}
|
95 |
+
|
96 |
+
return (MB_ENABLED === TRUE) ? ($val <= mb_strlen($str)) : ($val <= strlen($str));
|
97 |
+
}
|
98 |
+
|
99 |
+
// --------------------------------------------------------------------
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Max Length
|
103 |
+
*
|
104 |
+
* @param string
|
105 |
+
* @param string
|
106 |
+
* @return bool
|
107 |
+
*/
|
108 |
+
public static function max_length($str, $val)
|
109 |
+
{
|
110 |
+
if (!is_numeric($val))
|
111 |
+
{
|
112 |
+
return FALSE;
|
113 |
+
} else
|
114 |
+
{
|
115 |
+
$val = (int) $val;
|
116 |
+
}
|
117 |
+
|
118 |
+
return (MB_ENABLED === TRUE) ? ($val >= mb_strlen($str)) : ($val >= strlen($str));
|
119 |
+
}
|
120 |
+
|
121 |
+
// --------------------------------------------------------------------
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Exact Length
|
125 |
+
*
|
126 |
+
* @param string
|
127 |
+
* @param string
|
128 |
+
* @return bool
|
129 |
+
*/
|
130 |
+
public static function exact_length($str, $val)
|
131 |
+
{
|
132 |
+
if (!is_numeric($val))
|
133 |
+
{
|
134 |
+
return FALSE;
|
135 |
+
} else
|
136 |
+
{
|
137 |
+
$val = (int) $val;
|
138 |
+
}
|
139 |
+
return (MB_ENABLED === TRUE) ? (mb_strlen($str) === $val) : (strlen($str) === $val);
|
140 |
+
}
|
141 |
+
|
142 |
+
// --------------------------------------------------------------------
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Valid URL
|
146 |
+
*
|
147 |
+
* @param string $str
|
148 |
+
* @return bool
|
149 |
+
*/
|
150 |
+
public static function valid_url($str)
|
151 |
+
{
|
152 |
+
if (empty($str))
|
153 |
+
return FALSE;
|
154 |
+
|
155 |
+
$pattern = '/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i';
|
156 |
+
|
157 |
+
if (is_string($str) && strlen($str) < 2000)
|
158 |
+
{
|
159 |
+
if (preg_match($pattern, $str))
|
160 |
+
return true;
|
161 |
+
}
|
162 |
+
return false;
|
163 |
+
|
164 |
+
/*
|
165 |
+
if (empty($str))
|
166 |
+
{
|
167 |
+
return FALSE;
|
168 |
+
} elseif (preg_match('/^(?:([^:]*)\:)?\/\/(.+)$/', $str, $matches))
|
169 |
+
{
|
170 |
+
if (empty($matches[2]))
|
171 |
+
{
|
172 |
+
return FALSE;
|
173 |
+
} elseif (!in_array($matches[1], array('http', 'https'), TRUE))
|
174 |
+
{
|
175 |
+
return FALSE;
|
176 |
+
}
|
177 |
+
|
178 |
+
$str = $matches[2];
|
179 |
+
}
|
180 |
+
|
181 |
+
$str = 'http://' . $str;
|
182 |
+
|
183 |
+
// There's a bug affecting PHP 5.2.13, 5.3.2 that considers the
|
184 |
+
// underscore to be a valid hostname character instead of a dash.
|
185 |
+
// Reference: https://bugs.php.net/bug.php?id=51192
|
186 |
+
if (version_compare(PHP_VERSION, '5.2.13', '==') === 0 OR version_compare(PHP_VERSION, '5.3.2', '==') === 0)
|
187 |
+
{
|
188 |
+
sscanf($str, 'http://%[^/]', $host);
|
189 |
+
$str = substr_replace($str, strtr($host, array('_' => '-', '-' => '_')), 7, strlen($host));
|
190 |
+
}
|
191 |
+
|
192 |
+
return (filter_var($str, FILTER_VALIDATE_URL) !== FALSE);
|
193 |
+
*
|
194 |
+
*/
|
195 |
+
}
|
196 |
+
|
197 |
+
// --------------------------------------------------------------------
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Valid Email
|
201 |
+
*
|
202 |
+
* @param string
|
203 |
+
* @return bool
|
204 |
+
*/
|
205 |
+
public static function valid_email($str)
|
206 |
+
{
|
207 |
+
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
|
208 |
+
}
|
209 |
+
|
210 |
+
// --------------------------------------------------------------------
|
211 |
+
// --------------------------------------------------------------------
|
212 |
+
|
213 |
+
/**
|
214 |
+
* Alpha
|
215 |
+
*
|
216 |
+
* @param string
|
217 |
+
* @return bool
|
218 |
+
*/
|
219 |
+
public static function alpha($str)
|
220 |
+
{
|
221 |
+
return ctype_alpha($str);
|
222 |
+
}
|
223 |
+
|
224 |
+
// --------------------------------------------------------------------
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Alpha-numeric
|
228 |
+
*
|
229 |
+
* @param string
|
230 |
+
* @return bool
|
231 |
+
*/
|
232 |
+
public static function alpha_numeric($str)
|
233 |
+
{
|
234 |
+
return ctype_alnum((string) $str);
|
235 |
+
}
|
236 |
+
|
237 |
+
// --------------------------------------------------------------------
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Alpha-numeric w/ spaces
|
241 |
+
*
|
242 |
+
* @param string
|
243 |
+
* @return bool
|
244 |
+
*/
|
245 |
+
public static function alpha_numeric_spaces($str)
|
246 |
+
{
|
247 |
+
return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str);
|
248 |
+
}
|
249 |
+
|
250 |
+
// --------------------------------------------------------------------
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Alpha-numeric with underscores and dashes
|
254 |
+
*
|
255 |
+
* @param string
|
256 |
+
* @return bool
|
257 |
+
*/
|
258 |
+
public static function alpha_dash($str)
|
259 |
+
{
|
260 |
+
return (bool) preg_match('/^[a-z0-9_-]+$/i', $str);
|
261 |
+
}
|
262 |
+
|
263 |
+
// --------------------------------------------------------------------
|
264 |
+
|
265 |
+
/**
|
266 |
+
* Numeric
|
267 |
+
*
|
268 |
+
* @param string
|
269 |
+
* @return bool
|
270 |
+
*/
|
271 |
+
public static function numeric($str)
|
272 |
+
{
|
273 |
+
return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
|
274 |
+
}
|
275 |
+
|
276 |
+
// --------------------------------------------------------------------
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Integer
|
280 |
+
*
|
281 |
+
* @param string
|
282 |
+
* @return bool
|
283 |
+
*/
|
284 |
+
public static function integer($str)
|
285 |
+
{
|
286 |
+
return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
|
287 |
+
}
|
288 |
+
|
289 |
+
// --------------------------------------------------------------------
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Decimal number
|
293 |
+
*
|
294 |
+
* @param string
|
295 |
+
* @return bool
|
296 |
+
*/
|
297 |
+
public static function decimal($str)
|
298 |
+
{
|
299 |
+
return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str);
|
300 |
+
}
|
301 |
+
|
302 |
+
// --------------------------------------------------------------------
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Greater than
|
306 |
+
*
|
307 |
+
* @param string
|
308 |
+
* @param int
|
309 |
+
* @return bool
|
310 |
+
*/
|
311 |
+
public static function greater_than($str, $min)
|
312 |
+
{
|
313 |
+
return is_numeric($str) ? ($str > $min) : FALSE;
|
314 |
+
}
|
315 |
+
|
316 |
+
// --------------------------------------------------------------------
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Equal to or Greater than
|
320 |
+
*
|
321 |
+
* @param string
|
322 |
+
* @param int
|
323 |
+
* @return bool
|
324 |
+
*/
|
325 |
+
public static function greater_than_equal_to($str, $min)
|
326 |
+
{
|
327 |
+
return is_numeric($str) ? ($str >= $min) : FALSE;
|
328 |
+
}
|
329 |
+
|
330 |
+
// --------------------------------------------------------------------
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Less than
|
334 |
+
*
|
335 |
+
* @param string
|
336 |
+
* @param int
|
337 |
+
* @return bool
|
338 |
+
*/
|
339 |
+
public static function less_than($str, $max)
|
340 |
+
{
|
341 |
+
return is_numeric($str) ? ($str < $max) : FALSE;
|
342 |
+
}
|
343 |
+
|
344 |
+
// --------------------------------------------------------------------
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Equal to or Less than
|
348 |
+
*
|
349 |
+
* @param string
|
350 |
+
* @param int
|
351 |
+
* @return bool
|
352 |
+
*/
|
353 |
+
public static function less_than_equal_to($str, $max)
|
354 |
+
{
|
355 |
+
return is_numeric($str) ? ($str <= $max) : FALSE;
|
356 |
+
}
|
357 |
+
|
358 |
+
// --------------------------------------------------------------------
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Is a Natural number (0,1,2,3, etc.)
|
362 |
+
*
|
363 |
+
* @param string
|
364 |
+
* @return bool
|
365 |
+
*/
|
366 |
+
public static function is_natural($str)
|
367 |
+
{
|
368 |
+
return ctype_digit((string) $str);
|
369 |
+
}
|
370 |
+
|
371 |
+
// --------------------------------------------------------------------
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Is a Natural number, but not a zero (1,2,3, etc.)
|
375 |
+
*
|
376 |
+
* @param string
|
377 |
+
* @return bool
|
378 |
+
*/
|
379 |
+
public static function is_natural_no_zero($str)
|
380 |
+
{
|
381 |
+
return ($str != 0 && ctype_digit((string) $str));
|
382 |
+
}
|
383 |
+
|
384 |
+
// --------------------------------------------------------------------
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Valid Base64
|
388 |
+
*
|
389 |
+
* Tests a string for characters outside of the Base64 alphabet
|
390 |
+
* as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
|
391 |
+
*
|
392 |
+
* @param string
|
393 |
+
* @return bool
|
394 |
+
*/
|
395 |
+
public static function valid_base64($str)
|
396 |
+
{
|
397 |
+
return (base64_encode(base64_decode($str)) === $str);
|
398 |
+
}
|
399 |
+
|
400 |
+
// --------------------------------------------------------------------
|
401 |
+
|
402 |
+
/**
|
403 |
+
* Prep URL
|
404 |
+
*
|
405 |
+
* @param string
|
406 |
+
* @return string
|
407 |
+
*/
|
408 |
+
public static function prep_url($str = '')
|
409 |
+
{
|
410 |
+
if ($str === 'http://' OR $str === '')
|
411 |
+
{
|
412 |
+
return '';
|
413 |
+
}
|
414 |
+
|
415 |
+
if (strpos($str, 'http://') !== 0 && strpos($str, 'https://') !== 0)
|
416 |
+
{
|
417 |
+
return 'http://' . $str;
|
418 |
+
}
|
419 |
+
|
420 |
+
return $str;
|
421 |
+
}
|
422 |
+
|
423 |
+
// --------------------------------------------------------------------
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Convert PHP tags to entities
|
427 |
+
*
|
428 |
+
* @param string
|
429 |
+
* @return string
|
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 |
+
function affegg_intval_bool($str)
|
442 |
+
{
|
443 |
+
return intval((bool) $str);
|
444 |
+
}
|
445 |
+
|
446 |
}
|
application/helpers/ImageHelper.php
CHANGED
@@ -1,104 +1,106 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
$newfilename =
|
23 |
-
$newfilename =
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
return
|
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 |
-
return
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
}
|
|
|
|
1 |
+
<?php
|
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/13.1.2 Safari/605.1.15';
|
19 |
+
|
20 |
+
public static function saveImgLocaly($img_uri, $title = '', $check_image_type = true)
|
21 |
+
{
|
22 |
+
$newfilename = TextHelper::truncate($title);
|
23 |
+
$newfilename = TextHelper::rus2latin($newfilename);
|
24 |
+
$newfilename = preg_replace('/[^a-zA-Z0-9\-]/', '', $newfilename);
|
25 |
+
$newfilename = strtolower($newfilename);
|
26 |
+
if (!$newfilename)
|
27 |
+
$newfilename = time();
|
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 |
+
public static function downloadImg($img_uri, $save_dir, $file_name, $file_ext = null, $check_image_type = true)
|
38 |
+
{
|
39 |
+
$response = \wp_remote_get($img_uri, array('timeout' => self::DOWNLOAD_TIMEOUT, 'redirection' => 1, 'sslverify' => false, 'user-agent' => self::USERAGENT));
|
40 |
+
if (\is_wp_error($response) || (int) \wp_remote_retrieve_response_code($response) !== 200)
|
41 |
+
return false;
|
42 |
+
|
43 |
+
if ($file_ext === null)
|
44 |
+
{
|
45 |
+
$img_path = parse_url($img_uri, PHP_URL_PATH);
|
46 |
+
$file_ext = pathinfo(basename($img_path), PATHINFO_EXTENSION);
|
47 |
+
if (!$file_ext || $file_ext == 'aspx' || $file_ext == 'image')
|
48 |
+
{
|
49 |
+
$headers = \wp_remote_retrieve_headers($response);
|
50 |
+
if (empty($headers['content-type']))
|
51 |
+
return false;
|
52 |
+
$types = array_search($headers['content-type'], \wp_get_mime_types());
|
53 |
+
if (!$types)
|
54 |
+
return false;
|
55 |
+
|
56 |
+
$exts = explode('|', $types);
|
57 |
+
$file_ext = $exts[0];
|
58 |
+
}
|
59 |
+
}
|
60 |
+
if ($file_ext)
|
61 |
+
$file_name .= '.' . $file_ext;
|
62 |
+
|
63 |
+
$file_name = \wp_unique_filename($save_dir, $file_name);
|
64 |
+
|
65 |
+
if ($check_image_type)
|
66 |
+
{
|
67 |
+
$filetype = \wp_check_filetype($file_name, null);
|
68 |
+
if (substr($filetype['type'], 0, 5) != 'image')
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
|
72 |
+
$image_string = \wp_remote_retrieve_body($response);
|
73 |
+
$file_path = \trailingslashit($save_dir) . $file_name;
|
74 |
+
if (!file_put_contents($file_path, $image_string))
|
75 |
+
return false;
|
76 |
+
|
77 |
+
if ($check_image_type && !self::isImage($file_path))
|
78 |
+
{
|
79 |
+
@unlink($file_path);
|
80 |
+
return false;
|
81 |
+
}
|
82 |
+
if (!defined('FS_CHMOD_FILE'))
|
83 |
+
define('FS_CHMOD_FILE', ( fileperms(ABSPATH . 'index.php') & 0777 | 0644));
|
84 |
+
@chmod($file_path, FS_CHMOD_FILE);
|
85 |
+
|
86 |
+
return $file_name;
|
87 |
+
}
|
88 |
+
|
89 |
+
public static function isImage($path)
|
90 |
+
{
|
91 |
+
if (!$a = getimagesize($path))
|
92 |
+
return false;
|
93 |
+
$image_type = $a[2];
|
94 |
+
if (in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP)))
|
95 |
+
return true;
|
96 |
+
else
|
97 |
+
return false;
|
98 |
+
}
|
99 |
+
|
100 |
+
public static function getFullImgPath($img_path)
|
101 |
+
{
|
102 |
+
$uploads = \wp_upload_dir();
|
103 |
+
return trailingslashit($uploads['basedir']) . $img_path;
|
104 |
+
}
|
105 |
+
|
106 |
+
}
|
application/helpers/InputHelper.php
CHANGED
@@ -1,31 +1,33 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
*
|
9 |
-
*
|
10 |
-
* @
|
11 |
-
*
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
return $
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
return $
|
29 |
-
|
30 |
-
|
31 |
-
}
|
|
|
|
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
@@ -1,914 +1,1086 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace ContentEgg\application\helpers;
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
use ContentEgg\application\
|
8 |
-
use ContentEgg\application\
|
9 |
-
use ContentEgg\application\
|
10 |
-
use ContentEgg\application\
|
11 |
-
use ContentEgg\application\
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
return CurrencyHelper::getInstance()->
|
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 |
-
public static function
|
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 |
-
return $
|
123 |
-
|
124 |
-
return
|
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 |
-
foreach ($itemLinks as $link)
|
182 |
-
{
|
183 |
-
if ($link['Description'] == $description)
|
184 |
-
return $link['URL'];
|
185 |
-
}
|
186 |
-
return false;
|
187 |
-
}
|
188 |
-
|
189 |
-
public static function getLastUpdate($module_id, $post_id = null)
|
190 |
-
{
|
191 |
-
if (!$post_id)
|
192 |
-
{
|
193 |
-
global $post;
|
194 |
-
$post_id = $post->ID;
|
195 |
-
}
|
196 |
-
$res = \get_post_meta($post_id, ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module_id, true);
|
197 |
-
if (!$res)
|
198 |
-
$res = time();
|
199 |
-
return $res;
|
200 |
-
}
|
201 |
-
|
202 |
-
public static function dateFormatFromGmt($timestamp, $time = true)
|
203 |
-
{
|
204 |
-
$format = \get_option('date_format');
|
205 |
-
if ($time)
|
206 |
-
$format .= ' ' . \get_option('time_format');
|
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 |
-
return \date_i18n($format, $timestamp);
|
211 |
-
}
|
212 |
-
|
213 |
-
public static function getLastUpdateFormattedAmazon(array $data, $time = true)
|
214 |
-
{
|
215 |
-
if (!isset($data['Amazon']))
|
216 |
-
return false;
|
217 |
-
|
218 |
-
$item = current($data['Amazon']);
|
219 |
-
if (empty($item['last_update']))
|
220 |
-
return false;
|
221 |
-
|
222 |
-
$last_update = $item['last_update'];
|
223 |
-
|
224 |
-
return self::dateFormatFromGmt($last_update, $time);
|
225 |
-
}
|
226 |
-
|
227 |
-
public static function getLastUpdateFormatted($module_id, $post_id = null, $time = true)
|
228 |
-
{
|
229 |
-
if (!$post_id || $post_id === true) // $post_id === true - fix func params...
|
230 |
-
{
|
231 |
-
global $post;
|
232 |
-
$post_id = $post->ID;
|
233 |
-
}
|
234 |
-
|
235 |
-
$last_update = self::getLastUpdate($module_id, $post_id);
|
236 |
-
return self::dateFormatFromGmt($last_update, $time);
|
237 |
-
}
|
238 |
-
|
239 |
-
public static function filterDataByType($data, $type)
|
240 |
-
{
|
241 |
-
$results = array();
|
242 |
-
foreach ($data as $module_id => $items)
|
243 |
-
{
|
244 |
-
$module = \ContentEgg\application\components\ModuleManager::getInstance()->factory($module_id);
|
245 |
-
if ($module->getParserType() == $type)
|
246 |
-
$results[$module_id] = $items;
|
247 |
-
}
|
248 |
-
return $results;
|
249 |
-
}
|
250 |
-
|
251 |
-
public static function filterDataByModule($data, $module_ids)
|
252 |
-
{
|
253 |
-
if (!is_array($module_ids))
|
254 |
-
$module_ids = array($module_ids);
|
255 |
-
$results = array();
|
256 |
-
|
257 |
-
foreach ($data as $module_id => $items)
|
258 |
-
{
|
259 |
-
if (in_array($module_id, $module_ids))
|
260 |
-
$results[$module_id] = $items;
|
261 |
-
}
|
262 |
-
return $results;
|
263 |
-
}
|
264 |
-
|
265 |
-
public static function priceHistoryPrices($unique_id, $plugin_id, $limit = 5)
|
266 |
-
{
|
267 |
-
$prices = PriceHistoryModel::model()->getLastPrices($unique_id, $plugin_id, $limit);
|
268 |
-
$results = array();
|
269 |
-
foreach ($prices as $price)
|
270 |
-
{
|
271 |
-
$results[] = array(
|
272 |
-
'date' => strtotime($price['create_date']),
|
273 |
-
'price' => $price['price'],
|
274 |
-
);
|
275 |
-
}
|
276 |
-
return $results;
|
277 |
-
}
|
278 |
-
|
279 |
-
public static function priceHistoryMax($unique_id, $module_id)
|
280 |
-
{
|
281 |
-
if (!$price = PriceHistoryModel::model()->getMaxPrice($unique_id, $module_id))
|
282 |
-
return null;
|
283 |
-
return array('price' => $price['price'], 'date' => strtotime($price['create_date']));
|
284 |
-
}
|
285 |
-
|
286 |
-
public static function priceHistoryMin($unique_id, $module_id)
|
287 |
-
{
|
288 |
-
if (!$price = PriceHistoryModel::model()->getMinPrice($unique_id, $module_id))
|
289 |
-
return null;
|
290 |
-
return array('price' => $price['price'], 'date' => strtotime($price['create_date']));
|
291 |
-
}
|
292 |
-
|
293 |
-
public static function priceHistorySinceDate($unique_id, $module_id)
|
294 |
-
{
|
295 |
-
if (!$date = PriceHistoryModel::model()->getFirstDateValue($unique_id, $module_id))
|
296 |
-
return null;
|
297 |
-
return strtotime($date);
|
298 |
-
}
|
299 |
-
|
300 |
-
public static function priceChangesProducts($limit = 5)
|
301 |
-
{
|
302 |
-
$params = array(
|
303 |
-
//'select' => 'DISTINCT unique_id',
|
304 |
-
'order' => 'create_date DESC',
|
305 |
-
'where' => 'post_id IS NOT NULL',
|
306 |
-
'group' => 'unique_id',
|
307 |
-
'limit' => $limit,
|
308 |
-
);
|
309 |
-
$prices = PriceHistoryModel::model()->findAll($params);
|
310 |
-
$products = array();
|
311 |
-
// find products
|
312 |
-
foreach ($prices as $price)
|
313 |
-
{
|
314 |
-
if ($prod = ContentManager::getProductbyUniqueId($price['unique_id'], $price['module_id'], $price['post_id']))
|
315 |
-
$products[] = $prod;
|
316 |
-
}
|
317 |
-
return $products;
|
318 |
-
}
|
319 |
-
|
320 |
-
public static function priceHistoryMorrisChart($unique_id, $module_id, $days = 180, array $options = array(), $htmlOptions = array())
|
321 |
-
{
|
322 |
-
$where = PriceHistoryModel::model()->prepareWhere(
|
323 |
-
(array('unique_id = %s AND module_id = %s', array($unique_id, $module_id))), false);
|
324 |
-
$params = array(
|
325 |
-
'select' => 'date(create_date) as date, price as price',
|
326 |
-
'where' => $where . ' AND TIMESTAMPDIFF( DAY, create_date, "' . \current_time('mysql') . '") <= ' . $days,
|
327 |
-
//'group' => 'date',
|
328 |
-
'order' => 'date ASC'
|
329 |
-
);
|
330 |
-
$results = PriceHistoryModel::model()->findAll($params);
|
331 |
-
$results = array_reverse($results);
|
332 |
-
$prices = array();
|
333 |
-
/**
|
334 |
-
* php fix for selecting non-aggregate columns
|
335 |
-
* @see: https://stackoverflow.com/questions/1066453/mysql-group-by-and-order-by
|
336 |
-
*/
|
337 |
-
foreach ($results as $key => $r)
|
338 |
-
{
|
339 |
-
if ($key > 0 && $results[$key - 1]['date'] == $r['date'])
|
340 |
-
continue;
|
341 |
-
$price = array(
|
342 |
-
'date' => $r['date'],
|
343 |
-
'price' => $r['price'],
|
344 |
-
);
|
345 |
-
$prices[] = $price;
|
346 |
-
}
|
347 |
-
|
348 |
-
//add last known price to the chart
|
349 |
-
/*
|
350 |
-
$price = array(
|
351 |
-
'date' => $r['date'],
|
352 |
-
'price' => $r['price'],
|
353 |
-
);
|
354 |
-
$prices[] = $price;
|
355 |
-
*
|
356 |
-
*/
|
357 |
-
$data = array(
|
358 |
-
'chartType' => 'Area',
|
359 |
-
'data' => $prices,
|
360 |
-
'xkey' => 'date',
|
361 |
-
'ykeys' => array('price'),
|
362 |
-
'labels' => array(__('Price', 'content-egg-tpl')),
|
363 |
-
);
|
364 |
-
$options = array_merge($data, $options);
|
365 |
-
|
366 |
-
$id = $module_id . '-' . $unique_id . '-chart' . rand(0, 10000);
|
367 |
-
self::viewMorrisChart($id, $options, $htmlOptions);
|
368 |
-
}
|
369 |
-
|
370 |
-
public static function viewMorrisChart($id, array $options, $htmlOptions = array('style' => 'height: 250px;'))
|
371 |
-
{
|
372 |
-
// morris.js
|
373 |
-
\wp_enqueue_style('morrisjs');
|
374 |
-
\wp_enqueue_script('morrisjs');
|
375 |
-
|
376 |
-
if (!empty($options['chartType']) && in_array($options['chartType'], array('Line', 'Area', 'Donut', 'Bar')))
|
377 |
-
{
|
378 |
-
$chartType = $options['chartType'];
|
379 |
-
unset($options['chartType']);
|
380 |
-
} else
|
381 |
-
$chartType = 'Line';
|
382 |
-
$options['element'] = $id;
|
383 |
-
|
384 |
-
$html_attr = '';
|
385 |
-
foreach ($htmlOptions as $name => $value)
|
386 |
-
{
|
387 |
-
$html_attr .= ' ' . esc_attr($name) . '="' . esc_attr($value) . '"';
|
388 |
-
}
|
389 |
-
|
390 |
-
echo '<div style="direction: ltr;" id="' . esc_attr($id) . '"' . $html_attr . '></div>
|
391 |
-
<script>
|
392 |
-
jQuery(document).ready(function($) {
|
393 |
-
new Morris.' . $chartType . '(' . json_encode($options) . ');
|
394 |
-
});
|
395 |
-
</script>';
|
396 |
-
}
|
397 |
-
|
398 |
-
public static function isPriceAlertAllowed($unique_id = null, $module_id = null)
|
399 |
-
{
|
400 |
-
return \ContentEgg\application\PriceAlert::isPriceAlertAllowed($unique_id, $module_id);
|
401 |
-
}
|
402 |
-
|
403 |
-
public static function getCurrencyPos($currency)
|
404 |
-
{
|
405 |
-
return CurrencyHelper::getInstance()->getCurrencyPos($currency);
|
406 |
-
}
|
407 |
-
|
408 |
-
public static function getCurrencySymbol($currency)
|
409 |
-
{
|
410 |
-
return CurrencyHelper::getInstance()->getSymbol($currency);
|
411 |
-
}
|
412 |
-
|
413 |
-
public static function getCurrencyName($currency)
|
414 |
-
{
|
415 |
-
return CurrencyHelper::getInstance()->getName($currency);
|
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 |
-
public static function
|
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 |
-
public static function couponBtnText($print = true, array $item = array())
|
700 |
-
{
|
701 |
-
return self::btnText('btn_text_coupon', __('Shop Sale', 'content-egg-tpl'), $print, $item);
|
702 |
-
}
|
703 |
-
|
704 |
-
public static function getCurrentUserEmail()
|
705 |
-
{
|
706 |
-
if (!$current_user = wp_get_current_user())
|
707 |
-
return '';
|
708 |
-
return $current_user->user_email;
|
709 |
-
}
|
710 |
-
|
711 |
-
public static function getDaysAgo($ptime)
|
712 |
-
{
|
713 |
-
$etime = current_time('timestamp') - $ptime;
|
714 |
-
if ($etime < 1)
|
715 |
-
return '';
|
716 |
-
$d = $etime / (24 * 60 * 60);
|
717 |
-
|
718 |
-
if ($d < 1)
|
719 |
-
return __('today', 'content-egg-tpl');
|
720 |
-
$d = ceil($d);
|
721 |
-
|
722 |
-
if ($d > 1)
|
723 |
-
return sprintf(__('%d days ago', 'content-egg-tpl'), $d);
|
724 |
-
else
|
725 |
-
return sprintf(__('%d day ago', 'content-egg-tpl'), $d);
|
726 |
-
}
|
727 |
-
|
728 |
-
public static function getAmazonDisclaimer()
|
729 |
-
{
|
730 |
-
return __('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');
|
731 |
-
}
|
732 |
-
|
733 |
-
public static function printAmazonDisclaimer()
|
734 |
-
{
|
735 |
-
echo '<i class="cegg-disclaimer glyphicon glyphicon-info-sign" title="' . \esc_attr(self::getAmazonDisclaimer()) . '"></i>';
|
736 |
-
}
|
737 |
-
|
738 |
-
public static function btnText($option_name, $default, $print = true, array $item = array())
|
739 |
-
{
|
740 |
-
$text = GeneralConfig::getInstance()->option($option_name);
|
741 |
-
if (!$text)
|
742 |
-
$text = $default;
|
743 |
-
$text = \esc_attr(self::replacePatterns($text, $item));
|
744 |
-
|
745 |
-
if (!$print)
|
746 |
-
return $text;
|
747 |
-
|
748 |
-
echo $text;
|
749 |
-
}
|
750 |
-
|
751 |
-
private static function replacePatterns($template, array $item)
|
752 |
-
{
|
753 |
-
if (!$item)
|
754 |
-
return $template;
|
755 |
-
if (!preg_match_all('/%[a-zA-Z0-9_\.\,\(\)]+%/', $template, $matches))
|
756 |
-
return $template;
|
757 |
-
|
758 |
-
$replace = array();
|
759 |
-
foreach ($matches[0] as $pattern)
|
760 |
-
{
|
761 |
-
if (stristr($pattern, '%PRICE%'))
|
762 |
-
{
|
763 |
-
if (!empty($item['price']) && $item['currencyCode'])
|
764 |
-
$replace[$pattern] = TemplateHelper::formatPriceCurrency($item['price'], $item['currencyCode']);
|
765 |
-
else
|
766 |
-
$replace[$pattern] = '';
|
767 |
-
continue;
|
768 |
-
}
|
769 |
-
if (stristr($pattern, '%MERCHANT%'))
|
770 |
-
{
|
771 |
-
if ($merchant = TemplateHelper::getMerhantName($item))
|
772 |
-
$replace[$pattern] = $merchant;
|
773 |
-
else
|
774 |
-
$replace[$pattern] = '';
|
775 |
-
continue;
|
776 |
-
}
|
777 |
-
if (stristr($pattern, '%DOMAIN%'))
|
778 |
-
{
|
779 |
-
if (!empty($item['domain']))
|
780 |
-
$replace[$pattern] = $item['domain'];
|
781 |
-
else
|
782 |
-
$replace[$pattern] = TemplateHelper::getMerhantName($item);
|
783 |
-
continue;
|
784 |
-
}
|
785 |
-
if (stristr($pattern, '%STOCK_STATUS%'))
|
786 |
-
{
|
787 |
-
$replace[$pattern] = TemplateHelper::getStockStatusStr($item);
|
788 |
-
continue;
|
789 |
-
}
|
790 |
-
}
|
791 |
-
return str_ireplace(array_keys($replace), array_values($replace), $template);
|
792 |
-
}
|
793 |
-
|
794 |
-
public static function getStockStatusClass(array $item)
|
795 |
-
{
|
796 |
-
if (!isset($item['stock_status']))
|
797 |
-
return '';
|
798 |
-
|
799 |
-
if ($item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK)
|
800 |
-
return 'instock';
|
801 |
-
elseif ($item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
802 |
-
return 'outofstock';
|
803 |
-
elseif ($item['stock_status'] == ContentProduct::STOCK_STATUS_UNKNOWN)
|
804 |
-
return 'unknown';
|
805 |
-
else
|
806 |
-
return '';
|
807 |
-
}
|
808 |
-
|
809 |
-
public static function getStockStatusStr(array $item)
|
810 |
-
{
|
811 |
-
if (!isset($item['stock_status']))
|
812 |
-
return '';
|
813 |
-
if ($item['stock_status'] == ContentProduct::STOCK_STATUS_IN_STOCK)
|
814 |
-
return __('in stock', 'content-egg-tpl');
|
815 |
-
elseif ($item['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
816 |
-
return __('out of stock', 'content-egg-tpl');
|
817 |
-
else
|
818 |
-
return '';
|
819 |
-
}
|
820 |
-
|
821 |
-
public static function getPrivacyUrl()
|
822 |
-
{
|
823 |
-
if ($id = \get_option('wp_page_for_privacy_policy', ''))
|
824 |
-
return \get_permalink($id);
|
825 |
-
else
|
826 |
-
return '';
|
827 |
-
}
|
828 |
-
|
829 |
-
public static function getGroupsList(array $all_items, $sort_groups = array())
|
830 |
-
{
|
831 |
-
if (!isset($all_items[0]))
|
832 |
-
$all_items = TemplateHelper::sortAllByPrice($all_items);
|
833 |
-
|
834 |
-
$groups = array_unique(array_column($all_items, 'group'));
|
835 |
-
if ($sort_groups)
|
836 |
-
{
|
837 |
-
$res = array();
|
838 |
-
foreach ($sort_groups as $g)
|
839 |
-
{
|
840 |
-
if (in_array($g, $groups))
|
841 |
-
$res[] = $g;
|
842 |
-
}
|
843 |
-
return $res;
|
844 |
-
} else
|
845 |
-
{
|
846 |
-
sort($groups);
|
847 |
-
return $groups;
|
848 |
-
}
|
849 |
-
}
|
850 |
-
|
851 |
-
public static function filterByGroup(array $data, $group)
|
852 |
-
{
|
853 |
-
$res = array();
|
854 |
-
foreach ($data as $plugin_id => $d)
|
855 |
-
{
|
856 |
-
$r = array_filter($d, function ($data) use ($group) {
|
857 |
-
return isset($data) && $data['group'] == $group;
|
858 |
-
});
|
859 |
-
if ($r)
|
860 |
-
$res[$plugin_id] = $r;
|
861 |
-
}
|
862 |
-
|
863 |
-
return $res;
|
864 |
-
}
|
865 |
-
|
866 |
-
public static function generateGlobalId($prefix)
|
867 |
-
{
|
868 |
-
return $prefix . self::$global_id++;
|
869 |
-
}
|
870 |
-
|
871 |
-
public static function isModuleDataExist($items, $module_id)
|
872 |
-
{
|
873 |
-
foreach ($items as $item)
|
874 |
-
{
|
875 |
-
if (isset($item['module_id']) && $item['module_id'] == $module_id)
|
876 |
-
return true;
|
877 |
-
else
|
878 |
-
return false;
|
879 |
-
}
|
880 |
-
}
|
881 |
-
|
882 |
-
public static function isCashbackTrakerActive()
|
883 |
-
{
|
884 |
-
if (class_exists('\CashbackTracker\application\Plugin'))
|
885 |
-
return true;
|
886 |
-
else
|
887 |
-
return false;
|
888 |
-
}
|
889 |
-
|
890 |
-
public static function getCashbackStr(array $product)
|
891 |
-
{
|
892 |
-
if (GeneralConfig::getInstance()->option('cashback_integration') != 'enabled')
|
893 |
-
return '';
|
894 |
-
|
895 |
-
if (!self::isCashbackTrakerActive())
|
896 |
-
return '';
|
897 |
-
|
898 |
-
return \CashbackTracker\application\components\DeeplinkGenerator::getCashbackStrByUrl($product['url']);
|
899 |
-
}
|
900 |
-
|
901 |
-
public static function hideParamPrepare($hide)
|
902 |
-
{
|
903 |
-
if (!$hide)
|
904 |
-
return array();
|
905 |
-
|
906 |
-
$allowed_hide = array('price', 'priceOld', 'domain', 'rating', 'title', 'stock_status', 'img', 'merchant');
|
907 |
-
$hide = TextHelper::getArrayFromCommaList($hide);
|
908 |
-
if (in_array('price', $hide) && !in_array('priceOld', $hide))
|
909 |
-
$hide[] = 'priceOld';
|
910 |
-
|
911 |
-
return array_intersect($hide, $allowed_hide);
|
912 |
-
}
|
913 |
-
|
914 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace ContentEgg\application\helpers;
|
4 |
+
|
5 |
+
defined('\ABSPATH') || exit;
|
6 |
+
|
7 |
+
use ContentEgg\application\components\ContentManager;
|
8 |
+
use ContentEgg\application\models\PriceHistoryModel;
|
9 |
+
use ContentEgg\application\helpers\ArrayHelper;
|
10 |
+
use ContentEgg\application\admin\GeneralConfig;
|
11 |
+
use ContentEgg\application\components\ModuleManager;
|
12 |
+
use ContentEgg\application\components\ContentProduct;
|
13 |
+
use ContentEgg\application\helpers\TextHelper;
|
14 |
+
use ContentEgg\application\libs\amazon\AmazonLocales;
|
15 |
+
use ContentEgg\application\modules\Amazon\AmazonConfig;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* TemplateHelper class file
|
19 |
+
*
|
20 |
+
* @author keywordrush.com <support@keywordrush.com>
|
21 |
+
* @link https://www.keywordrush.com
|
22 |
+
* @copyright Copyright © 2020 keywordrush.com
|
23 |
+
*
|
24 |
+
*/
|
25 |
+
class TemplateHelper {
|
26 |
+
|
27 |
+
const MERHANT_LOGO_DIR = 'ce-logos';
|
28 |
+
|
29 |
+
static $global_id = 0;
|
30 |
+
static $logos = null;
|
31 |
+
|
32 |
+
public static function formatPriceCurrency($price, $currencyCode, $before_symbol = '', $after_symbol = '')
|
33 |
+
{
|
34 |
+
$decimal_sep = __('number_format_decimal_point', 'content-egg-tpl');
|
35 |
+
$thousand_sep = __('number_format_thousands_sep', 'content-egg-tpl');
|
36 |
+
if ($decimal_sep == 'number_format_decimal_point')
|
37 |
+
$decimal_sep = null;
|
38 |
+
if ($thousand_sep == 'number_format_thousands_sep')
|
39 |
+
$thousand_sep = null;
|
40 |
+
|
41 |
+
return CurrencyHelper::getInstance()->currencyFormat($price, $currencyCode, $thousand_sep, $decimal_sep, $before_symbol, $after_symbol);
|
42 |
+
}
|
43 |
+
|
44 |
+
public static function currencyTyping($c)
|
45 |
+
{
|
46 |
+
return CurrencyHelper::getInstance()->getSymbol($c);
|
47 |
+
}
|
48 |
+
|
49 |
+
/*
|
50 |
+
* @deprecated
|
51 |
+
*/
|
52 |
+
|
53 |
+
public static function number_format_i18n($number, $decimals = 0, $currency = null)
|
54 |
+
{
|
55 |
+
$decimal_sep = __('number_format_decimal_point', 'content-egg-tpl');
|
56 |
+
$thousand_sep = __('number_format_thousands_sep', 'content-egg-tpl');
|
57 |
+
if ($decimal_sep == 'number_format_decimal_point')
|
58 |
+
$decimal_sep = null;
|
59 |
+
if ($thousand_sep == 'number_format_thousands_sep')
|
60 |
+
$thousand_sep = null;
|
61 |
+
return CurrencyHelper::getInstance()->numberFormat($number, $currency, $thousand_sep, $decimal_sep, $decimals);
|
62 |
+
}
|
63 |
+
|
64 |
+
/*
|
65 |
+
* @deprecated
|
66 |
+
*/
|
67 |
+
|
68 |
+
public static function price_format_i18n($number, $currency = null)
|
69 |
+
{
|
70 |
+
return self::number_format_i18n($number, $decimal = null, $currency);
|
71 |
+
}
|
72 |
+
|
73 |
+
public static function truncate($string, $length = 80, $etc = '...', $charset = 'UTF-8', $break_words = false, $middle = false)
|
74 |
+
{
|
75 |
+
if ($length == 0)
|
76 |
+
return '';
|
77 |
+
|
78 |
+
if (mb_strlen($string, 'UTF-8') > $length)
|
79 |
+
{
|
80 |
+
$length -= min($length, mb_strlen($etc, 'UTF-8'));
|
81 |
+
if (!$break_words && !$middle)
|
82 |
+
{
|
83 |
+
$string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1, $charset));
|
84 |
+
}
|
85 |
+
if (!$middle)
|
86 |
+
{
|
87 |
+
return mb_substr($string, 0, $length, $charset) . $etc;
|
88 |
+
} else
|
89 |
+
{
|
90 |
+
return mb_substr($string, 0, $length / 2, $charset) . $etc . mb_substr($string, -$length / 2, $charset);
|
91 |
+
}
|
92 |
+
} else
|
93 |
+
{
|
94 |
+
return $string;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
static public function getTimeLeft($end_time_gmt, $return_array = false)
|
99 |
+
{
|
100 |
+
$current_time = strtotime(gmdate("M d Y H:i:s"));
|
101 |
+
$timeleft = strtotime($end_time_gmt) - $current_time;
|
102 |
+
if ($timeleft < 0)
|
103 |
+
return '';
|
104 |
+
|
105 |
+
$days_left = floor($timeleft / 86400);
|
106 |
+
$hours_left = floor(($timeleft - $days_left * 86400) / 3600);
|
107 |
+
$min_left = floor(($timeleft - $days_left * 86400 - $hours_left * 3600) / 60);
|
108 |
+
if ($return_array)
|
109 |
+
{
|
110 |
+
return array(
|
111 |
+
'days' => $days_left,
|
112 |
+
'hours' => $hours_left,
|
113 |
+
'min' => $min_left,
|
114 |
+
);
|
115 |
+
}
|
116 |
+
|
117 |
+
if ($days_left)
|
118 |
+
return $days_left . __('d', 'content-egg-tpl') . ' ';
|
119 |
+
elseif ($hours_left)
|
120 |
+
return $hours_left . __('h', 'content-egg-tpl') . ' ';
|
121 |
+
elseif ($min_left)
|
122 |
+
return $min_left . __('m', 'content-egg-tpl');
|
123 |
+
else
|
124 |
+
return '<1' . __('m', 'content-egg-tpl');
|
125 |
+
}
|
126 |
+
|
127 |
+
public static function filterData($data, $field_name, $field_values, $extra = false, $inverse = false)
|
128 |
+
{
|
129 |
+
$results = array();
|
130 |
+
foreach ($data as $key => $d)
|
131 |
+
{
|
132 |
+
if ($extra)
|
133 |
+
{
|
134 |
+
if (!isset($d['extra']) || !isset($d['extra'][$field_name]))
|
135 |
+
continue;
|
136 |
+
$value = $d['extra'][$field_name];
|
137 |
+
} else
|
138 |
+
{
|
139 |
+
if (!isset($d[$field_name]))
|
140 |
+
continue;
|
141 |
+
$value = $d[$field_name];
|
142 |
+
}
|
143 |
+
if (!is_array($field_values))
|
144 |
+
$field_values = array($field_values);
|
145 |
+
|
146 |
+
if (!$inverse && in_array($value, $field_values))
|
147 |
+
$results[$key] = $d;
|
148 |
+
elseif ($inverse && !in_array($value, $field_values))
|
149 |
+
$results[$key] = $d;
|
150 |
+
}
|
151 |
+
return $results;
|
152 |
+
}
|
153 |
+
|
154 |
+
public static function formatDatetime($datetime, $type = 'mysql', $separator = ' ')
|
155 |
+
{
|
156 |
+
if ('mysql' == $type)
|
157 |
+
{
|
158 |
+
return mysql2date(get_option('date_format'), $datetime) . $separator . mysql2date(get_option('time_format'), $datetime);
|
159 |
+
} else
|
160 |
+
{
|
161 |
+
return date_i18n(get_option('date_format'), $datetime) . $separator . date_i18n(get_option('time_format'), $datetime);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
|
165 |
+
public static function formatDate($timestamp, $gmt = false)
|
166 |
+
{
|
167 |
+
return date_i18n(get_option('date_format'), $timestamp, $gmt);
|
168 |
+
}
|
169 |
+
|
170 |
+
public static function splitAttributeName($attribute)
|
171 |
+
{
|
172 |
+
return trim(preg_replace('/([A-Z])([a-z])/', ' $1$2', $attribute));
|
173 |
+
}
|
174 |
+
|
175 |
+
public static function getAmazonLink($itemLinks, $description)
|
176 |
+
{
|
177 |
+
// api 5 fix
|
178 |
+
if (!is_array($itemLinks) || !$itemLinks)
|
179 |
+
return '';
|
180 |
+
|
181 |
+
foreach ($itemLinks as $link)
|
182 |
+
{
|
183 |
+
if ($link['Description'] == $description)
|
184 |
+
return $link['URL'];
|
185 |
+
}
|
186 |
+
return false;
|
187 |
+
}
|
188 |
+
|
189 |
+
public static function getLastUpdate($module_id, $post_id = null)
|
190 |
+
{
|
191 |
+
if (!$post_id)
|
192 |
+
{
|
193 |
+
global $post;
|
194 |
+
$post_id = $post->ID;
|
195 |
+
}
|
196 |
+
$res = \get_post_meta($post_id, ContentManager::META_PREFIX_LAST_ITEMS_UPDATE . $module_id, true);
|
197 |
+
if (!$res)
|
198 |
+
$res = time();
|
199 |
+
return $res;
|
200 |
+
}
|
201 |
+
|
202 |
+
public static function dateFormatFromGmt($timestamp, $time = true)
|
203 |
+
{
|
204 |
+
$format = \get_option('date_format');
|
205 |
+
if ($time)
|
206 |
+
$format .= ' ' . \get_option('time_format');
|
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 |
+
return \date_i18n($format, $timestamp);
|
211 |
+
}
|
212 |
+
|
213 |
+
public static function getLastUpdateFormattedAmazon(array $data, $time = true)
|
214 |
+
{
|
215 |
+
if (!isset($data['Amazon']))
|
216 |
+
return false;
|
217 |
+
|
218 |
+
$item = current($data['Amazon']);
|
219 |
+
if (empty($item['last_update']))
|
220 |
+
return false;
|
221 |
+
|
222 |
+
$last_update = $item['last_update'];
|
223 |
+
|
224 |
+
return self::dateFormatFromGmt($last_update, $time);
|
225 |
+
}
|
226 |
+
|
227 |
+
public static function getLastUpdateFormatted($module_id, $post_id = null, $time = true)
|
228 |
+
{
|
229 |
+
if (!$post_id || $post_id === true) // $post_id === true - fix func params...
|
230 |
+
{
|
231 |
+
global $post;
|
232 |
+
$post_id = $post->ID;
|
233 |
+
}
|
234 |
+
|
235 |
+
$last_update = self::getLastUpdate($module_id, $post_id);
|
236 |
+
return self::dateFormatFromGmt($last_update, $time);
|
237 |
+
}
|
238 |
+
|
239 |
+
public static function filterDataByType($data, $type)
|
240 |
+
{
|
241 |
+
$results = array();
|
242 |
+
foreach ($data as $module_id => $items)
|
243 |
+
{
|
244 |
+
$module = \ContentEgg\application\components\ModuleManager::getInstance()->factory($module_id);
|
245 |
+
if ($module->getParserType() == $type)
|
246 |
+
$results[$module_id] = $items;
|
247 |
+
}
|
248 |
+
return $results;
|
249 |
+
}
|
250 |
+
|
251 |
+
public static function filterDataByModule($data, $module_ids)
|
252 |
+
{
|
253 |
+
if (!is_array($module_ids))
|
254 |
+
$module_ids = array($module_ids);
|
255 |
+
$results = array();
|
256 |
+
|
257 |
+
foreach ($data as $module_id => $items)
|
258 |
+
{
|
259 |
+
if (in_array($module_id, $module_ids))
|
260 |
+
$results[$module_id] = $items;
|
261 |
+
}
|
262 |
+
return $results;
|
263 |
+
}
|
264 |
+
|
265 |
+
public static function priceHistoryPrices($unique_id, $plugin_id, $limit = 5)
|
266 |
+
{
|
267 |
+
$prices = PriceHistoryModel::model()->getLastPrices($unique_id, $plugin_id, $limit);
|
268 |
+
$results = array();
|
269 |
+
foreach ($prices as $price)
|
270 |
+
{
|
271 |
+
$results[] = array(
|
272 |
+
'date' => strtotime($price['create_date']),
|
273 |
+
'price' => $price['price'],
|
274 |
+
);
|
275 |
+
}
|
276 |
+
return $results;
|
277 |
+
}
|
278 |
+
|
279 |
+
public static function priceHistoryMax($unique_id, $module_id)
|
280 |
+
{
|
281 |
+
if (!$price = PriceHistoryModel::model()->getMaxPrice($unique_id, $module_id))
|
282 |
+
return null;
|
283 |
+
return array('price' => $price['price'], 'date' => strtotime($price['create_date']));
|
284 |
+
}
|
285 |
+
|
286 |
+
public static function priceHistoryMin($unique_id, $module_id)
|
287 |
+
{
|
288 |
+
if (!$price = PriceHistoryModel::model()->getMinPrice($unique_id, $module_id))
|
289 |
+
return null;
|
290 |
+
return array('price' => $price['price'], 'date' => strtotime($price['create_date']));
|
291 |
+
}
|
292 |
+
|
293 |
+
public static function priceHistorySinceDate($unique_id, $module_id)
|
294 |
+
{
|
295 |
+
if (!$date = PriceHistoryModel::model()->getFirstDateValue($unique_id, $module_id))
|
296 |
+
return null;
|
297 |
+
return strtotime($date);
|
298 |
+
}
|
299 |
+
|
300 |
+
public static function priceChangesProducts($limit = 5)
|
301 |
+
{
|
302 |
+
$params = array(
|
303 |
+
//'select' => 'DISTINCT unique_id',
|
304 |
+
'order' => 'create_date DESC',
|
305 |
+
'where' => 'post_id IS NOT NULL',
|
306 |
+
'group' => 'unique_id',
|
307 |
+
'limit' => $limit,
|
308 |
+
);
|
309 |
+
$prices = PriceHistoryModel::model()->findAll($params);
|
310 |
+
$products = array();
|
311 |
+
// find products
|
312 |
+
foreach ($prices as $price)
|
313 |
+
{
|
314 |
+
if ($prod = ContentManager::getProductbyUniqueId($price['unique_id'], $price['module_id'], $price['post_id']))
|
315 |
+
$products[] = $prod;
|
316 |
+
}
|
317 |
+
return $products;
|
318 |
+
}
|
319 |
+
|
320 |
+
public static function priceHistoryMorrisChart($unique_id, $module_id, $days = 180, array $options = array(), $htmlOptions = array())
|
321 |
+
{
|
322 |
+
$where = PriceHistoryModel::model()->prepareWhere(
|
323 |
+
(array('unique_id = %s AND module_id = %s', array($unique_id, $module_id))), false);
|
324 |
+
$params = array(
|
325 |
+
'select' => 'date(create_date) as date, price as price',
|
326 |
+
'where' => $where . ' AND TIMESTAMPDIFF( DAY, create_date, "' . \current_time('mysql') . '") <= ' . $days,
|
327 |
+
//'group' => 'date',
|
328 |
+
'order' => 'date ASC'
|
329 |
+
);
|
330 |
+
$results = PriceHistoryModel::model()->findAll($params);
|
331 |
+
$results = array_reverse($results);
|
332 |
+
$prices = array();
|
333 |
+
/**
|
334 |
+
* php fix for selecting non-aggregate columns
|
335 |
+
* @see: https://stackoverflow.com/questions/1066453/mysql-group-by-and-order-by
|
336 |
+
*/
|
337 |
+
foreach ($results as $key => $r)
|
338 |
+
{
|
339 |
+
if ($key > 0 && $results[$key - 1]['date'] == $r['date'])
|
340 |
+
continue;
|
341 |
+
$price = array(
|
342 |
+
'date' => $r['date'],
|
343 |
+
'price' => $r['price'],
|
344 |
+
);
|
345 |
+
$prices[] = $price;
|
346 |
+
}
|
347 |
+
|
348 |
+
//add last known price to the chart
|
349 |
+
/*
|
350 |
+
$price = array(
|
351 |
+
'date' => $r['date'],
|
352 |
+
'price' => $r['price'],
|
353 |
+
);
|
354 |
+
$prices[] = $price;
|
355 |
+
*
|
356 |
+
*/
|
357 |
+
$data = array(
|
358 |
+
'chartType' => 'Area',
|
359 |
+
'data' => $prices,
|
360 |
+
'xkey' => 'date',
|
361 |
+
'ykeys' => array('price'),
|
362 |
+
'labels' => array(__('Price', 'content-egg-tpl')),
|
363 |
+
);
|
364 |
+
$options = array_merge($data, $options);
|
365 |
+
|
366 |
+
$id = $module_id . '-' . $unique_id . '-chart' . rand(0, 10000);
|
367 |
+
self::viewMorrisChart($id, $options, $htmlOptions);
|
368 |
+
}
|
369 |
+
|
370 |
+
public static function viewMorrisChart($id, array $options, $htmlOptions = array('style' => 'height: 250px;'))
|
371 |
+
{
|
372 |
+
// morris.js
|
373 |
+
\wp_enqueue_style('morrisjs');
|
374 |
+
\wp_enqueue_script('morrisjs');
|
375 |
+
|
376 |
+
if (!empty($options['chartType']) && in_array($options['chartType'], array('Line', 'Area', 'Donut', 'Bar')))
|
377 |
+
{
|
378 |
+
$chartType = $options['chartType'];
|
379 |
+
unset($options['chartType']);
|
380 |
+
} else
|
381 |
+
$chartType = 'Line';
|
382 |
+
$options['element'] = $id;
|
383 |
+
|
384 |
+
$html_attr = '';
|
385 |
+
foreach ($htmlOptions as $name => $value)
|
386 |
+
{
|
387 |
+
$html_attr .= ' ' . esc_attr($name) . '="' . esc_attr($value) . '"';
|
388 |
+
}
|
389 |
+
|
390 |
+
echo '<div style="direction: ltr;" id="' . esc_attr($id) . '"' . $html_attr . '></div>
|
391 |
+
<script>
|
392 |
+
jQuery(document).ready(function($) {
|
393 |
+
new Morris.' . $chartType . '(' . json_encode($options) . ');
|
394 |
+
});
|
395 |
+
</script>';
|
396 |
+
}
|
397 |
+
|
398 |
+
public static function isPriceAlertAllowed($unique_id = null, $module_id = null)
|
399 |
+
{
|
400 |
+
return \ContentEgg\application\PriceAlert::isPriceAlertAllowed($unique_id, $module_id);
|
401 |
+
}
|
402 |
+
|
403 |
+
public static function getCurrencyPos($currency)
|
404 |
+
{
|
405 |
+
return CurrencyHelper::getInstance()->getCurrencyPos($currency);
|
406 |
+
}
|
407 |
+
|
408 |
+
public static function getCurrencySymbol($currency)
|
409 |
+
{
|
410 |
+
return CurrencyHelper::getInstance()->getSymbol($currency);
|
411 |
+
}
|
412 |
+
|
413 |
+
public static function getCurrencyName($currency)
|
414 |
+
{
|
415 |
+
return CurrencyHelper::getInstance()->getName($currency);
|
416 |
+
}
|
417 |
+
|
418 |
+
public static function getCustomLogo($domain)
|
419 |
+
{
|
420 |
+
if (self::$logos === null)
|
421 |
+
{
|
422 |
+
$logos = GeneralConfig::getInstance()->option('logos');
|
423 |
+
if (!$logos)
|
424 |
+
$logos = array();
|
425 |
+
foreach ($logos as $logo)
|
426 |
+
{
|
427 |
+
self::$logos[$logo['name']] = $logo['value'];
|
428 |
+
}
|
429 |
+
}
|
430 |
+
|
431 |
+
if (isset(self::$logos[$domain]))
|
432 |
+
return self::$logos[$domain];
|
433 |
+
else
|
434 |
+
return false;
|
435 |
+
}
|
436 |
+
|
437 |
+
private static function getMerchantImageUrl(array $item, $prefix = '', $remote_url = null, $blank_on_error = false)
|
438 |
+
{
|
439 |
+
$default_ext = 'png'; // ???
|
440 |
+
|
441 |
+
if (!strpos($remote_url, 'www.google.com/s2/favicons?domain'))
|
442 |
+
{
|
443 |
+
// custom logos for Offer module
|
444 |
+
if (isset($item['module_id']) && $item['module_id'] == 'Offer' && !empty($item['logo']))
|
445 |
+
return $item['logo'];
|
446 |
+
|
447 |
+
// custom logos
|
448 |
+
if (isset($item['domain']) && $custom_logo = self::getCustomLogo($item['domain']))
|
449 |
+
return $custom_logo;
|
450 |
+
}
|
451 |
+
|
452 |
+
if (!empty($item['domain']))
|
453 |
+
$logo_file_name = $item['domain'];
|
454 |
+
elseif (!empty($item['logo']))
|
455 |
+
$logo_file_name = md5($item['logo']);
|
456 |
+
else
|
457 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
458 |
+
|
459 |
+
$logo_file_name = str_replace('.', '-', $logo_file_name);
|
460 |
+
$logo_file_name .= '.' . $default_ext;
|
461 |
+
$logo_file_name = $prefix . $logo_file_name;
|
462 |
+
|
463 |
+
// check in distrib
|
464 |
+
if (file_exists(\ContentEgg\PLUGIN_PATH . 'res/logos/' . $logo_file_name))
|
465 |
+
return \ContentEgg\PLUGIN_RES . '/logos/' . $logo_file_name;
|
466 |
+
|
467 |
+
$uploads = \wp_upload_dir();
|
468 |
+
if (!$logo_dir = self::getMerchantLogoDir())
|
469 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
470 |
+
$logo_file = \trailingslashit($logo_dir) . $logo_file_name;
|
471 |
+
$logo_url = $uploads['baseurl'] . '/' . self::MERHANT_LOGO_DIR . '/' . $logo_file_name;
|
472 |
+
|
473 |
+
// logo exists
|
474 |
+
if (file_exists($logo_file))
|
475 |
+
return $logo_url;
|
476 |
+
|
477 |
+
// download
|
478 |
+
if (!$remote_url)
|
479 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
480 |
+
if ($logo_file_name = ImageHelper::downloadImg($remote_url, $logo_dir, $logo_file_name, '', true))
|
481 |
+
return $uploads['baseurl'] . '/' . self::MERHANT_LOGO_DIR . '/' . $logo_file_name;
|
482 |
+
else
|
483 |
+
{
|
484 |
+
// save blank to prevent new requests
|
485 |
+
copy(\ContentEgg\PLUGIN_PATH . 'res/img/blank.gif', $logo_file);
|
486 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
public static function getMerhantLogoUrl(array $item, $blank_on_error = false)
|
491 |
+
{
|
492 |
+
$prefix = '';
|
493 |
+
if (!empty($item['module_id']))
|
494 |
+
{
|
495 |
+
$parser = ModuleManager::getInstance()->parserFactory($item['module_id']);
|
496 |
+
if ($parser->getConfigInstance()->option_exists('show_large_logos') && !filter_var($parser->config('show_large_logos'), FILTER_VALIDATE_BOOLEAN))
|
497 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
498 |
+
}
|
499 |
+
|
500 |
+
if (!empty($item['logo']))
|
501 |
+
$remote_url = $item['logo'];
|
502 |
+
elseif (!empty($item['domain']))
|
503 |
+
{
|
504 |
+
$item['domain'] = preg_replace('/^https:\/\//', '', $item['domain']);
|
505 |
+
$remote_url = 'https://logo.clearbit.com/' . urlencode($item['domain']) . '?size=128';
|
506 |
+
} else
|
507 |
+
$remote_url = '';
|
508 |
+
return self::getMerchantImageUrl($item, $prefix, $remote_url, $blank_on_error);
|
509 |
+
}
|
510 |
+
|
511 |
+
public static function getMerhantIconUrl(array $item, $blank_on_error = false)
|
512 |
+
{
|
513 |
+
$prefix = 'icon_';
|
514 |
+
if (!empty($item['module_id']))
|
515 |
+
{
|
516 |
+
$parser = ModuleManager::getInstance()->parserFactory($item['module_id']);
|
517 |
+
if ($parser->getConfigInstance()->option_exists('show_small_logos') && !filter_var($parser->config('show_small_logos'), FILTER_VALIDATE_BOOLEAN))
|
518 |
+
return $blank_on_error ? self::getBlankImg() : false;
|
519 |
+
}
|
520 |
+
|
521 |
+
$item['domain'] = preg_replace('/^https:\/\//', '', $item['domain']);
|
522 |
+
$remote_url = 'https://www.google.com/s2/favicons?domain=' . urlencode($item['domain']);
|
523 |
+
return self::getMerchantImageUrl($item, $prefix, $remote_url, $blank_on_error);
|
524 |
+
}
|
525 |
+
|
526 |
+
public static function getMerhantName(array $item, $print = false)
|
527 |
+
{
|
528 |
+
if (!empty($item['domain']))
|
529 |
+
{
|
530 |
+
$name = ucfirst($item['domain']);
|
531 |
+
|
532 |
+
if ($name == 'Aliexpress.com')
|
533 |
+
$name = 'Aliexpress';
|
534 |
+
elseif ($name == 'Flipkart.com')
|
535 |
+
$name = 'Flipkart';
|
536 |
+
elseif ($name == 'Ebay.com')
|
537 |
+
$name = 'eBay.com';
|
538 |
+
elseif (strstr($name, 'Ebay.'))
|
539 |
+
$name = str_replace('Ebay.', 'eBay.', $name);
|
540 |
+
} elseif (!empty($item['merchant']))
|
541 |
+
$name = $item['merchant'];
|
542 |
+
else
|
543 |
+
$name = '';
|
544 |
+
|
545 |
+
if ($print)
|
546 |
+
echo \esc_html($name);
|
547 |
+
else
|
548 |
+
return $name;
|
549 |
+
}
|
550 |
+
|
551 |
+
public static function getMerchantLogoDir()
|
552 |
+
{
|
553 |
+
$uploads = \wp_upload_dir();
|
554 |
+
$logo_dir = \trailingslashit($uploads['basedir']) . self::MERHANT_LOGO_DIR;
|
555 |
+
if (is_dir($logo_dir))
|
556 |
+
return $logo_dir;
|
557 |
+
|
558 |
+
// create
|
559 |
+
if (\wp_mkdir_p($logo_dir))
|
560 |
+
return $logo_dir;
|
561 |
+
else
|
562 |
+
return false;
|
563 |
+
}
|
564 |
+
|
565 |
+
public static function getBlankImg()
|
566 |
+
{
|
567 |
+
return \ContentEgg\PLUGIN_RES . '/img/blank.gif';
|
568 |
+
}
|
569 |
+
|
570 |
+
public static function mergeData(array $data)
|
571 |
+
{
|
572 |
+
foreach ($data as $module_id => $items)
|
573 |
+
{
|
574 |
+
foreach ($items as $item_ar)
|
575 |
+
{
|
576 |
+
$item_ar['module_id'] = $module_id;
|
577 |
+
$all_items[] = $item_ar;
|
578 |
+
}
|
579 |
+
}
|
580 |
+
return $all_items;
|
581 |
+
}
|
582 |
+
|
583 |
+
public static function getMaxPriceItem(array $data)
|
584 |
+
{
|
585 |
+
return $data[ArrayHelper::getMaxKeyAssoc($data, 'price', true)];
|
586 |
+
}
|
587 |
+
|
588 |
+
public static function getMinPriceItem(array $data)
|
589 |
+
{
|
590 |
+
return $data[ArrayHelper::getMinKeyAssoc($data, 'price', true)];
|
591 |
+
}
|
592 |
+
|
593 |
+
public static function getCommonCurrencyCode($data)
|
594 |
+
{
|
595 |
+
$first = reset($data);
|
596 |
+
$currency = $first['currencyCode'];
|
597 |
+
foreach ($data as $d)
|
598 |
+
{
|
599 |
+
if (!empty($d['currencyCode']) && $d['currencyCode'] != $currency)
|
600 |
+
return false;
|
601 |
+
}
|
602 |
+
return $currency;
|
603 |
+
}
|
604 |
+
|
605 |
+
public static function getShopsList($data)
|
606 |
+
{
|
607 |
+
$list = array();
|
608 |
+
foreach ($data as $d)
|
609 |
+
{
|
610 |
+
if (!isset($list[$d['domain']]))
|
611 |
+
{
|
612 |
+
if (!empty($d['merchant']))
|
613 |
+
$list[$d['domain']] = $d['merchant'];
|
614 |
+
else
|
615 |
+
$list[$d['domain']] = self::getNameFromDomain($d['domain']);
|
616 |
+
}
|
617 |
+
}
|
618 |
+
return $list;
|
619 |
+
}
|
620 |
+
|
621 |
+
public static function getNameFromDomain($domain)
|
622 |
+
{
|
623 |
+
$parts = explode('.', $domain);
|
624 |
+
$merchant = $parts[0];
|
625 |
+
if ($merchant == 'ebay')
|
626 |
+
return 'eBay';
|
627 |
+
|
628 |
+
return ucfirst($merchant);
|
629 |
+
}
|
630 |
+
|
631 |
+
public static function sortByPrice(array $data, $order = 'asc')
|
632 |
+
{
|
633 |
+
if (!$order)
|
634 |
+
$order = 'asc';
|
635 |
+
if (!in_array($order, array('asc', 'desc')))
|
636 |
+
$order = 'asc';
|
637 |
+
|
638 |
+
// convert all prices to one currency
|
639 |
+
$currency_codes = array();
|
640 |
+
foreach ($data as $d)
|
641 |
+
{
|
642 |
+
if (empty($d['currencyCode']))
|
643 |
+
continue;
|
644 |
+
|
645 |
+
if (!isset($currency_codes[$d['currencyCode']]))
|
646 |
+
$currency_codes[$d['currencyCode']] = 1;
|
647 |
+
else
|
648 |
+
$currency_codes[$d['currencyCode']]++;
|
649 |
+
}
|
650 |
+
arsort($currency_codes);
|
651 |
+
$base_currency = key($currency_codes);
|
652 |
+
foreach ($data as $key => $d)
|
653 |
+
{
|
654 |
+
if (isset($d['stock_status']) && $d['stock_status'] == ContentProduct::STOCK_STATUS_OUT_OF_STOCK)
|
655 |
+
$data[$key]['converted_price'] = 0;
|
656 |
+
elseif (!empty($d['currencyCode']) && $d['currencyCode'] != $base_currency)
|
657 |
+
{
|
658 |
+
$rate = CurrencyHelper::getCurrencyRate($d['currencyCode'], $base_currency);
|
659 |
+
if (!$rate)
|
660 |
+
$rate = 1;
|
661 |
+
$data[$key]['converted_price'] = (float) $d['price'] * $rate;
|
662 |
+
} else
|
663 |
+
$data[$key]['converted_price'] = (float) $d['price'];
|
664 |
+
}
|
665 |
+
|
666 |
+
// modules priority
|
667 |
+
$modules_priority = array();
|
668 |
+
foreach ($data as $d)
|
669 |
+
{
|
670 |
+
$module_id = $d['module_id'];
|
671 |
+
|
672 |
+
if (isset($modules_priority[$module_id]))
|
673 |
+
continue;
|
674 |
+
if (!ModuleManager::getInstance()->moduleExists($module_id))
|
675 |
+
continue;
|
676 |
+
|
677 |
+
$module = ModuleManager::getInstance()->factory($module_id);
|
678 |
+
$modules_priority[$module_id] = (int) $module->config('priority');
|
679 |
+
}
|
680 |
+
|
681 |
+
// sort by price and priority
|
682 |
+
if ($order == 'asc')
|
683 |
+
{
|
684 |
+
usort($data, function($a, $b) use($modules_priority) {
|
685 |
+
if (!$a['price'] && !$b['price'])
|
686 |
+
return $modules_priority[$a['module_id']] - $modules_priority[$b['module_id']];
|
687 |
+
|
688 |
+
if (!$a['converted_price'])
|
689 |
+
return 1;
|
690 |
+
if (!$b['converted_price'])
|
691 |
+
return -1;
|
692 |
+
|
693 |
+
if ($a['converted_price'] == $b['converted_price'])
|
694 |
+
return $modules_priority[$a['module_id']] - $modules_priority[$b['module_id']];
|
695 |
+
|
696 |
+
return ($a['converted_price'] < $b['converted_price']) ? -1 : 1;
|
697 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|