From 10dde41836656efd38ed8997eb074042acba9989 Mon Sep 17 00:00:00 2001 From: jetrit Date: Sat, 16 Dec 2023 11:12:57 +0100 Subject: [PATCH 1/3] adding example, and comma in readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a280a8f..b3f3a73 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,10 @@ or, if you installed Pico CMS with composer Add the following expression in your Markdown file: - (% fotofolder (/path/to/your/images [sort] [order]) %) + (% fotofolder (/path/to/your/images, [sort], [order]) %) + + E.g. + (% fotofolder (/assets/gallery, date, dsc) %) Optional arguments: - `[sort]` Can be 'date or 'name'. This will sort the images according date, which means the exif image date not the file date, or according the filename. Default is 'name'. From 0a45ae1d6cadfa3e320c2fb6f142137394c9ea6e Mon Sep 17 00:00:00 2001 From: jetrit Date: Sat, 16 Dec 2023 11:24:41 +0100 Subject: [PATCH 2/3] moving the html output to onPageRendered as markdown-extra has a problem with html snippets --- PicoFotofolder.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/PicoFotofolder.php b/PicoFotofolder.php index 0c7c35b..2cc6a48 100644 --- a/PicoFotofolder.php +++ b/PicoFotofolder.php @@ -27,7 +27,8 @@ class PicoFotofolder extends AbstractPicoPlugin { */ public function onContentLoaded(&$rawContent) { $rawContent = preg_replace_callback( '/\(%\s+' . $this->p_keyword .'\s*\(\s*(.*?)\s*\)\s+%\)/', function($match) { - + // returning the input again unless an error happens. + $out = $match[0]; if ($match[1]) { //check for GD library see #1 @@ -38,27 +39,19 @@ public function onContentLoaded(&$rawContent) { list ($this->image_src['path'], $this->image_src['sort'], $this->image_src['order']) = explode(',', str_replace('"', '', $match[1])); - + $this->image_src['path'] = trim($this->image_src['path']); $this->image_src['sort'] = trim($this->image_src['sort']); $this->image_src['order'] = trim($this->image_src['order']); if ($this->image_src['sort'] == "") $this->image_src['sort'] = 'name'; if ($this->image_src['order'] == "") $this->image_src['order'] = 'dsc'; - // handle image path if %assets_url% is used see #1 + // handle image path if %assets_url% is used see #1 $this->image_src['path'] = preg_replace('/%assets_url%/', rtrim($this->getConfig('assets_url'), "/"), $this->image_src['path']); $repl = '/http[s]?:\/\/' . $_SERVER['SERVER_NAME'] . '/'; $this->image_src['path'] = preg_replace($repl, '', $this->image_src['path']); - $img_metas = $this->readMetaArray(); - - if (count($img_metas) > 0) { - $out = $this->createOutput($img_metas); - $this->p_count++; - } - else { - $out = "no media found in: {$this->image_src['path']}"; - } + $img_metas = $this->readMetaArray(); } } return $out; @@ -69,9 +62,12 @@ public function onContentLoaded(&$rawContent) { /** * Triggered after Pico has rendered the page */ - public function onPageRendered(&$output ) { - // add required elements in head tag + public function onPageRendered(&$output) { + $img_metas = $this->readMetaArray(); + $this->p_count = count($img_metas); if ($this->p_count > 0) { + + // add required elements in head tag $jsh = ' ' . "\n"; $jsh .= ' ' . "\n"; $jsh .= ' ' . "\n"; @@ -80,6 +76,9 @@ public function onPageRendered(&$output ) { $jsh .= '' . "\n" . '' . "\n"; $output = preg_replace('/\\<\\/head\\>\s*\n\s*\\/', $jsh, $output, 1); + // add photofolder to page + $output = preg_replace('/\(%\s+' . $this->p_keyword .'.*?\s%\)/', $this->createOutput($img_metas), $output, 1); + // Add LazyLoad $jsh = '' . "\n"; $jsh .= '' . "\n" . '' . "\n"; $output = preg_replace('/\\<\\/body\\>\s*\n\s*\\<\/html\\>/', $jsh, $output, 1); + } else { + $output = preg_replace('/\(%\s+' . $this->p_keyword .'.*?\s%\)/', "no media found in: {$this->image_src['path']}", $output, 1); } } @@ -162,7 +163,7 @@ private function readMetaArray() { /***************************************************************/ private function createOutput($img_metas) { - if ( $image_src['order'] == 'asc') { + if ( $this->image_src['order'] == 'asc') { usort($img_metas, function($a, $b) { return $a[$this->image_src['sort']] <=> $b[$this->image_src['sort']]; }); From a502ba8ecb93f61ee919e535d7eb1ca17a3da08f Mon Sep 17 00:00:00 2001 From: jetrit Date: Sun, 17 Dec 2023 21:57:14 +0100 Subject: [PATCH 3/3] php 8 compatibility --- PicoFotofolder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PicoFotofolder.php b/PicoFotofolder.php index 2cc6a48..fc98c1d 100644 --- a/PicoFotofolder.php +++ b/PicoFotofolder.php @@ -105,7 +105,11 @@ private function readMetaArray() { $img_metas = array(); $pattern = '{,.}*.{[jJ][pP][gG],[jJ][pP][eE][gG],[pP][nN][gG],[gG][iI][fF],dat}'; $filelist = glob($dir . '/' . $pattern, GLOB_BRACE); - usort($filelist, create_function('$a,$b', 'return filemtime($b) - filemtime($a);')); + + $timeCompareFunction = function($a, $b) { + return filemtime($b) - filemtime($a); + }; + usort($filelist, $timeCompareFunction); //check if metafile is still up to date or if we have to create a new one if (strpos($filelist[0], '.fotofolder.dat') == true) {