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 / Gallery.php

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

134 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 use Photonic_Plugin\Layouts\Core_Layout;
6 use Photonic_Plugin\Layouts\Grid;
7 use Photonic_Plugin\Layouts\Slideshow;
8 use Photonic_Plugin\Platforms\Base;
9 use Photonic_Plugin\Platforms\Flickr;
10 use Photonic_Plugin\Platforms\Google_Photos;
11 use Photonic_Plugin\Platforms\Instagram;
12 use Photonic_Plugin\Platforms\Native;
13 use Photonic_Plugin\Platforms\SmugMug;
14 use Photonic_Plugin\Platforms\Zenfolio;
15 use Photonic_Plugin\Platforms\DeviantArt;
16
17 class Gallery {
18 private array $attr;
19 /** @var Base */
20 private Base $module;
21
22 /** @var Core_Layout */
23 private Core_Layout $layout;
24
25 public function __construct($attr) {
26 $this->attr = $attr;
27 $type = $this->attr['type'];
28
29 $this->set_platform($type);
30
31 if ((!empty($attr['layout']) && in_array($type, ['flickr', 'smugmug', 'google', 'zenfolio', 'instagram', 'deviantart'], true) && in_array($attr['layout'], ['strip-above', 'strip-below', 'strip-right', 'no-strip'], true)) ||
32 (!empty($attr['style']) && in_array($type, ['default', 'wp'], true) && in_array($attr['style'], ['strip-above', 'strip-below', 'strip-right', 'no-strip'], true))) {
33 require_once PHOTONIC_PATH . '/Layouts/Slideshow.php';
34 $this->layout = Slideshow::get_instance();
35 }
36 else {
37 require_once PHOTONIC_PATH . '/Layouts/Grid.php';
38 $this->layout = Grid::get_instance();
39 }
40 }
41
42 private function set_platform(?string $type) {
43 if ('flickr' === $type) {
44 require_once PHOTONIC_PATH . "/Platforms/Flickr.php";
45 $this->module = Flickr::get_instance();
46 }
47 elseif ('smugmug' === $type || 'smug' === $type) {
48 require_once PHOTONIC_PATH . "/Platforms/SmugMug.php";
49 $this->module = SmugMug::get_instance();
50 }
51 elseif ('google' === $type) {
52 require_once PHOTONIC_PATH . "/Platforms/Google_Photos.php";
53 $this->module = Google_Photos::get_instance();
54 }
55 elseif ('instagram' === $type) {
56 require_once PHOTONIC_PATH . "/Platforms/Instagram.php";
57 $this->module = Instagram::get_instance();
58 }
59 elseif ('zenfolio' === $type) {
60 require_once PHOTONIC_PATH . "/Platforms/Zenfolio.php";
61 $this->module = Zenfolio::get_instance();
62 }
63 elseif ('deviantart' === $type) {
64 require_once PHOTONIC_PATH . "/Platforms/DeviantArt.php";
65 $this->module = DeviantArt::get_instance();
66 }
67 else {
68 require_once PHOTONIC_PATH . "/Platforms/Native.php";
69 $this->module = Native::get_instance();
70 }
71 }
72
73 /**
74 * Fetch the contents of a gallery. This first invokes the <code>get_gallery_images</code> method for each platform.
75 * Once the results are obtained, this method prints out the results.
76 *
77 * @return string
78 */
79 public function get_contents(): string {
80 $this->module->increment_gallery_index();
81 $contents = $this->module->get_gallery_images($this->attr);
82
83 $output = '';
84 if (is_array($contents)) {
85 foreach ($contents as $component) {
86 if (method_exists($component, 'html')) {
87 $output .= $component->html($this->module, $this->layout);
88 }
89 else {
90 $output .= $component;
91 }
92 }
93
94 // Special case --> when a native gallery is called with no <code>style</code> attribute, or if <code>style='default'</code>...
95 if (empty($output)) {
96 return '';
97 }
98
99 return $this->finalize_markup($output);
100 }
101 return $output;
102 }
103
104 public function get_helper_contents(): string {
105 return $this->module->execute_helper($this->attr);
106 }
107
108 /**
109 * Wraps the output of a gallery in markup tags indicating that it is a Photonic gallery.
110 *
111 * @param $content
112 * @return string
113 */
114 public function finalize_markup($content): string {
115 if ('modal' !== $this->attr['display']) {
116 $additional_classes = '';
117 if (!empty($this->attr['custom_classes'])) {
118 $additional_classes = $this->attr['custom_classes'];
119 }
120 if (!empty($this->attr['alignment'])) {
121 $additional_classes .= ' align' . $this->attr['alignment'];
122 }
123 $ret = "<div class='photonic-{$this->module->provider}-stream photonic-stream $additional_classes' id='photonic-{$this->module->provider}-stream-{$this->module->gallery_index}'>\n";
124 }
125 else {
126 $popup_id = "id='photonic-{$this->module->provider}-panel-" . $this->attr['panel'] . "'";
127 $ret = "<div class='photonic-{$this->module->provider}-panel photonic-panel' $popup_id>\n";
128 }
129 $ret .= $content . "\n";
130 $ret .= "</div><!-- .photonic-stream or .photonic-panel -->\n";
131 return $ret;
132 }
133 }
134