PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.36
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.36
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
← All changes | Layouts/Core_Layout.php +162 -25 2.413.36 View file →
@@ -1,8 +1,12 @@
1 1 <?php
2 +
2 3 namespace Photonic_Plugin\Layouts;
3 4
4 -use Photonic_Plugin\Modules\Core;
5 +use Photonic_Plugin\Components\Header;
6 +use Photonic_Plugin\Components\Single_Photo;
7 +use Photonic_Plugin\Core\Photonic;
8 +use Photonic_Plugin\Platforms\Base;
5 9
6 10 /**
7 11 * 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 12 * modified by JS on the front-end, however the base markup for it is similar to the square and circular thumbnails layout.
@@ -7,56 +11,63 @@
7 11 * 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 12 * modified by JS on the front-end, however the base markup for it is similar to the square and circular thumbnails layout.
9 13 *
10 14 * All other layout managers extend this, and might implement their own versions of generate_level_1_gallery and generate_level_2_gallery
11 - *
12 15 */
13 16 abstract class Core_Layout {
14 - protected $library;
17 + protected ?string $library;
18 + protected array $common_parameters = [];
19 + protected string $prompt_title;
20 + protected string $prompt_submit;
21 + protected string $prompt_text;
15 22
16 23 protected function __construct() {
17 - global $photonic_slideshow_library, $photonic_custom_lightbox;
18 - if ($photonic_slideshow_library != 'custom') {
19 - $this->library = $photonic_slideshow_library;
24 + $this->library = esc_attr(Photonic::$library);
25 +
26 + $this->prompt_title = esc_attr__('Protected Content', 'photonic');
27 + $this->prompt_submit = esc_attr__('Access', 'photonic');
28 + $this->prompt_text = esc_attr__('This album is password-protected. Please provide a valid password.', 'photonic');
29 + }
30 +
31 + final public static function get_instance() {
32 + static $instances = array();
33 + $called_class = get_called_class();
34 +
35 + if (!isset($instances[$called_class])) {
36 + $instances[$called_class] = new $called_class();
20 37 }
21 - else {
22 - $this->library = $photonic_custom_lightbox;
23 - }
38 + return $instances[$called_class];
24 39 }
25 40
26 41 /**
27 42 * Generates the markup for a single photo.
28 43 *
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
44 + * @param Single_Photo $photo Pertinent pieces of information about the photo - the source (src), the photo page (href), title and caption.
45 + * @param Base $module The object calling this. A CSS class is created in the header, photonic-single-<code>$module->provider</code>-photo-header.
31 46 * @return string
32 47 */
33 - function generate_single_photo_markup($data, $module) {
48 + public function generate_single_photo_markup(Single_Photo $photo, Base $module): string {
34 49 $module->push_to_stack('Generate single photo markup');
35 50 $ret = '';
36 - $photo = array_merge(
37 - ['src' => '', 'href' => '', 'title' => '', 'caption' => ''],
38 - $data
39 - );
40 51
41 - if (empty($photo['src'])) {
52 + if (empty($photo->src)) {
42 53 $module->pop_from_stack();
43 54 return $ret;
44 55 }
45 56
46 57 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";
58 + if (!empty($photo->title)) {
59 + $ret .= "\t" . '<h3 class="photonic-single-photo-header photonic-single-' . $module->provider . '-photo-header">' . $photo->title . "</h3>\n";
49 60 }
50 61
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>';
62 + $img = '<img src="' . esc_url($photo->src) . '" alt="' . esc_attr($photo->caption ?: $photo->title) . '" loading="eager"/>';
63 + if (!empty($photo->href)) {
64 + $img = '<a href="' . esc_url($photo->href) . '" title="' . esc_attr($photo->caption ?: $photo->title) . '" ' .
65 + (!empty($photonic_external_links_in_new_tab) ? ' target="_blank" ' : '') . '>' . $img . '</a>';
55 66 }
56 67
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";
68 + if (!empty($photo->caption)) {
69 + $ret .= "\t" . '<div class="wp-caption">' . "\n\t\t" . $img . "\n\t\t" . '<div class="wp-caption-text">' . wp_kses_post($photo->caption) . "</div>\n\t</div><!-- .wp-caption -->\n";
59 70 }
60 71 else {
61 72 $ret .= $img;
62 73 }
@@ -62,6 +73,132 @@
62 73 }
63 74
64 75 $module->pop_from_stack();
65 76 return $ret;
77 + }
78 +
79 + /**
80 + * Generates the markup for a <code>Header</code> element. A header typically consists of a thumbnail, a title and some
81 + * information about the child counts.
82 + *
83 + * @param Header $header
84 + * @param Base $module
85 + * @return string
86 + */
87 + public function generate_header_markup(Header $header, Base $module): string {
88 + if ('lightbox' === $header->display_location || $this instanceof Slideshow) {
89 + return '';
90 + }
91 +
92 + $ret = '';
93 + global $photonic_gallery_template_page, $photonic_page_content;
94 +
95 + if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page) && in_array($photonic_page_content, ['replace-if-available', 'append-if-available'], true)) {
96 + $ret = wptexturize(wp_kses_post($header->description));
97 + }
98 + elseif ((empty($photonic_gallery_template_page) ||
99 + !is_page() ||
100 + (is_page() && !empty($photonic_gallery_template_page) && !is_page($photonic_gallery_template_page))) &&
101 + !empty($header->title)) {
102 + global $photonic_external_links_in_new_tab;
103 + $title = esc_attr($header->title);
104 +
105 + if (!empty($photonic_external_links_in_new_tab)) {
106 + $target = ' target="_blank" ';
107 + }
108 + else {
109 + $target = '';
110 + }
111 +
112 + $anchor = '';
113 + if (!empty($header->thumb_url)) {
114 + $image = '<img src="' . esc_url($header->thumb_url) . '" alt="' . $title . '" />';
115 +
116 + if ($header->enable_link) {
117 + $anchor = "<a href='" . esc_url($header->page_url) . "' class='photonic-header-thumb photonic-{$module->provider}-{$header->header_for}-solo-thumb' title='" . $title . "' $target>" . $image . "</a>";
118 + }
119 + else {
120 + $anchor = "<div class='photonic-header-thumb photonic-{$module->provider}-{$header->header_for}-solo-thumb'>$image</div>";
121 + }
122 + }
123 +
124 + if (empty($header->hidden_elements['thumbnail']) || empty($header->hidden_elements['title']) || empty($header->hidden_elements['counter']) || empty($header->iterate_level_3)) {
125 + $popup_header_class = '';
126 + if ('modal' === $header->display_location) {
127 + $popup_header_class = 'photonic-panel-header';
128 + }
129 + $ret .= "<header class='photonic-object-header photonic-{$module->provider}-{$header->header_for} $popup_header_class'>";
130 +
131 + if (empty($header->hidden_elements['thumbnail'])) {
132 + $ret .= $anchor;
133 + }
134 + if (empty($header->hidden_elements['title']) || empty($header->hidden_elements['counter']) || empty($header->iterate_level_3)) {
135 + $ret .= "<div class='photonic-header-details photonic-{$header->header_for}-details'>";
136 + if (empty($header->hidden_elements['title']) || empty($header->iterate_level_3)) {
137 + $expand = empty($header->iterate_level_3) ? '<a href="#" title="' . esc_attr__('Show', 'photonic') . '" class="photonic-level-3-expand photonic-level-3-expand-plus" data-photonic-level-3="' . $module->provider . '-' . $header->header_for . '-' . $header->id . '" data-photonic-layout="' . $header->layout . '">&nbsp;</a>' : '';
138 +
139 + if ($header->enable_link) {
140 + $ret .= "<div class='photonic-header-title photonic-{$header->header_for}-title'><a href='" . esc_url($header->page_url) . "' $target>" . wptexturize($title) . '</a>' . $expand . '</div>';
141 + }
142 + else {
143 + $ret .= "<div class='photonic-header-title photonic-{$header->header_for}-title'>" . wptexturize($title) . $expand . '</div>';
144 + }
145 + }
146 +
147 + if (empty($header->hidden_elements['counter'])) {
148 + $counter_texts = [];
149 + if (!empty($header->counters['groups'])) {
150 + $counter_texts[] = esc_html(sprintf(_n('%s group', '%s groups', $header->counters['groups'], 'photonic'), $header->counters['groups']));
151 + }
152 + if (!empty($header->counters['sets'])) {
153 + $counter_texts[] = esc_html(sprintf(_n('%s set', '%s sets', $header->counters['sets'], 'photonic'), $header->counters['sets']));
154 + }
155 + if (!empty($header->counters['photos'])) {
156 + $counter_texts[] = esc_html(sprintf(_n('%s photo', '%s photos', $header->counters['photos'], 'photonic'), $header->counters['photos']));
157 + }
158 + if (!empty($header->counters['videos'])) {
159 + $counter_texts[] = esc_html(sprintf(_n('%s video', '%s videos', $header->counters['videos'], 'photonic'), $header->counters['videos']));
160 + }
161 +
162 + apply_filters('photonic_modify_counter_texts', $counter_texts, $header->counters);
163 +
164 + if (!empty($counter_texts)) {
165 + $ret .= "<span class='photonic-header-info photonic-{$header->header_for}-photos'>" . implode(', ', $counter_texts) . '</span>';
166 + }
167 + }
168 +
169 + $ret .= "</div><!-- .photonic-{$header->header_for}-details -->";
170 + }
171 + $ret .= "</header>";
172 + }
173 + }
174 + return $ret;
175 + }
176 +
177 + /**
178 + * @return string|void
179 + */
180 + public function get_library(): string {
181 + return $this->library;
182 + }
183 +
184 + public function get_title($title, $titles = [], $short_code = []): string {
185 + if (empty($short_code['caption']) || 'none' === $short_code['caption']) {
186 + return '';
187 + }
188 + else {
189 + $priority = explode('-', $short_code['caption']);
190 + if (count($priority) === 1) {
191 + return $titles[$priority[0]] ?? '';
192 + }
193 + else {
194 + foreach ($priority as $p) {
195 + if (!empty($titles[$p])) {
196 + return $titles[$p];
197 + }
198 + }
199 + }
200 + }
201 +
202 + return $title;
66 203 }
67 204 }