Plugin Directory


Ignore:
Timestamp:
04/16/2024 08:49:52 AM (12 months ago)
Author:
unitecms
Message:

update to 1.5.103 version.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • unlimited-elements-for-elementor/trunk/inc_php/unitecreator_template_engine.class.php

    r3063431 r3071404  
    5151        $arrDynamicSettings = null;
    5252
    53         if($this->isItemsFromPosts == true){
    54 
     53        if($this->isItemsFromPosts === true){
    5554            //HelperProviderUC::startDebugQueries();
    5655
     
    5857
    5958            //save post id
    60 
    6159            $arrItem = UniteFunctionsUC::getVal($itemParams, "item");
    62 
    6360            $postType = UniteFunctionsUC::getVal($arrItem, "object_type");
    64 
    6561            $postID = UniteFunctionsUC::getVal($arrItem, "object_id");
    6662
     
    6864
    6965            //woo commerce global object product save
    70 
    7166            if($postType == "product" && function_exists("wc_get_product")){
    72 
    7367                global $product;
    7468                $product = wc_get_product(GlobalsProviderUC::$lastObjectID);
     
    7670
    7771            //save post to allow dynamic tags inside the item
    78 
    7972            $post = UniteFunctionsUC::getVal(GlobalsProviderUC::$arrFetchedPostsObjectsCache, $postID);
    8073
     
    8275
    8376            if(!empty($post)){
    84 
    8577                self::$isPostIDSaved = true;
    8678
    8779                global $wp_query;
    8880
    89                 //backup the original querified object
     81                //backup the original queried object
    9082                $originalQueriedObject = $wp_query->queried_object;
    9183                self::$originalQueriedObject = $originalQueriedObject;
     
    9486                self::$originalQueriedObjectID = $originalQueriedObjectID;
    9587
    96                 $originalPost = UniteFunctionsUC::getVal($GLOBALS, 'post', null);
     88                $originalPost = UniteFunctionsUC::getVal($GLOBALS, "post", null);
    9789                self::$originalPost = $originalPost;
    9890
     
    10092                $wp_query->queried_object_id = $postID;
    10193
    102                 $GLOBALS['post'] = $post;
     94                $GLOBALS["post"] = $post;
    10395
    10496                //get dynamic settings from the widget if exists
    105 
    106                 $arrDynamicSettings = apply_filters("ue_get_current_widget_settings",array());
    107 
     97                $arrDynamicSettings = apply_filters("ue_get_current_widget_settings", array());
    10898            }
    109 
    110 
    11199        }
    112100
    113101        // handle params and html
    114 
    115102        $params = array_merge($this->arrParams, $itemParams);
    116103
    117         if(!empty($arrDynamicSettings) && is_array($arrDynamicSettings)){
    118 
     104        if(!empty($arrDynamicSettings) && is_array($arrDynamicSettings))
    119105            $params = array_merge($params, $arrDynamicSettings);
    120         }
    121 
    122106
    123107        GlobalsProviderUC::$lastItemParams = $params;
    124108
    125109        $htmlItem = $this->twig->render($templateName, $params);
    126 
    127110        $htmlItem = do_shortcode($htmlItem);
    128111
    129         if(!empty($sap)){
    130             if($index != 0)
    131                 echo UniteProviderFunctionsUC::escCombinedHtml($sap);
    132             echo UniteProviderFunctionsUC::escCombinedHtml($htmlItem);
    133         }else
    134             echo UniteProviderFunctionsUC::escCombinedHtml($htmlItem);
     112        if(!empty($sap) && $index !== 0)
     113            echo UniteProviderFunctionsUC::escCombinedHtml($sap);
     114
     115        echo UniteProviderFunctionsUC::escCombinedHtml($htmlItem);
    135116
    136117        if($newLine)
    137118            echo "\n";
    138119
    139 
    140         if($this->isItemsFromPosts == true){
    141 
     120        if($this->isItemsFromPosts === true){
    142121            GlobalsProviderUC::$isUnderRenderPostItem = false;
    143122
    144123            //restore the original queried object
    145 
    146             if(self::$isPostIDSaved == true){
    147 
     124            if(self::$isPostIDSaved === true){
    148125                $wp_query->queried_object = $originalQueriedObject;
    149126                $wp_query->queried_object_id = $originalQueriedObjectID;
    150                 $GLOBALS['post'] = $originalPost;
     127                $GLOBALS["post"] = $originalPost;
    151128            }
    152 
    153129        }
    154130
    155131        GlobalsProviderUC::$isUnderItem = false;
    156 
    157 
    158132    }
    159133
     
    164138    private function returnSavedPost(){
    165139
    166         if(self::$isPostIDSaved == false)
    167             return(false);
     140        if(self::$isPostIDSaved === false)
     141            return;
    168142
    169143        global $wp_query;
     
    171145        $wp_query->queried_object = self::$originalQueriedObject;
    172146        $wp_query->queried_object_id = self::$originalQueriedObjectID;
    173         $GLOBALS['post'] = self::$originalPost;
     147        $GLOBALS["post"] = self::$originalPost;
    174148
    175149        self::$isPostIDSaved = false;
    176 
    177     }
    178 
     150    }
    179151
    180152    /**
    181153     * put items actually
    182154     */
    183     private function putItemsWork($templateName, $sap=null, $numItem=null){
    184 
    185         if(empty($this->arrItems))
    186             return(false);
    187 
    188         if($this->isTemplateExists($templateName) == false)
    189             return(false);
     155    private function putItemsWork($templateName, $sap = null, $numItem = null){
     156
     157        if(empty($this->arrItems) === true)
     158            return;
     159
     160        if($this->isTemplateExists($templateName) === false)
     161            return;
    190162
    191163        if($numItem !== null){
    192164            $itemParams = UniteFunctionsUC::getVal($this->arrItems, $numItem);
    193             if(empty($itemParams))
    194                 return(false);
    195 
    196             $this->outputItem($numItem, $itemParams, $templateName, $sap, false);
    197 
    198             return(false);
    199         }
    200 
    201         //if sap, then no new line
     165
     166            if(empty($itemParams) === false)
     167                $this->outputItem($numItem, $itemParams, $templateName, $sap, false);
     168
     169            return;
     170        }
     171
     172        // if a sap, then no new line
    202173        $newLine = empty($sap);
    203174
    204         foreach($this->arrItems as $index => $itemParams)
     175        foreach($this->arrItems as $index => $itemParams){
    205176            $this->outputItem($index, $itemParams, $templateName, $sap, $newLine);
    206 
    207     }
    208 
     177        }
     178    }
     179
     180    /**
     181     * check the callable for a forbidden function
     182     */
     183    private function validateFilterCallable($filter, $callable){
     184
     185        $forbiddenFunctions = array("exec", "eval", "system", "shell_exec", "show_source", "passthru", "pcntl_exec", "proc_open");
     186
     187        if(is_string($callable) === true && in_array($callable, $forbiddenFunctions) === true)
     188            UniteFunctionsUC::throwError("Function \"" . $callable . "\" is forbidden for the \"" . $filter . "\" filter.");
     189    }
     190
     191    /**
     192     * "filter" filter
     193     */
     194    public function filter($env, $array, $arrow){
     195
     196        $this->validateFilterCallable("filter", $arrow);
     197
     198        return twig_array_filter($env, $array, $arrow);
     199    }
     200
     201    /**
     202     * "map" filter
     203     */
     204    public function map($env, $array, $arrow){
     205
     206        $this->validateFilterCallable("map", $arrow);
     207
     208        return twig_array_map($env, $array, $arrow);
     209    }
    209210
    210211    /**
     
    222223        }
    223224
    224         //parse the string input
    225 
     225        // parse the string input
    226226        if(is_string($input)){
    227 
    228227            switch($input){
    229                 case "shuffle":     //shuffle items
    230 
     228                case "shuffle": // shuffle items
    231229                    shuffle($this->arrItems);
    232230
    233                     foreach($this->arrItems as $key => $item)
    234                         $this->arrItems[$key][$templateName]["item_index"] = ($key+1);
    235 
     231                    foreach($this->arrItems as $key => $item){
     232                        $this->arrItems[$key][$templateName]["item_index"] = ($key + 1);
     233                    }
    236234                break;
    237                 case "one_random":      //get one random item
     235                case "one_random":    //get one random item
    238236                    shuffle($this->arrItems);
    239237                    $isGetFirst = true;
     
    246244                break;
    247245            }
    248 
    249         }
    250 
    251         //get first item
    252         if($isGetFirst == true && !empty($this->arrItems) && count($this->arrItems) > 1)
     246        }
     247
     248        // get first item
     249        if($isGetFirst === true && !empty($this->arrItems) && count($this->arrItems) > 1)
    253250            $this->arrItems = array($this->arrItems[0]);
    254 
    255251
    256252        $this->putItemsWork($templateName, $sap, $numItem);
     
    14941490            break;
    14951491            case "get_variable":
    1496                
     1492
    14971493                $getVarValue = UniteFunctionsUC::getGetVar($arg1,"",UniteFunctionsUC::SANITIZE_TEXT_FIELD);
    1498                
     1494
    14991495                return($getVarValue);
    15001496            break;
     
    15321528    protected function initTwig_addExtraFunctions(){
    15331529
     1530        //override filters
     1531        $filterFilter = new Twig\TwigFilter("filter", array($this, "filter"), array("needs_environment" => true));
     1532        $filterMap = new Twig\TwigFilter("map", array($this, "map"), array("needs_environment" => true));
     1533
    15341534        //add extra functions
    1535 
    15361535        $putItemsFunction = new Twig\TwigFunction('put_items', array($this,"putItems"));
    15371536        $putItemsFunction2 = new Twig\TwigFunction('put_items2', array($this,"putItems2"));
     
    15981597        $putTestHtml = new Twig\TwigFunction('putTestHTML', array($this,"putTestHTML"));
    15991598
     1599        //override filters
     1600        $this->twig->addFilter($filterFilter);
     1601        $this->twig->addFilter($filterMap);
    16001602
    16011603        //add extra functions
     
    16481650        $this->twig->addFunction($putTestHtml);
    16491651
    1650 
    16511652        //add filters
    16521653        $this->twig->addFilter($filterTruncate);
     
    16571658        $this->twig->addFilter($filterJsonDecode);
    16581659
    1659 
    16601660        //pro functions
    16611661        $this->twig->addFunction($doAction);
     
    16651665
    16661666        $this->initTwig_addExtraFunctionsPro();
    1667 
    16681667    }
    16691668
Note: See TracChangeset for help on using the changeset viewer.