/**
  * アンインストールのテスト
  */
 public function test_uninstall()
 {
     $post_ids = $this->factory->post->create_many(5, array('post_type' => MWF_Config::NAME));
     foreach ($post_ids as $post_id) {
         update_option(MWF_Config::NAME . '-chart-' . $post_id, 1);
         $data_post_ids = $this->factory->post->create_many(5, array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id)));
     }
     $MW_WP_Form_File = new MW_WP_Form_File();
     $temp_dir = $MW_WP_Form_File->get_temp_dir();
     $temp_dir = $temp_dir['dir'];
     system("sudo chmod 777 " . WP_CONTENT_DIR . '/uploads');
     $MW_WP_Form_File->create_temp_dir();
     $this->assertEquals(true, file_exists($temp_dir));
     update_option(MWF_Config::NAME, 1);
     MW_WP_Form::uninstall();
     $posts = get_posts(array('post_type' => MWF_Config::NAME, 'posts_per_page' => -1));
     $this->assertEquals(0, count($posts));
     foreach ($post_ids as $post_id) {
         $option = get_option(MWF_Config::NAME . '-chart-' . $post_id);
         $this->assertEquals(null, $option);
         $data_posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id), 'posts_per_page' => -1));
         $this->assertEquals(0, count($data_posts));
     }
     $this->assertEquals(false, file_exists($temp_dir));
     $option = get_option(MWF_Config::NAME);
     $this->assertEquals(null, $option);
 }
Exemple #2
0
 /**
  * メール送信
  */
 public function send()
 {
     if (!$this->to) {
         return;
     }
     $sender = $this->sender;
     $from = $this->from;
     $subject = $this->subject;
     $body = $this->body;
     add_action('phpmailer_init', array($this, 'set_return_path'));
     add_filter('wp_mail_from', array($this, 'set_mail_from'));
     add_filter('wp_mail_from_name', array($this, 'set_mail_from_name'));
     if (defined('MWFORM_DEBUG') && MWFORM_DEBUG === true) {
         $File = new MW_WP_Form_File();
         $File->create_temp_dir();
         $temp_dir = $File->get_temp_dir();
         $temp_dir = trailingslashit($temp_dir['dir']);
         $temp_dir = apply_filters('mwform_log_directory', $temp_dir);
     }
     $tos = explode(',', $this->to);
     foreach ($tos as $to) {
         $headers = array();
         if ($this->cc) {
             $headers[] = 'Cc: ' . $this->cc;
         }
         if ($this->bcc) {
             $headers[] = 'Bcc: ' . $this->bcc;
         }
         $to = trim($to);
         if (!empty($File)) {
             $contents = sprintf("====================\n\nSend Date: %s\nTo: %s\nSender: %s\nFrom: %s\nSubject: %s\nheaders:%s\n-----\n%s\n-----\nattachments:\n%s\n\n", date('M j Y, H:i:s'), $to, $sender, $from, $subject, implode("\n", $headers), $body, implode("\n", $this->attachments));
             file_put_contents($temp_dir . '/mw-wp-form-debug.log', $contents, FILE_APPEND);
         } else {
             @wp_mail($to, $subject, $body, $headers, $this->attachments);
         }
     }
     remove_action('phpmailer_init', array($this, 'set_return_path'));
     remove_filter('wp_mail_from', array($this, 'set_mail_from'));
     remove_filter('wp_mail_from_name', array($this, 'set_mail_from_name'));
 }
 /**
  * @group get_parsed_mail_object
  * @backupStaticAttributes enabled
  */
 public function test_get_parsed_mail_object_Nullでもデータベースに保存_ただし添付の場合は保存しない()
 {
     $MW_WP_Form_File = new MW_WP_Form_File();
     $temp_dir = $MW_WP_Form_File->get_temp_dir();
     $temp_dir = $temp_dir['dir'];
     system("sudo chmod 777 " . WP_CONTENT_DIR . '/uploads');
     $MW_WP_Form_File->create_temp_dir();
     file_put_contents($temp_dir . '/attachment_1.txt', 'hoge');
     file_put_contents($temp_dir . '/attachment_2.txt', 'fuga');
     $this->Data->set('attachment_1', null);
     $this->Mail->body = '{attachment_1}';
     $this->Mail->attachments = array('attachment_1' => $temp_dir . '/attachment_1.txt', 'attachment_2' => $temp_dir . '/attachment_2.txt');
     $Mail_Parser = new MW_WP_Form_Mail_Parser($this->Mail, $this->Setting);
     $Mail_Parser->get_parsed_mail_object(true);
     $posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($this->Setting->get('post_id'))));
     foreach ($posts as $post) {
         $post_metas = get_post_meta($post->ID);
         $this->assertFalse(isset($post_metas['attachment_1']));
         break;
     }
 }
 /**
  * アンインストールした時の処理
  */
 public static function uninstall()
 {
     $plugin_dir_path = plugin_dir_path(__FILE__);
     include_once $plugin_dir_path . 'classes/models/class.admin.php';
     $Admin = new MW_WP_Form_Admin();
     $forms = $Admin->get_forms();
     $data_post_ids = array();
     foreach ($forms as $form) {
         $data_post_ids[] = $form->ID;
         wp_delete_post($form->ID, true);
     }
     foreach ($data_post_ids as $data_post_id) {
         delete_option(MWF_Config::NAME . '-chart-' . $data_post_id);
         $data_posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($data_post_id), 'posts_per_page' => -1));
         if (empty($data_posts)) {
             continue;
         }
         foreach ($data_posts as $data_post) {
             wp_delete_post($data_post->ID, true);
         }
     }
     include_once plugin_dir_path(__FILE__) . 'classes/models/class.file.php';
     $File = new MW_WP_Form_File();
     $File->remove_temp_dir();
     delete_option(MWF_Config::NAME);
 }
