PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 1.6.3
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v1.6.3
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
474 lines
1 <?php
2 namespace EmbedPress\Ends\Back;
3
4 use \EmbedPress\Core;
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) 2017 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";
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' => "Load previews in the admin editor",
76 'section' => "admin"
77 ),
78 'enablePluginInFront' => array(
79 'label' => "Load previews in the frontend editor",
80 'section' => "admin"
81 ),
82 'forceFacebookLanguage' => array(
83 'label' => "Facebook embed 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_menu_page('EmbedPress Settings', 'EmbedPress', 'manage_options', 'embedpress', array(self::$namespace, 'renderForm'), null, 64);
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 $activeTab = isset($_GET['tab']) ? strtolower($_GET['tab']) : "";
124 if ($activeTab !== "embedpress") {
125 $action = "embedpress:{$activeTab}:settings:register";
126 } else {
127 $activeTab = "";
128 }
129
130 if (!empty($activeTab) && has_action($action)) {
131 do_action($action, array(
132 'id' => self::$sectionAdminIdentifier,
133 'slug' => self::$identifier
134 ));
135 } else {
136 register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier, array(self::$namespace, "validateForm"));
137
138 add_settings_section(self::$sectionAdminIdentifier, '', null, self::$identifier);
139
140 foreach (self::$fieldMap as $fieldName => $field) {
141 add_settings_field($fieldName, $field['label'], array(self::$namespace, "renderField_{$fieldName}"), self::$identifier, self::${"section". ucfirst($field['section']) ."Identifier"});
142 }
143 }
144 }
145
146 /**
147 * Method that render the settings's form.
148 *
149 * @since 1.0.0
150 * @static
151 */
152 public static function renderForm()
153 {
154 $activeTab = isset($_GET['tab']) ? strtolower($_GET['tab']) : "";
155 $settingsFieldsIdentifier = !empty($activeTab) ? "embedpress:{$activeTab}" : self::$sectionGroupIdentifier;
156 $settingsSectionsIdentifier = !empty($activeTab) ? "embedpress:{$activeTab}" : self::$identifier;
157 ?>
158 <div id="embedpress-settings-wrapper">
159 <header>
160 <a href="//wordpress.org/plugins/embedpress" target="_blank" rel="noopener noreferrer" title="EmbedPress" class="presshack-logo">
161 <img width="35" src="//pressshack.com/wp-content/uploads/2016/05/embedpress-150x150.png">
162 </a>
163 <h1>EmbedPress</h1>
164 </header>
165
166 <?php settings_errors(); ?>
167
168 <div>
169 <h2 class="nav-tab-wrapper">
170 <a href="?page=embedpress" class="nav-tab<?php echo $activeTab === 'embedpress' || empty($activeTab) ? ' nav-tab-active' : ''; ?> ">General settings</a>
171
172 <?php do_action('embedpress:settings:render:tab', $activeTab); ?>
173 </h2>
174
175 <form action="options.php" method="POST" style="padding-bottom: 20px;">
176 <?php settings_fields($settingsFieldsIdentifier); ?>
177 <?php do_settings_sections($settingsSectionsIdentifier); ?>
178
179 <button type="submit" class="button button-primary">Save changes</button>
180 </form>
181 </div>
182
183 <footer>
184 <p>
185 <a href="//wordpress.org/support/plugin/embedpress/reviews/#new-post" target="_blank" rel="noopener noreferrer">If you like <strong>EmbedPress</strong> please leave us a <span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span> rating. Thank you!</a>
186 </p>
187 <hr>
188 <nav>
189 <ul>
190 <li>
191 <a href="//pressshack.com/embedpress" target="_blank" rel="noopener noreferrer" title="About EmbedPress">About</a>
192 </li>
193 <li>
194 <a href="//pressshack.com/embedpress/docs/sources-support" target="_blank" rel="noopener noreferrer" title="List of supported sources by EmbedPress">Supported sources</a>
195 </li>
196 <li>
197 <a href="//pressshack.com/embedpress/docs" target="_blank" rel="noopener noreferrer" title="EmbedPress Documentation">Documentation</a>
198 </li>
199 <li>
200 <a href="//pressshack.com/embedpress/youtube" target="_blank" rel="noopener noreferrer" title="EmbedPress Add-Ons">Add-Ons</a>
201 </li>
202 <li>
203 <a href="//pressshack.com/contact" target="_blank" rel="noopener noreferrer" title="Contact the PressShack team">Contact</a>
204 </li>
205 <li>
206 <a href="//twitter.com/pressshack" target="_blank" rel="noopener noreferrer">
207 <span class="dashicons dashicons-twitter"></span>
208 </a>
209 </li>
210 <li>
211 <a href="//facebook.com/pressshack" target="_blank" rel="noopener noreferrer">
212 <span class="dashicons dashicons-facebook"></span>
213 </a>
214 </li>
215 </ul>
216 </nav>
217 <p>
218 <a href="//pressshack.com" target="_blank" rel="noopener noreferrer">
219 <img width="100" src="//pressshack.com/wp-content/uploads/2016/11/logo-450.png">
220 </a>
221 </p>
222 </footer>
223 </div>
224 <?php
225 }
226
227 /**
228 * Method that validates the form data.
229 *
230 * @since 1.0.0
231 * @static
232 *
233 * @param mixed $freshData Data received from the form.
234 *
235 * @return array
236 */
237 public static function validateForm($freshData)
238 {
239 $data = array(
240 'enablePluginInAdmin' => (bool)$freshData['enablePluginInAdmin'],
241 'enablePluginInFront' => (bool)$freshData['enablePluginInFront'],
242 'fbLanguage' => $freshData['fbLanguage']
243 );
244
245 return $data;
246 }
247
248 /**
249 * Method that renders the enablePluginInAdmin input.
250 *
251 * @since 1.0.0
252 * @static
253 */
254 public static function renderField_enablePluginInAdmin()
255 {
256 $fieldName = "enablePluginInAdmin";
257
258 $options = get_option(self::$sectionGroupIdentifier);
259
260 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
261
262 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
263 echo "&nbsp;&nbsp;";
264 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
265 echo '<p class="description">Do you want EmbedPress to run here in the admin area? Disabling this <strong>will not</strong> affect your frontend embeds.</p>';
266 }
267
268 /**
269 * Method that renders the enablePluginInFront input.
270 *
271 * @since 1.6.0
272 * @static
273 */
274 public static function renderField_enablePluginInFront()
275 {
276 $fieldName = "enablePluginInFront";
277
278 $options = get_option(self::$sectionGroupIdentifier);
279
280 $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
281
282 echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
283 echo "&nbsp;&nbsp;";
284 echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
285 echo '<p class="description">Do you want EmbedPress to run within editors in frontend (if there\'s any)? Disabling this <strong>will not</strong> affect embeds seem by your regular users in frontend.</p>';
286 }
287
288 /**
289 * Method that renders the forceFacebookLanguage input.
290 *
291 * @since 1.3.0
292 * @static
293 */
294 public static function renderField_forceFacebookLanguage()
295 {
296 $fieldName = "fbLanguage";
297
298 $options = get_option(self::$sectionGroupIdentifier);
299
300 $options[$fieldName] = !isset($options[$fieldName]) ? "" : $options[$fieldName];
301
302 $facebookLocales = self::getFacebookAvailableLocales();
303
304 echo '<select name="'. self::$sectionGroupIdentifier .'['. $fieldName .']">';
305 echo '<option value="0">Automatic (by Facebook)</option>';
306 echo '<optgroup label="Available">';
307 foreach ($facebookLocales as $locale => $localeName) {
308 echo '<option value="'. $locale .'"'. ($options[$fieldName] === $locale ? ' selected' : '') .'>'. $localeName .'</option>';
309 }
310 echo '</optgroup>';
311 echo '</select>';
312
313 echo '<p class="description">Sometimes Facebook can choose the wrong language for embeds. If this happens, choose the correct language here.</p>';
314 }
315
316 /**
317 * Returns a list of locales that can be used on Facebook embeds.
318 *
319 * @since 1.3.0
320 * @static
321 *
322 * @return array
323 */
324 public static function getFacebookAvailableLocales()
325 {
326 $locales = array(
327 'af_ZA' => "Afrikaans",
328 'ak_GH' => "Akan",
329 'am_ET' => "Amharic",
330 'ar_AR' => "Arabic",
331 'as_IN' => "Assamese",
332 'ay_BO' => "Aymara",
333 'az_AZ' => "Azerbaijani",
334 'be_BY' => "Belarusian",
335 'bg_BG' => "Bulgarian",
336 'bn_IN' => "Bengali",
337 'br_FR' => "Breton",
338 'bs_BA' => "Bosnian",
339 'ca_ES' => "Catalan",
340 'cb_IQ' => "Sorani Kurdish",
341 'ck_US' => "Cherokee",
342 'co_FR' => "Corsican",
343 'cs_CZ' => "Czech",
344 'cx_PH' => "Cebuano",
345 'cy_GB' => "Welsh",
346 'da_DK' => "Danish",
347 'de_DE' => "German",
348 'el_GR' => "Greek",
349 'en_GB' => "English (UK)",
350 'en_IN' => "English (India)",
351 'en_PI' => "English (Pirate)",
352 'en_UD' => "English (Upside Down)",
353 'en_US' => "English (US)",
354 'eo_EO' => "Esperanto",
355 'es_CL' => "Spanish (Chile)",
356 'es_CO' => "Spanish (Colombia)",
357 'es_ES' => "Spanish (Spain)",
358 'es_LA' => "Spanish",
359 'es_MX' => "Spanish (Mexico)",
360 'es_VE' => "Spanish (Venezuela)",
361 'et_EE' => "Estonian",
362 'eu_ES' => "Basque",
363 'fa_IR' => "Persian",
364 'fb_LT' => "Leet Speak",
365 'ff_NG' => "Fulah",
366 'fi_FI' => "Finnish",
367 'fo_FO' => "Faroese",
368 'fr_CA' => "French (Canada)",
369 'fr_FR' => "French (France)",
370 'fy_NL' => "Frisian",
371 'ga_IE' => "Irish",
372 'gl_ES' => "Galician",
373 'gn_PY' => "Guarani",
374 'gu_IN' => "Gujarati",
375 'gx_GR' => "Classical Greek",
376 'ha_NG' => "Hausa",
377 'he_IL' => "Hebrew",
378 'hi_IN' => "Hindi",
379 'hr_HR' => "Croatian",
380 'ht_HT' => "Haitian Creole",
381 'hu_HU' => "Hungarian",
382 'hy_AM' => "Armenian",
383 'id_ID' => "Indonesian",
384 'ig_NG' => "Igbo",
385 'is_IS' => "Icelandic",
386 'it_IT' => "Italian",
387 'ja_JP' => "Japanese",
388 'ja_KS' => "Japanese (Kansai)",
389 'jv_ID' => "Javanese",
390 'ka_GE' => "Georgian",
391 'kk_KZ' => "Kazakh",
392 'km_KH' => "Khmer",
393 'kn_IN' => "Kannada",
394 'ko_KR' => "Korean",
395 'ku_TR' => "Kurdish (Kurmanji)",
396 'ky_KG' => "Kyrgyz",
397 'la_VA' => "Latin",
398 'lg_UG' => "Ganda",
399 'li_NL' => "Limburgish",
400 'ln_CD' => "Lingala",
401 'lo_LA' => "Lao",
402 'lt_LT' => "Lithuanian",
403 'lv_LV' => "Latvian",
404 'mg_MG' => "Malagasy",
405 'mi_NZ' => "Māori",
406 'mk_MK' => "Macedonian",
407 'ml_IN' => "Malayalam",
408 'mn_MN' => "Mongolian",
409 'mr_IN' => "Marathi",
410 'ms_MY' => "Malay",
411 'mt_MT' => "Maltese",
412 'my_MM' => "Burmese",
413 'nb_NO' => "Norwegian (bokmal)",
414 'nd_ZW' => "Ndebele",
415 'ne_NP' => "Nepali",
416 'nl_BE' => "Dutch (België)",
417 'nl_NL' => "Dutch",
418 'nn_NO' => "Norwegian (nynorsk)",
419 'ny_MW' => "Chewa",
420 'or_IN' => "Oriya",
421 'pa_IN' => "Punjabi",
422 'pl_PL' => "Polish",
423 'ps_AF' => "Pashto",
424 'pt_BR' => "Portuguese (Brazil)",
425 'pt_PT' => "Portuguese (Portugal)",
426 'qc_GT' => "Quiché",
427 'qu_PE' => "Quechua",
428 'rm_CH' => "Romansh",
429 'ro_RO' => "Romanian",
430 'ru_RU' => "Russian",
431 'rw_RW' => "Kinyarwanda",
432 'sa_IN' => "Sanskrit",
433 'sc_IT' => "Sardinian",
434 'se_NO' => "Northern Sámi",
435 'si_LK' => "Sinhala",
436 'sk_SK' => "Slovak",
437 'sl_SI' => "Slovenian",
438 'sn_ZW' => "Shona",
439 'so_SO' => "Somali",
440 'sq_AL' => "Albanian",
441 'sr_RS' => "Serbian",
442 'sv_SE' => "Swedish",
443 'sw_KE' => "Swahili",
444 'sy_SY' => "Syriac",
445 'sz_PL' => "Silesian",
446 'ta_IN' => "Tamil",
447 'te_IN' => "Telugu",
448 'tg_TJ' => "Tajik",
449 'th_TH' => "Thai",
450 'tk_TM' => "Turkmen",
451 'tl_PH' => "Filipino",
452 'tl_ST' => "Klingon",
453 'tr_TR' => "Turkish",
454 'tt_RU' => "Tatar",
455 'tz_MA' => "Tamazight",
456 'uk_UA' => "Ukrainian",
457 'ur_PK' => "Urdu",
458 'uz_UZ' => "Uzbek",
459 'vi_VN' => "Vietnamese",
460 'wo_SN' => "Wolof",
461 'xh_ZA' => "Xhosa",
462 'yi_DE' => "Yiddish",
463 'yo_NG' => "Yoruba",
464 'zh_CN' => "Simplified Chinese (China)",
465 'zh_HK' => "Traditional Chinese (Hong Kong)",
466 'zh_TW' => "Traditional Chinese (Taiwan)",
467 'zu_ZA' => "Zulu",
468 'zz_TR' => "Zazaki"
469 );
470
471 return $locales;
472 }
473 }
474