예제 #1
0
 /**
  * setUp
  */
 public function setUp()
 {
     parent::setUp();
     $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME));
     $form_key = MWF_Functions::get_form_key_from_form_id($post_id);
     $this->Data = MW_WP_Form_Data::getInstance($form_key);
 }
 /**
  * setUp
  */
 public function setUp()
 {
     parent::setUp();
     $this->Field = new MW_WP_Form_Field_Checkbox();
     $this->form_key = MWF_Config::NAME . '-1';
     $this->Data = MW_WP_Form_Data::getInstance($this->form_key);
 }
예제 #3
0
 /**
  * __construct
  * @param string $key 識別子
  */
 public function __construct($key)
 {
     if (!$this->getName()) {
         exit('MW_Validation_Rule::$name must override.');
     }
     $this->Data = MW_WP_Form_Data::getInstance($key);
 }
 /**
  * setUp
  */
 public function setUp()
 {
     parent::setUp();
     $form_key = MWF_Config::NAME . '-1';
     $this->Data = MW_WP_Form_Data::getInstance($form_key);
     $this->Rule = new MW_WP_Form_Validation_Rule_Between();
     $this->Rule->set_Data($this->Data);
 }
예제 #5
0
 /**
  * __construct
  * 取得データを保存
  * @param string $key 識別子
  */
 public function __construct($key = '')
 {
     $this->Data = MW_WP_Form_Data::getInstance($key);
     if ($key) {
         $this->key = $key . '_key';
     }
     $this->modeCheck = $this->modeCheck();
 }
 public function setUp()
 {
     parent::setUp();
     $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME));
     $this->form_key = MWF_Config::NAME . '-' . $post_id;
     $this->Mail = new MW_WP_Form_Mail();
     $this->Setting = new MW_WP_Form_Setting($post_id);
     $this->Data = MW_WP_Form_Data::getInstance(MWF_Functions::get_form_key_from_form_id($post_id));
 }
 /**
  * setUp
  */
 public function setUp()
 {
     parent::setUp();
     $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME));
     $this->form_key = MWF_Config::NAME . '-' . $post_id;
     $this->Mail = new MW_WP_Form_Mail();
     $this->Data = MW_WP_Form_Data::getInstance($this->form_key);
     $Validation_Rule_Mail = new MW_WP_Form_Validation_Rule_Mail();
     $Validation_Rule_Mail->set_Data($this->Data);
     $this->Setting = new MW_WP_Form_Setting($post_id);
 }
예제 #8
0
 /**
  * __construct
  *
  * @param MW_WP_Form_Mail $Mail
  * @param strign $form_key
  * @param MW_WP_Form_Setting $Setting
  * @param array $attachments
  */
 public function __construct(MW_WP_Form_Mail $Mail, $form_key, MW_WP_Form_Setting $Setting, array $attachments = array())
 {
     $this->form_key = $form_key;
     $this->Data = MW_WP_Form_Data::getInstance();
     $this->Mail_raw = $Mail;
     $this->Mail_admin_raw = clone $Mail;
     $this->Mail_auto_raw = clone $Mail;
     $this->attachments = $attachments;
     $this->Setting = $Setting;
     if ($this->Setting->get('post_id')) {
         $this->set_admin_mail_raw_params();
         // 管理者宛メールにだけ添付ファイルを添付
         $this->set_attachments($this->Mail_admin_raw);
         $this->Mail_admin_raw = $this->apply_filters_mwform_admin_mail_raw($this->Mail_admin_raw);
         $this->set_reply_mail_raw_params();
         $this->Mail_auto_raw = $this->apply_filters_mwform_auto_mail_raw($this->Mail_auto_raw);
     } else {
         $Mail = $this->apply_filters_mwform_mail($Mail);
     }
 }
