/** * 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) { parent::__construct('input', array('type' => 'submit', 'name' => $name, 'class' => 'submit', 'value' => $title)); if (RTK::SetAndNotNull($args)) { $this->AddAttributes($args); } }
/** * 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) { parent::__construct('div', array('id' => $id, 'class' => $class)); if (RTK::SetAndNotNull($args)) { $this->AddAttributes($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 = '[IMG]', $args = null) { parent::__construct(); $img = new HtmlElement('img', $args); $img->AddAttributes(array('src' => RTK::GetBaseURL() . $imgurl, 'alt' => $alttext)); $this->AddChild($img); }
/** * Returns true if the client is connecting via HTTPS, otherwise it returns false. * @param boolean $forcehttps Specify if the link has to have https */ public static function GetBaseURL($forcehttps = false) { if (RTK::HasHttps() || $forcehttps) { return 'https://' . RTK_BASEURL; } else { return 'http://' . RTK_BASEURL; } }
/** * 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 = null, $name = null, $forcehttps = false, $args = null) { if ($url == null) { $url = RTK_EMPTYSTRING; } if ($name == null) { $name = RTK_EMPTYSTRING; } parent::__construct('a', array('href' => RTK::GetBaseURL($forcehttps) . $url), $name); $this->AddAttributes($args); }
public function __tostring() { $result = RTK_EMPTYSTRING; if (RTK::SetAndNotNull($this->_list) && is_array($this->_list)) { ksort($this->_list); foreach ($this->_list as $key => $val) { if (strstr(RTK_BOOLEANPARAMETERS, '|' . $key . '|') && $val == true) { $result .= RTK_SINGLESPACE . $key; } else { $result .= RTK_SINGLESPACE . $key . '="' . $val . '"'; } } } return $result; }
/** * A widget containing a dropdown selector * @param string $name The HTML name of the element * @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 item in the dropdown * @param HtmlAttributes $args Allows custom html tag arguments to be specified (not recommended) **/ public function __construct($name, $options, $selected = null, $args = null) { parent::__construct('select', array('name' => $name, 'id' => $name)); $this->AddAttributes($args); $option_value = RTK_EMPTYSTRING; $option_title = RTK_EMPTYSTRING; foreach ($options as $option) { if (RTK::ArrayIsLongerThan($option, 1)) { $option_value = $option[0]; $option_title = $option[1]; } else { $option_value = $option_title = $option; } $optionargs = array('value' => $option_value); if ($selected == $option_value) { $optionargs['selected'] = true; } $this->AddChild(new HtmlElement('option', $optionargs, $option_title)); } }
/** * A widget containing a line of user inputs for a form element * @param string $name The HTML name (and #id) of the input element(s) and label * @param string $title The text written next to the input element(s) * @param string $inputs The input element(s) for the form line **/ public function __construct($name, $title, $inputs) { parent::__construct('div', array('class' => 'formline')); // Add the label $this->AddContainer(new HtmlElement('label', array('for' => $name), $title), 'LABEL'); // Create the input group $group = new HtmlElement('div', array('class' => 'formgroup')); if (is_a($inputs, 'HtmlElement')) { $group->AddChild($inputs); } elseif (RTK::ArrayIsLongerThan($array, 0)) { foreach ($inputs as $input) { if (is_a($input, 'HtmlElement')) { $group->AddChild($input); } } } $this->AddContainer($group, 'GROUP'); // Add the error section $this->AddContainer(new HtmlElement(), 'ERROR'); }
// load all necessary config and class files, etc. include_once "class" . DIRECTORY_SEPARATOR . "RTK" . DIRECTORY_SEPARATOR . "rtk.php"; $showpage = RTK_EMPTYSTRING; if (RTK::SetAndNotNull($_GET, 'page')) { $showpage = $_GET['page']; } $showstyle = RTK_EMPTYSTRING; if (RTK::SetAndNotNull($_GET, 'style')) { $showstyle = $_GET['style']; } $pages = $styles = array(); foreach (glob('example' . DIRECTORY_SEPARATOR . '*.php') as $file) { $pages[] = pathinfo($file)['filename']; } foreach (glob(RTK_DIRECTORY . 'style' . DIRECTORY_SEPARATOR . '*') as $dir) { $styles[] = RTK::RemovePrefix(pathinfo($dir)['filename'], 'rtk-'); } if (!in_array($showpage, $pages)) { $showpage = $pages[0]; } if (!in_array($showstyle, $styles)) { $showstyle = $styles[0]; } // create the requested page $RTK = new HtmlDocument("RTK example test site"); $RTK->ClearStylesheets(); $faviconpath = 'image' . DIRECTORY_SEPARATOR . 'favicon.png'; if (file_exists($faviconpath)) { $RTK->SetFavicon($faviconpath); } $RTK->AddStylesheet(RTK_DIRECTORY . 'style/rtk-' . $showstyle . '.css');
/** * Converts the element into an HTML string * @param boolean $newline Specifies whether or not to start with a newline * @return string A string containing the entire HTML structure of the element and it's children **/ public function ToString(&$newline) { $return = RTK_EMPTYSTRING; if ($this->_tag != null) { if ($newline) { $return .= RTK_OUTPUTNEWLINE; } else { $newline = true; } if ($this->_oneline <= 1) { $return .= str_repeat(RTK_OUTPUTINDENT, $this->_indent); } $return .= '<' . $this->_tag; if (RTK::SetAndNotNull($this->_attributes) && RTK::ArrayIsLongerThan($this->_attributes, 0)) { ksort($this->_attributes); foreach ($this->_attributes as $key => $val) { if (strstr(RTK_BOOLEANPARAMETERS, '|' . $key . '|') && $val == true) { $return .= RTK_SINGLESPACE . $key; } else { $return .= RTK_SINGLESPACE . $key . '="' . $val . '"'; } } } if ($this->_endtag != RTK_EMPTYSTRING) { $return .= $this->_endtag . ">"; } else { if (sizeof($this->_children) == 0) { if ($this->_content != RTK_EMPTYSTRING) { if (strstr($this->_content, RTK_NEWLINE) && !strstr(RTK_PRESERVECONTENTS, $this->_tag)) { $return .= '>'; foreach (explode(NEWLINE, $this->_content) as $line) { if ($line == RTK_EMPTYSTRING || $line[strlen($line) - 1] != '>') { $line .= '<br />'; } $return .= RTK_OUTPUTNEWLINE . str_repeat(RTK_OUTPUTINDENT, $this->_indent + 1) . $line; } $return .= RTK_OUTPUTNEWLINE . str_repeat(RTK_OUTPUTINDENT, $this->_indent) . '</' . $this->_tag . '>'; } else { $return .= '>' . $this->_content . '</' . $this->_tag . '>'; } } elseif (strstr(RTK_VOIDELEMENTS, '|' . $this->_tag . '|')) { $return .= ' />'; } elseif (strstr(RTK_NONVOIDELEMENTS, '|' . $this->_tag . '|') || $this->_oneline) { $return .= '></' . $this->_tag . '>'; } else { $return .= ' />'; } } else { if ($this->_oneline) { $return .= '>'; foreach ($this->_children as $c) { $return .= $c; } $return .= '</' . $this->_tag . '>'; } else { $return .= '>' . RTK_OUTPUTNEWLINE; if ($this->_content != RTK_EMPTYSTRING) { $return .= str_repeat(RTK_OUTPUTINDENT, $this->_indent + 1) . str_replace("\n", '<br />' . RTK_OUTPUTNEWLINE . str_repeat(RTK_OUTPUTINDENT, $this->_indent), $this->_content) . RTK_OUTPUTNEWLINE; } if (sizeof($this->_children) > 0) { $newline = false; foreach ($this->_children as $c) { $return .= $c->ToString($newline); } } $return .= RTK_OUTPUTNEWLINE . str_repeat(RTK_OUTPUTINDENT, $this->_indent) . '</' . $this->_tag . '>'; } } } } else { $sizeofchildren = sizeof($this->_children); if ($sizeofchildren > 0) { $this->UpdateChildren(); // INFO: commenting this line seems to have fixed a double-linebreak issue, but may now cause a no-linebreak in some cases... stay tuned... //if ($newline) { $return .= RTK_OUTPUTNEWLINE; } for ($i = 0; $i < $sizeofchildren; $i++) { $return .= $this->_children[$i]->ToString($newline); } } } return $return; }
/** * Creates a list of HTML attributes from an array of key/values * @param array $array The array with named key/value pairs **/ public static function ListFromArray($array = null) { $list = array(); if (is_array($array) && RTK::ArrayIsLongerThan($array, 0)) { foreach ($array as $key => $value) { $list[] = new HtmlAttribute($key, $value); } } return $list; }
/** * Gets the class for a specific cell * @param integer $i The index of the cell * @param integer $last The index of the last cell in the row * @param boolean $isheader Determines whether the cell is in a header row or not **/ private function GetCellClass($i, $last, $isheader = false) { $value = 'lv_cell'; RTK::FlipBool($this->_alternatecell); if ($i === 0) { $value .= ' lv_firstcell'; } if ($isheader) { $value .= ' lv_headercell'; if ($this->_alternatecell) { $value .= ' lv_altheadercell'; } } if ($this->_alternatecell) { $value .= ' lv_headercell'; } if ($i == $last) { $value .= ' lv_lastcell'; } if (in_array($i, $this->_compressedcols)) { $value .= ' lv_smallcell'; } return $value; }
/** * 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 = RTK_EMPTYSTRING; $option_title = RTK_EMPTYSTRING; foreach ($options as $option) { if (RTK::ArrayIsLongerThan($option, 1)) { $option_value = $option[0]; $option_title = $option[1]; } else { $option_value = $option_title = $option; } $args = array('type' => 'radio', 'class' => 'radiobox', 'name' => $name, 'id' => $name, 'value' => $option_value); if ($selected == $option_value) { $args['checked'] = true; } $group->AddChild(new HtmlElement('input', $args)); $group->AddChild(new HtmlElement('span', null, $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); }