Location: PHPKode > projects > Mocovie web framework > webs/common/controls/imagerotator.php
<?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
 */

/**
 * Including the abstract dirlist.
 */
ControlFactory::load('imagegallery');

/**
 * Rotates a displayed image based on an image-pool.
 *
 * @package mocovi
 * @subpackage controls
 */
class imagerotator_control extends imagegallery_control
{
	protected $defaultOptions = array
		( 'source'		=> ''
		, 'description'	=> ''
		, 'orientation'	=> 'middle'
		, 'crop'		=> 'yes'	// yes|no
		, 'rule'		=> ''		// even or odd
		);

	/**
	 * @override
	 */
	protected function program()
	{
		$this->setRules();
		if(!is_dir($this->getOption('source')))
			$this->error($this->getOption('source').' could not be found.');
		else
		{
			$elements = $this->readElements($this->getOption('source'));
			if(count($elements) > 0 )
			{
				$filename = $elements[rand(0, count($elements) - 1)];
				$this->options['source'] .= $filename;
				if(strlen($this->getOption('description')) == 0)
					$this->options['description'] = $filename;
			}
			else
				$this->error($this->getOption('source').' contains no images.');
			$this->adoptAttribute('source');
		}
		$this->adoptAttribute('description');
	}

	/**
	 * Creates the own node and returns it.
	 *
	 * @return void
	 * @see nodeCreated()
	 * @see $node
	 * @see $dom
	 * @access protected
	 *
	 * @todo use _beforeCreateNode() instead!
	 */
	protected function createNode()
	{
		if(!$this->nodeCreated())
			$this->node = $this->dom->createElement('image');
	}
}
Return current item: Mocovie web framework