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
photonic / Core / Template.php

Template.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.36, at Core/Template.php

117 lines 4.8 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\Core;
4
5 /**
6 * Class Template
7 * Used for cases where clicking on an album link opens a Photonic gallery on its own page. This is triggered when the shortcode attribute
8 * <code>popup='page'</code> is set
9 */
10 class Template {
11 public function __construct() {
12 add_filter('the_content', [&$this, 'load_gallery'], 100);
13 add_filter('the_title', [&$this, 'set_header_title'], 10, 2);
14
15 /*
16 add_filter('wp_title', [&$this, 'set_meta_title'], 10, 3);
17 if (current_theme_supports('title-tag')) {
18 add_filter('pre_get_document_title', [&$this, 'set_meta_title'], 10, 1);
19 }
20 */
21 }
22
23 /**
24 * Changes the title of the template page to the title of the album being displayed.
25 *
26 * @param $title
27 * @param $id
28 * @return string|void
29 */
30 public function set_header_title($title, $id = null) {
31 global $photonic_page_title, $photonic_gallery_template_page;
32 if (!empty($id)) {
33 if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page) && 'replace-if-available' === $photonic_page_title && absint($photonic_gallery_template_page) === absint($id)) {
34 if (isset($_REQUEST['photonic_gallery_title'])) { // phpcs:ignore WordPress.Security.NonceVerification
35 return wptexturize(stripslashes_deep(wp_kses_post($_REQUEST['photonic_gallery_title']))); // phpcs:ignore WordPress.Security.NonceVerification
36 }
37 }
38 }
39 return $title;
40 }
41
42 /**
43 * Changes the title of the template page to the title of the album being displayed.
44 *
45 * @param $title
46 * @param string $seperator
47 * @param string $location
48 * @return string|void
49 */
50 public function set_meta_title($title, $seperator = ' &ndash; ', $location = 'right') {
51 global $photonic_page_meta_title, $photonic_gallery_template_page;
52 $id = get_queried_object_id();
53
54 if (!empty($_REQUEST['photonic_gallery_title']) && !empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page) && 'page' !== $photonic_page_meta_title && absint($photonic_gallery_template_page) === absint($id)) { // phpcs:ignore WordPress.Security.NonceVerification
55 $album_title = wptexturize(stripslashes_deep(wp_kses_post($_REQUEST['photonic_gallery_title']))); // phpcs:ignore WordPress.Security.NonceVerification
56
57 if ('replace-if-available' === $photonic_page_meta_title) {
58 return $album_title;
59 }
60 elseif ('append-if-available' === $photonic_page_meta_title) {
61 return $title . $seperator;// . ' - ';// . $album_title;
62 }
63 elseif ('prepend-if-available' === $photonic_page_meta_title) {
64 return $album_title . ' &ndash; ' . $title;
65 }
66 }
67
68 return $title;
69 }
70
71 /**
72 * Changes the content of the template page to have the description and contents of the gallery.
73 *
74 * @param $content
75 * @return string
76 */
77 public function load_gallery($content): string {
78 global $photonic_gallery_template_page;
79 if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page)) {
80 // Cannot check nonce for front-end gallery, but will vet the request fully
81 if (isset($_REQUEST['photonic_gallery'])) { // phpcs:ignore WordPress.Security.NonceVerification
82 global $photonic_alternative_shortcode;
83
84 $shortcode_tag = esc_attr($photonic_alternative_shortcode ?: 'gallery');
85 $shortcode = sanitize_text_field($_REQUEST['photonic_gallery']); // phpcs:ignore WordPress.Security.NonceVerification
86 $shortcode = base64_decode($shortcode); // The `encode` is defined in Core.php's get_gallery_url method. We check this in the following steps.
87
88 // Input is coming via a URL, so we have to ensure it is safe.
89 // The input is expected to be a Photonic shortcode, so the simplest way is to strip out all instances of the Photonic
90 // shortcode and verify that the input is blank. If it is blank, then all that the input had was a Photonic shortcode.
91 $content_without_shortcodes = strip_shortcodes($shortcode);
92 if (!empty(trim($shortcode)) && has_shortcode($shortcode, $shortcode_tag) && empty(trim($content_without_shortcodes))) {
93 // Looks good. Let's proceed.
94 global $photonic_page_content;
95 if ('replace-if-available' === $photonic_page_content) {
96 $content = do_shortcode($shortcode);
97 }
98 elseif ('append-if-available' === $photonic_page_content) {
99 $content .= do_shortcode($shortcode);
100 }
101 }
102 else {
103 // Input looks funny. Stay safe and exit
104 $content .= esc_html__('You are trying to display a gallery, but no gallery was found corresponding to the input.', 'photonic');
105 }
106 }
107 else {
108 // Input is blank. Show nothing and exit
109 $content .= esc_html__('You are trying to display a gallery, but no input was provided.', 'photonic');
110 }
111 }
112 return $content;
113 }
114 }
115
116 new Template();
117