@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'input' => 'wpcf7-form-control', |
|
6 | - 'input_text' => 'wpcf7-form-control wpcf7-text', |
|
7 | - 'input_email' => 'wpcf7-form-control wpcf7-text wpcf7-email', |
|
8 | - 'select' => 'wpcf7-form-control wpcf7-select', |
|
9 | - 'textarea' => 'wpcf7-form-control wpcf7-textarea', |
|
10 | - ], |
|
11 | - 'validation' => [ |
|
12 | - 'error_tag' => 'span', |
|
13 | - 'error_tag_class' => 'wpcf7-not-valid-tip', |
|
14 | - 'input_error_class' => 'wpcf7-not-valid', |
|
15 | - 'message_initial_class' => 'wpcf7-display-none', |
|
16 | - 'message_success_class' => 'wpcf7-mail-sent-ok', |
|
17 | - 'message_tag_class' => 'wpcf7-response-output', |
|
18 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'input' => 'wpcf7-form-control', |
|
6 | + 'input_text' => 'wpcf7-form-control wpcf7-text', |
|
7 | + 'input_email' => 'wpcf7-form-control wpcf7-text wpcf7-email', |
|
8 | + 'select' => 'wpcf7-form-control wpcf7-select', |
|
9 | + 'textarea' => 'wpcf7-form-control wpcf7-textarea', |
|
10 | + ], |
|
11 | + 'validation' => [ |
|
12 | + 'error_tag' => 'span', |
|
13 | + 'error_tag_class' => 'wpcf7-not-valid-tip', |
|
14 | + 'input_error_class' => 'wpcf7-not-valid', |
|
15 | + 'message_initial_class' => 'wpcf7-display-none', |
|
16 | + 'message_success_class' => 'wpcf7-mail-sent-ok', |
|
17 | + 'message_tag_class' => 'wpcf7-response-output', |
|
18 | + ], |
|
19 | 19 | ]; |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'input' => 'wpforms-field-large', |
|
6 | - 'label' => 'wpforms-field-label', |
|
7 | - 'label_checkbox' => 'wpforms-field-label-inline', |
|
8 | - 'label_radio' => 'wpforms-field-label-inline', |
|
9 | - 'select' => 'wpforms-field-large', |
|
10 | - 'textarea' => 'wpforms-field-large', |
|
11 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'input' => 'wpforms-field-large', |
|
6 | + 'label' => 'wpforms-field-label', |
|
7 | + 'label_checkbox' => 'wpforms-field-label-inline', |
|
8 | + 'label_radio' => 'wpforms-field-label-inline', |
|
9 | + 'select' => 'wpforms-field-large', |
|
10 | + 'textarea' => 'wpforms-field-large', |
|
11 | + ], |
|
12 | 12 | ]; |
@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'input' => 'form-control', |
|
6 | - 'input_checkbox' => 'custom-control-input', |
|
7 | - 'input_radio' => 'custom-control-input', |
|
8 | - 'label_checkbox' => 'custom-control-label', |
|
9 | - 'label_radio' => 'custom-control-label', |
|
10 | - 'select' => 'form-control', |
|
11 | - 'textarea' => 'form-control', |
|
12 | - ], |
|
13 | - 'validation' => [ |
|
14 | - 'error_tag' => 'div', |
|
15 | - 'error_tag_class' => 'invalid-feedback', |
|
16 | - 'field_class' => 'form-group', |
|
17 | - 'input_error_class' => 'is-invalid', |
|
18 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'input' => 'form-control', |
|
6 | + 'input_checkbox' => 'custom-control-input', |
|
7 | + 'input_radio' => 'custom-control-input', |
|
8 | + 'label_checkbox' => 'custom-control-label', |
|
9 | + 'label_radio' => 'custom-control-label', |
|
10 | + 'select' => 'form-control', |
|
11 | + 'textarea' => 'form-control', |
|
12 | + ], |
|
13 | + 'validation' => [ |
|
14 | + 'error_tag' => 'div', |
|
15 | + 'error_tag_class' => 'invalid-feedback', |
|
16 | + 'field_class' => 'form-group', |
|
17 | + 'input_error_class' => 'is-invalid', |
|
18 | + ], |
|
19 | 19 | ]; |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'label' => 'et_pb_contact_form_label', |
|
6 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'label' => 'et_pb_contact_form_label', |
|
6 | + ], |
|
7 | 7 | ]; |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'select' => 'browser-default', |
|
6 | - 'textarea' => 'materialize-textarea', |
|
7 | - ], |
|
8 | - 'pagination' => [ |
|
9 | - 'type' => 'list', |
|
10 | - ], |
|
11 | - 'validation' => [ |
|
12 | - 'error_tag' => 'span', |
|
13 | - 'input_error_class' => 'wpcf7-not-valid', |
|
14 | - 'error_tag_class' => 'wpcf7-not-valid-tip', |
|
15 | - 'input_error_class' => 'wpcf7-not-valid', |
|
16 | - 'message_tag_class' => 'wpcf7-response-output', |
|
17 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'select' => 'browser-default', |
|
6 | + 'textarea' => 'materialize-textarea', |
|
7 | + ], |
|
8 | + 'pagination' => [ |
|
9 | + 'type' => 'list', |
|
10 | + ], |
|
11 | + 'validation' => [ |
|
12 | + 'error_tag' => 'span', |
|
13 | + 'input_error_class' => 'wpcf7-not-valid', |
|
14 | + 'error_tag_class' => 'wpcf7-not-valid-tip', |
|
15 | + 'input_error_class' => 'wpcf7-not-valid', |
|
16 | + 'message_tag_class' => 'wpcf7-response-output', |
|
17 | + ], |
|
18 | 18 | ]; |
@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'input' => 'form-control', |
|
6 | - 'input_checkbox' => 'form-check-input', |
|
7 | - 'input_radio' => 'form-check-input', |
|
8 | - 'label_checkbox' => 'form-check-label', |
|
9 | - 'label_radio' => 'form-check-label', |
|
10 | - 'select' => 'form-control', |
|
11 | - 'textarea' => 'form-control', |
|
12 | - ], |
|
13 | - 'validation' => [ |
|
14 | - 'error_tag' => 'div', |
|
15 | - 'error_tag_class' => 'invalid-feedback', |
|
16 | - 'field_class' => 'form-group', |
|
17 | - 'input_error_class' => 'is-invalid', |
|
18 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'input' => 'form-control', |
|
6 | + 'input_checkbox' => 'form-check-input', |
|
7 | + 'input_radio' => 'form-check-input', |
|
8 | + 'label_checkbox' => 'form-check-label', |
|
9 | + 'label_radio' => 'form-check-label', |
|
10 | + 'select' => 'form-control', |
|
11 | + 'textarea' => 'form-control', |
|
12 | + ], |
|
13 | + 'validation' => [ |
|
14 | + 'error_tag' => 'div', |
|
15 | + 'error_tag_class' => 'invalid-feedback', |
|
16 | + 'field_class' => 'form-group', |
|
17 | + 'input_error_class' => 'is-invalid', |
|
18 | + ], |
|
19 | 19 | ]; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - ':star-empty' => glsr()->url('assets/images/star-empty.svg'), |
|
5 | - ':star-error' => glsr()->url('assets/images/star-error.svg'), |
|
6 | - ':star-full' => glsr()->url('assets/images/star-full.svg'), |
|
7 | - ':star-half' => glsr()->url('assets/images/star-half.svg'), |
|
4 | + ':star-empty' => glsr()->url('assets/images/star-empty.svg'), |
|
5 | + ':star-error' => glsr()->url('assets/images/star-error.svg'), |
|
6 | + ':star-full' => glsr()->url('assets/images/star-full.svg'), |
|
7 | + ':star-half' => glsr()->url('assets/images/star-half.svg'), |
|
8 | 8 | ]; |
@@ -8,137 +8,137 @@ |
||
8 | 8 | */ |
9 | 9 | class GL_Plugin_Check_v3 |
10 | 10 | { |
11 | - const MIN_PHP_VERSION = '5.6.0'; |
|
12 | - const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
11 | + const MIN_PHP_VERSION = '5.6.0'; |
|
12 | + const MIN_WORDPRESS_VERSION = '4.7.0'; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $file; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $file; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $versions; |
|
19 | + /** |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $versions; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $file |
|
26 | - */ |
|
27 | - public function __construct($file, array $versions = array()) |
|
28 | - { |
|
29 | - $this->file = realpath($file); |
|
30 | - $this->versions = wp_parse_args($versions, array( |
|
31 | - 'php' => static::MIN_PHP_VERSION, |
|
32 | - 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | - )); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @param string $file |
|
26 | + */ |
|
27 | + public function __construct($file, array $versions = array()) |
|
28 | + { |
|
29 | + $this->file = realpath($file); |
|
30 | + $this->versions = wp_parse_args($versions, array( |
|
31 | + 'php' => static::MIN_PHP_VERSION, |
|
32 | + 'wordpress' => static::MIN_WORDPRESS_VERSION, |
|
33 | + )); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function canProceed() |
|
40 | - { |
|
41 | - if ($this->isValid()) { |
|
42 | - return true; |
|
43 | - } |
|
44 | - add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | - add_action('admin_notices', array($this, 'deactivate')); |
|
46 | - return false; |
|
47 | - } |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function canProceed() |
|
40 | + { |
|
41 | + if ($this->isValid()) { |
|
42 | + return true; |
|
43 | + } |
|
44 | + add_action('activated_plugin', array($this, 'deactivate')); |
|
45 | + add_action('admin_notices', array($this, 'deactivate')); |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - */ |
|
52 | - public function isPhpValid() |
|
53 | - { |
|
54 | - return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + */ |
|
52 | + public function isPhpValid() |
|
53 | + { |
|
54 | + return !version_compare(PHP_VERSION, $this->versions['php'], '<'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function isValid() |
|
61 | - { |
|
62 | - return $this->isPhpValid() && $this->isWpValid(); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function isValid() |
|
61 | + { |
|
62 | + return $this->isPhpValid() && $this->isWpValid(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function isWpValid() |
|
69 | - { |
|
70 | - global $wp_version; |
|
71 | - return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | - } |
|
65 | + /** |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function isWpValid() |
|
69 | + { |
|
70 | + global $wp_version; |
|
71 | + return !version_compare($wp_version, $this->versions['wordpress'], '<'); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $plugin |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function deactivate($plugin) |
|
79 | - { |
|
80 | - if ($this->isValid()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $pluginSlug = plugin_basename($this->file); |
|
84 | - if ($plugin == $pluginSlug) { |
|
85 | - $this->redirect(); //exit |
|
86 | - } |
|
87 | - $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | - deactivate_plugins($pluginSlug); |
|
89 | - $this->printNotice($pluginData['name']); |
|
90 | - } |
|
74 | + /** |
|
75 | + * @param string $plugin |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function deactivate($plugin) |
|
79 | + { |
|
80 | + if ($this->isValid()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $pluginSlug = plugin_basename($this->file); |
|
84 | + if ($plugin == $pluginSlug) { |
|
85 | + $this->redirect(); //exit |
|
86 | + } |
|
87 | + $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin'); |
|
88 | + deactivate_plugins($pluginSlug); |
|
89 | + $this->printNotice($pluginData['name']); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getMessages() |
|
96 | - { |
|
97 | - return array( |
|
98 | - __('The %s plugin was deactivated.', 'site-reviews'), |
|
99 | - __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
100 | - __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
101 | - __('PHP version', 'site-reviews'), |
|
102 | - __('WordPress version', 'site-reviews'), |
|
103 | - __('Update WordPress', 'site-reviews'), |
|
104 | - __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | - ); |
|
106 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getMessages() |
|
96 | + { |
|
97 | + return array( |
|
98 | + __('The %s plugin was deactivated.', 'site-reviews'), |
|
99 | + __('This plugin requires %s or greater in order to work properly.', 'site-reviews'), |
|
100 | + __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'), |
|
101 | + __('PHP version', 'site-reviews'), |
|
102 | + __('WordPress version', 'site-reviews'), |
|
103 | + __('Update WordPress', 'site-reviews'), |
|
104 | + __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'), |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param string $pluginName |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - protected function printNotice($pluginName) |
|
113 | - { |
|
114 | - $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | - $messages = $this->getMessages(); |
|
116 | - $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | - if (!$this->isPhpValid()) { |
|
118 | - printf($noticeTemplate, |
|
119 | - sprintf($messages[0], $pluginName), |
|
120 | - sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | - sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | - ); |
|
123 | - } elseif (!$this->isWpValid()) { |
|
124 | - printf($noticeTemplate, |
|
125 | - sprintf($messages[0], $pluginName), |
|
126 | - sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | - $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | - ); |
|
129 | - } |
|
130 | - } |
|
108 | + /** |
|
109 | + * @param string $pluginName |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + protected function printNotice($pluginName) |
|
113 | + { |
|
114 | + $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>'; |
|
115 | + $messages = $this->getMessages(); |
|
116 | + $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName); |
|
117 | + if (!$this->isPhpValid()) { |
|
118 | + printf($noticeTemplate, |
|
119 | + sprintf($messages[0], $pluginName), |
|
120 | + sprintf($messages[1], $messages[3].' '.$this->versions['php']), |
|
121 | + sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage |
|
122 | + ); |
|
123 | + } elseif (!$this->isWpValid()) { |
|
124 | + printf($noticeTemplate, |
|
125 | + sprintf($messages[0], $pluginName), |
|
126 | + sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']), |
|
127 | + $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5]) |
|
128 | + ); |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - protected function redirect() |
|
136 | - { |
|
137 | - wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | - filter_input(INPUT_GET, 'plugin_status'), |
|
139 | - filter_input(INPUT_GET, 'paged'), |
|
140 | - filter_input(INPUT_GET, 's') |
|
141 | - ))); |
|
142 | - exit; |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + protected function redirect() |
|
136 | + { |
|
137 | + wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s', |
|
138 | + filter_input(INPUT_GET, 'plugin_status'), |
|
139 | + filter_input(INPUT_GET, 'paged'), |
|
140 | + filter_input(INPUT_GET, 's') |
|
141 | + ))); |
|
142 | + exit; |
|
143 | + } |
|
144 | 144 | } |
@@ -18,346 +18,346 @@ |
||
18 | 18 | */ |
19 | 19 | class Builder |
20 | 20 | { |
21 | - const INPUT_TYPES = [ |
|
22 | - 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
23 | - 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
24 | - 'url', 'week', |
|
25 | - ]; |
|
26 | - |
|
27 | - const TAGS_FORM = [ |
|
28 | - 'input', 'select', 'textarea', |
|
29 | - ]; |
|
30 | - |
|
31 | - const TAGS_SINGLE = [ |
|
32 | - 'img', |
|
33 | - ]; |
|
34 | - |
|
35 | - const TAGS_STRUCTURE = [ |
|
36 | - 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
37 | - ]; |
|
38 | - |
|
39 | - const TAGS_TEXT = [ |
|
40 | - 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
41 | - 'small', 'span', |
|
42 | - ]; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - public $args = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var bool |
|
51 | - */ |
|
52 | - public $render = false; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $tag; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $method |
|
61 | - * @param array $args |
|
62 | - * @return string|void |
|
63 | - */ |
|
64 | - public function __call($method, $args) |
|
65 | - { |
|
66 | - $instance = new static(); |
|
67 | - $instance->setTagFromMethod($method); |
|
68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | - $generatedTag = in_array($instance->tag, $tags) |
|
72 | - ? $instance->buildTag() |
|
73 | - : $instance->buildCustomField(); |
|
74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | - if (!$this->render) { |
|
76 | - return $generatedTag; |
|
77 | - } |
|
78 | - echo $generatedTag; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $property |
|
83 | - * @param mixed $value |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function __set($property, $value) |
|
87 | - { |
|
88 | - $properties = [ |
|
89 | - 'args' => 'is_array', |
|
90 | - 'render' => 'is_bool', |
|
91 | - 'tag' => 'is_string', |
|
92 | - ]; |
|
93 | - if (!isset($properties[$property]) |
|
94 | - || empty(array_filter([$value], $properties[$property])) |
|
95 | - ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - $this->$property = $value; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return void|string |
|
103 | - */ |
|
104 | - public function getClosingTag() |
|
105 | - { |
|
106 | - if (empty($this->tag)) { |
|
107 | - return; |
|
108 | - } |
|
109 | - return '</'.$this->tag.'>'; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void|string |
|
114 | - */ |
|
115 | - public function getOpeningTag() |
|
116 | - { |
|
117 | - if (empty($this->tag)) { |
|
118 | - return; |
|
119 | - } |
|
120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return void|string |
|
126 | - */ |
|
127 | - public function getTag() |
|
128 | - { |
|
129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
130 | - return $this->getOpeningTag(); |
|
131 | - } |
|
132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
133 | - return $this->buildDefaultTag(); |
|
134 | - } |
|
135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function raw(array $field) |
|
142 | - { |
|
143 | - unset($field['label']); |
|
144 | - return $this->{$field['type']}($field); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string|void |
|
149 | - */ |
|
150 | - protected function buildCustomField() |
|
151 | - { |
|
152 | - $className = $this->getCustomFieldClassName(); |
|
153 | - if (class_exists($className)) { |
|
154 | - return (new $className($this))->build(); |
|
155 | - } |
|
156 | - glsr_log()->error('Field missing: '.$className); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string|void |
|
161 | - */ |
|
162 | - protected function buildDefaultTag($text = '') |
|
163 | - { |
|
164 | - if (empty($text)) { |
|
165 | - $text = $this->args['text']; |
|
166 | - } |
|
167 | - return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @return string|void |
|
172 | - */ |
|
173 | - protected function buildFieldDescription() |
|
174 | - { |
|
175 | - if (empty($this->args['description'])) { |
|
176 | - return; |
|
177 | - } |
|
178 | - if ($this->args['is_widget']) { |
|
179 | - return $this->small($this->args['description']); |
|
180 | - } |
|
181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string|void |
|
186 | - */ |
|
187 | - protected function buildFormInput() |
|
188 | - { |
|
189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | - if (isset($this->args['multiple'])) { |
|
191 | - $this->args['name'].= '[]'; |
|
192 | - } |
|
193 | - return $this->buildFormLabel().$this->getOpeningTag(); |
|
194 | - } |
|
195 | - return empty($this->args['options']) |
|
196 | - ? $this->buildFormInputChoice() |
|
197 | - : $this->buildFormInputMultiChoice(); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @return string|void |
|
202 | - */ |
|
203 | - protected function buildFormInputChoice() |
|
204 | - { |
|
205 | - if (!empty($this->args['text'])) { |
|
206 | - $this->args['label'] = $this->args['text']; |
|
207 | - } |
|
208 | - if (!$this->args['is_public']) { |
|
209 | - return $this->buildFormLabel([ |
|
210 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
211 | - 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
212 | - ]); |
|
213 | - } |
|
214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
215 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
216 | - 'text' => $this->args['label'].'<span></span>', |
|
217 | - ]); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @return string|void |
|
222 | - */ |
|
223 | - protected function buildFormInputMultiChoice() |
|
224 | - { |
|
225 | - if ('checkbox' == $this->args['type']) { |
|
226 | - $this->args['name'].= '[]'; |
|
227 | - } |
|
228 | - $index = 0; |
|
229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
232 | - 'id' => $this->args['id'].'-'.$index++, |
|
233 | - 'name' => $this->args['name'], |
|
234 | - 'text' => $this->args['options'][$key], |
|
235 | - 'value' => $key, |
|
236 | - ])); |
|
237 | - }); |
|
238 | - return $this->ul($options, [ |
|
239 | - 'class' => $this->args['class'], |
|
240 | - 'id' => $this->args['id'], |
|
241 | - ]); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return void|string |
|
246 | - */ |
|
247 | - protected function buildFormLabel(array $customArgs = []) |
|
248 | - { |
|
249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
250 | - return; |
|
251 | - } |
|
252 | - return $this->label(wp_parse_args($customArgs, [ |
|
253 | - 'for' => $this->args['id'], |
|
254 | - 'is_public' => $this->args['is_public'], |
|
255 | - 'text' => $this->args['label'], |
|
256 | - 'type' => $this->args['type'], |
|
257 | - ])); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return string|void |
|
262 | - */ |
|
263 | - protected function buildFormSelect() |
|
264 | - { |
|
265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return string|void |
|
270 | - */ |
|
271 | - protected function buildFormSelectOptions() |
|
272 | - { |
|
273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | - return $carry.$this->option([ |
|
275 | - 'selected' => $this->args['value'] == $key, |
|
276 | - 'text' => $this->args['options'][$key], |
|
277 | - 'value' => $key, |
|
278 | - ]); |
|
279 | - }); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @return string|void |
|
284 | - */ |
|
285 | - protected function buildFormTextarea() |
|
286 | - { |
|
287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @return string|void |
|
292 | - */ |
|
293 | - protected function buildTag() |
|
294 | - { |
|
295 | - $this->mergeArgsWithRequiredDefaults(); |
|
296 | - return $this->getTag(); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - protected function getCustomFieldClassName() |
|
303 | - { |
|
304 | - $classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - protected function mergeArgsWithRequiredDefaults() |
|
312 | - { |
|
313 | - $className = $this->getCustomFieldClassName(); |
|
314 | - if (class_exists($className)) { |
|
315 | - $this->args = $className::merge($this->args); |
|
316 | - } |
|
317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * @param string|array ...$params |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - protected function normalize(...$params) |
|
325 | - { |
|
326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
328 | - } |
|
329 | - if (is_array($params[0])) { |
|
330 | - $this->args += $params[0]; |
|
331 | - } elseif (is_array($params[1])) { |
|
332 | - $this->args += $params[1]; |
|
333 | - } |
|
334 | - if (!isset($this->args['is_public'])) { |
|
335 | - $this->args['is_public'] = false; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * @param string $value |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - protected function setNameOrTextAttributeForTag($value) |
|
344 | - { |
|
345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
346 | - ? 'name' |
|
347 | - : 'text'; |
|
348 | - $this->args[$attribute] = $value; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @param string $method |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - protected function setTagFromMethod($method) |
|
356 | - { |
|
357 | - $this->tag = strtolower($method); |
|
358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
359 | - $this->args['type'] = $this->tag; |
|
360 | - $this->tag = 'input'; |
|
361 | - } |
|
362 | - } |
|
21 | + const INPUT_TYPES = [ |
|
22 | + 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
23 | + 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
24 | + 'url', 'week', |
|
25 | + ]; |
|
26 | + |
|
27 | + const TAGS_FORM = [ |
|
28 | + 'input', 'select', 'textarea', |
|
29 | + ]; |
|
30 | + |
|
31 | + const TAGS_SINGLE = [ |
|
32 | + 'img', |
|
33 | + ]; |
|
34 | + |
|
35 | + const TAGS_STRUCTURE = [ |
|
36 | + 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
37 | + ]; |
|
38 | + |
|
39 | + const TAGS_TEXT = [ |
|
40 | + 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
41 | + 'small', 'span', |
|
42 | + ]; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + public $args = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var bool |
|
51 | + */ |
|
52 | + public $render = false; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $tag; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $method |
|
61 | + * @param array $args |
|
62 | + * @return string|void |
|
63 | + */ |
|
64 | + public function __call($method, $args) |
|
65 | + { |
|
66 | + $instance = new static(); |
|
67 | + $instance->setTagFromMethod($method); |
|
68 | + call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | + $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | + do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | + $generatedTag = in_array($instance->tag, $tags) |
|
72 | + ? $instance->buildTag() |
|
73 | + : $instance->buildCustomField(); |
|
74 | + $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | + if (!$this->render) { |
|
76 | + return $generatedTag; |
|
77 | + } |
|
78 | + echo $generatedTag; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $property |
|
83 | + * @param mixed $value |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function __set($property, $value) |
|
87 | + { |
|
88 | + $properties = [ |
|
89 | + 'args' => 'is_array', |
|
90 | + 'render' => 'is_bool', |
|
91 | + 'tag' => 'is_string', |
|
92 | + ]; |
|
93 | + if (!isset($properties[$property]) |
|
94 | + || empty(array_filter([$value], $properties[$property])) |
|
95 | + ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + $this->$property = $value; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return void|string |
|
103 | + */ |
|
104 | + public function getClosingTag() |
|
105 | + { |
|
106 | + if (empty($this->tag)) { |
|
107 | + return; |
|
108 | + } |
|
109 | + return '</'.$this->tag.'>'; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void|string |
|
114 | + */ |
|
115 | + public function getOpeningTag() |
|
116 | + { |
|
117 | + if (empty($this->tag)) { |
|
118 | + return; |
|
119 | + } |
|
120 | + $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | + return '<'.trim($this->tag.' '.$attributes).'>'; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return void|string |
|
126 | + */ |
|
127 | + public function getTag() |
|
128 | + { |
|
129 | + if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
130 | + return $this->getOpeningTag(); |
|
131 | + } |
|
132 | + if (!in_array($this->tag, static::TAGS_FORM)) { |
|
133 | + return $this->buildDefaultTag(); |
|
134 | + } |
|
135 | + return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function raw(array $field) |
|
142 | + { |
|
143 | + unset($field['label']); |
|
144 | + return $this->{$field['type']}($field); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string|void |
|
149 | + */ |
|
150 | + protected function buildCustomField() |
|
151 | + { |
|
152 | + $className = $this->getCustomFieldClassName(); |
|
153 | + if (class_exists($className)) { |
|
154 | + return (new $className($this))->build(); |
|
155 | + } |
|
156 | + glsr_log()->error('Field missing: '.$className); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string|void |
|
161 | + */ |
|
162 | + protected function buildDefaultTag($text = '') |
|
163 | + { |
|
164 | + if (empty($text)) { |
|
165 | + $text = $this->args['text']; |
|
166 | + } |
|
167 | + return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @return string|void |
|
172 | + */ |
|
173 | + protected function buildFieldDescription() |
|
174 | + { |
|
175 | + if (empty($this->args['description'])) { |
|
176 | + return; |
|
177 | + } |
|
178 | + if ($this->args['is_widget']) { |
|
179 | + return $this->small($this->args['description']); |
|
180 | + } |
|
181 | + return $this->p($this->args['description'], ['class' => 'description']); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string|void |
|
186 | + */ |
|
187 | + protected function buildFormInput() |
|
188 | + { |
|
189 | + if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | + if (isset($this->args['multiple'])) { |
|
191 | + $this->args['name'].= '[]'; |
|
192 | + } |
|
193 | + return $this->buildFormLabel().$this->getOpeningTag(); |
|
194 | + } |
|
195 | + return empty($this->args['options']) |
|
196 | + ? $this->buildFormInputChoice() |
|
197 | + : $this->buildFormInputMultiChoice(); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @return string|void |
|
202 | + */ |
|
203 | + protected function buildFormInputChoice() |
|
204 | + { |
|
205 | + if (!empty($this->args['text'])) { |
|
206 | + $this->args['label'] = $this->args['text']; |
|
207 | + } |
|
208 | + if (!$this->args['is_public']) { |
|
209 | + return $this->buildFormLabel([ |
|
210 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
211 | + 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
212 | + ]); |
|
213 | + } |
|
214 | + return $this->getOpeningTag().$this->buildFormLabel([ |
|
215 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
216 | + 'text' => $this->args['label'].'<span></span>', |
|
217 | + ]); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @return string|void |
|
222 | + */ |
|
223 | + protected function buildFormInputMultiChoice() |
|
224 | + { |
|
225 | + if ('checkbox' == $this->args['type']) { |
|
226 | + $this->args['name'].= '[]'; |
|
227 | + } |
|
228 | + $index = 0; |
|
229 | + $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | + return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | + 'checked' => in_array($key, (array) $this->args['value']), |
|
232 | + 'id' => $this->args['id'].'-'.$index++, |
|
233 | + 'name' => $this->args['name'], |
|
234 | + 'text' => $this->args['options'][$key], |
|
235 | + 'value' => $key, |
|
236 | + ])); |
|
237 | + }); |
|
238 | + return $this->ul($options, [ |
|
239 | + 'class' => $this->args['class'], |
|
240 | + 'id' => $this->args['id'], |
|
241 | + ]); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return void|string |
|
246 | + */ |
|
247 | + protected function buildFormLabel(array $customArgs = []) |
|
248 | + { |
|
249 | + if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
250 | + return; |
|
251 | + } |
|
252 | + return $this->label(wp_parse_args($customArgs, [ |
|
253 | + 'for' => $this->args['id'], |
|
254 | + 'is_public' => $this->args['is_public'], |
|
255 | + 'text' => $this->args['label'], |
|
256 | + 'type' => $this->args['type'], |
|
257 | + ])); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return string|void |
|
262 | + */ |
|
263 | + protected function buildFormSelect() |
|
264 | + { |
|
265 | + return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return string|void |
|
270 | + */ |
|
271 | + protected function buildFormSelectOptions() |
|
272 | + { |
|
273 | + return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | + return $carry.$this->option([ |
|
275 | + 'selected' => $this->args['value'] == $key, |
|
276 | + 'text' => $this->args['options'][$key], |
|
277 | + 'value' => $key, |
|
278 | + ]); |
|
279 | + }); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @return string|void |
|
284 | + */ |
|
285 | + protected function buildFormTextarea() |
|
286 | + { |
|
287 | + return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @return string|void |
|
292 | + */ |
|
293 | + protected function buildTag() |
|
294 | + { |
|
295 | + $this->mergeArgsWithRequiredDefaults(); |
|
296 | + return $this->getTag(); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + protected function getCustomFieldClassName() |
|
303 | + { |
|
304 | + $classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | + return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + protected function mergeArgsWithRequiredDefaults() |
|
312 | + { |
|
313 | + $className = $this->getCustomFieldClassName(); |
|
314 | + if (class_exists($className)) { |
|
315 | + $this->args = $className::merge($this->args); |
|
316 | + } |
|
317 | + $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * @param string|array ...$params |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + protected function normalize(...$params) |
|
325 | + { |
|
326 | + if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | + $this->setNameOrTextAttributeForTag($params[0]); |
|
328 | + } |
|
329 | + if (is_array($params[0])) { |
|
330 | + $this->args += $params[0]; |
|
331 | + } elseif (is_array($params[1])) { |
|
332 | + $this->args += $params[1]; |
|
333 | + } |
|
334 | + if (!isset($this->args['is_public'])) { |
|
335 | + $this->args['is_public'] = false; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * @param string $value |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + protected function setNameOrTextAttributeForTag($value) |
|
344 | + { |
|
345 | + $attribute = in_array($this->tag, static::TAGS_FORM) |
|
346 | + ? 'name' |
|
347 | + : 'text'; |
|
348 | + $this->args[$attribute] = $value; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @param string $method |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + protected function setTagFromMethod($method) |
|
356 | + { |
|
357 | + $this->tag = strtolower($method); |
|
358 | + if (in_array($this->tag, static::INPUT_TYPES)) { |
|
359 | + $this->args['type'] = $this->tag; |
|
360 | + $this->tag = 'input'; |
|
361 | + } |
|
362 | + } |
|
363 | 363 | } |