PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.41
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.41
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 2.41, at Core/Template.php

77 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Photonic_Plugin\Core;
3
4 /**
5 * Class Template
6 * Used for cases where clicking on an album link opens a Photonic gallery on its own page. This is triggered when the shortcode attribute
7 * <code>popup='page'</code> is set
8 *
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_title'], 10, 2);
14 }
15
16 /**
17 * Changes the title of the template page to the title of the album being displayed.
18 *
19 * @param $title
20 * @param $id
21 * @return string|void
22 */
23 function set_title($title, $id) {
24 global $photonic_page_title, $photonic_gallery_template_page;
25 if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page) && $photonic_page_title == 'replace-if-available' && $id == $photonic_gallery_template_page) {
26 if (isset($_REQUEST['photonic_gallery_title'])) {
27 return esc_attr($_REQUEST['photonic_gallery_title']);
28 }
29 }
30 return $title;
31 }
32
33 /**
34 * Changes the content of the template page to have the description and contents of the gallery.
35 *
36 * @param $content
37 * @return string
38 */
39 function load_gallery($content) {
40 global $photonic_gallery_template_page;
41 if (!empty($photonic_gallery_template_page) && is_page($photonic_gallery_template_page)) {
42 if (isset($_REQUEST['photonic_gallery'])) {
43 global $photonic_alternative_shortcode;
44
45 $shortcode_tag = $photonic_alternative_shortcode ?: 'gallery';
46 $shortcode = $_REQUEST['photonic_gallery'];
47 $shortcode = base64_decode($shortcode);
48
49 // Input is coming via a URL, so we have to ensure it is safe.
50 // The input is expected to be a Photonic shortcode, so the simplest way is to strip out all instances of the Photonic
51 // shortcode and verify that the input is blank. If it is blank, then all that the input had was a Photonic shortcode.
52 $content_without_shortcodes = strip_shortcodes($shortcode);
53 if (!empty(trim($shortcode)) && has_shortcode($shortcode, $shortcode_tag) && empty(trim($content_without_shortcodes))) {
54 // Looks good. Let's proceed.
55 global $photonic_page_content;
56 if ($photonic_page_content == 'replace-if-available') {
57 $content = do_shortcode($shortcode);
58 }
59 else if ($photonic_page_content == 'append-if-available') {
60 $content .= do_shortcode($shortcode);
61 }
62 }
63 else {
64 // Input looks funny. Stay safe and exit
65 $content .= esc_html__('You are trying to display a gallery, but no gallery was found corresponding to the input.', 'photonic');
66 }
67 }
68 else {
69 // Input is blank. Show nothing and exit
70 $content .= esc_html__('You are trying to display a gallery, but no input was provided.', 'photonic');
71 }
72 }
73 return $content;
74 }
75 }
76
77 new Template();