PluginProbe
Content Egg – Affiliate Product Importer & Price Comparison / 11.2.0
Content Egg – Affiliate Product Importer & Price Comparison v11.2.0
11.8.1 11.8.0 11.7.0 11.6.0 11.5.0 11.4.0 11.3.0 11.2.0 11.1.0 trunk 1.6.0 1.6.1 1.7.1 1.8.0 1.9.0 10.0.0 10.1.0 11.0.0 2.0.1 2.1.0 2.2.0 2.3.0 2.4.0 2.4.2 2.5.1 All 65 releases
content-egg / application / BlockShortcode.php

BlockShortcode.php in Content Egg – Affiliate Product Importer & Price Comparison 11.2.0, at application/BlockShortcode.php

144 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\components\ShortcodeAtts;
10
11 use function ContentEgg\prn;
12 use function ContentEgg\prnx;;
13
14 /**
15 * BlockShortcode class file
16 *
17 * @author keywordrush.com <support@keywordrush.com>
18 * @link https://www.keywordrush.com
19 * @copyright Copyright &copy; 2026 keywordrush.com
20 */
21 class BlockShortcode extends EggShortcode
22 {
23 const shortcode = 'content-egg-block';
24
25 private static $instance = null;
26
27 public static function getInstance()
28 {
29 if (self::$instance == null)
30 self::$instance = new self;
31 return self::$instance;
32 }
33
34 private function __construct()
35 {
36 \add_shortcode(self::shortcode, array($this, 'viewDataShortcode'));
37 }
38
39 public function viewDataShortcode($atts, $content = '')
40 {
41 return $this->viewData($atts, $content);
42 }
43
44 protected function renderAsyncPlaceholder($post_id, array $a, $content = '')
45 {
46 $html = $this->buildAsyncPlaceholderHtml(
47 'cegg-block-',
48 'cegg-block',
49 'block',
50 $post_id,
51 $a,
52 $content
53 );
54
55 return $this->getAsyncInlineCssOnce() . $html;
56 }
57
58 public function viewData($atts, $content = '', $only_return_data = false)
59 {
60 $a = ShortcodeAtts::prepare($atts);
61
62 if (empty($a['post_id']))
63 {
64 global $post;
65 if (empty($post))
66 return '';
67
68 $post_id = $post->ID;
69 }
70 else
71 $post_id = $a['post_id'];
72
73 if (empty($a['template']))
74 return '';
75
76 if ($a['template'] != 'block_greenshift')
77 {
78 $tpl_manager = BlockTemplateManager::getInstance();
79
80 if (!$tpl_manager->isTemplateExists($a['template']))
81 return '';
82
83 $template_file = $tpl_manager->getViewPath($a['template']);
84 if (!$template_file)
85 return '';
86
87 // Get supported modules for this tpl
88 $headers = \get_file_data($template_file, array(
89 'module_ids' => 'Modules',
90 'module_types' => 'Module Types',
91 'shortcoded' => 'Shortcoded'
92 ));
93
94 $supported_module_ids = array();
95
96 if ($headers && !empty($headers['module_ids']))
97 {
98 $supported_module_ids = explode(',', $headers['module_ids']);
99 $supported_module_ids = array_map('trim', $supported_module_ids);
100 }
101 elseif ($headers && !empty($headers['module_types']))
102 {
103 $module_types = explode(',', $headers['module_types']);
104 $module_types = array_map('trim', $module_types);
105 $supported_module_ids = ModuleManager::getInstance()->getParserModuleIdsByTypes($module_types, true);
106 }
107 elseif (!$headers || empty($headers['module_types']))
108 $module_types = 'PRODUCT';
109
110 if ($headers && !empty($headers['shortcoded']))
111 $a['shortcoded'] = filter_var($headers['shortcoded'], FILTER_VALIDATE_BOOLEAN);
112 }
113 else
114 {
115 $a['shortcoded'] = true;
116 $supported_module_ids = ModuleManager::getInstance()->getParserModuleIdsByTypes('PRODUCT', true);
117 }
118
119 if (!$supported_module_ids)
120 return '';
121
122 /**
123 * Async mode (frontend only)
124 * - Do NOT use for editor preview or internal data-only calls.
125 */
126 if (!$this->isEditorRenderRequest() && !$only_return_data && !empty($a['async']))
127 {
128 return $this->renderAsyncPlaceholder($post_id, $a, $content);
129 }
130
131 if ($a['modules'])
132 $module_ids = $a['modules'];
133 else
134 $module_ids = ModuleManager::getInstance()->getParserModulesIdList(true);
135
136 $module_ids = array_intersect($module_ids, $supported_module_ids);
137
138 if ($a['exclude_modules'])
139 $module_ids = array_diff($module_ids, $a['exclude_modules']);
140
141 return ModuleViewer::getInstance()->viewBlockData($module_ids, $post_id, $a, $content, $only_return_data);
142 }
143 }
144