File "provider_admin.class.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/unlimited-elements-for-elementor/provider/provider_admin.class.php
File
size: 20.78 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UniteProviderAdminUC extends UniteCreatorAdmin
{
private $dbVersion = "2";
private static $arrMenuPages = array();
private static $arrSubMenuPages = array();
protected $capability = "manage_options";
public static $isUserHasCapability = true;
public static $adminTitle = null;
protected $mainFilepath;
protected $pluginFilebase;
private $dirPlugin;
protected $pluginName;
protected $arrAllowedViews = array();
private static $t;
const ACTION_ADMIN_MENU = "admin_menu";
const ACTION_ADMIN_INIT = "admin_init";
const ACTION_ADD_SCRIPTS = "admin_enqueue_scripts";
const ACTION_AFTER_SETUP_THEME = "after_setup_theme";
const ACTION_PRINT_SCRIPT = "admin_print_footer_scripts";
const ACTION_AFTER_SWITCH_THEME = "after_switch_theme";
const ACTION_PLUGINS_LOADED = "plugins_loaded";
const DIR_INSTALL_ADDONS = "addons_install";
protected $coreAddonType;
protected $coreAddonsView;
protected $textBuy;
protected $linkBuy;
protected $pluginTitle;
public function __construct($mainFilepath)
{
self::$t = $this;
$this->mainFilepath = $mainFilepath;
$mainFilename = basename($mainFilepath);
$pathPlugin = str_replace('\\', "/", GlobalsUC::$pathPlugin);
$dirPlugins = dirname($pathPlugin) . "/";
$dirPlugin = str_replace($dirPlugins, "", $pathPlugin);
$this->dirPlugin = $dirPlugin;
$this->pluginFilebase = $dirPlugin . $mainFilename;
UniteFunctionsUC::validateNotEmpty($this->coreAddonsView, "core addons view");
UniteFunctionsUC::validateNotEmpty($this->pluginTitle, "plugin title");
GlobalsUC::$view_default = $this->coreAddonsView;
GlobalsUC::$defaultAddonType = $this->coreAddonType;
parent::__construct();
$this->init();
}
public function onActivate()
{
$this->createTables();
$this->importCurrentThemeAddons();
$this->importPackageAddons();
}
public function afterSwitchTheme()
{
$this->importCurrentThemeAddons();
}
public function onThemeSetup()
{
}
public function createTables($isForce = false)
{
$this->createTable(GlobalsUC::TABLE_ADDONS_NAME, $isForce);
$this->createTable(GlobalsUC::TABLE_CATEGORIES_NAME, $isForce);
}
public function createTable($tableName, $isForce = false)
{
global $wpdb;
$tableRealName = $wpdb->prefix . $tableName;
if ($isForce == false && UniteFunctionsWPUC::isDBTableExists($tableRealName)) {
return false;
}
$charset_collate = $wpdb->get_charset_collate();
switch ($tableName) {
case GlobalsUC::TABLE_LAYOUTS_NAME:
$sql = "CREATE TABLE " . $tableRealName . " (\r\n\t\t\t\t\tid int(9) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\ttitle varchar(255) NOT NULL,\r\n\t\t\t\t\tlayout_data mediumtext,\t\t\t\t\t\r\n\t\t\t\t\tordering int not NULL,\r\n\t\t\t\t\tcatid int not NULL,\r\n\t\t\t\t\tlayout_type varchar(60),\r\n\t\t\t\t\trelate_id int not NULL,\r\n\t\t\t\t\tparent_id int not NULL,\r\n\t\t\t\t\tparams text NOT NULL,\r\n\t\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t\t\t){$charset_collate};";
break;
case GlobalsUC::TABLE_CATEGORIES_NAME:
$sql = "CREATE TABLE " . $tableRealName . " (\r\n\t\t\t\t\tid int(9) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\ttitle varchar(255) NOT NULL,\r\n\t\t\t\t\talias varchar(255),\r\n\t\t\t\t\tordering int not NULL,\r\n\t\t\t\t\tparams text NOT NULL,\r\n\t\t\t\t\ttype tinytext,\r\n\t\t\t\t\tparent_id int(9),\r\n\t\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t\t\t){$charset_collate};";
break;
case GlobalsUC::TABLE_ADDONS_NAME:
$sql = "CREATE TABLE " . $tableRealName . " (\r\n\t\t\t\t\tid int(9) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t\ttitle varchar(255),\r\n\t\t\t\t\tname varchar(128),\r\n\t\t\t\t\talias varchar(128),\r\n\t\t\t\t\taddontype varchar(128),\r\n\t\t\t\t\tdescription text,\r\n\t\t\t\t\tordering int not NULL,\r\n\t\t\t\t\ttemplates mediumtext,\r\n\t\t\t\t\tconfig mediumtext,\r\n\t\t\t\t\tcatid int,\r\n\t\t\t\t\tis_active tinyint,\r\n\t\t\t\t\ttest_slot1 text,\t\r\n\t\t\t\t\ttest_slot2 text,\t\r\n\t\t\t\t\ttest_slot3 text,\r\n\t\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t\t\t){$charset_collate};";
break;
default:
UniteFunctionsMeg::throwError("table: {$tableName} not found");
break;
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}
private function checkDBUpgrade()
{
$optionDBVersion = "unitecreator_db_version";
$savedDBVersion = get_option($optionDBVersion);
if ($savedDBVersion != $this->dbVersion) {
$this->createTables(true);
update_option($optionDBVersion, $this->dbVersion);
}
}
protected function addActionAjax($ajaxAction, $eventFunction)
{
$this->addAction('wp_ajax_' . GlobalsUC::PLUGIN_NAME . "_" . $ajaxAction, $eventFunction, true);
$this->addAction('wp_ajax_nopriv_' . GlobalsUC::PLUGIN_NAME . "_" . $ajaxAction, $eventFunction, true);
}
protected function addEvent_onActivate($eventFunc = "onActivate")
{
register_activation_hook($this->mainFilepath, array($this, $eventFunc));
}
protected function isInsidePlugin()
{
$page = UniteFunctionsUC::getGetVar("page", "", UniteFunctionsUC::SANITIZE_KEY);
$isPageMaster = strpos($page, "unlimited-elements-master") !== false;
if ($page == "addon-library-layouts_layout" || $isPageMaster == true) {
return true;
}
if ($page == $this->pluginName || strpos($page, $this->pluginName . "_") !== false || strpos($page, $this->pluginName . "-") !== false) {
return true;
}
return false;
}
protected function addAction($action, $eventFunction, $isStatic = false, $numArgs = 1)
{
if ($isStatic == false) {
add_action($action, array($this, $eventFunction), 10, $numArgs);
} else {
add_action($action, array(self::$t, $eventFunction), 10, $numArgs);
}
}
protected function addLocalFilter($tag, $func, $numArgs = 1)
{
add_filter($tag, array($this, $func), 10, $numArgs);
}
protected function validateAdminPermissions()
{
if (UniteFunctionsWPUC::isAdminPermissions() == false) {
echo "access denied, no admin permissions";
return false;
}
}
public function adminPages()
{
GlobalsUC::$alterViewHeaderPrefix = $this->pluginTitle;
if (!empty($this->arrAllowedViews) && in_array(self::$view, $this->arrAllowedViews) == false) {
echo esc_html__("this view not allowed in the plugin", "unlimited-elements-for-elementor");
return false;
}
$this->createTables();
parent::adminPages();
}
public function addScriptsToAllAdminPages()
{
HelperUC::addStyleAbsoluteUrl(GlobalsUC::$url_provider . "assets/provider_admin.css", "uc_provider_admin");
}
public function onAddOutsideScripts()
{
try {
$isPostsPage = UniteFunctionsWPUC::isAdminPostsPage();
$this->addScriptsToAllAdminPages();
} catch (Exception $e) {
HelperHtmlUC::outputException($e);
}
}
public function onPrintFooterScripts()
{
HelperProviderUC::onPrintFooterScripts();
}
private static function a_________MENU__________()
{
}
protected function addMenuPage($title, $pageFunctionName, $icon = null, $link = null, $menuSlug = null)
{
self::$arrMenuPages[] = array("title" => $title, "pageFunction" => $pageFunctionName, "icon" => $icon, "link" => $link, "slug" => $menuSlug);
}
protected function addSubMenuPage($slug, $title, $pageFunctionName, $realLink = false, $parentSlug = null)
{
self::$arrSubMenuPages[] = array("slug" => $slug, "title" => $title, "pageFunction" => $pageFunctionName, "realLink" => $realLink, "parentSlug" => $parentSlug);
}
public function addAdminMenu_putActually($arrMenuPages, $arrSubMenuPages)
{
global $menu, $submenu;
$cleanTitle = false;
$mainMenuSlug = null;
if (empty($arrMenuPages)) {
return false;
}
foreach ($arrMenuPages as $mainMenu) {
$title = $mainMenu["title"];
$pageFunctionName = $mainMenu["pageFunction"];
$pluginName = UniteFunctionsUC::getVal($mainMenu, "plugin_name");
$menuSlug = UniteFunctionsUC::getVal($mainMenu, "slug");
if (empty($menuSlug) && !empty($pluginName)) {
$menuSlug = $this->pluginName . "-" . $pluginName;
}
if (empty($menuSlug)) {
$menuSlug = $this->pluginName;
}
$icon = "";
if (isset($mainMenu["icon"])) {
$icon = $mainMenu["icon"];
}
add_menu_page($title, $title, $this->capability, $menuSlug, array(self::$t, $pageFunctionName), $icon);
$link = $mainMenu["link"];
$cleanTitle = $title;
$mainMenuSlug = $menuSlug;
if (!empty($link)) {
$cleanTitle = $title;
$mainMenuSlug = $link;
$keys = array_keys($menu);
$lastMainMenuKey = $keys[count($keys) - 1];
$menu[$lastMainMenuKey][2] = $link;
}
}
if (empty($arrSubMenuPages)) {
return false;
}
foreach ($arrSubMenuPages as $key => $submenuMenu) {
$title = $submenuMenu["title"];
$pageFunctionName = $submenuMenu["pageFunction"];
$pluginName = UniteFunctionsUC::getVal($submenuMenu, "plugin_name");
$isRealLink = $submenuMenu["realLink"];
$parentSlug = $submenuMenu["parentSlug"];
if (empty($parentSlug) && !empty($pluginName)) {
$parentSlug = $this->pluginName . "-" . $pluginName;
}
if (empty($parentSlug)) {
$parentSlug = $this->pluginName;
}
$slug = $parentSlug . "_" . $submenuMenu["slug"];
if ($key == 0 && $isRealLink == false) {
$slug = $parentSlug;
}
add_submenu_page($parentSlug, $title, $title, $this->capability, $slug, array(self::$t, $pageFunctionName));
if ($isRealLink === true && isset($submenu[$parentSlug])) {
$arrMain = $submenu[$parentSlug];
$keys = array_keys($arrMain);
$lastKey = $keys[count($keys) - 1];
$arrMain[$lastKey][2] = $submenuMenu["slug"];
$submenu[$parentSlug] = $arrMain;
}
}
if (!empty($cleanTitle) && isset($submenu[$mainMenuSlug])) {
$arrSubMenu = $submenu[$mainMenuSlug];
if ($arrSubMenu[0][0] == $cleanTitle) {
unset($submenu[$mainMenuSlug][0]);
}
}
}
public function addAdminMenu()
{
$this->addAdminMenu_putActually(self::$arrMenuPages, self::$arrSubMenuPages);
$arrMenuPages = UniteCreatorAdminWPPluginBase::getArrMenuPages();
$arrSubMenuPages = UniteCreatorAdminWPPluginBase::getArrSubmenuPages();
$this->addAdminMenu_putActually($arrMenuPages, $arrSubMenuPages);
}
private static function a_______IMPORT_ADDONS________()
{
}
protected function installAddonsFromPath($pathAddons, $addonsType = null)
{
if (empty($addonsType)) {
$addonsType = $this->coreAddonType;
}
if (is_dir($pathAddons) == false) {
return false;
}
$exporter = new UniteCreatorExporter();
$exporter->setMustImportAddonType($addonsType);
$exporter->importAddonsFromFolder($pathAddons);
}
private function importCurrentThemeAddons()
{
$pathCurrentTheme = get_template_directory() . "/";
$dirAddons = apply_filters("blox_path_theme_addons", GlobalsUC::DIR_THEME_ADDONS);
$pathAddons = $pathCurrentTheme . $dirAddons . "/";
$this->installAddonsFromPath($pathAddons);
}
protected function importPackageAddons()
{
$pathAddons = GlobalsUC::$pathPlugin . self::DIR_INSTALL_ADDONS . "/";
if (is_dir($pathAddons) == false) {
return false;
}
$imported = false;
$pathAddonsVC = $pathAddons . $this->coreAddonType . "/";
if (is_dir($pathAddonsVC)) {
$this->installAddonsFromPath($pathAddonsVC, $this->coreAddonType);
$imported = true;
}
return $imported;
}
protected function setPermissionEditor()
{
$this->capability = "edit_posts";
}
private static function a_____OTHERS____()
{
}
protected function isCreatorPluginExists()
{
$arrPlugins = get_plugins();
$pluginName = "addon_library_creator/addon_library_creator.php";
if (isset($arrPlugins[$pluginName]) == false) {
return false;
}
$isActive = is_plugin_active($pluginName);
return $isActive;
}
private function onAfterUpdatePlugin()
{
$isImported = $this->importPackageAddons();
if ($isImported == false) {
return false;
}
$urlRedirect = HelperUC::getViewUrl_Default();
dmp("addons installed, redirecting...");
echo "<script>location.href='{$urlRedirect}'</script>";
exit;
}
private function runProviderAction()
{
$action = UniteFunctionsUC::getGetVar("provider_action", "", UniteFunctionsUC::SANITIZE_KEY);
if (empty($action)) {
return false;
}
switch ($action) {
case "run_after_update":
$this->onAfterUpdatePlugin();
break;
}
}
public function plugin_action_links($links)
{
$settings_link = sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=' . Settings::PAGE_ID), __('Settings', 'elementor'));
array_unshift($links, $settings_link);
$links['go_pro'] = sprintf('<a href="%s" target="_blank" class="elementor-plugins-gopro">%s</a>', Utils::get_pro_link('https://elementor.com/pro/?utm_source=wp-plugins&utm_campaign=gopro&utm_medium=wp-dash'), __('Go Pro', 'elementor'));
return $links;
}
protected function checkMultisiteCreateTables()
{
global $wpdb;
$tablePrefix = $wpdb->prefix;
$option = "addon_library_tables_created_{$tablePrefix}";
$isCreated = get_option($option);
if ($isCreated == true) {
return true;
}
$this->createTables();
update_option($option, true);
}
private function getAdminPageBody()
{
ob_start();
$this->adminPages();
$content = ob_get_contents();
ob_end_clean();
return $content;
}
private function loadBlankWindowAdminPage($superClear = false)
{
if ($superClear == true) {
global $wp_styles;
if (empty($wp_styles)) {
$wp_styles = new WP_Styles();
}
$wp_styles->queue = array();
} else {
wp_enqueue_style('colors');
wp_enqueue_style('ie');
wp_enqueue_style('wp-auth-check');
wp_enqueue_script('wp-auth-check');
add_action('admin_print_footer_scripts', 'wp_auth_check_html', 5);
add_action('wp_print_footer_scripts', 'wp_auth_check_html', 5);
}
self::onAddScripts();
$htmlBody = $this->getAdminPageBody();
$title = UniteFunctionsWPUC::getAdminTitle(self::$adminTitle);
HelperUC::addStyle("blank_page_preview", "uc_blank_page_preview");
$arrCustomStyles = UniteProviderFunctionsUC::getCustomStyles();
$htmlCustomCssStyles = HelperHtmlUC::getHtmlCustomStyles($arrCustomStyles);
$arrJsCustomScripts = UniteProviderFunctionsUC::getCustomScripts();
$htmlJSScripts = HelperHtmlUC::getHtmlCustomScripts($arrJsCustomScripts);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php
echo esc_html($title);
?></title>
<?php
if ($superClear == true) {
print_admin_styles();
} else {
do_action("admin_print_styles");
}
print_head_scripts();
if (!empty($htmlCustomCssStyles)) {
echo "\n" . $htmlCustomCssStyles;
}
$view = self::$view;
?>
</head>
<body class="uc-blank-preview uc-view-<?php
echo esc_attr($view);
?>">
<?php
echo UniteProviderFunctionsUC::escCombinedHtml($htmlBody);
?>
<?php
echo UniteProviderFunctionsUC::escCombinedHtml($htmlJSScripts);
if ($superClear == true) {
print_footer_scripts();
} else {
do_action("admin_footer");
do_action("admin_print_footer_scripts");
}
?>
</body>
</html>
<?php
exit;
}
private function isLayoutBuilderPluginExists()
{
$objPlugins = new UniteCreatorPlugins();
$isExists = $objPlugins->isPluginExists("layouts_builder");
return $isExists;
}
private function checkMigrateFromAddonLibrary()
{
$isExists = $this->isLayoutBuilderPluginExists();
if ($isExists == false) {
return false;
}
$keyMigrate = "blox_is_migrated_from_addon_library";
$isMigrated = UniteProviderFunctionsUC::getOption($keyMigrate);
if ($isMigrated == true) {
return false;
}
$objAddons = new UniteCreatorAddons();
$objAddons->migrateAddonsFromType("wp");
UniteProviderFunctionsUC::updateOption($keyMigrate, true);
}
protected function modifyPluginVariables()
{
if ($this->pluginName == GlobalsUC::PLUGIN_NAME) {
return false;
}
$pluginName = $this->pluginName;
GlobalsUC::$url_component_admin = admin_url() . "admin.php?page={$pluginName}";
GlobalsUC::$url_component_client = GlobalsUC::$url_component_admin;
GlobalsUC::$url_component_admin_nowindow = GlobalsUC::$url_component_admin . "&ucwindow=blank";
}
private function setUserCapability()
{
$data = get_userdata(get_current_user_id());
if (is_object($data) == false) {
return false;
}
$allCaps = $data->allcaps;
$currentCapability = UniteFunctionsUC::getVal($allCaps, $this->capability);
if (empty($currentCapability)) {
self::$isUserHasCapability = false;
}
}
public function onAdminInit()
{
if (is_admin() == false) {
return true;
}
GlobalsUC::initAfterAdminInit();
$this->checkDBUpgrade();
$this->checkMigrateFromAddonLibrary();
$this->setUserCapability();
if (self::isInsidePlugin() == false) {
return true;
}
if (GlobalsUC::$blankWindowMode == false) {
return true;
}
$isSuperClear = UniteFunctionsUC::getGetVar("superclear", "", UniteFunctionsUC::SANITIZE_KEY);
$isSuperClear = UniteFunctionsUC::strToBool($isSuperClear);
$this->loadBlankWindowAdminPage($isSuperClear);
}
protected function addAdminMenuLinks()
{
}
protected function setPluginTitle()
{
}
protected function validateInitValues()
{
UniteFunctionsUC::validateNotEmpty($this->pluginName, "plugin name");
}
public function addAdminBodyClass($classes)
{
if (empty($classes)) {
$classes = "";
}
$classes .= " unite-view-" . self::$view;
return $classes;
}
protected function init()
{
$this->validateInitValues();
UniteProviderFunctionsUC::doAction(UniteCreatorFilters::ACTION_BEFORE_ADMIN_INIT);
parent::init();
HelperProviderUC::globalInit();
if (is_multisite() == true) {
$this->checkMultisiteCreateTables();
}
$this->setPluginTitle();
$this->modifyPluginVariables();
$this->addAdminMenuLinks();
$this->addAction(self::ACTION_ADMIN_MENU, "addAdminMenu");
if ($this->isInsidePlugin() == true) {
$this->addAction(self::ACTION_ADD_SCRIPTS, "onAddScripts", true);
$this->addLocalFilter("admin_body_class", "addAdminBodyClass");
} else {
$this->addAction(self::ACTION_ADD_SCRIPTS, "onAddOutsideScripts");
}
$this->addAction(self::ACTION_PRINT_SCRIPT, "onPrintFooterScripts");
$this->addAction(self::ACTION_AFTER_SWITCH_THEME, "afterSwitchTheme");
$this->addEvent_onActivate();
$this->addActionAjax("ajax_action", "onAjaxAction");
if ($this->isInsidePlugin()) {
$this->runProviderAction();
}
$this->addAction("admin_init", "onAdminInit");
}
}