private function getAllMatches($search, htmlpelements\BaseElement $searchIn, \htmlp\HTMLP $htmlp, $children = true) { $matches = array(); $search = trim($search); if ($searchIn->is($search)) { $matches[] = $searchIn; } if ($children) { foreach ($searchIn->children as $child) { $matches = array_merge($this->getAllMatches($search, $child, $htmlp), $matches); } } return $matches; }
/** * Get the next HTMLElement * * @param string $file The entire file content. * @param int $index The current position in our walker. * @param BaseElement $parent The parent of the next element. * * @return BaseElement */ public function nextElement($file, &$index, $parent) { $string = new \StringHelpers(); $string->set($file); $elements_name = ''; $elements_text = ''; $comment = false; $script_closed = true; $script_depth = 0; $is_alt_script = $is_inclusion = false; $thisElement = new BaseElement($this); $first_character = true; $single_line_element = false; while (false !== ($char = $string->charAt($index))) { if ($char == '{') { break; } elseif ($char == ';') { $single_line_element = true; break; } if ($first_character && $char == " ") { $index++; continue; } elseif ($first_character) { $first_character = false; } $elements_name .= $char; $index++; } $index++; if ($elements_name && $elements_name[strlen($elements_name) - 1] == ' ') { $elements_name = substr($elements_name, 0, strlen($elements_name) - 1); } $elements_true_name = $this->get_name_from_name($elements_name); $thisElement->set_type($elements_true_name); $thisElement->set_attributes($this->get_attributes_from_name($elements_name)); $is_attribute = false; $is_style = false; switch ($elements_true_name) { case 'style': $is_style = true; $is_alt_script = true; break; case 'script': $is_alt_script = true; break; case 'pre': $is_alt_script = true; break; case 'import': $is_inclusion = true; $thisElement = new EmptyHE($this); break; } if (strlen($elements_true_name) <= 0) { return $this->document; } if ($elements_true_name[0] == '@') { $is_alt_script = true; $is_attribute = true; } while (($file[$index] != '}' || !$script_closed || $comment) && !$single_line_element) { if (!$is_alt_script) { if ($file[$index] == " " && !$comment || $file[$index] == "\t" || $file[$index] == "\r") { # Skip any empty characters } elseif ($file[$index] == '"' && $file[$index - 1] != "\\" || $comment) { if (!$comment && $file[$index] == '"') { $comment = true; $index++; } if ($comment && $file[$index] == '"' && $file[$index - 1] != "\\") { $comment = false; $index++; if ($is_inclusion) { $htmlp = new \htmlp\HTMLP(); if (file_exists($elements_text . '.template')) { $htmlp->process($elements_text . '.template'); $thisElement->append_content($htmlp->get_render(), true); } else { $thisElement->append_content('File does not exist: ' . $elements_text . '.template', true); } } else { $thisElement->append_content($elements_text, true); } $elements_text = ''; continue; } if ($file[$index] == '\\' && $file[$index - 1] != '\\') { $index++; continue; } $elements_text .= $file[$index]; } else { $this->nextElement($file, $index, $thisElement); } } else { $elements_text .= $file[$index]; if ($file[$index] == '{') { $script_depth++; $script_closed = false; } elseif ($file[$index] == '}') { $script_depth--; if ($script_depth == 0) { $script_closed = true; } } } $index++; } if ($single_line_element) { } elseif ($is_attribute) { $attribute_name = substr($elements_true_name, 1); $line = preg_replace('/[\\t\\n]/', "", $elements_text); $script = trim($line); switch ($attribute_name) { case "style": $parent->add_attribute($attribute_name, $script); break; case "include": $template_name = explode(' ', $elements_name); $template_name = $template_name[1]; $element = new TemplateHE($this); $element->template = $template_name; $element->set_content($script); $parent->add_child_element($element); break; case "template": global $htmlp_templates; $template_name = explode(' ', $elements_name); $template_name = $template_name[1]; $htmlp_templates[$template_name] = $script; break; case "config": $rules = CSSParser::Parse($script, true); $this->config = array_merge($this->config, $rules); $this->reloadConfig(); break; default: //$parent->add_attribute($attribute_name, $script); break; } } elseif ($is_alt_script) { global $emailprocessor; if ($is_style && $emailprocessor->isEnabled('styleHandling')) { $rules = CSSParser::Parse($elements_text, false); $emailprocessor->addRules($rules); } else { if ($elements_true_name != 'pre') { $line = str_replace("\t", "", $elements_text); $script = substr($line, 1 + ($line[1] == ' ' ? 1 : 0), strlen($line)); $thisElement->append_content($script); $parent->add_child_element($thisElement); } else { $script = $elements_text; $thisElement->append_content($script); $parent->add_child_element($thisElement); } } } else { $parent->add_child_element($thisElement); } $index++; return $this->document; }
public function __construct($htmlp, $type = '') { parent::__construct($htmlp); }