Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
wp-content
/
plugins
/
unlimited-elements-for-elementor
/
inc_php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access'); class UCOperations extends UniteElementsBaseUC { private static $arrGeneralSettings = null; private static $arrLayoutsGeneralSettings = null; private static $arrCustomSettingsCache = array(); private static $arrUrlThumbCache = array(); const GENERAL_SETTINGS_OPTION = "unitecreator_general_settings"; private function a_______GENERAL_SETTING________() { } public function getGeneralSettings() { if (self::$arrGeneralSettings === null) { $objSettings = $this->getGeneralSettingsObject(); self::$arrGeneralSettings = $objSettings->getArrValues(); } return self::$arrGeneralSettings; } public function getGeneralSettingsCustomObject($filepathSettings) { $arrValues = UniteProviderFunctionsUC::getOption(self::GENERAL_SETTINGS_OPTION); $objSettings = new UniteCreatorSettings(); $objSettings->loadXMLFile($filepathSettings); if (!empty($arrValues)) { $objSettings->setStoredValues($arrValues); } return $arrValues; } private function getGeneralSettingsKey($key) { if ($key == self::GENERAL_SETTINGS_OPTION) { return $key; } if ($key == "general_settings") { return self::GENERAL_SETTINGS_OPTION; } $key = "unite_creator_" . $key; return $key; } public function getGeneralSettingsObject() { $filepathSettings = GlobalsUC::$pathSettings . "general_settings.xml"; $objSettings = new UniteCreatorSettings(); $objSettings->loadXMLFile($filepathSettings); $objSettings = UniteProviderFunctionsUC::applyFilters(UniteCreatorFilters::FILTER_MODIFY_GENERAL_SETTINGS, $objSettings); $arrValues = UniteProviderFunctionsUC::getOption(self::GENERAL_SETTINGS_OPTION); if (!empty($arrValues)) { $objSettings->setStoredValues($arrValues); } return $objSettings; } public function updateGeneralSettingsFromData($data, $isValidate = true, $settingsKey = self::GENERAL_SETTINGS_OPTION) { $arrValues = UniteFunctionsUC::getVal($data, "settings_values"); if ($isValidate == true) { UniteProviderFunctionsUC::doAction(UniteCreatorFilters::ACTION_VALIDATE_GENERAL_SETTINGS, $arrValues, $settingsKey); } $arrCurrentSettings = UniteProviderFunctionsUC::getOption($settingsKey); if (empty($arrCurrentSettings)) { $arrCurrentSettings = array(); } if (empty($arrValues)) { $arrValues = array(); } $arrValues = array_merge($arrCurrentSettings, $arrValues); if (isset(self::$arrCustomSettingsCache[$settingsKey])) { unset(self::$arrCustomSettingsCache[$settingsKey]); } UniteProviderFunctionsUC::updateOption($settingsKey, $arrValues); } private function validateNoGeneralSettingsKeysInCustomSettings($arrValues) { if (is_array($arrValues) == false) { return false; } $arrSettings = $this->getGeneralSettings(); if (is_array($arrSettings) == false) { return false; } $arrIntersect = array_intersect_key($arrSettings, $arrValues); if (empty($arrIntersect)) { return false; } $strIntersect = print_r($arrIntersect, true); UniteFunctionsUC::throwError("The custom settings should not contain general settings keys:" . $strIntersect); } public function updateUnlimitedElementsGeneralSettings($arrValues) { $key = "unlimited_elements_general_settings"; $customSettingsKey = self::getGeneralSettingsKey($key); $data = array(); $data["settings_values"] = $arrValues; $this->updateGeneralSettingsFromData($data, false, $customSettingsKey); } public function updateCustomSettingsFromData($data) { $arrValues = UniteFunctionsUC::getVal($data, "settings_values"); $key = UniteFunctionsUC::getVal($data, "settings_key"); if ($key == "general_settings") { $this->validateNoGeneralSettingsKeysInCustomSettings($arrValues); $this->updateGeneralSettingsFromData($data, false); } else { $customSettingsKey = self::getGeneralSettingsKey($key); $this->updateGeneralSettingsFromData($data, false, $customSettingsKey); } } public function getGeneralSettingsGoogleFonts() { $arrSettings = $this->getGeneralSettings(); $arrFonts = array(); $numFonts = 4; for ($i = 0; $i < $numFonts; $i++) { $fontName = UniteFunctionsUC::getVal($arrSettings, "google_font{$i}_name"); $fontName = trim($fontName); if (empty($fontName)) { continue; } $fontLink = UniteFunctionsUC::getVal($arrSettings, "google_font{$i}_link"); if (empty($fontLink)) { continue; } $fontLink = trim($fontLink); $fontLink = str_replace("https://fonts.googleapis.com/css?family=", "", $fontLink); $fontLink = str_replace("http://fonts.googleapis.com/css?family=", "", $fontLink); if (empty($fontLink)) { continue; } $arrFonts[$fontName] = $fontLink; } return $arrFonts; } private function a_________CUSTOM_SETTINGS___________() { } public function getCustomSettingsValues($customSettingsKey) { $settingsKey = self::getGeneralSettingsKey($customSettingsKey); $arrValues = UniteProviderFunctionsUC::getOption($settingsKey); return $arrValues; } public function getCustomSettingsObject($filepathSettings, $settingsKey) { $objSettings = new UniteCreatorSettings(); $objSettings->loadXMLFile($filepathSettings); $arrValues = $this->getCustomSettingsValues($settingsKey); if (!empty($arrValues)) { $objSettings->setStoredValues($arrValues); } return $objSettings; } public function getCustomSettingsObjectValues($filepathSettings, $settingsKey) { if (isset(self::$arrCustomSettingsCache[$settingsKey])) { return self::$arrCustomSettingsCache[$settingsKey]; } $objSettings = $this->getCustomSettingsObject($filepathSettings, $settingsKey); $arrValues = $objSettings->getArrValues(); self::$arrCustomSettingsCache[$settingsKey] = $arrValues; return $arrValues; } private function a__________OTHER_FUNCTIONS___________() { } public function checkInstagramRenewToken() { try { $objServices = new UniteServicesUC(); $objServices->includeInstagramAPI(); $isRenewed = HelperInstaUC::checkRenewAccessToken_onceInAWhile(); } catch (Exception $e) { } } public function getErrorMessageHtml($message, $trace = "") { $html = '<div class="unite-error-message">'; $html .= '<div class="unite-error-message-inner">'; $html .= $message; $html .= '</div>'; if (!empty($trace)) { $html .= '<div class="unite-error-trace">'; $html .= "<pre>{$trace}</pre>"; $html .= "</div>"; } $html .= '</div>'; return $html; } public function putModuleErrorMessage($message, $trace = "") { echo self::getErrorMessageHtml($message, $trace); } protected function getThumbWidthFromSize($sizeName) { switch ($sizeName) { case GlobalsUC::THUMB_SIZE_NORMAL: $size = GlobalsUC::THUMB_WIDTH; break; case GlobalsUC::THUMB_SIZE_LARGE: $size = GlobalsUC::THUMB_WIDTH_LARGE; break; default: $size = GlobalsUC::THUMB_WIDTH; break; } return $size; } public function createThumbs($urlImage, $thumbSize = null) { if (empty($urlImage)) { UniteFunctionsUC::throwError("empty image url"); } $thumbWidth = $this->getThumbWidthFromSize($thumbSize); $urlImage = HelperUC::URLtoRelative($urlImage); $info = HelperUC::getImageDetails($urlImage); $pathThumbs = $info["path_thumbs"]; if (!is_dir($pathThumbs)) { @mkdir($pathThumbs); } if (!is_dir($pathThumbs)) { UniteFunctionsUC::throwError("Can't make thumb folder: {$pathThumbs}. Please check php and folder permissions"); } $filepathImage = $info["filepath"]; $filenameThumb = $this->imageView->makeThumb($filepathImage, $pathThumbs, $thumbWidth); $urlThumb = ""; if (!empty($filenameThumb)) { $urlThumbs = $info["url_dir_thumbs"]; $urlThumb = $urlThumbs . $filenameThumb; } return $urlThumb; } public function getThumbURLFromImageUrl($urlImage, $imageID = null, $thumbSize = null) { try { $imageID = trim($imageID); if (is_numeric($urlImage)) { $imageID = $urlImage; } if (!empty($imageID)) { $urlThumb = UniteProviderFunctionsUC::getThumbUrlFromImageID($imageID, $thumbSize); } else { $urlThumb = $urlImage; } if (empty($urlThumb)) { return ""; } $urlThumb = HelperUC::URLtoFull($urlThumb); return $urlThumb; } catch (Exception $e) { return ""; } return ""; } private function getParamTitle() { $arr = array(); $arr["type"] = "uc_textfield"; $arr["title"] = "Title"; $arr["name"] = "title"; $arr["description"] = ""; $arr["default_value"] = ""; $arr["limited_edit"] = true; return $arr; } public function checkAddParamTitle($params) { if (empty($params)) { $paramTitle = $this->getParamTitle(); $params[] = $paramTitle; return $params; } foreach ($params as $param) { $name = UniteFunctionsUC::getVal($param, "name"); if ($name == "title") { return $params; } } $paramTitle = $this->getParamTitle(); array_unshift($params, $paramTitle); return $params; } public function getAddonBulkDialogFromData($data) { require_once GlobalsUC::$pathViewsObjects . "addon_view.class.php"; $objAddonView = new UniteCreatorAddonView(false); $response = $objAddonView->getBulkDialogContents($data); return $response; } private function a____________DATE____________() { } public function getDateRangeString($startTimeStamp, $endTimeStamp, $pattern = null) { $displayDate = ""; $startDate = getDate($startTimeStamp); $endDate = getDate($endTimeStamp); if ($startDate["year"] . $startDate["mon"] . $startDate["mday"] == $endDate["year"] . $endDate["mon"] . $endDate["mday"]) { $displayDate = date('j M Y', $endTimeStamp); return $displayDate; } if ($startDate["year"] != $endDate["year"]) { $displayDate = date('j M Y', $startTimeStamp) . " - " . date('j M Y', $endTimeStamp); return $displayDate; } if ($startDate["mon"] == $endDate["mon"]) { $displayDate = date('j', $startTimeStamp) . "-" . date('j M Y', $endTimeStamp); } $displayDate = date('j M', $startTimeStamp) . " - " . date('j M Y', $endTimeStamp); return $displayDate; } private function a____________SCREENSHOTS____________() { } private function saveScreenshot_layout_getFilepath($objLayout, $ext) { $pathImage = $objLayout->getPreviewImageFilepath(); if ($pathImage) { $isGenerated = UniteFunctionsUC::isPathUnderBase($pathImage, GlobalsUC::$path_images_screenshots); $info = pathinfo($pathImage); $extExisting = UniteFunctionsUC::getVal($info, "extension"); if ($extExisting == $ext && $isGenerated == true) { return $pathImage; } } $title = $objLayout->getTitle(); $type = $objLayout->getLayoutType(); $filename = "layout_" . HelperUC::convertTitleToHandle($title); if (!empty($type)) { $filename .= "_" . $type; } $addition = ""; $counter = 1; do { $filepath = GlobalsUC::$path_images_screenshots . $filename . $addition . "." . $ext; $isExists = file_exists($filepath); $counter++; $addition = "_" . $counter; } while ($isExists == true); return $filepath; } private function saveScreenshot_layout($layoutID, $screenshotData, $ext) { $objLayout = new UniteCreatorLayout(); $objLayout->initByID($layoutID); UniteFunctionsUC::checkCreateDir(GlobalsUC::$path_images_screenshots); $filepath = $this->saveScreenshot_layout_getFilepath($objLayout, $ext); $pathExistingImage = $objLayout->getPreviewImageFilepath(); $isGenerated = UniteFunctionsUC::isPathUnderBase($pathExistingImage, GlobalsUC::$path_images_screenshots); if ($isGenerated == true && $pathExistingImage != $filepath && file_exists($pathExistingImage)) { @unlink($pathExistingImage); } UniteFunctionsUC::writeFile($screenshotData, $filepath); if (file_exists($filepath) == false) { UniteFunctionsUC::throwError("The screenshot could not be created"); } $urlScreenshot = HelperUC::pathToRelativeUrl($filepath); $objLayout->updateParam("preview_image", $urlScreenshot); $objLayout->updateParam("page_image", ""); $urlScreenshotFull = HelperUC::URLtoFull($urlScreenshot); return $urlScreenshotFull; } public function saveScreenshotFromData($data) { try { $source = UniteFunctionsUC::getVal($data, "source"); $layoutID = UniteFunctionsUC::getVal($data, "layoutid"); $screenshotData = UniteFunctionsUC::getVal($data, "screenshot_data"); $ext = UniteFunctionsUC::getVal($data, "ext"); UniteFunctionsUC::validateNotEmpty($layoutID, "layoutID"); switch ($ext) { case "jpg": $screenshotData = $this->imageView->convertJPGDataToJPG($screenshotData); break; case "png": $screenshotData = $this->imageView->convertPngDataToPng($screenshotData); break; default: UniteFunctionsUC::throwError("wrong extension"); break; } switch ($source) { case "layout": $urlScreenshot = $this->saveScreenshot_layout($layoutID, $screenshotData, $ext); break; case "addon": dmp("save addon screenshot"); break; default: UniteFunctionsUC::throwError("wrong save source"); break; } } catch (Exception $e) { $errorMessage = $e->getMessage(); $output = array(); $output["error_message"] = $errorMessage; return $errorMessage; } $output = array(); $output["url_screenshot"] = $urlScreenshot; $output["layoutid"] = $layoutID; return $output; } public function getPostListForSelectFromData($data, $addNotSelected = false) { dmp("getPostListForSelect: function for overide"); exit; } private function getPostAttributesFromData_getPostAdditions($data) { $arrAdditions = array(); $enableCustomFields = UniteFunctionsUC::getVal($data, "enable_custom_fields"); $enableCustomFields = UniteFunctionsUC::strToBool($enableCustomFields); $enableCategory = UniteFunctionsUC::getVal($data, "enable_category"); $enableCategory = UniteFunctionsUC::strToBool($enableCategory); $enableWoo = UniteFunctionsUC::getVal($data, "enable_woo"); $enableWoo = UniteFunctionsUC::strToBool($enableWoo); if ($enableCustomFields == true) { $arrAdditions[] = GlobalsProviderUC::POST_ADDITION_CUSTOMFIELDS; } if ($enableCategory == true) { $arrAdditions[] = GlobalsProviderUC::POST_ADDITION_CATEGORY; } if ($enableWoo == true) { $arrAdditions[] = GlobalsProviderUC::POST_ADDITION_WOO; } return $arrAdditions; } public function getPostAttributesFromData($data) { $postID = UniteFunctionsUC::getVal($data, "postid"); require_once GlobalsUC::$pathViewsObjects . "addon_view.class.php"; require_once GlobalsUC::$pathProvider . "views/addon.php"; $objAddonView = new UniteCreatorAddonViewProvider(); $arrPostAdditions = $this->getPostAttributesFromData_getPostAdditions($data); $arrParams = $objAddonView->getChildParams_post($postID, $arrPostAdditions); $response = array(); $response["child_params_post"] = $arrParams; return $response; } }