PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 1.4.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v1.4.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 9 years ago index.html 9 years ago
Field.php
196 lines
1 <?php
2 namespace EmbedPress\Plugins\Html;
3
4 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
5
6 /**
7 * Entity responsible to generating and rendering html fields to the settings page.
8 *
9 * @package EmbedPress
10 * @author PressShack <help@pressshack.com>
11 * @copyright Copyright (C) 2016 Open Source Training, LLC. All rights reserved.
12 * @license GPLv2 or later
13 * @since 1.4.0
14 */
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 = array();
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 = array('<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 represents the slug of the plugin where the field belongs to.
106 * @return void
107 */
108 public static function render($params)
109 {
110 $field = json_decode(json_encode($params['field']));
111
112 $pluginSlug = "embedpress:{$params['pluginSlug']}";
113
114 $options = (array)get_option($pluginSlug);
115
116 $field->type = strtolower($field->type);
117
118 if ($field->slug === "license_key") {
119 $value = @$options['license']['key'];
120 } else {
121 $value = isset($options[$field->slug]) ? $options[$field->slug] : (isset($field->default) ? $field->default : '');
122 }
123
124 if (in_array($field->type, array('bool', 'boolean'))) {
125 $html = self::radio(array(
126 0 => 'No',
127 1 => 'Yes'
128 ), (int)$value);
129 } else if (isset($field->options)) {
130 $html = self::select((array)$field->options, (string)$value);
131 } else if (in_array($field->type, array('textarea'))) {
132 $html = self::textarea((string)$value);
133 } else {
134 $html = self::text((string)$value);
135 }
136
137 $html = str_replace('{{slug}}', $params['pluginSlug'], $html);
138 $html = str_replace('{{name}}', $field->slug, $html);
139 $html = str_replace('{{classes}}', implode(' ', (array)@$field->classes), $html);
140 $html = str_replace('{{placeholder}}', (string)@$field->placeholder, $html);
141
142 $html .= wp_nonce_field("{$pluginSlug}:nonce", "{$pluginSlug}:nonce");
143
144 if ($field->slug === "license_key") {
145 $licenseStatusClass = "ep-label-danger";
146 switch (trim(strtoupper(@$options['license']['status']))) {
147 case '':
148 $licenseStatusMessage = "Missing license";
149 break;
150 case 'EXPIRED':
151 $licenseStatusMessage = "Your license key is expired";
152 break;
153 case 'REVOKED':
154 $licenseStatusMessage = "Your license key has been disabled";
155 break;
156 case 'MISSING':
157 case 'INVALID':
158 $licenseStatusMessage = "Invalid license";
159 break;
160 case 'SITE_INACTIVE':
161 $licenseStatusMessage = "Your license is not active for this URL";
162 break;
163 case 'ITEM_NAME_MISMATCH':
164 $licenseStatusMessage = "This appears to be an invalid license key for this product";
165 break;
166 case 'NO_ACTIVATIONS_LEFT':
167 $licenseStatusMessage = "Your license key has reached its activation limit";
168 break;
169 case 'VALID':
170 $licenseStatusClass = "ep-label-success";
171 $licenseStatusMessage = "Activated";
172 break;
173 default:
174 $licenseStatusMessage = "Not validated yet";
175 break;
176 }
177
178 $html .= '<br/><br/><strong>Status: <span class="'. $licenseStatusClass .'">'. __($licenseStatusMessage) .'</span>.</strong><br/><br/>';
179 if (@$options['license']['status'] !== 'valid') {
180 $html .= '<button type="submit" class="button-secondary">' . __('Activate License') . '</button> ';
181 $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>';
182 $html .= '<br/><br/>';
183 }
184
185 $html .= '<hr>';
186 }
187
188 if (!empty($field->description)) {
189 $html .= '<br/>';
190 $html .= '<p class="description">'. $field->description .'</p>';
191 }
192
193 echo $html;
194 }
195 }
196