<?php
/*
* LayoutParser Class
*
* Copyright (c) 2003-4 St. Christopher House
*
* Developed by The Working Group Inc.
*
* 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: LayoutParser.php,v 1.53 2005/01/18 19:40:56 darcy Exp $
*
*/
require_once 'SimpleXMLParser.php';
class LayoutParser extends SimpleXMLParser {
var $lastTag;
var $counter;
var $blocksExist = FALSE;
var $layoutType;
function tag_open($parser, $tag, $attributes)
{
// PAGE tags
if ($tag == 'PAGE' || $tag == 'TUTORIAL' || $tag == 'NEWSLETTER') {
$this->content .= "\n<!-- BEGIN ".$tag." LAYOUT -->\n";
$this->layoutType = $tag;
}
// NEW tags
//else if ($tag == 'NEW') {
// $this->content .= "<div class=\"layoutRow layoutNew\"><div class=\"layoutColumn\">\n";
//}
// ROW tags
else if ($tag == 'ROW') {
$attr = '';
while(list($key,$value) = each($attributes)) {
$attr .= ' '.$key.'="'.$value.'"';
}
$attr .= ' class="layoutRow"';
$this->content .= '<div'.$attr.">\n";
}
// COLUMN tags
else if ($tag == 'COLUMN') {
if(!isset($this->counter)) $this->counter = 0;
$this->counter++;
$attr = '';
while(list($key,$value) = each($attributes)) {
if($key == 'TYPE') {
continue;
}
else if($key == 'WIDTH') {
//if($value == '100%') $value = '98%';
//if($value == '50%') $value = '49%';
$attr .= ' style="width:'.$value.'"';
}
else {
$attr .= ' '.$key.'="'.$value.'"';
}
}
$attr .= ' id="column'.$this->counter.'" class="layoutColumn"';
$this->content .= ' <div'.$attr.">\n";
// setup test to see if there are any blocks in this column
$this->blocksExistForLevel = FALSE;
}
// BLOCK tags
else if($tag == 'BLOCK') {
$this->blocksExist = TRUE;
$this->blocksExistForLevel = TRUE;
$this->content .= " <!-- START BLOCK -->\n";
$block =& new $GLOBALS['classes']['ko']['classname']($attributes['KOID']);
if($_SESSION['editMode'] == 'edit' && !$this->layoutType != 'PAGE') {
$class = ' editBlockMode';
// gets publish status
/*$status = $block->getStatus();
if ($status == 0) {
$class .= ' unpublishedKO';
}
else if ($status == 1) {
$class .= ' outOfDateKO';
}
else if ($status == 2) {
$class .= ' publishedKO';
}*/
} else {
$class = '';
}
if(isset($this->lastTag) && $this->lastTag != $tag) {
$this->content .= ' <div class="layoutBlock firstBlock'.$class."\">\n".$block->getContent()."\n";
} else {
$this->content .= ' <div class="layoutBlock'.$class."\">\n".$block->getContent()."\n";
}
}
}
function cdata($parser, $cdata)
{
if(!empty($cdata)) {
$this->content .= $cdata;
}
}
function tag_close($parser, $tag)
{
$this->lastTag = $tag;
// PAGE tags
if ($tag == 'PAGE' || $tag == 'TUTORIAL' || $tag == 'NEWSLETTER') {
if(!$this->blocksExist && $tag == 'PAGE') {
// turned off default block
//$block =& new $GLOBALS['classes']['ko']['classname'](CLN_DEFAULT_BLOCK_ID);
//$this->content .= " <div class=\"layoutBlock\">\n".$block->getContent()."</div>\n";
//$this->content .= 'There are no blocks on this page.';
PEAR::raiseError('This page is under construction and has no published blocks on it.<br/><br/>'
.'If you are working on this page, edit the page to add block(s).<br/><br/>'
.'If you are not working on this page, check back here soon.', E_USER_NOTICE);
}
$this->content .= "<!-- END LAYOUT -->\n";
}
// NEW tags
//else if ($tag == 'NEW') {
// $this->content .= " <br class=\"anchor\"></div>\n</div>\n";
//}
// ROW tags
else if ($tag == 'ROW') {
$this->content .= '<br class="anchor" />'."</div>\n";
}
// COLUMN tags
else if ($tag == 'COLUMN') {
if(!$this->blocksExistForLevel) {
$this->content .= " \n";
}
$this->content .= " </div>\n";
}
// BLOCK tags
else if($tag == 'BLOCK') {
$this->content .= '</div>'."\n".'<!-- END BLOCK -->'."\n";
}
}
} // end of class xml
?>