/** * A widget for displaying a list of items * @param string[] $columnheaders The headers in the top row * @param boolean $alternaterow Determines if different styling should be applied to every other row * @param boolean $alternatecell Determines if different styling should be applied to every other cell * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($columnheaders, $alternaterow = true, $alternatecell = false, $args = null) { HtmlAttributes::Assure($args); $args->Add('class', 'listview', false); parent::__construct(); $this->AddContainer(new HtmlElement('div', $args, EMPTYSTRING, new HtmlElement('table')), 'table'); //$this->SetPointer('table'); if ($alternaterow == false) { $this->_alternaterow = null; } else { $this->_alternaterow = true; } if ($alternatecell == false) { $this->_alternatecell = null; } else { $this->_alternatecell = true; } if (sizeof($columnheaders) > 0) { for ($i = 0; $i < sizeof($columnheaders); $i++) { $string = $columnheaders[$i]; if (is_string($string) && strlen($string) > 0 && $string[0] == '_') { $this->_compressedcols[] = $i; $columnheaders[$i] = substr($columnheaders[$i], 1); } } $this->AddHeader($columnheaders); } }
/** * A widget for containing/structuring other widgets (div) * @param string $id The HTML #id of the box * @param string $class The HTML .class of box * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($id = null, $class = null, $args = null) { HtmlAttributes::Assure($args); $args->Add('id', $id); $args->Add('class', $class); parent::__construct('div', $args); }
/** * A widget containing a menu * @param string $id The HTML #id of the element * @param string $class The HTML .class of element * @param string[][] $links The links in the menu * @param string $selected The title of the selected item in the menu * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($id, $class, $links, $selected = null, $args = null) { HtmlAttributes::Assure($args); $args->Add('id', $id); $args->Add('class', $class); $url = $title = null; $items = array(); foreach ($links as $link) { if (_array::IsLongerThan($link, 1)) { $url = $link[0]; $title = $link[1]; } else { $url = $title = $link; } $linkargs = null; $forcehttps = false; if (_string::StartsWith($title, '_')) { $title = _string::RemovePrefix($title, '_'); $forcehttps = true; } if ($selected != null && $selected == $title) { $linkargs = array('selected' => true); } $items[] = new RTK_Link($url, $title, $forcehttps, $linkargs); } parent::__construct($items, $args); }
/** * A widget for displaying an image (img) * @param string $imgurl The url of the image * @param string $alttext A text that will be shown if the image could not be loaded * @param boolean $forcehttps Specify if the link has to have https * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($imgurl = EMPTYSTRING, $alttext = EMPTYSTRING, $args = null) { HtmlAttributes::Assure($args); $args->Add('src', $imgurl, true); $args->Add('alt', $alttext, true); parent::__construct(); $this->AddChild(new HtmlElement('img', $args)); }
/** * A button widget * @param string $name The name/id of the button * @param string $title The text written on the button * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($name = 'submit', $title = 'Submit', $args = null) { HtmlAttributes::Assure($args); $args->Add('type', 'submit', false); $args->Add('name', $name, false); $args->Add('class', 'submit', false); $args->Add('value', $title, false); parent::__construct('input', $args); }
/** * A widget containing text (essentially just a div or span with text) * @param string $text The text to display * @param boolean $inline Determines if the widget should be span(true) or div(false) * @param string $id The HTML #id of the element * @param string $class The HTML .class of element * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($text = EMPTYSTRING, $inline = false, $id = null, $class = null, $args = null) { HtmlAttributes::Assure($args); if (Value::SetAndNotNull($id)) { $args->Add('id', $id); } if (Value::SetAndNotNull($class)) { $args->Add('class', $class); } $tag = $inline ? 'span' : 'div'; parent::__construct($tag, $args, $text); }
/** * A widget containing the links to different pages for a common URL * @param string $baseurl The base part of the URL that all links in the paginition shares * @param integer $amount The amount of items to divide into pages * @param integer $perpage The amount of items per page * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($baseurl, $amount, $perpage, $page, $args = null) { HtmlAttributes::Assure($args); $args->Add('class', 'pagination', false); if ($amount > $perpage || PAGINATIONSHOWEMPTY) { parent::__construct('ul', $args); $firstpage = 1; $lastpage = ceil($amount / $perpage); $lowerlimit = $page - PAGINATIONLINKS; $upperlimit = $page + PAGINATIONLINKS; $nolink = new HtmlElement('li', EMPTYSTRING, ' '); // First, previous if ($page > $firstpage) { $this->AddChild(new HtmlElement('li', EMPTYSTRING, EMPTYSTRING, new HtmlElement('a', array('href' => $baseurl . $firstpage . SINGLESLASH), PAGINATIONFIRST))); $this->AddChild(new HtmlElement('li', EMPTYSTRING, EMPTYSTRING, new HtmlElement('a', array('href' => $baseurl . ($page - 1) . SINGLESLASH), PAGINATIONPREV))); } else { $this->AddChild($nolink); $this->AddChild($nolink); } // Available page numbers for ($i = $lowerlimit; $i <= $upperlimit; $i++) { if ($i == $page) { $this->AddChild(new HtmlElement('li', array('class' => 'current'), $page)); } elseif ($i >= $firstpage && $i <= $lastpage) { $this->AddChild(new HtmlElement('li', EMPTYSTRING, EMPTYSTRING, new HtmlElement('a', array('href' => $baseurl . $i . SINGLESLASH), $i))); } else { $this->AddChild($nolink); } } // Next Page, Last Page if ($page < $lastpage) { $this->AddChild(new HtmlElement('li', EMPTYSTRING, EMPTYSTRING, new HtmlElement('a', array('href' => $baseurl . ($page + 1) . SINGLESLASH), PAGINATIONNEXT))); $this->AddChild(new HtmlElement('li', EMPTYSTRING, EMPTYSTRING, new HtmlElement('a', array('href' => $baseurl . $lastpage . SINGLESLASH), PAGINATIONLAST))); } else { $this->AddChild($nolink); $this->AddChild($nolink); } } else { parent::__construct(); } }
/** * A widget containing a clickable link (a) * @param string $url The url of the link * @param string $name The title of the list * @param boolean $forcehttps Specify if the link has to have https * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($url = EMPTYSTRING, $name = EMPTYSTRING, $forcehttps = false, $args = null) { HtmlAttributes::Assure($args); $args->Add('href', Site::GetBaseURL($forcehttps) . $url); parent::__construct('a', $args, $name); }
/** * Add a row of radiobuttons to the form * @param string $name The HTML name (and #id) of the input field * @param string $title The text written next to the input field * @param string[][] $options An array of options, each of which is an array of value and title * @param string $selected The value of the selected radiobutton * @param HtmlElement $container (optional) The "container" to add it to **/ public function AddRadioButtons($name, $title, $options, $selected = null, $container = null) { $group = new HtmlElement('div', array('class' => 'formgroup')); $option_value = EMPTYSTRING; $option_title = EMPTYSTRING; foreach ($options as $option) { if (_array::IsLongerThan($option, 1)) { $option_value = $option[0]; $option_title = $option[1]; } else { $option_value = $option_title = $option; } $args = new HtmlAttributes(); $args->Add('type', 'radio'); $args->Add('class', 'radiobox'); $args->Add('name', $name); $args->Add('id', $name); $args->Add('value', $option_value); if ($selected == $option_value) { $args->Add('checked', true); } $group->AddChild(new HtmlElement('input', $args)); $group->AddChild(new HtmlElement('span', EMPTYSTRING, $option_title)); } $field = new HtmlElement('div', array('class' => 'formline')); $field->AddChild(new HtmlElement('label', array('for' => $name), $title)); $field->AddChild($group); $this->AddToContainer($field, $container); }
/** * Adds a javascript to the HTML document * @param string $filename The name of the file to add * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) */ public function AddJavascript($filename, $args = null) { HtmlAttributes::Assure($args); $args->Add('src', $filename); $this->_javascripts[$filename] = new HtmlElement('script', $args); }
<?php Part::input($id, 'string'); Part::input($name, 'string'); Part::input($value, 'array', array()); Part::input($attrs, 'HtmlAttributes', new HtmlAttributes()); Part::input($classes, 'HtmlClasses', new HtmlClasses('nmc-controls-checkbox-array')); Part::input($choices, 'array'); $i = 0; $name = $name . '[]'; foreach ($choices as $key => $choiceValue) { $i++; $boxId = $id . '_' . $choiceValue; $attrs = new HtmlAttributes(); if (in_array($choiceValue, $value)) { $attrs->set('checked', 'checked'); } Part::draw('html/input', 'checkbox', $boxId, $name, (string) $choiceValue, $attrs, $classes); echo '<label for="' . $boxId . '">' . $key . '</label><br />'; }