Exemple #5
0
 /**
  * ファイルアップロード処理。実際のアップロード状況に合わせてフォームデータも再生成する。
  */
 protected function file_upload()
 {
     $File = new MW_WP_Form_File();
     $files = array();
     $upload_files = $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILES);
     if (!is_array($upload_files)) {
         $upload_files = array();
     }
     foreach ($upload_files as $key => $file) {
         if ($this->Validation->single_check($key)) {
             $files[$key] = $file;
         }
     }
     $uploaded_files = $File->upload($files);
     $this->Data->set_upload_file_keys();
     $this->Data->push_uploaded_file_keys($uploaded_files);
 }
 /**
  * 管理者メールの送信とデータベースへの保存
  */
 public function send_admin_mail()
 {
     // save_mail_body でファイルURLではなくファイルのIDが保存されるように
     foreach ($this->attachments as $key => $attachment) {
         $this->Data->clear_value($key);
     }
     if ($this->Setting->get('usedb')) {
         $Mail_admin = $this->get_parsed_mail_object($this->Mail_admin_raw, true);
     } else {
         $Mail_admin = $this->get_parsed_mail_object($this->Mail_admin_raw);
     }
     $Mail_admin->set_admin_mail_reaquire_params();
     $Mail_admin = $this->apply_filters_mwform_mail($Mail_admin);
     $Mail_admin = $this->apply_filters_mwform_admin_mail($Mail_admin);
     do_action('mwform_before_send_admin_mail_' . $this->form_key, clone $Mail_admin, clone $this->Data);
     $Mail_admin->send();
     // DB非保存時は管理者メール送信後、ファイルを削除
     if (!$this->Setting->get('usedb')) {
         $File = new MW_WP_Form_File();
         $File->delete_files($this->attachments);
     }
 }
Exemple #7
0
 /**
  * uninstall
  * アンインストールした時の処理
  */
 public static function uninstall()
 {
     $forms = get_posts(array('post_type' => MWF_Config::NAME, 'posts_per_page' => -1));
     $data_post_ids = array();
     foreach ($forms as $form) {
         $data_post_ids[] = $form->ID;
         wp_delete_post($form->ID, true);
     }
     foreach ($data_post_ids as $data_post_id) {
         delete_option(MWF_Config::NAME . '-chart-' . $data_post_id);
         $data_posts = get_posts(array('post_type' => MWF_Config::DBDATA . $data_post_id, 'posts_per_page' => -1));
         if (empty($data_posts)) {
             continue;
         }
         foreach ($data_posts as $data_post) {
             wp_delete_post($data_post->ID, true);
         }
     }
     include_once plugin_dir_path(__FILE__) . 'system/mw_wp_form_file.php';
     $File = new MW_WP_Form_File();
     $File->removeTempDir();
     delete_option(MWF_Config::NAME);
 }
 /**
  * @group get_temp_dir
  */
 public function test_get_temp_dir()
 {
     $this->assertEquals(array('dir' => ABSPATH . 'wp-content/uploads/mw-wp-form_uploads', 'url' => home_url('/wp-content/uploads/mw-wp-form_uploads')), $this->File->get_temp_dir());
 }