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