From OrganicDesign Wiki
| Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.
|
|
| This code has been ported to a standard MediaWiki extension called Pdf Book
|
|
<?
# Exports current article as a PDF using [http://www.htmldoc.org HTMLDOC]
if (!$GLOBALS['xwAnonymous']) {
$htdocs = $_SERVER['DOCUMENT_ROOT'];
$titles = array($title);
$layout = '--webpage';
if (!xwGetProperty($properties,'pdf/left-margin',$left)) $left = '1cm';
if (!xwGetProperty($properties,'pdf/right-margin',$right)) $right = '1cm';
if (!xwGetProperty($properties,'pdf/top-margin',$top)) $top = '1cm';
if (!xwGetProperty($properties,'pdf/bottom-margin',$bottom)) $bottom = '5mm';
if (!xwGetProperty($properties,'pdf/font-name',$font)) $font = 'Arial';
if (!xwGetProperty($properties,'pdf/font-size',$size)) $size = '8';
if (!xwGetProperty($properties,'pdf/links',$links)) $links = '217A28';
if (!xwGetProperty($properties,'pdf/toc-levels',$levels)) $levels = '2';
if (xwGetProperty($properties,'pdf/exclude',$exclude)) $exclude = split('\\s*,\\s*',$exclude); else $exclude = array();
if (eregi('^category:(.+)$',$title,$m)) {
global $wgContLang;
$db =& wfGetDB(DB_MASTER);
$subdb =& wfGetDB(DB_SLAVE);
$cl = $db->tableName('categorylinks');
$cur = $db->tableName('cur');
$cat = str_replace(' ','_',$m[1]);
$result = $db->query("SELECT cl_from,cl_sortkey FROM $cl WHERE cl_to = '$cat' ORDER BY cl_sortkey");
while ($row = mysql_fetch_assoc($result)) {
$id = $row['cl_from'];
$subresult = $subdb->query("SELECT cur_title,cur_namespace FROM $cur WHERE cur_id=$id");
if ($subrow = mysql_fetch_assoc($subresult)) {
$t = str_replace('_',' ',$subrow['cur_title']);
if ($ns = $wgContLang->getNsText($subrow['cur_namespace'])) $t = "$ns:$t";
$titles[] = $t;
}
}
$layout = '--firstpage toc';
}
# Parse each title and append to a file
$content = '';
foreach ($titles as $t) if (!in_array($t,$exclude)) {
$text = preg_replace('/((href|src)=[\'"]?)\\//','$1http://'.$_SERVER['HTTP_HOST'].'/',xwXmlWikiParse($t));
for ($i = 9; $i > 0; $i--) $text = preg_replace("/(<\\/?)h$i( *>)/i",'$1h'.($i+1).'$2',$text); # start at h2
$text = preg_replace('/<div class="editsection".+?<\\/div>/','',$text); # remove edit links
$t = ereg_replace('^Zenovia/Business Plan/','',$t); # Zenovia hack
$content .= "<h1>$t</h1>$text\n"; # add page title
}
$file = "$htdocs/wiki/tmp/".uniqid('pdf');
$fh = fopen($file,'w+');
fwrite($fh,$content);
fclose($fh);
ob_end_clean();
putenv("HTMLDOC_NOCGI=1");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"$title.pdf\"");
flush();
passthru("htmldoc -t pdf --left $left --right $right --top $top --bottom $bottom --header ... --footer .1. --headfootsize 8
--quiet --jpeg --color --bodyfont $font --fontsize $size --linkstyle plain
--linkcolor $links --toclevels $levels --format pdf14 --numbered $layout $file"
);
@unlink($file);
global $xwUserName;
$title = preg_replace('/^(?=Category:)/i',':',$title);
xwLog("[[$title]] exported as PDF by [[$xwUserName]]");
die;
} else xwMessage("Sorry, you must be logged in to export PDF's!",'red');
?>