Location: PHPKode > projects > Tv.2 CMS > tv2engine/tv2Site.class.php
<?php

require_once(ENGINE_DIR.'pyramidSite.class.php');

/**
 * Abstract class for Tv2 sites
 *
 * @package tv2-engine
 * @author Emilis Dambauskas (hide@address.com)
 * @copyright 2002–2003 Emilis Dambauskas under {@link http://opensource.org/licenses/artistic-license.php Artistic license}
 * @version $Id: tv2Site.class.php,v 1.4 2003/07/27 16:01:29 lunaticlt Exp $
 * @class tv2Site
 * @extends pyramidSite
 *
 * @log 2003-07-27 added methods showXImage(), showXFile() and getImageUrl()
 */
class tv2Site extends pyramidSite // and should extend tv2Client (see loadXdb() comments).
{
	/**
	 * A helper object for outputing files from Tv2 documents   
	 * @attribute private object $fh
	 */
	var $fh;
	
	/**
	 * Tv2 X database
	 * @attribute private object $xdb
	 */
	var $xdb;
	
	
	/**
	 * @constructor tv2Site
	 * @return object tv2Site object
	 * @use SITE_URL 
	 */
	function tv2Site()
	{
		$this->pyramidSite();
	}
	
	
	/**
	 * Shows a static page from /www/
	 *
	 * @method public staticPage
	 * @return string HTML if the page 
	 * @param mixed $url URL string / array  
	 */
	function staticPage($url)
	{
		if (is_array($url))
			$url = implode('/', $url);
			
		$this->loadXdb();
		$doc = &new tv2Document();
		
		if (!$doc->open('/www/'.$url) || ($doc->type != 'page' && $doc->type != 'html'))
			return $this->showError(404);
			
		return $this->showPage($doc->fv);
	}
	
	/**
	 * Shows index page of the site (shows static document /www/index)
	 *
	 * @method public showIndex
	 * @return string page HTML  
	 */
	function showIndex()
	{
		return $this->staticPage('index');
	}
	
	
	/**
	 * Shows image from Xdb image document
	 *
	 * @method public showXImage
	 * @return mixed NULL on success, error page HTML on failure 
	 * @param mixed $file url array  
	 *
	 * @since 2003-07-27
	 */  
	function showXImage($file)
	{
		return $this->showXFile($file);
	}
	
	
	/**
	 * Shows file from Xdb document
	 *
	 * @method public showXFile
	 * @return mixed NULL on success, error page HTML on failure 
	 * @param mixed $file url array  
	 *
	 * @since 2003-07-27
	 */  
	function showXFile($file)
	{
		$this->loadFileHelper();
		
		if (FALSE === $this->fh->showFileField('/www/'.implode('/', $file).':file'))
			return $this->showError(404);
		else
			return NULL;
	}
	
	
	/**
	 * Takes document ident and returns an URL for it
	 * 
	 * @method public getDocUrl
	 * @return string URL 
	 * @param string $ident document ident  
	 * @use SITE_URL  
	 */
	function getDocUrl($ident)
	{
		$url = 'http://'.SITE_URL.'/';
		
		if (substr($ident, 0, 5) != '/www/')
			return FALSE;
		
		$this->loadXdb();
		$fat = $this->xdb->getFat($ident);
		if ($fat[0]['type'] == 'image')
			$url .= 'images/';
			
		return $url.substr($ident, 5);
	}
	
	/**
	 * Takes image document ident and returns an URL for it
	 * 
	 * @method public getImageUrl
	 * @return string URL 
	 * @param string $ident image document ident  
	 * @use SITE_URL  
	 *
	 * @since 2003-07-27
	 */
	function getImageUrl($ident)
	{
		$url = 'http://'.SITE_URL.'/';
		
		if (substr($ident, 0, 5) != '/www/')
			return FALSE;
		
		$this->loadXdb();
		$fat = $this->xdb->getFat($ident);
		if ($fat[0]['type'] == 'image')
			return $url.'images/'.substr($ident, 5);
	}
	
	/**
	 * ATTENTION: method coppied from {@link tv2Client::loadXdb()}
	 *
	 * @method   private loadXdb
	 * @use $xdb  
	 * @use $config 
	 * @use ENGINE_DIR
	 */
	function loadXdb()
	{
		global $config;
		
		// load Tv2 Xdb if not loaded
		if (!@$GLOBALS['xdb'])
		{
			require_once(ENGINE_DIR.'tv2Xdb.class.php');
			
			$GLOBALS['xdb'] = &new tv2Xdb();
			
			$GLOBALS['xdb']->fat_table = $config['xdb']['fat_table'];
			$GLOBALS['xdb']->dir = $config['xdb']['dir'];
			
			$GLOBALS['xdb']->ver = @$config['xdb']['ver'];
			$GLOBALS['xdb']->ver_context = @$config['xdb']['ver_context'];
			$GLOBALS['xdb']->ver_table = @$config['xdb']['ver_table'];
			
			$GLOBALS['xdb']->connect();
		}
		if (!is_object(@$this->xdb))
			$this->xdb = &$GLOBALS['xdb'];
			
		if (@$this->xdb_vfilter)
			$this->xdb->setVersionFilter($this->xdb_vfilter);
		if (@$this->xdb_vprefs)
			$this->xdb->setVersionPreferences($this->xdb_vprefs);
	}
	
	/**
	 * ATTENTION: method coppied from {@link tv2Client::loadFileHelper()}
	 *
	 * @method private loadFileHelper
	 * @use ENGINE_DIR  
	 */
	function loadFileHelper()
	{
		if (!isset($this->fh) || !$this->fh)
		{
			require_once(ENGINE_DIR.'tv2FileHelper.class.php');
			$this->fh = &new tv2FileHelper();
		}
	}
}
Return current item: Tv.2 CMS