PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.9.21
Shortcodes and extra features for Phlox theme v2.9.21
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxin-widget-shortcode-map.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 3 years ago class-auxels-archive-menu-links.php 3 years ago class-auxels-envato-elements.php 3 years ago class-auxels-import-parser.php 3 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 3 years ago class-auxels-wc-attribute-nav-menu.php 4 years ago class-auxin-admin-dashboard.php 3 years ago class-auxin-demo-importer.php 3 years ago class-auxin-dependency-sorting.php 3 years ago class-auxin-import.php 3 years ago class-auxin-install.php 3 years ago class-auxin-master-nav-menu-admin.php 3 years ago class-auxin-page-template.php 4 years ago class-auxin-permalink.php 3 years ago class-auxin-plugin-requirements.php 3 years ago class-auxin-post-type-base.php 3 years ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 3 years ago class-auxin-walker-nav-menu-back.php 3 years ago class-auxin-welcome-sections.php 3 years ago class-auxin-welcome.php 3 years ago class-auxin-whitelabel.php 3 years ago class-auxin-widget-indie.php 3 years ago class-auxin-widget-shortcode-map.php 3 years ago class-auxin-widget.php 3 years ago
class-auxin-widget-shortcode-map.php
328 lines
1 <?php
2 /**
3 * Adds Theme Widgets (elements), shortcodes and visual elements
4 *
5 *
6 * @package Auxin
7 * @license LICENSE.txt
8 * @author averta
9 * @link http://phlox.pro/
10 * @copyright (c) 2010-2022 averta
11 */
12
13 // no direct access allowed
14 if ( ! defined('ABSPATH') ) exit;
15
16
17
18
19 class Auxin_Widget_Shortcode_Map {
20
21 /**
22 * Instance of this class.
23 *
24 * @var object
25 */
26 protected static $instance = null;
27
28 /**
29 * The Master list of all shortcodes and widgets
30 *
31 * @var array
32 */
33 private $master_array = array();
34
35 /**
36 * The Master list of all shortcodes
37 *
38 * @var array
39 */
40 public $master_shortcode_array = array();
41
42
43
44 public function __construct(){
45 add_action('auxin_loaded', array( $this, 'auxin_framework_loaded' ) );
46 }
47
48
49
50 public function auxin_framework_loaded(){
51
52 add_action( 'vc_before_init', array( $this, 'vc_mapper' ) );
53 add_action( 'widgets_init' , array( $this, 'add_widgets' ) );
54
55 // map and add all shortcodes
56 $this->add_shortcodes();
57 }
58
59
60
61 /**
62 * Collects and stores elements info
63 */
64 public function get_master_array(){
65
66 if( empty( $this->master_array ) ){
67
68 $master_array = apply_filters( 'auxin_master_array_shortcodes', array() );
69
70 foreach ( $master_array as $element_id => $element_info ) {
71 // determines whether the widget should be generated or not
72 $element_info['is_widget'] = isset( $element_info['is_widget'] ) && $element_info['is_widget'] === false ? false : true;
73 // determines whether the shortcode should be added or not
74 $element_info['is_shortcode'] = isset( $element_info['is_shortcode'] ) && $element_info['is_shortcode'] === false ? false : true;
75 // determines whether the an element in vc should be generated or not
76 $element_info['is_vc'] = isset( $element_info['is_vc'] ) && $element_info['is_vc'] === false ? false : true;
77
78 // make sure icon is set
79 $element_info['icon'] = isset( $element_info['icon'] ) && ! empty( $element_info['icon'] ) ? $element_info['icon'] : 'dashicons dashicons-admin-generic';
80
81 // make sure key in master array is base name of elements, in this case we can find elements in this array faster
82 $this->master_array[ $element_info['base'] ] = $element_info;
83 }
84 }
85
86 return $this->master_array;
87 }
88
89 /**
90 * Register all allowed widgets
91 */
92 public function add_widgets() {
93
94 $master_array = $this->get_master_array();
95
96 foreach ( $master_array as $element_id => $element_info ) {
97
98 // Add a widget if it was allowed
99 if( $element_info['is_widget'] ) {
100 $widget_info = $this->generate_widget_array( $element_info );
101 global $wp_widget_factory;
102 $wp_widget_factory->widgets[ $element_info['base'] ] = new Auxin_Widget( $widget_info );
103 }
104
105 }
106 }
107
108
109 /**
110 * Adds all collected shortcodes
111 */
112 private function add_shortcodes() {
113
114 $shortcode_array_list = $this->get_master_shortcode_array();
115
116 foreach ( $shortcode_array_list as $shortcode_index => $shortcode_array ) {
117 add_shortcode( $shortcode_array['base'], $shortcode_array['auxin_output_callback'] );
118 }
119 }
120
121 protected function remove_empty_nodes_recuresively( $array ){
122 $cleared_array = array();
123
124 foreach( $array as $key => $node ) {
125 if( is_array( $node ) ){
126 $cleared_array[ $key ] = $this->remove_empty_nodes_recuresively( $node );
127 } elseif ( ! empty( $node ) || $node === false ){
128 $cleared_array[ $key ] = $array[ $key ];
129 }
130 }
131
132 return $cleared_array;
133 }
134
135
136 /**
137 * Get list of allowed shortcodes
138 */
139 public function get_master_shortcode_array(){
140 $this->get_master_array();
141
142 if( empty( $this->master_shortcode_array ) ){
143 foreach ( $this->master_array as $element_id => $element_info ) {
144 // Collect the shortcode if it was allowed
145 if( $element_info['is_shortcode'] ){
146 $this->master_shortcode_array[] = $this->generate_shortcode_array( $element_info );
147 }
148 }
149 }
150
151 return $this->master_shortcode_array;
152 }
153
154
155 /**
156 * Sanitize and proper
157 *
158 * @param [type] $element_info [description]
159 * @return [type] [description]
160 */
161 protected function sanitize_element_info( $element_info ){
162
163 }
164
165
166 /**
167 * Generates shortcode info
168 */
169 protected function generate_shortcode_array( $element_info ){
170
171 $shortcode_array['base'] = $element_info['base'];
172 $shortcode_array['is_shortcode'] = $element_info['is_shortcode'];
173
174 $shortcode_array['auxin_output_callback'] = $element_info['auxin_output_callback'];
175
176 foreach ( $element_info['params'] as $param_id => $param ) {
177 if( isset( $param['def_value'] ) ){
178 $shortcode_array['params'][ $param['param_name'] ] = $param['def_value'];
179 } else {
180 $shortcode_array['params'][ $param['param_name'] ] = '';
181 }
182 }
183
184 return $shortcode_array;
185 }
186
187
188 /**
189 * Generates widget info
190 */
191 protected function generate_widget_array( $element_info ){
192 $widget_array = array();
193
194 $widget_array['base_ID'] = $element_info['base'];
195 $widget_array['name'] = $element_info['name'];
196 $widget_array['is_widget'] = $element_info['is_widget'];
197
198 /**
199 * This filter makes the others able to override element output function
200 */
201 $widget_array['auxin_output_callback'] = apply_filters( 'auxin_element_output_callback', $element_info['auxin_output_callback'], 'widget' );
202 $widget_array['args']['description'] = $element_info['description'];
203 $widget_array['args']['panels_groups'] = array('auxin');
204
205 if( ! empty( $element_info['icon'] ) ) {
206 $widget_array['args']['panels_icon'] = $element_info['icon'];
207 }
208
209 foreach ( $element_info['params'] as $param_id => $param ) {
210 $widget_params = array();
211
212 $widget_params['name'] = $param['heading'];
213 $widget_params['id'] = $param['param_name'];
214 $widget_params['type'] = $param['type'];
215
216 if( !empty( $param['std'] ) ) {
217 $widget_params['value'] = $param['std'];
218 }
219 elseif( !empty( $param['def_value'] ) ) {
220 $widget_params['value'] = $param['def_value'];
221 }
222 elseif( 1 ) {
223 $widget_params['value'] = isset( $param['value'] ) ? $param['value'] : '';
224 }
225 if( $widget_params['type'] == 'aux_visual_select' ) {
226 $widget_params['choices'] = $param['choices'];
227 }
228 if( isset( $param['description'] ) ) {
229 $widget_params['description'] = $param['description'];
230 }
231 if( isset( $param['dependency'] ) ) {
232 $widget_params['dependency'] = $param['dependency'];
233 }
234 // special param for aux_taxonomy field type
235 if( isset( $param['taxonomy'] ) ) {
236 $widget_params['taxonomy'] = $param['taxonomy'];
237 }
238 // TODO: It shoould convert to array an array when dependency js writes
239 // $widget_params['dependency'] = array( $param['dependency'] );
240
241 if( in_array( $param['type'], array( 'select', 'dropdown', 'aux_select2_multiple', 'aux_select2_single' ) ) ) {
242 $widget_params['options'] = $param['value'];
243 }
244
245 // lets set a key for each param, for improving search in array
246 $widget_array['params'][ $widget_params['id'] ] = $widget_params;
247 }
248
249 return $widget_array;
250 }
251
252
253 /**
254 * Adds all defined elements to vc
255 */
256 public function vc_mapper(){
257 $master_array = $this->get_master_array();
258
259 foreach ( $master_array as $array_node ) {
260 if( $array_node['is_vc'] !== false ) {
261 $array_node['params'] = $this->exchange_vc_fields( $array_node['params'] );
262 vc_map( $this->make_vc_compatible( $array_node ) );
263 }
264 }
265 }
266
267 /**
268 * Get the params array and flip the value array of its value key
269 */
270 public function exchange_vc_fields( $params ){
271 $result = array();
272
273 foreach ( $params as $params_cell => $params_value ) {
274 if( in_array( $params_value['type'], array( 'aux_visual_select', 'dropdown', 'aux_select2_multiple', 'aux_select2_single' ) ) ){
275 $params_value['value'] = ! empty( $params_value['value'] ) ? $params_value['value'] : '';
276 $params_value['std' ] = ! empty( $params_value['def_value'] ) ? $params_value['def_value'] : $params_value['value'];
277
278 if( $params_value['type' ] == 'dropdown' ){
279 $params_value['value'] = array_flip( $params_value['value'] );
280 }
281 }
282 $result[] = $params_value;
283 }
284
285 return $result;
286 }
287
288
289 /**
290 * Removes all empty array keys and appends some special fields for visual composer
291 */
292 protected function make_vc_compatible( $element_config ){
293
294 // Removes all empty array keys
295 $element_config = $this->remove_empty_nodes_recuresively( $element_config );
296
297 // Appending some special fields for visual composer
298 if( isset( $element_config['params'] ) ){
299 $element_config['params'][] = array(
300 'type' => 'css_editor',
301 'heading' => __( 'CSS', 'auxin-elements' ),
302 'param_name' => 'vc_css',
303 'group' => __( 'Design options', 'auxin-elements' )
304 );
305 }
306
307 return $element_config;
308 }
309
310
311 /**
312 * Return an instance of this class.
313 *
314 * @return object A single instance of this class.
315 */
316 public static function get_instance() {
317
318 // If the single instance hasn't been set, set it now.
319 if ( null == self::$instance ) {
320 self::$instance = new self;
321 }
322
323 return self::$instance;
324 }
325
326 }
327
328