Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/cc_lib/cc_page.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/>.
00022 require_once 'cc_general.php';
00023 
00024 class page11_resurce_file extends general_cc_file {
00025     protected $rootns = 'xmlns';
00026     protected $rootname = 'html';
00027     protected $ccnamespaces = array('xmlns' => 'http://www.w3.org/1999/xhtml');
00028 
00029     protected $content = null;
00030     protected $title = null;
00031     protected $intro = null;
00032 
00033     public function set_content($value) {
00034         $this->content = $value;
00035     }
00036 
00037     public function set_title($value) {
00038         $this->title = self::safexml($value);
00039     }
00040 
00041     public function set_intro($value) {
00042         $this->intro = self::safexml(strip_tags($value));
00043     }
00044 
00045     protected function on_create() {
00046         $impl = new DOMImplementation();
00047         $dtd  = $impl->createDocumentType( 'html',
00048                                            '-//W3C//DTD XHTML 1.0 Strict//EN',
00049                                            'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
00050         $doc = $impl->createDocument($this->ccnamespaces[$this->rootns], null, $dtd);
00051         $doc->formatOutput = true;
00052         $doc->preserveWhiteSpace = true;
00053         $this->doc = $doc;
00054         parent::on_create();
00055     }
00056 
00057     public function on_save() {
00058 
00059         $rns = $this->ccnamespaces[$this->rootns];
00060         //Add the basic tags
00061         $head = $this->append_new_element_ns($this->root, $rns, 'head');
00062         $this->append_new_attribute_ns($head, $rns, 'profile', 'http://dublincore.org/documents/dc-html/');
00063 
00064         //Linking Dublin Core Metadata 1.1
00065         $link_dc = $this->append_new_element_ns($head, $rns, 'link');
00066         $this->append_new_attribute_ns($link_dc, $rns, 'rel', 'schema.DC');
00067         $this->append_new_attribute_ns($link_dc, $rns, 'href', 'http://purl.org/dc/elements/1.1/');
00068         $link_dcterms = $this->append_new_element_ns($head, $rns, 'link');
00069         $this->append_new_attribute_ns($link_dcterms, $rns, 'rel', 'schema.DCTERMS');
00070         $this->append_new_attribute_ns($link_dcterms, $rns, 'href', 'http://purl.org/dc/terms/');
00071         //Content type
00072         $meta_type = $this->append_new_element_ns($head, $rns, 'meta');
00073         $this->append_new_attribute_ns($meta_type, $rns, 'name'   , 'DC.type'         );
00074         $this->append_new_attribute_ns($meta_type, $rns, 'scheme' , 'DCTERMS.DCMIType');
00075         $this->append_new_attribute_ns($meta_type, $rns, 'content', 'Text'            );
00076 
00077         //Content description
00078         if (!empty($this->intro)) {
00079             $meta_description = $this->append_new_element_ns($head, $rns     , 'meta'          );
00080             $this->append_new_attribute_ns($meta_description, $rns, 'name'   , 'DC.description');
00081             $this->append_new_attribute_ns($meta_description, $rns, 'content', $this->intro    );
00082         }
00083 
00084         $meta = $this->append_new_element_ns($head, $rns, 'meta');
00085         $this->append_new_attribute_ns($meta, $rns, 'http-equiv', 'Content-type');
00086         $this->append_new_attribute_ns($meta, $rns, 'content', 'text/html; charset=UTF-8');
00087         //set the title
00088         $title = $this->append_new_element_ns($head, $rns, 'title', $this->title);
00089         $body = $this->append_new_element_ns($this->root, $rns, 'body');
00090         //We are unable to use DOM for embedding HTML due to numerous content errors
00091         //Therefore we place a dummy tag that will be later replaced with the real content
00092         $this->append_new_element_ns($body, $rns, 'div', '##REPLACE##');
00093 
00094         return true;
00095     }
00096 
00097     public function saveTo($fname) {
00098         $result = $this->on_save();
00099         if ($result) {
00100             $dret = str_replace('<?xml version="1.0"?>'."\n", '', $this->viewXML());
00101             $dret = str_replace('<div>##REPLACE##</div>', $this->content, $dret);
00102             $result = (file_put_contents($fname, $dret) !== false);
00103             if ($result) {
00104                 $this->filename = $fname;
00105                 $this->processPath();
00106             }
00107         }
00108         return $result;
00109     }
00110 }
 All Data Structures Namespaces Files Functions Variables Enumerations