/** * 送信されたデータをもとに添付ファイル用の配列を生成して返す * * @return array $attachments pathの配列 */ protected function get_attachments() { $attachments = array(); $upload_file_keys = $this->Data->get_post_value_by_key(MWF_Config::UPLOAD_FILE_KEYS); if ($upload_file_keys !== null && is_array($upload_file_keys)) { $wp_upload_dir = wp_upload_dir(); foreach ($upload_file_keys as $key) { $upload_file_url = $this->Data->get_post_value_by_key($key); if (!$upload_file_url) { continue; } $filepath = MWF_Functions::fileurl_to_path($upload_file_url); if (file_exists($filepath)) { $filepath = MWF_Functions::move_temp_file_to_upload_dir($filepath); $new_upload_file_url = MWF_Functions::filepath_to_url($filepath); $this->Data->set($key, $new_upload_file_url); $attachments[$key] = $filepath; } } } return $attachments; }
/** * apply_filters_mwform_mail * メール送信フィルター */ protected function apply_filters_mwform_mail() { $Mail = new MW_Mail(); $Mail_raw = clone $Mail; if ($this->options_by_formkey) { $Mail_raw = $this->set_admin_mail_raw_params($Mail_raw); // 添付ファイルのデータをためた配列を作成 $attachments = array(); // $Mail->attachments を設定(メールにファイルを添付) $upload_file_keys = $this->Data->getValue(MWF_Config::UPLOAD_FILE_KEYS); if ($upload_file_keys !== null && is_array($upload_file_keys)) { $wp_upload_dir = wp_upload_dir(); foreach ($upload_file_keys as $key) { $upload_file_url = $this->Data->getValue($key); if (!$upload_file_url) { continue; } $filepath = MWF_Functions::fileurl_to_path($upload_file_url); if (file_exists($filepath)) { $filepath = $this->File->moveTempFileToUploadDir($filepath); $new_upload_file_url = MWF_Functions::filepath_to_url($filepath); $attachments[$key] = $filepath; $this->Data->setValue($key, $new_upload_file_url); } } $Mail_raw->attachments = $attachments; } $filter_name = 'mwform_admin_mail_raw_' . $this->key; $Mail_raw = apply_filters($filter_name, $Mail_raw, $this->Data->getValues()); if (!is_a($Mail_raw, 'MW_Mail')) { return; } $Mail = $this->parse_mail_object($Mail_raw); $Mail = $this->set_admin_mail_reaquire_params($Mail); } $filter_name = 'mwform_mail_' . $this->key; $Mail = apply_filters($filter_name, $Mail, $this->Data->getValues()); if ($this->options_by_formkey && is_a($Mail, 'MW_Mail') && is_a($Mail_raw, 'MW_Mail')) { // メール送信前にファイルのリネームをしないと、tempファイル名をメールで送信してしまう。 if (!empty($this->options_by_formkey['usedb'])) { // save_mail_body で登録されないように foreach ($attachments as $key => $filepath) { $this->Data->clearValue($key); } // $this->insert_id を設定 ( save_mail_body で 使用 ) $this->insert_id = wp_insert_post(array('post_title' => $Mail->subject, 'post_status' => 'publish', 'post_type' => MWF_Config::DBDATA . $this->options_by_formkey['post_id'])); // 保存 $this->save_mail_body($Mail_raw->body); // 添付ファイルをメディアに保存 if (!empty($this->insert_id)) { $this->File->saveAttachmentsInMedia($this->insert_id, $attachments, $this->options_by_formkey['post_id']); } } $filter_name = 'mwform_admin_mail_' . $this->key; $Mail = apply_filters($filter_name, $Mail, $this->Data->getValues()); if (!is_a($Mail, 'MW_Mail')) { return; } $Mail->send(); // DB非保存時は管理者メール送信後、ファイルを削除 if (empty($this->options_by_formkey['usedb'])) { foreach ($attachments as $filepath) { if (file_exists($filepath)) { unlink($filepath); } } } if (isset($this->options_by_formkey['automatic_reply_email'])) { $automatic_reply_email = $this->Data->getValue($this->options_by_formkey['automatic_reply_email']); if ($automatic_reply_email && !$this->validation_rules['mail']->rule($automatic_reply_email)) { $Mail_auto_raw = $this->set_reply_mail_raw_params(clone $Mail_raw); // 自動返信メールからは添付ファイルを削除 $Mail_auto_raw->attachments = array(); $filter_name = 'mwform_auto_mail_raw_' . $this->key; $Mail_auto_raw = apply_filters($filter_name, $Mail_auto_raw, $this->Data->getValues()); if (!is_a($Mail_auto_raw, 'MW_Mail')) { return; } $Mail_auto = $this->parse_mail_object($Mail_auto_raw); $Mail_auto = $this->set_reply_mail_reaquire_params($Mail_auto); $filter_name = 'mwform_auto_mail_' . $this->key; $Mail_auto = apply_filters($filter_name, $Mail_auto, $this->Data->getValues()); if (!is_a($Mail_auto, 'MW_Mail')) { return; } $Mail_auto->send(); } } // 問い合わせ番号を加算 if (preg_match('{' . MWF_Config::TRACKINGNUMBER . '}', $Mail_raw->body, $reg)) { $form_id = $this->options_by_formkey['post_id']; $tracking_number = $this->get_tracking_number($form_id); $new_tracking_number = $tracking_number + 1; update_post_meta($form_id, MWF_Config::TRACKINGNUMBER, $new_tracking_number); } } }