weekly release 2.2dev
[moodle.git] / admin / tool / xmldb / actions / view_xml / view_xml.class.php
CommitLineData
0df0df23 1<?php
f25d53a9
EL
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.
13//
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/>.
8c15ae99 16
f25d53a9 17/**
b007a5d0
PS
18 * @package tool
19 * @subpackage xmldb
20 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
f25d53a9 22 */
8c15ae99 23
f25d53a9
EL
24/**
25 * This class will display one XML file
26 *
b007a5d0
PS
27 * @package tool
28 * @subpackage xmldb
29 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
f25d53a9 31 */
8c15ae99 32class view_xml extends XMLDBAction {
33
eef868d1 34 /**
8c15ae99 35 * Init method, every subclass will have its own
36 */
37 function init() {
38 parent::init();
39 /// Set own core attributes
40 $this->can_subaction = ACTION_NONE;
41 //$this->can_subaction = ACTION_HAVE_SUBACTIONS;
42
43 /// Set own custom attributes
f25d53a9 44 $this->sesskey_protected = false; // This action doesn't need sesskey protection
8c15ae99 45
46 /// Get needed strings
47 $this->loadStrings(array(
48 /// 'key' => 'module',
49 ));
50 }
51
52 /**
53 * Invoke method, every class will have its own
54 * returns true/false on completion, setting both
55 * errormsg and output as necessary
56 */
57 function invoke() {
58 parent::invoke();
59
60 $result = true;
61
62 /// Set own core attributes
63 $this->does_generate = ACTION_GENERATE_XML;
64
65 /// These are always here
66 global $CFG, $XMLDB;
67
68 /// Do the job, setting result as needed
69
70 /// Get the file parameter
115a7365 71 $file = required_param('file', PARAM_PATH);
294ce987 72 $file = $CFG->dirroot . $file;
eef868d1 73 /// File must be under $CFG->wwwroot and
8c15ae99 74 /// under one db directory (simple protection)
75 if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
76 substr(dirname($file), -2, 2) == 'db') {
77 /// Everything is ok. Load the file to memory
78 $this->output = file_get_contents($file);
79 } else {
80 /// Switch to HTML and error
81 $this->does_generate = ACTION_GENERATE_HTML;
82 $this->errormsg = 'File not viewable (' . $file .')';
83 $result = false;
84 }
85
86 /// Return ok if arrived here
87 return $result;
88 }
89}
0df0df23 90