| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Unlimited Elements |
|---|
| 4 | * @author unlimited-elements.com |
|---|
| 5 | * @copyright (C) 2021 Unlimited Elements, All Rights Reserved. |
|---|
| 6 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
|---|
| 7 | * */ |
|---|
| 8 | if ( ! defined( 'ABSPATH' ) ) exit; |
|---|
| 9 | |
|---|
| 10 | class UniteCreatorAddons extends UniteElementsBaseUC{ |
|---|
| 11 | |
|---|
| 12 | protected function a_STATIC_METHODS(){ |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * get addons thumbnails |
|---|
| 17 | */ |
|---|
| 18 | public function getArrAddonPreviewUrls($arrAddons, $keyType){ |
|---|
| 19 | |
|---|
| 20 | $arrPreviews = array(); |
|---|
| 21 | |
|---|
| 22 | foreach($arrAddons as $addon){ |
|---|
| 23 | switch($keyType){ |
|---|
| 24 | case "title": |
|---|
| 25 | $key = $addon->getTitle(); |
|---|
| 26 | break; |
|---|
| 27 | default: |
|---|
| 28 | $key = $addon->getName(); |
|---|
| 29 | break; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | $urlPreview = $addon->getPreviewImageUrl(); |
|---|
| 33 | |
|---|
| 34 | if(empty($urlPreview)) |
|---|
| 35 | continue; |
|---|
| 36 | |
|---|
| 37 | $urlPreview = HelperUC::URLtoAssetsRelative($urlPreview); |
|---|
| 38 | |
|---|
| 39 | $arrPreviews[$key] = $urlPreview; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | return ($arrPreviews); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | /** |
|---|
| 47 | * get active filter where string |
|---|
| 48 | */ |
|---|
| 49 | public static function getFilterActiveWhere($filterActive = null, $prefix = null, $addonType = ""){ |
|---|
| 50 | |
|---|
| 51 | if($filterActive === null) |
|---|
| 52 | $filterActive = UniteCreatorManagerAddons::getStateFilterActive($addonType); |
|---|
| 53 | |
|---|
| 54 | $where = ""; |
|---|
| 55 | |
|---|
| 56 | //set active fitler where |
|---|
| 57 | switch($filterActive){ |
|---|
| 58 | case "active": |
|---|
| 59 | $where = "is_active=1"; |
|---|
| 60 | break; |
|---|
| 61 | case "not_active": |
|---|
| 62 | $where = "is_active=0"; |
|---|
| 63 | break; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | if(!empty($where) && !empty($prefix)) |
|---|
| 67 | $where = $prefix . "." . $where; |
|---|
| 68 | |
|---|
| 69 | return ($where); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | protected function a______GETTERS_________(){ |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * |
|---|
| 77 | * get items by id's |
|---|
| 78 | */ |
|---|
| 79 | private function getAddonsByIDs($addonIDs){ |
|---|
| 80 | |
|---|
| 81 | $strAddons = implode(",", $addonIDs); |
|---|
| 82 | |
|---|
| 83 | UniteFunctionsUC::validateIDsList($strAddons,"addons id's"); |
|---|
| 84 | |
|---|
| 85 | $tableAddons = GlobalsUC::$table_addons; |
|---|
| 86 | $sql = "select * from {$tableAddons} where id in({$strAddons})"; |
|---|
| 87 | $arrAddons = $this->db->fetchSql($sql); |
|---|
| 88 | |
|---|
| 89 | return ($arrAddons); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * get html of categories and items. |
|---|
| 94 | */ |
|---|
| 95 | protected function getCatsAndAddonsHtml($catID, $type, $data = null, $parentID = null){ |
|---|
| 96 | |
|---|
| 97 | $objManager = UniteCreatorManager::getObjManagerByAddonType($type, $data); |
|---|
| 98 | |
|---|
| 99 | $options = array(); |
|---|
| 100 | if(!empty($parentID)) |
|---|
| 101 | $options["parent_id"] = $parentID; |
|---|
| 102 | |
|---|
| 103 | $response = $objManager->getCatsAndAddonsHtml($catID, "", false, $options); |
|---|
| 104 | |
|---|
| 105 | return ($response); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * |
|---|
| 110 | * get layouts array |
|---|
| 111 | */ |
|---|
| 112 | public function getArrAddonsShort($order = "", $params = array(), $addonType = null){ |
|---|
| 113 | |
|---|
| 114 | if(empty($params)) |
|---|
| 115 | $params = array(); |
|---|
| 116 | |
|---|
| 117 | if(!empty($addonType)) |
|---|
| 118 | $params["addontype"] = $addonType; |
|---|
| 119 | |
|---|
| 120 | $arrWhere = array(); |
|---|
| 121 | |
|---|
| 122 | $filterNames = UniteFunctionsUC::getVal($params, "filter_names"); |
|---|
| 123 | if(!empty($filterNames)){ |
|---|
| 124 | $strNames = "'" . implode("','", $filterNames) . "'"; |
|---|
| 125 | $arrWhere[] = "name in ($strNames)"; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | $addonType = UniteFunctionsUC::getVal($params, "addontype"); |
|---|
| 129 | |
|---|
| 130 | $filterActive = UniteFunctionsUC::getVal($params, "filter_active"); |
|---|
| 131 | if(!empty($filterActive)) |
|---|
| 132 | $arrWhere[] = self::getFilterActiveWhere($filterActive, null, $addonType); |
|---|
| 133 | |
|---|
| 134 | $arrWhere[] = $this->db->getSqlAddonType($addonType); |
|---|
| 135 | |
|---|
| 136 | $where = ""; |
|---|
| 137 | if(!empty($arrWhere)) |
|---|
| 138 | $where = implode(" and ", $arrWhere); |
|---|
| 139 | |
|---|
| 140 | $response = $this->db->fetch(GlobalsUc::$table_addons, $where, $order); |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | return ($response); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | /** |
|---|
| 148 | * get addons list with name / title |
|---|
| 149 | */ |
|---|
| 150 | public function getArrAddonsNameTitle($order = "", $params = array(), $addonType = null, $isAlias = false){ |
|---|
| 151 | |
|---|
| 152 | $arrAddons = $this->getArrAddonsShort($order, $params, $addonType); |
|---|
| 153 | |
|---|
| 154 | $field = "name"; |
|---|
| 155 | if($isAlias == true) |
|---|
| 156 | $field = "alias"; |
|---|
| 157 | |
|---|
| 158 | $arrAssoc = UniteFunctionsUC::arrayToAssoc($arrAddons, $field, "title"); |
|---|
| 159 | |
|---|
| 160 | return ($arrAssoc); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * |
|---|
| 165 | * get addons array |
|---|
| 166 | */ |
|---|
| 167 | public function getArrAddons($order = "", $params = array(), $addonType = null){ |
|---|
| 168 | |
|---|
| 169 | if(empty($params)) |
|---|
| 170 | $params = array(); |
|---|
| 171 | |
|---|
| 172 | $response = $this->getArrAddonsShort($order, $params, $addonType); |
|---|
| 173 | |
|---|
| 174 | $arrAddons = array(); |
|---|
| 175 | foreach($response as $record){ |
|---|
| 176 | $objAddon = new UniteCreatorAddon(); |
|---|
| 177 | $objAddon->initByDBRecord($record); |
|---|
| 178 | $arrAddons[] = $objAddon; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | return ($arrAddons); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | /** |
|---|
| 185 | * |
|---|
| 186 | * get category items |
|---|
| 187 | */ |
|---|
| 188 | public function getCatAddons($catID, $isShort = false, $filterActive = null, $addonType = null, $includeImages = false, $extra = array()){ |
|---|
| 189 | |
|---|
| 190 | $arrWhere = array(); |
|---|
| 191 | |
|---|
| 192 | if(is_numeric($catID)) |
|---|
| 193 | $catID = (int)$catID; |
|---|
| 194 | |
|---|
| 195 | if($catID === null) |
|---|
| 196 | $catID = "all"; |
|---|
| 197 | |
|---|
| 198 | //get catID where |
|---|
| 199 | if($catID === "all"){ |
|---|
| 200 | $arrWhere = array(); |
|---|
| 201 | }elseif(is_numeric($catID)){ |
|---|
| 202 | $catID = (int)$catID; |
|---|
| 203 | $arrWhere[] = "catid=$catID"; |
|---|
| 204 | }else{ //multiple - array of id's |
|---|
| 205 | |
|---|
| 206 | if(is_array($catID) == false) |
|---|
| 207 | UniteFunctionsUC::throwError("catIDs could be array or number"); |
|---|
| 208 | |
|---|
| 209 | $strCats = implode(",", $catID); |
|---|
| 210 | $strCats = $this->db->escape($strCats); //for any case |
|---|
| 211 | $arrWhere[] = "catid in($strCats)"; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | $whereFilterActive = self::getFilterActiveWhere($filterActive, null, $addonType); |
|---|
| 215 | if(!empty($whereFilterActive)) |
|---|
| 216 | $arrWhere[] = $whereFilterActive; |
|---|
| 217 | |
|---|
| 218 | //set addon type - if specific category - no need |
|---|
| 219 | if(is_numeric($catID) == false || empty($catID) || $catID === "all") |
|---|
| 220 | $arrWhere[] = $this->db->getSqlAddonType($addonType); |
|---|
| 221 | |
|---|
| 222 | $filterSearch = UniteFunctionsUC::getVal($extra, "filter_search"); |
|---|
| 223 | $filterSearch = trim($filterSearch); |
|---|
| 224 | |
|---|
| 225 | if(!empty($filterSearch)){ |
|---|
| 226 | $filterSearch = $this->db->escape($filterSearch); |
|---|
| 227 | $filterSearch = strtolower($filterSearch); |
|---|
| 228 | |
|---|
| 229 | $arrWhere[] = "title like '%$filterSearch%'"; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | $where = ""; |
|---|
| 233 | if(!empty($arrWhere)) |
|---|
| 234 | $where = implode(" and ", $arrWhere); |
|---|
| 235 | |
|---|
| 236 | $records = $this->db->fetch(GlobalsUC::$table_addons, $where, "catid, ordering"); |
|---|
| 237 | |
|---|
| 238 | $arrAddons = array(); |
|---|
| 239 | foreach($records as $record){ |
|---|
| 240 | $objAddon = new UniteCreatorAddon(); |
|---|
| 241 | $objAddon->initByDBRecord($record); |
|---|
| 242 | |
|---|
| 243 | if($isShort == true){ |
|---|
| 244 | $arrAddons[] = $objAddon->getArrShort($includeImages); |
|---|
| 245 | }else{ |
|---|
| 246 | $arrAddons[] = $objAddon; |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | return ($arrAddons); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | /** |
|---|
| 254 | * remove non found categories |
|---|
| 255 | * with 0 addons or if title not match |
|---|
| 256 | */ |
|---|
| 257 | private function getAddonsWidthCategories_removeEmptyCats($arrCatsAssoc, $searchString){ |
|---|
| 258 | |
|---|
| 259 | if(empty($searchString)) |
|---|
| 260 | return ($arrCatsAssoc); |
|---|
| 261 | |
|---|
| 262 | foreach($arrCatsAssoc as $catTitle => $arrCat){ |
|---|
| 263 | $isTitleMatch = UniteFunctionsUC::isStringContains($catTitle, $searchString); |
|---|
| 264 | $arrAddons = UniteFunctionsUC::getVal($arrCat, "addons"); |
|---|
| 265 | |
|---|
| 266 | if(empty($arrAddons)) |
|---|
| 267 | $arrAddons = array(); |
|---|
| 268 | |
|---|
| 269 | $numAddons = count($arrAddons); |
|---|
| 270 | |
|---|
| 271 | if($numAddons == 0 && $isTitleMatch == false) |
|---|
| 272 | unset($arrCatsAssoc[$catTitle]); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | return ($arrCatsAssoc); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | /** |
|---|
| 279 | * get addons by categories |
|---|
| 280 | * $publishedCatOnly - get only from published ones |
|---|
| 281 | */ |
|---|
| 282 | public function getAddonsWidthCategories($publishedCatOnly = true, $isShort = false, $type = "", $extra = null){ |
|---|
| 283 | |
|---|
| 284 | $getCatObjects = UniteFunctionsUC::getVal($extra, "get_cat_objects"); |
|---|
| 285 | $getCatObjects = UniteFunctionsUC::strToBool($getCatObjects); |
|---|
| 286 | |
|---|
| 287 | $objCats = new UniteCreatorCategories(); |
|---|
| 288 | |
|---|
| 289 | if($getCatObjects == true) |
|---|
| 290 | $arrCats = $objCats->getCatRecordsWithAddType("uncategorized", $type); |
|---|
| 291 | else |
|---|
| 292 | $arrCats = $objCats->getCatsShort("uncategorized", $type); |
|---|
| 293 | |
|---|
| 294 | $arrIDs = array_keys($arrCats); |
|---|
| 295 | |
|---|
| 296 | $arrCatsAssoc = array(); |
|---|
| 297 | |
|---|
| 298 | //prepare structure |
|---|
| 299 | foreach($arrCats as $catID => $record){ |
|---|
| 300 | //if it's record |
|---|
| 301 | if(is_array($record)) |
|---|
| 302 | $title = $record["title"]; |
|---|
| 303 | else |
|---|
| 304 | $title = $record; |
|---|
| 305 | |
|---|
| 306 | $cat = array(); |
|---|
| 307 | $cat["id"] = $catID; |
|---|
| 308 | $cat["title"] = $title; |
|---|
| 309 | $cat["type"] = $type; |
|---|
| 310 | |
|---|
| 311 | //add cat object |
|---|
| 312 | if($getCatObjects == true && !empty($catID)){ |
|---|
| 313 | $objCat = new UniteCreatorCategory(); |
|---|
| 314 | $objCat->initByRecord($record); |
|---|
| 315 | $cat["objcat"] = $objCat; |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | $cat["addons"] = array(); |
|---|
| 319 | |
|---|
| 320 | $arrCatsAssoc[$title] = $cat; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | $filterActive = null; |
|---|
| 324 | if($publishedCatOnly == true) |
|---|
| 325 | $filterActive = "active"; |
|---|
| 326 | |
|---|
| 327 | $arrAdons = array(); |
|---|
| 328 | if(!empty($arrCatsAssoc)) |
|---|
| 329 | $arrAdons = $this->getCatAddons(null, false, $filterActive, $type, false, $extra); |
|---|
| 330 | |
|---|
| 331 | //put addons to category |
|---|
| 332 | foreach($arrAdons as $addon){ |
|---|
| 333 | $addonCatTitle = $addon->getCatTitle(); |
|---|
| 334 | $addonCatID = $addon->getCatID(); |
|---|
| 335 | |
|---|
| 336 | $addonCatID = (int)$addonCatID; |
|---|
| 337 | |
|---|
| 338 | $name = $addon->getName(); |
|---|
| 339 | |
|---|
| 340 | if($isShort == true){ |
|---|
| 341 | $addonForInsert = $addon->getArrShort(true); |
|---|
| 342 | $addonForInsert["name"] = $addon->getNameByType(); |
|---|
| 343 | }else |
|---|
| 344 | $addonForInsert = $addon; |
|---|
| 345 | |
|---|
| 346 | $insertKey = $addonCatTitle; |
|---|
| 347 | if($addonCatID === 0) |
|---|
| 348 | $insertKey = HelperUC::getText("uncategorized"); |
|---|
| 349 | |
|---|
| 350 | //skip addons without category |
|---|
| 351 | if(empty($insertKey)) |
|---|
| 352 | continue; |
|---|
| 353 | |
|---|
| 354 | $arrCatsAssoc[$insertKey]["addons"][$name] = $addonForInsert; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | //in case of search, filter empty categories |
|---|
| 358 | $filterSearch = UniteFunctionsUC::getVal($extra, "filter_search"); |
|---|
| 359 | if(!empty($filterSearch)) |
|---|
| 360 | $arrCatsAssoc = $this->getAddonsWidthCategories_removeEmptyCats($arrCatsAssoc, $filterSearch); |
|---|
| 361 | |
|---|
| 362 | return ($arrCatsAssoc); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | /** |
|---|
| 366 | * get addons with categories by comfortable format |
|---|
| 367 | */ |
|---|
| 368 | public function getAddonsWidthCategoriesShort($publishedCatOnly = true, $type = ""){ |
|---|
| 369 | |
|---|
| 370 | $arrCats = $this->getAddonsWidthCategories($publishedCatOnly, true, $type); |
|---|
| 371 | |
|---|
| 372 | return $arrCats; |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | /** |
|---|
| 376 | * check if addon exists by name |
|---|
| 377 | */ |
|---|
| 378 | public function isAddonExistsByName($name, $addonType = null){ |
|---|
| 379 | |
|---|
| 380 | $name = $this->db->escape($name); |
|---|
| 381 | |
|---|
| 382 | if(empty($addonType)) |
|---|
| 383 | $where = "name='{$name}'"; |
|---|
| 384 | else{ |
|---|
| 385 | $where = "alias='{$name}'"; |
|---|
| 386 | $where .= " and " . $this->db->getSqlAddonType($addonType); |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | $response = $this->db->fetch(GlobalsUC::$table_addons, $where); |
|---|
| 390 | |
|---|
| 391 | return (!empty($response)); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | /** |
|---|
| 395 | * get addon type from data |
|---|
| 396 | */ |
|---|
| 397 | public function getAddonTypeFromData($data){ |
|---|
| 398 | |
|---|
| 399 | $type = UniteFunctionsUC::getVal($data, "addontype"); |
|---|
| 400 | |
|---|
| 401 | if(empty($type)) |
|---|
| 402 | $type = UniteFunctionsUC::getVal($data, "type"); |
|---|
| 403 | |
|---|
| 404 | HelperUC::runProviderFunc("validateDataAddonsType", $type, $data); |
|---|
| 405 | |
|---|
| 406 | return ($type); |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | /** |
|---|
| 410 | * |
|---|
| 411 | * get max order from categories list |
|---|
| 412 | */ |
|---|
| 413 | public function getMaxOrder($catID){ |
|---|
| 414 | |
|---|
| 415 | UniteFunctionsUC::validateNotEmpty($catID, "category id"); |
|---|
| 416 | |
|---|
| 417 | UniteFunctionsUC::validateNumeric($catID, "category id"); |
|---|
| 418 | |
|---|
| 419 | $tableAddons = GlobalsUC::$table_addons; |
|---|
| 420 | $query = "select MAX(ordering) as maxorder from {$tableAddons} where catid={$catID}"; |
|---|
| 421 | |
|---|
| 422 | $rows = $this->db->fetchSql($query); |
|---|
| 423 | |
|---|
| 424 | $maxOrder = 0; |
|---|
| 425 | if(count($rows) > 0) |
|---|
| 426 | $maxOrder = $rows[0]["maxorder"]; |
|---|
| 427 | |
|---|
| 428 | if(!is_numeric($maxOrder)) |
|---|
| 429 | $maxOrder = 0; |
|---|
| 430 | |
|---|
| 431 | return ($maxOrder); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | /** |
|---|
| 435 | * get number of addons by category |
|---|
| 436 | */ |
|---|
| 437 | public function getNumAddons($catID = null, $filterActive = null, UniteCreatorAddonType $objTypeName = null){ |
|---|
| 438 | |
|---|
| 439 | $tableAddons = GlobalsUC::$table_addons; |
|---|
| 440 | $addonType = $objTypeName->typeName; |
|---|
| 441 | |
|---|
| 442 | $arrWhere = array(); |
|---|
| 443 | if(!empty($filterActive)){ |
|---|
| 444 | $whereActive = self::getFilterActiveWhere($filterActive, "a", $addonType); |
|---|
| 445 | if(!empty($whereActive)) |
|---|
| 446 | $arrWhere[] = $whereActive; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | if($objTypeName->isBasicType == true) |
|---|
| 450 | $addonType = null; |
|---|
| 451 | |
|---|
| 452 | $arrWhere[] = $this->db->getSqlAddonType($addonType); |
|---|
| 453 | |
|---|
| 454 | //all addons |
|---|
| 455 | if($catID === null){ |
|---|
| 456 | $query = "select count(*) as num_addons from {$tableAddons}"; |
|---|
| 457 | }else{ |
|---|
| 458 | |
|---|
| 459 | UniteFunctionsUC::validateNumeric($catID,"Category ID"); |
|---|
| 460 | |
|---|
| 461 | $query = "select count(*) as num_addons from {$tableAddons} as a"; |
|---|
| 462 | $arrWhere[] = "a.catid=$catID"; |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | if(!empty($arrWhere)) |
|---|
| 466 | $query .= " where " . implode(" and ", $arrWhere); |
|---|
| 467 | |
|---|
| 468 | $response = $this->db->fetchSql($query); |
|---|
| 469 | |
|---|
| 470 | if(empty($response)) |
|---|
| 471 | UniteFunctionsUC::throwError("Can't get number of zero addons"); |
|---|
| 472 | |
|---|
| 473 | $numAddons = $response[0]["num_addons"]; |
|---|
| 474 | |
|---|
| 475 | return ($numAddons); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | /** |
|---|
| 479 | * get addon output, for the editor |
|---|
| 480 | */ |
|---|
| 481 | public function getAddonOutput($objAddon, $options = array()){ |
|---|
| 482 | |
|---|
| 483 | $isWrap = UniteFunctionsUC::getVal($options, "wrap", false); |
|---|
| 484 | $includeSelectors = UniteFunctionsUC::getVal($options, "selectors", false); |
|---|
| 485 | $rootId = UniteFunctionsUC::getVal($options, "root_id"); |
|---|
| 486 | |
|---|
| 487 | $params = array( |
|---|
| 488 | "wrap_js_timeout" => $isWrap, |
|---|
| 489 | "add_selectors_css" => $includeSelectors, |
|---|
| 490 | "root_id" => $rootId, |
|---|
| 491 | ); |
|---|
| 492 | |
|---|
| 493 | $cacheOutput = false; |
|---|
| 494 | if(GlobalsProviderUC::$isInsideEditor == true) |
|---|
| 495 | $cacheOutput = true; |
|---|
| 496 | |
|---|
| 497 | if($cacheOutput == true){ |
|---|
| 498 | UniteFunctionsUC::obStart(); |
|---|
| 499 | } |
|---|
| 500 | |
|---|
| 501 | $objOutput = new UniteCreatorOutput(); |
|---|
| 502 | $objOutput->setProcessType(UniteCreatorParamsProcessor::PROCESS_TYPE_OUTPUT_BACK); |
|---|
| 503 | $objOutput->checkOutputDebug($objAddon); |
|---|
| 504 | $objOutput->initByAddon($objAddon); |
|---|
| 505 | |
|---|
| 506 | $htmlBefore = null; |
|---|
| 507 | |
|---|
| 508 | if($cacheOutput == true){ |
|---|
| 509 | $htmlBefore = ob_get_contents(); |
|---|
| 510 | ob_end_clean(); |
|---|
| 511 | } |
|---|
| 512 | |
|---|
| 513 | $html = $objOutput->getHtmlBody(true, false, true, $params); |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | if(!empty($htmlBefore)){ |
|---|
| 517 | $html = $htmlBefore.$html; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | $includes = $objOutput->getProcessedIncludes(true); |
|---|
| 521 | $outputId = $objOutput->getWidgetID(); |
|---|
| 522 | |
|---|
| 523 | $arr = array(); |
|---|
| 524 | $arr["html"] = $html; |
|---|
| 525 | $arr["includes"] = $includes; |
|---|
| 526 | |
|---|
| 527 | if($includeSelectors === true) |
|---|
| 528 | $arr["output_id"] = $outputId; |
|---|
| 529 | |
|---|
| 530 | return $arr; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | /** |
|---|
| 534 | * check addon global variables |
|---|
| 535 | */ |
|---|
| 536 | private function checkInitAddonGlobalVars($addonData){ |
|---|
| 537 | |
|---|
| 538 | //set edit mode |
|---|
| 539 | $source = UniteFunctionsUC::getVal($addonData, "source"); |
|---|
| 540 | if($source == "editor") |
|---|
| 541 | GlobalsProviderUC::$isInsideEditor = true; |
|---|
| 542 | |
|---|
| 543 | $platform = UniteFunctionsUC::getVal($addonData, "platform"); |
|---|
| 544 | if($platform == "gutenberg") |
|---|
| 545 | GlobalsProviderUC::$renderPlatform = GlobalsProviderUC::RENDER_PLATFORM_GUTENBERG; |
|---|
| 546 | |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | /** |
|---|
| 551 | * get addon output data |
|---|
| 552 | */ |
|---|
| 553 | public function getAddonOutputData($addonData, $isWrap = false){ |
|---|
| 554 | |
|---|
| 555 | $this->checkInitAddonGlobalVars($addonData); |
|---|
| 556 | |
|---|
| 557 | $objAddon = $this->prepareAddonByData($addonData, true); |
|---|
| 558 | |
|---|
| 559 | $rootId = UniteFunctionsUC::getVal($addonData, "root_id"); |
|---|
| 560 | $includeSelectors = UniteFunctionsUC::getVal($addonData, "selectors"); |
|---|
| 561 | $includeSelectors = UniteFunctionsUC::strToBool($includeSelectors); |
|---|
| 562 | |
|---|
| 563 | $outputOptions = array( |
|---|
| 564 | "root_id" => $rootId, |
|---|
| 565 | "selectors" => $includeSelectors, |
|---|
| 566 | "wrap"=>$isWrap |
|---|
| 567 | ); |
|---|
| 568 | |
|---|
| 569 | $output = $this->getAddonOutput($objAddon, $outputOptions); |
|---|
| 570 | |
|---|
| 571 | return($output); |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | /** |
|---|
| 576 | * get addon config html by data |
|---|
| 577 | */ |
|---|
| 578 | public function getAddonConfigHTML($data){ |
|---|
| 579 | |
|---|
| 580 | $objAddon = $this->initAddonByData($data); |
|---|
| 581 | |
|---|
| 582 | //init addon config |
|---|
| 583 | $addonConfig = new UniteCreatorAddonConfig(); |
|---|
| 584 | $addonConfig->setStartAddon($objAddon); |
|---|
| 585 | |
|---|
| 586 | $html = $addonConfig->getHtmlFrame(); |
|---|
| 587 | |
|---|
| 588 | $response = array(); |
|---|
| 589 | $response["html_config"] = $html; |
|---|
| 590 | |
|---|
| 591 | //get output data on live mode |
|---|
| 592 | $getOutputData = UniteFunctionsUC::getVal($data, "getcontent"); |
|---|
| 593 | $getOutputData = UniteFunctionsUC::strToBool($getOutputData); |
|---|
| 594 | if($getOutputData == true){ |
|---|
| 595 | $outputData = $this->getLayoutAddonOutputData($data); |
|---|
| 596 | $response["output"] = $outputData; |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | return ($response); |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | /** |
|---|
| 603 | * get item settings html |
|---|
| 604 | */ |
|---|
| 605 | public function getAddonSettingsHTMLFromData($data){ |
|---|
| 606 | |
|---|
| 607 | $this->checkInitAddonGlobalVars($data); |
|---|
| 608 | |
|---|
| 609 | $objAddon = $this->initAddonByData($data); |
|---|
| 610 | |
|---|
| 611 | //remember the addon for use inside the settings classes (used for multisource) |
|---|
| 612 | GlobalsProviderUC::$activeAddonForSettings = $objAddon; |
|---|
| 613 | |
|---|
| 614 | $html = $objAddon->getHtmlConfig(false, true); |
|---|
| 615 | |
|---|
| 616 | return ($html); |
|---|
| 617 | } |
|---|
| 618 | |
|---|
| 619 | /** |
|---|
| 620 | * get addon editor data |
|---|
| 621 | * including addon config, and output if needed |
|---|
| 622 | */ |
|---|
| 623 | public function getAddonEditorData($data){ |
|---|
| 624 | |
|---|
| 625 | $objAddon = $this->initAddonByData($data); |
|---|
| 626 | |
|---|
| 627 | $addonType = $objAddon->getType(); |
|---|
| 628 | |
|---|
| 629 | $arrData = array(); |
|---|
| 630 | $arrData["addontype"] = $addonType; |
|---|
| 631 | $arrData["name"] = $objAddon->getName(); |
|---|
| 632 | |
|---|
| 633 | $arrExtra = array(); |
|---|
| 634 | $arrExtra["title"] = $objAddon->getTitle(); |
|---|
| 635 | $arrExtra["url_icon"] = $objAddon->getUrlIcon(); |
|---|
| 636 | $arrExtra["admin_labels"] = $objAddon->getAdminLabels(); |
|---|
| 637 | $arrExtra["has_items"] = $objAddon->isHasItems(); |
|---|
| 638 | $arrExtra["num_items"] = $objAddon->getNumItems(); |
|---|
| 639 | $arrExtra["id"] = $objAddon->getID(); |
|---|
| 640 | |
|---|
| 641 | $objAddon->setIsInsideGrid(); |
|---|
| 642 | $arrExtra["html_settings"] = $objAddon->getHtmlConfig(false, true); |
|---|
| 643 | |
|---|
| 644 | $arrData["extra"] = $arrExtra; |
|---|
| 645 | |
|---|
| 646 | $returnOutput = UniteFunctionsUC::getVal($data, "return_output"); |
|---|
| 647 | $returnOutput = UniteFunctionsUC::strToBool($returnOutput); |
|---|
| 648 | if($returnOutput == true){ |
|---|
| 649 | $objLayoutOutput = new UniteCreatorLayoutOutput(); |
|---|
| 650 | $objLayoutOutput->setAddonType($addonType); |
|---|
| 651 | $arrData["output"] = $objLayoutOutput->getAddonOutput($objAddon); |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | return ($arrData); |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | /** |
|---|
| 658 | * get item settings html |
|---|
| 659 | */ |
|---|
| 660 | public function getAddonItemsSettingsHTMLFromData($data){ |
|---|
| 661 | |
|---|
| 662 | $addonID = UniteFunctionsUC::getVal($data, "addonid"); |
|---|
| 663 | |
|---|
| 664 | $addon = new UniteCreatorAddon(); |
|---|
| 665 | $addon->initByID($addonID); |
|---|
| 666 | |
|---|
| 667 | $html = $addon->getHtmlItemConfig(); |
|---|
| 668 | |
|---|
| 669 | return ($html); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | /** |
|---|
| 673 | * check if needed helper editor on admin addon output |
|---|
| 674 | */ |
|---|
| 675 | public function isHelperEditorNeeded(UniteCreatorAddon $addon){ |
|---|
| 676 | |
|---|
| 677 | $hasItems = $addon->isHasItems(); |
|---|
| 678 | if($hasItems == false) |
|---|
| 679 | return (false); |
|---|
| 680 | |
|---|
| 681 | $isItemsEditorExists = $addon->isEditorItemsAttributeExists(); |
|---|
| 682 | if($isItemsEditorExists == false) |
|---|
| 683 | return (false); |
|---|
| 684 | |
|---|
| 685 | $isMainEditorExists = $addon->isEditorMainAttributeExists(); |
|---|
| 686 | if($isMainEditorExists == true) |
|---|
| 687 | return (false); |
|---|
| 688 | |
|---|
| 689 | return (true); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | /** |
|---|
| 693 | * prepare addon by data |
|---|
| 694 | */ |
|---|
| 695 | public function prepareAddonByData($addonData, $isForOutput = false){ |
|---|
| 696 | |
|---|
| 697 | $addonName = UniteFunctionsUC::getVal($addonData, "name"); |
|---|
| 698 | $addonType = UniteFunctionsUC::getVal($addonData, "addontype"); |
|---|
| 699 | |
|---|
| 700 | $addonID = UniteFunctionsUC::getVal($addonData, "id"); |
|---|
| 701 | |
|---|
| 702 | //init addon |
|---|
| 703 | $objAddon = new UniteCreatorAddon(); |
|---|
| 704 | |
|---|
| 705 | if(empty($addonName) && !empty($addonID) && is_numeric($addonID)){ |
|---|
| 706 | // init by id |
|---|
| 707 | |
|---|
| 708 | $objAddon->initByID($addonID); |
|---|
| 709 | }else{ |
|---|
| 710 | // init by name or alias and type |
|---|
| 711 | |
|---|
| 712 | if(empty($addonType)) |
|---|
| 713 | $objAddon->initByName($addonName); |
|---|
| 714 | else |
|---|
| 715 | $objAddon->initByAlias($addonName, $addonType); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | $elementorSettings = UniteFunctionsUC::getVal($addonData, "elementor_settings"); |
|---|
| 719 | |
|---|
| 720 | //init by elementor settings |
|---|
| 721 | if(!empty($elementorSettings)){ |
|---|
| 722 | $objIntegrate = new UniteCreatorElementorIntegrate(); |
|---|
| 723 | $objIntegrate->includePluginFiles(); |
|---|
| 724 | |
|---|
| 725 | $objWidget = new UniteCreatorElementorBackgroundWidget(); |
|---|
| 726 | |
|---|
| 727 | $objAddon = $objWidget->setAddonSettingsFromElementorSettings($objAddon, $elementorSettings); |
|---|
| 728 | }else{ //init by blox settings |
|---|
| 729 | |
|---|
| 730 | $arrSettings = UniteFunctionsUC::getVal($addonData, "settings"); |
|---|
| 731 | |
|---|
| 732 | if(is_string($arrSettings)) |
|---|
| 733 | $arrSettings = UniteFunctionsUC::decodeContent($arrSettings); |
|---|
| 734 | |
|---|
| 735 | if(!empty($arrSettings)){ |
|---|
| 736 | |
|---|
| 737 | if(isset($arrSettings["uc_items"])){ |
|---|
| 738 | |
|---|
| 739 | $arrItems = UniteFunctionsUC::getVal($arrSettings, "uc_items"); |
|---|
| 740 | if(empty($arrItems)) |
|---|
| 741 | $arrItems = array(); |
|---|
| 742 | |
|---|
| 743 | $objAddon->setArrItems($arrItems); |
|---|
| 744 | |
|---|
| 745 | unset($arrSettings["uc_items"]); |
|---|
| 746 | } |
|---|
| 747 | |
|---|
| 748 | $objAddon->setParamsValues($arrSettings); |
|---|
| 749 | }else{ |
|---|
| 750 | //set addon data |
|---|
| 751 | $arrConfig = UniteFunctionsUC::getVal($addonData, "config"); |
|---|
| 752 | if(!empty($arrConfig)) |
|---|
| 753 | $objAddon->setParamsValues($arrConfig); |
|---|
| 754 | |
|---|
| 755 | $arrItems = UniteFunctionsUC::getVal($addonData, "items"); |
|---|
| 756 | if(!empty($arrItems)) |
|---|
| 757 | $objAddon->setArrItems($arrItems); |
|---|
| 758 | |
|---|
| 759 | $arrFonts = UniteFunctionsUC::getVal($addonData, "fonts"); |
|---|
| 760 | if(!empty($arrFonts)) |
|---|
| 761 | $objAddon->setArrFonts($arrFonts); |
|---|
| 762 | } |
|---|
| 763 | } |
|---|
| 764 | |
|---|
| 765 | return ($objAddon); |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | protected function a____________SETTERS__________(){ |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | /** |
|---|
| 772 | * |
|---|
| 773 | * delete addons |
|---|
| 774 | */ |
|---|
| 775 | private function deleteAddons($arrAddons){ |
|---|
| 776 | |
|---|
| 777 | //sanitize |
|---|
| 778 | $addons = array(); |
|---|
| 779 | |
|---|
| 780 | foreach($arrAddons as $key => $addonID){ |
|---|
| 781 | |
|---|
| 782 | $addon = new UniteCreatorAddon(); |
|---|
| 783 | $addon->initByID($addonID); |
|---|
| 784 | |
|---|
| 785 | $addons[] = $addon; |
|---|
| 786 | $arrAddons[$key] = $addon->getID(); |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | UniteProviderFunctionsUC::doAction("uc_before_delete_widgets", $arrAddons); |
|---|
| 790 | |
|---|
| 791 | $strAddonIDs = implode(",", $arrAddons); |
|---|
| 792 | $this->db->delete(GlobalsUC::$table_addons, "id in($strAddonIDs)"); |
|---|
| 793 | |
|---|
| 794 | foreach($addons as $addon){ |
|---|
| 795 | $addon->triggerAfterDeleteAction(); |
|---|
| 796 | } |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | /** |
|---|
| 800 | * |
|---|
| 801 | * save items order |
|---|
| 802 | */ |
|---|
| 803 | private function saveAddonsOrder($arrAddonIDs){ |
|---|
| 804 | |
|---|
| 805 | //get items assoc |
|---|
| 806 | $arrAddons = $this->getAddonsByIDs($arrAddonIDs); |
|---|
| 807 | $arrAddons = UniteFunctionsUC::arrayToAssoc($arrAddons, "id"); |
|---|
| 808 | |
|---|
| 809 | $order = 0; |
|---|
| 810 | foreach($arrAddonIDs as $addonID){ |
|---|
| 811 | $order++; |
|---|
| 812 | |
|---|
| 813 | $arrAddon = UniteFunctionsUC::getVal($arrAddons, $addonID); |
|---|
| 814 | if(!empty($arrAddon) && $arrAddon["ordering"] == $order) |
|---|
| 815 | continue; |
|---|
| 816 | |
|---|
| 817 | $arrUpdate = array(); |
|---|
| 818 | $arrUpdate["ordering"] = $order; |
|---|
| 819 | $this->db->update(GlobalsUC::$table_addons, $arrUpdate, array("id" => $addonID)); |
|---|
| 820 | |
|---|
| 821 | } |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | /** |
|---|
| 825 | * |
|---|
| 826 | * copy items to some category |
|---|
| 827 | */ |
|---|
| 828 | private function copyAddons($arrAddonIDs, $catID){ |
|---|
| 829 | |
|---|
| 830 | $category = new UniteCreatorCategories(); |
|---|
| 831 | $category->validateCatExist($catID); |
|---|
| 832 | |
|---|
| 833 | foreach($arrAddonIDs as $addonID){ |
|---|
| 834 | $this->copyAddon($addonID, $catID); |
|---|
| 835 | } |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | /** |
|---|
| 839 | * migrate addons from some type to blox |
|---|
| 840 | * copy the addon, skip if exists, remove the type |
|---|
| 841 | */ |
|---|
| 842 | public function migrateAddonsFromType($addonType){ |
|---|
| 843 | |
|---|
| 844 | dmp("migrate function disabled"); |
|---|
| 845 | exit(); |
|---|
| 846 | |
|---|
| 847 | if(empty($addonType)) |
|---|
| 848 | return (false); |
|---|
| 849 | |
|---|
| 850 | $arrAddons = $this->getArrAddons("", array(), $addonType); |
|---|
| 851 | |
|---|
| 852 | foreach($arrAddons as $addon){ |
|---|
| 853 | $alias = $addon->getAlias(); |
|---|
| 854 | if(empty($alias)) |
|---|
| 855 | continue; |
|---|
| 856 | |
|---|
| 857 | $title = $addon->getTitle(); |
|---|
| 858 | |
|---|
| 859 | $isExists = $this->isAddonExistsByName($alias); |
|---|
| 860 | if($isExists == true) |
|---|
| 861 | continue; |
|---|
| 862 | |
|---|
| 863 | $duplicatedID = $addon->duplicate(); |
|---|
| 864 | if(empty($duplicatedID)) |
|---|
| 865 | continue; |
|---|
| 866 | |
|---|
| 867 | $addonDuplicated = new UniteCreatorAddon(); |
|---|
| 868 | $addonDuplicated->initByID($duplicatedID); |
|---|
| 869 | $addonDuplicated->convertToType(GlobalsUC::ADDON_TYPE_REGULAR_ADDON, $alias, $title); |
|---|
| 870 | } |
|---|
| 871 | } |
|---|
| 872 | |
|---|
| 873 | /** |
|---|
| 874 | * migrate addons from type to type |
|---|
| 875 | */ |
|---|
| 876 | public function migrateAddonsToType($typeFrom, $typeTo){ |
|---|
| 877 | |
|---|
| 878 | $arrAddons = $this->getArrAddons("", array(), $typeFrom); |
|---|
| 879 | |
|---|
| 880 | $arrLog = array(); |
|---|
| 881 | $arrLog[] = "num addons: " . count($arrAddons); |
|---|
| 882 | |
|---|
| 883 | foreach($arrAddons as $addon){ |
|---|
| 884 | $title = $addon->getTitle(); |
|---|
| 885 | |
|---|
| 886 | $converted = $addon->convertToType($typeTo); |
|---|
| 887 | |
|---|
| 888 | if($converted == true) |
|---|
| 889 | $arrLog[] = "$title converted"; |
|---|
| 890 | else |
|---|
| 891 | $arrLog[] = "$title skipped"; |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | return ($arrLog); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | /** |
|---|
| 898 | * |
|---|
| 899 | * move multiple items to some category |
|---|
| 900 | */ |
|---|
| 901 | private function moveAddons($arrAddonIDs, $catID){ |
|---|
| 902 | |
|---|
| 903 | $category = new UniteCreatorCategories(); |
|---|
| 904 | $category->validateCatExist($catID); |
|---|
| 905 | |
|---|
| 906 | foreach($arrAddonIDs as $addonID){ |
|---|
| 907 | $this->moveAddon($addonID, $catID); |
|---|
| 908 | } |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | /** |
|---|
| 912 | * |
|---|
| 913 | * move addons to some category by change category id |
|---|
| 914 | */ |
|---|
| 915 | private function moveAddon($addonID, $catID){ |
|---|
| 916 | |
|---|
| 917 | $addonID = (int)$addonID; |
|---|
| 918 | $catID = (int)$catID; |
|---|
| 919 | |
|---|
| 920 | $arrUpdate = array(); |
|---|
| 921 | $arrUpdate["catid"] = $catID; |
|---|
| 922 | $this->db->update(GlobalsUC::$table_addons, $arrUpdate, array("id" => $addonID)); |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | /** |
|---|
| 926 | * |
|---|
| 927 | * duplciate addons within same category |
|---|
| 928 | */ |
|---|
| 929 | private function duplicateAddons($arrAddonIDs, $catID){ |
|---|
| 930 | |
|---|
| 931 | foreach($arrAddonIDs as $addonID){ |
|---|
| 932 | $addon = new UniteCreatorAddon(); |
|---|
| 933 | $addon->initByID($addonID); |
|---|
| 934 | $addon->duplicate(); |
|---|
| 935 | } |
|---|
| 936 | } |
|---|
| 937 | |
|---|
| 938 | /** |
|---|
| 939 | * create addon from data |
|---|
| 940 | */ |
|---|
| 941 | public function createFromData($data){ |
|---|
| 942 | |
|---|
| 943 | $objAddon = new UniteCreatorAddon(); |
|---|
| 944 | $id = $objAddon->add($data); |
|---|
| 945 | |
|---|
| 946 | return ($id); |
|---|
| 947 | } |
|---|
| 948 | |
|---|
| 949 | /** |
|---|
| 950 | * create addon from manager |
|---|
| 951 | */ |
|---|
| 952 | public function createFromManager($data){ |
|---|
| 953 | |
|---|
| 954 | $title = UniteFunctionsUC::getVal($data, "title"); |
|---|
| 955 | $name = UniteFunctionsUC::getVal($data, "name"); |
|---|
| 956 | $description = UniteFunctionsUC::getVal($data, "description"); |
|---|
| 957 | $catID = UniteFunctionsUC::getVal($data, "catid"); |
|---|
| 958 | $parentID = UniteFunctionsUC::getVal($data, "parent_id"); |
|---|
| 959 | |
|---|
| 960 | $addonType = $this->getAddonTypeFromData($data); |
|---|
| 961 | $objAddonType = UniteCreatorAddonType::getAddonTypeObject($addonType); |
|---|
| 962 | |
|---|
| 963 | $objManager = UniteCreatorManager::getObjManagerByAddonType($addonType, $data); |
|---|
| 964 | $isLayout = $objManager->getIsLayoutType(); |
|---|
| 965 | |
|---|
| 966 | if($isLayout == false){ |
|---|
| 967 | $objAddon = new UniteCreatorAddon(); |
|---|
| 968 | $newAddonID = $objAddon->addSmall($title, $name, $description, $catID, $addonType); |
|---|
| 969 | $urlAddon = HelperUC::getViewUrl_EditAddon($newAddonID); |
|---|
| 970 | $htmlItem = $objManager->getAddonAdminHtml($objAddon); |
|---|
| 971 | }else{ |
|---|
| 972 | //add layout |
|---|
| 973 | |
|---|
| 974 | $objLayout = new UniteCreatorLayout(); |
|---|
| 975 | $objLayout->setLayoutType($addonType); |
|---|
| 976 | |
|---|
| 977 | $params = array(); |
|---|
| 978 | if(!empty($parentID)) |
|---|
| 979 | $params["parent_id"] = $parentID; |
|---|
| 980 | |
|---|
| 981 | $newLayoutID = $objLayout->createSmall($title, $name, $description, $catID, $params); |
|---|
| 982 | $urlAddon = HelperUC::getViewUrl_Layout($newLayoutID); |
|---|
| 983 | |
|---|
| 984 | $htmlItem = $objManager->getAddonAdminHtml($objLayout); |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | $objCats = new UniteCreatorCategories(); |
|---|
| 988 | $htmlCatList = $objCats->getHtmlCatList($catID, $objAddonType); |
|---|
| 989 | |
|---|
| 990 | $output = array(); |
|---|
| 991 | $output["htmlItem"] = $htmlItem; |
|---|
| 992 | $output["htmlCats"] = $htmlCatList; |
|---|
| 993 | $output["url_addon"] = $urlAddon; |
|---|
| 994 | |
|---|
| 995 | return ($output); |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | /** |
|---|
| 999 | * update addon from data |
|---|
| 1000 | */ |
|---|
| 1001 | public function updateAddonFromData($data){ |
|---|
| 1002 | |
|---|
| 1003 | $addonData = UniteFunctionsUC::getVal($data, "addon_data"); |
|---|
| 1004 | |
|---|
| 1005 | if(!empty($addonData)) |
|---|
| 1006 | $data = UniteFunctionsUC::decodeContent($addonData); |
|---|
| 1007 | |
|---|
| 1008 | $addonID = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1009 | |
|---|
| 1010 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1011 | $objAddon->initByID($addonID); |
|---|
| 1012 | $objAddon->update($data); |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | /** |
|---|
| 1016 | * duplicate addon from data |
|---|
| 1017 | */ |
|---|
| 1018 | public function duplicateAddonFromData($data){ |
|---|
| 1019 | |
|---|
| 1020 | $addonID = UniteFunctionsUC::getVal($data, "addonID"); |
|---|
| 1021 | |
|---|
| 1022 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1023 | $objAddon->initByID($addonID); |
|---|
| 1024 | |
|---|
| 1025 | $response = $objAddon->duplicate(true); |
|---|
| 1026 | |
|---|
| 1027 | $htmlRow = HelperHtmlUC::getTableAddonsRow($response["id"], $response["title"]); |
|---|
| 1028 | |
|---|
| 1029 | return ($htmlRow); |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | /** |
|---|
| 1033 | * import addon from library |
|---|
| 1034 | */ |
|---|
| 1035 | public function importAddonFromLibrary($data){ |
|---|
| 1036 | |
|---|
| 1037 | $path = UniteFunctionsUC::getVal($data, "path"); |
|---|
| 1038 | if(empty($path)) |
|---|
| 1039 | UniteFunctionsUC::throwError("Empty Path"); |
|---|
| 1040 | |
|---|
| 1041 | $library = new UniteCreatorLibrary(); |
|---|
| 1042 | $addonData = $library->getPluginDataByPath($path); |
|---|
| 1043 | |
|---|
| 1044 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1045 | $addonID = $objAddon->add($addonData); |
|---|
| 1046 | $title = $objAddon->getTitle(true); |
|---|
| 1047 | |
|---|
| 1048 | $htmlRow = HelperHtmlUC::getTableAddonsRow($addonID, $title); |
|---|
| 1049 | |
|---|
| 1050 | return ($htmlRow); |
|---|
| 1051 | } |
|---|
| 1052 | |
|---|
| 1053 | /** |
|---|
| 1054 | * delete addon from imput data |
|---|
| 1055 | */ |
|---|
| 1056 | public function deleteAddonFromData($data){ |
|---|
| 1057 | |
|---|
| 1058 | $addonID = UniteFunctionsUC::getVal($data, "addonID"); |
|---|
| 1059 | UniteFunctionsUC::validateNotEmpty($addonID, "Widget ID"); |
|---|
| 1060 | |
|---|
| 1061 | UniteFunctionsUC::validateNumeric($addonID,"widget id"); |
|---|
| 1062 | |
|---|
| 1063 | $addon = new UniteCreatorAddon(); |
|---|
| 1064 | $addon->initByID($addonID); |
|---|
| 1065 | |
|---|
| 1066 | $addonID = (int)$addonID; |
|---|
| 1067 | |
|---|
| 1068 | $this->db->delete(GlobalsUC::$table_addons, "id={$addonID}"); |
|---|
| 1069 | |
|---|
| 1070 | $addon->triggerAfterDeleteAction(); |
|---|
| 1071 | } |
|---|
| 1072 | |
|---|
| 1073 | /** |
|---|
| 1074 | * update item title |
|---|
| 1075 | */ |
|---|
| 1076 | public function updateAddonTitleFromData($data){ |
|---|
| 1077 | |
|---|
| 1078 | $itemID = $data["itemID"]; |
|---|
| 1079 | $title = $data["title"]; |
|---|
| 1080 | $name = $data["name"]; |
|---|
| 1081 | $description = $data["description"]; |
|---|
| 1082 | |
|---|
| 1083 | $addonType = $this->getAddonTypeFromData($data); |
|---|
| 1084 | $isLayout = HelperUC::isLayoutAddonType($addonType); |
|---|
| 1085 | |
|---|
| 1086 | if($isLayout == false){ |
|---|
| 1087 | $addon = new UniteCreatorAddon(); |
|---|
| 1088 | $addon->initByID($itemID); |
|---|
| 1089 | $addon->updateNameTitle($name, $title, $description); |
|---|
| 1090 | }else{ |
|---|
| 1091 | $objLayout = new UniteCreatorLayout(); |
|---|
| 1092 | $objLayout->initByID($itemID); |
|---|
| 1093 | $objLayout->updateTitle($title); |
|---|
| 1094 | $objLayout->updateParam("description", $description); |
|---|
| 1095 | |
|---|
| 1096 | //check update isfree param |
|---|
| 1097 | if(isset($data["isfree"])){ |
|---|
| 1098 | $isFree = UniteFunctionsUC::getVal($data, "isfree"); |
|---|
| 1099 | $isFree = UniteFunctionsUC::strToBool($isFree); |
|---|
| 1100 | |
|---|
| 1101 | $objLayout->updateParam("isfree", $isFree); |
|---|
| 1102 | } |
|---|
| 1103 | } |
|---|
| 1104 | } |
|---|
| 1105 | |
|---|
| 1106 | /** |
|---|
| 1107 | * update items activation from data |
|---|
| 1108 | * |
|---|
| 1109 | * @param $data |
|---|
| 1110 | */ |
|---|
| 1111 | public function activateAddonsFromData($data){ |
|---|
| 1112 | |
|---|
| 1113 | $arrIDs = UniteFunctionsUC::getVal($data, "addons_ids"); |
|---|
| 1114 | if(is_array($arrIDs) == false) |
|---|
| 1115 | return (false); |
|---|
| 1116 | |
|---|
| 1117 | if(empty($arrIDs)) |
|---|
| 1118 | return (fale); |
|---|
| 1119 | |
|---|
| 1120 | $strIDs = implode(",", $arrIDs); |
|---|
| 1121 | |
|---|
| 1122 | UniteFunctionsUC::validateIDsList($strIDs, "id's list"); |
|---|
| 1123 | |
|---|
| 1124 | $isActive = UniteFunctionsUC::getVal($data, "is_active"); |
|---|
| 1125 | $isActive = (int)UniteFunctionsUC::strToBool($isActive); |
|---|
| 1126 | |
|---|
| 1127 | $tableAddons = GlobalsUC::$table_addons; |
|---|
| 1128 | $query = "update {$tableAddons} set is_active={$isActive} where id in($strIDs)"; |
|---|
| 1129 | |
|---|
| 1130 | $this->db->runSql($query); |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | /** |
|---|
| 1134 | * remove items from data |
|---|
| 1135 | */ |
|---|
| 1136 | public function removeAddonsFromData($data){ |
|---|
| 1137 | |
|---|
| 1138 | $catID = UniteFunctionsUC::getVal($data, "catid"); |
|---|
| 1139 | $type = $this->getAddonTypeFromData($data); |
|---|
| 1140 | $parentID = UniteFunctionsUC::getVal($data, "parentID"); |
|---|
| 1141 | $parentID = (int)$parentID; |
|---|
| 1142 | |
|---|
| 1143 | $addonsIDs = UniteFunctionsUC::getVal($data, "arrAddonsIDs"); |
|---|
| 1144 | |
|---|
| 1145 | if(HelperUC::isLayoutAddonType($type) == false){ //delete addons |
|---|
| 1146 | $this->deleteAddons($addonsIDs); |
|---|
| 1147 | }else{ //delete layouts |
|---|
| 1148 | |
|---|
| 1149 | $objLayouts = new UniteCreatorLayouts(); |
|---|
| 1150 | $objLayouts->deleteLayouts($addonsIDs); |
|---|
| 1151 | } |
|---|
| 1152 | |
|---|
| 1153 | $response = $this->getCatsAndAddonsHtml($catID, $type, $data, $parentID); |
|---|
| 1154 | |
|---|
| 1155 | return ($response); |
|---|
| 1156 | } |
|---|
| 1157 | |
|---|
| 1158 | /** |
|---|
| 1159 | * |
|---|
| 1160 | * save items order from data |
|---|
| 1161 | */ |
|---|
| 1162 | public function saveOrderFromData($data){ |
|---|
| 1163 | |
|---|
| 1164 | $addonType = $this->getAddonTypeFromData($data); |
|---|
| 1165 | $isLayout = HelperUC::isLayoutAddonType($addonType); |
|---|
| 1166 | |
|---|
| 1167 | $addonsIDs = UniteFunctionsUC::getVal($data, "addons_order"); |
|---|
| 1168 | |
|---|
| 1169 | UniteFunctionsUC::validateIDsList($addonsIDs,"addons_order"); |
|---|
| 1170 | |
|---|
| 1171 | if(empty($addonsIDs)) |
|---|
| 1172 | return (false); |
|---|
| 1173 | |
|---|
| 1174 | if($isLayout == false) |
|---|
| 1175 | $this->saveAddonsOrder($addonsIDs); |
|---|
| 1176 | else{ |
|---|
| 1177 | $objLayouts = new UniteCreatorLayouts(); |
|---|
| 1178 | $objLayouts->updateOrdering($addonsIDs); |
|---|
| 1179 | } |
|---|
| 1180 | } |
|---|
| 1181 | |
|---|
| 1182 | /** |
|---|
| 1183 | * |
|---|
| 1184 | * copy / move addons to some category |
|---|
| 1185 | * |
|---|
| 1186 | * @param $data |
|---|
| 1187 | */ |
|---|
| 1188 | public function moveAddonsFromData($data){ |
|---|
| 1189 | |
|---|
| 1190 | $targetCatID = UniteFunctionsUC::getVal($data, "targetCatID"); |
|---|
| 1191 | $selectedCatID = UniteFunctionsUC::getVal($data, "selectedCatID"); |
|---|
| 1192 | $targetParentID = UniteFunctionsUC::getVal($data, "parentID"); |
|---|
| 1193 | $targetParentID = (int)$targetParentID; |
|---|
| 1194 | |
|---|
| 1195 | $type = $this->getAddonTypeFromData($data); |
|---|
| 1196 | $isLayouts = HelperUC::isLayoutAddonType($type); |
|---|
| 1197 | |
|---|
| 1198 | $arrAddonIDs = UniteFunctionsUC::getVal($data, "arrAddonIDs"); |
|---|
| 1199 | |
|---|
| 1200 | UniteFunctionsUC::validateNotEmpty($targetCatID, "category id"); |
|---|
| 1201 | UniteFunctionsUC::validateNotEmpty($arrAddonIDs, "addon id's"); |
|---|
| 1202 | |
|---|
| 1203 | if($isLayouts == false) //addons |
|---|
| 1204 | $this->moveAddons($arrAddonIDs, $targetCatID); |
|---|
| 1205 | else{ |
|---|
| 1206 | $objLayouts = new UniteCreatorLayouts(); |
|---|
| 1207 | $objLayouts->moveLayouts($arrAddonIDs, $targetCatID, $targetParentID); |
|---|
| 1208 | } |
|---|
| 1209 | |
|---|
| 1210 | $repsonse = $this->getCatsAndAddonsHtml($selectedCatID, $type, $data, $targetParentID); |
|---|
| 1211 | |
|---|
| 1212 | return ($repsonse); |
|---|
| 1213 | } |
|---|
| 1214 | |
|---|
| 1215 | /** |
|---|
| 1216 | * duplicate items |
|---|
| 1217 | */ |
|---|
| 1218 | public function duplicateAddonsFromData($data){ |
|---|
| 1219 | |
|---|
| 1220 | $catID = UniteFunctionsUC::getVal($data, "catID"); |
|---|
| 1221 | $arrIDs = UniteFunctionsUC::getVal($data, "arrIDs"); |
|---|
| 1222 | $parentID = UniteFunctionsUC::getVal($data, "parentID"); |
|---|
| 1223 | |
|---|
| 1224 | $type = $this->getAddonTypeFromData($data); |
|---|
| 1225 | |
|---|
| 1226 | $isLayouts = HelperUC::isLayoutAddonType($type); |
|---|
| 1227 | |
|---|
| 1228 | if($isLayouts == false) |
|---|
| 1229 | $this->duplicateAddons($arrIDs, $catID); |
|---|
| 1230 | else{ |
|---|
| 1231 | $objLayouts = new UniteCreatorLayouts(); |
|---|
| 1232 | $objLayouts->duplicateLayouts($arrIDs, $catID); |
|---|
| 1233 | } |
|---|
| 1234 | |
|---|
| 1235 | $response = $this->getCatsAndAddonsHtml($catID, $type, $data, $parentID); |
|---|
| 1236 | |
|---|
| 1237 | return ($response); |
|---|
| 1238 | } |
|---|
| 1239 | |
|---|
| 1240 | /** |
|---|
| 1241 | * shift addons in category from some order (more then the order). |
|---|
| 1242 | */ |
|---|
| 1243 | public function shiftOrder($catID, $order){ |
|---|
| 1244 | |
|---|
| 1245 | $tableAddons = GlobalsUC::$table_addons; |
|---|
| 1246 | |
|---|
| 1247 | $query = "update $tableAddons set ordering = ordering+1 where catid={$catID} and ordering > {$order}"; |
|---|
| 1248 | |
|---|
| 1249 | $this->db->runSql($query); |
|---|
| 1250 | } |
|---|
| 1251 | |
|---|
| 1252 | /** |
|---|
| 1253 | * init addon by data |
|---|
| 1254 | */ |
|---|
| 1255 | public function initAddonByData($data){ |
|---|
| 1256 | |
|---|
| 1257 | if(is_string($data)){ |
|---|
| 1258 | $data = json_decode($data, true); |
|---|
| 1259 | } |
|---|
| 1260 | |
|---|
| 1261 | $addonID = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1262 | $addonName = UniteFunctionsUC::getVal($data, "name"); |
|---|
| 1263 | $arrConfig = UniteFunctionsUC::getVal($data, "config"); |
|---|
| 1264 | $arrItemsData = UniteFunctionsUC::getVal($data, "items"); |
|---|
| 1265 | $addonType = UniteFunctionsUC::getVal($data, "addontype"); |
|---|
| 1266 | $arrFonts = UniteFunctionsUC::getVal($data, "fonts"); |
|---|
| 1267 | $arrOptions = UniteFunctionsUC::getVal($data, "options"); |
|---|
| 1268 | |
|---|
| 1269 | $isInsideGrid = UniteFunctionsUC::getVal($data, "is_inside_grid"); |
|---|
| 1270 | $isInsideGrid = UniteFunctionsUC::strToBool($isInsideGrid); |
|---|
| 1271 | |
|---|
| 1272 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1273 | |
|---|
| 1274 | if(!empty($addonID)) |
|---|
| 1275 | $objAddon->initByID($addonID); |
|---|
| 1276 | else{ |
|---|
| 1277 | if(!empty($addonType)) |
|---|
| 1278 | $objAddon->initByAlias($addonName, $addonType); |
|---|
| 1279 | else |
|---|
| 1280 | $objAddon->initByName($addonName); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | $objAddon->setParamsValues($arrConfig); |
|---|
| 1284 | |
|---|
| 1285 | if(is_array($arrItemsData)) |
|---|
| 1286 | $objAddon->setArrItems($arrItemsData); |
|---|
| 1287 | |
|---|
| 1288 | if(!empty($arrFonts) && is_array($arrFonts)) |
|---|
| 1289 | $objAddon->setArrFonts($arrFonts); |
|---|
| 1290 | |
|---|
| 1291 | if($isInsideGrid == true) |
|---|
| 1292 | $objAddon->setIsInsideGrid(); |
|---|
| 1293 | |
|---|
| 1294 | return ($objAddon); |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | /** |
|---|
| 1298 | * show preview by data |
|---|
| 1299 | */ |
|---|
| 1300 | public function showAddonPreviewFromData($data){ |
|---|
| 1301 | |
|---|
| 1302 | try{ |
|---|
| 1303 | $objAddon = $this->initAddonByData($data); |
|---|
| 1304 | |
|---|
| 1305 | $objOutput = new UniteCreatorOutput(); |
|---|
| 1306 | $objOutput->setPreviewAddonMode(); |
|---|
| 1307 | |
|---|
| 1308 | $objOutput->initByAddon($objAddon); |
|---|
| 1309 | $objOutput->putPreviewHtml(); |
|---|
| 1310 | }catch(Exception $e){ |
|---|
| 1311 | $message = $e->getMessage(); |
|---|
| 1312 | |
|---|
| 1313 | $errorMessage = HelperUC::getHtmlErrorMessage($message, GlobalsUC::$SHOW_TRACE_FRONT); |
|---|
| 1314 | |
|---|
| 1315 | s_echo ($errorMessage); |
|---|
| 1316 | } |
|---|
| 1317 | |
|---|
| 1318 | exit(); |
|---|
| 1319 | } |
|---|
| 1320 | |
|---|
| 1321 | /** |
|---|
| 1322 | * save test addon data to some slot |
|---|
| 1323 | */ |
|---|
| 1324 | public function saveTestAddonData($data, $slot = 1){ |
|---|
| 1325 | |
|---|
| 1326 | $addonID = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1327 | |
|---|
| 1328 | if(!empty($addonID)){ |
|---|
| 1329 | $config = UniteFunctionsUC::getVal($data, "settings_values", array()); |
|---|
| 1330 | $items = UniteFunctionsUC::getVal($config, "uc_items", array()); |
|---|
| 1331 | $fonts = ""; |
|---|
| 1332 | |
|---|
| 1333 | unset($config["uc_items"]); |
|---|
| 1334 | |
|---|
| 1335 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1336 | $objAddon->initByID($addonID); |
|---|
| 1337 | }else{ |
|---|
| 1338 | $addonName = UniteFunctionsUC::getVal($data, "name"); |
|---|
| 1339 | $addontype = UniteFunctionsUC::getVal($data, "addontype"); |
|---|
| 1340 | |
|---|
| 1341 | $config = UniteFunctionsUC::getVal($data, "config", array()); |
|---|
| 1342 | $items = UniteFunctionsUC::getVal($data, "items", array()); |
|---|
| 1343 | $fonts = UniteFunctionsUC::getVal($data, "fonts"); |
|---|
| 1344 | |
|---|
| 1345 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1346 | $objAddon->initByMixed($addonName, $addontype); |
|---|
| 1347 | } |
|---|
| 1348 | |
|---|
| 1349 | $objAddon->saveTestSlotData($slot, $config, $items, $fonts); |
|---|
| 1350 | } |
|---|
| 1351 | |
|---|
| 1352 | /** |
|---|
| 1353 | * save addon defaults from data |
|---|
| 1354 | */ |
|---|
| 1355 | public function saveAddonDefaultsFromData($data){ |
|---|
| 1356 | |
|---|
| 1357 | $this->saveTestAddonData($data, 2); |
|---|
| 1358 | } |
|---|
| 1359 | |
|---|
| 1360 | /** |
|---|
| 1361 | * get test addon data |
|---|
| 1362 | */ |
|---|
| 1363 | public function getTestAddonData($data){ |
|---|
| 1364 | |
|---|
| 1365 | $objAddon = $this->initAddonByData($data); |
|---|
| 1366 | |
|---|
| 1367 | $slotNum = UniteFunctionsUC::getVal($data, "slotnum"); |
|---|
| 1368 | $isCombine = UniteFunctionsUC::getVal($data, "combine"); |
|---|
| 1369 | $isCombine = UniteFunctionsUC::strToBool($isCombine); |
|---|
| 1370 | |
|---|
| 1371 | |
|---|
| 1372 | $data = $objAddon->getTestData($slotNum); |
|---|
| 1373 | |
|---|
| 1374 | |
|---|
| 1375 | |
|---|
| 1376 | if($isCombine === true){ |
|---|
| 1377 | $config = UniteFunctionsUC::getVal($data, "config", array()); |
|---|
| 1378 | $items = UniteFunctionsUC::getVal($data, "items"); |
|---|
| 1379 | |
|---|
| 1380 | if(!empty($items)) |
|---|
| 1381 | $config["uc_items"] = $items; |
|---|
| 1382 | |
|---|
| 1383 | $output = array("settings_values" => $config); |
|---|
| 1384 | |
|---|
| 1385 | return $output; |
|---|
| 1386 | } |
|---|
| 1387 | |
|---|
| 1388 | return $data; |
|---|
| 1389 | } |
|---|
| 1390 | |
|---|
| 1391 | /** |
|---|
| 1392 | * delete test addon data |
|---|
| 1393 | * |
|---|
| 1394 | * @param $data |
|---|
| 1395 | */ |
|---|
| 1396 | public function deleteTestAddonData($data){ |
|---|
| 1397 | |
|---|
| 1398 | $objAddon = $this->initAddonByData($data); |
|---|
| 1399 | $slotNum = UniteFunctionsUC::getVal($data, "slotnum"); |
|---|
| 1400 | |
|---|
| 1401 | $slotNum = (int)$slotNum; |
|---|
| 1402 | |
|---|
| 1403 | $objAddon->clearTestDataSlot($slotNum); |
|---|
| 1404 | } |
|---|
| 1405 | |
|---|
| 1406 | /** |
|---|
| 1407 | * export addon |
|---|
| 1408 | */ |
|---|
| 1409 | public function exportAddon($data){ |
|---|
| 1410 | |
|---|
| 1411 | $addonType = $this->getAddonTypeFromData($data); |
|---|
| 1412 | $isLayout = HelperUC::isLayoutAddonType($addonType); |
|---|
| 1413 | |
|---|
| 1414 | try{ |
|---|
| 1415 | if($isLayout == false){ |
|---|
| 1416 | $addon = $this->initAddonByData($data); |
|---|
| 1417 | $exporter = new UniteCreatorExporter(); |
|---|
| 1418 | $exporter->initByAddon($addon); |
|---|
| 1419 | $exporter->export(); |
|---|
| 1420 | }else{ |
|---|
| 1421 | $layoutID = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1422 | |
|---|
| 1423 | $objLayout = new UniteCreatorLayout(); |
|---|
| 1424 | $objLayout->initByID($layoutID); |
|---|
| 1425 | |
|---|
| 1426 | $objExporter = new UniteCreatorLayoutsExporter(); |
|---|
| 1427 | $objExporter->initByLayout($objLayout); |
|---|
| 1428 | $objExporter->export(); |
|---|
| 1429 | } |
|---|
| 1430 | }catch(Exception $e){ |
|---|
| 1431 | $message = "Export error: " . $e->getMessage(); |
|---|
| 1432 | echo esc_html($message); |
|---|
| 1433 | } |
|---|
| 1434 | |
|---|
| 1435 | $message = "Export error:item not exported"; |
|---|
| 1436 | echo esc_html($message); |
|---|
| 1437 | exit(); |
|---|
| 1438 | } |
|---|
| 1439 | |
|---|
| 1440 | /** |
|---|
| 1441 | * export category addons |
|---|
| 1442 | */ |
|---|
| 1443 | public function exportCatAddons($data, $exportType = ""){ |
|---|
| 1444 | |
|---|
| 1445 | try{ |
|---|
| 1446 | $catID = UniteFunctionsUC::getVal($data, "catid"); |
|---|
| 1447 | UniteFunctionsUC::validateNotEmpty($catID); |
|---|
| 1448 | |
|---|
| 1449 | $objCats = new UniteCreatorCategories(); |
|---|
| 1450 | $objCats->validateCatExist($catID); |
|---|
| 1451 | |
|---|
| 1452 | $exporter = new UniteCreatorExporter(); |
|---|
| 1453 | $exporter->exportCatAddons($catID, $exportType); |
|---|
| 1454 | }catch(Exception $e){ |
|---|
| 1455 | $message = "Export category addons error: " . $e->getMessage(); |
|---|
| 1456 | echo esc_html($message); |
|---|
| 1457 | } |
|---|
| 1458 | |
|---|
| 1459 | $message = "Export category addons error: addons not exported"; |
|---|
| 1460 | echo esc_html($message); |
|---|
| 1461 | exit(); |
|---|
| 1462 | } |
|---|
| 1463 | |
|---|
| 1464 | /** |
|---|
| 1465 | * import addons |
|---|
| 1466 | */ |
|---|
| 1467 | public function importAddons($data){ |
|---|
| 1468 | |
|---|
| 1469 | $catID = UniteFunctionsUC::getVal($data, "catid"); |
|---|
| 1470 | $addonType = $this->getAddonTypeFromData($data); |
|---|
| 1471 | $isLayout = HelperUC::isLayoutAddonType($addonType); |
|---|
| 1472 | |
|---|
| 1473 | $isOverwrite = UniteFunctionsUC::getVal($data, "isoverwrite"); |
|---|
| 1474 | $isOverwrite = UniteFunctionsUC::strToBool($isOverwrite); |
|---|
| 1475 | |
|---|
| 1476 | $importType = UniteFunctionsUC::getVal($data, "importtype"); |
|---|
| 1477 | |
|---|
| 1478 | switch($importType){ |
|---|
| 1479 | case "autodetect": |
|---|
| 1480 | $forceToCat = false; |
|---|
| 1481 | break; |
|---|
| 1482 | case "specific": |
|---|
| 1483 | $forceToCat = true; |
|---|
| 1484 | break; |
|---|
| 1485 | default: |
|---|
| 1486 | UniteFunctionsUC::throwError("Wrong type: $importType"); |
|---|
| 1487 | break; |
|---|
| 1488 | } |
|---|
| 1489 | |
|---|
| 1490 | if(empty($catID)) |
|---|
| 1491 | $catID = null; |
|---|
| 1492 | |
|---|
| 1493 | $arrTempFile = UniteFunctionsUC::getVal($_FILES, "file"); |
|---|
| 1494 | |
|---|
| 1495 | //---- addon ----- |
|---|
| 1496 | |
|---|
| 1497 | if($isLayout == false){ |
|---|
| 1498 | $exporter = new UniteCreatorExporter(); |
|---|
| 1499 | $exporter->setMustImportAddonType($addonType); |
|---|
| 1500 | |
|---|
| 1501 | $importLog = $exporter->import($catID, $arrTempFile, $isOverwrite, $forceToCat); |
|---|
| 1502 | |
|---|
| 1503 | $catID = $exporter->getImportedCatID(); |
|---|
| 1504 | }else{ |
|---|
| 1505 | //----- layout ------- |
|---|
| 1506 | |
|---|
| 1507 | $arrParams = array(); |
|---|
| 1508 | if(!empty($forceToCat)) |
|---|
| 1509 | $arrParams["force_to_cat"] = $catID; |
|---|
| 1510 | |
|---|
| 1511 | if($addonType == GlobalsUnlimitedElements::ADDONSTYPE_ELEMENTOR_TEMPLATE){ |
|---|
| 1512 | $exporterLayouts = new UniteCreatorLayoutsExporterElementor(); |
|---|
| 1513 | $exporterLayouts->importElementorLayoutNew($arrTempFile, $isOverwrite, $data); |
|---|
| 1514 | }else{ |
|---|
| 1515 | $exporterLayouts = new UniteCreatorLayoutsExporter(); |
|---|
| 1516 | $exporterLayouts->import($arrTempFile, null, $isOverwrite, $arrParams); |
|---|
| 1517 | } |
|---|
| 1518 | |
|---|
| 1519 | $importLog = $exporterLayouts->getLogText(); |
|---|
| 1520 | } |
|---|
| 1521 | |
|---|
| 1522 | $response = $this->getCatsAndAddonsHtml($catID, $addonType, $data); |
|---|
| 1523 | $response["import_log"] = $importLog; |
|---|
| 1524 | |
|---|
| 1525 | return ($response); |
|---|
| 1526 | } |
|---|
| 1527 | |
|---|
| 1528 | /** |
|---|
| 1529 | * add addon changelog |
|---|
| 1530 | */ |
|---|
| 1531 | public function addAddonChangelog($data){ |
|---|
| 1532 | |
|---|
| 1533 | try{ |
|---|
| 1534 | $addonId = UniteFunctionsUC::getVal($data, "addon_id"); |
|---|
| 1535 | $type = UniteFunctionsUC::getVal($data, "type"); |
|---|
| 1536 | $text = UniteFunctionsUC::getVal($data, "text"); |
|---|
| 1537 | |
|---|
| 1538 | UniteFunctionsUC::validateNotEmpty($addonId, "addon id"); |
|---|
| 1539 | UniteFunctionsUC::validateNotEmpty($type, "type"); |
|---|
| 1540 | UniteFunctionsUC::validateNotEmpty($text, "text"); |
|---|
| 1541 | |
|---|
| 1542 | $changelog = new UniteCreatorAddonChangelog(); |
|---|
| 1543 | $changelog->addChangelog($addonId, $type, $text); |
|---|
| 1544 | }catch(Exception $e){ |
|---|
| 1545 | $message = "Add changelog error: " . $e->getMessage(); |
|---|
| 1546 | echo esc_html($message); |
|---|
| 1547 | exit(); |
|---|
| 1548 | } |
|---|
| 1549 | } |
|---|
| 1550 | |
|---|
| 1551 | /** |
|---|
| 1552 | * update addon changelog |
|---|
| 1553 | */ |
|---|
| 1554 | public function updateAddonChangelog($data){ |
|---|
| 1555 | |
|---|
| 1556 | try{ |
|---|
| 1557 | $id = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1558 | $type = UniteFunctionsUC::getVal($data, "type"); |
|---|
| 1559 | $text = UniteFunctionsUC::getVal($data, "text"); |
|---|
| 1560 | |
|---|
| 1561 | UniteFunctionsUC::validateNotEmpty($id, "id"); |
|---|
| 1562 | UniteFunctionsUC::validateNotEmpty($type, "type"); |
|---|
| 1563 | UniteFunctionsUC::validateNotEmpty($text, "text"); |
|---|
| 1564 | |
|---|
| 1565 | $changelog = new UniteCreatorAddonChangelog(); |
|---|
| 1566 | |
|---|
| 1567 | $changelog->updateChangelog($id, array( |
|---|
| 1568 | "type" => $type, |
|---|
| 1569 | "text" => $text, |
|---|
| 1570 | )); |
|---|
| 1571 | }catch(Exception $e){ |
|---|
| 1572 | $message = "Update changelog error: " . $e->getMessage(); |
|---|
| 1573 | echo esc_html($message); |
|---|
| 1574 | exit(); |
|---|
| 1575 | } |
|---|
| 1576 | } |
|---|
| 1577 | |
|---|
| 1578 | /** |
|---|
| 1579 | * delete addon changelog |
|---|
| 1580 | */ |
|---|
| 1581 | public function deleteAddonChangelog($data){ |
|---|
| 1582 | |
|---|
| 1583 | try{ |
|---|
| 1584 | $id = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1585 | |
|---|
| 1586 | UniteFunctionsUC::validateNotEmpty($id, "id"); |
|---|
| 1587 | |
|---|
| 1588 | $changelog = new UniteCreatorAddonChangelog(); |
|---|
| 1589 | $changelog->deleteChangelog($id); |
|---|
| 1590 | }catch(Exception $e){ |
|---|
| 1591 | $message = "Delete changelog error: " . $e->getMessage(); |
|---|
| 1592 | echo esc_html($message); |
|---|
| 1593 | exit(); |
|---|
| 1594 | } |
|---|
| 1595 | } |
|---|
| 1596 | |
|---|
| 1597 | /** |
|---|
| 1598 | * create addon revision |
|---|
| 1599 | */ |
|---|
| 1600 | public function createAddonRevision($data){ |
|---|
| 1601 | |
|---|
| 1602 | try{ |
|---|
| 1603 | $addon = $this->initAddonByData($data); |
|---|
| 1604 | |
|---|
| 1605 | $revisioner = new UniteCreatorAddonRevisioner(); |
|---|
| 1606 | $revisioner->createAddonRevision($addon); |
|---|
| 1607 | }catch(Exception $e){ |
|---|
| 1608 | $message = "Create addon revision error: " . $e->getMessage(); |
|---|
| 1609 | echo esc_html($message); |
|---|
| 1610 | exit(); |
|---|
| 1611 | } |
|---|
| 1612 | } |
|---|
| 1613 | |
|---|
| 1614 | /** |
|---|
| 1615 | * restore addon revision |
|---|
| 1616 | */ |
|---|
| 1617 | public function restoreAddonRevision($data){ |
|---|
| 1618 | |
|---|
| 1619 | try{ |
|---|
| 1620 | $addon = $this->initAddonByData($data); |
|---|
| 1621 | $revisionId = UniteFunctionsUC::getVal($data, "revision_id"); |
|---|
| 1622 | |
|---|
| 1623 | $revisioner = new UniteCreatorAddonRevisioner(); |
|---|
| 1624 | $importLog = $revisioner->restoreAddonRevision($addon, $revisionId); |
|---|
| 1625 | |
|---|
| 1626 | $response = array(); |
|---|
| 1627 | $response["import_log"] = $importLog; |
|---|
| 1628 | |
|---|
| 1629 | return $response; |
|---|
| 1630 | }catch(Exception $e){ |
|---|
| 1631 | $message = "Restore addon revision error: " . $e->getMessage(); |
|---|
| 1632 | echo esc_html($message); |
|---|
| 1633 | exit(); |
|---|
| 1634 | } |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | /** |
|---|
| 1638 | * download addon revision |
|---|
| 1639 | */ |
|---|
| 1640 | public function downloadAddonRevision($data){ |
|---|
| 1641 | |
|---|
| 1642 | try{ |
|---|
| 1643 | $addon = $this->initAddonByData($data); |
|---|
| 1644 | $revisionId = UniteFunctionsUC::getVal($data, "revision_id"); |
|---|
| 1645 | |
|---|
| 1646 | $revisioner = new UniteCreatorAddonRevisioner(); |
|---|
| 1647 | $revisioner->downloadAddonRevision($addon, $revisionId); |
|---|
| 1648 | }catch(Exception $e){ |
|---|
| 1649 | $message = "Download addon revision error: " . $e->getMessage(); |
|---|
| 1650 | echo esc_html($message); |
|---|
| 1651 | exit(); |
|---|
| 1652 | } |
|---|
| 1653 | } |
|---|
| 1654 | |
|---|
| 1655 | /** |
|---|
| 1656 | * update addon from catalog |
|---|
| 1657 | */ |
|---|
| 1658 | public function updateAddonFromCatalogFromData($data){ |
|---|
| 1659 | |
|---|
| 1660 | $widgetName = UniteFunctionsUC::getVal($data, "widget_name"); |
|---|
| 1661 | |
|---|
| 1662 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1663 | |
|---|
| 1664 | $addonID = null; |
|---|
| 1665 | |
|---|
| 1666 | if(!empty($widgetName)){ |
|---|
| 1667 | $alias = str_replace("ucaddon_", "", $widgetName); |
|---|
| 1668 | |
|---|
| 1669 | $objAddon->initByAlias($alias, GlobalsUC::ADDON_TYPE_ELEMENTOR); |
|---|
| 1670 | }else{ //init by id |
|---|
| 1671 | |
|---|
| 1672 | $addonID = UniteFunctionsUC::getVal($data, "id"); |
|---|
| 1673 | $addonID = (int)$addonID; |
|---|
| 1674 | |
|---|
| 1675 | $objAddon->initByID($addonID); |
|---|
| 1676 | } |
|---|
| 1677 | |
|---|
| 1678 | $installData = array(); |
|---|
| 1679 | |
|---|
| 1680 | $installData["name"] = $objAddon->getAlias(); |
|---|
| 1681 | $installData["cat"] = $objAddon->getCatTitle(); |
|---|
| 1682 | $installData["type"] = $objAddon->getType(); |
|---|
| 1683 | |
|---|
| 1684 | $webAPI = new UniteCreatorWebAPI(); |
|---|
| 1685 | |
|---|
| 1686 | $webAPI->checkUpdateCatalog(true); |
|---|
| 1687 | $webAPI->installCatalogAddonFromData($installData); |
|---|
| 1688 | |
|---|
| 1689 | if(empty($addonID)) |
|---|
| 1690 | return (null); |
|---|
| 1691 | |
|---|
| 1692 | $urlRedirect = HelperUC::getViewUrl_EditAddon($addonID); |
|---|
| 1693 | |
|---|
| 1694 | return ($urlRedirect); |
|---|
| 1695 | } |
|---|
| 1696 | |
|---|
| 1697 | /** |
|---|
| 1698 | * update bulk params in addons from data |
|---|
| 1699 | * return bulk dialog html |
|---|
| 1700 | */ |
|---|
| 1701 | public function updateAddonsBulkFromData($data){ |
|---|
| 1702 | |
|---|
| 1703 | $paramType = UniteFunctionsUC::getVal($data, "param_type"); |
|---|
| 1704 | $paramData = UniteFunctionsUC::getVal($data, "param_data"); |
|---|
| 1705 | $paramName = UniteFunctionsUC::getVal($paramData, "name"); |
|---|
| 1706 | |
|---|
| 1707 | $sourceAddonID = UniteFunctionsUC::getVal($data, "addon_id"); |
|---|
| 1708 | $targetAddonIDs = UniteFunctionsUC::getVal($data, "addon_ids"); |
|---|
| 1709 | $action = UniteFunctionsUC::getVal($data, "action_bulk"); |
|---|
| 1710 | |
|---|
| 1711 | $position = UniteFunctionsUC::getVal($data, "param_position"); |
|---|
| 1712 | |
|---|
| 1713 | //get position in addon |
|---|
| 1714 | |
|---|
| 1715 | $objAddon = new UniteCreatorAddon(); |
|---|
| 1716 | $objAddon->initByID($sourceAddonID); |
|---|
| 1717 | |
|---|
| 1718 | $isMain = ($paramType == "main"); |
|---|
| 1719 | |
|---|
| 1720 | if(empty($position)) |
|---|
| 1721 | $position = $objAddon->getParamPosition($paramName, $isMain); |
|---|
| 1722 | |
|---|
| 1723 | //clear category data |
|---|
| 1724 | unset($paramData["__attr_catid__"]); |
|---|
| 1725 | |
|---|
| 1726 | //update addons |
|---|
| 1727 | |
|---|
| 1728 | foreach($targetAddonIDs as $addonID){ |
|---|
| 1729 | $objTargetAddon = new UniteCreatorAddon(); |
|---|
| 1730 | $objTargetAddon->initByID($addonID); |
|---|
| 1731 | |
|---|
| 1732 | switch($action){ |
|---|
| 1733 | case "update": |
|---|
| 1734 | $objTargetAddon->addUpdateParam_updateDB($paramData, $isMain, $position); |
|---|
| 1735 | break; |
|---|
| 1736 | case "delete": |
|---|
| 1737 | $objTargetAddon->deleteParam_updateDB($paramName, $isMain); |
|---|
| 1738 | break; |
|---|
| 1739 | default: |
|---|
| 1740 | UniteFunctionsUC::throwError("Wrong bulk action: $action"); |
|---|
| 1741 | break; |
|---|
| 1742 | } |
|---|
| 1743 | } |
|---|
| 1744 | } |
|---|
| 1745 | |
|---|
| 1746 | /** |
|---|
| 1747 | * install addons from catalog if not exists |
|---|
| 1748 | */ |
|---|
| 1749 | public function installMultipleAddons($arrAddonNames, $addonType){ |
|---|
| 1750 | |
|---|
| 1751 | if(empty($addonType)) |
|---|
| 1752 | return ("installMultipleAddons - addonType is empty"); |
|---|
| 1753 | |
|---|
| 1754 | if(empty($arrAddonNames)) |
|---|
| 1755 | return ("installMultipleAddons - no addons found"); |
|---|
| 1756 | |
|---|
| 1757 | $numAddons = count($arrAddonNames); |
|---|
| 1758 | |
|---|
| 1759 | if($numAddons > 25) |
|---|
| 1760 | UniteFunctionsUC::throwError("Too much widgets to install: $numAddons"); |
|---|
| 1761 | |
|---|
| 1762 | $webAPI = new UniteCreatorWebAPI(); |
|---|
| 1763 | |
|---|
| 1764 | $strLog = ""; |
|---|
| 1765 | |
|---|
| 1766 | foreach($arrAddonNames as $alias){ |
|---|
| 1767 | $isExists = $this->isAddonExistsByName($alias, $addonType); |
|---|
| 1768 | |
|---|
| 1769 | if(!empty($strLog)) |
|---|
| 1770 | $strLog .= "\n"; |
|---|
| 1771 | |
|---|
| 1772 | if($isExists == true){ |
|---|
| 1773 | $strLog .= "Skipped widget install: $alias"; |
|---|
| 1774 | continue; |
|---|
| 1775 | } |
|---|
| 1776 | |
|---|
| 1777 | $strLog .= $webAPI->installCatalogAddonByName($alias, $addonType); |
|---|
| 1778 | } |
|---|
| 1779 | |
|---|
| 1780 | return ($strLog); |
|---|
| 1781 | } |
|---|
| 1782 | |
|---|
| 1783 | } |
|---|