annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
1 <?php
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
2 function activeNav($input, $name, $lang)
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
3 {
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
4 $pattern = "/<li id=\"${name}\"\s?([^>]*)>/is";
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
5 $replacement = "<li id=\"${name}\" class=\"active\" $1>";
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
6 $output= preg_replace($pattern, $replacement, $input);
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
7
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
8 $pattern = '/<li id="([^"]+)"\s?([^>]*)>(.*?)<\/li>/is';
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
9 $replacement = "<li id=\"\$1\" \$2><a href=\"?name=$1&amp;lang=${lang}\">\$3</a></li>";
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
10 $output=preg_replace($pattern, $replacement, $output);
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
11
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
12 return $output;
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
13 }
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
14
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
15 function addLangBar($input, $lang) {
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
16 $languages = array("no","en");
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
17 $langbar='<ul id="language-select">';
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
18
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
19 foreach($languages as $l) {
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
20 $active=($l == $lang)?1:0;
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
21 $langbar.= "
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
22 <li class=\"${l}\">
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
23 <img src=\"http://dev.bfginvest.no/php/flag.php?lang=${l}&amp;active=${active}\" width=\"20\" height=\"16\" alt=\"Norsk versjon - inaktiv\" title=\"Norsk\"/>
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
24 </li>
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
25 ";
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
26
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
27 }
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
28 $langbar.='</ul>';
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
29 $pattern = '/<ul id="language-select"\/>/';
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
30 $replacement = $langbar;
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
31 $output=preg_replace($pattern, $replacement, $input);
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
32
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
33 return $output;
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
34 }
74196528fc64 Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff changeset
35 ?>