function p_file_xhtml($id, $excuse = false) { if (@file_exists($id)) { return p_cached_output($id, 'xhtml', $id); } return p_wiki_xhtml($id, '', $excuse); }
function test_staleness() { global $ID; $ID = 'stale'; $file = wikiFN($ID); # Prepare test page saveWikiText($ID, 'Fresh', 'Created'); # Create stale cache $cache = new cache_renderer($ID, $file, 'xhtml'); $cache->storeCache('Stale'); $stale = $cache->retrieveCache(); # Prepare stale cache for testing $time = filemtime($file); touch($cache->cache, $time); # Make the test $fresh = p_cached_output($file, 'xhtml', $ID); $this->assertNotEquals($fresh, $stale, 'Stale cache failed to expire'); }
function _exportPostcontent($exporter) { global $ID, $INFO, $REV, $conf; $exporter->setParameters('Article: ' . $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), $this->_getDokuUrl(), $this->_getDokuUrl() . 'doku.php?', 'utf-8', $this->agentlink); // create user object // $id, $uri, $name, $email, $homepage='', $foaf_uri='', $role=false, $nick='', $sioc_url='', $foaf_url='' $dwuserpage_id = cleanID($this->getConf('userns')) . ($conf['useslash'] ? '/' : ':') . $INFO['editor']; /* if ($INFO['editor'] && $this->getConf('userns')) $pageuser = new SIOCUser($INFO['editor'], normalizeUri(getAbsUrl(exportlink($dwuserpage_id, 'siocxml', array('type'=>'user'), false, '&'))), // user page $INFO['meta']['contributor'][$INFO['editor']], getDwUserInfo($dwuserpage_id,$this,'mail'), '', // no homepage is saved for dokuwiki user '#'.$INFO['editor'], // local uri false, // no roles right now '', // no nick name is saved for dokuwiki user normalizeUri($exporter->siocURL('user', $dwuserpage_id)) ); */ // create wiki page object $wikipage = new SIOCDokuWikiArticle($ID, normalizeUri($exporter->siocURL('post', $ID . ($REV ? $exporter->_urlseparator . 'rev' . $exporter->_urlequal . $REV : ''))), $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), rawWiki($ID, $REV)); /* encoded content */ $wikipage->addContentEncoded(p_cached_output(wikiFN($ID, $REV), 'xhtml')); /* created */ if (isset($INFO['meta']['date']['created'])) { $wikipage->addCreated(date('c', $INFO['meta']['date']['created'])); } /* or modified */ if (isset($INFO['meta']['date']['modified'])) { $wikipage->addModified(date('c', $INFO['meta']['date']['modified'])); } /* creator/modifier */ if ($INFO['editor'] && $this->getConf('userns')) { $wikipage->addCreator(array('foaf:maker' => '#' . $INFO['editor'], 'sioc:modifier' => $dwuserpage_id)); } /* is creator */ if (isset($INFO['meta']['date']['created'])) { $wikipage->isCreator(); } /* intern wiki links */ $wikipage->addLinks($INFO['meta']['relation']['references']); // contributors - only for last revision b/c of wrong meta data for older revisions if (!$REV && $this->getConf('userns') && isset($INFO['meta']['contributor'])) { $cont_temp = array(); $cont_ns = $this->getConf('userns') . ($conf['useslash'] ? '/' : ':'); foreach ($INFO['meta']['contributor'] as $cont_id => $cont_name) { $cont_temp[$cont_ns . $cont_id] = $cont_name; } $wikipage->addContributors($cont_temp); } // backlinks - only for last revision if (!$REV) { require_once DOKU_INC . 'inc/fulltext.php'; $backlinks = ft_backlinks($ID); if (count($backlinks) > 0) { $wikipage->addBacklinks($backlinks); } } // TODO: addLinksExtern /* previous and next revision */ $changelog = new PageChangeLog($ID); $pagerevs = $changelog->getRevisions(0, $conf['recent'] + 1); $prevrev = false; $nextrev = false; if (!$REV) { // latest revision, previous rev is on top in array $prevrev = 0; } else { // other revision $currentrev = array_search($REV, $pagerevs); if ($currentrev !== false) { $prevrev = $currentrev + 1; $nextrev = $currentrev - 1; } } if ($prevrev !== false && $prevrev > -1 && page_exists($ID, $pagerevs[$prevrev])) { /* previous revision*/ $wikipage->addVersionPrevious($pagerevs[$prevrev]); } if ($nextrev !== false && $nextrev > -1 && page_exists($ID, $pagerevs[$nextrev])) { /* next revision*/ $wikipage->addVersionNext($pagerevs[$nextrev]); } /* latest revision */ if ($REV) { $wikipage->addVersionLatest(); } // TODO: topics /* has_container */ if ($INFO['namespace']) { $wikipage->addContainer($INFO['namespace']); } /* has_space */ if ($this->getConf('owners')) { $wikipage->addSite($this->getConf('owners')); } // TODO: dc:contributor / has_modifier // TODO: attachment (e.g. pictures in that dwns) // add wiki page to exporter $exporter->addObject($wikipage); //if ($INFO['editor'] && $this->getConf('userns')) $exporter->addObject($pageuser); return $exporter; }
/** * Retrieve a language dependent file and pass to xhtml renderer for display * template equivalent of p_locale_xhtml() * * @param string $id id of language dependent wiki page * @return string parsed contents of the wiki page in xhtml format */ function tpl_locale_xhtml($id) { return p_cached_output(tpl_localeFN($id)); }
/** * Returns the specified local text in parsed format * * @author Andreas Gohr <*****@*****.**> */ function p_locale_xhtml($id) { //fetch parsed locale $html = p_cached_output(localeFN($id)); return $html; }
/** * Export a wiki page for various formats * * Triggers ACTION_EXPORT_POSTPROCESS * * Event data: * data['id'] -- page id * data['mode'] -- requested export mode * data['headers'] -- export headers * data['output'] -- export output * * @author Andreas Gohr <*****@*****.**> * @author Michael Klier <*****@*****.**> */ function act_export($act) { global $ID; global $REV; global $conf; global $lang; $pre = ''; $post = ''; $output = ''; $headers = array(); // search engines: never cache exported docs! (Google only currently) $headers['X-Robots-Tag'] = 'noindex'; $mode = substr($act, 7); switch ($mode) { case 'raw': $headers['Content-Type'] = 'text/plain; charset=utf-8'; $headers['Content-Disposition'] = 'attachment; filename=' . noNS($ID) . '.txt'; $output = rawWiki($ID, $REV); break; case 'xhtml': $pre .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' . DOKU_LF; $pre .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . DOKU_LF; $pre .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $conf['lang'] . '"' . DOKU_LF; $pre .= ' lang="' . $conf['lang'] . '" dir="' . $lang['direction'] . '">' . DOKU_LF; $pre .= '<head>' . DOKU_LF; $pre .= ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . DOKU_LF; $pre .= ' <title>' . $ID . '</title>' . DOKU_LF; // get metaheaders ob_start(); tpl_metaheaders(); $pre .= ob_get_clean(); $pre .= '</head>' . DOKU_LF; $pre .= '<body>' . DOKU_LF; $pre .= '<div class="dokuwiki export">' . DOKU_LF; // get toc $pre .= tpl_toc(true); $headers['Content-Type'] = 'text/html; charset=utf-8'; $output = p_wiki_xhtml($ID, $REV, false); $post .= '</div>' . DOKU_LF; $post .= '</body>' . DOKU_LF; $post .= '</html>' . DOKU_LF; break; case 'xhtmlbody': $headers['Content-Type'] = 'text/html; charset=utf-8'; $output = p_wiki_xhtml($ID, $REV, false); break; default: $output = p_cached_output(wikiFN($ID, $REV), $mode); $headers = p_get_metadata($ID, "format {$mode}"); break; } // prepare event data $data = array(); $data['id'] = $ID; $data['mode'] = $mode; $data['headers'] = $headers; $data['output'] =& $output; trigger_event('ACTION_EXPORT_POSTPROCESS', $data); if (!empty($data['output'])) { if (is_array($data['headers'])) { foreach ($data['headers'] as $key => $val) { header("{$key}: {$val}"); } } print $pre . $data['output'] . $post; exit; } return 'show'; }
/** * Get the sidebar html. Get cached sidebar if $cache param is true. * * @author Cameron Little <*****@*****.**> */ function bootstrap_tpl_get_sidebar($pageid, $cache) { global $TOC; $oldtoc = $TOC; $html = ''; $rev = ''; $file = wikiFN($pageid, $rev); if ($cache && !$rev) { if (@file_exists($file)) { $html = p_cached_output($file, 'xhtml', $pageid); } } else { if (@file_exists($file)) { $html = p_render('xhtml', p_get_instructions(io_readWikiPage($file, $pageid, $rev)), $info); //no caching on old revisions } } return $html; }
function render($mode, &$renderer, $data) { global $ID; global $conf; global $INFO; global $lang; list($type, $num, $order) = $data; if ($type == "book") { $renderer->info['cache'] = false; if ($mode == 'text' && (isset($_GET['do']) && $_GET['do'] == 'export_text')) { $mode = 'xhtml'; } if ($mode == 'xhtml') { // verifica che se l'utente può salvare/eliminare le selezioni $this->usercansave = auth_quickaclcheck($this->getConf('save_namespace') . ':*') >= AUTH_CREATE; // verifica che se l'utente può salvare/eliminare le selezioni if ($this->usercansave) { if (isset($_POST['task']) && $_POST['task'] == "save") { checkSecurityToken(); if (isset($_COOKIE['list-pagelist'])) { if (isset($_POST['bookcreator_title'])) { $list = explode("|", $_COOKIE['list-pagelist']); $content = "====== " . $_POST['bookcreator_title'] . " ======" . DOKU_LF; for ($n = 0; $n < count($list); $n++) { $page = $list[$n]; $content .= " * [[:{$page}]]" . DOKU_LF; } saveWikiText($this->getConf('save_namespace') . ":" . $_POST['bookcreator_title'], $content, "selection created"); msg($this->getLang('bookcreator_saved') . ": " . $this->getConf('save_namespace') . ":" . $_POST['bookcreator_title']); } else { msg($this->getLang('bookcreator_needtitle')); } } else { msg($this->getLang('bookcreator_empty')); } } elseif (isset($_POST['task']) && $_POST['task'] == "del") { saveWikiText($this->getConf('save_namespace') . ":" . $_POST['page'], '', "selection removed"); msg($this->getLang('bookcreator_deleted') . ": " . $this->getConf('save_namespace') . ":" . $_POST['page']); } } if (isset($_GET['do']) || isset($_GET['mddo'])) { if ($_GET['do'] == 'export_html' || $_GET['do'] == 'export_text') { if (isset($_COOKIE['list-pagelist'])) { $renderer->doc = ''; $list = explode("|", $_COOKIE['list-pagelist']); } $render_mode = 'xhtml'; $lf_subst = ''; if ($_GET['do'] == 'export_text') { $render_mode = 'text'; $lf_subst = '<br>'; } for ($n = 0; $n < count($list); $n++) { $page = $list[$n]; $renderer->doc .= str_replace(DOKU_LF, $lf_subst, p_cached_output(wikiFN($page), $render_mode)); //p_wiki_xhtml($page,$REV,false); } } } else { $renderer->info['cache'] = FALSE; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/core.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/events.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/css.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/coordinates.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/drag.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/dragsort.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/cookies.js"></script>'; $renderer->doc .= '<script language="JavaScript" type="text/javascript" src="' . DOKU_URL . 'lib/plugins/bookcreator/sorter/more.js"></script>'; if (isset($_COOKIE['bookcreator']) || isset($_POST['task']) && $_POST['task'] == "read") { $list = array(); $i = 0; // c'è una selezione salvata da recuperare if (isset($_POST['task']) && $_POST['task'] == "read") { checkSecurityToken(); $renderer->doc .= "\n <script type='text/javascript'><!--//--><![CDATA[//><!-- \n book_removeAllPages('bookcreator');\n //--><!]]></script>"; $select = rawWiki($this->getConf('save_namespace') . ":" . $_POST['page']); $lines = explode("\n", $select); $nr = count($lines); for ($n = 0; $n < $nr; $n++) { if (trim($lines[$n]) == '') { continue; } if ($n > 0 && substr($lines[$n], 0, 7) != " * [[:") { continue; } if ($n === 0) { $lines[$n] = str_replace("====== ", '', $lines[$n]); $lines[$n] = str_replace(" ======", '', $lines[$n]); $title = $lines[$i]; } else { $lines[$n] = str_replace(" * [[:", '', $lines[$n]); $lines[$n] = str_replace("]]", '', $lines[$n]); $list[$n] = $lines[$n]; $renderer->doc .= ' <script type="text/javascript"><!--//--><![CDATA[//><!-- book_changePage(\'bookcreator[' . $list[$n] . ']\', 1, new Date(\'July 21, 2099 00:00:00\'), \'/\'); //--><!]]></script>'; $i++; } } // oppure quella appena selezionata } elseif (isset($_COOKIE['bookcreator'])) { $fav = $_COOKIE['bookcreator']; //Se non ci sono pagine già inserite if ($fav == "" || count($fav) == 0) { $renderer->doc .= $this->getLang('bookcreator_empty'); return; } foreach ($fav as $page => $cpt) { list($cpt, $date) = explode(";", $cpt); if ($cpt < 1) { continue; } $i++; $list[$i] = $page; } } $renderer->doc .= "<table width='100%' border='0' ><tr>"; $renderer->doc .= "<td width='60%' valign='top'>"; // Pagine selezionate for ($n = 1; $n <= $i; $n++) { $page = $list[$n]; if ($n == 1) { $renderer->header($this->getLang('bookcreator_toprint'), 2, 0); $renderer->doc .= '<ul id="pagelist" class="boxes">'; } $lien = $this->createLink($page); $renderer->doc .= ' <li itemID="' . $page . '">'; $renderer->doc .= ' <a href="javascript:book_changePage(\'bookcreator[' . $page . ']\', 0, new Date(\'July 21, 2099 00:00:00\'), \'/\'); book_recharge();"><img src="' . DOKU_URL . 'lib/plugins/bookcreator/images/remove.png" title="' . $this->getLang('bookcreator_remove') . '" border="0" style="vertical-align:middle;" name="ctrl" /></a> '; $renderer->doc .= $lien; $renderer->doc .= '</li>'; if ($n == $i) { $renderer->doc .= '</ul>'; $renderer->doc .= "<br />"; } } // Pagine selezionate // Pagine escluse dal libro if (isset($fav)) { $i = 0; foreach ($fav as $page => $cpt) { list($cpt, $date) = explode(";", $cpt); if ($cpt == 0) { if (!$i) { $renderer->header($this->getLang('bookcreator_removed'), 2, 0); $renderer->listu_open(); } $lien = $this->createLink($page); $i++; $renderer->doc .= "<div id=\"ex__{$page}\">"; $renderer->listitem_open(1); $renderer->doc .= '<a href="javascript:book_changePage(\'bookcreator[' . $page . ']\', 1, new Date(\'July 21, 2099 00:00:00\'), \'/\'); book_recharge();"><img src="' . DOKU_URL . 'lib/plugins/bookcreator/images/include.png" title="' . $this->getLang('bookcreator_include') . '" border="0" style="vertical-align:middle;" name="ctrl" /></a> '; $renderer->doc .= $lien; $renderer->doc .= "</div>"; $renderer->listitem_close(); } } if ($i) { $renderer->listu_close(); } } // azzera selezione $renderer->doc .= "<div align='center'>"; $onclick = "javascript:if(confirm('" . $this->getLang('bookcreator_reserconfirm') . "')) {book_removeAllPages('bookcreator'); document.reset.submit();}"; $renderer->doc .= '<form name="reset" class="button" method="get" action="' . wl($ID) . '">'; $renderer->doc .= "<input type='button' value='" . $this->getLang('bookcreator_reset') . "' class='button' onclick=\"" . $onclick . "\">"; $renderer->doc .= "<input type='hidden' name='id' value='{$ID}'/>"; $renderer->doc .= formSecurityToken(false); $renderer->doc .= '</form>'; $renderer->doc .= '</div>'; // azzera selezione $renderer->doc .= "</td>"; $renderer->doc .= "<td width='40%' valign='top' >"; $renderer->doc .= "<div align='center'>"; //Esportazione PDF $renderer->doc .= '<form class="button" method="get" action="' . wl($ID) . '" accept-charset="' . $lang['encoding'] . '">'; $renderer->doc .= "<fieldset style=\"text-align:left;\"><legend><b>" . $this->getLang('bookcreator_export') . "</b></legend>"; $renderer->doc .= $this->getLang('bookcreator_title') . " "; $renderer->doc .= '<input type="text" class="edit" value="' . $title . '" name="pdfbook_title" size="40" />'; $renderer->doc .= '<select name="do" size="1">'; $renderer->doc .= '<option value="export_html" selected="selected">' . $this->getLang('bookcreator_exportprint') . '</option>'; if (file_exists(DOKU_PLUGIN . "text/renderer.php") && !plugin_isdisabled("text")) { $renderer->doc .= '<option value="export_text">' . $this->getLang('bookcreator_exporttext') . '</option>'; } if (file_exists(DOKU_PLUGIN . "dw2pdf/action.php") && !plugin_isdisabled("dw2pdf")) { $renderer->doc .= '<option value="export_pdfbook" selected="selected">' . $this->getLang('bookcreator_exportpdf') . '</option>'; } $renderer->doc .= '</select>'; $renderer->doc .= '<input type="submit" value="' . $this->getLang('bookcreator_create') . '" class="button"/> <input type="hidden" name="id" value="' . $ID . '" />'; $renderer->doc .= '</fieldset>'; $renderer->doc .= formSecurityToken(false); $renderer->doc .= '</form>'; //Esportazione PDF if ($this->usercansave) { //Salva selezione $renderer->doc .= '<form class="button" method="post" action="' . wl($ID) . '" accept-charset="' . $lang['encoding'] . '">'; $renderer->doc .= "<fieldset style=\"text-align:left;\"><legend><b>" . $this->getLang('bookcreator_saveselection') . "</b></legend>"; $renderer->doc .= '<input type="text" class="edit" value="' . $title . '" name="bookcreator_title" />'; $renderer->doc .= '<input type="submit" value="' . $this->getLang('bookcreator_save') . '" class="button"/>'; $renderer->doc .= '<input type="hidden" name="task" value="save" /> <input type="hidden" name="id" value="' . $ID . '" />'; $renderer->doc .= '</fieldset>'; $renderer->doc .= formSecurityToken(false); $renderer->doc .= '</form>'; //Salva selezione } $renderer->doc .= '</div>'; $renderer->doc .= "</tr></td>"; $renderer->doc .= "</table>"; } else { $renderer->doc .= $this->getLang('bookcreator_nocookies'); } // genera la lista delle selezioni salvate $result = $this->_getlist($order); if (sizeof($result) > 0) { $renderer->doc .= '<form class="button" id="bookcreator__selections__list" name="bookcreator__selections__list" method="post" action="' . wl($ID) . '">'; $renderer->doc .= "<fieldset style=\"text-align:left;\"><legend><b>" . $this->getLang('bookcreator_listselections') . "</b></legend>"; $this->_showlist($renderer, $result, true, true); $renderer->doc .= "<input type='hidden' name='task' value=''/>"; $renderer->doc .= "<input type='hidden' name='page' value=''/>"; $renderer->doc .= "<input type='hidden' name='id' value='{$ID}'/>"; $renderer->doc .= formSecurityToken(false); $renderer->doc .= '</fieldset>'; $renderer->doc .= '</form>'; } // genera la lista delle selezioni salvate } } return false; } else { if ($mode == 'xhtml') { // genera la lista delle selezioni salvate $result = $this->_getlist($order, $num); if (sizeof($result) > 0) { $renderer->doc .= '<form class="button" id="bookcreator__selections__list" name="bookcreator__selections__list" method="post" action="' . wl($this->getConf('book_page')) . '">'; $this->_showlist($renderer, $result); $renderer->doc .= "<input type='hidden' name='task' value=''/>"; $renderer->doc .= "<input type='hidden' name='page' value=''/>"; $renderer->doc .= "<input type='hidden' name='id' value='" . $this->getConf('book_page') . "'/>"; $renderer->doc .= formSecurityToken(false); $renderer->doc .= '</form>'; } // genera la lista delle selezioni salvate } return false; } }
/** * Do the HTML to PDF conversion work * * @param Doku_Event $event * @param array $param * @return bool */ public function convert(&$event, $param) { global $ACT; global $REV; global $ID; // our event? if ($ACT != 'export_pdfbook' && $ACT != 'export_pdf') { return false; } // check user's rights if (auth_quickaclcheck($ID) < AUTH_READ) { return false; } // one or multiple pages? $list = array(); if ($ACT == 'export_pdf') { $list[0] = $ID; $title = p_get_first_heading($ID); } elseif (isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) { //is in Bookmanager of bookcreator plugin title given if (!($title = $_GET['pdfbook_title'])) { //TODO when title is changed, the cached file contains the old title /** @var $bookcreator action_plugin_bookcreator */ $bookcreator = plugin_load('action', 'bookcreator'); msg($bookcreator->getLang('needtitle'), -1); $event->data = 'show'; $_SERVER['REQUEST_METHOD'] = 'POST'; //clears url return false; } $list = explode("|", $_COOKIE['list-pagelist']); } else { /** @var $bookcreator action_plugin_bookcreator */ $bookcreator = plugin_load('action', 'bookcreator'); msg($bookcreator->getLang('empty'), -1); $event->data = 'show'; $_SERVER['REQUEST_METHOD'] = 'POST'; //clears url return false; } // it's ours, no one else's $event->preventDefault(); // prepare cache $cache = new cache(join(',', $list) . $REV . $this->tpl, '.dw2.pdf'); $depends['files'] = array_map('wikiFN', $list); $depends['files'][] = __FILE__; $depends['files'][] = dirname(__FILE__) . '/renderer.php'; $depends['files'][] = dirname(__FILE__) . '/mpdf/mpdf.php'; $depends['files'] = array_merge($depends['files'], getConfigFiles('main')); // hard work only when no cache available if (!$this->getConf('usecache') || !$cache->useCache($depends)) { // initialize PDF library require_once dirname(__FILE__) . "/DokuPDF.class.php"; $mpdf = new DokuPDF(); // let mpdf fix local links $self = parse_url(DOKU_URL); $url = $self['scheme'] . '://' . $self['host']; if ($self['port']) { $url .= ':' . $self['port']; } $mpdf->setBasePath($url); // Set the title $mpdf->SetTitle($title); // some default settings $mpdf->mirrorMargins = 1; $mpdf->useOddEven = 1; $mpdf->setAutoTopMargin = 'stretch'; $mpdf->setAutoBottomMargin = 'stretch'; // load the template $template = $this->load_template($title); // prepare HTML header styles $html = '<html><head>'; $html .= '<style type="text/css">'; $html .= $this->load_css(); $html .= '@page { size:auto; ' . $template['page'] . '}'; $html .= '@page :first {' . $template['first'] . '}'; $html .= '</style>'; $html .= '</head><body>'; $html .= $template['html']; $html .= '<div class="dokuwiki">'; // loop over all pages $cnt = count($list); for ($n = 0; $n < $cnt; $n++) { $page = $list[$n]; $html .= p_cached_output(wikiFN($page, $REV), 'dw2pdf', $page); $html .= $this->page_depend_replacements($template['cite'], cleanID($page)); if ($n < $cnt - 1) { $html .= '<pagebreak />'; } } $html .= '</div>'; $mpdf->WriteHTML($html); // write to cache file $mpdf->Output($cache->cache, 'F'); } // deliver the file header('Content-Type: application/pdf'); header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0'); header('Pragma: public'); http_conditionalRequest(filemtime($cache->cache)); $filename = rawurlencode(cleanID(strtr($title, ':/;"', ' '))); if ($this->getConf('output') == 'file') { header('Content-Disposition: attachment; filename="' . $filename . '.pdf";'); } else { header('Content-Disposition: inline; filename="' . $filename . '.pdf";'); } if (http_sendfile($cache->cache)) { exit; } $fp = @fopen($cache->cache, "rb"); if ($fp) { http_rangeRequest($fp, filesize($cache->cache), 'application/pdf'); } else { header("HTTP/1.0 500 Internal Server Error"); print "Could not read file - bad permissions?"; } exit; }
private function sync($id) { global $ID; // save $ID $save_ID = $ID; $pages_path = DOKU_DATA . 'pages/' . implode('/', explode(':', $this->ID)) . '/'; $path = $pages_path . $id . '.txt'; $ID = $this->ID . ":" . $id; // clear cache $cache = new cache_renderer($ID, $path, 'metadata'); $cache->removeCache(); $cache = new cache_renderer($ID, $path, 'xhtml'); $cache->removeCache(); $cache = new cache_instructions($ID, $path); $cache->removeCache(); p_cached_output($path, 'metadata', $ID); // restore $ID $ID = $save_ID; }
/** * Build a ODT from the articles * * @param string $cachefile * @param string $title */ protected function generateODT($cachefile, $title) { global $ID; global $REV; global $INPUT; //some shortcuts to export settings // $hasToC = $this->getExportConfig('hasToC'); $levels = $this->getExportConfig('levels'); $isDebug = $this->getExportConfig('isDebug'); //etc etc // store original pageid $keep = $ID; // loop over all pages $cnt = count($this->list); for ($n = 0; $n < $cnt; $n++) { $page = $this->list[$n]; // set global pageid to the rendered page $ID = $page; $pagecontent = p_cached_output(wikiFN($page, $REV), 'odt', $page); if ($n < $cnt - 1) { // $pagecontent .= '<pagebreak />'; } // Store/Buffer page .. } //restore ID $ID = $keep; // insert the back page // $body_end = $template['back']; // $body_end .= '</div>'; // finish body html //.... //Return html for debugging if ($isDebug) { if ($INPUT->str('debughtml', 'text', true) == 'html') { echo $html; } else { header('Content-Type: text/plain; charset=utf-8'); echo $html; } exit; } // write to cache file //$cachefile = ...; }
<?php $text = plugin_load("renderer", "text"); // Try to render with text plugin first if (!@$_REQUEST["do"] && $text != null) { $id = $_SERVER["QUERY_STRING"]; $id = str_replace("/", ":", $id); $id = str_replace("id=", "", $id); $file = wikiFN($id); $str = p_cached_output($file, 'text'); $contentType = "text/plain"; if (isset($GLOBALS["contentType"])) { $contentType = $GLOBALS["contentType"]; } if (!headers_sent()) { header("Content-Type: {$contentType}"); } echo $str; } else { if (!@$_REQUEST["do"]) { ob_start(); tpl_content(false); $str = ob_get_contents(); ob_end_clean(); $str = trim(strip_tags($str)); $contentType = "text/plain"; if (isset($GLOBALS["contentType"])) { $contentType = $GLOBALS["contentType"]; } if (!headers_sent()) { header("Content-Type: {$contentType}");
/** * Build a pdf from the html * * @param string $cachefile * @param string $title */ protected function generatePDF($cachefile, $title) { global $ID; global $REV; global $INPUT; //some shortcuts to export settings $hasToC = $this->getExportConfig('hasToC'); $levels = $this->getExportConfig('levels'); $isDebug = $this->getExportConfig('isDebug'); // initialize PDF library require_once dirname(__FILE__) . "/DokuPDF.class.php"; $mpdf = new DokuPDF($this->getExportConfig('pagesize'), $this->getExportConfig('orientation')); // let mpdf fix local links $self = parse_url(DOKU_URL); $url = $self['scheme'] . '://' . $self['host']; if ($self['port']) { $url .= ':' . $self['port']; } $mpdf->setBasePath($url); // Set the title $mpdf->SetTitle($title); // some default document settings //note: double-sided document, starts at an odd page (first page is a right-hand side page) // single-side document has only odd pages $mpdf->mirrorMargins = $this->getExportConfig('doublesided'); $mpdf->setAutoTopMargin = 'stretch'; $mpdf->setAutoBottomMargin = 'stretch'; // $mpdf->pagenumSuffix = '/'; //prefix for {nbpg} if ($hasToC) { $mpdf->PageNumSubstitutions[] = array('from' => 1, 'reset' => 0, 'type' => 'i', 'suppress' => 'off'); //use italic pageno until ToC $mpdf->h2toc = $levels; } else { $mpdf->PageNumSubstitutions[] = array('from' => 1, 'reset' => 0, 'type' => '1', 'suppress' => 'off'); } // load the template $template = $this->load_template($title); // prepare HTML header styles $html = ''; if ($isDebug) { $html .= '<html><head>'; $html .= '<style type="text/css">'; } $styles = $this->load_css(); $styles .= '@page { size:auto; ' . $template['page'] . '}'; $styles .= '@page :first {' . $template['first'] . '}'; $styles .= '@page landscape-page { size:landscape }'; $styles .= 'div.dw2pdf-landscape { page:landscape-page }'; $styles .= '@page portrait-page { size:portrait }'; $styles .= 'div.dw2pdf-portrait { page:portrait-page }'; $mpdf->WriteHTML($styles, 1); if ($isDebug) { $html .= $styles; $html .= '</style>'; $html .= '</head><body>'; } $body_start = $template['html']; $body_start .= '<div class="dokuwiki">'; // insert the cover page $body_start .= $template['cover']; $mpdf->WriteHTML($body_start, 2, true, false); //start body html if ($isDebug) { $html .= $body_start; } if ($hasToC) { //Note: - for double-sided document the ToC is always on an even number of pages, so that the following content is on a correct odd/even page // - first page of ToC starts always at odd page (so eventually an additional blank page is included before) // - there is no page numbering at the pages of the ToC $mpdf->TOCpagebreakByArray(array('toc-preHTML' => '<h2>' . $this->getLang('tocheader') . '</h2>', 'toc-bookmarkText' => $this->getLang('tocheader'), 'links' => true, 'outdent' => '1em', 'resetpagenum' => true, 'pagenumstyle' => '1')); $html .= '<tocpagebreak>'; } // store original pageid $keep = $ID; // loop over all pages $cnt = count($this->list); for ($n = 0; $n < $cnt; $n++) { $page = $this->list[$n]; // set global pageid to the rendered page $ID = $page; $pagehtml = p_cached_output(wikiFN($page, $REV), 'dw2pdf', $page); $pagehtml .= $this->page_depend_replacements($template['cite'], $page); if ($n < $cnt - 1) { $pagehtml .= '<pagebreak />'; } $mpdf->WriteHTML($pagehtml, 2, false, false); //intermediate body html if ($isDebug) { $html .= $pagehtml; } } //restore ID $ID = $keep; // insert the back page $body_end = $template['back']; $body_end .= '</div>'; $mpdf->WriteHTML($body_end, 2, false, true); // finish body html if ($isDebug) { $html .= $body_end; $html .= '</body>'; $html .= '</html>'; } //Return html for debugging if ($isDebug) { if ($INPUT->str('debughtml', 'text', true) == 'html') { echo $html; } else { header('Content-Type: text/plain; charset=utf-8'); echo $html; } exit; } // write to cache file $mpdf->Output($cachefile, 'F'); }
/** * Handle export request for exporting the selection as pdf or text * * @param Doku_renderer_xhtml $renderer */ private function exportOnScreen(&$renderer) { global $ID; global $INPUT; $list = array(); if (isset($_COOKIE['list-pagelist'])) { $renderer->doc = ''; $list = explode("|", $_COOKIE['list-pagelist']); } $render_mode = 'xhtml'; $lf_subst = ''; if ($INPUT->get->str('do') == 'export_text') { $render_mode = 'text'; $lf_subst = '<br>'; } $keep = $ID; foreach ($list as $page) { $ID = $page; $renderer->doc .= str_replace(DOKU_LF, $lf_subst, p_cached_output(wikiFN($page), $render_mode, $page)); //p_wiki_xhtml($page,$REV,false); } $ID = $keep; }
/** * locale_xhtml($id) * * retrieve a language dependent wiki page and pass to xhtml renderer for display * plugin equivalent of p_locale_xhtml() * * @param $id id of language dependent wiki page * @return string parsed contents of the wiki page in xhtml format */ function locale_xhtml($id) { return p_cached_output($this->localFN($id)); }
/** * Handle 'edit', 'preview' * * @author Andreas Gohr <*****@*****.**> */ function act_export($act) { global $ID; global $REV; // search engines: never cache exported docs! (Google only currently) header('X-Robots-Tag: noindex'); // no renderer for this if ($act == 'export_raw') { header('Content-Type: text/plain; charset=utf-8'); print rawWiki($ID, $REV); exit; } // html export #FIXME what about the template's style? if ($act == 'export_xhtml') { global $conf; global $lang; header('Content-Type: text/html; charset=utf-8'); ptln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'); ptln(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); ptln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . $conf['lang'] . '"'); ptln(' lang="' . $conf['lang'] . '" dir="' . $lang['direction'] . '">'); ptln('<head>'); ptln(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'); ptln(' <title>' . $ID . '</title>'); tpl_metaheaders(); ptln('</head>'); ptln('<body>'); ptln('<div class="dokuwiki export">'); $html = p_wiki_xhtml($ID, $REV, false); tpl_toc(); echo $html; ptln('</div>'); ptln('</body>'); ptln('</html>'); exit; } // html body only if ($act == 'export_xhtmlbody') { $html = p_wiki_xhtml($ID, $REV, false); tpl_toc(); echo $html; exit; } // try to run renderer $mode = substr($act, 7); $text = p_cached_output(wikiFN($ID, $REV), $mode); $headers = p_get_metadata($ID, "format {$mode}"); if (!is_null($text)) { if (is_array($headers)) { foreach ($headers as $key => $val) { header("{$key}: {$val}"); } } print $text; exit; } return 'show'; }
/** * *** DEPRECATED *** * * use p_cached_output() * * Returns the given file parsed to XHTML * * Uses and creates a cachefile * * @deprecated * @author Andreas Gohr <*****@*****.**> * @todo rewrite to use mode instead of hardcoded XHTML */ function p_cached_xhtml($file) { return p_cached_output($file); }
/** * Handle export request for exporting the selection as pdf or text * * @param Doku_renderer_xhtml $renderer */ private function exportOnScreen(&$renderer) { $list = array(); if (isset($_COOKIE['list-pagelist'])) { $renderer->doc = ''; $list = explode("|", $_COOKIE['list-pagelist']); } $render_mode = 'xhtml'; $lf_subst = ''; if ($_GET['do'] == 'export_text') { $render_mode = 'text'; $lf_subst = '<br>'; } foreach ($list as $page) { $renderer->doc .= str_replace(DOKU_LF, $lf_subst, p_cached_output(wikiFN($page), $render_mode)); //p_wiki_xhtml($page,$REV,false); } }