Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Outputs documentation in PDF format
4
 *
5
 * phpDocumentor :: automatic documentation generator
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * Copyright (c) 2002-2006 Gregory Beaver
10
 *
11
 * LICENSE:
12
 *
13
 * This library is free software; you can redistribute it
14
 * and/or modify it under the terms of the GNU Lesser General
15
 * Public License as published by the Free Software Foundation;
16
 * either version 2.1 of the License, or (at your option) any
17
 * later version.
18
 *
19
 * This library is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
 * Lesser General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public
25
 * License along with this library; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
 *
28
 * @package    Converters
29
 * @subpackage PDFdefault
30
 * @author     Greg Beaver <cellog@php.net>
31
 * @copyright  2002-2006 Gregory Beaver
32
 * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
33
 * @version    CVS: $Id: PDFdefaultConverter.inc 236747 2007-05-31 02:02:42Z ashnazg $
34
 * @filesource
35
 * @link       http://www.phpdoc.org
36
 * @link       http://pear.php.net/PhpDocumentor
37
 * @since      1.2
38
 */
39
/**
40
 * The Cezpdf class library
41
 */
42
include_once('phpDocumentor/Converters/PDF/default/class.phpdocpdf.php');
43
/**
44
 * PDF output converter.
45
 * This Converter takes output from the {@link Parser} and converts it to PDF-ready output for use with {@link Cezpdf}.
46
 * This is now beta code
47
 *
48
 * @package Converters
49
 * @subpackage PDFdefault
50
 * @author Greg Beaver <cellog@php.net>
51
 * @since 1.1
52
 * @version $Id: PDFdefaultConverter.inc 236747 2007-05-31 02:02:42Z ashnazg $
53
 * @todo Implement links to conflicts/inheritance
54
 */
55
class PDFdefaultConverter extends Converter
56
{
57
    /**
58
     * default PDF Converter wants elements sorted by type as well as alphabetically
59
     * @see Converter::$sort_page_contents_by_type
60
     * @var boolean
61
     */
62
    var $sort_absolutely_everything = true;
63
    var $leftindex = array('classes' => false, 'pages' => false, 'functions' => false, 'defines' => false, 'globals' => false);
64
    var $pagepackage_pagenums = array();
65
    var $classpackage_pagenums = array();
66
    /** @var string always PDF */
67
    var $outputformat = 'PDF';
68
    /** @var string always default */
69
    var $name = 'default';
70
    var $curpagepackage = false;
71
    var $curclasspackage = false;
72
    var $smarty_dir;
73
    /**
74
     * @var Cezpdf
75
     */
76
    var $pdf = false;
77
    var $ric_set = array();
78
    /**
79
     * Source files for appendix C are stored here
80
     *
81
     * Format: array(array(package => packagename, code => array(highlightedsource code 1, ...)))
82
     * @var array
83
     */
84
    var $_sourcecode;
85
    /**
86
     * @see Converter::Converter()
87
     */
88
    function PDFdefaultConverter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $templateDir, $title)
89
    {
90
        Converter::Converter($allp, $packp, $classes, $procpages, $po, $pp, $qm, $targetDir, $templateDir, $title);
91
        $this->pdf =& new phpdocpdf($this, $this->getConverterDir() . PATH_DELIMITER .'templates/fonts/','letter');
92
        $this->pdf->selectFont($this->getConverterDir() . PATH_DELIMITER .'templates/fonts/Helvetica.afm');
93
// put a line top and bottom on all the pages
94
        $this->pdf->ezSetMargins(50,70,50,50);
95
        $template = &$this->newSmarty();
96
        $this->pdf->ezText($template->fetch('footer.tpl'));
97
        $template->assign('title',$title);
98
        if (file_exists($this->templateDir . 'templates' . PATH_DELIMITER . 'media'. PATH_DELIMITER .'logo.jpg'))
99
        {
100
            $template->assign('logo',$this->templateDir . 'templates' . PATH_DELIMITER . 'media'. PATH_DELIMITER .'logo.jpg');
101
        }
102
        $this->pdf->ezText($template->fetch('title_page.tpl'));
103
        unset($template);
104
    }
105
 
106
    function writeSource($path, $value)
107
    {
108
        $templ = &$this->newSmarty();
109
        $pathinfo = $this->proceduralpages->getPathInfo($path, $this);
110
        $templ->assign('source',$value);
111
        $templ->assign('package',$pathinfo['package']);
112
        $templ->assign('subpackage',$pathinfo['subpackage']);
113
        $templ->assign('name',$pathinfo['name']);
114
        $templ->assign('source_loc',$pathinfo['source_loc']);
115
        $templ->assign('docs',$pathinfo['docs']);
116
        $templ->assign('dest', $this->getFileSourceName($path));
117
        $this->setSourcePaths($path);
118
        $this->_sourcecode[$pathinfo['package']][] = $templ->fetch('filesource.tpl');
119
    }
