tabs; } /** * Plugin menu link. * * Adds link to admin menu under Elementor menu * * Fired by `admin_menu` action. * * @since 1.0.0 * @access public */ public function admin_pages() { /* translators: %s: Theme name */ $temp = AIDA_PLUGIN_NAME; add_submenu_page( 'elementor', $temp, $temp, 'manage_options', $this->importer_page, [ $this, 'display_import_page' ] ); } /** * Display import page. * * Output the content for the import page. * * @since 1.0 * @access public */ public function display_import_page() { $tabs = $this->get_tabs(); ?>

get_page_title(); ?>


$tab ) { $active_class = ''; if ( 'import' === $tab_id ) { $active_class = ' active-section'; } echo '
'; $section_method = 'tab_section_'.$tab_id; if( method_exists( $this, $section_method ) ){ $this->$section_method(); } echo '
'; } ?>
display_import_page() * * @since 1.0 * @access public */ public function tab_section_import() { ?>

<?php esc_html_e( 'Image of templates to import.', 'ai-elementor'); ?>


display_import_page() * * @since 1.0 * @access public */ public function tab_section_instructions() { ?>

<?php esc_html_e( 'Add templates button in Elementor', 'ai-elementor'); ?>

<?php esc_html_e( 'Import templates in Elementor', 'ai-elementor'); ?>

display_import_page() * * @since 1.0 * @access public */ public function tab_section_apollo13themes() { ?>

'', //empty to avoid bonus logic 'start' => esc_html__( 'Starting import', 'ai-elementor' ), 'download_files' => esc_html__( 'Downloading files', 'ai-elementor' ), 'install_content' => esc_html__( 'Importing templates', 'ai-elementor' ), 'clean' => esc_html__( 'Cleaning...', 'ai-elementor' ), 'end' => esc_html__( 'Everything done!', 'ai-elementor' ), ); if($pack === 'free'){ unset( $levels['start'] ); unset( $levels['download_files'] ); unset( $levels['clean'] ); } //get current level key if ( strlen( $level ) === 0 ) { //get first level to process $level = key( $levels ); } else { //move array pointer to current importing level while ( key( $levels ) !== $level ) { //and ask for next one next( $levels ); $array_index++; } //save new current level $level = key( $levels ); } //Execute current level function $method = 'import_' . $level; if ( method_exists( $this, $method ) ) { //no notices or other "echos", we put it in $log ob_start(); $sublevel = $this->$method( $sublevel, $sublevel_name ); //collect all produced output to log $log = ob_get_contents(); ob_end_clean(); //should we move to next level if ( $sublevel === true ) { $sublevel = ''; //reset next( $levels ); $level = key( $levels ); } } //no function - move to next level. Some steps are just information without action else { next( $levels ); $array_index ++; $level = key( $levels ); } //check if this is last element $is_it_end = false; end( $levels ); if ( key( $levels ) === $level ) { $is_it_end = true; } //prepare progress info $progress = round( 100 * ( 1 + $array_index ) / count( $levels ) ); $result = [ 'level' => $level, 'level_name' => $levels[ $level ], 'sublevel' => $sublevel, 'sublevel_name' => $sublevel_name, 'log' => $log, 'progress' => $progress, 'is_it_end' => $is_it_end ]; //send AJAX response echo json_encode( sizeof( $result ) ? $result : false ); die(); //this is required to return a proper result } /** * Import process - import content * * Part of import process responsible for importing posts * * Fired by $this->import_templates() * * @since 1.0 * @access public */ private function import_install_content($sublevel, &$sublevel_name){ //imports templates $dir = AIDA_PATH . '/data/'; $templates = array(); //get all templates to import if ( is_dir( $dir ) ) { //The GLOB_BRACE flag is not available on some non GNU systems, like Solaris. So we use merge:-) foreach ( (array) glob( $dir . '/*.json' ) as $file ) { $templates[] = basename( $file ); } } if ( strlen( $sublevel ) === 0 ) {//we will import first template on list but in second call of this function $sublevel = key( $templates ); $sublevel_name = $templates[ $sublevel ]; } else { //save last template end( $templates ); $last_template = key( $templates ); reset( $templates ); $sublevel = (int) $sublevel;//convert from string type // template to import now $file = $dir . $templates[ $sublevel ]; /** @var \Elementor\TemplateLibrary\Source_Local $source */ $source = \Elementor\Plugin::instance()->templates_manager->get_source( 'local' ); $source->import_template( $templates[ $sublevel ], $file ); //if this was last plugin on list then we end this process if ( $last_template === $sublevel ) { $sublevel = true; } else{ //move to next template to import $sublevel++; $sublevel_name = $templates[ $sublevel ]; } } return $sublevel; } /** * Importer constructor. * * @since 1.0.0 * @access public */ public function __construct() { add_action( 'admin_menu', array(&$this, 'admin_pages'), 600 ); //as last item add_action( 'wp_ajax_a13ree_import_templates', array(&$this, 'import_templates') ); $this->tabs = [ 'import' => esc_html__( 'Templates import', 'ai-elementor' ), 'instructions' => esc_html__( 'Plugin Instructions', 'ai-elementor' ), 'apollo13themes' => esc_html__( 'More from Codenpy.com', 'ai-elementor' ) ]; } } new AI_Data_Importer();