|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 require(dirname(__FILE__) . '/../../../../config.php'); 00027 require_once($CFG->libdir . '/pdflib.php'); 00028 00029 require_login(); 00030 $context = get_context_instance(CONTEXT_SYSTEM); 00031 require_capability('tool/unittest:execute', $context); 00032 00033 $getpdf = optional_param('getpdf', 0, PARAM_INT); 00034 $fontfamily = optional_param('fontfamily', PDF_DEFAULT_FONT, PARAM_ALPHA); // to be configurable 00035 00043 class testable_pdf extends pdf { 00044 public function returnFontsList() { 00045 return $this->fontlist; 00046 } 00047 public function _getfontpath() { 00048 return parent::_getfontpath(); 00049 } 00050 } 00051 00052 if ($getpdf) { 00053 $doc = new testable_pdf(); 00054 00055 $doc->SetTitle('Moodle PDF library test'); 00056 $doc->SetAuthor('Moodle ' . $CFG->release); 00057 $doc->SetCreator('admin/tool/unittest/pdflibtestpage.php'); 00058 $doc->SetKeywords('Moodle, PDF'); 00059 $doc->SetSubject('This has been generated by Moodle as its PDF library test page'); 00060 $doc->SetMargins(15, 30); 00061 00062 $doc->setPrintHeader(true); 00063 $doc->setHeaderMargin(10); 00064 $doc->setHeaderFont(array($fontfamily, 'b', 10)); 00065 $doc->setHeaderData('pix/moodlelogo-med-white.gif', 40, $SITE->fullname, $CFG->wwwroot); 00066 00067 $doc->setPrintFooter(true); 00068 $doc->setFooterMargin(10); 00069 $doc->setFooterFont(array($fontfamily, '', 8)); 00070 00071 $doc->AddPage(); 00072 00073 $doc->SetTextColor(255,255,255); 00074 $doc->SetFillColor(255,203,68); 00075 $doc->SetFont($fontfamily, 'B', 24); 00076 $doc->Cell(0, 0, 'Moodle PDF library test', 0, 1, 'C', 1); 00077 00078 $doc->SetFont($fontfamily, '', 12); 00079 $doc->Ln(6); 00080 $doc->SetTextColor(0,0,0); 00081 00082 $c = '<h3>General information</h3>'; 00083 $c .= 'Moodle release: ' . $CFG->release . '<br />'; 00084 $c .= 'PDF producer: TCPDF ' . $doc->getTCPDFVersion() . ' (http://www.tcpdf.org) <br />'; 00085 $c .= 'Font of this test page: ' . $fontfamily . '<br />'; 00086 00087 $c .= '<h3>Current settings</h3>'; 00088 $c .= '<table border="1" cellspacing="0" cellpadding="1">'; 00089 foreach (array('K_PATH_MAIN', 'K_PATH_URL', 'K_PATH_FONTS', 'K_PATH_CACHE', 'K_PATH_IMAGES', 'K_BLANK_IMAGE', 00090 'K_CELL_HEIGHT_RATIO', 'K_SMALL_RATIO', 'PDF_CUSTOM_FONT_PATH', 'PDF_DEFAULT_FONT') as $setting) { 00091 if (defined($setting)) { 00092 $c .= '<tr style="font-size: x-small;"><td>' . $setting . '</td><td>' . constant($setting) . '</td></tr>'; 00093 } 00094 } 00095 $c .= '<tr style="font-size: x-small;"><td>Effective font path</td><td>' . $doc->_getfontpath() . '</td></tr>'; 00096 $c .= '</table><br />'; 00097 00098 $c .= '<h3>Available font files</h3>'; 00099 $fontfiles = $doc->returnFontsList(); 00100 sort($fontfiles); 00101 $c .= implode(', ', $fontfiles); 00102 $c .= '<br />'; 00103 00104 $c .= '<h3>Installed languages and their alphabets</h3>'; 00105 $languages = array(); 00106 $langdirs = get_list_of_plugins('lang', '', $CFG->dataroot); 00107 array_unshift($langdirs, 'en'); 00108 foreach ($langdirs as $langdir) { 00109 if ('en' == $langdir) { 00110 $langconfig = $CFG->dirroot . '/lang/en/langconfig.php'; 00111 } else { 00112 $langconfig = $CFG->dataroot . '/lang/' . $langdir . '/langconfig.php'; 00113 } 00114 if (is_readable($langconfig)) { 00115 include($langconfig); 00116 if (is_array($string)) { 00117 $languages[$langdir] = new stdClass(); 00118 $languages[$langdir]->langname = isset($string['thislanguage']) ? $string['thislanguage'] : '(unknown)'; 00119 $languages[$langdir]->alphabet = isset($string['alphabet']) ? $string['alphabet'] : '(no alphabet defined)'; 00120 } 00121 } 00122 } 00123 $c .= '<dl>'; 00124 foreach ($languages as $langcode => $language) { 00125 $c .= '<dt>' . $language->langname . ' (' . $langcode . ')</dt>'; 00126 $c .= '<dd>"' . $language->alphabet . '"</dd>'; 00127 } 00128 $c .= '</dl>'; 00129 00130 $doc->writeHTML($c); 00131 00132 $doc->Output('pdflibtestpage.pdf'); 00133 exit(); 00134 } 00135 00136 $PAGE->set_url('/admin/tool/unittest/other/pdflibtestpage.php'); 00137 $PAGE->set_context($context); 00138 $PAGE->set_title('PDF library test'); 00139 $PAGE->set_heading('PDF library test'); 00140 00141 echo $OUTPUT->header(); 00142 echo $OUTPUT->heading('Press the button to generate test PDF', 2); 00143 echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1))); 00144 echo $OUTPUT->footer();