120
 
121
    function postProcess($text)
122
    {
123
        return htmlspecialchars($text);
124
    }
125
 
126
    function writeExample($title, $path, $source)
127
    {
128
        $templ = &$this->newSmarty();
129
        $templ->assign('source',$source);
130
        if (empty($title))
131
        {
132
            $title = 'example';
133
            addWarning(PDERROR_EMPTY_EXAMPLE_TITLE, $path, $title);
134
        }
135
        $templ->assign('title',$title);
136
        $templ->assign('file',$path);
137
        $this->pdf->ezText($templ->fetch('examplesource.tpl'));
138
    }
139
 
140
    function getExampleLink($path, $title)
141
    {
142
        return '';
143
        return $this->returnLink('{$subdir}__examplesource' . PATH_DELIMITER . 'exsource_'.$path.'.html',$title);
144
    }
145
 
146
    function getSourceLink($path)
147
    {
148
//        var_dump(htmlentities('<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>'));
149
        return '<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>';
150
    }
151
 
152
    function getFileSourceName($path, $anchor = '')
153
    {
154
        return urlencode($anchor . parent::getFileSourceName($path));
155
    }
156
 
157
    /**
158
     * Retrieve a Converter-specific anchor to a segment of a source code file
159
     * parsed via a {@tutorial tags.filesource.pkg} tag.
160
     * @param string full path to source file
161
     * @param string name of anchor
162
     * @param string link text, if this is a link
163
     * @param boolean returns either a link or a destination based on this
164
     *                parameter
165
     * @return string link to an anchor, or the anchor
166
     */
167
    function getSourceAnchor($sourcefile,$anchor,$text = '',$link = false)
168
    {
169
        if ($link)
170
        {
171
            return '<c:ilink:' . $this->getFileSourceName($sourcefile, $anchor). '>' . $text . '</c:ilink>';
172
        } else
173
        {
174
            return '</text><pdffunction:addDestination arg="'.$this->getFileSourceName($sourcefile, $anchor).'" arg="FitH" arg=$this->y /><text size="8">';
175
        }
176
    }
177
 
178
    /**
179
     * Returns a bookmark using Cezpdf 009
180
     *
181
     * @param abstractLink a descendant of abstractlink should be passed, and never text
182
     * @param string text to display in the link
183
     */
184
    function returnSee(&$element, $eltext = false)
185
    {
186
        if (!$element) return false;
187
        if (!$eltext)
188
        {
189
            $eltext = '';
190
            switch($element->type)
191
            {
192
                case 'tutorial' :
193
                $eltext = $element->title;
194
                break;
195
                case 'method' :
196
                case 'var' :
197
                case 'const' :
198
                $eltext .= $element->class.'::';
199
                case 'page' :
200
                case 'define' :
201
                case 'class' :
202
                case 'function' :
203
                case 'global' :
204
                default :
205
                $eltext .= $element->name;
206
                if ($element->type == 'function' || $element->type == 'method') $eltext .= '()';
207
                break;
208
            }
209
        }
210
        switch ($element->type)
211
        {
212
            case 'tutorial' :
213
            return '<c:ilink:'.urlencode($element->type.$element->package.$element->subpackage.$element->name.$element->section).'>'.$eltext.'</c:ilink>';
214
            case 'page' :
215
            return '<c:ilink:'.urlencode($element->type.$element->package.$element->path).'>'.$eltext.'</c:ilink>';
216
            case 'define' :
217
            case 'global' :
218
            case 'class' :
219
            case 'function' :
220
            return '<c:ilink:'.urlencode($element->type.$element->package.$element->name).'>'.$eltext.'</c:ilink>';
221
            case 'method' :
222
            case 'var' :
223
            case 'const' :
224
            return '<c:ilink:'.urlencode($element->type.$element->package.$element->class.'::'.$element->name).'>'.$eltext.'</c:ilink>';
225
        }
226
        return $element;
227
    }
228
 
229
    /**
230
     * @param string
231
     * @param string
232
     * @return string <c:alink:$link>$text</c:alink>
233
     */
234
    function returnLink($link,$text)
235
    {
236
        return "<c:alink:$link>$text</c:alink>";
237
    }
238
 
239
    /**
240
     * Convert README/INSTALL/CHANGELOG file contents to output format
241
     * @param README|INSTALL|CHANGELOG
242
     * @param string contents of the file
243
     */
