| 1 |
<?php |
| 2 |
|
| 3 |
namespace Photonic_Plugin\Admin\Wizard; |
| 4 |
|
| 5 |
use Photonic_Plugin\Core\Utilities; |
| 6 |
|
| 7 |
class WP extends Source { |
| 8 |
private static ?WP $instance = null; |
| 9 |
|
| 10 |
protected function __construct() { |
| 11 |
parent::__construct(); |
| 12 |
$this->provider = 'wp'; |
| 13 |
$this->allowed_image_sizes['wp'] = [ |
| 14 |
'thumb_size' => Utilities::get_wp_image_sizes(false, true), |
| 15 |
'tile_size' => Utilities::get_wp_image_sizes(true, true), |
| 16 |
'main_size' => Utilities::get_wp_image_sizes(true, true), |
| 17 |
]; |
| 18 |
} |
| 19 |
|
| 20 |
public static function get_instance(): WP { |
| 21 |
if (null === self::$instance) { |
| 22 |
self::$instance = new WP(); |
| 23 |
} |
| 24 |
return self::$instance; |
| 25 |
} |
| 26 |
|
| 27 |
public function get_screen_2(): array { |
| 28 |
return [ |
| 29 |
'header' => esc_html__('Choose Type of Gallery', 'photonic'), |
| 30 |
'display' => [ |
| 31 |
'display_type' => [ |
| 32 |
'desc' => esc_html__('What do you want to show?', 'photonic'), |
| 33 |
'type' => 'select', |
| 34 |
'options' => [ |
| 35 |
'' => '', |
| 36 |
'current-post' => esc_html__('Gallery attached to the current post', 'photonic'), |
| 37 |
'multi-photo' => esc_html__('Photos from Media Library', 'photonic'), |
| 38 |
], |
| 39 |
'req' => 1, |
| 40 |
], |
| 41 |
], |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
public function get_screen_3(): array { |
| 46 |
return []; |
| 47 |
} |
| 48 |
|
| 49 |
public function get_screen_4(): array { |
| 50 |
return []; |
| 51 |
} |
| 52 |
|
| 53 |
public function get_screen_5(): array { |
| 54 |
return [ |
| 55 |
'wp' => [ |
| 56 |
'count' => [ |
| 57 |
'desc' => esc_html__('Number of photos to show', 'photonic'), |
| 58 |
'type' => 'text', |
| 59 |
'hint' => esc_html__('Numeric values only. Shows all photos by default.', 'photonic'), |
| 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 |
], |
| 91 |
'main_size' => [ |
| 92 |
'desc' => esc_html__('Main image size', 'photonic'), |
| 93 |
'type' => 'select', |
| 94 |
'options' => $this->allowed_image_sizes['wp']['main_size'], |
| 95 |
'std' => 'full', |
| 96 |
], |
| 97 |
] |
| 98 |
]; |
| 99 |
} |
| 100 |
|
| 101 |
public function get_square_size_options(): array { |
| 102 |
return [ |
| 103 |
'thumb_size' => [ |
| 104 |
'desc' => esc_html__('Thumbnail size', 'photonic'), |
| 105 |
'type' => 'select', |
| 106 |
'options' => $this->allowed_image_sizes['wp']['thumb_size'], |
| 107 |
'std' => 'thumbnail', |
| 108 |
], |
| 109 |
]; |
| 110 |
} |
| 111 |
|
| 112 |
public function get_random_size_options(): array { |
| 113 |
return [ |
| 114 |
'tile_size' => [ |
| 115 |
'desc' => esc_html__('Tile size', 'photonic'), |
| 116 |
'type' => 'select', |
| 117 |
'options' => $this->allowed_image_sizes['wp']['tile_size'], |
| 118 |
'std' => 'full', |
| 119 |
], |
| 120 |
]; |
| 121 |
} |
| 122 |
|
| 123 |
public function make_request($display_type, $for, $flattened_fields): array { |
| 124 |
return []; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Blank for WP, since there is nothing to do. |
| 129 |
* |
| 130 |
* @param $response |
| 131 |
* @param $display_type |
| 132 |
* @param null $url |
| 133 |
* @param array $pagination |
| 134 |
* @return array |
| 135 |
*/ |
| 136 |
public function process_response($response, $display_type, $url = null, &$pagination = []): array { |
| 137 |
return []; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* @param $display_type |
| 142 |
* @return array |
| 143 |
*/ |
| 144 |
public function construct_shortcode_from_screen_selections($display_type): array { |
| 145 |
$short_code = []; |
| 146 |
|
| 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 |
} |
| 154 |
} |
| 155 |
return $short_code; |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* @param $input |
| 160 |
* @return array |
| 161 |
*/ |
| 162 |
public function deconstruct_shortcode_to_screen_selections($input): array { |
| 163 |
$deconstructed = []; |
| 164 |
|
| 165 |
if (empty($input->id) && empty($input->ids) && empty($input->include)) { |
| 166 |
$deconstructed['display_type'] = 'current-post'; |
| 167 |
} |
| 168 |
elseif (!empty($input->ids) || !empty($input->include)) { |
| 169 |
$deconstructed['display_type'] = 'multi-photo'; |
| 170 |
$deconstructed['selected_data'] = !empty($input->ids) ? $input->ids : $input->include; |
| 171 |
} |
| 172 |
|
| 173 |
return $deconstructed; |
| 174 |
} |
| 175 |
} |
| 176 |
|