[evolvis-commits] r17725: [#2030] theme-evolvis pending merges:↵ Thorsten Glaser 2011-11-25 we now chave greeet weee to make table↵ Thorsten Glaser 2011-11-25 I’m ashamed of the way we create HTML in FusionForge.↵ Thorsten Glaser 2011-11-25 revert part of the last commit that was already here, functionality-wise↵ Roland Mas 2011-11-16 the ability to run code just shy of the </body></html>

mirabilos at evolvis.org mirabilos at evolvis.org
Fri Nov 25 17:20:26 CET 2011


Author: mirabilos
Date: 2011-11-25 17:20:26 +0100 (Fri, 25 Nov 2011)
New Revision: 17725

Added:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/EvolvisTable.class.php
Modified:
   trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php
   trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
   trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/EvStyle.class.php
   trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php
Log:
[#2030] theme-evolvis pending merges:
  Thorsten Glaser 2011-11-25 we now chave greeet weee to make table
    Thorsten Glaser 2011-11-25 I’m ashamed of the way we create HTML in FusionForge.
    Thorsten Glaser 2011-11-25 revert part of the last commit that was already here, functionality-wise
    Roland Mas 2011-11-16 the ability to run code just shy of the </body></html>


Added: trunk/gforge_base/evolvisforge-5.1/src/common/include/EvolvisTable.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/EvolvisTable.class.php	                        (rev 0)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/EvolvisTable.class.php	2011-11-25 16:20:26 UTC (rev 17725)
@@ -0,0 +1,219 @@
+<?php
+/*-
+ * XHTML Table generation support for FusionForge
+ *
+ * Copyright © 2011
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
+ * All rights reserved.
+ *
+ * This file is part of FusionForge. FusionForge 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 Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge 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 FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *-
+ * Easily generate XHTML tables, with a Prototype-like API.
+ * Supports colspan but not rowspan at the moment.
+ */
+
+class EvolvisTable {
+
+	/**
+	 * EvolvisTable() - Initialise a table object
+	 *
+	 * @param	array	$title_arr
+	 *			The array of titles
+	 * @param	array	$links_arr
+	 *		(optional) The array of title links
+	 * @param	array	$params
+	 *		(optional) flags, such as:
+	 *			- bool sortable
+	 *			- false/string border
+	 */
+	function EvolvisTable($title_arr, $links_arr=false, $param=array()) {
+		$ct = count($title_arr);
+		$cl = is_array(util_ifsetor($links_arr)) ?
+		    count($links_arr) : 0;
+
+		if (!$ct) {
+			throw new Exception('Missing $title_arr');
+			return false;
+		}
+
+		if ($cl && ($ct != $cl)) {
+			throw new Exception('Inequal magnitude of ' .
+			    '$title_arr and $links_arr');
+			return false;
+		}
+
+		$param['text'] = $title_arr;
+		$param['link'] = $cl ? $links_arr : array();
+		$this->param = $param;
+
+		$this->ncols = $ct;
+		$this->rows = array();
+		return true;
+	}
+
+	/**
+	 * tr() - Add table row
+	 *
+	 * @param	array	$attrs
+	 *		(optional) attributes of the table row
+	 * @param	integer	$atpos
+	 *		(optional) after which position to add
+	 *		(default: -1 a.k.a. at the end)
+	 * @return	&EvolvisTableRow object
+	 */
+	function &tr($attrs=array(), $atpos=-1) {
+		$therow = new EvolvisTableRow($attrs);
+		if ($atpos == -1) {
+			$this->rows[] = $therow;
+		} else {
+			array_splice($this->rows, $atpos, 0, array($therow));
+		}
+		return $therow;
+	}
+
+	/**
+	 * emit() - Return the table as XHTML
+	 *
+	 * @return	string
+	 */
+	function emit() {
+		global $HTML;
+
+		if (!count($this->rows)) {
+			return "";
+		}
+		$rv = $HTML->listTableStart($this->param);
+		$i = 0;
+		foreach ($this->rows as $v) {
+			$numcols = $v->getncols();
+			if ($numcols != $this->ncols) {
+				throw new Exception("Row " .
+				    $i . " #cols " . $numcols .
+				    " not expected " . $this->ncols);
+			}
+			/*XXX breaks Kapselung */
+			$HTML->boxApplyAltRowStyle($i++, $v->attrs);
+			$rv .= $v->emit();
+		}
+		$rv .= $HTML->listTableBottom();
+		return $rv;
+	}
+}
+
+class EvolvisTableRow {
+	function EvolvisTableRow($attrs=array()) {
+		$this->attrs = $attrs;
+		$this->cols = array();
+		return true;
+	}
+
+	/**
+	 * th() - Add table column (header)
+	 *
+	 * @param	array	$attrs
+	 *		(optional) attributes of the table field
+	 * @param	integer	$atpos
+	 *		(optional) after which position to add
+	 *		(default: -1 a.k.a. at the end)
+	 * @param	string	$txt
+	 *		(optional) text to htmlencode and set
+	 * @return	&EvolvisTableColumn object
+	 */
+	function &th($attrs=array(), $atpos=-1, $txt=false) {
+		$thecol = new EvolvisTableColumn($attrs, 'th');
+		if ($atpos == -1) {
+			$this->cols[] = $thecol;
+		} else {
+			array_splice($this->cols, $atpos, 0, array($thecol));
+		}
+		if ($txt !== false) {
+			$thecol->set($txt);
+		}
+		return $thecol;
+	}
+
+	/**
+	 * td() - Add table column (data)
+	 *
+	 * @param	array	$attrs
+	 *		(optional) attributes of the table field
+	 * @param	integer	$atpos
+	 *		(optional) after which position to add
+	 *		(default: -1 a.k.a. at the end)
+	 * @param	string	$txt
+	 *		(optional) text to htmlencode and set
+	 * @return	&EvolvisTableColumn object
+	 */
+	function &td($attrs=array(), $atpos=-1, $txt=false) {
+		$thecol = new EvolvisTableColumn($attrs);
+		if ($atpos == -1) {
+			$this->cols[] = $thecol;
+		} else {
+			array_splice($this->cols, $atpos, 0, array($thecol));
+		}
+		if ($txt !== false) {
+			$thecol->set($txt);
+		}
+		return $thecol;
+	}
+
+	function getncols() {
+		$nc = 0;
+		foreach ($this->cols as $v) {
+			/*XXX breaks Kapselung */
+			$nc += util_ifsetor($v->attrs['colspan'], 1);
+		}
+		return $nc;
+	}
+
+	function emit() {
+		$rv = "\n\t" . html_eo('tr', $this->attrs);
+		foreach ($this->cols as $v) {
+			$rv .= "\n\t\t" . $v->emit();
+		}
+		$rv .= "\n\t</tr>";
+		return $rv;
+	}
+}
+
+class EvolvisTableColumn {
+	function EvolvisTableColumn($attrs=array(), $type='td') {
+		$this->type = $type;
+		$this->attrs = $attrs;
+		$this->content = "";
+		return true;
+	}
+
+	function set($to) {
+		$this->setraw(util_html_secure($to));
+	}
+
+	function append($me) {
+		$this->appendraw(util_html_secure($me));
+	}
+
+	function setraw($to) {
+		$this->content = "" . $to;
+	}
+
+	function appendraw($me) {
+		$this->content .= $me;
+	}
+
+	function emit() {
+		return html_e($this->type, $this->attrs, $this->content, false);
+	}
+}

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php	2011-11-25 13:55:26 UTC (rev 17724)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/Layout.class.php	2011-11-25 16:20:26 UTC (rev 17725)
@@ -485,6 +485,11 @@
 			</div>
 
 			<?php echo $this->navigation->getShowSource(); ?>
+<?php
+               foreach ($this->footer_hooks as $h) {
+                       call_user_func($h, $params);
+               }
+?>
 
 			</body>
 			<script language="javascript" src="<?php echo util_make_uri('/js/awstats_misc_tracker.js');?>"></script><noscript><img src="<?php echo util_make_uri('/js/awstats_misc_tracker.js?nojs=y');?>" height="0" width="0" border="0" style="display: none"></noscript>

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2011-11-25 13:55:26 UTC (rev 17724)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/include/html.php	2011-11-25 16:20:26 UTC (rev 17725)
@@ -5,6 +5,8 @@
  * Copyright 1999-2001 (c) VA Linux Systems
  * Copyright 2010 (c) FusionForge Team
  * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
+ * Copyright © 2011
+ *	Thorsten “mirabilos” Glaser <t.glaser at tarent.de>
  *
  * This file is part of FusionForge. FusionForge is free software;
  * you can redistribute it and/or modify it under the terms of the
@@ -869,6 +871,129 @@
 	return $hashstr;
 }
 
+
+/* TODO: think about beautifying output */
+
+/**
+ * html_eo() - Return proper element XHTML start tag
+ *
+ * @param	string	$name
+ *			element name
+ * @param	array	$attrs
+ *		(optional) associative array of element attributes
+ *			empty values are ignored; arrays space-imploded
+ * @return	string
+ *		XHTML string suitable for echo'ing
+ */
+function html_eo($name, $attrs=array()) {
+	$rv = '<' . $name;
+	foreach ($attrs as $key => $value) {
+		if (!$value) {
+			continue;
+		} else if (is_array($value)) {
+			$value = implode(" ", $value);
+		}
+		$rv .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
+	}
+	$rv .= '>';
+	return $rv;
+}
+
+/**
+ * html_e() - Return proper element XHTML start/end sequence
+ *
+ * @param	string	$name
+ *			element name
+ * @param	array	$attrs
+ *		(optional) associative array of element attributes
+ *			empty values are ignored; arrays space-imploded
+ * @param	string	$content
+ *		(optional) XHTML to be placed inside
+ * @param	bool	$shortform
+ *		(optional) allow short open-close form
+ *		(default: true)
+ * @return	string
+ *		XHTML string suitable for echo'ing
+ */
+function html_e($name, $attrs=array(), $content="", $shortform=true) {
+	$rv = '<' . $name;
+	foreach ($attrs as $key => $value) {
+		if (!$value) {
+			continue;
+		} else if (is_array($value)) {
+			$value = implode(" ", $value);
+		}
+		$rv .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
+	}
+	if (!$content) {
+		if ($shortform) {
+			$rv .= ' />';
+			return $rv;
+		}
+		$content = "";
+	}
+	$rv .= '>' . $content . '</' . $name . '>';
+	return $rv;
+}
+
+$html_autoclose_stack = array();
+$html_autoclose_pos = 0;
+
+/**
+ * html_ap() - Return XHTML element autoclose stack position
+ *
+ * @return	integer
+ */
+function html_ap() {
+	global $html_autoclose_pos;
+
+	return $html_autoclose_pos;
+}
+
+/**
+ * html_ao() - Return proper element XHTML start tag, with autoclose
+ *
+ * @param	string	$name
+ *			element name
+ * @param	array	$attrs
+ *		(optional) associative array of element attributes
+ * @return	string
+ *		XHTML string suitable for echo'ing
+ */
+function html_ao($name, $attrs=array()) {
+	global $html_autoclose_pos, $html_autoclose_stack;
+
+	$html_autoclose_stack[$html_autoclose_pos++] = $name;
+	return html_eo($name, $attrs);
+}
+
+/**
+ * html_ac() - Return proper element XHTML end tags, autoclosing
+ *
+ * @param	integer	$spos
+ *			stack position to return to
+ * @return	string
+ *		XHTML string suitable for echo'ing
+ */
+function html_ac($spos) {
+	global $html_autoclose_pos, $html_autoclose_stack;
+
+	if ($html_autoclose_pos < $spos) {
+		$e = "html_autoclose stack underflow; closing down to " .
+		    $spos . " but we're down to " . $html_autoclose_pos .
+		    " already!";
+		throw new Exception($e);
+	}
+
+	$rv = "";
+	while ($html_autoclose_pos > $spos) {
+		--$html_autoclose_pos;
+		$rv .= '</' . $html_autoclose_stack[$html_autoclose_pos] . '>';
+		unset($html_autoclose_stack[$html_autoclose_pos]);
+	}
+	return $rv;
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/EvStyle.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/EvStyle.class.php	2011-11-25 13:55:26 UTC (rev 17724)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/EvStyle.class.php	2011-11-25 16:20:26 UTC (rev 17725)
@@ -38,7 +38,7 @@
   }
 
 
-  /*
+  /**
    * create HTML for one headlink
    *
    * @param   char    $colourkey
@@ -67,7 +67,7 @@
   }
 
 
-  /*
+  /**
    * emit HTML for xml, doctype, head until end, body tag
    *
    * @param   Layout  $T
@@ -111,7 +111,7 @@
   }
 
 
-  /*
+  /**
    * emit HTML for the first div inside of body tag
    *
    * @param   Layout  $T
@@ -218,7 +218,7 @@
   }
 
 
-  /*
+  /**
    * emit HTML for the last div inside of body tag; run footer_hooks
    *
    * @param   Layout  $T

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php	2011-11-25 13:55:26 UTC (rev 17724)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/themes/evolvis/Theme.class.php	2011-11-25 16:20:26 UTC (rev 17725)
@@ -322,6 +322,20 @@
 		}
 	}
 
+	function boxApplyAltRowStyle($i, &$attrs) {
+		switch ($i % 3 ) {
+		case 0:
+			$attrs['bgcolor'] = "#F4F4F4";
+			break;
+		case 1:
+			$attrs['bgcolor'] = "#EAEAEA";
+			break;
+		case 2:
+			$attrs['bgcolor'] = "#E0E0E0";
+			break;
+		}
+	}
+
 	/**
 	 * boxBottom() - Bottom HTML box
 	 */
@@ -342,39 +356,14 @@
 	 * @param	bool	Show a table border (default: false)
 	 */
 	function listTableTop($title_arr,$links_arr=false,$cnt=0,$useborder=false) {
-		$rv = '
-		<!-- listTableTop[ -->
-		<table cellspacing="0" cellpadding="1" width="100%" ' .
-		($useborder ? $useborder : 'border="0"') . '>
-		<tr class="ff"><td class="ff">
-		<table width="100%" border="0" cellspacing="2" cellpadding="0">
-		<thead>
-		<tr class="ff">';
-
-		$count = count($title_arr);
-		if (!$count) {
-			$rv .= '<td style="color:red;">No $title_arr:' .
-			    "<pre>\n" . htmlentities(debug_string_backtrace()) .
-			    "</pre></td>\n";
-		} else if ($links_arr) {
-			for ($i=0; $i<$count; $i++) {
-				$rv .= '
-		<td class="ff" align="left"><a class="titlebar" href="'.$links_arr[$i].'">'.$title_arr[$i].'</a></td>';
-			}
-		} else {
-			for ($i=0; $i<$count; $i++) {
-				$rv .= '
-		<td align="left" class="list_table_top">'.$title_arr[$i].'</td>';
-			}
+		$params = array();
+		$params['text'] = &$title_arr;
+		if ($links_arr) {
+			$params['link'] = &$links_arr;
 		}
-		$rv .= '
-		</tr>
-		</thead><tfoot>
-		<tr class="ff" align="left" bgcolor="'. $this->COLOR_HTMLBOX_BACK .'">
-		<td class="ff" colspan="'.$count.'" height="1"><img src="'.$this->imgroot.'clear.png" height="1" width="1" alt="" /></td>
-		</tr>
-		</tfoot><tbody><!-- ]listTableTop -->'."\n";
-		return $rv;
+		$params['border'] = &$useborder;
+		$params['sortable'] = false;
+		return $this->listTableStart($params);
 	}
 
 	/**
@@ -384,33 +373,101 @@
 	 * @param	array	The array of title links
 	 */
 	function listTableTopSortable($title_arr,$links_arr=false) {
-		$rv= '
-		<!-- listTableTopSortable[ -->
-		<table cellspacing="0" cellpadding="1" width="100%" border="0">
-		<tr class="ff"><td class="ff">
-		<table class="sortable" width="100%" border="0" cellspacing="2" cellpadding="0">
-		<thead>
-		<tr class="ff">';
+		$params = array();
+		$params['text'] = &$title_arr;
+		if ($links_arr) {
+			$params['link'] = &$links_arr;
+		}
+		$params['border'] = false;
+		$params['sortable'] = true;
+		return $this->listTableStart($params);
+	}
 
-		$count = count($title_arr);
-		if ($links_arr) {
-			for ($i=0; $i<$count; $i++) {
-				$rv.= '
-				<th class="ff" align="left"><a class="titlebar" href="'.$links_arr[$i].'">'.$title_arr[$i].'</a></th>';
+	function listTableStart($params) {
+		/*XXX do an html_ap and pass to listTableBottom */
+
+		$rv = "<!-- listTableStart[ -->\n";
+		$rv .= html_eo('table', array(
+			'cellspacing' => 0,
+			'cellpadding' => 1,
+			'width' => "100%",
+			'bgcolor' => $this->COLOR_HTMLBOX_BACK,
+			'border' => (util_ifsetor($params['border']) ?
+			    preg_replace('/^\s*border="(.*)"\s*$/', "\\1",
+			    $params['border']) : '0'),
+		    ));
+		$rv .= html_eo('tr', array('class' => 'ff'));
+		$rv .= html_eo('td', array('class' => 'ff'));
+		$tclass = array();
+		if (util_ifsetor($params['sortable'])) {
+			$tclass[] = 'sortable';
+		}
+		$rv .= html_eo('table', array(
+			'class' => $tclass,
+			'width' => "100%",
+			'border' => 0,
+			'cellspacing' => 2,
+			'cellpadding' => 0,
+		    ));
+		$spos = html_ap();
+		$rv .= html_ao('thead');
+
+		$ct = count($params['text']);
+		$cl = is_array(util_ifsetor($params['link'])) ?
+		    count($params['link']) : 0;
+
+		if ($ct && $cl && ($ct != $cl)) {
+			$rv .= html_e('tr', array(), html_e('td', array(
+				'align' => 'center',
+				'style' => 'color:red;',
+				'colspan' => $ct,
+			    ), 'Inequal magnitutes of $params["text"] and ' .
+			    '$params["link"]:' . html_e('pre', array(),
+			    "\n" . htmlentities(debug_string_backtrace()))));
+		}
+
+		$rv .= html_ao('tr', array('class' => 'ff'));
+		if (!$ct) {
+			$rv .= html_e('td', array(
+				'align' => 'center',
+				'style' => 'color:red;',
+			    ), 'No $params["text"]:' . html_e('pre', array(),
+			    "\n" . htmlentities(debug_string_backtrace())));
+		} else if ($ct == $cl) {
+			for ($i = 0; $i < $ct; ++$ct) {
+				$rv .= html_e('th', array(
+					'class' => 'ff',
+					'align' => 'left',
+				    ), html_e('a', array(
+					'class' => 'titlebar',
+					'href' => $params['link'][$i],
+				    ), $params['text'][$i]));
 			}
 		} else {
-			for ($i=0; $i<$count; $i++) {
-				$rv.= '
-				<th align="left" class="list_table_top">'.$title_arr[$i].'</th>';
+			foreach ($params['text'] as $x) {
+				$rv .= html_e('th', array(
+					'class' => 'list_table_top',
+					'align' => 'left',
+				    ), $x);
 			}
 		}
-		$rv.= '
-		</tr>
-		</thead>
-		<tfoot><tr class="ff" align="left" bgcolor="'. $this->COLOR_HTMLBOX_BACK .'">
-		<td class="ff" colspan="'.$count.'" height="1"><img src="'.$this->imgroot.'clear.png" height="1" width="1" alt="" /></td>
-		</tr></tfoot>
-		<tbody><!-- ]listTableTopSortable -->'."\n";
+		$rv .= html_ac($spos);
+		$rv .= html_e('tfoot', array(), html_e('tr', array(
+			'class' => 'ff',
+			'align' => 'left',
+			'bgcolor' => $this->COLOR_HTMLBOX_BACK,
+		    ), html_e('td', array(
+			'class' => 'ff',
+			'colspan' => $ct,
+			'height' => 1,
+		    ), html_e('img', array(
+			'src' => $this->imgroot . "clear.png",
+			'height' => 1,
+			'width' => 1,
+			'alt' => " ",
+		    )))));
+		$rv .= html_eo('tbody');
+		$rv .= "\n<!-- ]listTableStart -->";
 		return $rv;
 	}
 



More information about the evolvis-commits mailing list