Changeset 3071404 for unlimited-elements-for-elementor/trunk/inc_php/unitecreator_template_engine.class.php
- Timestamp:
- 04/16/2024 08:49:52 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
unlimited-elements-for-elementor/trunk/inc_php/unitecreator_template_engine.class.php
r3063431 r3071404 51 51 $arrDynamicSettings = null; 52 52 53 if($this->isItemsFromPosts == true){ 54 53 if($this->isItemsFromPosts === true){ 55 54 //HelperProviderUC::startDebugQueries(); 56 55 … … 58 57 59 58 //save post id 60 61 59 $arrItem = UniteFunctionsUC::getVal($itemParams, "item"); 62 63 60 $postType = UniteFunctionsUC::getVal($arrItem, "object_type"); 64 65 61 $postID = UniteFunctionsUC::getVal($arrItem, "object_id"); 66 62 … … 68 64 69 65 //woo commerce global object product save 70 71 66 if($postType == "product" && function_exists("wc_get_product")){ 72 73 67 global $product; 74 68 $product = wc_get_product(GlobalsProviderUC::$lastObjectID); … … 76 70 77 71 //save post to allow dynamic tags inside the item 78 79 72 $post = UniteFunctionsUC::getVal(GlobalsProviderUC::$arrFetchedPostsObjectsCache, $postID); 80 73 … … 82 75 83 76 if(!empty($post)){ 84 85 77 self::$isPostIDSaved = true; 86 78 87 79 global $wp_query; 88 80 89 //backup the original queri fied object81 //backup the original queried object 90 82 $originalQueriedObject = $wp_query->queried_object; 91 83 self::$originalQueriedObject = $originalQueriedObject; … … 94 86 self::$originalQueriedObjectID = $originalQueriedObjectID; 95 87 96 $originalPost = UniteFunctionsUC::getVal($GLOBALS, 'post', null);88 $originalPost = UniteFunctionsUC::getVal($GLOBALS, "post", null); 97 89 self::$originalPost = $originalPost; 98 90 … … 100 92 $wp_query->queried_object_id = $postID; 101 93 102 $GLOBALS[ 'post'] = $post;94 $GLOBALS["post"] = $post; 103 95 104 96 //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()); 108 98 } 109 110 111 99 } 112 100 113 101 // handle params and html 114 115 102 $params = array_merge($this->arrParams, $itemParams); 116 103 117 if(!empty($arrDynamicSettings) && is_array($arrDynamicSettings)){ 118 104 if(!empty($arrDynamicSettings) && is_array($arrDynamicSettings)) 119 105 $params = array_merge($params, $arrDynamicSettings); 120 }121 122 106 123 107 GlobalsProviderUC::$lastItemParams = $params; 124 108 125 109 $htmlItem = $this->twig->render($templateName, $params); 126 127 110 $htmlItem = do_shortcode($htmlItem); 128 111 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); 135 116 136 117 if($newLine) 137 118 echo "\n"; 138 119 139 140 if($this->isItemsFromPosts == true){ 141 120 if($this->isItemsFromPosts === true){ 142 121 GlobalsProviderUC::$isUnderRenderPostItem = false; 143 122 144 123 //restore the original queried object 145 146 if(self::$isPostIDSaved == true){ 147 124 if(self::$isPostIDSaved === true){ 148 125 $wp_query->queried_object = $originalQueriedObject; 149 126 $wp_query->queried_object_id = $originalQueriedObjectID; 150 $GLOBALS[ 'post'] = $originalPost;127 $GLOBALS["post"] = $originalPost; 151 128 } 152 153 129 } 154 130 155 131 GlobalsProviderUC::$isUnderItem = false; 156 157 158 132 } 159 133 … … 164 138 private function returnSavedPost(){ 165 139 166 if(self::$isPostIDSaved == false)167 return (false);140 if(self::$isPostIDSaved === false) 141 return; 168 142 169 143 global $wp_query; … … 171 145 $wp_query->queried_object = self::$originalQueriedObject; 172 146 $wp_query->queried_object_id = self::$originalQueriedObjectID; 173 $GLOBALS[ 'post'] = self::$originalPost;147 $GLOBALS["post"] = self::$originalPost; 174 148 175 149 self::$isPostIDSaved = false; 176 177 } 178 150 } 179 151 180 152 /** 181 153 * put items actually 182 154 */ 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; 190 162 191 163 if($numItem !== null){ 192 164 $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 202 173 $newLine = empty($sap); 203 174 204 foreach($this->arrItems as $index => $itemParams) 175 foreach($this->arrItems as $index => $itemParams){ 205 176 $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 } 209 210 210 211 /** … … 222 223 } 223 224 224 //parse the string input 225 225 // parse the string input 226 226 if(is_string($input)){ 227 228 227 switch($input){ 229 case "shuffle": //shuffle items 230 228 case "shuffle": // shuffle items 231 229 shuffle($this->arrItems); 232 230 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 } 236 234 break; 237 case "one_random": //get one random item235 case "one_random": //get one random item 238 236 shuffle($this->arrItems); 239 237 $isGetFirst = true; … … 246 244 break; 247 245 } 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) 253 250 $this->arrItems = array($this->arrItems[0]); 254 255 251 256 252 $this->putItemsWork($templateName, $sap, $numItem); … … 1494 1490 break; 1495 1491 case "get_variable": 1496 1492 1497 1493 $getVarValue = UniteFunctionsUC::getGetVar($arg1,"",UniteFunctionsUC::SANITIZE_TEXT_FIELD); 1498 1494 1499 1495 return($getVarValue); 1500 1496 break; … … 1532 1528 protected function initTwig_addExtraFunctions(){ 1533 1529 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 1534 1534 //add extra functions 1535 1536 1535 $putItemsFunction = new Twig\TwigFunction('put_items', array($this,"putItems")); 1537 1536 $putItemsFunction2 = new Twig\TwigFunction('put_items2', array($this,"putItems2")); … … 1598 1597 $putTestHtml = new Twig\TwigFunction('putTestHTML', array($this,"putTestHTML")); 1599 1598 1599 //override filters 1600 $this->twig->addFilter($filterFilter); 1601 $this->twig->addFilter($filterMap); 1600 1602 1601 1603 //add extra functions … … 1648 1650 $this->twig->addFunction($putTestHtml); 1649 1651 1650 1651 1652 //add filters 1652 1653 $this->twig->addFilter($filterTruncate); … … 1657 1658 $this->twig->addFilter($filterJsonDecode); 1658 1659 1659 1660 1660 //pro functions 1661 1661 $this->twig->addFunction($doAction); … … 1665 1665 1666 1666 $this->initTwig_addExtraFunctionsPro(); 1667 1668 1667 } 1669 1668
Note: See TracChangeset
for help on using the changeset viewer.