Пример #1
0
 /**
  * @see PMXI_Model_Record::insert()
  */
 public function insert()
 {
     $file_contents = NULL;
     if ($this->offsetExists('contents')) {
         $file_contents = $this['contents'];
         unset($this->contents);
     }
     parent::insert();
     $uploads = wp_upload_dir();
     if (isset($this->id) and !is_null($file_contents)) {
         file_put_contents($uploads['basedir'] . '/wpallimport/history/' . $this->id, $file_contents);
     }
     $list = new PMXI_File_List();
     $list->sweepHistory();
     return $this;
 }
Пример #2
0
 public function index()
 {
     $this->data['post'] = $post = $this->input->post(PMXI_Plugin::getInstance()->getOption());
     /*$addons = new PMXI_Admin_Addons();
     
     		$this->data['addons'] = $addons->get_premium_addons();*/
     $this->data['addons']['PMXI_Plugin'] = array('title' => __('WP All Import', 'wp_all_import_plugin'), 'active' => class_exists('PMXI_Plugin') and defined('PMXI_EDITION') and PMXI_EDITION == 'paid');
     $this->data['addons'] = array_reverse($this->data['addons']);
     if ($this->input->post('is_settings_submitted')) {
         // save settings form
         check_admin_referer('edit-settings', '_wpnonce_edit-settings');
         if (!preg_match('%^\\d+$%', $post['history_file_count'])) {
             $this->errors->add('form-validation', __('History File Count must be a non-negative integer', 'wp_all_import_plugin'));
         }
         if (!preg_match('%^\\d+$%', $post['history_file_age'])) {
             $this->errors->add('form-validation', __('History Age must be a non-negative integer', 'wp_all_import_plugin'));
         }
         if (empty($post['html_entities'])) {
             $post['html_entities'] = 0;
         }
         if (empty($post['utf8_decode'])) {
             $post['utf8_decode'] = 0;
         }
         if (!$this->errors->get_error_codes()) {
             // no validation errors detected
             PMXI_Plugin::getInstance()->updateOption($post);
             if (empty($_POST['pmxi_license_activate']) and empty($_POST['pmxi_license_deactivate'])) {
                 foreach ($this->data['addons'] as $class => $addon) {
                     $post['statuses'][$class] = $this->check_license($class);
                 }
                 PMXI_Plugin::getInstance()->updateOption($post);
             }
             isset($_POST['pmxi_license_activate']) and $this->activate_licenses();
             $files = new PMXI_File_List();
             $files->sweepHistory();
             // adjust file history to new settings specified
             wp_redirect(add_query_arg('pmxi_nt', urlencode(__('Settings saved', 'wp_all_import_plugin')), $this->baseUrl));
             die;
         }
     }
     /*else{			
     
     			foreach ($this->data['addons'] as $class => $addon) {
     				$post['statuses'][$class] = $this->check_license($class);
     			}								
     
     			PMXI_Plugin::getInstance()->updateOption($post);	
     		}*/
     if ($this->input->post('is_templates_submitted')) {
         // delete templates form
         check_admin_referer('delete-templates', '_wpnonce_delete-templates');
         if ($this->input->post('import_templates')) {
             if (!empty($_FILES)) {
                 $file_name = $_FILES['template_file']['name'];
                 $file_size = $_FILES['template_file']['size'];
                 $tmp_name = $_FILES['template_file']['tmp_name'];
                 if (isset($file_name)) {
                     $filename = stripslashes($file_name);
                     $extension = strtolower(pmxi_getExtension($filename));
                     if ($extension != "txt") {
                         $this->errors->add('form-validation', __('Unknown File extension. Only txt files are permitted', 'wp_all_import_plugin'));
                     } else {
                         $import_data = @file_get_contents($tmp_name);
                         if (!empty($import_data)) {
                             $templates_data = json_decode($import_data, true);
                             if (!empty($templates_data)) {
                                 $template = new PMXI_Template_Record();
                                 foreach ($templates_data as $template_data) {
                                     unset($template_data['id']);
                                     $template->clear()->set($template_data)->insert();
                                 }
                                 wp_redirect(add_query_arg('pmxi_nt', urlencode(sprintf(_n('%d template imported', '%d templates imported', count($templates_data), 'wp_all_import_plugin'), count($templates_data))), $this->baseUrl));
                                 die;
                             } else {
                                 $this->errors->add('form-validation', __('Wrong imported data format', 'wp_all_import_plugin'));
                             }
                         } else {
                             $this->errors->add('form-validation', __('File is empty or doesn\'t exests', 'wp_all_import_plugin'));
                         }
                     }
                 } else {
                     $this->errors->add('form-validation', __('Undefined entry!', 'wp_all_import_plugin'));
                 }
             } else {
                 $this->errors->add('form-validation', __('Please select file.', 'wp_all_import_plugin'));
             }
         } else {
             $templates_ids = $this->input->post('templates', array());
             if (empty($templates_ids)) {
                 $this->errors->add('form-validation', __('Templates must be selected', 'wp_all_import_plugin'));
             }
             if (!$this->errors->get_error_codes()) {
                 // no validation errors detected
                 if ($this->input->post('delete_templates')) {
                     $template = new PMXI_Template_Record();
                     foreach ($templates_ids as $template_id) {
                         $template->clear()->set('id', $template_id)->delete();
                     }
                     wp_redirect(add_query_arg('pmxi_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'wp_all_import_plugin'), count($templates_ids))), $this->baseUrl));
                     die;
                 }
                 if ($this->input->post('export_templates')) {
                     $export_data = array();
                     $template = new PMXI_Template_Record();
                     foreach ($templates_ids as $template_id) {
                         $export_data[] = $template->clear()->getBy('id', $template_id)->toArray(TRUE);
                     }
                     $uploads = wp_upload_dir();
                     $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
                     $export_file_name = "templates_" . uniqid() . ".txt";
                     file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
                     PMXI_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
                 }
             }
         }
     }
     $this->render();
 }