diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filters.inc.php	Sun Jan 22 19:22:00 2023 +0100
@@ -0,0 +1,78 @@
+<?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}&amp;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;
+}
+?>