0d872428d8211a62c1f2218913aaa1d5cde0eb9d
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / InlineTags.inc
1 <?php\r
2 /**\r
3  * All abstract representations of inline tags are in this file\r
4  *\r
5  * phpDocumentor :: automatic documentation generator\r
6  * \r
7  * PHP versions 4 and 5\r
8  *\r
9  * Copyright (c) 2002-2006 Gregory Beaver\r
10  * \r
11  * LICENSE:\r
12  * \r
13  * This library is free software; you can redistribute it\r
14  * and/or modify it under the terms of the GNU Lesser General\r
15  * Public License as published by the Free Software Foundation;\r
16  * either version 2.1 of the License, or (at your option) any\r
17  * later version.\r
18  * \r
19  * This library is distributed in the hope that it will be useful,\r
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
22  * Lesser General Public License for more details.\r
23  * \r
24  * You should have received a copy of the GNU Lesser General Public\r
25  * License along with this library; if not, write to the Free Software\r
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
27  *\r
28  * @package    phpDocumentor\r
29  * @subpackage InlineTags\r
30  * @author     Gregory Beaver <cellog@php.net>\r
31  * @copyright  2002-2006 Gregory Beaver\r
32  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL\r
33  * @version    CVS: $Id: InlineTags.inc,v 1.7 2007/04/19 20:20:57 ashnazg Exp $\r
34  * @filesource\r
35  * @link       http://www.phpdoc.org\r
36  * @link       http://pear.php.net/PhpDocumentor\r
37  * @since      separate file since 1.2\r
38  */\r
39 /**\r
40  * Use this element to represent an {@}inline tag} like {@}link}\r
41  * @see parserStringWithInlineTags\r
42  * @package phpDocumentor\r
43  * @subpackage InlineTags\r
44  * @author Greg Beaver <cellog@php.net>\r
45  * @since 1.0rc1\r
46  * @version $Revision: 1.7 $\r
47  * @tutorial inlinetags.pkg\r
48  */\r
49 class parserInlineTag extends parserBase\r
50 {\r
51     /**\r
52      * Element type\r
53      *\r
54      * Type is used by many functions to skip the hassle of\r
55      *\r
56      * <code>\r
57      * if phpDocumentor_get_class($blah) == 'parserBlah'\r
58      * </code>\r
59      * always "inlinetag"\r
60      * @var string\r
61      */\r
62     var $type = 'inlinetag';\r
63     /**\r
64      * the name of the inline tag (like link)\r
65      * @var string\r
66      */\r
67     var $inlinetype = '';\r
68     \r
69     /**\r
70      * @param string $type tag type (example: link)\r
71      * @param string $value tag value (example: what to link to)\r
72      */\r
73     function parserInlineTag($type,$value)\r
74     {\r
75         $this->inlinetype = $type;\r
76         $this->value = trim($value);\r
77     }\r
78     \r
79     /**\r
80      * @return integer length of the tag\r
81      */\r
82     function Strlen()\r
83     {\r
84         // fix 1203451\r
85         if (is_array($this->value))\r
86         {\r
87             return array_reduce(create_function('$a,$b', 'return $a + strlen($b);')) +\r
88                 count($this->value);\r
89         }\r
90         return strlen($this->value);\r
91     }\r
92     \r
93     /**\r
94      * @return string always '', used by {@link Parser::handleDocBlock()} to\r
95      *                calculate the short description of a DocBlock\r
96      * @see parserStringWithInlineTags::getString()\r
97      * @see parserStringWithInlineTags::trimmedStrlen()\r
98      */\r
99     function getString()\r
100     {\r
101         return '';\r
102     }\r
103 }\r
104 \r
105 /**\r
106  * represents inline links\r
107  * @tutorial tags.inlinelink.pkg\r
108  * @package phpDocumentor\r
109  * @subpackage InlineTags\r
110  * @author Greg Beaver <cellog@php.net>\r
111  * @since 1.0rc1\r
112  */\r
113 class parserLinkInlineTag extends parserInlineTag\r
114 {\r
115     /**\r
116      * text to display in the link, can be different from the link for standard\r
117      * links like websites\r
118      * @var string\r
119      */\r
120     var $linktext = '';\r
121     \r
122     /**\r
123      * @param string $link stored in $value, see {@link parserBase::$value}\r
124      * @param string $text see {@link $linktext}\r
125      */\r
126     function parserLinkInlineTag($link,$text)\r
127     {\r
128         if (strpos($link, ','))\r
129         {\r
130             $link = explode(',',$link);\r
131             parserInlineTag::parserInlineTag('link','');\r
132             $this->value = $link;\r
133         } else\r
134         {\r
135             parserInlineTag::parserInlineTag('link',$link);\r
136         }\r
137         $this->linktext = trim($text);\r
138     }\r
139     \r
140     /**\r
141      * @param Converter converter used to change the abstract link into text for\r
142      *                  display\r
143      * @return false|string returns the converted link or false if not converted\r
144      *                      successfully\r
145      */\r
146     function Convert(&$c)\r
147     {\r
148         if (is_array($this->value))\r
149         {\r
150             $ret = '';\r
151             foreach($this->value as $text)\r
152             {\r
153                 if (!empty($ret))\r
154                 {\r
155                     $ret .= ', ';\r
156                 }\r
157                 $ret .= $this->ConvertPart($c, trim($text));\r
158             }\r
159             return $ret;\r
160         } else\r
161         {\r
162             return $this->ConvertPart($c, $this->value);\r
163         }\r
164     }\r
165     \r
166     function ConvertPart(&$c, $value)\r
167     {\r
168         if (strpos($value,'://') || (strpos($value,'mailto:') === 0))\r
169         {\r
170             if (strpos($value, ' '))\r
171             {\r
172                 $value = explode(' ', $value);\r
173                 $link = array_shift($value);\r
174                 $text = join(' ', $value);\r
175             } else\r
176             {\r
177                 $link = $value;\r
178                 $text = $this->linktext;\r
179             }\r
180             return $c->returnLink($link,htmlspecialchars($text));\r
181         } else\r
182         {\r
183             $savevalue = $value;\r
184             $descrip = false;\r
185             if (strpos(trim($value),' '))\r
186             {\r
187                 $v = preg_split('/\s/',trim($value));\r
188                 if (in_array(strtolower($v[0]), array('object', 'function')))\r
189                 {\r
190                     if (!isset($v[1]) ||\r
191                         (isset($v[1]) && strlen($v[1])\r
192                             && !in_array($v[1]{0}, array('$','&'))\r
193                             && $v[1] != '###commanana####'))\r
194                     {\r
195                         $vsave = $v[0];\r
196                         array_shift($v);\r
197                         $v[0] = $vsave . ' ' . $v[0];\r
198                     }\r
199                 }\r
200                 $value = $c->getLink($v[0]);\r
201                 array_shift($v);\r
202                 $descrip = join($v,' ');\r
203                 $descrip = str_replace('###commanana####', ',', $descrip);\r
204             } else\r
205             {\r
206                 $value = $c->getLink($value);\r
207             }\r
208             if (is_string($value))\r
209             {\r
210                 // feature 564991\r
211                 if (strpos($value,'://'))\r
212                 {\r
213                     // php function\r
214                     return $c->returnLink($value,\r
215                         $descrip ? $descrip : str_replace('PHP_MANUAL#','',$value));\r
216                 }\r
217                 return $value;\r
218             }\r
219             if (!$descrip) $descrip = $c->type_adjust($savevalue);\r
220             if (is_object($value)) return $c->returnSee($value, $descrip);\r
221 /*            // getLink parsed a comma-delimited list of linked thingies, add the commas back in\r
222             if (is_array($value))\r
223             {\r
224                 $a = '';\r
225                 foreach($value as $i => $bub)\r
226                 {\r
227                     if (!empty($a)) $a .= ', ';\r
228                     if (is_string($value[$i]))\r
229                     {\r
230                         // feature 564991\r
231                         if (strpos($value[$i],'://'))\r
232                         {\r
233                             // php function\r
234                             $a .= $c->returnLink($value[$i],str_replace('PHP_MANUAL#','',$vals[$i]));\r
235                         } else\r
236                         $a .= $value[$i];\r
237                     }\r
238                     if (is_object($value[$i])) $a .= $c->returnSee($value[$i],$descrip[$i]);\r
239                 }\r
240                 return $a;\r
241             } */\r
242             return $savevalue;\r
243         }\r
244     }\r
245 }\r
246 \r
247 /**\r
248  * Represents inline links to external tutorial documentation\r
249  * @tutorial tags.inlinetutorial.pkg\r
250  * @package phpDocumentor\r
251  * @subpackage InlineTags\r
252  */\r
253 class parserTutorialInlineTag extends parserLinkInlineTag\r
254 {\r
255     /**\r
256      * @param string $link stored in $value, see {@link parserBase::$value}\r
257      * @param string $text see {@link $linktext}\r
258      */\r
259     function parserTutorialInlineTag($link,$text)\r
260     {\r
261         parserInlineTag::parserInlineTag('tutorial',$link);\r
262         $this->linktext = trim($text);\r
263     }\r
264 \r
265     /**\r
266      * @param Converter converter used to change the abstract link into text for display\r
267      * @return mixed returns the converted link or false if not converted successfully\r
268      */\r
269     function Convert(&$c)\r
270     {\r
271         $descrip = false;\r
272         if (strpos($this->value,',') === false)\r
273         {\r
274             if (strpos(trim($this->value),' '))\r
275             {\r
276                 $v = split(' ',trim($this->value));\r
277                 $value = $c->getTutorialLink($v[0]);\r
278                 array_shift($v);\r
279                 $descrip = join($v,' ');\r
280             } else $value = $c->getTutorialLink($this->value);\r
281         } else\r
282         {\r
283             $vals = split(',',$this->value);\r
284             $descrip = array();\r
285             foreach($vals as $val)\r
286             {\r
287                 $val = trim($val);\r
288                 if (strpos($val,' '))\r
289                 {\r
290                     $v = split(' ',$val);\r
291                     $value[] = $c->getTutorialLink($v[0]);\r
292                     array_shift($v);\r
293                     $descrip[] = join($v,' ');\r
294                 } else\r
295                 {\r
296                     $value[] = $c->getTutorialLink($val);\r
297                     $descrip[] = false;\r
298                 }\r
299             }\r
300         }\r
301         if (is_string($value))\r
302         {\r
303             return $value;\r
304         }\r
305         if (is_object($value)) return $c->returnSee($value,$descrip);\r
306         // getLink parsed a comma-delimited list of linked thingies, add the commas back in\r
307         if (is_array($value))\r
308         {\r
309             $a = '';\r
310             foreach($value as $i => $bub)\r
311             {\r
312                 if (!empty($a)) $a .= ', ';\r
313                 if (is_string($value[$i]))\r
314                 {\r
315                     $a .= $value[$i];\r
316                 }\r
317                 if (is_object($value[$i])) $a .= $c->returnSee($value[$i],$descrip[$i]);\r
318             }\r
319             return $a;\r
320         }\r
321         return false;\r
322     }\r
323 }\r
324 \r
325 /**\r
326  * represents inline source tag, used for function/method source\r
327  * @tutorial tags.inlinesource.pkg\r
328  * @package phpDocumentor\r
329  * @subpackage InlineTags\r
330  */\r
331 class parserSourceInlineTag extends parserInlineTag\r
332 {\r
333     /**\r
334      * always 'source'\r
335      * @var string\r
336      */\r
337     var $inlinetype = 'source';\r
338     /**\r
339      * First line of source code to display\r
340      * @var integer\r
341      * @see $end\r
342      */\r
343     var $start = 1;\r
344     /**\r
345      * Last line to display\r
346      * @var '*'|integer If '*' then the whole source will be used, otherwise\r
347      *                  the {@link $start} to $end line numbers will be displayed\r
348      */\r
349     var $end = '*';\r
350     /**\r
351      * tokenized source organized by line numbers for php 4.3.0+, the old\r
352      * {@}source} tag used a string\r
353      * @var string|array\r
354      */\r
355     var $source = false;\r
356     /**#@+ @access private */\r
357     /** @var string|false */\r
358     var $_class;\r
359     /**#@-*/\r
360     /**\r
361      * @param string format "start [end]" where start and end are line numbers\r
362      *               with the end line number optional\r
363      */\r
364     function parserSourceInlineTag($value)\r
365     {\r
366         parserInlineTag::parserInlineTag('source','');\r
367         preg_match('/^([0-9]+)\W([0-9]*)$/',trim($value), $match);\r
368         if (!count($match))\r
369         {\r
370             preg_match('/^([0-9]+)$/',trim($value),$match);\r
371             if (count($match))\r
372             {\r
373                 $this->start = (int) $match[1];\r
374             }\r
375         } else\r
376         {\r
377             $this->start = (int) $match[1];\r
378             $this->end = (int) $match[2];\r
379         }\r
380     }\r
381     \r
382     /**\r
383      * only used to determine blank lines.  {@}source} will not be blank,\r
384      * probably\r
385      */\r
386     function Strlen()\r
387     {\r
388         return 1;\r
389     }\r
390     \r
391     function getString()\r
392     {\r
393         return '{@source}';\r
394     }\r
395     \r
396     /**\r
397      * @param string|array source code\r
398      * @param boolean in php 4.3.0, if this is a method this will be true\r
399      * @param string class name if this is a method\r
400      */\r
401     function setSource($source, $class = false)\r
402     {\r
403         if (is_array($source))\r
404         {\r
405             $this->_class = $class;\r
406             $this->source = $source;\r
407         } else\r
408         {\r
409             $source = strstr($source,'function');\r
410             $pos = strrpos($source,'}');\r
411             $this->source = substr($source,0,$pos + 1);\r
412         }\r
413     }\r
414     \r
415     /**\r
416      * @uses stringConvert() in PHP 4.2.3-, this method is used to convert\r
417      * @uses arrayConvert() in PHP 4.3.0+, this method is used to convert\r
418      * @param Converter\r
419      */\r
420     function Convert(&$c)\r
421     {\r
422         if (is_string($this->source)) return $this->stringConvert($c);\r
423         return $this->arrayConvert($c);\r
424     }\r
425     \r
426     /**\r
427      * @param Converter\r
428      * @uses phpDocumentor_HighlightParser Parses the tokenized source\r
429      */\r
430     function arrayConvert(&$c)\r
431     {\r
432         $source = $this->source;\r
433         if ($this->end != '*')\r
434         {\r
435             $source = array_slice($this->source,0,$this->end + $this->start - 1);\r
436         }\r
437         $start = $this->start - 1;\r
438         if ($start < 0) $start = 0;\r
439         return $c->ProgramExample($source, true, true, $this->_class, $start);\r
440     }\r
441     \r
442     /**\r
443      * @param Converter\r
444      * @uses Converter::unmangle() remove the extraneous stuff from\r
445      *                             {@link highlight_string()}\r
446      * @deprecated in favor of PHP 4.3.0+ {@link arrayConvert()}\r
447      */\r
448     function stringConvert(&$c)\r
449     {\r
450         $source = highlight_string('<?php '.$this->source.' ?>', true);\r
451         $source = '<code>'.substr($source,strlen('<code><font color="#000000">\r
452 <font color="#0000CC">&lt;?php&nbsp;</font>') - 1);\r
453         $source = str_replace('}&nbsp;</font><font color="#0000CC">?&gt;</font>','}</font></code>',$source);\r
454         if ($this->start || ($this->end != '*'))\r
455         {\r
456             $source = explode('<br />',$source);\r
457             $start = $this->start;\r
458             if ($this->end != '*')\r
459             {\r
460                 $source = array_slice($source,$start - 1,$this->end - $start + 1);\r
461             } else\r
462             {\r
463                 $source = array_slice($source,$start - 1);\r
464             }\r
465             $source = implode($source,'<br />');\r
466             if ($start > 0) $source = "<code>$source";\r
467             if ($this->end != '*') $source = "$source</code>";\r
468         }\r
469         $source = $c->unmangle($source,$this->source);\r
470         return $source;\r
471     }\r
472 }\r
473 \r
474 /**\r
475  * Represents the example inline tag, used to display an example file\r
476  * inside a docblock or tutorial\r
477  * @tutorial tags.inlineexample.pkg\r
478  * @package phpDocumentor\r
479  * @subpackage InlineTags\r
480  */\r
481 class parserExampleInlineTag extends parserSourceInlineTag\r
482 {\r
483     /**\r
484      * @param string format "filepath[ start [end]]" where start and end are line numbers\r
485      *               with the end line number optional\r
486      * @param string full path to the current file, used to check relative\r
487      *               directory locations\r
488      * @param boolean if true, then this is in a tutorial\r
489      */\r
490     function parserExampleInlineTag($value, $current_path, $isTutorial = false)\r
491     {\r
492         global $_phpDocumentor_setting;\r
493         parserInlineTag::parserInlineTag('example','');\r
494         $path = false;\r
495         $tagValue = trim($value);\r
496         $path = $isAbsPath = $pathOnly = $fileName = $fileExt = $original_path  = $title = FALSE;\r
497         do\r
498         {\r
499             // make sure the format is stuff.ext startline[ endline]\r
500             if (!preg_match('`(.*)\.(\w*)\s(.*)`', $tagValue, $match))\r
501             {\r
502                 // or format is stuff.ext\r
503                 if (!preg_match('`(.*)\.(\w*)\s*$`', $tagValue, $match))\r
504                 {\r
505                     // Murphy: Some funny path was given\r
506                     $original_path = $tagValue; // used for error output\r
507                     break; // try-block\r
508                 }\r
509             }\r
510             if (strlen($match[1]) === 0)\r
511             {\r
512                 // Murphy: Some funny path was given\r
513                 $original_path = $tagValue; // used for error output\r
514                 break; // try-block\r
515             }\r
516             $fileExt = $match[2];\r
517             if (isset($match[3]))\r
518             {\r
519                 $lines = explode(' ', trim($match[3]));\r
520                 $this->start = (int) $lines[0];\r
521                 if (isset($lines[1])) {\r
522                     $this->end = (int) $lines[1];\r
523                 }\r
524             }\r
525             $pathTmp = str_replace('\\', '/', $match[1]); // Replace windows '\' the path.\r
526 \r
527             // Is there a path and a file or is it just a file?\r
528             if (strpos($pathTmp,'/') === false)\r
529             {\r
530                 // No path part\r
531                 $pathOnly = '';\r
532                 $fileName = $pathTmp .'.'. $fileExt;\r
533             } else\r
534             {\r
535                 $splitPos = strrpos($pathTmp,'/'); // split the path on the last directory, find the filename\r
536                 $pathOnly = substr($match[1], 0, $splitPos+1);\r
537                 $fileName = substr($match[1], $splitPos+1) .'.'. $fileExt;\r
538                 // Is the path absolute? (i.e. does it start like an absolute path?)\r
539                 if (('/' === $pathTmp[0]) || preg_match('`^\w*:`i', $pathTmp))\r
540                 { // works for both windows 'C:' and URLs like 'http://'\r
541                     $isAbsPath = true; // Yes\r
542                 }\r
543             }\r
544 \r
545             $original_path = $pathOnly . $fileName;\r
546 \r
547             // Now look for the file starting with abs. path.\r
548             if ($isAbsPath)\r
549             {\r
550                 $tmp = realpath($original_path); // remove any weirdities like /../file.ext\r
551                 if ($tmp && is_file($tmp))\r
552                 {\r
553                     $path = $tmp;\r
554                 }\r
555                 // Alway break if abs. path was detected; even if file was not found.\r
556                 break; // try-block\r
557             }\r
558 \r
559             // Search for the example file some standard places \r
560             // 1) Look if the ini-var examplesdir is set and look there ...\r
561             if (isset($_phpDocumentor_setting['examplesdir']))\r
562             {\r
563                 $tmp = realpath($_phpDocumentor_setting['examplesdir'] . PATH_DELIMITER  . $original_path);\r
564                 if ($tmp && is_file($tmp))\r
565                 {\r
566                     $path = $tmp; // Yo! found it :)\r
567                     break; // try-block\r
568                 }\r
569             }\r
570 \r
571             // 2) Then try to look for an 'example/'-dir below the *currently* parsed file ...\r
572             if (!empty($current_path))\r
573             {\r
574                 $tmp = realpath(dirname($current_path) . PATH_DELIMITER . 'examples' . PATH_DELIMITER . $fileName);\r
575                 if ($tmp && is_file($tmp))\r
576                 {\r
577                     $path = $tmp; // Yo! found it :)\r
578                     break; // try-block\r
579                 }\r
580             }\r
581 \r
582             // 3) Then try to look for the example file below the subdir PHPDOCUMENTOR_BASE/examples/ ...\r
583             if (is_dir(PHPDOCUMENTOR_BASE . PATH_DELIMITER . 'examples'))\r
584             {\r
585                 $tmp = realpath(PHPDOCUMENTOR_BASE . PATH_DELIMITER . 'examples' . PATH_DELIMITER . $original_path);\r
586                 if ($tmp && is_file($tmp))\r
587                 {\r
588                     $path = $tmp; // Yo! found it :)\r
589                     break; // try-block\r
590                 }\r
591             }\r
592 \r
593             $tmp = realpath(PHPDOCUMENTOR_BASE . PATH_DELIMITER . $original_path);\r
594             if ($tmp && is_file($tmp))\r
595             {\r
596                 $path = $tmp; // Yo! found it :)\r
597                 break; // try-block\r
598             }\r
599             // If we reach this point, nothing was found and $path is false.\r
600         } while (false);\r
601 \r
602         if (!$path)\r
603         {\r
604             addWarning(PDERROR_EXAMPLE_NOT_FOUND, $original_path);\r
605             $this->path = false;\r
606         } else\r
607         {\r
608             $f = @fopen($path,'r');\r
609             if ($f)\r
610             {\r
611                 $example = fread($f,filesize($path));\r
612                 if (tokenizer_ext && !$isTutorial)\r
613                 {\r
614                     $obj = new phpDocumentorTWordParser;\r
615                     $obj->setup($example);\r
616                     $this->setSource($obj->getFileSource());\r
617                     unset($obj);\r
618                 } else\r
619                 {\r
620                     $this->setSource($example);\r
621                 }\r
622             }\r
623         }\r
624     }\r
625     \r
626     /**\r
627      * @param string|array source code\r
628      * @param boolean in php 4.3.0, if this is a method this will be true\r
629      * @param string class name if this is a method\r
630      */\r
631     function setSource($source, $class = false)\r
632     {\r
633         $this->_class = $class;\r
634         $this->source = $source;\r
635     }\r
636     \r
637     /**\r
638      * @param Converter\r
639      * @uses phpDocumentor_HighlightParser Parses the tokenized source\r
640      */\r
641     function arrayConvert(&$c)\r
642     {\r
643         $source = $this->source;\r
644         if ($this->end != '*')\r
645         {\r
646             $source = array_slice($this->source,0,$this->end + $this->start - 1);\r
647         }\r
648         $start = $this->start - 1;\r
649         if ($start < 0) $start = 0;\r
650         return $c->exampleProgramExample($source, true, true, $this->_class, $start);\r
651     }\r
652 \r
653     /**\r
654      * Return the source for the example file, enclosed in\r
655      * a <programlisting> tag to use in a tutorial\r
656      * @return string\r
657      */\r
658     function getProgramListing()\r
659     {\r
660         $source = explode("\n", $this->source);\r
661         $start = $this->start;\r
662         if ($this->end != '*')\r
663         {\r
664             $source = array_slice($source,$start - 1,$this->end - $start + 1);\r
665         } else\r
666         {\r
667             $source = array_slice($source,$start - 1);\r
668         }\r
669         $source = join("\n", $source);\r
670         return\r
671         "<programlisting role=\"php\">\r
672          <![CDATA[\n" .\r
673           $source .\r
674         "\n]]>\n</programlisting>";\r
675     }\r
676 }\r
677 \r
678 /**\r
679  * Represents the inheritdoc inline tag, used by classes/methods/vars to inherit\r
680  * documentation from the parent class if possible\r
681  * @tutorial tags.inlineinheritdoc.pkg\r
682  * @package phpDocumentor\r
683  * @subpackage InlineTags\r
684  */\r
685 class parserInheritdocInlineTag extends parserInlineTag\r
686 {\r
687     /**\r
688      * always 'inheritdoc'\r
689      * @var string\r
690      */\r
691     var $inlinetype = 'inheritdoc';\r
692     \r
693     /**\r
694      * Does nothing, overrides parent constructor\r
695      */\r
696     function parserInheritdocInlineTag()\r
697     {\r
698     }\r
699     \r
700     function Convert()\r
701     {\r
702         addWarning(PDERROR_INHERITDOC_DONT_WORK_HERE);\r
703         return '';\r
704     }\r
705 }\r
706 \r
707 /**\r
708  * Represents the inline {@}id} tag for tutorials\r
709  * @tutorial tags.inlineid.pkg\r
710  * @package phpDocumentor\r
711  * @subpackage InlineTags\r
712  */\r
713 class parserIdInlineTag extends parserInlineTag\r
714 {\r
715     /**\r
716      * always 'id'\r
717      * @var string\r
718      */\r
719     var $inlinetype = 'id';\r
720     /**\r
721      * package of the {@}id}\r
722      * @var string\r
723      */\r
724     var $package = 'default';\r
725     /**\r
726      * category of the {@}id}\r
727      * @var string\r
728      */\r
729     var $category = 'default';\r
730     /**\r
731      * subpackage of the {@}id}\r
732      * @var string\r
733      */\r
734     var $subpackage = '';\r
735     /**\r
736      * full name of the tutorial\r
737      * @var string\r
738      */\r
739     var $tutorial;\r
740     /**\r
741      * section/subsection name\r
742      * @var string\r
743      */\r
744     var $id;\r
745     \r
746     /**\r
747      * @param string package name\r
748      * @param string subpackage name\r
749      * @param string tutorial name\r
750      * @param string section/subsection name\r
751      * @param string category name\r
752      */\r
753     function parserIdInlineTag($category,$package,$subpackage,$tutorial,$id = false)\r
754     {\r
755         $this->package = $package;\r
756         $this->subpackage = $subpackage;\r
757         $this->tutorial = $tutorial;\r
758         $this->id = $id;\r
759         $this->category = $category;\r
760     }\r
761     \r
762     /**\r
763      * @param Converter\r
764      * @uses Converter::getTutorialId() retrieve converter-specific ID\r
765      */\r
766     function Convert(&$c)\r
767     {\r
768         if (!$this->id) return '';\r
769         return $c->getTutorialId($this->package,$this->subpackage,$this->tutorial,$this->id,$this->category);\r
770     }\r
771 }\r
772 \r
773 /**\r
774  * Represents {@}toc} for table of contents generation in tutorials\r
775  * @tutorial tags.inlinetoc.pkg\r
776  * @package phpDocumentor\r
777  * @subpackage InlineTags\r
778  */\r
779 class parserTocInlineTag extends parserInlineTag\r
780 {\r
781     /**\r
782      * always 'toc'\r
783      * @var string\r
784      */\r
785     var $inlinetype = 'toc';\r
786     /**\r
787      * @var array format:\r
788      * <pre>\r
789      * array(array('tagname' => section,\r
790      *             'link' => returnsee link,\r
791      *             'id' => anchor name,\r
792      *             'title' => from title tag),...)\r
793      * </pre>\r
794      * @access private\r
795      */\r
796     var $_toc = false;\r
797     /**\r
798      * full path to tutorial, used in conversion\r
799      * @var string\r
800      * @access private\r
801      */\r
802     var $_path = false;\r
803 \r
804     function parserTocInlineTag()\r
805     {\r
806         parent::parserInlineTag('toc','');\r
807     }\r
808     \r
809     /**\r
810      * @param array format:\r
811      * <pre>\r
812      * array(array('tag' => {@link parserXMLDocBookTag},\r
813      *             'id' => {@link parserIdInlineTag},\r
814      *             'title' => {@link parserXMLDocBookTag title}),...)\r
815      * </pre>\r
816      */\r
817     function setTOC($toc)\r
818     {\r
819         $this->toc = $toc;\r
820     }\r
821     \r
822     /**\r
823      * @param string\r
824      */\r
825     function setPath($path)\r
826     {\r
827         $this->_path = $path;\r
828     }\r
829     \r
830     /**\r
831      * @uses Converter::formatTutorialTOC() passes an array of format:\r
832      *\r
833      * <pre>\r
834      * array(\r
835      *    'tagname' => string name of tag,\r
836      *    'link' => {@link tutorialLink} to the tutorial,\r
837      *    'id' => converter specific tutorial ID from {@link Converter::getTutorialId()}\r
838      *    'title' => title of the tutorial)\r
839      * </pre>\r
840      *\r
841      * and returns the results as the table of contents\r
842      * @uses Converter::getTutorialId() retrieve the tutorial ID for\r
843      * @param Converter\r
844      */\r
845     function Convert(&$c)\r
846     {\r
847         $newtoc = array();\r
848         if (isset($this->toc) && is_array($this->toc)) {\r
849             foreach($this->toc as $i => $toc)\r
850             {\r
851                 if (isset($toc['title']))\r
852                 $toc['tag']->setTitle($toc['title']);\r
853                 else\r
854                 $toc['tag']->setTitle(new parserStringWithInlineTags);\r
855                 $newtoc[$i]['tagname'] = $toc['tag']->name;\r
856                 $l = new tutorialLink;\r
857                 if (!isset($toc['title'])) $title = 'section '.$toc['id']->id;\r
858                 else\r
859                 $title = $toc['title']->Convert($c);\r
860                 $l->addLink($toc['id']->id,$this->_path,basename($this->_path),$toc['id']->package, $toc['id']->subpackage, strip_tags($title));\r
861                 $newtoc[$i]['link'] = $c->returnSee($l);\r
862                 $newtoc[$i]['id'] = $c->getTutorialId($toc['id']->package, $toc['id']->subpackage, basename($this->_path), $toc['id']->id, $toc['id']->category);\r
863                 $newtoc[$i]['title'] = $title;\r
864             }\r
865         }\r
866         return $c->formatTutorialTOC($newtoc);\r
867     }\r
868 }\r
869 ?>\r