PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.33
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.33
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
photonic / Layouts / Core_Layout.php

Core_Layout.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.33, at Layouts/Core_Layout.php

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