├── .gitignore
├── README.md
├── assets
├── banner-772x250.jpg
├── icon-256x256.jpg
└── screenshot-1.png
└── trunk
├── Admin
├── DynamicConditionsAdmin.php
├── css
│ └── dynamic-conditions-admin.css
├── index.php
├── js
│ ├── dynamic-conditions-admin.js
│ └── index.php
└── partials
│ ├── dynamic-conditions-admin-display.php
│ └── index.php
├── LICENSE.txt
├── Legacy
├── Lib
│ ├── DynamicConditionsDate.php
│ └── index.php
├── WeakMap_Fallback.php
└── index.php
├── Lib
├── Activator.php
├── Date.php
├── Deactivator.php
├── DynamicConditions.php
├── DynamicTags
│ ├── NumberPostsTag.php
│ └── index.php
├── I18n.php
├── Loader.php
└── index.php
├── Public
├── DynamicConditionsPublic.php
├── css
│ ├── debug.css
│ ├── dynamic-conditions-public.css
│ └── index.php
├── index.php
├── js
│ ├── dynamic-conditions-public.js
│ └── index.php
└── partials
│ ├── debug.php
│ ├── dynamic-conditions-public-display.php
│ └── index.php
├── README.txt
├── composer.json
├── dynamic-conditions.php
├── index.php
├── languages
├── dynamicconditions-de_DE.mo
├── dynamicconditions-de_DE.po
├── dynamicconditions.pot
└── index.php
├── uninstall.php
└── vendor
├── autoload.php
└── composer
├── ClassLoader.php
├── LICENSE
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
└── installed.json
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | /trunk/vendor
3 | .idea
4 | .svn
5 | /tags
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DynamicConditions
2 |
3 | Activates conditions for dynamic tags to show/hides a widget.
4 | You can check every field which support dynamic-tags (also advanced custom fields) and check for empty, contain, equal.
5 |
6 | # Install
7 | ### Requirements
8 | - Composer (https://getcomposer.org/)
9 | - Elementor (https://wordpress.org/plugins/elementor/)
10 | - Elementor Pro (https://elementor.com)
11 |
12 | ### Run this
13 | ```
14 | $ git clone git@github.com:RTO-Websites/dynamic-conditions.git
15 | cd trunk
16 | composer install
17 | ```
18 |
--------------------------------------------------------------------------------
/assets/banner-772x250.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RTO-Websites/dynamic-conditions/792231b9b1044f1d9e94a1d547e6015666517ee2/assets/banner-772x250.jpg
--------------------------------------------------------------------------------
/assets/icon-256x256.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RTO-Websites/dynamic-conditions/792231b9b1044f1d9e94a1d547e6015666517ee2/assets/icon-256x256.jpg
--------------------------------------------------------------------------------
/assets/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RTO-Websites/dynamic-conditions/792231b9b1044f1d9e94a1d547e6015666517ee2/assets/screenshot-1.png
--------------------------------------------------------------------------------
/trunk/Admin/DynamicConditionsAdmin.php:
--------------------------------------------------------------------------------
1 |
35 | */
36 | class DynamicConditionsAdmin {
37 | private string $pluginName;
38 | private string $version;
39 |
40 | public function __construct( string $pluginName, string $version ) {
41 |
42 | $this->pluginName = $pluginName;
43 | $this->version = $version;
44 |
45 | }
46 |
47 |
48 | /**
49 | * Register the stylesheets for the admin area.
50 | *
51 | * @since 1.0.0
52 | */
53 | public function enqueueStyles(): void {
54 |
55 | wp_enqueue_style( $this->pluginName, DynamicConditions_URL . '/Admin/css/dynamic-conditions-admin.css', [], $this->version, 'all' );
56 |
57 | }
58 |
59 | public function addAdminNotices(): void {
60 | $message = '';
61 | $class = 'notice notice-error';
62 |
63 | if ( !defined( 'ELEMENTOR_VERSION' ) && !defined( 'ELEMENTOR_PRO_VERSION' ) ) {
64 | $message = __( 'Elementor and Elementor Pro not installed.', 'dynamic-conditions' );
65 | } else if ( !defined( 'ELEMENTOR_PRO_VERSION' ) ) {
66 | $message = __( 'Elementor Pro not installed.', 'dynamic-conditions' );
67 | } else if ( !defined( 'ELEMENTOR_VERSION' ) ) {
68 | $message = __( 'Elementor not installed.', 'dynamic-conditions' );
69 | }
70 |
71 |
72 | if ( empty( $message ) ) {
73 | return;
74 | }
75 | printf( '
', esc_attr( $class ), esc_html( $message ) );
76 | }
77 |
78 |
79 | /**
80 | * Creates section for dynamic conditions in elementor-widgets
81 | * @param Element_Base|Document $element
82 | */
83 | public function addConditionFields( $element, $section_id = null, ?array $args = null ): void {
84 | $valueCondition = [
85 | 'equal',
86 | 'not_equal',
87 | 'contains',
88 | 'not_contains',
89 | 'less',
90 | 'greater',
91 | 'between',
92 | 'in_array',
93 | 'in_array_contains',
94 | ];
95 |
96 | $allCondition = [
97 | 'equal',
98 | 'not_equal',
99 | 'contains',
100 | 'not_contains',
101 | 'less',
102 | 'greater',
103 | 'between',
104 | 'empty',
105 | 'not_empty',
106 | ];
107 |
108 | $type = 'element';
109 | $renderType = 'template';
110 | if ( !empty( $element ) && is_object( $element ) && method_exists( $element, 'get_type' ) ) {
111 | $type = $element->get_type();
112 | }
113 |
114 | $categories = [
115 | Module::BASE_GROUP,
116 | Module::TEXT_CATEGORY,
117 | Module::URL_CATEGORY,
118 | Module::GALLERY_CATEGORY,
119 | Module::IMAGE_CATEGORY,
120 | Module::MEDIA_CATEGORY,
121 | Module::POST_META_CATEGORY,
122 | ];
123 |
124 | $categoriesTextOnly = [
125 | Module::BASE_GROUP,
126 | Module::TEXT_CATEGORY,
127 | Module::URL_CATEGORY,
128 | Module::POST_META_CATEGORY,
129 | ];
130 |
131 | if ( defined( Module::class . '::COLOR_CATEGORY' ) ) {
132 | $categories[] = Module::COLOR_CATEGORY;
133 | }
134 |
135 | $element->start_controls_section(
136 | 'dynamicconditions_section',
137 | [
138 | 'tab' => Controls_Manager::TAB_ADVANCED,
139 | 'label' => __( 'Dynamic Conditions', 'dynamicconditions' ),
140 | ]
141 | );
142 |
143 | $element->add_control(
144 | 'dynamicconditions_dynamic',
145 | [
146 | 'label' => __( 'Dynamic Tag', 'dynamicconditions' ),
147 | 'type' => Controls_Manager::MEDIA,
148 | 'dynamic' => [
149 | 'active' => true,
150 | 'categories' => $categories,
151 | ],
152 | 'render_type' => $renderType,
153 | 'placeholder' => __( 'Select condition field', 'dynamicconditions' ),
154 | ]
155 | );
156 |
157 | $element->add_control(
158 | 'dynamicconditions_visibility',
159 | [
160 | 'label' => __( 'Show/Hide', 'dynamicconditions' ),
161 | 'type' => Controls_Manager::SELECT,
162 | 'default' => 'hide',
163 | 'options' => [
164 | 'show' => __( 'Show when condition met', 'dynamicconditions' ),
165 | 'hide' => __( 'Hide when condition met', 'dynamicconditions' ),
166 | ],
167 | 'render_type' => $renderType,
168 | 'separator' => 'before',
169 | ]
170 | );
171 |
172 | $element->add_control(
173 | 'dynamicconditions_condition',
174 | [
175 | 'label' => __( 'Condition', 'dynamicconditions' ),
176 | 'type' => Controls_Manager::SELECT2,
177 | 'multiple' => false,
178 | 'label_block' => true,
179 | 'options' => [
180 | 'equal' => __( 'Is equal to', 'dynamicconditions' ),
181 | 'not_equal' => __( 'Is not equal to', 'dynamicconditions' ),
182 | 'contains' => __( 'Contains', 'dynamicconditions' ),
183 | 'not_contains' => __( 'Does not contain', 'dynamicconditions' ),
184 | 'empty' => __( 'Is empty', 'dynamicconditions' ),
185 | 'not_empty' => __( 'Is not empty', 'dynamicconditions' ),
186 | 'between' => __( 'Between', 'dynamicconditions' ),
187 | 'less' => __( 'Less than', 'dynamicconditions' ),
188 | 'greater' => __( 'Greater than', 'dynamicconditions' ),
189 | 'in_array' => __( 'In array', 'dynamicconditions' ),
190 | 'in_array_contains' => __( 'In array contains', 'dynamicconditions' ),
191 | ],
192 | 'description' => __( 'Select your condition for this widget visibility.', 'dynamicconditions' ),
193 |
194 | 'prefix_class' => 'dc-has-condition dc-condition-',
195 | 'render_type' => 'template',
196 | ]
197 | );
198 |
199 | $element->add_control(
200 | 'dynamicconditions_type',
201 | [
202 | 'label' => __( 'Compare Type', 'dynamicconditions' ),
203 | 'type' => Controls_Manager::SELECT,
204 | 'multiple' => false,
205 | 'label_block' => true,
206 | 'options' => [
207 | 'default' => __( 'Text', 'dynamicconditions' ),
208 | 'date' => __( 'Date', 'dynamicconditions' ),
209 | 'days' => __( 'Weekdays', 'dynamicconditions' ),
210 | 'months' => __( 'Months', 'dynamicconditions' ),
211 | 'strtotime' => __( 'String to time', 'dynamicconditions' ),
212 | 'int' => __( 'Integer', 'dynamicconditions' ),
213 | ],
214 | 'default' => 'default',
215 | 'render_type' => $renderType,
216 | 'description' => __( 'Select what do you want to compare', 'dynamicconditions' ),
217 | 'condition' => [
218 | 'dynamicconditions_condition' => $valueCondition,
219 | ],
220 | ]
221 | );
222 |
223 | $element->add_control(
224 | 'dynamicconditions_value',
225 | [
226 | 'type' => Controls_Manager::TEXTAREA,
227 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
228 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
229 | 'render_type' => $renderType,
230 |
231 | 'dynamic' => [
232 | 'active' => true,
233 | 'categories' => $categoriesTextOnly,
234 | ],
235 | 'condition' => [
236 | 'dynamicconditions_condition' => $valueCondition,
237 | 'dynamicconditions_type' => [ 'default', 'strtotime', 'int' ],
238 | ],
239 | ]
240 | );
241 |
242 | $element->add_control(
243 | 'dynamicconditions_value2',
244 | [
245 | 'type' => Controls_Manager::TEXTAREA,
246 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
247 | 'description' => __( 'Add a second condition value, if between is selected', 'dynamicconditions' ),
248 | 'render_type' => $renderType,
249 | 'dynamic' => [
250 | 'active' => true,
251 | 'categories' => $categoriesTextOnly,
252 | ],
253 |
254 | 'condition' => [
255 | 'dynamicconditions_condition' => [ 'between' ],
256 | 'dynamicconditions_type' => [ 'default', 'strtotime', 'int' ],
257 | ],
258 | ]
259 | );
260 |
261 |
262 | $element->add_control(
263 | 'dynamicconditions_date_value',
264 | [
265 | 'type' => Controls_Manager::DATE_TIME,
266 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
267 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
268 | 'render_type' => $renderType,
269 |
270 | 'condition' => [
271 | 'dynamicconditions_condition' => $valueCondition,
272 | 'dynamicconditions_type' => 'date',
273 | ],
274 | ]
275 | );
276 |
277 | $element->add_control(
278 | 'dynamicconditions_date_value2',
279 | [
280 | 'type' => Controls_Manager::DATE_TIME,
281 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
282 | 'description' => __( 'Add a second condition value, if between is selected', 'dynamicconditions' ),
283 | 'render_type' => $renderType,
284 | 'condition' => [
285 | 'dynamicconditions_condition' => [ 'between' ],
286 | 'dynamicconditions_type' => 'date',
287 | ],
288 | ]
289 | );
290 |
291 | $element->add_control(
292 | 'dynamicconditions_day_array_value',
293 | [
294 | 'type' => Controls_Manager::SELECT2,
295 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
296 | 'render_type' => $renderType,
297 | 'condition' => [
298 | 'dynamicconditions_condition' => [ 'in_array' ],
299 | 'dynamicconditions_type' => 'days',
300 | ],
301 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
302 | 'options' => Date::getDaysTranslated(),
303 | 'multiple' => true,
304 | ]
305 | );
306 | $element->add_control(
307 | 'dynamicconditions_day_value',
308 | [
309 | 'type' => Controls_Manager::SELECT,
310 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
311 | 'render_type' => $renderType,
312 | 'condition' => [
313 | 'dynamicconditions_condition' => array_diff( $valueCondition, [ 'in_array' ] ),
314 | 'dynamicconditions_type' => 'days',
315 | ],
316 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
317 | 'options' => Date::getDaysTranslated(),
318 | ]
319 | );
320 |
321 | $element->add_control(
322 | 'dynamicconditions_day_value2',
323 | [
324 | 'type' => Controls_Manager::SELECT,
325 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
326 | 'render_type' => $renderType,
327 | 'condition' => [
328 | 'dynamicconditions_condition' => [ 'between' ],
329 | 'dynamicconditions_type' => 'days',
330 | ],
331 | 'description' => __( 'Add a second condition value, if between is selected', 'dynamicconditions' ),
332 | 'options' => Date::getDaysTranslated(),
333 | ]
334 | );
335 |
336 | $element->add_control(
337 | 'dynamicconditions_month_array_value',
338 | [
339 | 'type' => Controls_Manager::SELECT2,
340 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
341 | 'render_type' => $renderType,
342 | 'condition' => [
343 | 'dynamicconditions_condition' => [ 'in_array' ],
344 | 'dynamicconditions_type' => 'months',
345 | ],
346 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
347 | 'options' => Date::getMonthsTranslated(),
348 | 'multiple' => true,
349 | ]
350 | );
351 |
352 | $element->add_control(
353 | 'dynamicconditions_month_value',
354 | [
355 | 'type' => Controls_Manager::SELECT,
356 | 'label' => __( 'Conditional value', 'dynamicconditions' ),
357 | 'render_type' => $renderType,
358 | 'condition' => [
359 | 'dynamicconditions_condition' => array_diff( $valueCondition, [ 'in_array' ] ),
360 | 'dynamicconditions_type' => 'months',
361 | ],
362 | 'description' => __( 'Add your conditional value to compare here.', 'dynamicconditions' ),
363 | 'options' => Date::getMonthsTranslated(),
364 | ]
365 | );
366 |
367 | $element->add_control(
368 | 'dynamicconditions_month_value2',
369 | [
370 | 'type' => Controls_Manager::SELECT,
371 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
372 | 'render_type' => $renderType,
373 | 'condition' => [
374 | 'dynamicconditions_condition' => [ 'between' ],
375 | 'dynamicconditions_type' => 'months',
376 | ],
377 | 'description' => __( 'Add a second condition value, if between is selected', 'dynamicconditions' ),
378 | 'options' => Date::getMonthsTranslated(),
379 | ]
380 | );
381 |
382 |
383 | $element->add_control(
384 | 'dynamicconditions_in_array_description',
385 | [
386 | 'type' => Controls_Manager::RAW_HTML,
387 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
388 | 'render_type' => $renderType,
389 | 'condition' => [
390 | 'dynamicconditions_condition' => [ 'in_array' ],
391 | ],
392 | 'show_label' => false,
393 | 'raw' => __( 'Use comma-separated values, to check if dynamic-value is equal with one of each item.', 'dynamicconditions' ),
394 | ]
395 | );
396 |
397 | $element->add_control(
398 | 'dynamicconditions_in_array_contains_description',
399 | [
400 | 'type' => Controls_Manager::RAW_HTML,
401 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
402 | 'render_type' => $renderType,
403 | 'condition' => [
404 | 'dynamicconditions_condition' => [ 'in_array_contains' ],
405 | ],
406 | 'show_label' => false,
407 | 'raw' => __( 'Use comma-separated values, to check if dynamic-value contains one of each item.', 'dynamicconditions' ),
408 | ]
409 | );
410 |
411 | $languageArray = explode( '_', get_locale() );
412 | $language = array_shift( $languageArray );
413 | $element->add_control(
414 | 'dynamicconditions_date_description',
415 | [
416 | 'type' => Controls_Manager::RAW_HTML,
417 | 'label' => __( 'Conditional value', 'dynamicconditions' ) . ' 2',
418 | 'render_type' => $renderType,
419 | 'condition' => [
420 | 'dynamicconditions_condition' => $valueCondition,
421 | 'dynamicconditions_type' => 'strtotime',
422 | ],
423 | 'show_label' => false,
424 | 'raw' => '',
427 | ]
428 | );
429 |
430 | $element->add_control(
431 | 'dynamicconditions_hr',
432 | [
433 | 'type' => Controls_Manager::DIVIDER,
434 | 'style' => 'thick',
435 | 'condition' => [
436 | 'dynamicconditions_condition' => $valueCondition,
437 | ],
438 | ]
439 | );
440 |
441 | $element->add_control(
442 | 'dynamicconditions_hideContentOnly',
443 | [
444 | 'type' => Controls_Manager::SWITCHER,
445 | 'label' => __( 'Hide only content', 'dynamicconditions' ),
446 | 'description' => __( 'If checked, only the inner content will be hidden, so you will see an empty section', 'dynamicconditions' ),
447 | 'return_value' => 'on',
448 | 'render_type' => $renderType,
449 | 'condition' => [
450 | 'dynamicconditions_condition' => $allCondition,
451 | ],
452 | ]
453 | );
454 |
455 | $element->add_control(
456 | 'dynamicconditions_removeStyles',
457 | [
458 | 'type' => Controls_Manager::SWITCHER,
459 | 'label' => __( 'Remove Styles', 'dynamicconditions' ),
460 | 'description' => __( 'If checked, all style- and link-tags will be removed from the element. Can affect other elements.', 'dynamicconditions' ),
461 | 'return_value' => 'on',
462 | 'render_type' => $renderType,
463 | 'condition' => [
464 | 'dynamicconditions_condition' => $allCondition,
465 | ],
466 | ]
467 | );
468 |
469 | if ( $type === 'column' ) {
470 | $element->add_control(
471 | 'dynamicconditions_resizeOtherColumns',
472 | [
473 | 'type' => Controls_Manager::SWITCHER,
474 | 'label' => __( 'Resize other columns', 'dynamicconditions' ),
475 | 'render_type' => $renderType,
476 | 'condition' => [
477 | 'dynamicconditions_condition' => $allCondition,
478 | 'dynamicconditions_hideContentOnly!' => 'on',
479 | ],
480 | 'return_value' => 'on',
481 | ]
482 | );
483 | }
484 |
485 |
486 | $element->add_control(
487 | 'dynamicconditions_headline_expert',
488 | [
489 | 'label' => __( 'Expert', 'dynamicconditions' ),
490 | 'type' => Controls_Manager::HEADING,
491 | 'separator' => 'before',
492 | ]
493 | );
494 |
495 | $element->add_control(
496 | 'dynamicconditions_parse_shortcodes',
497 | [
498 | 'type' => Controls_Manager::SWITCHER,
499 | 'label' => __( 'Parse shortcodes', 'dynamicconditions' ),
500 | 'render_type' => $renderType,
501 | ]
502 | );
503 |
504 | $element->add_control(
505 | 'dynamicconditions_prevent_date_parsing',
506 | [
507 | 'type' => Controls_Manager::SWITCHER,
508 | 'label' => __( 'Prevent date parsing', 'dynamicconditions' ),
509 | 'render_type' => $renderType,
510 | ]
511 | );
512 |
513 |
514 | $element->add_control(
515 | 'dynamicconditions_hr3',
516 | [
517 | 'type' => Controls_Manager::DIVIDER,
518 | 'style' => 'thick',
519 | ]
520 | );
521 |
522 |
523 | $element->add_control(
524 | 'dynamicconditions_hideWrapper',
525 | [
526 | 'type' => Controls_Manager::TEXT,
527 | 'label' => __( 'Hide wrapper', 'dynamicconditions' ),
528 | 'description' => __( 'Will hide a parent matching the selector.', 'dynamicconditions' ),
529 | 'placeholder' => 'selector',
530 | 'render_type' => $renderType,
531 | ]
532 | );
533 |
534 | $element->add_control(
535 | 'dynamicconditions_hideOthers',
536 | [
537 | 'type' => Controls_Manager::TEXT,
538 | 'label' => __( 'Hide other elements', 'dynamicconditions' ),
539 | 'description' => __( 'Will hide all other elements matching the selector.', 'dynamicconditions' ),
540 | 'placeholder' => 'selector',
541 | 'render_type' => $renderType,
542 | ]
543 | );
544 |
545 | $element->add_control(
546 | 'dynamicconditions_hr4',
547 | [
548 | 'type' => Controls_Manager::DIVIDER,
549 | 'style' => 'thick',
550 | ]
551 | );
552 |
553 | $element->add_control(
554 | 'dynamicconditions_widget_id',
555 | [
556 | 'type' => Controls_Manager::TEXT,
557 | 'label' => __( 'Widget-ID', 'dynamicconditions' ),
558 | 'render_type' => $renderType,
559 | 'description' => '',
565 | ]
566 | );
567 |
568 | $element->add_control(
569 | 'dynamicconditions_hr5',
570 | [
571 | 'type' => Controls_Manager::DIVIDER,
572 | 'style' => 'thick',
573 | ]
574 | );
575 |
576 | $element->add_control(
577 | 'dynamicconditions_debug',
578 | [
579 | 'type' => Controls_Manager::SWITCHER,
580 | 'label' => __( 'Debug-Mode', 'dynamicconditions' ),
581 | 'render_type' => $renderType,
582 | ]
583 | );
584 |
585 | $element->end_controls_section();
586 | }
587 | }
588 |
--------------------------------------------------------------------------------
/trunk/Admin/css/dynamic-conditions-admin.css:
--------------------------------------------------------------------------------
1 |
2 |
3 | .elementor-control-dynamicconditions_dynamic .elementor-control-media__tools {
4 | bottom: 0 !important;
5 | }
6 |
7 | .elementor-control-dynamicconditions_dynamic .elementor-control-media__tool,
8 | .elementor-control-dynamicconditions_dynamic .elementor-control-media-upload-button {
9 | display: none;
10 | }
11 |
12 | .elementor-control-dynamicconditions_dynamic .elementor-control-media__content {
13 | height: 27px;
14 | padding-bottom: 0 !important;
15 | }
16 |
17 | .elementor-control-dynamicconditions_dynamic .elementor-control-dynamic-switcher {
18 | width: 100%;
19 | }
20 |
--------------------------------------------------------------------------------
/trunk/Admin/index.php:
--------------------------------------------------------------------------------
1 |
21 |
22 |
--------------------------------------------------------------------------------
/trunk/Admin/partials/index.php:
--------------------------------------------------------------------------------
1 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/trunk/Legacy/Lib/DynamicConditionsDate.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class Activator {
31 |
32 | /**
33 | * Short Description. (use period)
34 | *
35 | * Long Description.
36 | *
37 | * @since 1.0.0
38 | */
39 | public static function activate() {
40 |
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/trunk/Lib/Date.php:
--------------------------------------------------------------------------------
1 | getTimestamp();
57 | }
58 |
59 | /**
60 | * Convert string to timestamp or return string if it´s already a timestamp
61 | *
62 | * @param $string
63 | * @return int
64 | */
65 | public static function stringToTime( $string = '' ) {
66 | $timestamp = $string;
67 | $strToTime = strtotime( $string ?? '', time() );
68 | if ( !empty( $strToTime ) && !self::isTimestamp( $timestamp ) ) {
69 | $timestamp = $strToTime;
70 | }
71 |
72 | return intval( $timestamp );
73 | }
74 |
75 | /**
76 | * @param string $string
77 | * @return bool
78 | */
79 | public static function isTimestamp( $string ) {
80 | if ( !is_numeric( $string ) ) {
81 | return false;
82 | }
83 | try {
84 | new \DateTime( '@' . $string );
85 | } catch ( \Exception $e ) {
86 | return false;
87 | }
88 | return true;
89 | }
90 |
91 | /**
92 | * Untranslate a date-string to english date
93 | *
94 | * @param string $needle
95 | * @param null $setLocale
96 | * @return mixed|string
97 | */
98 | public static function unTranslateDate( $needle = '', $setLocale = null ) {
99 | if (empty($needle)) {
100 | return $needle;
101 | }
102 | // get in translated lang
103 | $translatedMonths = self::getMonthsTranslated();
104 | $translatedDays = self::getDaysTranslated();
105 |
106 | // get in english
107 | $englishMonths = self::getMonths();
108 | $englishDays = self::getDays();
109 |
110 | // replace translated days/months with english ones
111 | $needle = str_ireplace( $translatedDays, $englishDays, $needle );
112 | $needle = str_ireplace( $translatedMonths, $englishMonths, $needle );
113 |
114 | return $needle;
115 | }
116 |
117 | /**
118 | * Get a list of months (january, february,...) in current language
119 | *
120 | * @return array
121 | */
122 | public static function getMonthsTranslated() {
123 | $monthList = [];
124 | // translate monthlist by wordpress-lang
125 | $monthList[1] = __( 'January' );
126 | $monthList[2] = __( 'February' );
127 | $monthList[3] = __( 'March' );
128 | $monthList[4] = __( 'April' );
129 | $monthList[5] = __( 'May' );
130 | $monthList[6] = __( 'June' );
131 | $monthList[7] = __( 'July' );
132 | $monthList[8] = __( 'August' );
133 | $monthList[9] = __( 'September' );
134 | $monthList[10] = __( 'October' );
135 | $monthList[11] = __( 'November' );
136 | $monthList[12] = __( 'December' );
137 |
138 | return $monthList;
139 | }
140 |
141 | /**
142 | * Get a list of months (january, february,...)
143 | *
144 | * @return array
145 | */
146 | private static function getMonths() {
147 | $monthList = [];
148 | $monthList[1] = 'January';
149 | $monthList[2] = 'February';
150 | $monthList[3] = 'March';
151 | $monthList[4] = 'April';
152 | $monthList[5] = 'May';
153 | $monthList[6] = 'June';
154 | $monthList[7] = 'July';
155 | $monthList[8] = 'August';
156 | $monthList[9] = 'September';
157 | $monthList[10] = 'October';
158 | $monthList[11] = 'November';
159 | $monthList[12] = 'December';
160 |
161 | return $monthList;
162 | }
163 |
164 | /**
165 | * Get a list of days (monday, tuesday,...) in current language
166 | *
167 | * @return array
168 | */
169 | public static function getDaysTranslated() {
170 | $dayList = [];
171 |
172 | // translate by wordpress-lang
173 | $dayList[1] = __( 'Monday' );
174 | $dayList[2] = __( 'Tuesday' );
175 | $dayList[3] = __( 'Wednesday' );
176 | $dayList[4] = __( 'Thursday' );
177 | $dayList[5] = __( 'Friday' );
178 | $dayList[6] = __( 'Saturday' );
179 | $dayList[7] = __( 'Sunday' );
180 |
181 | return $dayList;
182 | }
183 |
184 | /**
185 | * Get a list of days (monday, tuesday,...)
186 | *
187 | * @return array
188 | */
189 | private static function getDays() {
190 | $dayList = [];
191 | $dayList[1] = 'Monday';
192 | $dayList[2] = 'Tuesday';
193 | $dayList[3] = 'Wednesday';
194 | $dayList[4] = 'Thursday';
195 | $dayList[5] = 'Friday';
196 | $dayList[6] = 'Saturday';
197 | $dayList[7] = 'Sunday';
198 |
199 | return $dayList;
200 | }
201 |
202 | /**
203 | * Sets a local
204 | * Fix issue with too long locales returned by setLocale(LC_ALL, 0)
205 | *
206 | * @param $locale
207 | */
208 | public static function setLocale( $locale ) {
209 | $localeSettings = explode( ";", $locale );
210 |
211 | foreach ( $localeSettings as $localeSetting ) {
212 | if ( strpos( $localeSetting, "=" ) !== false ) {
213 | $categorylocale = explode( "=", $localeSetting );
214 | $category = $categorylocale[0];
215 | $locale = $categorylocale[1];
216 | } else {
217 | $category = LC_ALL;
218 | $locale = $localeSetting;
219 | }
220 |
221 | if ( is_string( $category ) && defined( $category ) ) {
222 | $category = constant( $category );
223 | }
224 |
225 | if ( !is_integer( $category ) ) {
226 | continue;
227 | }
228 |
229 | setlocale( $category, $locale );
230 | }
231 | }
232 | }
--------------------------------------------------------------------------------
/trunk/Lib/Deactivator.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class Deactivator {
31 |
32 | /**
33 | * Short Description. (use period)
34 | *
35 | * Long Description.
36 | *
37 | * @since 1.0.0
38 | */
39 | public static function deactivate() {
40 |
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/trunk/Lib/DynamicConditions.php:
--------------------------------------------------------------------------------
1 |
42 | */
43 | class DynamicConditions {
44 |
45 | protected Loader $loader;
46 |
47 | protected string $pluginName;
48 |
49 | protected string $version;
50 |
51 | /**
52 | * Define the core functionality of the plugin.
53 | *
54 | * Set the plugin name and the plugin version that can be used throughout the plugin.
55 | * Load the dependencies, define the locale, and set the hooks for the admin area and
56 | * the public-facing side of the site.
57 | *
58 | * @since 1.0.0
59 | */
60 | public function __construct() {
61 | $this->pluginName = 'dynamic-conditions';
62 | $this->version = DynamicConditions_VERSION;
63 |
64 | $this->loadDependencies();
65 | $this->setLocale();
66 |
67 | $this->defineAdminHooks();
68 | $this->definePublicHooks();
69 | $this->defineElementorHooks();
70 |
71 | }
72 |
73 | /**
74 | * Load the required dependencies for this plugin.
75 | *
76 | * Include the following files that make up the plugin:
77 | *
78 | * - DynamicConditionsLoader. Orchestrates the hooks of the plugin.
79 | * - DynamicConditionsI18n. Defines internationalization functionality.
80 | * - DynamicConditionsAdmin. Defines all hooks for the admin area.
81 | * - DynamicConditionsPublic. Defines all hooks for the public side of the site.
82 | *
83 | * Create an instance of the loader which will be used to register the hooks
84 | * with WordPress.
85 | *
86 | * @since 1.0.0
87 | * @access private
88 | */
89 | private function loadDependencies(): void {
90 |
91 | $this->loader = new Loader();
92 |
93 | }
94 |
95 | /**
96 | * Define the locale for this plugin for internationalization.
97 | *
98 | * Uses the DynamicConditionsI18n class in order to set the domain and to register the hook
99 | * with WordPress.
100 | *
101 | * @since 1.0.0
102 | * @access private
103 | */
104 | private function setLocale(): void {
105 |
106 | $pluginI18n = new I18n();
107 | $pluginI18n->setDomain( 'dynamicconditions' );
108 |
109 | $this->loader->addAction( 'plugins_loaded', $pluginI18n, 'loadPluginTextdomain' );
110 |
111 | }
112 |
113 | /**
114 | * Register all of the hooks related to the admin area functionality
115 | * of the plugin.
116 | *
117 | * @since 1.0.0
118 | * @access private
119 | */
120 | private function defineAdminHooks(): void {
121 | $pluginAdmin = new DynamicConditionsAdmin( $this->getDynamicConditions(), $this->getVersion() );
122 |
123 | $this->loader->addAction( 'elementor/element/column/section_advanced/after_section_end', $pluginAdmin, 'addConditionFields', 10, 3 );
124 | $this->loader->addAction( 'elementor/element/section/section_advanced/after_section_end', $pluginAdmin, 'addConditionFields', 10, 3 );
125 | $this->loader->addAction( 'elementor/element/common/_section_style/after_section_end', $pluginAdmin, 'addConditionFields', 10, 3 );
126 |
127 | $this->loader->addAction( 'elementor/element/popup/section_advanced/after_section_end', $pluginAdmin, 'addConditionFields', 10, 3 );
128 |
129 | $this->loader->addAction( 'elementor/element/container/section_layout/after_section_end', $pluginAdmin, 'addConditionFields', 10, 3 );
130 |
131 | $this->loader->addAction( 'admin_notices', $pluginAdmin, 'addAdminNotices', 10, 3 );
132 | $this->loader->addAction( 'admin_enqueue_scripts', $pluginAdmin, 'enqueueStyles' );
133 | $this->loader->addAction( 'elementor/editor/before_enqueue_styles', $pluginAdmin, 'enqueueStyles' );
134 | }
135 |
136 | /**
137 | * Register all of the hooks related to the public-facing functionality
138 | * of the plugin.
139 | *
140 | * @since 1.0.0
141 | * @access private
142 | */
143 | private function definePublicHooks(): void {
144 | $pluginPublic = new DynamicConditionsPublic( $this->getDynamicConditions(), $this->getVersion() );
145 |
146 | $this->loader->addAction( 'wp_enqueue_scripts', $pluginPublic, 'enqueueScripts' );
147 |
148 | // filter widgets
149 | $this->loader->addAction( "elementor/frontend/widget/before_render", $pluginPublic, 'filterSectionContentBefore', 10, 1 );
150 | $this->loader->addAction( "elementor/frontend/widget/after_render", $pluginPublic, 'filterSectionContentAfter', 10, 1 );
151 |
152 | // filter sections
153 | $this->loader->addAction( "elementor/frontend/section/before_render", $pluginPublic, 'filterSectionContentBefore', 10, 1 );
154 | $this->loader->addAction( "elementor/frontend/section/after_render", $pluginPublic, 'filterSectionContentAfter', 10, 1 );
155 |
156 | // filter columns
157 | $this->loader->addAction( "elementor/frontend/column/before_render", $pluginPublic, 'filterSectionContentBefore', 10, 1 );
158 | $this->loader->addAction( "elementor/frontend/column/after_render", $pluginPublic, 'filterSectionContentAfter', 10, 1 );
159 |
160 | // filter container
161 | $this->loader->addAction( "elementor/frontend/container/before_render", $pluginPublic, 'filterSectionContentBefore', 10, 1 );
162 | $this->loader->addAction( "elementor/frontend/container/after_render", $pluginPublic, 'filterSectionContentAfter', 10, 1 );
163 |
164 | // filter popup
165 | $this->loader->addAction( "elementor/theme/before_do_popup", $pluginPublic, 'checkPopupsCondition', 10, 1 );
166 | }
167 |
168 | /**
169 | * Register all of the hooks related to the elementor-facing functionality
170 | * of the plugin.
171 | *
172 | * @since 1.2.0
173 | * @access private
174 | */
175 | private function defineElementorHooks(): void {
176 | $this->loader->addAction( 'elementor/dynamic_tags/register', $this, 'registerDynamicTags', 10, 1 );
177 | $this->loader->addAction( 'wp_footer', $this, 'setFooterStyleForPreview', 10, 0 );
178 | }
179 |
180 | public function registerDynamicTags( Manager $dynamicTags ): void {
181 | $dynamicTags->register( new NumberPostsTag );
182 | }
183 |
184 | /**
185 | * Sets style for preview
186 | *
187 | * @since 1.3.0
188 | */
189 | public function setFooterStyleForPreview(): void {
190 | if ( !class_exists('Elementor\Plugin') || !Plugin::$instance->preview->is_preview_mode() ) {
191 | return;
192 | }
193 | ?>
194 |
209 | pluginName;
214 | }
215 |
216 | public function getLoader(): Loader {
217 | return $this->loader;
218 | }
219 |
220 | public function getVersion(): string {
221 | return $this->version;
222 | }
223 |
224 | /**
225 | * Run the loader to execute all of the hooks with WordPress.
226 | *
227 | * @since 1.0.0
228 | */
229 | public static function run(): void {
230 | $plugin = new self();
231 | $plugin->loader->run();
232 | }
233 | }
--------------------------------------------------------------------------------
/trunk/Lib/DynamicTags/NumberPostsTag.php:
--------------------------------------------------------------------------------
1 | add_control(
36 | 'category',
37 | [
38 | 'label' => __( 'Category', 'elementor-pro' ),
39 | 'type' => Controls_Manager::SELECT2,
40 | 'label_block' => true,
41 | 'default' => [],
42 | 'options' => $this->getCategories(),
43 | 'multiple' => true,
44 | ]
45 | );
46 | $this->add_control(
47 | 'posttypes',
48 | [
49 | 'label' => __( 'Post-Types', 'elementor-pro' ),
50 | 'type' => Controls_Manager::SELECT2,
51 | 'label_block' => true,
52 | 'default' => [],
53 | 'options' => get_post_types(),
54 | 'multiple' => true,
55 | ]
56 | );
57 | }
58 |
59 | /**
60 | * Get a list of all categories
61 | *
62 | * @return array
63 | */
64 | private function getCategories() {
65 | $result = [];
66 | foreach ( get_categories() as $category ) {
67 | $result[$category->term_id] = $category->name;
68 | }
69 |
70 | return $result;
71 | }
72 |
73 |
74 | /**
75 | * Print the number of posts in category/post-type
76 | */
77 | public function render() {
78 | $settings = $this->get_settings();
79 | $posts = get_posts( [
80 | 'category' => implode( ',', $settings['category'] ),
81 | 'post_type' => empty( $settings['posttypes'] ) ? 'any' : $settings['posttypes'],
82 | 'numberposts' => -1,
83 | 'posts_per_page' => -1,
84 | 'fields' => 'ids',
85 | ] );
86 |
87 | echo count( $posts );
88 | }
89 | }
--------------------------------------------------------------------------------
/trunk/Lib/DynamicTags/index.php:
--------------------------------------------------------------------------------
1 |
33 | */
34 | class I18n {
35 |
36 | /**
37 | * The domain specified for this plugin.
38 | *
39 | * @since 1.0.0
40 | * @access private
41 | * @var string $domain The domain identifier for this plugin.
42 | */
43 | private $domain;
44 |
45 | /**
46 | * Load the plugin text domain for translation.
47 | *
48 | * @since 1.0.0
49 | */
50 | public function loadPluginTextdomain() {
51 |
52 | load_plugin_textdomain(
53 | $this->domain,
54 | false,
55 | dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
56 | );
57 |
58 | }
59 |
60 | /**
61 | * Set the domain equal to that of the specified domain.
62 | *
63 | * @since 1.0.0
64 | * @param string $domain The domain that represents the locale of this plugin.
65 | */
66 | public function setDomain( $domain ) {
67 | $this->domain = $domain;
68 | }
69 |
70 | }
--------------------------------------------------------------------------------
/trunk/Lib/Loader.php:
--------------------------------------------------------------------------------
1 |
30 | */
31 | class Loader {
32 |
33 | /**
34 | * The array of actions registered with WordPress.
35 | *
36 | * @since 1.0.0
37 | * @access protected
38 | * @var array $actions The actions registered with WordPress to fire when the plugin loads.
39 | */
40 | protected $actions;
41 |
42 | /**
43 | * The array of filters registered with WordPress.
44 | *
45 | * @since 1.0.0
46 | * @access protected
47 | * @var array $filters The filters registered with WordPress to fire when the plugin loads.
48 | */
49 | protected $filters;
50 |
51 | /**
52 | * Initialize the collections used to maintain the actions and filters.
53 | *
54 | * @since 1.0.0
55 | */
56 | public function __construct() {
57 |
58 | $this->actions = array();
59 | $this->filters = array();
60 |
61 | }
62 |
63 | /**
64 | * Add a new action to the collection to be registered with WordPress.
65 | *
66 | * @since 1.0.0
67 | * @param string $hook The name of the WordPress action that is being registered.
68 | * @param object $component A reference to the instance of the object on which the action is defined.
69 | * @param string $callback The name of the function definition on the $component.
70 | * @param int Optional $priority The priority at which the function should be fired.
71 | * @param int Optional $acceptedArgs The number of arguments that should be passed to the $callback.
72 | */
73 | public function addAction( $hook, $component, $callback, $priority = 10, $acceptedArgs = 1 ) {
74 | $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $acceptedArgs );
75 | }
76 |
77 | /**
78 | * Add a new filter to the collection to be registered with WordPress.
79 | *
80 | * @since 1.0.0
81 | * @param string $hook The name of the WordPress filter that is being registered.
82 | * @param object $component A reference to the instance of the object on which the filter is defined.
83 | * @param string $callback The name of the function definition on the $component.
84 | * @param int Optional $priority The priority at which the function should be fired.
85 | * @param int Optional $acceptedArgs The number of arguments that should be passed to the $callback.
86 | */
87 | public function addFilter( $hook, $component, $callback, $priority = 10, $acceptedArgs = 1 ) {
88 | $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $acceptedArgs );
89 | }
90 |
91 | /**
92 | * A utility function that is used to register the actions and hooks into a single
93 | * collection.
94 | *
95 | * @since 1.0.0
96 | * @access private
97 | * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
98 | * @param string $hook The name of the WordPress filter that is being registered.
99 | * @param object $component A reference to the instance of the object on which the filter is defined.
100 | * @param string $callback The name of the function definition on the $component.
101 | * @param int Optional $priority The priority at which the function should be fired.
102 | * @param int Optional $acceptedArgs The number of arguments that should be passed to the $callback.
103 | * @return array The collection of actions and filters registered with WordPress.
104 | */
105 | private function add( $hooks, $hook, $component, $callback, $priority, $acceptedArgs ) {
106 |
107 | $hooks[] = array(
108 | 'hook' => $hook,
109 | 'component' => $component,
110 | 'callback' => $callback,
111 | 'priority' => $priority,
112 | 'acceptedArgs' => $acceptedArgs
113 | );
114 |
115 | return $hooks;
116 |
117 | }
118 |
119 | /**
120 | * Register the filters and actions with WordPress.
121 | *
122 | * @since 1.0.0
123 | */
124 | public function run() {
125 |
126 | foreach ( $this->filters as $hook ) {
127 | add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['acceptedArgs'] );
128 | }
129 |
130 | foreach ( $this->actions as $hook ) {
131 | add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['acceptedArgs'] );
132 | }
133 |
134 | }
135 |
136 | }
--------------------------------------------------------------------------------
/trunk/Lib/index.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 | class DynamicConditionsPublic {
38 |
39 | private string $pluginName;
40 |
41 | private string $version;
42 |
43 | private array $elementSettings = [];
44 |
45 | /**
46 | * @access private
47 | * @var array $isSectionHidden For storing hidden-status
48 | */
49 | private array $isSectionHidden = [];
50 |
51 | private Date $dateInstance;
52 |
53 | private static bool $debugCssRendered = false;
54 |
55 | private array $shortcodeTags = [];
56 |
57 | /**
58 | * Initialize the class and set its properties.
59 | */
60 | public function __construct( string $pluginName, string $version ) {
61 |
62 | $this->pluginName = $pluginName;
63 | $this->version = $version;
64 | $this->dateInstance = new Date();
65 | }
66 |
67 | /**
68 | * Gets settings with english locale (needed for date)
69 | * @param Element_Base|Document $element
70 | */
71 | private function getElementSettings( $element ): array {
72 | $id = get_the_id(). '-'. $element->get_id();
73 |
74 | if ( !empty( $this->elementSettings[$id] ) ) {
75 | return $this->elementSettings[$id];
76 | }
77 | $clonedElement = clone $element;
78 |
79 | $fields = '__dynamic__
80 | dynamicconditions_dynamic
81 | dynamicconditions_condition
82 | dynamicconditions_type
83 | dynamicconditions_resizeOtherColumns
84 | dynamicconditions_hideContentOnly
85 | dynamicconditions_visibility
86 | dynamicconditions_day_value
87 | dynamicconditions_day_value2
88 | dynamicconditions_day_array_value
89 | dynamicconditions_month_value
90 | dynamicconditions_month_value2
91 | dynamicconditions_month_array_value
92 | dynamicconditions_date_value
93 | dynamicconditions_date_value2
94 | dynamicconditions_value
95 | dynamicconditions_value2
96 | dynamicconditions_parse_shortcodes
97 | dynamicconditions_debug
98 | dynamicconditions_hideOthers
99 | dynamicconditions_hideWrapper
100 | dynamicconditions_removeStyles
101 | _column_size
102 | _inline_size';
103 |
104 | $fieldArray = explode( "\n", $fields );
105 |
106 | $this->elementSettings[$id]['dynamicconditions_dynamic_raw'] = $element->get_settings_for_display( 'dynamicconditions_dynamic' );
107 |
108 | $preventDateParsing = $element->get_settings_for_display( 'dynamicconditions_prevent_date_parsing' );
109 | $this->elementSettings[$id]['preventDateParsing'] = $preventDateParsing;
110 |
111 | if ( empty( $preventDateParsing ) ) {
112 | // set locale to english, for better parsing
113 | $currentLocale = setlocale( LC_ALL, 0 );
114 | setlocale( LC_ALL, 'en_GB' );
115 | add_filter( 'date_i18n', [ $this->dateInstance, 'filterDateI18n' ], 10, 4 );
116 | add_filter( 'get_the_date', [ $this->dateInstance, 'filterPostDate' ], 10, 3 );
117 | add_filter( 'get_the_modified_date', [ $this->dateInstance, 'filterPostDate' ], 10, 3 );
118 | }
119 |
120 | foreach ( $fieldArray as $field ) {
121 | $field = trim( $field );
122 | $this->elementSettings[$id][$field] = $clonedElement->get_settings_for_display( $field );
123 | }
124 | unset( $clonedElement );
125 |
126 | if ( empty( $preventDateParsing ) ) {
127 | remove_filter( 'date_i18n', [ $this->dateInstance, 'filterDateI18n' ], 10 );
128 | remove_filter( 'get_the_date', [ $this->dateInstance, 'filterPostDate' ], 10 );
129 | remove_filter( 'get_the_modified_date', [ $this->dateInstance, 'filterPostDate' ], 10 );
130 |
131 | // reset locale
132 | Date::setLocale( $currentLocale );
133 | }
134 |
135 | $tagData = $this->getDynamicTagData( $id );
136 | $this->convertAcfDate( $id, $tagData );
137 |
138 | $this->elementSettings[$id]['dynamicConditionsData'] = [
139 | 'id' => $id,
140 | 'type' => $element->get_type(),
141 | 'name' => $element->get_name(),
142 | 'selectedTag' => $tagData['selectedTag'],
143 | 'tagData' => $tagData['tagData'],
144 | 'tagKey' => $tagData['tagKey'],
145 | ];
146 |
147 | return $this->elementSettings[$id];
148 | }
149 |
150 | /**
151 | * Returns data of dynamic tag
152 | */
153 | private function getDynamicTagData( string $id ): array {
154 | $dynamicEmpty = empty( $this->elementSettings[$id]['__dynamic__'] )
155 | || empty( $this->elementSettings[$id]['__dynamic__']['dynamicconditions_dynamic'] );
156 | $staticEmpty = empty( $this->elementSettings[$id]['dynamicconditions_dynamic'] )
157 | || empty( $this->elementSettings[$id]['dynamicconditions_dynamic']['url'] );
158 |
159 | if ( $dynamicEmpty && $staticEmpty ) {
160 | // no dynamic tag or static value set
161 | return [
162 | 'selectedTag' => null,
163 | 'tagData' => null,
164 | 'tagKey' => null,
165 | ];
166 | }
167 |
168 | $selectedTag = null;
169 | $tagSettings = null;
170 | $tagData = [];
171 | $tagKey = null;
172 |
173 | if ( $dynamicEmpty ) {
174 | // no dynamic tag set, but static value
175 | $this->elementSettings[$id]['__dynamic__'] = [
176 | 'dynamicconditions_dynamic' => $this->elementSettings[$id]['dynamicconditions_dynamic'],
177 | ];
178 | $selectedTag = 'static';
179 | }
180 |
181 |
182 | $tag = $this->elementSettings[$id]['__dynamic__']['dynamicconditions_dynamic'];
183 | if ( is_array( $tag ) ) {
184 | return [
185 | 'selectedTag' => null,
186 | 'tagData' => null,
187 | 'tagKey' => null,
188 | ];
189 | }
190 | $splitTag = explode( ' name="', $tag );
191 |
192 | // get selected tag
193 | if ( !empty( $splitTag[1] ) ) {
194 | $splitTag2 = explode( '"', $splitTag[1] );
195 | $selectedTag = $splitTag2[0];
196 | }
197 |
198 | // get tag settings
199 | if ( strpos( $selectedTag, 'acf-' ) === 0 ) {
200 | $splitTag = explode( ' settings="', $tag );
201 | if ( !empty( $splitTag[1] ) ) {
202 | $splitTag2 = explode( '"', $splitTag[1] );
203 | $tagSettings = json_decode( urldecode( $splitTag2[0] ), true );
204 | if ( !empty( $tagSettings['key'] ) ) {
205 | $tagKey = $tagSettings['key'];
206 | $tagData = get_field_object( explode( ':', $tagSettings['key'] )[0] );
207 | }
208 | }
209 | }
210 | return [
211 | 'selectedTag' => $selectedTag,
212 | 'tagData' => $tagData,
213 | 'tagKey' => $tagKey,
214 | ];
215 |
216 | }
217 |
218 | /**
219 | * Convert acf date to timestamp
220 | */
221 | private function convertAcfDate( string $id, ?array $data ): void {
222 | if ( empty( $data ) ) {
223 | return;
224 | }
225 |
226 | if ( !empty( $this->elementSettings[$id]['preventDateParsing'] ) ) {
227 | return;
228 | }
229 |
230 | $allowedTypes = [
231 | 'date_time_picker',
232 | 'date_picker',
233 | ];
234 |
235 | $tagData = $data['tagData'];
236 |
237 | if ( empty( $data['tagKey'] ) || strpos( $data['selectedTag'], 'acf-' ) !== 0 ) {
238 | return;
239 | }
240 |
241 | if ( empty( $tagData['type'] ) || !in_array( trim( $tagData['type'] ), $allowedTypes, true ) ) {
242 | return;
243 | }
244 |
245 | if ( empty( $tagData['value'] ) || empty( $tagData['return_format'] ) ) {
246 | return;
247 | }
248 |
249 | $time = \DateTime::createFromFormat( $tagData['return_format'], Date::unTranslateDate( $tagData['value'] ) );
250 |
251 | if ( empty( $time ) ) {
252 | return;
253 | }
254 |
255 | if ( $tagData['type'] === 'date_picker' ) {
256 | $time->setTime( 0, 0, 0 );
257 | }
258 |
259 | $timestamp = $time->getTimestamp();
260 |
261 | // override value with timestamp
262 | $this->elementSettings[$id]['dynamicconditions_dynamic'] = $timestamp;
263 | }
264 |
265 |
266 | /**
267 | * Removes popup from location, if it is hidden by condition
268 | */
269 | public function checkPopupsCondition( Locations_Manager $locationManager ): void {
270 | if ( $this->getMode() !== 'website' ) {
271 | return;
272 | }
273 |
274 | $conditionManager = Module::instance()->get_conditions_manager();
275 | $module = $conditionManager->get_documents_for_location( 'popup' );
276 |
277 | foreach ( $module as $documentId => $document ) {
278 | $settings = $this->getElementSettings( $document );
279 | $hide = $this->checkCondition( $settings );
280 |
281 | if ( $hide ) {
282 | $locationManager->remove_doc_from_location( 'popup', $documentId );
283 | }
284 | }
285 | }
286 |
287 | /**
288 | * Check if section is hidden, before rendering
289 | * @param Element_Base|Document $section
290 | */
291 | public function filterSectionContentBefore( $section ): void {
292 | if ( $this->getMode() === 'edit' ) {
293 | return;
294 | }
295 |
296 | $settings = $this->getElementSettings( $section );
297 | $hide = $this->checkCondition( $settings );
298 |
299 | if ( !$hide ) {
300 | return;
301 | }
302 |
303 | $id = get_the_id() .'-'. $section->get_id();
304 | $this->isSectionHidden[$id] = true;
305 |
306 | //prevent shortcodes from execution
307 | $this->shortcodeTags += $GLOBALS['shortcode_tags'];
308 | $GLOBALS['shortcode_tags'] = [];
309 |
310 | ob_start();
311 | }
312 |
313 | /**
314 | * Clean output of section if it is hidden
315 | *
316 | * @param Element_Base|Document $section
317 | */
318 | public function filterSectionContentAfter( $section ): void {
319 | // reset shortcode tags
320 | $GLOBALS['shortcode_tags'] += $this->shortcodeTags;
321 | if ( empty( $section ) ||
322 | empty( $this->isSectionHidden[get_the_id() .'-'. $section->get_id()] )
323 | ) {
324 | return;
325 | }
326 | $id = get_the_id() .'-'. $section->get_id();
327 |
328 | /*while ( ob_get_level() > $this->widgetCache[$section->get_id()]['ob_level'] ) {
329 | ob_end_flush();
330 | }*/
331 |
332 | $content = ob_get_clean();
333 | $matchesLinkTags = [];
334 | $matchesStyleTags = [];
335 |
336 | $type = $section->get_type();
337 | $settings = $this->elementSettings[$id];
338 |
339 | if ( empty( $settings['dynamicconditions_removeStyles'] ) ) {
340 | preg_match_all( '//', $content, $matchesLinkTags );
341 | preg_match_all( '/';
748 | }
749 |
750 | /**
751 | * Returns elementor-mode (edit, preview or website)
752 | */
753 | private function getMode(): string {
754 | if ( !class_exists( 'Elementor\Plugin' ) ) {
755 | return '';
756 | }
757 |
758 | if ( !empty( Plugin::$instance->editor ) && Plugin::$instance->editor->is_edit_mode() ) {
759 | return 'edit';
760 | }
761 |
762 | if ( !empty( Plugin::$instance->preview ) && Plugin::$instance->preview->is_preview_mode() ) {
763 | return 'preview';
764 | }
765 |
766 | return 'website';
767 | }
768 |
769 | /**
770 | * Register the stylesheets for the public-facing side of the site.
771 | *
772 | * @since 1.0.0
773 | */
774 | public function enqueueScripts(): void {
775 | if ( $this->getMode() === 'edit' ) {
776 | return;
777 | }
778 | wp_enqueue_script( $this->pluginName, DynamicConditions_URL . '/Public/js/dynamic-conditions-public.js', [ 'jquery' ], $this->version, true );
779 | }
780 |
781 | }
--------------------------------------------------------------------------------
/trunk/Public/css/debug.css:
--------------------------------------------------------------------------------
1 |
2 | .dynamicconditions-debug {
3 | position: relative;
4 | width: 100%;
5 | background-color: #efefef;
6 | color: #333;
7 | padding: 5px 10px;
8 | font-size: 10px;
9 | font-family: Verdana, Helvetica, sans-serif;
10 | line-height: 16px;
11 | letter-spacing: 0;
12 | margin: 2px 2px;
13 | border: 1px solid #333;
14 | box-sizing: border-box;
15 | }
16 |
17 | .dynamicconditions-debug::before {
18 | content: 'DynamicConditions-Debug';
19 | position: relative;
20 | display: block;
21 | top: 0;
22 | font-size: 9px;
23 | background-color: #ccc;
24 | padding: 0 10px 2px;
25 | color: #333;
26 | border-bottom: 1px solid #999;
27 | margin: -5px -10px 2px;
28 | }
29 |
30 | .dc-debug-row {
31 | position: relative;
32 | }
33 |
34 | .dc-debug-row::after {
35 | content: '';
36 | clear: both;
37 | display: block;
38 | }
39 |
40 | .dc-debug-label {
41 | float: left;
42 | width: 135px;
43 | white-space: nowrap;
44 | }
45 |
46 | .dc-debug-value {
47 | float: left;
48 | }
49 |
50 | .dc-debug-remove {
51 | position: absolute;
52 | right: 5px;
53 | top: 4px;
54 | cursor: pointer;
55 | }
56 |
--------------------------------------------------------------------------------
/trunk/Public/css/dynamic-conditions-public.css:
--------------------------------------------------------------------------------
1 | /**
2 | * All of the CSS for your public-facing functionality should be
3 | * included in this file.
4 | */
--------------------------------------------------------------------------------
/trunk/Public/css/index.php:
--------------------------------------------------------------------------------
1 | .elementor-column';
9 |
10 |
11 | function resizeColumns() {
12 | const $columns = $(dcHiddenSelector);
13 | $columns.each(function(index, column) {
14 | const $column = $(column),
15 | hiddenSize = parseFloat($column.data('size')),
16 | $row = $column.closest(dcRowSelector),
17 | $children = $row.find(dcColumnSelector);
18 |
19 | if ($children.length === 0) {
20 | return;
21 | }
22 |
23 | // get percent-width of row
24 | const rowSize = $children.toArray().reduce(
25 | (acc, child) => acc + calcRowWidth($(child), $row),
26 | 0
27 | );
28 |
29 | $children.each(function(cIndex, child) {
30 | // resize columns
31 | const $child = $(child),
32 | childSize = calcRowWidth($child, $row),
33 | newSize = childSize + (hiddenSize * (childSize / rowSize));
34 |
35 | if (childSize < 100) {
36 | $child.css({width: newSize + '%'});
37 | }
38 | });
39 |
40 | });
41 | }
42 |
43 | function calcRowWidth($child, $row) {
44 | return parseFloat($child.width() / $row.width() * 100);
45 | }
46 |
47 | function resetColumns() {
48 | const $columns = $(dcHiddenSelector);
49 | $columns.each(function(index, column) {
50 | const $children = $(column).closest(dcRowSelector).find(dcColumnSelector);
51 |
52 | // reset width for recalc
53 | $children.css({width: ''});
54 | });
55 | }
56 |
57 | function hideWrappers() {
58 | const $elements = $(dcHideWrapperSelector);
59 | $elements.each(function(index, element) {
60 | const $element = $(element),
61 | $wrapper = $element.closest($element.data('selector'));
62 | $wrapper.css({display: 'none'});
63 | });
64 | }
65 |
66 | function hideOthers() {
67 | const $elements = $(dcHideOthersSelector);
68 | $elements.each(function(index, element) {
69 | const $element = $(element),
70 | $toHide = $($element.data('selector'));
71 | $toHide.css({display: 'none'});
72 | });
73 | }
74 |
75 | $(window).on('resize', function() {
76 | resetColumns();
77 | resizeColumns();
78 | });
79 |
80 | $(window).on('elementor/frontend/init', function() {
81 | resetColumns();
82 | resizeColumns();
83 | hideWrappers();
84 | hideOthers();
85 | });
86 | })(jQuery);
87 |
--------------------------------------------------------------------------------
/trunk/Public/js/index.php:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
26 |
27 |
28 |
DynamicTag-Tag:
29 |
30 |
31 |
32 |
33 |
DynamicTag-Key:
34 |
35 |
36 |
37 |
38 |
DynamicTag-Value:
39 |
40 |
41 |
42 |
DynamicTag-Value-Raw:
43 |
44 |
45 |
46 |
47 |
Check-Value:
48 |
49 |
50 |
51 |
52 |
Check-Value2:
53 |
54 |
55 |
56 |
57 |
Condition-Type:
58 |
59 |
60 |
61 |
62 |
Condition:
63 |
64 |
65 |
66 |
67 |
Condition met:
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/trunk/Public/partials/dynamic-conditions-public-display.php:
--------------------------------------------------------------------------------
1 |
21 |
22 |
--------------------------------------------------------------------------------
/trunk/Public/partials/index.php:
--------------------------------------------------------------------------------
1 | `
169 |
--------------------------------------------------------------------------------
/trunk/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "ext-json": "*"
4 | },
5 | "autoload": {
6 | "psr-4": {
7 | "DynamicConditions\\": "./",
8 | "DynamicConditions\\Pub\\": "Public/",
9 | "Lib\\" :"Legacy/Lib/"
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/trunk/dynamic-conditions.php:
--------------------------------------------------------------------------------
1 |
7 | * Jordi Boggiano
8 | *
9 | * For the full copyright and license information, please view the LICENSE
10 | * file that was distributed with this source code.
11 | */
12 |
13 | namespace Composer\Autoload;
14 |
15 | /**
16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
17 | *
18 | * $loader = new \Composer\Autoload\ClassLoader();
19 | *
20 | * // register classes with namespaces
21 | * $loader->add('Symfony\Component', __DIR__.'/component');
22 | * $loader->add('Symfony', __DIR__.'/framework');
23 | *
24 | * // activate the autoloader
25 | * $loader->register();
26 | *
27 | * // to enable searching the include path (eg. for PEAR packages)
28 | * $loader->setUseIncludePath(true);
29 | *
30 | * In this example, if you try to use a class in the Symfony\Component
31 | * namespace or one of its children (Symfony\Component\Console for instance),
32 | * the autoloader will first look for the class under the component/
33 | * directory, and it will then fallback to the framework/ directory if not
34 | * found before giving up.
35 | *
36 | * This class is loosely based on the Symfony UniversalClassLoader.
37 | *
38 | * @author Fabien Potencier
39 | * @author Jordi Boggiano
40 | * @see http://www.php-fig.org/psr/psr-0/
41 | * @see http://www.php-fig.org/psr/psr-4/
42 | */
43 | class ClassLoader
44 | {
45 | // PSR-4
46 | private $prefixLengthsPsr4 = array();
47 | private $prefixDirsPsr4 = array();
48 | private $fallbackDirsPsr4 = array();
49 |
50 | // PSR-0
51 | private $prefixesPsr0 = array();
52 | private $fallbackDirsPsr0 = array();
53 |
54 | private $useIncludePath = false;
55 | private $classMap = array();
56 | private $classMapAuthoritative = false;
57 | private $missingClasses = array();
58 | private $apcuPrefix;
59 |
60 | public function getPrefixes()
61 | {
62 | if (!empty($this->prefixesPsr0)) {
63 | return call_user_func_array('array_merge', $this->prefixesPsr0);
64 | }
65 |
66 | return array();
67 | }
68 |
69 | public function getPrefixesPsr4()
70 | {
71 | return $this->prefixDirsPsr4;
72 | }
73 |
74 | public function getFallbackDirs()
75 | {
76 | return $this->fallbackDirsPsr0;
77 | }
78 |
79 | public function getFallbackDirsPsr4()
80 | {
81 | return $this->fallbackDirsPsr4;
82 | }
83 |
84 | public function getClassMap()
85 | {
86 | return $this->classMap;
87 | }
88 |
89 | /**
90 | * @param array $classMap Class to filename map
91 | */
92 | public function addClassMap(array $classMap)
93 | {
94 | if ($this->classMap) {
95 | $this->classMap = array_merge($this->classMap, $classMap);
96 | } else {
97 | $this->classMap = $classMap;
98 | }
99 | }
100 |
101 | /**
102 | * Registers a set of PSR-0 directories for a given prefix, either
103 | * appending or prepending to the ones previously set for this prefix.
104 | *
105 | * @param string $prefix The prefix
106 | * @param array|string $paths The PSR-0 root directories
107 | * @param bool $prepend Whether to prepend the directories
108 | */
109 | public function add($prefix, $paths, $prepend = false)
110 | {
111 | if (!$prefix) {
112 | if ($prepend) {
113 | $this->fallbackDirsPsr0 = array_merge(
114 | (array) $paths,
115 | $this->fallbackDirsPsr0
116 | );
117 | } else {
118 | $this->fallbackDirsPsr0 = array_merge(
119 | $this->fallbackDirsPsr0,
120 | (array) $paths
121 | );
122 | }
123 |
124 | return;
125 | }
126 |
127 | $first = $prefix[0];
128 | if (!isset($this->prefixesPsr0[$first][$prefix])) {
129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths;
130 |
131 | return;
132 | }
133 | if ($prepend) {
134 | $this->prefixesPsr0[$first][$prefix] = array_merge(
135 | (array) $paths,
136 | $this->prefixesPsr0[$first][$prefix]
137 | );
138 | } else {
139 | $this->prefixesPsr0[$first][$prefix] = array_merge(
140 | $this->prefixesPsr0[$first][$prefix],
141 | (array) $paths
142 | );
143 | }
144 | }
145 |
146 | /**
147 | * Registers a set of PSR-4 directories for a given namespace, either
148 | * appending or prepending to the ones previously set for this namespace.
149 | *
150 | * @param string $prefix The prefix/namespace, with trailing '\\'
151 | * @param array|string $paths The PSR-4 base directories
152 | * @param bool $prepend Whether to prepend the directories
153 | *
154 | * @throws \InvalidArgumentException
155 | */
156 | public function addPsr4($prefix, $paths, $prepend = false)
157 | {
158 | if (!$prefix) {
159 | // Register directories for the root namespace.
160 | if ($prepend) {
161 | $this->fallbackDirsPsr4 = array_merge(
162 | (array) $paths,
163 | $this->fallbackDirsPsr4
164 | );
165 | } else {
166 | $this->fallbackDirsPsr4 = array_merge(
167 | $this->fallbackDirsPsr4,
168 | (array) $paths
169 | );
170 | }
171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172 | // Register directories for a new namespace.
173 | $length = strlen($prefix);
174 | if ('\\' !== $prefix[$length - 1]) {
175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176 | }
177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
178 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
179 | } elseif ($prepend) {
180 | // Prepend directories for an already registered namespace.
181 | $this->prefixDirsPsr4[$prefix] = array_merge(
182 | (array) $paths,
183 | $this->prefixDirsPsr4[$prefix]
184 | );
185 | } else {
186 | // Append directories for an already registered namespace.
187 | $this->prefixDirsPsr4[$prefix] = array_merge(
188 | $this->prefixDirsPsr4[$prefix],
189 | (array) $paths
190 | );
191 | }
192 | }
193 |
194 | /**
195 | * Registers a set of PSR-0 directories for a given prefix,
196 | * replacing any others previously set for this prefix.
197 | *
198 | * @param string $prefix The prefix
199 | * @param array|string $paths The PSR-0 base directories
200 | */
201 | public function set($prefix, $paths)
202 | {
203 | if (!$prefix) {
204 | $this->fallbackDirsPsr0 = (array) $paths;
205 | } else {
206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
207 | }
208 | }
209 |
210 | /**
211 | * Registers a set of PSR-4 directories for a given namespace,
212 | * replacing any others previously set for this namespace.
213 | *
214 | * @param string $prefix The prefix/namespace, with trailing '\\'
215 | * @param array|string $paths The PSR-4 base directories
216 | *
217 | * @throws \InvalidArgumentException
218 | */
219 | public function setPsr4($prefix, $paths)
220 | {
221 | if (!$prefix) {
222 | $this->fallbackDirsPsr4 = (array) $paths;
223 | } else {
224 | $length = strlen($prefix);
225 | if ('\\' !== $prefix[$length - 1]) {
226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227 | }
228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
229 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
230 | }
231 | }
232 |
233 | /**
234 | * Turns on searching the include path for class files.
235 | *
236 | * @param bool $useIncludePath
237 | */
238 | public function setUseIncludePath($useIncludePath)
239 | {
240 | $this->useIncludePath = $useIncludePath;
241 | }
242 |
243 | /**
244 | * Can be used to check if the autoloader uses the include path to check
245 | * for classes.
246 | *
247 | * @return bool
248 | */
249 | public function getUseIncludePath()
250 | {
251 | return $this->useIncludePath;
252 | }
253 |
254 | /**
255 | * Turns off searching the prefix and fallback directories for classes
256 | * that have not been registered with the class map.
257 | *
258 | * @param bool $classMapAuthoritative
259 | */
260 | public function setClassMapAuthoritative($classMapAuthoritative)
261 | {
262 | $this->classMapAuthoritative = $classMapAuthoritative;
263 | }
264 |
265 | /**
266 | * Should class lookup fail if not found in the current class map?
267 | *
268 | * @return bool
269 | */
270 | public function isClassMapAuthoritative()
271 | {
272 | return $this->classMapAuthoritative;
273 | }
274 |
275 | /**
276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277 | *
278 | * @param string|null $apcuPrefix
279 | */
280 | public function setApcuPrefix($apcuPrefix)
281 | {
282 | $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
283 | }
284 |
285 | /**
286 | * The APCu prefix in use, or null if APCu caching is not enabled.
287 | *
288 | * @return string|null
289 | */
290 | public function getApcuPrefix()
291 | {
292 | return $this->apcuPrefix;
293 | }
294 |
295 | /**
296 | * Registers this instance as an autoloader.
297 | *
298 | * @param bool $prepend Whether to prepend the autoloader or not
299 | */
300 | public function register($prepend = false)
301 | {
302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend);
303 | }
304 |
305 | /**
306 | * Unregisters this instance as an autoloader.
307 | */
308 | public function unregister()
309 | {
310 | spl_autoload_unregister(array($this, 'loadClass'));
311 | }
312 |
313 | /**
314 | * Loads the given class or interface.
315 | *
316 | * @param string $class The name of the class
317 | * @return bool|null True if loaded, null otherwise
318 | */
319 | public function loadClass($class)
320 | {
321 | if ($file = $this->findFile($class)) {
322 | includeFile($file);
323 |
324 | return true;
325 | }
326 | }
327 |
328 | /**
329 | * Finds the path to the file where the class is defined.
330 | *
331 | * @param string $class The name of the class
332 | *
333 | * @return string|false The path if found, false otherwise
334 | */
335 | public function findFile($class)
336 | {
337 | // class map lookup
338 | if (isset($this->classMap[$class])) {
339 | return $this->classMap[$class];
340 | }
341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342 | return false;
343 | }
344 | if (null !== $this->apcuPrefix) {
345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit);
346 | if ($hit) {
347 | return $file;
348 | }
349 | }
350 |
351 | $file = $this->findFileWithExtension($class, '.php');
352 |
353 | // Search for Hack files if we are running on HHVM
354 | if (false === $file && defined('HHVM_VERSION')) {
355 | $file = $this->findFileWithExtension($class, '.hh');
356 | }
357 |
358 | if (null !== $this->apcuPrefix) {
359 | apcu_add($this->apcuPrefix.$class, $file);
360 | }
361 |
362 | if (false === $file) {
363 | // Remember that this class does not exist.
364 | $this->missingClasses[$class] = true;
365 | }
366 |
367 | return $file;
368 | }
369 |
370 | private function findFileWithExtension($class, $ext)
371 | {
372 | // PSR-4 lookup
373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374 |
375 | $first = $class[0];
376 | if (isset($this->prefixLengthsPsr4[$first])) {
377 | $subPath = $class;
378 | while (false !== $lastPos = strrpos($subPath, '\\')) {
379 | $subPath = substr($subPath, 0, $lastPos);
380 | $search = $subPath . '\\';
381 | if (isset($this->prefixDirsPsr4[$search])) {
382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383 | foreach ($this->prefixDirsPsr4[$search] as $dir) {
384 | if (file_exists($file = $dir . $pathEnd)) {
385 | return $file;
386 | }
387 | }
388 | }
389 | }
390 | }
391 |
392 | // PSR-4 fallback dirs
393 | foreach ($this->fallbackDirsPsr4 as $dir) {
394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
395 | return $file;
396 | }
397 | }
398 |
399 | // PSR-0 lookup
400 | if (false !== $pos = strrpos($class, '\\')) {
401 | // namespaced class name
402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404 | } else {
405 | // PEAR-like class name
406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
407 | }
408 |
409 | if (isset($this->prefixesPsr0[$first])) {
410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411 | if (0 === strpos($class, $prefix)) {
412 | foreach ($dirs as $dir) {
413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
414 | return $file;
415 | }
416 | }
417 | }
418 | }
419 | }
420 |
421 | // PSR-0 fallback dirs
422 | foreach ($this->fallbackDirsPsr0 as $dir) {
423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
424 | return $file;
425 | }
426 | }
427 |
428 | // PSR-0 include paths.
429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430 | return $file;
431 | }
432 |
433 | return false;
434 | }
435 | }
436 |
437 | /**
438 | * Scope isolated include.
439 | *
440 | * Prevents access to $this/self from included files.
441 | */
442 | function includeFile($file)
443 | {
444 | include $file;
445 | }
446 |
--------------------------------------------------------------------------------
/trunk/vendor/composer/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) Nils Adermann, Jordi Boggiano
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is furnished
9 | to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 |
22 |
--------------------------------------------------------------------------------
/trunk/vendor/composer/autoload_classmap.php:
--------------------------------------------------------------------------------
1 | array($baseDir . '/Legacy/Lib'),
10 | 'DynamicConditions\\Pub\\' => array($baseDir . '/Public'),
11 | 'DynamicConditions\\' => array($baseDir . '/'),
12 | );
13 |
--------------------------------------------------------------------------------
/trunk/vendor/composer/autoload_real.php:
--------------------------------------------------------------------------------
1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27 | if ($useStaticLoader) {
28 | require_once __DIR__ . '/autoload_static.php';
29 |
30 | call_user_func(\Composer\Autoload\ComposerStaticInit808d05525ff962fd8697790ec816888f::getInitializer($loader));
31 | } else {
32 | $map = require __DIR__ . '/autoload_namespaces.php';
33 | foreach ($map as $namespace => $path) {
34 | $loader->set($namespace, $path);
35 | }
36 |
37 | $map = require __DIR__ . '/autoload_psr4.php';
38 | foreach ($map as $namespace => $path) {
39 | $loader->setPsr4($namespace, $path);
40 | }
41 |
42 | $classMap = require __DIR__ . '/autoload_classmap.php';
43 | if ($classMap) {
44 | $loader->addClassMap($classMap);
45 | }
46 | }
47 |
48 | $loader->register(true);
49 |
50 | return $loader;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/trunk/vendor/composer/autoload_static.php:
--------------------------------------------------------------------------------
1 |
11 | array (
12 | 'Lib\\' => 4,
13 | ),
14 | 'D' =>
15 | array (
16 | 'DynamicConditions\\Pub\\' => 22,
17 | 'DynamicConditions\\' => 18,
18 | ),
19 | );
20 |
21 | public static $prefixDirsPsr4 = array (
22 | 'Lib\\' =>
23 | array (
24 | 0 => __DIR__ . '/../..' . '/Legacy/Lib',
25 | ),
26 | 'DynamicConditions\\Pub\\' =>
27 | array (
28 | 0 => __DIR__ . '/../..' . '/Public',
29 | ),
30 | 'DynamicConditions\\' =>
31 | array (
32 | 0 => __DIR__ . '/../..' . '/',
33 | ),
34 | );
35 |
36 | public static function getInitializer(ClassLoader $loader)
37 | {
38 | return \Closure::bind(function () use ($loader) {
39 | $loader->prefixLengthsPsr4 = ComposerStaticInit808d05525ff962fd8697790ec816888f::$prefixLengthsPsr4;
40 | $loader->prefixDirsPsr4 = ComposerStaticInit808d05525ff962fd8697790ec816888f::$prefixDirsPsr4;
41 |
42 | }, null, ClassLoader::class);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/trunk/vendor/composer/installed.json:
--------------------------------------------------------------------------------
1 | []
2 |
--------------------------------------------------------------------------------