| @@ -1,63 +1,64 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Photonic_Plugin\Admin\Forms; |
| 3 | 4 | |
| 4 | 5 | class Edit_Gallery_Templates { |
| 5 | - private $fields, $providers; | |
| 6 | - private static $instance = null; | |
| 6 | + private array $fields; | |
| 7 | + private array $providers; | |
| 8 | + private static ?Edit_Gallery_Templates $instance = null; | |
| 7 | 9 | |
| 8 | 10 | private function __construct() { |
| 9 | - require_once(PHOTONIC_PATH.'/Admin/Forms/Vanilla_Form.php'); | |
| 11 | + require_once PHOTONIC_PATH . '/Admin/Forms/Vanilla_Form.php'; | |
| 10 | 12 | $form = Vanilla_Form::get_instance(); |
| 11 | 13 | $this->fields = $form->get_fields(); |
| 12 | 14 | |
| 13 | - $this->providers = ['default', 'flickr', 'google', 'smugmug', 'zenfolio', 'instagram']; | |
| 15 | + $this->providers = ['default', 'flickr', 'smugmug', 'zenfolio']; | |
| 14 | 16 | } |
| 15 | 17 | |
| 16 | - public static function get_instance() { | |
| 17 | - if (self::$instance == null) { | |
| 18 | + public static function get_instance(): Edit_Gallery_Templates { | |
| 19 | + if (null === self::$instance) { | |
| 18 | 20 | self::$instance = new Edit_Gallery_Templates(); |
| 19 | 21 | } |
| 20 | 22 | return self::$instance; |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - function render() { | |
| 25 | + public function render() { | |
| 24 | 26 | foreach ($this->providers as $provider) { |
| 25 | 27 | ?> |
| 26 | - <script type="text/html" id="tmpl-photonic-editor-<?php echo $provider; ?>"> | |
| 28 | + <script type="text/html" id="tmpl-photonic-editor-<?php echo esc_attr($provider); ?>"> | |
| 27 | 29 | <?php |
| 28 | 30 | $field_list = $this->fields[$provider]['fields']; |
| 29 | 31 | echo "<div class='photonic-form'>\n"; |
| 30 | - echo "<h2>Photonic ".($provider == 'default' ? 'WP' : $provider)." Gallery Settings</h2>\n"; | |
| 32 | + echo "<h2>Photonic " . wp_kses_post('default' === $provider ? 'WP' : $provider) . " Gallery Settings</h2>\n"; | |
| 31 | 33 | foreach ($field_list as $field) { |
| 32 | 34 | echo "\t<label class='setting'>\n"; |
| 33 | - echo "\t\t<span class='label'>{$field['name']} " . (isset($field['req']) && $field['req'] ? '(*)' : '') . " </span>\n"; | |
| 34 | - $alt_id = !empty($field['alt_id']) ? " alt_id='{$field['alt_id']}' " : ''; | |
| 35 | + echo "\t\t<span class='label'>" . wp_kses_post($field['name'] . (isset($field['req']) && $field['req'] ? '(*)' : '')) . " </span>\n"; | |
| 35 | 36 | switch ($field['type']) { |
| 36 | 37 | case 'text': |
| 37 | - echo "\t\t<input type='text' name='{$field['id']}' value='" . (isset($field['std']) ? $field['std'] : '') . "' $alt_id/>\n"; | |
| 38 | + echo "\t\t<input type='text' name='" . esc_attr($field['id']) . "' value='" . esc_attr($field['std'] ?? '') . "' />\n"; | |
| 38 | 39 | break; |
| 39 | 40 | |
| 40 | 41 | case 'select': |
| 41 | - echo "\t\t<select name='{$field['id']}' $alt_id>\n"; | |
| 42 | - $default = isset($field['std']) ? $field['std'] : ''; | |
| 42 | + echo "\t\t<select name='" . esc_attr($field['id']) . "'>\n"; | |
| 43 | + $default = $field['std'] ?? ''; | |
| 43 | 44 | foreach ($field['options'] as $option_name => $option_value) { |
| 44 | - if ($option_name == $default) { | |
| 45 | + if ($option_name === $default) { | |
| 45 | 46 | $selected = 'selected'; |
| 46 | 47 | } |
| 47 | 48 | else { |
| 48 | 49 | $selected = ''; |
| 49 | 50 | } |
| 50 | - echo "\t\t\t<option value='$option_name' $selected>" . esc_attr($option_value) . "</option>\n"; | |
| 51 | + echo "\t\t\t<option value='" . esc_attr($option_name) . "' " . esc_attr($selected) . ">" . esc_attr($option_value) . "</option>\n"; | |
| 51 | 52 | } |
| 52 | 53 | echo "\t\t</select>\n"; |
| 53 | 54 | break; |
| 54 | 55 | |
| 55 | 56 | case 'raw': |
| 56 | - echo "\t\t" . $field['std'] . "\n"; | |
| 57 | + echo "\t\t" . wp_kses($field['std'], ['select' => ['name'], 'option' => ['value', 'selected']]) . "\n"; | |
| 57 | 58 | break; |
| 58 | 59 | } |
| 59 | - echo "\t\t<span class='hint'>" . (isset($field['hint']) ? $field['hint'] : '') . "</span>\n"; | |
| 60 | + echo "\t\t<span class='hint'>" . wp_kses_post($field['hint'] ?? '') . "</span>\n"; | |
| 60 | 61 | echo "\t</label>\n"; |
| 61 | 62 | } |
| 62 | 63 | echo "</div>\n"; |
| 63 | 64 | ?> |
| @@ -66,6 +67,6 @@ | ||
| 66 | 67 | } |
| 67 | 68 | } |
| 68 | 69 | } |
| 69 | 70 | |
| 70 | -$edit_gallery = Edit_Gallery_Templates::get_instance(); | |
| 71 | -$edit_gallery->render(); | |
| 71 | +$photonic_edit_gallery = Edit_Gallery_Templates::get_instance(); | |
| 72 | +$photonic_edit_gallery->render(); | |