PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 1.4.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v1.4.2
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
198 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 = isset($options['license']['key']) ? (string)$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(' ', (!empty($field->classes) ? (array)$field->classes : array())), $html);
140 $html = str_replace('{{placeholder}}', (!empty($field->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 $currentLicenseStatus = isset($options['license']['status']) ? trim(strtoupper($options['license']['status'])) : "";
147 switch ($currentLicenseStatus) {
148 case '':
149 $licenseStatusMessage = "Missing license";
150 break;
151 case 'EXPIRED':
152 $licenseStatusMessage = "Your license key is expired";
153 break;
154 case 'REVOKED':
155 $licenseStatusMessage = "Your license key has been disabled";
156 break;
157 case 'MISSING':
158 case 'INVALID':
159 $licenseStatusMessage = "Invalid license";
160 break;
161 case 'SITE_INACTIVE':
162 $licenseStatusMessage = "Your license is not active for this URL";
163 break;
164 case 'ITEM_NAME_MISMATCH':
165 $licenseStatusMessage = "This appears to be an invalid license key for this product";
166 break;
167 case 'NO_ACTIVATIONS_LEFT':
168 $licenseStatusMessage = "Your license key has reached its activation limit";
169 break;
170 case 'VALID':
171 $licenseStatusClass = "ep-label-success";
172 $licenseStatusMessage = "Activated";
173 break;
174 default:
175 $licenseStatusMessage = "Not validated yet";
176 break;
177 }
178
179 $html .= '<br/><br/><strong>Status: <span class="'. $licenseStatusClass .'">'. __($licenseStatusMessage) .'</span>.</strong><br/><br/>';
180
181 if (!(isset($options['license']['status']) && $options['license']['status'] === 'valid')) {
182 $html .= '<button type="submit" class="button-secondary">' . __('Activate License') . '</button> ';
183 $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>';
184 $html .= '<br/><br/>';
185 }
186
187 $html .= '<hr>';
188 }
189
190 if (!empty($field->description)) {
191 $html .= '<br/>';
192 $html .= '<p class="description">'. $field->description .'</p>';
193 }
194
195 echo $html;
196 }
197 }
198