├── trunk ├── Legacy │ ├── WeakMap_Fallback.php │ ├── index.php │ └── Lib │ │ ├── index.php │ │ └── DynamicConditionsDate.php ├── index.php ├── vendor │ ├── composer │ │ ├── installed.json │ │ ├── autoload_classmap.php │ │ ├── autoload_namespaces.php │ │ ├── autoload_psr4.php │ │ ├── LICENSE │ │ ├── autoload_static.php │ │ ├── autoload_real.php │ │ └── ClassLoader.php │ └── autoload.php ├── Admin │ ├── index.php │ ├── js │ │ ├── index.php │ │ └── dynamic-conditions-admin.js │ ├── partials │ │ ├── index.php │ │ └── dynamic-conditions-admin-display.php │ ├── css │ │ └── dynamic-conditions-admin.css │ └── DynamicConditionsAdmin.php ├── Lib │ ├── index.php │ ├── DynamicTags │ │ ├── index.php │ │ └── NumberPostsTag.php │ ├── Activator.php │ ├── Deactivator.php │ ├── I18n.php │ ├── Loader.php │ ├── Date.php │ └── DynamicConditions.php ├── Public │ ├── index.php │ ├── css │ │ ├── index.php │ │ ├── dynamic-conditions-public.css │ │ └── debug.css │ ├── js │ │ ├── index.php │ │ └── dynamic-conditions-public.js │ ├── partials │ │ ├── index.php │ │ ├── dynamic-conditions-public-display.php │ │ └── debug.php │ └── DynamicConditionsPublic.php ├── languages │ ├── index.php │ ├── dynamicconditions-de_DE.mo │ ├── dynamicconditions.pot │ └── dynamicconditions-de_DE.po ├── composer.json ├── uninstall.php ├── dynamic-conditions.php ├── README.txt └── LICENSE.txt ├── .gitignore ├── assets ├── icon-256x256.jpg ├── screenshot-1.png └── banner-772x250.jpg └── README.md /trunk/Legacy/WeakMap_Fallback.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Legacy/Lib'), 10 | 'DynamicConditions\\Pub\\' => array($baseDir . '/Public'), 11 | 'DynamicConditions\\' => array($baseDir . '/'), 12 | ); 13 | -------------------------------------------------------------------------------- /trunk/Legacy/Lib/DynamicConditionsDate.php: -------------------------------------------------------------------------------- 1 | 21 | 22 | -------------------------------------------------------------------------------- /trunk/Public/partials/dynamic-conditions-public-display.php: -------------------------------------------------------------------------------- 1 | 21 | 22 | -------------------------------------------------------------------------------- /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/Lib/Activator.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/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/Admin/js/dynamic-conditions-admin.js: -------------------------------------------------------------------------------- 1 | (function( $ ) { 2 | 'use strict'; 3 | 4 | /** 5 | * All of the code for your admin-specific JavaScript source 6 | * should reside in this file. 7 | * 8 | * Note that this assume you're going to use jQuery, so it prepares 9 | * the $ function reference to be used within the scope of this 10 | * function. 11 | * 12 | * From here, you're able to define handlers for when the DOM is 13 | * ready: 14 | * 15 | * $(function() { 16 | * 17 | * }); 18 | * 19 | * Or when the window is loaded: 20 | * 21 | * $( window ).load(function() { 22 | * 23 | * }); 24 | * 25 | * ...and so on. 26 | * 27 | * Remember that ideally, we should not attach any more than a single DOM-ready or window-load handler 28 | * for any particular page. Though other scripts in WordPress core, other plugins, and other themes may 29 | * be doing this, we should try to minimize doing that in our own work. 30 | */ 31 | 32 | })( jQuery ); 33 | -------------------------------------------------------------------------------- /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/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/uninstall.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/Lib/I18n.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/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/dynamic-conditions.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/Public/js/dynamic-conditions-public.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | 'use strict'; 3 | 4 | const dcHiddenSelector = '.dc-hidden-column', 5 | dcHideWrapperSelector = '.dc-hide-wrapper', 6 | dcHideOthersSelector = '.dc-hide-others', 7 | dcRowSelector = '.elementor-row,.elementor-container', 8 | dcColumnSelector = '> .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/languages/dynamicconditions.pot: -------------------------------------------------------------------------------- 1 | #, fuzzy 2 | msgid "" 3 | msgstr "" 4 | "Project-Id-Version: dynamic-conditions\n" 5 | "POT-Creation-Date: 2018-11-07 14:41+0100\n" 6 | "PO-Revision-Date: 2018-11-07 09:30+0100\n" 7 | "Last-Translator: \n" 8 | "Language-Team: \n" 9 | "Language: en\n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Generator: Poedit 2.2\n" 14 | "X-Poedit-Basepath: .\n" 15 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 16 | "X-Poedit-KeywordsList: __;_e\n" 17 | "X-Poedit-SearchPath-0: .\n" 18 | 19 | #: admin/DynamicConditionsAdmin.php:66 20 | msgid "Elementor and Elementor Pro not installed." 21 | msgstr "" 22 | 23 | #: admin/DynamicConditionsAdmin.php:68 24 | msgid "Elementor Pro not installed." 25 | msgstr "" 26 | 27 | #: admin/DynamicConditionsAdmin.php:70 28 | msgid "Elementor not installed." 29 | msgstr "" 30 | 31 | #: admin/DynamicConditionsAdmin.php:93 32 | msgid "Dynamic Conditions" 33 | msgstr "" 34 | 35 | #: admin/DynamicConditionsAdmin.php:103 36 | msgid "Dynamic Tag" 37 | msgstr "" 38 | 39 | #: admin/DynamicConditionsAdmin.php:117 40 | msgid "Select condition field" 41 | msgstr "" 42 | 43 | #: admin/DynamicConditionsAdmin.php:125 44 | msgid "Show/Hide" 45 | msgstr "" 46 | 47 | #: admin/DynamicConditionsAdmin.php:129 48 | msgid "Show when condition met" 49 | msgstr "" 50 | 51 | #: admin/DynamicConditionsAdmin.php:130 52 | msgid "Hide when condition met" 53 | msgstr "" 54 | 55 | #: admin/DynamicConditionsAdmin.php:143 56 | msgid "Condition" 57 | msgstr "" 58 | 59 | #: admin/DynamicConditionsAdmin.php:148 60 | msgid "Is equal to" 61 | msgstr "" 62 | 63 | #: admin/DynamicConditionsAdmin.php:149 64 | msgid "Is not equal to" 65 | msgstr "" 66 | 67 | #: admin/DynamicConditionsAdmin.php:150 68 | msgid "Contains" 69 | msgstr "" 70 | 71 | #: admin/DynamicConditionsAdmin.php:151 72 | msgid "Does not contain" 73 | msgstr "" 74 | 75 | #: admin/DynamicConditionsAdmin.php:152 76 | msgid "Is empty" 77 | msgstr "" 78 | 79 | #: admin/DynamicConditionsAdmin.php:153 80 | msgid "Is not empty" 81 | msgstr "" 82 | 83 | #: admin/DynamicConditionsAdmin.php:154 84 | msgid "Less than" 85 | msgstr "Kleiner als" 86 | 87 | #: admin/DynamicConditionsAdmin.php:155 88 | msgid "Greater than" 89 | msgstr "Größer als" 90 | 91 | #: admin/DynamicConditionsAdmin.php:158 92 | msgid "Select your condition for this widget visibility." 93 | msgstr "" 94 | 95 | #: admin/DynamicConditionsAdmin.php:168 96 | msgid "Conditional value" 97 | msgstr "" 98 | 99 | #: admin/DynamicConditionsAdmin.php:169 100 | msgid "" 101 | "Add your conditional value here if you selected equal to, not equal to or " 102 | "contains on the selection above." 103 | msgstr "" 104 | -------------------------------------------------------------------------------- /trunk/Public/partials/debug.php: -------------------------------------------------------------------------------- 1 | 17 | 18 |
19 |
20 |
Element:
21 |
25 |
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/languages/dynamicconditions-de_DE.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: dynamic-conditions\n" 4 | "POT-Creation-Date: 2018-11-07 09:29+0100\n" 5 | "PO-Revision-Date: 2021-04-02 12:43+0200\n" 6 | "Language-Team: \n" 7 | "MIME-Version: 1.0\n" 8 | "Content-Type: text/plain; charset=UTF-8\n" 9 | "Content-Transfer-Encoding: 8bit\n" 10 | "X-Generator: Poedit 2.4.1\n" 11 | "X-Poedit-Basepath: .\n" 12 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 13 | "X-Poedit-KeywordsList: __;_e\n" 14 | "Last-Translator: \n" 15 | "Language: de\n" 16 | "X-Poedit-SearchPath-0: .\n" 17 | 18 | #: admin/DynamicConditionsAdmin.php:66 19 | msgid "Elementor and Elementor Pro not installed." 20 | msgstr "Elementor und Elementor Pro nicht installiert." 21 | 22 | #: admin/DynamicConditionsAdmin.php:68 23 | msgid "Elementor Pro not installed." 24 | msgstr "Elementor Pro nicht installiert." 25 | 26 | #: admin/DynamicConditionsAdmin.php:70 27 | msgid "Elementor not installed." 28 | msgstr "Elementor nicht installiert." 29 | 30 | #: admin/DynamicConditionsAdmin.php:93 31 | msgid "Dynamic Conditions" 32 | msgstr "Dynamic Conditions" 33 | 34 | #: admin/DynamicConditionsAdmin.php:103 35 | msgid "Dynamic Tag" 36 | msgstr "Dynamic Tag" 37 | 38 | #: admin/DynamicConditionsAdmin.php:117 39 | msgid "Select condition field" 40 | msgstr "Wähle Bedingungsfeld" 41 | 42 | #: admin/DynamicConditionsAdmin.php:125 43 | msgid "Show/Hide" 44 | msgstr "Zeige/Verstecke" 45 | 46 | #: admin/DynamicConditionsAdmin.php:129 47 | msgid "Show when condition met" 48 | msgstr "Zeige wenn Bedingung zutrifft" 49 | 50 | #: admin/DynamicConditionsAdmin.php:130 51 | msgid "Hide when condition met" 52 | msgstr "Verstecke wenn Bedingung zutrifft" 53 | 54 | #: admin/DynamicConditionsAdmin.php:143 55 | msgid "Condition" 56 | msgstr "Bedingung" 57 | 58 | #: admin/DynamicConditionsAdmin.php:148 59 | msgid "Is equal to" 60 | msgstr "Ist identisch zu" 61 | 62 | #: admin/DynamicConditionsAdmin.php:149 63 | msgid "Is not equal to" 64 | msgstr "Ist nicht identisch zu" 65 | 66 | #: admin/DynamicConditionsAdmin.php:150 67 | msgid "Contains" 68 | msgstr "Enthält" 69 | 70 | #: admin/DynamicConditionsAdmin.php:151 71 | msgid "Does not contain" 72 | msgstr "Enthält nicht" 73 | 74 | #: admin/DynamicConditionsAdmin.php:152 75 | msgid "Is empty" 76 | msgstr "Ist leer" 77 | 78 | #: admin/DynamicConditionsAdmin.php:153 79 | msgid "Is not empty" 80 | msgstr "Ist nicht leer" 81 | 82 | #: admin/DynamicConditionsAdmin.php:154 83 | msgid "Less than" 84 | msgstr "Kleiner als" 85 | 86 | #: admin/DynamicConditionsAdmin.php:155 87 | msgid "Greater than" 88 | msgstr "Größer als" 89 | 90 | msgid "Between" 91 | msgstr "Zwischen" 92 | 93 | msgid "Compare Type" 94 | msgstr "Vergleichs-Typ" 95 | 96 | msgid "Date" 97 | msgstr "Datum" 98 | 99 | msgid "Months" 100 | msgstr "Monate" 101 | 102 | msgid "Weekdays" 103 | msgstr "Wochentage" 104 | 105 | #: admin/DynamicConditionsAdmin.php:158 106 | msgid "Select your condition for this widget visibility." 107 | msgstr "Wähle die Bedingung um das Widget anzuzeigen/verstecken." 108 | 109 | msgid "Add a second condition value, if between is selected" 110 | msgstr "Zweite Bedingung falls zwischen gewählt wurde" 111 | 112 | #: admin/DynamicConditionsAdmin.php:168 113 | msgid "Conditional value" 114 | msgstr "Bedingter Wert" 115 | 116 | msgid "Select what do you want to compare" 117 | msgstr "Wähle aus was du vergleichen möchtest" 118 | 119 | #: admin/DynamicConditionsAdmin.php:169 120 | msgid "Add your conditional value to compare here." 121 | msgstr "Gib hier deine Vergleichs-Bedingung an." 122 | 123 | msgid "Supported Date and Time Formats" 124 | msgstr "Unterstützte Datums- und Zeitformate" 125 | 126 | msgid "Hide only content" 127 | msgstr "Verstecke nur den Inhalt" 128 | 129 | msgid "Resize other columns" 130 | msgstr "Vergrößere andere Spalten" 131 | 132 | msgid "If checked, only the inner content will be hidden, so you will see an empty section" 133 | msgstr "Wenn aktiviert, wird nur der innere Inhalt versteckt und eine leere Section angezeigt" 134 | 135 | msgid "Parse shortcodes" 136 | msgstr "Führe Shortcodes aus" 137 | 138 | msgid "In array" 139 | msgstr "Im Array" 140 | 141 | msgid "Use comma-separated values, to check if dynamic-value is equal with one of each item." 142 | msgstr "Verwende Komma-getrennte Werte, um zu prüfen ob der Dynamic-Wert identisch mit dem einzelnem Wert ist." 143 | 144 | msgid "Prevent date parsing" 145 | msgstr "Verhindere Datums-Parsing" 146 | 147 | msgid "Debug-Mode" 148 | msgstr "Debug-Modus" 149 | 150 | msgid "Use comma-separated values, to check if dynamic-value contains one of each item." 151 | msgstr "Verwende Komma-getrennte Werte, um zu prüfen ob der Dynamic-Wert einen der einzelnem Werte enthält." 152 | 153 | msgid "In array contains" 154 | msgstr "Im Array enthält" 155 | 156 | msgid "Hide wrapper" 157 | msgstr "Verstecke Wrapper" 158 | 159 | msgid "Hide other elements" 160 | msgstr "Verstecke andere Elemente" 161 | 162 | msgid "Will hide a parent matching the selector." 163 | msgstr "Versteckt ein Elternelement, welches auf den Selector zutrifft." 164 | 165 | msgid "Will hide all other elements matching the selector." 166 | msgstr "Versteckt alle elements auf welche der Selectior zutrifft." 167 | -------------------------------------------------------------------------------- /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/README.txt: -------------------------------------------------------------------------------- 1 | === Dynamic Conditions === 2 | Contributors: rtowebsites 3 | Donate link: https://www.rto.de 4 | Tags: elementor, conditions, dynamic, fields, rto 5 | Requires at least: 5.0 6 | Requires PHP: 7.4 7 | Tested up to: 6.7 8 | Stable tag: 1.7.5 9 | License: GPLv2 or later 10 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 | 12 | Activates conditions for dynamic tags to show/hide a widget or section. 13 | 14 | == Description == 15 | 16 | Dynamic Conditions is an Elementor addon that adds conditional logic to show or hide different elements. The plugin adds conditions to dynamic tags to show/hide a widget or section. 17 | 18 | The plugin requires Elementor Pro since it uses Dynamic Tags to set the comparison conditions. 19 | 20 | Setting display conditions is easy! Just enter the condition value and compare it to any dynamic tag. If the condition is met, set whether you want to show or hide the element. Can it be more simple? 21 | 22 | Advanced users can set complex conditions - you can check if a field is empty, if it contains some value, if it equals a value, greater/smaller or between a certain value. 23 | 24 | Special thanks to [WPTuts](https://wptuts.co.uk) for making a nice video tutorial: 25 | 26 | https://www.youtube.com/watch?v=bRqW4Oaxtls 27 | 28 | You can support development by contributing to the plugin´s GitHub repository: 29 | 30 | [Github Dynamic Conditions](https://github.com/RTO-Websites/dynamic-conditions) 31 | 32 | = Usage = 33 | 34 | 1. Select a widget or a section. 35 | 2. Go to the Advanced tab. 36 | 3. Click the Dynamic Conditions area. 37 | 4. Set the "Dynamic Tag" field you want to compare to. 38 | 5. Set whether you want to "Show/Hide" the element if the condition is met. 39 | 6. Under the "Condition" field, select what you wish to compare. You can compare whether the field is empty/not-empty, check if it has a specific value or if its value is between two other values. 40 | 7. The "Compare Type" field defines what type of fields do you want to compare. Default compares two strings (text). But if you want to show a widget/section only on Monday or only in December, you can select Days or Month as Compare-Type. 41 | 8. At last you have to enter the value to compare the dynamic-field with. Or two values, if you have selected the "between" condition. 42 | 43 | == Frequently Asked Questions == 44 | = Can I use custom-fields, ACF fields, Pods? = 45 | Yes, all the above are supported and many others supported out-of-the-box by Elementor Pro. 46 | 47 | = Can I set date based conditions? = 48 | Yes, the plugin supports date based conditions, for example current-date or post-date. You can compare dates, days and months. 49 | 50 | = Can I show/hide elements for logged-in or logged-out users? = 51 | Yes, you can set display conditions for logged in or logged out users. Selecting the "user information" dynamic-tag, and set it to "user ID". Now check if it is empty or not. 52 | 53 | = Are my elements only hidden or fully removed? = 54 | The elements will be fully removed from source code, like they are not existing. 55 | Only if you use the experts options to hide also wrappers or other elements, they will only be hidden with css. 56 | 57 | = I´m missing some dynamic tags = 58 | We have developed an other plugin which provides some useful tags. 59 | You can find it here: 60 | [DynamicTags](https://wordpress.org/plugins/dynamictags/) 61 | 62 | 63 | == Screenshots == 64 | 65 | 1. Widget options for conditions 66 | 67 | == Changelog == 68 | = 1.7.5 = 69 | * Fix a potential vulnerability 70 | 71 | = 1.7.4 = 72 | * Fix big issue with loops destroying everything 73 | 74 | = 1.7.3 = 75 | * Fix issue with date-conditions 76 | 77 | = 1.7.2 = 78 | * Fix issue with broken layout caused by weakmap and ob_cache 79 | 80 | = 1.7.1 = 81 | * Hotfix issue when element is no Base_Element 82 | 83 | = 1.7.0 = 84 | * Fix issue with removed css 85 | * Add int as option for compare-type 86 | * Add dashed border for elements with condition in editor 87 | * Add support for php 7.4 again 88 | 89 | = 1.6.3 = 90 | * Fix issue with optimized_control_loading 91 | * Fix php warnings 92 | 93 | = 1.6.2 = 94 | * Fix missing css if elements are hidden 95 | * Hotfix weird php-error on array-to-string-conversion 96 | 97 | = 1.6.1 = 98 | * Fix deprecated warnings 99 | 100 | = 1.6.0 = 101 | * Add support for containers 102 | 103 | = 1.5.1 = 104 | * Fix issue with shortcodes 105 | 106 | = 1.5.0 = 107 | * Add option to hide wrappers and other elements by selector (javascript only) 108 | * Add new compare type "in_array_contains" 109 | * Fix error when elementor is disabled 110 | * Styling dynamic-tag field 111 | * Prevent shortcode-execution on hidden elements 112 | * Make condition value dynamic 113 | 114 | = 1.4.5 = 115 | * Fix some issues with date-parsing 116 | * Add option to disable date-parsing 117 | 118 | = 1.4.4 = 119 | * Fix issues with parsing of dates from shortcodes 120 | * Fix issue with Elementor 2.9 121 | 122 | = 1.4.3 = 123 | * Fix issue with popups in editor 124 | * Fix double slash on javascript-enqueue 125 | 126 | = 1.4.2 = 127 | * Fix issue with popups in preview 128 | 129 | = 1.4.1 = 130 | * Fix issue with calculation of hidden columns 131 | 132 | = 1.4.0 = 133 | * Add array conditions 134 | * Add conditions for popups 135 | * Change code-structure 136 | * Fix issues with day-/month-translation 137 | 138 | = 1.3.0 = 139 | * Improve parsing of acf dates 140 | * Add icon to elements with condition in preview 141 | * Add option to parse shortcodes 142 | * Fix some issues 143 | 144 | = 1.2.1 = 145 | * Fix issue with date timestamp in custom skins 146 | * Improve performance 147 | 148 | = 1.2.0 = 149 | * Add condition between 150 | * Add date, day and month compare options 151 | * Add NumberPostsTag 152 | * Add short documentation 153 | * Add debug-mode 154 | 155 | = 1.1.2 = 156 | * Fix issue with section 157 | 158 | = 1.1 = 159 | * Add condition greater and less than 160 | 161 | = 1.0.1 = 162 | * Fix sections 163 | * Some refactoring 164 | 165 | = 1.0 = 166 | * Release 167 | 168 | `` 169 | -------------------------------------------------------------------------------- /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/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/vendor/composer/ClassLoader.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/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 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/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( '

