Mercurial > SimpleWebPresenter
view filters.inc.php @ 136:60bc8f62384d default tip
Use internal URL if available to generate Sitemap.
| author | Tom Fredrik Blenning <bfg@bfgconsult.no> |
|---|---|
| date | Mon, 23 Jan 2023 00:17:36 +0100 |
| parents | b6b4a58c7625 |
| children |
line wrap: on
line source
<?php /** * @file * Filters which may be used from xml */ /** * A configuration function for generating an active status in a list * item corresponding to the currently active 'name' * * @param $input the string to be processed * @param $options Options for this file */ function activeNav($input, $options) { $name = $options->getName(); if (!$name) $name = $options->getInputDefault('name'); $lang = $options->getLang(); $pattern = "/<li id=\"${name}\"\s?([^>]*)>/is"; $replacement = "<li id=\"${name}\" class=\"active\" $1>"; $output = preg_replace($pattern, $replacement, $input); $pattern = '/<li id="([^"]+)"\s?([^>]*)>(.*?)<\/li>/is'; $replacement = "<li id=\"\$1\" \$2><a href=\"%URL-$1%\">\$3</a></li>"; $output = preg_replace_callback($pattern, function($matches) use ($options){ $opt = $options->getUrlParams(); $baseUrl = $options->getBaseUrl(); $g=genUrl($opt, array("name" => $matches[1]), array("lang", "name") ); return "<li id=\"$matches[1]\" $matches[2]><a href=\"$baseUrl" . $g . "\">$matches[3]</a></li>"; }, $output); return $output; } /** * A configuration function for generating a language bar. * * @param $input the string to be processed * @param $options Options for this file * @param $languages array of alternative languages */ function addLangBar($input, $options, $languages) { $name = $options->getName(); $lang = $options->getLang(); $langbar='<ul id="language-select">'; foreach($languages as $l) { $active = ($l == $lang) ? 0 : 1; $langbar.= " <li class=\"${l}\">"; if ($active) $langbar .= '<a href="'.genUrl($options->getUrlParams(), array( 'lang' => $l), array('lang', 'name') ) . '">'; $flagUrl = $options->getFlagUrl(); $langbar .= " <img src=\"${flagUrl}?lang=${l}&active=${active}\" width=\"20\" height=\"16\" alt=\"Norsk versjon - inaktiv\" title=\"Norsk\"/>"; if ($active) $langbar .= "</a>"; $langbar .= " </li> "; } $langbar.='</ul>'; $pattern = '/<ul id="language-select"\/>/'; $replacement = $langbar; $output = preg_replace($pattern, $replacement, $input); return $output; } ?>