예제 #9
0
 /**
  * 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');
     }
 }
예제 #10
0
 /**
  * メールを送信内容に置換
  *
  * @param MW_WP_Form_Setting $Setting
  * @param bool $do_update
  */
 public function parse($Setting, $do_update = false)
 {
     $Data = MW_WP_Form_Data::getInstance();
     $Mail_Parser = new MW_WP_Form_Mail_Parser($this, $Setting);
     $Mail = $Mail_Parser->get_parsed_mail_object($do_update);
     foreach (get_object_vars($Mail) as $key => $value) {
         $this->{$key} = $value;
     }
 }
 /**
  * フォームを表示するためのショートコードを登録
  *
  * @param string $view_flg
  * @param MW_WP_Form_Setting $Setting
  * @param MW_WP_Form_Form $Form
  */
 public function add_shortcode($view_flg, MW_WP_Form_Setting $Setting, MW_WP_Form_Form $Form)
 {
     $this->view_flg = $view_flg;
     $this->Setting = $Setting;
     $this->Form = $Form;
     $this->Data = MW_WP_Form_Data::getInstance();
     add_shortcode('mwform_formkey', array($this, 'mwform_formkey'));
     add_shortcode('mwform', array($this, 'mwform'));
     add_shortcode('mwform_complete_message', array($this, 'mwform_complete_message'));
 }
 /**
  * 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;
 }
 /**
  * add_shortcode
  * フォーム項目を返す
  * @param MW_WP_Form_Form $Form
  * @param string $view_flg
  * @param MW_WP_Form_Error $Error
  * @param string $form_key
  */
 public function add_shortcode(MW_WP_Form_Form $Form, $view_flg, MW_WP_Form_Error $Error, $form_key)
 {
     if (!empty($this->shortcode_name)) {
         $this->Form = $Form;
         $this->Error = $Error;
         $this->form_key = $form_key;
         $this->Data = MW_WP_Form_Data::getInstance();
         switch ($view_flg) {
             case 'input':
                 add_shortcode($this->shortcode_name, array($this, '_input_page'));
                 break;
             case 'confirm':
                 add_shortcode($this->shortcode_name, array($this, '_confirm_page'));
                 break;
             case 'complete':
                 break;
             default:
                 exit('$view_flg is not right value. $view_flg is ' . $view_flg . ' now.');
         }
     }
 }
