]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - wiki_stdlib.php3
This commit was generated by cvs2svn to compensate for changes in r2,
[SourceForge/phpwiki.git] / wiki_stdlib.php3
1 <?
2    /*
3       Standard functions for Wiki functionality
4          WikiToolBar() 
5          WikiHeader($pagename) 
6          WikiFooter() 
7          GetCurrentDate()
8          LinkExistingWikiWord($wikiword) 
9          LinkUnknownWikiWord($wikiword) 
10          RenderQuickSearch() 
11          RenderFullSearch() 
12          CookSpaces($pagearray) 
13          class Stack
14          SetHTMLOutputMode($newmode, $depth)
15    */
16
17    // render the Wiki toolbar at bottom of page
18    function WikiToolBar() {
19       global $ScriptUrl, $pagename, $pagehash;
20       echo "<hr>\n";
21       echo "<a href=\"$ScriptUrl?edit=$pagename\">EditText</a>\n";
22       echo " of this page\n";
23       if (is_array($pagehash)) {
24          echo " (last edited ", $pagehash["date"], ")\n";
25       }
26       echo "<br>\n";
27
28       echo "<a href='$ScriptUrl?FindPage&value=$pagename";
29       echo "'>FindPage</a> by browsing or searching\n";
30    }
31
32    // top of page
33    function WikiHeader($pagename) {
34       global $LogoImage, $ScriptUrl;
35       echo "<html>\n";
36       echo "<head>\n";
37       echo "<title>$pagename</title>\n";
38       echo "</head>\n";
39       echo "<body>\n";
40    }
41
42    function WikiFooter() {
43       echo "</body>\n</html>\n";
44    }
45
46    function GetCurrentDate() {
47       // format is like December 13, 1999
48       return date("F j, Y");
49    }
50    
51    function LinkExistingWikiWord($wikiword) {
52       global $ScriptUrl;
53       return "<a href=\"$ScriptUrl?$wikiword\">$wikiword</a>";
54    }
55
56    function LinkUnknownWikiWord($wikiword) {
57       global $ScriptUrl;
58       return "$wikiword<a href=\"$ScriptUrl?edit=$wikiword\">?</a>";
59
60    }
61
62    
63    function RenderQuickSearch() {
64       global $value, $ScriptUrl;
65       static $formtext = "<form action='$ScriptUrl'>\n<input type='text' size='40' name='search' value='$value'>\n</form>\n";
66       return $formtext;
67    }
68
69    function RenderFullSearch() {
70       global $value, $ScriptUrl;
71       static $formtext = "<form action='$ScriptUrl'>\n<input type='text' size='40' name='full' value='$value'>\n</form>\n";
72       return $formtext;
73    }
74
75    // converts spaces to tabs
76    function CookSpaces($pagearray) {
77       return preg_replace("/ {3,8}/", "\t", $pagearray);
78    }
79
80
81    class Stack {
82       var $items;
83       var $size = 0;
84
85       function push($item) {
86          $this->items[$this->size] = $item;
87          $this->size++;
88          return true;
89       }  
90    
91       function pop() {
92          if ($this->size == 0) {
93             return false; // stack is empty
94          }  
95          $this->size--;
96          return $this->items[$this->size];
97       }  
98    
99       function cnt() {
100          return $this->size;
101       }  
102
103       function top() {
104          return $this->items[$this->size - 1];
105       }  
106
107    }  
108    // end class definition
109
110
111    /* 
112       Wiki HTML output can, at any given time, be in only one mode.
113       It will be something like Unordered List, Preformatted Text,
114       plain text etc. When we change modes we have to issue close tags
115       for one mode and start tags for another.
116    */
117
118    // couldn't create a static version :-/
119    // I couldn't move this to config.php3 because it 
120    // wasn't declared yet.
121    $stack = new Stack;
122
123    function SetHTMLOutputMode($tag, $tagdepth, $tabcount) {
124       global $stack;
125    
126       if ($tagdepth == SINGLE_DEPTH) {
127    
128          if ($tabcount < $stack->cnt()) {
129    
130             // there are fewer tabs than stack, reduce stack
131             // to one less than tab count; then push new tag
132             while ($stack->cnt() > ($tabcount - 1)) {
133                $closetag = $stack->pop();
134                if ($closetag == false) {
135                   //echo "bounds error in tag stack";
136                   //exit();
137                   break;
138                }
139                echo "</$closetag>\n";
140             }
141    
142             echo "<$tag>\n";
143             $stack->push($tag);
144    
145          } elseif ($tabcount > $stack->cnt()) {
146             // we add the diff to the stack
147             // stack might be zero
148             while ($stack->cnt() < $tabcount) {
149                echo "<$tag>\n";
150                $stack->push($tag);
151                if ($stack->cnt() > 10) {
152                   // arbitrarily limit tag nesting
153                   echo "Stack bounds exceeded in SetHTMLOutputMode\n";
154                   exit();
155                }
156             }
157    
158          } else {
159             if ($tag == $stack->top()) {
160                return;
161             } else {
162                $closetag = $stack->pop();
163                echo "</$closetag>\n";
164                echo "<$tag>\n";
165                $stack->push($tag);
166             }
167          }
168    
169       } elseif ($tagdepth == ZERO_DEPTH) {
170          // empty the stack for $depth == 0;
171          // what if the stack is empty?
172          if ($tag == $stack->top()) {
173             return;
174          }
175          while ($stack->cnt() > 0) {
176             $closetag = $stack->pop();
177             echo "</$closetag>\n";
178          }
179    
180          if ($tag) {
181             echo "<$tag>\n";
182             $stack->push($tag);
183          }
184    
185       } else {
186          // error
187          echo "Passed bad tag depth value in SetHTMLOutputMode\n";
188          exit();
189       }
190    }
191    // end SetHTMLOutputMode
192
193
194 ?>