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->defaultView, "default view"); UniteFunctionsUC::validateNotEmpty($this->pluginTitle, "plugin title"); //update globals GlobalsUC::$view_default = $this->defaultView; GlobalsUC::$defaultAddonType = $this->defaultAddonType; parent::__construct(); $this->init(); } /** * process activate event - install the db (with delta). */ public function onActivate(){ $this->createTables(); $this->importCurrentThemeAddons(); //import addons that comes in the addon library package $this->importPackageAddons(); } /** * after switch theme */ public function afterSwitchTheme(){ $this->importCurrentThemeAddons(); } /** * do all actions on theme setup */ public function onThemeSetup(){ } /** * create the tables if not exists */ public function createTables($isForce = false){ $this->createTable(GlobalsUC::TABLE_ADDONS_NAME, $isForce); $this->createTable(GlobalsUC::TABLE_CATEGORIES_NAME, $isForce); $isAddonChangelogEnabled = HelperProviderUC::isAddonChangelogEnabled(); if($isAddonChangelogEnabled === true) $this->createTable(GlobalsUC::TABLE_CHANGELOG_NAME, $isForce); $isFormEntriesEnabled = HelperProviderUC::isFormEntriesEnabled(); if($isFormEntriesEnabled === true){ $this->createTable(GlobalsUC::TABLE_FORM_ENTRIES_NAME, $isForce); $this->createTable(GlobalsUC::TABLE_FORM_ENTRY_FIELDS_NAME, $isForce); } } /** * create tables */ public function createTable($tableName, $isForce = false){ global $wpdb; //if table exists - don't create it. $tableRealName = UniteFunctionsWPUC::prefixDBTable($tableName); if($isForce == false && UniteFunctionsWPUC::isDBTableExists($tableRealName)) return; $charset_collate = $wpdb->get_charset_collate(); switch($tableName){ case GlobalsUC::TABLE_LAYOUTS_NAME: $sql = "CREATE TABLE " . $tableRealName . " ( id INT(9) NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, layout_data MEDIUMTEXT, ordering INT NOT NULL, catid INT NOT NULL, layout_type VARCHAR(60), relate_id INT NOT NULL, parent_id INT NOT NULL, params TEXT NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; break; case GlobalsUC::TABLE_CATEGORIES_NAME: $sql = "CREATE TABLE " . $tableRealName . " ( id INT(9) NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, alias VARCHAR(255), ordering INT NOT NULL, params TEXT NOT NULL, type TINYTEXT, parent_id INT(9), PRIMARY KEY (id) ) $charset_collate;"; break; case GlobalsUC::TABLE_ADDONS_NAME: $sql = "CREATE TABLE " . $tableRealName . " ( id BIGINT(20) NOT NULL AUTO_INCREMENT, title VARCHAR(255), name VARCHAR(128), alias VARCHAR(128), addontype VARCHAR(128), description TEXT, ordering INT NOT NULL, templates MEDIUMTEXT, config MEDIUMTEXT, catid INT, is_active TINYINT, test_slot1 TEXT, test_slot2 TEXT, test_slot3 TEXT, PRIMARY KEY (id) ) $charset_collate;"; break; case GlobalsUC::TABLE_CHANGELOG_NAME: $isAddonChangelogEnabled = HelperProviderUC::isAddonChangelogEnabled(); if($isAddonChangelogEnabled === false) return; $sql = "CREATE TABLE " . $tableRealName . " ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, addon_id BIGINT(20) UNSIGNED NOT NULL, addon_title VARCHAR(255) NOT NULL, user_id BIGINT(20) UNSIGNED NULL, type VARCHAR(32) NOT NULL, text TEXT NOT NULL, plugin_version VARCHAR(32) NOT NULL, created_at DATETIME NOT NULL, PRIMARY KEY (id), INDEX addon_id_index (addon_id) ) $charset_collate;"; break; case GlobalsUC::TABLE_FORM_ENTRIES_NAME: $isFormEntriesEnabled = HelperProviderUC::isFormEntriesEnabled(); if($isFormEntriesEnabled === false) return; $sql = "CREATE TABLE " . $tableRealName . " ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, form_name VARCHAR(64) NOT NULL, post_id BIGINT(20) UNSIGNED NOT NULL, post_title VARCHAR(300) NOT NULL, post_url VARCHAR(500) NOT NULL, user_id BIGINT(20) UNSIGNED NULL, user_ip VARCHAR(46) NOT NULL, user_agent TEXT NOT NULL, created_at DATETIME NOT NULL, seen_at DATETIME NULL, deleted_at DATETIME NULL, PRIMARY KEY (id), INDEX form_name_index (form_name), INDEX post_id_index (post_id), INDEX post_title_index (post_title) ) $charset_collate;"; break; case GlobalsUC::TABLE_FORM_ENTRY_FIELDS_NAME: $isFormEntriesEnabled = HelperProviderUC::isFormEntriesEnabled(); if($isFormEntriesEnabled === false) return; $sql = "CREATE TABLE " . $tableRealName . " ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, entry_id BIGINT(20) UNSIGNED NOT NULL, title VARCHAR(128) NULL, name VARCHAR(64) NULL, type VARCHAR(32) NULL, value LONGTEXT NULL, PRIMARY KEY (id), INDEX entry_id_index (entry_id) ) $charset_collate;"; break; default: UniteFunctionsUC::throwError("table: $tableName not found"); break; } require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * check db upgrae from admin_init - for plugin update */ private function checkDBUpgrade(){ $optionDBVersion = "unitecreator_db_version"; $savedDBVersion = get_option($optionDBVersion); if($savedDBVersion != $this->dbVersion){ $this->createTables(true); update_option($optionDBVersion, $this->dbVersion); } } /** * * add ajax back end callback, on some action to some function. */ 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); } /** * * register the "onActivate" event */ protected function addEvent_onActivate($eventFunc = "onActivate"){ register_activation_hook($this->mainFilepath, array($this, $eventFunc)); } /** * * tells if the the current plugin opened is this plugin or not * in the admin side. */ 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); } /** * * add some wordpress action */ protected function addAction($action, $eventFunction, $isStatic = false, $numArgs = 1, $priority = 10){ if($isStatic == false){ add_action($action, array($this, $eventFunction), $priority, $numArgs); }else{ add_action($action, array(self::$t, $eventFunction), $priority, $numArgs); } } /** * add local filter */ protected function addLocalFilter($tag, $func, $numArgs = 1){ add_filter($tag, array($this, $func), 10, $numArgs); } /** * * validate admin permissions, if no pemissions - exit */ protected function validateAdminPermissions(){ if(UniteFunctionsWPUC::isAdminPermissions() == false){ echo "access denied, no admin permissions"; return (false); } } /** * admin main page function. */ 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(); } /** * add scripts to all admin pages */ public function addScriptsToAllAdminPages(){ HelperUC::addStyleAbsoluteUrl(GlobalsUC::$url_provider . "assets/provider_admin.css", "uc_provider_admin"); } /** * add outside plugin scripts */ public function onAddOutsideScripts(){ try{ //add outside scripts, only on posts or pages page $isPostsPage = UniteFunctionsWPUC::isAdminPostsPage(); $this->addScriptsToAllAdminPages(); }catch(Exception $e){ HelperHtmlUC::outputException($e); } } /** * print custom scripts */ public function onPrintFooterScripts(){ HelperProviderUC::onPrintFooterScripts(); } private static function a_________MENU__________(){ } /** * * add menu page */ protected function addMenuPage($title, $pageFunctionName, $icon = null, $link = null, $menuSlug = null){ self::$arrMenuPages[] = array("title" => $title, "pageFunction" => $pageFunctionName, "icon" => $icon, "link" => $link, "slug" => $menuSlug); } /** * * add sub menu page */ protected function addSubMenuPage($slug, $title, $pageFunctionName, $realLink = false, $parentSlug = null){ self::$arrSubMenuPages[] = array("slug" => $slug, "title" => $title, "pageFunction" => $pageFunctionName, "realLink" => $realLink, "parentSlug" => $parentSlug); } /** * put admin menu actually */ 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)); //switch the link for real link 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; } } //clean double submenus if(!empty($cleanTitle) && isset($submenu[$mainMenuSlug])){ $arrSubMenu = $submenu[$mainMenuSlug]; if($arrSubMenu[0][0] == $cleanTitle) unset($submenu[$mainMenuSlug][0]); } } /** * add admin menus from the list. */ public function addAdminMenu(){ //add blox menu $this->addAdminMenu_putActually(self::$arrMenuPages, self::$arrSubMenuPages); //add plugins menu $arrMenuPages = UniteCreatorAdminWPPluginBase::getArrMenuPages(); $arrSubMenuPages = UniteCreatorAdminWPPluginBase::getArrSubmenuPages(); $this->addAdminMenu_putActually($arrMenuPages, $arrSubMenuPages); /* global $menu, $submenu; dmp($menu); dmp($submenu); exit(); */ } private static function a_______IMPORT_ADDONS________(){ } /** * install addosn from some path */ protected function installAddonsFromPath($pathAddons, $addonsType = null){ if(empty($addonsType)) $addonsType = $this->defaultAddonType; if(is_dir($pathAddons) == false) return (false); $exporter = new UniteCreatorExporter(); $exporter->setMustImportAddonType($addonsType); $exporter->importAddonsFromFolder($pathAddons); } /** * import current theme addons */ private function importCurrentThemeAddons(){ $pathCurrentTheme = get_template_directory() . "/"; $dirAddons = apply_filters("ue_path_theme_addons", GlobalsUC::DIR_THEME_ADDONS); $pathAddons = $pathCurrentTheme . $dirAddons . "/"; $this->installAddonsFromPath($pathAddons); } /** * import package addons */ protected function importPackageAddons(){ $pathAddons = GlobalsUC::$pathPlugin . self::DIR_INSTALL_ADDONS . "/"; if(is_dir($pathAddons) == false) return (false); $imported = false; //install vc addons $pathAddonsVC = $pathAddons . $this->defaultAddonType . "/"; if(is_dir($pathAddonsVC)){ $this->installAddonsFromPath($pathAddonsVC, $this->defaultAddonType); $imported = true; } return ($imported); } /** * set editor permission * in default it's admin menu permission */ protected function setPermissionEditor(){ $this->capability = "edit_posts"; } private static function a_____OTHERS____(){ } /** * return if creator plugin exists */ 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); } /** * after update plugin * install package addons, then redirect to dashboard */ private function onAfterUpdatePlugin(){ $isImported = $this->importPackageAddons(); if($isImported == false) return (false); //redirect to main view $urlRedirect = HelperUC::getViewUrl_Default(); dmp("addons installed, redirecting..."); echo ""; exit(); } /** * run provider action if exists - only if inside plugin */ 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; } } /** * * plugin action links */ public function plugin_action_links($links){ $settings_link = sprintf('%s', admin_url('admin.php?page=' . Settings::PAGE_ID), __('Settings', 'elementor')); array_unshift($links, $settings_link); $links['go_pro'] = sprintf('%s', Utils::get_pro_link('https://elementor.com/pro/?utm_source=wp-plugins&utm_campaign=gopro&utm_medium=wp-dash'), __('Go Pro', 'elementor')); return $links; } /** * create tables if not created on multisite */ 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); } /** * get admin page body */ private function getAdminPageBody(){ ob_start(); $this->adminPages(); $content = ob_get_contents(); ob_end_clean(); return ($content); } /** * load in blank window html */ private function loadBlankWindowAdminPage($superClear = false){ if($superClear == true){ //clear all styles global $wp_styles; if(empty($wp_styles)) $wp_styles = new WP_Styles(); $wp_styles->queue = array(); }else{ //add wp styles wp_enqueue_style('colors'); wp_enqueue_style('ie'); //wp_auth_check_load(); 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); ?>