예제 #14
0
 /**
  * main
  * 表示画面でのプラグインの処理等。
  * @param string $template
  * @return string $template
  */
 public function main($template)
 {
     global $post;
     // URL設定を取得
     add_shortcode('mwform', array($this, '_meta_mwform'));
     // formkeyでのフォーム生成の場合はそれをもとに設定を取得
     add_shortcode('mwform_formkey', array($this, '_meta_mwform_formkey'));
     if (is_singular() && !empty($post->ID)) {
         $shortcode = $this->get_shortcode($post->post_content);
     }
     if (empty($shortcode) && !(defined('MWFORM_NOT_USE_TEMPLATE') && MWFORM_NOT_USE_TEMPLATE === true)) {
         $template_data = @file_get_contents($template);
         $shortcode = $this->get_shortcode($template_data);
     }
     if (is_array($shortcode) && !empty($shortcode[0])) {
         do_shortcode($shortcode[0]);
     }
     remove_shortcode('mwform');
     remove_shortcode('mwform_formkey');
     // フォームが定義されていない場合は終了
     if (is_null($this->key) || is_null($this->input) || is_null($this->confirm) || is_null($this->complete) || is_null($this->validation_error)) {
         return $template;
     }
     nocache_headers();
     // セッション初期化
     $this->Data = MW_WP_Form_Data::getInstance($this->key);
     // $_POSTがあるときは$_POST
     if (!empty($_POST)) {
         $this->Data->setValues(stripslashes_deep($_POST));
     }
     // $_FILESがあるときは$this->dataに統合
     $files = array();
     foreach ($_FILES as $key => $file) {
         if (!isset($_POST[$key]) || !empty($file['name'])) {
             if ($file['error'] == UPLOAD_ERR_OK && is_uploaded_file($file['tmp_name'])) {
                 $this->Data->setValue($key, $file['name']);
             } else {
                 $this->Data->setValue($key, '');
             }
             if (!empty($file['name'])) {
                 $files[$key] = $file;
             }
         }
     }
     // この条件判定がないと fileSize チェックが正しく動作しない
     if ($files) {
         $this->Data->setValue(MWF_Config::UPLOAD_FILES, $files);
     }
     // フォームオブジェクト生成
     $this->Form = new MW_Form($this->key);
     // バリデーションオブジェクト生成
     $this->Validation = new MW_Validation($this->key);
     foreach ($this->validation_rules as $validation_name => $instance) {
         if (is_callable(array($instance, 'rule'))) {
             $this->Validation->add_validation_rule($instance->getName(), $instance);
         }
     }
     // バリデーション実行(Validation->dataに値がないと$Errorは返さない(true))
     $this->apply_filters_mwform_validation();
     // ファイル操作オブジェクト生成
     $this->File = new MW_WP_Form_File();
     // 入力画面(戻る)のとき
     if ($this->Form->isBack()) {
         $this->redirect($this->input);
     } elseif ($this->Form->isConfirm()) {
         $this->fileUpload();
         if ($this->Validation->check()) {
             $this->viewFlg = 'confirm';
             $this->redirect($this->confirm);
         } else {
             if (!empty($this->validation_error)) {
                 $this->redirect($this->validation_error);
             } else {
                 $this->redirect($this->input);
             }
         }
     } elseif ($this->Form->isComplete()) {
         $this->fileUpload();
         if ($this->Validation->check()) {
             $this->viewFlg = 'complete';
             if ($this->Data->getValue($this->Form->getTokenName())) {
                 $this->apply_filters_mwform_mail();
                 $this->Data->clearValue($this->Form->getTokenName());
                 // 手動フォーム対応
                 $REQUEST_URI = $this->parse_url($this->get_request_uri());
                 $input = $this->parse_url($this->input);
                 $complete = $this->parse_url($this->complete);
                 if (!$this->options_by_formkey && $REQUEST_URI !== $complete && $input !== $complete) {
                     $this->Data->clearValues();
                 }
             }
             $this->redirect($this->complete);
         } else {
             if (!empty($this->validation_error)) {
                 $this->redirect($this->validation_error);
             } else {
                 $this->redirect($this->input);
             }
         }
     } else {
         // 完了 or 確認画面 or エラーURLが設定済みで
         // 完了 or 確認画面 or エラーに直接アクセスした場合、
         // 入力画面に戻れれば戻る。戻れない場合はトップに戻す
         $REQUEST_URI = $this->parse_url($this->get_request_uri());
         $check_urls = array($this->confirm, $this->complete);
         $back_url = $this->input ? $this->input : home_url();
         foreach ($check_urls as $check_url) {
             if ($REQUEST_URI === $check_url) {
                 $this->Data->clearValues();
                 $this->redirect($back_url);
             }
         }
         $this->redirect($this->input);
         if ($this->Validation->check() && $REQUEST_URI == $this->validation_error) {
             $this->Data->clearValues();
             $this->redirect($back_url);
         }
     }
     // スクロール用スクリプトのロード
     if (!empty($this->options_by_formkey['scroll'])) {
         if ($this->Form->isConfirm() || $this->Form->isComplete() || !$this->Validation->check()) {
             add_action('wp_enqueue_scripts', array($this, 'scroll_script'));
         }
     }
     add_shortcode('mwform_formkey', array($this, '_mwform_formkey'));
     add_shortcode('mwform', array($this, '_mwform'));
     add_shortcode('mwform_complete_message', array($this, '_mwform_complete_message'));
     add_action('wp_footer', array($this->Data, 'clearValues'));
     add_action('wp_enqueue_scripts', array($this, 'original_style'));
     add_action('wp_enqueue_scripts', array($this, 'original_script'));
     return $template;
 }
예제 #15
0
 /**
  * 配列データを整形して返す ( チェックボックス等用 )。配列の場合はpost値を連結して返す
  *
  * @param string $key name属性
  * @param array $children 選択肢
  * @return string データ
  */
 public function get_separated_raw_value($key, array $children = array())
 {
     MWF_Functions::deprecated_message('MW_WP_Form_Form::get_separated_raw_value()', 'MW_WP_Form_Data::get_separated_raw_value()');
     $Data = MW_WP_Form_Data::getInstance();
     return $Data->get_separated_raw_value($key, $children);
 }
