| 1 |
<?php |
| 2 |
namespace Photonic_Plugin\Core; |
| 3 |
|
| 4 |
class Utilities { |
| 5 |
public static function get_formatted_post_type_array() { |
| 6 |
global $photonic_post_type_array; |
| 7 |
$ret = []; |
| 8 |
|
| 9 |
$post_types = get_post_types(['show_ui' => 1], 'objects'); |
| 10 |
if (!empty($post_types)) { |
| 11 |
foreach ($post_types as $name => $post_type) { |
| 12 |
$ret[$name] = ["title" => $post_type->label." (Post type: $name)", "depth" => 0]; |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
$photonic_post_type_array = $ret; |
| 17 |
return $ret; |
| 18 |
} |
| 19 |
|
| 20 |
public static function get_pages() { |
| 21 |
$pages = get_pages(); |
| 22 |
$output = [ |
| 23 |
'' => '', |
| 24 |
]; |
| 25 |
foreach ($pages as $page) { |
| 26 |
$output[$page->ID] = $page->post_title; |
| 27 |
} |
| 28 |
return $output; |
| 29 |
} |
| 30 |
|
| 31 |
public static function title_caption_options($blank = false, $selection = false) { |
| 32 |
$ret = [ |
| 33 |
'' => esc_html__('Default from settings', 'photonic'), |
| 34 |
'none' => esc_html__('No title / caption / description', 'photonic'), |
| 35 |
'title' => esc_html__('Always use the photo title, even if blank', 'photonic'), |
| 36 |
'desc' => esc_html__('Always use the photo description / caption, even if blank', 'photonic'), |
| 37 |
'desc-title' => esc_html__('Use the photo description / caption. If blank use the title', 'photonic'), |
| 38 |
'title-desc' => esc_html__('Use the photo title. If blank use the description / caption', 'photonic'), |
| 39 |
]; |
| 40 |
|
| 41 |
if (!$blank) { |
| 42 |
unset($ret['']); |
| 43 |
} |
| 44 |
else if (!empty($ret[$selection])) { |
| 45 |
$ret[''] .= ' - '.$ret[$selection]; |
| 46 |
} |
| 47 |
|
| 48 |
return $ret; |
| 49 |
} |
| 50 |
|
| 51 |
public static function layout_options($show_blank = false, $blank_text = '') { |
| 52 |
$ret = []; |
| 53 |
if ($show_blank) { |
| 54 |
$ret[''] = $blank_text; |
| 55 |
} |
| 56 |
return array_merge($ret, [ |
| 57 |
'strip-below' => esc_html__('Thumbnail strip below slideshow', 'photonic'), |
| 58 |
'strip-above' => esc_html__('Thumbnail strip above slideshow', 'photonic'), |
| 59 |
'strip-right' => esc_html__('Thumbnail strip to the right of the slideshow', 'photonic'), |
| 60 |
'no-strip' => esc_html__('Slideshow without thumbnails', 'photonic'), |
| 61 |
'square' => esc_html__('Square thumbnail grid, lightbox', 'photonic'), |
| 62 |
'circle' => esc_html__('Circular thumbnail grid, lightbox', 'photonic'), |
| 63 |
'random' => esc_html__('Random justified gallery, lightbox', 'photonic'), |
| 64 |
'masonry' => esc_html__('Masonry layout, lightbox', 'photonic'), |
| 65 |
'mosaic' => esc_html__('Mosaic layout, lightbox', 'photonic'), |
| 66 |
]); |
| 67 |
} |
| 68 |
|
| 69 |
public static function media_options($blank = false, $selection = false) { |
| 70 |
$options = [ |
| 71 |
'' => esc_html__('Default from settings', 'photonic'), |
| 72 |
'photos' => esc_html__('Photos only', 'photonic'), |
| 73 |
'videos' => esc_html__('Videos only', 'photonic'), |
| 74 |
'all' => esc_html__('Both photos and videos', 'photonic'), |
| 75 |
]; |
| 76 |
|
| 77 |
if (!$blank) { |
| 78 |
unset($options['']); |
| 79 |
} |
| 80 |
else if (!empty($options[$selection])) { |
| 81 |
$options[''] .= ' - '.$options[$selection]; |
| 82 |
} |
| 83 |
|
| 84 |
return $options; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* @param $show_full |
| 89 |
* @param bool $return_formatted |
| 90 |
* @return array |
| 91 |
*/ |
| 92 |
public static function get_wp_image_sizes($show_full, $return_formatted = false) { |
| 93 |
global $_wp_additional_image_sizes; |
| 94 |
$image_sizes = []; |
| 95 |
$standard_sizes = ['thumbnail', 'medium', 'large']; |
| 96 |
if ($show_full) { |
| 97 |
$standard_sizes[] = 'full'; |
| 98 |
} |
| 99 |
foreach ($standard_sizes as $standard_size) { |
| 100 |
if ($standard_size != 'full') { |
| 101 |
$image_sizes[$standard_size] = ['width' => get_option($standard_size . '_size_w'), 'height' => get_option($standard_size . '_size_h')]; |
| 102 |
} |
| 103 |
else { |
| 104 |
$image_sizes[$standard_size] = ['width' => esc_html__('Original width', 'photonic'), 'height' => esc_html__('Original height', 'photonic')]; |
| 105 |
} |
| 106 |
} |
| 107 |
if (is_array($_wp_additional_image_sizes)) { |
| 108 |
$image_sizes = array_merge($image_sizes, $_wp_additional_image_sizes); |
| 109 |
} |
| 110 |
|
| 111 |
if ($return_formatted) { |
| 112 |
$formatted = []; |
| 113 |
foreach ($image_sizes as $size_name => $size_attrs) { |
| 114 |
$formatted[$size_name] = "$size_name ({$size_attrs['width']} × {$size_attrs['height']})"; |
| 115 |
} |
| 116 |
return $formatted; |
| 117 |
} |
| 118 |
return $image_sizes; |
| 119 |
} |
| 120 |
} |