244
    function Convert_RIC($name, $contents)
245
    {
246
        $this->ric_set[$name] = $contents;
247
    }
248
 
249
    function convertDocBlock(&$element)
250
    {
251
        if (!$element->docblock) return;
252
        $template = &$this->newSmarty();
253
 
254
        $nopackage = true;
255
        if ($element->type == 'page' || $element->type == 'class') $nopackage = false;
256
        $tagses = $element->docblock->listTags();
257
        $tags = array();
258
        $names = array('staticvar' => 'Static Variable','deprec' => 'Deprecated','abstract' => 'Abstract Element','todo' => 'TODO');
259
        if (!$nopackage)
260
        {
261
            $tags[] = array('keyword' => 'Package','data' => $element->docblock->package);
262
            if (!empty($element->docblock->subpackage)) $tags[] = array('keyword' => 'Sub-Package','data' => $element->docblock->subpackage);
263
        }
264
        if ($element->docblock->var)
265
        {
266
            $a = $element->docblock->var->Convert($this);
267
            if (!empty($a))
268
            $tags[] = array('keyword' => 'Var', 'data' => $a);
269
        }
270
        if ($element->docblock->funcglobals)
271
        foreach($element->docblock->funcglobals as $global => $val)
272
        {
273
            if ($a = $this->getGlobalLink($global,$element->docblock->package))
274
            {
275
                $global = $a;
276
            }
277
            $b = Converter::getLink($val[0]);
278
            if (is_object($b) && phpDocumentor_get_class($b) == 'classlink')
279
            {
280
                $val[0] = $this->returnSee($b);
281
            }
282
            $tags[] = array('keyword' => 'Global Variable Used','data' => $val[0].' '.$global.': '.$val[1]->Convert($this));
283
        }
284
        if ($element->docblock->statics)
285
        foreach($element->docblock->statics as $static => $val)
286
        {
287
            $a = $val->Convert($this);
288
            $tags[] = array('keyword' => 'Static Variable Used','data' => $val->converted_returnType.' '.$static.': '.$a);
289
        }
290
        if ($element->docblock->properties)
291
        foreach($element->docblock->properties as $property => $val)
292
        {
293
            $a = $val->Convert($this);
294
            $tags[] = array('keyword' => ucfirst($val->keyword),'data' => $val->converted_returnType.' '.$property.': '.$a);
295
        }
296
        foreach($tagses as $tag)
297
        {
298
            if (isset($names[$tag->keyword])) $tag->keyword = $names[$tag->keyword];
299
            $tags[] = array("keyword" => ucfirst($tag->keyword),"data" => $tag->Convert($this));
300
        }
301
        $utags = array();
302
        foreach($element->docblock->unknown_tags as $keyword => $t)
303
        {
304
            foreach($t as $tag)
305
            $utags[] = array('keyword' => $keyword, 'data' => $tag->Convert($this));
306
        }
307
        if ($element->type == 'packagepage') return;
308
        $sdesc = $element->docblock->getSDesc($this);
309
        $desc = $element->docblock->getDesc($this);
310
        $template->assign('utags',$utags);
311
        $template->assign('tags',$tags);
312
        $template->assign('sdesc',$sdesc);
313
        $template->assign('desc',$desc);
314
        if (false) // $element->type != 'page')
315
        {
316
            if ($element->type != 'var' && $element->type != 'method')
317
            {
318
                $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->name),'FitH',$this->pdf->y);
319
            } else
320
            {
321
                $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name),'FitH',$this->pdf->y);
322
            }
323
        } elseif (false)
324
        {
325
            $this->pdf->addDestination(urlencode('page'.$element->parent->package.$element->parent->getPath()),'FitH',$this->pdf->y);
326
        }
327
        $this->convertParams($element);
328
        $this->pdf->ezText($template->fetch('docblock.tpl'));
329
    }
330
 
331
    function convertParams(&$element)
332
    {
333
        if ($element->type != 'function' && $element->type != 'method') return;
334
        if (count($element->docblock->params))
335
        {
336
            $template = &$this->newSmarty();
337
            $params = array();
338
            if (count($element->docblock->params))
339
            foreach($element->docblock->params as $param => $val)
340
            {
341
                $a = $val->Convert($this);
342
                $params[] = array("name" => $param,"type" => $val->converted_returnType,"description" => $a);
343
            }
344
            $template->assign('params',$params);
345
            $this->pdf->ezText($template->fetch('params.tpl'));
346
        }
347
    }
348
 
349
    function convertGlobal(&$element)
