changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / filter / fun_upsidedown.php
1 <?php
2
3 /*
4    Ripped from the debian text filters package. This filter was originally
5    written by Joey Hess. While this wasn't mentioned clearly I would assume
6    that these two lines were released under the GNU GPL (so now is this
7    file, see the GPL.txt file).
8    (this is mostly reverse-engineered, the perl stuff made no sense to me
9    at all)
10    This implementation uses "J" to replace "r", to make it distinguishable
11    from the transited "f".
12    Good fonts to use with this plugin are sans-serif ones like Arial
13    or Verdana.
14 */
15
16
17 #-- glue
18 $ewiki_plugins["view_final"][] = "ewiki_page_upsidedown";
19 //$ewiki_plugins["handler"][] = "ewiki_page_view_preconvert_upsidedown";
20
21
22 #-- reverses all lines of text
23 function ewiki_page_view_preconvert_upsidedown(&$id, &$data, &$action) {
24    if ($action == "view") {
25       $data["content"] = implode("\n", array_reverse(explode("\n", $data["content"])));
26    }
27 }
28
29
30 #-- sends all text pieces trough the filter function below
31 function ewiki_page_upsidedown(&$o) {
32    $o = preg_replace('/>([^<>]+)</e',
33    '">".htmlentities((str_upsidedown(stripslashes("\\1"))))."<"', $o);
34 }
35
36
37 #-- this does the string transformation for plain ASCII text
38 function str_upsidedown($text) {
39
40    $text = explode("\n", $text);
41    foreach ($text as $i=>$line) {
42
43       $line = strrev($line);
44       $line = str_replace('"', "''", $line);
45       $line = strtolower($line);
46
47       $line = strtr($line,
48          "abcdefghijklmnopqrstuvwxyz 123456789 ,!?¯_ []{}<> .''  ",
49          "eq)paj6y!fk7wuodbJsfn^mxhz l2Eh59L86 `i¿_¯ ][}{>< ',,  "
50       );
51
52       $line = str_replace("k", ">|", $line);
53       $text[$i] = $line;
54
55    }
56    $text = implode("\n", $text);
57
58    return($text);
59 }
60
61
62 #-- reversal
63 function decode_upsidedown($text) {
64    $text = explode("\n", $text);
65    foreach ($text as $i=>$line) {
66       $line = str_replace(">|", "k", $line);
67       $line = strtr($line,
68          "eq)paj6y!fk7wuodbJsfn^mxhz l2E59L8 `i%_¯ ][}{>< ',,  ",
69          "abcdefghijklmnopqrstuvwxyz 1235678 ,!?¯_ []{}<> .''  "
70       );
71       $line = str_replace("''", '"', $line);
72       $line = strrev($line);
73       $text[$i] = $line;
74    }
75    $text = implode("\n", $text);
76    return($text);
77 }
78
79
80 ?>