r22617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22616‎ | r22617 | r22618 >
Date:03:41, 1 June 2007
Author:tstarling
Status:old
Tags:
Comment:
Fixed a couple of image bugs. Many remain.
Modified paths:
  • /trunk/wap/hawiki/hawiki.inc (modified) (history)
  • /trunk/wap/hawiki/hawiki_parser_hawpedia.inc (modified) (history)
  • /trunk/wap/image.php (modified) (history)

Diff [purge]

Index: trunk/wap/image.php
@@ -33,33 +33,18 @@
3434 default :
3535 $img = imagecreatefromstring($src);
3636 break;
37 - }
38 - $tf = ('.gif');
39 -/*
40 - $tf = ('.wbmp');
41 - $fmt = ($_SERVER['HTTP_ACCEPT']);
42 - $fmts = (preg_split('/[ ,]+/', $fmt));
43 - foreach($fmts as $fmt)
44 - {
45 - if(strtolower($fmt == 'image/gif'))
46 - {
47 - $tf = ('.gif');
48 - break;
49 - }
5037 }
51 -*/
 38+
5239 if($img)
5340 {
54 - switch($tf)
55 - {
56 - case '.gif' :
57 - header('Content-Type: Image/gif');
58 - imagegif($img);
59 - break;
60 - default :
61 - header('Content-Type: Image/wbmp');
62 - imagewbmp($img);
63 - break;
 41+ $accept = isset( $_SERVER['HTTP_ACCEPT'] ) ? $_SERVER['HTTP_ACCEPT'] : '';
 42+ $types = array_map( 'trim', explode( ',', $accept ) );
 43+ if ( in_array( 'image/gif', $types ) ) {
 44+ header('Content-Type: image/gif');
 45+ imagegif($img);
 46+ } else {
 47+ header('Content-Type: image/vnd.wap.wbmp');
 48+ imagewbmp($img);
6449 }
6550 }
6651 ?>
Index: trunk/wap/hawiki/hawiki_parser_hawpedia.inc
@@ -245,11 +245,21 @@
246246 # $imagename .
247247 # ($width ? (DIRECTORY_SEPARATOR.$width.'px-'.$imagename) : ''));
248248 # echo '<br />'.
249 - $po['src'] = ((($imagetype == '.svg' || $imagetype == '.png')?('/image.php?'):''). // convert image locally
250 - $img_url_head . // else load from wmf server, be it the wiki or commons
251 - ($width ? ('/' . translate_wikipedia_keyword('thumb')) : '' ).
252 - $img_url_tail .
253 - ($width ? ("/{$width}px-{$imagename}") : ''));
 249+ if ( $imagetype == '.svg' ) {
 250+ $po['src'] = "image.php?$img_url_head/thumb$img_url_tail/{$width}px-{$imagename}.png";
 251+ } elseif ( $imagetype == '.png' ) {
 252+ if ( $width ) {
 253+ $po['src'] = "image.php?$img_url_head/thumb$img_url_tail/{$width}px-{$imagename}";
 254+ } else {
 255+ $po['src'] = "image.php?$img_url_head$img_url_tail";
 256+ }
 257+ } else {
 258+ if ( $width ) {
 259+ $po['src'] = "$img_url_head/thumb$img_url_tail/{$width}px-{$imagename}";
 260+ } else {
 261+ $po['src'] = "$img_url_head$img_url_tail";
 262+ }
 263+ }
254264 $po["token"] = HAWIKI_TOKEN_IMAGE;
255265 return($po);
256266 }
Index: trunk/wap/hawiki/hawiki.inc
@@ -78,662 +78,598 @@
7979
8080 function HAWIKI_error($error_msg)
8181 {
82 - // throw out error message via HAWHAW and terminate
 82+ // throw out error message via HAWHAW and terminate
8383
84 - $error_deck = new HAW_deck(HAWIKI_TITLE);
85 - $error_deck->enable_session();
 84+ $error_deck = new HAW_deck(HAWIKI_TITLE);
 85+ $error_deck->enable_session();
8686
87 - $error_text = new HAW_text($error_msg);
88 - $error_deck->add_text($error_text);
89 - $error_deck->create_page();
90 - exit();
 87+ $error_text = new HAW_text($error_msg);
 88+ $error_deck->add_text($error_text);
 89+ $error_deck->create_page();
 90+ exit();
9191 }
9292
9393
9494 class HAWIKI_page
9595 {
96 - var $deck; // HAW_deck object
97 - var $wiki_string; // input in wiki syntax
98 - var $wiki_base; // URL for WikiName links
99 - var $title; // page title
100 - var $navlink; // array with navigation links (home, menue etc.)
101 - var $phonelink; // array with HAW_phone link information
102 - var $smiley_dir; // where smiley gif's are stored
103 - var $link_jingle; // where link wav file for VoiceXML is located
104 - var $hawimconv; // where HAWHAW image converter script is located
105 - var $firstColumn; // flag to determine parser position
106 - var $listLine; // flag to indicate that line belongs to a list
107 - var $listNumbering; // array with current list numbers
108 - var $debugflags; // flags for dumping debug info
109 - var $textformat; // text format: bold, italic etc.
110 - var $textcolor; // text color
 96+ var $deck; // HAW_deck object
 97+ var $wiki_string; // input in wiki syntax
 98+ var $wiki_base; // URL for WikiName links
 99+ var $title; // page title
 100+ var $navlink; // array with navigation links (home, menue etc.)
 101+ var $phonelink; // array with HAW_phone link information
 102+ var $smiley_dir; // where smiley gif's are stored
 103+ var $link_jingle; // where link wav file for VoiceXML is located
 104+ var $hawimconv; // where HAWHAW image converter script is located
 105+ var $firstColumn; // flag to determine parser position
 106+ var $listLine; // flag to indicate that line belongs to a list
 107+ var $listNumbering; // array with current list numbers
 108+ var $debugflags; // flags for dumping debug info
 109+ var $textformat; // text format: bold, italic etc.
 110+ var $textcolor; // text color
111111
112 - function HAWIKI_page($input, $wiki_base, $title, $lang)
113 - {
114 - $this->wiki_string = $input;
115 - $this->wiki_base = $wiki_base;
116 - $this->title = $title;
117 - $this->smiley_dir = ""; // has to be set later by function call
118 - $this->link_jingle = ""; // dito
119 - $this->hawimconv = ""; // dito
120 - //$this->phonelink = ""; // dito
121 - $this->navlink = array();
122 - $this->firstColumn = true;
123 - $this->listLine = false;
124 - $this->listNumbering = array();
125 - $this->debugflags = HAWIKI_DEBUG_NONE;
126 - $this->textformat = HAW_TEXTFORMAT_NORMAL;
127 - $this->textcolor = "";
 112+ function HAWIKI_page($input, $wiki_base, $title, $lang)
 113+ {
 114+ $this->wiki_string = $input;
 115+ $this->wiki_base = $wiki_base;
 116+ $this->title = $title;
 117+ $this->smiley_dir = ""; // has to be set later by function call
 118+ $this->link_jingle = ""; // dito
 119+ $this->hawimconv = ""; // dito
 120+ //$this->phonelink = ""; // dito
 121+ $this->navlink = array();
 122+ $this->firstColumn = true;
 123+ $this->listLine = false;
 124+ $this->listNumbering = array();
 125+ $this->debugflags = HAWIKI_DEBUG_NONE;
 126+ $this->textformat = HAW_TEXTFORMAT_NORMAL;
 127+ $this->textcolor = "";
128128
129 - // check input string for presence resp. maximum length
130 - if (strlen($input) > HAWIKI_MAXINPUTCHARS)
131 - {
132 - // invalid input size
133 - HAWIKI_error("Error: Invalid wiki size"); // script end
134 - }
 129+ // check input string for presence resp. maximum length
 130+ if (strlen($input) > HAWIKI_MAXINPUTCHARS)
 131+ {
 132+ // invalid input size
 133+ HAWIKI_error("Error: Invalid wiki size"); // script end
 134+ }
135135
136 - $this->deck = new HAW_deck(HAWIKI_TITLE);
 136+ $this->deck = new HAW_deck(HAWIKI_TITLE);
137137
138 - // set display properties
139 - $this->deck->set_charset("UTF-8");
140 - $this->deck->set_width(HAWIKI_DISP_WIDTH);
141 - $this->deck->set_height(HAWIKI_DISP_HEIGHT);
142 - $this->deck->set_disp_bgcolor(HAWIKI_DISP_BGCOLOR);
 138+ // set display properties
 139+ $this->deck->set_charset("UTF-8");
 140+ $this->deck->set_width(HAWIKI_DISP_WIDTH);
 141+ $this->deck->set_height(HAWIKI_DISP_HEIGHT);
 142+ $this->deck->set_disp_bgcolor(HAWIKI_DISP_BGCOLOR);
143143
144 - if (defined('HAWIKI_SKIN'))
145 - $this->deck->use_simulator(HAWIKI_SKIN);
146 -
147 - if (isset($lang) && (strlen($lang) == 2))
148 - {
149 - $this->deck->set_language($lang);
 144+ if (defined('HAWIKI_SKIN'))
 145+ $this->deck->use_simulator(HAWIKI_SKIN);
150146
151 - if ($this->deck->ml == HAW_VXML)
152 - {
153 - global $language; // needed for tra(nslation) to work properly
154 - $language = $lang;
 147+ if (isset($lang) && (strlen($lang) == 2))
 148+ {
 149+ $this->deck->set_language($lang);
155150
156 - if ($lang == "en")
157 - $this->deck->set_voice_nomatch("I did not understand what you said, please try again.");
 151+ if ($this->deck->ml == HAW_VXML)
 152+ {
 153+ global $language; // needed for tra(nslation) to work properly
 154+ $language = $lang;
158155
159 - if ($lang == "fr")
160 - $this->deck->set_voice_nomatch("Je n'ai pas compris ce que vous avez dit. SVP essayer de nouveau.");
 156+ if ($lang == "en")
 157+ $this->deck->set_voice_nomatch("I did not understand what you said, please try again.");
161158
162 - if ($lang == "es")
163 - $this->deck->set_voice_nomatch("No comprendo lo que tu dices. Por favor, intenta otra vez.");
 159+ if ($lang == "fr")
 160+ $this->deck->set_voice_nomatch("Je n'ai pas compris ce que vous avez dit. SVP essayer de nouveau.");
164161
165 - if ($lang == "de")
166 - $this->deck->set_voice_nomatch("Ich habe Sie leider nicht verstanden. Bitte wiederholen Sie.");
167 - }
168 - }
169 - }
 162+ if ($lang == "es")
 163+ $this->deck->set_voice_nomatch("No comprendo lo que tu dices. Por favor, intenta otra vez.");
170164
 165+ if ($lang == "de")
 166+ $this->deck->set_voice_nomatch("Ich habe Sie leider nicht verstanden. Bitte wiederholen Sie.");
 167+ }
 168+ }
 169+ }
171170
172 - function display()
173 - {
174 - // convert wiki text into HAWHAW object structure and create appropriate markup
175171
176 - if (isset($_GET["hawikidebugremote"]))
177 - $url_debugflags = $_GET["hawikidebugremote"];
178 - else
179 - $url_debugflags = HAWIKI_DEBUG_NONE;
180 -
181 - if ($url_debugflags && ($this->debugflags == HAWIKI_DEBUG_NONE))
182 - $this->debugflags = $url_debugflags;
 172+ function display()
 173+ {
 174+ // convert wiki text into HAWHAW object structure and create appropriate markup
183175
 176+ if (isset($_GET["hawikidebugremote"]))
 177+ $url_debugflags = $_GET["hawikidebugremote"];
 178+ else
 179+ $url_debugflags = HAWIKI_DEBUG_NONE;
184180
 181+ if ($url_debugflags && ($this->debugflags == HAWIKI_DEBUG_NONE))
 182+ $this->debugflags = $url_debugflags;
185183
186 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
187 - printf("<b>Input:</b><br><pre>%s</pre><br>\n", $this->wiki_string);
188184
189 - if ($this->title)
190 - {
191 - $title = new HAW_text($this->title, HAW_TEXTFORMAT_BIG | HAW_TEXTFORMAT_BOXED);
192 - $this->deck->add_text($title);
193 - }
194185
195 - $link_counter = 0;
196 - foreach ($this->navlink as $value)
197 - {
198 - // create navigation link(s) at top of wiki page
 186+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 187+ printf("<b>Input:</b><br><pre>%s</pre><br>\n", $this->wiki_string);
199188
200 - if ($value["pos"] & HAWIKI_NAVLINK_TOP)
201 - {
202 - $link = new HAW_link($value["label"], $value["url"]);
203 - $this->deck->add_link($link);
204 - $link_counter++;
205 - }
206 - }
 189+ if ($this->title)
 190+ {
 191+ $title = new HAW_text($this->title, HAW_TEXTFORMAT_BIG | HAW_TEXTFORMAT_BOXED);
 192+ $this->deck->add_text($title);
 193+ }
207194
208 - if (isset($this->phonelink) &&
209 - ($this->phonelink['pos'] & HAWIKI_NAVLINK_TOP))
210 - {
211 - // add callable phone number at top of wiki page
212 - $phone = new HAW_phone($this->phonelink['phone_number'],
213 - $this->phonelink['label']);
214 - $this->deck->add_phone($phone);
215 - }
216 -
217 - if (($link_counter > 0) || $this->title)
218 - {
219 - // create horizontal rule between page header and wiki content
220 - $rule = new HAW_rule();
221 - $this->deck->add_rule($rule);
222 - }
 195+ $link_counter = 0;
 196+ foreach ($this->navlink as $value)
 197+ {
 198+ // create navigation link(s) at top of wiki page
223199
224 - $input = strip_tags($this->wiki_string); // remove all HTML
225 - while ($po = HAWIKI_parser($input, $this->firstColumn)) // evaluate parser output
226 - {
227 - $this->firstColumn = false; // default
 200+ if ($value["pos"] & HAWIKI_NAVLINK_TOP)
 201+ {
 202+ $link = new HAW_link($value["label"], $value["url"]);
 203+ $this->deck->add_link($link);
 204+ $link_counter++;
 205+ }
 206+ }
228207
229 - switch ($po["token"])
230 - {
231 - case HAWIKI_TOKEN_DUMMY:
232 - {
233 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
234 - printf("<b>Dummy token</b><br>\n");
 208+ if (isset($this->phonelink) &&
 209+ ($this->phonelink['pos'] & HAWIKI_NAVLINK_TOP))
 210+ {
 211+ // add callable phone number at top of wiki page
 212+ $phone = new HAW_phone($this->phonelink['phone_number'],
 213+ $this->phonelink['label']);
 214+ $this->deck->add_phone($phone);
 215+ }
235216
236 - // unsupported syntax element ==> do nothing
 217+ if (($link_counter > 0) || $this->title)
 218+ {
 219+ // create horizontal rule between page header and wiki content
 220+ $rule = new HAW_rule();
 221+ $this->deck->add_rule($rule);
 222+ }
237223
238 - if (isset($po["firstColumn"]) && ($po["firstColumn"] == true))
239 - $this->firstColumn = true;
 224+ $input = strip_tags($this->wiki_string); // remove all HTML
 225+ while ($po = HAWIKI_parser($input, $this->firstColumn)) // evaluate parser output
 226+ {
 227+ $this->firstColumn = false; // default
240228
241 - break;
242 - }
 229+ switch ($po["token"])
 230+ {
 231+ case HAWIKI_TOKEN_DUMMY:
 232+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 233+ printf("<b>Dummy token</b><br>\n");
243234
244 - case HAWIKI_TOKEN_NEWLINE:
245 - {
246 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
247 - printf("<b>Newline:</b> %d<br>\n", $po["count"]);
 235+ // unsupported syntax element ==> do nothing
248236
249 - $text = new HAW_text("");
250 - $text->set_br($po["count"]); // set number of line breaks
251 - $this->deck->add_text($text);
252 - $this->firstColumn = true; // now we're again in column 0
 237+ if (isset($po["firstColumn"]) && ($po["firstColumn"] == true))
 238+ $this->firstColumn = true;
253239
254 - // numbered list are terminated by all lines, that are not list elements
255 - if ($this->listLine)
256 - $this->listLine = false; // continuation of numbered list is possible
257 - else
258 - $this->listNumbering = array(); // init numbering array
 240+ break;
259241
260 - // reset text formatting
261 - $this->textformat = HAW_TEXTFORMAT_NORMAL;
 242+ case HAWIKI_TOKEN_NEWLINE:
 243+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 244+ printf("<b>Newline:</b> %d<br>\n", $po["count"]);
262245
263 - break;
264 - }
 246+ $text = new HAW_text("");
 247+ $text->set_br($po["count"]); // set number of line breaks
 248+ $this->deck->add_text($text);
 249+ $this->firstColumn = true; // now we're again in column 0
265250
266 - case HAWIKI_TOKEN_TEXT:
267 - {
268 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
269 - printf("<b>Text:</b> %s<br>\n", $po["text"]);
 251+ // numbered list are terminated by all lines, that are not list elements
 252+ if ($this->listLine)
 253+ $this->listLine = false; // continuation of numbered list is possible
 254+ else
 255+ $this->listNumbering = array(); // init numbering array
270256
271 - if (strlen($po["text"]) > 0)
272 - {
273 - $text = new HAW_text($po["text"], $this->textformat);
274 -
275 - if ($this->textcolor)
276 - $text->set_color($this->textcolor);
277 -
278 - $text->set_br(0);
279 - $this->deck->add_text($text);
280 - }
 257+ // reset text formatting
 258+ $this->textformat = HAW_TEXTFORMAT_NORMAL;
281259
282 - break;
283 - }
 260+ break;
284261
285 - case HAWIKI_TOKEN_BOLD:
286 - {
287 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
288 - printf("<b>Toggle bold</b><br>\n");
 262+ case HAWIKI_TOKEN_TEXT:
 263+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 264+ printf("<b>Text:</b> %s<br>\n", $po["text"]);
289265
290 - $this->textformat ^= HAW_TEXTFORMAT_BOLD;
 266+ if (strlen($po["text"]) > 0)
 267+ {
 268+ $text = new HAW_text($po["text"], $this->textformat);
291269
292 - break;
293 - }
 270+ if ($this->textcolor)
 271+ $text->set_color($this->textcolor);
294272
295 - case HAWIKI_TOKEN_ITALIC:
296 - {
297 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
298 - printf("<b>Toggle italic</b><br>\n");
 273+ $text->set_br(0);
 274+ $this->deck->add_text($text);
 275+ }
299276
300 - $this->textformat ^= HAW_TEXTFORMAT_ITALIC;
 277+ break;
301278
302 - break;
303 - }
 279+ case HAWIKI_TOKEN_BOLD:
 280+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 281+ printf("<b>Toggle bold</b><br>\n");
304282
305 - case HAWIKI_TOKEN_UNDERLINE:
306 - {
307 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
308 - printf("<b>Toggle underline</b><br>\n");
 283+ $this->textformat ^= HAW_TEXTFORMAT_BOLD;
309284
310 - $this->textformat ^= HAW_TEXTFORMAT_UNDERLINE;
 285+ break;
311286
312 - break;
313 - }
 287+ case HAWIKI_TOKEN_ITALIC:
 288+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 289+ printf("<b>Toggle italic</b><br>\n");
314290
315 - case HAWIKI_TOKEN_COLORED:
316 - {
317 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
318 - printf("<b>Colored: %s</b><br>\n", $po["color"]);
 291+ $this->textformat ^= HAW_TEXTFORMAT_ITALIC;
319292
320 - $this->textcolor = $po["color"];
 293+ break;
321294
322 - break;
323 - }
 295+ case HAWIKI_TOKEN_UNDERLINE:
 296+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 297+ printf("<b>Toggle underline</b><br>\n");
324298
325 - case HAWIKI_TOKEN_MONOSPACED:
326 - {
327 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
328 - printf("<b>Monospaced</b><br>\n");
 299+ $this->textformat ^= HAW_TEXTFORMAT_UNDERLINE;
329300
330 - // monospace is not supported by HAWHAW -> draw small instead
331 - $this->textformat |= HAW_TEXTFORMAT_SMALL;
 301+ break;
332302
333 - break;
334 - }
 303+ case HAWIKI_TOKEN_COLORED:
 304+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 305+ printf("<b>Colored: %s</b><br>\n", $po["color"]);
335306
336 - case HAWIKI_TOKEN_PARAGRAPH:
337 - {
338 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
339 - printf("<b>Paragraph:</b> %s<br>\n", $po["text"]);
 307+ $this->textcolor = $po["color"];
340308
341 - $paragraph = new HAW_text($po["text"], HAW_TEXTFORMAT_BIG | HAW_TEXTFORMAT_BOXED);
342 - $paragraph->set_br(0);
343 - $this->deck->add_text($paragraph);
 309+ break;
344310
345 - break;
346 - }
 311+ case HAWIKI_TOKEN_MONOSPACED:
 312+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 313+ printf("<b>Monospaced</b><br>\n");
347314
348 - case HAWIKI_TOKEN_HEADING:
349 - {
350 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
351 - printf("<b>Heading (level %d)</b><br>\n", $po["level"]);
 315+ // monospace is not supported by HAWHAW -> draw small instead
 316+ $this->textformat |= HAW_TEXTFORMAT_SMALL;
352317
353 - $this->textformat |= HAW_TEXTFORMAT_BOLD;
 318+ break;
354319
355 - if ($po["level"] <= 2)
356 - $this->textformat |= HAW_TEXTFORMAT_BIG;
 320+ case HAWIKI_TOKEN_PARAGRAPH:
 321+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 322+ printf("<b>Paragraph:</b> %s<br>\n", $po["text"]);
357323
358 - if ($po["level"] == 1)
359 - $this->textformat |= HAW_TEXTFORMAT_UNDERLINE;
 324+ $paragraph = new HAW_text($po["text"], HAW_TEXTFORMAT_BIG | HAW_TEXTFORMAT_BOXED);
 325+ $paragraph->set_br(0);
 326+ $this->deck->add_text($paragraph);
360327
361 - break;
362 - }
 328+ break;
363329
364 - case HAWIKI_TOKEN_BULLIST:
365 - {
366 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
367 - printf("<b>Bullet list (level %d)</b><br>\n", $po["level"]);
 330+ case HAWIKI_TOKEN_HEADING:
 331+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 332+ printf("<b>Heading (level %d)</b><br>\n", $po["level"]);
368333
369 - $bullet = str_repeat("-", $po["level"]);
 334+ $this->textformat |= HAW_TEXTFORMAT_BOLD;
370335
371 - $text = new HAW_text($bullet . " ");
372 - $text->set_br(0);
373 - $this->deck->add_text($text);
 336+ if ($po["level"] <= 2)
 337+ $this->textformat |= HAW_TEXTFORMAT_BIG;
374338
375 - break;
376 - }
 339+ if ($po["level"] == 1)
 340+ $this->textformat |= HAW_TEXTFORMAT_UNDERLINE;
377341
378 - case HAWIKI_TOKEN_NUMLIST:
379 - {
380 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
381 - printf("<b>Numbered list (level %d)</b><br>\n", $po["level"]);
 342+ break;
382343
383 - if (isset($this->listNumbering[$po["level"]]))
384 - $this->listNumbering[$po["level"]]++; // increment this level
385 - else
386 - $this->listNumbering[$po["level"]] = 1; // init this level
 344+ case HAWIKI_TOKEN_BULLIST:
 345+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 346+ printf("<b>Bullet list (level %d)</b><br>\n", $po["level"]);
387347
388 - $number = "";
 348+ $bullet = str_repeat("-", $po["level"]);
389349
390 - for ($n=1; $n <= $po["level"]; $n++)
391 - {
392 - // assemble current numbering
393 - if (isset($this->listNumbering[$n]))
394 - $number .= sprintf("%d.", $this->listNumbering[$n]);
395 - else
396 - $number .= "0.";
397 - }
 350+ $text = new HAW_text($bullet . " ");
 351+ $text->set_br(0);
 352+ $this->deck->add_text($text);
398353
399 - $number = substr($number, 0, -1); // remove trailing dot
 354+ break;
400355
401 - $text = new HAW_text($number . " ", HAW_TEXTFORMAT_BOLD);
402 - $text->set_br(0);
403 - $this->deck->add_text($text);
 356+ case HAWIKI_TOKEN_NUMLIST:
 357+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 358+ printf("<b>Numbered list (level %d)</b><br>\n", $po["level"]);
404359
405 - $this->listLine = true;
 360+ if (isset($this->listNumbering[$po["level"]]))
 361+ $this->listNumbering[$po["level"]]++; // increment this level
 362+ else
 363+ $this->listNumbering[$po["level"]] = 1; // init this level
406364
407 - break;
408 - }
 365+ $number = "";
409366
410 - case HAWIKI_TOKEN_RULE:
411 - {
412 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
413 - printf("<b>Horizontal rule</b><br>\n");
 367+ for ($n=1; $n <= $po["level"]; $n++)
 368+ {
 369+ // assemble current numbering
 370+ if (isset($this->listNumbering[$n]))
 371+ $number .= sprintf("%d.", $this->listNumbering[$n]);
 372+ else
 373+ $number .= "0.";
 374+ }
414375
415 - $rule = new HAW_rule();
416 - $this->deck->add_rule($rule);
417 - $this->firstColumn = true; // now we're again in column 0
 376+ $number = substr($number, 0, -1); // remove trailing dot
418377
419 - break;
420 - }
 378+ $text = new HAW_text($number . " ", HAW_TEXTFORMAT_BOLD);
 379+ $text->set_br(0);
 380+ $this->deck->add_text($text);
421381
422 - case HAWIKI_TOKEN_WIKINAME:
423 - {
424 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
425 - printf("<b>WikiName:</b> extwiki:%s page:%s label:%s dtmf:%s<br>\n",
426 - $po["extwiki"], $po["page"], $po["label"], $po["dtmf"]);
427 -
428 - if ($po["extwiki"])
429 - {
430 - $link = new HAW_link($po["label"], ereg_replace('\$page', urlencode($po["page"]), $po["extwiki"]) . "&mode=mobile");
431 - }
432 - else
433 - $link = new HAW_link($po["label"], $this->wiki_base . urlencode($po["page"]));
 382+ $this->listLine = true;
434383
435 - if (isset($po["dtmf"]))
436 - // assign DTMF key
437 - $link->set_voice_dtmf($po["dtmf"]);
 384+ break;
438385
439 - $link->set_br(0);
440 - $this->deck->add_link($link);
 386+ case HAWIKI_TOKEN_RULE:
 387+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 388+ printf("<b>Horizontal rule</b><br>\n");
441389
442 - break;
443 - }
 390+ $rule = new HAW_rule();
 391+ $this->deck->add_rule($rule);
 392+ $this->firstColumn = true; // now we're again in column 0
444393
445 - case HAWIKI_TOKEN_LINK:
446 - {
447 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
448 - printf("<b>Link:</b> url:%s label:%s<br>\n", $po["url"], $po["label"]);
 394+ break;
449395
450 - // determine file extension of link
451 - if (preg_match("/\.(\w*)$/", $po["url"], $matches))
452 - $extension = strtolower($matches[1]);
 396+ case HAWIKI_TOKEN_WIKINAME:
 397+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 398+ printf("<b>WikiName:</b> extwiki:%s page:%s label:%s dtmf:%s<br>\n",
 399+ $po["extwiki"], $po["page"], $po["label"], $po["dtmf"]);
453400
454 - if (($this->deck->ml == HAW_VXML) && isset($extension) &&
455 - (($extension == "wav") || ($extension == "mp3")))
456 - {
457 - // play audio file on VoiceXML browser instead of creating link
458 - $introtext = new HAW_text($po["label"]);
459 - $this->deck->add_text($introtext);
460 - $audio = new HAW_text("");
461 - $audio->set_voice_text("Sorry, this voice browser does not support " . $extension . " format", $po["url"]);
462 - $this->deck->add_text($audio);
463 - }
464 - else
465 - {
466 - // mark as external link
467 - if ($po["ext"])
468 - {
469 - $el_image = new HAW_image(HAWIKI_EXTLINK_ICON . ".wbmp",
470 - HAWIKI_EXTLINK_ICON . ".gif", $po["extlink_text"]);
471 - $el_image->set_voice_text($po["extlink_text"]);
472 - $this->deck->add_image($el_image);
473 - }
 401+ if ($po["extwiki"])
 402+ {
 403+ $link = new HAW_link($po["label"], ereg_replace('\$page', urlencode($po["page"]), $po["extwiki"]) . "&mode=mobile");
 404+ }
 405+ else
 406+ $link = new HAW_link($po["label"], $this->wiki_base . urlencode($po["page"]));
474407
475 - // create link
476 - $link = new HAW_link($po["label"], $po["url"]);
477 - $link->set_br(0);
478 - $this->deck->add_link($link);
479 - }
 408+ if (isset($po["dtmf"]))
 409+ // assign DTMF key
 410+ $link->set_voice_dtmf($po["dtmf"]);
480411
481 - break;
482 - }
 412+ $link->set_br(0);
 413+ $this->deck->add_link($link);
483414
484 - case HAWIKI_TOKEN_TABLE:
485 - {
486 - // format of "text":
487 - // colums are seperated by '|' (this is pipe, not slash!)
488 - // rows are seperated by '\n'
 415+ break;
489416
490 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
491 - printf("<b>Table:</b> %s<br>\n", $po["text"]);
 417+ case HAWIKI_TOKEN_LINK:
 418+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 419+ printf("<b>Link:</b> url:%s label:%s<br>\n", $po["url"], $po["label"]);
492420
493 - $table = new HAW_table();
494 - $table_arr = explode("\n", $po["text"]);
 421+ // determine file extension of link
 422+ if (preg_match("/\.(\w*)$/", $po["url"], $matches))
 423+ $extension = strtolower($matches[1]);
495424
496 - while (list($key1, $val1) = each($table_arr))
497 - {
498 - $row = new HAW_row();
499 - $row_arr = explode("|", $val1);
 425+ if (($this->deck->ml == HAW_VXML) && isset($extension) &&
 426+ (($extension == "wav") || ($extension == "mp3")))
 427+ {
 428+ // play audio file on VoiceXML browser instead of creating link
 429+ $introtext = new HAW_text($po["label"]);
 430+ $this->deck->add_text($introtext);
 431+ $audio = new HAW_text("");
 432+ $audio->set_voice_text("Sorry, this voice browser does not support " . $extension . " format", $po["url"]);
 433+ $this->deck->add_text($audio);
 434+ }
 435+ else
 436+ {
 437+ // mark as external link
 438+ if ($po["ext"])
 439+ {
 440+ $el_image = new HAW_image(HAWIKI_EXTLINK_ICON . ".wbmp",
 441+ HAWIKI_EXTLINK_ICON . ".gif", $po["extlink_text"]);
 442+ $el_image->set_voice_text($po["extlink_text"]);
 443+ $this->deck->add_image($el_image);
 444+ }
500445
501 - while (list($key2, $val2) = each($row_arr))
502 - {
503 - $text = new HAW_text($val2);
504 - $text->set_br(0);
505 - $row->add_column($text);
506 - }
 446+ // create link
 447+ $link = new HAW_link($po["label"], $po["url"]);
 448+ $link->set_br(0);
 449+ $this->deck->add_link($link);
 450+ }
507451
508 - $table->add_row($row);
509 - }
 452+ break;
510453
511 - $this->deck->add_table($table);
 454+ case HAWIKI_TOKEN_TABLE:
 455+ // format of "text":
 456+ // colums are seperated by '|' (this is pipe, not slash!)
 457+ // rows are seperated by '\n'
512458
513 - break;
514 - }
 459+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 460+ printf("<b>Table:</b> %s<br>\n", $po["text"]);
515461
516 - case HAWIKI_TOKEN_IMAGE:
517 - {
518 - global $tikidomain;
519 -#echo("##########################################");
520 - if ($tikidomain)
521 - $po["src"] = preg_replace("~img/wiki_up/~","img/wiki_up/$tikidomain/", $po["src"]);
 462+ $table = new HAW_table();
 463+ $table_arr = explode("\n", $po["text"]);
522464
523 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
524 - printf("<b>Image:</b> src:%s alt:%s link:%s<br>\n", $po["src"], $po["alt"], $po["link"]);
 465+ while (list($key1, $val1) = each($table_arr))
 466+ {
 467+ $row = new HAW_row();
 468+ $row_arr = explode("|", $val1);
525469
526 - if ($po["src"])
527 - {
528 - if ($this->hawimconv)
529 - {
530 - // HAWHAW image converter available
 470+ while (list($key2, $val2) = each($row_arr))
 471+ {
 472+ $text = new HAW_text($val2);
 473+ $text->set_br(0);
 474+ $row->add_column($text);
 475+ }
531476
532 - if (preg_match("/^htt/", $po["src"]))
533 - {
534 - // full qualified url ==> use unchanged
535 - $img_wbmp = sprintf("%s?img=%s", $this->hawimconv, urlencode($po["src"]));
536 - }
537 - elseif(preg_match("/^\//", $po["src"]))
538 - {
539 - // absolute url ==> append filename to document root
540 - $img_wbmp = sprintf("%s?img=%s", $this->hawimconv,
541 - urlencode($_SERVER["DOCUMENT_ROOT"] . $po["src"]));
 477+ $table->add_row($row);
 478+ }
542479
543 - }
544 - else
545 - {
546 - // relative url ==> append filename to working directory
547 - $img_wbmp = sprintf("%s?img=%s", $this->hawimconv,
548 - urlencode(getcwd() . "/" . $po["src"]));
549 - }
550 - }
551 - else
552 - {
553 - // no image converter available ==> rely on available wbmp image ...
554 - $img_wbmp = ereg_replace(".gif$|.png$|.jpg$", ".wbmp", $po["src"]);
555 - }
 480+ $this->deck->add_table($table);
556481
557 - if (isset($po["alt"]) && ($po["alt"] != ""))
558 - $img_alt = $po["alt"];
559 - else
560 - $img_alt = $po["src"]; // set alternative text to src, if not available
 482+ break;
561483
562 - $image = new HAW_image($img_wbmp, $po["src"], $img_alt);
563 - $this->deck->add_image($image);
564 - }
 484+ case HAWIKI_TOKEN_IMAGE:
 485+ global $tikidomain;
 486+ #echo("##########################################");
 487+ if ($tikidomain)
 488+ $po["src"] = preg_replace("~img/wiki_up/~","img/wiki_up/$tikidomain/", $po["src"]);
565489
566 - if (isset($po["link"]) && $po["link"] && ($this->deck->ml != HAW_VXML))
567 - {
568 - // HAWHAW does not support images as links
569 - // ==> draw @-link next to image (for visual browsers)
570 - $po["link"] = ereg_replace("&amp;", "&", $po["link"]); // &-treatment is done by HAWHAW
571 - $link = new HAW_link("@", $po["link"]);
572 - $link->set_br(0);
573 - $this->deck->add_link($link);
574 - }
 490+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 491+ printf("<b>Image:</b> src:%s alt:%s link:%s<br>\n", $po["src"], $po["alt"], $po["link"]);
575492
576 - break;
577 - }
 493+ if ($po["src"])
 494+ {
 495+ if ( substr( $po['src'], 0, 10 ) !== 'image.php?' ) {
 496+ $img_wbmp = 'image.php?' . $po['src'];
 497+ } else {
 498+ $img_wbmp = $po['src'];
 499+ }
 500+ if (isset($po["alt"]) && ($po["alt"] != ""))
 501+ $img_alt = $po["alt"];
 502+ else
 503+ $img_alt = $po["src"]; // set alternative text to src, if not available
578504
579 - case HAWIKI_TOKEN_SMILEY:
580 - {
581 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
582 - printf("<b>Smiley:</b> %s<br>\n", $po["text"]);
 505+ $image = new HAW_image($img_wbmp, $po["src"], $img_alt);
 506+ $this->deck->add_image($image);
 507+ }
583508
584 - if ($this->smiley_dir)
585 - {
586 - // smiley directory has been set by the user
 509+ if (isset($po["link"]) && $po["link"] && ($this->deck->ml != HAW_VXML))
 510+ {
 511+ // HAWHAW does not support images as links
 512+ // ==> draw @-link next to image (for visual browsers)
 513+ $po["link"] = ereg_replace("&amp;", "&", $po["link"]); // &-treatment is done by HAWHAW
 514+ $link = new HAW_link("@", $po["link"]);
 515+ $link->set_br(0);
 516+ $this->deck->add_link($link);
 517+ }
587518
588 - $img_html = $this->smiley_dir . "/icon_" . $po["text"] . ".gif";
589 - $img_wbmp = $this->smiley_dir . "/icon_" . $po["text"] . ".wbmp";
590 - $img_alt = ":)";
591 - $image = new HAW_image($img_wbmp, $img_html, $img_alt);
592 - $image->use_localsrc("smileyface");
593 - $this->deck->add_image($image);
594 - }
 519+ break;
595520
596 - break;
597 - }
 521+ case HAWIKI_TOKEN_SMILEY:
 522+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 523+ printf("<b>Smiley:</b> %s<br>\n", $po["text"]);
598524
599 - case HAWIKI_TOKEN_PLUGIN:
600 - {
601 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
602 - printf("<b>Plugin:</b> %s<br>\n", htmlspecialchars($po["html"]));
 525+ if ($this->smiley_dir)
 526+ {
 527+ // smiley directory has been set by the user
603528
604 - if ($po["html"])
605 - {
606 - // plugins return pure HTML ==> show on HTML browsers only
607 - $rawhtml = new HAW_raw(HAW_HTML, $po["html"]);
608 - $this->deck->add_raw($rawhtml);
609 - }
 529+ $img_html = $this->smiley_dir . "/icon_" . $po["text"] . ".gif";
 530+ $img_wbmp = $this->smiley_dir . "/icon_" . $po["text"] . ".wbmp";
 531+ $img_alt = ":)";
 532+ $image = new HAW_image($img_wbmp, $img_html, $img_alt);
 533+ $image->use_localsrc("smileyface");
 534+ $this->deck->add_image($image);
 535+ }
610536
611 - break;
612 - }
 537+ break;
613538
614 - default:
615 - {
616 - if ($this->debugflags & HAWIKI_DEBUG_PARSER)
617 - printf("<b>Unknown token:</b> %d<br>\n", $po["token"]);
 539+ case HAWIKI_TOKEN_PLUGIN:
 540+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 541+ printf("<b>Plugin:</b> %s<br>\n", htmlspecialchars($po["html"]));
618542
619 - break;
620 - }
621 - }
622 - }
 543+ if ($po["html"])
 544+ {
 545+ // plugins return pure HTML ==> show on HTML browsers only
 546+ $rawhtml = new HAW_raw(HAW_HTML, $po["html"]);
 547+ $this->deck->add_raw($rawhtml);
 548+ }
623549
624 - if (strlen($input) > 0)
625 - {
626 - // parsing aborted due to syntax error
627 - // ==> terminate output with error message
 550+ break;
628551
629 - $newline = new HAW_text("");
630 - $this->deck->add_text($newline);
631 - $error_text = new HAW_text("Error: Invalid wiki syntax");
632 - $this->deck->add_text($error_text);
633 - }
 552+ default:
 553+ if ($this->debugflags & HAWIKI_DEBUG_PARSER)
 554+ printf("<b>Unknown token:</b> %d<br>\n", $po["token"]);
634555
635 - $link_counter = 0;
636 - foreach ($this->navlink as $value)
637 - {
638 - // create navigation link(s) at bottom of wiki page
 556+ break;
 557+ }
 558+ }
639559
640 - if ($value["pos"] & HAWIKI_NAVLINK_BOTTOM)
641 - {
642 - if ($link_counter == 0)
643 - {
644 - // create horozontal rule between wiki content and 1st link
645 - $rule = new HAW_rule();
646 - $this->deck->add_rule($rule);
647 - }
 560+ if (strlen($input) > 0)
 561+ {
 562+ // parsing aborted due to syntax error
 563+ // ==> terminate output with error message
648564
649 - $link = new HAW_link($value["label"], $value["url"]);
650 - $this->deck->add_link($link);
651 - $link_counter++;
652 - }
653 - }
 565+ $newline = new HAW_text("");
 566+ $this->deck->add_text($newline);
 567+ $error_text = new HAW_text("Error: Invalid wiki syntax");
 568+ $this->deck->add_text($error_text);
 569+ }
654570
655 - if (isset($this->phonelink) &&
656 - ($this->phonelink['pos'] & HAWIKI_NAVLINK_BOTTOM))
657 - {
658 - // add callable phone number at bottom of wiki page
659 - $phone = new HAW_phone($this->phonelink['phone_number'],
660 - $this->phonelink['label']);
661 - $this->deck->add_phone($phone);
662 - }
663 -
664 - // set jingle for VoiceXML links
665 - if ($this->link_jingle)
666 - {
667 - // jingle has been set by hawiki user
668 - $this->deck->set_voice_jingle($this->link_jingle);
669 - }
 571+ $link_counter = 0;
 572+ foreach ($this->navlink as $value)
 573+ {
 574+ // create navigation link(s) at bottom of wiki page
670575
671 - // smooth voice sections
672 - $this->deck->smooth_voice();
 576+ if ($value["pos"] & HAWIKI_NAVLINK_BOTTOM)
 577+ {
 578+ if ($link_counter == 0)
 579+ {
 580+ // create horozontal rule between wiki content and 1st link
 581+ $rule = new HAW_rule();
 582+ $this->deck->add_rule($rule);
 583+ }
673584
674 - // output appropriate markup language
675 - $this->deck->create_page();
676 - }
 585+ $link = new HAW_link($value["label"], $value["url"]);
 586+ $this->deck->add_link($link);
 587+ $link_counter++;
 588+ }
 589+ }
677590
 591+ if (isset($this->phonelink) &&
 592+ ($this->phonelink['pos'] & HAWIKI_NAVLINK_BOTTOM))
 593+ {
 594+ // add callable phone number at bottom of wiki page
 595+ $phone = new HAW_phone($this->phonelink['phone_number'],
 596+ $this->phonelink['label']);
 597+ $this->deck->add_phone($phone);
 598+ }
678599
679 - function set_navlink($label, $url, $pos)
680 - {
681 - // define navigation link on top and/or bottom of wiki page
682 - // label: link text
683 - // url: link url
684 - // pos: HAWIKI_NAVLINK_TOP (link is created at top of wiki page)
685 - // HAWIKI_NAVLINK_BOTTOM (link is created at bottom of wiki page)
686 - // HAWIKI_NAVLINK_TOP | HAWIKI_NAVLINK_BOTTOM (top AND bottom)
 600+ // set jingle for VoiceXML links
 601+ if ($this->link_jingle)
 602+ {
 603+ // jingle has been set by hawiki user
 604+ $this->deck->set_voice_jingle($this->link_jingle);
 605+ }
687606
688 - $arr["label"] = $label;
689 - $arr["url"] = $url;
690 - $arr["pos"] = $pos;
 607+ // smooth voice sections
 608+ $this->deck->smooth_voice();
691609
692 - $this->navlink[] = $arr; // enhance array with navigation links
693 - }
 610+ // output appropriate markup language
 611+ $this->deck->create_page();
 612+ }
694613
695614
696 - function set_phonelink($label, $phone_number, $pos)
697 - {
698 - // define phone link on top and/or bottom of wiki page
699 - // label: link text
700 - // url: phone url
701 - // pos: HAWIKI_NAVLINK_TOP (link is created at top of wiki page)
702 - // HAWIKI_NAVLINK_BOTTOM (link is created at bottom of wiki page)
703 - // HAWIKI_NAVLINK_TOP | HAWIKI_NAVLINK_BOTTOM (top AND bottom)
 615+ function set_navlink($label, $url, $pos)
 616+ {
 617+ // define navigation link on top and/or bottom of wiki page
 618+ // label: link text
 619+ // url: link url
 620+ // pos: HAWIKI_NAVLINK_TOP (link is created at top of wiki page)
 621+ // HAWIKI_NAVLINK_BOTTOM (link is created at bottom of wiki page)
 622+ // HAWIKI_NAVLINK_TOP | HAWIKI_NAVLINK_BOTTOM (top AND bottom)
704623
705 - $arr["label"] = $label;
706 - $arr["phone_number"] = $phone_number;
707 - $arr["pos"] = $pos;
 624+ $arr["label"] = $label;
 625+ $arr["url"] = $url;
 626+ $arr["pos"] = $pos;
708627
709 - $this->phonelink = $arr; // set array with phone info
710 - }
 628+ $this->navlink[] = $arr; // enhance array with navigation links
 629+ }
711630
712631
713 - function set_smiley_dir($dir)
714 - {
715 - // set directory where smileys are stored
716 - $this->smiley_dir = $dir;
717 - }
 632+ function set_phonelink($label, $phone_number, $pos)
 633+ {
 634+ // define phone link on top and/or bottom of wiki page
 635+ // label: link text
 636+ // url: phone url
 637+ // pos: HAWIKI_NAVLINK_TOP (link is created at top of wiki page)
 638+ // HAWIKI_NAVLINK_BOTTOM (link is created at bottom of wiki page)
 639+ // HAWIKI_NAVLINK_TOP | HAWIKI_NAVLINK_BOTTOM (top AND bottom)
718640
 641+ $arr["label"] = $label;
 642+ $arr["phone_number"] = $phone_number;
 643+ $arr["pos"] = $pos;
719644
720 - function set_link_jingle($url)
721 - {
722 - // set link wav-file for VoiceXML
723 - $this->link_jingle = $url;
724 - }
 645+ $this->phonelink = $arr; // set array with phone info
 646+ }
725647
726648
727 - function set_hawimconv($url)
728 - {
729 - // determine HAWHAW image conversion script
730 - $this->hawimconv = $url;
731 - }
 649+ function set_smiley_dir($dir)
 650+ {
 651+ // set directory where smileys are stored
 652+ $this->smiley_dir = $dir;
 653+ }
732654
733655
734 - function set_debugflags($flags)
735 - {
736 - $this->debugflags = $flags;
737 - }
 656+ function set_link_jingle($url)
 657+ {
 658+ // set link wav-file for VoiceXML
 659+ $this->link_jingle = $url;
 660+ }
 661+
 662+
 663+ function set_hawimconv($url)
 664+ {
 665+ // determine HAWHAW image conversion script
 666+ $this->hawimconv = $url;
 667+ }
 668+
 669+
 670+ function set_debugflags($flags)
 671+ {
 672+ $this->debugflags = $flags;
 673+ }
738674 };
739675
740676 ?>