comparison filters.inc.php @ 134:b6b4a58c7625

Using .inc.php rather than just .inc for include files.
author Tom Fredrik Blenning <bfg@bfgconsult.no>
date Sun, 22 Jan 2023 19:22:00 +0100
parents filters.inc@ef487503dded
children
comparison
equal deleted inserted replaced
133:00255ca89459 134:b6b4a58c7625
1 <?php
2 /**
3 * @file
4 * Filters which may be used from xml
5 */
6
7 /**
8 * A configuration function for generating an active status in a list
9 * item corresponding to the currently active 'name'
10 *
11 * @param $input the string to be processed
12 * @param $options Options for this file
13 */
14 function activeNav($input, $options)
15 {
16 $name = $options->getName();
17 if (!$name)
18 $name = $options->getInputDefault('name');
19 $lang = $options->getLang();
20 $pattern = "/<li id=\"${name}\"\s?([^>]*)>/is";
21 $replacement = "<li id=\"${name}\" class=\"active\" $1>";
22 $output = preg_replace($pattern, $replacement, $input);
23
24 $pattern = '/<li id="([^"]+)"\s?([^>]*)>(.*?)<\/li>/is';
25 $replacement = "<li id=\"\$1\" \$2><a href=\"%URL-$1%\">\$3</a></li>";
26
27 $output = preg_replace_callback($pattern,
28 function($matches) use ($options){
29 $opt = $options->getUrlParams();
30 $baseUrl = $options->getBaseUrl();
31 $g=genUrl($opt, array("name" => $matches[1]), array("lang", "name") );
32 return "<li id=\"$matches[1]\" $matches[2]><a href=\"$baseUrl" . $g . "\">$matches[3]</a></li>";
33 },
34 $output);
35
36 return $output;
37 }
38
39 /**
40 * A configuration function for generating a language bar.
41 *
42 * @param $input the string to be processed
43 * @param $options Options for this file
44 * @param $languages array of alternative languages
45 */
46 function addLangBar($input, $options, $languages)
47 {
48 $name = $options->getName();
49 $lang = $options->getLang();
50 $langbar='<ul id="language-select">';
51
52 foreach($languages as $l) {
53 $active = ($l == $lang) ? 0 : 1;
54 $langbar.= "
55 <li class=\"${l}\">";
56 if ($active)
57 $langbar .= '<a href="'.genUrl($options->getUrlParams(), array( 'lang' => $l), array('lang', 'name') ) . '">';
58
59 $flagUrl = $options->getFlagUrl();
60
61 $langbar .= "
62 <img src=\"${flagUrl}?lang=${l}&amp;active=${active}\" width=\"20\" height=\"16\" alt=\"Norsk versjon - inaktiv\" title=\"Norsk\"/>";
63 if ($active)
64 $langbar .= "</a>";
65
66 $langbar .= "
67 </li>
68 ";
69
70 }
71 $langbar.='</ul>';
72 $pattern = '/<ul id="language-select"\/>/';
73 $replacement = $langbar;
74 $output = preg_replace($pattern, $replacement, $input);
75
76 return $output;
77 }
78 ?>