350
    {
351
        $sdesc = '';
352
        if ($element->docblock->sdesc)
353
        {
354
            $sdesc = $element->docblock->sdesc->Convert($this);
355
        }
356
        $template = &$this->newSmarty();
357
        $template->assign('linenumber',$element->getLineNumber());
358
        if ($this->hasSourceCode($element->getPath()))
359
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
360
        else
361
        $template->assign('slink', false);
362
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
363
        $template->assign('type',$element->getDataType($this));
364
        $template->assign('name',$element->name);
365
        $template->assign('value',$this->getGlobalValue($element->getValue()));
366
        $template->assign('sdesc',$sdesc);
367
        $this->pdf->ezText($template->fetch('global.tpl'));
368
        $this->convertDocBlock($element);
369
    }
370
 
371
    function getGlobalValue($value)
372
    {
373
        return parent::getGlobalValue(htmlspecialchars($value));
374
    }
375
 
376
    function convertMethod(&$element)
377
    {
378
        $sdesc = '';
379
        if ($element->docblock->sdesc)
380
        {
381
            $sdesc = $element->docblock->sdesc->Convert($this);
382
        }
383
        $params = array();
384
        if (count($element->docblock->params))
385
        foreach($element->docblock->params as $param => $val)
386
        {
387
            $a = $val->Convert($this);
388
            $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
389
        }
390
        if ($element->docblock->return)
391
        {
392
            if (!$element->docblock->return->returnType) $element->docblock->return->returnType = 'void';
393
        }
394
        $template = &$this->newSmarty();
395
        $template->assign('class',$this->class);
396
        $template->assign('constructor',$element->isConstructor);
397
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
398
        $template->assign('linenumber',$element->getLineNumber());
399
        if ($this->hasSourceCode($element->getPath()))
400
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
401
        else
402
        $template->assign('slink',false);
403
        $ret = 'void';
404
        if ($element->docblock->return)
405
        {
406
            $ret = $element->docblock->return->returnType;
407
        }
408
        $template->assign('return',$ret);
409
        $template->assign('functioncall',$element->getFunctionCall());
410
        $template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
411
        $template->assign('sdesc',$sdesc);
412
        $this->pdf->ezText($template->fetch('method.tpl'));
413
        $this->convertDocBlock($element);
414
    }
415
 
416
    function convertVar(&$element)
417
    {
418
        $sdesc = '';
419
        if ($element->docblock->sdesc)
420
        {
421
            $sdesc = $element->docblock->sdesc->Convert($this);
422
        }
423
        $template = &$this->newSmarty();
424
        $template->assign('class',$this->class);
425
        $template->assign('linenumber',$element->getLineNumber());
426
        if ($this->hasSourceCode($element->getPath()))
427
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
428
        else
429
        $template->assign('slink',false);
430
        $template->assign('type',$element->docblock->var->returnType);
431
        $template->assign('name',$element->name);
432
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
433
        $template->assign('value',$element->value);
434
        $template->assign('sdesc',$sdesc);
435
        $this->pdf->ezText($template->fetch('var.tpl'));
436
        $this->convertDocBlock($element);
437
    }
438
 
439
    function convertConst(&$element)
440
    {
441
        $sdesc = '';
442
        if ($element->docblock->sdesc)
443
        {
444
            $sdesc = $element->docblock->sdesc->Convert($this);
445
        }
446
        $template = &$this->newSmarty();
447
        $template->assign('class',$this->class);
448
        $template->assign('linenumber',$element->getLineNumber());
449
        if ($this->hasSourceCode($element->getPath()))
450
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
451
        else
452
        $template->assign('slink',false);
453
        $template->assign('name',$element->name);
454
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
455
        $template->assign('value',$element->value);
456
        $template->assign('sdesc',$sdesc);
457
        $this->pdf->ezText($template->fetch('const.tpl'));
458
        $this->convertDocBlock($element);
459
    }
460
 
461
    function convertClass(&$element)
462
    {
463
        $template = &$this->newSmarty();
464
        if ($this->curclasspackage != $element->docblock->package)
465
        {
466
            $template->assign('includeheader',true);
467
            if (isset($this->package_pages[$element->docblock->package]))
468
            {
469
                $template->assign('ppage',$this->package_pages[$element->docblock->package]);
470
                $template->assign('isclass',true);
471
                unset($this->package_pages[$element->docblock->package]);
472
            }
473
            $template->assign('classeslink',rawurlencode("Package ".$element->docblock->package." Classes"));
474
        }
475
        $sdesc = '';
476
        if ($element->docblock->sdesc)
477
        {
478
            $sdesc = $element->docblock->sdesc->Convert($this);
479
        }
480
        $this->curclasspackage = $element->docblock->package;
481
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
482
        $template->assign('package',$element->docblock->package);
483
        $template->assign('linenumber',$element->getLineNumber());
484
        if ($this->hasSourceCode($element->getPath()))
485
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
486
        else
487
        $template->assign('slink',false);
488
        $template->assign('name',$element->name);
489
        $template->assign('sdesc',$sdesc);
490
        $this->pdf->ezText($template->fetch('class.tpl'));
491
        $this->convertDocBlock($element);
492
    }
