| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Photonic_Plugin\Admin\Wizard; |
| 3 | 4 | |
| 4 | 5 | use Photonic_Plugin\Core\Utilities; |
| 5 | 6 | |
| 6 | 7 | class WP extends Source { |
| 7 | - private static $instance; | |
| 8 | + private static ?WP $instance = null; | |
| 8 | 9 | |
| 9 | 10 | protected function __construct() { |
| 10 | 11 | parent::__construct(); |
| 11 | 12 | $this->provider = 'wp'; |
| @@ -10,88 +11,118 @@ | ||
| 10 | 11 | parent::__construct(); |
| 11 | 12 | $this->provider = 'wp'; |
| 12 | 13 | $this->allowed_image_sizes['wp'] = [ |
| 13 | 14 | 'thumb_size' => Utilities::get_wp_image_sizes(false, true), |
| 14 | - 'tile_size' => Utilities::get_wp_image_sizes(true, true), | |
| 15 | - 'main_size' => Utilities::get_wp_image_sizes(true, true), | |
| 15 | + 'tile_size' => Utilities::get_wp_image_sizes(true, true), | |
| 16 | + 'main_size' => Utilities::get_wp_image_sizes(true, true), | |
| 16 | 17 | ]; |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | - public static function get_instance() { | |
| 20 | - if (self::$instance == null) { | |
| 20 | + public static function get_instance(): WP { | |
| 21 | + if (null === self::$instance) { | |
| 21 | 22 | self::$instance = new WP(); |
| 22 | 23 | } |
| 23 | 24 | return self::$instance; |
| 24 | 25 | } |
| 25 | 26 | |
| 26 | - function get_screen_2() { | |
| 27 | + public function get_screen_2(): array { | |
| 27 | 28 | return [ |
| 28 | - 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 29 | + 'header' => esc_html__('Choose Type of Gallery', 'photonic'), | |
| 29 | 30 | 'display' => [ |
| 30 | 31 | 'display_type' => [ |
| 31 | - 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 32 | - 'type' => 'select', | |
| 32 | + 'desc' => esc_html__('What do you want to show?', 'photonic'), | |
| 33 | + 'type' => 'select', | |
| 33 | 34 | 'options' => [ |
| 34 | - '' => '', | |
| 35 | + '' => '', | |
| 35 | 36 | 'current-post' => esc_html__('Gallery attached to the current post', 'photonic'), |
| 36 | - 'multi-photo' => esc_html__('Photos from Media Library', 'photonic'), | |
| 37 | + 'multi-photo' => esc_html__('Photos from Media Library', 'photonic'), | |
| 37 | 38 | ], |
| 38 | - 'req' => 1, | |
| 39 | + 'req' => 1, | |
| 39 | 40 | ], |
| 40 | 41 | ], |
| 41 | 42 | ]; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | - function get_screen_3() { | |
| 45 | + public function get_screen_3(): array { | |
| 45 | 46 | return []; |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | - function get_screen_4() { | |
| 49 | + public function get_screen_4(): array { | |
| 49 | 50 | return []; |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | - function get_screen_5() { | |
| 53 | + public function get_screen_5(): array { | |
| 53 | 54 | return [ |
| 54 | 55 | 'wp' => [ |
| 55 | - 'count' => [ | |
| 56 | + 'count' => [ | |
| 56 | 57 | 'desc' => esc_html__('Number of photos to show', 'photonic'), |
| 57 | 58 | 'type' => 'text', |
| 58 | 59 | 'hint' => esc_html__('Numeric values only. Shows all photos by default.', 'photonic'), |
| 59 | 60 | ], |
| 61 | + 'orderby' => [ | |
| 62 | + 'desc' => esc_html__('Sort photos by', 'photonic'), | |
| 63 | + 'type' => 'select', | |
| 64 | + 'options' => [ | |
| 65 | + '' => '', | |
| 66 | + 'menu_order' => esc_html__('Sequence in which they are provided', 'photonic'), | |
| 67 | + 'title' => esc_html__('Title of the image in the media library', 'photonic'), | |
| 68 | + 'post_date' => esc_html__('Creation date', 'photonic'), | |
| 69 | + 'rand' => esc_html__('Random order', 'photonic'), | |
| 70 | + 'ID' => esc_html__('Photo ID', 'photonic'), | |
| 71 | + ], | |
| 72 | + ], | |
| 73 | + 'order' => [ | |
| 74 | + 'desc' => esc_html__('Sort order', 'photonic'), | |
| 75 | + 'type' => 'select', | |
| 76 | + 'options' => [ | |
| 77 | + '' => '', | |
| 78 | + 'ASC' => esc_html__('Ascending', 'photonic'), | |
| 79 | + 'DESC' => esc_html__('Descending', 'photonic'), | |
| 80 | + ], | |
| 81 | + ], | |
| 82 | + 'link' => [ | |
| 83 | + 'desc' => esc_html__('Link photo to', 'photonic'), | |
| 84 | + 'hint' => esc_html__('By default WP links photos to their respective attachment pages. You can change this behaviour.', 'photonic'), | |
| 85 | + 'type' => 'select', | |
| 86 | + 'options' => [ | |
| 87 | + '' => esc_html__('Attachment page', 'photonic'), | |
| 88 | + 'file' => esc_html__('Image file', 'photonic'), | |
| 89 | + ], | |
| 90 | + ], | |
| 60 | 91 | 'main_size' => [ |
| 61 | - 'desc' => esc_html__('Main image size', 'photonic'), | |
| 62 | - 'type' => 'select', | |
| 92 | + 'desc' => esc_html__('Main image size', 'photonic'), | |
| 93 | + 'type' => 'select', | |
| 63 | 94 | 'options' => $this->allowed_image_sizes['wp']['main_size'], |
| 64 | - 'std' => 'full', | |
| 95 | + 'std' => 'full', | |
| 65 | 96 | ], |
| 66 | 97 | ] |
| 67 | 98 | ]; |
| 68 | 99 | } |
| 69 | 100 | |
| 70 | - function get_square_size_options() { | |
| 101 | + public function get_square_size_options(): array { | |
| 71 | 102 | return [ |
| 72 | 103 | 'thumb_size' => [ |
| 73 | - 'desc' => esc_html__('Thumbnail size', 'photonic'), | |
| 74 | - 'type' => 'select', | |
| 104 | + 'desc' => esc_html__('Thumbnail size', 'photonic'), | |
| 105 | + 'type' => 'select', | |
| 75 | 106 | 'options' => $this->allowed_image_sizes['wp']['thumb_size'], |
| 76 | - 'std' => 'thumbnail', | |
| 107 | + 'std' => 'thumbnail', | |
| 77 | 108 | ], |
| 78 | 109 | ]; |
| 79 | 110 | } |
| 80 | 111 | |
| 81 | - function get_random_size_options() { | |
| 112 | + public function get_random_size_options(): array { | |
| 82 | 113 | return [ |
| 83 | 114 | 'tile_size' => [ |
| 84 | - 'desc' => esc_html__('Tile size', 'photonic'), | |
| 85 | - 'type' => 'select', | |
| 115 | + 'desc' => esc_html__('Tile size', 'photonic'), | |
| 116 | + 'type' => 'select', | |
| 86 | 117 | 'options' => $this->allowed_image_sizes['wp']['tile_size'], |
| 87 | - 'std' => 'full', | |
| 118 | + 'std' => 'full', | |
| 88 | 119 | ], |
| 89 | 120 | ]; |
| 90 | 121 | } |
| 91 | 122 | |
| 92 | - function make_request($display_type, $for, $flattened_fields) { | |
| 93 | - return null; | |
| 123 | + public function make_request($display_type, $for, $flattened_fields): array { | |
| 124 | + return []; | |
| 94 | 125 | } |
| 95 | 126 | |
| 96 | 127 | /** |
| 97 | 128 | * Blank for WP, since there is nothing to do. |
| @@ -99,42 +130,43 @@ | ||
| 99 | 130 | * @param $response |
| 100 | 131 | * @param $display_type |
| 101 | 132 | * @param null $url |
| 102 | 133 | * @param array $pagination |
| 103 | - * @return mixed|null | |
| 134 | + * @return array | |
| 104 | 135 | */ |
| 105 | - function process_response($response, $display_type, $url = null, &$pagination = []) { | |
| 106 | - return null; | |
| 136 | + public function process_response($response, $display_type, $url = null, &$pagination = []): array { | |
| 137 | + return []; | |
| 107 | 138 | } |
| 108 | 139 | |
| 109 | 140 | /** |
| 110 | 141 | * @param $display_type |
| 111 | - * @return array|mixed | |
| 142 | + * @return array | |
| 112 | 143 | */ |
| 113 | - function construct_shortcode_from_screen_selections($display_type) { | |
| 144 | + public function construct_shortcode_from_screen_selections($display_type): array { | |
| 114 | 145 | $short_code = []; |
| 115 | 146 | |
| 116 | - if ($display_type == 'current-post' && !empty($_POST['post_id'])) { | |
| 117 | - $short_code['id'] = sanitize_text_field($_POST['post_id']); | |
| 147 | + if (check_ajax_referer('photonic-wizard-next-' . get_current_user_id())) { | |
| 148 | + if ('current-post' === $display_type && !empty($_POST['post_id'])) { | |
| 149 | + $short_code['id'] = sanitize_text_field(wp_unslash($_POST['post_id'])); | |
| 150 | + } | |
| 151 | + elseif (!empty($_POST['selected_data'])) { | |
| 152 | + $short_code['ids'] = sanitize_text_field(wp_unslash($_POST['selected_data'])); | |
| 153 | + } | |
| 118 | 154 | } |
| 119 | - else if (!empty($_POST['selected_data'])) { | |
| 120 | - $short_code['ids'] = sanitize_text_field($_POST['selected_data']); | |
| 121 | - } | |
| 122 | - | |
| 123 | 155 | return $short_code; |
| 124 | 156 | } |
| 125 | 157 | |
| 126 | 158 | /** |
| 127 | 159 | * @param $input |
| 128 | - * @return array|mixed | |
| 160 | + * @return array | |
| 129 | 161 | */ |
| 130 | - function deconstruct_shortcode_to_screen_selections($input) { | |
| 162 | + public function deconstruct_shortcode_to_screen_selections($input): array { | |
| 131 | 163 | $deconstructed = []; |
| 132 | 164 | |
| 133 | 165 | if (empty($input->id) && empty($input->ids) && empty($input->include)) { |
| 134 | 166 | $deconstructed['display_type'] = 'current-post'; |
| 135 | 167 | } |
| 136 | - else if (!empty($input->ids) || !empty($input->include)) { | |
| 168 | + elseif (!empty($input->ids) || !empty($input->include)) { | |
| 137 | 169 | $deconstructed['display_type'] = 'multi-photo'; |
| 138 | 170 | $deconstructed['selected_data'] = !empty($input->ids) ? $input->ids : $input->include; |
| 139 | 171 | } |
| 140 | 172 | |
| @@ -139,5 +171,5 @@ | ||
| 139 | 171 | } |
| 140 | 172 | |
| 141 | 173 | return $deconstructed; |
| 142 | 174 | } |
| 143 | -} | |
| 175 | +} | |