Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_blogpdf
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24267/serendipity_event_blogpdf
Added Files:
fpdf.php serendipity_event_blogpdf.php
Log Message:
blog -> pdf plugin
--- NEW FILE: fpdf.php ---
<?php
/*******************************************************************************
* Software: FPDF *
* Version: 1.52 *
* Date: 2003-12-30 *
* Author: Olivier PLATHEY *
* License: Freeware *
* *
* You may use, modify and redistribute this software as you wish. *
*******************************************************************************/
if(!class_exists('FPDF'))
{
define('FPDF_VERSION','1.52');
class FPDF
{
//Private properties
var $page; //current page number
[...1579 lines suppressed...]
function _out($s)
{
//Add a line to the document
if($this->state==2)
$this->pages[$this->page].=$s."\n";
else
$this->buffer.=$s."\n";
}
//End of class
}
//Handle special IE contype request
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype')
{
Header('Content-Type: application/pdf');
exit;
}
}
?>
--- NEW FILE: serendipity_event_blogpdf.php ---
<?php # $Id: serendipity_event_blogpdf.php,v 1.1 2004/07/09 09:37:03 garvinhicking Exp $
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_EVENT_BLOGPDF_NAME', 'Blog als PDF exportieren');
@define('PLUGIN_EVENT_BLOGPDF_DESC', 'Exportiert alle Einträge des Blogs in eine PDF-Datei');
@define('PLUGIN_EVENT_BLOGPDF_DOWNLOAD', 'Download des Blogs als plaintext-PDF!');
@define('PLUGIN_EVENT_BLOGPDF_PAGE', 'Seite');
@define('PLUGIN_EVENT_BLOGPDF_EXPORT', 'Blog Export');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_EVENT_BLOGPDF_NAME', 'Export blog as PDF');
@define('PLUGIN_EVENT_BLOGPDF_DESC', 'Exports your full blog as a PDF file');
@define('PLUGIN_EVENT_BLOGPDF_DOWNLOAD', 'Download this blog as plaintext-PDF!');
@define('PLUGIN_EVENT_BLOGPDF_PAGE', 'Page');
@define('PLUGIN_EVENT_BLOGPDF_EXPORT', 'Blog Export');
break;
}
define('FPDF_FONTPATH',$serendipity['serendipityPath'] . 'plugins/serendipity_event_blogpdf/font/');
require('fpdf.php');
class PDF extends FPDF {
function Header() {
global $serendipity;
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, PLUGIN_EVENT_BLOGPDF_EXPORT .' :' . $serendipity['blogTitle'] . ', ' . $serendipity['baseURL'], 1, 0, 'C');
$this->Ln(20);
}
function Footer() {
global $serendipity;
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, PLUGIN_EVENT_BLOGPDF_PAGE . ' ' . $this->PageNo() . ' / {nb}', 0, 0, 'C');
}
}
class serendipity_event_blogpdf extends serendipity_event
{
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_BLOGPDF_NAME);
$propbag->add('description', PLUGIN_EVENT_BLOGPDF_DESC);
$propbag->add('event_hooks', array(
'external_plugin' => true,
'entries_footer' => true
));
}
function generate_content(&$title) {
$title = PLUGIN_EVENT_BLOGPDF_NAME;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'entries_footer':
echo '<br /><a href="' . $serendipity['baseURL'] . 'plugin/blogpdf">' . PLUGIN_EVENT_BLOGPDF_DOWNLOAD . '</a>';
return true;
break;
case 'external_plugin':
if (stristr($eventData, 'blogpdf')) {
$feedcache = $serendipity['serendipityPath'] . 'archives/blog.pdf';
$cachetime = 60*60*24; // one day
$pdf = new PDF();
$pdf->AliasNbPages();
if (!file_exists($feedcache) || filesize($feedcache) == 0 || filemtime($feedcache) < (time() - $cachetime)) {
$this->print_entries(serendipity_fetchEntries(), $pdf);
$pdf->Close();
$fp = fopen($feedcache, 'wb');
fwrite($fp, $pdf->buffer);
fclose($fp);
} else {
$pdf->buffer = file_get_contents($feedcache);
$pdf->state = 3; // fake closed document to insert cached PDF
}
$pdf->Output();
}
return true;
break;
default:
return false;
break;
}
} else {
return false;
}
}
function print_entries($entries, &$pdf) {
$extended = true;
$preview = false;
$addData = array('extended' => $extended, 'preview' => $preview, 'no_scramble' => true);
serendipity_plugin_api::hook_event('entry_display', $entries, $addData);
/* pre-walk the array to collect them keyed by date */
$bydate = array();
if (!is_array($entries) || $entries[0] == false) {
return;
}
$lastDate = '';
for ($x = 0, $num_entries = count($entries); $x < $num_entries; $x++) {
$d = serendipity_formatTime(DATE_FORMAT_ENTRY, $entries[$x]['timestamp']);
$bydate[$d][] = $entries[$x];
}
foreach ($bydate as $date => $ents) {
$pdf->AddPage();
$pdf->SetFont('Courier','',12);
$pdf->Cell(0, 10, $date, 1);
$pdf->Ln();
$pdf->Ln();
foreach ($ents as $x => $entry) {
$entryLink = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', false);
serendipity_plugin_api::hook_event('frontend_display', $entry, array('no_scramble' => true));
$posted_by = ' ' . POSTED_BY . ' ' . htmlspecialchars($entry['username']);
if (is_array($entry['categories']) && sizeof($entry['categories']) > 0) {
$posted_by .= ' ' . IN . ' ';
$cats = array();
foreach ($entry['categories'] as $cat) {
$cats[] = $cat['category_name'];
}
$posted_by .= implode(', ', $cats);
}
$posted_by .= ' ' . AT . ' ' . date('H:i', $entry['timestamp']);
$pdf->SetFont('Arial', 'B', 11);
$pdf->Write(4, strip_tags($entry['title']) . "\n");
$pdf->Ln();
$pdf->SetFont('Arial', '', 10);
$pdf->Write(4, strip_tags($entry['body'] . $entry['extended']) . "\n");
$pdf->Ln();
$pdf->SetFont('Courier', '', 9);
$pdf->Write(4, strip_tags($posted_by) . "\n");
$pdf->Ln();
} // end for-loop (entries)
} // end for-loop (dates)
} // end function serendipity_printEntries
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|