first commit
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType{
|
||||
|
||||
public $textSingle, $textPlural, $typeName, $typeNameDistinct, $typeNameCategory, $textShowType;
|
||||
public $isSVG = false, $isLayout = false, $titlePrefix = "", $isBasicType = true;
|
||||
|
||||
//manager
|
||||
|
||||
public $enableCategories = true, $enableShortcodes = false;
|
||||
public $allowDuplicateTitle = true, $isAutoScreenshot = false;
|
||||
public $allowNoCategory = true, $defaultCatTitle, $allowWebCatalog = true;
|
||||
public $exportPrefix = null, $requireCatalogPreview = false;
|
||||
public $catalogKey="addons", $allowManagerWebCatalog = true;
|
||||
public $arrCatalogExcludeCats = array(); //categories for exclude
|
||||
public $isWebCatalogMode = false;
|
||||
|
||||
public $managerHeaderPrefix = null;
|
||||
public $showDescriptionField = true;
|
||||
public $hasParents = false;
|
||||
|
||||
//addon view
|
||||
public $addonView_htmlTabOnly = false, $addonView_showConstantVars = true;
|
||||
public $addonView_showPreviewSettings = true, $addonView_showAddonDefaults = true;
|
||||
public $addonView_tabHtmlTitle = null, $addonView_htmlEditorMode = null;
|
||||
public $addonView_arrCustomConstants = null, $addonView_showTestAddon = true;
|
||||
public $addonView_urlBack = null, $addonView_showSmallIconOption = true;
|
||||
|
||||
public $browser_addEmptyItem = false, $browser_textBuy = null, $browser_textHoverPro = null, $browser_urlBuyPro = null, $browser_buyProNewPage = false;
|
||||
public $browser_urlPreview = null;
|
||||
|
||||
public static $arrTypesCache = array();
|
||||
public $pathAssets, $urlAssets; //in case that assets path defers
|
||||
|
||||
|
||||
//internal
|
||||
public $textNoAddons;
|
||||
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function init(){
|
||||
|
||||
$this->typeName = "";
|
||||
|
||||
$this->textSingle = __("Addon", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("Addons", "unlimited-elements-for-elementor");
|
||||
$this->textShowType = __("Regular Addon", "unlimited-elements-for-elementor");
|
||||
$this->defaultCatTitle = __("Main", "unlimited-elements-for-elementor");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init distinct type name
|
||||
*/
|
||||
private function initDistinctTypeName(){
|
||||
|
||||
$this->typeNameDistinct = $this->typeName;
|
||||
|
||||
if(!empty($this->typeNameDistinct))
|
||||
return(false);
|
||||
|
||||
if($this->isLayout == true)
|
||||
$this->typeNameDistinct = GlobalsUC::ADDON_TYPE_REGULAR_LAYOUT;
|
||||
else
|
||||
$this->typeNameDistinct = GlobalsUC::ADDON_TYPE_REGULAR_ADDON;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init derived text
|
||||
*/
|
||||
protected function initInternal(){
|
||||
|
||||
$this->textNoAddons = "No"." ".$this->textPlural." "."Found";
|
||||
|
||||
$this->initDistinctTypeName();
|
||||
|
||||
$this->typeNameCategory = $this->typeName;
|
||||
|
||||
if(empty($this->typeNameCategory) && $this->isLayout == true)
|
||||
$this->typeNameCategory = GlobalsUC::ADDON_TYPE_REGULAR_LAYOUT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* function for override
|
||||
*/
|
||||
protected function initChild(){}
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public function __construct($typeName = ""){
|
||||
|
||||
$this->init();
|
||||
|
||||
if(!empty($typeName))
|
||||
$this->typeName = $typeName;
|
||||
|
||||
$this->initChild();
|
||||
$this->initInternal();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get addon type object
|
||||
*/
|
||||
public static function getAddonTypeObject($type, $isLayout = false){
|
||||
|
||||
|
||||
if(empty($type)){
|
||||
|
||||
if($isLayout == true)
|
||||
$type = GlobalsUC::ADDON_TYPE_REGULAR_LAYOUT;
|
||||
else
|
||||
$type = GlobalsUC::ADDON_TYPE_REGULAR_ADDON;
|
||||
}
|
||||
|
||||
|
||||
$cacheName = $type;
|
||||
if(empty($type))
|
||||
$cacheName = GlobalsUC::ADDON_TYPE_REGULAR_ADDON;
|
||||
|
||||
if(isset(self::$arrTypesCache[$cacheName]))
|
||||
return(self::$arrTypesCache[$cacheName]);
|
||||
|
||||
switch($type){
|
||||
case GlobalsUC::ADDON_TYPE_SHAPE_DEVIDER:
|
||||
$objType = new UniteCreatorAddonType_Shape_Divider();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_SHAPES:
|
||||
$objType = new UniteCreatorAddonType_Shape();
|
||||
break;
|
||||
case "elementor": //special type
|
||||
case "vc": //special type
|
||||
$objType = new UniteCreatorAddonType($type);
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_REGULAR_ADDON:
|
||||
$objType = new UniteCreatorAddonType();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_REGULAR_LAYOUT:
|
||||
$objType = new UniteCreatorAddonType_Layout();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_LAYOUT_SECTION:
|
||||
$objType = new UniteCreatorAddonType_Layout_Section();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_LAYOUT_GENERAL:
|
||||
$objType = new UniteCreatorAddonType_Layout_General();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_BGADDON:
|
||||
$objType = new UniteCreatorAddonType_BGAddon();
|
||||
break;
|
||||
default:
|
||||
UniteFunctionsUC::throwError("wrong addon type: ".$type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
self::$arrTypesCache[$cacheName] = $objType;
|
||||
|
||||
return($objType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get addon types for the picker
|
||||
*/
|
||||
public static function getAddonTypesForAddonPicker(){
|
||||
|
||||
$arrTypeNames = array();
|
||||
$arrTypeNames[] = GlobalsUC::ADDON_TYPE_REGULAR_ADDON;
|
||||
$arrTypeNames[] = GlobalsUC::ADDON_TYPE_SHAPES;
|
||||
|
||||
$arrTypes = array();
|
||||
foreach($arrTypeNames as $typeName){
|
||||
|
||||
$objType = self::getAddonTypeObject($typeName);
|
||||
$arrTypes[$typeName] = $objType->textShowType;
|
||||
}
|
||||
|
||||
return($arrTypes);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_BGAddon extends UniteCreatorAddonType{
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function init(){
|
||||
|
||||
$this->typeName = GlobalsUC::ADDON_TYPE_BGADDON;
|
||||
$this->textSingle = __("Background Widget", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("Background Widgets", "unlimited-elements-for-elementor");
|
||||
$this->textShowType = $this->textSingle;
|
||||
$this->titlePrefix = $this->textSingle." - ";
|
||||
$this->isBasicType = false;
|
||||
$this->allowWebCatalog = true;
|
||||
$this->allowManagerWebCatalog = true;
|
||||
$this->catalogKey = $this->typeName;
|
||||
$this->allowNoCategory = false;
|
||||
$this->defaultCatTitle = "Main";
|
||||
|
||||
$this->browser_textBuy = esc_html__("Go Pro", "unlimited-elements-for-elementor");
|
||||
$this->browser_textHoverPro = __("Upgrade to PRO version <br> to use this widget", "unlimited-elements-for-elementor");
|
||||
$this->browser_urlPreview = "https://unlimited-elements.com/widget-preview/?widget=[name]";
|
||||
|
||||
$urlLicense = GlobalsUnlimitedElements::LINK_BUY;
|
||||
|
||||
$this->browser_urlBuyPro = $urlLicense;
|
||||
|
||||
$responseAssets = UniteProviderFunctionsUC::setAssetsPath("ac_assets", true);
|
||||
|
||||
$this->pathAssets = $responseAssets["path_assets"];
|
||||
$this->urlAssets = $responseAssets["url_assets"];
|
||||
|
||||
$this->addonView_urlBack = HelperUC::getViewUrl(GlobalsUnlimitedElements::VIEW_BACKGROUNDS);
|
||||
$this->addonView_showSmallIconOption = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_Layout extends UniteCreatorAddonType{
|
||||
|
||||
const DISPLAYTYPE_TABLE = "table";
|
||||
const DISPLAYTYPE_MANAGER = "manager";
|
||||
const DISPLAYTYPE_BOTH = "both";
|
||||
|
||||
const LAYOUT_PARAMS_TYPE_SCREENSHOT = "screenshot";
|
||||
|
||||
public $isTemplate = false, $displayType = self::DISPLAYTYPE_TABLE;
|
||||
public $layoutTypeForCategory = "layout", $allowImportFromCatalog = true, $allowManagerLocalLayouts = true;
|
||||
public $showPageSettings = true, $defaultBlankTemplate = false;
|
||||
public $paramsSettingsType = null, $paramSettingsTitle = null, $showParamsTopBarButton = false;
|
||||
public $putScreenshotOnGridSave = false;
|
||||
public $arrLayoutBrowserAddonTypes = null;
|
||||
public $postType = null, $isBloxPage = true;
|
||||
|
||||
|
||||
/**
|
||||
* construct
|
||||
*/
|
||||
public function __construct($typeName = ""){
|
||||
parent::__construct($typeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function initChild(){
|
||||
|
||||
$this->isLayout = true;
|
||||
|
||||
$this->textShowType = $this->textSingle;
|
||||
|
||||
$this->paramsSettingsType = "screenshot";
|
||||
$this->paramSettingsTitle = __("Preview Image Settings", "unlimited-elements-for-elementor");
|
||||
|
||||
$this->requireCatalogPreview = true;
|
||||
$this->allowWebCatalog = false;
|
||||
$this->catalogKey = "pages";
|
||||
$this->allowManagerWebCatalog = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_Layout_General extends UniteCreatorAddonType_Layout{
|
||||
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function initChild(){
|
||||
|
||||
parent::initChild();
|
||||
|
||||
$this->typeName = GlobalsUC::ADDON_TYPE_LAYOUT_GENERAL;
|
||||
|
||||
$this->isBasicType = false;
|
||||
$this->textSingle = __("Layout", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("General Layouts", "unlimited-elements-for-elementor");
|
||||
$this->layoutTypeForCategory = $this->typeName;
|
||||
|
||||
$this->textShowType = $this->textSingle;
|
||||
$this->displayType = self::DISPLAYTYPE_MANAGER;
|
||||
|
||||
$this->allowImportFromCatalog = true;
|
||||
$this->allowDuplicateTitle = false;
|
||||
|
||||
$this->isAutoScreenshot = true;
|
||||
$this->allowNoCategory = false;
|
||||
$this->allowWebCatalog = false;
|
||||
$this->showPageSettings = true;
|
||||
|
||||
$this->defaultBlankTemplate = true;
|
||||
$this->enableShortcodes = true;
|
||||
|
||||
$this->paramsSettingsType = "screenshot";
|
||||
$this->paramSettingsTitle = __("Preview Image Settings", "unlimited-elements-for-elementor");
|
||||
$this->putScreenshotOnGridSave = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_Layout_Section extends UniteCreatorAddonType_Layout{
|
||||
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function initChild(){
|
||||
|
||||
parent::initChild();
|
||||
|
||||
$this->typeName = GlobalsUC::ADDON_TYPE_LAYOUT_SECTION;
|
||||
|
||||
$this->isBasicType = false;
|
||||
$this->textSingle = __("Section", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("Sections", "unlimited-elements-for-elementor");
|
||||
$this->layoutTypeForCategory = $this->typeName;
|
||||
|
||||
$this->textShowType = $this->textSingle;
|
||||
$this->displayType = self::DISPLAYTYPE_MANAGER;
|
||||
$this->allowImportFromCatalog = false;
|
||||
$this->allowDuplicateTitle = false;
|
||||
$this->isAutoScreenshot = true;
|
||||
$this->allowNoCategory = false;
|
||||
$this->allowWebCatalog = true;
|
||||
$this->showPageSettings = false;
|
||||
$this->defaultBlankTemplate = true;
|
||||
$this->exportPrefix = "section_";
|
||||
$this->titlePrefix = $this->textSingle." - ";
|
||||
$this->allowManagerWebCatalog = true;
|
||||
$this->catalogKey = $this->typeName;
|
||||
|
||||
$this->paramsSettingsType = "screenshot";
|
||||
$this->paramSettingsTitle = __("Preview Image Settings", "unlimited-elements-for-elementor");
|
||||
$this->showParamsTopBarButton = true;
|
||||
$this->putScreenshotOnGridSave = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_Shape extends UniteCreatorAddonType{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function init(){
|
||||
|
||||
$this->typeName = GlobalsUC::ADDON_TYPE_SHAPES;
|
||||
$this->textSingle = __("Shape", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("Shapes", "unlimited-elements-for-elementor");
|
||||
$this->isSVG = true;
|
||||
$this->textShowType = $this->textSingle;
|
||||
$this->titlePrefix = $this->textSingle." - ";
|
||||
$this->isBasicType = false;
|
||||
$this->allowWebCatalog = true;
|
||||
$this->allowManagerWebCatalog = true;
|
||||
$this->catalogKey = $this->typeName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonType_Shape_Divider extends UniteCreatorAddonType{
|
||||
|
||||
|
||||
/**
|
||||
* init the addon type
|
||||
*/
|
||||
protected function initChild(){
|
||||
|
||||
$this->typeName = GlobalsUC::ADDON_TYPE_SHAPE_DEVIDER;
|
||||
$this->textSingle = __("Divider", "unlimited-elements-for-elementor");
|
||||
$this->textPlural = __("Dividers", "unlimited-elements-for-elementor");
|
||||
$this->isSVG = true;
|
||||
$this->textShowType = $this->textSingle;
|
||||
$this->titlePrefix = $this->textSingle." - ";
|
||||
$this->isBasicType = false;
|
||||
$this->allowWebCatalog = true;
|
||||
$this->allowManagerWebCatalog = true;
|
||||
$this->catalogKey = $this->typeName;
|
||||
$this->browser_addEmptyItem = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteBaseAdminClassUC{
|
||||
|
||||
|
||||
protected static $master_view;
|
||||
protected static $view;
|
||||
|
||||
private static $arrSettings = array();
|
||||
private static $tempVars = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* main constructor
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->initView();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get path to settings file
|
||||
* @param $settingsFile
|
||||
*/
|
||||
protected static function getSettingsFilePath($settingsFile){
|
||||
|
||||
$filepath = self::$path_plugin."settings/$settingsFile.php";
|
||||
return($filepath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set the view from GET variables
|
||||
*/
|
||||
private function initView(){
|
||||
|
||||
$defaultView = GlobalsUC::$view_default;
|
||||
|
||||
//set view
|
||||
$viewInput = UniteFunctionsUC::getGetVar("view","",UniteFunctionsUC::SANITIZE_KEY);
|
||||
$page = UniteFunctionsUC::getGetVar("page","",UniteFunctionsUC::SANITIZE_KEY);
|
||||
|
||||
//get the view out of the page
|
||||
|
||||
if(!empty($viewInput)){
|
||||
self::$view = $viewInput;
|
||||
return(false);
|
||||
}
|
||||
|
||||
//check bottom devider
|
||||
$deviderPos = strpos($page,"_");
|
||||
if($deviderPos !== false){
|
||||
|
||||
self::$view = substr($page, $deviderPos+1);
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
//check middle devider
|
||||
$deviderPos = strpos($page, "-");
|
||||
if($deviderPos !== false){
|
||||
self::$view = substr($page, $deviderPos+1);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
self::$view = $defaultView;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set view that will be the master
|
||||
*/
|
||||
protected static function setMasterView($masterView){
|
||||
self::$master_view = $masterView;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* scan all plugin paths, maybe find the view there
|
||||
*/
|
||||
private static function getPluginViewFilePath($viewFilepath, $view){
|
||||
|
||||
if(empty($view))
|
||||
return($viewFilepath);
|
||||
|
||||
$arrViewPaths = GlobalsUC::$arrAdminViewPaths;
|
||||
|
||||
if(empty($arrViewPaths))
|
||||
return($viewFilepath);
|
||||
|
||||
foreach($arrViewPaths as $path){
|
||||
|
||||
$filepath = $path.$view.".php";
|
||||
|
||||
if(file_exists($filepath) == true)
|
||||
return($filepath);
|
||||
|
||||
}
|
||||
|
||||
return($viewFilepath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* inlcude some view file
|
||||
*/
|
||||
protected static function requireView($view){
|
||||
|
||||
try{
|
||||
|
||||
//require master view file, and
|
||||
if(!empty(self::$master_view) && !isset(self::$tempVars["is_masterView"]) ){
|
||||
$masterViewFilepath = GlobalsUC::$pathViews.self::$master_view.".php";
|
||||
|
||||
UniteFunctionsUC::validateFilepath($masterViewFilepath,"Master View");
|
||||
|
||||
self::$tempVars["is_masterView"] = true;
|
||||
|
||||
require $masterViewFilepath;
|
||||
|
||||
}
|
||||
else{ //simple require the view file.
|
||||
|
||||
$viewFilepath = GlobalsUC::$pathViews.$view.".php";
|
||||
$pathViewProvider = GlobalsUC::$pathProviderViews.$view.".php";
|
||||
|
||||
//replace thef ile by provider view file if needed
|
||||
if(file_exists($viewFilepath) == false && file_exists($pathViewProvider) == true)
|
||||
$viewFilepath = $pathViewProvider;
|
||||
|
||||
/**
|
||||
* check admin view array
|
||||
*/
|
||||
if(file_exists($viewFilepath) == false)
|
||||
$viewFilepath = self::getPluginViewFilePath($viewFilepath, $view);
|
||||
|
||||
$viewFilepath = UniteProviderFunctionsUC::applyFilters(UniteCreatorFilters::FILTER_ADMIN_VIEW_FILEPATH, $viewFilepath, $view);
|
||||
|
||||
UniteFunctionsUC::validateFilepath($viewFilepath,"View");
|
||||
|
||||
require $viewFilepath;
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception $e){
|
||||
|
||||
$view = esc_html($view);
|
||||
$message = $e->getMessage();
|
||||
$message = esc_html($message);
|
||||
|
||||
echo "<div id='uc_view_error_message'> <br><br>View ($view) Error: <b>".$message."</b>";
|
||||
|
||||
if(GlobalsUC::$SHOW_TRACE == true)
|
||||
dmp($e->getTraceAsString());
|
||||
echo "</div>";
|
||||
?>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
var htmlError = jQuery("#uc_view_error_message").html();
|
||||
jQuery("#viewWrapper").append("Duplicating Error Here: <br> <div style='padding-left:20px;padding-right:20px;'>"+htmlError+"</div><br><br>");
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* require settings file, the filename without .php
|
||||
*/
|
||||
protected static function requireSettings($settingsFile){
|
||||
|
||||
try{
|
||||
require self::$path_plugin."settings/$settingsFile.php";
|
||||
}catch (Exception $e){
|
||||
echo "<br><br>Settings ($settingsFile) Error: <b>".$e->getMessage()."</b>";
|
||||
dmp($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get view
|
||||
*/
|
||||
public static function getView(){
|
||||
|
||||
return self::$view;
|
||||
}
|
||||
|
||||
/**
|
||||
* set view manually
|
||||
*/
|
||||
public static function setView($view){
|
||||
self::$view = $view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteOutputBaseUC{
|
||||
|
||||
protected $arrParams;
|
||||
protected $arrOriginalParams; //params as they came originally from the database
|
||||
|
||||
protected $skipJsOptions = array();
|
||||
|
||||
const TYPE_NUMBER = "number";
|
||||
const TYPE_BOOLEAN = "boolean";
|
||||
const TYPE_OBJECT = "object";
|
||||
const TYPE_SIZE = "size";
|
||||
|
||||
const VALIDATE_EXISTS = "validate";
|
||||
const VALIDATE_NUMERIC = "numeric";
|
||||
const VALIDATE_SIZE = "size";
|
||||
const FORCE_NUMERIC = "force_numeric";
|
||||
const FORCE_BOOLEAN = "force_boolean";
|
||||
const FORCE_SIZE = "force_size";
|
||||
|
||||
|
||||
/**
|
||||
* add js option to skip
|
||||
*/
|
||||
protected function addSkipJsOption($name){
|
||||
|
||||
$this->skipJsOptions[$name] = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if some param exists in params array
|
||||
*/
|
||||
protected function isParamExists($name){
|
||||
$exists = array_key_exists($name, $this->arrParams);
|
||||
return $exists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get some param
|
||||
*/
|
||||
protected function getParam($name, $validateMode = null){
|
||||
|
||||
if(is_array($this->arrParams) == false)
|
||||
$this->arrParams = array();
|
||||
|
||||
if(array_key_exists($name, $this->arrParams)){
|
||||
$arrParams = $this->arrParams;
|
||||
$value = $this->arrParams[$name];
|
||||
}
|
||||
else{
|
||||
if(is_array($this->arrOriginalParams) == false)
|
||||
$this->arrOriginalParams = array();
|
||||
|
||||
$arrParams = $this->arrOriginalParams;
|
||||
$value = UniteFunctionsUC::getVal($this->arrOriginalParams, $name);
|
||||
}
|
||||
|
||||
switch ($validateMode) {
|
||||
case self::VALIDATE_EXISTS:
|
||||
if (array_key_exists($name, $arrParams) == false)
|
||||
UniteFunctionsUC::throwError("The param: {$name} don't exists");
|
||||
break;
|
||||
case self::VALIDATE_NUMERIC:
|
||||
if (is_numeric($value) == false)
|
||||
UniteFunctionsUC::throwError("The param: {$name} is not numeric");
|
||||
break;
|
||||
case self::VALIDATE_SIZE:
|
||||
if(strpos($value, "%") === false && is_numeric($value) == false)
|
||||
UniteFunctionsUC::throwError("The param: {$name} is not size");
|
||||
break;
|
||||
case self::FORCE_SIZE:
|
||||
$isPercent = (strpos($value, "%") !== false);
|
||||
if($isPercent == false && is_numeric($value) == false)
|
||||
UniteFunctionsUC::throwError("The param: {$name} is not size");
|
||||
|
||||
if($isPercent == false)
|
||||
$value .= "px";
|
||||
break;
|
||||
case self::FORCE_NUMERIC:
|
||||
$value = floatval($value);
|
||||
$value = (double) $value;
|
||||
break;
|
||||
case self::FORCE_BOOLEAN:
|
||||
$value = UniteFunctionsUC::strToBool($value);
|
||||
break;
|
||||
}
|
||||
|
||||
return($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rename option (if exists)
|
||||
*/
|
||||
protected function renameOption($keySource, $keyDest){
|
||||
|
||||
if(array_key_exists($keySource, $this->arrParams)){
|
||||
|
||||
$this->arrParams[$keyDest] = $this->arrParams[$keySource];
|
||||
unset($this->arrParams[$keySource]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* build javascript param
|
||||
*/
|
||||
protected function buildJsParam($paramName, $validate = null, $type = null){
|
||||
$output = array("name"=>$paramName, "validate"=>$validate, "type"=>$type);
|
||||
return($output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* build and get js settings
|
||||
*/
|
||||
protected function buildJsParams(){
|
||||
|
||||
$arrJsParams = $this->getArrJsOptions();
|
||||
$jsOutput = "";
|
||||
$counter = 0;
|
||||
$tabs = " ";
|
||||
|
||||
|
||||
foreach($arrJsParams as $arrParam){
|
||||
$name = $arrParam["name"];
|
||||
$validate = $arrParam["validate"];
|
||||
$type = $arrParam["type"];
|
||||
|
||||
if(array_key_exists($name, $this->skipJsOptions) == true)
|
||||
continue;
|
||||
|
||||
if($this->isParamExists($name)){
|
||||
$value = $this->getParam($name, $validate);
|
||||
|
||||
$putInBrackets = false;
|
||||
switch($type){
|
||||
case self::TYPE_NUMBER:
|
||||
case self::TYPE_BOOLEAN:
|
||||
case self::TYPE_OBJECT:
|
||||
break;
|
||||
case self::TYPE_SIZE:
|
||||
if(strpos($value, "%") !== 0)
|
||||
$putInBrackets = true;
|
||||
break;
|
||||
default: //string
|
||||
$putInBrackets = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if($putInBrackets == true){
|
||||
$value = str_replace('"','\\"', $value);
|
||||
$value = '"'.$value.'"';
|
||||
}
|
||||
|
||||
if($counter > 0)
|
||||
$jsOutput .= ",\n".$tabs;
|
||||
$jsOutput .= "{$name}:{$value}";
|
||||
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
$jsOutput .= "\n";
|
||||
|
||||
return($jsOutput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get string from position options
|
||||
*/
|
||||
protected function getPositionString(){
|
||||
|
||||
$position = $this->getParam("position");
|
||||
|
||||
$wrapperStyle = "";
|
||||
|
||||
switch($position){
|
||||
case "default":
|
||||
break;
|
||||
case "center":
|
||||
default:
|
||||
$wrapperStyle .= "margin:0px auto;";
|
||||
break;
|
||||
case "left":
|
||||
$wrapperStyle .= "float:left;";
|
||||
break;
|
||||
case "right":
|
||||
$wrapperStyle .= "float:right;";
|
||||
break;
|
||||
}
|
||||
|
||||
//add left / right margin
|
||||
if($position != "center"){
|
||||
$marginLeft = $this->getParam("margin_left", self::FORCE_NUMERIC);
|
||||
$marginRight = $this->getParam("margin_right", self::FORCE_NUMERIC);
|
||||
|
||||
if($marginLeft != 0)
|
||||
$wrapperStyle .= "margin-left:{$marginLeft}px;";
|
||||
|
||||
if($marginRight != 0)
|
||||
$wrapperStyle .= "margin-right:{$marginRight}px;";
|
||||
|
||||
}
|
||||
|
||||
//add top / bottom margin
|
||||
$marginTop = $this->getParam("margin_top", self::FORCE_NUMERIC);
|
||||
$marginBottom = $this->getParam("margin_bottom", self::FORCE_NUMERIC);
|
||||
|
||||
if($marginTop != 0)
|
||||
$wrapperStyle .= "margin-top:{$marginTop}px;";
|
||||
|
||||
if($marginBottom != 0)
|
||||
$wrapperStyle .= "margin-bottom:{$marginBottom}px;";
|
||||
|
||||
return($wrapperStyle);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCssParserUC{
|
||||
|
||||
private $cssContent;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* init the parser, set css content
|
||||
*/
|
||||
public function initContent($cssContent){
|
||||
$this->cssContent = $cssContent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get array of slide classes, between two sections.
|
||||
*/
|
||||
public function getArrClasses($startText = "",$endText=""){
|
||||
|
||||
$content = $this->cssContent;
|
||||
|
||||
//trim from top
|
||||
if(!empty($startText)){
|
||||
$posStart = strpos($content, $startText);
|
||||
if($posStart !== false)
|
||||
$content = substr($content, $posStart,strlen($content)-$posStart);
|
||||
}
|
||||
|
||||
//trim from bottom
|
||||
if(!empty($endText)){
|
||||
$posEnd = strpos($content, $endText);
|
||||
if($posEnd !== false)
|
||||
$content = substr($content,0,$posEnd);
|
||||
}
|
||||
|
||||
//get styles
|
||||
$lines = explode("\n",$content);
|
||||
$arrClasses = array();
|
||||
foreach($lines as $key=>$line){
|
||||
$line = trim($line);
|
||||
|
||||
if(strpos($line, "{") === false)
|
||||
continue;
|
||||
|
||||
//skip unnessasary links
|
||||
if(strpos($line, ".caption a") !== false)
|
||||
continue;
|
||||
|
||||
if(strpos($line, ".tp-caption a") !== false)
|
||||
continue;
|
||||
|
||||
//get style out of the line
|
||||
$class = str_replace("{", "", $line);
|
||||
$class = trim($class);
|
||||
|
||||
//skip captions like this: .tp-caption.imageclass img
|
||||
if(strpos($class," ") !== false)
|
||||
continue;
|
||||
|
||||
//skip captions like this: .tp-caption.imageclass:hover, :before, :after
|
||||
if(strpos($class,":") !== false)
|
||||
continue;
|
||||
|
||||
$class = str_replace(".caption.", ".", $class);
|
||||
$class = str_replace(".tp-caption.", ".", $class);
|
||||
|
||||
$class = str_replace(".", "", $class);
|
||||
$class = trim($class);
|
||||
$arrWords = explode(" ", $class);
|
||||
$class = $arrWords[count($arrWords)-1];
|
||||
$class = trim($class);
|
||||
|
||||
$arrClasses[] = $class;
|
||||
}
|
||||
|
||||
sort($arrClasses);
|
||||
|
||||
return($arrClasses);
|
||||
}
|
||||
|
||||
public static function parseCssToArray($css){
|
||||
|
||||
while(strpos($css, '/*') !== false){
|
||||
if(strpos($css, '*/') === false) return false;
|
||||
$start = strpos($css, '/*');
|
||||
$end = strpos($css, '*/') + 2;
|
||||
$css = str_replace(substr($css, $start, $end - $start), '', $css);
|
||||
}
|
||||
|
||||
preg_match_all( '/(?ims)([a-z0-9\s\.\:#_\-@]+)\{([^\}]*)\}/', $css, $arr);
|
||||
|
||||
$result = array();
|
||||
foreach ($arr[0] as $i => $x){
|
||||
$selector = trim($arr[1][$i]);
|
||||
if(strpos($selector, '{') !== false || strpos($selector, '}') !== false) return false;
|
||||
$rules = explode(';', trim($arr[2][$i]));
|
||||
$result[$selector] = array();
|
||||
foreach ($rules as $strRule){
|
||||
if (!empty($strRule)){
|
||||
$rule = explode(":", $strRule);
|
||||
if(strpos($rule[0], '{') !== false || strpos($rule[0], '}') !== false || strpos($rule[1], '{') !== false || strpos($rule[1], '}') !== false) return false;
|
||||
|
||||
//put back everything but not $rule[0];
|
||||
$key = trim($rule[0]);
|
||||
unset($rule[0]);
|
||||
$values = implode(':', $rule);
|
||||
|
||||
$result[$selector][trim($key)] = trim(str_replace("'", '"', $values));
|
||||
}
|
||||
}
|
||||
}
|
||||
return($result);
|
||||
}
|
||||
|
||||
public static function parseDbArrayToCss($cssArray, $nl = "\n\r"){
|
||||
|
||||
$css = '';
|
||||
foreach($cssArray as $id => $attr){
|
||||
|
||||
$params = $attr['params'];
|
||||
|
||||
$styles = json_decode($params);
|
||||
|
||||
if(empty($styles))
|
||||
$styles = json_decode($params);
|
||||
|
||||
if(!empty($styles))
|
||||
$styles = (array)$styles;
|
||||
|
||||
$css.= $attr['handle']." {".$nl;
|
||||
if(is_array($styles)){
|
||||
foreach($styles as $name => $style){
|
||||
$css.= $name.':'.$style.";".$nl;
|
||||
}
|
||||
}
|
||||
$css.= "}".$nl.$nl;
|
||||
|
||||
//add hover
|
||||
$setting = json_decode($attr['settings'], true);
|
||||
if(@$setting['hover'] == 'true'){
|
||||
$hover = json_decode($attr['hover'], true);
|
||||
if(is_array($hover)){
|
||||
$css.= $attr['handle'].":hover {".$nl;
|
||||
foreach($hover as $name => $style){
|
||||
$css.= $name.':'.$style.";".$nl;
|
||||
}
|
||||
$css.= "}".$nl.$nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $css;
|
||||
}
|
||||
|
||||
public static function parseArrayToCss($cssArray, $nl = "\n\r"){
|
||||
$css = '';
|
||||
foreach($cssArray as $id => $attr){
|
||||
$styles = (array)$attr['params'];
|
||||
$css.= $attr['handle']." {".$nl;
|
||||
if(is_array($styles) && !empty($styles)){
|
||||
foreach($styles as $name => $style){
|
||||
if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
|
||||
$rgb = explode(',', str_replace('rgba', 'rgb', $style));
|
||||
unset($rgb[count($rgb)-1]);
|
||||
$rgb = implode(',', $rgb).')';
|
||||
$css.= $name.':'.$rgb.";".$nl;
|
||||
}
|
||||
$css.= $name.':'.$style.";".$nl;
|
||||
}
|
||||
}
|
||||
$css.= "}".$nl.$nl;
|
||||
|
||||
//add hover
|
||||
$setting = (array)$attr['settings'];
|
||||
if(@$setting['hover'] == 'true'){
|
||||
$hover = (array)$attr['hover'];
|
||||
if(is_array($hover)){
|
||||
$css.= $attr['handle'].":hover {".$nl;
|
||||
foreach($hover as $name => $style){
|
||||
if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
|
||||
$rgb = explode(',', str_replace('rgba', 'rgb', $style));
|
||||
unset($rgb[count($rgb)-1]);
|
||||
$rgb = implode(',', $rgb).')';
|
||||
$css.= $name.':'.$rgb.";".$nl;
|
||||
}
|
||||
$css.= $name.':'.$style.";".$nl;
|
||||
}
|
||||
$css.= "}".$nl.$nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $css;
|
||||
}
|
||||
|
||||
|
||||
public static function parseStaticArrayToCss($cssArray, $nl = "\n"){
|
||||
$css = '';
|
||||
foreach($cssArray as $class => $styles){
|
||||
$css.= $class." {".$nl;
|
||||
if(is_array($styles) && !empty($styles)){
|
||||
foreach($styles as $name => $style){
|
||||
$css.= $name.':'.$style.";".$nl;
|
||||
}
|
||||
}
|
||||
$css.= "}".$nl.$nl;
|
||||
}
|
||||
return $css;
|
||||
}
|
||||
|
||||
public static function parseDbArrayToArray($cssArray, $handle = false){
|
||||
|
||||
if(!is_array($cssArray) || empty($cssArray)) return false;
|
||||
|
||||
foreach($cssArray as $key => $css){
|
||||
if($handle != false){
|
||||
if($cssArray[$key]['handle'] == '.tp-caption.'.$handle){
|
||||
$cssArray[$key]['params'] = json_decode($css['params']);
|
||||
$cssArray[$key]['hover'] = json_decode($css['hover']);
|
||||
$cssArray[$key]['settings'] = json_decode($css['settings']);
|
||||
return $cssArray[$key];
|
||||
}else{
|
||||
unset($cssArray[$key]);
|
||||
}
|
||||
}else{
|
||||
$cssArray[$key]['params'] = json_decode($css['params']);
|
||||
$cssArray[$key]['hover'] = json_decode($css['hover']);
|
||||
$cssArray[$key]['settings'] = json_decode($css['settings']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $cssArray;
|
||||
}
|
||||
|
||||
|
||||
public static function compress_css($buffer){
|
||||
/* remove comments */
|
||||
$buffer = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $buffer) ;
|
||||
/* remove tabs, spaces, newlines, etc. */
|
||||
$arr = array("\r\n", "\r", "\n", "\t", " ", " ", " ");
|
||||
$rep = array("", "", "", "", " ", " ", " ");
|
||||
$buffer = str_replace($arr, $rep, $buffer);
|
||||
/* remove whitespaces around {}:, */
|
||||
$buffer = preg_replace("/\s*([\{\}:,])\s*/", "$1", $buffer);
|
||||
/* remove last ; */
|
||||
$buffer = str_replace(';}', "}", $buffer);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,609 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCreatorDB{
|
||||
|
||||
const ISNULL = "dbisnull";
|
||||
|
||||
private $pdb;
|
||||
private $lastRowID;
|
||||
public static $arrTableTitles;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* constructor - set database object
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->pdb = new UniteProviderDBUC();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* throw error
|
||||
*/
|
||||
private function throwError($message,$code=-1){
|
||||
UniteFunctionsUC::throwError($message,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the original db object
|
||||
*/
|
||||
public function getPDB(){
|
||||
|
||||
return($this->pdb->getDBObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* validate for errors
|
||||
* @param unknown_type $prefix
|
||||
*/
|
||||
private function checkForErrors($prefix = ""){
|
||||
|
||||
$message = $this->pdb->getErrorMsg();
|
||||
|
||||
if(!$message)
|
||||
return(false);
|
||||
|
||||
if(!empty($prefix))
|
||||
$message = $prefix." ".$message;
|
||||
|
||||
$errorNum = $this->pdb->getErrorNum();
|
||||
|
||||
$this->throwError($message, $errorNum);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return if table exists
|
||||
*/
|
||||
public function isTableExists($table){
|
||||
|
||||
try{
|
||||
|
||||
$this->fetchSql("select * from $table limit 1", true);
|
||||
|
||||
}catch(Exception $e){
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* insert variables to some table
|
||||
*/
|
||||
public function insert($tableName,$arrItems){
|
||||
|
||||
$strFields = "";
|
||||
$strValues = "";
|
||||
foreach($arrItems as $field=>$value){
|
||||
$value = "'".$this->escape($value)."'";
|
||||
if($field == "id") continue;
|
||||
if($strFields != "") $strFields .= ",";
|
||||
if($strValues != "") $strValues .= ",";
|
||||
$strFields .= $field;
|
||||
$strValues .= $value;
|
||||
}
|
||||
|
||||
$insertQuery = "insert into $tableName($strFields) values($strValues)";
|
||||
|
||||
$this->runSql($insertQuery,"insert");
|
||||
$this->lastRowID = $this->pdb->insertid();
|
||||
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get last insert id
|
||||
*/
|
||||
public function getLastInsertID(){
|
||||
$this->lastRowID = $this->pdb->insertid();
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* delete rows
|
||||
*/
|
||||
public function delete($table,$where){
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($table,"table name");
|
||||
UniteFunctionsUC::validateNotEmpty($where,"where");
|
||||
|
||||
if(is_array($where))
|
||||
$where = $this->getWhereString($where);
|
||||
|
||||
$query = "delete from $table where $where";
|
||||
|
||||
$success = $this->runSql($query, "delete error");
|
||||
return($success);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete multiple items from table by id
|
||||
* Enter description here ...
|
||||
*/
|
||||
public function deleteMultipleByID($table, $arrItems){
|
||||
|
||||
foreach($arrItems as $key=>$itemID)
|
||||
$arrItems[$key] = (int)$itemID;
|
||||
|
||||
$strItemsIDs = implode(",", $arrItems);
|
||||
|
||||
$this->delete($table,"id in($strItemsIDs)");
|
||||
}
|
||||
|
||||
/**
|
||||
* get category id with "all" option
|
||||
*/
|
||||
public function getWhereCatIDWithAll($catID){
|
||||
|
||||
$arrWhere = array();
|
||||
|
||||
if(is_numeric($catID))
|
||||
$catID = (int)$catID;
|
||||
|
||||
if($catID === null)
|
||||
$catID = "all";
|
||||
|
||||
//get catID where
|
||||
if($catID === "all"){
|
||||
$arrWhere = array();
|
||||
}
|
||||
else if(is_numeric($catID)){
|
||||
$catID = (int)$catID;
|
||||
$arrWhere[] = "catid=$catID";
|
||||
}
|
||||
else{ //multiple - array of id's
|
||||
|
||||
if(is_array($catID) == false)
|
||||
UniteFunctionsUC::throwError("catIDs could be array or number");
|
||||
|
||||
$strCats = implode(",", $catID);
|
||||
$strCats = $this->escape($strCats); //for any case
|
||||
$arrWhere[] = "catid in($strCats)";
|
||||
}
|
||||
|
||||
|
||||
return($arrWhere);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get where string from where array
|
||||
*/
|
||||
private function getWhereString($where){
|
||||
|
||||
$where_format = null;
|
||||
|
||||
foreach ( $where as $key=>$value ) {
|
||||
|
||||
if($value == self::ISNULL){
|
||||
$wheres[] = "($key = '' or $key is null)";
|
||||
continue;
|
||||
}
|
||||
|
||||
if($key == self::ISNULL || is_numeric($key)){
|
||||
$wheres[] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
// array('sign',values);
|
||||
|
||||
$sign = "=";
|
||||
|
||||
$isEscape = true;
|
||||
|
||||
if(is_array($value)){
|
||||
$sign = $value[0];
|
||||
$value = $value[1];
|
||||
}
|
||||
|
||||
if(is_numeric($value) == false){
|
||||
$value = $this->escape($value);
|
||||
$value = "'$value'";
|
||||
}
|
||||
|
||||
$wheres[] = "$key $sign {$value}";
|
||||
}
|
||||
|
||||
$strWhere = implode( ' AND ', $wheres );
|
||||
|
||||
return($strWhere);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* insert variables to some table
|
||||
*/
|
||||
public function update($tableName,$arrData,$where){
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($tableName,"table cannot be empty");
|
||||
UniteFunctionsUC::validateNotEmpty($where,"where cannot be empty");
|
||||
UniteFunctionsUC::validateNotEmpty($arrData,"data cannot be empty");
|
||||
|
||||
if(is_array($where))
|
||||
$where = $this->getWhereString($where);
|
||||
|
||||
$strFields = "";
|
||||
foreach($arrData as $field=>$value){
|
||||
$value = "'".$this->escape($value)."'";
|
||||
if($strFields != "") $strFields .= ",";
|
||||
$strFields .= "$field=$value";
|
||||
}
|
||||
|
||||
$updateQuery = "update $tableName set $strFields where $where";
|
||||
|
||||
$numRows = $this->runSql($updateQuery, "update error");
|
||||
|
||||
return($numRows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* run some sql query
|
||||
*/
|
||||
public function runSql($query){
|
||||
|
||||
$response = $this->pdb->query($query);
|
||||
|
||||
$this->checkForErrors("Regular query error");
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* fetch rows from sql query
|
||||
*/
|
||||
public function fetchSql($query, $supressErrors = false){
|
||||
|
||||
$rows = $this->pdb->fetchSql($query, $supressErrors);
|
||||
|
||||
$this->checkForErrors("fetch");
|
||||
|
||||
$rows = UniteFunctionsUC::convertStdClassToArray($rows);
|
||||
|
||||
return($rows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get row wp emulator
|
||||
*/
|
||||
public function get_row($query = null){
|
||||
|
||||
$rows = $this->pdb->fetchSql($query);
|
||||
|
||||
$this->checkForErrors("get_row");
|
||||
|
||||
if(count($rows) == 1)
|
||||
$result = $rows[0];
|
||||
else
|
||||
$result = $rows;
|
||||
|
||||
return($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get "where" query part
|
||||
*/
|
||||
private function getQueryPart_where($where = ""){
|
||||
|
||||
if($where){
|
||||
|
||||
if(is_array($where))
|
||||
$where = $this->getWhereString($where);
|
||||
|
||||
$where = " where $where";
|
||||
}
|
||||
|
||||
return($where);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create fetch query
|
||||
*/
|
||||
private function createFetchQuery($tableName, $fields=null, $where="", $orderField="", $groupByField="", $sqlAddon=""){
|
||||
|
||||
if(empty($fields)){
|
||||
$fields = "*";
|
||||
}else{
|
||||
if(is_array($fields))
|
||||
$fields = implode(",", $fields);
|
||||
}
|
||||
|
||||
$query = "select $fields from $tableName";
|
||||
|
||||
$where = $this->getQueryPart_where($where);
|
||||
|
||||
if(!empty($where))
|
||||
$query .= $where;
|
||||
|
||||
if($orderField){
|
||||
$orderField = $this->escape($orderField);
|
||||
$query .= " order by $orderField";
|
||||
}
|
||||
|
||||
if($groupByField){
|
||||
$groupByField = $this->escape($groupByField);
|
||||
$query .= " group by $groupByField";
|
||||
}
|
||||
|
||||
if($sqlAddon)
|
||||
$query .= " ".$sqlAddon;
|
||||
|
||||
return($query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get data array from the database
|
||||
*
|
||||
*/
|
||||
public function fetch($tableName, $where="", $orderField="", $groupByField="", $sqlAddon=""){
|
||||
|
||||
$query = $this->createFetchQuery($tableName, null, $where, $orderField, $groupByField, $sqlAddon);
|
||||
|
||||
$rows = $this->fetchSql($query);
|
||||
|
||||
return($rows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get total rows
|
||||
*/
|
||||
public function getTotalRows($tableName, $where=""){
|
||||
|
||||
$where = $this->getQueryPart_where($where);
|
||||
|
||||
$query = "select count(*) as numrows from $tableName".$where;
|
||||
|
||||
$response = $this->fetchSql($query);
|
||||
|
||||
$totalRows = $response[0]["numrows"];
|
||||
|
||||
return($totalRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch records by id's
|
||||
*/
|
||||
public function fetchByIDs($table, $arrIDs){
|
||||
|
||||
if(is_string($arrIDs))
|
||||
$strIDs = $arrIDs;
|
||||
else
|
||||
$strIDs = implode(",", $arrIDs);
|
||||
|
||||
$sql = "select * from {$table} where id in({$strIDs})";
|
||||
$arrRecords = $this->fetchSql($sql);
|
||||
|
||||
return($arrRecords);
|
||||
}
|
||||
|
||||
/**
|
||||
* update objects ordering
|
||||
* using (ordering, id fields, and ID's array)
|
||||
*/
|
||||
public function updateRecordsOrdering($table, $arrIDs){
|
||||
|
||||
$arrRecords = $this->fetchByIDs($table, $arrIDs);
|
||||
|
||||
//get items assoc
|
||||
$arrRecords = UniteFunctionsUC::arrayToAssoc($arrRecords,"id");
|
||||
|
||||
$order = 0;
|
||||
foreach($arrIDs as $recordID){
|
||||
$order++;
|
||||
|
||||
$arrRecord = UniteFunctionsUC::getVal($arrRecords, $recordID);
|
||||
if(!empty($arrRecord) && $arrRecord["ordering"] == $order)
|
||||
continue;
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["ordering"] = $order;
|
||||
$this->update($table, $arrUpdate, array("id"=>$recordID));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get data array from the database
|
||||
* pagingOptions - page, inpage
|
||||
*/
|
||||
public function fetchPage($tableName, $pagingOptions, $where="", $orderField="", $groupByField="", $sqlAddon=""){
|
||||
|
||||
$page = UniteFunctionsUC::getVal($pagingOptions, "page");
|
||||
$rowsInPage = UniteFunctionsUC::getVal($pagingOptions, "inpage");
|
||||
|
||||
|
||||
//valdiate and sanitize
|
||||
UniteFunctionsUC::validateNumeric($page);
|
||||
UniteFunctionsUC::validateNumeric($rowsInPage);
|
||||
UniteFunctionsUC::validateNotEmpty($rowsInPage);
|
||||
if($page < 1)
|
||||
$page = 1;
|
||||
|
||||
|
||||
//get total
|
||||
$totalRows = $this->getTotalRows($tableName, $where);
|
||||
$numPages = $pages = ceil($totalRows / $rowsInPage);
|
||||
|
||||
//build query
|
||||
$offset = ($page - 1) * $rowsInPage;
|
||||
|
||||
$query = $this->createFetchQuery($tableName, null, $where, $orderField, $groupByField, $sqlAddon);
|
||||
|
||||
$query .= " limit $rowsInPage offset $offset";
|
||||
|
||||
$rows = $this->fetchSql($query);
|
||||
|
||||
//output response
|
||||
$response = array();
|
||||
$response["total"] = $totalRows;
|
||||
$response["page"] = $page;
|
||||
$response["num_pages"] = $numPages;
|
||||
$response["inpage"] = $rowsInPage;
|
||||
|
||||
$response["rows"] = $rows;
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fields could be array or string comma saparated
|
||||
*/
|
||||
public function fetchFields($tableName, $fields, $where="", $orderField="", $groupByField="", $sqlAddon=""){
|
||||
|
||||
$query = $this->createFetchQuery($tableName, $fields, $where, $orderField, $groupByField, $sqlAddon);
|
||||
|
||||
$rows = $this->fetchSql($query);
|
||||
|
||||
return($rows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* fetch only one item. if not found - throw error
|
||||
*/
|
||||
public function fetchSingle($tableName,$where="",$orderField="",$groupByField="",$sqlAddon=""){
|
||||
|
||||
$errorEmpty = "";
|
||||
|
||||
if(is_array($tableName)){
|
||||
$arguments = $tableName;
|
||||
|
||||
$tableName = UniteFunctionsUC::getVal($arguments, "tableName");
|
||||
$where = UniteFunctionsUC::getVal($arguments, "where");
|
||||
$orderField = UniteFunctionsUC::getVal($arguments, "orderField");
|
||||
$groupByField = UniteFunctionsUC::getVal($arguments, "groupByField");
|
||||
$sqlAddon = UniteFunctionsUC::getVal($arguments, "sqlAddon");
|
||||
$errorEmpty = UniteFunctionsUC::getVal($arguments, "errorEmpty");
|
||||
}
|
||||
|
||||
if(empty($errorEmpty)){
|
||||
$tableTitle = UniteFunctionsUC::getVal(self::$arrTableTitles, $tableName, __("Record", "unlimited-elements-for-elementor"));
|
||||
|
||||
$errorEmpty = $tableTitle." ".__("not found", "unlimited-elements-for-elementor");
|
||||
}
|
||||
|
||||
$response = $this->fetch($tableName, $where, $orderField, $groupByField, $sqlAddon);
|
||||
|
||||
if(empty($response)){
|
||||
$this->throwError($errorEmpty);
|
||||
}
|
||||
|
||||
$record = $response[0];
|
||||
return($record);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get max order from categories list
|
||||
*/
|
||||
public function getMaxOrder($table, $field = "ordering"){
|
||||
|
||||
$query = "select MAX($field) as maxorder from {$table}";
|
||||
|
||||
$rows = $this->fetchSql($query);
|
||||
|
||||
$maxOrder = 0;
|
||||
if(count($rows)>0)
|
||||
$maxOrder = $rows[0]["maxorder"];
|
||||
|
||||
if(!is_numeric($maxOrder))
|
||||
$maxOrder = 0;
|
||||
|
||||
return($maxOrder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update layout in db
|
||||
*/
|
||||
public function createObjectInDB($table, $arrInsert){
|
||||
|
||||
$maxOrder = $this->getMaxOrder($table);
|
||||
|
||||
$arrInsert["ordering"] = $maxOrder+1;
|
||||
|
||||
$id = $this->insert($table, $arrInsert);
|
||||
|
||||
return($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* escape data to avoid sql errors and injections.
|
||||
*/
|
||||
public function escape($string){
|
||||
$newString = $this->pdb->escape($string);
|
||||
return($newString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get sql addon type for quest string
|
||||
*/
|
||||
public function getSqlAddonType($addonType, $dbfield = "addontype"){
|
||||
|
||||
if(is_array($addonType)){
|
||||
|
||||
$arrSql = array();
|
||||
foreach($addonType as $singleType)
|
||||
$arrSql[] = $this->getSqlAddonType($singleType, $dbfield);
|
||||
|
||||
$sql = "(".implode(" or ", $arrSql).")";
|
||||
return($sql);
|
||||
}
|
||||
|
||||
if($addonType == GlobalsUC::ADDON_TYPE_REGULAR_ADDON || $addonType == GlobalsUC::ADDON_TYPE_LAYOUT_GENERAL)
|
||||
$addonType = null;
|
||||
|
||||
$addonType = $this->escape($addonType);
|
||||
if(empty($addonType)){
|
||||
$where = "({$dbfield}='' or {$dbfield} is null)";
|
||||
}else
|
||||
$where = "{$dbfield}='{$addonType}'";
|
||||
|
||||
|
||||
return($where);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteElementsBaseUC{
|
||||
|
||||
protected $db;
|
||||
protected $imageView;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$this->db = new UniteCreatorDB();
|
||||
$this->imageView = new UniteImageViewUC();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
class UEExchangeRateAPIClient{
|
||||
|
||||
const BASE_URL = "https://v6.exchangerate-api.com/v6";
|
||||
|
||||
private $apiKey;
|
||||
private $cacheTime = 0; // in seconds
|
||||
|
||||
/**
|
||||
* Create a new client instance.
|
||||
*
|
||||
* @param string $apiKey
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($apiKey){
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache time.
|
||||
*
|
||||
* @param int $seconds
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCacheTime($seconds){
|
||||
|
||||
$this->cacheTime = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of rates for the given currency (ISO 4217).
|
||||
*
|
||||
* @param string $currency
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRates($currency){
|
||||
|
||||
try{
|
||||
$currency = urlencode($currency);
|
||||
|
||||
$response = $this->get("/latest/$currency");
|
||||
$rates = array();
|
||||
|
||||
foreach($response["conversion_rates"] as $code => $rate){
|
||||
$rates[] = UEExchangeRateAPIRate::transform(array(
|
||||
'code' => $code,
|
||||
'rate' => $rate,
|
||||
));
|
||||
}
|
||||
|
||||
return $rates;
|
||||
}catch(UEHttpResponseException $exception){
|
||||
if($exception->getResponse()->status() === 404)
|
||||
throw new Exception("Invalid currency.");
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a GET request to the API.
|
||||
*
|
||||
* @param $endpoint
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function get($endpoint, $params = array()){
|
||||
|
||||
return $this->request(UEHttpRequest::METHOD_GET, $endpoint, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to the API.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function request($method, $endpoint, $params = array()){
|
||||
|
||||
$url = self::BASE_URL . "/" . $this->apiKey . $endpoint;
|
||||
$query = ($method === UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
$body = ($method !== UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->asJson();
|
||||
$request->acceptJson();
|
||||
$request->cacheTime($this->cacheTime);
|
||||
$request->withQuery($query);
|
||||
$request->withBody($body);
|
||||
|
||||
$request->validateResponse(function($response){
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if($data["result"] !== "success")
|
||||
$this->throwError($data["error-type"]);
|
||||
});
|
||||
|
||||
$response = $request->request($method, $url);
|
||||
$data = $response->json();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown an exception with the given message.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function throwError($message){
|
||||
|
||||
UniteFunctionsUC::throwError("ExchangeRate API Error: $message");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/client.class.php";
|
||||
require_once __DIR__ . "/model.class.php";
|
||||
|
||||
require_once __DIR__ . "/rate.class.php";
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
abstract class UEExchangeRateAPIModel{
|
||||
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($attributes){
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform list of items into models.
|
||||
*
|
||||
* @param array $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function transformAll($items){
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach($items as $attributes){
|
||||
$data[] = self::transform($attributes);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attributes into a model.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function transform($attributes){
|
||||
|
||||
$model = new static($attributes);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribute value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getAttribute($key, $fallback = null){
|
||||
|
||||
$value = UniteFunctionsUC::getVal($this->attributes, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,925 @@
|
||||
<?php
|
||||
|
||||
class UEExchangeRateAPIRate extends UEExchangeRateAPIModel{
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getCode();
|
||||
$id = strtolower($id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCode(){
|
||||
|
||||
$code = $this->getAttribute("code");
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(){
|
||||
|
||||
$name = $this->getInfo("name", $this->getCode());
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symbol.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSymbol(){
|
||||
|
||||
$symbol = $this->getInfo("symbol", $this->getCode());
|
||||
|
||||
return $symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFlagUrl(){
|
||||
|
||||
$country = $this->getCountry();
|
||||
$country = strtolower($country);
|
||||
|
||||
$url = "https://flagcdn.com/" . $country . ".svg";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate.
|
||||
*
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRate($precision = 2){
|
||||
|
||||
$rate = $this->getAttribute("rate");
|
||||
$rate = number_format($rate, $precision, ".", "");
|
||||
|
||||
return $rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the info.
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getInfo($field, $code){
|
||||
|
||||
$info = array(
|
||||
"USD" => array(
|
||||
"name" => "United States Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "US",
|
||||
),
|
||||
"AED" => array(
|
||||
"name" => "United Arab Emirates Dirham",
|
||||
"symbol" => "د.إ",
|
||||
"country" => "AE",
|
||||
),
|
||||
"AFN" => array(
|
||||
"name" => "Afghan Afghani",
|
||||
"symbol" => "؋",
|
||||
"country" => "AF",
|
||||
),
|
||||
"ALL" => array(
|
||||
"name" => "Albanian Lek",
|
||||
"symbol" => "L",
|
||||
"country" => "AL",
|
||||
),
|
||||
"AMD" => array(
|
||||
"name" => "Armenian Dram",
|
||||
"symbol" => "֏",
|
||||
"country" => "AM",
|
||||
),
|
||||
"ANG" => array(
|
||||
"name" => "Netherlands Antillean Guilder",
|
||||
"symbol" => "ƒ",
|
||||
"country" => "NL",
|
||||
),
|
||||
"AOA" => array(
|
||||
"name" => "Angolan Kwanza",
|
||||
"symbol" => "Kz",
|
||||
"country" => "AO",
|
||||
),
|
||||
"ARS" => array(
|
||||
"name" => "Argentine Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "AR",
|
||||
),
|
||||
"AUD" => array(
|
||||
"name" => "Australian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "AU",
|
||||
),
|
||||
"AWG" => array(
|
||||
"name" => "Aruban Florin",
|
||||
"symbol" => "ƒ",
|
||||
"country" => "AW",
|
||||
),
|
||||
"AZN" => array(
|
||||
"name" => "Azerbaijani Manat",
|
||||
"symbol" => "₼",
|
||||
"country" => "AZ",
|
||||
),
|
||||
"BAM" => array(
|
||||
"name" => "Bosnia-Herzegovina Convertible Mark",
|
||||
"symbol" => "KM",
|
||||
"country" => "BA",
|
||||
),
|
||||
"BBD" => array(
|
||||
"name" => "Barbadian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "BB",
|
||||
),
|
||||
"BDT" => array(
|
||||
"name" => "Bangladeshi Taka",
|
||||
"symbol" => "৳",
|
||||
"country" => "BD",
|
||||
),
|
||||
"BGN" => array(
|
||||
"name" => "Bulgarian Lev",
|
||||
"symbol" => "лв",
|
||||
"country" => "BG",
|
||||
),
|
||||
"BHD" => array(
|
||||
"name" => "Bahraini Dinar",
|
||||
"symbol" => "ب.د",
|
||||
"country" => "BH",
|
||||
),
|
||||
"BIF" => array(
|
||||
"name" => "Burundian Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "BI",
|
||||
),
|
||||
"BMD" => array(
|
||||
"name" => "Bermudian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "BM",
|
||||
),
|
||||
"BND" => array(
|
||||
"name" => "Brunei Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "BN",
|
||||
),
|
||||
"BOB" => array(
|
||||
"name" => "Bolivian Boliviano",
|
||||
"symbol" => "Bs.",
|
||||
"country" => "BO",
|
||||
),
|
||||
"BRL" => array(
|
||||
"name" => "Brazilian Real",
|
||||
"symbol" => "R$",
|
||||
"country" => "BR",
|
||||
),
|
||||
"BSD" => array(
|
||||
"name" => "Bahamian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "BS",
|
||||
),
|
||||
"BTN" => array(
|
||||
"name" => "Bhutanese Ngultrum",
|
||||
"symbol" => "Nu.",
|
||||
"country" => "BT",
|
||||
),
|
||||
"BWP" => array(
|
||||
"name" => "Botswanan Pula",
|
||||
"symbol" => "P",
|
||||
"country" => "BW",
|
||||
),
|
||||
"BYN" => array(
|
||||
"name" => "Belarusian Ruble",
|
||||
"symbol" => "Br",
|
||||
"country" => "BY",
|
||||
),
|
||||
"BZD" => array(
|
||||
"name" => "Belize Dollar",
|
||||
"symbol" => "BZ$",
|
||||
"country" => "BZ",
|
||||
),
|
||||
"CAD" => array(
|
||||
"name" => "Canadian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "CA",
|
||||
),
|
||||
"CDF" => array(
|
||||
"name" => "Congolese Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "CD",
|
||||
),
|
||||
"CHF" => array(
|
||||
"name" => "Swiss Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "CH",
|
||||
),
|
||||
"CLP" => array(
|
||||
"name" => "Chilean Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "CL",
|
||||
),
|
||||
"CNY" => array(
|
||||
"name" => "Chinese Yuan",
|
||||
"symbol" => "¥",
|
||||
"country" => "CN",
|
||||
),
|
||||
"COP" => array(
|
||||
"name" => "Colombian Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "CO",
|
||||
),
|
||||
"CRC" => array(
|
||||
"name" => "Costa Rican Colón",
|
||||
"symbol" => "₡",
|
||||
"country" => "CR",
|
||||
),
|
||||
"CUP" => array(
|
||||
"name" => "Cuban Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "CU",
|
||||
),
|
||||
"CVE" => array(
|
||||
"name" => "Cape Verdean Escudo",
|
||||
"symbol" => "$",
|
||||
"country" => "CV",
|
||||
),
|
||||
"CZK" => array(
|
||||
"name" => "Czech Republic Koruna",
|
||||
"symbol" => "Kč",
|
||||
"country" => "CZ",
|
||||
),
|
||||
"DJF" => array(
|
||||
"name" => "Djiboutian Franc",
|
||||
"symbol" => "Fdj",
|
||||
"country" => "DJ",
|
||||
),
|
||||
"DKK" => array(
|
||||
"name" => "Danish Krone",
|
||||
"symbol" => "kr",
|
||||
"country" => "DK",
|
||||
),
|
||||
"DOP" => array(
|
||||
"name" => "Dominican Peso",
|
||||
"symbol" => "RD$",
|
||||
"country" => "DO",
|
||||
),
|
||||
"DZD" => array(
|
||||
"name" => "Algerian Dinar",
|
||||
"symbol" => "دج",
|
||||
"country" => "DZ",
|
||||
),
|
||||
"EGP" => array(
|
||||
"name" => "Egyptian Pound",
|
||||
"symbol" => "E£",
|
||||
"country" => "EG",
|
||||
),
|
||||
"ERN" => array(
|
||||
"name" => "Eritrean Nakfa",
|
||||
"symbol" => "Nfk",
|
||||
"country" => "ER",
|
||||
),
|
||||
"ETB" => array(
|
||||
"name" => "Ethiopian Birr",
|
||||
"symbol" => "Br",
|
||||
"country" => "ET",
|
||||
),
|
||||
"EUR" => array(
|
||||
"name" => "Euro",
|
||||
"symbol" => "€",
|
||||
"country" => "EU",
|
||||
),
|
||||
"FJD" => array(
|
||||
"name" => "Fijian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "FJ",
|
||||
),
|
||||
"FKP" => array(
|
||||
"name" => "Falkland Islands Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "FK",
|
||||
),
|
||||
"FOK" => array(
|
||||
"name" => "Faroese Króna",
|
||||
"symbol" => "kr",
|
||||
"country" => "FO",
|
||||
),
|
||||
"GBP" => array(
|
||||
"name" => "British Pound Sterling",
|
||||
"symbol" => "£",
|
||||
"country" => "GB",
|
||||
),
|
||||
"GEL" => array(
|
||||
"name" => "Georgian Lari",
|
||||
"symbol" => "₾",
|
||||
"country" => "GE",
|
||||
),
|
||||
"GGP" => array(
|
||||
"name" => "Guernsey Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "GG",
|
||||
),
|
||||
"GHS" => array(
|
||||
"name" => "Ghanaian Cedi",
|
||||
"symbol" => "₵",
|
||||
"country" => "GH",
|
||||
),
|
||||
"GIP" => array(
|
||||
"name" => "Gibraltar Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "GI",
|
||||
),
|
||||
"GMD" => array(
|
||||
"name" => "Gambian Dalasi",
|
||||
"symbol" => "D",
|
||||
"country" => "GM",
|
||||
),
|
||||
"GNF" => array(
|
||||
"name" => "Guinean Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "GN",
|
||||
),
|
||||
"GTQ" => array(
|
||||
"name" => "Guatemalan Quetzal",
|
||||
"symbol" => "Q",
|
||||
"country" => "GT",
|
||||
),
|
||||
"GYD" => array(
|
||||
"name" => "Guyanese Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "GY",
|
||||
),
|
||||
"HKD" => array(
|
||||
"name" => "Hong Kong Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "HK",
|
||||
),
|
||||
"HNL" => array(
|
||||
"name" => "Honduran Lempira",
|
||||
"symbol" => "L",
|
||||
"country" => "HN",
|
||||
),
|
||||
"HRK" => array(
|
||||
"name" => "Croatian Kuna",
|
||||
"symbol" => "kn",
|
||||
"country" => "HR",
|
||||
),
|
||||
"HTG" => array(
|
||||
"name" => "Haitian Gourde",
|
||||
"symbol" => "G",
|
||||
"country" => "HT",
|
||||
),
|
||||
"HUF" => array(
|
||||
"name" => "Hungarian Forint",
|
||||
"symbol" => "Ft",
|
||||
"country" => "HU",
|
||||
),
|
||||
"IDR" => array(
|
||||
"name" => "Indonesian Rupiah",
|
||||
"symbol" => "Rp",
|
||||
"country" => "ID",
|
||||
),
|
||||
"ILS" => array(
|
||||
"name" => "Israeli New Shekel",
|
||||
"symbol" => "₪",
|
||||
"country" => "IL",
|
||||
),
|
||||
"IMP" => array(
|
||||
"name" => "Isle of Man Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "IM",
|
||||
),
|
||||
"INR" => array(
|
||||
"name" => "Indian Rupee",
|
||||
"symbol" => "₹",
|
||||
"country" => "IN",
|
||||
),
|
||||
"IQD" => array(
|
||||
"name" => "Iraqi Dinar",
|
||||
"symbol" => "ع.د",
|
||||
"country" => "IQ",
|
||||
),
|
||||
"IRR" => array(
|
||||
"name" => "Iranian Rial",
|
||||
"symbol" => "﷼",
|
||||
"country" => "IR",
|
||||
),
|
||||
"ISK" => array(
|
||||
"name" => "Icelandic Króna",
|
||||
"symbol" => "kr",
|
||||
"country" => "IS",
|
||||
),
|
||||
"JEP" => array(
|
||||
"name" => "Jersey Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "JE",
|
||||
),
|
||||
"JMD" => array(
|
||||
"name" => "Jamaican Dollar",
|
||||
"symbol" => "J$",
|
||||
"country" => "JM",
|
||||
),
|
||||
"JOD" => array(
|
||||
"name" => "Jordanian Dinar",
|
||||
"symbol" => "د.ا",
|
||||
"country" => "JO",
|
||||
),
|
||||
"JPY" => array(
|
||||
"name" => "Japanese Yen",
|
||||
"symbol" => "¥",
|
||||
"country" => "JP",
|
||||
),
|
||||
"KES" => array(
|
||||
"name" => "Kenyan Shilling",
|
||||
"symbol" => "KSh",
|
||||
"country" => "KE",
|
||||
),
|
||||
"KGS" => array(
|
||||
"name" => "Kyrgystani Som",
|
||||
"symbol" => "с",
|
||||
"country" => "KG",
|
||||
),
|
||||
"KHR" => array(
|
||||
"name" => "Cambodian Riel",
|
||||
"symbol" => "៛",
|
||||
"country" => "KH",
|
||||
),
|
||||
"KID" => array(
|
||||
"name" => "Kiribati Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "KI",
|
||||
),
|
||||
"KMF" => array(
|
||||
"name" => "Comorian Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "KM",
|
||||
),
|
||||
"KRW" => array(
|
||||
"name" => "South Korean Won",
|
||||
"symbol" => "₩",
|
||||
"country" => "KR",
|
||||
),
|
||||
"KWD" => array(
|
||||
"name" => "Kuwaiti Dinar",
|
||||
"symbol" => "د.ك",
|
||||
"country" => "KW",
|
||||
),
|
||||
"KYD" => array(
|
||||
"name" => "Cayman Islands Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "KY",
|
||||
),
|
||||
"KZT" => array(
|
||||
"name" => "Kazakhstani Tenge",
|
||||
"symbol" => "₸",
|
||||
"country" => "KZ",
|
||||
),
|
||||
"LAK" => array(
|
||||
"name" => "Laotian Kip",
|
||||
"symbol" => "₭",
|
||||
"country" => "LA",
|
||||
),
|
||||
"LBP" => array(
|
||||
"name" => "Lebanese Pound",
|
||||
"symbol" => "ل.ل",
|
||||
"country" => "LB",
|
||||
),
|
||||
"LKR" => array(
|
||||
"name" => "Sri Lankan Rupee",
|
||||
"symbol" => "₨",
|
||||
"country" => "LK",
|
||||
),
|
||||
"LRD" => array(
|
||||
"name" => "Liberian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "LR",
|
||||
),
|
||||
"LSL" => array(
|
||||
"name" => "Lesotho Loti",
|
||||
"symbol" => "L",
|
||||
"country" => "LS",
|
||||
),
|
||||
"LYD" => array(
|
||||
"name" => "Libyan Dinar",
|
||||
"symbol" => "ل.د",
|
||||
"country" => "LY",
|
||||
),
|
||||
"MAD" => array(
|
||||
"name" => "Moroccan Dirham",
|
||||
"symbol" => "د.م.",
|
||||
"country" => "MA",
|
||||
),
|
||||
"MDL" => array(
|
||||
"name" => "Moldovan Leu",
|
||||
"symbol" => "L",
|
||||
"country" => "MD",
|
||||
),
|
||||
"MGA" => array(
|
||||
"name" => "Malagasy Ariary",
|
||||
"symbol" => "Ar",
|
||||
"country" => "MG",
|
||||
),
|
||||
"MKD" => array(
|
||||
"name" => "Macedonian Denar",
|
||||
"symbol" => "ден",
|
||||
"country" => "MK",
|
||||
),
|
||||
"MMK" => array(
|
||||
"name" => "Myanmar Kyat",
|
||||
"symbol" => "K",
|
||||
"country" => "MM",
|
||||
),
|
||||
"MNT" => array(
|
||||
"name" => "Mongolian Tugrik",
|
||||
"symbol" => "₮",
|
||||
"country" => "MN",
|
||||
),
|
||||
"MOP" => array(
|
||||
"name" => "Macanese Pataca",
|
||||
"symbol" => "MOP$",
|
||||
"country" => "MO",
|
||||
),
|
||||
"MRU" => array(
|
||||
"name" => "Mauritanian Ouguiya",
|
||||
"symbol" => "UM",
|
||||
"country" => "MR",
|
||||
),
|
||||
"MUR" => array(
|
||||
"name" => "Mauritian Rupee",
|
||||
"symbol" => "₨",
|
||||
"country" => "MU",
|
||||
),
|
||||
"MVR" => array(
|
||||
"name" => "Maldivian Rufiyaa",
|
||||
"symbol" => "Rf",
|
||||
"country" => "MV",
|
||||
),
|
||||
"MWK" => array(
|
||||
"name" => "Malawian Kwacha",
|
||||
"symbol" => "MK",
|
||||
"country" => "MW",
|
||||
),
|
||||
"MXN" => array(
|
||||
"name" => "Mexican Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "MX",
|
||||
),
|
||||
"MYR" => array(
|
||||
"name" => "Malaysian Ringgit",
|
||||
"symbol" => "RM",
|
||||
"country" => "MY",
|
||||
),
|
||||
"MZN" => array(
|
||||
"name" => "Mozambican Metical",
|
||||
"symbol" => "MT",
|
||||
"country" => "MZ",
|
||||
),
|
||||
"NAD" => array(
|
||||
"name" => "Namibian Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "NA",
|
||||
),
|
||||
"NGN" => array(
|
||||
"name" => "Nigerian Naira",
|
||||
"symbol" => "₦",
|
||||
"country" => "NG",
|
||||
),
|
||||
"NIO" => array(
|
||||
"name" => "Nicaraguan Córdoba",
|
||||
"symbol" => "C$",
|
||||
"country" => "NI",
|
||||
),
|
||||
"NOK" => array(
|
||||
"name" => "Norwegian Krone",
|
||||
"symbol" => "kr",
|
||||
"country" => "NO",
|
||||
),
|
||||
"NPR" => array(
|
||||
"name" => "Nepalese Rupee",
|
||||
"symbol" => "₨",
|
||||
"country" => "NP",
|
||||
),
|
||||
"NZD" => array(
|
||||
"name" => "New Zealand Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "NZ",
|
||||
),
|
||||
"OMR" => array(
|
||||
"name" => "Omani Rial",
|
||||
"symbol" => "ر.ع.",
|
||||
"country" => "OM",
|
||||
),
|
||||
"PAB" => array(
|
||||
"name" => "Panamanian Balboa",
|
||||
"symbol" => "B/.",
|
||||
"country" => "PA",
|
||||
),
|
||||
"PEN" => array(
|
||||
"name" => "Peruvian Nuevo Sol",
|
||||
"symbol" => "S/.",
|
||||
"country" => "PE",
|
||||
),
|
||||
"PGK" => array(
|
||||
"name" => "Papua New Guinean Kina",
|
||||
"symbol" => "K",
|
||||
"country" => "PG",
|
||||
),
|
||||
"PHP" => array(
|
||||
"name" => "Philippine Peso",
|
||||
"symbol" => "₱",
|
||||
"country" => "PH",
|
||||
),
|
||||
"PKR" => array(
|
||||
"name" => "Pakistani Rupee",
|
||||
"symbol" => "₨",
|
||||
"country" => "PK",
|
||||
),
|
||||
"PLN" => array(
|
||||
"name" => "Polish Złoty",
|
||||
"symbol" => "zł",
|
||||
"country" => "PL",
|
||||
),
|
||||
"PYG" => array(
|
||||
"name" => "Paraguayan Guarani",
|
||||
"symbol" => "₲",
|
||||
"country" => "PY",
|
||||
),
|
||||
"QAR" => array(
|
||||
"name" => "Qatari Riyal",
|
||||
"symbol" => "ر.ق",
|
||||
"country" => "QA",
|
||||
),
|
||||
"RON" => array(
|
||||
"name" => "Romanian Leu",
|
||||
"symbol" => "lei",
|
||||
"country" => "RO",
|
||||
),
|
||||
"RSD" => array(
|
||||
"name" => "Serbian Dinar",
|
||||
"symbol" => "дин.",
|
||||
"country" => "RS",
|
||||
),
|
||||
"RUB" => array(
|
||||
"name" => "Russian Ruble",
|
||||
"symbol" => "₽",
|
||||
"country" => "RU",
|
||||
),
|
||||
"RWF" => array(
|
||||
"name" => "Rwandan Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "RW",
|
||||
),
|
||||
"SAR" => array(
|
||||
"name" => "Saudi Riyal",
|
||||
"symbol" => "ر.س",
|
||||
"country" => "SA",
|
||||
),
|
||||
"SBD" => array(
|
||||
"name" => "Solomon Islands Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "SB",
|
||||
),
|
||||
"SCR" => array(
|
||||
"name" => "Seychellois Rupee",
|
||||
"symbol" => "₨",
|
||||
"country" => "SC",
|
||||
),
|
||||
"SDG" => array(
|
||||
"name" => "Sudanese Pound",
|
||||
"symbol" => "ج.س.",
|
||||
"country" => "SD",
|
||||
),
|
||||
"SEK" => array(
|
||||
"name" => "Swedish Krona",
|
||||
"symbol" => "kr",
|
||||
"country" => "SE",
|
||||
),
|
||||
"SGD" => array(
|
||||
"name" => "Singapore Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "SG",
|
||||
),
|
||||
"SHP" => array(
|
||||
"name" => "Saint Helena Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "SH",
|
||||
),
|
||||
"SLE" => array(
|
||||
"name" => "Sierra Leonean Leone",
|
||||
"symbol" => "Le",
|
||||
"country" => "SL",
|
||||
),
|
||||
"SLL" => array(
|
||||
"name" => "Sierra Leonean Leone",
|
||||
"symbol" => "Le",
|
||||
"country" => "SL",
|
||||
),
|
||||
"SOS" => array(
|
||||
"name" => "Somali Shilling",
|
||||
"symbol" => "Sh.So.",
|
||||
"country" => "SO",
|
||||
),
|
||||
"SRD" => array(
|
||||
"name" => "Surinamese Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "SR",
|
||||
),
|
||||
"SSP" => array(
|
||||
"name" => "South Sudanese Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "SS",
|
||||
),
|
||||
"STN" => array(
|
||||
"name" => "São Tomé and Príncipe Dobra",
|
||||
"symbol" => "Db",
|
||||
"country" => "ST",
|
||||
),
|
||||
"SYP" => array(
|
||||
"name" => "Syrian Pound",
|
||||
"symbol" => "£",
|
||||
"country" => "SY",
|
||||
),
|
||||
"SZL" => array(
|
||||
"name" => "Swazi Lilangeni",
|
||||
"symbol" => "L",
|
||||
"country" => "SZ",
|
||||
),
|
||||
"THB" => array(
|
||||
"name" => "Thai Baht",
|
||||
"symbol" => "฿",
|
||||
"country" => "TH",
|
||||
),
|
||||
"TJS" => array(
|
||||
"name" => "Tajikistani Somoni",
|
||||
"symbol" => "ЅМ",
|
||||
"country" => "TJ",
|
||||
),
|
||||
"TMT" => array(
|
||||
"name" => "Turkmenistani Manat",
|
||||
"symbol" => "T",
|
||||
"country" => "TM",
|
||||
),
|
||||
"TND" => array(
|
||||
"name" => "Tunisian Dinar",
|
||||
"symbol" => "د.ت",
|
||||
"country" => "TN",
|
||||
),
|
||||
"TOP" => array(
|
||||
"name" => "Tongan Pa'anga",
|
||||
"symbol" => "T$",
|
||||
"country" => "TO",
|
||||
),
|
||||
"TRY" => array(
|
||||
"name" => "Turkish Lira",
|
||||
"symbol" => "₺",
|
||||
"country" => "TR",
|
||||
),
|
||||
"TTD" => array(
|
||||
"name" => "Trinidad and Tobago Dollar",
|
||||
"symbol" => "TT$",
|
||||
"country" => "TT",
|
||||
),
|
||||
"TVD" => array(
|
||||
"name" => "Tuvaluan Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "TV",
|
||||
),
|
||||
"TWD" => array(
|
||||
"name" => "New Taiwan Dollar",
|
||||
"symbol" => "NT$",
|
||||
"country" => "TW",
|
||||
),
|
||||
"TZS" => array(
|
||||
"name" => "Tanzanian Shilling",
|
||||
"symbol" => "TSh",
|
||||
"country" => "TZ",
|
||||
),
|
||||
"UAH" => array(
|
||||
"name" => "Ukrainian Hryvnia",
|
||||
"symbol" => "₴",
|
||||
"country" => "UA",
|
||||
),
|
||||
"UGX" => array(
|
||||
"name" => "Ugandan Shilling",
|
||||
"symbol" => "USh",
|
||||
"country" => "UG",
|
||||
),
|
||||
"UYU" => array(
|
||||
"name" => "Uruguayan Peso",
|
||||
"symbol" => "$",
|
||||
"country" => "UY",
|
||||
),
|
||||
"UZS" => array(
|
||||
"name" => "Uzbekistan Som",
|
||||
"symbol" => "лв",
|
||||
"country" => "UZ",
|
||||
),
|
||||
"VES" => array(
|
||||
"name" => "Venezuelan Bolívar",
|
||||
"symbol" => "Bs.S",
|
||||
"country" => "VE",
|
||||
),
|
||||
"VND" => array(
|
||||
"name" => "Vietnamese Dong",
|
||||
"symbol" => "₫",
|
||||
"country" => "VN",
|
||||
),
|
||||
"VUV" => array(
|
||||
"name" => "Vanuatu Vatu",
|
||||
"symbol" => "VT",
|
||||
"country" => "VU",
|
||||
),
|
||||
"WST" => array(
|
||||
"name" => "Samoan Tala",
|
||||
"symbol" => "WS$",
|
||||
"country" => "WS",
|
||||
),
|
||||
"XAF" => array(
|
||||
"name" => "Central African CFA Franc",
|
||||
"symbol" => "FCFA",
|
||||
"country" => "CM",
|
||||
),
|
||||
"XCD" => array(
|
||||
"name" => "East Caribbean Dollar",
|
||||
"symbol" => "$",
|
||||
"country" => "AG",
|
||||
),
|
||||
"XDR" => array(
|
||||
"name" => "International Monetary Fund (IMF) Special Drawing Rights",
|
||||
"symbol" => "XDR",
|
||||
"country" => "",
|
||||
),
|
||||
"XOF" => array(
|
||||
"name" => "West African CFA Franc",
|
||||
"symbol" => "CFA",
|
||||
"country" => "BJ",
|
||||
),
|
||||
"XPF" => array(
|
||||
"name" => "CFP Franc",
|
||||
"symbol" => "Fr",
|
||||
"country" => "PF",
|
||||
),
|
||||
"YER" => array(
|
||||
"name" => "Yemeni Rial",
|
||||
"symbol" => "﷼",
|
||||
"country" => "YE",
|
||||
),
|
||||
"ZAR" => array(
|
||||
"name" => "South African Rand",
|
||||
"symbol" => "R",
|
||||
"country" => "ZA",
|
||||
),
|
||||
"ZMW" => array(
|
||||
"name" => "Zambian Kwacha",
|
||||
"symbol" => "ZK",
|
||||
"country" => "ZM",
|
||||
),
|
||||
"ZWL" => array(
|
||||
"name" => "Zimbabwean Dollar",
|
||||
"symbol" => "Z$",
|
||||
"country" => "ZW",
|
||||
),
|
||||
);
|
||||
|
||||
$fields = UniteFunctionsUC::getVal($info, $code, array());
|
||||
$value = UniteFunctionsUC::getVal($fields, $field, "");
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the country.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCountry(){
|
||||
|
||||
$country = $this->getInfo("country", $this->getCode());
|
||||
|
||||
return $country;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if(!function_exists("dmp")){
|
||||
function dmp($str){
|
||||
|
||||
echo "<div align='left' style='direction:ltr;color:black;'>";
|
||||
echo "<pre>";
|
||||
print_r($str);
|
||||
echo "</pre>";
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists("dmpGet")){
|
||||
|
||||
function dmpGet($str){
|
||||
|
||||
$html = "";
|
||||
|
||||
$html .= "<div align='left' style='direction:ltr;color:black;'>";
|
||||
|
||||
$html .= "<pre>";
|
||||
$html .= print_r($str, true);
|
||||
$html .= "</pre>";
|
||||
$html .= "</div>";
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPICalendarEvent extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getAttribute("id");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(){
|
||||
|
||||
$title = $this->getAttribute("summary");
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description.
|
||||
*
|
||||
* @param bool $asHtml
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription($asHtml = false){
|
||||
|
||||
$description = $this->getAttribute("description");
|
||||
|
||||
if($asHtml === true)
|
||||
$description = nl2br($description);
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLocation(){
|
||||
|
||||
$location = $this->getAttribute("location");
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(){
|
||||
|
||||
$url = $this->getAttribute("htmlLink");
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStartDate($format){
|
||||
|
||||
$start = $this->getAttribute("start");
|
||||
$date = $this->getDate($start, $format);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEndDate($format){
|
||||
|
||||
$end = $this->getAttribute("end");
|
||||
$date = $this->getDate($end, $format);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date.
|
||||
*
|
||||
* @param object $time
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDate($time, $format){
|
||||
|
||||
$date = UniteFunctionsUC::getVal($time, "date", null);
|
||||
$dateTime = UniteFunctionsUC::getVal($time, "dateTime", null);
|
||||
|
||||
$date = $date ?: $dateTime;
|
||||
$time = strtotime($date);
|
||||
$date = date($format, $time);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* https://developers.google.com/calendar/api/v3/reference
|
||||
*/
|
||||
class UEGoogleAPICalendarService extends UEGoogleAPIClient{
|
||||
|
||||
/**
|
||||
* Get the events.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param array $params
|
||||
*
|
||||
* @return UEGoogleAPICalendarEvent[]
|
||||
*/
|
||||
public function getEvents($calendarId, $params = array()){
|
||||
|
||||
$calendarId = urlencode($calendarId);
|
||||
|
||||
$params["timeZone"] = wp_timezone_string();
|
||||
|
||||
$response = $this->get("/calendars/$calendarId/events", $params);
|
||||
$response = UEGoogleAPICalendarEvent::transformAll($response["items"]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the API.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseUrl(){
|
||||
|
||||
return "https://www.googleapis.com/calendar/v3";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
abstract class UEGoogleAPIClient{
|
||||
|
||||
const PARAM_QUERY = "__query__";
|
||||
|
||||
private $accessToken;
|
||||
private $apiKey;
|
||||
private $cacheTime = 0; // in seconds
|
||||
|
||||
/**
|
||||
* Set the access token.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAccessToken($token){
|
||||
|
||||
$this->accessToken = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the API key.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setApiKey($key){
|
||||
|
||||
$this->apiKey = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache time.
|
||||
*
|
||||
* @param int $seconds
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCacheTime($seconds){
|
||||
|
||||
$this->cacheTime = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the API.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getBaseUrl();
|
||||
|
||||
/**
|
||||
* Make a GET request to the API.
|
||||
*
|
||||
* @param $endpoint
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function get($endpoint, $params = array()){
|
||||
|
||||
return $this->request(UEHttpRequest::METHOD_GET, $endpoint, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a PUT request to the API.
|
||||
*
|
||||
* @param $endpoint
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function put($endpoint, $params = array()){
|
||||
|
||||
return $this->request(UEHttpRequest::METHOD_PUT, $endpoint, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a POST request to the API.
|
||||
*
|
||||
* @param $endpoint
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function post($endpoint, $params = array()){
|
||||
|
||||
return $this->request(UEHttpRequest::METHOD_POST, $endpoint, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to the API.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function request($method, $endpoint, $params = array()){
|
||||
|
||||
$url = $this->getBaseUrl() . $endpoint;
|
||||
$query = ($method === UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
$body = ($method !== UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
|
||||
if(empty($params[self::PARAM_QUERY]) === false){
|
||||
$query = array_merge($query, $params[self::PARAM_QUERY]);
|
||||
|
||||
unset($params[self::PARAM_QUERY]);
|
||||
}
|
||||
|
||||
$query = array_merge($query, $this->getAuthParams());
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->asJson();
|
||||
$request->acceptJson();
|
||||
$request->cacheTime($this->cacheTime);
|
||||
$request->withQuery($query);
|
||||
$request->withBody($body);
|
||||
|
||||
$request->validateResponse(function($response){
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if(empty($data["error"]) === false){
|
||||
$error = $data["error"];
|
||||
$message = $error["message"];
|
||||
$status = isset($error["status"]) ? $error["status"] : $error["code"];
|
||||
|
||||
$this->throwError("$message ($status)");
|
||||
}elseif(empty($data["error_message"]) === false){
|
||||
$message = $data["error_message"];
|
||||
$status = isset($data["status"]) ? $data["status"] : $data["code"];
|
||||
|
||||
$this->throwError("$message ($status)");
|
||||
}
|
||||
});
|
||||
|
||||
$response = $request->request($method, $url);
|
||||
$data = $response->json();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parameters for the authorization.
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getAuthParams(){
|
||||
|
||||
if(empty($this->accessToken) === false)
|
||||
return array("access_token" => $this->accessToken);
|
||||
|
||||
if(empty($this->apiKey) === false)
|
||||
return array("key" => $this->apiKey);
|
||||
|
||||
$this->throwError("Either an access token or an API key must be specified.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown an exception with the given message.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function throwError($message){
|
||||
|
||||
UniteFunctionsUC::throwError("Google API Error: $message");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPIHelper{
|
||||
|
||||
const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
||||
|
||||
const SCOPE_CALENDAR_EVENTS = "https://www.googleapis.com/auth/calendar.events.readonly";
|
||||
const SCOPE_SHEETS_ALL = "https://www.googleapis.com/auth/spreadsheets";
|
||||
const SCOPE_USER_EMAIL = "https://www.googleapis.com/auth/userinfo.email";
|
||||
const SCOPE_YOUTUBE = "https://www.googleapis.com/auth/youtube.readonly";
|
||||
|
||||
private static $credentials = array();
|
||||
|
||||
/**
|
||||
* Get the API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getApiKey(){
|
||||
|
||||
$apiKey = HelperProviderCoreUC_EL::getGeneralSetting("google_api_key");
|
||||
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the access token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAccessToken(){
|
||||
|
||||
$credentials = self::getCredentials();
|
||||
$accessToken = UniteFunctionsUC::getVal($credentials, "access_token");
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fresh access token.
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getFreshAccessToken(){
|
||||
|
||||
if(self::isAccessTokenExpired() === true)
|
||||
self::refreshAccessToken();
|
||||
|
||||
$accessToken = self::getAccessToken();
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's email address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getUserEmail(){
|
||||
|
||||
$credentials = self::getCredentials();
|
||||
$user = UniteFunctionsUC::getVal($credentials, "user", array());
|
||||
$email = UniteFunctionsUC::getVal($user, "email");
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorization URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthUrl(){
|
||||
|
||||
$returnUrl = HelperUC::getUrlAjax("save_google_connect_data");
|
||||
$returnUrl = UniteFunctionsUC::encodeContent($returnUrl);
|
||||
|
||||
$params = array(
|
||||
"client_id" => GlobalsUnlimitedElements::GOOGLE_CONNECTION_CLIENTID,
|
||||
"redirect_uri" => GlobalsUnlimitedElements::GOOGLE_CONNECTION_URL,
|
||||
"scope" => implode(" ", self::getScopes()),
|
||||
"access_type" => "offline",
|
||||
"prompt" => "consent select_account",
|
||||
"response_type" => "code",
|
||||
"include_granted_scopes" => "true",
|
||||
"state" => $returnUrl,
|
||||
);
|
||||
|
||||
$url = self::AUTH_URL . "?" . http_build_query($params);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the revoke URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRevokeUrl(){
|
||||
|
||||
$returnUrl = HelperUC::getUrlAjax("remove_google_connect_data");
|
||||
$returnUrl = UniteFunctionsUC::encodeContent($returnUrl);
|
||||
|
||||
$params = array(
|
||||
"revoke_token" => self::getAccessToken(),
|
||||
"state" => $returnUrl,
|
||||
);
|
||||
|
||||
$url = GlobalsUnlimitedElements::GOOGLE_CONNECTION_URL . "?" . http_build_query($params);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the credentials.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function saveCredentials($data){
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($data, "access_token");
|
||||
$refreshToken = UniteFunctionsUC::getVal($data, "refresh_token");
|
||||
$expiresAt = UniteFunctionsUC::getVal($data, "expires_at", 0);
|
||||
$scopes = UniteFunctionsUC::getVal($data, "scopes", array());
|
||||
$user = UniteFunctionsUC::getVal($data, "user", array());
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($accessToken, "access_token");
|
||||
UniteFunctionsUC::validateNotEmpty($refreshToken, "refresh_token");
|
||||
UniteFunctionsUC::validateNotEmpty($expiresAt, "expires_at");
|
||||
UniteFunctionsUC::validateNotEmpty($scopes, "scopes");
|
||||
UniteFunctionsUC::validateNotEmpty($user, "user");
|
||||
|
||||
self::validateScopes($scopes);
|
||||
|
||||
$credentials = array(
|
||||
"access_token" => $accessToken,
|
||||
"refresh_token" => $refreshToken,
|
||||
"expires_at" => $expiresAt,
|
||||
"scopes" => $scopes,
|
||||
"user" => $user,
|
||||
);
|
||||
|
||||
self::setCredentials($credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the credentials.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function removeCredentials(){
|
||||
|
||||
self::setCredentials(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to settings.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function redirectToSettings($params = array()){
|
||||
|
||||
$params = http_build_query($params) . "#tab=integrations";
|
||||
$url = HelperUC::getViewUrl(GlobalsUnlimitedElements::VIEW_SETTINGS_ELEMENTOR, $params);
|
||||
|
||||
UniteFunctionsUC::redirectToUrl($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scopes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getScopes(){
|
||||
|
||||
$scopes = array(
|
||||
self::SCOPE_SHEETS_ALL,
|
||||
self::SCOPE_USER_EMAIL,
|
||||
);
|
||||
|
||||
if(GlobalsUnlimitedElements::$enableGoogleCalendarScopes === true)
|
||||
$scopes[] = self::SCOPE_CALENDAR_EVENTS;
|
||||
|
||||
if(GlobalsUnlimitedElements::$enableGoogleYoutubeScopes === true)
|
||||
$scopes[] = self::SCOPE_YOUTUBE;
|
||||
|
||||
return $scopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the scopes.
|
||||
*
|
||||
* @param array $scopes
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function validateScopes($scopes){
|
||||
|
||||
$requestedScopes = self::getScopes();
|
||||
$grantedScopes = array_intersect($requestedScopes, $scopes);
|
||||
|
||||
if(count($grantedScopes) !== count($requestedScopes))
|
||||
UniteFunctionsUC::throwError("Required permissions are missing. Please grant all requested permissions.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credentials.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getCredentials(){
|
||||
|
||||
if(empty(self::$credentials) === true)
|
||||
self::$credentials = HelperProviderUC::getGoogleConnectCredentials();
|
||||
|
||||
return self::$credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the credentials.
|
||||
*
|
||||
* @param array $credentials
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function setCredentials($credentials){
|
||||
|
||||
self::$credentials = $credentials;
|
||||
|
||||
HelperProviderUC::saveGoogleConnectCredentials(self::$credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the credentials.
|
||||
*
|
||||
* @param array $credentials
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function mergeCredentials($credentials){
|
||||
|
||||
$credentials = array_merge(self::getCredentials(), $credentials);
|
||||
|
||||
self::setCredentials($credentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the refresh token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getRefreshToken(){
|
||||
|
||||
$credentials = self::getCredentials();
|
||||
$refreshToken = UniteFunctionsUC::getVal($credentials, "refresh_token");
|
||||
|
||||
return $refreshToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expiration time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function getExpirationTime(){
|
||||
|
||||
$credentials = self::getCredentials();
|
||||
$expirationTime = UniteFunctionsUC::getVal($credentials, "expires_at", 0);
|
||||
|
||||
return $expirationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the access token is expired.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function isAccessTokenExpired(){
|
||||
|
||||
$accessToken = self::getAccessToken();
|
||||
$expirationTime = self::getExpirationTime();
|
||||
|
||||
if(empty($accessToken) === true)
|
||||
return true;
|
||||
|
||||
// Check if the token expires in the next 30 seconds
|
||||
if($expirationTime - 30 < time())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the access token.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function refreshAccessToken(){
|
||||
|
||||
$refreshToken = self::getRefreshToken();
|
||||
|
||||
if(empty($refreshToken) === true)
|
||||
UniteFunctionsUC::throwError("Refresh token is missing.");
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->acceptJson();
|
||||
|
||||
$response = $request->get(GlobalsUnlimitedElements::GOOGLE_CONNECTION_URL, array("refresh_token" => $refreshToken));
|
||||
$data = $response->json();
|
||||
|
||||
if(isset($data["error"]) === true)
|
||||
UniteFunctionsUC::throwError("Unable to refresh the access token: {$data["error"]}");
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($data, "access_token");
|
||||
$expiresAt = UniteFunctionsUC::getVal($data, "expires_at", 0);
|
||||
$scopes = UniteFunctionsUC::getVal($data, "scopes", array());
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($accessToken, "access_token");
|
||||
UniteFunctionsUC::validateNotEmpty($expiresAt, "expires_at");
|
||||
UniteFunctionsUC::validateNotEmpty($scopes, "scopes");
|
||||
|
||||
self::validateScopes($scopes);
|
||||
|
||||
$credentials = array(
|
||||
"access_token" => $accessToken,
|
||||
"expires_at" => $expiresAt,
|
||||
"scopes" => $scopes,
|
||||
);
|
||||
|
||||
self::mergeCredentials($credentials);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/helper.class.php";
|
||||
require_once __DIR__ . "/client.class.php";
|
||||
require_once __DIR__ . "/model.class.php";
|
||||
|
||||
require_once __DIR__ . "/calendar/calendar_event.class.php";
|
||||
require_once __DIR__ . "/calendar/calendar_service.class.php";
|
||||
|
||||
require_once __DIR__ . "/places/place_review.class.php";
|
||||
require_once __DIR__ . "/places/place.class.php";
|
||||
require_once __DIR__ . "/places/places_services.class.php";
|
||||
|
||||
require_once __DIR__ . "/sheets/sheet_values.class.php";
|
||||
require_once __DIR__ . "/sheets/sheet.class.php";
|
||||
require_once __DIR__ . "/sheets/spreadsheet.class.php";
|
||||
require_once __DIR__ . "/sheets/sheets_service.class.php";
|
||||
|
||||
require_once __DIR__ . "/youtube/playlist_item.class.php";
|
||||
require_once __DIR__ . "/youtube/youtube_service.class.php";
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
abstract class UEGoogleAPIModel{
|
||||
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($attributes){
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform list of items into models.
|
||||
*
|
||||
* @param array $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function transformAll($items){
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach($items as $attributes){
|
||||
$data[] = self::transform($attributes);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attributes into a model.
|
||||
*
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function transform($attributes){
|
||||
|
||||
$model = new static($attributes);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribute value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getAttribute($key, $fallback = null){
|
||||
|
||||
$value = UniteFunctionsUC::getVal($this->attributes, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPIPlace extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the reviews.
|
||||
*
|
||||
* @return UEGoogleAPIPlaceReview[]
|
||||
*/
|
||||
public function getReviews(){
|
||||
|
||||
$reviews = $this->getAttribute("reviews", array());
|
||||
$reviews = UEGoogleAPIPlaceReview::transformAll($reviews);
|
||||
|
||||
return $reviews;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPIPlaceReview extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getTime();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text.
|
||||
*
|
||||
* @param bool $asHtml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText($asHtml = false){
|
||||
|
||||
$text = $this->getAttribute("text");
|
||||
|
||||
if($asHtml === true)
|
||||
$text = nl2br($text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rating.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRating(){
|
||||
|
||||
$rating = $this->getAttribute("rating");
|
||||
|
||||
return $rating;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate($format){
|
||||
|
||||
$time = $this->getTime();
|
||||
$date = date($format, $time);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the author name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorName(){
|
||||
|
||||
$name = $this->getAttribute("author_name");
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the author photo URL.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAuthorPhotoUrl(){
|
||||
|
||||
$url = $this->getAttribute("profile_photo_url");
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getTime(){
|
||||
|
||||
$time = $this->getAttribute("time");
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://developers.google.com/maps/documentation/places/web-service/overview
|
||||
*/
|
||||
class UEGoogleAPIPlacesService extends UEGoogleAPIClient{
|
||||
|
||||
/**
|
||||
* Get the place details.
|
||||
*
|
||||
* @param string $placeId
|
||||
* @param array $params
|
||||
*
|
||||
* @return UEGoogleAPIPlace
|
||||
*/
|
||||
public function getDetails($placeId, $params = array()){
|
||||
|
||||
$params["place_id"] = $placeId;
|
||||
|
||||
$response = $this->get("/details/json", $params);
|
||||
$response = UEGoogleAPIPlace::transform($response["result"]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the API.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseUrl(){
|
||||
|
||||
return "https://maps.googleapis.com/maps/api/place";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPISheet extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getPropertyValue("sheetId");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(){
|
||||
|
||||
$title = $this->getPropertyValue("title");
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getPropertyValue($key, $fallback = null){
|
||||
|
||||
$properties = $this->getAttribute("properties");
|
||||
$value = UniteFunctionsUC::getVal($properties, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPISheetValues extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues(){
|
||||
|
||||
$values = $this->getAttribute("values", array());
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://developers.google.com/sheets/api/reference/rest
|
||||
*/
|
||||
class UEGoogleAPISheetsService extends UEGoogleAPIClient{
|
||||
|
||||
/**
|
||||
* Get the spreadsheet.
|
||||
*
|
||||
* @param string $spreadsheetId
|
||||
* @param array $params
|
||||
*
|
||||
* @return UEGoogleAPISpreadsheet
|
||||
*/
|
||||
public function getSpreadsheet($spreadsheetId, $params = array()){
|
||||
|
||||
$response = $this->get("/$spreadsheetId", $params);
|
||||
$response = UEGoogleAPISpreadsheet::transform($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the spreadsheet values.
|
||||
*
|
||||
* @param string $spreadsheetId
|
||||
* @param string $range
|
||||
* @param array $params
|
||||
*
|
||||
* @return UEGoogleAPISheetValues
|
||||
*/
|
||||
public function getSpreadsheetValues($spreadsheetId, $range, $params = array()){
|
||||
|
||||
$range = urlencode($range);
|
||||
|
||||
$response = $this->get("/$spreadsheetId/values/$range", $params);
|
||||
$response = UEGoogleAPISheetValues::transform($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch update the spreadsheet.
|
||||
*
|
||||
* @param string $spreadsheetId
|
||||
* @param array $requests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function batchUpdateSpreadsheet($spreadsheetId, $requests){
|
||||
|
||||
$this->post("/$spreadsheetId:batchUpdate", array(
|
||||
"requests" => $requests,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the insert dimension request.
|
||||
*
|
||||
* @param int $sheetId
|
||||
* @param int $startIndex
|
||||
* @param int $endIndex
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInsertDimensionRequest($sheetId, $startIndex, $endIndex){
|
||||
|
||||
$request = array(
|
||||
"insertDimension" => array(
|
||||
"range" => array(
|
||||
"sheetId" => $sheetId,
|
||||
"startIndex" => $startIndex,
|
||||
"endIndex" => $endIndex,
|
||||
"dimension" => "ROWS",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the update cells request.
|
||||
*
|
||||
* @param int $sheetId
|
||||
* @param int $startIndex
|
||||
* @param int $endIndex
|
||||
* @param array $rows
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUpdateCellsRequest($sheetId, $startIndex, $endIndex, $rows){
|
||||
|
||||
$request = array(
|
||||
"updateCells" => array(
|
||||
"range" => array(
|
||||
"sheetId" => $sheetId,
|
||||
"startRowIndex" => $startIndex,
|
||||
"endRowIndex" => $endIndex,
|
||||
),
|
||||
"rows" => $rows,
|
||||
"fields" => "*",
|
||||
),
|
||||
);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the row data.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepareRowData($values){
|
||||
|
||||
$data = array(
|
||||
"values" => $values,
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the cell data.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepareCellData($value){
|
||||
|
||||
if(is_numeric($value) === true)
|
||||
$type = "numberValue";
|
||||
elseif(is_bool($value) === true)
|
||||
$type = "boolValue";
|
||||
else{
|
||||
$type = "stringValue";
|
||||
$value = (string)$value;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
"userEnteredValue" => array(
|
||||
$type => $value,
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the bold formatting for the cell.
|
||||
*
|
||||
* @param array $cell
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function applyBoldFormatting($cell){
|
||||
|
||||
$cell["userEnteredFormat"] = array(
|
||||
"textFormat" => array(
|
||||
"bold" => true,
|
||||
),
|
||||
);
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the API.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseUrl(){
|
||||
|
||||
return "https://sheets.googleapis.com/v4/spreadsheets";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPISpreadsheet extends UEGoogleAPIModel{
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getAttribute("spreadsheetId");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sheets.
|
||||
*
|
||||
* @return UEGoogleAPISheet[]
|
||||
*/
|
||||
public function getSheets(){
|
||||
|
||||
$sheets = $this->getAttribute("sheets");
|
||||
$sheets = UEGoogleAPISheet::transformAll($sheets);
|
||||
|
||||
return $sheets;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
class UEGoogleAPIPlaylistItem extends UEGoogleAPIModel{
|
||||
|
||||
const IMAGE_SIZE_DEFAULT = "default";
|
||||
const IMAGE_SIZE_MEDIUM = "medium";
|
||||
const IMAGE_SIZE_HIGH = "high";
|
||||
const IMAGE_SIZE_MAX = "maxres";
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getAttribute("id");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle(){
|
||||
|
||||
$title = $this->getSnippetValue("title");
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description.
|
||||
*
|
||||
* @param bool $asHtml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription($asHtml = false){
|
||||
|
||||
$description = $this->getSnippetValue("description");
|
||||
|
||||
if($asHtml === true)
|
||||
$description = nl2br($description);
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate($format){
|
||||
|
||||
$date = $this->getSnippetValue("publishedAt");
|
||||
$time = strtotime($date);
|
||||
$date = date($format, $time);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image URL.
|
||||
*
|
||||
* @param string $size
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImageUrl($size){
|
||||
|
||||
$images = $this->getSnippetValue("thumbnails");
|
||||
$image = UniteFunctionsUC::getVal($images, $size, array());
|
||||
$url = UniteFunctionsUC::getVal($image, "url");
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the video identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoId(){
|
||||
|
||||
$id = $this->getDetailsValue("videoId");
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the video date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoDate($format){
|
||||
|
||||
$date = $this->getDetailsValue("videoPublishedAt");
|
||||
$time = strtotime($date);
|
||||
$date = date($format, $time);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the video URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoUrl(){
|
||||
|
||||
$id = $this->getVideoId();
|
||||
$url = "https://youtube.com/watch?v=$id";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snippet value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getSnippetValue($key, $fallback = null){
|
||||
|
||||
$snippet = $this->getAttribute("snippet");
|
||||
$value = UniteFunctionsUC::getVal($snippet, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the details value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getDetailsValue($key, $fallback = null){
|
||||
|
||||
$details = $this->getAttribute("contentDetails");
|
||||
$value = UniteFunctionsUC::getVal($details, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://developers.google.com/youtube/v3/docs
|
||||
*/
|
||||
class UEGoogleAPIYouTubeService extends UEGoogleAPIClient{
|
||||
|
||||
/**
|
||||
* Get the playlist items.
|
||||
*
|
||||
* @param string $playlistId
|
||||
* @param array $params
|
||||
*
|
||||
* @return UEGoogleAPIPlaylistItem[]
|
||||
*/
|
||||
public function getPlaylistItems($playlistId, $params = array()){
|
||||
|
||||
$params["playlistId"] = $playlistId;
|
||||
$params["part"] = "snippet,contentDetails";
|
||||
|
||||
$response = $this->get("/playlistItems", $params);
|
||||
$response = UEGoogleAPIPlaylistItem::transformAll($response["items"]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base URL for the API.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseUrl(){
|
||||
|
||||
return "https://www.googleapis.com/youtube/v3";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteHelperBaseUC extends HtmlOutputBaseUC{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response
|
||||
*/
|
||||
public static function ajaxResponse($success,$message,$arrData = null){
|
||||
|
||||
$response = array();
|
||||
$response["success"] = $success;
|
||||
$response["message"] = $message;
|
||||
|
||||
if(!empty($arrData)){
|
||||
|
||||
if(gettype($arrData) == "string")
|
||||
$arrData = array("data"=>$arrData);
|
||||
|
||||
$response = array_merge($response,$arrData);
|
||||
}
|
||||
|
||||
$json = json_encode($response);
|
||||
|
||||
|
||||
// clean the buffier,
|
||||
// but return the content if exists for showing the warnings
|
||||
|
||||
if(ob_get_length() > 0) {
|
||||
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
echo $content;
|
||||
}
|
||||
|
||||
|
||||
$isJsonOutput = UniteFunctionsUC::getGetVar("json","",UniteFunctionsUC::SANITIZE_KEY);
|
||||
$isJsonOutput = UniteFunctionsUC::strToBool($isJsonOutput);
|
||||
|
||||
if($isJsonOutput == true)
|
||||
header('Content-Type: application/json');
|
||||
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($json);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response, without message, only data
|
||||
*/
|
||||
public static function ajaxResponseData($arrData){
|
||||
|
||||
if(gettype($arrData) == "string")
|
||||
$arrData = array("data"=>$arrData);
|
||||
|
||||
self::ajaxResponse(true,"",$arrData);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* echo json ajax response
|
||||
*/
|
||||
public static function ajaxResponseError($message,$arrData = null){
|
||||
|
||||
self::ajaxResponse(false,$message,$arrData,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* echo ajax success response
|
||||
*/
|
||||
public static function ajaxResponseSuccess($message,$arrData = null){
|
||||
|
||||
self::ajaxResponse(true,$message,$arrData,true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* echo ajax success response
|
||||
*/
|
||||
public static function ajaxResponseSuccessRedirect($message,$url){
|
||||
$arrData = array("is_redirect"=>true,"redirect_url"=>$url);
|
||||
|
||||
self::ajaxResponse(true,$message,$arrData,true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class HtmlOutputBaseUC{
|
||||
|
||||
const BR = "\n";
|
||||
const BR2 = "\n\n";
|
||||
const TAB = " ";
|
||||
const TAB2 = " ";
|
||||
const TAB3 = " ";
|
||||
const TAB4 = " ";
|
||||
const TAB5 = " ";
|
||||
const TAB6 = " ";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
abstract class UEHttp{
|
||||
|
||||
/**
|
||||
* Create a new request instance.
|
||||
*
|
||||
* @return UEHttpRequest
|
||||
*/
|
||||
public static function make(){
|
||||
|
||||
return new UEHttpRequest();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
abstract class UEHttpException extends Exception{
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class UEHttpRequestException extends UEHttpException{
|
||||
|
||||
private $request;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param string $message
|
||||
* @param UEHttpRequest $request
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($message, $request){
|
||||
|
||||
$this->request = $request;
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request instance.
|
||||
*
|
||||
* @return UEHttpRequest
|
||||
*/
|
||||
public function getRequest(){
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class UEHttpResponseException extends UEHttpException{
|
||||
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param string $message
|
||||
* @param UEHttpResponse $response
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($message, $response){
|
||||
|
||||
$this->response = $response;
|
||||
|
||||
parent::__construct($message, $response->status());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response instance.
|
||||
*
|
||||
* @return UEHttpResponse
|
||||
*/
|
||||
public function getResponse(){
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/exceptions/exception.class.php";
|
||||
require_once __DIR__ . "/exceptions/request_exception.class.php";
|
||||
require_once __DIR__ . "/exceptions/response_exception.class.php";
|
||||
|
||||
require_once __DIR__ . "/response.class.php";
|
||||
require_once __DIR__ . "/request.class.php";
|
||||
require_once __DIR__ . "/client.class.php";
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
class UEHttpRequest{
|
||||
|
||||
const CACHE_KEY = "ue_http_request";
|
||||
|
||||
const BODY_FORMAT_FORM = "form";
|
||||
const BODY_FORMAT_JSON = "json";
|
||||
const BODY_FORMAT_MULTIPART = "multipart";
|
||||
|
||||
const METHOD_GET = "GET";
|
||||
const METHOD_PUT = "PUT";
|
||||
const METHOD_POST = "POST";
|
||||
|
||||
const REQUEST_TIMEOUT = 120;
|
||||
|
||||
private $debug = false;
|
||||
private $cacheTime = 0;
|
||||
private $bodyFormat;
|
||||
|
||||
private $headers = array();
|
||||
private $query = array();
|
||||
private $body = array();
|
||||
|
||||
private $validateResponse;
|
||||
|
||||
/**
|
||||
* Enable the debug mode.
|
||||
*
|
||||
* @param bool $debug
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function debug($debug = true){
|
||||
|
||||
$this->debug = $debug;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache time.
|
||||
*
|
||||
* @param int $seconds
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function cacheTime($seconds){
|
||||
|
||||
$this->cacheTime = $seconds;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate the request contains form parameters.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function asForm(){
|
||||
|
||||
return $this->bodyFormat(self::BODY_FORMAT_FORM)->contentType("application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate the request contains JSON.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function asJson(){
|
||||
|
||||
return $this->bodyFormat(self::BODY_FORMAT_JSON)->contentType("application/json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate the request contains multipart parameters.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function asMultipart(){
|
||||
|
||||
return $this->bodyFormat(self::BODY_FORMAT_MULTIPART)->contentType("multipart/form-data");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that JSON should be returned by the server.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function acceptJson(){
|
||||
|
||||
return $this->accept("application/json");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given headers to the request.
|
||||
*
|
||||
* @param array $headers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withHeaders($headers){
|
||||
|
||||
$this->headers = array_merge($this->headers, $headers);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given parameters to the request query.
|
||||
*
|
||||
* @param array $query
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withQuery($query){
|
||||
|
||||
$this->query = array_merge($this->query, $query);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given parameters to the request body.
|
||||
*
|
||||
* @param array $body
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withBody($body){
|
||||
|
||||
$this->body = array_merge($this->body, $body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the validation function of the response.
|
||||
*
|
||||
* @param callable $callback
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function validateResponse($callback){
|
||||
|
||||
$this->validateResponse = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a GET request to the server.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $query
|
||||
*
|
||||
* @return UEHttpResponse
|
||||
* @throws UEHttpException
|
||||
*/
|
||||
public function get($url, $query = array()){
|
||||
|
||||
return $this->withQuery($query)->request(self::METHOD_GET, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a POST request to the server.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $body
|
||||
*
|
||||
* @return UEHttpResponse
|
||||
* @throws UEHttpException
|
||||
*/
|
||||
public function post($url, $body = array()){
|
||||
|
||||
return $this->withBody($body)->request(self::METHOD_POST, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to the server.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
*
|
||||
* @return UEHttpResponse
|
||||
* @throws UEHttpException
|
||||
*/
|
||||
public function request($method, $url){
|
||||
|
||||
$headers = $this->headers;
|
||||
$query = $this->query;
|
||||
$body = $this->prepareBody($method);
|
||||
$url = $this->prepareUrl($url, $query);
|
||||
|
||||
if($this->isDebug() === true){
|
||||
dmp("Request data:");
|
||||
dmp($url);
|
||||
dmp($headers);
|
||||
dmp($query);
|
||||
dmp($body);
|
||||
}
|
||||
|
||||
$cacheKey = $this->prepareCacheKey($url);
|
||||
$cacheTime = $this->prepareCacheTime($method);
|
||||
|
||||
$requestResponse = UniteProviderFunctionsUC::rememberTransient($cacheKey, $cacheTime, function() use ($url, $method, $headers, $body){
|
||||
|
||||
$wpResponse = wp_remote_request($url, array(
|
||||
"method" => $method,
|
||||
"headers" => $headers,
|
||||
"body" => $body,
|
||||
"timeout" => self::REQUEST_TIMEOUT,
|
||||
"sslverify" => false,
|
||||
));
|
||||
|
||||
if(is_wp_error($wpResponse) === true)
|
||||
throw new UEHttpRequestException($wpResponse->get_error_message(), $this);
|
||||
|
||||
$requestResponse = array(
|
||||
"status" => wp_remote_retrieve_response_code($wpResponse),
|
||||
"headers" => wp_remote_retrieve_headers($wpResponse)->getAll(),
|
||||
"body" => wp_remote_retrieve_body($wpResponse),
|
||||
);
|
||||
|
||||
if($this->isDebug() === true){
|
||||
dmp("Fetched response:");
|
||||
dmp($requestResponse);
|
||||
}
|
||||
|
||||
if(is_callable($this->validateResponse) === true){
|
||||
$response = new UEHttpResponse($requestResponse);
|
||||
$validResponse = call_user_func($this->validateResponse, $response);
|
||||
|
||||
if($validResponse === false)
|
||||
throw new UEHttpResponseException("Response validation failed.", $response);
|
||||
}
|
||||
|
||||
return $requestResponse;
|
||||
});
|
||||
|
||||
if($this->isDebug() === true){
|
||||
dmp("Cached response:");
|
||||
dmp($requestResponse);
|
||||
}
|
||||
|
||||
return new UEHttpResponse($requestResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the debug mode is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isDebug(){
|
||||
|
||||
return $this->debug === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the body format of the request.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function bodyFormat($format){
|
||||
|
||||
$this->bodyFormat = $format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate the content type that should be returned by the server.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function accept($type){
|
||||
|
||||
return $this->withHeaders(["Accept" => $type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content type of the request.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function contentType($type){
|
||||
|
||||
return $this->withHeaders(["Content-Type" => $type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given URL for the request.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function prepareUrl($url, $query){
|
||||
|
||||
$url .= strpos($url, "?") === false ? "?" : "&";
|
||||
$url .= http_build_query($query);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the body for the request.
|
||||
*
|
||||
* @param string $method
|
||||
*
|
||||
* @return array|string|null
|
||||
*/
|
||||
private function prepareBody($method){
|
||||
|
||||
if($method === self::METHOD_GET)
|
||||
return null;
|
||||
|
||||
switch($this->bodyFormat){
|
||||
case self::BODY_FORMAT_JSON:
|
||||
return json_encode($this->body);
|
||||
}
|
||||
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the cache key for the request.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function prepareCacheKey($url){
|
||||
|
||||
return self::CACHE_KEY . ":" . md5($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the cache time for the request.
|
||||
*
|
||||
* @param string $method
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function prepareCacheTime($method){
|
||||
|
||||
return ($method === self::METHOD_GET) ? $this->cacheTime : 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
class UEHttpResponse{
|
||||
|
||||
private $status;
|
||||
private $headers;
|
||||
private $body;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data){
|
||||
|
||||
$this->status = UniteFunctionsUC::getVal($data, "status", 0);
|
||||
$this->headers = UniteFunctionsUC::getVal($data, "headers", array());
|
||||
$this->body = UniteFunctionsUC::getVal($data, "body");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status code of the response.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function status(){
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the headers of the response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function headers(){
|
||||
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body of the response.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function body(){
|
||||
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JSON decoded body of the response.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws UEHttpResponseException
|
||||
*/
|
||||
public function json(){
|
||||
|
||||
$data = json_decode($this->body(), true);
|
||||
|
||||
if($data === null)
|
||||
throw new UEHttpResponseException("Unable to parse the JSON body.", $this);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,598 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteImageViewUC{
|
||||
|
||||
private $pathCache;
|
||||
private $pathImages;
|
||||
private $urlImages;
|
||||
|
||||
private $filename = null;
|
||||
private $maxWidth = null;
|
||||
private $maxHeight = null;
|
||||
private $type = null;
|
||||
private $effect = null;
|
||||
private $effect_arg1 = null;
|
||||
private $effect_arg2 = null;
|
||||
|
||||
const EFFECT_BW = "bw";
|
||||
const EFFECT_BRIGHTNESS = "bright";
|
||||
const EFFECT_CONTRAST = "contrast";
|
||||
const EFFECT_EDGE = "edge";
|
||||
const EFFECT_EMBOSS = "emboss";
|
||||
const EFFECT_BLUR = "blur";
|
||||
const EFFECT_BLUR3 = "blur3";
|
||||
const EFFECT_MEAN = "mean";
|
||||
const EFFECT_SMOOTH = "smooth";
|
||||
const EFFECT_DARK = "dark";
|
||||
|
||||
const TYPE_EXACT = "exact";
|
||||
const TYPE_EXACT_TOP = "exacttop";
|
||||
|
||||
private $jpg_quality;
|
||||
|
||||
public function __construct(){
|
||||
|
||||
$this->jpg_quality = GlobalsUC::DEFAULT_JPG_QUALITY;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* throw error
|
||||
*/
|
||||
private function throwError($message,$code=null){
|
||||
UniteFunctionsUC::throwError($message,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* validate type
|
||||
* @param unknown_type $type
|
||||
*/
|
||||
private function validateType($type){
|
||||
switch($type){
|
||||
case self::TYPE_EXACT:
|
||||
case self::TYPE_EXACT_TOP:
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Wrong image type: ".$type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get filename for thumbnail save / retrieve
|
||||
*/
|
||||
private function getThumbFilename(){
|
||||
|
||||
$info = pathInfo($this->filename);
|
||||
|
||||
|
||||
//add dirname as postfix (if exists)
|
||||
$postfix = "";
|
||||
|
||||
$dirname = UniteFunctionsUC::getVal($info, "dirname");
|
||||
if($dirname == ".")
|
||||
$dirname = null;
|
||||
|
||||
if(!empty($dirname))
|
||||
$postfix = str_replace("/", "-", $dirname);
|
||||
|
||||
$ext = $info["extension"];
|
||||
$name = $info["filename"];
|
||||
$width = ceil($this->maxWidth);
|
||||
$height = ceil($this->maxHeight);
|
||||
$thumbFilename = $name."_".$width."x".$height;
|
||||
$this->type = trim($this->type);
|
||||
|
||||
|
||||
if(!empty($this->type))
|
||||
$thumbFilename .= "_" . $this->type;
|
||||
|
||||
if(!empty($this->effect)){
|
||||
$thumbFilename .= "_e" . $this->effect;
|
||||
if(!empty($this->effect_arg1)){
|
||||
$thumbFilename .= "x" . $this->effect_arg1;
|
||||
}
|
||||
}
|
||||
|
||||
//add postfix
|
||||
if(!empty($postfix))
|
||||
$thumbFilename .= "_".$postfix;
|
||||
|
||||
$thumbFilename .= ".".$ext;
|
||||
|
||||
return($thumbFilename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get thumbnail fielpath by parameters.
|
||||
*/
|
||||
private function getThumbFilepath(){
|
||||
$filename = $this->getThumbFilename();
|
||||
$filepath = $this->pathCache .$filename;
|
||||
return($filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* ouptput emtpy image code
|
||||
*/
|
||||
private function outputEmptyImageCode(){
|
||||
echo "empty image";
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* outputs image and exit
|
||||
*
|
||||
*/
|
||||
private function outputImage($filepath){
|
||||
|
||||
$info = UniteFunctionsUC::getPathInfo($filepath);
|
||||
$ext = $info["extension"];
|
||||
|
||||
$ext = strtolower($ext);
|
||||
if($ext == "jpg")
|
||||
$ext = "jpeg";
|
||||
|
||||
$numExpires = 31536000; //one year
|
||||
$strExpires = @date('D, d M Y H:i:s',time()+$numExpires);
|
||||
|
||||
$contents = file_get_contents($filepath);
|
||||
$filesize = strlen($contents);
|
||||
/*header("Last-Modified: $strModified GMT");*/
|
||||
header("Expires: $strExpires GMT");
|
||||
header("Cache-Control: public");
|
||||
header("Content-Type: image/$ext");
|
||||
header("Content-Length: $filesize");
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($contents);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// get src image from filepath according the image type
|
||||
private function getGdSrcImage($filepath,$type){
|
||||
// create the image
|
||||
$src_img = false;
|
||||
switch($type){
|
||||
case IMAGETYPE_JPEG:
|
||||
$src_img = @imagecreatefromjpeg($filepath);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$src_img = @imagecreatefrompng($filepath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$src_img = @imagecreatefromgif($filepath);
|
||||
break;
|
||||
case IMAGETYPE_BMP:
|
||||
$src_img = @imagecreatefromwbmp($filepath);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$src_img = @imagecreatefromwebp($filepath);
|
||||
break;
|
||||
default:
|
||||
$this->throwError("wrong image format <b>$type</b> , can't resize");
|
||||
break;
|
||||
}
|
||||
|
||||
if($src_img == false){
|
||||
$this->throwError("Can't resize image");
|
||||
}
|
||||
|
||||
return($src_img);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// save gd image to some filepath. return if success or not
|
||||
private function saveGdImage($dst_img,$filepath,$type){
|
||||
$successSaving = false;
|
||||
switch($type){
|
||||
case IMAGETYPE_JPEG:
|
||||
$successSaving = imagejpeg($dst_img,$filepath,$this->jpg_quality);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$successSaving = imagepng($dst_img,$filepath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$successSaving = imagegif($dst_img,$filepath);
|
||||
break;
|
||||
case IMAGETYPE_BMP:
|
||||
$successSaving = imagewbmp($dst_img,$filepath);
|
||||
break;
|
||||
}
|
||||
|
||||
return($successSaving);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// crop image to specifix height and width , and save it to new path
|
||||
private function cropImageSaveNew($filepath,$filepathNew){
|
||||
|
||||
$imgInfo = getimagesize($filepath);
|
||||
$imgType = $imgInfo[2];
|
||||
|
||||
$src_img = $this->getGdSrcImage($filepath,$imgType);
|
||||
|
||||
$width = imageSX($src_img);
|
||||
$height = imageSY($src_img);
|
||||
|
||||
//crop the image from the top
|
||||
$startx = 0;
|
||||
$starty = 0;
|
||||
|
||||
//find precrop width and height:
|
||||
$percent = $this->maxWidth / $width;
|
||||
$newWidth = $this->maxWidth;
|
||||
$newHeight = ceil($percent * $height);
|
||||
|
||||
if($this->type == "exact"){ //crop the image from the middle
|
||||
$startx = 0;
|
||||
$starty = ($newHeight-$this->maxHeight)/2 / $percent;
|
||||
}
|
||||
|
||||
if($newHeight < $this->maxHeight){ //by width
|
||||
$percent = $this->maxHeight / $height;
|
||||
$newHeight = $this->maxHeight;
|
||||
$newWidth = ceil($percent * $width);
|
||||
|
||||
if($this->type == "exact"){ //crop the image from the middle
|
||||
$startx = ($newWidth - $this->maxWidth) /2 / $percent; //the startx is related to big image
|
||||
$starty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//resize the picture:
|
||||
$tmp_img = ImageCreateTrueColor($newWidth,$newHeight);
|
||||
|
||||
$this->handleTransparency($tmp_img,$imgType,$newWidth,$newHeight);
|
||||
|
||||
imagecopyresampled($tmp_img,$src_img,0,0,$startx,$starty,$newWidth,$newHeight,$width,$height);
|
||||
|
||||
$this->handleImageEffects($tmp_img);
|
||||
|
||||
//crop the picture:
|
||||
$dst_img = ImageCreateTrueColor($this->maxWidth,$this->maxHeight);
|
||||
|
||||
$this->handleTransparency($dst_img,$imgType,$this->maxWidth,$this->maxHeight);
|
||||
|
||||
imagecopy($dst_img, $tmp_img, 0, 0, 0, 0, $newWidth, $newHeight);
|
||||
|
||||
//save the picture
|
||||
$is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType);
|
||||
|
||||
imagedestroy($dst_img);
|
||||
imagedestroy($src_img);
|
||||
imagedestroy($tmp_img);
|
||||
|
||||
return($is_saved);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// if the images are png or gif - handle image transparency
|
||||
private function handleTransparency(&$dst_img,$imgType,$newWidth,$newHeight){
|
||||
//handle transparency:
|
||||
if($imgType == IMAGETYPE_PNG || $imgType == IMAGETYPE_GIF){
|
||||
imagealphablending($dst_img, false);
|
||||
imagesavealpha($dst_img,true);
|
||||
$transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
|
||||
imagefilledrectangle($dst_img, 0, 0, $newWidth, $newHeight, $transparent);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// handle image effects
|
||||
private function handleImageEffects(&$imgHandle){
|
||||
if(empty($this->effect))
|
||||
return(false);
|
||||
|
||||
switch($this->effect){
|
||||
case self::EFFECT_BW:
|
||||
if(defined("IMG_FILTER_GRAYSCALE"))
|
||||
imagefilter($imgHandle,IMG_FILTER_GRAYSCALE);
|
||||
break;
|
||||
case self::EFFECT_BRIGHTNESS:
|
||||
if(defined("IMG_FILTER_BRIGHTNESS")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = 50; //set default value
|
||||
UniteFunctionsUC::validateNumeric($this->effect_arg1,"'ea1' argument");
|
||||
imagefilter($imgHandle,IMG_FILTER_BRIGHTNESS,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_DARK:
|
||||
if(defined("IMG_FILTER_BRIGHTNESS")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = -50; //set default value
|
||||
UniteFunctionsUC::validateNumeric($this->effect_arg1,"'ea1' argument");
|
||||
imagefilter($imgHandle,IMG_FILTER_BRIGHTNESS,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_CONTRAST:
|
||||
if(defined("IMG_FILTER_CONTRAST")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = -5; //set default value
|
||||
imagefilter($imgHandle,IMG_FILTER_CONTRAST,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_EDGE:
|
||||
if(defined("IMG_FILTER_EDGEDETECT"))
|
||||
imagefilter($imgHandle,IMG_FILTER_EDGEDETECT);
|
||||
break;
|
||||
case self::EFFECT_EMBOSS:
|
||||
if(defined("IMG_FILTER_EMBOSS"))
|
||||
imagefilter($imgHandle,IMG_FILTER_EMBOSS);
|
||||
break;
|
||||
case self::EFFECT_BLUR:
|
||||
$this->effect_Blur($imgHandle,5);
|
||||
/*
|
||||
if(defined("IMG_FILTER_GAUSSIAN_BLUR"))
|
||||
imagefilter($imgHandle,IMG_FILTER_GAUSSIAN_BLUR);
|
||||
*/
|
||||
break;
|
||||
case self::EFFECT_MEAN:
|
||||
if(defined("IMG_FILTER_MEAN_REMOVAL"))
|
||||
imagefilter($imgHandle,IMG_FILTER_MEAN_REMOVAL);
|
||||
break;
|
||||
case self::EFFECT_SMOOTH:
|
||||
if(defined("IMG_FILTER_SMOOTH")){
|
||||
if(!is_numeric($this->effect_arg1))
|
||||
$this->effect_arg1 = 15; //set default value
|
||||
imagefilter($imgHandle,IMG_FILTER_SMOOTH,$this->effect_arg1);
|
||||
}
|
||||
break;
|
||||
case self::EFFECT_BLUR3:
|
||||
$this->effect_Blur($imgHandle,5);
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Effect not supported: <b>".$this->effect."</b>");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function effect_Blur(&$gdimg, $radius=0.5) {
|
||||
// Taken from Torstein Hרnsi's phpUnsharpMask (see phpthumb.unsharp.php)
|
||||
|
||||
$radius = round(max(0, min($radius, 50)) * 2);
|
||||
if (!$radius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$w = ImageSX($gdimg);
|
||||
$h = ImageSY($gdimg);
|
||||
if ($imgBlur = ImageCreateTrueColor($w, $h)) {
|
||||
// Gaussian blur matrix:
|
||||
// 1 2 1
|
||||
// 2 4 2
|
||||
// 1 2 1
|
||||
|
||||
// Move copies of the image around one pixel at the time and merge them with weight
|
||||
// according to the matrix. The same matrix is simply repeated for higher radii.
|
||||
for ($i = 0; $i < $radius; $i++) {
|
||||
ImageCopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000); // down right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000); // up right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left
|
||||
ImageCopyMerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000); // right
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000); // up
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667); // down
|
||||
ImageCopyMerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000); // center
|
||||
ImageCopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// resize image and save it to new path
|
||||
private function resizeImageSaveNew($filepath,$filepathNew){
|
||||
|
||||
$imgInfo = getimagesize($filepath);
|
||||
$imgType = $imgInfo[2];
|
||||
|
||||
$src_img = $this->getGdSrcImage($filepath,$imgType);
|
||||
|
||||
$width = imageSX($src_img);
|
||||
$height = imageSY($src_img);
|
||||
|
||||
$newWidth = $width;
|
||||
$newHeight = $height;
|
||||
|
||||
//find new width
|
||||
if($height > $this->maxHeight){
|
||||
$procent = $this->maxHeight / $height;
|
||||
$newWidth = ceil($width * $procent);
|
||||
$newHeight = $this->maxHeight;
|
||||
}
|
||||
|
||||
//if the new width is grater than max width, find new height, and remain the width.
|
||||
if($newWidth > $this->maxWidth){
|
||||
$procent = $this->maxWidth / $newWidth;
|
||||
$newHeight = ceil($newHeight * $procent);
|
||||
$newWidth = $this->maxWidth;
|
||||
}
|
||||
|
||||
//if the image don't need to be resized, just copy it from source to destanation.
|
||||
if($newWidth == $width && $newHeight == $height && empty($this->effect)){
|
||||
$success = copy($filepath,$filepathNew);
|
||||
if($success == false)
|
||||
$this->throwError("can't copy the image from one path to another");
|
||||
}
|
||||
else{ //else create the resized image, and save it to new path:
|
||||
$dst_img = ImageCreateTrueColor($newWidth,$newHeight);
|
||||
|
||||
$this->handleTransparency($dst_img,$imgType,$newWidth,$newHeight);
|
||||
|
||||
//copy the new resampled image:
|
||||
imagecopyresampled($dst_img,$src_img,0,0,0,0,$newWidth,$newHeight,$width,$height);
|
||||
|
||||
$this->handleImageEffects($dst_img);
|
||||
|
||||
$is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType);
|
||||
imagedestroy($dst_img);
|
||||
}
|
||||
|
||||
imagedestroy($src_img);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* set image effect
|
||||
*/
|
||||
public function setEffect($effect,$arg1 = ""){
|
||||
$this->effect = $effect;
|
||||
$this->effect_arg1 = $arg1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* set jpg quality output
|
||||
*/
|
||||
public function setJPGQuality($quality){
|
||||
$this->jpg_quality = $quality;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make thumbnail from the image, and save to some path
|
||||
* return new path
|
||||
*/
|
||||
public function makeThumb($filepathImage, $pathThumbs, $maxWidth=-1, $maxHeight=-1, $type=""){
|
||||
|
||||
//validate input
|
||||
UniteFunctionsUC::validateFilepath($filepathImage, "image not found");
|
||||
|
||||
UniteFunctionsUC::validateDir($pathThumbs, "Thumbs folder don't exists.");
|
||||
|
||||
if($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP){
|
||||
if($maxHeight == -1)
|
||||
$this->throwError("image with exact type must have height!");
|
||||
if($maxWidth == -1)
|
||||
$this->throwError("image with exact type must have width!");
|
||||
}
|
||||
|
||||
//get filename
|
||||
$info = UniteFunctionsUC::getPathInfo($filepathImage);
|
||||
$filename = UniteFunctionsUC::getVal($info, "basename");
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($filename, "image filename not given");
|
||||
|
||||
//if gd library doesn't exists - output normal image without resizing.
|
||||
if(function_exists("gd_info") == false)
|
||||
$this->throwError("php must support GD Library");
|
||||
|
||||
if($maxWidth == -1 && $maxHeight == -1)
|
||||
$this->throwError("Wrong thumb size");
|
||||
|
||||
if($maxWidth == -1)
|
||||
$maxWidth = 1000000;
|
||||
|
||||
if($maxHeight == -1)
|
||||
$maxHeight = 100000;
|
||||
|
||||
$this->filename = $filename;
|
||||
$this->maxWidth = $maxWidth;
|
||||
$this->maxHeight = $maxHeight;
|
||||
$this->type = $type;
|
||||
$this->pathCache = $pathThumbs;
|
||||
|
||||
$filenameThumb = $this->getThumbFilename();
|
||||
$filepathNew = $this->pathCache.$filenameThumb;
|
||||
|
||||
if(file_exists($filepathNew))
|
||||
return($filenameThumb);
|
||||
|
||||
if($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP){
|
||||
$isSaved = $this->cropImageSaveNew($filepathImage, $filepathNew);
|
||||
}
|
||||
else
|
||||
$isSaved = $this->resizeImageSaveNew($filepathImage, $filepathNew);
|
||||
|
||||
if($isSaved)
|
||||
return($filenameThumb);
|
||||
else
|
||||
return("");
|
||||
}
|
||||
|
||||
/**
|
||||
* convert png data to png
|
||||
*/
|
||||
public function convertPngDataToPng($strPngData){
|
||||
|
||||
$strPngData = str_replace("data:image/png;base64,", "", $strPngData);
|
||||
|
||||
$strPng = base64_decode($strPngData);
|
||||
|
||||
return($strPng);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert png data to png
|
||||
*/
|
||||
public function convertJPGDataToJPG($strJpgData){
|
||||
|
||||
$strJpgData = str_replace("data:image/jpeg;base64,", "", $strJpgData);
|
||||
|
||||
$strJpg = base64_decode($strJpgData);
|
||||
|
||||
return($strJpg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert png to jpg
|
||||
* quality from 0 - compression to 70 - quality
|
||||
*/
|
||||
public function png2jpg($filepathPNG, $filepathJPGOutput, $quality = 70) {
|
||||
|
||||
$image = imagecreatefrompng($filepathPNG);
|
||||
imagejpeg($image, $filepathJPGOutput, $quality);
|
||||
imagedestroy($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert png string to jpg
|
||||
*/
|
||||
public function strPngToStrJpg($strPng, $quality = 70){
|
||||
|
||||
$image = imagecreatefromstring($strPng);
|
||||
if(empty($image))
|
||||
UniteFunctionsUC::throwError("can't convert image");
|
||||
|
||||
ob_start();
|
||||
|
||||
imagejpeg($image, null, $quality);
|
||||
|
||||
$strJpg = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
imagedestroy($image);
|
||||
|
||||
return($strJpg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
$folderIncludes = dirname(__FILE__)."/";
|
||||
$folderCreatorIncludes = $folderIncludes."../";
|
||||
$folderProvider = $folderIncludes."../../provider/";
|
||||
|
||||
//include provider classes
|
||||
require_once $folderIncludes . 'functions.php';
|
||||
require_once $folderIncludes . 'functions.class.php';
|
||||
require_once $folderIncludes . 'html_output_base.class.php';
|
||||
|
||||
require_once $folderProvider."include_provider.php";
|
||||
|
||||
require_once $folderIncludes . 'http/includes.php';
|
||||
require_once $folderIncludes . 'db.class.php';
|
||||
require_once $folderIncludes . 'params_manager.class.php';
|
||||
require_once $folderIncludes . 'settings.class.php';
|
||||
require_once $folderIncludes . 'cssparser.class.php';
|
||||
require_once $folderIncludes . 'settings_advances.class.php';
|
||||
require_once $folderIncludes . 'settings_output.class.php';
|
||||
require_once $folderProvider . 'provider_settings_output.class.php';
|
||||
require_once $folderCreatorIncludes . 'unitecreator_settings_output.class.php';
|
||||
|
||||
require_once $folderIncludes . 'settings_output_wide.class.php';
|
||||
require_once $folderIncludes . 'settings_output_inline.class.php';
|
||||
require_once $folderIncludes . 'settings_output_sidebar.class.php';
|
||||
|
||||
require_once $folderIncludes . 'image_proccess.class.php';
|
||||
require_once $folderIncludes . 'zip.class.php';
|
||||
|
||||
require_once $folderIncludes . 'base_admin.class.php';
|
||||
|
||||
require_once $folderIncludes . 'elements_base.class.php';
|
||||
require_once $folderIncludes . 'base_output.class.php';
|
||||
require_once $folderIncludes . 'helper_base.class.php';
|
||||
require_once $folderIncludes . 'table.class.php';
|
||||
require_once $folderIncludes . 'font_manager.class.php';
|
||||
require_once $folderIncludes . 'shapes.class.php';
|
||||
require_once $folderIncludes . 'services.class.php';
|
||||
|
||||
//include composer - twig
|
||||
$isTwigExists = interface_exists("Twig\\Loader\\LoaderInterface");
|
||||
|
||||
if($isTwigExists == false){
|
||||
require $folderIncludes."../../vendor/autoload.php";
|
||||
}
|
||||
@@ -0,0 +1,503 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class HelperInstaUC{
|
||||
|
||||
const RENEW_DELAY_SIX_HOURS = 21600;
|
||||
const KEY_RENEW_BLOCKED = "unlimited_elements_instagram_renew_blocked";
|
||||
private static $instaCheckRunOnce = false;
|
||||
|
||||
|
||||
/**
|
||||
* get instagram access data
|
||||
*/
|
||||
public static function getInstagramSavedAccessData(){
|
||||
|
||||
$settings = HelperProviderCoreUC_EL::getGeneralSettingsValues();
|
||||
|
||||
$arrData = array();
|
||||
$arrData["access_token"] = UniteFunctionsUC::getVal($settings, "instagram_access_token");
|
||||
$arrData["user_id"] = UniteFunctionsUC::getVal($settings, "instagram_user_id");
|
||||
$arrData["username"] = UniteFunctionsUC::getVal($settings, "instagram_username");
|
||||
$arrData["expires"] = UniteFunctionsUC::getVal($settings, "instagram_expires");
|
||||
|
||||
return($arrData);
|
||||
}
|
||||
|
||||
/**
|
||||
* return if access token exists in settings
|
||||
*/
|
||||
public static function isAccessTokenExists(){
|
||||
|
||||
$arrData = self::getInstagramSavedAccessData();
|
||||
|
||||
$token = UniteFunctionsUC::getVal($arrData, "access_token");
|
||||
|
||||
$isExists = !empty($token);
|
||||
|
||||
return($isExists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* redirect to general settings
|
||||
*/
|
||||
public static function redirectToGeneralSettings(){
|
||||
|
||||
$urlRedirect = HelperUC::getViewUrl(GlobalsUnlimitedElements::VIEW_SETTINGS_ELEMENTOR,"#tab=instagram");
|
||||
UniteFunctionsUC::redirectToUrl($urlRedirect);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* save connect data, from ajax function
|
||||
* redirect to general settings
|
||||
*/
|
||||
public static function saveInstagramConnectDataAjax($data, $noUser = false, $redirect = true){
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($data, "access_token");
|
||||
$userID = UniteFunctionsUC::getVal($data, "user_id");
|
||||
$username = UniteFunctionsUC::getVal($data, "username");
|
||||
$expiresIn = UniteFunctionsUC::getVal($data, "expires");
|
||||
|
||||
UniteFunctionsUC::validateNumeric($expiresIn, "expires in ");
|
||||
|
||||
$expiresAt = time()+$expiresIn;
|
||||
|
||||
$expireDate = UniteFunctionsUC::timestamp2Date($expiresAt);
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($accessToken,"instagram access token");
|
||||
|
||||
if($noUser == false){
|
||||
UniteFunctionsUC::validateNotEmpty($userID,"instagram user id");
|
||||
UniteFunctionsUC::validateNotEmpty($userID,"instagram username");
|
||||
}
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["instagram_access_token"] = $accessToken;
|
||||
$arrUpdate["instagram_expires"] = $expiresAt;
|
||||
|
||||
if($noUser == false){
|
||||
$arrUpdate["instagram_user_id"] = $userID;
|
||||
$arrUpdate["instagram_username"] = $username;
|
||||
}
|
||||
|
||||
HelperUC::$operations->updateUnlimitedElementsGeneralSettings($arrUpdate);
|
||||
|
||||
if($redirect == true)
|
||||
self::redirectToGeneralSettings();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get expires html
|
||||
*/
|
||||
public static function getHTMLExpires($expiresAt){
|
||||
|
||||
if(empty($expiresAt))
|
||||
return("");
|
||||
|
||||
$stamp = time();
|
||||
|
||||
$expiresIn = $expiresAt - $stamp;
|
||||
|
||||
$expireDays = $expiresIn / 60 / 60 / 24;
|
||||
|
||||
$expireDays = ceil($expireDays);
|
||||
|
||||
if($expireDays < 0){
|
||||
$expireDays *= -1;
|
||||
$html = "<span class='unite-color-red'>".__("The token has expired ","unlimited-elements-for-elementor").$expireDays.__(" ago","unlimited-elements-for-elementor")."</span>";
|
||||
}else{
|
||||
|
||||
$html = __("The token will expire in ","unlimited-elements-for-elementor").$expireDays .__(" days. Don't worry, it should auto renew.","unlimited-elements-for-elementor");
|
||||
}
|
||||
|
||||
//add renew link
|
||||
|
||||
$htmlLink = null;
|
||||
|
||||
if($expireDays < 60){
|
||||
$linkRenew = HelperUC::getUrlAjax("renew_instagram_access_token");
|
||||
$htmlLink = HelperHtmlUC::getHtmlLink($linkRenew, "renew access token");
|
||||
}
|
||||
|
||||
if(!empty($htmlLink))
|
||||
$html .= " ".$htmlLink;
|
||||
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* put connect with instagram button to general settings
|
||||
*/
|
||||
public static function putConnectWithInstagramButton(){
|
||||
|
||||
$urlAuthorize = InstagramAPIOfficialUC::URL_AUTHORIZE;
|
||||
$clientID = InstagramAPIOfficialUC::APP_CLIENT_ID;
|
||||
$urlConnect = InstagramAPIOfficialUC::URL_APP_CONNECT;
|
||||
|
||||
$urlReturn = HelperUC::getUrlAjax("save_instagram_connect_data");
|
||||
|
||||
$urlReturn = UniteFunctionsUC::encodeContent($urlReturn);
|
||||
|
||||
$urlConnect = "{$urlAuthorize}?client_id={$clientID}&scope=user_profile,user_media&response_type=code&redirect_uri={$urlConnect}&state=$urlReturn";
|
||||
|
||||
$buttonText = __("Connect With Instagram", "unlimited-elements-for-elementor");
|
||||
|
||||
$htmlButton = HelperHtmlUC::getHtmlLink($urlConnect, "", "", "uc-button-connect-instagram");
|
||||
|
||||
//put access data as well
|
||||
$data = self::getInstagramSavedAccessData();
|
||||
$accessToken = UniteFunctionsUC::getVal($data, "access_token");
|
||||
|
||||
$expiresAt = UniteFunctionsUC::getVal($data, "expires");
|
||||
|
||||
|
||||
if(!empty($accessToken)){
|
||||
|
||||
$username = UniteFunctionsUC::getVal($data, "username");
|
||||
|
||||
$expiresHTML = self::getHTMLExpires($expiresAt);
|
||||
|
||||
$urlTestView = HelperUC::getViewUrl("instagram-test");
|
||||
$linkTest = HelperHtmlUC::getHtmlLink($urlTestView, "Test Instagram Data");
|
||||
|
||||
$text = __("The instagram access token are already set up", "unlimited-elements-for-elementor");
|
||||
|
||||
if(!empty($username))
|
||||
$text .= __(" for user: ", "unlimited-elements-for-elementor")."<b>$username</b>";
|
||||
|
||||
?>
|
||||
<div id="uc_instagram_reconnect_message" class="instagram-reconnect-message">
|
||||
<?php echo $text?>
|
||||
<a id="uc_button_delete_insta_data" href="javascript:void(0)" class="unite-button-secondary"> <?php _e("Clear Access Data","unlimited-elements-for-elementor")?></a>
|
||||
|
||||
<br>
|
||||
<?php echo $linkTest?>
|
||||
|
||||
</div>
|
||||
<div id="uc_instagram_connect_button_wrapper" class="uc-instagram-connect-button-wrapper" style="display:none">
|
||||
<?php echo $htmlButton?>
|
||||
</div>
|
||||
<br>
|
||||
<div class="uc-instagram-message-expire"><?php echo $expiresHTML?></div>
|
||||
<?php
|
||||
}else{
|
||||
|
||||
//put error message
|
||||
|
||||
if(GlobalsUnlimitedElements::$enableInstagramErrorMessage == true){
|
||||
?>
|
||||
<div class="instagram-error-message">
|
||||
|
||||
Our app is currently restricted to access the Instagram API due to recent requirements in Facebook's policies.
|
||||
<br>
|
||||
Our team is actively working to find solution to restore the functionality.
|
||||
<br>
|
||||
We appreciate your patience and understanding during this time.
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
echo $htmlButton;
|
||||
|
||||
}
|
||||
?>
|
||||
<br><br>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* renew the access token
|
||||
* redirect to settings later
|
||||
*/
|
||||
public static function renewAccessToken(){
|
||||
|
||||
$accessData = self::getInstagramSavedAccessData();
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($accessData, "access_token");
|
||||
|
||||
if(empty($accessToken))
|
||||
return(false);
|
||||
|
||||
//get new access token
|
||||
$objAPI = new InstagramAPIOfficialUC();
|
||||
$response = $objAPI->renewToken($accessToken);
|
||||
|
||||
$data = array();
|
||||
$data["access_token"] = UniteFunctionsUC::getVal($response, "access_token");
|
||||
$data["expires"] = UniteFunctionsUC::getVal($response, "expires_in");
|
||||
|
||||
self::saveInstagramConnectDataAjax($data, true, false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check and renew access token if needed
|
||||
*/
|
||||
public static function checkRenewAccessToken(){
|
||||
|
||||
$accessData = self::getInstagramSavedAccessData();
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($accessData, "access_token");
|
||||
|
||||
if(empty($accessToken))
|
||||
return(false);
|
||||
|
||||
$expires = UniteFunctionsUC::getVal($accessData, "expires");
|
||||
|
||||
if(empty($expires))
|
||||
return(false);
|
||||
|
||||
if(is_numeric($expires) == false)
|
||||
return(false);
|
||||
|
||||
//$strTime = UniteFunctionsUC::timestamp2DateTime($expires);
|
||||
|
||||
$currentStamp = time();
|
||||
|
||||
$diff = $expires - $currentStamp;
|
||||
|
||||
$month = 60*60*24*30;
|
||||
|
||||
if($diff > $month)
|
||||
return(false);
|
||||
|
||||
$isRenewed = false;
|
||||
|
||||
try{
|
||||
|
||||
$isRenewed = self::renewAccessToken();
|
||||
|
||||
}catch(Exception $e){}
|
||||
|
||||
return($isRenewed);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check transient once a day
|
||||
*/
|
||||
public static function checkRenewAccessToken_onceInAWhile(){
|
||||
|
||||
if(self::$instaCheckRunOnce == true)
|
||||
return(false);
|
||||
|
||||
self::$instaCheckRunOnce = true;
|
||||
|
||||
$value = UniteProviderFunctionsUC::getTransient(self::KEY_RENEW_BLOCKED);
|
||||
|
||||
if(!empty($value))
|
||||
return(false);
|
||||
|
||||
UniteProviderFunctionsUC::setTransient(self::KEY_RENEW_BLOCKED, true, self::RENEW_DELAY_SIX_HOURS);
|
||||
|
||||
set_transient(self::KEY_RENEW_BLOCKED, true, self::RENEW_DELAY_SIX_HOURS);
|
||||
|
||||
$isRenewed = self::checkRenewAccessToken();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert title to handle
|
||||
*/
|
||||
public static function convertTitleToHandle($title, $removeNonAscii = true){
|
||||
|
||||
$handle = strtolower($title);
|
||||
|
||||
$handle = str_replace(array("<22>", "<22>"), "a", $handle);
|
||||
$handle = str_replace(array("<22>", "<22>"), "a", $handle);
|
||||
$handle = str_replace(array("<22>", "<22>"), "o", $handle);
|
||||
|
||||
if($removeNonAscii == true){
|
||||
|
||||
// Remove any character that is not alphanumeric, white-space, or a hyphen
|
||||
$handle = preg_replace("/[^a-z0-9\s\_]/i", " ", $handle);
|
||||
|
||||
}
|
||||
|
||||
// Replace multiple instances of white-space with a single space
|
||||
$handle = preg_replace("/\s\s+/", " ", $handle);
|
||||
// Replace all spaces with underscores
|
||||
$handle = preg_replace("/\s/", "_", $handle);
|
||||
// Replace multiple underscore with a single underscore
|
||||
$handle = preg_replace("/\_\_+/", "_", $handle);
|
||||
// Remove leading and trailing underscores
|
||||
$handle = trim($handle, "_");
|
||||
|
||||
return($handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert number to textual representation
|
||||
*/
|
||||
public static function convertNumberToText($num){
|
||||
|
||||
if(empty($num))
|
||||
$num = 0;
|
||||
|
||||
$x = round($num);
|
||||
|
||||
$x_number_format = number_format($x);
|
||||
|
||||
if($x < 10000)
|
||||
return($x_number_format);
|
||||
|
||||
$x_array = explode(',', $x_number_format);
|
||||
$x_parts = array('k', 'm', 'b', 't');
|
||||
$x_count_parts = count($x_array) - 1;
|
||||
|
||||
$x_display = $x_array[0];
|
||||
|
||||
$x_display .= $x_parts[$x_count_parts - 1];
|
||||
|
||||
return $x_display;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate instagram user
|
||||
*/
|
||||
public static function validateInstance($user, $instance="user"){
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($user,"instagram $instance");
|
||||
|
||||
if(preg_match('/^[a-zA-Z0-9._]+$/', $user) == false)
|
||||
UniteFunctionsUC::throwError("The instagram $instance is incorrect");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sanitize insta user
|
||||
*/
|
||||
public static function sanitizeUser($user){
|
||||
|
||||
$user = str_replace("@","",$user);
|
||||
|
||||
return($user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sanitize insta user
|
||||
*/
|
||||
public static function sanitizeTag($tag){
|
||||
|
||||
$tag = str_replace("#","", $tag);
|
||||
|
||||
return($tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* containing - cotnain the txtopen adn txtclose or not
|
||||
*/
|
||||
public static function getTextPart($contents, $txtOpen, $txtClose, $containing = false, $numTimes = 1){
|
||||
|
||||
$pos1 = strpos($contents,$txtOpen);
|
||||
if($numTimes>1) {
|
||||
for($i=1;$i<$numTimes;$i++){
|
||||
$pos1 = strpos($contents,$txtOpen,$pos1+1);
|
||||
}
|
||||
}
|
||||
|
||||
if($pos1 === FALSE)
|
||||
return(false);
|
||||
|
||||
if($containing == false)
|
||||
$pos1 += strlen($txtOpen);
|
||||
|
||||
$pos2 = strpos($contents,$txtClose,$pos1);
|
||||
if($pos2 === false)
|
||||
return(false);
|
||||
|
||||
if($containing == true)
|
||||
$pos2 += strlen($txtClose);
|
||||
|
||||
$trans = substr($contents,$pos1,$pos2-$pos1);
|
||||
|
||||
$trans = trim($trans);
|
||||
|
||||
return($trans);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert stamp to date
|
||||
*/
|
||||
public static function stampToDate($stamp){
|
||||
|
||||
if(is_numeric($stamp) == false)
|
||||
return("");
|
||||
|
||||
$dateText = date("d F Y, H:i", $stamp);
|
||||
|
||||
return($dateText);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get time sinse the event
|
||||
*/
|
||||
public static function getTimeSince($time_stamp){
|
||||
|
||||
$time_difference = strtotime('now') - $time_stamp;
|
||||
|
||||
//year
|
||||
if ($time_difference >= 60 * 60 * 24 * 365.242199)
|
||||
return self::get_time_ago_string($time_stamp, 60 * 60 * 24 * 365.242199, 'y');
|
||||
|
||||
//month
|
||||
if ($time_difference >= 60 * 60 * 24 * 30.4368499)
|
||||
return self::get_time_ago_string($time_stamp, 60 * 60 * 24 * 30.4368499, 'mon');
|
||||
|
||||
//week
|
||||
if ($time_difference >= 60 * 60 * 24 * 7)
|
||||
return self::get_time_ago_string($time_stamp, 60 * 60 * 24 * 7, 'w');
|
||||
|
||||
//day
|
||||
if ($time_difference >= 60 * 60 * 24)
|
||||
return self::get_time_ago_string($time_stamp, 60 * 60 * 24, 'd');
|
||||
|
||||
//hour
|
||||
if($time_difference >= 60 * 60)
|
||||
return self::get_time_ago_string($time_stamp, 60 * 60, 'h');
|
||||
|
||||
//minute
|
||||
return self::get_time_ago_string($time_stamp, 60, 'min');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get time ago string
|
||||
*/
|
||||
private static function get_time_ago_string($time_stamp, $divisor, $time_unit){
|
||||
|
||||
$time_difference = strtotime("now") - $time_stamp;
|
||||
$time_units = floor($time_difference / $divisor);
|
||||
|
||||
settype($time_units, 'string');
|
||||
|
||||
if ($time_units === '0')
|
||||
return '1' . $time_unit;
|
||||
|
||||
return $time_units . $time_unit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
$pathBase = dirname(__FILE__) . "/";
|
||||
|
||||
require_once $pathBase . 'instagram_api_official.class.php';
|
||||
require_once $pathBase . 'obj_items.class.php';
|
||||
require_once $pathBase . 'obj_item.class.php';
|
||||
require_once $pathBase . 'obj_user.class.php';
|
||||
require_once $pathBase . 'obj_comments.class.php';
|
||||
require_once $pathBase . 'obj_comment.class.php';
|
||||
require_once $pathBase . 'helper.class.php';
|
||||
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class InstagramAPIOfficialUC{
|
||||
|
||||
const URL_REFRESH = "https://graph.instagram.com/refresh_access_token";
|
||||
const URL_AUTHORIZE = "https://api.instagram.com/oauth/authorize";
|
||||
const APP_CLIENT_ID = "301063367606985";
|
||||
const URL_APP_CONNECT = "https://unlimited-elements.com/instagram-connect/connect.php";
|
||||
|
||||
private $accessToken;
|
||||
private $userID;
|
||||
private $limit = 30;
|
||||
private $maxItems = 30;
|
||||
|
||||
const CACHE_RESPONSE = true;
|
||||
const DEBUG_SERVER_REQUEST = false;
|
||||
|
||||
/**
|
||||
* throw error
|
||||
*/
|
||||
private function throwError($message){
|
||||
|
||||
UniteFunctionsUC::throwError("Instagram API Error: $message");
|
||||
}
|
||||
|
||||
/**
|
||||
* call api
|
||||
*/
|
||||
private function serverRequest($url, $cacheSeconds = null){
|
||||
|
||||
$this->validateRequestCredentials($url);
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->debug(self::DEBUG_SERVER_REQUEST);
|
||||
$request->acceptJson();
|
||||
$request->cacheTime($this->shouldCacheRequest() === true ? $cacheSeconds : 0);
|
||||
|
||||
$request->withHeaders(array(
|
||||
"Accept-Charset" => "utf-8;q=0.7,*;q=0.7",
|
||||
"User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8",
|
||||
));
|
||||
|
||||
$request->validateResponse(function($response){
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if(isset($data["error"]) === true){
|
||||
$message = UniteFunctionsUC::getVal($data["error"], "message");
|
||||
|
||||
if(GlobalsUC::$is_admin === false)
|
||||
$message = null;
|
||||
|
||||
if(empty($message) === true)
|
||||
$message = "Oops! Something went wrong, please try again later.";
|
||||
|
||||
$this->throwError($message);
|
||||
}
|
||||
});
|
||||
|
||||
$response = $request->get($url);
|
||||
$data = $response->json();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate request credentials
|
||||
*/
|
||||
private function validateRequestCredentials($url){
|
||||
|
||||
$info = parse_url($url);
|
||||
$query = UniteFunctionsUC::getVal($info, "query");
|
||||
|
||||
parse_str($query, $params);
|
||||
|
||||
if(isset($params["access_token"]) === false)
|
||||
$this->throwError("Access token not found.");
|
||||
}
|
||||
|
||||
/**
|
||||
* should cache request
|
||||
*/
|
||||
private function shouldCacheRequest(){
|
||||
|
||||
if(self::CACHE_RESPONSE === false)
|
||||
return false;
|
||||
|
||||
$withoutCache = UniteFunctionsUC::getGetVar("ucnocache", "", UniteFunctionsUC::SANITIZE_TEXT_FIELD);
|
||||
$withoutCache = UniteFunctionsUC::strToBool($withoutCache);
|
||||
|
||||
if(UniteFunctionsWPUC::isCurrentUserHasPermissions() === false)
|
||||
$withoutCache = false;
|
||||
|
||||
return $withoutCache === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get request url for graph api
|
||||
*/
|
||||
private function getUrlRequest($type, $fields){
|
||||
|
||||
$userID = $this->userID;
|
||||
$accessToken = $this->accessToken;
|
||||
$baseURL = "https://graph.instagram.com/";
|
||||
|
||||
switch($type){
|
||||
case "user":
|
||||
$urlRequest = "{$baseURL}{$userID}?fields={$fields}";
|
||||
break;
|
||||
case "media":
|
||||
$limit = $this->limit;
|
||||
$urlRequest = "{$baseURL}{$userID}/media?limit={$limit}&fields={$fields}";
|
||||
break;
|
||||
default:
|
||||
$this->throwError("Wrong request type \"$type\".");
|
||||
}
|
||||
|
||||
$since = "";
|
||||
|
||||
$urlRequest .= "&access_token={$accessToken}&since=";
|
||||
|
||||
return $urlRequest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* request new graph
|
||||
*/
|
||||
private function requestGraphNew($type, $fields){
|
||||
|
||||
$urlRequest = $this->getUrlRequest($type, $fields);
|
||||
|
||||
$arrData = $this->serverRequest($urlRequest);
|
||||
|
||||
return($arrData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* request for user
|
||||
* Enter description here ...
|
||||
*/
|
||||
private function requestUser(){
|
||||
|
||||
$fields = array(
|
||||
"id",
|
||||
"media_count",
|
||||
"username",
|
||||
"account_type",
|
||||
);
|
||||
|
||||
$strFields = implode(",", $fields);
|
||||
|
||||
$response = $this->requestGraphNew("user", $strFields);
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* request for media
|
||||
*/
|
||||
private function requestMedia(){
|
||||
|
||||
$fields = "media_url,thumbnail_url,caption,id,media_type,timestamp,username,permalink,children{media_url,id,media_type,timestamp,permalink,thumbnail_url}";
|
||||
|
||||
$data = array();
|
||||
$count = 2;
|
||||
|
||||
$urlNext = $this->getUrlRequest("media", $fields);
|
||||
|
||||
$arrDataCombined = array();
|
||||
|
||||
$maxRequest = 3;
|
||||
|
||||
do{
|
||||
$response = $this->serverRequest($urlNext);
|
||||
|
||||
$data = UniteFunctionsUC::getVal($response, "data");
|
||||
if(empty($data))
|
||||
$data = array();
|
||||
|
||||
if(!empty($data))
|
||||
$arrDataCombined = array_merge($arrDataCombined, $data);
|
||||
|
||||
$numItems = count($arrDataCombined);
|
||||
|
||||
if($numItems >= $this->maxItems)
|
||||
return($arrDataCombined);
|
||||
|
||||
$paging = UniteFunctionsUC::getVal($response, "paging");
|
||||
$urlNext = UniteFunctionsUC::getVal($paging, "next");
|
||||
|
||||
$maxRequest--;
|
||||
if($maxRequest <= 0)
|
||||
$urlNext = null;
|
||||
|
||||
if($numItems >= $this->maxItems) //for insurance
|
||||
$urlNext = null;
|
||||
|
||||
}while(!empty($urlNext));
|
||||
|
||||
|
||||
return($arrDataCombined);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the access data
|
||||
*/
|
||||
private function initAccessData(){
|
||||
|
||||
$arrData = HelperInstaUC::getInstagramSavedAccessData();
|
||||
|
||||
$this->accessToken = UniteFunctionsUC::getVal($arrData, "access_token");
|
||||
$this->userID = UniteFunctionsUC::getVal($arrData, "user_id");
|
||||
|
||||
if(empty($this->accessToken) || empty($this->userID))
|
||||
UniteFunctionsUC::throwError("Wrong access data");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get images from user
|
||||
*/
|
||||
private function getUserData_new($user, $lastID = null, $userID = null){
|
||||
|
||||
$user = HelperInstaUC::sanitizeUser($user);
|
||||
|
||||
HelperInstaUC::validateInstance($user, "user");
|
||||
|
||||
$this->initAccessData();
|
||||
|
||||
$arrUserData = $this->requestUser();
|
||||
|
||||
$arrItemsData = $this->requestMedia();
|
||||
|
||||
$objItems = new InstaObjUserUCItemsUC();
|
||||
$objItems->initOfficialAPI($arrItemsData, $arrUserData);
|
||||
|
||||
return($objItems);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* renew the token
|
||||
*/
|
||||
public function renewToken($currentToken){
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->acceptJson();
|
||||
|
||||
$response = $request->get(self::URL_REFRESH, array(
|
||||
"grant_type" => "ig_refresh_token",
|
||||
"access_token" => $currentToken,
|
||||
));
|
||||
|
||||
$data = $response->json();
|
||||
$newAccessToken = UniteFunctionsUC::getVal($data, "access_token");
|
||||
|
||||
if(empty($newAccessToken) === true)
|
||||
$this->throwError("Unable to refresh the access token.");
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function ____END_NEW_REQUEST______(){}
|
||||
|
||||
|
||||
/**
|
||||
* convert items to simple array
|
||||
*/
|
||||
private function convertItemsToSimpleArray($objItems, $maxItems = null){
|
||||
|
||||
if($maxItems !== null){
|
||||
$maxItems = (int)$maxItems;
|
||||
if($maxItems < 1)
|
||||
$maxItems = null;
|
||||
}
|
||||
|
||||
$arrItems = $objItems->getItems();
|
||||
|
||||
$arrItemsData = array();
|
||||
|
||||
foreach($arrItems as $index=>$item){
|
||||
|
||||
if($maxItems && $index >= $maxItems)
|
||||
break;
|
||||
|
||||
$data = $item->getDataSimple();
|
||||
$arrItemsData[] = $data;
|
||||
}
|
||||
|
||||
|
||||
return($arrItemsData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get items data uf it's user or tag
|
||||
*/
|
||||
public function getItemsData($mixed, $lastID=null, $userID = null, $maxItems = null){
|
||||
|
||||
|
||||
$type = "";
|
||||
if(strpos($mixed,"@") === 0)
|
||||
$type = "user";
|
||||
else
|
||||
if(strpos($mixed,"#") === 0)
|
||||
$type = "tag";
|
||||
|
||||
if(empty($type)){
|
||||
$type = "user";
|
||||
$mixed .= "@".$mixed;
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
if(empty($type))
|
||||
UniteFunctionsUC::throwError("Wrong type, should be user or tag");
|
||||
|
||||
switch($type){
|
||||
case "user":
|
||||
|
||||
//$objItems = $this->getUserData($mixed, $lastID, $userID);
|
||||
$objItems = $this->getUserData_new($mixed, $lastID, $userID);
|
||||
|
||||
break;
|
||||
case "tag":
|
||||
$objItems = $this->getTagData($mixed, $lastID, $userID);
|
||||
break;
|
||||
}
|
||||
|
||||
$arrItems = $this->convertItemsToSimpleArray($objItems, $maxItems);
|
||||
|
||||
}catch(Exception $e){
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
//renew here
|
||||
HelperInstaUC::checkRenewAccessToken_onceInAWhile();
|
||||
|
||||
|
||||
$pageData = $objItems->getArrPageData();
|
||||
|
||||
$response = array();
|
||||
$response["main"] = $pageData;
|
||||
$response["items"] = $arrItems;
|
||||
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class InstaObjCommentUC{
|
||||
|
||||
public $commentID;
|
||||
|
||||
public $createdDateStamp;
|
||||
public $createdDate;
|
||||
|
||||
public $text;
|
||||
public $fromUser;
|
||||
public $username;
|
||||
|
||||
|
||||
/**
|
||||
* print all globals variables
|
||||
*/
|
||||
public function printVars(){
|
||||
|
||||
$vars = get_object_vars($this);
|
||||
|
||||
dmp($vars);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get text
|
||||
*/
|
||||
public function getText(){
|
||||
|
||||
$this->text = UniteProviderFunctionsIG::convertEmoji($this->text);
|
||||
|
||||
return($this->text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get username
|
||||
*/
|
||||
public function getUsername(){
|
||||
|
||||
return($this->username);
|
||||
}
|
||||
|
||||
/**
|
||||
* init comment by array
|
||||
*/
|
||||
public function init($comment){
|
||||
|
||||
//get date
|
||||
$this->createdDateStamp = UniteFunctionsUC::getVal($comment, "created_time");
|
||||
|
||||
$this->createdDate = HelperInstaUC::stampToDate($this->createdDateStamp);
|
||||
|
||||
//get text
|
||||
$this->text = UniteFunctionsUC::getVal($comment, "text");
|
||||
|
||||
//get from user
|
||||
$fromUser = UniteFunctionsUC::getVal($comment, "from");
|
||||
|
||||
$this->fromUser = new InstaObjUserUC();
|
||||
$this->fromUser->init($fromUser);
|
||||
|
||||
|
||||
//get id
|
||||
$this->commentID = UniteFunctionsUC::getVal($comment, "id");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* init by data
|
||||
*/
|
||||
public function initByData($text, $username){
|
||||
$this->username = $username;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* init by new API
|
||||
*/
|
||||
public function initNewAPI($data){
|
||||
|
||||
if(isset($data["node"]))
|
||||
$data = $data["node"];
|
||||
|
||||
$this->commentID = UniteFunctionsUC::getVal($data, "id");
|
||||
|
||||
$dataUser = UniteFunctionsUC::getVal($data, "owner");
|
||||
if(empty($dataUser))
|
||||
$dataUser = UniteFunctionsUC::getVal($data, "user");
|
||||
|
||||
$this->fromUser = new InstaObjUserUC();
|
||||
$this->fromUser->initByComment($dataUser);
|
||||
|
||||
$this->username = $dataUser["username"];
|
||||
|
||||
$this->text = UniteFunctionsUC::getVal($data, "text");
|
||||
|
||||
$this->createdDateStamp = $data["created_at"];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
/**
|
||||
* instagram comments list class
|
||||
*/
|
||||
class InstaObjCommentsUC{
|
||||
|
||||
private $arrComments = array();
|
||||
|
||||
|
||||
/**
|
||||
* get comments array
|
||||
*/
|
||||
public function getArrComments(){
|
||||
|
||||
return($this->arrComments);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get comments array from data
|
||||
*/
|
||||
private function getArrCommentsFromData($data){
|
||||
|
||||
$arrData = @$data["graphql"]["shortcode_media"]["edge_media_to_comment"]["edges"];
|
||||
|
||||
if(empty($arrData))
|
||||
$arrData = @$data["edge_media_to_comment"]["edges"];
|
||||
|
||||
if(empty($arrData))
|
||||
$arrData = @$data["media"]["comments"]["nodes"];
|
||||
|
||||
return($arrData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get caption from data
|
||||
*/
|
||||
private function getCaptionFromData($data){
|
||||
|
||||
$caption = @$data["graphql"]["shortcode_media"]["edge_media_to_caption"]["edges"][0]["node"]["text"];
|
||||
|
||||
if(empty($caption))
|
||||
$caption = @$data["edge_media_to_caption"]["edges"][0]["node"]["text"];
|
||||
|
||||
return($caption);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get username from data
|
||||
*/
|
||||
private function getUsernameFromData($data){
|
||||
|
||||
$username = @$data["owner"]["username"];
|
||||
|
||||
if(empty($username))
|
||||
$username = @$data["graphql"]["shortcode_media"]["owner"]["username"];
|
||||
|
||||
if(!empty($username))
|
||||
$username = "@".$username;
|
||||
|
||||
return($username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init comments by data from instagram server
|
||||
*/
|
||||
public function initByData($data){
|
||||
|
||||
$arrDataComments = $this->getArrCommentsFromData($data);
|
||||
|
||||
//create first comment
|
||||
$caption = $this->getCaptionFromData($data);
|
||||
$username = $this->getUsernameFromData($data);
|
||||
|
||||
if(!empty($caption)){
|
||||
$objComment = new InstaObjCommentUC();
|
||||
$objComment->initByData($caption, $username);
|
||||
$this->arrComments[] = $objComment;
|
||||
}
|
||||
|
||||
if(empty($arrDataComments) && empty($caption))
|
||||
return(false);
|
||||
|
||||
foreach($arrDataComments as $comment){
|
||||
|
||||
$objComment = new InstaObjCommentUC();
|
||||
$objComment->initNewAPI($comment);
|
||||
|
||||
$this->arrComments[] = $objComment;
|
||||
}
|
||||
|
||||
|
||||
return($this->arrComments);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,682 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class InstaObjItemUC{
|
||||
|
||||
const TYPE_VIDEO = "video";
|
||||
const TYPE_IMAGE = "image";
|
||||
const TYPE_ALBOM = "albom";
|
||||
|
||||
const IMAGE_LOW = "low_resolution";
|
||||
const IMAGE_STANDARD = "standard_resolution";
|
||||
const IMAGE_THUMB = "thumbnail";
|
||||
|
||||
const VIDEO_STANDART = "standard_resolution";
|
||||
const VIDEO_LOWRES = "low_resolution";
|
||||
const VIDEO_LOWBENDWIDTH = "low_bandwidth";
|
||||
|
||||
|
||||
public $isInited = false;
|
||||
private $item;
|
||||
public $code;
|
||||
public $locationName;
|
||||
public $arrImages;
|
||||
public $arrVideos;
|
||||
public $urlVideo;
|
||||
public $videoViews;
|
||||
public $canViewComments = false;
|
||||
public $numComments;
|
||||
public $arrComments = array();
|
||||
public $objComments;
|
||||
public $urlAltMedia;
|
||||
|
||||
public $hasCaption = false;
|
||||
public $captionText = "";
|
||||
public $captionTextProcessed = null;
|
||||
public $objCaption;
|
||||
|
||||
public $link;
|
||||
public $numLikes;
|
||||
public $arrLikesUsers = array();
|
||||
public $createdDateStamp;
|
||||
public $createdDateText;
|
||||
public $type;
|
||||
public $id;
|
||||
public $itemUser;
|
||||
public $itemUserID;
|
||||
|
||||
/**
|
||||
* validate if the item is inited
|
||||
*/
|
||||
private function validateInited(){
|
||||
|
||||
if($this->isInited == false)
|
||||
UniteFunctionsUC::throwError("The item is not inited");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get image standart resolution
|
||||
*/
|
||||
public function getImageStandart(){
|
||||
|
||||
$url = $this->arrImages[self::IMAGE_STANDARD]["url"];
|
||||
return($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* get video standart
|
||||
*/
|
||||
public function getVideoStandart(){
|
||||
|
||||
if(!isset($this->arrVideos[self::VIDEO_STANDART]))
|
||||
return("");
|
||||
|
||||
$url = $this->arrVideos[self::VIDEO_STANDART]["url"];
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* get link
|
||||
*/
|
||||
public function getLink(){
|
||||
|
||||
return($this->link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* process caption text
|
||||
*/
|
||||
private function processText($text){
|
||||
|
||||
$text = preg_replace('/#(\w+)/', '<a href="https://instagram.com/explore/tags/$1" target="_blank">#$1</a>', $text);
|
||||
$text = preg_replace('/@(\w+)/', '<a href="https://instagram.com/$1" target="_blank">@$1</a>', $text);
|
||||
|
||||
return($text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get caption text
|
||||
*/
|
||||
public function getCaptionText(){
|
||||
|
||||
if(empty($this->captionText))
|
||||
return($this->captionText);
|
||||
|
||||
if(empty($this->captionTextProcessed))
|
||||
$this->captionTextProcessed = $this->processText($this->captionText);
|
||||
|
||||
return($this->captionTextProcessed);
|
||||
}
|
||||
|
||||
/**
|
||||
* get num likes
|
||||
*/
|
||||
public function getNumLikes(){
|
||||
|
||||
return($this->numLikes);
|
||||
}
|
||||
|
||||
/**
|
||||
* num comments
|
||||
*/
|
||||
public function getNumComments(){
|
||||
|
||||
return($this->numComments);
|
||||
}
|
||||
|
||||
/**
|
||||
* get num comments textual
|
||||
*/
|
||||
public function getNumCommentsText(){
|
||||
|
||||
$numComments = HelperInstaUC::convertNumberToText($this->numComments);
|
||||
return($numComments);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get num likes textual
|
||||
*/
|
||||
public function getNumLikesText(){
|
||||
|
||||
$numLikes = HelperInstaUC::convertNumberToText($this->numLikes);
|
||||
return($numLikes);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get numer of video views text
|
||||
*/
|
||||
public function getNumVideoViewsText(){
|
||||
|
||||
$numViews = HelperInstaUC::convertNumberToText($this->videoViews);
|
||||
|
||||
return($numViews);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get comments array
|
||||
*/
|
||||
public function getArrComments(){
|
||||
|
||||
if(!empty($this->arrComments))
|
||||
return($this->arrComments);
|
||||
|
||||
if(empty($this->objComments))
|
||||
return(array());
|
||||
|
||||
$arrComments = $this->objComments->getArrComments();
|
||||
|
||||
return($arrComments);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get likes array
|
||||
*/
|
||||
public function getArrLikes(){
|
||||
|
||||
return($this->arrLikesUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* get url image low
|
||||
*/
|
||||
public function getImageLow(){
|
||||
$url = $this->arrImages[self::IMAGE_LOW]["url"];
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get caption text
|
||||
*/
|
||||
public function getCaption(){
|
||||
|
||||
if($this->hasCaption == false)
|
||||
return("");
|
||||
|
||||
$text = $this->captionText;
|
||||
|
||||
return($text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get location
|
||||
*/
|
||||
public function getLocation(){
|
||||
$location = $this->locationName;
|
||||
|
||||
return($location);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return if the item is video
|
||||
*/
|
||||
public function isVideo(){
|
||||
|
||||
if($this->type == "video")
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the id
|
||||
*/
|
||||
public function getID(){
|
||||
|
||||
return($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the code
|
||||
*/
|
||||
public function getCode(){
|
||||
|
||||
return($this->code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get time passed till now
|
||||
*/
|
||||
public function getTimePassedText(){
|
||||
|
||||
$timeSinse = HelperInstaUC::getTimeSince($this->createdDateStamp);
|
||||
|
||||
return($timeSinse);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get simple data
|
||||
*/
|
||||
public function getDataSimple(){
|
||||
|
||||
$isVideo = $this->isVideo();
|
||||
|
||||
$class = "";
|
||||
if($isVideo == true)
|
||||
$class = "uc-video-item";
|
||||
|
||||
$arr = array();
|
||||
$arr["thumb"] = $this->getImageLow();
|
||||
$arr["image"] = $this->getImageStandart();
|
||||
$arr["caption"] = $this->getCaption();
|
||||
$arr["num_likes"] = $this->getNumLikesText();
|
||||
$arr["num_comments"] = $this->getNumCommentsText();
|
||||
$arr["link"] = $this->getLink();
|
||||
$arr["isvideo"] = $isVideo;
|
||||
$arr["video_class"] = $class;
|
||||
$arr["num_video_views"] = $this->getNumVideoViewsText();
|
||||
$arr["url_video"] = $this->urlVideo;
|
||||
$arr["date_stamp"] = $this->createdDateStamp;
|
||||
$arr["date"] = $this->createdDateText;
|
||||
$arr["time_passed"] = $this->getTimePassedText();
|
||||
|
||||
|
||||
return($arr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get item value
|
||||
*/
|
||||
private function getVal($field){
|
||||
|
||||
$value = UniteFunctionsUC::getVal($this->item, $field);
|
||||
|
||||
unset($this->item[$field]);
|
||||
|
||||
return($value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse comments
|
||||
*/
|
||||
private function parseComments(){
|
||||
|
||||
$comments = $this->getVal("comments");
|
||||
|
||||
$this->numComments = UniteFunctionsUC::getVal($comments, "count");
|
||||
|
||||
$commentsData = UniteFunctionsUC::getVal($comments, "data");
|
||||
|
||||
if(empty($commentsData))
|
||||
return(false);
|
||||
|
||||
if(is_array($commentsData) == false)
|
||||
return(false);
|
||||
|
||||
//get all comments
|
||||
foreach($commentsData as $comment){
|
||||
|
||||
$objComment = new InstaObjCommentUC();
|
||||
$objComment->init($comment);
|
||||
|
||||
$this->arrComments[] = $objComment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse likes
|
||||
*/
|
||||
private function parseLikes(){
|
||||
|
||||
$likes = $this->getVal("likes");
|
||||
|
||||
//get num likes
|
||||
|
||||
$numLikes = UniteFunctionsUC::getVal($likes, "count");
|
||||
if(empty($numLikes))
|
||||
$numLikes = 0;
|
||||
|
||||
$this->numLikes = $numLikes;
|
||||
|
||||
//get likes users
|
||||
|
||||
$likesData = UniteFunctionsUC::getVal($likes, "data");
|
||||
|
||||
if(empty($likesData))
|
||||
return(false);
|
||||
|
||||
if(is_array($likesData) == false)
|
||||
return(false);
|
||||
|
||||
foreach($likesData as $likeUser){
|
||||
|
||||
$user = new InstaObjUserUC();
|
||||
$user->init($likeUser);
|
||||
|
||||
$this->arrLikesUsers[] = $user;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse user
|
||||
*/
|
||||
private function parseUser(){
|
||||
|
||||
$user = $this->getVal("user");
|
||||
|
||||
if(empty($user))
|
||||
return(false);
|
||||
|
||||
$this->itemUser = new InstaObjUserUC();
|
||||
$this->itemUser->init($user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse video type
|
||||
*/
|
||||
private function parseVideoRelated(){
|
||||
|
||||
$this->videoViews = $this->getVal("video_views");
|
||||
$this->arrVideos = $this->getVal("videos");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* parse the caption
|
||||
*/
|
||||
private function parseCaption(){
|
||||
|
||||
$caption = $this->getVal("caption");
|
||||
|
||||
if(empty($caption))
|
||||
return(false);
|
||||
|
||||
$this->hasCaption = true;
|
||||
|
||||
$this->objCaption = new InstaObjCommentUC();
|
||||
$this->objCaption->init($caption);
|
||||
|
||||
$this->captionText = $this->objCaption->text;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init by api response
|
||||
*/
|
||||
public function init($item){
|
||||
|
||||
//unset some vars
|
||||
unset($item["can_delete_comments"]);
|
||||
|
||||
$this->item = $item;
|
||||
|
||||
//code
|
||||
$this->code = $this->getVal("code");
|
||||
|
||||
//location
|
||||
$arrLocation = $this->getVal("location");
|
||||
$this->locationName = UniteFunctionsUC::getVal($arrLocation, "name");
|
||||
|
||||
//get images
|
||||
$this->arrImages = $this->getVal("images");
|
||||
|
||||
//get comments
|
||||
$canViewComments = $this->getVal("can_view_comments");
|
||||
$this->canViewComments = UniteFunctionsUC::strToBool($canViewComments);
|
||||
if($this->canViewComments == true)
|
||||
$this->parseComments();
|
||||
|
||||
//get alt media
|
||||
$this->urlAltMedia = $this->getVal("alt_media_url");
|
||||
|
||||
//get caption
|
||||
$this->parseCaption();
|
||||
|
||||
//link
|
||||
$this->link = $this->getVal("link");
|
||||
|
||||
//likes
|
||||
$this->parseLikes();
|
||||
|
||||
//created date
|
||||
$this->createdDateStamp = $this->getVal("created_time");
|
||||
$this->createdDateText = HelperInstaUC::stampToDate($this->createdDateStamp);
|
||||
|
||||
//get type
|
||||
$this->type = $this->getVal("type");
|
||||
|
||||
switch($this->type){
|
||||
case "image":
|
||||
break;
|
||||
case "video":
|
||||
$this->parseVideoRelated();
|
||||
break;
|
||||
default:
|
||||
throw new Error("Wrong item type: $this->type");
|
||||
break;
|
||||
}
|
||||
|
||||
//id
|
||||
$this->id = $this->getVal("id");
|
||||
|
||||
//user
|
||||
$this->parseUser();
|
||||
|
||||
if(!empty($this->item))
|
||||
UniteFunctionsUC::throwError("There something else need to be parsed");
|
||||
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* init is video
|
||||
*/
|
||||
private function initNew_isVideo($item){
|
||||
|
||||
$isVideo = UniteFunctionsUC::getVal($item, "is_video");
|
||||
$isVideo = UniteFunctionsUC::strToBool($isVideo);
|
||||
|
||||
$mediaType = UniteFunctionsUC::getVal($item, "media_type");
|
||||
|
||||
if($isVideo == true){
|
||||
$this->type = self::TYPE_VIDEO;
|
||||
}
|
||||
else{
|
||||
$this->type = self::TYPE_IMAGE;
|
||||
}
|
||||
|
||||
if($this->type != self::TYPE_VIDEO)
|
||||
return(false);
|
||||
|
||||
if(isset($item["video_url"])){
|
||||
$this->arrVideos[self::VIDEO_STANDART] = array();
|
||||
$this->arrVideos[self::VIDEO_STANDART]["url"] = UniteFunctionsUC::getVal($item, "video_url");
|
||||
}
|
||||
|
||||
$this->videoViews = UniteFunctionsUC::getVal($item, "video_view_count");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get link from code
|
||||
*/
|
||||
private function getLinkFromCode($code){
|
||||
|
||||
$link = "https://www.instagram.com/p/{$code}";
|
||||
|
||||
return($link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init by new API
|
||||
*/
|
||||
public function initNewAPI($item){
|
||||
|
||||
|
||||
if(isset($item["node"]))
|
||||
$item = $item["node"];
|
||||
|
||||
$this->initNew_isVideo($item);
|
||||
|
||||
$this->id = UniteFunctionsUC::getVal($item, "id");
|
||||
$this->code = UniteFunctionsUC::getVal($item, "code");
|
||||
if(empty($this->code))
|
||||
$this->code = $this->code = UniteFunctionsUC::getVal($item, "shortcode");
|
||||
|
||||
$commentsDisabled = UniteFunctionsUC::getVal($item, "comments_disabled");
|
||||
$commentsDisabled = UniteFunctionsUC::strToBool($commentsDisabled);
|
||||
|
||||
$this->canViewComments = !$commentsDisabled;
|
||||
|
||||
$this->createdDateStamp = UniteFunctionsUC::getVal($item, "taken_at_timestamp");
|
||||
|
||||
if(!empty($this->createdDateStamp))
|
||||
$this->createdDateText = HelperInstaUC::stampToDate($this->createdDateStamp);
|
||||
|
||||
$this->captionText = UniteFunctionsUC::getVal($item, "caption");
|
||||
$this->captionText = trim($this->captionText);
|
||||
|
||||
if(!empty($this->captionText))
|
||||
$this->hasCaption = true;
|
||||
|
||||
$this->link = $this->getLinkFromCode($this->code);
|
||||
|
||||
//init images
|
||||
|
||||
$this->arrImages = array();
|
||||
$this->arrImages[self::IMAGE_LOW] = array();
|
||||
$this->arrImages[self::IMAGE_STANDARD] = array();
|
||||
|
||||
$urlImageNormal = UniteFunctionsUC::getVal($item, "display_url");
|
||||
|
||||
$this->arrImages[self::IMAGE_LOW]["url"] = UniteFunctionsUC::getVal($item, "thumbnail_src");
|
||||
$this->arrImages[self::IMAGE_STANDARD]["url"] = $urlImageNormal;
|
||||
|
||||
$arrLikes = UniteFunctionsUC::getVal($item, "edge_liked_by");
|
||||
if(empty($arrLikes))
|
||||
$arrLikes = UniteFunctionsUC::getVal($item, "edge_media_preview_like");
|
||||
|
||||
$this->numLikes = UniteFunctionsUC::getVal($arrLikes, "count");
|
||||
|
||||
//init owner
|
||||
$ownerID = UniteFunctionsUC::getVal($item, "owner");
|
||||
if(!empty($ownerID))
|
||||
$this->itemUserID = $ownerID;
|
||||
|
||||
//get comments
|
||||
$arrComments = UniteFunctionsUC::getVal($item, "comments");
|
||||
if(empty($arrComments)){
|
||||
$arrComments = UniteFunctionsUC::getVal($item, "edge_media_to_comment");
|
||||
}
|
||||
|
||||
$this->numComments = UniteFunctionsUC::getVal($arrComments, "count");
|
||||
|
||||
$commentsNodes = UniteFunctionsUC::getVal($arrComments, "nodes");
|
||||
if(empty($commentsNodes))
|
||||
$commentsNodes = UniteFunctionsUC::getVal($arrComments, "edges");
|
||||
|
||||
if(!empty($commentsNodes)){
|
||||
|
||||
$this->objComments = new InstaObjCommentsUC();
|
||||
$this->objComments->initByData($item);
|
||||
}
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init item by official API
|
||||
*/
|
||||
public function initOfficialAPI($item){
|
||||
|
||||
$mediaType = UniteFunctionsUC::getVal($item, "media_type");
|
||||
|
||||
switch($mediaType){
|
||||
default:
|
||||
case "IMAGE":
|
||||
$this->type = self::TYPE_IMAGE;
|
||||
break;
|
||||
case "CAROUSEL_ALBUM":
|
||||
$this->type = self::TYPE_ALBOM;
|
||||
break;
|
||||
case "VIDEO":
|
||||
$this->type = self::TYPE_VIDEO;
|
||||
break;
|
||||
}
|
||||
|
||||
$urlImage = UniteFunctionsUC::getVal($item, "media_url");
|
||||
|
||||
if($this->type == self::TYPE_VIDEO){
|
||||
|
||||
$url = $this->arrVideos[self::VIDEO_STANDART]["url"] = $urlImage;
|
||||
|
||||
$urlImage = UniteFunctionsUC::getVal($item, "thumbnail_url");
|
||||
|
||||
$this->urlVideo = UniteFunctionsUC::getVal($item, "media_url");
|
||||
}
|
||||
|
||||
$this->arrImages[self::IMAGE_LOW]["url"] = $urlImage;
|
||||
$this->arrImages[self::IMAGE_STANDARD]["url"] = $urlImage;
|
||||
|
||||
$this->hasCaption = true;
|
||||
$this->captionText = UniteFunctionsUC::getVal($item, "caption");
|
||||
|
||||
$this->id = UniteFunctionsUC::getVal($item, "id");
|
||||
|
||||
$this->link = UniteFunctionsUC::getVal($item, "permalink");
|
||||
|
||||
$time = UniteFunctionsUC::getVal($item, "timestamp");
|
||||
|
||||
$timeStamp = strtotime($time);
|
||||
|
||||
$this->createdDateStamp = $timeStamp;
|
||||
|
||||
if(!empty($this->createdDateStamp))
|
||||
$this->createdDateText = HelperInstaUC::stampToDate($this->createdDateStamp);
|
||||
|
||||
$this->isInited = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* print item data
|
||||
*/
|
||||
public function printData(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
$str = "ID: {$this->id} <br> caption: $this->captionText ";
|
||||
|
||||
dmp($str);
|
||||
|
||||
dmp("---------------------");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class InstaObjUserUCItemsUC{
|
||||
|
||||
protected $isInited = false;
|
||||
protected $istag = false;
|
||||
protected $status;
|
||||
protected $totalItems;
|
||||
protected $numItems;
|
||||
protected $arrItems = array();
|
||||
protected $isMoreAvaliable = false;
|
||||
protected $lastID = null;
|
||||
private $username;
|
||||
private $userID;
|
||||
private $objUser;
|
||||
private $profileImage;
|
||||
|
||||
|
||||
/**
|
||||
* construct the class
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->objUser = new InstaObjUserUC();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate inited
|
||||
*/
|
||||
private function validateInited(){
|
||||
|
||||
if($this->isInited == false)
|
||||
UniteFunctionsUC::throwError("the items object not inited");
|
||||
|
||||
}
|
||||
|
||||
private function _GETTERS(){}
|
||||
|
||||
|
||||
/**
|
||||
* get items
|
||||
*/
|
||||
public function getItems(){
|
||||
|
||||
$this->validateInited();
|
||||
return($this->arrItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* get last ID
|
||||
*/
|
||||
public function getLastID(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
return($this->lastID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get user id
|
||||
*/
|
||||
public function getUserID(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
return($this->userID);
|
||||
}
|
||||
|
||||
/**
|
||||
* get username text
|
||||
*/
|
||||
public function getUsernameText(){
|
||||
|
||||
$name = $this->username;
|
||||
|
||||
if(!empty($this->objUser))
|
||||
$name = $this->objUser->name;
|
||||
|
||||
if(!$name)
|
||||
$name = $this->username;
|
||||
|
||||
return($name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get username
|
||||
*/
|
||||
public function getUsername(){
|
||||
|
||||
if($this->istag == false)
|
||||
$username = "@".$this->username;
|
||||
else
|
||||
$username = "#".$this->username;
|
||||
|
||||
return($username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get profile image
|
||||
*/
|
||||
public function getProfileImage(){
|
||||
|
||||
if(!empty($this->profileImage))
|
||||
return($this->profileImage);
|
||||
|
||||
if(!$this->objUser)
|
||||
return(false);
|
||||
|
||||
$profileImage = $this->objUser->urlProfileImage;
|
||||
|
||||
if(!$profileImage)
|
||||
return(false);
|
||||
|
||||
return($profileImage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get if more available
|
||||
*/
|
||||
public function getIsMoreAvaliable(){
|
||||
|
||||
return($this->isMoreAvaliable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get link to page
|
||||
*/
|
||||
public function getLink(){
|
||||
|
||||
if($this->istag == false)
|
||||
$link = "https://www.instagram.com/".$this->username;
|
||||
else
|
||||
$link = "https://www.instagram.com/explore/tags/".$this->username;
|
||||
|
||||
return($link);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get page data
|
||||
*/
|
||||
public function getArrPageData(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
$arr = array();
|
||||
$arr["name"] = $this->objUser->name;
|
||||
$arr["username"] = $this->getUsername();
|
||||
$arr["biography"] = $this->objUser->biography;
|
||||
$arr["image_profile"] = $this->objUser->urlProfileImage;
|
||||
$arr["num_followers"] = HelperInstaUC::convertNumberToText($this->objUser->numFollowedBy);
|
||||
$arr["num_following"] = HelperInstaUC::convertNumberToText($this->objUser->numFollows);
|
||||
$arr["num_posts"] = HelperInstaUC::convertNumberToText($this->objUser->numPosts);
|
||||
|
||||
$arr["url_external"] = $this->objUser->externalUrl;
|
||||
$arr["link"] = $this->getLink();
|
||||
|
||||
return($arr);
|
||||
}
|
||||
|
||||
|
||||
private function ___________SETTERS___________(){}
|
||||
|
||||
|
||||
/**
|
||||
* parse items from api
|
||||
*/
|
||||
private function parseItems($items){
|
||||
|
||||
$this->arrItems = array();
|
||||
|
||||
if(empty($items))
|
||||
return(false);
|
||||
|
||||
if(is_array($items) == false)
|
||||
return(false);
|
||||
|
||||
foreach($items as $item){
|
||||
|
||||
$objItem = new InstaObjItemUC();
|
||||
$objItem->init($item);
|
||||
|
||||
$this->arrItems[] = $objItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* parse item new api
|
||||
*/
|
||||
private function parseItemsNewApi($arrNodes){
|
||||
|
||||
$arrItems = array();
|
||||
foreach($arrNodes as $item){
|
||||
|
||||
$objItem = new InstaObjItemUC();
|
||||
$objItem->initNewAPI($item);
|
||||
|
||||
$arrItems[] = $objItem;
|
||||
}
|
||||
|
||||
$this->arrItems = $arrItems;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* set if it's user or tag
|
||||
*/
|
||||
public function setIsTag(){
|
||||
$this->istag = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init by api response
|
||||
*/
|
||||
public function init($apiResponse, $username){
|
||||
|
||||
$this->username = $username;
|
||||
|
||||
$this->status = UniteFunctionsUC::getVal($apiResponse, "status");
|
||||
|
||||
if($this->status != "ok"){
|
||||
dmp("status not ok!!!");
|
||||
dmp($apiResponse);
|
||||
exit();
|
||||
}
|
||||
|
||||
$moreAvailable = UniteFunctionsUC::getVal($apiResponse, "more_available");
|
||||
$this->isMoreAvaliable = UniteFunctionsUC::strToBool($moreAvailable);
|
||||
|
||||
$items = UniteFunctionsUC::getVal($apiResponse, "items");
|
||||
$this->parseItems($items);
|
||||
|
||||
$this->numItems = count($this->arrItems);
|
||||
|
||||
//init user
|
||||
if($this->numItems == 0)
|
||||
$this->objUser = null;
|
||||
else{
|
||||
$firstItem = $this->arrItems[0];
|
||||
$this->objUser = $firstItem->itemUser;
|
||||
if(!$this->objUser)
|
||||
$this->objUser = null;
|
||||
}
|
||||
|
||||
//set last ID
|
||||
if($this->numItems > 0)
|
||||
$this->lastID = $this->arrItems[$this->numItems-1]->getID();
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* init from graph ql api
|
||||
*/
|
||||
public function initApiGraphQL($arrItemsData, $arrUserData){
|
||||
|
||||
$arrData = UniteFunctionsUC::getVal($arrItemsData, "data");
|
||||
|
||||
if(empty($arrData))
|
||||
return(null);
|
||||
|
||||
$arrUser = UniteFunctionsUC::getVal($arrData, "user");
|
||||
|
||||
if(empty($arrUser))
|
||||
return(null);
|
||||
|
||||
$arrMedia = UniteFunctionsUC::getVal($arrUser, "edge_owner_to_timeline_media");
|
||||
|
||||
if(empty($arrMedia))
|
||||
return(null);
|
||||
|
||||
$arrEdges = UniteFunctionsUC::getVal($arrMedia, "edges");
|
||||
|
||||
if(empty($arrEdges))
|
||||
return(null);
|
||||
|
||||
//$keys = array_keys($arrEdges);
|
||||
$this->parseItemsNewApi($arrEdges);
|
||||
|
||||
$this->totalItems = 0;
|
||||
|
||||
//init obj user
|
||||
$this->userID = UniteFunctionsUC::getVal($arrUserData, "pk");
|
||||
$this->username = UniteFunctionsUC::getVal($arrUserData, "username");
|
||||
$this->objUser->initByNew($arrUserData);
|
||||
|
||||
$this->isInited = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* init new API
|
||||
*/
|
||||
public function initNewAPI($apiResponse){
|
||||
|
||||
$arrInstance = null;
|
||||
|
||||
if(isset($apiResponse["entry_data"])){
|
||||
$apiResponse = $apiResponse["entry_data"];
|
||||
$apiResponse = $apiResponse["ProfilePage"][0];
|
||||
}
|
||||
if(isset($apiResponse["graphql"]))
|
||||
$apiResponse = $apiResponse["graphql"];
|
||||
|
||||
|
||||
if(isset($apiResponse["user"]))
|
||||
$arrInstance = $apiResponse["user"];
|
||||
else
|
||||
if(isset($apiResponse["tag"]))
|
||||
$arrInstance = $apiResponse["tag"];
|
||||
|
||||
//init user
|
||||
if(!empty($apiResponse["user"])){
|
||||
$this->userID = UniteFunctionsUC::getVal($arrInstance, "id");
|
||||
$this->username = UniteFunctionsUC::getVal($arrInstance, "username");
|
||||
$this->objUser->initByNew($arrInstance);
|
||||
}
|
||||
|
||||
if(empty($arrInstance))
|
||||
UniteFunctionsUC::throwError("Server error - instance items not found");
|
||||
|
||||
$arrTopPosts = UniteFunctionsUC::getVal($arrInstance, "top_posts");
|
||||
$arrMedia = UniteFunctionsUC::getVal($arrInstance, "edge_owner_to_timeline_media");
|
||||
|
||||
|
||||
$arrNodes = array();
|
||||
if(!empty($arrTopPosts))
|
||||
$arrNodes = $arrTopPosts["nodes"];
|
||||
|
||||
if(!empty($arrMedia)){
|
||||
$arrMediaNodes = $arrMedia["edges"];
|
||||
foreach($arrMediaNodes as $node)
|
||||
$arrNodes[] = $node;
|
||||
}
|
||||
|
||||
if(empty($arrNodes))
|
||||
UniteFunctionsUC::throwError("No items found");
|
||||
|
||||
$this->parseItemsNewApi($arrNodes);
|
||||
|
||||
//get total items
|
||||
$this->totalItems = UniteFunctionsUC::getVal($arrMedia, "count");
|
||||
if(empty($this->totalItems))
|
||||
$this->totalItems = 0;
|
||||
|
||||
$arrPageInfo = UniteFunctionsUC::getVal($arrMedia, "page_info");
|
||||
|
||||
$this->isMoreAvaliable = false;
|
||||
|
||||
if(!empty($arrPageInfo)){
|
||||
$hasNext = UniteFunctionsUC::getVal($arrPageInfo, "has_next_page");
|
||||
$hasNext = UniteFunctionsUC::strToBool($hasNext);
|
||||
$this->isMoreAvaliable = $hasNext;
|
||||
if($hasNext == true)
|
||||
$this->lastID = UniteFunctionsUC::getVal($arrPageInfo, "end_cursor");
|
||||
}
|
||||
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* init from official api
|
||||
*/
|
||||
public function initOfficialAPI($arrItemsData, $arrUserData){
|
||||
|
||||
$this->userID = UniteFunctionsUC::getVal($arrUserData, "id");
|
||||
$this->username = UniteFunctionsUC::getVal($arrUserData, "username");
|
||||
$this->isInited = true;
|
||||
|
||||
$this->isMoreAvaliable = false;
|
||||
|
||||
if(empty($arrItemsData))
|
||||
UniteFunctionsUC::throwError("No Items Found");
|
||||
|
||||
foreach($arrItemsData as $item){
|
||||
|
||||
$objItem = new InstaObjItemUC();
|
||||
$objItem->initOfficialAPI($item);
|
||||
|
||||
$this->arrItems[] = $objItem;
|
||||
}
|
||||
|
||||
$this->numItems = count($this->arrItems);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* print the data
|
||||
*/
|
||||
public function printData(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
dmp("num items: ".$this->numItems);
|
||||
|
||||
dmp("---------------");
|
||||
|
||||
foreach($this->arrItems as $key => $item){
|
||||
|
||||
dmp($key);
|
||||
|
||||
$item->printData();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class InstaObjUserUC{
|
||||
|
||||
public $isInited = false;
|
||||
public $username,$urlProfileImage,$id,$name,$externalUrl,$numFollows;
|
||||
public $numFollowedBy, $biography, $urlProfileImageHD, $userData, $numPosts;
|
||||
|
||||
|
||||
/**
|
||||
* init user
|
||||
*/
|
||||
public function init($user){
|
||||
|
||||
if(empty($user))
|
||||
return(false);
|
||||
|
||||
if(is_array($user) == false)
|
||||
return(false);
|
||||
|
||||
$this->username = UniteFunctionsUC::getVal($user, "username");
|
||||
$this->urlProfileImage = UniteFunctionsUC::getVal($user, "profile_picture");
|
||||
$this->id = UniteFunctionsUC::getVal($user, "id");
|
||||
$this->name = UniteFunctionsUC::getVal($user, "full_name");
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init by new API
|
||||
*/
|
||||
public function initByNew($user){
|
||||
|
||||
|
||||
$this->externalUrl = UniteFunctionsUC::getVal($user, "external_url");
|
||||
|
||||
$this->name = UniteFunctionsUC::getVal($user, "full_name");
|
||||
|
||||
$this->id = UniteFunctionsUC::getVal($user, "id");
|
||||
|
||||
$media = UniteFunctionsUC::getVal($user, "edge_owner_to_timeline_media");
|
||||
$this->numPosts = UniteFunctionsUC::getVal($media, "count");
|
||||
|
||||
$arrFollows = UniteFunctionsUC::getVal($user, "edge_follow");
|
||||
$this->numFollows = UniteFunctionsUC::getVal($arrFollows, "count");
|
||||
|
||||
$arrFollowedBy = UniteFunctionsUC::getVal($user, "edge_followed_by");
|
||||
$this->numFollowedBy = UniteFunctionsUC::getVal($arrFollowedBy, "count");
|
||||
|
||||
$this->urlProfileImage = UniteFunctionsUC::getVal($user, "profile_pic_url");
|
||||
|
||||
$this->urlProfileImageHD = UniteFunctionsUC::getVal($user, "profile_pic_url_hd");
|
||||
|
||||
$this->biography = UniteFunctionsUC::getVal($user, "biography");
|
||||
|
||||
$this->username = UniteFunctionsUC::getVal($user, "username");
|
||||
|
||||
$this->userData = $user;
|
||||
|
||||
$this->isInited = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init by new API - from comment
|
||||
*/
|
||||
public function initByComment($user){
|
||||
|
||||
$this->id = UniteFunctionsUC::getVal($user, "id");
|
||||
$this->urlProfileImage = UniteFunctionsUC::getVal($user, "profile_pic_url");
|
||||
$this->username = UniteFunctionsUC::getVal($user, "username");
|
||||
|
||||
$this->isInited = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteMySql{
|
||||
|
||||
// sqlite class constants:
|
||||
const TYPE_KEY = "INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT";
|
||||
const TYPE_STRING = "VARCHAR(120)";
|
||||
const TYPE_NUMBER = "INTEGER";
|
||||
const TYPE_TEXT = "TEXT";
|
||||
const TYPE_BOOLEAN = "BOOLEAN";
|
||||
|
||||
//error codes:
|
||||
const CODE_ZERO = 0;
|
||||
const CODE_TABLE_NOT_EXISTS = 1;
|
||||
|
||||
private $mysql_host = "";
|
||||
private $mysql_user = "";
|
||||
private $mysql_pass = "";
|
||||
private $mysql_database = "";
|
||||
|
||||
public static $handle = null;
|
||||
public $lastRowID = -1;
|
||||
public $lastArr = array();
|
||||
private $charset = null;
|
||||
|
||||
|
||||
function __construct(){}
|
||||
|
||||
|
||||
/**
|
||||
* connect to database
|
||||
*/
|
||||
public function connect($host,$user,$pass,$database){
|
||||
|
||||
if(!function_exists("mysqli_connect"))
|
||||
throw new Exception("php mysql extension doesn't activated, please activate it in php.ini");
|
||||
|
||||
$this->mysql_host = $host;
|
||||
$this->mysql_user = $user;
|
||||
$this->mysql_pass = $pass;
|
||||
$this->mysql_database = $database;
|
||||
|
||||
$this->getCreateDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* set charset before connect
|
||||
*/
|
||||
public function setCharset($charset){
|
||||
|
||||
$this->charset = $charset;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* perform multi queries
|
||||
*/
|
||||
public function multiQueries($query){
|
||||
|
||||
$result = mysqli_multi_query(self::$handle, $query);
|
||||
|
||||
$this->checkForErrors("Multi Query");
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* throw new error
|
||||
*
|
||||
*/
|
||||
private function throwError($message, $code=null){
|
||||
|
||||
if($code == null)
|
||||
throw new Exception($message);
|
||||
else
|
||||
throw new Exception($message,$code);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
public function confirmOutput($message=""){
|
||||
return(array("success"=>true,"message"=>$message));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// validates if handle exists. if not - exit with error message
|
||||
public function validateHandle($functionName = ""){
|
||||
if(self::$handle == false){
|
||||
if($functionName) $this->exitWithMessage("$functionName error - no open database");
|
||||
else $this->throwError("sqlite error - no open database");
|
||||
}
|
||||
return($this->confirmOutput());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// validate table name field if empty or not exists - write error and exit.
|
||||
public function validateTableName($tableName,$functionName=""){
|
||||
if(trim($tableName) == ""){
|
||||
if($functionName) $this->throwError("$functionName error - no table found");
|
||||
else $this->throwError("sqlite error - no table found");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// validate if table is created. if not - write error message and exist
|
||||
public function validateTable($tableName,$functionName){
|
||||
$this->validateTableName($tableName,$functionName);
|
||||
if($this->isTableExists($tableName) == false){
|
||||
if($functionName) return($this->throwError("$functionName error - the table $tableName doesn't exists",self::CODE_TABLE_NOT_EXISTS));
|
||||
else $this->throwError("sqlite error - the table $tableName doesn't exists",self::CODE_TABLE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// valiadte fields array. if empty or the type is not array - write error message and exit.
|
||||
public function validateFields($arrFields,$functionName=""){
|
||||
if(gettype($arrFields)!="array") $this->throwError("createTable error - the fields array isn't array type.");
|
||||
if(count($arrFields) == 0) $this->throwError("createTable error - the fields don't given.");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// set database file (without path)
|
||||
public function setDbFile($dbFilepath){
|
||||
$this->dbFilepath = $dbFilepath;
|
||||
$response = $this->getCreateDatabase();
|
||||
return($response);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
public function setAbsolutePath($path){
|
||||
$this->databaseAbsolutePath = $path;
|
||||
$this->dbFilepath = "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
public function getLastRowID(){
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// return if table exists or not.
|
||||
public function isTableExists($tableName){
|
||||
$sql = 'select * from '.$tableName;
|
||||
|
||||
$numRows = mysqli_num_rows(mysqli_query(self::$handle,"SHOW TABLES LIKE '".$tableName."'"));
|
||||
$this->checkForErrors("Is table exists error",$sql);
|
||||
|
||||
return($numRows != 0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// create database. if already created - get database.
|
||||
public function getCreateDatabase(){
|
||||
|
||||
self::$handle = @mysqli_connect($this->mysql_host, $this->mysql_user, $this->mysql_pass);
|
||||
|
||||
if(!self::$handle){
|
||||
|
||||
$errorNumber = mysqli_connect_errno();
|
||||
|
||||
if(!empty($errorNumber)){
|
||||
$error = mysqli_connect_error();
|
||||
$this->throwError($error);
|
||||
}
|
||||
}
|
||||
|
||||
mysqli_select_db(self::$handle,$this->mysql_database);
|
||||
$this->checkForErrors("Mysql connect to database error");
|
||||
|
||||
if(!empty($this->charset))
|
||||
mysqli_set_charset(self::$handle, $this->charset);
|
||||
|
||||
return($this->confirmOutput());
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
// validate for errors
|
||||
private function checkForErrors($prefix = "",$query=""){
|
||||
|
||||
if(mysqli_error(self::$handle) == false)
|
||||
return(false);
|
||||
|
||||
$message = mysqli_error(self::$handle);
|
||||
if($prefix) $message = $prefix.' - '.$message;
|
||||
if($query) $message .= ' query: ' . $query;
|
||||
$this->throwError($message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get error message
|
||||
*/
|
||||
public function getErrorMsg(){
|
||||
|
||||
return mysqli_error(self::$handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get last operation error code
|
||||
*/
|
||||
public function getErrorNumber(){
|
||||
|
||||
return mysql_errno(self::$handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* execute query with some error text
|
||||
*/
|
||||
public function query($query,$errorText=""){
|
||||
|
||||
mysqli_query(self::$handle,$query);
|
||||
|
||||
$this->checkForErrors($errorText,$query);
|
||||
|
||||
return(mysqli_affected_rows(self::$handle));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get query array
|
||||
*/
|
||||
public function getQueryArr($query, $errorText){
|
||||
|
||||
$rs = mysqli_query(self::$handle, $query);
|
||||
|
||||
$this->checkForErrors($errorText, $query);
|
||||
|
||||
$arrRows = array();
|
||||
|
||||
while($row = mysqli_fetch_assoc($rs))
|
||||
$arrRows[] = $row;
|
||||
|
||||
$this->lastArr = $arrRows;
|
||||
|
||||
return($arrRows);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get affected rows
|
||||
*/
|
||||
public function getAffectedRows(){
|
||||
|
||||
return(mysqli_affected_rows(self::$handle));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* returrn last insert id.
|
||||
*/
|
||||
public function insertid(){
|
||||
|
||||
$this->lastRowID = mysqli_insert_id(self::$handle);
|
||||
|
||||
return($this->lastRowID);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
//return escape database parameter string.
|
||||
public function escape($str){
|
||||
|
||||
if(function_exists("mysqli_real_escape_string"))
|
||||
return mysqli_real_escape_string(self::$handle, $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}// Database class end.
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
class UEOpenWeatherAPIClient{
|
||||
|
||||
const DATA_BASE_URL = "https://api.openweathermap.org/data/3.0";
|
||||
const GEO_BASE_URL = "http://api.openweathermap.org/geo/1.0";
|
||||
|
||||
private $apiKey;
|
||||
private $cacheTime = 0; // in seconds
|
||||
|
||||
/**
|
||||
* Create a new client instance.
|
||||
*
|
||||
* @param string $apiKey
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($apiKey){
|
||||
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache time.
|
||||
*
|
||||
* @param int $seconds
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCacheTime($seconds){
|
||||
|
||||
$this->cacheTime = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the test URL for the API key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKeyTestUrl(){
|
||||
|
||||
return self::DATA_BASE_URL . "/onecall?" . http_build_query(array(
|
||||
// London, GB
|
||||
"lat" => "51.5073219",
|
||||
"lon" => "-0.1276474",
|
||||
"appid" => $this->apiKey,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get forecasts for the given location.
|
||||
*
|
||||
* @param string $country
|
||||
* @param string $city
|
||||
* @param string $units
|
||||
*
|
||||
* @return UEOpenWeatherAPIForecast[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getForecasts($country, $city, $units = UEOpenWeatherAPIForecast::UNITS_STANDARD){
|
||||
|
||||
$location = $this->findLocation($country, $city);
|
||||
|
||||
$locale = get_locale();
|
||||
$locale = explode("_", $locale);
|
||||
$locale = reset($locale);
|
||||
|
||||
$params = array(
|
||||
"lat" => $location["lat"],
|
||||
"lon" => $location["lon"],
|
||||
"units" => $units,
|
||||
"exclude" => "minutely",
|
||||
"lang" => $locale,
|
||||
);
|
||||
|
||||
$response = $this->get(self::DATA_BASE_URL . "/onecall", $params);
|
||||
|
||||
$params = array(
|
||||
"latitude" => UniteFunctionsUC::getVal($response, "lat"),
|
||||
"longitude" => UniteFunctionsUC::getVal($response, "lon"),
|
||||
"timezone" => UniteFunctionsUC::getVal($response, "timezone"),
|
||||
"timezone_offset" => UniteFunctionsUC::getVal($response, "timezone_offset"),
|
||||
"units" => $units,
|
||||
);
|
||||
|
||||
$current = UniteFunctionsUC::getVal($response, "current", array());
|
||||
$current = UEOpenWeatherAPIForecastCurrent::transform($current, $params);
|
||||
|
||||
$hourly = UniteFunctionsUC::getVal($response, "hourly", array());
|
||||
$hourly = UEOpenWeatherAPIForecastHourly::transformAll($hourly, $params);
|
||||
|
||||
$daily = UniteFunctionsUC::getVal($response, "daily", array());
|
||||
$daily = UEOpenWeatherAPIForecastDaily::transformAll($daily, $params);
|
||||
|
||||
$alerts = UniteFunctionsUC::getVal($response, "alerts", array());
|
||||
|
||||
$forecast = array(
|
||||
"current" => $current,
|
||||
"hourly" => $hourly,
|
||||
"daily" => $daily,
|
||||
"alerts" => $alerts,
|
||||
);
|
||||
|
||||
return $forecast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a location by the given country and city.
|
||||
*
|
||||
* @param string $country
|
||||
* @param string $city
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function findLocation($country, $city){
|
||||
|
||||
$params = array(
|
||||
"q" => "$city, $country",
|
||||
"limit" => 1,
|
||||
);
|
||||
|
||||
$response = $this->get(self::GEO_BASE_URL . "/direct", $params);
|
||||
$location = reset($response);
|
||||
|
||||
if(empty($location) === true)
|
||||
throw new Exception("Location not found.");
|
||||
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a GET request to the API.
|
||||
*
|
||||
* @param $url
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function get($url, $params = array()){
|
||||
|
||||
return $this->request(UEHttpRequest::METHOD_GET, $url, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request to the API.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function request($method, $url, $params = array()){
|
||||
|
||||
$params["appid"] = $this->apiKey;
|
||||
|
||||
$query = ($method === UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
$body = ($method !== UEHttpRequest::METHOD_GET) ? $params : array();
|
||||
|
||||
$request = UEHttp::make();
|
||||
$request->asJson();
|
||||
$request->acceptJson();
|
||||
$request->cacheTime($this->cacheTime);
|
||||
$request->withQuery($query);
|
||||
$request->withBody($body);
|
||||
|
||||
$request->validateResponse(function($response){
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
if(isset($data["cod"]) === true)
|
||||
$this->throwError("{$data["message"]} ({$data["cod"]})");
|
||||
});
|
||||
|
||||
$response = $request->request($method, $url);
|
||||
$data = $response->json();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown an exception with the given message.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function throwError($message){
|
||||
|
||||
UniteFunctionsUC::throwError("OpenWeather API Error: $message");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,545 @@
|
||||
<?php
|
||||
|
||||
class UEOpenWeatherAPIForecast extends UEOpenWeatherAPIModel{
|
||||
|
||||
const UNITS_STANDARD = "standard";
|
||||
const UNITS_METRIC = "metric";
|
||||
const UNITS_IMPERIAL = "imperial";
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getTime();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(){
|
||||
|
||||
$description = $this->getAttribute("summary");
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconName(){
|
||||
|
||||
$iconName = $this->getWeatherArrayAttribute("icon");
|
||||
|
||||
return $iconName;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current description
|
||||
*/
|
||||
public function getCurrentDescription(){
|
||||
|
||||
$description = $this->getWeatherArrayAttribute("description");
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current description
|
||||
*/
|
||||
public function getCurrentState(){
|
||||
|
||||
$state = $this->getWeatherArrayAttribute("main");
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconUrl(){
|
||||
|
||||
$name = $this->getIconName();
|
||||
$url = "https://openweathermap.org/img/wn/" . $name . "@2x.png";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pressure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPressure(){
|
||||
|
||||
$pressure = $this->getAttribute("pressure");
|
||||
$pressure = sprintf(__("%s hPa", "unlimited-elements-for-elementor"), $pressure);
|
||||
|
||||
return $pressure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the humidity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumidity(){
|
||||
|
||||
$humidity = $this->getAttribute("humidity");
|
||||
$humidity = $this->formatPercentage($humidity);
|
||||
|
||||
return $humidity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cloudiness.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCloudiness(){
|
||||
|
||||
$cloudiness = $this->getAttribute("clouds");
|
||||
$cloudiness = $this->formatPercentage($cloudiness);
|
||||
|
||||
return $cloudiness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rain.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRain(){
|
||||
|
||||
$rain = $this->getAttribute("rain", 0);
|
||||
$rain = $this->formatPrecipitation($rain);
|
||||
|
||||
return $rain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snow.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSnow(){
|
||||
|
||||
$snow = $this->getAttribute("snow", 0);
|
||||
$snow = $this->formatPrecipitation($snow);
|
||||
|
||||
return $snow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UVI.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getUvi(){
|
||||
|
||||
$uvi = $this->getAttribute("uvi");
|
||||
|
||||
return $uvi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMinTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("min");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMaxTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("max");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the morning temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorningTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("morn");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the day temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDayTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("day");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evening temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEveningTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("eve");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the night temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNightTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("night");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current temperature
|
||||
*/
|
||||
public function getCurrentTemperature(){
|
||||
|
||||
$temperature = $this->getAttributeTemperature("temp");
|
||||
|
||||
return ($temperature);
|
||||
}
|
||||
|
||||
/**
|
||||
* get current feels like
|
||||
*/
|
||||
public function getCurrentFeelsLike(){
|
||||
|
||||
$temperature = $this->getAttributeTemperature("feels_like");
|
||||
|
||||
return ($temperature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the morning "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorningFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("morn");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the day "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDayFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("day");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evening "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEveningFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("eve");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the night "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNightFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("night");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind speed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWindSpeed(){
|
||||
|
||||
$speed = $this->getAttribute("wind_speed");
|
||||
$speed = $this->formatSpeed($speed);
|
||||
|
||||
return $speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind degrees.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWindDegrees(){
|
||||
|
||||
$degrees = $this->getAttribute("wind_deg");
|
||||
|
||||
return $degrees;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind gust.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWindGust(){
|
||||
|
||||
$gust = $this->getAttribute("wind_gust");
|
||||
$gust = $this->formatSpeed($gust);
|
||||
|
||||
return $gust;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate($format){
|
||||
|
||||
$time = $this->getTime();
|
||||
$date = $this->formatTime($time, $format);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* get sunrise
|
||||
*/
|
||||
public function getSunrise(){
|
||||
|
||||
$sunrise = $this->getAttribute("sunrise");
|
||||
|
||||
$sunrise = $this->formatTime($sunrise, "H:i");
|
||||
|
||||
return ($sunrise);
|
||||
}
|
||||
|
||||
/**
|
||||
* get sunrise
|
||||
*/
|
||||
public function getSunset(){
|
||||
|
||||
$sunset = $this->getAttribute("sunset");
|
||||
|
||||
$sunset = $this->formatTime($sunset, "H:i");
|
||||
|
||||
return ($sunset);
|
||||
}
|
||||
|
||||
/**
|
||||
* format hours for sunset
|
||||
*/
|
||||
private function formatTime($timestemp, $format){
|
||||
|
||||
$timezone = $this->getParameter("timezone");
|
||||
|
||||
$date = new DateTime();
|
||||
$objTimezone = new DateTimeZone($timezone);
|
||||
|
||||
$date->setTimestamp($timestemp);
|
||||
|
||||
$date->setTimezone($objTimezone);
|
||||
|
||||
$hours = $date->format($format);
|
||||
|
||||
return ($hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getWeatherArrayAttribute($key){
|
||||
|
||||
$weather = $this->getAttribute("weather");
|
||||
$weather = UniteFunctionsUC::getVal($weather, 0, array()); // the first weather condition is primary
|
||||
$value = UniteFunctionsUC::getVal($weather, $key);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* get temperature from numeric attribute
|
||||
*/
|
||||
private function getAttributeTemperature($key){
|
||||
|
||||
$temperature = $this->getAttribute($key);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return ($temperature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the temperature.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemperature($key, $fallback = null){
|
||||
|
||||
$temperature = $this->getAttribute("temp");
|
||||
$temperature = UniteFunctionsUC::getVal($temperature, $key, $fallback);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "feels like" temperature.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFeelsLike($key, $fallback = null){
|
||||
|
||||
$temperature = $this->getAttribute("feels_like");
|
||||
$temperature = UniteFunctionsUC::getVal($temperature, $key, $fallback);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getTime(){
|
||||
|
||||
$time = $this->getAttribute("dt");
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the units.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getUnits(){
|
||||
|
||||
$units = $this->getParameter("units");
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the percentage.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatPercentage($value){
|
||||
|
||||
return sprintf(__("%s%%", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the precipitation.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatPrecipitation($value){
|
||||
|
||||
if(is_array($value))
|
||||
$value = UniteFunctionsUC::getArrFirstValue($value);
|
||||
|
||||
if(is_array($value))
|
||||
$value = 0;
|
||||
|
||||
return sprintf(__("%s mm", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the speed.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatSpeed($value){
|
||||
|
||||
switch($this->getUnits()){
|
||||
case self::UNITS_IMPERIAL:
|
||||
return sprintf(__("%s mph", "unlimited-elements-for-elementor"), $value);
|
||||
default:
|
||||
return sprintf(__("%s m/s", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the temperature.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function formatTemperature($value){
|
||||
|
||||
if(is_numeric($value))
|
||||
$value = round($value);
|
||||
|
||||
return sprintf(__("%s°", "unlimited-elements-for-elementor"), $value);
|
||||
|
||||
//switch($this->getUnits()){
|
||||
// case self::UNITS_METRIC:
|
||||
// return sprintf(__("%s°C", "unlimited-elements-for-elementor"), $value);
|
||||
// case self::UNITS_IMPERIAL:
|
||||
// return sprintf(__("%s°F", "unlimited-elements-for-elementor"), $value);
|
||||
// default:
|
||||
// return sprintf(__("%sK", "unlimited-elements-for-elementor"), $value);
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
|
||||
abstract class UEOpenWeatherAPIForecastAbstract extends UEOpenWeatherAPIModel{
|
||||
|
||||
const UNITS_STANDARD = "standard";
|
||||
const UNITS_METRIC = "metric";
|
||||
const UNITS_IMPERIAL = "imperial";
|
||||
|
||||
/**
|
||||
* Get the identifier.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(){
|
||||
|
||||
$id = $this->getTime();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate($format){
|
||||
|
||||
$time = $this->getTime();
|
||||
$date = $this->formatTime($time, $format);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(){
|
||||
|
||||
$description = $this->getWeather("description");
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getState(){
|
||||
|
||||
$state = $this->getWeather("main");
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconName(){
|
||||
|
||||
$name = $this->getWeather("icon");
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconUrl(){
|
||||
|
||||
$name = $this->getIconName();
|
||||
$url = "https://openweathermap.org/img/wn/" . $name . "@2x.png";
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pressure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPressure(){
|
||||
|
||||
$pressure = $this->getAttribute("pressure");
|
||||
$pressure = sprintf(__("%s hPa", "unlimited-elements-for-elementor"), $pressure);
|
||||
|
||||
return $pressure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the humidity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHumidity(){
|
||||
|
||||
$humidity = $this->getAttribute("humidity");
|
||||
$humidity = $this->formatPercentage($humidity);
|
||||
|
||||
return $humidity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cloudiness.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCloudiness(){
|
||||
|
||||
$cloudiness = $this->getAttribute("clouds");
|
||||
$cloudiness = $this->formatPercentage($cloudiness);
|
||||
|
||||
return $cloudiness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rain.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRain(){
|
||||
|
||||
$rain = $this->getAttribute("rain", 0);
|
||||
$rain = $this->formatPrecipitation($rain);
|
||||
|
||||
return $rain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the snow.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSnow(){
|
||||
|
||||
$snow = $this->getAttribute("snow", 0);
|
||||
$snow = $this->formatPrecipitation($snow);
|
||||
|
||||
return $snow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UVI.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getUvi(){
|
||||
|
||||
$uvi = $this->getAttribute("uvi");
|
||||
|
||||
return $uvi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind speed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWindSpeed(){
|
||||
|
||||
$speed = $this->getAttribute("wind_speed");
|
||||
$speed = $this->formatSpeed($speed);
|
||||
|
||||
return $speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind degrees.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWindDegrees(){
|
||||
|
||||
$degrees = $this->getAttribute("wind_deg");
|
||||
|
||||
return $degrees;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wind gust.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWindGust(){
|
||||
|
||||
$gust = $this->getAttribute("wind_gust");
|
||||
$gust = $this->formatSpeed($gust);
|
||||
|
||||
return $gust;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the weather.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getWeather($key, $fallback = null){
|
||||
|
||||
$weather = $this->getAttribute("weather");
|
||||
$weather = UniteFunctionsUC::getVal($weather, 0, array()); // the first weather condition is primary
|
||||
$value = UniteFunctionsUC::getVal($weather, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getTime(){
|
||||
|
||||
$time = $this->getAttribute("dt");
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the units.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getUnits(){
|
||||
|
||||
$units = $this->getParameter("units");
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the percentage.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatPercentage($value){
|
||||
|
||||
return sprintf(__("%s%%", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the precipitation.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatPrecipitation($value){
|
||||
|
||||
if(is_array($value))
|
||||
$value = UniteFunctionsUC::getArrFirstValue($value);
|
||||
|
||||
if(is_array($value))
|
||||
$value = 0;
|
||||
|
||||
return sprintf(__("%s mm", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the speed.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatSpeed($value){
|
||||
|
||||
switch($this->getUnits()){
|
||||
case self::UNITS_IMPERIAL:
|
||||
return sprintf(__("%s mph", "unlimited-elements-for-elementor"), $value);
|
||||
default:
|
||||
return sprintf(__("%s m/s", "unlimited-elements-for-elementor"), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the temperature.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatTemperature($value){
|
||||
|
||||
if(is_numeric($value) === true)
|
||||
$value = round($value);
|
||||
|
||||
return sprintf(__("%s°", "unlimited-elements-for-elementor"), $value);
|
||||
|
||||
//switch($this->getUnits()){
|
||||
// case self::UNITS_METRIC:
|
||||
// return sprintf(__("%s°C", "unlimited-elements-for-elementor"), $value);
|
||||
// case self::UNITS_IMPERIAL:
|
||||
// return sprintf(__("%s°F", "unlimited-elements-for-elementor"), $value);
|
||||
// default:
|
||||
// return sprintf(__("%sK", "unlimited-elements-for-elementor"), $value);
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the time.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* @param string $format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatTime($timestamp, $format){
|
||||
|
||||
$timezone = $this->getParameter("timezone");
|
||||
|
||||
$dateTimezone = new DateTimeZone($timezone);
|
||||
|
||||
$date = new DateTime();
|
||||
$date->setTimezone($dateTimezone);
|
||||
$date->setTimestamp($timestamp);
|
||||
|
||||
$time = $date->format($format);
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class UEOpenWeatherAPIForecastCurrent extends UEOpenWeatherAPIForecastAbstract{
|
||||
|
||||
use UEOpenWeatherAPIForecastHasInlineTemperature, UEOpenWeatherAPIForecastHasSunTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
class UEOpenWeatherAPIForecastDaily extends UEOpenWeatherAPIForecastAbstract{
|
||||
|
||||
use UEOpenWeatherAPIForecastHasSunTime;
|
||||
|
||||
/**
|
||||
* Get the minimum temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMinTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("min");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMaxTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("max");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the morning temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorningTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("morn");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the day temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDayTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("day");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evening temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEveningTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("eve");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the night temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNightTemperature(){
|
||||
|
||||
$temperature = $this->getTemperature("night");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the morning "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMorningFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("morn");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the day "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDayFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("day");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evening "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEveningFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("eve");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the night "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNightFeelsLike(){
|
||||
|
||||
$temperature = $this->getFeelsLike("night");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the temperature.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTemperature($key){
|
||||
|
||||
$temperature = $this->getAttribute("temp", array());
|
||||
$temperature = UniteFunctionsUC::getVal($temperature, $key, 0);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "feels like" temperature.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getFeelsLike($key){
|
||||
|
||||
$temperature = $this->getAttribute("feels_like", array());
|
||||
$temperature = UniteFunctionsUC::getVal($temperature, $key, 0);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
trait UEOpenWeatherAPIForecastHasInlineTemperature{
|
||||
|
||||
/**
|
||||
* Get the temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemperature(){
|
||||
|
||||
$temperature = $this->getTemperatureAttribute("temp");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "feels like" temperature.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFeelsLike(){
|
||||
|
||||
$temperature = $this->getTemperatureAttribute("feels_like");
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the temperature attribute.
|
||||
*/
|
||||
private function getTemperatureAttribute($key){
|
||||
|
||||
$temperature = $this->getAttribute($key);
|
||||
$temperature = $this->formatTemperature($temperature);
|
||||
|
||||
return $temperature;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
trait UEOpenWeatherAPIForecastHasSunTime{
|
||||
|
||||
/**
|
||||
* Get the sunrise time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSunrise(){
|
||||
|
||||
$sunrise = $this->getAttribute("sunrise");
|
||||
$sunrise = $this->formatTime($sunrise, "H:i");
|
||||
|
||||
return $sunrise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sunset time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSunset(){
|
||||
|
||||
$sunset = $this->getAttribute("sunset");
|
||||
$sunset = $this->formatTime($sunset, "H:i");
|
||||
|
||||
return $sunset;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
class UEOpenWeatherAPIForecastHourly extends UEOpenWeatherAPIForecastAbstract{
|
||||
|
||||
use UEOpenWeatherAPIForecastHasInlineTemperature;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/model.class.php";
|
||||
require_once __DIR__ . "/client.class.php";
|
||||
|
||||
require_once __DIR__ . "/forecast/forecast_has_inline_temperature.class.php";
|
||||
require_once __DIR__ . "/forecast/forecast_has_sun_time.class.php";
|
||||
require_once __DIR__ . "/forecast/forecast_abstract.class.php";
|
||||
require_once __DIR__ . "/forecast/forecast_current.class.php";
|
||||
require_once __DIR__ . "/forecast/forecast_daily.class.php";
|
||||
require_once __DIR__ . "/forecast/forecast_hourly.class.php";
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
abstract class UEOpenWeatherAPIModel{
|
||||
|
||||
private $attributes;
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($attributes, $parameters = array()){
|
||||
|
||||
$this->attributes = $attributes;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform list of items into models.
|
||||
*
|
||||
* @param array $items
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return static[]
|
||||
*/
|
||||
public static function transformAll($items, $parameters = array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach($items as $attributes){
|
||||
$data[] = self::transform($attributes, $parameters);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attributes into a model.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function transform($attributes, $parameters = array()){
|
||||
|
||||
$model = new static($attributes, $parameters);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attribute value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getAttribute($key, $fallback = null){
|
||||
|
||||
$value = UniteFunctionsUC::getVal($this->attributes, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parameter value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $fallback
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getParameter($key, $fallback = null){
|
||||
|
||||
$value = UniteFunctionsUC::getVal($this->parameters, $key, $fallback);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UEParamsManager{
|
||||
|
||||
/**
|
||||
* Determine if the parameter passes conditions.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $param
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function isParamPassesConditions($params, $param){
|
||||
|
||||
$enableCondition = UniteFunctionsUC::getVal($param, "enable_condition");
|
||||
$enableCondition = UniteFunctionsUC::strToBool($enableCondition);
|
||||
|
||||
if($enableCondition === false)
|
||||
return true;
|
||||
|
||||
$conditions = array(
|
||||
array(
|
||||
"attribute" => UniteFunctionsUC::getVal($param, "condition_attribute"),
|
||||
"operator" => UniteFunctionsUC::getVal($param, "condition_operator"),
|
||||
"value" => UniteFunctionsUC::getVal($param, "condition_value"),
|
||||
),
|
||||
array(
|
||||
"attribute" => UniteFunctionsUC::getVal($param, "condition_attribute2"),
|
||||
"operator" => UniteFunctionsUC::getVal($param, "condition_operator2"),
|
||||
"value" => UniteFunctionsUC::getVal($param, "condition_value2"),
|
||||
),
|
||||
);
|
||||
|
||||
foreach($conditions as $condition){
|
||||
$passed = self::checkCondition($params, $condition);
|
||||
|
||||
if($passed === false)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a parameter by the given name.
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $name
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
private static function findParamByName($params, $name){
|
||||
|
||||
foreach($params as $param){
|
||||
$paramName = UniteFunctionsUC::getVal($param, "name");
|
||||
|
||||
if($paramName === $name){
|
||||
return $param;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parameter condition.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $condition
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function checkCondition($params, $condition){
|
||||
|
||||
if(empty($condition["attribute"]) === true)
|
||||
return true;
|
||||
|
||||
$conditionedParam = self::findParamByName($params, $condition["attribute"]);
|
||||
|
||||
if($conditionedParam === null)
|
||||
return false;
|
||||
|
||||
if(is_array($condition["value"]) === false)
|
||||
$condition["value"] = array($condition["value"]);
|
||||
|
||||
$conditionedValue = UniteFunctionsUC::getVal($conditionedParam, "value");
|
||||
|
||||
switch($condition["operator"]){
|
||||
case "equal":
|
||||
return in_array($conditionedValue, $condition["value"]);
|
||||
case "not_equal":
|
||||
return !in_array($conditionedValue, $condition["value"]);
|
||||
default:
|
||||
UniteFunctionsUC::throwError("Operator \"{$condition["operator"]}\" is not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
// advanced settings class. adds some advanced features
|
||||
class UniteServicesUC{
|
||||
|
||||
/**
|
||||
* include exchange rate api
|
||||
*/
|
||||
public function includeExchangeRateAPI(){
|
||||
|
||||
$pathAPI = GlobalsUC::$pathPlugin."inc_php/framework/exchangerate/includes.php";
|
||||
require_once($pathAPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* include google api
|
||||
*/
|
||||
public function includeGoogleAPI(){
|
||||
|
||||
$pathAPI = GlobalsUC::$pathPlugin."inc_php/framework/google/includes.php";
|
||||
require_once($pathAPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* include open weather api
|
||||
*/
|
||||
public function includeOpenWeatherAPI(){
|
||||
|
||||
$pathAPI = GlobalsUC::$pathPlugin."inc_php/framework/openweather/includes.php";
|
||||
require_once($pathAPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* include instagram api
|
||||
*/
|
||||
public function includeInstagramAPI(){
|
||||
|
||||
$pathAPI = GlobalsUC::$pathPlugin."inc_php/framework/instagram/include_insta_api.php";
|
||||
require_once($pathAPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* get instagram data array
|
||||
*/
|
||||
public function getInstagramSavedDataArray(){
|
||||
|
||||
$this->includeInstagramAPI();
|
||||
|
||||
$arrData = HelperInstaUC::getInstagramSavedAccessData();
|
||||
|
||||
return($arrData);
|
||||
}
|
||||
|
||||
/**
|
||||
* get instagram data
|
||||
*/
|
||||
public function getInstagramData($user, $maxItems = null, $isDebug = false){
|
||||
|
||||
$arrData = $this->getInstagramSavedDataArray();
|
||||
|
||||
$accessToken = UniteFunctionsUC::getVal($arrData, "access_token");
|
||||
|
||||
if(empty($accessToken))
|
||||
UniteFunctionsUC::throwError("Please connect instagram from general settings -> instagram");
|
||||
|
||||
$api = new InstagramAPIOfficialUC();
|
||||
|
||||
$response = $api->getItemsData($user,null,null,$maxItems);
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
// advanced settings class. adds some advanced features
|
||||
class UniteSettingsAdvancedUC extends UniteSettingsUC{
|
||||
|
||||
const TYPE_CONTENT = "content";
|
||||
|
||||
|
||||
/**
|
||||
* add boolean true/false select with custom names
|
||||
*/
|
||||
public function addSelect_boolean($name,$text,$bValue=true,$firstItem="Enable",$secondItem="Disable",$arrParams=array()){
|
||||
$arrItems = array($firstItem=>"true",$secondItem=>"false");
|
||||
$defaultText = "true";
|
||||
if($bValue == false)
|
||||
$defaultText = "false";
|
||||
|
||||
$this->addSelect($name,$arrItems,$text,$defaultText,$arrParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* add radio item boolean true / false
|
||||
*/
|
||||
public function addRadioBoolean($name, $text, $defaultValue = true, $trueText = "Yes", $falseText = "No", $params = array()){
|
||||
|
||||
$trueValue = UniteFunctionsUC::getVal($params, "true_value", true);
|
||||
$falseValue = UniteFunctionsUC::getVal($params, "false_value", false);
|
||||
$defaultItem = ($defaultValue === $trueValue) ? $trueValue : $falseValue;
|
||||
|
||||
$params["items"] = array($falseText => $falseValue, $trueText => $trueValue);
|
||||
|
||||
$this->add($name, $defaultItem, $text, self::TYPE_SWITCHER, $params);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add float select
|
||||
public function addSelect_float($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("left"=>"Left","right"=>"Right"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add align select
|
||||
public function addSelect_alignX($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("left"=>"Left","center"=>"Center","right"=>"Right"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add align select
|
||||
public function addSelect_alignY($name,$defaultValue,$text,$arrParams=array()){
|
||||
$this->addSelect($name,array("top"=>"Top","middle"=>"Middle","bottom"=>"Bottom"),$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select
|
||||
public function addSelect_border($name,$defaultValue,$text,$arrParams=array()){
|
||||
$arrItems = array();
|
||||
$arrItems["solid"] = "Solid";
|
||||
$arrItems["dashed"] = "Dashed";
|
||||
$arrItems["dotted"] = "Dotted";
|
||||
$arrItems["double"] = "Double";
|
||||
$arrItems["groove"] = "Groove";
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select
|
||||
public function addSelect_textDecoration($name,$defaultValue,$text,$arrParams=array()){
|
||||
$arrItems = array();
|
||||
$arrItems["none"] = "None";
|
||||
$arrItems["underline"] = "Underline";
|
||||
$arrItems["overline"] = "Overline";
|
||||
$arrItems["line-through"] = "Line-through";
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//add transitions select - arrExtensions may be string, and lower case
|
||||
public function addSelect_filescan($name,$path,$arrExtensions,$defaultValue,$text,$arrParams=array()){
|
||||
|
||||
if(getType($arrExtensions) == "string")
|
||||
$arrExtensions = array($arrExtensions);
|
||||
elseif(getType($arrExtensions) != "array")
|
||||
$this->throwError("The extensions array is not array and not string in setting: $name, please check.");
|
||||
|
||||
//make items array
|
||||
if(!is_dir($path))
|
||||
$this->throwError("path: $path not found");
|
||||
|
||||
$arrItems = array();
|
||||
$files = scandir($path);
|
||||
foreach($files as $file){
|
||||
//general filter
|
||||
if($file == ".." || $file == "." || $file == ".svn")
|
||||
continue;
|
||||
|
||||
$info = pathinfo($file);
|
||||
$ext = UniteFunctionsUC::getVal($info,"extension");
|
||||
$ext = strtolower($ext);
|
||||
|
||||
if(array_search($ext,$arrExtensions) === FALSE)
|
||||
continue;
|
||||
|
||||
$arrItems[$file] = $file;
|
||||
}
|
||||
|
||||
//handle add data array
|
||||
if(isset($arrParams["addData"])){
|
||||
foreach($arrParams["addData"] as $key=>$value)
|
||||
$arrItems[$key] = $value;
|
||||
}
|
||||
|
||||
if(empty($defaultValue) && !empty($arrItems))
|
||||
$defaultValue = current($arrItems);
|
||||
|
||||
$this->addSelect($name,$arrItems,$text,$defaultValue,$arrParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get transitions array
|
||||
*/
|
||||
private function getArrEasing(){
|
||||
|
||||
$arrItems = array();
|
||||
$arrItems["linear"] = "Linear";
|
||||
$arrItems["swing"] = "Swing";
|
||||
|
||||
$arrItems["easeOutQuad"] = "EaseOut - Quad";
|
||||
$arrItems["easeOutQuint"] = "EaseOut - Quint";
|
||||
$arrItems["easeOutBounce"] = "EaseOut - Bounce";
|
||||
$arrItems["easeOutElastic"] = "EaseOut - Elastic";
|
||||
$arrItems["easeOutBack"] = "EaseOut - Back";
|
||||
$arrItems["easeOutQuart"] = "EaseOut - Quart";
|
||||
$arrItems["easeOutExpo"] = "EaseOut - Expo";
|
||||
$arrItems["easeOutCubic"] = "EaseOut - Cubic";
|
||||
$arrItems["easeOutSine"] = "EaseOut - Sine";
|
||||
$arrItems["easeOutCirc"] = "EaseOut - Circ";
|
||||
|
||||
|
||||
$arrItems["easeInQuad"] = "EaseIn - Quad";
|
||||
$arrItems["easeInQuint"] = "EaseIn - Quint";
|
||||
$arrItems["easeInBounce"] = "EaseIn - Bounce";
|
||||
$arrItems["easeInElastic"] = "EaseIn - Elastic";
|
||||
$arrItems["easeInBack"] = "EaseIn - Back";
|
||||
$arrItems["easeInQuart"] = "EaseIn - Quart";
|
||||
$arrItems["easeInExpo"] = "EaseIn - Expo";
|
||||
$arrItems["easeInCubic"] = "EaseIn - Cubic";
|
||||
$arrItems["easeInSine"] = "EaseIn - Sine";
|
||||
$arrItems["easeInCirc"] = "EaseIn - Circ";
|
||||
|
||||
|
||||
$arrItems["easeInOutQuad"] = "EaseInOut - Quad";
|
||||
$arrItems["easeInQuint"] = "EaseInOut - Quint";
|
||||
$arrItems["easeInOutBounce"] = "EaseInOut - Bounce";
|
||||
$arrItems["easeInOutElastic"] = "EaseInOut - Elastic";
|
||||
$arrItems["easeInOutBack"] = "EaseInOut - Back";
|
||||
$arrItems["easeInOutQuart"] = "EaseInOut - Quart";
|
||||
$arrItems["easeInOutExpo"] = "EaseInOut - Expo";
|
||||
$arrItems["easeInOutCubic"] = "EaseInOut - Cubic";
|
||||
$arrItems["easeInOutSine"] = "EaseInOut - Sine";
|
||||
$arrItems["easeInOutCirc"] = "EaseInOut - Circ";
|
||||
|
||||
return($arrItems);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add transitions array item to some select
|
||||
*/
|
||||
public function updateSelectToEasing($name){
|
||||
|
||||
$arrItems = $this->getArrEasing();
|
||||
$this->updateSettingItems($name, $arrItems);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* add transitions array item to some select
|
||||
*/
|
||||
public function updateSelectToAlignHor($name, $default = null){
|
||||
|
||||
$arrItems = array(
|
||||
"left"=>__("Left","unlimited-elements-for-elementor"),
|
||||
"center"=>__("Center", "unlimited-elements-for-elementor"),
|
||||
"right"=>__("Right", "unlimited-elements-for-elementor")
|
||||
);
|
||||
|
||||
$this->updateSettingItems($name, $arrItems, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* add transitions array item to some select
|
||||
*/
|
||||
public function updateSelectToAlignVert($name, $default = null){
|
||||
|
||||
$arrItems = array(
|
||||
"top"=>__("Top","unlimited-elements-for-elementor"),
|
||||
"middle"=>__("Middle", "unlimited-elements-for-elementor"),
|
||||
"bottom"=>__("Bottom", "unlimited-elements-for-elementor")
|
||||
);
|
||||
|
||||
$this->updateSettingItems($name, $arrItems, $default);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add transitions array item to some select
|
||||
*/
|
||||
public function updateSelectToAlignCombo($name, $default = null){
|
||||
|
||||
$arrItems = array(
|
||||
"left"=>__("Left","unlimited-elements-for-elementor"),
|
||||
"center"=>__("Center", "unlimited-elements-for-elementor"),
|
||||
"right"=>__("Right", "unlimited-elements-for-elementor"),
|
||||
"top"=>__("Top","unlimited-elements-for-elementor"),
|
||||
"middle"=>__("Middle", "unlimited-elements-for-elementor"),
|
||||
"bottom"=>__("Bottom", "unlimited-elements-for-elementor")
|
||||
);
|
||||
|
||||
$this->updateSettingItems($name, $arrItems, $default);
|
||||
}
|
||||
|
||||
|
||||
private function a_CONTNET_SELECTOR(){}
|
||||
|
||||
|
||||
/**
|
||||
* add content selector fields, function for override
|
||||
*/
|
||||
protected function addContentSelectorField($option, $name, $arrDefaultValues){
|
||||
dmp("addContentSelectorFields: function for override");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add content selector options
|
||||
*/
|
||||
protected function addContentSelectorOptions($arrOptions, $name){
|
||||
dmp("addContentSelectorFields: function for override");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* add post picker
|
||||
*/
|
||||
public function addContentSelector($name, $defaultValue = "",$text = "",$arrParams = array()){
|
||||
|
||||
if(empty($defaultValue))
|
||||
$defaultValue = "custom";
|
||||
|
||||
//$this->add($name, $defaultValue, $text, self::TYPE_CONTENT, $arrParams);
|
||||
|
||||
$arrOptions = array();
|
||||
$arrOptions["Custom"] = "custom";
|
||||
|
||||
$arrOptions = $this->addContentSelectorOptions($arrOptions, $name);
|
||||
|
||||
|
||||
$radioValue = "custom";
|
||||
|
||||
if(is_array($defaultValue))
|
||||
$radioValue = UniteFunctionsUC::getVal($defaultValue, $name);
|
||||
|
||||
$this->addRadio($name, $arrOptions, "<b>".$text."<b>", $radioValue);
|
||||
|
||||
//add fields
|
||||
foreach($arrOptions as $text=>$option){
|
||||
|
||||
$this->startBulkControl($name, self::CONTROL_TYPE_SHOW, $option);
|
||||
|
||||
switch($option){
|
||||
case "custom":
|
||||
|
||||
/*
|
||||
$params = array(
|
||||
UniteSettingsUC::PARAM_CLASSADD=>"unite-content-title");
|
||||
|
||||
$this->addTextBox($name."_title", "", __(" Title","unlimited-elements-for-elementor"), $params);
|
||||
|
||||
$params = array(
|
||||
UniteSettingsUC::PARAM_CLASSADD=>"unite-content-intro");
|
||||
|
||||
$this->addTextArea($name."_intro", "", __(" Custom Intro","unlimited-elements-for-elementor"), $params);
|
||||
*/
|
||||
|
||||
$params = array(
|
||||
UniteSettingsUC::PARAM_CLASSADD=>"unite-content-content");
|
||||
|
||||
if(is_string($defaultValue))
|
||||
$value = $defaultValue;
|
||||
else
|
||||
$value = UniteFunctionsUC::getVal($defaultValue, $name."_content");
|
||||
|
||||
$this->addEditor($name."_content", $value, __(" Custom Content","unlimited-elements-for-elementor"), $params);
|
||||
|
||||
/*
|
||||
$params = array(
|
||||
UniteSettingsUC::PARAM_CLASSADD=>"unite-content-link");
|
||||
|
||||
$this->addTextBox($name."_link", "", __(" Link","unlimited-elements-for-elementor"), $params);
|
||||
*/
|
||||
|
||||
break;
|
||||
default:
|
||||
$this->addContentSelectorField($option, $name, $defaultValue);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->endBulkControl();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteSettingsOutputInlineUC extends UniteCreatorSettingsOutput{
|
||||
|
||||
|
||||
/**
|
||||
* constuct function
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->isParent = true;
|
||||
self::$serial++;
|
||||
$this->wrapperID = "unite_settings_wide_output_".self::$serial;
|
||||
$this->settingsMainClass = "unite-settings-inline";
|
||||
$this->showDescAsTips = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw settings row
|
||||
* @param $setting
|
||||
*/
|
||||
protected function drawSettingRow($setting, $mode=""){
|
||||
|
||||
//set cellstyle:
|
||||
$cellStyle = "";
|
||||
if(isset($setting[UniteSettingsUC::PARAM_CELLSTYLE])){
|
||||
$cellStyle .= $setting[UniteSettingsUC::PARAM_CELLSTYLE];
|
||||
}
|
||||
|
||||
if($cellStyle != "")
|
||||
$cellStyle = "style='".$cellStyle."'";
|
||||
|
||||
$textStyle = $this->drawSettingRow_getTextStyle($setting);
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting, "unite-setting-row");
|
||||
|
||||
$text = $this->drawSettingRow_getText($setting);
|
||||
|
||||
$description = UniteFunctionsUC::getVal($setting,"description");
|
||||
|
||||
$addField = UniteFunctionsUC::getVal($setting, UniteSettingsUC::PARAM_ADDFIELD);
|
||||
|
||||
?>
|
||||
|
||||
<div id="<?php echo esc_attr($setting["id_row"])?>" <?php echo UniteProviderFunctionsUC::escAddParam($rowClass)?>>
|
||||
|
||||
<div class="unite-setting-text" <?php echo UniteProviderFunctionsUC::escAddParam($textStyle)?> >
|
||||
<?php if($this->showDescAsTips == true): ?>
|
||||
<span class='setting_text' title="<?php echo esc_attr($description)?>"><?php echo $text?></span>
|
||||
<?php else:?>
|
||||
<?php echo $text?>
|
||||
<?php endif?>
|
||||
</div>
|
||||
<div class="unite-setting-content" <?php echo UniteProviderFunctionsUC::escAddParam($cellStyle)?>>
|
||||
<?php
|
||||
$this->drawInputs($setting);
|
||||
$this->drawInputAdditions($setting);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw wrapper end after settings
|
||||
*/
|
||||
protected function drawSettingsAfter(){
|
||||
|
||||
?><div class="unite-clear"></div><?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteSettingsOutputSidebarUC extends UniteCreatorSettingsOutput{
|
||||
|
||||
private $showSapTitle = true;
|
||||
private $isAccordion = true;
|
||||
private $accordionItemsSpaceBetween = 0;//space between accordion items
|
||||
|
||||
/**
|
||||
* constuct function
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
self::$serial++;
|
||||
|
||||
$this->isSidebar = true;
|
||||
$this->isParent = true;
|
||||
$this->wrapperID = "unite_settings_sidebar_output_" . self::$serial;
|
||||
$this->settingsMainClass = "unite-settings-sidebar";
|
||||
$this->showDescAsTips = false;
|
||||
|
||||
$this->setShowSaps(true, self::SAPS_TYPE_ACCORDION);
|
||||
}
|
||||
|
||||
/**
|
||||
* draw before settings row
|
||||
*/
|
||||
protected function drawSettings_before(){
|
||||
|
||||
parent::drawSettings_before();
|
||||
|
||||
?>
|
||||
<ul class="unite-list-settings">
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw wrapper end after settings
|
||||
*/
|
||||
protected function drawSettingsAfter(){
|
||||
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
|
||||
parent::drawSettingsAfter();
|
||||
}
|
||||
|
||||
/**
|
||||
* get options override (add accordion space)
|
||||
*/
|
||||
protected function getOptions(){
|
||||
|
||||
$arrOptions = parent::getOptions();
|
||||
$arrOptions["accordion_sap"] = $this->accordionItemsSpaceBetween;
|
||||
|
||||
return $arrOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* set draw options before draw
|
||||
*/
|
||||
protected function setDrawOptions(){
|
||||
|
||||
$numSaps = $this->settings->getNumSaps();
|
||||
|
||||
if($numSaps <= 1)
|
||||
$this->showSapTitle = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* draw responsive picker
|
||||
*/
|
||||
private function drawResponsivePicker($selectedType){
|
||||
|
||||
$devices = array(
|
||||
"desktop" => array(
|
||||
"title" => __("Desktop", "unlimited-elements-for-elementor"),
|
||||
"icon" => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 10"><path d="M3.5 10.5h5M6 7.5v3M11.5.5H.5v7h11v-7Z" /></svg>',
|
||||
),
|
||||
"tablet" => array(
|
||||
"title" => __("Tablet", "unlimited-elements-for-elementor"),
|
||||
"icon" => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 12"><path d="M2.5 9.5h5M8.5.5h-7a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1Z" /></svg>',
|
||||
),
|
||||
"mobile" => array(
|
||||
"title" => __("Mobile", "unlimited-elements-for-elementor"),
|
||||
"icon" => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 8 12"><path d="M2.5 9.5h3M6.5.5h-5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-9a1 1 0 0 0-1-1Z" /></svg>',
|
||||
),
|
||||
);
|
||||
|
||||
?>
|
||||
<select class="unite-responsive-picker">
|
||||
<?php foreach($devices as $type => $device): ?>
|
||||
<option
|
||||
value="<?php esc_attr_e($type); ?>"
|
||||
data-content="<?php esc_attr_e('<div class="unite-responsive-picker-item uc-tip" title="' . esc_attr($device["title"]) . '" data-tipsy-gravity="w">' . $device["icon"] . '</div>'); ?>"
|
||||
<?php echo $type === $selectedType ? "selected" : ""; ?>
|
||||
>
|
||||
<?php esc_html_e($device["title"]); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw settings row
|
||||
*/
|
||||
protected function drawSettingRow($setting, $mode = ""){
|
||||
|
||||
$addAttr = "";
|
||||
$baseClass = "unite-setting-row";
|
||||
|
||||
$id = UniteFunctionsUC::getVal($setting, "id");
|
||||
$type = UniteFunctionsUC::getVal($setting, "type");
|
||||
$text = UniteFunctionsUC::getVal($setting, "text");
|
||||
$description = UniteFunctionsUC::getVal($setting, "description");
|
||||
|
||||
$toDrawText = true;
|
||||
|
||||
$attribsText = UniteFunctionsUC::getVal($setting, "attrib_text");
|
||||
if(empty($attribsText) && empty($text))
|
||||
$toDrawText = false;
|
||||
|
||||
$labelBlock = UniteFunctionsUC::getVal($setting, "label_block");
|
||||
$labelBlock = UniteFunctionsUC::strToBool($labelBlock);
|
||||
|
||||
if($labelBlock === false)
|
||||
$baseClass .= " unite-inline-setting";
|
||||
|
||||
$isResponsive = UniteFunctionsUC::getVal($setting, "is_responsive");
|
||||
$isResponsive = UniteFunctionsUC::strToBool($isResponsive);
|
||||
$responsiveId = UniteFunctionsUC::getVal($setting, "responsive_id");
|
||||
$responsiveType = UniteFunctionsUC::getVal($setting, "responsive_type");
|
||||
|
||||
if($isResponsive === true)
|
||||
$addAttr .= " data-responsive-id=\"$responsiveId\" data-responsive-type=\"$responsiveType\"";
|
||||
|
||||
$tabsId = UniteFunctionsUC::getVal($setting, "tabs_id");
|
||||
$tabsValue = UniteFunctionsUC::getVal($setting, "tabs_value");
|
||||
|
||||
if (empty($tabsId) === false && empty($tabsValue) === false)
|
||||
$addAttr .= " data-tabs-id=\"$tabsId\" data-tabs-value=\"$tabsValue\"";
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting, $baseClass);
|
||||
|
||||
?>
|
||||
<li
|
||||
id="<?php esc_attr_e($id); ?>_row"
|
||||
<?php echo UniteProviderFunctionsUC::escAddParam($rowClass); ?>
|
||||
<?php echo UniteProviderFunctionsUC::escAddParam($addAttr); ?>
|
||||
data-type="<?php esc_attr_e($type); ?>"
|
||||
>
|
||||
|
||||
<div class="unite-setting-field">
|
||||
|
||||
<?php if($toDrawText === true): ?>
|
||||
<div class="unite-setting-text-wrapper">
|
||||
<div id="<?php echo esc_attr($id); ?>_text" class='unite-setting-text' <?php echo UniteProviderFunctionsUC::escAddParam($attribsText); ?>>
|
||||
<?php echo esc_html($text); ?>
|
||||
</div>
|
||||
<?php if($isResponsive === true): ?>
|
||||
<?php $this->drawResponsivePicker($responsiveType); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if(!empty($addHtmlBefore)): ?>
|
||||
<div class="unite-setting-addhtmlbefore"><?php echo UniteProviderFunctionsUC::escAddParam($addHtmlBefore); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="unite-setting-input">
|
||||
<?php $this->drawInputs($setting); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php if(!empty($description)): ?>
|
||||
<div class="unite-setting-helper">
|
||||
<?php echo $description; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw text row
|
||||
*/
|
||||
protected function drawTextRow($setting){
|
||||
|
||||
$id = UniteFunctionsUC::getVal($setting, "id");
|
||||
$label = UniteFunctionsUC::getVal($setting, "label");
|
||||
$text = UniteFunctionsUC::getVal($setting, "text");
|
||||
$classAdd = UniteFunctionsUC::getVal($setting, UniteSettingsUC::PARAM_CLASSADD);
|
||||
$isHeading = UniteFunctionsUC::getVal($setting, "is_heading");
|
||||
$isHeading = UniteFunctionsUC::strToBool($isHeading);
|
||||
|
||||
if($isHeading === true)
|
||||
$classAdd .= " unite-settings-static-text__heading";
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting);
|
||||
|
||||
?>
|
||||
<li id="<?php esc_attr_e($id) ?>_row" <?php echo UniteProviderFunctionsUC::escAddParam($rowClass); ?>>
|
||||
|
||||
<?php if(empty($label) === false): ?>
|
||||
<span class="unite-settings-text-label">
|
||||
<?php esc_html_e($label) ?>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
|
||||
<span class="unite-settings-static-text<?php esc_attr_e($classAdd); ?>">
|
||||
<?php esc_html_e($text); ?>
|
||||
</span>
|
||||
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw sap before override
|
||||
*/
|
||||
protected function drawSapBefore($sap, $key){
|
||||
|
||||
$tab = UniteFunctionsUC::getVal($sap, "tab");
|
||||
$name = UniteFunctionsUC::getVal($sap, "name");
|
||||
$text = UniteFunctionsUC::getVal($sap, "text");
|
||||
//$classIcon = UniteFunctionsUC::getVal($sap, "icon");
|
||||
$classIcon = null; // disable icon for now
|
||||
$isHidden = UniteFunctionsUC::getVal($sap, "hidden");
|
||||
$isHidden = UniteFunctionsUC::strToBool($isHidden);
|
||||
|
||||
if(empty($tab) === true)
|
||||
$tab = UniteSettingsUC::TAB_CONTENT;
|
||||
|
||||
if(empty($name) === true)
|
||||
$name = "unnamed_" . UniteFunctionsUC::getRandomString();
|
||||
|
||||
$class = "unite-postbox";
|
||||
|
||||
if(empty($this->addClass) === false)
|
||||
$class .= " " . $this->addClass;
|
||||
|
||||
if($this->isAccordion === false)
|
||||
$class .= " unite-no-accordion";
|
||||
|
||||
if($isHidden === true)
|
||||
$class .= " unite-setting-hidden";
|
||||
|
||||
$id = $this->idPrefix . "ucsap_" . $name;
|
||||
|
||||
|
||||
?>
|
||||
<div
|
||||
id="<?php esc_attr_e($id) ?>"
|
||||
class="<?php esc_attr_e($class); ?>"
|
||||
data-tab="<?php esc_attr_e($tab); ?>"
|
||||
>
|
||||
|
||||
<?php if($this->showSapTitle === true): ?>
|
||||
<div class="unite-postbox-title">
|
||||
|
||||
<?php if(empty($classIcon) === false): ?>
|
||||
<i class="unite-postbox-icon <?php esc_attr_e($classIcon); ?>"></i>
|
||||
<?php endif; ?>
|
||||
|
||||
<span><?php esc_html_e($text); ?></span>
|
||||
|
||||
<?php if($this->isAccordion === true): ?>
|
||||
<div class="unite-postbox-arrow"></div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="unite-postbox-inside">
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw sap after
|
||||
*/
|
||||
protected function drawSapAfter(){
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* draw hr row
|
||||
*/
|
||||
protected function drawHrRow($setting){
|
||||
|
||||
$id = UniteFunctionsUC::getVal($setting, "id");
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting);
|
||||
|
||||
?>
|
||||
<li id="<?php esc_attr_e($id) ?>_row" <?php echo UniteProviderFunctionsUC::escAddParam($rowClass) ?>>
|
||||
<hr id="<?php esc_attr_e($id) ?>">
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteSettingsOutputWideUC extends UniteCreatorSettingsOutput{
|
||||
|
||||
|
||||
/**
|
||||
* constuct function
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->isParent = true;
|
||||
self::$serial++;
|
||||
$this->wrapperID = "unite_settings_wide_output_".self::$serial;
|
||||
$this->settingsMainClass = "unite_settings_wide";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw settings row
|
||||
* @param $setting
|
||||
* modes: single_editor (only 1 setting, editor type)
|
||||
*/
|
||||
protected function drawSettingRow($setting, $mode = ""){
|
||||
|
||||
//set cellstyle:
|
||||
$cellStyle = "";
|
||||
if(isset($setting[UniteSettingsUC::PARAM_CELLSTYLE])){
|
||||
$cellStyle .= $setting[UniteSettingsUC::PARAM_CELLSTYLE];
|
||||
}
|
||||
|
||||
if($cellStyle != "")
|
||||
$cellStyle = "style='".$cellStyle."'";
|
||||
|
||||
$textStyle = $this->drawSettingRow_getTextStyle($setting);
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting);
|
||||
|
||||
$text = $this->drawSettingRow_getText($setting);
|
||||
|
||||
$description = UniteFunctionsUC::getVal($setting,"description");
|
||||
|
||||
|
||||
//set settings text width:
|
||||
$textWidth = "";
|
||||
if(isset($setting["textWidth"]))
|
||||
$textWidth = 'width="'.$setting["textWidth"].'"';
|
||||
|
||||
$addField = UniteFunctionsUC::getVal($setting, UniteSettingsUC::PARAM_ADDFIELD);
|
||||
|
||||
$drawTh = true;
|
||||
$tdHtmlAdd = "";
|
||||
if($mode == "single_editor")
|
||||
$drawTh = false;
|
||||
|
||||
if(empty($text))
|
||||
$drawTh = false;
|
||||
|
||||
if($drawTh == false)
|
||||
$tdHtmlAdd = " colspan=2";
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
if(!empty($addField)):
|
||||
|
||||
$addSetting = $this->settings->getSettingByName($addField);
|
||||
UniteFunctionsUC::validateNotEmpty($addSetting,"AddSetting {$addField}");
|
||||
|
||||
$addSettingText = UniteFunctionsUC::getVal($addSetting,"text","");
|
||||
$addSettingText = str_replace(" "," ", $addSettingText);
|
||||
$tdSettingAdd = "";
|
||||
if(!empty($addSetting)){
|
||||
$tdSettingAdd = ' class="unite-settings-onecell" colspan="2"';
|
||||
}
|
||||
|
||||
?>
|
||||
<tr <?php echo UniteProviderFunctionsUC::escAddParam($rowClass)?> valign="top">
|
||||
|
||||
<?php if(empty($addSettingText)):?>
|
||||
|
||||
<th <?php echo UniteProviderFunctionsUC::escAddParam($textStyle)?> scope="row" <?php echo UniteProviderFunctionsUC::escAddParam($textWidth) ?>>
|
||||
<?php if($this->showDescAsTips == true): ?>
|
||||
<span class='setting_text' title="<?php echo esc_attr($description)?>"><?php echo $text?></span>
|
||||
<?php else:?>
|
||||
<?php echo $text?>
|
||||
<?php endif?>
|
||||
</th>
|
||||
|
||||
<?php endif?>
|
||||
|
||||
<td <?php echo UniteProviderFunctionsUC::escAddParam($cellStyle)?> <?php echo UniteProviderFunctionsUC::escAddParam($tdSettingAdd)?>>
|
||||
|
||||
<span id="<?php echo UniteProviderFunctionsUC::escAddParam($setting["id_row"])?>">
|
||||
|
||||
<?php if(!empty($addSettingText)):?>
|
||||
<span class='setting_onecell_text'><?php echo esc_html($text)?></span>
|
||||
<?php endif?>
|
||||
|
||||
<?php
|
||||
$this->drawInputs($setting);
|
||||
$this->drawInputAdditions($setting);
|
||||
?>
|
||||
|
||||
<?php if(!empty($addSettingText)):?>
|
||||
<span class="setting_onecell_horsap"></span>
|
||||
<?php endif?>
|
||||
</span>
|
||||
|
||||
<span id="<?php echo esc_attr($addSetting["id_row"])?>">
|
||||
<span class='setting_onecell_text'><?php echo esc_html($addSettingText)?></span>
|
||||
<?php
|
||||
$this->drawInputs($addSetting);
|
||||
$this->drawInputAdditions($addSetting);
|
||||
?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
?>
|
||||
<?php else: ?>
|
||||
<tr id="<?php echo esc_attr($setting["id_row"])?>" <?php echo UniteProviderFunctionsUC::escAddParam($rowClass)?> valign="top">
|
||||
|
||||
<?php if($drawTh == true):?>
|
||||
|
||||
<th <?php echo UniteProviderFunctionsUC::escAddParam($textStyle)?> scope="row" <?php echo UniteProviderFunctionsUC::escAddParam($textWidth) ?>>
|
||||
<?php if($this->showDescAsTips == true): ?>
|
||||
<span class='setting_text' title="<?php echo esc_attr($description)?>"><?php echo $text?></span>
|
||||
<?php else:?>
|
||||
<?php echo $text?>
|
||||
<?php endif?>
|
||||
</th>
|
||||
|
||||
<?php endif?>
|
||||
|
||||
<td <?php echo UniteProviderFunctionsUC::escAddParam($cellStyle)?> <?php echo UniteProviderFunctionsUC::escAddParam($tdHtmlAdd)?>>
|
||||
<?php
|
||||
$this->drawInputs($setting);
|
||||
$this->drawInputAdditions($setting);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* draw hr row
|
||||
* @param $setting
|
||||
*/
|
||||
protected function drawHrRow($setting){
|
||||
|
||||
//set hidden
|
||||
|
||||
$class = UniteFunctionsUC::getVal($setting, "class");
|
||||
|
||||
$classHidden = $this->drawSettingRow_getRowHiddenClass($setting);
|
||||
if(!empty($classHidden)){
|
||||
|
||||
if(!empty($class))
|
||||
$class .= " ";
|
||||
|
||||
$class .= $classHidden;
|
||||
}
|
||||
|
||||
if(!empty($class)){
|
||||
$class = esc_attr($class);
|
||||
$class = "class='$class'";
|
||||
}
|
||||
|
||||
?>
|
||||
<tr id="<?php echo esc_attr($setting["id_row"])?>">
|
||||
<td colspan="4" align="left" style="text-align:left;">
|
||||
<hr <?php echo UniteProviderFunctionsUC::escAddParam($class); ?> />
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* draw text row
|
||||
* @param unknown_type $setting
|
||||
*/
|
||||
protected function drawTextRow($setting){
|
||||
|
||||
//set cell style
|
||||
$cellStyle = "";
|
||||
if(isset($setting["padding"]))
|
||||
$cellStyle .= "padding-left:".$setting["padding"].";";
|
||||
|
||||
if(!empty($cellStyle))
|
||||
$cellStyle="style='$cellStyle'";
|
||||
|
||||
//set style
|
||||
|
||||
$tdHtmlAdd = 'colspan="2"';
|
||||
|
||||
$label = UniteFunctionsUC::getVal($setting, "label");
|
||||
if(!empty($label))
|
||||
$tdHtmlAdd = "";
|
||||
|
||||
$rowClass = $this->drawSettingRow_getRowClass($setting);
|
||||
|
||||
$classAdd = UniteFunctionsUC::getVal($setting, UniteSettingsUC::PARAM_CLASSADD);
|
||||
|
||||
if(!empty($classAdd))
|
||||
$classAdd = " ".$classAdd;
|
||||
|
||||
?>
|
||||
<tr id="<?php echo esc_attr($setting["id_row"])?>" <?php echo UniteProviderFunctionsUC::escAddParam($rowClass)?> valign="top">
|
||||
<?php if(!empty($label)):?>
|
||||
<th>
|
||||
<?php echo $label?>
|
||||
</th>
|
||||
<?php endif?>
|
||||
<td <?php echo UniteProviderFunctionsUC::escAddParam($tdHtmlAdd)?> <?php echo UniteProviderFunctionsUC::escAddParam($cellStyle)?>>
|
||||
<span class="unite-settings-static-text<?php echo esc_attr($classAdd)?>"><?php echo $setting["text"]?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw wrapper before settings
|
||||
*/
|
||||
protected function drawSettings_before(){
|
||||
?><table class='unite_table_settings_wide'><?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* draw wrapper end after settings
|
||||
*/
|
||||
protected function drawSettingsAfter(){
|
||||
|
||||
?></table><?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteShapeManagerUC extends HtmlOutputBaseUC{
|
||||
|
||||
private static $arrShapeDividersCache = array();
|
||||
private static $arrShapesCache = array();
|
||||
|
||||
|
||||
/**
|
||||
* get output shapes by type
|
||||
*/
|
||||
private function getShapesOutputByType($arrAddons, $getType){
|
||||
|
||||
$arrOutput = array();
|
||||
|
||||
foreach($arrAddons as $addon){
|
||||
|
||||
$alias = $addon->getAlias();
|
||||
|
||||
switch($getType){
|
||||
case "picker":
|
||||
$title = $addon->getTitle();
|
||||
$arrOutput[$alias] = $title;
|
||||
break;
|
||||
case "short":
|
||||
$title = $addon->getTitle();
|
||||
$arrOutput[$title] = $alias;
|
||||
break;
|
||||
case "data":
|
||||
$svgContent = $addon->getHtml();
|
||||
$svgEncoded = base64_encode($svgContent);
|
||||
|
||||
$arrOutput[$alias] = $svgEncoded;
|
||||
break;
|
||||
case "bgurl":
|
||||
$svgContent = $addon->getHtml();
|
||||
$svgEncoded = UniteFunctionsUC::encodeSVGForBGUrl($svgContent);
|
||||
|
||||
$arrOutput[$alias] = $svgEncoded;
|
||||
break;
|
||||
case "svg":
|
||||
$svgContent = $addon->getHtml();
|
||||
$arrOutput[$alias] = $svgContent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return($arrOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* get shape deviders array
|
||||
* getType - short / html
|
||||
*/
|
||||
public function getArrShapeDividers($getType = null){
|
||||
|
||||
if(empty(self::$arrShapeDividersCache)){
|
||||
$objAddons = new UniteCreatorAddons();
|
||||
$params = array();
|
||||
$params["addontype"] = GlobalsUC::ADDON_TYPE_SHAPE_DEVIDER;
|
||||
|
||||
self::$arrShapeDividersCache = $objAddons->getArrAddons("", $params);
|
||||
}
|
||||
|
||||
if(empty($getType))
|
||||
return(self::$arrShapeDividersCache);
|
||||
|
||||
$arrOutput = $this->getShapesOutputByType(self::$arrShapeDividersCache, $getType);
|
||||
|
||||
|
||||
return($arrOutput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get shape deviders array
|
||||
* getType - short / html
|
||||
*/
|
||||
public function getArrShapes($getType = null){
|
||||
|
||||
if(empty(self::$arrShapesCache)){
|
||||
$objAddons = new UniteCreatorAddons();
|
||||
$params = array();
|
||||
$params["addontype"] = GlobalsUC::ADDON_TYPE_SHAPES;
|
||||
|
||||
self::$arrShapesCache = $objAddons->getArrAddons("", $params);
|
||||
}
|
||||
|
||||
if(empty($getType))
|
||||
return(self::$arrShapesCache);
|
||||
|
||||
$arrOutput = self::getShapesOutputByType(self::$arrShapesCache, $getType);
|
||||
|
||||
return($arrOutput);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get element shape evider html
|
||||
*/
|
||||
private function getElementShapeDividerHtml($position, $settings, $elementID){
|
||||
|
||||
$enableKey = "enable_shape_devider_".$position;
|
||||
|
||||
if(isset($settings[$enableKey])){
|
||||
$isEnable = UniteFunctionsUC::getVal($settings, "enable_shape_devider_".$position);
|
||||
$isEnable = UniteFunctionsUC::strToBool($isEnable);
|
||||
|
||||
if($isEnable == false)
|
||||
return("");
|
||||
}
|
||||
|
||||
$shapeType = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_type");
|
||||
|
||||
if(empty($shapeType))
|
||||
return("");
|
||||
|
||||
$class = "uc-shape-devider-{$position}";
|
||||
$selector = "#{$elementID} > .{$class}";
|
||||
|
||||
$shapeColor = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_color");
|
||||
$isflip = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_flip");
|
||||
$isflip = UniteFunctionsUC::strToBool($isflip);
|
||||
$height = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_height");
|
||||
$placement = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_placement");
|
||||
$repeat = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_repeat");
|
||||
|
||||
|
||||
$arrShapes = self::getArrShapeDividers("svg");
|
||||
$shapeSVG = UniteFunctionsUC::getVal($arrShapes, $shapeType);
|
||||
|
||||
if(empty($shapeSVG))
|
||||
return("");
|
||||
|
||||
//replace color
|
||||
if(!empty($shapeColor)){
|
||||
$shapeSVG = str_replace('g fill="#ffffff"', 'g fill="'.$shapeColor.'"', $shapeSVG);
|
||||
}
|
||||
|
||||
$shapeContent = UniteFunctionsUC::encodeSVGForBGUrl($shapeSVG);
|
||||
|
||||
$arrCss = array();
|
||||
$arrCss["background-image"] = "url('{$shapeContent}')";
|
||||
|
||||
//add rotation
|
||||
$rotation = "";
|
||||
|
||||
if($isflip == true){
|
||||
if($position == "top")
|
||||
$arrCss["transform"] = "rotateY(180deg)";
|
||||
else
|
||||
$arrCss["transform"] = "rotateX(180deg) rotateY(180deg)";
|
||||
}
|
||||
|
||||
//set repeat
|
||||
$percentRepeat = 100;
|
||||
|
||||
if(is_numeric($repeat)){
|
||||
if($repeat <= 0)
|
||||
$repeat = 1;
|
||||
|
||||
if($repeat > 1)
|
||||
$percentRepeat = 100 / $repeat;
|
||||
|
||||
$decimal = $percentRepeat - (int)$percentRepeat;
|
||||
if($decimal > 0)
|
||||
$percentRepeat = number_format($percentRepeat, 2);
|
||||
}
|
||||
|
||||
if(!empty($height)){
|
||||
$height = UniteFunctionsUC::normalizeSize($height);
|
||||
$arrCss["height"] = $height;
|
||||
$arrCss["background-size"] = $percentRepeat."% ".$height;
|
||||
}
|
||||
|
||||
|
||||
//get mobile size css
|
||||
$arrCssSizes = array();
|
||||
foreach(GlobalsUC::$arrSizes as $size){
|
||||
|
||||
$settingName = "shape_devider_{$position}_height_$size";
|
||||
|
||||
$heightSize = UniteFunctionsUC::getVal($settings, $settingName);
|
||||
$arrCssSize = array();
|
||||
|
||||
if(empty($heightSize))
|
||||
continue;
|
||||
|
||||
$heightSize = UniteFunctionsUC::normalizeSize($heightSize);
|
||||
$arrCssSize["height"] = $heightSize;
|
||||
$arrCssSize["background-size"] = $percentRepeat."% ".$heightSize;
|
||||
|
||||
$cssSize = UniteFunctionsUC::arrStyleToStrStyle($arrCssSize, $selector);
|
||||
|
||||
$arrCssSizes[$size] = $cssSize;
|
||||
}
|
||||
|
||||
|
||||
if($placement == "beneath"){
|
||||
$arrCss["z-index"] = "0";
|
||||
}
|
||||
|
||||
|
||||
//--- output
|
||||
|
||||
$css = UniteFunctionsUC::arrStyleToStrStyle($arrCss, $selector);
|
||||
|
||||
HelperUC::putInlineStyle(self::BR2.$css);
|
||||
|
||||
//put mobile size css
|
||||
if(!empty($arrCssSizes)){
|
||||
$cssMobileSize = HelperUC::getCssMobileSize($arrCssSizes);
|
||||
HelperUC::putInlineStyle(self::BR2.$cssMobileSize);
|
||||
}
|
||||
|
||||
$html = "";
|
||||
|
||||
$class = esc_attr($class);
|
||||
|
||||
$html .= "<div class='uc-shape-devider {$class}'></div> \n";
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get shpae devider addons from grid settings
|
||||
*/
|
||||
public function getShapeDividerNameFromSettings($settings, $position){
|
||||
|
||||
//preserve old way
|
||||
$enableKey = "enable_shape_devider_".$position;
|
||||
|
||||
if(isset($settings[$enableKey])){
|
||||
$isEnable = $settings[$enableKey];
|
||||
$isEnable = UniteFunctionsUC::strToBool($isEnable);
|
||||
|
||||
if($isEnable == false)
|
||||
return(null);
|
||||
}
|
||||
|
||||
$shapeType = UniteFunctionsUC::getVal($settings, "shape_devider_{$position}_type");
|
||||
|
||||
if(empty($shapeType))
|
||||
return(null);
|
||||
|
||||
return($shapeType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get element shape deviders
|
||||
*/
|
||||
public function getElementShapeDividersHtml($settings, $elementID){
|
||||
|
||||
$html = "";
|
||||
$html .= self::getElementShapeDividerHtml("top", $settings, $elementID);
|
||||
$html .= self::getElementShapeDividerHtml("bottom", $settings, $elementID);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* output shapes css
|
||||
*/
|
||||
public function outputCssShapes(){
|
||||
|
||||
header("Content-type: text/css");
|
||||
|
||||
$arrShapes = self::getArrShapes("bgurl");
|
||||
$css = "";
|
||||
foreach($arrShapes as $name=>$urlShape)
|
||||
$css .= ".unite-shapecontent-{$name}{background-image:url({$urlShape})}".self::BR2;
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($css);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get json shapes array for the picker
|
||||
*/
|
||||
public function getJsonShapes(){
|
||||
|
||||
try{
|
||||
|
||||
$arrShapes = $this->getArrShapes("picker");
|
||||
|
||||
}catch(Exception $e){
|
||||
|
||||
$arrShapes = array();
|
||||
}
|
||||
|
||||
$jsonShapes = json_encode($arrShapes);
|
||||
|
||||
return($jsonShapes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get shape svg content
|
||||
*/
|
||||
public function getShapeSVGContent($shapeName){
|
||||
|
||||
try{
|
||||
|
||||
$addon = new UniteCreatorAddon();
|
||||
$addon->initByAlias($shapeName, GlobalsUC::ADDON_TYPE_SHAPES);
|
||||
|
||||
$svgContent = $addon->getHtml();
|
||||
|
||||
return($svgContent);
|
||||
|
||||
}catch(Exception $e){
|
||||
|
||||
return($shapeName." not found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get shape content by id
|
||||
*/
|
||||
public function getShapeBGContentBYAddonID($addonID){
|
||||
|
||||
$objAddon = new UniteCreatorAddon();
|
||||
$objAddon->initByID($addonID);
|
||||
|
||||
$objAddonType = $objAddon->getObjAddonType();
|
||||
|
||||
if($objAddonType->isSVG == false)
|
||||
UniteFunctionsUC::throwError("The addon is not svg");
|
||||
|
||||
$svgContent = $objAddon->getHtml();
|
||||
$encodedContent = base64_encode($svgContent);
|
||||
|
||||
return($encodedContent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get devider content by data
|
||||
*/
|
||||
public static function getShapeDividerBGContentByData($data){
|
||||
|
||||
$name = UniteFunctionsUC::getVal($data, "name");
|
||||
$SVGcontent = $this->getShapeSVGContent($name);
|
||||
$encodedContent = UniteFunctionsUC::encodeSVGForBGUrl($SVGcontent);
|
||||
|
||||
$response = array();
|
||||
$response["content"] = $encodedContent;
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,639 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* outputs all related to table with paging
|
||||
*
|
||||
*/
|
||||
class UniteTableUC extends HtmlOutputBaseUC{
|
||||
|
||||
const GET_FIELD_PAGE = "table_page";
|
||||
const GET_FIELD_INPAGE = "table_inpage";
|
||||
const GET_FIELD_SEARCH = "table_search";
|
||||
const GET_FIELD_CATEGORY = "table_category";
|
||||
const GET_FIELD_ORDER = "table_order";
|
||||
const GET_FIELD_ORDER_DIR = "table_order_dir";
|
||||
|
||||
const GET_FIELD_OPTION = "option";
|
||||
const GET_FIELD_VIEW = "view";
|
||||
|
||||
private $isPaging = false;
|
||||
private $isInsideTopActions = false;
|
||||
|
||||
private $defaultOrderby;
|
||||
private $page;
|
||||
private $inPage;
|
||||
private $total;
|
||||
private $numPages;
|
||||
private $baseUrl;
|
||||
private $arrOrderFields;
|
||||
|
||||
private $defaultInPage = 10;
|
||||
|
||||
|
||||
/**
|
||||
* validate that the paging is inited
|
||||
*/
|
||||
private function validatePaging(){
|
||||
|
||||
if($this->isPaging == false)
|
||||
UniteFunctionsUC::throwError("The paging should be available");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* validate that it's inside top actions
|
||||
*/
|
||||
private function validateTopActions(){
|
||||
|
||||
if($this->isInsideTopActions == false)
|
||||
UniteFunctionsUC::throwError("The top actions form should be started");
|
||||
|
||||
}
|
||||
|
||||
private function a_GETTERS(){}
|
||||
|
||||
|
||||
/**
|
||||
* get page from get
|
||||
*/
|
||||
private function getPageFromGet(){
|
||||
|
||||
$page = UniteFunctionsUC::getGetVar(self::GET_FIELD_PAGE,1,UniteFunctionsUC::SANITIZE_ID);
|
||||
$page = (int)$page;
|
||||
|
||||
return($page);
|
||||
}
|
||||
|
||||
/**
|
||||
* get inpage from get
|
||||
*/
|
||||
private function getInPageFromGet(){
|
||||
$inpage = UniteFunctionsUC::getGetVar(self::GET_FIELD_INPAGE, $this->defaultInPage, UniteFunctionsUC::SANITIZE_ID);
|
||||
$inpage = (int)$inpage;
|
||||
|
||||
return($inpage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get category from get
|
||||
*/
|
||||
private function getCategoryFromGet(){
|
||||
|
||||
$cat = UniteFunctionsUC::getGetVar(self::GET_FIELD_CATEGORY, "", UniteFunctionsUC::SANITIZE_KEY);
|
||||
|
||||
if($cat == "all" || $cat === "")
|
||||
$cat = null;
|
||||
else
|
||||
$cat = (int)$cat;
|
||||
|
||||
return($cat);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get search value from get
|
||||
*/
|
||||
private function getSearchValueFromGet(){
|
||||
|
||||
$search = UniteFunctionsUC::getGetVar(self::GET_FIELD_SEARCH, "", UniteFunctionsUC::SANITIZE_TEXT_FIELD);
|
||||
|
||||
return($search);
|
||||
}
|
||||
|
||||
/**
|
||||
* get order value from get
|
||||
*/
|
||||
private function getOrderValueFromGet(){
|
||||
|
||||
$order = UniteFunctionsUC::getGetVar(self::GET_FIELD_ORDER, "", UniteFunctionsUC::SANITIZE_TEXT_FIELD);
|
||||
|
||||
if(empty($order))
|
||||
$order = $this->defaultOrderby;
|
||||
|
||||
return($order);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get all available get fields
|
||||
*/
|
||||
private function getGetFieldsNames($includeBaseFields = false, $isBaseOnly = false){
|
||||
|
||||
$fields = array();
|
||||
|
||||
if($includeBaseFields == true){
|
||||
$fields[] = self::GET_FIELD_OPTION;
|
||||
$fields[] = self::GET_FIELD_VIEW;
|
||||
|
||||
if($isBaseOnly == true)
|
||||
return($fields);
|
||||
}
|
||||
|
||||
$fields[] = self::GET_FIELD_PAGE;
|
||||
$fields[] = self::GET_FIELD_INPAGE;
|
||||
$fields[] = self::GET_FIELD_SEARCH;
|
||||
$fields[] = self::GET_FIELD_CATEGORY;
|
||||
$fields[] = self::GET_FIELD_ORDER;
|
||||
$fields[] = self::GET_FIELD_ORDER_DIR;
|
||||
|
||||
return($fields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get field values from get, from names array
|
||||
*/
|
||||
private function getArrFieldsValuesFromGet($fieldNames, $exceptField = null){
|
||||
|
||||
$arrFields = array();
|
||||
|
||||
foreach($fieldNames as $name){
|
||||
|
||||
if(!empty($exceptField) && $name == $exceptField)
|
||||
continue;
|
||||
|
||||
$fieldValue = UniteFunctionsUC::getGetVar($name, "", UniteFunctionsUC::SANITIZE_TEXT_FIELD);
|
||||
if(!empty($fieldValue))
|
||||
$arrFields[$name] = $fieldValue;
|
||||
}
|
||||
|
||||
return($arrFields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get array of fields from get
|
||||
*/
|
||||
private function getArrGetFields($includeBaseFields = false, $exceptField = null){
|
||||
|
||||
$fieldNames = $this->getGetFieldsNames($includeBaseFields);
|
||||
|
||||
$arrFields = $this->getArrFieldsValuesFromGet($fieldNames, $exceptField);
|
||||
|
||||
return($arrFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* get base fields obnly
|
||||
*/
|
||||
private function getArrBaseFields(){
|
||||
|
||||
$fieldNames = $this->getGetFieldsNames(true, true);
|
||||
|
||||
$arrFields = $this->getArrFieldsValuesFromGet($fieldNames);
|
||||
|
||||
return($arrFields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get page url
|
||||
*/
|
||||
private function getUrlPage($page = null,$exceptField=null){
|
||||
|
||||
$arrGetFields = $this->getArrGetFields(false, $exceptField);
|
||||
|
||||
if(!empty($page))
|
||||
$arrGetFields[self::GET_FIELD_PAGE] = $page;
|
||||
|
||||
$urlPage = UniteFunctionsUC::addUrlParams($this->baseUrl, $arrGetFields);
|
||||
|
||||
return($urlPage);
|
||||
}
|
||||
|
||||
private function a_SETTERS(){}
|
||||
|
||||
/**
|
||||
* set default orderby
|
||||
*/
|
||||
public function setDefaultOrderby($orderby){
|
||||
|
||||
$this->defaultOrderby = $orderby;
|
||||
}
|
||||
|
||||
private function a_GENERAL_GET(){}
|
||||
|
||||
/**
|
||||
* get paging options from get and default
|
||||
*/
|
||||
public function getPagingOptions(){
|
||||
|
||||
$output = array();
|
||||
$output["page"] = $this->getPageFromGet();
|
||||
$output["inpage"] = $this->getInPageFromGet();
|
||||
$output["search"] = $this->getSearchValueFromGet();
|
||||
$output["category"] = $this->getCategoryFromGet();
|
||||
|
||||
//take ordering
|
||||
$ordering = $this->getOrderValueFromGet();
|
||||
|
||||
$ordering = str_replace("_desc", " desc", $ordering);
|
||||
|
||||
$output["ordering"] = $ordering;
|
||||
|
||||
return($output);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set paging data
|
||||
*/
|
||||
public function setPagingData($baseURl, $data){
|
||||
|
||||
$this->baseUrl = $baseURl;
|
||||
|
||||
$this->total = UniteFunctionsUC::getVal($data, "total");
|
||||
$this->page = UniteFunctionsUC::getVal($data, "page");
|
||||
$this->inPage = UniteFunctionsUC::getVal($data, "inpage");
|
||||
$this->numPages = UniteFunctionsUC::getVal($data, "num_pages");
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($this->inPage, "in page");
|
||||
if($this->total > 0){
|
||||
UniteFunctionsUC::validateNotEmpty($this->page, "page");
|
||||
UniteFunctionsUC::validateNotEmpty($this->numPages, "num pages");
|
||||
}
|
||||
|
||||
$this->isPaging = true;
|
||||
}
|
||||
|
||||
|
||||
private function a_GET_HTML(){}
|
||||
|
||||
/**
|
||||
* convert fields array to html hidden inputs
|
||||
*/
|
||||
private function arrFieldsToHtmlHiddenInputs($arrGetFields){
|
||||
|
||||
$html = "";
|
||||
foreach($arrGetFields as $name=>$value)
|
||||
$html .= self::TAB3.HelperHtmlUC::getHiddenInputField($name, $value).self::BR;
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get all hidden fields html
|
||||
*/
|
||||
private function getHtmlHiddenInputs($except_field){
|
||||
|
||||
$arrGetFields = $this->getArrGetFields(true, $except_field);
|
||||
|
||||
$html = $this->arrFieldsToHtmlHiddenInputs($arrGetFields);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get all hidden fields html
|
||||
*/
|
||||
private function getHtmlHiddenBaseInputs(){
|
||||
|
||||
$arrGetFields = $this->getArrBaseFields();
|
||||
|
||||
$html = $this->arrFieldsToHtmlHiddenInputs($arrGetFields);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put actions form end
|
||||
*/
|
||||
public function putActionsFormStart(){
|
||||
$this->validatePaging();
|
||||
|
||||
$url = $this->baseUrl;
|
||||
$url = htmlspecialchars($url);
|
||||
|
||||
|
||||
$html = "";
|
||||
$html .= self::TAB2."<form method='get' name='unite-table-actions' action='{$url}'>".self::BR2;
|
||||
$html .= $this->getHtmlHiddenBaseInputs();
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
|
||||
$this->isInsideTopActions = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put actions form start
|
||||
*/
|
||||
public function putActionsFormEnd(){
|
||||
|
||||
$this->validateTopActions();
|
||||
|
||||
$html = self::TAB2."</form>".self::BR;
|
||||
|
||||
$this->isInsideTopActions = false;
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* get select form
|
||||
*/
|
||||
private function getHtmlFormSelect($htmlSelect, $htmlGetFields){
|
||||
|
||||
$html = "";
|
||||
|
||||
if($this->isInsideTopActions == false)
|
||||
$html .= "<form method='get'>";
|
||||
|
||||
$html .= $htmlSelect;
|
||||
|
||||
if($this->isInsideTopActions == false){
|
||||
$html .= $htmlGetFields;
|
||||
$html .= '</form>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get input with count content, about 10,25,50,100
|
||||
*/
|
||||
public function getHTMLInpageSelect(){
|
||||
|
||||
$inpage = $this->getInPageFromGet();
|
||||
|
||||
$arrNumbers = array(
|
||||
"10","25","50","100"
|
||||
);
|
||||
|
||||
$fieldInpage = self::GET_FIELD_INPAGE;
|
||||
|
||||
$htmlSelect = HelperHtmlUC::getHTMLSelect($arrNumbers, $inpage, "name='{$fieldInpage}' class='unite-tableitems-selectrecords' onchange='this.form.submit()'");
|
||||
$htmlGetFields = $this->getHtmlHiddenInputs($fieldInpage);
|
||||
|
||||
$html = $this->getHtmlFormSelect($htmlSelect, $htmlGetFields);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put filter category input
|
||||
*/
|
||||
public function putFilterCategory(){
|
||||
|
||||
$cat = $this->getCategoryFromGet();
|
||||
|
||||
$objCats = new UniteCreatorCategories;
|
||||
$arrCats = $objCats->getCatsShort("all_uncat_layouts", "layout");
|
||||
|
||||
$html = "";
|
||||
|
||||
$fieldCat = self::GET_FIELD_CATEGORY;
|
||||
|
||||
if($cat === "" || $cat === null)
|
||||
$cat = "all";
|
||||
|
||||
$htmlSelect = HelperHtmlUC::getHTMLSelect($arrCats, $cat, "name='{$fieldCat}' class='unite-tableitems-category' onchange='this.form.submit()'", true);
|
||||
$htmlGetFields = $this->getHtmlHiddenInputs($fieldCat);
|
||||
|
||||
$html = "<span class='uc-table-top-filter-title'>".esc_html__("Filter Category", "unlimited-elements-for-elementor")."</span>";
|
||||
|
||||
$html .= $this->getHtmlFormSelect($htmlSelect, $htmlGetFields);
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get pagination html
|
||||
*/
|
||||
private function getPaginationHtml(){
|
||||
|
||||
$this->validatePaging();
|
||||
|
||||
$item_per_page = $this->inPage;
|
||||
$current_page = $this->page;
|
||||
$total_records = $this->total;
|
||||
$total_pages = $this->numPages;
|
||||
|
||||
|
||||
$isShowExtras = true;
|
||||
|
||||
$pagination = '';
|
||||
if($total_pages > 0 && $total_pages != 1 && $current_page <= $total_pages){ //verify total pages and current page number
|
||||
$pagination .= '<ul class="unite-pagination class-for-pagination">';
|
||||
|
||||
$right_links = $current_page + 8;
|
||||
$previous = $current_page - 1; //previous link
|
||||
$next = $current_page + 1; //next link
|
||||
$first_link = true; //boolean var to decide our first link
|
||||
|
||||
//put first and previous
|
||||
if($current_page > 1 && $isShowExtras == true){
|
||||
$previous_link = ($previous==0)?1:$previous;
|
||||
|
||||
$urlFirst = $this->getUrlPage(1);
|
||||
$urlPrev = $this->getUrlPage($previous_link);
|
||||
|
||||
$titleFirst = esc_html__("First", "unlimited-elements-for-elementor");
|
||||
$titlePrev = esc_html__("Previous", "unlimited-elements-for-elementor");
|
||||
|
||||
$textFirst = "";
|
||||
$textPrev = "";
|
||||
|
||||
$pagination .= '<li class="unite-first"><a href="'.$urlFirst.'" title="'.$titleFirst.'" > « '.$textFirst.'</a></li>'; //first link
|
||||
$pagination .= '<li><a href="'.$urlPrev.'" title="'.$titlePrev.'">< '.$textPrev.'</a></li>'; //previous link
|
||||
|
||||
for($i = ($current_page-3); $i < $current_page; $i++){ //Create left-hand side links
|
||||
if($i > 0){
|
||||
$urlPage = $this->getUrlPage($i);
|
||||
$pagination .= '<li><a href="'.$urlPage.'">'.$i.'</a></li>';
|
||||
}
|
||||
}
|
||||
$first_link = false; //set first link to false
|
||||
}
|
||||
|
||||
if($first_link){ //if current active page is first link
|
||||
$pagination .= '<li class="unite-first unite-active"><a href="javascript:void(0)">'.$current_page.'</a></li>';
|
||||
}elseif($current_page == $total_pages){ //if it's the last active link
|
||||
$pagination .= '<li class="unite-last unite-active"><a href="javascript:void(0)">'.$current_page.'</a></li>';
|
||||
}else{ //regular current link
|
||||
$pagination .= '<li class="unite-active"><a href="javascript:void(0)">'.$current_page.'</a></li>';
|
||||
}
|
||||
|
||||
for($i = $current_page+1; $i < $right_links ; $i++){ //create right-hand side links
|
||||
if($i<=$total_pages){
|
||||
|
||||
$urlPage = $this->getUrlPage($i);
|
||||
|
||||
$pagination .= '<li><a href="'.$urlPage.'">'.$i.'</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
//show first / last
|
||||
if($current_page < $total_pages && $isShowExtras == true){
|
||||
|
||||
//next and last pages
|
||||
$next_link = ($i > $total_pages)? $total_pages : $i;
|
||||
|
||||
$urlNext = $this->getUrlPage($next_link);
|
||||
$urlLast = $this->getUrlPage($total_pages);
|
||||
|
||||
$titleNext = esc_html__("Next Page", "unlimited-elements-for-elementor");
|
||||
$titleLast = esc_html__("Last Page", "unlimited-elements-for-elementor");
|
||||
|
||||
$textNext = "";
|
||||
$textLast = "";
|
||||
|
||||
$pagination .= "<li><a href=\"{$urlNext}\" title=\"$titleNext\" >{$textNext} ></a></li>";
|
||||
$pagination .= "<li class=\"unite-last\"><a href=\"{$urlLast}\" title=\"$titleLast\" >{$textLast} » </a></li>";
|
||||
}
|
||||
|
||||
$pagination .= '</ul>';
|
||||
}
|
||||
|
||||
return($pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* draw table pagination
|
||||
*/
|
||||
public function putPaginationHtml(){
|
||||
$this->validatePaging();
|
||||
|
||||
$html = $this->getPaginationHtml();
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* put inpage select
|
||||
*/
|
||||
public function putInpageSelect(){
|
||||
$this->validatePaging();
|
||||
|
||||
if($this->total <= 10)
|
||||
return("");
|
||||
|
||||
$html = $this->getHTMLInpageSelect();
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* function for search content and sorting
|
||||
*/
|
||||
public function putSearchForm($buttonText = "", $clearText = "", $putByDefault = true){
|
||||
|
||||
//the button must be inside top actions
|
||||
$this->validateTopActions();
|
||||
|
||||
$html = "";
|
||||
|
||||
|
||||
$fieldValue = $this->getSearchValueFromGet();
|
||||
$fieldValue = htmlspecialchars($fieldValue);
|
||||
|
||||
if(empty($buttonText))
|
||||
$buttonText = esc_html__("Search", "unlimited-elements-for-elementor");
|
||||
|
||||
if(empty($clearText))
|
||||
$clearText = esc_html__("Clear", "unlimited-elements-for-elementor");
|
||||
|
||||
|
||||
$fieldName = self::GET_FIELD_SEARCH;
|
||||
$htmlFields = $this->getHtmlHiddenInputs($fieldName);
|
||||
$urlClear = $this->getUrlPage();
|
||||
|
||||
//is total allow to put search
|
||||
$isTotalAllow = ($this->total > 5);
|
||||
|
||||
if($isTotalAllow == false && empty($fieldValue))
|
||||
return(false);
|
||||
|
||||
if($putByDefault == false && empty($fieldValue))
|
||||
return(false);
|
||||
|
||||
if($this->isInsideTopActions == false){
|
||||
$urlForm = $this->baseUrl;
|
||||
$html .= self::TAB2."<form name='unite_form_table_search' method='get' action='$urlForm'>".self::BR;
|
||||
}
|
||||
|
||||
$html .= self::TAB2." <input name='$fieldName' type='text' class='unite-input-medium mbottom_0 unite-cursor-text' value=\"{$fieldValue}\"/> ".self::BR;
|
||||
$html .= self::TAB2." <button class='unite-button-primary' type='submit' value='1'>".$buttonText."</button>".self::BR;
|
||||
|
||||
//add clear button
|
||||
if(!empty($fieldValue)){
|
||||
$urlClear = $this->getUrlPage(null, self::GET_FIELD_SEARCH);
|
||||
|
||||
$html .= self::TAB2." <a class='unite-button-secondary' href=\"{$urlClear}\" >". $clearText."</a>".self::BR;
|
||||
}
|
||||
|
||||
|
||||
if($this->isInsideTopActions == false){
|
||||
$html .= self::TAB3.$htmlFields.self::BR;
|
||||
$html .= self::TAB2."</form>".self::BR;
|
||||
}
|
||||
|
||||
if(!empty($searchValue))
|
||||
$html .= " <a href=\"{$url}\" class=\"unite-button-secondary\">".$clearText."</a>";
|
||||
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* put table order header - inside table th
|
||||
*/
|
||||
public function putTableOrderHeader($name, $text){
|
||||
|
||||
$currentOrder = $this->getOrderValueFromGet();
|
||||
|
||||
$currentOrderField = str_replace("_desc", "", $currentOrder);
|
||||
|
||||
$isDesc = ($currentOrder != $currentOrderField);
|
||||
|
||||
$orderForLink = $name;
|
||||
if($currentOrderField == $name && $isDesc == false)
|
||||
$orderForLink = $name."_desc";
|
||||
|
||||
$link = $this->getUrlPage(null, self::GET_FIELD_ORDER);
|
||||
|
||||
$link = UniteFunctionsUC::addUrlParams($link, self::GET_FIELD_ORDER."=".$orderForLink);
|
||||
|
||||
//get text
|
||||
$signUp = "∧";
|
||||
$signDown = "∨";
|
||||
|
||||
$linkText = $text;
|
||||
if($name == $currentOrderField){
|
||||
if($isDesc == true)
|
||||
$linkText .= " ".$signUp;
|
||||
else
|
||||
$linkText .= " ".$signDown;
|
||||
}
|
||||
|
||||
$html = "<a href='$link'>$linkText</a>";
|
||||
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteTranslateUC{
|
||||
|
||||
private $entries;
|
||||
private $domain;
|
||||
|
||||
|
||||
/**
|
||||
* load language
|
||||
*/
|
||||
public function __construct($domain){
|
||||
$this->domain = $domain;
|
||||
$this->get_translations_for_domain($domain);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* read from language file and put it in entries for translate
|
||||
* @Params String $domain - basse name of language file
|
||||
*/
|
||||
private function get_translations_for_domain( $domain = "default" ){
|
||||
|
||||
if($this->entries != null){
|
||||
return true;
|
||||
}
|
||||
|
||||
$mo = new MO();
|
||||
$current_language = JFactory::getLanguage();
|
||||
|
||||
$mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR."language".DIRECTORY_SEPARATOR. $domain ."-". $current_language->getTag() .".mo" ;
|
||||
|
||||
|
||||
if(!file_exists($mo_file)){
|
||||
$mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR."language".DIRECTORY_SEPARATOR. $domain ."-". str_replace("-", "_", $current_language->getTag()) .".mo" ;
|
||||
if(!file_exists($mo_file)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$mo->import_from_file( $mo_file ) ) return false;
|
||||
if ( !isset( $lang[$domain] ) ){
|
||||
$lang[$domain] = $mo;
|
||||
}
|
||||
|
||||
$this->merge_with( $lang[$domain] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translate text
|
||||
*/
|
||||
private function translate_singular($singular, $context=null) {
|
||||
|
||||
$entry = new Translation_Entry(array('singular' => $singular, 'context' => $context));
|
||||
$translated = $this->translate_entry($entry);
|
||||
return ($translated && !empty($translated->translations))? $translated->translations[0] : $singular;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* put data read from language file to entries for translate
|
||||
*/
|
||||
private function merge_with(&$other) {
|
||||
|
||||
foreach( $other->entries as $entry ) {
|
||||
$this->entries[$entry->key()] = $entry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translate entry
|
||||
*/
|
||||
private function translate_entry(&$entry) {
|
||||
|
||||
$key = $entry->key();
|
||||
return isset($this->entries[$key])? $this->entries[$key] : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* translate the text
|
||||
*/
|
||||
public function translate($text) {
|
||||
|
||||
$translations = $this->translate_singular($text);
|
||||
|
||||
return $translations;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,557 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteZipUC{
|
||||
|
||||
private $_methods = array(0x0 => 'None', 0x1 => 'Shrunk', 0x2 => 'Super Fast', 0x3 => 'Fast', 0x4 => 'Normal', 0x5 => 'Maximum', 0x6 => 'Imploded', 0x8 => 'Deflated');
|
||||
private $_ctrlDirHeader = "\x50\x4b\x01\x02";
|
||||
private $_ctrlDirEnd = "\x50\x4b\x05\x06\x00\x00\x00\x00";
|
||||
private $_fileHeader = "\x50\x4b\x03\x04";
|
||||
private $_data = null;
|
||||
private $_metadata = null;
|
||||
private $contents = array();
|
||||
private $ctrldir = array();
|
||||
private $isZipArchiveExists = false;
|
||||
private $zip;
|
||||
|
||||
/**
|
||||
* make zip archive
|
||||
* if exists additional paths, add additional items to the zip
|
||||
*/
|
||||
public function makeZip($srcPath, $zipFilepath, $additionPaths = array()){
|
||||
|
||||
if(!is_dir($srcPath))
|
||||
UniteFunctionsUC::throwError("The path: '$srcPath' don't exists, can't zip");
|
||||
|
||||
$this->isZipArchiveExists = $this->isZipArchiveExists();
|
||||
|
||||
if($this->isZipArchiveExists === true){
|
||||
$this->zip = new ZipArchive();
|
||||
$success = $this->zip->open($zipFilepath, ZipArchive::CREATE);
|
||||
if($success === false)
|
||||
UniteFunctionsUC::throwError("Can't create zip file: $zipFilepath");
|
||||
}else{
|
||||
$this->contents = array();
|
||||
$this->ctrldir = array();
|
||||
}
|
||||
|
||||
$this->addItem($srcPath, $srcPath);
|
||||
|
||||
if(gettype($additionPaths) != "array")
|
||||
UniteFunctionsUC::throwError("Wrong additional paths variable.");
|
||||
|
||||
//add additional paths
|
||||
if(!empty($additionPaths))
|
||||
foreach($additionPaths as $path){
|
||||
if(!is_dir($path))
|
||||
UniteFunctionsUC::throwError("Path: $path not found, can't zip");
|
||||
$this->addItem($path, $path);
|
||||
}
|
||||
|
||||
if($this->isZipArchiveExists == true){
|
||||
$this->zip->close();
|
||||
}else{
|
||||
$this->_createZIPFile($this->contents, $this->ctrldir, $zipFilepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* extract zip archive
|
||||
*/
|
||||
public function extract($src, $dest){
|
||||
|
||||
if($this->isZipArchiveExists() === true){
|
||||
$success = $this->extract_zipArchive($src, $dest);
|
||||
|
||||
if($success === true)
|
||||
return true;
|
||||
|
||||
$filename = basename($src);
|
||||
|
||||
UniteFunctionsUC::throwError("Can't extract zip: $filename");
|
||||
}
|
||||
|
||||
$success = $this->extract_custom($src, $dest);
|
||||
|
||||
return ($success);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the zip archive exists
|
||||
*/
|
||||
private function isZipArchiveExists(){
|
||||
|
||||
$exists = class_exists("ZipArchive");
|
||||
|
||||
return $exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* add zip file
|
||||
*/
|
||||
private function addItem($basePath, $path){
|
||||
|
||||
$rel_path = str_replace($basePath . "/", "", $path);
|
||||
|
||||
if(is_dir($path)){ //directory
|
||||
|
||||
//add dir to zip
|
||||
if($basePath != $path){
|
||||
if($this->isZipArchiveExists)
|
||||
$this->zip->addEmptyDir($rel_path);
|
||||
}
|
||||
|
||||
$files = scandir($path);
|
||||
foreach($files as $file){
|
||||
if($file == "." || $file == ".." || $file == ".svn")
|
||||
continue;
|
||||
$filepath = $path . "/" . $file;
|
||||
|
||||
$this->addItem($basePath, $filepath);
|
||||
}
|
||||
}else{ //file
|
||||
if(!file_exists($path))
|
||||
UniteFunctionsUC::throwError("filepath: '$path' don't exists, can't zip");
|
||||
|
||||
if($this->isZipArchiveExists){
|
||||
$path = str_replace("//", "/", $path);
|
||||
|
||||
$this->zip->addFile($path, $rel_path);
|
||||
}else
|
||||
$this->addFileToCustomZip($path, $rel_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if dir exists, if not, create it recursively
|
||||
*/
|
||||
private function checkCreateDir($filepath){
|
||||
|
||||
$dir = dirname($filepath);
|
||||
|
||||
if(is_dir($dir) == false)
|
||||
$success = $this->checkCreateDir($dir);
|
||||
else
|
||||
return (true);
|
||||
|
||||
//this dir is not exists, and all parent dirs exists
|
||||
|
||||
@mkdir($dir);
|
||||
if(is_dir($dir) == false)
|
||||
UniteFunctionsUC::throwError("Can't create directory: {$dir} maybe zip file is brocken");
|
||||
}
|
||||
|
||||
/**
|
||||
* write some file
|
||||
*/
|
||||
private function writeFile($str, $filepath){
|
||||
|
||||
//create folder if not exists
|
||||
$this->checkCreateDir($filepath);
|
||||
|
||||
$fp = fopen($filepath, "w+");
|
||||
fwrite($fp, $str);
|
||||
fclose($fp);
|
||||
|
||||
if(file_exists($filepath) == false)
|
||||
UniteFunctionsUC::throwError("can't write file: $filepath");
|
||||
}
|
||||
|
||||
/**
|
||||
* extract using zip archive
|
||||
*/
|
||||
private function extract_zipArchive($src, $dest){
|
||||
|
||||
$zip = new ZipArchive();
|
||||
|
||||
$result = $zip->open($src);
|
||||
if($result !== true){
|
||||
switch($result){
|
||||
case ZipArchive::ER_NOZIP:
|
||||
UniteFunctionsUC::throwError('not a zip archive');
|
||||
case ZipArchive::ER_INCONS :
|
||||
UniteFunctionsUC::throwError('consistency check failed');
|
||||
case ZipArchive::ER_CRC :
|
||||
UniteFunctionsUC::throwError('checksum failed');
|
||||
default:
|
||||
UniteFunctionsUC::throwError('error ' . $result);
|
||||
}
|
||||
}
|
||||
|
||||
$extracted = @$zip->extractTo($dest);
|
||||
$zip->close();
|
||||
|
||||
if($extracted == false)
|
||||
return (false);
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
private function a_MAKEZIP_CUSTOM(){}
|
||||
|
||||
/**
|
||||
* add empty dir to custom zip
|
||||
*/
|
||||
/*
|
||||
private function addEmptyZipToCustomZip($path, $rel_path){
|
||||
|
||||
if(is_dir($path) == false)
|
||||
UniteFunctionsUC::throwError("Can't add directory to zip: $path");
|
||||
|
||||
$time = filemtime($path);
|
||||
|
||||
$file = array();
|
||||
$file["data"] = "";
|
||||
$file["name"] = $rel_path;
|
||||
$file["time"] = $time;
|
||||
|
||||
$this->_addToZIPFile($file, $this->contents, $this->ctrldir);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* add some file to custom zip
|
||||
*/
|
||||
private function addFileToCustomZip($path, $rel_path){
|
||||
|
||||
if(is_file($path) == false)
|
||||
UniteFunctionsUC::throwError("can't add to zip file: $path");
|
||||
|
||||
$content = file_get_contents($path);
|
||||
$time = filemtime($path);
|
||||
|
||||
$file = array();
|
||||
$file["data"] = $content;
|
||||
$file["name"] = $rel_path;
|
||||
$file["time"] = $time;
|
||||
|
||||
$this->_addToZIPFile($file, $this->contents, $this->ctrldir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a "file" to the ZIP archive.
|
||||
*
|
||||
* @param array &$file File data array to add
|
||||
* @param array &$contents An array of existing zipped files.
|
||||
* @param array &$ctrldir An array of central directory information.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @todo Review and finish implementation
|
||||
*/
|
||||
private function _addToZIPFile(array &$file, array &$contents, array &$ctrldir){
|
||||
|
||||
$data = &$file['data'];
|
||||
$name = str_replace('\\', '/', $file['name']);
|
||||
|
||||
/* See if time/date information has been provided. */
|
||||
$ftime = null;
|
||||
|
||||
if(isset($file['time'])){
|
||||
$ftime = $file['time'];
|
||||
}
|
||||
|
||||
// Get the hex time.
|
||||
$dtime = dechex($this->_unix2DosTime($ftime));
|
||||
$hexdtime = chr(hexdec($dtime[6] . $dtime[7])) . chr(hexdec($dtime[4] . $dtime[5])) . chr(hexdec($dtime[2] . $dtime[3]))
|
||||
. chr(hexdec($dtime[0] . $dtime[1]));
|
||||
|
||||
/* Begin creating the ZIP data. */
|
||||
$fr = $this->_fileHeader;
|
||||
/* Version needed to extract. */
|
||||
$fr .= "\x14\x00";
|
||||
/* General purpose bit flag. */
|
||||
$fr .= "\x00\x00";
|
||||
/* Compression method. */
|
||||
$fr .= "\x08\x00";
|
||||
/* Last modification time/date. */
|
||||
$fr .= $hexdtime;
|
||||
|
||||
/* "Local file header" segment. */
|
||||
$unc_len = strlen($data);
|
||||
$crc = crc32($data);
|
||||
$zdata = gzcompress($data);
|
||||
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
|
||||
$c_len = strlen($zdata);
|
||||
|
||||
/* CRC 32 information. */
|
||||
$fr .= pack('V', $crc);
|
||||
/* Compressed filesize. */
|
||||
$fr .= pack('V', $c_len);
|
||||
/* Uncompressed filesize. */
|
||||
$fr .= pack('V', $unc_len);
|
||||
/* Length of filename. */
|
||||
$fr .= pack('v', strlen($name));
|
||||
/* Extra field length. */
|
||||
$fr .= pack('v', 0);
|
||||
/* File name. */
|
||||
$fr .= $name;
|
||||
|
||||
/* "File data" segment. */
|
||||
$fr .= $zdata;
|
||||
|
||||
/* Add this entry to array. */
|
||||
$old_offset = strlen(implode('', $contents));
|
||||
$contents[] = &$fr;
|
||||
|
||||
/* Add to central directory record. */
|
||||
$cdrec = $this->_ctrlDirHeader;
|
||||
/* Version made by. */
|
||||
$cdrec .= "\x00\x00";
|
||||
/* Version needed to extract */
|
||||
$cdrec .= "\x14\x00";
|
||||
/* General purpose bit flag */
|
||||
$cdrec .= "\x00\x00";
|
||||
/* Compression method */
|
||||
$cdrec .= "\x08\x00";
|
||||
/* Last mod time/date. */
|
||||
$cdrec .= $hexdtime;
|
||||
/* CRC 32 information. */
|
||||
$cdrec .= pack('V', $crc);
|
||||
/* Compressed filesize. */
|
||||
$cdrec .= pack('V', $c_len);
|
||||
/* Uncompressed filesize. */
|
||||
$cdrec .= pack('V', $unc_len);
|
||||
/* Length of filename. */
|
||||
$cdrec .= pack('v', strlen($name));
|
||||
/* Extra field length. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* File comment length. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* Disk number start. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* Internal file attributes. */
|
||||
$cdrec .= pack('v', 0);
|
||||
/* External file attributes -'archive' bit set. */
|
||||
$cdrec .= pack('V', 32);
|
||||
/* Relative offset of local header. */
|
||||
$cdrec .= pack('V', $old_offset);
|
||||
/* File name. */
|
||||
$cdrec .= $name;
|
||||
/* Optional extra field, file comment goes here. */
|
||||
|
||||
/* Save to central directory array. */
|
||||
$ctrldir[] = &$cdrec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ZIP file.
|
||||
*
|
||||
* Official ZIP file format: https://support.pkware.com/display/PKZIP/APPNOTE
|
||||
*
|
||||
* @param array &$contents An array of existing zipped files.
|
||||
* @param array &$ctrlDir An array of central directory information.
|
||||
* @param string $path The path to store the archive.
|
||||
*
|
||||
* @return boolean True if successful
|
||||
*
|
||||
* @since 11.1
|
||||
*
|
||||
* @todo Review and finish implementation
|
||||
*/
|
||||
private function _createZIPFile(array &$contents, array &$ctrlDir, $path){
|
||||
|
||||
$data = implode('', $contents);
|
||||
$dir = implode('', $ctrlDir);
|
||||
|
||||
$buffer = $data . $dir . $this->_ctrlDirEnd . /* Total # of entries "on this disk". */
|
||||
pack('v', count($ctrlDir)) . /* Total # of entries overall. */
|
||||
pack('v', count($ctrlDir)) . /* Size of central directory. */
|
||||
pack('V', strlen($dir)) . /* Offset to start of central dir. */
|
||||
pack('V', strlen($data)) . /* ZIP file comment length. */
|
||||
"\x00\x00";
|
||||
|
||||
UniteFunctionsUC::writeFile($buffer, $path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a UNIX timestamp to a 4-byte DOS date and time format
|
||||
* (date in high 2-bytes, time in low 2-bytes allowing magnitude
|
||||
* comparison).
|
||||
*
|
||||
* @param int $unixtime The current UNIX timestamp.
|
||||
*
|
||||
* @return int The current date in a 4-byte DOS format.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
private function _unix2DOSTime($unixtime = null){
|
||||
|
||||
$timearray = (is_null($unixtime)) ? getdate() : getdate($unixtime);
|
||||
|
||||
if($timearray['year'] < 1980){
|
||||
$timearray['year'] = 1980;
|
||||
$timearray['mon'] = 1;
|
||||
$timearray['mday'] = 1;
|
||||
$timearray['hours'] = 0;
|
||||
$timearray['minutes'] = 0;
|
||||
$timearray['seconds'] = 0;
|
||||
}
|
||||
|
||||
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) |
|
||||
($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
|
||||
}
|
||||
|
||||
private function a_EXTRACT_CUSTOM(){}
|
||||
|
||||
/**
|
||||
* extract zip customely
|
||||
*/
|
||||
private function extract_custom($src, $dest){
|
||||
|
||||
$this->_data = null;
|
||||
$this->_metadata = null;
|
||||
|
||||
if(!extension_loaded('zlib'))
|
||||
UniteFunctionsUC::throwError('Zlib not supported, please enable in php.ini');
|
||||
|
||||
$this->_data = file_get_contents($src);
|
||||
if(!$this->_data)
|
||||
UniteFunctionsUC::throwError('Get ZIP Data failed');
|
||||
|
||||
$success = $this->extract_custom_readZipInfo($this->_data);
|
||||
if(!$success)
|
||||
UniteFunctionsUC::throwError('Get ZIP Information failed');
|
||||
|
||||
for($i = 0, $n = count($this->_metadata); $i < $n; $i++){
|
||||
$lastPathCharacter = substr($this->_metadata[$i]['name'], -1, 1);
|
||||
|
||||
if($lastPathCharacter !== '/' && $lastPathCharacter !== '\\'){
|
||||
//write file
|
||||
|
||||
$buffer = $this->extract_custom_getFileData($i);
|
||||
$destFilepath = UniteFunctionsUC::cleanPath($dest . '/' . $this->_metadata[$i]['name']);
|
||||
|
||||
$this->writeFile($buffer, $destFilepath);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* read zip info
|
||||
*/
|
||||
private function extract_custom_readZipInfo(&$data){
|
||||
|
||||
$entries = array();
|
||||
|
||||
// Find the last central directory header entry
|
||||
$fhLast = strpos($data, $this->_ctrlDirEnd);
|
||||
|
||||
do{
|
||||
$last = $fhLast;
|
||||
}while(($fhLast = strpos($data, $this->_ctrlDirEnd, $fhLast + 1)) !== false);
|
||||
|
||||
// Find the central directory offset
|
||||
$offset = 0;
|
||||
|
||||
if($last){
|
||||
$endOfCentralDirectory = unpack(
|
||||
'vNumberOfDisk/vNoOfDiskWithStartOfCentralDirectory/vNoOfCentralDirectoryEntriesOnDisk/' .
|
||||
'vTotalCentralDirectoryEntries/VSizeOfCentralDirectory/VCentralDirectoryOffset/vCommentLength',
|
||||
substr($data, $last + 4)
|
||||
);
|
||||
$offset = $endOfCentralDirectory['CentralDirectoryOffset'];
|
||||
}
|
||||
|
||||
// Get details from central directory structure.
|
||||
$fhStart = strpos($data, $this->_ctrlDirHeader, $offset);
|
||||
$dataLength = strlen($data);
|
||||
|
||||
do{
|
||||
if($dataLength < $fhStart + 31){
|
||||
UniteFunctionsUC::throwError('Invalid Zip Data');
|
||||
}
|
||||
|
||||
$info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength', substr($data, $fhStart + 10, 20));
|
||||
$name = substr($data, $fhStart + 46, $info['Length']);
|
||||
|
||||
$entries[$name] = array(
|
||||
'attr' => null,
|
||||
'crc' => sprintf("%08s", dechex($info['CRC32'])),
|
||||
'csize' => $info['Compressed'],
|
||||
'date' => null,
|
||||
'_dataStart' => null,
|
||||
'name' => $name,
|
||||
'method' => $this->_methods[$info['Method']],
|
||||
'_method' => $info['Method'],
|
||||
'size' => $info['Uncompressed'],
|
||||
'type' => null,
|
||||
);
|
||||
|
||||
$entries[$name]['date'] = mktime(
|
||||
(($info['Time'] >> 11) & 0x1f),
|
||||
(($info['Time'] >> 5) & 0x3f),
|
||||
(($info['Time'] << 1) & 0x3e),
|
||||
(($info['Time'] >> 21) & 0x07),
|
||||
(($info['Time'] >> 16) & 0x1f),
|
||||
((($info['Time'] >> 25) & 0x7f) + 1980)
|
||||
);
|
||||
|
||||
if($dataLength < $fhStart + 43){
|
||||
UniteFunctionsUC::throwError('Invalid Zip Data');
|
||||
}
|
||||
|
||||
$info = unpack('vInternal/VExternal/VOffset', substr($data, $fhStart + 36, 10));
|
||||
|
||||
$entries[$name]['type'] = ($info['Internal'] & 0x01) ? 'text' : 'binary';
|
||||
$entries[$name]['attr'] = (($info['External'] & 0x10) ? 'D' : '-') . (($info['External'] & 0x20) ? 'A' : '-')
|
||||
. (($info['External'] & 0x03) ? 'S' : '-') . (($info['External'] & 0x02) ? 'H' : '-') . (($info['External'] & 0x01) ? 'R' : '-');
|
||||
$entries[$name]['offset'] = $info['Offset'];
|
||||
|
||||
// Get details from local file header since we have the offset
|
||||
$lfhStart = strpos($data, $this->_fileHeader, $entries[$name]['offset']);
|
||||
|
||||
if($dataLength < $lfhStart + 34){
|
||||
UniteFunctionsUC::throwError('Invalid Zip Data');
|
||||
}
|
||||
|
||||
$info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength/vExtraLength', substr($data, $lfhStart + 8, 25));
|
||||
$name = substr($data, $lfhStart + 30, $info['Length']);
|
||||
$entries[$name]['_dataStart'] = $lfhStart + 30 + $info['Length'] + $info['ExtraLength'];
|
||||
|
||||
// Bump the max execution time because not using the built in php zip libs makes this process slow.
|
||||
|
||||
$maxTime = ini_get('max_execution_time');
|
||||
|
||||
if(!empty($maxTime) && is_numeric($maxTime))
|
||||
@set_time_limit($maxTime);
|
||||
}while((($fhStart = strpos($data, $this->_ctrlDirHeader, $fhStart + 46)) !== false));
|
||||
|
||||
$this->_metadata = array_values($entries);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get file data for extract
|
||||
*/
|
||||
private function extract_custom_getFileData($key){
|
||||
|
||||
if($this->_metadata[$key]['_method'] == 0x8){
|
||||
return gzinflate(substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']));
|
||||
}elseif($this->_metadata[$key]['_method'] == 0x0){
|
||||
/* Files that aren't compressed. */
|
||||
return substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']);
|
||||
}elseif($this->_metadata[$key]['_method'] == 0x12){
|
||||
// If bz2 extension is loaded use it
|
||||
if(extension_loaded('bz2')){
|
||||
return bzdecompress(substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize']));
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorLayoutOutputConfigBase{
|
||||
|
||||
public $allowAnimations = true;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* function for override
|
||||
*/
|
||||
protected function initChild(){
|
||||
dmp("init child - function for override");
|
||||
}
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
private function init(){
|
||||
|
||||
$this->initChild();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,815 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorLayoutsWork extends UniteElementsBaseUC{
|
||||
|
||||
protected $lastDuplicatedID;
|
||||
|
||||
|
||||
private function a_GET_LAYOUTS(){}
|
||||
|
||||
|
||||
/**
|
||||
* get layout where from params
|
||||
*/
|
||||
private function getWhereFromParams($params){
|
||||
|
||||
$where = array();
|
||||
|
||||
$catID = UniteFunctionsUC::getVal($params, "catid");
|
||||
if(!empty($catID))
|
||||
$where["catid"] = $catID;
|
||||
|
||||
$layoutType = UniteFunctionsUC::getVal($params, "layout_type");
|
||||
if(empty($layoutType))
|
||||
$layoutType = UniteCreatorDB::ISNULL;
|
||||
|
||||
$where["layout_type"] = $layoutType;
|
||||
|
||||
return($where);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get galleries array
|
||||
*/
|
||||
private function getRecords($order = "ordering", $params = array(), $layoutType = null){
|
||||
|
||||
if(empty($params))
|
||||
$params = array();
|
||||
|
||||
$params["layout_type"] = $layoutType;
|
||||
|
||||
|
||||
if(empty($order))
|
||||
$order = "ordering";
|
||||
|
||||
$where = $this->getWhereFromParams($params);
|
||||
|
||||
$response = $this->db->fetch(GlobalsUC::$table_layouts, $where, $order);
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get records with paging
|
||||
*/
|
||||
private function getRecordsPaging($pagingOptions){
|
||||
|
||||
$arrWhere = array();
|
||||
|
||||
//search
|
||||
$search = UniteFunctionsUC::getVal($pagingOptions, "search");
|
||||
|
||||
if(!empty($search)) {
|
||||
$search = $this->db->escape($search);
|
||||
$arrWhere["title"] = array("LIKE","%{$search}%");
|
||||
}
|
||||
|
||||
$order = UniteFunctionsUC::getVal($pagingOptions, "ordering");
|
||||
|
||||
$filterCat = UniteFunctionsUC::getVal($pagingOptions, "category");
|
||||
|
||||
if(!empty($filterCat) && $filterCat != 'all'){
|
||||
$filterCat = (int)$filterCat;
|
||||
|
||||
$arrWhere["catid"] = $filterCat;
|
||||
}
|
||||
|
||||
//add layout type
|
||||
$layoutType = UniteFunctionsUC::getVal($pagingOptions, "layout_type");
|
||||
if(empty($layoutType))
|
||||
$layoutType = UniteCreatorDB::ISNULL;
|
||||
|
||||
$arrWhere["layout_type"] = $layoutType;
|
||||
|
||||
$response = $this->db->fetchPage(GlobalsUC::$table_layouts, $pagingOptions, $arrWhere, $order);
|
||||
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get layout from data
|
||||
*/
|
||||
private function getLayoutFromData($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layout_id");
|
||||
UniteFunctionsUC::validateNumeric($layoutID);
|
||||
UniteFunctionsUC::validateNotEmpty($layoutID);
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
|
||||
return($objLayout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert records to layouts objects
|
||||
*/
|
||||
private function recordsToLayouts($records){
|
||||
|
||||
if(empty($records))
|
||||
return(array());
|
||||
|
||||
$arrLayouts = array();
|
||||
foreach($records as $record){
|
||||
$layoutID = UniteFunctionsUC::getVal($record, "id");
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
|
||||
$arrLayouts[] = $objLayout;
|
||||
}
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* get addons array
|
||||
*/
|
||||
public function getArrLayouts($order = "ordering", $params = array(), $layoutType = null){
|
||||
|
||||
$response = $this->getRecords($order, $params, $layoutType);
|
||||
|
||||
$arrLayouts = $this->recordsToLayouts($response);
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get layouts with paging data
|
||||
*/
|
||||
public function getArrLayoutsPaging($pagingOptions){
|
||||
|
||||
$response = $this->getRecordsPaging($pagingOptions);
|
||||
|
||||
$rows = $response["rows"];
|
||||
unset($response["rows"]);
|
||||
|
||||
$arrLayouts = $this->recordsToLayouts($rows);
|
||||
|
||||
$output = array();
|
||||
$output["paging"] = $response;
|
||||
$output["layouts"] = $arrLayouts;
|
||||
|
||||
return($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* get layouts array short version - without content
|
||||
*/
|
||||
public function getArrLayoutsShort($addEmpty = false, $params = array(), $layoutType = null){
|
||||
|
||||
if($layoutType == GlobalsUC::ADDON_TYPE_REGULAR_LAYOUT)
|
||||
$layoutType = null;
|
||||
|
||||
if(!empty($layoutType))
|
||||
$params["layout_type"] = $layoutType;
|
||||
|
||||
$where = $this->getWhereFromParams($params);
|
||||
|
||||
$arrLayouts = $this->db->fetchFields(GlobalsUC::$table_layouts, "id, title", $where, "ordering");
|
||||
if(empty($arrLayouts))
|
||||
$arrLayouts = array();
|
||||
|
||||
if($addEmpty == true){
|
||||
$arrItem = array("id"=>"empty", "title"=>"[Not Selected]");
|
||||
$arrAdd = array($arrItem);
|
||||
|
||||
$arrLayouts = array_merge($arrAdd, $arrLayouts);
|
||||
}
|
||||
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* get layouts array short version - without content
|
||||
*/
|
||||
public function getArrLayoutsKeyValue($addEmpty = false, $layoutType = null){
|
||||
|
||||
if(!empty($layoutType))
|
||||
$params["layout_type"] = $layoutType;
|
||||
|
||||
$where = $this->getWhereFromParams($params);
|
||||
|
||||
$arrLayouts = $this->db->fetchFields(GlobalsUC::$table_layouts, "id, title", $where, "ordering");
|
||||
if(empty($arrLayouts))
|
||||
$arrLayouts = array();
|
||||
|
||||
if($addEmpty == true){
|
||||
$arrItem = array("id"=>"empty", "title"=>"[Not Selected]");
|
||||
$arrAdd = array($arrItem);
|
||||
|
||||
$arrLayouts = array_merge($arrAdd, $arrLayouts);
|
||||
}
|
||||
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get active template part
|
||||
*/
|
||||
public function getActiveTempaltePart($layoutType){
|
||||
|
||||
$arrLayouts = $this->getArrLayouts(null, null, $layoutType);
|
||||
|
||||
if(empty($arrLayouts))
|
||||
return(null);
|
||||
|
||||
$firstLayout = $arrLayouts[0];
|
||||
|
||||
return($firstLayout);
|
||||
}
|
||||
|
||||
/**
|
||||
* get items by id's
|
||||
*/
|
||||
private function getLayoutsByIDs($arrLayoutIDs){
|
||||
|
||||
$tableLayouts = GlobalsUC::$table_layouts;
|
||||
$arrLayouts = $this->db->fetchByIDs($tableLayouts, $arrLayoutIDs);
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get category layouts. category id can be null, all number or 0 (uncategorized)
|
||||
*/
|
||||
public function getCatLayouts($catID, $objAddonType = null, $onlyRecords = false){
|
||||
|
||||
if($catID == "zero")
|
||||
$catID = 0;
|
||||
|
||||
$arrWhere = $this->db->getWhereCatIDWithAll($catID);
|
||||
|
||||
$typeName = null;
|
||||
if(!empty($objAddonType)){
|
||||
$typeName = $objAddonType->typeName;
|
||||
if($objAddonType->isBasicType == true)
|
||||
$typeName = null;
|
||||
}
|
||||
|
||||
//set addon type - if specific category - no need
|
||||
if((is_numeric($catID) == false || empty($catID) || $catID === "all") && $typeName !== null )
|
||||
$arrWhere[] = $this->db->getSqlAddonType($typeName, "layout_type");
|
||||
|
||||
$where = "";
|
||||
if(!empty($arrWhere))
|
||||
$where = implode(" and ", $arrWhere);
|
||||
|
||||
$records = $this->db->fetch(GlobalsUC::$table_layouts, $where, "catid, ordering");
|
||||
|
||||
if($onlyRecords === true)
|
||||
return($records);
|
||||
|
||||
$arrLayouts = $this->recordsToLayouts($records);
|
||||
|
||||
return($arrLayouts);
|
||||
}
|
||||
|
||||
/**
|
||||
* get num category layouts
|
||||
*/
|
||||
public function getNumCatLayouts($catID, UniteCreatorAddonType $objAddonType){
|
||||
|
||||
if($objAddonType->isLayout == false)
|
||||
UniteFunctionsUC::throwError("Wrong layout type");
|
||||
|
||||
if($catID === 0){
|
||||
$catID = "zero";
|
||||
}
|
||||
|
||||
$arrRecords = $this->getCatLayouts($catID, $objAddonType, true);
|
||||
|
||||
$numRecords = count($arrRecords);
|
||||
|
||||
return($numRecords);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get all layouts with categories by some layout type
|
||||
*/
|
||||
public function getLayoutsWithCategories($layoutType, $isShort = false){
|
||||
|
||||
$arrLayouts = $this->getArrLayouts(null, array(), $layoutType);
|
||||
|
||||
$generated = UniteFunctionsUC::getRandomString(5);
|
||||
$prefix = "layout_".$generated."_";
|
||||
|
||||
$arrCats = array();
|
||||
foreach($arrLayouts as $key => $objLayout){
|
||||
|
||||
$name = $objLayout->getName();
|
||||
if(empty($name))
|
||||
$name = $prefix.$key;
|
||||
|
||||
$catTitle = $objLayout->getCategoryName();
|
||||
|
||||
if(empty($catTitle))
|
||||
$catTitle = "Uncategorized";
|
||||
|
||||
if(isset($arrCats[$catTitle]) == false)
|
||||
$arrCats[$catTitle] = array();
|
||||
|
||||
if($isShort == false)
|
||||
$arrCats[$catTitle][$name] = $objLayout;
|
||||
else
|
||||
$arrCats[$catTitle][$name] = $objLayout->getShortData();
|
||||
|
||||
}
|
||||
|
||||
return($arrCats);
|
||||
}
|
||||
|
||||
|
||||
private function a_______OTHER_GETTERS_________(){}
|
||||
|
||||
|
||||
/**
|
||||
* check if layout exists by title
|
||||
*/
|
||||
public function isLayoutExistsByTitle($title, $layoutType = null){
|
||||
|
||||
$arrLayout = $this->getLayoutRecordByTitle($title, $layoutType);
|
||||
|
||||
$isExists = !empty($arrLayout);
|
||||
|
||||
return($isExists);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get layout record by title
|
||||
*/
|
||||
private function getLayoutRecordByTitle($title, $layoutType){
|
||||
|
||||
$whereType = $this->db->getSqlAddonType($layoutType, "layout_type");
|
||||
|
||||
$response = $this->db->fetch(GlobalsUC::$table_layouts, array("title"=>$title, UniteCreatorDB::ISNULL=>$whereType));
|
||||
if(empty($response))
|
||||
return($response);
|
||||
|
||||
$response = $response[0];
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* get max order from categories list
|
||||
*/
|
||||
public function getMaxOrder(){
|
||||
|
||||
$tableLayouts = GlobalsUC::$table_layouts;
|
||||
|
||||
$query = "select MAX(ordering) as maxorder from {$tableLayouts}";
|
||||
|
||||
$rows = $this->db->fetchSql($query);
|
||||
|
||||
$maxOrder = 0;
|
||||
if(count($rows)>0)
|
||||
$maxOrder = $rows[0]["maxorder"];
|
||||
|
||||
if(!is_numeric($maxOrder))
|
||||
$maxOrder = 0;
|
||||
|
||||
return($maxOrder);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get take screenshot url, or template of it
|
||||
*/
|
||||
public function getUrlTakeScreenshot($isTakeScreenshot = true, $layoutID = null){
|
||||
|
||||
$addParams = "screenshot=true";
|
||||
if($isTakeScreenshot == true)
|
||||
$addParams .= "&take_screenshot=true";
|
||||
|
||||
$isFront = true;
|
||||
|
||||
$url = HelperUC::getViewUrl_LayoutPreview($layoutID, true, $addParams, $isFront);
|
||||
|
||||
return($url);
|
||||
}
|
||||
|
||||
|
||||
private function a_OPERATIONS(){}
|
||||
|
||||
|
||||
/**
|
||||
* validate layout type
|
||||
*/
|
||||
public function validateLayoutType($layoutType){
|
||||
|
||||
$objLayout = UniteCreatorAddonType::getAddonTypeObject($layoutType, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* duplicate layouts
|
||||
*/
|
||||
public function duplicateLayouts($arrIDs, $catID){
|
||||
|
||||
foreach($arrIDs as $layoutID){
|
||||
$layout = new UniteCreatorLayout();
|
||||
$layout->initByID($layoutID);
|
||||
$layout->duplicate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update category layout
|
||||
* @param unknown_type $data
|
||||
*/
|
||||
public function updateLayoutCategoryFromData($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layoutid");
|
||||
$catID = UniteFunctionsUC::getVal($data, "catid");
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
$objLayout->updateCategory($catID);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update layout properties from data
|
||||
*/
|
||||
public function updateParamsFromData($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layoutid");
|
||||
$params = UniteFunctionsUC::getVal($data, "params");
|
||||
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
$objLayout->updateParams($params);
|
||||
|
||||
$isFromManager = UniteFunctionsUC::getVal($data, "from_manager");
|
||||
$isFromManager = UniteFunctionsUC::strToBool($isFromManager);
|
||||
|
||||
if($isFromManager == true){
|
||||
|
||||
$addonType = UniteFunctionsUC::getVal($data, "addontype");
|
||||
$objManager = UniteCreatorManager::getObjManagerByAddonType($addonType, $data);
|
||||
|
||||
$htmlItem = $objManager->getAddonAdminHtml($objLayout);
|
||||
|
||||
$response = array();
|
||||
$response["html_item"] = $htmlItem;
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
return(array());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update layout from data
|
||||
*/
|
||||
public function updateLayoutFromData($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layoutid");
|
||||
|
||||
|
||||
$isTitleOnly = UniteFunctionsUC::getVal($data, "title_only");
|
||||
$isTitleOnly = UniteFunctionsUC::strToBool($isTitleOnly);
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
|
||||
$isUpdate = false;
|
||||
|
||||
if(empty($layoutID)){
|
||||
|
||||
$responseCreate = $objLayout->create($data);
|
||||
$layoutID = $responseCreate["id"];
|
||||
$name = $responseCreate["name"];
|
||||
|
||||
$message = HelperUC::getText("layout_created");
|
||||
|
||||
}else{
|
||||
|
||||
$isUpdate = true;
|
||||
|
||||
//update layout
|
||||
$objLayout->initByID($layoutID);
|
||||
|
||||
$name = UniteFunctionsUC::getVal($data, "name");
|
||||
if(!empty($name))
|
||||
$name = HelperUC::convertTitleToAlias($name);
|
||||
else{
|
||||
if(!isset($data["name"]))
|
||||
$name = null; //to avoid validation if not passed
|
||||
}
|
||||
|
||||
|
||||
if($isTitleOnly == true){
|
||||
$title = UniteFunctionsUC::getVal($data, "title");
|
||||
|
||||
$objLayout->updateTitle($title, $name);
|
||||
$message = esc_html__("Title Saved","unlimited-elements-for-elementor");
|
||||
|
||||
}else{
|
||||
$objLayout->update($data);
|
||||
$message = HelperUC::getText("layout_updated");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$response = array();
|
||||
$response["is_update"] = $isUpdate;
|
||||
$response["layout_id"] = $layoutID;
|
||||
|
||||
if(!empty($name))
|
||||
$response["page_name"] = $name;
|
||||
|
||||
$response["message"] = $message;
|
||||
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete layouts
|
||||
*/
|
||||
public function deleteLayouts($arrIDs){
|
||||
|
||||
if(empty($arrIDs))
|
||||
UniteFunctionsUC::throwError("no id's to delete");
|
||||
|
||||
$this->db->deleteMultipleByID(GlobalsUC::$table_layouts, $arrIDs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* delete layout from data
|
||||
*/
|
||||
public function deleteLayoutFromData($data){
|
||||
|
||||
$objLayout = $this->getLayoutFromData($data);
|
||||
|
||||
$objLayout->delete();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get layout name, and find name that don't exists in database using counter *
|
||||
*/
|
||||
public function getUniqueTitle($title, $layoutType = null){
|
||||
|
||||
$counter = 1;
|
||||
|
||||
$isExists = $this->isLayoutExistsByTitle($title, $layoutType);
|
||||
|
||||
if($isExists == false)
|
||||
return($title);
|
||||
|
||||
$limit = 1;
|
||||
while($isExists == true && $limit < 10){
|
||||
$limit++;
|
||||
$counter++;
|
||||
$newTitle = $title."-".$counter;
|
||||
$isExists = $this->isLayoutExistsByTitle($newTitle, $layoutType);
|
||||
}
|
||||
|
||||
return($newTitle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* shift addons in category from some order (more then the order).
|
||||
*/
|
||||
public function shiftOrder($order, $layoutType){
|
||||
|
||||
UniteFunctionsUC::validateNumeric($order);
|
||||
|
||||
$tableLayouts = GlobalsUC::$table_layouts;
|
||||
|
||||
$sqlLayoutType = $this->db->getSqlAddonType($layoutType,"layout_type");
|
||||
|
||||
$query = "update {$tableLayouts} set ordering = ordering+1 where ordering > {$order} and {$sqlLayoutType}";
|
||||
|
||||
$this->db->runSql($query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* export layout from get data
|
||||
*/
|
||||
public function exportLayout($data = null){
|
||||
|
||||
if(!empty($data)){
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "id");
|
||||
}else{
|
||||
$layoutID = UniteFunctionsUC::getGetVar("id","",UniteFunctionsUC::SANITIZE_ID);
|
||||
}
|
||||
|
||||
$layoutID = (int)$layoutID;
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
|
||||
$exporter = new UniteCreatorLayoutsExporter();
|
||||
$exporter->initByLayout($objLayout);
|
||||
$exporter->export();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* import layouts
|
||||
*/
|
||||
public function importLayouts($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layoutID");
|
||||
if(!empty($layoutID))
|
||||
$layoutID = (int)$layoutID;
|
||||
|
||||
$arrTempFile = UniteFunctionsUC::getVal($_FILES, "import_layout");
|
||||
|
||||
$isOverwriteAddons = UniteFunctionsUC::getVal($data, "overwrite_addons");
|
||||
|
||||
$params = UniteFunctionsUC::getVal($data, "params");
|
||||
if(empty($params))
|
||||
$params = array();
|
||||
|
||||
$exporter = new UniteCreatorLayoutsExporter();
|
||||
$exporter->import($arrTempFile, $layoutID, $isOverwriteAddons, $params);
|
||||
|
||||
$noRedirect = UniteFunctionsUC::getVal($data, "no_redirect");
|
||||
$noRedirect = UniteFunctionsUC::strToBool($noRedirect);
|
||||
if($noRedirect == true)
|
||||
return(null);
|
||||
|
||||
if(empty($layoutID))
|
||||
$urlRedirect = HelperUC::getViewUrl_LayoutsList($params);
|
||||
else
|
||||
$urlRedirect = HelperUC::getViewUrl_Layout($layoutID, $params);
|
||||
|
||||
|
||||
return($urlRedirect);
|
||||
}
|
||||
|
||||
/**
|
||||
* update ordering
|
||||
*/
|
||||
public function updateOrdering($layoutsIDs){
|
||||
|
||||
if(empty($layoutsIDs))
|
||||
return(false);
|
||||
|
||||
$this->db->updateRecordsOrdering(GlobalsUC::$table_layouts, $layoutsIDs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* save items order from data
|
||||
*/
|
||||
public function updateOrderFromData($data){
|
||||
|
||||
$layoutsIDs = UniteFunctionsUC::getVal($data, "layouts_order");
|
||||
|
||||
$this->updateOrdering($layoutsIDs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* move layouts
|
||||
*/
|
||||
public function moveLayouts($arrIDs, $catID, $targetParentID = null){
|
||||
|
||||
$category = new UniteCreatorCategories();
|
||||
$category->validateCatExist($catID);
|
||||
|
||||
foreach($arrIDs as $layoutID){
|
||||
$this->moveLayout($layoutID, $catID, $targetParentID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* move layouts to some category by change category id
|
||||
*/
|
||||
protected function moveLayout($layoutID, $catID, $targetParentID = null){
|
||||
|
||||
$layoutID = (int)$layoutID;
|
||||
$catID = (int)$catID;
|
||||
|
||||
$arrUpdate = array();
|
||||
$arrUpdate["catid"] = $catID;
|
||||
$this->db->update(GlobalsUC::$table_layouts, $arrUpdate, array("id"=>$layoutID));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* save section to library from data
|
||||
*/
|
||||
public function saveSectionToLibraryFromData($data){
|
||||
|
||||
$dataForCreate = array();
|
||||
$title = UniteFunctionsUC::getVal($data, "section_title");
|
||||
$gridData = UniteFunctionsUC::getVal($data, "section_data");
|
||||
|
||||
$dataForCreate["title"] = $title;
|
||||
$dataForCreate["grid_data"] = $gridData;
|
||||
|
||||
$layoutType = GlobalsUC::ADDON_TYPE_LAYOUT_SECTION;
|
||||
|
||||
$dataForCreate["layout_type"] = $layoutType;
|
||||
|
||||
$isOverwrite = UniteFunctionsUC::getVal($data, "section_overwrite");
|
||||
$isOverwrite = UniteFunctionsUC::strToBool($isOverwrite);
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
|
||||
$record = null;
|
||||
if($isOverwrite == true)
|
||||
$record = $this->getLayoutRecordByTitle($title, $layoutType);
|
||||
|
||||
if($record){ //update
|
||||
|
||||
$objLayout->initByRecord($record);
|
||||
$objLayout->updateGridData($gridData);
|
||||
|
||||
$layoutID = $objLayout->getID();
|
||||
|
||||
}else{ //create
|
||||
|
||||
$catID = UniteFunctionsUC::getVal($data, "section_library_category");
|
||||
$dataForCreate["catid"] = $catID;
|
||||
|
||||
if($dataForCreate["catid"] == "new" || is_numeric($catID) == false || empty($catID)){
|
||||
|
||||
$newCatTitle = UniteFunctionsUC::getVal($data, "section_category_new");
|
||||
$objCat = new UniteCreatorCategory();
|
||||
$catCreateResponse = $objCat->add($newCatTitle, $layoutType);
|
||||
|
||||
$newCatID = $catCreateResponse["id"];
|
||||
|
||||
$dataForCreate["catid"] = $newCatID;
|
||||
}
|
||||
|
||||
$createResponse = $objLayout->create($dataForCreate);
|
||||
$layoutID = $createResponse["id"];
|
||||
}
|
||||
|
||||
|
||||
$response = array();
|
||||
$response["layoutid"] = $layoutID;
|
||||
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get layout grid data
|
||||
*/
|
||||
public function getLayoutGridDataForEditor($data){
|
||||
|
||||
$layoutID = UniteFunctionsUC::getVal($data, "layoutid");
|
||||
|
||||
$objLayout = new UniteCreatorLayout();
|
||||
$objLayout->initByID($layoutID);
|
||||
|
||||
$gridData = $objLayout->getGridDataForEditor();
|
||||
$gridData = json_encode($gridData);
|
||||
|
||||
$response = array();
|
||||
$response["grid_data"] = $gridData;
|
||||
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,878 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCreatorManager{
|
||||
|
||||
const TYPE_ADDONS = "addons";
|
||||
const TYPE_ITEMS_INLINE = "inline";
|
||||
const TYPE_PAGES = "pages";
|
||||
|
||||
const VIEW_TYPE_INFO = "info"; //addons view type
|
||||
const VIEW_TYPE_THUMB = "thumb";
|
||||
|
||||
protected $type = null, $arrText = array(), $arrOptions = array();
|
||||
protected $viewType = null; //view type in addition to type
|
||||
protected $managerName = null; //manager name
|
||||
protected $arrPassData = null; //pass data via js
|
||||
|
||||
protected $hasCats = true;
|
||||
|
||||
protected $objCats = null;
|
||||
protected $selectedCategory = "";
|
||||
|
||||
private $managerAddHtml = "";
|
||||
private $errorMessage = null;
|
||||
protected $itemsLoaderText = "";
|
||||
protected $textItemsSelected = "";
|
||||
protected $enableCatsActions = true;
|
||||
protected $listClassType = null;
|
||||
protected $enableStatusLineOperations = true;
|
||||
protected $hasHeaderLine = false;
|
||||
protected $headerLineText = null;
|
||||
protected $addClass = null;
|
||||
protected $putUpdateCatalogButton = false;
|
||||
protected $putDialogDebug = false;
|
||||
protected $enableActions = true; //enable add/edit actions
|
||||
|
||||
|
||||
protected function a_______REWRITE_FUNCTIONS________(){}
|
||||
|
||||
|
||||
/**
|
||||
* get manager by addon type
|
||||
*/
|
||||
public static function getObjManagerByAddonType($addonType, $data = array()){
|
||||
|
||||
$objAddonType = UniteCreatorAddonType::getAddonTypeObject($addonType);
|
||||
|
||||
$manager = UniteProviderFunctionsUC::applyFilters(UniteCreatorFilters::FILTER_GET_MANAGER_OBJECT_BYDATA, null, $data);
|
||||
|
||||
if(empty($manager)){
|
||||
if($objAddonType->isLayout == true)
|
||||
$manager = new UniteCreatorManagerLayouts();
|
||||
else
|
||||
$manager = new UniteCreatorManagerAddons();
|
||||
}
|
||||
|
||||
//init the manager inside
|
||||
$manager->setManagerNameFromData($data);
|
||||
|
||||
|
||||
return($manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* set header line text
|
||||
*/
|
||||
public function setHeaderLineText($text){
|
||||
|
||||
$this->headerLineText = $text;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* before init - function for override
|
||||
*/
|
||||
protected function beforeInit($type){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* run after init - function for override
|
||||
*/
|
||||
protected function afterInit($type){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put items buttons
|
||||
*/
|
||||
protected function putItemsButtons(){
|
||||
|
||||
?>
|
||||
put buttons from child classes
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put filters - function for override
|
||||
*/
|
||||
protected function putItemsFilters(){}
|
||||
|
||||
|
||||
/**
|
||||
* ge tmenu single item
|
||||
*/
|
||||
protected function getMenuSingleItem(){
|
||||
|
||||
$arrMenuItem = array();
|
||||
$arrMenuItem["no_action"] = esc_html__("No Action","unlimited-elements-for-elementor");
|
||||
|
||||
return($arrMenuItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* get item field menu
|
||||
*/
|
||||
protected function getMenuField(){
|
||||
|
||||
$arrMenuField = array();
|
||||
$arrMenuField["no_action"] = esc_html__("No Action","unlimited-elements-for-elementor");
|
||||
|
||||
return($arrMenuField);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put additional html here
|
||||
*/
|
||||
protected function putAddHtml(){
|
||||
dmp("put add html here by child class");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get no items text
|
||||
*/
|
||||
protected function getNoItemsText(){
|
||||
|
||||
$text = esc_html__("No Items", "unlimited-elements-for-elementor");
|
||||
|
||||
return($text);
|
||||
}
|
||||
|
||||
protected function a_________SET_DATA_BEFORE_PUT________(){}
|
||||
|
||||
|
||||
/**
|
||||
* set manager add html, must be called before put
|
||||
*/
|
||||
protected function setManagerAddHtml($addHtml){
|
||||
$this->managerAddHtml = $addHtml;
|
||||
}
|
||||
|
||||
protected function a_______CATEGORIES_RELATED___________(){}
|
||||
|
||||
|
||||
/**
|
||||
* get category list
|
||||
*/
|
||||
protected function getCatList(){
|
||||
|
||||
dmp("getCatList - function for override!!!");
|
||||
UniteFunctionsUC::showTrace();
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put categories html
|
||||
*/
|
||||
private function putHtmlCats($htmlCatList = null){
|
||||
|
||||
if(empty($htmlCatList))
|
||||
$htmlCatList = $this->getCatList();
|
||||
|
||||
$showAllButtons = false;
|
||||
|
||||
?>
|
||||
<div id="categories_wrapper" class="categories_wrapper unselectable">
|
||||
|
||||
<div class="manager-cats-buttons">
|
||||
<span class="manager-cats-title"><?php esc_html_e("Categories","unlimited-elements-for-elementor")?></span>
|
||||
<?php if($this->enableCatsActions == true):?>
|
||||
|
||||
<a id="button_add_category" data-action="add_category" type="button" class="uc-cat-action-button uc-button-add-cat">+</a>
|
||||
<?php endif?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div id="cats_section" class="cats_section">
|
||||
<div class="cat_list_wrapper">
|
||||
<ul id="list_cats" class="list_cats">
|
||||
<?php echo UniteProviderFunctionsUC::escCombinedHtml($htmlCatList)?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put category edit dialog
|
||||
*/
|
||||
protected function putDialogEditCategory(){
|
||||
?>
|
||||
<div id="uc_dialog_edit_category" title="<?php esc_html_e("Edit Category","unlimited-elements-for-elementor")?>" style="display:none;" >
|
||||
|
||||
<div class="unite-dialog-top"></div>
|
||||
|
||||
<?php esc_html_e("Category ID", "unlimited-elements-for-elementor")?>: <b><span id="span_catdialog_id"></span></b>
|
||||
|
||||
<br><br>
|
||||
|
||||
<?php esc_html_e("Edit Title", "unlimited-elements-for-elementor")?>:
|
||||
<input type="text" id="uc_dialog_edit_category_title" class="unite-input-regular">
|
||||
|
||||
<?php
|
||||
$prefix = "uc_dialog_edit_category";
|
||||
$buttonTitle = esc_html__("Update Category", "unlimited-elements-for-elementor");
|
||||
$loaderTitle = esc_html__("Updating Category...", "unlimited-elements-for-elementor");
|
||||
$successTitle = esc_html__("Category Updated", "unlimited-elements-for-elementor");
|
||||
HelperHtmlUC::putDialogActions($prefix, $buttonTitle, $loaderTitle, $successTitle);
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put add category dialog
|
||||
*/
|
||||
protected function putDialogAddCategory(){
|
||||
?>
|
||||
|
||||
<div id="uc_dialog_add_category" title="<?php esc_html_e("Add New Category","unlimited-elements-for-elementor")?>" style="display:none;" class="unite-inputs">
|
||||
|
||||
<div class="unite-dialog-top"></div>
|
||||
<div class="unite-inputs-label"><?php esc_html_e("Enter Category Name", "unlimited-elements-for-elementor")?></div>
|
||||
|
||||
<input id="uc_dialog_add_category_catname" type="text" class="unite-input-regular" value="">
|
||||
|
||||
<?php
|
||||
$prefix = "uc_dialog_add_category";
|
||||
$buttonTitle = esc_html__("Create Category", "unlimited-elements-for-elementor");
|
||||
$loaderTitle = esc_html__("Adding Category...", "unlimited-elements-for-elementor");
|
||||
$successTitle = esc_html__("Category Added", "unlimited-elements-for-elementor");
|
||||
HelperHtmlUC::putDialogActions($prefix, $buttonTitle, $loaderTitle, $successTitle);
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put add category dialog
|
||||
*/
|
||||
protected function putDialogDeleteCategory(){
|
||||
?>
|
||||
<div id="uc_dialog_delete_category" title="<?php esc_html_e("Delete Category","unlimited-elements-for-elementor")?>" style="display:none;" class="unite-inputs">
|
||||
|
||||
<div class="unite-dialog-top"></div>
|
||||
|
||||
<?php esc_html_e("Are you sure you want to delete the: ")?>
|
||||
|
||||
<b><span id="uc_dialog_delete_category_catname"></span></b>
|
||||
|
||||
<?php esc_html_e(" category and all it's widgets?")?>
|
||||
|
||||
<?php
|
||||
$prefix = "uc_dialog_delete_category";
|
||||
$buttonTitle = esc_html__("Delete Category", "unlimited-elements-for-elementor");
|
||||
$loaderTitle = esc_html__("Deleting Category...", "unlimited-elements-for-elementor");
|
||||
$successTitle = esc_html__("Category and it's addons Deleted", "unlimited-elements-for-elementor");
|
||||
HelperHtmlUC::putDialogActions($prefix, $buttonTitle, $loaderTitle, $successTitle);
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get category menu
|
||||
*/
|
||||
protected function getMenuCategory(){
|
||||
|
||||
$arrMenuCat = array();
|
||||
$arrMenuCat["no_action"] = esc_html__("No Action","unlimited-elements-for-elementor");
|
||||
|
||||
return($arrMenuCat);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put some right menu
|
||||
*/
|
||||
protected function putRightMenu($arrMenu, $menuID, $menuType){
|
||||
|
||||
?>
|
||||
|
||||
<!-- Right menu <?php echo esc_html($menuType)?> -->
|
||||
<ul id="<?php echo esc_attr($menuID)?>" class="unite-context-menu" data-type="<?php echo esc_attr($menuType)?>" style="display:none">
|
||||
<?php foreach($arrMenu as $operation=>$text):
|
||||
$class = "";
|
||||
if(is_array($text)){
|
||||
$arr = $text;
|
||||
$text = $arr["text"];
|
||||
$class = UniteFunctionsUC::getVal($arr, "class");
|
||||
}
|
||||
|
||||
if(!empty($class)){
|
||||
$class = esc_attr($class);
|
||||
$class = "class='$class'";
|
||||
}
|
||||
?>
|
||||
<li>
|
||||
<a href="javascript:void(0)" data-operation="<?php echo esc_attr($operation)?>" <?php echo UniteProviderFunctionsUC::escAddParam($class)?>><?php echo esc_html($text)?></a>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put right menu category
|
||||
*/
|
||||
private function putMenuCategory(){
|
||||
|
||||
//init category menu
|
||||
$arrMenuCat = $this->getMenuCategory();
|
||||
|
||||
$this->putRightMenu($arrMenuCat, "rightmenu_cat", "category");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put right menu category field
|
||||
*/
|
||||
private function putMenuCatField(){
|
||||
|
||||
//init category field menu
|
||||
$arrMenuCatField = array();
|
||||
$arrMenuCatField["add_category"] = __("Add Category","unlimited-elements-for-elementor");
|
||||
|
||||
if($this->enableCatsActions == false){
|
||||
$arrMenuCatField = array();
|
||||
$arrMenuCatField["no_action"] = __("No Action","unlimited-elements-for-elementor");
|
||||
}
|
||||
|
||||
$this->putRightMenu($arrMenuCatField, "rightmenu_catfield", "category_field");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put categories related items
|
||||
*/
|
||||
protected function putCatRelatedItems(){
|
||||
|
||||
$this->putMenuCopyMove();
|
||||
$this->putMenuCategory();
|
||||
$this->putMenuCatField();
|
||||
$this->putDialogEditCategory();
|
||||
$this->putDialogAddCategory();
|
||||
$this->putDialogDeleteCategory();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function a___________MAIN_FUNCTIONS_________(){}
|
||||
|
||||
|
||||
/**
|
||||
* validate inited function
|
||||
*/
|
||||
private function validateInited(){
|
||||
|
||||
if(empty($this->type))
|
||||
UniteFunctionsUC::throwError("The manager is not inited");
|
||||
}
|
||||
|
||||
/**
|
||||
* function for override
|
||||
*/
|
||||
protected function putInitItems(){}
|
||||
|
||||
|
||||
/**
|
||||
* function for override
|
||||
*/
|
||||
protected function putListWrapperContent(){}
|
||||
|
||||
|
||||
/**
|
||||
* put after buttons html
|
||||
*/
|
||||
protected function putHtmlAfterButtons(){}
|
||||
|
||||
/**
|
||||
* put items wrapper html
|
||||
*/
|
||||
private function putItemsWrapper(){
|
||||
|
||||
$addClass = "";
|
||||
if(!empty($this->viewType)){
|
||||
$addClass = " listitems-view-".esc_attr($this->viewType);
|
||||
}
|
||||
|
||||
$listClass = "uc-listitems-".$this->type;
|
||||
if(!empty($this->listClassType))
|
||||
$listClass = "uc-listitems-".$this->listClassType;
|
||||
|
||||
?>
|
||||
<div class="items_wrapper unselectable">
|
||||
|
||||
<?php if($this->enableActions == true):?>
|
||||
<div id="manager_buttons" class="manager_buttons">
|
||||
|
||||
<?php $this->putItemsButtons()?>
|
||||
|
||||
</div>
|
||||
<?php endif?>
|
||||
|
||||
<?php $this->putHtmlAfterButtons()?>
|
||||
|
||||
<hr>
|
||||
|
||||
<?php $this->putItemsFilters()?>
|
||||
|
||||
<div id="items_outer" class="items_outer">
|
||||
|
||||
<div id="items_list_wrapper" class="items_list_wrapper unselectable">
|
||||
<div id="items_loader" class="items_loader" style="display:none;">
|
||||
<?php echo esc_html($this->itemsLoaderText)?>...
|
||||
</div>
|
||||
|
||||
<div id="no_items_text" class="no_items_text" style="display:none;">
|
||||
<?php echo UniteProviderFunctionsUC::escCombinedHtml($this->getNoItemsText())?>
|
||||
</div>
|
||||
|
||||
<?php $this->putListWrapperContent()?>
|
||||
|
||||
<ul id="uc_list_items" class="list_items unselectable <?php echo esc_attr($listClass)?> <?php echo esc_attr($addClass)?>"><?php $this->putInitItems()?></ul>
|
||||
<div id="drag_indicator" class="drag_indicator" style="display:none;"></div>
|
||||
<div id="shadow_bar" class="shadow_bar" style="display:none"></div>
|
||||
<div id="select_bar" class="select_bar" style="display:none"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get html categories select
|
||||
*/
|
||||
protected function getHtmlSelectCats(){
|
||||
|
||||
echo("getHtmlSelectCats: function for override");
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* put status line operations additions
|
||||
* funciton for override
|
||||
*/
|
||||
protected function putStatusLineOperationsAdditions(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* html status operations html
|
||||
*/
|
||||
private function putStatusLineOperations(){
|
||||
|
||||
?>
|
||||
|
||||
<div class="status_operations">
|
||||
<div class="status_num_selected">
|
||||
<span id="num_items_selected">0</span> <?php echo esc_attr($this->textItemsSelected)?>
|
||||
</div>
|
||||
|
||||
<?php if($this->hasCats == true):
|
||||
$htmlCatSelect = $this->getHtmlSelectCats();
|
||||
?>
|
||||
|
||||
<div id="item_operations_wrapper" class="item_operations_wrapper unite-disabled">
|
||||
|
||||
<?php esc_html_e("Move To", "unlimited-elements-for-elementor")?>
|
||||
|
||||
<select id="select_item_category" disabled="disabled">
|
||||
<?php echo UniteProviderFunctionsUC::escCombinedHtml($htmlCatSelect) ?>
|
||||
</select>
|
||||
|
||||
<a id="button_items_operation" class="unite-button-secondary button-disabled" href="javascript:void(0)">GO</a>
|
||||
</div>
|
||||
|
||||
<?php endif?>
|
||||
|
||||
<?php $this->putStatusLineOperationsAdditions()?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put status line html
|
||||
*/
|
||||
private function putStatusLine(){
|
||||
|
||||
?>
|
||||
<div class="status_line">
|
||||
|
||||
<?php
|
||||
if($this->enableStatusLineOperations == true)
|
||||
$this->putStatusLineOperations();
|
||||
?>
|
||||
<div class="status_loader_wrapper">
|
||||
<div id="status_loader" class="status_loader" style="display:none;"></div>
|
||||
</div>
|
||||
|
||||
<div class="status_text_wrapper">
|
||||
<span id="status_text" class="status_text" style="display:none;"></span>
|
||||
</div>
|
||||
|
||||
<?php if($this->putDialogDebug == true):?>
|
||||
<a href="javascript:void(0)" class="manager-button-debug-dialog" title="<?php _e("Show Debug Data","unlimited-elements-for-elementor")?>">
|
||||
<i class="fas fa-question"></i>
|
||||
</a>
|
||||
<?php endif?>
|
||||
|
||||
<?php if($this->putUpdateCatalogButton == true):?>
|
||||
<a href="javascript:void(0)" class="manager-button-update-catalog" title="<?php _e("Update Catalog","unlimited-elements-for-elementor")?>">
|
||||
<i class="fas fa-sync"></i>
|
||||
</a>
|
||||
<?php endif?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* put copy move menu
|
||||
*/
|
||||
private function putMenuCopyMove(){
|
||||
?>
|
||||
<ul id="menu_copymove" class="unite-context-menu" style="display:none">
|
||||
<li>
|
||||
<a href="javascript:void(0)" data-operation="copymove_move"><?php esc_html_e("Move Here","unlimited-elements-for-elementor")?></a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* put single item menu
|
||||
*/
|
||||
private function putMenuSingleItem(){
|
||||
|
||||
$arrMenuItem = $this->getMenuSingleItem();
|
||||
|
||||
if(!is_array($arrMenuItem))
|
||||
$arrMenuItem = array();
|
||||
|
||||
$this->putRightMenu($arrMenuItem, "rightmenu_item", "single_item");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get multiple items menu
|
||||
*/
|
||||
protected function getMenuMulitipleItems(){
|
||||
$arrMenuItemMultiple = array();
|
||||
$arrMenuItemMultiple["no_action"] = __("No Action","unlimited-elements-for-elementor");
|
||||
return($arrMenuItemMultiple);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put multiple items menu
|
||||
*/
|
||||
private function putMenuMultipleItems(){
|
||||
|
||||
$arrMenuItemMultiple = $this->getMenuMulitipleItems();
|
||||
|
||||
?>
|
||||
<!-- Right menu multiple -->
|
||||
|
||||
<ul id="rightmenu_item_multiple" class="unite-context-menu" style="display:none">
|
||||
<?php foreach($arrMenuItemMultiple as $operation=>$text):?>
|
||||
<li>
|
||||
<a href="javascript:void(0)" data-operation="<?php echo esc_attr($operation)?>"><?php echo esc_html($text)?></a>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put right menu field
|
||||
*/
|
||||
private function putMenuField(){
|
||||
|
||||
$arrMenuField = $this->getMenuField();
|
||||
|
||||
|
||||
?>
|
||||
<!-- Right menu field -->
|
||||
<ul id="rightmenu_field" class="unite-context-menu" style="display:none">
|
||||
<?php foreach($arrMenuField as $operation=>$text):?>
|
||||
<li>
|
||||
<a href="javascript:void(0)" data-operation="<?php echo esc_attr($operation)?>"><?php echo esc_html($text)?></a>
|
||||
</li>
|
||||
<?php endforeach?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set view type
|
||||
*/
|
||||
public function setViewType($viewType){
|
||||
$this->viewType = $viewType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get manager name
|
||||
*/
|
||||
public function getManagerName(){
|
||||
|
||||
return($this->managerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* set manager name
|
||||
*/
|
||||
public function setManagerName($name){
|
||||
|
||||
$this->managerName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the pass data to js / php interface
|
||||
*/
|
||||
public function addPassData($key, $value){
|
||||
|
||||
if(empty($this->arrPassData))
|
||||
$this->arrPassData = array();
|
||||
|
||||
|
||||
$this->arrPassData[$key] = $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* put scripts according manager type
|
||||
*/
|
||||
public static function putScriptsIncludes($type){
|
||||
|
||||
//clear dropzone third party inclues
|
||||
UniteFunctionsWPUC::findAndRemoveInclude("dropzone.min");
|
||||
|
||||
|
||||
HelperUC::addScript("dropzone", "dropzone_js","js/dropzone");
|
||||
HelperUC::addStyle("dropzone", "dropzone_css","js/dropzone");
|
||||
|
||||
HelperUC::addScript("unitecreator_manager_items","unitecreator_manager_items","js/manager");
|
||||
HelperUC::addScript("unitecreator_manager","unitecreator_manager","js/manager");
|
||||
HelperUC::addStyle("unitecreator_manager","unitecreator_manager_css");
|
||||
|
||||
switch($type){
|
||||
case self::TYPE_PAGES:
|
||||
case self::TYPE_ADDONS:
|
||||
HelperUC::addScript("unitecreator_manager_cats","unitecreator_manager_cats","js/manager");
|
||||
HelperUC::addScript("unitecreator_manager_actions_addons","unitecreator_manager_actions_addons","js/manager");
|
||||
HelperUC::addScript("unitecreator_browser","unitecreator_browser");
|
||||
HelperUC::addStyle("unitecreator_browser","unitecreator_browser_css");
|
||||
break;
|
||||
case self::TYPE_ITEMS_INLINE:
|
||||
HelperUC::addScript("unitecreator_params_dialog", "unitecreator_params_dialog");
|
||||
HelperUC::addScript("unitecreator_manager_actions_inline","unitecreator_manager_actions_inline","js/manager");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* call it before put html, function for override
|
||||
*/
|
||||
protected function onBeforePutHtml(){}
|
||||
|
||||
/**
|
||||
* put html header line
|
||||
* function for override
|
||||
*/
|
||||
protected function putHtmlHeaderLine(){}
|
||||
|
||||
|
||||
/**
|
||||
* output manager html
|
||||
*/
|
||||
public function outputHtml(){
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
$this->onBeforePutHtml();
|
||||
|
||||
$addClass = "";
|
||||
if($this->hasCats == false)
|
||||
$addClass = " uc-nocats ";
|
||||
|
||||
$managerClass = "uc-manager-".$this->type;
|
||||
|
||||
if(!empty($this->addClass))
|
||||
$managerClass .= " ".$this->addClass;
|
||||
|
||||
$htmlPassData = "";
|
||||
if(!empty($this->arrPassData))
|
||||
$htmlPassData = UniteFunctionsUC::jsonEncodeForHtmlData($this->arrPassData,"passdata");
|
||||
|
||||
//add text
|
||||
if(!empty($this->arrText)){
|
||||
$optionText = UniteFunctionsUC::jsonEncodeForHtmlData($this->arrText, "text");
|
||||
if(!empty($optionText))
|
||||
$this->managerAddHtml .= " ".$optionText;
|
||||
}
|
||||
|
||||
if(!empty($this->arrOptions)){
|
||||
$optionOptions = UniteFunctionsUC::jsonEncodeForHtmlData($this->arrOptions, "options");
|
||||
if(!empty($optionOptions))
|
||||
$this->managerAddHtml .= " ".$optionOptions;
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
$htmlCatList = $this->getCatList();
|
||||
|
||||
$isNoCats = empty($htmlCatList);
|
||||
|
||||
HelperHtmlUC::putHtmlAdminNotices();
|
||||
|
||||
?>
|
||||
|
||||
<div id="uc_managerw" class="uc-manager-outer <?php echo esc_attr($managerClass)?>" data-managername="<?php echo esc_attr($this->managerName)?>" data-type="<?php echo esc_attr($this->type)?>" <?php echo UniteProviderFunctionsUC::escAddParam($htmlPassData)?> <?php echo UniteProviderFunctionsUC::escAddParam($this->managerAddHtml)?>>
|
||||
|
||||
<?php if($this->hasHeaderLine == true)
|
||||
$this->putHtmlHeaderLine();
|
||||
?>
|
||||
|
||||
<div class="manager_wrapper <?php echo esc_attr($addClass)?> unselectable" >
|
||||
|
||||
<?php if($this->hasCats == true): ?>
|
||||
|
||||
<table class="layout_table" width="100%" cellpadding="0" cellspacing="0">
|
||||
|
||||
<tr>
|
||||
<td class="cell_cats" width="220px" valign="top">
|
||||
<?php $this->putHtmlCats($htmlCatList)?>
|
||||
</td>
|
||||
|
||||
<td class="cell_items" valign="top">
|
||||
|
||||
<?php $this->putItemsWrapper()?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
|
||||
<?php $this->putStatusLine() ?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<?php else:?>
|
||||
|
||||
<?php
|
||||
$this->putItemsWrapper();
|
||||
$this->putStatusLine();
|
||||
?>
|
||||
|
||||
|
||||
<?php endif?>
|
||||
|
||||
</div> <!-- end manager wrapper -->
|
||||
|
||||
<div id="manager_shadow_overlay" class="manager_shadow_overlay" style="display:none"></div>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
$this->putMenuSingleItem();
|
||||
$this->putMenuMultipleItems();
|
||||
$this->putMenuField();
|
||||
|
||||
if($this->hasCats)
|
||||
$this->putCatRelatedItems();
|
||||
|
||||
$this->putAddHtml();
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}catch(Exception $e){
|
||||
$message = "<br><br>manager error: <b>".$e->getMessage()."</b>";
|
||||
|
||||
echo "</div>";
|
||||
echo "</div>";
|
||||
echo "</div>";
|
||||
|
||||
echo "<div class='unite-color-red'>".esc_html($message)."</div>";
|
||||
|
||||
if(GlobalsUC::$SHOW_TRACE == true)
|
||||
dmp($e->getTraceAsString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init manager
|
||||
*/
|
||||
public function init($type = ""){
|
||||
|
||||
$this->beforeInit($type);
|
||||
|
||||
//the type should be set already in child classes
|
||||
$this->validateInited();
|
||||
|
||||
$this->itemsLoaderText = __("Getting Items", "unlimited-elements-for-elementor");
|
||||
$this->textItemsSelected = __("items selected","unlimited-elements-for-elementor");
|
||||
|
||||
if($this->hasCats){
|
||||
$this->objCats = new UniteCreatorCategories();
|
||||
$this->selectedCategory = "";
|
||||
}
|
||||
|
||||
$this->afterInit($type);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCreatorManagerInline extends UniteCreatorManager{
|
||||
|
||||
private $startAddon;
|
||||
private $itemsType;
|
||||
private $source = "";
|
||||
|
||||
|
||||
/**
|
||||
* construct the manager
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->type = self::TYPE_ITEMS_INLINE;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* set source
|
||||
*/
|
||||
public function setSource($source){
|
||||
|
||||
$this->source = $source;
|
||||
$this->arrOptions["source"] = $source;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate that the start addon exists
|
||||
*/
|
||||
private function validateStartAddon(){
|
||||
|
||||
if(empty($this->startAddon))
|
||||
UniteFunctionsUC::throwError("The start addon not given");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the data from start addon
|
||||
*/
|
||||
private function initStartAddonData(){
|
||||
|
||||
$this->itemsType = $this->startAddon->getItemsType();
|
||||
|
||||
//set init data
|
||||
$arrItems = $this->startAddon->getArrItemsForConfig();
|
||||
|
||||
$strItems = "";
|
||||
if(!empty($arrItems)){
|
||||
$strItems = json_encode($arrItems);
|
||||
$strItems = htmlspecialchars($strItems);
|
||||
}
|
||||
|
||||
$addHtml = " data-init-items=\"{$strItems}\" ";
|
||||
|
||||
$this->setManagerAddHtml($addHtml);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set start addon
|
||||
*/
|
||||
public function setStartAddon($addon){
|
||||
$this->startAddon = new UniteCreatorAddon(); //just for code completion
|
||||
$this->startAddon = $addon;
|
||||
|
||||
$this->initStartAddonData();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get category list
|
||||
*/
|
||||
protected function getCatList($selectCatID = null, $arrCats = null, $params = array()){
|
||||
|
||||
$htmlCatList = "";
|
||||
|
||||
return($htmlCatList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get single item menu
|
||||
*/
|
||||
protected function getMenuSingleItem(){
|
||||
|
||||
$arrMenuItem = array();
|
||||
$arrMenuItem["edit_item"] = esc_html__("Edit Item","unlimited-elements-for-elementor");
|
||||
$arrMenuItem["remove_items"] = esc_html__("Delete","unlimited-elements-for-elementor");
|
||||
$arrMenuItem["duplicate_items"] = esc_html__("Duplicate","unlimited-elements-for-elementor");
|
||||
|
||||
return($arrMenuItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* get multiple items menu
|
||||
*/
|
||||
protected function getMenuMulitipleItems(){
|
||||
$arrMenuItemMultiple = array();
|
||||
$arrMenuItemMultiple["remove_items"] = esc_html__("Delete","unlimited-elements-for-elementor");
|
||||
$arrMenuItemMultiple["duplicate_items"] = esc_html__("Duplicate","unlimited-elements-for-elementor");
|
||||
return($arrMenuItemMultiple);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get item field menu
|
||||
*/
|
||||
protected function getMenuField(){
|
||||
$arrMenuField = array();
|
||||
$arrMenuField["add_item"] = esc_html__("Add Item","unlimited-elements-for-elementor");
|
||||
$arrMenuField["select_all"] = esc_html__("Select All","unlimited-elements-for-elementor");
|
||||
|
||||
return($arrMenuField);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put items buttons
|
||||
*/
|
||||
protected function putItemsButtons(){
|
||||
|
||||
$this->validateStartAddon();
|
||||
|
||||
$itemType = $this->startAddon->getItemsType();
|
||||
|
||||
$buttonClass = "unite-button-primary button-disabled uc-button-item uc-button-add";
|
||||
|
||||
//put add item button according the type
|
||||
switch($itemType){
|
||||
default:
|
||||
case UniteCreatorAddon::ITEMS_TYPE_DEFAULT:
|
||||
?>
|
||||
<a data-action="add_item" type="button" class="<?php echo esc_attr($buttonClass)?>"><?php esc_html_e("Add Item","unlimited-elements-for-elementor")?></a>
|
||||
<?php
|
||||
break;
|
||||
case UniteCreatorAddon::ITEMS_TYPE_IMAGE:
|
||||
?>
|
||||
<a data-action="add_images" type="button" class="<?php echo esc_attr($buttonClass)?>"><?php esc_html_e("Add Images","unlimited-elements-for-elementor")?></a>
|
||||
<?php
|
||||
break;
|
||||
case UniteCreatorAddon::ITEMS_TYPE_FORM:
|
||||
?>
|
||||
<a data-action="add_form_item" type="button" class="<?php echo esc_attr($buttonClass)?>"><?php esc_html_e("Add Form Item","unlimited-elements-for-elementor")?></a>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
<a data-action="select_all_items" type="button" class="unite-button-secondary button-disabled uc-button-item uc-button-select" data-textselect="<?php esc_html_e("Select All","unlimited-elements-for-elementor")?>" data-textunselect="<?php esc_html_e("Unselect All","unlimited-elements-for-elementor")?>"><?php esc_html_e("Select All","unlimited-elements-for-elementor")?></a>
|
||||
<a data-action="duplicate_items" type="button" class="unite-button-secondary button-disabled uc-button-item"><?php esc_html_e("Duplicate","unlimited-elements-for-elementor")?></a>
|
||||
<a data-action="remove_items" type="button" class="unite-button-secondary button-disabled uc-button-item"><?php esc_html_e("Delete","unlimited-elements-for-elementor")?></a>
|
||||
<a data-action="edit_item" type="button" class="unite-button-secondary button-disabled uc-button-item uc-single-item"><?php esc_html_e("Edit Item","unlimited-elements-for-elementor")?> </a>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put add edit item dialog
|
||||
*/
|
||||
private function putAddEditDialog(){
|
||||
|
||||
$isLoadByAjax = $this->startAddon->isEditorItemsAttributeExists();
|
||||
|
||||
|
||||
$addHtml = "";
|
||||
if($isLoadByAjax == true){
|
||||
|
||||
$addonID = $this->startAddon->getID();
|
||||
$addonID = esc_attr($addonID);
|
||||
$addHtml = "data-initbyaddon=\"{$addonID}\"";
|
||||
}
|
||||
|
||||
?>
|
||||
<div title="<?php esc_html_e("Edit Item","unlimited-elements-for-elementor")?>" class="uc-dialog-edit-item" style="display:none">
|
||||
<div class="uc-item-config-settings" autofocus="true" <?php echo UniteProviderFunctionsUC::escAddParam($addHtml);?>>
|
||||
|
||||
<?php if($isLoadByAjax == false):
|
||||
|
||||
if($this->startAddon)
|
||||
$this->startAddon->putHtmlItemConfig();
|
||||
?>
|
||||
<?php else: //load by ajax?>
|
||||
|
||||
<div class="unite-dialog-loader-wrapper">
|
||||
<div class="unite-dialog-loader"><?php esc_html_e("Loading Settings", "unlimited-elements-for-elementor")?>...</div>
|
||||
</div>
|
||||
|
||||
<?php endif?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put form dialog
|
||||
*/
|
||||
protected function putFormItemsDialog(){
|
||||
|
||||
$objDialogParam = new UniteCreatorDialogParam();
|
||||
$objDialogParam->init(UniteCreatorDialogParam::TYPE_FORM_ITEM, $this->startAddon);
|
||||
$objDialogParam->outputHtml();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put additional html here
|
||||
*/
|
||||
protected function putAddHtml(){
|
||||
|
||||
if($this->itemsType == UniteCreatorAddon::ITEMS_TYPE_FORM)
|
||||
$this->putFormItemsDialog();
|
||||
else
|
||||
$this->putAddEditDialog();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* before init
|
||||
*/
|
||||
protected function beforeInit($addonType){
|
||||
$this->hasCats = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorManagerLayouts extends UniteCreatorManagerAddons{
|
||||
|
||||
/**
|
||||
* construct the manager
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
$this->isLayouts = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
/**
|
||||
* plugin base
|
||||
*
|
||||
*/
|
||||
class UniteCreatorPluginBase extends UniteCreatorFilters{
|
||||
|
||||
protected $urlPlugin;
|
||||
protected $pathPlugin;
|
||||
|
||||
private $isRegistered = false;
|
||||
private $objPlugins;
|
||||
|
||||
|
||||
/**
|
||||
* set path and url plugin
|
||||
*/
|
||||
private function initPaths($pathPlugin){
|
||||
|
||||
if(empty($pathPlugin))
|
||||
return(false);
|
||||
|
||||
$this->pathPlugin = $pathPlugin;
|
||||
$this->urlPlugin = HelperUC::pathToFullUrl($this->pathPlugin);
|
||||
|
||||
//autoregister views path
|
||||
$pathViews = $this->pathPlugin."views/";
|
||||
if(is_dir($pathViews))
|
||||
$this->registerAdminViewPath($pathViews);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public function __construct($pathPlugin = null){
|
||||
|
||||
$this->initPaths($pathPlugin);
|
||||
|
||||
$this->objPlugins = new UniteCreatorPlugins();
|
||||
|
||||
//actions
|
||||
UniteProviderFunctionsUC::addAction(GlobalsProviderUC::ACTION_RUN_ADMIN, array($this,"runAdmin"));
|
||||
UniteProviderFunctionsUC::addAction(GlobalsProviderUC::ACTION_RUN_FRONT, array($this,"runFront"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate that the plugin is registered
|
||||
*/
|
||||
protected function validateRegistered(){
|
||||
|
||||
if($this->isRegistered == false)
|
||||
UniteFunctionsUC::throwError("The plugin is not registered");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register the plugin
|
||||
*/
|
||||
protected function register($name, $title, $version, $description, $params){
|
||||
|
||||
$this->objPlugins->registerPlugin($name, $title, $version, $description, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add action
|
||||
*/
|
||||
protected function addAction($tag, $function_to_add, $priority = 10, $accepted_args = 1){
|
||||
UniteProviderFunctionsUC::addAction($tag, array($this,$function_to_add),$priority, $accepted_args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add filter
|
||||
*/
|
||||
protected function addFilter($tag, $function_to_add, $priority = 10, $accepted_args = 1){
|
||||
UniteProviderFunctionsUC::addFilter($tag, array($this,$function_to_add), $priority, $accepted_args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register view alias
|
||||
*/
|
||||
public function registerViewAlias($alias, $view){
|
||||
|
||||
GlobalsUC::$arrViewAliases[$alias] = $view;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register admin view path
|
||||
*/
|
||||
public function registerAdminViewPath($path){
|
||||
|
||||
GlobalsUC::$arrAdminViewPaths[] = $path;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* register ajax action function
|
||||
* the callback should be: onStandAloneAjaxAction($found, $action, $data)
|
||||
* should be called from admin class
|
||||
*/
|
||||
public function registerAdminAjaxActionFunction($func){
|
||||
|
||||
UniteProviderFunctionsUC::addFilter(UniteCreatorFilters::FILTER_ADMIN_AJAX_ACTION, $func, 10, 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register dataset type
|
||||
*/
|
||||
protected function registerDatasetType($type, $title, $arrQueries){
|
||||
|
||||
$objDataset = new UniteCreatorDataset();
|
||||
$objDataset->registerDataset($type, $title, $arrQueries);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register custom addon type
|
||||
*/
|
||||
public function registerAddonType($typeName, $objAddonType){
|
||||
|
||||
if(isset(UniteCreatorAddonType::$arrTypesCache[$typeName]))
|
||||
UniteFunctionsUC::throwError("Addon type alrady exists: $typeName");
|
||||
|
||||
|
||||
UniteCreatorAddonType::$arrTypesCache[$typeName] = $objAddonType;
|
||||
}
|
||||
|
||||
/**
|
||||
* layout output mode
|
||||
*/
|
||||
public function registerLayoutOutputMode($mode, UniteCreatorLayoutOutputConfigBase $objConfig){
|
||||
|
||||
if(isset(UniteCreatorLayoutOutput::$arrOutputModes[$mode]))
|
||||
UniteFunctionsUC::throwError("Layout output mode already exists: ".$mode);
|
||||
|
||||
UniteCreatorLayoutOutput::$arrOutputModes[$mode] = $objConfig;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* run admin, function for override
|
||||
*/
|
||||
public function runAdmin(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* run front, function for override
|
||||
*/
|
||||
public function runFront(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCreatorFilters{
|
||||
|
||||
const FILTER_CLIENTSIDE_GENERAL_SETTINGS = "uc_get_client_general_settings";
|
||||
const FILTER_MODIFY_GENERAL_SETTINGS = "uc_modify_general_settings";
|
||||
const FILTER_MANAGER_MENU_SINGLE = "uc_manager_addons_menu_single";
|
||||
const FILTER_MANAGER_PAGES_MENU_SINGLE = "uc_manager_pages_menu_single";
|
||||
const FILTER_MANAGER_MENU_FIELD = "uc_manager_addons_menu_field";
|
||||
const FILTER_MANAGER_MENU_MULTIPLE = "uc_manager_addons_menu_multiple";
|
||||
const FILTER_MANAGER_MENU_CATEGORY = "uc_manager_addons_menu_category";
|
||||
const FILTER_MANAGER_ADDONS_PLUGINS = "uc_manager_addons_plugins";
|
||||
const FILTER_MANAGER_ADDON_ADDHTML = "addon_library_manager_addon_addhtml";
|
||||
const FILTER_MANAGER_LAYOUT_ADDHTML = "addon_library_manager_layout_addhtml";
|
||||
const FILTER_MANAGER_LAYOUT_LI_ADDHTML = "addon_library_manager_layout_li_addhtml";
|
||||
const FILTER_MANAGER_PAGE_ADD_ITEM_HTML = "addon_library_manager_page_add_item_html";
|
||||
const ACTION_MANAGER_PAGES_ADD_HTML = "uc_manager_pages_add_html";
|
||||
const FILTER_GET_MANAGER_OBJECT_BYDATA = "uc_get_manager_object_bydata";
|
||||
const FILTER_MANAGER_ADDONS_CATEGORY_SETTINGS = "uc_filter_manager_addons_category_settings";
|
||||
const FILTER_URL_LAYOUTS_LIST = "uc_filter_url_layouts_list";
|
||||
const FILTER_URL_TEMPLATES_LIST = "uc_filter_url_templates_list";
|
||||
const FILTER_GET_DATASET_RECORDS = "uc_filter_get_dataset_records";
|
||||
const FILTER_GET_DATASET_HEADERS = "uc_filter_get_dataset_headers";
|
||||
|
||||
|
||||
const FILTER_ADMIN_AJAX_ACTION = "addon_library_ajax_action";
|
||||
const FILTER_ADMIN_VIEW_FILEPATH = "addon_library_admin_view_filepath";
|
||||
const FILTER_MODIFY_URL_VIEW = "addon_library_modify_url_view";
|
||||
const FILTER_MODIFY_URL_LAYOUT_PREVIEW_FRONT = "addon_library_modify_url_layout_preview_front";
|
||||
const FILTER_LAYOUTS_ACTIONS_COL_WIDTH = "addon_library_layouts_actions_colwidth";
|
||||
const FILTER_EXPORT_ADDON_DATA = "addon_library_export_addon_data";
|
||||
const FILTER_EXPORT_CAT_TITLE = "addon_library_export_cat_title";
|
||||
const FILTER_PARAMS_DIALOG_MAIN_PARAMS = "addon_library_params_dialog_main_param";
|
||||
const FILTER_GET_GENERAL_SETTINGS_FILEPATH = "addon_library_get_general_settings_filepath";
|
||||
const FILTER_ADD_ADDON_OUTPUT_CONSTANT_DATA = "addon_library_add_constant_data";
|
||||
const FILTER_LAYOUT_PROPERTIES_SETTINGS = "addon_library_get_layout_properties_settings";
|
||||
const FILTER_MODIFY_ADDON_OUTPUT_PARAMS = "addon_library_modify_addon_output_params";
|
||||
|
||||
const ACTION_VALIDATE_GENERAL_SETTINGS = "uc_validate_general_settings";
|
||||
const ACTION_MANAGER_ITEM_BUTTONS1 = "uc_manager_action_item_buttons1";
|
||||
const ACTION_MANAGER_ITEM_BUTTONS2 = "uc_manager_action_item_buttons2";
|
||||
const ACTION_MANAGER_ITEM_BUTTONS3 = "uc_manager_action_item_buttons3";
|
||||
const ACTION_MANAGER_PAGES_ITEM_BUTTONS = "uc_manager_pages_action_item_buttons";
|
||||
|
||||
const ACTION_EDIT_ADDON_EXTRA_BUTTONS = "addon_library_addon_edit_extra_buttons";
|
||||
const ACTION_EDIT_GLOBALS = "addon_library_edit_globals";
|
||||
const ACTION_BOTTOM_PLUGIN_VERSION = "addon_library_bottom_plugin_version";
|
||||
const ACTION_ADD_ADMIN_SCRIPTS = "addon_library_add_admin_scripts";
|
||||
const ACTION_ADD_LAYOUT_TOOLBAR_BUTTON = "addon_library_add_layout_toolbar_button";
|
||||
const ACTION_ADD_LAYOUTS_TOOLBAR_BUTTON = "addon_library_add_layouts_toolbar_button";
|
||||
const ACTION_ADD_ADDONS_TOOLBAR_BUTTON = "addon_library_add_addons_toolbar_button";
|
||||
const ACTION_LAYOUT_EDIT_HTML = "addon_library_layout_edit_html";
|
||||
const ACTION_MODIFY_ADDONS_MANAGER = "addon_library_modify_addons_manager";
|
||||
const ACTION_LAYOUTS_LIST_ACTIONS = "addon_library_layouts_list_actions";
|
||||
const ACTION_EDIT_ADDON_ADDSETTINGS = "addon_library_edit_addon_addsettings";
|
||||
const ACTION_AFTER_LAYOUT_PREVIEW_OUTPUT = "addon_library_after_layout_preview_output";
|
||||
const ACTION_AFTER_IMPORT_LAYOUT_FILE = "addon_library_after_import_layout_file";
|
||||
const ACTION_AFTER_IMPORT_LAYOUT_FILE_IMAGES = "addon_library_after_import_layout_images";
|
||||
const ACTION_BEFORE_ADMIN_INIT = "addon_library_before_admin_init";
|
||||
const ACTION_RUN_AFTER_INCLUDES = "addon_library_action_run_after_includes";
|
||||
const ACTION_AFTER_INIT_GLOBALS = "addon_library_after_init_globals";
|
||||
|
||||
const ACTION_ADDON_AFTER_UPDATE = "uc_addon_after_update";
|
||||
const ACTION_ADDON_AFTER_DELETE = "uc_addon_after_delete";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
|
||||
class UniteCreatorPlugins extends UniteCreatorFilters{
|
||||
|
||||
private static $isInited = false;
|
||||
private static $arrPlugins = array();
|
||||
|
||||
|
||||
/**
|
||||
* register plugin
|
||||
*/
|
||||
public function registerPlugin($name, $title, $version, $description, $params=null){
|
||||
|
||||
$arrPlugin = array();
|
||||
$arrPlugin["name"] = $name;
|
||||
$arrPlugin["title"] = $title;
|
||||
$arrPlugin["version"] = $version;
|
||||
$arrPlugin["description"] = $description;
|
||||
|
||||
if(!empty($params) && is_array($params))
|
||||
$arrPlugin = array_merge($arrPlugin, $params);
|
||||
|
||||
self::$arrPlugins[$name] = $arrPlugin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init plugins
|
||||
*/
|
||||
public function initPlugins(){
|
||||
|
||||
if(self::$isInited == true)
|
||||
UniteFunctionsUC::throwError("The plugins are already inited");
|
||||
|
||||
$arrPaths = UniteProviderFunctionsUC::getArrPluginsPaths();
|
||||
|
||||
foreach($arrPaths as $path){
|
||||
if(file_exists($path) == false)
|
||||
continue;
|
||||
|
||||
require_once $path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get arr plugins
|
||||
*/
|
||||
public function getArrPlugins(){
|
||||
|
||||
return(self::$arrPlugins);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if plugin exists by name
|
||||
*/
|
||||
public function isPluginExists($name){
|
||||
|
||||
if(empty(self::$arrPlugins))
|
||||
return(false);
|
||||
|
||||
if(array_key_exists($name, self::$arrPlugins) == true)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,802 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorActions{
|
||||
|
||||
|
||||
/**
|
||||
* on update layout response, function for override
|
||||
*/
|
||||
protected function onUpdateLayoutResponse($response){
|
||||
|
||||
$isUpdate = $response["is_update"];
|
||||
|
||||
//create
|
||||
if($isUpdate == false){
|
||||
HelperUC::ajaxResponseData($response);
|
||||
}else{
|
||||
//update
|
||||
|
||||
$message = $response["message"];
|
||||
$pageName = UniteFunctionsUC::getVal($response, "page_name");
|
||||
|
||||
$arrData = array();
|
||||
if(!empty($pageName))
|
||||
$arrData["page_name"] = $pageName;
|
||||
|
||||
HelperUC::ajaxResponseSuccess($message, $arrData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get data array from request
|
||||
*/
|
||||
private function getDataFromRequest(){
|
||||
|
||||
$data = UniteFunctionsUC::getPostGetVariable("data", "", UniteFunctionsUC::SANITIZE_NOTHING);
|
||||
if(empty($data))
|
||||
$data = $_REQUEST;
|
||||
|
||||
if(is_string($data)){
|
||||
$arrData = (array)json_decode($data);
|
||||
|
||||
if(empty($arrData)){
|
||||
$arrData = stripslashes(trim($data));
|
||||
$arrData = (array)json_decode($arrData);
|
||||
}
|
||||
|
||||
$data = $arrData;
|
||||
}
|
||||
|
||||
return ($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* on ajax action
|
||||
*/
|
||||
public function onAjaxAction(){
|
||||
|
||||
if(GlobalsUC::$inDev == true || GlobalsUC::$debugAjaxErrors == true){
|
||||
|
||||
ini_set("display_errors", "on");
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
||||
$actionType = UniteFunctionsUC::getPostGetVariable("action", "", UniteFunctionsUC::SANITIZE_KEY);
|
||||
|
||||
if($actionType != GlobalsUC::PLUGIN_NAME . "_ajax_action")
|
||||
return (false);
|
||||
|
||||
$action = UniteFunctionsUC::getPostGetVariable("client_action", "", UniteFunctionsUC::SANITIZE_KEY);
|
||||
|
||||
GlobalsUC::$ajaxAction = $action;
|
||||
|
||||
|
||||
//check front actions
|
||||
switch($action){
|
||||
/*
|
||||
case "get_filters_data":
|
||||
$this->onAjaxFrontAction();
|
||||
exit();
|
||||
break;
|
||||
*/
|
||||
}
|
||||
|
||||
$operations = new ProviderOperationsUC();
|
||||
$addons = new UniteCreatorAddons();
|
||||
$assets = new UniteCreatorAssetsWork();
|
||||
$categories = new UniteCreatorCategories();
|
||||
$layouts = new UniteCreatorLayouts();
|
||||
$webAPI = new UniteCreatorWebAPI();
|
||||
|
||||
$data = $this->getDataFromRequest();
|
||||
$addonType = $addons->getAddonTypeFromData($data);
|
||||
|
||||
$data = UniteFunctionsUC::convertStdClassToArray($data);
|
||||
$data = UniteProviderFunctionsUC::normalizeAjaxInputData($data);
|
||||
|
||||
try{
|
||||
|
||||
//protection - it's intended to logged in users only with the capabilities defined in the plugin
|
||||
|
||||
$nonce = UniteFunctionsUC::getPostGetVariable("nonce", "", UniteFunctionsUC::SANITIZE_NOTHING);
|
||||
UniteProviderFunctionsUC::verifyNonce($nonce);
|
||||
|
||||
|
||||
switch($action){
|
||||
case "remove_category":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $categories->removeFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("The category deleted successfully", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "update_category":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$categories->updateFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Category updated", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_cat_order":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$categories->updateOrderFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Order updated", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "get_category_settings_html":
|
||||
|
||||
$manager = UniteCreatorManager::getObjManagerByAddonType($addonType);
|
||||
$response = $manager->getCatSettingsHtmlFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_cat_addons":
|
||||
|
||||
$manager = UniteCreatorManager::getObjManagerByAddonType($addonType, $data);
|
||||
$response = $manager->getCatAddonsHtmlFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_layouts_params_settings_html":
|
||||
|
||||
$manager = UniteCreatorManager::getObjManagerByAddonType($addonType, $data);
|
||||
$response = $manager->getAddonPropertiesDialogHtmlFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_catlist":
|
||||
|
||||
$manager = UniteCreatorManager::getObjManagerByAddonType($addonType, $data);
|
||||
$response = $manager->getCatListFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_layouts_categories":
|
||||
$response = $categories->getLayoutsCatsListFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_addon_changelog":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonChangelogEnabled();
|
||||
|
||||
$response = $operations->getAddonChangelogFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "add_addon_changelog":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonChangelogEnabled();
|
||||
|
||||
$addons->addAddonChangelog($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Log added.", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_addon_changelog":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonChangelogEnabled();
|
||||
|
||||
$addons->updateAddonChangelog($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Log updated.", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "delete_addon_changelog":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonChangelogEnabled();
|
||||
|
||||
$addons->deleteAddonChangelog($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Log deleted.", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "get_addon_revisions":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonRevisionsEnabled();
|
||||
|
||||
$response = $operations->getAddonRevisionsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "create_addon_revision":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonRevisionsEnabled();
|
||||
|
||||
$addons->createAddonRevision($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Revision created.", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "restore_addon_revision":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonRevisionsEnabled();
|
||||
|
||||
$response = $addons->restoreAddonRevision($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Revision restored.", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "download_addon_revision":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
HelperProviderUC::verifyAddonRevisionsEnabled();
|
||||
|
||||
$addons->downloadAddonRevision($data);
|
||||
exit;
|
||||
break;
|
||||
case "update_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->updateAddonFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Updated.", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "get_addon_bulk_dialog":
|
||||
|
||||
$response = $operations->getAddonBulkDialogFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "update_addons_bulk":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->updateAddonsBulkFromData($data);
|
||||
$response = $operations->getAddonBulkDialogFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "delete_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->deleteAddonFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("The addon deleted successfully", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "add_category":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $categories->addFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "add_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
if(GlobalsUC::$permisison_add === false)
|
||||
UniteFunctionsUC::throwError("Operation not permitted");
|
||||
|
||||
$response = $addons->createFromManager($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widget added successfully", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "update_addon_title":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->updateAddonTitleFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widget updated successfully", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_addons_activation":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->activateAddonsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widgets updated successfully", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "remove_addons":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $addons->removeAddonsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widgets Removed", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "update_addons_order":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->saveOrderFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Order Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_layouts_order":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$layouts->updateOrderFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Order Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "move_addons":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $addons->moveAddonsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Done Operation", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "duplicate_addons":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $addons->duplicateAddonsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Duplicated Successfully", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "get_addon_config_html": //from elementor
|
||||
|
||||
$response = $addons->getAddonConfigHTML($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_addon_settings_html": //from elementor/gutenberg
|
||||
|
||||
$html = $addons->getAddonSettingsHTMLFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData(array("html" => $html));
|
||||
break;
|
||||
case "get_addon_item_settings_html": //from elementor
|
||||
|
||||
$html = $addons->getAddonItemsSettingsHTMLFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData(array("html" => $html));
|
||||
break;
|
||||
case "get_addon_editor_data": //from elementor
|
||||
|
||||
$response = $addons->getAddonEditorData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_addon_output_data": //from elementor editor bg/gutenberg
|
||||
|
||||
$response = $addons->getAddonOutputData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "show_preview":
|
||||
|
||||
$addons->showAddonPreviewFromData($data);
|
||||
exit;
|
||||
break;
|
||||
case "save_addon_defaults":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->saveAddonDefaultsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "save_test_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->saveTestAddonData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "get_test_addon_data":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $addons->getTestAddonData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "delete_test_addon_data":
|
||||
//Security Update 3
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->deleteTestAddonData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Test data deleted", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "export_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->exportAddon($data);
|
||||
exit;
|
||||
break;
|
||||
case "export_cat_addons":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$addons->exportCatAddons($data);
|
||||
break;
|
||||
case "import_addons":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $addons->importAddons($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Addons Imported", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "import_layouts":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$urlRedirect = $layouts->importLayouts($data);
|
||||
|
||||
if(!empty($urlRedirect))
|
||||
HelperUC::ajaxResponseSuccessRedirect(HelperUC::getText("layout_imported"), $urlRedirect);
|
||||
else
|
||||
HelperUC::ajaxResponseSuccess(HelperUC::getText("layout_imported"));
|
||||
|
||||
break;
|
||||
case "get_image_url":
|
||||
$id = UniteFunctionsUC::getVal($data, "id");
|
||||
$size = UniteFunctionsUC::getVal($data, "size", "full");
|
||||
$url = UniteProviderFunctionsUC::getImageUrlFromImageID($id, $size);
|
||||
|
||||
HelperUC::ajaxResponseData(array("url" => $url));
|
||||
break;
|
||||
case "get_version_text":
|
||||
|
||||
$content = HelperHtmlUC::getVersionText();
|
||||
|
||||
HelperUC::ajaxResponseData(array("text" => $content));
|
||||
break;
|
||||
case "update_plugin":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
if(method_exists("UniteProviderFunctionsUC", "updatePlugin"))
|
||||
UniteProviderFunctionsUC::updatePlugin();
|
||||
else{
|
||||
echo "Functionality Don't Exists";
|
||||
exit;
|
||||
}
|
||||
|
||||
break;
|
||||
case "update_general_settings":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$operations->updateGeneralSettingsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Settings Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_global_layout_settings":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
UniteCreatorLayout::updateLayoutGlobalSettingsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Settings Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_layout":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $layouts->updateLayoutFromData($data);
|
||||
|
||||
$this->onUpdateLayoutResponse($response);
|
||||
break;
|
||||
case "update_layout_category":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$layouts->updateLayoutCategoryFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Category Updated", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "update_layout_params":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $layouts->updateParamsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Layout Updated", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "delete_layout":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$layouts->deleteLayoutFromData($data);
|
||||
|
||||
$urlLayouts = HelperUC::getViewUrl_LayoutsList();
|
||||
|
||||
HelperUC::ajaxResponseSuccessRedirect(HelperUC::getText("layout_deleted"), $urlLayouts);
|
||||
break;
|
||||
case "export_layout":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$layouts->exportLayout($data);
|
||||
exit;
|
||||
break;
|
||||
case "activate_product":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$expireDays = $webAPI->activateProductFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Product Activated", "unlimited-elements-for-elementor"), array("expire_days" => $expireDays));
|
||||
break;
|
||||
case "deactivate_product":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$webAPI->deactivateProduct($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess("Product Deactivated, please refresh the page");
|
||||
break;
|
||||
case "check_catalog":
|
||||
|
||||
$isForce = UniteFunctionsUC::getVal($data, "force");
|
||||
$isForce = UniteFunctionsUC::strToBool($isForce);
|
||||
|
||||
$response = $webAPI->checkUpdateCatalog($isForce);
|
||||
|
||||
$operations->checkInstagramRenewToken();
|
||||
|
||||
do_action("ue_on_check_catalog_ajax_action");
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "install_catalog_addon":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $webAPI->installCatalogAddonFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widget Installed", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "install_catalog_page":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $webAPI->installCatalogPageFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Template Installed", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "update_addon_from_catalog": //by id
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$urlRedirect = $addons->updateAddonFromCatalogFromData($data);
|
||||
|
||||
if(!empty($urlRedirect))
|
||||
HelperUC::ajaxResponseSuccessRedirect(esc_html__("Widget Updated", "unlimited-elements-for-elementor"), $urlRedirect);
|
||||
else
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Widget Updated", "unlimited-elements-for-elementor"));
|
||||
|
||||
break;
|
||||
case "get_shapes_css":
|
||||
|
||||
$objShapes = new UniteShapeManagerUC();
|
||||
$objShapes->outputCssShapes();
|
||||
exit;
|
||||
break;
|
||||
case "save_screenshot":
|
||||
|
||||
$response = $operations->saveScreenshotFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Screenshot Saved", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "save_section_tolibrary":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $layouts->saveSectionToLibraryFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Section Saved", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "get_grid_import_layout_data":
|
||||
|
||||
$response = $layouts->getLayoutGridDataForEditor($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "save_custom_settings":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$operations->updateCustomSettingsFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Settings Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "get_link_autocomplete":
|
||||
$response = $operations->getLinkAutocompleteFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "get_users_list_forselect":
|
||||
$arrUsersList = $operations->getUsersListForSelectFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($arrUsersList);
|
||||
break;
|
||||
case "get_terms_list_forselect":
|
||||
$arrTermsList = $operations->getTermsListForSelectFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($arrTermsList);
|
||||
break;
|
||||
case "get_posts_list_forselect":
|
||||
$arrPostList = $operations->getPostListForSelectFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($arrPostList);
|
||||
break;
|
||||
case "get_select2_post_titles":
|
||||
$arrData = $operations->getSelect2PostTitles($data);
|
||||
|
||||
HelperUC::ajaxResponseData(array("select2_data" => $arrData));
|
||||
break;
|
||||
case "get_select2_terms_titles":
|
||||
$arrData = $operations->getSelect2TermsTitles($data);
|
||||
|
||||
HelperUC::ajaxResponseData(array("select2_data" => $arrData));
|
||||
break;
|
||||
case "get_select2_users_titles":
|
||||
$arrData = $operations->getSelect2UsersTitles($data);
|
||||
|
||||
HelperUC::ajaxResponseData(array("select2_data" => $arrData));
|
||||
break;
|
||||
case "get_post_child_params":
|
||||
|
||||
$response = $operations->getPostAttributesFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "import_elementor_catalog_template":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $webAPI->installCatalogTemplateFromData($data);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Template Imported", "unlimited-elements-for-elementor"), $response);
|
||||
break;
|
||||
case "save_instagram_connect_data":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$objServices = new UniteServicesUC();
|
||||
$objServices->includeInstagramAPI();
|
||||
|
||||
HelperInstaUC::saveInstagramConnectDataAjax($data);
|
||||
break;
|
||||
case "renew_instagram_access_token":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$objServices = new UniteServicesUC();
|
||||
$objServices->includeInstagramAPI();
|
||||
|
||||
HelperInstaUC::renewAccessToken();
|
||||
HelperInstaUC::redirectToGeneralSettings();
|
||||
break;
|
||||
case "save_google_connect_data":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$objServices = new UniteServicesUC();
|
||||
$objServices->includeGoogleAPI();
|
||||
|
||||
try{
|
||||
$params = array();
|
||||
$error = UniteFunctionsUC::getVal($data, "error");
|
||||
|
||||
if(empty($error) === false)
|
||||
UniteFunctionsUC::throwError($error);
|
||||
|
||||
UEGoogleAPIHelper::saveCredentials($data);
|
||||
}catch(Exception $exception){
|
||||
$params = array("google_connect_error" => $exception->getMessage());
|
||||
}
|
||||
|
||||
UEGoogleAPIHelper::redirectToSettings($params);
|
||||
break;
|
||||
case "remove_google_connect_data":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$objServices = new UniteServicesUC();
|
||||
$objServices->includeGoogleAPI();
|
||||
|
||||
try{
|
||||
$params = array();
|
||||
$error = UniteFunctionsUC::getVal($data, "error");
|
||||
|
||||
if(empty($error) === false)
|
||||
UniteFunctionsUC::throwError($error);
|
||||
|
||||
UEGoogleAPIHelper::removeCredentials();
|
||||
}catch(Exception $exception){
|
||||
$params = array("google_connect_error" => $exception->getMessage());
|
||||
}
|
||||
|
||||
UEGoogleAPIHelper::redirectToSettings($params);
|
||||
break;
|
||||
case "dismiss_notice":
|
||||
|
||||
UCAdminNoticesManager::dismissNotice($data['id']);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Notice Dismissed", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "postpone_notice":
|
||||
|
||||
UCAdminNoticesManager::postponeNotice($data['id'], $data['duration']);
|
||||
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("Notice Postponed", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
default:
|
||||
|
||||
//check assets
|
||||
$found = $assets->checkAjaxActions($action, $data);
|
||||
|
||||
if(!$found)
|
||||
$found = UniteProviderFunctionsUC::applyFilters(UniteCreatorFilters::FILTER_ADMIN_AJAX_ACTION, $found, $action, $data);
|
||||
|
||||
if(!$found)
|
||||
HelperUC::ajaxResponseError("wrong ajax action: <b>$action</b> ");
|
||||
break;
|
||||
}
|
||||
}catch(Exception $e){
|
||||
$errorMessage = $e->getMessage();
|
||||
|
||||
if(GlobalsUC::$SHOW_TRACE === true){
|
||||
$trace = $e->getTraceAsString();
|
||||
$errorMessage .= "<pre>" . $trace . "</pre>";
|
||||
}
|
||||
|
||||
HelperUC::ajaxResponseError($errorMessage);
|
||||
}
|
||||
|
||||
//it's an ajax action, so exit
|
||||
HelperUC::ajaxResponseError("No response output on <b> $action </b> action. please check with the developer.");
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* on ajax action
|
||||
*/
|
||||
public function onAjaxFrontAction(){
|
||||
|
||||
$actionType = UniteFunctionsUC::getPostGetVariable("action", "", UniteFunctionsUC::SANITIZE_KEY);
|
||||
|
||||
if($actionType != GlobalsUC::PLUGIN_NAME . "_ajax_action")
|
||||
return (false);
|
||||
|
||||
$action = UniteFunctionsUC::getPostGetVariable("client_action", "", UniteFunctionsUC::SANITIZE_KEY);
|
||||
$data = $this->getDataFromRequest();
|
||||
|
||||
try{
|
||||
//switch($action){}
|
||||
}catch(Exception $e){
|
||||
$message = $e->getMessage();
|
||||
$errorMessage = $message;
|
||||
|
||||
if(GlobalsUC::$SHOW_TRACE == true){
|
||||
$trace = $e->getTraceAsString();
|
||||
$errorMessage = $message . "<pre>" . $trace . "</pre>";
|
||||
}
|
||||
|
||||
HelperUC::ajaxResponseError($errorMessage);
|
||||
}
|
||||
|
||||
//it's an ajax action, so exit
|
||||
HelperUC::ajaxResponseError("No response output on <b> $action </b> action. please check with the developer.");
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonChangelog{
|
||||
|
||||
const TYPE_CHANGE = "change";
|
||||
const TYPE_FEATURE = "feature";
|
||||
const TYPE_FIX = "fix";
|
||||
const TYPE_OTHER = "other";
|
||||
|
||||
/**
|
||||
* Get the table name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTable(){
|
||||
|
||||
$table = UniteFunctionsWPUC::prefixDBTable(GlobalsUC::TABLE_CHANGELOG_NAME);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTypes(){
|
||||
|
||||
$types = array(
|
||||
self::TYPE_CHANGE => $this->getTypeTitle(self::TYPE_CHANGE),
|
||||
self::TYPE_FEATURE => $this->getTypeTitle(self::TYPE_FEATURE),
|
||||
self::TYPE_FIX => $this->getTypeTitle(self::TYPE_FIX),
|
||||
self::TYPE_OTHER => $this->getTypeTitle(self::TYPE_OTHER),
|
||||
);
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the given addon.
|
||||
*
|
||||
* @param int $addonId
|
||||
* @param string $fallback
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAddonTitle($addonId, $fallback){
|
||||
|
||||
try{
|
||||
$addon = new UniteCreatorAddon();
|
||||
$addon->initByID($addonId);
|
||||
|
||||
return $addon->getTitle();
|
||||
}catch(Exception $exception){
|
||||
return sprintf(__("%s (deleted)", "unlimited-elements-for-elementor"), $fallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the given addon.
|
||||
*
|
||||
* @param int $addonId
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getAddonVersion($addonId){
|
||||
|
||||
try{
|
||||
$addon = new UniteCreatorAddon();
|
||||
$addon->initByID($addonId);
|
||||
|
||||
$options = $addon->getOptions();
|
||||
|
||||
if(isset($options["is_free_addon"]) === false)
|
||||
return null;
|
||||
|
||||
$isFree = UniteFunctionsUC::getVal($options, "is_free_addon");
|
||||
$isFree = UniteFunctionsUC::strToBool($isFree);
|
||||
|
||||
if($isFree === true)
|
||||
return __("Free", "unlimited-elements-for-elementor");
|
||||
|
||||
return __("Pro", "unlimited-elements-for-elementor");
|
||||
}catch(Exception $exception){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of changelogs for the given addon.
|
||||
*
|
||||
* @param int $addonId
|
||||
* @param array $filters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddonChangelogs($addonId, $filters = array()){
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM {$this->getTable()}
|
||||
WHERE addon_id = %d
|
||||
ORDER BY created_at DESC
|
||||
";
|
||||
|
||||
$limit = UniteFunctionsUC::getVal($filters, "limit", null);
|
||||
|
||||
if($limit !== null){
|
||||
$sql .= " LIMIT " . intval($limit);
|
||||
}
|
||||
|
||||
$sql = $wpdb->prepare($sql, array($addonId));
|
||||
$results = $wpdb->get_results($sql, ARRAY_A);
|
||||
$changelogs = $this->prepareChangelogs($results);
|
||||
|
||||
return $changelogs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the changelog by the identifier.
|
||||
*
|
||||
* @param int|int[] $id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findChangelog($id){
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$ids = is_array($id) ? $id : array($id);
|
||||
$idPlaceholders = UniteFunctionsWPUC::getDBPlaceholders($ids, "%d");
|
||||
|
||||
if(empty($ids) === true)
|
||||
return array();
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM {$this->getTable()}
|
||||
WHERE id IN($idPlaceholders)
|
||||
ORDER BY created_at DESC
|
||||
";
|
||||
|
||||
$sql = $wpdb->prepare($sql, $ids);
|
||||
$results = $wpdb->get_results($sql, ARRAY_A);
|
||||
$items = $this->prepareChangelogs($results);
|
||||
|
||||
if(is_array($id) === true)
|
||||
return $items;
|
||||
|
||||
return reset($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new changelog.
|
||||
*
|
||||
* @param int $addonId
|
||||
* @param string $type
|
||||
* @param string $text
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addChangelog($addonId, $type, $text){
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$addon = new UniteCreatorAddon();
|
||||
$addon->initByID($addonId);
|
||||
|
||||
$data = array(
|
||||
"addon_id" => $addon->getID(),
|
||||
"addon_title" => $addon->getTitle(),
|
||||
"user_id" => get_current_user_id(),
|
||||
"type" => $type,
|
||||
"text" => $text,
|
||||
"plugin_version" => UNLIMITED_ELEMENTS_VERSION,
|
||||
"created_at" => current_time("mysql"),
|
||||
);
|
||||
|
||||
$result = $wpdb->insert($this->getTable(), $data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the given changelog.
|
||||
*
|
||||
* @param int|int[] $id
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateChangelog($id, $data){
|
||||
|
||||
$result = UniteFunctionsWPUC::processDBTransaction(function() use ($id, $data){
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$ids = is_array($id) ? $id : array($id);
|
||||
$table = $this->getTable();
|
||||
$result = 0;
|
||||
|
||||
foreach($ids as $id){
|
||||
$where = array("id" => $id);
|
||||
$result += $wpdb->update($table, $data, $where);
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the changelog permanently.
|
||||
*
|
||||
* @param int|int[] $id
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteChangelog($id){
|
||||
|
||||
$result = UniteFunctionsWPUC::processDBTransaction(function() use ($id){
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$ids = is_array($id) ? $id : array($id);
|
||||
$table = $this->getTable();
|
||||
$result = 0;
|
||||
|
||||
foreach($ids as $id){
|
||||
$where = array("id" => $id);
|
||||
$result += $wpdb->delete($table, $where);
|
||||
}
|
||||
|
||||
return $result;
|
||||
});
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the given type.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getTypeTitle($type){
|
||||
|
||||
$titles = array(
|
||||
self::TYPE_CHANGE => __("Change", "unlimited-elements-for-elementor"),
|
||||
self::TYPE_FEATURE => __("Feature", "unlimited-elements-for-elementor"),
|
||||
self::TYPE_FIX => __("Fix", "unlimited-elements-for-elementor"),
|
||||
self::TYPE_OTHER => __("Other", "unlimited-elements-for-elementor"),
|
||||
);
|
||||
|
||||
return UniteFunctionsUC::getVal($titles, $type, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare changelogs from the given results.
|
||||
*
|
||||
* @param array $results
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function prepareChangelogs($results){
|
||||
|
||||
$changelogs = array();
|
||||
|
||||
foreach($results as $result){
|
||||
$user = get_user_by("id", $result["user_id"]);
|
||||
|
||||
$textHtml = esc_html($result["text"]);
|
||||
$textHtml = nl2br($textHtml);
|
||||
|
||||
$changelogs[] = array_merge($result, array(
|
||||
"user_username" => $user ? $user->user_login : __("(deleted)", "unlimited-elements-for-elementor"),
|
||||
"addon_title" => $this->getAddonTitle($result["addon_id"], $result["addon_title"]),
|
||||
"addon_version" => $this->getAddonVersion($result["addon_id"]),
|
||||
"type_title" => $this->getTypeTitle($result["type"]),
|
||||
"text_html" => $textHtml,
|
||||
"created_date" => mysql2date("j F Y H:i:s", $result["created_at"]),
|
||||
"created_time" => strtotime($result["created_at"]),
|
||||
));
|
||||
}
|
||||
|
||||
return $changelogs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonConfig extends HtmlOutputBaseUC{
|
||||
|
||||
|
||||
private $startWithAddon = false;
|
||||
private $isPreviewMode = false;
|
||||
private $startAddon;
|
||||
private $selectedTab = null;
|
||||
private $isSourceAddon = false;
|
||||
private $isFontsPanelEnabled = true;
|
||||
|
||||
|
||||
/**
|
||||
* construct the object
|
||||
*/
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate start addon
|
||||
*/
|
||||
private function valdiateStartAddon(){
|
||||
|
||||
if($this->startWithAddon == false)
|
||||
UniteFunctionsUC::throwError("No start addon found");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get preview html
|
||||
*/
|
||||
private function getHtmlPreview(){
|
||||
|
||||
$html = "";
|
||||
|
||||
//preview
|
||||
$html .= self::TAB2."<div class='uc-addon-config-preview' style='display:none'>".self::BR;
|
||||
$html .= self::TAB3."<div class='uc-addon-config-preview-title'>Preview".self::BR;
|
||||
$html .= self::TAB3."</div>".self::BR;
|
||||
|
||||
$html .= self::TAB3."<div class='uc-preview-content'>".self::BR;
|
||||
|
||||
$html .= self::TAB4."<iframe class='uc-preview-iframe'>".self::BR;
|
||||
$html .= self::TAB4."</iframe>".self::BR;
|
||||
|
||||
$html .= self::TAB3."</div>".self::BR;
|
||||
|
||||
$html .= self::TAB2."</div>".self::BR;
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get item settings html
|
||||
*/
|
||||
private function getHtmlSettings($putMode = false){
|
||||
|
||||
$html = "";
|
||||
|
||||
$html .= self::TAB3."<div class='uc-addon-config-settings unite-settings'>".self::BR;
|
||||
|
||||
if($putMode == true){
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
$html = "";
|
||||
}
|
||||
|
||||
if($this->startWithAddon == true){
|
||||
|
||||
$params = array();
|
||||
if($this->isSourceAddon == true)
|
||||
$params["source"] = "addon";
|
||||
|
||||
if($this->isFontsPanelEnabled == false)
|
||||
$params["disable_fonts"] = true;
|
||||
|
||||
if($putMode == true)
|
||||
|
||||
$this->startAddon->putHtmlConfig(false,$params);
|
||||
else{
|
||||
|
||||
$htmlConfig = $this->startAddon->getHtmlConfig(false,false,$params);
|
||||
$html .= $htmlConfig;
|
||||
}
|
||||
}
|
||||
|
||||
$html .= self::TAB3."</div>".self::BR; //settings
|
||||
|
||||
|
||||
if($putMode == true)
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
else
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function a___________OTHERS____________(){}
|
||||
|
||||
|
||||
/**
|
||||
* get tab html
|
||||
*/
|
||||
private function getHtmlTab($name, $text){
|
||||
|
||||
$selectedClass = "";
|
||||
|
||||
if(empty($this->selectedTab)){
|
||||
$this->selectedTab = $name;
|
||||
$selectedClass = " uc-tab-selected";
|
||||
}
|
||||
|
||||
$html = self::TAB3."<a href='javascript:void(0)' data-name='{$name}' onfocus='this.blur()' class='uc-addon-config-tab {$selectedClass}'>".$text."</a>".self::BR;
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put html frame of the config
|
||||
*/
|
||||
public function getHtmlFrame($putMode = false){
|
||||
|
||||
$title = esc_html__("Addon Title", "unlimited-elements-for-elementor");
|
||||
$this->valdiateStartAddon();
|
||||
|
||||
$addHtml = "";
|
||||
$title = $this->startAddon->getTitle(true);
|
||||
$title .= " - ".esc_html__("Config", "unlimited-elements-for-elementor");
|
||||
|
||||
$titleSmall = $this->startAddon->getTitle(true);
|
||||
|
||||
$addonName = $this->startAddon->getNameByType();
|
||||
$addonID = $this->startAddon->getID();
|
||||
$addonType = $this->startAddon->getType();
|
||||
|
||||
$enableFontsPanel = true;
|
||||
|
||||
$options = $this->startAddon->getOptions();
|
||||
$urlIcon = $this->startAddon->getUrlIcon();
|
||||
|
||||
$options["title"] = $this->startAddon->getTitle();
|
||||
$options["url_icon"] = $urlIcon;
|
||||
$options["addon_name"] = $addonName;
|
||||
$options["addon_id"] = $addonID;
|
||||
$options["addon_type"] = $addonType;
|
||||
$options["admin_labels"] = $this->startAddon->getAdminLabels();
|
||||
|
||||
$strOptions = UniteFunctionsUC::jsonEncodeForHtmlData($options,"options");
|
||||
|
||||
$addonName = esc_attr($addonName);
|
||||
$addonType = esc_attr($addonType);
|
||||
|
||||
$addHtml .= " data-name=\"{$addonName}\" data-addontype=\"{$addonType}\" {$strOptions} ";
|
||||
|
||||
$html = "";
|
||||
|
||||
//settings
|
||||
$html .= self::TAB. "<div id='uc_addon_config' class='uc-addon-config' {$addHtml}>".self::BR;
|
||||
|
||||
//set preview style
|
||||
$styleConfigTable = "";
|
||||
if($this->isPreviewMode == true)
|
||||
$styleConfigTable = "style='display:none'";
|
||||
|
||||
|
||||
$html .= self::TAB."<div class='uc-addon-config-table'>".self::BR;
|
||||
|
||||
//put settings
|
||||
if($putMode == true){
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
$html = "";
|
||||
$this->getHtmlSettings(true);
|
||||
}else{
|
||||
$html .= $this->getHtmlSettings();
|
||||
}
|
||||
|
||||
$html .= self::TAB."</div>";
|
||||
|
||||
//end config table
|
||||
|
||||
|
||||
//end preview table
|
||||
$html .= $this->getHtmlPreview();
|
||||
|
||||
$html .= self::TAB."</div>".self::BR; //main wrapper
|
||||
|
||||
if($putMode == true)
|
||||
echo UniteProviderFunctionsUC::escCombinedHtml($html);
|
||||
else
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* put html frame
|
||||
*/
|
||||
public function putHtmlFrame(){
|
||||
$this->getHtmlFrame(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* set to start with preview
|
||||
*/
|
||||
public function startWithPreview($isPreview){
|
||||
|
||||
$this->isPreviewMode = $isPreview;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set addon as image source
|
||||
*/
|
||||
public function setSourceAddon(){
|
||||
$this->isSourceAddon = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set start addon
|
||||
*/
|
||||
public function setStartAddon(UniteCreatorAddon $objAddon){
|
||||
$this->startWithAddon = true;
|
||||
|
||||
UniteFunctionsUC::validateNotEmpty($objAddon, "addon");
|
||||
|
||||
$this->startAddon = $objAddon;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* disable fonts panel in the config
|
||||
*/
|
||||
public function disableFontsPanel(){
|
||||
|
||||
$this->isFontsPanelEnabled = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonRevisioner{
|
||||
|
||||
const FOLDER_NAME = 'unlimited_elements_revisions';
|
||||
const MAX_REVISIONS = 10;
|
||||
const MAX_TODAY_REVISIONS = 5;
|
||||
|
||||
private static $initialized = false;
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
public static function init(){
|
||||
|
||||
$shouldInitialize = self::shouldInitialize();
|
||||
|
||||
if($shouldInitialize === false)
|
||||
return;
|
||||
|
||||
self::registerHooks();
|
||||
|
||||
self::$initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of revision for the addon
|
||||
*/
|
||||
public function getAddonRevisions($addon){
|
||||
|
||||
$files = $this->getRevisions($addon);
|
||||
$files = array_reverse($files); // new at the top
|
||||
$revisions = array();
|
||||
|
||||
foreach($files as $file){
|
||||
$revisions[] = $this->prepareRevision($file);
|
||||
}
|
||||
|
||||
return $revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new revision for the addon
|
||||
*/
|
||||
public function createAddonRevision($addon){
|
||||
|
||||
$this->createRevision($addon);
|
||||
$this->purgeRevisions($addon);
|
||||
}
|
||||
|
||||
/**
|
||||
* restore the addon revision
|
||||
*/
|
||||
public function restoreAddonRevision($addon, $revisionId){
|
||||
|
||||
$revision = $this->getAddonRevision($addon, $revisionId);
|
||||
$filePath = $revision['path'];
|
||||
$categoryId = null; // autodetect
|
||||
|
||||
// create a new revision before restoring
|
||||
$this->createRevision($addon);
|
||||
|
||||
$exporter = new UniteCreatorExporter();
|
||||
$exporter->initByAddon($addon);
|
||||
$exporter->setMustImportAddonType($addon->getType());
|
||||
$log = $exporter->import($categoryId, $filePath, true, false);
|
||||
|
||||
$this->purgeRevisions($addon);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* download the addon revision
|
||||
*/
|
||||
public function downloadAddonRevision($addon, $revisionId){
|
||||
|
||||
$revision = $this->getAddonRevision($addon, $revisionId);
|
||||
$filePath = $revision['path'];
|
||||
$fileName = $addon->getName() . ' - ' . $revision['date'] . '.' . $revision['extension'];
|
||||
|
||||
UniteFunctionsUC::downloadFile($filePath, $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete all revisions of the addon
|
||||
*/
|
||||
public function deleteAddonRevisions($addon){
|
||||
|
||||
$folderPath = $this->getFolderPath($addon);
|
||||
|
||||
UniteFunctionsUC::deleteDir($folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if revisions need to be initialized
|
||||
*/
|
||||
private static function shouldInitialize(){
|
||||
|
||||
if(self::$initialized === true)
|
||||
return false;
|
||||
|
||||
if(GlobalsUC::$is_admin === false)
|
||||
return false;
|
||||
|
||||
$isRevisionsEnabled = HelperProviderUC::isAddonRevisionsEnabled();
|
||||
|
||||
if($isRevisionsEnabled === false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* register hooks
|
||||
*/
|
||||
private static function registerHooks(){
|
||||
|
||||
$instance = new self();
|
||||
|
||||
UniteProviderFunctionsUC::addAction(UniteCreatorFilters::ACTION_ADDON_AFTER_UPDATE, array($instance, 'createAddonRevision'));
|
||||
UniteProviderFunctionsUC::addAction(UniteCreatorFilters::ACTION_ADDON_AFTER_DELETE, array($instance, 'deleteAddonRevisions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the revision folder path
|
||||
*/
|
||||
private function getFolderPath($addon){
|
||||
|
||||
$id = $addon->getID();
|
||||
|
||||
$path = GlobalsUC::$path_images
|
||||
. self::FOLDER_NAME . '/'
|
||||
. $id . '/';
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate the revision file name
|
||||
*/
|
||||
private function generateFileName(){
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$time = current_time('timestamp');
|
||||
$name = $time . '-' . $user->user_login;
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of revisions
|
||||
*/
|
||||
private function getRevisions($addon){
|
||||
|
||||
$path = $this->getFolderPath($addon);
|
||||
$files = list_files($path, 1);
|
||||
|
||||
sort($files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete previous revisions
|
||||
*/
|
||||
private function purgeRevisions($addon){
|
||||
|
||||
$files = $this->getRevisions($addon);
|
||||
$todayFiles = array();
|
||||
$pastFiles = array();
|
||||
|
||||
foreach($files as $file){
|
||||
$revision = $this->prepareRevision($file);
|
||||
|
||||
if($revision['is_today'])
|
||||
$todayFiles[] = $file;
|
||||
else
|
||||
$pastFiles[] = $file;
|
||||
}
|
||||
|
||||
$maxTodayFiles = max(self::MAX_TODAY_REVISIONS, self::MAX_REVISIONS - count($pastFiles));
|
||||
$deleteTodayFiles = array_slice($todayFiles, 0, -$maxTodayFiles);
|
||||
$leftFiles = array_diff($files, $deleteTodayFiles);
|
||||
$deleteLeftFiles = array_slice($leftFiles, 0, -self::MAX_REVISIONS);
|
||||
$deleteFiles = array_merge($deleteTodayFiles, $deleteLeftFiles);
|
||||
|
||||
UniteFunctionsUC::deleteListOfFiles($deleteFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new revision
|
||||
*/
|
||||
private function createRevision($addon){
|
||||
|
||||
// create revisions folder
|
||||
$revisionsPath = GlobalsUC::$path_images . self::FOLDER_NAME . "/";
|
||||
|
||||
UniteFunctionsUC::checkCreateDir($revisionsPath);
|
||||
|
||||
if(is_dir($revisionsPath) === false)
|
||||
return;
|
||||
|
||||
// create addon folder
|
||||
$folderPath = $this->getFolderPath($addon);
|
||||
|
||||
UniteFunctionsUC::checkCreateDir($folderPath);
|
||||
|
||||
if(is_dir($folderPath) === false)
|
||||
return;
|
||||
|
||||
$fileName = $this->generateFileName();
|
||||
|
||||
$exporter = new UniteCreatorExporter();
|
||||
$exporter->initByAddon($addon);
|
||||
$exporter->setFilename($fileName);
|
||||
$exporter->export($folderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare revision data
|
||||
*/
|
||||
private function prepareRevision($file){
|
||||
|
||||
$info = pathinfo($file);
|
||||
$name = explode('-', $info['filename'], 2);
|
||||
$time = $name[0];
|
||||
$username = $name[1];
|
||||
|
||||
$currentTime = current_time('timestamp');
|
||||
$todayStartTime = strtotime('today', $currentTime);
|
||||
$todayEndTime = strtotime('tomorrow', $todayStartTime) - 1;
|
||||
|
||||
$date = date('Y-m-d H:i:s', $time);
|
||||
$isToday = ($time >= $todayStartTime && $time <= $todayEndTime);
|
||||
|
||||
$revision = array(
|
||||
'id' => $info['basename'],
|
||||
'path' => $file,
|
||||
'time' => $time,
|
||||
'date' => $date,
|
||||
'extension' => $info['extension'],
|
||||
'username' => $username,
|
||||
'is_today' => $isToday,
|
||||
);
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the addon revision
|
||||
*/
|
||||
private function getAddonRevision($addon, $revisionId){
|
||||
|
||||
$files = $this->getRevisions($addon);
|
||||
$revision = null;
|
||||
|
||||
foreach($files as $file){
|
||||
if(strpos($file, $revisionId) !== false){
|
||||
$revision = $this->prepareRevision($file);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $revision;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAddonValidator{
|
||||
|
||||
protected $objAddon;
|
||||
protected $arrMessages = array();
|
||||
const VALIDATION_PREVIEW_EXISTS = "preview_exists";
|
||||
|
||||
protected $arrExtraValidations;
|
||||
|
||||
|
||||
/**
|
||||
* validate inited
|
||||
*/
|
||||
protected function validateInited(){
|
||||
|
||||
if(empty($this->objAddon))
|
||||
UniteFunctionsUC::throwError("Widget is not inited");
|
||||
}
|
||||
|
||||
/**
|
||||
* add preview link exists validation
|
||||
*/
|
||||
public function addValidation_isPreviewLinkExists(){
|
||||
|
||||
$this->arrExtraValidations[] = self::VALIDATION_PREVIEW_EXISTS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init addon
|
||||
*/
|
||||
protected function init($objAddon){
|
||||
$this->objAddon = $objAddon;
|
||||
$this->arrMessages = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* get message array
|
||||
*/
|
||||
public function getArrMessages(){
|
||||
|
||||
return($this->arrMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* return if addon missing defaults
|
||||
*/
|
||||
protected function isAddonMissingDefaults(){
|
||||
|
||||
$hasItems = $this->objAddon->isHasItems();
|
||||
if($hasItems == false)
|
||||
return(false);
|
||||
|
||||
$arrDefaults = $this->objAddon->getDefaultData();
|
||||
$items = UniteFunctionsUC::getVal($arrDefaults, "items");
|
||||
|
||||
if(empty($items))
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check if some of the param missing default value
|
||||
*/
|
||||
protected function isParamsMissingDefaultValue($arrParams){
|
||||
|
||||
if(empty($arrParams))
|
||||
return(false);
|
||||
|
||||
foreach($arrParams as $param){
|
||||
$defaultValue = UniteFunctionsUC::getVal($param, "default_value");
|
||||
if(empty($defaultValue))
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return if missing image url
|
||||
*/
|
||||
protected function isAddonMissingImageUrl(){
|
||||
|
||||
$arrImagesParams = $this->objAddon->getParams(UniteCreatorDialogParam::PARAM_IMAGE);
|
||||
$arrImagesParamsItems = $this->objAddon->getParamsItems(UniteCreatorDialogParam::PARAM_IMAGE);
|
||||
|
||||
$isMissing = $this->isParamsMissingDefaultValue($arrImagesParams);
|
||||
if($isMissing == true)
|
||||
return(true);
|
||||
|
||||
$isMissing = $this->isParamsMissingDefaultValue($arrImagesParamsItems);
|
||||
if($isMissing == true)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if addon has non existing includes
|
||||
*/
|
||||
protected function isHasNonExistingIncludes(){
|
||||
|
||||
$arrIncludes = $this->objAddon->getAllRegularIncludesUrls();
|
||||
|
||||
$name = $this->objAddon->getName();
|
||||
|
||||
$objAddonType = $this->objAddon->getObjAddonType();
|
||||
|
||||
foreach($arrIncludes as $urlInclude){
|
||||
|
||||
$isUnderAssets = HelperUC::isUrlUnderAssets($urlInclude, $objAddonType);
|
||||
if($isUnderAssets == false)
|
||||
continue;
|
||||
|
||||
$pathInclude = HelperUC::urlToPath($urlInclude);
|
||||
|
||||
if(empty($pathInclude))
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the preview link exists
|
||||
*/
|
||||
private function isPreviewLinkExists(){
|
||||
|
||||
$linkPreview = $this->objAddon->getOption("link_preview");
|
||||
|
||||
$linkPreview = trim($linkPreview);
|
||||
|
||||
if(empty($linkPreview))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* run validation
|
||||
*/
|
||||
private function runValidation($validation){
|
||||
|
||||
switch($validation){
|
||||
case self::VALIDATION_PREVIEW_EXISTS:
|
||||
|
||||
$isExists = $this->isPreviewLinkExists();
|
||||
|
||||
if($isExists == false)
|
||||
$this->arrMessages[] = __("Missing Preview Link","unlimited-elements-for-elementor");
|
||||
|
||||
break;
|
||||
default:
|
||||
UniteFunctionsUC::throwError("wrong validation: ".$validation);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* validate extra validations
|
||||
*/
|
||||
private function validateExtraValidations(){
|
||||
|
||||
if(empty($this->arrExtraValidations))
|
||||
return(false);
|
||||
|
||||
foreach($this->arrExtraValidations as $validation){
|
||||
|
||||
$this->runValidation($validation);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* check if addon has non valid html
|
||||
*/
|
||||
protected function isHasNonValidHtml(){
|
||||
|
||||
$html = $this->objAddon->getHtml();
|
||||
|
||||
$arrErrors = UniteFunctionsUC::validateHTML($html);
|
||||
|
||||
dmp($arrErrors);
|
||||
exit();
|
||||
|
||||
$isNotValid = !empty($arrErrors);
|
||||
|
||||
return($isNotValid);
|
||||
}
|
||||
|
||||
/**
|
||||
* validate regular addon
|
||||
*/
|
||||
protected function validateRegularAddon(){
|
||||
|
||||
//check if missing default image
|
||||
/*
|
||||
$isMissingDefaluts = $this->isAddonMissingDefaults();
|
||||
if($isMissingDefaluts == true)
|
||||
$this->arrMessages[] = __("Missing Default Items!","unlimited-elements-for-elementor");
|
||||
|
||||
//check if missing default url
|
||||
$isMissingDefalutImage = $this->isAddonMissingImageUrl();
|
||||
if($isMissingDefalutImage == true)
|
||||
$this->arrMessages[] = __("Missing Default Image!","unlimited-elements-for-elementor");
|
||||
*/
|
||||
|
||||
$hasNonExistingIncludes = $this->isHasNonExistingIncludes();
|
||||
if($hasNonExistingIncludes == true)
|
||||
$this->arrMessages[] = __("Not existing include file!","unlimited-elements-for-elementor");
|
||||
|
||||
/*
|
||||
$htmlNotValid = $this->isHasNonValidHtml();
|
||||
if($htmlNotValid == true)
|
||||
$this->arrMessages[] = __("Not valid HTML!", "unlimited-elements-for-elementor");
|
||||
*/
|
||||
|
||||
$this->validateExtraValidations();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* validate devider
|
||||
*/
|
||||
protected function validateShapeDevider(){
|
||||
|
||||
$html = $this->objAddon->getHtml();
|
||||
$pos = strpos($html, 'g fill="#ffffff"');
|
||||
if($pos === false)
|
||||
$this->arrMessages[] = __("Not valid fill color!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* run the validation
|
||||
*/
|
||||
protected function runValidations(){
|
||||
|
||||
$addonType = $this->objAddon->getObjAddonType();
|
||||
|
||||
$type = $addonType->typeNameDistinct;
|
||||
|
||||
switch($type){
|
||||
case GlobalsUC::ADDON_TYPE_BGADDON:
|
||||
case GlobalsUC::ADDON_TYPE_REGULAR_ADDON:
|
||||
case GlobalsUC::ADDON_TYPE_ELEMENTOR:
|
||||
$this->validateRegularAddon();
|
||||
break;
|
||||
case GlobalsUC::ADDON_TYPE_SHAPE_DEVIDER:
|
||||
$this->validateShapeDevider();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get messages html
|
||||
*/
|
||||
public function getHtmlMessages(){
|
||||
|
||||
if(empty($this->arrMessages))
|
||||
return("");
|
||||
|
||||
$html = "";
|
||||
foreach($this->arrMessages as $index => $message){
|
||||
|
||||
$class = "";
|
||||
if($index > 0)
|
||||
$class = " uc-master-second";
|
||||
|
||||
if($index > 1)
|
||||
$class = " uc-master-third";
|
||||
|
||||
$message = esc_html($message);
|
||||
|
||||
$html .= "<div class='uc-manager-addon-validation-message{$class}'>{$message}</div>";
|
||||
}
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate addon, throw error with message if found
|
||||
*/
|
||||
public function isValid(UniteCreatorAddon $objAddon){
|
||||
|
||||
$this->init($objAddon);
|
||||
|
||||
$this->runValidations();
|
||||
|
||||
if(!empty($this->arrMessages))
|
||||
return(false);
|
||||
else
|
||||
return(true);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAjaxSeach{
|
||||
|
||||
public static $arrCurrentParams;
|
||||
public static $customSearchEnabled = false;
|
||||
|
||||
private $searchMetaKey = "";
|
||||
|
||||
|
||||
/**
|
||||
* on posts response
|
||||
*/
|
||||
public function onPostsResponse($arrPosts, $value, $filters){
|
||||
|
||||
if(GlobalsProviderUC::$isUnderAjaxSearch == false)
|
||||
return($arrPosts);
|
||||
|
||||
$name = UniteFunctionsUC::getVal($value, "uc_posts_name");
|
||||
|
||||
$args = GlobalsProviderUC::$lastQueryArgs;
|
||||
|
||||
$maxItems = UniteFunctionsUC::getVal($args, "posts_per_page", 9);
|
||||
|
||||
$numPosts = count($arrPosts);
|
||||
|
||||
//if maximum reached - return the original
|
||||
|
||||
if($numPosts >= $maxItems)
|
||||
return($arrPosts);
|
||||
|
||||
$search = $args["s"];
|
||||
|
||||
unset($args["s"]);
|
||||
|
||||
//search in meta
|
||||
|
||||
if(!empty($this->searchMetaKey)){
|
||||
|
||||
$arrMetaItem = array(
|
||||
'key' => $this->searchMetaKey,
|
||||
'value' => $search,
|
||||
'compare' => "LIKE"
|
||||
);
|
||||
|
||||
$arrMetaQuery = array("relation"=>"OR",$arrMetaItem);
|
||||
|
||||
$arrExistingMeta = UniteFunctionsUC::getVal($args, "meta_query",array());
|
||||
|
||||
$args["meta_query"] = array_merge($arrExistingMeta, $arrMetaQuery);
|
||||
}
|
||||
|
||||
$query = new WP_Query();
|
||||
$query->query($args);
|
||||
|
||||
$arrNewPosts = $query->posts;
|
||||
|
||||
|
||||
$arrPosts = array_merge($arrPosts, $arrNewPosts);
|
||||
|
||||
return($arrPosts);
|
||||
}
|
||||
|
||||
/**
|
||||
* supress third party filters except of this class ones
|
||||
*/
|
||||
public static function supressThirdPartyFilters(){
|
||||
|
||||
global $wp_filter;
|
||||
|
||||
if(self::$customSearchEnabled == false){
|
||||
|
||||
$wp_filter = array();
|
||||
return(false);
|
||||
}
|
||||
|
||||
$arrKeys = array("uc_filter_posts_list");
|
||||
|
||||
$newFilters = array();
|
||||
|
||||
foreach($arrKeys as $key){
|
||||
|
||||
$filter = UniteFunctionsUC::getVal($wp_filter, $key);
|
||||
|
||||
if(!empty($filter))
|
||||
$newFilters[$key] = $filter;
|
||||
}
|
||||
|
||||
$wp_filter = $newFilters;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the ajax search - before the get posts accure, from ajax request
|
||||
*/
|
||||
public function initCustomAjaxSeach(UniteCreatorAddon $addon){
|
||||
|
||||
$arrParams = $addon->getProcessedMainParamsValues(UniteCreatorParamsProcessor::PROCESS_TYPE_CONFIG);
|
||||
|
||||
self::$arrCurrentParams = $arrParams;
|
||||
|
||||
$searchInMeta = UniteFunctionsUC::getVal($arrParams, "search_in_meta");
|
||||
$searchInMeta = UniteFunctionsUC::strToBool($searchInMeta);
|
||||
|
||||
if($searchInMeta == true){
|
||||
|
||||
self::$customSearchEnabled = true;
|
||||
|
||||
$this->searchMetaKey = "country";
|
||||
|
||||
UniteProviderFunctionsUC::addFilter("uc_filter_posts_list", array($this,"onPostsResponse"),10,3);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,484 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Unlimited Elements
|
||||
* @author unlimited-elements.com
|
||||
* @copyright (C) 2021 Unlimited Elements, All Rights Reserved.
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* */
|
||||
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
|
||||
|
||||
class UniteCreatorAssetsWork extends UniteCreatorAssets{
|
||||
|
||||
private $pathAssetsBase;
|
||||
|
||||
|
||||
/**
|
||||
* init includes asset type
|
||||
*/
|
||||
private function initIncludesType($objAddon){
|
||||
|
||||
$this->setOption(self::OPTION_ID, "uc_includes_browser");
|
||||
$this->setOption(self::OPTION_CHECKBOX_ON_TYPES, array("css","js"));
|
||||
|
||||
$this->setBrowserMode();
|
||||
$this->setStartPath($this->pathAssetsBase);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init folder browser type
|
||||
*/
|
||||
private function initFolderBrowserType(){
|
||||
|
||||
$this->setBrowserMode();
|
||||
|
||||
$this->setStartPath($this->pathAssetsBase);
|
||||
|
||||
$this->setOption(self::OPTION_PUT_ACTIVEPATH, false);
|
||||
$this->setOption(self::OPTION_FOLDERS_ONLY, true);
|
||||
$this->setOption(self::OPTION_SINGLE_ITEM_SELECT, true);
|
||||
$this->setOption(self::OPTION_FILTER_FOLDER_NAMES, array(GlobalsUC::DIR_THUMBS));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set image and audio types common features
|
||||
*/
|
||||
private function setImageAudioBrowserCommon(){
|
||||
|
||||
$this->setStartPath($this->pathAssetsBase);
|
||||
$this->setBrowserMode();
|
||||
|
||||
$this->setOption(self::OPTION_PUT_ACTIVEPATH, true);
|
||||
$this->setOption(self::OPTION_SINGLE_ITEM_SELECT, true);
|
||||
$this->setOption(self::OPTION_DISABLE_CHECKBOXES, true);
|
||||
$this->setOption(self::OPTION_FILTER_FOLDER_NAMES, array(GlobalsUC::DIR_THUMBS, GlobalsUC::DIR_THUMBS_ELFINDER));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init image browser type
|
||||
*/
|
||||
private function initImageBrowserType(){
|
||||
|
||||
$this->setImageAudioBrowserCommon();
|
||||
|
||||
$this->setOption(self::OPTION_SHOW_ONLY_TYPES, array(self::FILETYPE_IMAGE));
|
||||
$this->setOption(self::OPTION_THUMBS_VIEW, true);
|
||||
$this->setOption(self::OPTION_SHOW_FILE_EXTENTIONS, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init image browser type
|
||||
*/
|
||||
private function initAudioBrowserType(){
|
||||
|
||||
$this->setImageAudioBrowserCommon();
|
||||
|
||||
$this->setOption(self::OPTION_SHOW_ONLY_TYPES, array(self::FILETYPE_AUDIO));
|
||||
$this->setOption(self::OPTION_THUMBS_VIEW, false);
|
||||
$this->setOption(self::OPTION_SHOW_FILE_EXTENTIONS, true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* init assets manager
|
||||
*/
|
||||
private function initAssetsManager(){
|
||||
|
||||
$this->setStartPath($this->pathAssetsBase);
|
||||
$this->setOption(self::OPTION_ID, "uc_assets_manager");
|
||||
$this->setOption(self::OPTION_FILTER_FOLDER_NAMES, array(GlobalsUC::DIR_THUMBS));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init the assets manager by key
|
||||
* each key has it's own options
|
||||
*/
|
||||
public function initByKey($key, $objAddon = null){
|
||||
|
||||
//set assets path
|
||||
$this->pathAssetsBase = GlobalsUC::$pathAssets;
|
||||
if(!empty($objAddon)){
|
||||
$this->objAddon = $objAddon;
|
||||
$this->pathAssetsBase = $objAddon->getPathAssetsBase();
|
||||
}
|
||||
|
||||
if(empty($key))
|
||||
return(false);
|
||||
|
||||
$this->setDefaultOptions();
|
||||
|
||||
switch($key){
|
||||
case "includes":
|
||||
$this->initIncludesType($objAddon);
|
||||
break;
|
||||
case "assets_manager":
|
||||
$this->initAssetsManager();
|
||||
break;
|
||||
case "folder_browser":
|
||||
$this->initFolderBrowserType();
|
||||
break;
|
||||
case "image_browser":
|
||||
$this->initImageBrowserType();
|
||||
break;
|
||||
case "audio_browser":
|
||||
$this->initAudioBrowserType();
|
||||
break;
|
||||
default:
|
||||
UniteFunctionsUC::throwError("Wrong manager key: $key");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->pathKey = $key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set path key from data
|
||||
*/
|
||||
private function initFromData($data){
|
||||
|
||||
$key = UniteFunctionsUC::getVal($data, "pathkey");
|
||||
$addonID = UniteFunctionsUC::getVal($data, "addonID");
|
||||
|
||||
if(!empty($addonID)){
|
||||
$this->objAddon = new UniteCreatorAddon();
|
||||
$this->objAddon->initByID($addonID);
|
||||
}
|
||||
|
||||
$this->initByKey($key, $this->objAddon);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get options for client
|
||||
*/
|
||||
protected function getArrOptionsForClient(){
|
||||
|
||||
$arrOptions = parent::getArrOptionsForClient();
|
||||
|
||||
if(!empty($this->objAddon)){
|
||||
|
||||
$addonID = $this->objAddon->getID();
|
||||
$arrOptions["addon_id"] = $addonID;
|
||||
}
|
||||
|
||||
return($arrOptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get filelist from data
|
||||
*/
|
||||
public function getHtmlFilelistFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$startPath = UniteFunctionsUC::getVal($data, "startpath");
|
||||
|
||||
if(!empty($startPath))
|
||||
$this->setCustomStartPath($startPath);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete files
|
||||
*/
|
||||
public function deleteFilesFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
|
||||
$arrFiles = UniteFunctionsUC::getVal($data, "arrFiles");
|
||||
|
||||
$this->deleteFiles($path, $arrFiles);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle upload files
|
||||
*/
|
||||
public function handleUploadFiles(){
|
||||
|
||||
//get upload path
|
||||
$uploadPath = UniteFunctionsUC::getPostVariable("upload_path","",UniteFunctionsUC::SANITIZE_NOTHING);
|
||||
$uploadPath = $this->sanitizePath($uploadPath);
|
||||
|
||||
if(empty($uploadPath))
|
||||
UniteFunctionsUC::throwError("Empty upload path");
|
||||
|
||||
//move uploaded file
|
||||
$arrFile = UniteFunctionsUC::getVal($_FILES, "file");
|
||||
|
||||
if(empty($arrFile))
|
||||
UniteFunctionsUC::throwError("No uploaded files found");
|
||||
|
||||
$this->handleUploadFile($uploadPath, $arrFile);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create folder from data
|
||||
*/
|
||||
private function createFolderFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$folderName = UniteFunctionsUC::getVal($data, "folder_name");
|
||||
|
||||
$this->createFolder($path, $folderName);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create folder from data
|
||||
*/
|
||||
private function createFileFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$filename = UniteFunctionsUC::getVal($data, "filename");
|
||||
|
||||
$this->createFile($path, $filename);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rename file from data
|
||||
*/
|
||||
private function renameFileFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$filename = UniteFunctionsUC::getVal($data, "filename");
|
||||
$filenameNew = UniteFunctionsUC::getVal($data, "filename_new");
|
||||
|
||||
$this->renameFile($path, $filename, $filenameNew);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get content from data
|
||||
* $data
|
||||
*/
|
||||
function getContentFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$filename = UniteFunctionsUC::getVal($data, "filename");
|
||||
|
||||
$content = $this->getFileContent($path, $filename);
|
||||
|
||||
return($content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* save file from data
|
||||
*/
|
||||
private function saveFileFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$filename = UniteFunctionsUC::getVal($data, "filename");
|
||||
$content = UniteFunctionsUC::getVal($data, "content");
|
||||
|
||||
$this->saveFileContent($path, $filename, $content);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* move files from data
|
||||
* @param $data
|
||||
*/
|
||||
private function moveFilesFromData($data){
|
||||
|
||||
$pathSource = UniteFunctionsUC::getVal($data, "pathSource");
|
||||
$arrFiles = UniteFunctionsUC::getVal($data, "arrFiles");
|
||||
$pathTarget = UniteFunctionsUC::getVal($data, "pathTarget");
|
||||
$actionOnExists = UniteFunctionsUC::getVal($data, "actionOnExists");
|
||||
|
||||
$message = $this->moveFiles($pathSource, $arrFiles, $pathTarget, $actionOnExists);
|
||||
|
||||
if(!empty($message)){
|
||||
$response = array("done"=>false,"message"=>$message);
|
||||
}
|
||||
else{
|
||||
$html = $this->getHtmlDir($pathSource);
|
||||
$response["html"] = $html;
|
||||
$response["message"] = esc_html__("files moved successfully", "unlimited-elements-for-elementor");
|
||||
}
|
||||
return($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* unzip files from data
|
||||
*/
|
||||
private function unzipFileFromData($data){
|
||||
|
||||
$path = UniteFunctionsUC::getVal($data, "path");
|
||||
$filename = UniteFunctionsUC::getVal($data, "filename");
|
||||
|
||||
$this->unzipFile($path, $filename);
|
||||
|
||||
//set checked file
|
||||
$this->setCheckedFiles($path, $filename);
|
||||
|
||||
$html = $this->getHtmlDir($path);
|
||||
return($html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* do ajax actions browser related
|
||||
*/
|
||||
private function checkAjaxActions_browser($action, $data){
|
||||
|
||||
switch($action){
|
||||
case "assets_get_filelist":
|
||||
$this->validateInited();
|
||||
|
||||
$htmlFilelist = $this->getHtmlFilelistFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
default:
|
||||
return(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* do ajax actions manager related
|
||||
*/
|
||||
private function checkAjaxActions_editor($action, $data){
|
||||
|
||||
switch($action){
|
||||
case "assets_upload_files":
|
||||
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$this->validateInited();
|
||||
|
||||
$this->handleUploadFiles();
|
||||
break;
|
||||
case "assets_get_filelist":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->getHtmlFilelistFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
case "assets_delete_files":
|
||||
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->deleteFilesFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
case "assets_create_folder":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->createFolderFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
case "assets_create_file":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->createFileFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
case "assets_rename_file":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->renameFileFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
case "assets_get_file_content":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$content = $this->getContentFromData($data);
|
||||
HelperUC::ajaxResponseData(array("content"=>$content));
|
||||
break;
|
||||
case "assets_save_file":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$this->saveFileFromData($data);
|
||||
HelperUC::ajaxResponseSuccess(esc_html__("File Saved", "unlimited-elements-for-elementor"));
|
||||
break;
|
||||
case "assets_move_files":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$response = $this->moveFilesFromData($data);
|
||||
HelperUC::ajaxResponseData($response);
|
||||
break;
|
||||
case "assets_unzip_file":
|
||||
$this->validateInited();
|
||||
HelperProviderUC::verifyAdminPermission();
|
||||
|
||||
$htmlFilelist = $this->unzipFileFromData($data);
|
||||
HelperUC::ajaxResponseData(array("html"=>$htmlFilelist));
|
||||
break;
|
||||
default:
|
||||
return(false);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* run ajax actions
|
||||
*/
|
||||
public function checkAjaxActions($action, $data){
|
||||
|
||||
$this->initFromData($data);
|
||||
|
||||
if($this->isBrowerMode == true){
|
||||
return $this->checkAjaxActions_browser($action, $data);
|
||||
}else{
|
||||
return $this->checkAjaxActions_editor($action, $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user