IHMPlotContextFileClass.php 1.29 KB
<?php

class IHMPlotContextFileClass {
	public static function parse($filePath) {
		if (!file_exists($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
		
		$doc = new DOMDocument("1.0", "UTF-8");
		$doc->preserveWhiteSpace = false;
		$doc->formatOutput = true;
		
		if (!$doc->load($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
		
		//<page>
		$pageNodes = $doc->getElementsByTagName('page');
		
		if ($pageNodes->length <= 0)
			return array("success" => false, "message" => "Cannot load context page node");
		
		$pageNode = $pageNodes->item(0);
		
		$pageContext = array(
			'startTime' => $pageNode->getAttribute('startTime'),
			'stopTime'  => $pageNode->getAttribute('stopTime'),
			'portrait'  => ($pageNode->getAttribute('portrait') == "true"),
			//An image rotation of 90 deg. is done after request execution if a page is in "portrait" mode
			'width'     => ($pageNode->getAttribute('portrait') == "true" ? $pageNode->getAttribute('height') : $pageNode->getAttribute('width')),
			'height'    => ($pageNode->getAttribute('portrait') == "true" ? $pageNode->getAttribute('width') : $pageNode->getAttribute('height')),
			'panels'    => array()
		);
		
		return array("success" => true, "page" => $pageContext);
	}
}

?>