Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/xmldb/actions/view_xml/view_xml.class.php
Go to the documentation of this file.
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 
00032 class view_xml extends XMLDBAction {
00033 
00037     function init() {
00038         parent::init();
00039         // Set own core attributes
00040         $this->can_subaction = ACTION_NONE;
00041         //$this->can_subaction = ACTION_HAVE_SUBACTIONS;
00042 
00043         // Set own custom attributes
00044         $this->sesskey_protected = false; // This action doesn't need sesskey protection
00045 
00046         // Get needed strings
00047         $this->loadStrings(array(
00048             // 'key' => 'module',
00049         ));
00050     }
00051 
00057     function invoke() {
00058         parent::invoke();
00059 
00060         $result = true;
00061 
00062         // Set own core attributes
00063         $this->does_generate = ACTION_GENERATE_XML;
00064 
00065         // These are always here
00066         global $CFG, $XMLDB;
00067 
00068         // Do the job, setting result as needed
00069 
00070         // Get the file parameter
00071         $file = required_param('file', PARAM_PATH);
00072         $file = $CFG->dirroot . $file;
00073         // File must be under $CFG->wwwroot and
00074         // under one db directory (simple protection)
00075         if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
00076             substr(dirname($file), -2, 2) == 'db') {
00077             // Everything is ok. Load the file to memory
00078             $this->output = file_get_contents($file);
00079         } else {
00080             // Switch to HTML and error
00081             $this->does_generate = ACTION_GENERATE_HTML;
00082             $this->errormsg = 'File not viewable (' . $file .')';
00083             $result = false;
00084         }
00085 
00086         // Return ok if arrived here
00087         return $result;
00088     }
00089 }
00090 
 All Data Structures Namespaces Files Functions Variables Enumerations