<?php
/**
* Copyright (C) 2010 Kai Dorschner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Kai Dorschner <the-hide@address.com>
* @copyright Copyright 2010, Kai Dorschner
* @license http://www.gnu.org/licenses/gpl.html GPLv3
* @package mocovi
* @subpackage controls
*/
/**
* Require dirlist control
*/
ControlFactory::load('dirlist');
/**
* This is a prototype control.
*
* From this class all other controls can be derived.
*
* @package mocovi
* @subpackage controls
*/
class newestpostings_control extends dirlist_control
{
protected $date;
protected $defaultOptions = array
( 'maximum' => '*'
, 'format' => 'r' // PHP date() format
);
/**
* @override
*/
protected function program()
{
$this->date = ControlFactory::createVirtual
( 'date'
, array
( 'format' => $this->getOption('format')
)
);
$this->readElementsIn($this->node, '/');
}
/**
* @override
*/
protected function readElementsIn(DomNode &$container, $dir)
{
$fs = $GLOBALS['filesystem'];
$list = $fs->getList($dir);
$elementcounter = 0;
foreach($list as $file)
{
$name = $fs->contextQuery($file, '@name')->item(0)->value;
$currentDir = $dir.$name.'/';
$currentFile = $dir.$name.'.html';
$element = $this->dom->createElement('element');
if($lastModifiedNode = $fs->contextQuery($file, '@lastModified')->item(0))
$lastModified = $lastModifiedNode->value;
else
$lastModified = 0;
if(strlen($lastModified) == 0 || $lastModified == '*')
if($createdNode = $fs->contextQuery($file, '@created')->item(0))
$lastModified = $createdNode->value;
$element->setAttribute('order', $lastModified);
$element->setAttribute
( 'lastModified'
, $this->date->formatTime(strtotime($lastModified))
);
$element->setAttribute('path', $currentFile);
if($authorNode = $fs->contextQuery($file, '@author')->item(0))
$element->setAttribute('author', $authorNode->value);
if($headlineNode = $fs->contextQuery($file, './/mocovi:headline')->item(0))
{
$headline = $headlineNode->nodeValue;
if(empty($headline) && $headlineTokenNode = $fs->contextQuery($headlineNode, '@textToken')->item(0))
$headline = translator::translateToken($headlineTokenNode->value)->nodeValue;
$element->appendChild($this->dom->createElement('title', $headline));
}
if($paragraphNode = $fs->contextQuery($file, './/mocovi:paragraph')->item(0))
{
$paragraph = $paragraphNode->nodeValue;
if(empty($paragraph) && $paragraphTokenNode = $fs->contextQuery($paragraphNode, '@textToken')->item(0))
$paragraph = translator::translateToken($paragraphTokenNode->value)->nodeValue;
$element->appendChild($this->dom->createElement('description', $paragraph));
}
$container->appendChild($element);
$this->readElementsIn($container, $currentDir); // Recursion
}
$this->adoptAttribute('maximum');
}
}