/** * @backupStaticAttributes enabled */ public function test_データベースに保存() { $this->Setting->set('usedb', 1); $Mail_Service = new MW_WP_Form_Mail_Service($this->Mail, $this->form_key, $this->Setting); $Mail_Service->send_admin_mail(); $Mail_Service->send_reply_mail(); $this->assertEquals(1, count(get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($this->Setting->get('post_id')), 'posts_per_page' => -1)))); }
/** * setUp */ public function setUp() { parent::setUp(); $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME)); $Setting = new MW_WP_Form_Setting($post_id); $Setting->set('usedb', 1); $post_ids = $this->factory->post->create_many(50, array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($Setting->get('post_id')))); $this->post_type = get_post_type($post_ids[0]); $this->CSV = new MW_WP_Form_CSV($this->post_type); }
/** * add_shortcode した後の ExecShortcode を返す * * @param string $view_flg * @return MW_WP_Form_Exec_Shortcode */ protected function get_ExecShortcode_after_add_shortcode($view_flg) { $post = $this->generate_page_has_mwform_formkey($this->Setting); $ExecShortcode = new MW_WP_Form_Exec_Shortcode($post, ''); $Form = new MW_WP_Form_Form(); $Data = MW_WP_Form_Data::getInstance($ExecShortcode->get('key')); $ExecShortcode->add_shortcode($view_flg, $this->Setting, $Form); $attributes = array('key' => $this->Setting->get('post_id')); $ExecShortcode->set_settings_by_mwform_formkey($attributes); return $ExecShortcode; }
/** * 管理者メールの送信とデータベースへの保存 */ 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); $Mail_admin->send(); // DB非保存時は管理者メール送信後、ファイルを削除 if (!$this->Setting->get('usedb')) { $File = new MW_WP_Form_File(); $File->delete_files($this->attachments); } }
/** * @group get_forms_using_database */ public function test_get_forms_using_database() { $forms = array(); $_forms = $this->Admin->get_forms(); foreach ($_forms as $form) { $Setting = new MW_WP_Form_Setting($form->ID); if (!$Setting->get('usedb')) { continue; } $forms[] = $form; } $forms_using_database = $this->Admin->get_forms_using_database(); $this->assertEquals(1, count($forms_using_database)); $this->assertEquals(count($forms), count($forms_using_database)); }
/** * @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; } }
/** * メール送信 */ protected function send() { $Mail = new MW_WP_Form_Mail(); $form_key = $this->ExecShortcode->get('key'); $attachments = $this->get_attachments(); $Mail_Service = new MW_WP_Form_Mail_Service($Mail, $form_key, $this->Setting, $attachments); // 管理画面で作成した場合だけ自動で送信 if ($this->ExecShortcode->is_generated_by_formkey()) { $Mail_Service->send_admin_mail(); // 自動返信メールの送信 $automatic_reply_email = $this->Setting->get('automatic_reply_email'); if ($automatic_reply_email) { $automatic_reply_email = $this->Data->get_post_value_by_key($automatic_reply_email); $is_invalid_mail_address = $this->validation_rules['mail']->rule($automatic_reply_email); if ($automatic_reply_email && !$is_invalid_mail_address) { $Mail_Service->send_reply_mail(); } } // 問い合わせ番号を加算 $Mail_Service->update_tracking_number(); } }
/** * $this->_parse_mail_content(), $this->_save_mail_content の本体 * 第2引数でDB保存するか判定 * * @param array $matches * @param bool $do_update * @return string $value */ protected function parse($matches, $do_update = false) { $match = $matches[1]; $form_id = $this->Setting->get('post_id'); // MWF_Config::TRACKINGNUMBER のときはお問い合せ番号を参照する if ($match === MWF_Config::TRACKINGNUMBER) { if ($form_id) { $value = $this->Setting->get_tracking_number($form_id); } } else { $form_key = MWF_Functions::get_form_key_from_form_id($form_id); $value = $this->Data->get($match); $value = $this->apply_filters_mwform_custom_mail_tag($form_key, $value, $match); } // 値が null でも保存(チェッボックス未チェックで直送信でも保存させるため) // ただし、画像の場合はURLが保存されないように調整がはいるため除外が必要 if ($do_update) { if (!array_key_exists($match, $this->Mail->attachments)) { update_post_meta($this->insert_contact_data_id, $match, $value); } } return $value; }
/** * set_rules * * @param MW_WP_Form_Setting $Setting */ public function set_rules(MW_WP_Form_Setting $Setting) { $Data = MW_WP_Form_Data::getInstance(); $rules = array(); $validations = $Setting->get('validation'); if ($validations) { foreach ($validations as $validation) { foreach ($validation as $rule => $options) { if ($rule == 'target') { continue; } if (!is_array($options)) { $options = array(); } $this->set_rule($validation['target'], $rule, $options); } } } $Akismet = new MW_WP_Form_Akismet(); $akismet_check = $Akismet->check($Setting->get('akismet_author'), $Setting->get('akismet_author_email'), $Setting->get('akismet_author_url'), $Data); if ($akismet_check) { $this->set_rule(MWF_Config::AKISMET, 'akismet_check'); } }
/** * 自動返信メール用に初期値を設定 * * @param MW_WP_Form_Setting $Setting */ public function set_reply_mail_raw_params(MW_WP_Form_Setting $Setting) { $this->to = ''; $this->cc = ''; $this->bcc = ''; $this->attachments = array(); $Data = MW_WP_Form_Data::getInstance(); $automatic_reply_email = $Setting->get('automatic_reply_email'); $form_id = $Setting->get('post_id'); if ($form_id) { $Validation = new MW_WP_Form_Validation_Rule_Mail(); $Validation->set_Data($Data); $is_invalid_mail_address = $Validation->rule($automatic_reply_email); // 送信先を指定 if ($automatic_reply_email && !$is_invalid_mail_address) { $this->to = $Data->get_post_value_by_key($automatic_reply_email); } // 送信元を指定 $reply_mail_from = get_bloginfo('admin_email'); if ($Setting->get('mail_from')) { $reply_mail_from = $Setting->get('mail_from'); } $this->from = $reply_mail_from; // 送信者を指定 $reply_mail_sender = get_bloginfo('name'); if ($Setting->get('mail_sender')) { $reply_mail_sender = $Setting->get('mail_sender'); } $this->sender = $reply_mail_sender; // タイトルを指定 $this->subject = $Setting->get('mail_subject'); // 本文を指定 $this->body = $Setting->get('mail_content'); } }
/** * ショートコード mwform_formkey をもとにフォームの実行に必須のデータを設定 * * @param array $attributes|'' */ public function set_settings_by_mwform_formkey($attributes) { $post_id = $this->get_form_id_by_mwform_formkey($attributes); $this->post_id = $post_id; $settings = array(); if (!empty($post_id)) { $Setting = new MW_WP_Form_Setting($post_id); foreach ($this->settings as $key => $value) { $settings[$key] = $Setting->get($key); } $settings['key'] = MWF_Functions::get_form_key_from_form_id($post_id); } $this->set_settings($settings); }
/** * get_option * フォームの設定データを返す * @param string $key 設定データのキー * @return mixed 設定データ */ protected function get_option($key) { global $post; $Setting = new MW_WP_Form_Setting($post->ID); if ($key === MWF_Config::TRACKINGNUMBER) { $value = $Setting->get_tracking_number(); } else { $value = $Setting->get($key); } if (!is_null($value)) { return $value; } else { $date = $post->post_date; $modified = $post->post_modified; if ($date === $modified) { return apply_filters('mwform_default_settings', '', $key); } } }
/** * get_forms_using_database * @return array データベースに保存が有効なフォーム(WP_Post)の配列 */ public function get_forms_using_database() { $forms_using_database = array(); $forms = $this->get_forms(); foreach ($forms as $form) { $Setting = new MW_WP_Form_Setting($form->ID); if (!$Setting->get('usedb')) { continue; } $forms_using_database[$form->ID] = $form; } return $forms_using_database; }
/** * @group get_tracking_number */ public function test_get_tracking_number_登録されている場合はそれを返す() { update_post_meta($this->Setting->get('post_id'), MWF_Config::TRACKINGNUMBER, 2); $this->assertEquals(2, $this->Setting->get_tracking_number()); }