• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

system/handlers/adminimporthandler.php

00001 <?php
00007 namespace Habari;
00008 
00014 class AdminImportHandler extends AdminHandler
00015 {
00019   public function get_import()
00020   {
00021     // First check for plugins that provide troublseome features
00022     $features_present = Plugins::provided();
00023     $troublemakers = array();
00024     $bad_features = array(
00025         'ping',
00026         'pingback',
00027         'spamcheck',
00028     );
00029     $unwanted_features = array_intersect_key($features_present, array_flip($bad_features));
00030     array_walk( $unwanted_features, function($item, $key ) use(&$troublemakers) {
00031       foreach( $item as $current ) {
00032         if( !in_array( $current, $troublemakers ) ) {
00033           $troublemakers[] = $current;
00034         }
00035       }
00036     });
00037 
00038     if( count( $troublemakers ) ) {
00039       $troublemakers = implode( ', ', $troublemakers );
00040       $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>';
00041       $msg .= $troublemakers;
00042       $this->theme->conflicting_plugins = $msg;
00043       Session::error( $msg );
00044     }
00045 
00046     // Now get on with creating the page
00047     $importer = isset( $_POST['importer'] ) ? $_POST['importer'] : '';
00048     $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : '1';
00049     $step = isset( $_POST['step'] ) ? $_POST['step'] : '1';
00050 
00051 //    $this->theme->enctype = Plugins::filter( 'import_form_enctype', 'application/x-www-form-urlencoded', $importer, $stage, $step );
00052 
00053     // filter to get registered importers
00054     $importers = Plugins::filter( 'import_names', array() );
00055 
00056     // filter to get the output of the current importer, if one is running
00057     if ( $importer == '' ) {
00058       $output = $this->get_form( $importers, $importer );
00059     }
00060     else {
00061       $output = Plugins::filter( 'import_stage', '', $importer, $stage, $step );
00062     }
00063 
00064     $this->theme->importer = $importer;
00065     $this->theme->stage = $stage;
00066     $this->theme->step = $step;
00067     $this->theme->importers = $importers;
00068     $this->theme->output = $output;
00069 
00070     $this->display( 'import' );
00071 
00072   }
00073 
00078   public function post_import()
00079   {
00080     if ( !isset( $_POST['importer'] ) ) {
00081       Utils::redirect( URL::get( 'display_import' ) );
00082     }
00083 
00084     $this->get_import();
00085   }
00086 
00094   public function get_form( $importers, $importer )
00095   {
00096     $form = new FormUI( 'import' );
00097 
00098     if( count( $importers ) == 0 ) {
00099       $form->append( FormControlStatic(' <p>' . _t( 'You do not currently have any import plugins installed.' ) . '</p>' ) );
00100       $form->append( FormControlStatic(' <p>' . _t( 'Please <a href="%1$s">activate an import plugin</a> to enable importing.', array( URL::get( 'display_plugins' ) ) ) . '</p>' ) );
00101     }
00102     else {
00103       $form->append( FormControlLabel::wrap( _t( 'Please choose the type of import to perform:' ),
00104         FormControlSelect::create( 'importer' )->set_options( array_combine( $importers, $importers ) )
00105       ));
00106       $form->append( FormControlSubmit::create( 'import' )->set_caption(  _t( 'Select' ) ) );
00107     }
00108 
00109     return $form->get();
00110   }
00111 
00112 }

Generated on Sun Aug 4 2013 12:51:43 for Habari by  doxygen 1.7.1