'100%',
'color' => '#ccffcc',
'color_raw' => '#ccccff',
'color_null' => '#ffcccc',
'color_bool' => '#ccc',
'raw_params' => array
(
'raw',
'header',
'banner',
),
);
// --------------------------------------------------------------------
// Public methods
// --------------------------------------------------------------------
/**
* Returns or print the CSS style
*
* @access public
* @param bool
* @return string|void
*/
public static function css($print = FALSE)
{
$css = implode(' ', self::$css);
if (!$print)
{
return $css;
}
echo $css;
}
/**
* Returns or print the table
*
* @access public
* @param array
* @param bool
* @param array
* @return string|void
*/
public static function table($content, $print = FALSE, $settings = array())
{
self::$settings = array_merge(self::$settings, $settings);
$table = self::build_table($content);
if (!$print)
{
return $table;
}
echo $table;
}
// --------------------------------------------------------------------
// Private methods
// --------------------------------------------------------------------
/**
* Builds table
*
* @access private
* @param array
* @param int
* @param string
* @param string
* @param bool
* @return string
*/
private static function build_table($content, $width = NULL, $td_width = '50%', $class = 'rtg_outer', $build_th = TRUE)
{
if (!$width)
{
$width = self::$settings['width'];
}
$table = '
';
if ($build_th)
{
$table .= '| Parameter | Value |
';
}
foreach ($content as $param => $value)
{
$table .= self::build_tr($param, $value, $class, $td_width);
}
if ($build_th)
{
$table .=
'| '.
'HSDN Recursive Table Generator'.
' |
';
}
$table .= '
';
return $table;
}
/**
* Builds table tr
*
* @access private
* @param string
* @param mixed
* @param string
* @param string
* @return string
*/
private static function build_tr($param, $value, $class, $width)
{
$bg_color = self::$settings['color'];
list($color, $param) = self::build_param($param);
if (!is_null($color))
{
$bg_color = $color;
}
list($color, $value) = self::build_value($value);
if (!is_null($color))
{
$bg_color = $color;
}
$tr = '';
$tr .= '| '.$param.' | ';
if (is_array($value))
{
$tr .= '';
$tr .= self::build_table($value, '100%', '1%', 'rtg_inner', FALSE);
$tr .= ' | ';
}
else
{
$tr .= '';
$tr .= $value;
$tr .= ' | ';
}
$tr .= '
';
return $tr;
}
/**
* Build param
*
* @access private
* @param string
* @return array
*/
private static function build_param($param)
{
$color = NULL;
foreach (self::$settings['raw_params'] as $raw_param)
{
if ($param === $raw_param)
{
$color = self::$settings['color_raw'];
break;
}
}
if (is_numeric($param))
{
$param = 'Entry '.($param + 1);
}
else
{
$param = str_replace(' ', ' ', ucwords(str_replace('_', ' ', htmlspecialchars($param))));
}
return array($color, $param);
}
/**
* Build value
*
* @access private
* @param string
* @return array
*/
private static function build_value($value)
{
$color = NULL;
if (!is_array($value))
{
if (is_null($value))
{
$color = self::$settings['color_null'];
$value = '<no data>';
}
elseif (is_bool($value))
{
$color = self::$settings['color_bool'];
if ($value === TRUE)
{
$value = '<data boolean: TRUE>';
}
else
{
$value = '<data boolean: FALSE>';
}
}
else
{
$value = nl2br(htmlspecialchars($value));
}
}
return array($color, $value);
}
}
/* End of File */