Source for file pnHTML.php
Documentation is available at pnHTML.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnHTML.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* Set object to keep generated HTML.
* After calling SetOutputMode() with this value, all future calls to
* pnHTML methods will store their HTML in the objecr rather than
* returning it to the calling process.
* $const _PNH_KEEPOUTPUT Keep the output from method calls
* Set object to return generated HTML to caller.
* After calling SetOutputMode() with this value, all future calls to
* pnHTML methods will return their HTML directly to the calling process
* rather than storing it within the object.
* $const _PNH_RETURNOUTPUT Return the output from method calls
define('_PNH_RETURNOUTPUT', 1);
* Set incoming text to be copied verbatim to the output buffer
* $const _PNH_VERBATIMINPUT Do not parse incoming text
define('_PNH_VERBATIMINPUT', 0);
* Set incoming text to be parsed for display before putting in the output buffer
* $const _PNH_PARSEINPUT Parse incoming text
* HTML creation and display functions
* This class is designed to make generating HTML output in Zikula
* very simple, and also allows for much greater control of output by
* the site administrator.
* <strong>Example</strong>
* $colors = array(array('id' => 1,
* 'encoding' => 'ff0000'),
* 'encoding' => '00ff00'),
* 'encoding' => '0000ff'));
* // Create the HTML object and start it
* $myhtml = new pnHTML();
* // Add table showing encoding information
* $myhtml->TableStart('Colors and Their Encodings', array('Color', 'Encoding'));
* foreach ($colors as $color) {
* $info = array($color['name'], $color['encoding']);
* $myhtml->TableAddRow($info);
* // Add form to select a color
* $myhtml->Text('<P><P>');
* $myhtml->FormStart('colorchosen.php');
* $myhtml->Text('Select a color: ');
* $myhtml->FormList('chosen', $colorinfo);
* $myhtml->FormSubmit('That\'s the color I want');
* // End the HTML object and print it
* ==============================================================================*
* ==============================================================================
* Specific headers which must be printed prior to the main body of HTML
* The pending HTML output
* Current tab index value
* @since 1.13 - 2002/01/23
* @var integer $fileupload
* ==============================================================================*
* ==============================================================================
* @return boolean Always returns true
$this->header = array ();
* Return the current state of the output stream
* @since 1.13 - 2002/01/23
* @return integer Current output state
// The ONLY time this should be accessed directly
* Set state of the output stream
* @since 1.14 - 2002/01/29
* @param int $st Output state to set to
* @return integer Previous state
// The ONLY time this should be accessed directly
// The ONLY time this should be accessed directly
* Retrive the current input state
* @since 1.13 - 2002/01/23
* @return integer Current input state
// The ONLY time this should be accessed directly
* Set state of the input stream
* @since 1.14 - 2002/01/29
* @param int $st Input state to set to
* @return integer Previous state
// The ONLY time this should be accessed directly
// The ONLY time this should be accessed directly
* Set the form to allow file uploads to take place
* @since 1.13 - 2002/01/23
* @return boolean Always returns true
* @see FormStart(), FormFile()
* ==============================================================================*
* ==============================================================================
* Return the HTML output from the buffer.
* Note that this function does not clear out the object's buffer.
* @since 1.15 - 2002/01/30
* @return string An HTML string
return implode($this->header, "\n") . "\n" . $this->output;
* Print the HTML currently held in the object.
* Note that this function does not clear out the object's buffer.
// Headers set by the system
foreach ($this->header as $headerline) {
// Removed as per patch #264 bvdbos
// header('Content-length: ' . strlen($this->output));
* ==============================================================================*
* ==============================================================================
* Put the appropriate HTML tags in place to create a valid start to HTML output.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
// print '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
// Fixes bug 16 Neo submitted by keops 14/09/2002
// Remove extra table on output for XTE for .726
// print '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="left" valign="top">';
$this->output .= $output;
* Put the appropriate HTML tags in place to create a valid end to HTML output.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
//if (!class_exists('Xanthia')) {
// Do we really need an extra table here? - markwest
// Not just with Xanthia themes but rendered modules
// This prevents this like RSS theme overrrides etc.
//print '</td></tr></table><!-- testing tables footer -->';
$this->output .= $output;
* @author Greg 'Adam Baum'
* @since 1.13 - 2002/01/23
* @param integer $startnum start iteam
* @param integer $total total number of items present
* @param string $urltemplate template for url, will replace '%%' with item number
* @param integer $perpage number of links to display (default=10)
function Pager($startnum, $total, $urltemplate, $perpage = 10)
// Quick check to ensure that we have work to do
if ($total <= $perpage) {
// Make << and >> do paging properly
// Display subset of pages if large number
// Check that we are needed
if ($total <= $perpage) {
// Show Introtext for WCAG
$compoutput->Text(_PAGE. ' ');
$compoutput->URL($url, '<<');
$compoutput->Text(' | ');
for ($curnum = 1; $curnum <= $total; $curnum += $perpage) {
if (($startnum < $curnum) || ($startnum > ($curnum + $perpage - 1))) {
//mod by marsu - use sliding window for pagelinks
if ((($pagenum% 10)== 0) // link if page is multiple of 10
|| ($pagenum== 1) // link first page
|| (($curnum > ($startnum- 4* $perpage)) //link -3 and +3 pages
&& ($curnum < ($startnum+ 4* $perpage)))
// Not on this page - show link
$compoutput->URL($url, $pagenum);
$compoutput->Text(' | ');
// On this page - show text
$compoutput->Text($pagenum. ' ');
$compoutput->Text(' | ');
if (($curnum >= $perpage + 1) && ($startnum < $curnum - $perpage)) {
$url = preg_replace('/%%/', $curnum - $perpage, $urltemplate);
$compoutput->URL($url, '>>');
return $compoutput->PrintPage();
$this->output .= $compoutput->GetOutput();
* Redirect the user to another page
* This function is broken, do not use it!
* @param string $url URL to redirect to
* @param integer $waittime Seconds to wait before redirecting
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
* @todo This function is broken, do not use it!
// Removing leading slashes from path
// Removing leading slashes from redirect url
$output = "Location: http://$server/$url";
$output = "Location: http://$server/$path/$url";
$this->header[] = $output;
* composite function for generic confirmation of action
* @param string $confirm_text Confirmation message to display
* @param string $confirm_url URL to go to if confirm button is clicked
* @param string $cancel_text Link text cor the cancel message
* @param string $cancel_url URL to go to is action is canceled
* @param array $arg An array of args to create hidden fields for
function ConfirmAction($confirm_text, $confirm_url, $cancel_text, $cancel_url, $arg = array ())
$compoutput->FormStart($confirm_url);
$compoutput->Text($confirm_text);
$compoutput->Linebreak(2);
$arg['confirmation'] = 1;
$compoutput->FormHidden($arg);
$compoutput->Linebreak(2);
$compoutput->URL($cancel_url, $cancel_text);
return $compoutput->PrintPage();
$this->output .= $compoutput->GetOutput();
* ==============================================================================*
* ==============================================================================
* Add free-form text to the object's buffer
* @param string $text The text string to add
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
* Add free-form text to the object's buffer as a title
* @param string $text the text string to add
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$this->output .= $output;
* Add free-form text to the object's buffer as a title
* @param string $text the text string to add
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$this->output .= $output;
* add bold text to the object's buffer
* @param string $text the text string to add
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
* @param integer $numbreaks number of linebreaks to add
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
for ($i = 0; $i < $numbreaks; $i++ ) {
* Add HTML tags for a hotlink.
* @since 1.13 - 2002/01/23
* @param string $url the URL of the link
* @param string $text the text that the URL is anchored to
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function URL($url= '', $text= '')
$output = '<a href="' . $url . '" ';
$output .= 'title="' . $title . '">'. $text;
$this->output .= $output;
* ==============================================================================*
* ==============================================================================
* Add HTML tags for the start of a table.
* @param string $title the title of the table
* @param array $headers an array of column headings
* @param integer $border size of table borders
* @param string $width the width of the table. can be null if no width needs
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function TableStart($title = '', $headers = array(), $border = 0, $width = '100%', $cellpadding = 0, $cellspacing = 0)
// Wrap the user table in our own invisible table to make the title sit properly
$output = '<table border="' . $border . '"' . ((empty ($width)) ? '' : ' width="' . $width . '"') . ' cellpadding="' . $cellpadding . '" cellspacing="' . $cellspacing . "\">\n";
$output .= '<tr><th align="center">' . $title . '</th></tr>' . "\n";
$output .= '<table border="' . $border . '" width="100%">';
foreach ($headers as $head) {
$output .= '<th>' . $head . '</th>';
$this->output .= $output;
* Add HTML tags for the start of a table row.
* @param string $align Default horizantal alignment for all columns on this row
* @param string $valign Default vertical alignment for all columns on this row
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$output = '<tr align="' . $align . '" valign="' . $valign . '">';
$this->output .= $output;
* Add HTML tags for the start of a table column.
* @param integer $colspan number of columns that this column spans
* @param string $align Horizantal alignment of the column
* @param string $valign Vertical alignment of this column
* @param integer $rowspan Total rows this column uses
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function TableColStart($colspan = 1, $align = 'center', $valign = 'middle', $rowspan = 1)
$output = '<td colspan="' . $colspan . '" rowspan="' . $rowspan . '" align="' . $align . '" valign="' . $valign . '">';
$this->output .= $output;
* Add HTML tags for the end of a table column.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$this->output .= $output;
* Add HTML tags for the end of a table row.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$this->output .= $output;
* Add HTML tags for the end of a table.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$output = '</table></td></tr></table>';
$this->output .= $output;
* Add HTML tags for a row of a table.
* @param array $row an array of row entries
* @param string $align (optional) the alignment of the row, which can be
* one of <code>'left'</code>, <code>'center'</code> or <code>'right'</code>
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function TableAddRow($row, $align = 'center', $valign = 'middle')
$output = '<tr align="' . $align . '" valign="' . $valign. '">';
// test to see if we are using the latest array style
foreach ($row as $rowitem) {
if (!isset ($rowitem['content'])) {
$rowitem['content'] = ' ';
. ((empty ($rowitem['align'])) ? '' : ' align="'. $rowitem['align']. '"')
. ((empty ($rowitem['valign'])) ? '' : ' valign="'. $rowitem['valign']. '"')
. ((empty ($rowitem['color'])) ? '' : ' bgcolor="'. $rowitem['color']. '"')
. ((empty ($rowitem['class'])) ? $rowitem['content'] : $rowitem['content'])
foreach ($row as $rowitem) {
$output .= '<td>' . $rowitem . '</td>';
$this->output .= $output;
* ==============================================================================*
* ==============================================================================
* Add HTML tags to start a form.
* @param string $action the URL that this form should go to on submission
* @param string $id OPTIONAL - the unique ID of this form
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
. ' enctype="'. ((empty ($this->fileupload)) ? 'application/x-www-form-urlencoded' : 'multipart/form-data'). '"';
$this->output .= $output;
* Add HTML tags to end a form.
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
$output = '</div></form>';
$this->output .= $output;
* Add HTML tags for a submission button as part of a form.
* @param string $label (optional) the name of the submission button. This
* defaults to <code>'Submit'</code>
* @param string $accesskey (optional) accesskey to active this button
* @param string $name (optional) name for this button
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormSubmit($label = 'Submit', $accesskey = '', $name = '')
. ' tabindex="'. $this->tabindex. '"'
$this->output .= $output;
* Add HTML tags for a text field as part of a form.
* @param string $fieldname the name of the text field
* @param string $contents (optional) the inital value of the text field
* @param integer $size (optional) the size of the text field on the page
* in number of characters
* @param integer $maxlength (optional) the maximum number of characters the
* @param boolean $password (optional) field acts as a password field
* @param string $accesskey (optional) accesskey to active this item
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormText($fieldname, $contents = '', $size = 16, $maxlength = 64, $password = false, $accesskey = '')
if (empty ($fieldname)) {
. ' type="'. (($password) ? 'password' : 'text'). '"'
. ' tabindex="'. $this->tabindex. '"'
$this->output .= $output;
* Add HTML tags for a text area as part of a form
* @param string $fieldname the name of the text area filed
* @param string $contents the initial value of the text area field
* @param integer $rows the number of rows that the text area
* @param integer $cols the number of columns that the text area
* @param string $wrap (optional) wordwrap mode to use, either <code>'soft'</code> or <code>'hard'</code>
* @param string $accesskey (optional) accesskey to active this item
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormTextArea($fieldname, $contents = '', $rows = 6, $cols = 40, $wrap = 'soft', $accesskey = '')
if (empty ($fieldname)) {
//.' wrap="'.(($wrap = 'soft') ? 'soft' : 'hard').'"' // not proper HTML, but too useful to abandon yet
. ' tabindex="'. $this->tabindex. '"'
$this->output .= $output;
* Add HTML tags for a hidden field as part of a form.
* @param mixed $fieldname the name of the hidden field. can also be an array.
* @param string $value the value of the hidden field
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
if (empty ($fieldname)) {
foreach ($fieldname as $n=> $v) {
//.' id="'.DataUtil::formatForDisplay($n).'"'
//.' id="'.DataUtil::formatForDisplay($fieldname).'"'
$this->output .= $output;
* Add HTML tags for a select field as part of a form.
* @since 1.13 - 2002/01/23
* @param string $fieldname the name of the select field
* @param array $data an array containing the data for the list. Each array
* entry is itself an array, containing the values for <code>'id'</code>
* (the value returned if the entry is selected), <code>'name'</code>
* (the string displayed for this entry) and <code>'selected'</code>
* (optional, <code>1</code> if this option is selected)
* @param integer $multiple (optional) <code>1</code> if the user is allowed to
* make multiple selections
* @param integer $size (optional) the number of entries that are visible in the
* select at any one time. Note that if the number
* of actual items is less than this value then the select box will
* shrink automatically to the correct size
* @param string $selected (optional) selected value of <code>id</code>
* @param string $accesskey (optional) accesskey to active this item
* @param string $events: javascript events
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormSelectMultiple($fieldname, $data, $multiple= 0, $size= 1, $selected = '', $accesskey= '', $events= '')
if (empty ($fieldname)) {
// Set up selected if required
for ($i= 0; !empty($data[$i]); $i++ ) {
if ($data[$i]['id'] == $selected) {
$data[$i]['selected'] = 1;
. (($multiple == 1) ? ' multiple="multiple"' : '')
. ' tabindex="'. $this->tabindex. '"';
foreach ($data as $datum) {
. ((empty ($datum['selected'])) ? '' : ' selected="selected"')
$this->output .= $output;
* Add HTML tags for a checkbox or radio button field as part of a form.
* @since 1.13 - 2002/01/23
* @param string $fieldname the name of the checkbox field
* @param string $value (optional) the value of the checkbox field
* @param boolean $checked (optional) the field is checked
* @param string $type (optional) the type of field this is, either
* <code>'checkbox'</code> or <code>'radio'</code>
* @param string $accesskey (optional) accesskey to active this item
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormCheckbox($fieldname, $checked = false, $value = '1', $type = 'checkbox', $accesskey = '')
if (empty ($fieldname)) {
. ' type="'. (($type == 'checkbox') ? 'checkbox' : 'radio'). '"'
. (($checked) ? ' checked="checked"' : '')
. ' tabindex="'. $this->tabindex. '"'
$this->output .= $output;
* Add HTML tags for a file upload field as part of a form.
* @since 1.13 - 2002/01/23
* @param string $fieldname the name of the field
* @param integer $size (optional) the size of the field on the page in number
* @param integer $maxsize (optional) the maximum file size allowed (in bytes)
* @param string $accesskey (optional) accesskey to active this item
* @return string An HTML string if <code>ReturnHTML()</code> has been called,
function FormFile($fieldname, $size = 32, $maxsize = 1000000, $accesskey = '')
if (empty ($fieldname)) {
. ' tabindex="'. $this->tabindex. '"'
$this->output .= $output;
|