PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 1.3.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v1.3.1
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.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 / Ends / Back / Settings.php
embedpress / EmbedPress / Ends / Back Last commit date
Handler.php 9 years ago Settings.php 9 years ago index.html 9 years ago
Settings.php
415 lines
1 <?php
2 namespace EmbedPress\Ends\Back;
3
4 use \EmbedPress\Plugin;
5
6 (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
7
8 /**
9 * Entity that handles the plugin's settings page.
10 *
11 * @package EmbedPress
12 * @subpackage EmbedPress/Ends/Back
13 * @author PressShack <help@pressshack.com>
14 * @copyright Copyright (C) 2016 Open Source Training, LLC. All rights reserved.
15 * @license GPLv2 or later
16 * @since 1.0.0
17 */
18 class Settings
19 {
20 /**
21 * This class namespace.
22 *
23 * @since 1.0.0
24 * @access private
25 * @static
26 *
27 * @var string $namespace
28 */
29 private static $namespace = '\EmbedPress\Ends\Back\Settings';
30
31 /**
32 * The plugin's unique identifier.
33 *
34 * @since 1.0.0
35 * @access private
36 * @static
37 *
38 * @var string $identifier
39 */
40 private static $identifier = "plg_embedpress";
41
42 /**
43 * Unique identifier to the plugin's admin settings section.
44 *
45 * @since 1.0.0
46 * @access private
47 * @static
48 *
49 * @var string $sectionAdminIdentifier
50 */
51 private static $sectionAdminIdentifier = "embedpress_options_admin";
52
53 /**
54 * Unique identifier to the plugin's general settings section.
55 *
56 * @since 1.0.0
57 * @access private
58 * @static
59 *
60 * @var string $sectionGroupIdentifier The name of the plugin.
61 */
62 private static $sectionGroupIdentifier = "embedpress_options";
63
64 /**
65 * Map to all settings.
66 *
67 * @since 1.0.0
68 * @access private
69 * @static
70 *
71 * @var string $fieldMap
72 */
73 private static $fieldMap = array(
74 'enablePluginInAdmin' => array(
75 'label' => "Enable EmbedPress in the admin area",
76 'section' => "admin"
77 ),
78 'displayPreviewBox' => array(
79 'label' => "Display Preview Box inside editor",
80 'section' => "admin"
81 ),
82 'forceFacebookLanguage' => array(
83 'label' => "Display Facebook embeds in a different language",
84 'section' => "admin"
85 )
86 );
87
88 /**
89 * Class constructor. This prevents the class being directly instantiated.
90 *
91 * @since 1.0.0
92 */
93 public function __construct()
94 {}
95
96 /**
97 * This prevents the class being cloned.
98 *
99 * @since 1.0.0
100 */
101 public function __clone()
102 {}
103
104 /**
105 * Method that adds an sub-item for EmbedPress to the WordPress Settings menu.
106 *
107 * @since 1.0.0
108 * @static
109 */
110 public static function registerMenuItem()
111 {
112 add_object_page('EmbedPress Settings', 'EmbedPress', 'manage_options', 'embedpress', array(self::$namespace, 'renderForm'));
113 }
114
115 /**
116 * Method that configures the EmbedPress settings page.
117 *
118 * @since 1.0.0
119 * @static
120 */
121 public static function registerActions()
122 {
123 register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier, array(self::$namespace, "validateForm"));
124
125 add_settings_section(self::$sectionAdminIdentifier, 'Admin Section Settings', array(self::$namespace, 'renderHelpText'), self::$identifier);
126
127 foreach (self::$fieldMap as $fieldName => $field) {
128 add_settings_field($fieldName, $field['label'], array(self::$namespace, "renderField_{$fieldName}"), self::$identifier, self::${"section". ucfirst($field['section']) ."Identifier"});
129 }
130 }
131
132 /**
133 * Method that render the settings's form.
134 *
135 * @since 1.0.0
136 * @static
137 */
138 public static function renderForm()
139 {
140 ?>
141 <div>
142 <h2>EmbedPress Settings Page</h2>
143 <form action="options.php" method="POST">
144 <?php settings_fields(self::$sectionGroupIdentifier); ?>
145 <?php do_settings_sections(self::$identifier); ?>
146
147 <input name="Submit" type="submit" class="button button-primary" value="Save changes" />
148 </form>
149 </div>
150 <?php
151 }
152
153 /**
154 * Method that validates the form data.
155 *
156 * @since 1.0.0
157 * @static
158 *
159 * @param mixed $freshData Data received from the form.
160 *
161 * @return array
162 */
163 public static function validateForm($freshData)
164 {
165 $data = array(
166 'displayPreviewBox' => (bool)$freshData['displayPreviewBox'],
167 'enablePluginInAdmin' => (bool)$freshData['enablePluginInAdmin'],
168 'fbLanguage' => $freshData['fbLanguage']
169 );
170
171 return $data;
172 }
173
174 /**
175 * Method that prints help info for the form.
176 *
177 * @since 1.0.0
178 * @static
179 *
180 * @return string
181 */
182 public static function renderHelpText()
183 {
184 return "";
185 }
186
187 /**
188 * Method that renders the displayPreviewBox input.
189 *
190 * @since 1.0.0
191 * @static
192 */
193 public static function renderField_displayPreviewBox()
194 {
195 $fieldName = "displayPreviewBox";
196
197 $options = get_option(self::$sectionGroupIdentifier);
198
199 $activeOptions = Plugin::getSettings();
200 if (isset($activeOptions->enablePluginInAdmin) && (bool)$activeOptions->enablePluginInAdmin === false) {
201 $options[$fieldName] = false;
202 } else {
203 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
204 }
205 unset($activeOptions);
206
207 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
208 echo "&nbsp;&nbsp;";
209 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
210 }
211
212 /**
213 * Method that renders the enablePluginInAdmin input.
214 *
215 * @since 1.0.0
216 * @static
217 */
218 public static function renderField_enablePluginInAdmin()
219 {
220 $fieldName = "enablePluginInAdmin";
221
222 $options = get_option(self::$sectionGroupIdentifier);
223
224 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
225
226 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
227 echo "&nbsp;&nbsp;";
228 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
229 }
230
231 /**
232 * Method that renders the forceFacebookLanguage input.
233 *
234 * @since 1.3.0
235 * @static
236 */
237 public static function renderField_forceFacebookLanguage()
238 {
239 $fieldName = "fbLanguage";
240
241 $options = get_option(self::$sectionGroupIdentifier);
242
243 $options[$fieldName] = !isset($options[$fieldName]) ? "" : $options[$fieldName];
244
245 $facebookLocales = self::getFacebookAvailableLocales();
246
247 echo '<select name="'. self::$sectionGroupIdentifier .'['. $fieldName .']">';
248 echo '<option value="0">Automatic (by Facebook)</option>';
249 echo '<optgroup label="Available">';
250 foreach ($facebookLocales as $locale => $localeName) {
251 echo '<option value="'. $locale .'"'. ($options[$fieldName] === $locale ? ' selected' : '') .'>'. $localeName .'</option>';
252 }
253 echo '</optgroup>';
254 echo '</select>';
255 }
256
257 /**
258 * Returns a list of locales that can be used on Facebook embeds.
259 *
260 * @since 1.3.0
261 * @static
262 *
263 * @return array
264 */
265 public static function getFacebookAvailableLocales()
266 {
267 $locales = array(
268 'af_ZA' => "Afrikaans",
269 'ak_GH' => "Akan",
270 'am_ET' => "Amharic",
271 'ar_AR' => "Arabic",
272 'as_IN' => "Assamese",
273 'ay_BO' => "Aymara",
274 'az_AZ' => "Azerbaijani",
275 'be_BY' => "Belarusian",
276 'bg_BG' => "Bulgarian",
277 'bn_IN' => "Bengali",
278 'br_FR' => "Breton",
279 'bs_BA' => "Bosnian",
280 'ca_ES' => "Catalan",
281 'cb_IQ' => "Sorani Kurdish",
282 'ck_US' => "Cherokee",
283 'co_FR' => "Corsican",
284 'cs_CZ' => "Czech",
285 'cx_PH' => "Cebuano",
286 'cy_GB' => "Welsh",
287 'da_DK' => "Danish",
288 'de_DE' => "German",
289 'el_GR' => "Greek",
290 'en_GB' => "English (UK)",
291 'en_IN' => "English (India)",
292 'en_PI' => "English (Pirate)",
293 'en_UD' => "English (Upside Down)",
294 'en_US' => "English (US)",
295 'eo_EO' => "Esperanto",
296 'es_CL' => "Spanish (Chile)",
297 'es_CO' => "Spanish (Colombia)",
298 'es_ES' => "Spanish (Spain)",
299 'es_LA' => "Spanish",
300 'es_MX' => "Spanish (Mexico)",
301 'es_VE' => "Spanish (Venezuela)",
302 'et_EE' => "Estonian",
303 'eu_ES' => "Basque",
304 'fa_IR' => "Persian",
305 'fb_LT' => "Leet Speak",
306 'ff_NG' => "Fulah",
307 'fi_FI' => "Finnish",
308 'fo_FO' => "Faroese",
309 'fr_CA' => "French (Canada)",
310 'fr_FR' => "French (France)",
311 'fy_NL' => "Frisian",
312 'ga_IE' => "Irish",
313 'gl_ES' => "Galician",
314 'gn_PY' => "Guarani",
315 'gu_IN' => "Gujarati",
316 'gx_GR' => "Classical Greek",
317 'ha_NG' => "Hausa",
318 'he_IL' => "Hebrew",
319 'hi_IN' => "Hindi",
320 'hr_HR' => "Croatian",
321 'ht_HT' => "Haitian Creole",
322 'hu_HU' => "Hungarian",
323 'hy_AM' => "Armenian",
324 'id_ID' => "Indonesian",
325 'ig_NG' => "Igbo",
326 'is_IS' => "Icelandic",
327 'it_IT' => "Italian",
328 'ja_JP' => "Japanese",
329 'ja_KS' => "Japanese (Kansai)",
330 'jv_ID' => "Javanese",
331 'ka_GE' => "Georgian",
332 'kk_KZ' => "Kazakh",
333 'km_KH' => "Khmer",
334 'kn_IN' => "Kannada",
335 'ko_KR' => "Korean",
336 'ku_TR' => "Kurdish (Kurmanji)",
337 'ky_KG' => "Kyrgyz",
338 'la_VA' => "Latin",
339 'lg_UG' => "Ganda",
340 'li_NL' => "Limburgish",
341 'ln_CD' => "Lingala",
342 'lo_LA' => "Lao",
343 'lt_LT' => "Lithuanian",
344 'lv_LV' => "Latvian",
345 'mg_MG' => "Malagasy",
346 'mi_NZ' => "Māori",
347 'mk_MK' => "Macedonian",
348 'ml_IN' => "Malayalam",
349 'mn_MN' => "Mongolian",
350 'mr_IN' => "Marathi",
351 'ms_MY' => "Malay",
352 'mt_MT' => "Maltese",
353 'my_MM' => "Burmese",
354 'nb_NO' => "Norwegian (bokmal)",
355 'nd_ZW' => "Ndebele",
356 'ne_NP' => "Nepali",
357 'nl_BE' => "Dutch (België)",
358 'nl_NL' => "Dutch",
359 'nn_NO' => "Norwegian (nynorsk)",
360 'ny_MW' => "Chewa",
361 'or_IN' => "Oriya",
362 'pa_IN' => "Punjabi",
363 'pl_PL' => "Polish",
364 'ps_AF' => "Pashto",
365 'pt_BR' => "Portuguese (Brazil)",
366 'pt_PT' => "Portuguese (Portugal)",
367 'qc_GT' => "Quiché",
368 'qu_PE' => "Quechua",
369 'rm_CH' => "Romansh",
370 'ro_RO' => "Romanian",
371 'ru_RU' => "Russian",
372 'rw_RW' => "Kinyarwanda",
373 'sa_IN' => "Sanskrit",
374 'sc_IT' => "Sardinian",
375 'se_NO' => "Northern Sámi",
376 'si_LK' => "Sinhala",
377 'sk_SK' => "Slovak",
378 'sl_SI' => "Slovenian",
379 'sn_ZW' => "Shona",
380 'so_SO' => "Somali",
381 'sq_AL' => "Albanian",
382 'sr_RS' => "Serbian",
383 'sv_SE' => "Swedish",
384 'sw_KE' => "Swahili",
385 'sy_SY' => "Syriac",
386 'sz_PL' => "Silesian",
387 'ta_IN' => "Tamil",
388 'te_IN' => "Telugu",
389 'tg_TJ' => "Tajik",
390 'th_TH' => "Thai",
391 'tk_TM' => "Turkmen",
392 'tl_PH' => "Filipino",
393 'tl_ST' => "Klingon",
394 'tr_TR' => "Turkish",
395 'tt_RU' => "Tatar",
396 'tz_MA' => "Tamazight",
397 'uk_UA' => "Ukrainian",
398 'ur_PK' => "Urdu",
399 'uz_UZ' => "Uzbek",
400 'vi_VN' => "Vietnamese",
401 'wo_SN' => "Wolof",
402 'xh_ZA' => "Xhosa",
403 'yi_DE' => "Yiddish",
404 'yo_NG' => "Yoruba",
405 'zh_CN' => "Simplified Chinese (China)",
406 'zh_HK' => "Traditional Chinese (Hong Kong)",
407 'zh_TW' => "Traditional Chinese (Taiwan)",
408 'zu_ZA' => "Zulu",
409 'zz_TR' => "Zazaki"
410 );
411
412 return $locales;
413 }
414 }
415