MW WP Form - Version 0.5

Version Description

  • Initial release.
Download this release

Release Info

Developer inc2734
Plugin Icon wp plugin MW WP Form
Version 0.5
Comparing to
See all releases

Version 0.5

css/style.css ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ @charset "utf-8";
2
+
3
+ .mw_wp_form .error {
4
+ font-size : 93%;
5
+ color : #B70000;
6
+ display : block;
7
+ }
form_fields/mw_form_checkbox.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Checkbox
4
+ * URI: http://2inc.org
5
+ * Description: チェックボックスを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_checkbox extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'children' => '',
38
+ 'value' => '',
39
+ 'show_error' => 'true',
40
+ );
41
+ }
42
+
43
+ /**
44
+ * inputPage
45
+ * 入力ページでのフォーム項目を返す
46
+ * @return String HTML
47
+ */
48
+ protected function inputPage() {
49
+ $children = $this->getChildren();
50
+ $_ret = $this->Form->checkbox( $this->atts['name'], $children, array(
51
+ 'value' => $this->atts['value'],
52
+ ) );
53
+ if ( $this->atts['show_error'] !== 'false' )
54
+ $_ret .= $this->getError( $this->atts['name'] );
55
+ return $_ret;
56
+ }
57
+
58
+ /**
59
+ * previewPage
60
+ * 確認ページでのフォーム項目を返す
61
+ * @return String HTML
62
+ */
63
+ protected function previewPage() {
64
+ $children = $this->getChildren();
65
+ $value = $this->Form->getCheckedValue( $this->atts['name'], $children );
66
+ $_ret = $value;
67
+ $_ret .= $this->Form->hidden( $this->atts['name'] . '[data]', $value );
68
+ $_ret .= $this->Form->separator( $this->atts['name'] );
69
+ return $_ret;
70
+ }
71
+ }
form_fields/mw_form_datepicker.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Datepicker
4
+ * URI: http://2inc.org
5
+ * Description: datepickerを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_datepicker extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'size' => 30,
38
+ 'js' => '',
39
+ 'value' => '',
40
+ 'show_error' => 'true',
41
+ );
42
+ }
43
+
44
+ /**
45
+ * inputPage
46
+ * 入力ページでのフォーム項目を返す
47
+ * @return String HTML
48
+ */
49
+ protected function inputPage() {
50
+ wp_enqueue_style( 'jquery.ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css', array(), '1.9.2' );
51
+ wp_enqueue_script( 'jquery-ui-datepicker' );
52
+ // 日本語の場合は日本語表記に変更
53
+ if ( get_locale() == 'ja' ) {
54
+ if ( !empty( $this->atts['js'] ) )
55
+ $this->atts['js'] = $this->atts['js'] . ',';
56
+ $this->atts['js'] .= '
57
+ dateFormat: "yy-mm-dd",
58
+ dayNames: ["日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日"],
59
+ dayNamesMin: ["日","月","火","水","木","金","土"],
60
+ dayNamesShort: ["日曜","月曜","火曜","水曜","木曜","金曜","土曜"],
61
+ monthNames: ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],
62
+ monthNamesShort: ["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
63
+ ';
64
+ }
65
+ $_ret = '';
66
+ $_ret .= $this->Form->datepicker( $this->atts['name'], array(
67
+ 'size' => $this->atts['size'],
68
+ 'js' => $this->atts['js'],
69
+ 'value' => $this->atts['value'],
70
+ ) );
71
+ if ( $this->atts['show_error'] !== 'false' )
72
+ $_ret .= $this->getError( $this->atts['name'] );
73
+ return $_ret;
74
+ }
75
+
76
+ /**
77
+ * previewPage
78
+ * 確認ページでのフォーム項目を返す
79
+ * @return String HTML
80
+ */
81
+ protected function previewPage() {
82
+ $value = $this->Form->getValue( $this->atts['name'] );
83
+ $_ret = $value;
84
+ $_ret .= $this->Form->hidden( $this->atts['name'], $value );
85
+ return $_ret;
86
+ }
87
+ }
form_fields/mw_form_error.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Error
4
+ * URI: http://2inc.org
5
+ * Description: エラーを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_error extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'keys' => '',
37
+ );
38
+ }
39
+
40
+ /**
41
+ * inputPage
42
+ * 入力ページでのフォーム項目を返す
43
+ * @return String HTML
44
+ */
45
+ protected function inputPage() {
46
+ $keys = explode( ',', $this->atts['keys'] );
47
+ $_ret = '';
48
+ foreach ( $keys as $key ) {
49
+ $_ret .= $this->getError( trim( $key ) );
50
+ }
51
+ return $_ret;
52
+ }
53
+
54
+ /**
55
+ * previewPage
56
+ * 確認ページでのフォーム項目を返す
57
+ * @return String HTML
58
+ */
59
+ protected function previewPage() {
60
+ }
61
+ }
form_fields/mw_form_field_back_button.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Back Button
4
+ * URI: http://2inc.org
5
+ * Description: 戻るボタンを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_back_button extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'value' => __( 'Back', self::DOMAIN ),
37
+ );
38
+ }
39
+
40
+ /**
41
+ * inputPage
42
+ * 入力ページでのフォーム項目を返す
43
+ * @return String HTML
44
+ */
45
+ protected function inputPage() {
46
+ }
47
+
48
+ /**
49
+ * previewPage
50
+ * 確認ページでのフォーム項目を返す
51
+ * @return String HTML
52
+ */
53
+ protected function previewPage() {
54
+ return $this->Form->submit( $this->Form->getBackButtonName(), $this->atts['value'] );
55
+ }
56
+ }
form_fields/mw_form_field_button.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Button
4
+ * URI: http://2inc.org
5
+ * Description: ボタンを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_button extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'value' => '',
38
+ );
39
+ }
40
+
41
+ /**
42
+ * inputPage
43
+ * 入力ページでのフォーム項目を返す
44
+ * @return String HTML
45
+ */
46
+ protected function inputPage() {
47
+ return $this->Form->button( $this->atts['name'], $this->atts['value'] );
48
+ }
49
+
50
+ /**
51
+ * previewPage
52
+ * 確認ページでのフォーム項目を返す
53
+ * @return String HTML
54
+ */
55
+ protected function previewPage() {
56
+ return $this->inputPage();
57
+ }
58
+ }
form_fields/mw_form_field_hidden.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Hidden
4
+ * URI: http://2inc.org
5
+ * Description: hiddenフィールドを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_hidden extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'value' => '',
38
+ );
39
+ }
40
+
41
+ /**
42
+ * inputPage
43
+ * 入力ページでのフォーム項目を返す
44
+ * @return String HTML
45
+ */
46
+ protected function inputPage() {
47
+ return $this->Form->hidden( $this->atts['name'], $this->atts['value'] );
48
+ }
49
+
50
+ /**
51
+ * previewPage
52
+ * 確認ページでのフォーム項目を返す
53
+ * @return String HTML
54
+ */
55
+ protected function previewPage() {
56
+ $value = $this->Form->getValue( $this->atts['name'] );
57
+ return $this->Form->hidden( $this->atts['name'], $value );
58
+ }
59
+ }
form_fields/mw_form_field_password.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Password
4
+ * URI: http://2inc.org
5
+ * Description: パスワードフィールドを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_password extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'size' => 60,
38
+ 'maxlength' => 255,
39
+ 'value' => '',
40
+ 'show_error' => 'true',
41
+ );
42
+ }
43
+
44
+ /**
45
+ * inputPage
46
+ * 入力ページでのフォーム項目を返す
47
+ * @return String HTML
48
+ */
49
+ protected function inputPage() {
50
+ $_ret = $this->Form->password( $this->atts['name'], array(
51
+ 'size' => $this->atts['size'],
52
+ 'maxlength' => $this->atts['maxlength'],
53
+ 'value' => $this->atts['value'],
54
+ ) );
55
+ if ( $this->atts['show_error'] !== 'false' )
56
+ $_ret .= $this->getError( $this->atts['name'] );
57
+ return $_ret;
58
+ }
59
+
60
+ /**
61
+ * previewPage
62
+ * 確認ページでのフォーム項目を返す
63
+ * @return String HTML
64
+ */
65
+ protected function previewPage() {
66
+ $value = $this->Form->getValue( $this->atts['name'] );
67
+ return '*****' . $this->Form->hidden( $this->atts['name'], $this->atts );
68
+ }
69
+ }
form_fields/mw_form_field_preview_button.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Preview Button
4
+ * URI: http://2inc.org
5
+ * Description: 確認ボタンを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_preview_button extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'value' => __( 'Confirm', self::DOMAIN ),
37
+ );
38
+ }
39
+
40
+ /**
41
+ * inputPage
42
+ * 入力ページでのフォーム項目を返す
43
+ * @return String HTML
44
+ */
45
+ protected function inputPage() {
46
+ return $this->Form->submit( $this->Form->getPreviewButtonName(), $this->atts['value'] );
47
+ }
48
+
49
+ /**
50
+ * previewPage
51
+ * 確認ページでのフォーム項目を返す
52
+ * @return String HTML
53
+ */
54
+ protected function previewPage() {
55
+ }
56
+ }
form_fields/mw_form_field_submit.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Submit Button
4
+ * URI: http://2inc.org
5
+ * Description: 確認ボタンと送信ボタンを自動出力。同一ページ変遷の場合に利用。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_submit_button extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'preview_value' => __( 'Confirm', self::DOMAIN ),
38
+ 'submit_value' => __( 'Send', self::DOMAIN ),
39
+ );
40
+ }
41
+
42
+ /**
43
+ * inputPage
44
+ * 入力ページでのフォーム項目を返す
45
+ * @return String HTML
46
+ */
47
+ protected function inputPage() {
48
+ if ( !empty( $this->atts['preview_value'] ) ) {
49
+ return $this->Form->submit( $this->Form->getPreviewButtonName(), $this->atts['preview_value'] );
50
+ }
51
+ return $this->Form->submit( $this->atts['name'], $this->atts['submit_value'] );
52
+ }
53
+
54
+ /**
55
+ * previewPage
56
+ * 確認ページでのフォーム項目を返す
57
+ * @return String HTML
58
+ */
59
+ protected function previewPage() {
60
+ return $this->Form->submit( $this->atts['name'], $this->atts['submit_value'] );
61
+ }
62
+ }
form_fields/mw_form_field_submit_button.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Submit
4
+ * URI: http://2inc.org
5
+ * Description: サブミットボタンを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_submit extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'value' => __( 'Send', self::DOMAIN ),
38
+ );
39
+ }
40
+
41
+ /**
42
+ * inputPage
43
+ * 入力ページでのフォーム項目を返す
44
+ * @return String HTML
45
+ */
46
+ protected function inputPage() {
47
+ return $this->Form->submit( $this->atts['name'], $this->atts['value'] );
48
+ }
49
+
50
+ /**
51
+ * previewPage
52
+ * 確認ページでのフォーム項目を返す
53
+ * @return String HTML
54
+ */
55
+ protected function previewPage() {
56
+ return $this->inputPage();
57
+ }
58
+ }
form_fields/mw_form_field_tel.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Tel
4
+ * URI: http://2inc.org
5
+ * Description: 電話番号フィールドを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_tel extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'show_error' => 'true',
38
+ );
39
+ }
40
+
41
+ /**
42
+ * inputPage
43
+ * 入力ページでのフォーム項目を返す
44
+ * @return String HTML
45
+ */
46
+ protected function inputPage() {
47
+ $_ret = $this->Form->tel( $this->atts['name'] );
48
+ if ( $this->atts['show_error'] !== 'false' )
49
+ $_ret .= $this->getError( $this->atts['name'] );
50
+ return $_ret;
51
+ }
52
+
53
+ /**
54
+ * previewPage
55
+ * 確認ページでのフォーム項目を返す
56
+ * @return String HTML
57
+ */
58
+ protected function previewPage() {
59
+ $value = $this->Form->getTelValue( $this->atts['name'] );
60
+ $_ret = $value;
61
+ $_ret .= $this->Form->hidden( $this->atts['name'].'[data]', $value );
62
+ $_ret .= $this->Form->separator( $this->atts['name'] );
63
+ return $_ret;
64
+ }
65
+ }
form_fields/mw_form_field_text.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Text
4
+ * URI: http://2inc.org
5
+ * Description: テキストフィールドを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_text extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'size' => 60,
38
+ 'maxlength' => 255,
39
+ 'value' => '',
40
+ 'show_error' => 'true'
41
+ );
42
+ }
43
+
44
+ /**
45
+ * inputPage
46
+ * 入力ページでのフォーム項目を返す
47
+ * @return String HTML
48
+ */
49
+ protected function inputPage() {
50
+ $_ret = $this->Form->text( $this->atts['name'], array(
51
+ 'size' => $this->atts['size'],
52
+ 'maxlength' => $this->atts['maxlength'],
53
+ 'value' => $this->atts['value'],
54
+ ) );
55
+ if ( $this->atts['show_error'] !== 'false' )
56
+ $_ret .= $this->getError( $this->atts['name'] );
57
+ return $_ret;
58
+ }
59
+
60
+ /**
61
+ * previewPage
62
+ * 確認ページでのフォーム項目を返す
63
+ * @return String HTML
64
+ */
65
+ protected function previewPage() {
66
+ $value = $this->Form->getValue( $this->atts['name'] );
67
+ $_ret = $value;
68
+ $_ret .= $this->Form->hidden( $this->atts['name'], $value );
69
+ return $_ret;
70
+ }
71
+ }
form_fields/mw_form_field_zip.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Zip
4
+ * URI: http://2inc.org
5
+ * Description: 郵便番号フィールドを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_zip extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'show_error' => 'true',
38
+ );
39
+ }
40
+
41
+ /**
42
+ * inputPage
43
+ * 入力ページでのフォーム項目を返す
44
+ * @return String HTML
45
+ */
46
+ protected function inputPage() {
47
+ $_ret = $this->Form->zip( $this->atts['name'] );
48
+ if ( $this->atts['show_error'] !== 'false' )
49
+ $_ret .= $this->getError( $this->atts['name'] );
50
+ return $_ret;
51
+ }
52
+
53
+ /**
54
+ * previewPage
55
+ * 確認ページでのフォーム項目を返す
56
+ * @return String HTML
57
+ */
58
+ protected function previewPage() {
59
+ $value = $this->Form->getZipValue( $this->atts['name'] );
60
+ $_ret = $value;
61
+ $_ret .= $this->Form->hidden( $this->atts['name'].'[data]', $value );
62
+ $_ret .= $this->Form->separator( $this->atts['name'] );
63
+ return $_ret;
64
+ }
65
+ }
form_fields/mw_form_radio.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Radio
4
+ * URI: http://2inc.org
5
+ * Description: ラジオボタンを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_radio extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'children' => '',
38
+ 'value' => '',
39
+ 'show_error' => 'true',
40
+ );
41
+ }
42
+
43
+ /**
44
+ * inputPage
45
+ * 入力ページでのフォーム項目を返す
46
+ * @return String HTML
47
+ */
48
+ protected function inputPage() {
49
+ $children = $this->getChildren();
50
+ $_ret = $this->Form->radio( $this->atts['name'], $children, array(
51
+ 'value' => $this->atts['value'],
52
+ ) );
53
+ if ( $this->atts['show_error'] !== 'false' )
54
+ $_ret .= $this->getError( $this->atts['name'] );
55
+ return $_ret;
56
+ }
57
+
58
+ /**
59
+ * previewPage
60
+ * 確認ページでのフォーム項目を返す
61
+ * @return String HTML
62
+ */
63
+ protected function previewPage() {
64
+ $children = $this->getChildren();
65
+ $value = $this->Form->getRadioValue( $this->atts['name'], $children );
66
+ $_ret = $value;
67
+ $_ret .= $this->Form->hidden( $this->atts['name'], $value );
68
+ return $_ret;
69
+ }
70
+ }
form_fields/mw_form_select.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field Select
4
+ * URI: http://2inc.org
5
+ * Description: セレクトボックスを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_select extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'children' => '',
38
+ 'value' => '',
39
+ 'show_error' => 'true',
40
+ );
41
+ }
42
+
43
+ /**
44
+ * inputPage
45
+ * 入力ページでのフォーム項目を返す
46
+ * @return String HTML
47
+ */
48
+ protected function inputPage() {
49
+ $children = $this->getChildren();
50
+ $_ret = $this->Form->select( $this->atts['name'], $children, array(
51
+ 'value' => $this->atts['value'],
52
+ ) );
53
+ if ( $this->atts['show_error'] !== 'false' )
54
+ $_ret .= $this->getError( $this->atts['name'] );
55
+ return $_ret;
56
+ }
57
+
58
+ /**
59
+ * previewPage
60
+ * 確認ページでのフォーム項目を返す
61
+ * @return String HTML
62
+ */
63
+ protected function previewPage() {
64
+ $children = $this->getChildren();
65
+ $value = $this->Form->getSelectedValue( $this->atts['name'], $children );
66
+ $_ret = $value;
67
+ $_ret .= $this->Form->hidden( $this->atts['name'], $value );
68
+ return $_ret;
69
+ }
70
+ }
form_fields/mw_form_textarea.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field TextArea
4
+ * URI: http://2inc.org
5
+ * Description: テキストエリアを出力。
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class mw_form_field_textarea extends mw_form_field {
28
+
29
+ /**
30
+ * setDefaults
31
+ * $this->defaultsを設定し返す
32
+ * @return Array defaults
33
+ */
34
+ protected function setDefaults() {
35
+ return array(
36
+ 'name' => '',
37
+ 'cols' => 50,
38
+ 'rows' => 5,
39
+ 'value' => '',
40
+ 'show_error' => 'true',
41
+ );
42
+ }
43
+
44
+ /**
45
+ * inputPage
46
+ * 入力ページでのフォーム項目を返す
47
+ * @return String HTML
48
+ */
49
+ protected function inputPage() {
50
+ $_ret = $this->Form->textarea( $this->atts['name'], array(
51
+ 'cols' => $this->atts['cols'],
52
+ 'rows' => $this->atts['rows'],
53
+ 'value' => $this->atts['value'],
54
+ ) );
55
+ if ( $this->atts['show_error'] !== 'false' )
56
+ $_ret .= $this->getError( $this->atts['name'] );
57
+ return $_ret;
58
+ }
59
+
60
+ /**
61
+ * previewPage
62
+ * 確認ページでのフォーム項目を返す
63
+ * @return String HTML
64
+ */
65
+ protected function previewPage() {
66
+ $value = $this->Form->getValue( $this->atts['name'] );
67
+ $_ret = nl2br( $value );
68
+ $_ret .= $this->Form->hidden( $this->atts['name'], $value );
69
+ return $_ret;
70
+ }
71
+ }
languages/mw-wp-form-ja.mo ADDED
Binary file
languages/mw-wp-form-ja.po ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2012 MW WP Form
2
+ # This file is distributed under the same license as the MW WP Form package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: MW WP Form 0.5\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/mw-wp-form\n"
7
+ "POT-Creation-Date: 2012-12-14 15:41+0900\n"
8
+ "PO-Revision-Date: 2012-12-16 22:06+0900\n"
9
+ "Last-Translator: \n"
10
+ "Language-Team: Takashi Kitajima <inc@2inc.org>\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "Plural-Forms: nplurals=1; plural=0;\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Generator: Poedit 1.5.4\n"
18
+ "X-Poedit-KeywordsList: __;_e\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+
21
+ #: form_fields/mw_form_field_back_button.php:36
22
+ msgid "Back"
23
+ msgstr "戻る"
24
+
25
+ #: form_fields/mw_form_field_preview_button.php:36
26
+ #: form_fields/mw_form_field_submit.php:37
27
+ msgid "Confirm"
28
+ msgstr "確認画面へ"
29
+
30
+ #: form_fields/mw_form_field_submit.php:38
31
+ #: form_fields/mw_form_field_submit_button.php:37
32
+ msgid "Send"
33
+ msgstr "送信する"
34
+
35
+ #: mw-wp-form.php:201
36
+ msgid "Validation Object is not a MW Validation Class."
37
+ msgstr ""
38
+
39
+ #: system/mw_validation.php:75
40
+ msgid "This is required."
41
+ msgstr "必須項目です。"
42
+
43
+ #: system/mw_validation.php:95 system/mw_validation.php:117
44
+ msgid "Please enter."
45
+ msgstr "未入力です。"
46
+
47
+ #: system/mw_validation.php:139
48
+ msgid "Please enter with a half-width alphabetic character."
49
+ msgstr "半角英字で入力してください。"
50
+
51
+ #: system/mw_validation.php:161
52
+ msgid "Please enter with a half-width number."
53
+ msgstr "半角数字で入力してください。"
54
+
55
+ #: system/mw_validation.php:183
56
+ msgid "Please enter with a half-width alphanumeric character."
57
+ msgstr "半角英数字で入力してください。"
58
+
59
+ #: system/mw_validation.php:205
60
+ msgid "This is not the format of a zip code."
61
+ msgstr "郵便番号の形式ではありません。"
62
+
63
+ #: system/mw_validation.php:232
64
+ msgid "This is not the format of a tel number."
65
+ msgstr "電話番号の形式ではありません。"
66
+
67
+ #: system/mw_validation.php:259
68
+ msgid "This is not the format of a mail address."
69
+ msgstr "メールアドレスの形式ではありません。"
70
+
71
+ #: system/mw_validation.php:281
72
+ msgid "This is not the format of a url."
73
+ msgstr "URLの形式ではありません。"
74
+
75
+ #: system/mw_validation.php:304
76
+ msgid "This is not in agreement."
77
+ msgstr "一致しません。"
78
+
79
+ #: system/mw_validation.php:328
80
+ msgid "The number of characters is invalid."
81
+ msgstr "文字数が正しくありません。"
82
+
83
+ #: system/mw_validation.php:352
84
+ msgid "The number of characters is a few."
85
+ msgstr "文字数が足りません。"
86
+
87
+ #: system/mw_validation.php:376
88
+ msgid "This value is invalid."
89
+ msgstr "値が不正です。"
90
+
91
+ #: system/mw_validation.php:398
92
+ msgid "This is not the format of a date."
93
+ msgstr "日付の形式ではありません。"
94
+
95
+ #. Plugin Name of the plugin/theme
96
+ msgid "MW WP Form"
97
+ msgstr ""
98
+
99
+ #. Plugin URI of the plugin/theme
100
+ msgid "http://2inc.org/blog/category/products/wordpress_plugins/mw-wp-form/"
101
+ msgstr ""
102
+
103
+ #. Description of the plugin/theme
104
+ msgid ""
105
+ "Plug-in which can create mail form using short code. E-mail sending and "
106
+ "validation can be specified at functions.php."
107
+ msgstr ""
108
+
109
+ #. Author of the plugin/theme
110
+ msgid "Takashi Kitajima"
111
+ msgstr ""
112
+
113
+ #. Author URI of the plugin/theme
114
+ msgid "http://2inc.org"
115
+ msgstr ""
languages/mw-wp-form.pot ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2012 MW WP Form
2
+ # This file is distributed under the same license as the MW WP Form package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: MW WP Form 0.5\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/mw-wp-form\n"
7
+ "POT-Creation-Date: 2012-12-14 15:41+0900\n"
8
+ "PO-Revision-Date: 2012-12-14 15:42+0900\n"
9
+ "Last-Translator: Takashi Kitajima <inc@2inc.org>\n"
10
+ "Language-Team: Takashi Kitajima <inc@2inc.org>\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "Plural-Forms: nplurals=1; plural=0;\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Generator: Poedit 1.5.4\n"
18
+ "X-Poedit-KeywordsList: __;_e\n"
19
+ "X-Poedit-SearchPath-0: ..\n"
20
+
21
+ #: form_fields/mw_form_field_back_button.php:36
22
+ msgid "Back"
23
+ msgstr ""
24
+
25
+ #: form_fields/mw_form_field_preview_button.php:36
26
+ #: form_fields/mw_form_field_submit.php:37
27
+ msgid "Confirm"
28
+ msgstr ""
29
+
30
+ #: form_fields/mw_form_field_submit.php:38
31
+ #: form_fields/mw_form_field_submit_button.php:37
32
+ msgid "Send"
33
+ msgstr ""
34
+
35
+ #: mw-wp-form.php:201
36
+ msgid "Validation Object is not a MW Validation Class."
37
+ msgstr ""
38
+
39
+ #: system/mw_validation.php:75
40
+ msgid "This is required."
41
+ msgstr ""
42
+
43
+ #: system/mw_validation.php:95 system/mw_validation.php:117
44
+ msgid "Please enter."
45
+ msgstr ""
46
+
47
+ #: system/mw_validation.php:139
48
+ msgid "Please enter with a half-width alphabetic character."
49
+ msgstr ""
50
+
51
+ #: system/mw_validation.php:161
52
+ msgid "Please enter with a half-width number."
53
+ msgstr ""
54
+
55
+ #: system/mw_validation.php:183
56
+ msgid "Please enter with a half-width alphanumeric character."
57
+ msgstr ""
58
+
59
+ #: system/mw_validation.php:205
60
+ msgid "This is not the format of a zip code."
61
+ msgstr ""
62
+
63
+ #: system/mw_validation.php:232
64
+ msgid "This is not the format of a tel number."
65
+ msgstr ""
66
+
67
+ #: system/mw_validation.php:259
68
+ msgid "This is not the format of a mail address."
69
+ msgstr ""
70
+
71
+ #: system/mw_validation.php:281
72
+ msgid "This is not the format of a url."
73
+ msgstr ""
74
+
75
+ #: system/mw_validation.php:304
76
+ msgid "This is not in agreement."
77
+ msgstr ""
78
+
79
+ #: system/mw_validation.php:328
80
+ msgid "The number of characters is invalid."
81
+ msgstr ""
82
+
83
+ #: system/mw_validation.php:352
84
+ msgid "The number of characters is a few."
85
+ msgstr ""
86
+
87
+ #: system/mw_validation.php:376
88
+ msgid "This value is invalid."
89
+ msgstr ""
90
+
91
+ #: system/mw_validation.php:398
92
+ msgid "This is not the format of a date."
93
+ msgstr ""
94
+
95
+ #. Plugin Name of the plugin/theme
96
+ msgid "MW WP Form"
97
+ msgstr ""
98
+
99
+ #. Plugin URI of the plugin/theme
100
+ msgid "http://2inc.org/blog/category/products/wordpress_plugins/mw-wp-form/"
101
+ msgstr ""
102
+
103
+ #. Description of the plugin/theme
104
+ msgid ""
105
+ "Plug-in which can create mail form using short code. E-mail sending and "
106
+ "validation can be specified at functions.php."
107
+ msgstr ""
108
+
109
+ #. Author of the plugin/theme
110
+ msgid "Takashi Kitajima"
111
+ msgstr ""
112
+
113
+ #. Author URI of the plugin/theme
114
+ msgid "http://2inc.org"
115
+ msgstr ""
mw-wp-form.php ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: MW WP Form
4
+ * Plugin URI: http://2inc.org/blog/category/products/wordpress_plugins/mw-wp-form/
5
+ * Description: Plug-in which can create mail form using short code. E-mail sending and validation can be specified at functions.php.
6
+ * Version: 0.5
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: September 25, 2012
10
+ * Modified: December 14, 2012
11
+ * Text Domain: mw-wp-form
12
+ * Domain Path: /languages/
13
+ * License: GPL2
14
+ *
15
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
16
+ *
17
+ * This program is free software; you can redistribute it and/or modify
18
+ * it under the terms of the GNU General Public License, version 2, as
19
+ * published by the Free Software Foundation.
20
+ *
21
+ * This program is distributed in the hope that it will be useful,
22
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ * GNU General Public License for more details.
25
+ *
26
+ * You should have received a copy of the GNU General Public License
27
+ * along with this program; if not, write to the Free Software
28
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
+ */
30
+ $mw_wp_form = new mw_wp_form();
31
+ class mw_wp_form {
32
+
33
+ const NAME = 'mw-wp-form';
34
+ const DOMAIN = 'mw-wp-form';
35
+ const CUSTOM_FIELD_NAME = '_mwform';
36
+ protected $key;
37
+ protected $input;
38
+ protected $preview;
39
+ protected $complete;
40
+ protected $data;
41
+ protected $Form;
42
+ protected $Validation;
43
+ protected $Error;
44
+ protected $Session;
45
+ protected $viewFlg = 'input';
46
+
47
+ /**
48
+ * __construct
49
+ */
50
+ public function __construct() {
51
+ // ファイルロード
52
+ load_plugin_textdomain( self::DOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages' );
53
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_error.php' );
54
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_form.php' );
55
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_mail.php' );
56
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_session.php' );
57
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_validation.php' );
58
+ include_once( plugin_dir_path( __FILE__ ) . 'system/mw_form_field.php' );
59
+ foreach( glob( plugin_dir_path( __FILE__ ) . 'form_fields/*.php' ) as $form_field ) {
60
+ include_once $form_field;
61
+ }
62
+ add_action( 'get_header', array( $this, 'init' ) );
63
+ add_action( 'save_post', array( $this, 'save_post' ) );
64
+ add_action( 'wp_print_styles', array( $this, 'original_style' ) );
65
+ }
66
+
67
+ /**
68
+ * original_style
69
+ * CSS適用
70
+ */
71
+ public function original_style() {
72
+ $url = plugin_dir_url( __FILE__ );
73
+ wp_register_style( self::DOMAIN, $url.'css/style.css' );
74
+ wp_enqueue_style( self::DOMAIN );
75
+ }
76
+
77
+ /**
78
+ * save_post
79
+ * 編集・保存時にカスタムフィールドに[mwform〜]を保存
80
+ * @param Int 投稿ID
81
+ */
82
+ public function save_post( $id ) {
83
+ $post = get_post( $id );
84
+ preg_match( '/(\[mwform .+?\])/msi', $post->post_content, $reg );
85
+ if ( !empty( $reg[1] ) ) {
86
+ delete_post_meta( $id, self::CUSTOM_FIELD_NAME );
87
+ add_post_meta( $id, self::CUSTOM_FIELD_NAME, $reg[1], true );
88
+ }
89
+ }
90
+
91
+ /**
92
+ * _meta_mwform
93
+ * [mwform〜]を解析し、プロパティを設定
94
+ * @param Array ( input, preview, complete, key )
95
+ */
96
+ public function _meta_mwform( $atts ) {
97
+ $atts = shortcode_atts( array(
98
+ 'input' => '',
99
+ 'preview' => '',
100
+ 'complete' => '',
101
+ 'key' => 'mwform'
102
+ ), $atts );
103
+ $this->key = $atts['key'];
104
+ $this->input = $atts['input'];
105
+ $this->preview = $atts['preview'];
106
+ $this->complete = $atts['complete'];
107
+ }
108
+
109
+ /**
110
+ * init
111
+ * 表示画面でのプラグインの初期化処理等。カスタムフィールド_mwformが無いときはショートコードの有効化、処理をしない。
112
+ */
113
+ public function init() {
114
+ global $post;
115
+ if ( empty( $post->ID ) ) return;
116
+ $_mwform = get_post_meta( $post->ID, self::CUSTOM_FIELD_NAME, true );
117
+ // カスタムフィールドに値がなければ終了
118
+ if ( empty( $_mwform ) ) return;
119
+ // カスタムフィールドから設定を取得
120
+ add_shortcode( 'mwform', array( $this, '_meta_mwform' ) );
121
+ do_shortcode( $_mwform );
122
+ remove_shortcode( 'mwform' );
123
+ // ショートコード有効化
124
+ add_shortcode( 'mwform', array( $this, '_mwform' ) );
125
+ add_shortcode( 'mwform_complete_message', array( $this, '_mwform_complete_message' ) );
126
+ add_shortcode( 'mwform_error', array( $this, '_mwform_error' ) );
127
+ add_shortcode( 'mwform_text', array( $this, '_mwform_text' ) );
128
+ add_shortcode( 'mwform_submitButton', array( $this, '_mwform_submitButton' ) );
129
+ add_shortcode( 'mwform_submit', array( $this, '_mwform_submit' ) );
130
+ add_shortcode( 'mwform_previewButton', array( $this, '_mwform_previewButton' ) );
131
+ add_shortcode( 'mwform_backButton', array( $this, '_mwform_backButton' ) );
132
+ add_shortcode( 'mwform_button', array( $this, '_mwform_button' ) );
133
+ add_shortcode( 'mwform_hidden', array( $this, '_mwform_hidden' ) );
134
+ add_shortcode( 'mwform_password', array( $this, '_mwform_password' ) );
135
+ add_shortcode( 'mwform_zip', array( $this, '_mwform_zip' ) );
136
+ add_shortcode( 'mwform_tel', array( $this, '_mwform_tel' ) );
137
+ add_shortcode( 'mwform_textarea', array( $this, '_mwform_textarea' ) );
138
+ add_shortcode( 'mwform_select', array( $this, '_mwform_select' ) );
139
+ add_shortcode( 'mwform_radio', array( $this, '_mwform_radio' ) );
140
+ add_shortcode( 'mwform_checkbox', array( $this, '_mwform_checkbox' ) );
141
+ add_shortcode( 'mwform_datepicker', array( $this, '_mwform_datepicker' ) );
142
+
143
+ // セッション初期化
144
+ $this->Session = MW_Session::start( $this->key );
145
+ // $_POSTがあるときは$_POST、無いときは$this->Session->getValues()
146
+ $this->data = ( !empty( $_POST ) ) ? $_POST : $this->Session->getValues();
147
+ // フォームオブジェクト生成
148
+ $this->Form = new MW_Form( $this->data, $this->key );
149
+ // セッションデータ設定
150
+ $this->Session->clearValues();
151
+ if ( !empty( $_POST ) ) $this->Session->save( $_POST );
152
+
153
+ // バリデーションオブジェクト生成
154
+ $this->Validation = new MW_Validation( $this->data );
155
+ // バリデーション実行(Validation->dataに値がないと$Errorは返さない(true))
156
+ $this->apply_filters_mwform_validation();
157
+
158
+ // 入力画面(戻る)のとき
159
+ if ( $this->Form->isInput() ) {
160
+ $this->redirect( $this->input );
161
+ }
162
+ // 確認画面のとき
163
+ elseif ( $this->Form->isPreview() ) {
164
+ if ( $this->Validation->check() ) {
165
+ $this->viewFlg = 'preview';
166
+ $this->redirect( $this->preview );
167
+ } else {
168
+ $this->redirect( $this->input );
169
+ }
170
+ }
171
+ // 完了画面のとき
172
+ elseif ( $this->Form->isComplete() ) {
173
+ if ( $this->Validation->check() ) {
174
+ $this->viewFlg = 'complete';
175
+ $this->do_action_mwform_mail();
176
+ $this->Form->clearToken();
177
+ $this->redirect( $this->complete );
178
+ } else {
179
+ $this->redirect( $this->input );
180
+ }
181
+ }
182
+ $this->Session->clearValues();
183
+ }
184
+
185
+ /**
186
+ * apply_filters_mwform_validation
187
+ * バリデーション用フィルタ。フィルタの実行結果としてValidationオブジェクトが返ってこなければエラー
188
+ * 各バリデーションメソッドの詳細は /system/mw_validation.php を参照
189
+ * @example
190
+ * // hoge識別子のフォームのバリデーションを行う場合
191
+ * add_filters( 'mwform_validation_hoge', 'mwform_validation_hoge' );
192
+ * function mwform_validation_hoge( $v ) {
193
+ * $v->setRule( 'key', 'noEmpty' );
194
+ * return $V;
195
+ * }
196
+ */
197
+ protected function apply_filters_mwform_validation() {
198
+ $filterName = 'mwform_validation_'.$this->key;
199
+ $this->Validation = apply_filters( $filterName, $this->Validation );
200
+ if ( !is_a( $this->Validation, 'MW_Validation' ) ) {
201
+ exit( __( 'Validation Object is not a MW Validation Class.', self::DOMAIN ) );
202
+ }
203
+ }
204
+
205
+ /**
206
+ * do_action_mwform_mail
207
+ * メール送信アクション
208
+ * @example
209
+ * // hoge識別子のフォームのメール送信を行う場合
210
+ * // $dataにフォームから送信された内容が配列で格納されている。
211
+ * add_action( 'mwform_mail_hoge', 'mwform_mail_hoge', 10, 2 );
212
+ * function mwform_mail_hoge( $m, $data ) {
213
+ * $m->to = $data['your_email']; // 宛先
214
+ * $m->from = 'inc@2inc.org'; // 送信元
215
+ * $m->sender = 'kitajima' // 送信者
216
+ * $m->subject = '送信ありがとうございます。'; // 題名
217
+ * $m->body = '本文'; // 本文
218
+ * $m->send(); // 送信
219
+ * }
220
+ */
221
+ protected function do_action_mwform_mail() {
222
+ $Mail = new MW_Mail();
223
+ $actionName = 'mwform_mail_'.$this->key;
224
+ do_action( $actionName, $Mail, $this->data );
225
+ }
226
+
227
+ /**
228
+ * redirect
229
+ * 現在のURLと引数で渡されたリダイレクトURLが同じであればリダイレクトしない
230
+ * @param String リダイレクトURL
231
+ */
232
+ private function redirect( $url ) {
233
+ $redirect = ( empty( $url ) ) ? $_SERVER['REQUEST_URI'] : $url;
234
+ if ( $redirect != $_SERVER['REQUEST_URI'] || $this->Form->isInput() && !empty( $_POST ) ) {
235
+ wp_redirect( $redirect );
236
+ exit();
237
+ }
238
+ }
239
+
240
+ /**
241
+ * _mwform
242
+ * @example
243
+ * 同一画面変遷の場合
244
+ * [mwform key="hoge"]〜[/mwform]
245
+ * 別ページ画面変遷の場合
246
+ * 確認画面ありの場合
247
+ * 入力画面 : [mwform preview="/form_preview/" key="hoge"]〜[/mwform]
248
+ * 確認画面 : [mwform input="/form_input/" complete="/form_complete/" key="hoge"]〜[/mwform]
249
+ * 確認画面なしの場合
250
+ * 入力画面 : [mwform complete="/form_complete/" key="hoge"]〜[/mwform]
251
+ */
252
+ public function _mwform( $atts, $content = '' ) {
253
+ // 完了画面ではフォームは表示しない
254
+ $atts = shortcode_atts( array(
255
+ 'input' => '',
256
+ 'preview' => '',
257
+ 'complete' => '',
258
+ 'key' => 'mwform'
259
+ ), $atts );
260
+
261
+ if ( $this->viewFlg == 'input' || $this->viewFlg == 'preview' ) {
262
+ $this->Error = $this->Validation->Error();
263
+ return
264
+ '<div id="mw_wp_form_' . $atts['key'] . '" class="mw_wp_form">' .
265
+ $this->Form->start() .
266
+ do_shortcode( $content ) .
267
+ $this->Form->end() .
268
+ '<!-- end .mw_wp_form --></div>';
269
+ }
270
+ }
271
+
272
+ /**
273
+ * _mwform_complete_message
274
+ * 完了後のメッセージ。同一ページで画面変遷したときだけ実行する
275
+ * @example
276
+ * [mwform …]〜[/mwform]
277
+ * [mwform_complete_message]ここに完了後に表示するメッセージ[/mwform_complete_message]
278
+ */
279
+ public function _mwform_complete_message( $atts, $content = '' ) {
280
+ if ( $this->viewFlg == 'complete' ) {
281
+ return $content;
282
+ }
283
+ }
284
+
285
+ /**
286
+ * _mwform_error
287
+ * エラーを出力。
288
+ * @example
289
+ * [mwform_error keys="hoge,fuga"]
290
+ */
291
+ public function _mwform_error( $atts ) {
292
+ $form_field = new mw_form_field_error( $this->Form, $atts, $this->viewFlg, $this->Error );
293
+ return $form_field->getField();
294
+ }
295
+
296
+ /**
297
+ * _mwform_text
298
+ * テキストフィールドを出力。
299
+ * @example
300
+ * [mwform_text name="hoge" size="60" maxlength="255" value="" show_error="true"]
301
+ */
302
+ public function _mwform_text( $atts ) {
303
+ $form_field = new mw_form_field_text( $this->Form, $atts, $this->viewFlg, $this->Error );
304
+ return $form_field->getField();
305
+ }
306
+
307
+ /**
308
+ * _mwform_submitButton
309
+ * 確認ボタンと送信ボタンを自動出力。同一ページ変遷の場合に利用。
310
+ * @example
311
+ * [mwform_submitButton name="hoge" preview_value="確認画面へ" submit_value="送信する"]
312
+ *
313
+ * viewFlg == inputで
314
+ * preview_valueあるときは確認ボタン
315
+ * preview_valueないときは送信ボタン
316
+ * viewFlg == preview
317
+ * 送信ボタン
318
+ * viewFlg == complete
319
+ * 非表示
320
+ */
321
+ public function _mwform_submitButton( $atts ) {
322
+ $form_field = new mw_form_field_submit_button( $this->Form, $atts, $this->viewFlg, $this->Error );
323
+ return $form_field->getField();
324
+ }
325
+
326
+ /**
327
+ * _mwform_submit
328
+ * サブミットボタンを出力。
329
+ * @example
330
+ * [mwform_submit name="hoge" value="送信する"]
331
+ */
332
+ public function _mwform_submit( $atts ) {
333
+ $form_field = new mw_form_field_submit( $this->Form, $atts, $this->viewFlg, $this->Error );
334
+ return $form_field->getField();
335
+ }
336
+
337
+ /**
338
+ * _mwform_previewButton
339
+ * 確認ボタンを出力。
340
+ * @example
341
+ * [mwform_previewButton value="確認画面へ"]
342
+ */
343
+ public function _mwform_previewButton( $atts ) {
344
+ $form_field = new mw_form_field_preview_button( $this->Form, $atts, $this->viewFlg, $this->Error );
345
+ return $form_field->getField();
346
+ }
347
+
348
+ /**
349
+ * _mwform_backButton
350
+ * 戻るボタンを出力。
351
+ * @example
352
+ * [mwform_backButton value="戻る"]
353
+ */
354
+ public function _mwform_backButton( $atts ) {
355
+ $form_field = new mw_form_field_back_button( $this->Form, $atts, $this->viewFlg, $this->Error );
356
+ return $form_field->getField();
357
+ }
358
+
359
+ /**
360
+ * _mwform_button
361
+ * ボタンを出力。
362
+ * @example
363
+ * [mwform_button name="hoge" value="hugaボタン"]
364
+ */
365
+ public function _mwform_button( $atts ) {
366
+ $form_field = new mw_form_field_button( $this->Form, $atts, $this->viewFlg, $this->Error );
367
+ return $form_field->getField();
368
+ }
369
+
370
+ /**
371
+ * _mwform_hidden
372
+ * hiddenフィールドを出力。
373
+ * @example
374
+ * [mwform_hidden name="hoge" value="fuga"]
375
+ */
376
+ public function _mwform_hidden( $atts ) {
377
+ $form_field = new mw_form_field_hidden( $this->Form, $atts, $this->viewFlg, $this->Error );
378
+ return $form_field->getField();
379
+ }
380
+
381
+ /**
382
+ * _mwform_password
383
+ * パスワードフィールドを出力。
384
+ * @example
385
+ * [mwform_password name="hoge" size="60" maxlength="255" value="" show_error=""]
386
+ */
387
+ public function _mwform_password( $atts ) {
388
+ $form_field = new mw_form_field_password( $this->Form, $atts, $this->viewFlg, $this->Error );
389
+ return $form_field->getField();
390
+ }
391
+
392
+ /**
393
+ * _mwform_zip
394
+ * 郵便番号フィールドを出力。確認画面からの送信時は-区切りに変換されるが、
395
+ * 入力画面からの送信時は配列で送信されるので注意
396
+ * @example
397
+ * [mwform_zip name="hoge" show_error=""]
398
+ */
399
+ public function _mwform_zip( $atts ) {
400
+ $form_field = new mw_form_field_zip( $this->Form, $atts, $this->viewFlg, $this->Error );
401
+ return $form_field->getField();
402
+ }
403
+
404
+ /**
405
+ * _mwform_tel
406
+ * 電話番号フィールドを出力。確認画面からの送信時は-区切りに返還されるが、
407
+ * 入力画面からの送信時は配列で送信されるので注意
408
+ * @example
409
+ * [mwform_tel name="hoge" show_error=""]
410
+ */
411
+ public function _mwform_tel( $atts ) {
412
+ $form_field = new mw_form_field_tel( $this->Form, $atts, $this->viewFlg, $this->Error );
413
+ return $form_field->getField();
414
+ }
415
+
416
+ /**
417
+ * _mwform_textarea
418
+ * テキストエリアを出力。
419
+ * @example
420
+ * [mwform_textarea name="hoge" cols="50" rows="5" value="" show_error=""]
421
+ */
422
+ public function _mwform_textarea( $atts ) {
423
+ $form_field = new mw_form_field_textarea( $this->Form, $atts, $this->viewFlg, $this->Error );
424
+ return $form_field->getField();
425
+ }
426
+
427
+ /**
428
+ * _mwform_select
429
+ * セレクトボックスを出力。
430
+ * @example
431
+ * [mwform_select name="hoge" children="日本,アメリカ,中国" value="初期値として選択状態にしたい値があれば指定" show_error=""]
432
+ */
433
+ public function _mwform_select( $atts ) {
434
+ $form_field = new mw_form_field_select( $this->Form, $atts, $this->viewFlg, $this->Error );
435
+ return $form_field->getField();
436
+ }
437
+
438
+ /**
439
+ * _mwform_radio
440
+ * ラジオボタンを出力。
441
+ * @example
442
+ * [mwform_radio name="hoge" children="日本,アメリカ,中国" value="初期値として選択状態にしたい値があれば指定" show_error=""]
443
+ */
444
+ public function _mwform_radio( $atts ) {
445
+ $form_field = new mw_form_field_radio( $this->Form, $atts, $this->viewFlg, $this->Error );
446
+ return $form_field->getField();
447
+ }
448
+
449
+ /**
450
+ * _mwform_checkbox
451
+ * チェックボックスを出力。
452
+ * @example
453
+ * [mwform_checkbox name="hoge" children="日本,アメリカ,中国" value="初期値として選択状態にしたい値があれば,区切りで指定" show_error=""]
454
+ */
455
+ public function _mwform_checkbox( $atts ) {
456
+ $form_field = new mw_form_field_checkbox( $this->Form, $atts, $this->viewFlg, $this->Error );
457
+ return $form_field->getField();
458
+ }
459
+
460
+ /**
461
+ * _mwform_datepicker
462
+ * datepickerを出力。
463
+ * @example
464
+ * [mwform_checkbox name="hoge" children="日本,アメリカ,中国" value="初期値として選択状態にしたい値があれば,区切りで指定" show_error=""]
465
+ */
466
+ public function _mwform_datepicker( $atts ) {
467
+ $form_field = new mw_form_field_datepicker( $this->Form, $atts, $this->viewFlg, $this->Error );
468
+ return $form_field->getField();
469
+ }
470
+ }
readme.txt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: Takashi Kitajima
3
+ Donate link:
4
+ Tags: plugin, form, confirm, preview
5
+ Requires at least: 3.4
6
+ Tested up to: 3.5
7
+ Stable tag: 0.5
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Plug-in which can create mail form using short code. E-mail sending and validation can be specified at functions.php.
12
+
13
+ == Description ==
14
+
15
+ Plug-in which can create mail form using short code. E-mail sending and validation can be specified at functions.php.
16
+ http://2inc.org/blog/category/products/wordpress_plugins/mw-wp-form/
17
+
18
+ == Installation ==
19
+
20
+ 1. Upload `MW WP Form` to the `/wp-content/plugins/` directory
21
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
22
+ 1. Place `<?php add_filter( 'mwform_validation_{$key}', array( $this, 'my_validation_filter_name' ) ); ?>` in your functions.php
23
+ 1. Place `<?php add_action( 'mwform_mail_{$key}', array( $this, 'my_mail_action_name' ) ); ?>` in your functions.php
24
+
25
+ == Changelog ==
26
+
27
+ = 0.5 =
28
+ * Initial release.
system/mw_error.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Error
4
+ * URI: http://2inc.org
5
+ * Description: エラークラス
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: July 17, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ class MW_Error {
28
+
29
+ private $errors = array();
30
+
31
+ /**
32
+ * setError
33
+ * エラーメッセージをセット
34
+ * @param String キー
35
+ * String メッセージ
36
+ */
37
+ public function setError( $key, $message ) {
38
+ if ( !is_string( $message ) ) exit( 'The Validate error message must be string!');
39
+ $this->errors[$key][] = $message;
40
+ }
41
+
42
+ /**
43
+ * getError
44
+ * エラーメッセージを返す
45
+ * @param String キー
46
+ * @return Array ( メッセージ, … )
47
+ */
48
+ public function getError( $key ) {
49
+ if ( isset( $this->errors[$key] ) ) {
50
+ return $this->errors[$key];
51
+ }
52
+ return array();
53
+ }
54
+
55
+ /**
56
+ * getErrors
57
+ * 全てのエラーメッセージを返す
58
+ * @return Array ( キー => ( メッセージ, … ), … )
59
+ */
60
+ public function getErrors() {
61
+ return $this->errors;
62
+ }
63
+ }
system/mw_form.php ADDED
@@ -0,0 +1,606 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form
4
+ * URI: http://2inc.org
5
+ * Description: フォームクラス
6
+ * Version: 1.2.6
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: September 25, 2012
10
+ * Modified: December 14, 2012
11
+ * License: GPL2
12
+ *
13
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
14
+ *
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License, version 2, as
17
+ * published by the Free Software Foundation.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+ class MW_Form {
29
+
30
+ protected $key = 'form_token'; // 識別子
31
+ public $tokenName = 'token'; // トークンタグ用のトークン名
32
+ protected $token; // トークンの値
33
+ protected $data; // データ
34
+ protected $Session; // sessionオブジェクト
35
+ protected $previewButton = 'submitPreview'; // 確認ボタンの名前
36
+ protected $backButton = 'submitBack'; // 戻るボタンの名前
37
+ protected $modeCheck = 'input';
38
+ protected $method = 'post';
39
+ private $ENCODE = 'utf-8';
40
+
41
+ /**
42
+ * __construct
43
+ * 取得データを保存、識別子とセッションIDののhash値をトークンとして利用
44
+ * @param Array リクエストデータ
45
+ * String 識別子
46
+ */
47
+ public function __construct( $data, $key = '' ) {
48
+ $this->data = $data;
49
+ if ( !empty( $key ) ) {
50
+ $this->key = $key.'_token';
51
+ }
52
+ $this->Session = MW_Session::start( $this->key );
53
+ $this->modeCheck = $this->modeCheck();
54
+ $this->token = sha1( $this->key . session_id() );
55
+ if ( $this->isInput() && empty( $_POST ) ) {
56
+ $this->Session->save( array( $this->tokenName => $this->token ) );
57
+ }
58
+ // 戻る、確認画面へのポスト、完了画面へのポストでないときはデータを破棄
59
+ if ( !( isset( $this->data[$this->backButton] ) || $this->isPreview() || $this->isComplete() ) ) {
60
+ // フォームオブジェクト再生成
61
+ $this->data = array();
62
+ }
63
+ }
64
+
65
+ /**
66
+ * clearToken
67
+ * トークン用のセッションを破棄
68
+ */
69
+ public function clearToken() {
70
+ $this->Session->clearValue( $this->tokenName );
71
+ }
72
+
73
+ /**
74
+ * isComplete
75
+ * 完了画面かどうか
76
+ * @return Boolean
77
+ */
78
+ public function isComplete() {
79
+ $_ret = false;
80
+ if ( !empty( $this->data ) && $this->modeCheck === 'complete' ) {
81
+ $_ret = true;
82
+ }
83
+ return $_ret;
84
+ }
85
+
86
+ /**
87
+ * isPreview
88
+ * 確認画面かどうか
89
+ * @return Boolean
90
+ */
91
+ public function isPreview() {
92
+ $_ret = false;
93
+ if ( !empty( $this->data ) && $this->modeCheck === 'preview' ) {
94
+ $_ret = true;
95
+ }
96
+ return $_ret;
97
+ }
98
+
99
+ /**
100
+ * isInput
101
+ * 入力画面かどうか
102
+ * @return Boolean
103
+ */
104
+ public function isInput() {
105
+ $_ret = false;
106
+ if ( $this->modeCheck === 'input' ) {
107
+ $_ret = true;
108
+ }
109
+ return $_ret;
110
+ }
111
+
112
+ /**
113
+ * modeCheck
114
+ * 表示画面判定
115
+ * @return input || preview || complete
116
+ */
117
+ protected function modeCheck() {
118
+ if ( isset( $this->data[$this->backButton] ) ) {
119
+ $backButton = $this->data[$this->backButton];
120
+ } elseif ( isset( $this->data[$this->previewButton] ) ) {
121
+ $previewButton = $this->data[$this->previewButton];
122
+ }
123
+ $_ret = 'input';
124
+ if ( isset( $backButton ) ) {
125
+ $_ret = 'input';
126
+ } elseif ( isset( $previewButton ) ) {
127
+ $_ret = 'preview';
128
+ } elseif ( !isset( $previewButton ) && !isset( $backButton ) && $this->check() ) {
129
+ $_ret = 'complete';
130
+ }
131
+ return $_ret;
132
+ }
133
+
134
+ /**
135
+ * check
136
+ * トークンチェック
137
+ * @return Boolean
138
+ */
139
+ protected function check() {
140
+ if ( isset( $_POST[$this->tokenName] ) ) $requestToken = $_POST[$this->tokenName];
141
+ $_ret = false;
142
+ $s_token = $this->Session->getValue( $this->tokenName );
143
+ if ( isset( $requestToken ) && !empty( $s_token ) && $requestToken == $s_token ) {
144
+ $_ret = true;
145
+ }
146
+ return $_ret;
147
+ }
148
+
149
+ /**
150
+ * getPreviewButtonName
151
+ * 確認画面への変遷用ボタンのname属性値を返す
152
+ * @return String name属性値
153
+ */
154
+ public function getPreviewButtonName() {
155
+ return $this->previewButton;
156
+ }
157
+
158
+ /**
159
+ * getBackButtonName
160
+ * 戻る用ボタンのname属性値を返す
161
+ * @return String
162
+ */
163
+ public function getBackButtonName() {
164
+ return $this->backButton;
165
+ }
166
+
167
+ /**
168
+ * getValue
169
+ * データを返す
170
+ * @param String キー
171
+ * @return Mixed データ
172
+ */
173
+ public function getValue( $key ) {
174
+ $_ret = null;
175
+ if ( isset( $this->data[$key] ) ) {
176
+ $_ret = $this->data[$key];
177
+ $_ret = $this->e( $_ret );
178
+ }
179
+ return $_ret;
180
+ }
181
+
182
+ /**
183
+ * getZipValue
184
+ * データを返す ( 郵便番号用 )
185
+ * @param String キー
186
+ * @return Mixed データ
187
+ */
188
+ public function getZipValue( $key ) {
189
+ $_ret = null;
190
+ $separator = $this->getSeparatorValue( $key );
191
+ // すべて空のからのときはimplodeしないように(---がいってしまうため)
192
+ if ( is_array( $this->data[$key]['data'] ) && array_key_exists( 'data', $this->data[$key] ) && !empty( $separator ) ) {
193
+ foreach ( $this->data[$key]['data'] as $val ) {
194
+ if ( !( $val === '' || $val === null ) ) {
195
+ $_ret = implode( $separator, $this->data[$key]['data'] );
196
+ $_ret = $this->e( $_ret );
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ return $_ret;
202
+ }
203
+
204
+ /**
205
+ * getTelValue
206
+ * データを返す ( 電話番号用 )
207
+ * @param String キー
208
+ * @return String データ
209
+ */
210
+ public function getTelValue( $key ) {
211
+ return $this->getZipValue( $key );
212
+ }
213
+
214
+ /**
215
+ * getCheckedValue
216
+ * データを返す( checkbox用 )。$dataに含まれる値のみ返す
217
+ * @param String キー
218
+ * Array データ
219
+ * @return String データ
220
+ */
221
+ public function getCheckedValue( $key, Array $data ) {
222
+ $_ret = null;
223
+ $separator = $this->getSeparatorValue( $key );
224
+ if ( is_array( $this->data[$key]['data'] ) && array_key_exists( 'data', $this->data[$key] ) && !empty( $separator ) ) {
225
+ foreach ( $this->data[$key]['data'] as $val ) {
226
+ if ( isset( $data[$val] ) ) {
227
+ $_ret = implode( $separator, $this->data[$key]['data'] );
228
+ $_ret = $this->e( $_ret );
229
+ break;
230
+ }
231
+ }
232
+ }
233
+ return $_ret;
234
+ }
235
+
236
+ /**
237
+ * getRadioValue
238
+ * データを返す( radio用 )。$dataに含まれる値のみ返す
239
+ * @param String キー
240
+ * Array データ
241
+ * @return String データ
242
+ */
243
+ public function getRadioValue( $key, Array $data ) {
244
+ $_ret = null;
245
+ if ( isset( $this->data[$key] ) && !is_array( $this->data[$key] ) ) {
246
+ if ( isset( $data[$this->data[$key]] ) ) {
247
+ $_ret = $data[$this->data[$key]];
248
+ $_ret = $this->e( $_ret );
249
+ }
250
+ }
251
+ return $_ret;
252
+ }
253
+
254
+ /**
255
+ * getSelectedValue
256
+ * データを返す( selectbox用 )。$dataに含まれる値のみ返す
257
+ * @param String キー
258
+ * Array データ
259
+ * @return String データ
260
+ */
261
+ public function getSelectedValue( $key, Array $data ) {
262
+ return $this->getRadioValue( $key, $data );
263
+ }
264
+
265
+ /**
266
+ * separator
267
+ * separatorを設定するためのhiddenを返す
268
+ * @param String キー
269
+ * String 区切り文字
270
+ * @return String HTML
271
+ */
272
+ public function separator( $key, $separator = '' ) {
273
+ if ( !$separator && $post_separator = $this->getSeparatorValue( $key ) )
274
+ $separator = $post_separator;
275
+ if ( $separator )
276
+ return $this->hidden( $key.'[separator]', $separator );
277
+ }
278
+
279
+ /**
280
+ * getSeparatorValue
281
+ * 送られてきたseparatorを返す
282
+ * @param String キー
283
+ * Array データ
284
+ * @return String データ
285
+ */
286
+ public function getSeparatorValue( $key ) {
287
+ if ( isset( $this->data[$key]['separator'] ) )
288
+ return $this->data[$key]['separator'];
289
+ }
290
+
291
+ /**
292
+ start
293
+ * フォームタグ生成
294
+ * @param Array ( 'action' =>, 'enctype' => )
295
+ * @return String form開始タグ
296
+ */
297
+ public function start( $options = array() ) {
298
+ $defaults = array(
299
+ 'action' => '',
300
+ 'enctype' => 'application/x-www-form-urlencoded',
301
+ );
302
+ $options = array_merge( $defaults, $options );
303
+ $_ret = sprintf( '<form method="%s" action="%s" enctype="%s">',
304
+ $this->method, $this->e( $options['action'] ), $this->e( $options['enctype'] ) );
305
+ return $_ret;
306
+ }
307
+
308
+ /**
309
+ * end
310
+ * トークンタグ、閉じタグ生成
311
+ * @return String input[type=hidden]
312
+ */
313
+ public function end() {
314
+ $_ret = '';
315
+ if ( $this->method == 'post' ) {
316
+ $_ret .= sprintf( '<input type="hidden" name="%s" value="%s" />', $this->tokenName, $this->token );
317
+ }
318
+ $_ret .= '</form>';
319
+ return $_ret;
320
+ }
321
+
322
+ /**
323
+ * text
324
+ * input[type=text]タグ生成
325
+ * @param String name属性
326
+ * Array ( 'size' =>, 'maxlength' =>, 'value' => )
327
+ * @return String htmlタグ
328
+ */
329
+ public function text( $name, $options = array() ) {
330
+ $defaults = array(
331
+ 'size' => 60,
332
+ 'maxlength' => 255,
333
+ 'value' => '',
334
+ );
335
+ $options = array_merge( $defaults, $options );
336
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
337
+ $_ret = sprintf( '<input type="text" name="%s" value="%s" size="%d" maxlength="%d" />',
338
+ $this->e( $name ), $this->e( $value ), $this->e( $options['size'] ), $this->e( $options['maxlength'] )
339
+ );
340
+ return $_ret;
341
+ }
342
+
343
+ /**
344
+ * hidden
345
+ * input[type=hidden]タグ生成
346
+ * @param String name属性
347
+ * String 値
348
+ * @return String htmlタグ
349
+ */
350
+ public function hidden( $name, $value ) {
351
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $value;
352
+ if ( is_array( $value ) )
353
+ $value = $this->getZipValue( $name );
354
+ $_ret = sprintf( '<input type="hidden" name="%s" value="%s" />', $this->e( $name ), $this->e( $value ) );
355
+ return $_ret;
356
+ }
357
+
358
+ /**
359
+ * password
360
+ * input[type=password]タグ生成
361
+ * @param String name属性
362
+ * Array ( 'size' =>, 'maxlength' =>, 'value' => )
363
+ * @return String htmlタグ
364
+ */
365
+ public function password( $name, $options = array() ) {
366
+ $defaults = array(
367
+ 'size' => 60,
368
+ 'maxlength' => 255,
369
+ 'value' => '',
370
+ );
371
+ $options = array_merge( $defaults, $options );
372
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
373
+ $_ret = sprintf( '<input type="password" name="%s" value="%s" size="%d" maxlength="%d" />',
374
+ $this->e( $name ), $this->e( $value ), $this->e( $options['size'] ), $this->e( $options['maxlength'] )
375
+ );
376
+ return $_ret;
377
+ }
378
+
379
+ /**
380
+ * zip
381
+ * 郵便番号フィールド生成
382
+ * @param String name属性
383
+ * @return String htmlタグ
384
+ */
385
+ public function zip( $name ) {
386
+ $separator = '-';
387
+ if ( isset( $this->data[$name]['data'] ) ) {
388
+ if ( is_array( $this->data[$name]['data'] ) ) {
389
+ $value = $this->data[$name]['data'];
390
+ } else {
391
+ $value = explode( $separator, $this->data[$name]['data'] );
392
+ }
393
+ }
394
+ $value0 = ( isset( $value[0] ) )? $value[0] : '';
395
+ $value1 = ( isset( $value[1] ) )? $value[1] : '';
396
+ $_ret = '〒';
397
+ $_ret .= $this->text( $name.'[data][0]', array( 'size' => 4, 'maxlength' => 3, 'value' => $value0 ) );
398
+ $_ret .= ' '.$separator.' ';
399
+ $_ret .= $this->text( $name.'[data][1]', array( 'size' => 5, 'maxlength' => 4, 'value' => $value1 ) );
400
+ $_ret .= $this->separator( $name, $separator );
401
+ return $_ret;
402
+ }
403
+
404
+ /**
405
+ * tel
406
+ * 電話番号フィールド生成
407
+ * @param String name属性
408
+ * @return String htmlタグ
409
+ */
410
+ public function tel( $name ) {
411
+ $separator = '-';
412
+ if ( isset( $this->data[$name]['data'] ) ) {
413
+ if ( is_array( $this->data[$name]['data'] ) ) {
414
+ $value = $this->data[$name]['data'];
415
+ } else {
416
+ $value = explode( $separator, $this->data[$name]['data'] );
417
+ }
418
+ }
419
+ $value0 = ( isset( $value[0] ) )? $value[0] : '';
420
+ $value1 = ( isset( $value[1] ) )? $value[1] : '';
421
+ $value2 = ( isset( $value[2] ) )? $value[2] : '';
422
+ $_ret = '';
423
+ $_ret .= $this->text( $name.'[data][0]', array( 'size' => 5, 'maxlength' => 4, 'value' => $value0 ) );
424
+ $_ret .= ' '.$separator.' ';
425
+ $_ret .= $this->text( $name.'[data][1]', array( 'size' => 5, 'maxlength' => 4, 'value' => $value1 ) );
426
+ $_ret .= ' '.$separator.' ';
427
+ $_ret .= $this->text( $name.'[data][2]', array( 'size' => 5, 'maxlength' => 4, 'value' => $value2 ) );
428
+ $_ret .= $this->separator( $name, $separator );
429
+ return $_ret;
430
+ }
431
+
432
+ /**
433
+ * textarea
434
+ * textareaタグ生成
435
+ * @param String name属性
436
+ * Array ( 'cols' =>, 'rows' =>, 'value' => )
437
+ * @return String htmlタグ
438
+ */
439
+ public function textarea( $name, $options = array() ) {
440
+ $defaults = array(
441
+ 'cols' => 50,
442
+ 'rows' => 5,
443
+ 'value' => ''
444
+ );
445
+ $options = array_merge( $defaults, $options );
446
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
447
+ $_ret = sprintf( '<textarea name="%s" cols="%d" rows="%d">%s</textarea>',
448
+ $this->e( $name ), $this->e( $options['cols'] ), $this->e( $options['rows'] ), $this->e( $value )
449
+ );
450
+ return $_ret;
451
+ }
452
+
453
+ /**
454
+ * select
455
+ * selectタグ生成
456
+ * @param String name属性
457
+ * Array ( キー => 値, … )
458
+ * Array ( 'value' => )
459
+ * @return String htmlタグ
460
+ */
461
+ public function select( $name, $children = array(), $options = array() ) {
462
+ $defaults = array(
463
+ 'value' => ''
464
+ );
465
+ $options = array_merge( $defaults, $options );
466
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
467
+ $_ret = sprintf( '<select name="%s">', $this->e( $name ) );
468
+ foreach ( $children as $key => $val ) {
469
+ $selected = ( $key == $value )? ' selected="selected"' : '';
470
+ $_ret .= sprintf( '<option value="%s"%s>%s</option>',
471
+ $this->e( $key ), $selected, $this->e( $val )
472
+ );
473
+ }
474
+ $_ret .= '</select>';
475
+ return $_ret;
476
+ }
477
+
478
+ /**
479
+ * radio
480
+ * radioタグ生成
481
+ * @param String name属性
482
+ * Array ( キー => 値, … )
483
+ * Array ( 'value' => )
484
+ * @return String htmlタグ
485
+ */
486
+ public function radio( $name, $children = array(), $options = array() ) {
487
+ $defaults = array(
488
+ 'value' => ''
489
+ );
490
+ $options = array_merge( $defaults, $options );
491
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
492
+ $_ret = '';
493
+ foreach ( $children as $key => $val ) {
494
+ $checked = ( $key == $value )? ' checked="checked"' : '';
495
+ $_ret .= sprintf( '<label><input type="radio" name="%s" value="%s"%s />%s</label>',
496
+ $this->e( $name ), $this->e( $key ), $checked, $this->e( $val )
497
+ );
498
+ }
499
+ return $_ret;
500
+ }
501
+
502
+ /**
503
+ * checkbox
504
+ * checkboxタグ生成
505
+ * @param String name属性
506
+ * Array ( キー => 値, … )
507
+ * Array ( 'value' => Mixed )
508
+ * @return String htmlタグ
509
+ */
510
+ public function checkbox( $name, $children = array(), $options = array() ) {
511
+ $separator = ',';
512
+ $defaults = array(
513
+ 'value' => array()
514
+ );
515
+ $options = array_merge( $defaults, $options );
516
+
517
+ $value = $options['value'];
518
+ if ( isset( $this->data[$name]['data'] ) ) {
519
+ $value = $this->data[$name]['data'];
520
+ }
521
+ if ( !is_array( $value ) ) {
522
+ $value = explode( $separator, $value );
523
+ }
524
+ $_ret = '';
525
+ foreach ( $children as $key => $val ) {
526
+ $checked = ( is_array( $value ) && in_array( $key, $value ) )? ' checked="checked"' : '';
527
+ $_ret .= sprintf( '<label><input type="checkbox" name="%s" value="%s"%s />%s</label>',
528
+ $this->e( $name.'[data][]' ), $this->e( $key ), $checked, $this->e( $val )
529
+ );
530
+ }
531
+ $_ret .= $this->separator( $name, $separator );
532
+ return $_ret;
533
+ }
534
+
535
+ /**
536
+ * submit
537
+ * submitボタン生成
538
+ * @param String name属性
539
+ * String value属性
540
+ * @return String submitボタン
541
+ */
542
+ public function submit( $name, $value ) {
543
+ $_ret = sprintf( '<input type="submit" name="%s" value="%s" />', $this->e( $name ), $this->e( $value ) );
544
+ return $_ret;
545
+ }
546
+
547
+ /**
548
+ * button
549
+ * ボタン生成
550
+ * @param String name属性
551
+ * String value属性
552
+ * @return String ボタン
553
+ */
554
+ public function button( $name, $value ) {
555
+ $_ret = sprintf( '<input type="button" name="%s" value="%s" />', $this->e( $name ), $this->e( $value ) );
556
+ return $_ret;
557
+ }
558
+
559
+ /**
560
+ * datepicker
561
+ * datepicker生成
562
+ * @param String name属性
563
+ * String size属性
564
+ * String value属性
565
+ String js datepickerの引数
566
+ * @return String ボタン
567
+ */
568
+ public function datepicker( $name, $options = array() ) {
569
+ $defaults = array(
570
+ 'size' => 30,
571
+ 'js' => '',
572
+ 'value' => '',
573
+ );
574
+ $options = array_merge( $defaults, $options );
575
+ $value = ( isset( $this->data[$name] ) )? $this->data[$name] : $options['value'];
576
+ $_ret = sprintf( '<input type="text" name="%s" value="%s" size="%d" />',
577
+ $this->e( $name ), $this->e( $value ), $this->e( $options['size'] )
578
+ );
579
+ $_ret .= sprintf( '
580
+ <script type="text/javascript">
581
+ jQuery( function( $ ) {
582
+ $("input[name=\'%s\']").datepicker({%s});
583
+ } );
584
+ </script>
585
+ ',$this->e( $name ), $options['js'] );
586
+ return $_ret;
587
+ }
588
+
589
+ /**
590
+ * e
591
+ * htmlサニタイズ
592
+ * @param Mixed
593
+ * @return Mixed
594
+ */
595
+ public function e( $str ){
596
+ if ( is_null( $str ) ) {
597
+ return null;
598
+ } elseif ( is_array( $str ) ) {
599
+ return array_map( array( $this, 'e' ), $str );
600
+ } else {
601
+ $str = stripslashes( $str );
602
+ return htmlspecialchars( $str, ENT_QUOTES, $this->ENCODE );
603
+ }
604
+ }
605
+ }
606
+ ?>
system/mw_form_field.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Form Field
4
+ * URI: http://2inc.org
5
+ * Description: フォームフィールドの抽象クラス
6
+ * Version: 1.0
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: December 14, 2012
10
+ * License: GPL2
11
+ *
12
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
13
+ *
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License, version 2, as
16
+ * published by the Free Software Foundation.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
+ */
27
+ abstract class mw_form_field {
28
+
29
+ /**
30
+ * Form $Form
31
+ */
32
+ const DOMAIN = 'mw-wp-form';
33
+
34
+ /**
35
+ * Form $Form
36
+ */
37
+ protected $Form;
38
+
39
+ /**
40
+ * Array $defaults 属性値等初期値
41
+ */
42
+ protected $defaults;
43
+
44
+ /**
45
+ * Array $atts 属性値等
46
+ */
47
+ protected $atts;
48
+
49
+ /**
50
+ * String $viewFlg 表示ページ種別( input, preview )
51
+ */
52
+ protected $viewFlg;
53
+
54
+ /**
55
+ * Error $Error エラーオブジェクト
56
+ */
57
+ protected $Error;
58
+
59
+ /**
60
+ * __construct
61
+ * @param mw_form $Form
62
+ * Array $atts 属性値等
63
+ * String $viewFlg 表示ページ種別( input, preview )
64
+ */
65
+ public function __construct( mw_form $Form, $atts, $viewFlg, $Error ) {
66
+ $this->Form = $Form;
67
+ $this->defaults = $this->setDefaults();
68
+ $this->atts = shortcode_atts( $this->defaults, $atts );
69
+ $this->viewFlg = $viewFlg;
70
+ $this->Error = $Error;
71
+ }
72
+
73
+ /**
74
+ * getField
75
+ * フォーム項目を返す
76
+ * @return String HTML
77
+ */
78
+ public function getField() {
79
+ switch( $this->viewFlg ) {
80
+ case 'input' :
81
+ return $this->inputPage();
82
+ break;
83
+ case 'preview' :
84
+ return $this->previewPage();
85
+ break;
86
+ default :
87
+ exit( '$viewFlg is not right value.' );
88
+ }
89
+ }
90
+
91
+ /**
92
+ * getError
93
+ * @param String フォーム項目名
94
+ * @return String エラーHTML
95
+ */
96
+ protected function getError( $key ) {
97
+ $_ret = '';
98
+ if ( is_array( $this->Error->getError( $key ) ) ) {
99
+ foreach ( $this->Error->getError( $key ) as $error ) {
100
+ $_ret .= sprintf( '<span class="error">%s</span>', htmlspecialchars( $error, ENT_QUOTES ) );
101
+ }
102
+ }
103
+ return $_ret;
104
+ }
105
+
106
+ /**
107
+ * setDefaults
108
+ * $this->defaultsを設定し返す
109
+ * @return Array defaults
110
+ */
111
+ abstract protected function setDefaults();
112
+
113
+ /**
114
+ * inputPage
115
+ * 入力ページでのフォーム項目を返す
116
+ * @return String HTML
117
+ */
118
+ abstract protected function inputPage();
119
+
120
+ /**
121
+ * previewPage
122
+ * 確認ページでのフォーム項目を返す
123
+ * @return String HTML
124
+ */
125
+ abstract protected function previewPage();
126
+
127
+ /**
128
+ * getChildren
129
+ * 選択肢の配列を返す
130
+ * @return Array $children
131
+ */
132
+ protected function getChildren() {
133
+ $children = array();
134
+ if ( !is_array( $this->atts['children'] ) )
135
+ $_children = explode( ',', $this->atts['children'] );
136
+ foreach ( $_children as $child ) {
137
+ $children[$child] = $child;
138
+ }
139
+ return $children;
140
+ }
141
+ }
system/mw_mail.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Mail
4
+ * URI: http://2inc.org
5
+ * Description: メールクラス
6
+ * Version: 1.2.1
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: July 20, 2012
10
+ * Modified: December 14, 2012
11
+ * License: GPL2
12
+ *
13
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
14
+ *
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License, version 2, as
17
+ * published by the Free Software Foundation.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+ class MW_Mail {
29
+
30
+ public $to; // 宛先
31
+ public $from; // 送信元
32
+ public $sender; // 送信者
33
+ public $subject; // 題名
34
+ public $body; // 本文
35
+ // private $targetEncodeing = 'ISO-2022-JP';
36
+ private $ENCODE = 'utf-8';
37
+
38
+ /**
39
+ * send
40
+ * メール送信
41
+ */
42
+ public function send() {
43
+ if ( !$this->to ) return;
44
+ /*
45
+ mb_language( 'ja' );
46
+ mb_internal_encoding( $this->ENCODE );
47
+ $subject = mb_encode_mimeheader( $this->subject );
48
+ $body = base64_encode( $this->body );
49
+ $body = mb_convert_encoding( $this->body, $this->targetEncodeing, $this->ENCODE );
50
+ */
51
+ $subject = $this->subject;
52
+ $body = $this->body;
53
+
54
+ $fromHeader = '';
55
+ if ( !empty( $this->from ) ) {
56
+ if ( empty( $this->sender ) ) {
57
+ $fromHeader = $this->from;
58
+ } else if ( !empty( $this->sender ) ) {
59
+ // $sender = mb_encode_mimeheader( $this->sender );
60
+ $sender = $this->sender;
61
+ $fromHeader = $sender.' <'.$this->from.'>';
62
+ }
63
+ }
64
+
65
+ $header = '';
66
+ /*
67
+ $header .= "Content-Type: text/plain;charset=".$this->targetEncodeing."\n";
68
+ $header .= "Content-Transfer-Encoding: 7bit\n";
69
+ $header .= "MIME-Version: 1.0\n";
70
+ $header .= "X-Mailer:PHP\n";
71
+ */
72
+ $header .= "From:" . $fromHeader . "\n";
73
+ wp_mail( $this->to, $subject, $body, $header );
74
+ // mail( $this->to, $subject, $body, $header );
75
+ }
76
+
77
+ /**
78
+ * createBody
79
+ * 配列からbodyを生成
80
+ * @param Array ( 見出し => 内容, … )
81
+ * Array ( 'exclude' => array( 除外したいキー1, … ) )
82
+ */
83
+ public function createBody( Array $array, Array $options = array() ) {
84
+ $_ret = '';
85
+ $defaults = array(
86
+ 'exclude' => array()
87
+ );
88
+ $options = array_merge( $defaults, $options );
89
+ foreach( $array as $key => $val ) {
90
+ if ( in_array( $key, $options['exclude'] ) ) continue;
91
+ if ( is_array( $val ) && array_key_exists( 'data', $val ) && array_key_exists( 'separator', $val ) ) {
92
+ if ( is_array( $val['data'] ) ) {
93
+ foreach ( $val['data'] as $_val ) {
94
+ if ( !( $_val === '' || $_val === null ) ) {
95
+ $val = implode( $val['separator'], $val['data'] );
96
+ break;
97
+ }
98
+ $val = '';
99
+ }
100
+ } else {
101
+ $val = $val['data'];
102
+ }
103
+ }
104
+ $_ret .= sprintf( "▼%s\n%s\n\n", $this->e( $key ), $this->e( $val ) );
105
+ }
106
+ return $_ret;
107
+ }
108
+
109
+ /**
110
+ * e
111
+ * htmlサニタイズ
112
+ * @param Mixed
113
+ * @return Mixed
114
+ */
115
+ public function e( $str ){
116
+ if ( is_array( $str ) ) {
117
+ return array_map( array( $this, 'e' ), $str );
118
+ } else {
119
+ $str = stripslashes( $str );
120
+ return htmlspecialchars( $str, ENT_QUOTES, $this->ENCODE );
121
+ }
122
+ }
123
+ }
124
+ ?>
system/mw_session.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Session
4
+ * URI: http://2inc.org
5
+ * Description: セッションクラス
6
+ * Version: 1.1
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: July 17, 2012
10
+ * Modified: August 29, 2012
11
+ * License: GPL2
12
+ *
13
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
14
+ *
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License, version 2, as
17
+ * published by the Free Software Foundation.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+ class MW_Session {
29
+
30
+ private static $session; // セッションフラグ
31
+ private static $sessionName = 'nw_session'; // セッション名
32
+ private $name; // 擬似セッション名
33
+
34
+ private function __construct( $name ) {
35
+ $this->setSessionName( $name );
36
+ }
37
+
38
+ /**
39
+ * start
40
+ * インスタンス化
41
+ * @param String 擬似セッション名
42
+ * @return Session Sessionオブジェクト
43
+ */
44
+ public static function start( $name ) {
45
+ if ( self::$session == null ){
46
+ session_name( self::$sessionName );
47
+ session_set_cookie_params( 0, '/' );
48
+ session_start();
49
+ self::$session = 1;
50
+ }
51
+ $Session = new MW_Session( $name );
52
+ return $Session;
53
+ }
54
+
55
+ /**
56
+ * setSessionName
57
+ * 疑似セッション名を設定
58
+ * @param String 擬似セッション名
59
+ */
60
+ private function setSessionName( $name ) {
61
+ $this->name = $name;
62
+ }
63
+
64
+ /**
65
+ * save
66
+ * セッション変数にセット
67
+ * @param Array ( キー => 値, … )
68
+ */
69
+ public function save( Array $data ) {
70
+ foreach ( $data as $key => $val ) {
71
+ $_SESSION[$this->name][$key] = $val;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * getValue
77
+ * セッション変数から取得
78
+ * @param String キー
79
+ * @return Mixed セッション値
80
+ */
81
+ public function getValue( $key ) {
82
+ $_ret = null;
83
+ if ( isset( $_SESSION[$this->name][$key] ) ) {
84
+ $_ret = $_SESSION[$this->name][$key];
85
+ }
86
+ return $_ret;
87
+ }
88
+
89
+ /**
90
+ * getValues
91
+ * セッション変数から取得
92
+ * @param Array ( キー => 値, … )
93
+ */
94
+ public function getValues() {
95
+ $_ret = array();
96
+ if ( isset( $_SESSION[$this->name] ) ) {
97
+ $_ret = $_SESSION[$this->name];
98
+ }
99
+ return $_ret;
100
+ }
101
+
102
+ /**
103
+ * clearValue
104
+ * セッション変数を空に
105
+ * @param String キー
106
+ */
107
+ public function clearValue( $key ) {
108
+ if ( isset( $_SESSION[$this->name][$key] ) ) {
109
+ unset( $_SESSION[$this->name][$key] );
110
+ }
111
+ }
112
+
113
+ /**
114
+ * clearValues
115
+ * セッション変数を空に
116
+ */
117
+ public function clearValues() {
118
+ if ( isset( $_SESSION[$this->name] ) ) {
119
+ unset( $_SESSION[$this->name] );
120
+ }
121
+ }
122
+
123
+ /**
124
+ * destroy
125
+ * $_SESSIONを破壊
126
+ */
127
+ public function destroy(){
128
+ $_SESSION = array();
129
+ if ( isset( $_COOKIE[ session_name() ] ) ) {
130
+ setcookie( session_name(), '', time()-42000, '/' );
131
+ }
132
+ session_destroy();
133
+ }
134
+
135
+ /**
136
+ * session_regenerate_id
137
+ * 現在のセッションIDを新しく生成したものと置き換える
138
+ */
139
+ public function session_regenerate_id(){
140
+ session_regenerate_id( TRUE );
141
+ }
142
+ }
system/mw_validation.php ADDED
@@ -0,0 +1,489 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Name: MW Validation
4
+ * URI: http://2inc.org
5
+ * Description: バリデーションクラス
6
+ * Version: 1.2.1
7
+ * Author: Takashi Kitajima
8
+ * Author URI: http://2inc.org
9
+ * Created: July 20, 2012
10
+ * Modified: December 14, 2012
11
+ * License: GPL2
12
+ *
13
+ * Copyright 2012 Takashi Kitajima (email : inc@2inc.org)
14
+ *
15
+ * This program is free software; you can redistribute it and/or modify
16
+ * it under the terms of the GNU General Public License, version 2, as
17
+ * published by the Free Software Foundation.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+ class MW_Validation {
29
+
30
+ const DOMAIN = 'mw-wp-form';
31
+ protected $data = array();
32
+ protected $Error;
33
+ public $validate = array();
34
+ private $ENCODE = 'utf-8';
35
+
36
+ /**
37
+ * __construct
38
+ * @param Array リクエストデータ
39
+ */
40
+ public function __construct( Array $data = array() ) {
41
+ $this->data = $data;
42
+ // エラーオブジェクトを設定
43
+ $this->Error = new MW_Error();
44
+ }
45
+
46
+ private function getValue( $key ) {
47
+ $value = null;
48
+ if ( ! isset( $this->data[$key] ) ) return $value;
49
+ if ( is_array( $this->data[$key] ) ) {
50
+ if ( array_key_exists( 'data', $this->data[$key] ) ) {
51
+ if ( is_array( $this->data[$key]['data'] ) ) {
52
+ $value = $this->array_clean( $this->data[$key]['data'] );
53
+ } else {
54
+ $value = $this->data[$key]['data'];
55
+ }
56
+ }
57
+ } else {
58
+ $value = $this->data[$key];
59
+ }
60
+ return $value;
61
+ }
62
+
63
+ /**
64
+ * required
65
+ * 値が存在する
66
+ * @param String キー
67
+ * Array ( 'message' => )
68
+ * @return String エラーメッセージ
69
+ */
70
+ public function required( $key, $options = array() ) {
71
+ $_ret = '';
72
+ $value = $this->getValue( $key );
73
+ if ( !isset( $value ) ) {
74
+ $defaults = array(
75
+ 'message' => __( 'This is required.', self::DOMAIN )
76
+ );
77
+ $options = array_merge( $defaults, $options );
78
+ $_ret = $options['message'];
79
+ }
80
+ return $_ret;
81
+ }
82
+
83
+ /**
84
+ * noEmpty
85
+ * 値が空ではない(0は許可)
86
+ * @param String キー
87
+ * Array ( 'message' => )
88
+ * @return String エラーメッセージ
89
+ */
90
+ public function noEmpty( $key, $options = array() ) {
91
+ $_ret = '';
92
+ $value = $this->getValue( $key );
93
+ if ( isset( $value ) ) {
94
+ $defaults = array(
95
+ 'message' => __( 'Please enter.', self::DOMAIN )
96
+ );
97
+ $options = array_merge( $defaults, $options );
98
+ if ( $value == array() || $value === '' || $value === null ) {
99
+ $_ret = $options['message'];
100
+ }
101
+ }
102
+ return $_ret;
103
+ }
104
+
105
+ /**
106
+ * noFalse
107
+ * 値が空ではない(0も不可)
108
+ * @param String キー
109
+ * Array ( 'message' => )
110
+ * @return String エラーメッセージ
111
+ */
112
+ public function noFalse( $key, $options = array() ) {
113
+ $_ret = '';
114
+ $value = $this->getValue( $key );
115
+ if ( isset( $value ) ) {
116
+ $defaults = array(
117
+ 'message' => __( 'Please enter.', self::DOMAIN )
118
+ );
119
+ $options = array_merge( $defaults, $options );
120
+ if ( empty( $value ) ) {
121
+ $_ret = $options['message'];
122
+ }
123
+ }
124
+ return $_ret;
125
+ }
126
+
127
+ /**
128
+ * alpha
129
+ * 値がアルファベット
130
+ * @param String キー
131
+ * Array ( 'message' => )
132
+ * @return String エラーメッセージ
133
+ */
134
+ public function alpha( $key, $options = array() ) {
135
+ $_ret = '';
136
+ $value = $this->getValue( $key );
137
+ if ( isset( $value ) ) {
138
+ $defaults = array(
139
+ 'message' => __( 'Please enter with a half-width alphabetic character.', self::DOMAIN )
140
+ );
141
+ $options = array_merge( $defaults, $options );
142
+ if ( !preg_match( '/^[A-Za-z]+$/', $value ) ) {
143
+ $_ret = $options['message'];
144
+ }
145
+ }
146
+ return $_ret;
147
+ }
148
+
149
+ /**
150
+ * numeric
151
+ * 値が数値
152
+ * @param String キー
153
+ * Array ( 'message' => )
154
+ * @return String エラーメッセージ
155
+ */
156
+ public function numeric( $key, $options = array() ) {
157
+ $_ret = '';
158
+ $value = $this->getValue( $key );
159
+ if ( isset( $value ) ) {
160
+ $defaults = array(
161
+ 'message' => __( 'Please enter with a half-width number.', self::DOMAIN )
162
+ );
163
+ $options = array_merge( $defaults, $options );
164
+ if ( !preg_match( '/^[0-9]+$/', $value ) ) {
165
+ $_ret = $options['message'];
166
+ }
167
+ }
168
+ return $_ret;
169
+ }
170
+
171
+ /**
172
+ * alphaNumeric
173
+ * 値が英数値
174
+ * @param String キー
175
+ * Array ( 'message' => )
176
+ * @return String エラーメッセージ
177
+ */
178
+ public function alphaNumeric( $key, $options = array() ) {
179
+ $_ret = '';
180
+ $value = $this->getValue( $key );
181
+ if ( isset( $value ) ) {
182
+ $defaults = array(
183
+ 'message' => __( 'Please enter with a half-width alphanumeric character.', self::DOMAIN )
184
+ );
185
+ $options = array_merge( $defaults, $options );
186
+ if ( !preg_match( '/^[0-9A-Za-z]+$/', $value ) ) {
187
+ $_ret = $options['message'];
188
+ }
189
+ }
190
+ return $_ret;
191
+ }
192
+
193
+ /**
194
+ * zip
195
+ * 値が郵便番号
196
+ * @param String キー
197
+ * Array ( 'message' => )
198
+ * @return String エラーメッセージ
199
+ */
200
+ public function zip( $key, $options = array() ) {
201
+ $_ret = '';
202
+ $value = $this->getValue( $key );
203
+ if ( isset( $value ) ) {
204
+ $defaults = array(
205
+ 'message' => __( 'This is not the format of a zip code.', self::DOMAIN )
206
+ );
207
+ $options = array_merge( $defaults, $options );
208
+ if ( !empty( $value ) ) {
209
+ if ( is_array( $value ) ) {
210
+ $value = implode( '-', $value );
211
+ }
212
+ if ( !preg_match( '/^\d{3}-\d{4}$/', $value ) ) {
213
+ $_ret = $options['message'];
214
+ }
215
+ }
216
+ }
217
+ return $_ret;
218
+ }
219
+
220
+ /**
221
+ * tel
222
+ * 値が電話番号
223
+ * @param String キー
224
+ * Array ( 'message' => )
225
+ * @return String エラーメッセージ
226
+ */
227
+ public function tel( $key, $options = array() ) {
228
+ $_ret = '';
229
+ $value = $this->getValue( $key );
230
+ if ( isset( $value ) ) {
231
+ $defaults = array(
232
+ 'message' => __( 'This is not the format of a tel number.', self::DOMAIN )
233
+ );
234
+ $options = array_merge( $defaults, $options );
235
+ if ( !empty( $value ) ) {
236
+ if ( is_array( $value ) ) {
237
+ $value = implode( '-', $value );
238
+ }
239
+ if ( !preg_match( '/^\d{2,4}-\d{2,4}-\d{4}$/', $value ) ) {
240
+ $_ret = $options['message'];
241
+ }
242
+ }
243
+ }
244
+ return $_ret;
245
+ }
246
+
247
+ /**
248
+ * mail
249
+ * 値がメールアドレス
250
+ * @param String キー
251
+ * Array ( 'message' => )
252
+ * @return String エラーメッセージ
253
+ */
254
+ public function mail( $key, $options = array() ) {
255
+ $_ret = '';
256
+ $value = $this->getValue( $key );
257
+ if ( isset( $value ) ) {
258
+ $defaults = array(
259
+ 'message' => __( 'This is not the format of a mail address.', self::DOMAIN )
260
+ );
261
+ $options = array_merge( $defaults, $options );
262
+ if ( !preg_match( '/^.+@.+$/', $value ) ) {
263
+ $_ret = $options['message'];
264
+ }
265
+ }
266
+ return $_ret;
267
+ }
268
+
269
+ /**
270
+ * url
271
+ * 値がURL
272
+ * @param String キー
273
+ * Array ( 'message' => )
274
+ * @return String エラーメッセージ
275
+ */
276
+ public function url( $key, $options = array() ) {
277
+ $_ret = '';
278
+ $value = $this->getValue( $key );
279
+ if ( isset( $value ) ) {
280
+ $defaults = array(
281
+ 'message' => __( 'This is not the format of a url.', self::DOMAIN )
282
+ );
283
+ $options = array_merge( $defaults, $options );
284
+ if ( !preg_match( '/^https{0,1}:\/\//', $value ) ) {
285
+ $_ret = $options['message'];
286
+ }
287
+ }
288
+ return $_ret;
289
+ }
290
+
291
+ /**
292
+ * eq
293
+ * 値が一致している
294
+ * @param String キー
295
+ * Array ( 'target' =>, 'message' => )
296
+ * @return String エラーメッセージ
297
+ */
298
+ public function eq( $key, $options = array() ) {
299
+ $_ret = '';
300
+ $value = $this->getValue( $key );
301
+ if ( isset( $value ) ) {
302
+ $defaults = array(
303
+ 'target' => null,
304
+ 'message' => __( 'This is not in agreement.', self::DOMAIN )
305
+ );
306
+ $options = array_merge( $defaults, $options );
307
+ if ( !( isset( $this->data[$options['target']] ) && $value == $this->data[$options['target']] ) ) {
308
+ $_ret = $options['message'];
309
+ }
310
+ }
311
+ return $_ret;
312
+ }
313
+
314
+ /**
315
+ * between
316
+ * 値の文字数が範囲内
317
+ * @param String キー
318
+ * Array ( 'min' =>, 'max' =>, 'message' => )
319
+ * @return String エラーメッセージ
320
+ */
321
+ public function between( $key, $options = array() ) {
322
+ $_ret = '';
323
+ $value = $this->getValue( $key );
324
+ if ( isset( $value ) ) {
325
+ $defaults = array(
326
+ 'min' => 0,
327
+ 'max' => 0,
328
+ 'message' => __( 'The number of characters is invalid.', self::DOMAIN )
329
+ );
330
+ $options = array_merge( $defaults, $options );
331
+ $length = mb_strlen( $value, $this->ENCODE );
332
+ if ( preg_match( '/^\d+$/', $options['min'] ) && preg_match( '/^\d+$/', $options['max'] ) && !( $options['min'] <= $length && $length <= $options['max'] ) ) {
333
+ $_ret = $options['message'];
334
+ }
335
+ }
336
+ return $_ret;
337
+ }
338
+
339
+ /**
340
+ * minLength
341
+ * 値の文字数が範囲内
342
+ * @param String キー
343
+ * Array ( 'min' =>, 'message' => )
344
+ * @return String エラーメッセージ
345
+ */
346
+ public function minLength( $key, $options = array() ) {
347
+ $_ret = '';
348
+ $value = $this->getValue( $key );
349
+ if ( isset( $value ) ) {
350
+ $defaults = array(
351
+ 'min' => 0,
352
+ 'message' => __( 'The number of characters is a few.', self::DOMAIN )
353
+ );
354
+ $options = array_merge( $defaults, $options );
355
+ $length = mb_strlen( $value, $this->ENCODE );
356
+ if ( preg_match( '/^\d+$/', $options['min'] ) && $options['min'] > $length ) {
357
+ $_ret = $options['message'];
358
+ }
359
+ }
360
+ return $_ret;
361
+ }
362
+
363
+ /**
364
+ * in
365
+ * 値が、配列で指定された中に含まれている
366
+ * @param String キー
367
+ * Array ( 'options' =>, 'message' => )
368
+ * @return String エラーメッセージ
369
+ */
370
+ public function in( $key, $options = array() ) {
371
+ $_ret = '';
372
+ $value = $this->getValue( $key );
373
+ if ( isset( $value ) ) {
374
+ $defaults = array(
375
+ 'options' => array(),
376
+ 'message' => __( 'This value is invalid.', self::DOMAIN )
377
+ );
378
+ $options = array_merge( $defaults, $options );
379
+ if ( !( isset( $options[ 'options' ] ) && is_array( $options[ 'options' ] ) ) ) {
380
+ $_ret = $options['message'];
381
+ }
382
+ }
383
+ return $_ret;
384
+ }
385
+
386
+ /**
387
+ * date
388
+ * 日付が正しいかどうか
389
+ * @param String キー
390
+ * Array ( 'options' =>, 'message' => )
391
+ * @return String エラーメッセージ
392
+ */
393
+ public function date( $key, $options = array() ) {
394
+ $_ret = '';
395
+ $value = $this->getValue( $key );
396
+ if ( isset( $value ) ) {
397
+ $defaults = array(
398
+ 'message' => __( 'This is not the format of a date.', self::DOMAIN )
399
+ );
400
+ $options = array_merge( $defaults, $options );
401
+ $timestamp = strtotime( $value );
402
+ $year = date( 'Y', $timestamp );
403
+ $month = date( 'm', $timestamp );
404
+ $day = date( 'd', $timestamp );
405
+ $checkdate = checkdate( $month, $day, $year );
406
+ if ( !empty( $value ) && ( !$timestamp || !$checkdate ) ) {
407
+ $_ret = $options['message'];
408
+ }
409
+ }
410
+ return $_ret;
411
+ }
412
+
413
+ /**
414
+ * Error
415
+ * エラーオブジェクトを返す
416
+ * @return Error エラーオブジェクト
417
+ */
418
+ public function Error() {
419
+ return $this->Error;
420
+ }
421
+
422
+ /**
423
+ * isValid
424
+ * バリデートが通っているかチェック
425
+ * @return Boolean
426
+ */
427
+ protected function isValid() {
428
+ $errors = $this->Error->getErrors();
429
+ if ( empty( $errors ) ) {
430
+ return true;
431
+ } else {
432
+ return false;
433
+ }
434
+ }
435
+
436
+ /**
437
+ * setRule
438
+ * バリデートが通っているかチェック
439
+ * @param String キー
440
+ * String バリデーションルール名
441
+ * Array オプション
442
+ * @return Boolean
443
+ */
444
+ public function setRule( $key, $rule, Array $options = array() ) {
445
+ $rules = array(
446
+ 'rule' => $rule,
447
+ 'options' =>$options
448
+ );
449
+ $this->validate[$key][] = $rules;
450
+ return $this;
451
+ }
452
+
453
+ /**
454
+ * check
455
+ * validate実行
456
+ * @return Boolean
457
+ */
458
+ public function check() {
459
+ foreach ( $this->validate as $key => $rules ) {
460
+ foreach ( $rules as $ruleSet ) {
461
+ if ( isset( $ruleSet['rule'] ) ) {
462
+ $rule = $ruleSet['rule'];
463
+ $options = array();
464
+ if ( isset( $ruleSet['options'] ) ) {
465
+ $options = $ruleSet['options'];
466
+ }
467
+ if ( method_exists( $this, $rule ) ) {
468
+ $message = $this->$rule( $key, $options );
469
+ if ( !empty( $message ) ) {
470
+ $this->Error->setError( $key, $this->$rule( $key, $options ) );
471
+ }
472
+ }
473
+ }
474
+ }
475
+ }
476
+ return $this->isValid();
477
+ }
478
+
479
+ /**
480
+ * array_clean
481
+ * 配列内の値の重複を消す
482
+ * @param Array
483
+ * @return Array
484
+ */
485
+ protected function array_clean( $array ) {
486
+ return array_merge( array_diff( $array, array( '' ) ) );
487
+ }
488
+ }
489
+ ?>