1: <?php
 2:  3:  4:  5:  6:  7:  8:  9: 10: 
11: class Jonah_View_StoryPdf extends Jonah_View
12: {
13:     public function run()
14:     {
15:         extract($this->_params, EXTR_REFS);
16: 
17:         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
18:         if (!$story_id) {
19:             try {
20:                 $story_id = $GLOBALS['injector']->getInstance('Jonah_Driver')->getLatestStoryId($channel_id);
21:             } catch (Exception $e) {
22:                 $this->_exit($e->getMessage());
23:             }
24:         }
25:         try {
26:             $story = $driver->getStory($channel_id, $story_id, !$browser->isRobot());
27:         } catch (Exception $e) {
28:             $this->_exit($e->getMessage());
29:         }
30: 
31:         
32:         if (!empty($story['body_type']) && $story['body_type'] == 'richtext') {
33:             $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'html2text');
34:         }
35: 
36:         
37:         $pdf = new Horde_Pdf_Writer(array('format' => 'Letter', 'unit' => 'pt'));
38:         $pdf->setMargins(50, 50);
39: 
40:         
41:         $pdf->setAutoPageBreak(true, 50);
42: 
43:         
44:         $pdf->open();
45: 
46:         
47:         $pdf->addPage();
48: 
49:         
50:         if (!empty($story['published_date'])) {
51:             $pdf->setFont('Times', 'B', 14);
52:             $pdf->cell(0, 14, $story['published_date'], 0, 1);
53:             $pdf->newLine(10);
54:         }
55: 
56:         
57:         $pdf->setFont('Times', 'B', 24);
58:         $pdf->multiCell(0, 24, $story['title'], 'B', 1);
59:         $pdf->newLine(20);
60: 
61:         
62:         $pdf->setFont('Times', '', 14);
63:         $pdf->write(14, $story['body']);
64: 
65:         
66:         $browser->downloadHeaders($story['title'] . '.pdf', 'application/pdf');
67:         echo $pdf->getOutput();
68:     }
69: 
70: }