<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: PageXML |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2003-2005 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> |
// | Oli Oskarsson <hide@address.com> |
// +---------------------------------------------------------------------------+
//
// $Id: PageXML.inc.php 229 2008-04-17 09:20:31Z oli $
//
// This file contains the Nitro Page XML generation class
//
/**
* Nitro PageXML
*
* This is the main XML engine of Nitro. Here the page objects are retreived,
* initialized and the given objects and calls are returned as XML
*
* @package Nitro
* @subpackage Base
* @author Siggi Oskarsson
* @author Oli Oskarsson
* @version $Revision: 1.34 $
* @copyright 2003-2005 June Systems BV
*/
/**
* Defines used by this class
*/
define ('NITRO_DEFAULT_TEMPLATENAME', "Defaults/Templates/DefaultXML.tpl");
/**
* Require the Nitro Page class
*/
require_once "Nitro/Page.inc.php";
/**
* Nitro Page XML Class
*
* This class creates a new page, with all linked objects, and create and XML
* response for the given objects with the selected template.
*
* <CODE>
* Usage:
* $XML = new NitroPageXML();
* $XML->InitPageFromString($_GET["P"]);
* echo $XML->Draw($_GET['O'], $_GET['C']);
* </CODE>
*
* @package Nitro
* @subpackage Base
* @access public
*/
class NitroPageXML extends NitroPage {
var $Error;
function NitroPageXML() {
DebugGroup("PageXML", "Init", "New Page XML init", __FILE__, __LINE__, DEBUG_APPL_OK);
parent::NitroPage();
DebugCloseGroup(DEBUG_APPL_OK);
}
/**
* Return string from XML object using function
*
* @param mixed $ObjectID Int id of object (ObjectID) or IDString !
* @param string $FunctionCall Function to call with xml, may be prepended with DivID: to force insert into specific DivID (only works with first returned array element)
*/
function Draw($ObjectID, $FunctionCall, $DivID = FALSE)
{
DebugGroup(__CLASS__, __FUNCTION__, "called", __FILE__, __LINE__, DEBUG_APPL_OK);
if ($this->Error) {
$Result = Array('Error' => $this->Error);
if ($this->ErrorCode == 401) {
// unauthorized, try to log on
$Result['JSCRIPT:()'] = 'NitroLogon()';
}
} else {
$this->LoadPageData();
foreach($this->Objects AS $i => $object) {
// search for object
if ($ObjectID == $object['ObjectID'] OR $ObjectID == $object['Object']->ObjectIDString) {
$Object =& $this->Objects[$i];
break;
}
}
// Create and Pre-Proccess requested Object.
// Set and check Settings correctly for the module
$Object["DefaultSettings"] = unserialize($Object["DefaultSettings"]);
$Object["Settings"] = unserialize($Object["Settings"]);
$Object["RuntimeSettings"] = unserialize($Object["RuntimeSettings"]);
if (!is_array($Object["DefaultSettings"])) $Object["DefaultSettings"] = Array();
if (!is_array($Object["Settings"])) $Object["Settings"] = Array();
if (!is_array($Object["RuntimeSettings"])) $Object["RuntimeSettings"] = Array();
$Settings = array_merge($Object["DefaultSettings"], $Object["Settings"]);
if ($Object["Object"] = $this->InitModule($Object["File"], $Object["Class"], $Object["ObjectID"], $Settings)) {
// set version if != 1 and IDString of object
if ($Object["ObjectVersion"] > 1) $Object["Object"]->ObjectVersion = $Object["ObjectVersion"];
if ($Object["ObjectIDString"]) $Object["Object"]->ObjectIDString = $Object["ObjectIDString"];
if ($Object["ObjectLastEdited"]) $Object["Object"]->ObjectLastEdited = $Object["ObjectLastEdited"];
// PRE-PROCESSING
$Object["Object"]->PreProcess();
}
if (is_object($Object["Object"])) {
if (method_exists($Object["Object"], 'XMLCall')) {
//Also done in regular Page class
//$Object['Object']->PreProcess(); //snieuw! vertrouw siggi niet! testen!
$Object['Object']->Process();
if (ereg('Type=', $FunctionCall)) {
// type is being called
$t = explode('=', $FunctionCall);
$type = $t[1];
// $type can be comma seperated, but should always be passed on as an array
$Result = $Object['Object']->DrawResult(explode(',', $type));
} else {
if (ereg('\:\:', $FunctionCall)) {
// Do nothing, :: is allowed for Generic Module XML calls
} else if (ereg('\:', $FunctionCall)) {
$t = explode(':', $FunctionCall);
$DivID = $t[0]; // overwrite $DivID
$FunctionCall = $t[1];
}
$Result = $Object['Object']->XMLCall($FunctionCall);
if (!is_array($Result) && count($Result)) {
$Result = Array('Error' => 'XMLCall did not return a valid result');
} elseif ($DivID !== FALSE) {
$newResult = Array();
$n = 0;
foreach($Result AS $key => $val) {
if ($n == 0) $newResult[$DivID] = $val;
else $newResult[$key] = $val;
$n++;
}
$Result = $newResult;
}
}
$Object['Object']->PostProcess();
} else {
$Result = Array('Error' => 'XMLCalls are not supported in this object');
}
} else {
$Result = Array('Error' => 'Object ID does not exist on this page');
}
}
DebugCloseGroup(DEBUG_APPL_OK);
return $Result;
}
}
?>