Plugin Directory

Changeset 2704875


Ignore:
Timestamp:
04/05/2022 08:26:45 AM (4 years ago)
Author:
Sygnoos
Message:

New version 4.1.5 released

Location:
popup-builder
Files:
359 added
11 edited

Legend:

Unmodified
Added
Removed
  • popup-builder/trunk/com/classes/Ajax.php

    r2688779 r2704875  
    22namespace sgpb;
    33use \ConfigDataHelper;
    4 use \SgpbDataConfig;
    54
    65class Ajax
     
    412411        // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    413412        $newsletterData = isset($_POST['newsletterData']) ? stripslashes_deep($_POST['newsletterData']) : [];
    414         array_walk_recursive($newsletterData, function(&$item){
    415             $item = sanitize_text_field($item);
     413        array_walk_recursive($newsletterData, function(&$item, $k){
     414            if ($k === 'messageBody'){
     415                $item = wp_kses($item, AdminHelper::allowed_html_tags());
     416            } else {
     417                $item = sanitize_text_field($item);
     418            }
    416419        });
    417420        if(isset($newsletterData['testSendingStatus']) && $newsletterData['testSendingStatus'] == 'test') {
     
    619622        check_ajax_referer(SG_AJAX_NONCE, 'nonce_ajax');
    620623
    621         $postTypeName = isset($_POST['searchKey']) ? sanitize_text_field($_POST['searchKey']) : '';
     624        $postTypeName = isset($_POST['searchKey']) ? sanitize_text_field($_POST['searchKey']) : ''; // TODO strongly validate postTypeName example: use ENUM
    622625        $search = isset($_POST['searchTerm']) ? sanitize_text_field($_POST['searchTerm']) : '';
    623         $searchResults = $this->selectFromPost($postTypeName, $search);
     626
     627        switch($postTypeName){
     628            case 'postCategories':
     629                $searchResults  = ConfigDataHelper::getPostsAllCategories('post', [], $search);
     630                break;
     631            case 'postTags':
     632                $searchResults  = ConfigDataHelper::getAllTags($search);
     633                break;
     634            default:
     635                $searchResults = $this->selectFromPost($postTypeName, $search);
     636        }
    624637
    625638        if(isset($_POST['searchCallback'])) {
  • popup-builder/trunk/com/classes/ConditionCreator.php

    r2686454 r2704875  
    364364    }
    365365
     366    private static function isAssociativeArrayOrEmptyString($args)
     367    {
     368        if (gettype($args) === 'string') return true;
     369        if (array() === $args) return false;
     370        return array_keys($args) !== range(0, count($args) - 1);
     371    }
     372
    366373    public static function createRuleField($ruleElementData)
    367374    {
     
    388395
    389396                if (empty($ruleElementData['data'])) {
    390                     $ruleElementData['data'] = $ruleElementData['saved'];
    391                     $savedData = array();
    392 
    393                     if (!empty($ruleElementData['saved'])) {
    394                         $savedData = array_keys($ruleElementData['saved']);
     397                    // this check is for current version update!
     398                    // the old value was a simple array!
     399                    // after update we need to convert them all to a associative array
     400                    // this check will resolve UI issues and also prevent bugs after update-ing the existing popup
     401                    // this change is for post_category and post_tags!
     402                    if (self::isAssociativeArrayOrEmptyString($ruleElementData['saved'])){
     403                        $ruleElementData['data'] = $ruleElementData['saved'];
     404                        $savedData = array();
     405
     406                        if (!empty($ruleElementData['saved'])) {
     407                            $savedData = array_keys($ruleElementData['saved']);
     408                        }
     409                    } else {
     410                        $ruleElementData['data'] = $ruleElementData['saved'];
     411
     412                        if (!empty($ruleElementData['saved'])) {
     413                            if (isset($attr['isPostCategory'])){
     414                                $ruleElementData['data'] = \ConfigDataHelper::getTermsByIds($ruleElementData['saved']);
     415                            } elseif(isset($attr['isPostTag'])) {
     416                                $ruleElementData['data'] = \ConfigDataHelper::getTagsByIds($ruleElementData['saved']);
     417                            }
     418                            $savedData = $ruleElementData['saved'];
     419                        }
    395420                    }
    396421                }
  • popup-builder/trunk/com/classes/PopupChecker.php

    r2686454 r2704875  
    425425
    426426            foreach ($currentPostCategories as $categoryName) {
    427                 if (in_array($categoryName->term_id, $values)) {
     427                if (in_array($categoryName->term_id, $values) || in_array($categoryName->term_id, array_keys($values))) {
    428428                    $isSatisfy = true;
    429429                    break;
     
    470470
    471471            foreach ($tagsObj as $tagObj) {
    472                 if (in_array($tagObj->slug, $selectedTags)) {
     472                if (in_array($tagObj->slug, $selectedTags) || in_array($tagObj->slug, array_keys($postTagsValues))) {
    473473                    $isSatisfy = true;
    474474                    break;
  • popup-builder/trunk/com/classes/PopupLoader.php

    r2672747 r2704875  
    7474            $popupFromUrl = SGPopup::find($getterId, $args);
    7575            if (!empty($popupFromUrl)) {
    76                 global $SGPB_DATA_CONFIG_ARRAY;
    7776                $defaultEvent = array();
    7877                $customDelay = $popupFromUrl->getOptionValue('sgpb-popup-delay');
    79                 $defaultEvent[] = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
     78                $defaultEvent[] = \SgpbDataConfig::websiteDefaultConfigs()[0];
    8079                $defaultEvent[0]['value'] = 0;
    8180                if ($customDelay) {
     
    102101        }
    103102        if (!empty($foundPopup)) {
    104             global $SGPB_DATA_CONFIG_ARRAY;
    105103            if (@$foundPopup->post_type == SG_POPUP_POST_TYPE) {
    106                 $events = $SGPB_DATA_CONFIG_ARRAY['events']['initialData'][0];
    107                 $targets = array($SGPB_DATA_CONFIG_ARRAY['target']['initialData']);
     104                $events = \SgpbDataConfig::websiteDefaultConfigs()['events'][0];
     105                $targets = array(\SgpbDataConfig::websiteDefaultConfigs()['target']);
    108106                // for any targets preview popup should open
    109107                if (!empty($targets[0][0])) {
  • popup-builder/trunk/com/classes/popups/SGPopup.php

    r2686454 r2704875  
    661661                    }
    662662
     663                    if (isset($valueAttrs['isPostCategory'])){
     664                        $targetData[$groupId][$ruleId]['value'] = ConfigDataHelper::getTermsByIds($ruleData['value']);
     665                    } elseif(isset($valueAttrs['isPostTag'])) {
     666                        $targetData[$groupId][$ruleId]['value'] = ConfigDataHelper::getTagsByIds($ruleData['value']);
     667                    }
     668
    663669                    /*
    664670                     * $isNotPostType => false must search inside post types post
  • popup-builder/trunk/com/config/configPackage.php

    r2698835 r2704875  
    44}
    55
    6 define('SG_POPUP_VERSION', '4.1.4');
     6define('SG_POPUP_VERSION', '4.1.5');
    77define('SGPB_POPUP_PKG', SGPB_POPUP_PKG_FREE);
    88define('POPUP_BUILDER_BASENAME', 'popupbuilder-platinum/popup-builder.php');
  • popup-builder/trunk/com/config/dataConfig.php

    r2578665 r2704875  
    6969        $targetDataParams['post_selected'] = apply_filters('sgPopupTargetPostData', array());
    7070        $targetDataParams['page_selected'] = apply_filters('sgPopupTargetPageSelected', array());
    71         $targetDataParams['post_type'] = apply_filters('sgPopupTargetPostType', ConfigDataHelper::getAllCustomPostTypes());
    72         $targetDataParams['post_category'] = apply_filters('sgPopupTargetPostCategory', ConfigDataHelper::getPostsAllCategories());
    73         $targetDataParams['page_type'] = apply_filters('sgPopupTargetPageType', ConfigDataHelper::getPageTypes());
     71        $targetDataParams['post_type'] = apply_filters('sgPopupTargetPostType', array());
     72        $targetDataParams['post_category'] = apply_filters('sgPopupTargetPostCategory', array());
     73        $targetDataParams['page_type'] = apply_filters('sgPopupTargetPageType', array());
    7474        $targetDataParams['page_template'] = apply_filters('sgPopupPageTemplates', array());
    75         $targetDataParams['post_tags_ids'] = apply_filters('sgPopupTags', ConfigDataHelper::getAllTags());
     75        $targetDataParams['post_tags_ids'] = apply_filters('sgPopupTags', array());
    7676        $targetDataParams['everywhere'] = null;
    7777        $targetDataParams['not_rule'] = null;
     
    149149                    'class' => 'js-sg-select2 js-select-ajax',
    150150                    'data-select-class' => 'js-select-ajax',
    151                     'data-select-type' => 'multiple',
     151                    'data-select-type' => 'ajax',
    152152                    'data-value-param' => 'postCategories',
    153153                    'isNotPostType' => true,
     154                    'isPostCategory' => true,
    154155                    'multiple' => 'multiple'
    155156                ),
     
    164165                    'data-select-class' => 'js-select-ajax',
    165166                    'data-select-type' => 'multiple',
    166                     'data-value-param' => 'postCategories',
     167                    'data-value-param' => 'pageTypes',
    167168                    'isNotPostType' => true,
    168169                    'multiple' => 'multiple'
     
    191192                    'class' => 'js-sg-select2 js-select-ajax',
    192193                    'data-select-class' => 'js-select-ajax',
    193                     'data-select-type' => 'multiple',
     194                    'data-select-type' => 'ajax',
    194195                    'data-value-param' => 'postTags',
    195196                    'isNotPostType' => true,
     197                    'isPostTag' => true,
    196198                    'multiple' => 'multiple'
    197199                ),
     
    10311033        $SGPB_TRANSIENT_CONFIG = apply_filters('sgpbAllTransients', $SGPB_TRANSIENT_CONFIG);
    10321034    }
     1035
     1036    /**
     1037     * method to get popup default conditions or other configs
     1038     *
     1039    */
     1040    public static function websiteDefaultConfigs() {
     1041        $configs = array();
     1042        $eventsInitialData = array(
     1043            array('param' => 'load', 'value' => '', 'hiddenOption' => array())
     1044        );
     1045        $targetInitialData = array(
     1046            array('param' => 'everywhere')
     1047        );
     1048        $configs['events'] = apply_filters('sgPopupEventsInitialData', $eventsInitialData);
     1049        $configs['target'] = apply_filters('sgPopupTargetInitialData', $targetInitialData);
     1050
     1051        return $configs;
     1052    }
    10331053}
  • popup-builder/trunk/com/helpers/ConfigDataHelper.php

    r2578665 r2704875  
    33{
    44    public static $customPostType;
     5    public static $allCustomPosts = array();
    56
    67    public static function getPostTypeData($args = array())
     
    3334    }
    3435
     36    /**
     37     * this method is used for to get all other post types
     38     * that may created by another plugins or theme or website owner!
     39     *
     40     * example: download from EDD, product from Woocommerce!
     41     */
    3542    public static function getAllCustomPosts()
    3643    {
     
    4552            unset($allCustomPosts[SG_POPUP_POST_TYPE]);
    4653        }
    47 
    48         return $allCustomPosts;
     54        self::$allCustomPosts = $allCustomPosts;
     55        return $allCustomPosts; // TODO check for usages and remove this line
    4956    }
    5057
     
    5663    private static function addPostTypeToFilters()
    5764    {
     65        self::getAllCustomPosts();
    5866        add_filter('sgPopupTargetParams', array(__CLASS__, 'addPopupTargetParams'), 1, 1);
    5967        add_filter('sgPopupTargetData', array(__CLASS__, 'addPopupTargetData'), 1, 1);
     
    6169        add_filter('sgPopupTargetAttrs', array(__CLASS__, 'addPopupTargetAttrs'), 1, 1);
    6270        add_filter('sgPopupPageTemplates', array(__CLASS__, 'addPopupPageTemplates'), 1, 1);
     71        add_filter('sgPopupTargetPostType', array(__CLASS__, 'getAllCustomPostTypes'), 1, 1);
     72        add_filter('sgPopupTargetPageType', array(__CLASS__, 'getPageTypes'), 1, 1);
    6373    }
    6474
    6575    public static function addPopupTargetParams($targetParams)
    6676    {
    67         $allCustomPostTypes = self::getAllCustomPosts();
     77        $allCustomPostTypes = self::$allCustomPosts;
    6878        // for conditions, to exclude other post types, tags etc.
    6979        if (isset($targetParams['select_role'])) {
     
    8595    public static function addPopupTargetData($targetData)
    8696    {
    87         $allCustomPostTypes = self::getAllCustomPosts();
     97        $allCustomPostTypes = self::$allCustomPosts;
    8898
    8999        foreach ($allCustomPostTypes as $customPostType) {
     
    109119    public static function addPopupTargetTypes($targetTypes)
    110120    {
    111         $allCustomPostTypes = self::getAllCustomPosts();
     121        $allCustomPostTypes = self::$allCustomPosts;
    112122
    113123        foreach ($allCustomPostTypes as $customPostType) {
     
    121131    public static function addPopupTargetAttrs($targetAttrs)
    122132    {
    123         $allCustomPostTypes = self::getAllCustomPosts();
     133        $allCustomPostTypes = self::$allCustomPosts;
    124134
    125135        foreach ($allCustomPostTypes as $customPostType) {
     
    158168    }
    159169
    160     public static function getPostsAllCategories($postType = 'post', $taxonomies = array())
    161     {
    162         $cats = get_transient(SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES);
    163         if ($cats === false) {
    164             $cats =  get_terms(
    165                 array(
    166                     'taxonomy' => $taxonomies,
    167                     'hide_empty' => false,
    168                     'type'      => $postType,
    169                     'orderby'   => 'name',
    170                     'order'     => 'ASC'
    171                 )
    172             );
    173             set_transient(SGPB_TRANSIENT_POPUPS_ALL_CATEGORIES, $cats, SGPB_TRANSIENT_TIMEOUT_WEEK);
    174         }
     170    public static function getPostsAllCategories($postType = 'post', $taxonomies = array(), $search_text = '')
     171    {
     172        $cats =  get_terms(
     173            array(
     174                'taxonomy' => $taxonomies,
     175                'hide_empty' => false,
     176                'type'      => $postType,
     177                'orderby'   => 'name',
     178                'order'     => 'ASC',
     179                'number'    => 200,
     180                'offset'    => 0,
     181                'name__like'    => $search_text
     182            )
     183        );
    175184
    176185        $supportedTaxonomies = array('category');
     
    230239    }
    231240
    232     public static function getAllTags()
     241    public static function getAllTags($search_text = '')
    233242    {
    234243        $allTags = array();
    235244        $tags = get_tags(array(
    236             'hide_empty' => false
     245            'hide_empty' => false,
     246            'name__like' => $search_text
    237247        ));
    238248
     
    241251        }
    242252
     253        return $allTags;
     254    }
     255    public static function getTagsByIds($ids = [])
     256    {
     257        $allTags = array();
     258        $tags = get_tags(array(
     259            'hide_empty' => false,
     260            'include' => $ids
     261        ));
     262        foreach ($tags as $tag) {
     263            $allTags[$tag->slug] = $tag->name;
     264        }
     265        return $allTags;
     266    }
     267
     268    public static function getTermsByIds($ids = array())
     269    {
     270        $allTags = array();
     271        $terms = get_terms(array(
     272            'hide_empty' => false,
     273            'include' => $ids
     274        ));
     275        foreach ($terms as $term) {
     276            $allTags[$term->term_id] = $term->name;
     277        }
    243278        return $allTags;
    244279    }
  • popup-builder/trunk/popup-builder.php

    r2698835 r2704875  
    44* Plugin URI: https://popup-builder.com
    55* Description: The most complete popup plugin. Html, image, iframe, shortcode, video and many other popup types. Manage popup dimensions, effects, themes and more.
    6 * Version: 4.1.4
     6* Version: 4.1.5
    77* Author: Sygnoos
    88* Author URI: https://sygnoos.com
  • popup-builder/trunk/public/js/PopupBuilder.js

    r2505152 r2704875  
    198198        if (typeof popupOptions['sgpb-popup-dimension-mode'] !== 'undefined' && popupOptions['sgpb-popup-dimension-mode'] === 'responsiveMode') {
    199199            var openedPopupWidth = parseInt(window.innerHeight-100);
    200             if (jQuery('.sgpb-popup-builder-content-'+popupId +' iframe').length) {
    201                 jQuery('.sgpb-popup-builder-content-'+popupId).attr('style', 'height:'+openedPopupWidth+'px !important;');
     200            if (e.detail.popupData['sgpb-type'] === 'iframe' || e.detail.popupData['sgpb-type'] === 'video') {
     201                if (jQuery('.sgpb-popup-builder-content-'+popupId +' iframe').length) {
     202                    jQuery('.sgpb-popup-builder-content-'+popupId).attr('style', 'height:'+openedPopupWidth+'px !important;');
     203                }
    202204            }
    203205        }
  • popup-builder/trunk/readme.txt

    r2698837 r2704875  
    99Tested up to: 5.9
    1010Requires PHP: 5.3.3
    11 Stable tag: 4.1.4
     11Stable tag: 4.1.5
    1212License: GPLv2 or later
    1313License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    147147== Changelog ==
    148148
     149= Version 4.1.5 =
     150* Improvement of code, some queries are optimized
     151* Bug fixed related to popup opening issues on iOS devices
     152* Bug fixed related to Newsletter text formatting in testing mode
     153* Bug fixed related to popups that are set to appear on post categories
     154
    149155= Version 4.1.4 =
    150156* Bug fixed related to filenames that contain non ascii characters
     
    520526== Upgrade Notice ==
    521527
    522 Current Version of Popup Builder is 4.1.4
     528Current Version of Popup Builder is 4.1.5
Note: See TracChangeset for help on using the changeset viewer.