Location: PHPKode > projects > OpenNitro > trunk/html/GetObject.php
<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Base :: GetObject                                                |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems BV                                        |
// +---------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify it   |
// | under the terms of the GNU Lesser General Public License as published by  |
// | the Free Software Foundation; either version 2.1 of the License, or (at   |
// | your option) any later version.                                           |
// |                                                                           |
// | This library 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 Lesser   |
// | General Public License for more details.                                  |
// |                                                                           |
// | You should have received a copy of the GNU Lesser General Public License  |
// | along with this library; if not, write to the Free Software Foundation,   |
// | Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA            |
// +---------------------------------------------------------------------------+
// | Authors: Siggi Oskarsson <hide@address.com>                          |
// |          Jesper Avot <hide@address.com                              |
// +---------------------------------------------------------------------------+
//
// $Id: GetObject.php 245 2008-06-26 05:55:13Z andries $
//
// Nitro's GetObject script
//

/**
 * Include NitroBaseConfig file
 */
include_once "NitroBaseConfig.inc.php";

/**
 * Check if the config is loaded correct.
 */
if ($__NitroConf->isLoaded) {
	if (isset($_GET['NitroDefault']) && $_GET['NitroDefault'] != "") {
		/**
		 * Retrieve the file from the Defaults dir in the nitro root
		 */
		if ($URIs = explode(';', ereg_replace('^.*'.basename(__FILE__).'\?NitroDefault=', '', $_SERVER['REQUEST_URI']))) {
			/**
			 * The Header below is very important, Internet Explorer does not work with inline files over a secured connection (HTTPS [SSL]).
			 * So we need to set this header, because PHP sets the Pragma default to 'no-cache'
			 */
			Header("Pragma: Cache"); 
			Header("Cache-Control: Private"); 

			$rv = '';
			foreach($URIs AS $n => $uri) {
				$_GET = Array(); // reset _GET String
				list($FileName, $getString) = explode('?', $uri);
				if ($getString = explode('&', $getString)) {
					foreach($getString AS $get) {
						$get = explode('=', $get);
						$_GET[$get[0]] = $get[1];
					}
				}
				$FileName = NitroCleanRequestStringFile(NITRO_ROOT.'Nitro/Defaults/'.$FileName, NITRO_ROOT.'Nitro/Defaults/');

				if (file_exists($FileName)) {
					// Get file output
					if (ereg('\.php$', $FileName)) {
						// include to eval php code
						ob_start();
						include $FileName;
						$rv.= ob_get_contents();
						ob_end_clean();
					} else {
						if ($n === 0) {
							//set Headers for 1st file
							$MimeType = new getMimeType();
							header("Content-Type: " . $MimeType->getType($FileName));
							header("Content-Disposition: inline; filename=\"" . basename($FileName) . "\"");
							header("Expires: " . gmdate("D, d M Y H:i:s", strtotime("+1 day")) . " GMT");
						}
						$rv.= file_get_contents($FileName);
					}
				}
			}

			// TODO: build in optional content compression
			header("Content-Length: " . strlen($rv));
			echo $rv;
		}
	} else {
		/**
		 * Retrieve the Object's IDString from the GET array and get its data from the DB.
		 */
		$ObjectIDString = $_GET["ID"];
		$Query = "
			SELECT
				O.*,
				OD.*,
				M.File,
				M.Class
			FROM
				(`Object` AS O,
				`Module` AS M)
			LEFT JOIN `ObjectData` AS OD
				 ON O.ObjectID = OD.ObjectID
				AND (OD.Language = ".NitroPrepareDB($__NSess->Language)." OR OD.Language = '')
				AND (OD.VisibleFrom >= CURRENT_TIMESTAMP OR VisibleFrom IS NULL)
				AND (OD.VisibleTill < CURRENT_TIMESTAMP OR VisibleTill IS NULL)
				AND OD.Published = 1
			WHERE O.ModuleID = M.ModuleID
				AND O.IDString = '".NitroPrepareDB($ObjectIDString)."'
				AND O.AllowView = 1
			ORDER BY
				OD.Language DESC,
				OD.Version
			DESC LIMIT 1
		";
		$Object = $DB["Nitro"]->getRow($Query);
		
		if (is_array($Object)) {
			$DefaultSettings = unserialize($Object["DefaultSettings"]);
			if (!is_array($DefaultSettings)) $DefaultSettings = Array();
			$Settings = unserialize($Object["Settings"]);
			if (!is_array($Settings)) $Settings = Array();
			$Settings = array_merge($DefaultSettings, $Settings);
		
			if (file_exists($Object["File"])) {
				include_once $Object["File"];
				
				eval('$temp = new ' . $Object["Class"] . '($Object["ObjectID"],$Settings);');
				
				$temp->ObjectLanguage = $Object["Language"];
				$temp->ObjectVersion = $Object["Version"];
			
				echo $temp->DrawObject();
			} else {
				echo "File (" . $Object["File"] . ") not found!";
			}
		} else {
			echo (($ObjectIDString && $ObjectIDString != "") ? "Object (" . $ObjectIDString . ") not found!" : "No Object given.");
		}
	}
} else {
	/**
	 * No NitroBaseConfig file found, error time!
	 */
	echo "Configuration File could not be loaded. => " . $__NitroConf->Error;	
	exit;
}
?>
Return current item: OpenNitro