493
 
494
    function convertInclude(&$element)
495
    {
496
        $template = &$this->newSmarty();
497
        $template->assign('linenumber',$element->getLineNumber());
498
        if ($this->hasSourceCode($element->getPath()))
499
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
500
        else
501
        $template->assign('slink',false);
502
        $template->assign('name',$element->name);
503
        $template->assign('value',$this->getIncludeValue($element->getValue(), $element->getPath()));
504
        $this->pdf->ezText($template->fetch('include.tpl'));
505
        $this->convertDocBlock($element);
506
    }
507
 
508
    function convertFunction(&$element)
509
    {
510
        $sdesc = '';
511
        if ($element->docblock->sdesc)
512
        {
513
            $sdesc = $element->docblock->sdesc->Convert($this);
514
        }
515
        $params = array();
516
        if (count($element->docblock->params))
517
        foreach($element->docblock->params as $param => $val)
518
        {
519
            $a = $val->Convert($this);
520
            $params[$param] = array("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
521
        }
522
        if (!$element->docblock->return)
523
        {
524
            $element->docblock->return->returnType = 'void';
525
        }
526
        $template = &$this->newSmarty();
527
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
528
        $template->assign('linenumber',$element->getLineNumber());
529
        if ($this->hasSourceCode($element->getPath()))
530
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
531
        else
532
        $template->assign('slink',false);
533
        $template->assign('return',$element->docblock->return->returnType);
534
        $template->assign('functioncall',$element->getFunctionCall());
535
        $template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
536
        $template->assign('sdesc',$sdesc);
537
        $this->pdf->ezText($template->fetch('function.tpl'));
538
        $this->convertDocBlock($element);
539
    }
540
 
541
    function convertDefine(&$element)
542
    {
543
        $sdesc = '';
544
        if ($element->docblock->sdesc)
545
        {
546
            $sdesc = $element->docblock->sdesc->Convert($this);
547
        }
548
        $template = &$this->newSmarty();
549
        $template->assign('linenumber',$element->getLineNumber());
550
        if ($this->hasSourceCode($element->getPath()))
551
        $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
552
        else
553
        $template->assign('slink',false);
554
        $template->assign('name',$element->name);
555
        $template->assign('dest', urlencode($element->type.$element->docblock->package.$element->name));
556
        $template->assign('value',$element->value);
557
        $template->assign('sdesc',$sdesc);
558
        $this->pdf->ezText($template->fetch('define.tpl'));
559
        $this->convertDocBlock($element);
560
    }
561
 
562
    function convertPage(&$element)
563
    {
564
        $template = &$this->newSmarty();
565
        $template->assign('includeheader',false);
566
        $sdesc = '';
567
        if ($element->docblock->sdesc)
568
        {
569
            $sdesc = $element->docblock->sdesc->Convert($this);
570
        }
571
        if (count($element->elements) || ($sdesc) || count($element->docblock->tags))
572
        {
573
            if ($this->curpagepackage != $element->parent->package)
574
            {
575
                $template->assign('includeheader',true);
576
                if (isset($this->package_pages[$element->parent->package]))
577
                {
578
                    $template->assign('ppage',$this->package_pages[$element->parent->package]);
579
                    unset($this->package_pages[$element->parent->package]);
580
                }
581
            }
582
            $this->curpagepackage = $element->parent->package;
583
            $template->assign('dest', urlencode('page'.$element->parent->package.$element->parent->getPath()));
584
            $template->assign('sdesc',$sdesc);
585
            $template->assign('package',$element->parent->package);
586
            $template->assign('name',$element->parent->file);
587
            $this->pdf->ezText($template->fetch('page.tpl'));
588
            $this->convertDocBlock($element);
589
        }
590
    }
591
 
592
 
593
    /**
594
     * Used to translate an XML DocBook tag from a tutorial by reading the
595
     * options.ini file for the template.
596
     * @param string tag name
597
     * @param string any attributes Format: array(name => value)
598
     * @param string the tag contents, if any
599
     * @param string the tag contents, if any, unpost-processed
600
     * @return string
601
     */
602
    function TranslateTag($name,$attr,$cdata,$unconvertedcdata)
603
    {
604
        if ($name == 'example' && @$attr['role'] == 'html')
605
        {
606
            $cdata = htmlspecialchars($cdata);
607
            $unconvertedcdata = htmlspecialchars($unconvertedcdata);
608
        }
609
        if ($name == 'programlisting' && @$attr['role'] == 'php')
610
        {
611
            $unconvertedcdata = strtr($unconvertedcdata, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
612
            $a = parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
613
//            var_dump(htmlspecialchars($cdata), htmlspecialchars($unconvertedcdata), htmlspecialchars($a));
614
            return $a;
615
        }
616
        return parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
617
    }
618
 
619
    function getPageName(&$element)
620
    {
621
        if (phpDocumentor_get_class($element) == 'parserpage') return $element->getName();
622
        return $element->parent->getName();
623
    }
624
 
625
    function getTutorialId($package,$subpackage,$tutorial,$id)
626
    {
627
        return 'tutorial'.$package.$subpackage.$tutorial.$id;
628
    }
629
 
630
    function getCData($value)
631
    {
632
        return str_replace(array('<c:','<C:'),array("&lt;c:","&lt;C:"),$value);
633
    }
634
 
635
    /**
636
     * @deprecated html package pages just don't work with PDF, use {@tutorial tutorials.pkg}
637
     */
638
    function convertPackagepage(&$element)
639
    {
640
        $x = $element->Convert($this);
641
        $x = substr($x,strpos($x,'<body'));
642
        $this->package_pages[$element->package] = trim(substr($x,strpos($x,'>') + 1,strpos($x,'</body>') - 6));
643
    }
644
 
645
    function convertTutorial(&$element)
646
    {
647
        $x = $element->Convert($this, true);
648
        $template = &$this->newSmarty();
649
        $template->assign('package',$element->package);
650
        $template->assign('subpackage',$element->subpackage);
651
        $template->assign('contents',$x);
652
        $template->assign('title',$element->getTitle($this));
653
        $template->assign('child',$element->parent);
654
        if (isset($element->parent->parent)) $template->assign('hasparent',$element->parent->parent);
655
        $template->assign('element',$element);
656
        $this->pdf->ezText($template->fetch('tutorial.tpl'));
657
    }
658
 
659
    /**
660
     * returns a template-enabled array of class trees
661
     *
662
     * @param    string    $package    package to generate a class tree for
663
     * @see $roots, getRootTree()
664
     */
665
    function generateFormattedClassTrees($package)
666
    {
667
        if (!isset($this->roots[$package])) return array();
668
        $roots = $trees = array();
669
        $roots = $this->roots[$package];
670
        for($i=0;$i<count($roots);$i++)
671
        {
672
            $trees[] = array('class' => $roots[$i],'class_tree' => "<ul>\n".$this->getRootTree($this->getSortedClassTreeFromClass($roots[$i],$package,''),$package)."</ul>\n");
673
        }
674
        return $trees;
675
    }
676
 
677
    /**
678
     * return formatted class tree for the Class Trees page
679
     *
680
     * @param array $tree output from {@link getSortedClassTreeFromClass()}
681
     * @see Classes::$definitechild, generateFormattedClassTrees()
682
     * @return string
683
     */
684
    function getRootTree($tree,$package)
685
    {
686
        if (!$tree) return '';
687
        $my_tree = '';
688
        $cur = '#root';
689
        $lastcur = array(false);
690
        $kids = array();
691
        $dopar = false;
692
        if ($tree[$cur]['parent'])
693
        {
694
            $dopar = true;
695
            if (!is_object($tree[$cur]['parent']))
696
            {
697
//                debug("parent ".$tree[$cur]['parent']." not found");
698
                $my_tree .= '<li>' . $tree[$cur]['parent'] .'<ul>';
699
            }
700
            else
701
            {
702
//                        debug("parent ".$this->returnSee($tree[$cur]['parent'], false, false)." in other package");
703
                $my_tree .= '<li>' . $this->returnSee($tree[$cur]['parent'], false, false);
704
                if ($tree[$cur]['parent']->package != $package) $my_tree .= ' <b>(Different package)</b><ul>';
705
            }
706
        }
707
        do
708
        {
709
//            fancy_debug($cur,$lastcur,$kids);
710
            if (count($tree[$cur]['children']))
711
            {
712
//                debug("$cur has children");
713
                if (!isset($kids[$cur]))
714
                {
715
//                    debug("set $cur kids");
716
                    $kids[$cur] = 1;
717
                    $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
718
                    $my_tree .= '<ul>'."\n";
719
                }
720
                array_push($lastcur,$cur);
721
                list(,$cur) = each($tree[$cur]['children']);
722
//                var_dump('listed',$cur);
723
                if ($cur)
724
                {
725
                    $cur = $cur['package'] . '#' . $cur['class'];
726
//                    debug("set cur to child $cur");
727
//                    $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
728
                    continue;
729
                } else
730
                {
731
//                    debug("end of children for $cur");
732
                    $cur = array_pop($lastcur);
733
                    $cur = array_pop($lastcur);
734
                    $my_tree .= '</ul></li>'."\n";
735
                    if ($dopar && ($cur == '#root' || !$cur)) $my_tree .= '</ul></li>';
736
                }
737
            } else
738
            {
739
//                debug("$cur has no children");
740
                $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false)."</li>";
741
                if ($dopar && $cur == '#root') $my_tree .= '</ul></li>';
742
                $cur = array_pop($lastcur);
743
            }
744
        } while ($cur);
745
        return $my_tree;
746
    }
747
 
748
    /**
749
     * calls {@link Cezpdf::ezOutput()} and writes documentation.pdf to targetDir
750
     */
751
    function Output($title = 'Generated Documentation')
752
    {
753
        phpDocumentor_out("Generating PDF file..");
754
        flush();
755
        $template = &$this->newSmarty();
756
        $this->pdf->ezText($template->fetch('appendix_title_page.tpl'));
757
        $trees = array();
758
        foreach($this->all_packages as $package => $rest)
759
        {
760
            if (!isset($this->pkg_elements[$package])) continue;
761
            $a = array();
762
            phpDocumentor_out('.');
763
            flush();
764
            $a['package'] = $package;
765
            $a["trees"] = $this->generateFormattedClassTrees($package);
766
            $trees[] = $a;
767
        }
768
        $template->assign('trees',$trees);
769
        $this->pdf->ezText($template->fetch('classtree.tpl'));
770
        phpDocumentor_out('.');
771
        if (count($this->ric_set))
772
        $this->pdf->ezText($template->fetch('ric_title_page.tpl'));
773
        foreach($this->ric_set as $name => $contents)
774
        {
775
            $template->assign('contents',$contents);
776
            $template->assign('name',$name);
777
            $this->pdf->ezText($template->fetch('ric.tpl'));
778
        }
779
        if (count($this->_sourcecode))
780
        {
781
            $this->pdf->ezText($template->fetch('source_title_page.tpl'));
782
            $template->assign('source',$this->_sourcecode);
783
            $this->pdf->ezText($template->fetch('source_loop.tpl'));
784
        }
785
        flush();
786
        if (count($this->todoList))
787
        {
788
            $todolist = array();
789
            foreach($this->todoList as $package => $alltodos)
790
            {
791
                foreach($alltodos as $todos)
792
                {
793
                    $converted = array();
794
                    $converted['link'] = $this->returnSee($todos[0]);
795
                    if (!is_array($todos[1]))
796
                    {
797
                        $converted['todos'][] = $todos[1]->Convert($this);
798
                    } else
799
                    {
800
                        foreach($todos[1] as $todo)
801
                        {
802
                            $converted['todos'][] = $todo->Convert($this);
803
                        }
804
                    }
805
                    $todolist[$package][] = $converted;
806
                }
807
            }
808
            $template->assign('todos',$todolist);
809
 
810
            $this->pdf->ezText($template->fetch('todolist.tpl'));
811
        }
812
        if (false) {
813
        $fp = @fopen("C:/Documents and Settings/Owner/Desktop/pdfsourceorig.txt",'w');
814
        if ($fp)
815
        {
816
            $a = $this->pdf->ezOutput(true); // debug
817
            fwrite($fp, $a, strlen($a));
818
            fclose($fp);
819
        }
820
        }
821
        $this->pdf->setupTOC();
822
        $template->assign('contents',$this->pdf->reportContents);
823
        $this->pdf->ezText($template->fetch('toc.tpl'));
824
        $x = $this->pdf->ezOutput(false, $template);
825
        phpDocumentor_out("done\n");
826
        flush();
827
        $this->writeFile("documentation.pdf", $x, true);
828
    }
829
 
830
    function mystrnatcasecmp($a,$b)
831
    {
832
        return strnatcasecmp($a[0],$b[0]);
833
    }
834
 
835
 
836
    /**
837
     * @param string name of class
838
     * @param string package name
839
     * @param string full path to look in (used in index generation)
840
     * @return mixed false if not found, or an html a link to the class's documentation
841
     * @see parent::getClassLink()
842
     */
843
    function getClassLink($expr,$package, $file = false,$text = false)
844
    {
845
        $a = Converter::getClassLink($expr,$package,$file);
846
        if (!$a) return false;
847
        return $this->returnSee($a, $text);
848
    }
849
 
850
    /**
851
     * @param string name of function
852
     * @param string package name
853
     * @param string full path to look in (used in index generation)
854
     * @param boolean deprecated
855
     * @return mixed false if not found, or an html a link to the function's documentation
856
     * @see parent::getFunctionLink()
857
     */
858
    function getFunctionLink($expr,$package, $file = false,$text = false)
859
    {
860
        $a = Converter::getFunctionLink($expr,$package,$file);
861
        if (!$a) return false;
862
        return $this->returnSee($a, $text);
863
    }
864
 
865
    /**
866
     * @param string name of define
867
     * @param string package name
868
     * @param string full path to look in (used in index generation)
869
     * @param boolean deprecated
870
     * @return mixed false if not found, or an html a link to the define's documentation
871
     * @see parent::getDefineLink()
872
     */
873
    function getDefineLink($expr,$package, $file = false,$text = false)
874
    {
875
        $a = Converter::getDefineLink($expr,$package,$file);
876
        if (!$a) return false;
877
        return $this->returnSee($a, $text);
878
    }
879
 
880
    /**
881
     * @param string name of global variable
882
     * @param string package name
883
     * @param string full path to look in (used in index generation)
884
     * @param boolean deprecated
885
     * @return mixed false if not found, or an html a link to the global variable's documentation
886
     * @see parent::getGlobalLink()
887
     */
888
    function getGlobalLink($expr,$package, $file = false,$text = false)
889
    {
890
        $a = Converter::getGlobalLink($expr,$package,$file);
891
        if (!$a) return false;
892
        return $this->returnSee($a, $text);
893
    }
894
 
895
    /**
896
     * @param string name of procedural page
897
     * @param string package name
898
     * @param string full path to look in (used in index generation)
899
     * @param boolean deprecated
900
     * @return mixed false if not found, or an html a link to the procedural page's documentation
901
     * @see parent::getPageLink()
902
     */
903
    function getPageLink($expr,$package, $path = false,$text = false)
904
    {
905
        $a = Converter::getPageLink($expr,$package,$path);
906
        if (!$a) return false;
907
        return $this->returnSee($a, $text);
908
    }
909
 
910
    /**
911
     * @param string name of method
912
     * @param string class containing method
913
     * @param string package name
914
     * @param string full path to look in (used in index generation)
915
     * @param boolean deprecated
916
     * @return mixed false if not found, or an html a link to the method's documentation
917
     * @see parent::getMethodLink()
918
     */
919
    function getMethodLink($expr,$class,$package, $file = false,$text = false)
920
    {
921
        $a = Converter::getMethodLink($expr,$class,$package,$file);
922
        if (!$a) return false;
923
        return $this->returnSee($a, $text);
924
    }
925
 
926
    /**
927
     * @param string name of var
928
     * @param string class containing var
929
     * @param string package name
930
     * @param string full path to look in (used in index generation)
931
     * @param boolean deprecated
932
     * @param boolean return just the URL, or enclose it in an html a tag
933
     * @return mixed false if not found, or an html a link to the var's documentation
934
     * @see parent::getVarLink()
935
     */
936
    function getVarLink($expr,$class,$package, $file = false,$text = false)
937
    {
938
        $a = Converter::getVarLink($expr,$class,$package,$file);
939
        if (!$a) return false;
940
        return $this->returnSee($a, $text);
941
    }
942
 
943
    /**
944
     * @param string name of class constant
945
     * @param string class containing class constant
946
     * @param string package name
947
     * @param string full path to look in (used in index generation)
948
     * @param boolean deprecated
949
     * @param boolean return just the URL, or enclose it in an html a tag
950
     * @return mixed false if not found, or an html a link to the var's documentation
951
     * @see parent::getConstLink()
952
     */
953
    function getConstLink($expr,$class,$package, $file = false,$text = false)
954
    {
955
        $a = Converter::getConstLink($expr,$class,$package,$file);
956
        if (!$a) return false;
957
        return $this->returnSee($a, $text);
958
    }
959
 
960
    function setTemplateDir($dir)
961
    {
962
        Converter::setTemplateDir($dir);
963
        $this->smarty_dir = $this->templateDir;
964
    }
965
 
966
    /** @return 1 always the same */
967
    function getState()
968
    {
969
        return 1;
970
    }
971
 
972
    /**
973
     * @see parent::unmangle()
974
     */
975
    function unmangle($notused,$source)
976
    {
977
//        $source = str_replace("\n","<mybr>",$source);
978
        return $source;
979
    }
980
}
981
?>