1<?php 2/** 3 * @package Habari 4 * 5 */ 6 7/** 8 * Habari AdminImportHandler Class 9 * Handles import-related actions in the admin 10 * 11 */ 12class AdminImportHandler extends AdminHandler 13{ 14 /** 15 * Handles GET requests for the import page. 16 */ 17 public function get_import() 18 { 19 // First check for troublesome plugins 20 $bad_features = array( 21 'ping', 22 'pingback', 23 'spamcheck', 24 ); 25 $troublemakers = array(); 26 $plugins = Plugins::list_active(); 27 foreach( $plugins as $plugin ) { 28 $info = Plugins::load_info( $plugin ); 29 $provides = array(); 30 if( isset($info->provides ) ) { 31 foreach( $info->provides->feature as $feature ) { 32 $provides[] = $feature; 33 } 34 } 35 $has_bad = array_intersect( $bad_features, $provides ); 36 if( count( $has_bad ) ) { 37 $troublemakers[] = $info->name; 38 } 39 } 40 if( count( $troublemakers ) ) { 41 $troublemakers = implode( ', ', $troublemakers ); 42 $msg = _t( 'Plugins that conflict with importing are active. To prevent undesirable consequences, please de-activate the following plugins until the import is finished: ' ) . '<br>'; 43 $msg .= $troublemakers; 44 $this->theme->conflicting_plugins = $msg; 45 Session::error( $msg ); 46 } 47 48 // Now get on with creating the page 49 $importer = isset( $_POST['importer'] ) ? $_POST['importer'] : ''; 50 $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : '1'; 51 $step = isset( $_POST['step'] ) ? $_POST['step'] : '1'; 52 53 $this->theme->enctype = Plugins::filter( 'import_form_enctype', 'application/x-www-form-urlencoded', $importer, $stage, $step ); 54 55 // filter to get registered importers 56 $importers = Plugins::filter( 'import_names', array() ); 57 58 // fitler to get the output of the current importer, if one is running 59 if ( $importer != '' ) { 60 $output = Plugins::filter( 'import_stage', '', $importer, $stage, $step ); 61 } 62 else { 63 $output = ''; 64 } 65 66 $this->theme->importer = $importer; 67 $this->theme->stage = $stage; 68 $this->theme->step = $step; 69 $this->theme->importers = $importers; 70 $this->theme->output = $output; 71 72 $this->display( 'import' ); 73 74 } 75 76 /** 77 * Handles the submission of the import form, importing data from a WordPress database. 78 * This function should probably be broken into an importer class, since it is WordPress-specific. 79 */ 80 public function post_import() 81 { 82 if ( !isset( $_POST['importer'] ) ) { 83 Utils::redirect( URL::get( 'admin', 'page=import' ) ); 84 } 85 86 $this->get_import(); 87 } 88 89} 90