public function addTextChild($text) { $child = new self(); $child->setParent($this); $child->setText($text); $this->addChild($child); }
/** One-stop fn to provide help Only call this, and all necessary fields will be filled. Note, that the position of the help section within the html page will depend on the order this fn() is called. */ public static function DoHelp($text, $icon = null) { global $PAGE_ELEMS; $help_elem = new self(); //$help_elem->setIcon('vcard.png'); $help_elem->setText($text); $PAGE_ELEMS[] =& $help_elem; }
/** * Message box * * @param Window $parent * @param string $text * @param string $title * @return void */ public static function box(Window $parent, $text, $title) { $msg = new self($parent); $msg->setText($text); $msg->setTitle($title); $msg->start(); unset($msg); }
/** * Static factory. * @param string element name (or NULL) * @param array|string element's attributes (or textual content) * @return TexyHtml */ public static function el($name = NULL, $attrs = NULL) { $el = new self(); $el->setName($name); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== NULL) { $el->setText($attrs); } return $el; }
public static function getInstance() { $db = PearDatabase::getInstance(); $query = 'SELECT tandc FROM ' . self::tableName; $result = $db->pquery($query, array()); $instance = new self(); if ($db->num_rows($result) > 0) { $text = $db->query_result($result, 0, 'tandc'); $instance->setText($text); } return $instance; }
/** * Static factory. * @param string element name (or NULL) * @param array|string element's attributes (or textual content) * @return Html */ public static function el($name = NULL, $attrs = NULL) { $el = new self(); $parts = explode(' ', $name); $el->setName(array_shift($parts)); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== NULL) { $el->setText($attrs); } foreach ($parts as $pair) { $pair = explode('=', $pair, 2); $el->attrs[$pair[0]] = isset($pair[1]) ? trim($pair[1], '"') : TRUE; } return $el; }
/** * Static factory. * @param string element name (or NULL) * @param array|string element's attributes (or textual content) * @return Html */ public static function el($name = NULL, $attrs = NULL) { $el = new self(); $parts = explode(' ', $name, 2); $el->setName($parts[0]); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== NULL) { $el->setText($attrs); } if (isset($parts[1])) { foreach (String::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\\s))?#i') as $m) { $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE; } } return $el; }
public static function el($name = NULL, $attrs = NULL) { $el = new self(); $parts = explode(' ', $name, 2); $el->setName($parts[0]); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== NULL) { $el->setText($attrs); } return $el; }
static function el($name = NULL, $attrs = NULL) { $el = new self(); $parts = explode(' ', $name, 2); $el->setName($parts[0]); if (is_array($attrs)) { $el->attrs = $attrs; } elseif ($attrs !== NULL) { $el->setText($attrs); } if (isset($parts[1])) { preg_match_all('#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\\s))?#i', $parts[1] . ' ', $parts, PREG_SET_ORDER); foreach ($parts as $m) { $el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE; } } return $el; }
/** * Returns an element instance from the given source. * The first and last tag will be used as the opening and closing tag respectively. * Anything between those tags will be used as contents. * * @param string $html HTML source code * @return \Jyxo\HtmlTag * @throws \InvalidArgumentException If an invalid HTML source was given */ public static function createFromSource(string $html) : self { if (preg_match('~<(\\w+)(\\s[^>]*)+>(.*)((<[^>]+>)?[^>]*)$~', $html, $matches)) { $tag = new self($matches[1]); if ('' !== $matches[3]) { // @todo Maybe some kind of recursion to create a tree of elements $tag->setText($matches[3]); } if (preg_match_all('/(\\w+)\\s*=\\s*"([^"]+)"/', $matches[2], $submatches, PREG_PATTERN_ORDER)) { $attrs = array_combine($submatches[1], $submatches[2]); $tag->setAttributes($attrs); } return $tag; } throw new \InvalidArgumentException('Zadaný text neobsahuje validní html'); }
public static function message($message) { $instance = new self('message/text'); $instance->setText($message); return json_encode($instance); }