/*
* mediaSpace
*
* Copyright (c) 2005 1000camels and Mental Blocks
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @version $Id: index.php,v 1.3 2005/03/30 02:20:35 darcy Exp $
*
*/
//**************************************************************************
// configuration variables
define('RELATIVE_ROOT','./');
if(file_exists(RELATIVE_ROOT.'lib/config.php')) {
require_once(RELATIVE_ROOT.'lib/config.php');
}
if(!defined('COLLECTION_DIRECTORY')) define('COLLECTION_DIRECTORY','system/collections/');
if(!defined('MEDIA_DIRECTORY')) define('MEDIA_DIRECTORY','system/media/');
if(!defined('TAG_DIRECTORY')) define('TAG_DIRECTORY','system/tags/');
if(!defined('STYLE_ROOT')) define('STYLE_ROOT','style/');
if(!defined('LIBRARY_ROOT')) define('LIBRARY_ROOT','lib/');
if(!defined('CLASS_ROOT')) define('CLASS_ROOT','classes/');
if(!defined('SHOW_SYSTEM_MESSAGES')) define('SHOW_SYSTEM_MESSAGES',1);
if(!defined('DEFAULT_HEADER')) define('DEFAULT_HEADER',"\n");
if(!defined('XMLEDITOR_LOG')) define('XMLEDITOR_LOG','log/error.log');
if(!defined('BASE_URL')) define('BASE_URL','http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/');
//**************************************************************************
// setup environment
require_once('PEAR.php');
// error handling
error_reporting(E_ALL);
PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);
//**************************************************************************
// process URI - follow cleanURLs
// load some general libraries for dealing with urls
require_once(RELATIVE_ROOT.'lib/URLFunctions.php');
// ****************************************************************************
// This is used to catch bad url requests. they need to end with a / or a filename
// do it here before all the libraries, so it does load too much before refreshing
if(isset($_GET['path']) && substr($_GET['path'],-4) != '.php' && substr($_GET['path'],-1) != '/') {
Header('Location: ' . cleanURL($_GET['path'].'/'));
exit;
}
setIncludePath();
if(isset($_REQUEST)) stripGPCSlashes($_REQUEST);
if(isset($_POST)) stripGPCSlashes($_POST);
if(isset($_GET)) stripGPCSlashes($_GET);
if(isset($_COOKIE)) stripGPCSlashes($_COOKIE);
session_start();
// set up control variables
if(isset($_REQUEST['path'])) {
$GLOBALS['galleryPath'] = $_REQUEST['path'];
} else {
$GLOBALS['galleryPath'] = "";
}
setCleanUrlBase($GLOBALS['galleryPath']);
// create php4 file_put_contents
if(!function_exists('file_put_contents')) {
function file_put_contents($filename, $data, $file_append = false) {
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
if(!$fp) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
}
fputs($fp, $data);
fclose($fp);
}
}
//**************************************************************************
// parse url
$GLOBALS['url_parts'] = split('/',$GLOBALS['galleryPath']);
if(empty($GLOBALS['url_parts'][(count($GLOBALS['url_parts'])-1)])) {
array_pop($GLOBALS['url_parts']);
}
//**************************************************************************
// Main
//**************************************************************************
// determine which object we are working with
// choices: collection, media and tag
if(isset($GLOBALS['url_parts'][0])) {
// set properties if they are available
$objectId = (!isset($GLOBALS['url_parts'][1])) ? '' : $GLOBALS['url_parts'][1];
$view = (!isset($GLOBALS['url_parts'][2])) ? '' : $GLOBALS['url_parts'][2];
if($GLOBALS['url_parts'][0] == 'collection') {
include(CLASS_ROOT.'Collection.php');
$thisCollection =& new Collection($objectId);
$content = $thisCollection->getContent($view);
}
else if($GLOBALS['url_parts'][0] == 'media') {
include(CLASS_ROOT.'Media.php');
$thisMedia =& new Media($objectId);
$content = $thisMedia->getContent($view);
}
else if($GLOBALS['url_parts'][0] == 'tag') {
include(CLASS_ROOT.'Tag.php');
$thisTag =& new Tag($objectId);
$content = $thisTag->getContent($view);
}
else {
// show all collections
$content = 'requesting unavailable service: '.$GLOBALS['url_parts'][0].'';
$GLOBALS['xslFile'] = "style/system.xsl";
}
} else {
$content = showServices();
}
//**************************************************************************
// Transformation (XSLT)
header('Content-type: application/xml');
echo $content;
//**************************************************************************
// Functions
/**
* Shows available services
*
* @access public
* @return STRING xml
*/
function showServices() {
$xmlString = ''
.''
.''
.''
.'';
return $xmlString;
}
/**
* perform xsl transformation
*
* @access public
* @return STRING xml
*/
function transform($xmlString,$xslFile,$xslParams = '') {
if(empty($xslParams)) $xslParams = array();
$xmldoc = domxml_open_mem($xmlString);
$xsldoc = domxml_xslt_stylesheet_file($xslFile);
$result = $xsldoc->process($xmldoc,$xslParams);
$transformedContent =& $xsldoc->result_dump_mem($result);
return $transformedContent;
}
//**************************************************************************
?>