Merge branch 'MDL-40255_M25' of git://github.com/lazydaisy/moodle into MOODLE_25_STABLE
[moodle.git] / lib / tests / other / pdflibtestpage.php
blob7c53a2ec293274876712acd74f0f19f995e2dd8c
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Produces a sample PDF using lib/pdflib.php
20 * @package core
21 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require(dirname(__FILE__) . '/../../../config.php');
26 require_once($CFG->libdir . '/pdflib.php');
28 require_login();
29 $context = context_system::instance();
30 require_capability('moodle/site:config', $context);
32 $getpdf = optional_param('getpdf', 0, PARAM_INT);
33 $fontfamily = optional_param('fontfamily', PDF_DEFAULT_FONT, PARAM_ALPHA); // to be configurable
35 /**
36 * Extend the standard PDF class to get access to some protected values we want to display
37 * at the test page.
39 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class testable_pdf extends pdf {
43 public function returnFontsList() {
44 return $this->fontlist;
46 public function _getfontpath() {
47 return parent::_getfontpath();
51 if ($getpdf) {
52 $doc = new testable_pdf();
54 $doc->SetTitle('Moodle PDF library test');
55 $doc->SetAuthor('Moodle ' . $CFG->release);
56 $doc->SetCreator('lib/tests/other/pdflibtestpage.php');
57 $doc->SetKeywords('Moodle, PDF');
58 $doc->SetSubject('This has been generated by Moodle as its PDF library test page');
59 $doc->SetMargins(15, 30);
61 $doc->setPrintHeader(true);
62 $doc->setHeaderMargin(10);
63 $doc->setHeaderFont(array($fontfamily, 'b', 10));
64 $doc->setHeaderData('pix/moodlelogo-med-white.gif', 40, $SITE->fullname, $CFG->wwwroot);
66 $doc->setPrintFooter(true);
67 $doc->setFooterMargin(10);
68 $doc->setFooterFont(array($fontfamily, '', 8));
70 $doc->AddPage();
72 $doc->SetTextColor(255,255,255);
73 $doc->SetFillColor(255,203,68);
74 $doc->SetFont($fontfamily, 'B', 24);
75 $doc->Cell(0, 0, 'Moodle PDF library test', 0, 1, 'C', 1);
77 $doc->SetFont($fontfamily, '', 12);
78 $doc->Ln(6);
79 $doc->SetTextColor(0,0,0);
81 $c = '<h3>General information</h3>';
82 $c .= 'Moodle release: ' . $CFG->release . '<br />';
83 $c .= 'PDF producer: TCPDF ' . $doc->getTCPDFVersion() . ' (http://www.tcpdf.org) <br />';
84 $c .= 'Font of this test page: ' . $fontfamily . '<br />';
86 $c .= '<h3>Current settings</h3>';
87 $c .= '<table border="1" cellspacing="0" cellpadding="1">';
88 foreach (array('K_PATH_MAIN', 'K_PATH_URL', 'K_PATH_FONTS', 'K_PATH_CACHE', 'K_PATH_IMAGES', 'K_BLANK_IMAGE',
89 'K_CELL_HEIGHT_RATIO', 'K_SMALL_RATIO', 'PDF_CUSTOM_FONT_PATH', 'PDF_DEFAULT_FONT') as $setting) {
90 if (defined($setting)) {
91 $c .= '<tr style="font-size: x-small;"><td>' . $setting . '</td><td>' . constant($setting) . '</td></tr>';
94 $c .= '<tr style="font-size: x-small;"><td>Effective font path</td><td>' . $doc->_getfontpath() . '</td></tr>';
95 $c .= '</table><br />';
97 $c .= '<h3>Available font files</h3>';
98 $fontfiles = $doc->returnFontsList();
99 sort($fontfiles);
100 $c .= implode(', ', $fontfiles);
101 $c .= '<br />';
103 $c .= '<h3>Installed languages and their alphabets</h3>';
104 $languages = array();
105 $langdirs = get_list_of_plugins('lang', '', $CFG->dataroot);
106 array_unshift($langdirs, 'en');
107 foreach ($langdirs as $langdir) {
108 if ('en' == $langdir) {
109 $langconfig = $CFG->dirroot . '/lang/en/langconfig.php';
110 } else {
111 $langconfig = $CFG->dataroot . '/lang/' . $langdir . '/langconfig.php';
113 if (is_readable($langconfig)) {
114 include($langconfig);
115 if (is_array($string)) {
116 $languages[$langdir] = new stdClass();
117 $languages[$langdir]->langname = isset($string['thislanguage']) ? $string['thislanguage'] : '(unknown)';
118 $languages[$langdir]->alphabet = isset($string['alphabet']) ? $string['alphabet'] : '(no alphabet defined)';
122 $c .= '<dl>';
123 foreach ($languages as $langcode => $language) {
124 $c .= '<dt>' . $language->langname . ' (' . $langcode . ')</dt>';
125 $c .= '<dd>"' . $language->alphabet . '"</dd>';
127 $c .= '</dl>';
129 $doc->writeHTML($c);
131 $doc->Output('pdflibtestpage.pdf');
132 exit();
135 $PAGE->set_url('/lib/tests/other/pdflibtestpage.php');
136 $PAGE->set_context($context);
137 $PAGE->set_title('PDF library test');
138 $PAGE->set_heading('PDF library test');
140 echo $OUTPUT->header();
141 echo $OUTPUT->heading('Press the button to generate test PDF', 2);
142 echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1)));
143 echo $OUTPUT->footer();