/**
* Returns a string with a span tag with a title set
*/
- function spanTitle(string $title, string $text): string
+ function spanTitle(string $title, string $text, array | null $class): string
{
- return "<span title='$title'>$text</span> ";
+ $html = "<span";
+
+ if (!is_null($class))
+ $html .= ' class="' . implode(' ', $class) . '"';
+
+ $html .= " title='$title'>$text</span> ";
+
+ return $html;
}
/**
* Returns a string with an anchor tag
*/
- function a(string $url, string $text, string $title = null): string
+ function a(string $url, string $text, string | null $title, array | null $class): string
{
- $str = "<a href='$url'";
- if (!is_null($title)) {
- $str .= " title='$title'";
- }
- $str .= ">$text</a> ";
+ $html = "<a";
+
+ if (!is_null($class))
+ $html .= ' class="' . implode(' ', $class) . '"';
- return $str;
+ $html .= " href='$url'";
+
+ if (!is_null($title))
+ $html .= " title='$title'";
+
+ $html .= ">$text</a> ";
+
+ return $html;
}
/**
$html .= '>';
if (empty($text) && !empty($url))
- $html .= $this->a($url, $section, $title);
+ $html .= $this->a($url, $section, $title, $filtered_classes);
elseif (empty($text) && !empty($title))
- $html .= $this->spanTitle($title, $section);
+ $html .= $this->spanTitle($title, $section, $filtered_classes);
else
$html .= $section;
private function form_content(string $text, array $class, string $url, string $title): string
{
$html = "";
+ $filtered_classes = $this->filter_meta_classes($class);
// if has title and url = a with title
if (!empty($title) && !empty($url))
- $html .= $this->a($url, $text, $title);
+ $html .= $this->a($url, $text, $title, $filtered_classes);
// if has only title = span with title
elseif (!empty($title)) {
- $html .= $this->spanTitle($title, $text);
+ $html .= $this->spanTitle($title, $text, $filtered_classes);
}
// if has only url = a
elseif (!empty($url))
- $html .= $this->a($url, $text);
+ $html .= $this->a($url, $text, null, $filtered_classes);
// else just text = p
else
$html .= $text;
if (in_array("no-space", $class))
$html = trim($html);
-
+
return $html;
}
// if has title and url = a with title
if (!empty($title) && !empty($url)) {
$html .= '>';
- $html .= $this->a($url, $text, $title);
+ $html .= $this->a($url, $text, $title, null);
}
// if has only title = span with title
elseif (!empty($title)) {
$generator->writeToFile($header_path, '<ul>');
foreach ($data['menu'] as $item) {
$generator->writeToFile($header_path, '<li>');
- $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item']));
+ $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item'], null, null));
$generator->writeToFile($header_path, '</li>');
}
$generator->writeToFile($header_path, '</ul>');