changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / page / README.php
1 <?php
2
3 /*
4   This is a plugin for the sf.net site, which splits the README
5   into multiple parts, that then will be printed read-only.
6
7   It was not developed to understand the format used by other text
8   files, so please do not annoy me, if it refuses to work for you.
9   Examples are examples. No support.  -- milky
10 */
11
12
13 $ewiki_plugins["page"]["README"] = "ewiki_page_README";
14 $ewiki_plugins["page"]["README.config"] = "ewiki_page_README";
15 $ewiki_plugins["page"]["README.plugins"] = "ewiki_page_README";
16 $ewiki_plugins["page"]["README.fragments"] = "ewiki_page_README";
17 $ewiki_plugins["page"]["ProtectedMode"] = "ewiki_page_README";
18 $ewiki_plugins["page"]["INTERNALS"] = "ewiki_page_README";
19 #$ewiki_plugins["page"]["README.de"] = "ewiki_page_README";
20
21
22 function ewiki_page_README($id, $data, $action) {
23
24    $UNDERLINE = "¯¯¯";
25    $SECTIONSEP = "--------------------------------------------------------------";
26
27    #-- open "README" text file
28    if (($r = fopen("$id", "r")) or ($r = fopen("doc/$id", "r"))) {
29
30       #-- received request for a specific entry
31       if (($para = $_REQUEST["paragraph"]) || ($goto=$_REQUEST["goto"])) {
32
33          $str_next = $str_prev = "???";
34
35          #-- exact "title" pattern given
36          $n = 0;
37          if ($para) {
38             while (!feof($r) && (trim($line) != $para)  )
39             {
40                $line = fgets($r, 4096);
41                if (strstr($line, $UNDERLINE)) { 
42                   $n++;
43                   $str_prev = $last;
44                }
45                $last = $line;
46             }
47             $n++;
48          }
49          #-- search for a paragraph number
50          elseif ($goto) {
51             while (!feof($r) && ($n < $goto) )
52             {
53                $para = $line;
54                $line = fgets($r, 4096);
55                if (strstr($line, $UNDERLINE)) { 
56                   $n++;
57                   $str_prev = $last;
58                }
59                $last = $line;
60             }
61          }
62
63          if ( ($goto&&($n==$goto)) || strstr(fgets($r, 4096), $UNDERLINE)) {
64             $hl = str_replace("[", "![", "\n!! $para\n\n<pre>");
65             $line = "";
66             $lines = array();
67             $strip_n = -1;
68             while (!feof($r) && (!strstr($line, $UNDERLINE))) {
69                $last = $line;
70                $line = fgets($r, 4096);
71                if ($strip_n == -1) {
72                   preg_match("/^([ ]+)/", $line, $uu);
73                   $strip_n = strlen($uu[1]);
74                }
75                if ($strip_n) {
76                   $line = preg_replace("/^[ ]{{$strip_n}}/", "", $line);
77                }
78                $lines[] = $line;
79             }
80             $str_next = $last;
81
82             array_pop($lines);
83             array_pop($lines);
84             $src = rtrim(implode("", $lines)); $lines = "";
85
86             #-- transformation
87 #            $src =  str_replace("[", "![", $src);
88             if (preg_match_all('/^\s+(EWIKI_[^\s]+)/m', $src, $uu)
89                 && (count($uu[1])>10)   ||
90                 preg_match_all('/^[ ]+([^\n]+)\n\s\s\s------+/m', $src, $uu)
91                 && (count($uu[1])>7)
92               )
93             {
94
95                $src = preg_replace('/^[ ]+(EWIKI_[^\s]+)/m',
96                                    ' $1#[$1":"]', $src);
97                $src = preg_replace('/^[ ]+([^\n]+)\n\s\s\s(------+)/m',
98                                    "\n   $1#[$1\"\"]\n   $2", $src);
99                foreach ($uu[1] as $anchor) {
100                   $pre .= "- [#$anchor \"$anchor\"]\n";
101                }
102                $src = $pre."\n".$src;
103             }
104
105             $end = "\n</pre>\n";
106             $o .= ewiki_format($hl.$src.$end);
107
108          }
109
110       }
111
112       #-- otherwise print all paragraph headlines in ordered lists
113       else {
114
115          $o .= "\n<h2>$id overview</h2>\n";
116
117          $ol_level = 0;
118          $first = 0;
119          $last = "";
120
121          $o .= "<ol>\n";
122
123          while (!feof($r)) {
124
125             $line = fgets($r, 4096);
126
127             if (strstr($line, $SECTIONSEP)) {
128                while($ol_level) {
129                   $o .= "</ol>\n";
130                   $ol_level--;
131                }
132                $first=1;
133             }
134
135             if (strstr($line, $UNDERLINE) && ($lastline!=="$id")) {
136
137                $new_ol_level = 1 - $first + (strpos($line, $UNDERLINE)>2 ?1:0);
138                while($ol_level > $new_ol_level) {
139                   $o .= "</ol>\n";
140                   $ol_level--;
141                }
142                while($ol_level < $new_ol_level) {
143                   $o .= "<ol>\n";
144                   $ol_level++;
145                }
146                $first = 0;
147
148                $o .= '<li><a href="' . ewiki_script("", "$id",
149                      array("paragraph"=>$lastline)) . '">' . $lastline .
150                      '</a><br /></li>' . "\n";
151
152                $section=1;
153             }
154
155             $lastline = trim($line);
156          }
157
158          while($ol_level--) {
159             $o .= "</ol>\n";
160          }
161
162          $o .= "</ol>\n";
163
164       }
165
166    }
167
168    if ($n) {
169       $o .= '<a href="' . ewiki_script("", "$id", "goto=".($n-1)).'">'.
170             'prev &lt;&lt; "'.trim($str_prev).'"</a><br />';
171       $o .= '<a href="' . ewiki_script("", "$id", "goto=".($n+1)).'">'.
172             'next &gt;&gt; "'.trim($str_next).'"</a><br />';
173    }
174
175    $br = ewiki_script("", "BugReports");
176    $us = ewiki_script("", "UserSuggestions");
177    $dc = ewiki_script("", "{$id}.Discussion");
178    $o .= "
179 <br />
180 <hr>
181 You cannot modify the {$id} file, but anyhow any ideas or suggestion should
182 as usually get filed on <a href=\"$br\">BugReports</a>,
183 <a href=\"$us\">UserSuggestions</a> or even better the
184 <a href=\"$dc\">{$id}.Discussion</a>.
185 <br />
186 "; 
187
188    return($o);
189 }
190
191 ?>