PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 2.2.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v2.2.0
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Plugins / Html / Field.php
embedpress / EmbedPress / Plugins / Html Last commit date
Field.php 7 years ago index.html 7 years ago
Field.php
201 lines
1 <?php
2
3 namespace EmbedPress\Plugins\Html;
4
5 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
6
7 /**
8 * Entity responsible to generating and rendering html fields to the settings page.
9 *
10 * @package EmbedPress
11 * @author EmbedPress <help@embedpress.com>
12 * @copyright Copyright (C) 2018 EmbedPress. All rights reserved.
13 * @license GPLv2 or later
14 * @since 1.4.0
15 */
16 class Field
17 {
18 /**
19 * Generates a text type input.
20 *
21 * @since 1.4.0
22 * @access protected
23 * @static
24 *
25 * @return string
26 */
27 protected static function text($value)
28 {
29 $html = '<input type="text" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}" value="' . (string)$value . '">';
30
31 return $html;
32 }
33
34 /**
35 * Generates a textarea input.
36 *
37 * @since 1.4.0
38 * @access protected
39 * @static
40 *
41 * @return string
42 */
43 protected static function textarea($value)
44 {
45 $html = '<textarea name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" placeholder="{{placeholder}}">' . (string)$value . '</textarea>';
46
47 return $html;
48 }
49
50 /**
51 * Generates a radio type input.
52 *
53 * @since 1.4.0
54 * @access protected
55 * @static
56 *
57 * @return string
58 */
59 protected static function radio($options, $value = null)
60 {
61 $html = [];
62
63 foreach ((array)$options as $optionValue => $optionLabel) {
64 $html[] = '<label>';
65 $html[] = '<input type="radio" name="embedpress:{{slug}}[{{name}}]" class="{{classes}}" value="' . $optionValue . '"' . ($value === $optionValue ? ' checked' : '') . '>';
66 $html[] = '&nbsp;' . $optionLabel;
67 $html[] = '</label>&nbsp;&nbsp;';
68 }
69
70 $html = implode('', $html);
71
72 return $html;
73 }
74
75 /**
76 * Generates a select input.
77 *
78 * @since 1.4.0
79 * @access protected
80 * @static
81 *
82 * @return string
83 */
84 protected static function select($options, $value = null)
85 {
86 $html = ['<select name="embedpress:{{slug}}[{{name}}]" class="{{classes}}">'];
87
88 foreach ((array)$options as $optionValue => $optionLabel) {
89 $html[] = '<option value="' . $optionValue . '"' . ($value === (string)$optionValue ? ' selected' : '') . '>' . $optionLabel . '</option>';
90 }
91
92 $html[] = '</select>';
93
94 $html = implode('', $html);
95
96 return $html;
97 }
98
99 /**
100 * Render a field based on a field schema.
101 *
102 * @since 1.4.0
103 * @static
104 *
105 * @param array $params There's two available keys: 'field' which holds the field schema; and 'pluginSlug' which
106 * represents the slug of the plugin where the field belongs to.
107 *
108 * @return void
109 */
110 public static function render($params)
111 {
112 $field = json_decode(json_encode($params['field']));
113
114 $pluginSlug = "embedpress:{$params['pluginSlug']}";
115
116 $options = (array)get_option($pluginSlug);
117
118 $field->type = strtolower($field->type);
119
120 if ($field->slug === "license_key") {
121 $value = isset($options['license']['key']) ? (string)$options['license']['key'] : "";
122 } else {
123 $value = isset($options[$field->slug]) ? $options[$field->slug] : (isset($field->default) ? $field->default : '');
124 }
125
126 if (in_array($field->type, ['bool', 'boolean'])) {
127 $html = self::radio([
128 0 => 'No',
129 1 => 'Yes',
130 ], (int)$value);
131 } elseif (isset($field->options)) {
132 $html = self::select((array)$field->options, (string)$value);
133 } elseif (in_array($field->type, ['textarea'])) {
134 $html = self::textarea((string)$value);
135 } else {
136 $html = self::text((string)$value);
137 }
138
139 $html = str_replace('{{slug}}', $params['pluginSlug'], $html);
140 $html = str_replace('{{name}}', $field->slug, $html);
141 $html = str_replace('{{classes}}', implode(' ', (! empty($field->classes) ? (array)$field->classes : [])),
142 $html);
143 $html = str_replace('{{placeholder}}', (! empty($field->placeholder) ? (string)$field->placeholder : ""),
144 $html);
145
146 $html .= wp_nonce_field("{$pluginSlug}:nonce", "{$pluginSlug}:nonce");
147
148 if ($field->slug === "license_key") {
149 $licenseStatusClass = "ep-label-danger";
150 $currentLicenseStatus = isset($options['license']['status']) ? trim(strtoupper($options['license']['status'])) : "";
151 switch ($currentLicenseStatus) {
152 case '':
153 $licenseStatusMessage = "Missing license";
154 break;
155 case 'EXPIRED':
156 $licenseStatusMessage = "Your license key is expired";
157 break;
158 case 'REVOKED':
159 $licenseStatusMessage = "Your license key has been disabled";
160 break;
161 case 'MISSING':
162 case 'INVALID':
163 $licenseStatusMessage = "Invalid license";
164 break;
165 case 'SITE_INACTIVE':
166 $licenseStatusMessage = "Your license is not active for this URL";
167 break;
168 case 'ITEM_NAME_MISMATCH':
169 $licenseStatusMessage = "This appears to be an invalid license key for this product";
170 break;
171 case 'NO_ACTIVATIONS_LEFT':
172 $licenseStatusMessage = "Your license key has reached its activation limit";
173 break;
174 case 'VALID':
175 $licenseStatusClass = "ep-label-success";
176 $licenseStatusMessage = "Activated";
177 break;
178 default:
179 $licenseStatusMessage = "Not validated yet";
180 break;
181 }
182
183 $html .= '<br/><br/><strong>Status: <span class="' . $licenseStatusClass . '">' . __($licenseStatusMessage) . '</span>.</strong><br/><br/>';
184
185 if ( ! (isset($options['license']['status']) && $options['license']['status'] === 'valid')) {
186 $html .= '<a href="' . EMBEDPRESS_LICENSES_MORE_INFO_URL . '" target="_blank" class="ep-small-link ep-small-spacing" rel="noopener noreferrer" style="display: inline-block; margin-left: 20px;" title="' . __('Click here to read more about licenses.') . '">' . __('More information') . '</a>';
187 $html .= '<br/><br/>';
188 }
189
190 $html .= '<hr>';
191 }
192
193 if ( ! empty($field->description)) {
194 $html .= '<br/>';
195 $html .= '<p class="description">' . $field->description . '</p>';
196 }
197
198 echo $html;
199 }
200 }
201