DynamicConditions: %2$s

', 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/Public/DynamicConditionsPublic.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( '//s', $content, $matchesStyleTags ); 342 | echo implode( '', $matchesLinkTags[0] ); 343 | echo implode( '', $matchesStyleTags[0] ); 344 | } 345 | 346 | if ( !empty( $settings['dynamicconditions_hideContentOnly'] ) ) { 347 | // render wrapper 348 | $section->before_render(); 349 | $section->after_render(); 350 | } else if ( $type == 'column' && $settings['dynamicconditions_resizeOtherColumns'] ) { 351 | echo '
'; 352 | } 353 | 354 | if ( !empty( $settings['dynamicconditions_hideWrapper'] ) ) { 355 | echo '
'; 356 | } 357 | 358 | if ( !empty( $settings['dynamicconditions_hideOthers'] ) ) { 359 | echo '
'; 360 | } 361 | 362 | echo ""; 363 | } 364 | 365 | /** 366 | * Checks condition, return if element is hidden 367 | */ 368 | public function checkCondition( array $settings ): bool { 369 | if ( !$this->hasCondition( $settings ) ) { 370 | return false; 371 | } 372 | 373 | if ( $this->getMode() === 'edit' ) { 374 | return false; 375 | } 376 | /*if ( filter_input( INPUT_SERVER, 'REQUEST_METHOD' ) === 'POST' ) { 377 | return false; 378 | }*/ 379 | 380 | // loop values 381 | $condition = $this->loopValues( $settings ); 382 | 383 | $hide = false; 384 | 385 | $visibility = self::checkEmpty( $settings, 'dynamicconditions_visibility', 'hide' ); 386 | switch ( $visibility ) { 387 | case 'show': 388 | if ( !$condition ) { 389 | $hide = true; 390 | } 391 | break; 392 | case 'hide': 393 | default: 394 | if ( $condition ) { 395 | $hide = true; 396 | } 397 | break; 398 | } 399 | 400 | return $hide; 401 | } 402 | 403 | /** 404 | * Loop widget-values and check the condition 405 | */ 406 | private function loopValues( array $settings ): bool { 407 | $condition = false; 408 | $dynamicTagValueArray = self::checkEmpty( $settings, 'dynamicconditions_dynamic' ); 409 | 410 | if ( !is_array( $dynamicTagValueArray ) ) { 411 | $dynamicTagValueArray = [ $dynamicTagValueArray ]; 412 | } 413 | 414 | // get value form conditions 415 | $compareType = self::checkEmpty( $settings, 'dynamicconditions_type', 'default' ); 416 | $checkValues = $this->getCheckValue( $compareType, $settings ); 417 | $checkValue = $checkValues[0]; 418 | $checkValue2 = $checkValues[1]; 419 | 420 | $debugValue = ''; 421 | 422 | foreach ( $dynamicTagValueArray as $dynamicTagValue ) { 423 | if ( is_array( $dynamicTagValue ) ) { 424 | if ( !empty( $dynamicTagValue['id'] ) ) { 425 | $dynamicTagValue = wp_get_attachment_url( $dynamicTagValue['id'] ); 426 | } else { 427 | continue; 428 | } 429 | } 430 | 431 | if ( !empty( $settings['dynamicconditions_parse_shortcodes'] ) ) { 432 | $dynamicTagValue = do_shortcode( $dynamicTagValue ); 433 | } 434 | 435 | // parse value based on compare-type 436 | $this->parseDynamicTagValue( $dynamicTagValue, $compareType ); 437 | 438 | $debugValue .= $dynamicTagValue . '~~*#~~'; 439 | 440 | // compare widget-value with check-values 441 | $compareValues = $this->compareValues( $settings['dynamicconditions_condition'], $dynamicTagValue, $checkValue, $checkValue2 ); 442 | $condition = $compareValues[0]; 443 | $break = $compareValues[1]; 444 | $breakFalse = $compareValues[2]; 445 | 446 | if ( $break && $condition ) { 447 | // break if condition is true 448 | break; 449 | } 450 | 451 | if ( $breakFalse && !$condition ) { 452 | // break if condition is false 453 | break; 454 | } 455 | } 456 | 457 | // debug output 458 | $this->renderDebugInfo( $settings, $debugValue, $checkValue, $checkValue2, $condition ); 459 | 460 | return $condition; 461 | } 462 | 463 | /** 464 | * Compare values 465 | * 466 | * @param $compare 467 | * @param $dynamicTagValue 468 | * @param $checkValue 469 | * @param $checkValue2 470 | * @return array 471 | */ 472 | private function compareValues( $compare, $dynamicTagValue, $checkValue, $checkValue2 ): array { 473 | $break = false; 474 | $breakFalse = false; 475 | $condition = false; 476 | if ( is_null( $dynamicTagValue ) ) { 477 | $dynamicTagValue = ''; 478 | } 479 | 480 | switch ( $compare ) { 481 | case 'equal': 482 | $condition = $checkValue == $dynamicTagValue; 483 | $break = true; 484 | break; 485 | 486 | case 'not_equal': 487 | $condition = $checkValue != $dynamicTagValue; 488 | $breakFalse = true; 489 | break; 490 | 491 | case 'contains': 492 | if ( empty( $checkValue ) ) { 493 | break; 494 | } 495 | $condition = strpos( $dynamicTagValue, $checkValue ) !== false; 496 | $break = true; 497 | break; 498 | 499 | case 'not_contains': 500 | if ( empty( $checkValue ) ) { 501 | break; 502 | } 503 | $condition = strpos( $dynamicTagValue, $checkValue ) === false; 504 | $breakFalse = true; 505 | break; 506 | 507 | case 'empty': 508 | $condition = empty( $dynamicTagValue ); 509 | $breakFalse = true; 510 | break; 511 | 512 | case 'not_empty': 513 | $condition = !empty( $dynamicTagValue ); 514 | $break = true; 515 | break; 516 | 517 | case 'less': 518 | if ( is_numeric( $dynamicTagValue ) ) { 519 | $condition = $dynamicTagValue < $checkValue; 520 | } else { 521 | $condition = strlen( $dynamicTagValue ) < strlen( $checkValue ); 522 | } 523 | $break = true; 524 | break; 525 | 526 | case 'greater': 527 | if ( is_numeric( $dynamicTagValue ) ) { 528 | $condition = $dynamicTagValue > $checkValue; 529 | } else { 530 | $condition = strlen( $dynamicTagValue ) > strlen( $checkValue ); 531 | } 532 | $break = true; 533 | break; 534 | 535 | case 'between': 536 | $condition = $dynamicTagValue >= $checkValue && $dynamicTagValue <= $checkValue2; 537 | $break = true; 538 | break; 539 | 540 | case 'in_array': 541 | $condition = in_array( $dynamicTagValue, explode( ',', $checkValue ) ) !== false; 542 | $break = true; 543 | break; 544 | 545 | case 'in_array_contains': 546 | foreach ( explode( ',', $checkValue ) as $toCheck ) { 547 | $condition = strpos( $dynamicTagValue, $toCheck ) !== false; 548 | if ( $condition ) { 549 | break; 550 | } 551 | } 552 | $break = true; 553 | break; 554 | } 555 | 556 | return [ 557 | $condition, 558 | $break, 559 | $breakFalse, 560 | ]; 561 | } 562 | 563 | /** 564 | * Parse value of widget to timestamp, day or month 565 | */ 566 | private function parseDynamicTagValue( ?string &$dynamicTagValue, string $compareType ): void { 567 | switch ( $compareType ) { 568 | case 'days': 569 | $dynamicTagValue = date( 'N', Date::stringToTime( $dynamicTagValue ) ); 570 | break; 571 | 572 | case 'months': 573 | $dynamicTagValue = date( 'n', Date::stringToTime( $dynamicTagValue ) ); 574 | break; 575 | 576 | case 'int': 577 | $dynamicTagValue = (int)filter_var( $dynamicTagValue, FILTER_SANITIZE_NUMBER_INT ); 578 | break; 579 | 580 | case 'strtotime': 581 | // nobreak 582 | case 'date': 583 | $dynamicTagValue = Date::stringToTime( $dynamicTagValue ); 584 | break; 585 | } 586 | } 587 | 588 | /** 589 | * Get value to compare 590 | */ 591 | private function getCheckValue( string $compareType, array $settings ): array { 592 | 593 | switch ( $compareType ) { 594 | case 'days': 595 | if ( $settings['dynamicconditions_condition'] === 'in_array' ) { 596 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_day_array_value' ); 597 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 598 | $checkValue = implode( ',', $checkValue ); 599 | } else { 600 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_day_value' ); 601 | $checkValue = $this->parseShortcode( $checkValue ); 602 | } 603 | $checkValue2 = self::checkEmpty( $settings, 'dynamicconditions_day_value2' ); 604 | $checkValue2 = $this->parseShortcode( $checkValue2, $settings ); 605 | $checkValue = Date::unTranslateDate( $checkValue ); 606 | $checkValue2 = Date::unTranslateDate( $checkValue2 ); 607 | break; 608 | 609 | case 'months': 610 | if ( $settings['dynamicconditions_condition'] === 'in_array' ) { 611 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_month_array_value' ); 612 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 613 | $checkValue = implode( ',', $checkValue ); 614 | } else { 615 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_month_value' ); 616 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 617 | } 618 | $checkValue2 = self::checkEmpty( $settings, 'dynamicconditions_month_value2' ); 619 | $checkValue2 = $this->parseShortcode( $checkValue2, $settings ); 620 | $checkValue = Date::unTranslateDate( $checkValue ); 621 | $checkValue2 = Date::unTranslateDate( $checkValue2 ); 622 | break; 623 | 624 | case 'date': 625 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_date_value' ); 626 | $checkValue2 = self::checkEmpty( $settings, 'dynamicconditions_date_value2' ); 627 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 628 | $checkValue2 = $this->parseShortcode( $checkValue2, $settings ); 629 | $checkValue = Date::stringToTime( $checkValue ); 630 | $checkValue2 = Date::stringToTime( $checkValue2 ); 631 | break; 632 | 633 | case 'strtotime': 634 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_value' ); 635 | $checkValue2 = self::checkEmpty( $settings, 'dynamicconditions_value2' ); 636 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 637 | $checkValue2 = $this->parseShortcode( $checkValue2, $settings ); 638 | $checkValue = Date::stringToTime( $checkValue ); 639 | $checkValue2 = Date::stringToTime( $checkValue2 ); 640 | break; 641 | 642 | case 'int': 643 | $checkValue = (int)filter_var( self::checkEmpty( $settings, 'dynamicconditions_value' ), FILTER_SANITIZE_NUMBER_INT ); 644 | $checkValue2 = (int)filter_var( self::checkEmpty( $settings, 'dynamicconditions_value2' ), FILTER_SANITIZE_NUMBER_INT ); 645 | break; 646 | 647 | case 'default': 648 | default: 649 | $checkValue = self::checkEmpty( $settings, 'dynamicconditions_value' ); 650 | $checkValue2 = self::checkEmpty( $settings, 'dynamicconditions_value2' ); 651 | $checkValue = $this->parseShortcode( $checkValue, $settings ); 652 | $checkValue2 = $this->parseShortcode( $checkValue2, $settings ); 653 | break; 654 | } 655 | 656 | return [ 657 | $checkValue, 658 | $checkValue2, 659 | ]; 660 | } 661 | 662 | /** 663 | * Parse shortcode if active 664 | * @return mixed 665 | */ 666 | private function parseShortcode( $value, array $settings = [] ) { 667 | if ( !is_string( $value ) ) { 668 | return $value; 669 | } 670 | if ( empty( $settings['dynamicconditions_parse_shortcodes'] ) ) { 671 | return $value; 672 | } 673 | return do_shortcode( $value ); 674 | } 675 | 676 | /** 677 | * Checks if an array or entry in array is empty and return its value 678 | * @return mixed 679 | */ 680 | public static function checkEmpty( array $array = [], ?string $key = null, ?string $fallback = null ) { 681 | if ( empty( $key ) ) { 682 | return !empty( $array ) ? $array : $fallback; 683 | } 684 | 685 | return !empty( $array[$key] ) ? $array[$key] : $fallback; 686 | } 687 | 688 | /** 689 | * Checks if element has a condition 690 | */ 691 | public function hasCondition( array $settings ): bool { 692 | if ( empty( $settings['dynamicconditions_condition'] ) || empty( $settings['dynamicConditionsData']['selectedTag'] ) 693 | ) { 694 | // no condition or no tag selected - disable conditions 695 | return false; 696 | } 697 | 698 | return true; 699 | } 700 | 701 | /** 702 | * Renders debug info 703 | * 704 | * @param $settings 705 | * @param $dynamicTagValue 706 | * @param $checkValue 707 | * @param $checkValue2 708 | * @param $conditionMets 709 | */ 710 | private function renderDebugInfo( $settings, $dynamicTagValue, $checkValue, $checkValue2, $conditionMets ): void { 711 | if ( !$settings['dynamicconditions_debug'] ) { 712 | return; 713 | } 714 | 715 | if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { 716 | return; 717 | } 718 | 719 | $visibility = self::checkEmpty( $settings, 'dynamicconditions_visibility', 'hide' ); 720 | 721 | $dynamicTagValue = str_replace( '[', '[', htmlentities( $dynamicTagValue ?? '' ) ); 722 | $dynamicTagValue = str_replace( '~~*#~~', '
', $dynamicTagValue ); 723 | $checkValue = str_replace( '[', '[', htmlentities( $checkValue ?? '' ) ); 724 | $checkValue2 = str_replace( '[', '[', htmlentities( $checkValue2 ?? '' ) ); 725 | $dynamicTagValueRaw = self::checkEmpty( $settings, 'dynamicconditions_dynamic_raw', '' ); 726 | 727 | if ( is_array( $dynamicTagValueRaw ) ) { 728 | $dynamicTagValueRaw = json_encode( $dynamicTagValueRaw ); 729 | } 730 | 731 | include( 'partials/debug.php' ); 732 | 733 | $this->renderDebugCss(); 734 | } 735 | 736 | /** 737 | * Renders css for debug-output 738 | */ 739 | private function renderDebugCss(): void { 740 | if ( self::$debugCssRendered ) { 741 | return; 742 | } 743 | self::$debugCssRendered = true; 744 | 745 | echo ''; 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 | } --------------------------------------------------------------------------------