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

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

116 lines 4.7 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, 1);
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 $id
47 * @return string|void
48 */
49 public function set_meta_title($title, $seperator = ' &ndash; ', $location = 'right') {
50 global $photonic_page_meta_title, $photonic_gallery_template_page;
51 $id = get_queried_object_id();
52
53 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
54 $album_title = wptexturize(stripslashes_deep(wp_kses_post($_REQUEST['photonic_gallery_title']))); // phpcs:ignore WordPress.Security.NonceVerification
55
56 if ('replace-if-available' === $photonic_page_meta_title) {
57 return $album_title;
58 }
59 elseif ('append-if-available' === $photonic_page_meta_title) {
60 return $title . $seperator;// . ' - ';// . $album_title;
61 }
62 elseif ('prepend-if-available' === $photonic_page_meta_title) {
63 return $album_title . ' &ndash; ' . $title;
64 }
65 }
66
67 return $title;
68 }
69
70 /**
71 * Changes the content of the template page to have the description and contents of the gallery.
72 *
73 * @param $content
74 * @return string
75 */
76 public function load_gallery($content) {
77 global $photonic_gallery_template_page;
78 if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page)) {
79 // Cannot check nonce for front-end gallery, but will vet the request fully
80 if (isset($_REQUEST['photonic_gallery'])) { // phpcs:ignore WordPress.Security.NonceVerification
81 global $photonic_alternative_shortcode;
82
83 $shortcode_tag = esc_attr($photonic_alternative_shortcode ?: 'gallery');
84 $shortcode = sanitize_text_field($_REQUEST['photonic_gallery']); // phpcs:ignore WordPress.Security.NonceVerification
85 $shortcode = base64_decode($shortcode); // The `encode` is defined in Core.php's get_gallery_url method. We check this in the following steps.
86
87 // Input is coming via a URL, so we have to ensure it is safe.
88 // The input is expected to be a Photonic shortcode, so the simplest way is to strip out all instances of the Photonic
89 // shortcode and verify that the input is blank. If it is blank, then all that the input had was a Photonic shortcode.
90 $content_without_shortcodes = strip_shortcodes($shortcode);
91 if (!empty(trim($shortcode)) && has_shortcode($shortcode, $shortcode_tag) && empty(trim($content_without_shortcodes))) {
92 // Looks good. Let's proceed.
93 global $photonic_page_content;
94 if ('replace-if-available' === $photonic_page_content) {
95 $content = do_shortcode($shortcode);
96 }
97 elseif ('append-if-available' === $photonic_page_content) {
98 $content .= do_shortcode($shortcode);
99 }
100 }
101 else {
102 // Input looks funny. Stay safe and exit
103 $content .= esc_html__('You are trying to display a gallery, but no gallery was found corresponding to the input.', 'photonic');
104 }
105 }
106 else {
107 // Input is blank. Show nothing and exit
108 $content .= esc_html__('You are trying to display a gallery, but no input was provided.', 'photonic');
109 }
110 }
111 return $content;
112 }
113 }
114
115 new Template();
116