PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.31
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.31
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 2.45 All 140 releases
photonic / Core / Template.php

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

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