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