| 1 |
<?php |
| 2 |
namespace Photonic_Plugin\Admin\Wizard; |
| 3 |
|
| 4 |
use Photonic_Plugin\Core\Utilities; |
| 5 |
|
| 6 |
class WP extends Source { |
| 7 |
private static $instance; |
| 8 |
|
| 9 |
protected function __construct() { |
| 10 |
parent::__construct(); |
| 11 |
$this->provider = 'wp'; |
| 12 |
$this->allowed_image_sizes['wp'] = [ |
| 13 |
'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), |
| 16 |
]; |
| 17 |
} |
| 18 |
|
| 19 |
public static function get_instance() { |
| 20 |
if (self::$instance == null) { |
| 21 |
self::$instance = new WP(); |
| 22 |
} |
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
|
| 26 |
function get_screen_2() { |
| 27 |
return [ |
| 28 |
'header' => esc_html__('Choose Type of Gallery', 'photonic'), |
| 29 |
'display' => [ |
| 30 |
'display_type' => [ |
| 31 |
'desc' => esc_html__('What do you want to show?', 'photonic'), |
| 32 |
'type' => 'select', |
| 33 |
'options' => [ |
| 34 |
'' => '', |
| 35 |
'current-post' => esc_html__('Gallery attached to the current post', 'photonic'), |
| 36 |
'multi-photo' => esc_html__('Photos from Media Library', 'photonic'), |
| 37 |
], |
| 38 |
'req' => 1, |
| 39 |
], |
| 40 |
], |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
function get_screen_3() { |
| 45 |
return []; |
| 46 |
} |
| 47 |
|
| 48 |
function get_screen_4() { |
| 49 |
return []; |
| 50 |
} |
| 51 |
|
| 52 |
function get_screen_5() { |
| 53 |
return [ |
| 54 |
'wp' => [ |
| 55 |
'count' => [ |
| 56 |
'desc' => esc_html__('Number of photos to show', 'photonic'), |
| 57 |
'type' => 'text', |
| 58 |
'hint' => esc_html__('Numeric values only. Shows all photos by default.', 'photonic'), |
| 59 |
], |
| 60 |
'main_size' => [ |
| 61 |
'desc' => esc_html__('Main image size', 'photonic'), |
| 62 |
'type' => 'select', |
| 63 |
'options' => $this->allowed_image_sizes['wp']['main_size'], |
| 64 |
'std' => 'full', |
| 65 |
], |
| 66 |
] |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
function get_square_size_options() { |
| 71 |
return [ |
| 72 |
'thumb_size' => [ |
| 73 |
'desc' => esc_html__('Thumbnail size', 'photonic'), |
| 74 |
'type' => 'select', |
| 75 |
'options' => $this->allowed_image_sizes['wp']['thumb_size'], |
| 76 |
'std' => 'thumbnail', |
| 77 |
], |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
function get_random_size_options() { |
| 82 |
return [ |
| 83 |
'tile_size' => [ |
| 84 |
'desc' => esc_html__('Tile size', 'photonic'), |
| 85 |
'type' => 'select', |
| 86 |
'options' => $this->allowed_image_sizes['wp']['tile_size'], |
| 87 |
'std' => 'full', |
| 88 |
], |
| 89 |
]; |
| 90 |
} |
| 91 |
|
| 92 |
function make_request($display_type, $for, $flattened_fields) { |
| 93 |
return null; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Blank for WP, since there is nothing to do. |
| 98 |
* |
| 99 |
* @param $response |
| 100 |
* @param $display_type |
| 101 |
* @param null $url |
| 102 |
* @param array $pagination |
| 103 |
* @return mixed|null |
| 104 |
*/ |
| 105 |
function process_response($response, $display_type, $url = null, &$pagination = []) { |
| 106 |
return null; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* @param $display_type |
| 111 |
* @return array|mixed |
| 112 |
*/ |
| 113 |
function construct_shortcode_from_screen_selections($display_type) { |
| 114 |
$short_code = []; |
| 115 |
|
| 116 |
if ($display_type == 'current-post' && !empty($_POST['post_id'])) { |
| 117 |
$short_code['id'] = sanitize_text_field($_POST['post_id']); |
| 118 |
} |
| 119 |
else if (!empty($_POST['selected_data'])) { |
| 120 |
$short_code['ids'] = sanitize_text_field($_POST['selected_data']); |
| 121 |
} |
| 122 |
|
| 123 |
return $short_code; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* @param $input |
| 128 |
* @return array|mixed |
| 129 |
*/ |
| 130 |
function deconstruct_shortcode_to_screen_selections($input) { |
| 131 |
$deconstructed = []; |
| 132 |
|
| 133 |
if (empty($input->id) && empty($input->ids) && empty($input->include)) { |
| 134 |
$deconstructed['display_type'] = 'current-post'; |
| 135 |
} |
| 136 |
else if (!empty($input->ids) || !empty($input->include)) { |
| 137 |
$deconstructed['display_type'] = 'multi-photo'; |
| 138 |
$deconstructed['selected_data'] = !empty($input->ids) ? $input->ids : $input->include; |
| 139 |
} |
| 140 |
|
| 141 |
return $deconstructed; |
| 142 |
} |
| 143 |
} |