| 1 |
<?php |
| 2 |
namespace Photonic_Plugin\Layouts; |
| 3 |
|
| 4 |
use Photonic_Plugin\Modules\Core; |
| 5 |
|
| 6 |
/** |
| 7 |
* Layout Manager to generate the grid layouts and the "Justified Grid" layout, all of which use the same markup. The Justified Grid layout is |
| 8 |
* modified by JS on the front-end, however the base markup for it is similar to the square and circular thumbnails layout. |
| 9 |
* |
| 10 |
* All other layout managers extend this, and might implement their own versions of generate_level_1_gallery and generate_level_2_gallery |
| 11 |
* |
| 12 |
*/ |
| 13 |
abstract class Core_Layout { |
| 14 |
protected $library; |
| 15 |
|
| 16 |
protected function __construct() { |
| 17 |
global $photonic_slideshow_library, $photonic_custom_lightbox; |
| 18 |
if ($photonic_slideshow_library != 'custom') { |
| 19 |
$this->library = $photonic_slideshow_library; |
| 20 |
} |
| 21 |
else { |
| 22 |
$this->library = $photonic_custom_lightbox; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Generates the markup for a single photo. |
| 28 |
* |
| 29 |
* @param $data array Pertinent pieces of information about the photo - the source (src), the photo page (href), title and caption |
| 30 |
* @param $module Core The object calling this. A CSS class is created in the header, photonic-single-<code>$module->provider</code>-photo-header |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
function generate_single_photo_markup($data, $module) { |
| 34 |
$module->push_to_stack('Generate single photo markup'); |
| 35 |
$ret = ''; |
| 36 |
$photo = array_merge( |
| 37 |
['src' => '', 'href' => '', 'title' => '', 'caption' => ''], |
| 38 |
$data |
| 39 |
); |
| 40 |
|
| 41 |
if (empty($photo['src'])) { |
| 42 |
$module->pop_from_stack(); |
| 43 |
return $ret; |
| 44 |
} |
| 45 |
|
| 46 |
global $photonic_external_links_in_new_tab; |
| 47 |
if (!empty($photo['title'])) { |
| 48 |
$ret .= "\t".'<h3 class="photonic-single-photo-header photonic-single-'.$module->provider.'-photo-header">'.$photo['title']."</h3>\n"; |
| 49 |
} |
| 50 |
|
| 51 |
$img = '<img src="'.$photo['src'].'" alt="'.esc_attr(empty($photo['caption']) ? $photo['title'] : $photo['caption']).'" loading="eager"/>'; |
| 52 |
if (!empty($photo['href'])) { |
| 53 |
$img = '<a href="'.esc_url($photo['href']).'" title="'.esc_attr(empty($photo['caption']) ? $photo['title'] : $photo['caption']).'" '. |
| 54 |
(!empty($photonic_external_links_in_new_tab) ? ' target="_blank" ' : '').'>'.$img.'</a>'; |
| 55 |
} |
| 56 |
|
| 57 |
if (!empty($photo['caption'])) { |
| 58 |
$ret .= "\t".'<div class="wp-caption">'."\n\t\t".$img."\n\t\t".'<div class="wp-caption-text">'.$photo['caption']."</div>\n\t</div><!-- .wp-caption -->\n"; |
| 59 |
} |
| 60 |
else { |
| 61 |
$ret .= $img; |
| 62 |
} |
| 63 |
|
| 64 |
$module->pop_from_stack(); |
| 65 |
return $ret; |
| 66 |
} |
| 67 |
} |
| 68 |
|