diff filters.inc @ 4:74196528fc64

Refac to use xml as input, and remove filters and helper-functions from main script.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 19 May 2011 18:04:33 +0200
parents
children 18aafb1a8986
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/filters.inc	Thu May 19 18:04:33 2011 +0200
@@ -0,0 +1,35 @@
+<?php
+function activeNav($input, $name, $lang)
+{
+	$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=\"?name=$1&amp;lang=${lang}\">\$3</a></li>";
+	$output=preg_replace($pattern, $replacement, $output);
+
+	return $output;
+}
+
+function addLangBar($input, $lang) {
+	 $languages = array("no","en");
+	 $langbar='<ul id="language-select">';
+
+	 foreach($languages as $l) {
+	   $active=($l == $lang)?1:0;
+	     $langbar.= "
+	    <li class=\"${l}\">
+	      <img src=\"http://dev.bfginvest.no/php/flag.php?lang=${l}&amp;active=${active}\" width=\"20\" height=\"16\" alt=\"Norsk versjon - inaktiv\" title=\"Norsk\"/>
+	    </li>
+";
+
+	}
+	$langbar.='</ul>';
+	$pattern = '/<ul id="language-select"\/>/';
+	$replacement = $langbar;
+	$output=preg_replace($pattern, $replacement, $input);
+
+	return $output;
+}
+?>
\ No newline at end of file