Hi,
I’ve the following snippets. They get the six most recent files in a directory and create a mini image gallery. The work fine as functions out of modX (with the necesary modifications), but not inside. Can anybody help me?.
-----[[gallery]]-----
<?php<br />$path = $modx->config[’base_url’] . ’assets/templates/tmplts/images’;<br />$params[’folder’] = $path;<br />$files = array();<br />$files = $modx->runSnippet(’lastfiles’, $params);<br />echo $path;<br /><br />for ($i=0;$i<=5;$i++) {<br /> $numimg= $i+1;<br /> echo ’<img id="imgBlueScoop’. $numimg .’" alt=""<br /> src="’ . $files[$i] .’"<br /> style="width: 75px; height: 75px;"<br /> class="PopBoxImageSmall"<br /> pbShowPopText=false<br /> pbShowPopImage=false<br /> pbShowPopBar=false<br /> pbShowRevertBar=false<br /> pbShowRevertImage=false<br /> pbShowRevertText=false<br /> onclick="Pop(this,50,\’PopBoxImageLarge\’);"><br /> ’;<br />}<br />return ’’;
-----[[end of gallery]]-----
-----[[lastfiles]]-----
<?php<br />$numimages = 6;<br />$images = array();<br />foreach (scandir($folder) as $node) {<br /> $nodePath = $folder . ’/’ . $node;<br /> if (!is_dir($nodePath) && strcmp($node,"base.png")!=0){<br /> $images[$nodePath] = filemtime($nodePath);<br /> }<br />}<br />arsort($images);<br />$i=0;<br />$newest = array();<br />foreach ($images as $key => $val) {<br />print($key);<br /> if ($i <= $numimages) {<br /> $newest[$i] = $key;<br /> $i++;<br /> } <br />}<br />return $newest;
-----[[end of lastfiles]]-----