changed git call from https to git readonly
[atutor.git] / mods / pdf_converter / pdf_converter.php
1 <?php\r
2 require('fpdf.php');\r
3 include( 'class.ezpdf.php' );\r
4 define('AT_INCLUDE_PATH', '../../include/');\r
5 require (AT_INCLUDE_PATH.'vitals.inc.php');\r
6 \r
7 if(isset($_GET['cid'])){\r
8         $sql    = "SELECT * FROM ".TABLE_PREFIX."content WHERE content_id=$_GET[cid]";\r
9         $result = mysql_query($sql);\r
10         if(mysql_num_rows($result)!=0){\r
11                 $content_row = mysql_fetch_assoc($result);\r
12                 //$titulo = strip_tags($content_row['title']);\r
13                 $titulo = $content_row['title'];\r
14                 //$contenido = strip_tags($content_row['text']);\r
15                 $contenido = $content_row['text'];\r
16 /*\r
17                 ///JOOMLA\r
18                 //$params = new mosParameters( $row->attribs );\r
19                 //$params->def( 'author',       !$mainframe->getCfg( 'hideAuthor' ) );\r
20                 //$params->def( 'createdate', !$mainframe->getCfg( 'hideCreateDate' ) );\r
21                 //$params->def( 'modifydate', !$mainframe->getCfg( 'hideModifyDate' ) );\r
22 \r
23                 $titulo         = strip_tags(pdfCleaner( $titulo ));\r
24                 $contenido      = trim(strip_tags(pdfCleaner( $contenido )));\r
25 \r
26 \r
27                 $pdf = new Cezpdf( 'a4', 'P' );  //A4 Portrait\r
28                 $pdf -> ezSetCmMargins( 2, 1.5, 1, 1);\r
29                 $pdf->selectFont( './fonts/Helvetica.afm' ); //choose font\r
30 \r
31                 $all = $pdf->openObject();\r
32                 $pdf->saveState();\r
33                 $pdf->setStrokeColor( 0, 0, 0, 1 );\r
34 \r
35                 // footer\r
36                 //$pdf->addText( 250, 822, 6, $mosConfig_sitename );\r
37                 $pdf->line( 10, 40, 578, 40 );\r
38                 $pdf->line( 10, 818, 578, 818 );\r
39                 //$pdf->addText( 30, 34, 6, $mosConfig_live_site );\r
40                 //$pdf->addText( 250, 34, 6, _PDF_POWERED );\r
41                 //$pdf->addText( 450, 34, 6, _PDF_GENERATED .' '. date( 'j F, Y, H:i', time() + $mosConfig_offset * 60 * 60 ) );\r
42 \r
43                 $pdf->restoreState();\r
44                 $pdf->closeObject();\r
45                 $pdf->addObject( $all, 'all' );\r
46                 $pdf->ezSetDy( 30 );\r
47 \r
48                 $txt1 = $titulo;\r
49                 $pdf->ezText( $txt1, 14 );\r
50 \r
51                 //$txt2 = AuthorDateLine( $row, $params );\r
52                 $txt2 = $contenido;\r
53 \r
54                 $pdf->ezText( $txt2, 8 );\r
55 \r
56                 //$txt3 = $row->introtext ."\n". $row->fulltext;\r
57                 //$pdf->ezText( $txt3, 10 );\r
58 \r
59                 $pdf->ezStream();\r
60 \r
61                 //FIN JOOMLA\r
62 */\r
63                 $titulo         = strip_tags(pdfCleaner( $titulo ));\r
64                 $contenido      = trim(strip_tags(pdfCleaner( $contenido )));\r
65                 //$contenido    = str_word_count($contenido,1);\r
66                 //$contenido    = implode(" ",$contenido);\r
67 \r
68                 //Leemos el fichero\r
69                 $muestra_pdf = 'muestra_pdf.txt';\r
70         $f=fopen($muestra_pdf,'w');\r
71         fwrite($f,$contenido);\r
72         fclose($f);\r
73         $f=fopen($muestra_pdf,'r+');\r
74                 $pdf=new FPDF();\r
75                 $pdf->AddPage();\r
76                 $pdf->SetFont('Arial','',10);\r
77                 fclose($f);\r
78                 //$pdf->Cell(0,5,$titulo);\r
79                 //$pdf->Ln(10);\r
80                 $pdf->MultiCell(0,3,$contenido);\r
81                 $pdf->Output();\r
82         }\r
83         else{\r
84                 echo(_AT('error'));\r
85 \r
86         }\r
87 }\r
88 \r
89 function decodeHTML( $string ) {\r
90         $string = strtr( $string, array_flip(get_html_translation_table( HTML_ENTITIES ) ) );\r
91         $string = preg_replace( "/&#([0-9]+);/me", "chr('\\1')", $string );\r
92 \r
93         return $string;\r
94 }\r
95 \r
96 \r
97 function pdfCleaner( $text ) {\r
98         // Ugly but needed to get rid of all the stuff the PDF class cant handle\r
99 \r
100         $text = str_replace( '<p>',                     "\n\n",         $text );\r
101         $text = str_replace( '<P>',                     "\n\n",         $text );\r
102         $text = str_replace( '<br />',                  "\n",           $text );\r
103         $text = str_replace( '<br>',                    "\n",           $text );\r
104         $text = str_replace( '<BR />',                  "\n",           $text );\r
105         $text = str_replace( '<BR>',                    "\n",           $text );\r
106         $text = str_replace( '<li>',                    "\n - ",        $text );\r
107         $text = str_replace( '<LI>',                    "\n - ",        $text );\r
108         $text = str_replace( '{mosimage}',              '',             $text );\r
109         $text = str_replace( '{mospagebreak}',  '',                     $text );\r
110         $text = str_replace( '<table>','',$text );\r
111         $text = str_replace( '<TABLE>','',$text );\r
112         $text = str_replace( '</table>','',$text );\r
113         $text = str_replace( '</TABLE>','',$text );\r
114         $text = str_replace( '<tr>','',$text );\r
115         $text = str_replace( '</tr>','',$text );\r
116         $text = str_replace( '<TR>','',$text );\r
117         $text = str_replace( '</TR>','',$text );\r
118         $text = str_replace( '&nbsp;','',$text );\r
119 \r
120 \r
121 \r
122         $text = strip_tags( $text );\r
123         $text = decodeHTML( $text );\r
124 \r
125         return $text;\r
126 }\r
127 ?>