/**
  * @param $identifier
  * @param $headline
  * @param $helpUrl
  * @param $actionUrl
  * @return string
  * @throws IfwPsn_Wp_Plugin_Exception
  */
 public static function getImportForm($identifier, $headline, $helpUrl, $actionUrl)
 {
     $helpText = sprintf(__('Need help? <a href="%s" target="_blank">Check the docs</a>.', 'psn'), IfwPsn_Wp_Plugin_Manager::getInstance('Psn')->getConfig()->plugin->docUrl . $helpUrl);
     $options = array('headline' => $headline, 'help_text' => $helpText, 'action_url' => $actionUrl, 'import_file_label' => __('Import file', 'psn'), 'import_file_description' => __('Please select a valid .xml export file.', 'psn'), 'import_prefix_label' => __('Import prefix (optional)', 'psn'), 'import_prefix_description' => __('Prepend this text to imported items names to identify them.', 'psn'), 'wait_text_headline' => __('Processing file', 'psn'), 'wait_text_description' => __('Please wait while the export file is being processed ...', 'psn'));
     return IfwPsn_Wp_Data_Importer::getForm(IfwPsn_Wp_Plugin_Manager::getInstance('Psn'), $identifier, $options);
 }
Exemple #2
0
 /**
  * Options:
  * - file
  * - keep_file
  * - prefix
  * - item_callback
  * - id_col
  * - name_col
  * - skip_col
  * - goto_index
  * @param array $options
  */
 public function handleImport(array $options = array())
 {
     if (!wp_verify_nonce($this->_request->get('nonce'), self::getImportNonceAction($this->getSingular()))) {
         $this->getAdminNotices()->persistError($this->getInvalidAccessMessage());
         $this->gotoIndex();
     }
     if (isset($options['file']) && file_exists($options['file'])) {
         $file = $options['file'];
     } else {
         $file = $_FILES['importfile']['tmp_name'];
     }
     $importer = new IfwPsn_Wp_Data_Importer($file, $this->getModelMapper()->getExportOptions($this->_pm->getAbbrLower() . '_'));
     $item_callback = array(array($this, 'handleImportNameCheck'));
     if (isset($options['item_callback'])) {
         if (is_callable($options['item_callback'])) {
             $item_callback = array_merge($item_callback, array($options['item_callback']));
         } elseif (is_array($options['item_callback'])) {
             $item_callback = array_merge($item_callback, $options['item_callback']);
         }
         unset($options['item_callback']);
     }
     $options = array_merge(array('prefix' => esc_attr($this->getRequest()->get('import_prefix')), 'item_callback' => $item_callback), $options);
     $result = $importer->import($this->getModelName(), $options);
     if (!isset($options['keep_file']) || $options['keep_file'] != true) {
         @unlink($file);
     }
     if (!$result) {
         $this->getAdminNotices()->persistError($importer->getError());
     }
     if (!isset($options['goto_index']) || $options['goto_index'] == true) {
         $this->gotoIndex();
     }
 }