<?php /** * Description goes here... * * @author Pontus Östlund <spam@poppa.se> */ PLib::Import('IO.StreamReader'); $p = getProject(); #$p->usecache = false; $p->Header('Tutorials'); echo $p->Textify(" # Tutorials Here I will collect a few PLib tutorials. **List of tutorials** "); $now = time(); $dir = new Dir('.'); $dir->Sort('-ctime'); $container = array(); while ($file = $dir->Emit()) { if ($file->filetype == 'dir') { $index = $file->path . '/index.php'; if (file_exists($index)) { $item = new stdClass(); $item->path = FilePathToURI($file->path); $sr = new StreamReader($index); $i = 0; while ($line = $sr->ReadLine()) { if (!empty($line) && $line[0] == '#') { if (preg_match('/#(TITLE|PUBLISH)\s+(.*)\n/', $line, $m)) { switch ($m[1]) { case 'TITLE': $item->title = $m[2]; break; case 'PUBLISH': $item->publish = new Date($m[2]); break; } if (isset($item->title) && isset($item->publish) || $i > 10) break; } } $i++; } array_push($container, $item); $sr->Close(); } } } function _sort($a, $b) { $a1 = $a->publish->unixtime; $b1 = $b->publish->unixtime; return $a1 != $b1 ? $a1 > $b1 ? 1 : -1 : 0; } usort($container, '_sort'); $container = array_reverse($container); echo "<ul class='filelist'>\n"; foreach ($container as $item) { $diff = $now - $item->publish->unixtime; $class = $diff < 604800 ? ' class="new"' : ''; echo "<li$class><a href='{$item->path}'>" . "<span class='date'>{$item->publish->ymdShort}</span> ". "{$item->title}</a></li>\n"; } echo "</ul>\n"; $p->Footer(); ?>