tiki-print.php 4.49 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9
// $Id$
10

11
$section_class="tiki_wiki_page print";
12
require_once ('tiki-setup.php');
lphuberdeau's avatar
lphuberdeau committed
13
$wikilib = TikiLib::lib('wiki');
14

15 16
$auto_query_args = array('page');

17
$access->check_feature(array('feature_wiki', 'feature_wiki_print'));
18

19
// Create the HomePage if it doesn't exist
20 21
if (!$tikilib->page_exists($prefs['wikiHomePage'])) {
	$tikilib->create_page($prefs['wikiHomePage'], 0, '', $tikilib->now, 'Tiki initialization');
22
}
23
// Get the page from the request var or default it to HomePage
24
if (!isset($_REQUEST["page"])) {
25 26
	$page = $prefs['wikiHomePage'];
	$smarty->assign('page', $prefs['wikiHomePage']);
27
} else {
28 29
	$page = $_REQUEST["page"];
	$smarty->assign_by_ref('page', $_REQUEST["page"]);
30 31
}
// If the page doesn't exist then display an error
32 33 34
if (!($info = $tikilib->get_page_info($page))) {
	$smarty->assign('msg', tra('Page cannot be found'));
	$smarty->display('error.tpl');
35 36
	die;
}
37 38
$smarty->assign('page_id', $info['page_id']);

39
// Now check permissions to access this page
changi67's avatar
changi67 committed
40
$tikilib->get_perm_object($page, 'wiki page', $info);
41
$access->check_permission('tiki_p_view', '', 'wiki page', $page);
42

43
// Now increment page hits since we are visiting this page
44
if ($prefs['count_admin_pvs'] == 'y' || $user != 'admin') {
45
	$tikilib->add_hit($page);
46
}
47
if (isset($prefs['wiki_feature_copyrights']) && $prefs['wiki_feature_copyrights'] == 'y' && isset($prefs['wikiLicensePage'])) {
48
	// insert license if wiki copyrights enabled
49 50
	$license_info = $tikilib->get_page_info($prefs['wikiLicensePage']);
	$tikilib->add_hit($prefs['wikiLicensePage']);
51 52
	$info["data"] = $info["data"] . "\n<HR>\n" . $license_info["data"];
	$_REQUEST['copyrightpage'] = $page;
53
}
54
// Verify lock status
55 56
if ($info["flag"] == 'L') {
	$smarty->assign('lock', true);
57
} else {
58
	$smarty->assign('lock', false);
59
}
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
if ($prefs['feature_wiki_structure'] == 'y') {
	$structlib = TikiLib::lib('struct');
	if (isset($_REQUEST['page_ref_id'])) {
		// If a structure page has been requested
		$page_ref_id = $_REQUEST['page_ref_id'];
	} else {
		$page_ref_id = $structlib->get_struct_ref_id($_REQUEST['page']);
	}
	if ($page_ref_id) {
		$page_info = $structlib->s_get_page_info($page_ref_id);
		$structure = 'y';
		$structure_path = $structlib->get_structure_path($page_ref_id);
		$smarty->assign('structure_path', $structure_path);
		if (!empty($page_info['page_alias'])) {
			$crumbpage = $page_info['page_alias'];
		} else {
			$crumbpage = $page;
		}
	}
79
}
80
$pdata = $tikilib->parse_data($info["data"], array('is_html' => $info["is_html"], 'print' => 'y', 'namespace' => $info["namespace"]));
81 82 83 84
$smarty->assign_by_ref('parsed', $pdata);
$smarty->assign_by_ref('lastModif', $info["lastModif"]);
if (empty($info["user"])) {
	$info["user"] = 'anonymous';
85
}
changi67's avatar
changi67 committed
86
$smarty->assign_by_ref('lastVersion', $info["version"]);
87
$smarty->assign_by_ref('lastUser', $info["user"]);
88
$crumbs[] = new Breadcrumb(isset($crumbpage)?$crumbpage:$page, $info["description"], 'tiki-index.php?page=' . urlencode($page), '', '');
89
ask_ticket('print');
90 91
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
92
// Display the Index Template
93
$creator = $wikilib->get_creator($page);
94
$smarty->assign('creator', $creator);
95
$smarty->assign('print_page', 'y');
96
$smarty->assign('urlprefix', $base_url); // Obsolete, use base_url instead. This is for compatibility purposes only.
97
$smarty->assign('mid', 'extends:layouts/internal/layout_view.tpl|tiki-show_page.tpl');
changi67's avatar
changi67 committed
98
$smarty->assign('display', isset($_REQUEST['display']) ? $_REQUEST['display'] : '');
99
// Allow PDF export by installing a Mod that define an appropriate function
changi67's avatar
changi67 committed
100
if (isset($_REQUEST['display']) && $_REQUEST['display'] == 'pdf') {
killianebel's avatar
killianebel committed
101 102
	require_once 'lib/pdflib.php';
	$generator = new PdfGenerator();
103
	$pdf = $generator->getPdf('tiki-print.php', array('page' => $page));
104
	if (empty($pdf)) {
arildb's avatar
arildb committed
105 106 107 108 109 110
		echo "Unable to generate PDF";
	} else {
		$length = strlen($pdf);
		header('Cache-Control: private, must-revalidate');
		header('Pragma: private');
		header("Content-Description: File Transfer");
111
		header('Content-disposition: attachment; filename="'. TikiLib::lib('tiki')->remove_non_word_characters_and_accents($page) . '.pdf"');
arildb's avatar
arildb committed
112 113 114 115 116
		header("Content-Type: application/pdf");
		header("Content-Transfer-Encoding: binary");
		header('Content-Length: '. $length);
		echo $pdf;
	}
117 118 119
} else {
	$smarty->display('tiki-print.tpl');
}