Skip to content

Commit

Permalink
Merge pull request #272 from katgirl/feature-globaltitle
Browse files Browse the repository at this point in the history
Make global title
  • Loading branch information
splitbrain authored Jun 13, 2017
2 parents 806282d + 0335276 commit 335efac
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class action_plugin_dw2pdf extends DokuWiki_Action_Plugin {
*/
protected $exportConfig = null;
protected $tpl;
protected $title;
protected $list = array();

/**
* Constructor. Sets the correct template
*
* @param string $title
*/
public function __construct() {
$this->tpl = $this->getExportConfig('template');
public function __construct($title=null) {
$this->tpl = $this->getExportConfig('template');
$this->title = $title ? $title : '';
}

/**
Expand Down Expand Up @@ -60,7 +64,7 @@ public function convert(Doku_Event $event) {
if(auth_quickaclcheck($ID) < AUTH_READ) return false;

if($data = $this->collectExportPages($event)) {
list($title, $this->list) = $data;
list($this->title, $this->list) = $data;
} else {
return false;
}
Expand All @@ -70,18 +74,18 @@ public function convert(Doku_Event $event) {

// prepare cache and its dependencies
$depends = array();
$cache = $this->prepareCache($title, $depends);
$cache = $this->prepareCache($depends);

// hard work only when no cache available or needed for debugging
if(!$this->getConf('usecache') || $this->getExportConfig('isDebug') || !$cache->useCache($depends)) {
// generating the pdf may take a long time for larger wikis / namespaces with many pages
set_time_limit(0);

$this->generatePDF($cache->cache, $title);
$this->generatePDF($cache->cache);
}

// deliver the file
$this->sendPDFFile($cache->cache, $title);
$this->sendPDFFile($cache->cache);
return true;
}

Expand All @@ -103,15 +107,15 @@ protected function collectExportPages(Doku_Event $event) {

if($ACT == 'export_pdf') {
$list[0] = $ID;
$title = $INPUT->str('pdftitle'); //DEPRECATED
$title = $INPUT->str('book_title', $title, true);
if(empty($title)) {
$title = p_get_first_heading($ID);
$this->title = $INPUT->str('pdftitle'); //DEPRECATED
$this->title = $INPUT->str('book_title', $this->title, true);
if(empty($this->title)) {
$this->title = p_get_first_heading($ID);
}

} elseif($ACT == 'export_pdfns') {
//check input for title and ns
if(!$title = $INPUT->str('book_title')) {
if(!$this->title = $INPUT->str('book_title')) {
$this->showPageWithErrorMsg($event, 'needtitle');
return false;
}
Expand Down Expand Up @@ -164,9 +168,9 @@ protected function collectExportPages(Doku_Event $event) {
} elseif(isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) {
/** @deprecated April 2016 replaced by localStorage version of Bookcreator*/
//is in Bookmanager of bookcreator plugin a title given?
$title = $INPUT->str('pdfbook_title'); //DEPRECATED
$title = $INPUT->str('book_title', $title, true);
if(empty($title)) {
$this->title = $INPUT->str('pdfbook_title'); //DEPRECATED
$this->title = $INPUT->str('book_title', $this->title, true);
if(empty($this->title)) {
$this->showPageWithErrorMsg($event, 'needtitle');
return false;
} else {
Expand All @@ -189,9 +193,9 @@ protected function collectExportPages(Doku_Event $event) {
exit();
}

$title = $INPUT->str('pdfbook_title'); //DEPRECATED
$title = $INPUT->str('book_title', $title, true);
if(empty($title)) {
$this->title = $INPUT->str('pdfbook_title'); //DEPRECATED
$this->title = $INPUT->str('book_title', $this->title, true);
if(empty($this->title)) {
http_status(400);
print $this->getLang('needtitle');
exit();
Expand Down Expand Up @@ -228,17 +232,16 @@ protected function collectExportPages(Doku_Event $event) {

}

return array($title, $list);
return array($this->title, $list);
}

/**
* Prepare cache
*
* @param string $title
* @param array $depends (reference) array with dependencies
* @return cache
*/
protected function prepareCache($title, &$depends) {
protected function prepareCache(&$depends) {
global $REV;

$cachekey = join(',', $this->list)
Expand All @@ -249,7 +252,7 @@ protected function prepareCache($title, &$depends) {
. $this->getExportConfig('font-size')
. $this->getExportConfig('doublesided')
. ($this->getExportConfig('hasToC') ? join('-', $this->getExportConfig('levels')) : '0')
. $title;
. $this->title;
$cache = new cache($cachekey, '.dw2.pdf');

$dependencies = array();
Expand Down Expand Up @@ -312,9 +315,8 @@ private function showPageWithErrorMsg(Doku_Event $event, $msglangkey, $replaceme
* Build a pdf from the html
*
* @param string $cachefile
* @param string $title
*/
protected function generatePDF($cachefile, $title) {
protected function generatePDF($cachefile) {
global $ID;
global $REV;
global $INPUT;
Expand All @@ -340,7 +342,7 @@ protected function generatePDF($cachefile, $title) {
$mpdf->setBasePath($url);

// Set the title
$mpdf->SetTitle($title);
$mpdf->SetTitle($this->title);

// some default document settings
//note: double-sided document, starts at an odd page (first page is a right-hand side page)
Expand All @@ -357,7 +359,7 @@ protected function generatePDF($cachefile, $title) {
}

// load the template
$template = $this->load_template($title);
$template = $this->load_template();

// prepare HTML header styles
$html = '';
Expand Down Expand Up @@ -470,15 +472,14 @@ protected function generatePDF($cachefile, $title) {

/**
* @param string $cachefile
* @param string $title
*/
protected function sendPDFFile($cachefile, $title) {
protected function sendPDFFile($cachefile) {
header('Content-Type: application/pdf');
header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
header('Pragma: public');
http_conditionalRequest(filemtime($cachefile));

$filename = rawurlencode(cleanID(strtr($title, ':/;"', ' ')));
$filename = rawurlencode(cleanID(strtr($this->title, ':/;"', ' ')));
if($this->getConf('output') == 'file') {
header('Content-Disposition: attachment; filename="' . $filename . '.pdf";');
} else {
Expand All @@ -504,10 +505,9 @@ protected function sendPDFFile($cachefile, $title) {
/**
* Load the various template files and prepare the HTML/CSS for insertion
*
* @param string $title
* @return array
*/
protected function load_template($title) {
protected function load_template() {
global $ID;
global $conf;

Expand Down Expand Up @@ -548,7 +548,7 @@ protected function load_template($title) {
$replace = array(
'@PAGE@' => '{PAGENO}',
'@PAGES@' => '{nbpg}', //see also $mpdf->pagenumSuffix = ' / '
'@TITLE@' => hsc($title),
'@TITLE@' => hsc($this->title),
'@WIKI@' => $conf['title'],
'@WIKIURL@' => DOKU_URL,
'@DATE@' => dformat(time()),
Expand Down

0 comments on commit 335efac

Please sign in to comment.