예제 #16
0
 /**
  * @group parse
  * @backupStaticAttributes enabled
  */
 public function test_parse_データベースに保存()
 {
     $post_id = $this->factory->post->create(array('post_type' => MWF_Config::NAME));
     $Setting = new MW_WP_Form_Setting($post_id);
     $Data = MW_WP_Form_Data::getInstance(MWF_Functions::get_form_key_from_form_id($post_id));
     $Data->set('example', 'example');
     $this->Mail->body = '{example}';
     $this->Mail->parse($Setting, true);
     $posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($post_id)));
     foreach ($posts as $post) {
         $this->assertEquals('example', get_post_meta($post->ID, 'example', true));
         break;
     }
 }
예제 #17
0
 /**
  * @param MW_WP_Form_Mail $Mail
  * @param MW_WP_Form_Setting $Setting
  */
 public function __construct(MW_WP_Form_Mail $Mail, MW_WP_Form_Setting $Setting)
 {
     $this->Mail = clone $Mail;
     $this->Data = MW_WP_Form_Data::getInstance();
     $this->Setting = $Setting;
 }
예제 #18
0
 /**
  * 表示画面でのプラグインの処理等
  *
  * @param string $template
  * @return string $template
  */
 public function template_include($template)
 {
     global $post;
     $this->ExecShortcode = new MW_WP_Form_Exec_Shortcode($post, $template);
     $has_shortcode = $this->ExecShortcode->has_shortcode();
     if (!$has_shortcode) {
         return $template;
     }
     $form_key = $this->ExecShortcode->get('key');
     $form_id = $this->ExecShortcode->get_form_id();
     $this->Setting = new MW_WP_Form_Setting($form_id);
     $this->Data = MW_WP_Form_Data::getInstance($form_key, $_POST, $_FILES);
     foreach ($this->validation_rules as $validation_name => $validation_rule) {
         if (is_callable(array($validation_rule, 'set_Data'))) {
             $validation_rule->set_Data($this->Data);
         }
     }
     nocache_headers();
     $Error = new MW_WP_Form_Error();
     $this->Validation = new MW_WP_Form_Validation($Error);
     $this->Validation->set_validation_rules($this->validation_rules);
     $this->Validation->set_rules($this->Setting);
     $this->Validation = apply_filters('mwform_validation_' . $form_key, $this->Validation, $this->Data->gets(), clone $this->Data);
     $token_check = $this->token_check();
     $post_condition = $this->Data->get_post_condition($token_check);
     $is_valid = $this->Validation->check();
     $this->Redirected = new MW_WP_Form_Redirected($this->ExecShortcode->get('input_url'), $this->ExecShortcode->get('confirmation_url'), $this->ExecShortcode->get('complete_url'), $this->ExecShortcode->get('validation_error_url'), $is_valid, $post_condition, $this->Setting->get('querystring'));
     $url = $this->Redirected->get_url();
     $view_flg = $this->Redirected->get_view_flg();
     // confirm もしくは complete のとき
     if (in_array($post_condition, array('confirm', 'complete'))) {
         $this->file_upload();
     }
     // complete のとき
     if ($view_flg === 'complete') {
         if (!$this->is_complete_twice()) {
             $this->send();
         }
         // 手動フォームの場合は完了画面に ExecShortcode が無く footer の clear_values が
         // 効かないためここで消す
         if (!$form_id) {
             $this->Data->clear_values();
         }
     }
     $this->redirect($url);
     // スクロール用スクリプトのロード
     if ($this->Setting->get('scroll')) {
         if ($post_condition !== 'input') {
             add_action('wp_enqueue_scripts', array($this, 'scroll_script'));
         }
     }
     // 画面表示用のショートコードを登録
     do_action('mwform_add_shortcode', new MW_WP_Form_Form(), $view_flg, $Error, $form_key, $this->Data);
     $Form = new MW_WP_Form_Form();
     $this->ExecShortcode->add_shortcode($view_flg, $this->Setting, $Form);
     add_action('wp_footer', array($this->Data, 'clear_values'));
     add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
     return $template;
 }
예제 #19
0
 /**
  * singleCheck
  * 特定の項目のvalidate実行
  * @param string $key
  * @return bool エラーがなければ true
  */
 public function singleCheck($key)
 {
     $Data = MW_WP_Form_Data::getInstance($this->key);
     $rules = array();
     if (is_array($this->validate) && isset($this->validate[$key])) {
         $rules = $this->validate[$key];
         if ($this->_check($key, $rules)) {
             return false;
         }
     }
     return true;
 }