Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/cc_lib/gral_lib/parser.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 
00017 require_once $CFG->dirroot .'/backup/cc/cc_lib/xmlbase.php';
00018 require_once 'cssparser.php';
00019 require_once 'pathutils.php';
00020 
00021 
00022 
00023 function is_url($url) {
00024     if (
00025          !preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url) &&
00026          !preg_match('#^https\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url) &&
00027          !preg_match('#^ftp\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url)
00028         ) {
00029         $status = false;
00030     } else {
00031         $status = true;
00032     }
00033     return $status;
00034 }
00035 
00036 function GetDepFiles($manifestroot, $fname,$folder,&$filenames) {
00037 
00038     $extension      = end(explode('.',$fname));
00039     $filenames      = array();
00040     $dcx            = new XMLGenericDocument();
00041     $result         = true;
00042 
00043     switch ($extension){
00044         case 'xml':
00045                  $result = @$dcx->loadXMLFile($manifestroot.$folder.$fname);
00046                  if (!$result) {
00047                     $result = @$dcx->loadXMLFile($manifestroot.DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR.$fname);
00048                  }
00049                  GetDepFilesXML($manifestroot, $fname,$filenames,$dcx, $folder);
00050             break;
00051         case 'html':
00052         case 'htm':
00053                  $result = @$dcx->loadHTMLFile($manifestroot.$folder.$fname);
00054                  if (!$result) {
00055                     $result = @$dcx->loadHTMLFile($manifestroot.DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR.$fname);
00056                  }
00057                  GetDepFilesHTML($manifestroot, $fname,$filenames,$dcx, $folder);
00058             break;
00059     }
00060     return $result;
00061 }
00062 
00063 
00064 
00065 function GetDepFilesXML ($manifestroot, $fname,&$filenames,&$dcx, $folder){
00066         $nlist = $dcx->nodeList("//img/@src | //attachments/attachment/@href  | //link/@href | //script/@src");
00067         $css_obj_array = array();
00068         foreach ($nlist as $nl) {
00069             $item = $nl->nodeValue;
00070             $path_parts = pathinfo($item);
00071             $fname = $path_parts['basename'];
00072             $ext   = array_key_exists('extension',$path_parts) ? $path_parts['extension'] : '';
00073             if (!is_url($nl->nodeValue)) {
00074               //$file =   $folder.$nl->nodeValue; // DEPENDERA SI SE QUIERE Q SEA RELATIVO O ABSOLUTO
00075               $file =   $nl->nodeValue;
00076               toNativePath($file);
00077               $filenames[]=$file;
00078             }
00079         }
00080         $dcx->registerNS('qti','http://www.imsglobal.org/xsd/imscc/ims_qtiasiv1p2.xsd');
00081         $dcx->resetXpath();
00082         $nlist = $dcx->nodeList("//qti:mattext | //text");
00083         $dcx2 = new XMLGenericDocument();
00084         foreach ($nlist as $nl) {
00085             if ($dcx2->loadString($nl->nodeValue)){
00086                 GetDepFilesHTML($manifestroot,$fname,$filenames,$dcx2,$folder);
00087             }
00088         }
00089 }
00090 
00091 
00092 
00093 function GetDepFilesHTML ($manifestroot, $fname,&$filenames,&$dcx, $folder){
00094         $dcx->resetXpath();
00095         $nlist = $dcx->nodeList("//img/@src | //link/@href | //script/@src | //a[not(starts-with(@href,'#'))]/@href");
00096         $css_obj_array=array();
00097         foreach ($nlist as $nl) {
00098             $item = $nl->nodeValue;
00099             $path_parts = pathinfo($item);
00100             $fname = $path_parts['basename'];
00101             $ext   = array_key_exists('extension',$path_parts) ? $path_parts['extension'] : '';
00102             if (!is_url($folder.$nl->nodeValue) && !is_url($nl->nodeValue)) {
00103               $path = $nl->nodeValue;
00104               //$file = fullPath($path,"/");
00105               toNativePath($path);
00106               $filenames[]= $path;
00107             }
00108             if ($ext == 'css') {
00109                 $css = new cssparser();
00110                 $css->Parse($dcx->filePath().$nl->nodeValue);
00111                 $css_obj_array[$item]=$css;
00112             }
00113         }
00114         $nlist = $dcx->nodeList("//*/@class");
00115         foreach ($nlist as $nl) {
00116             $item = $nl->nodeValue;
00117             foreach ($css_obj_array as $csskey => $cssobj) {
00118                 $bimg = $cssobj->Get($item,"background-image");
00119                 $limg = $cssobj->Get($item,"list-style-image");
00120                 $npath = pathinfo($csskey);
00121                 if ((!empty($bimg))&& ($bimg != 'none')) {
00122                     $filenames[] = stripUrl($bimg,$npath['dirname'].'/');
00123                 } else
00124                 if ((!empty($limg))&& ($limg != 'none')) {
00125                     $filenames[] = stripUrl($limg,$npath['dirname'].'/');
00126                 }
00127             }
00128         }
00129         $elems_to_check = array("body","p","ul","h4","a","th");
00130         $do_we_have_it = array();
00131         foreach ($elems_to_check as $elem) {
00132             $do_we_have_it[$elem]=($dcx->nodeList("//".$elem)->length > 0);
00133         }
00134         foreach ($elems_to_check as $elem) {
00135             if ($do_we_have_it[$elem]) {
00136                 foreach ($css_obj_array as $csskey => $cssobj) {
00137                     $sb = $cssobj->Get($elem, "background-image");
00138                     $sbl = $cssobj->Get($elem,"list-style-image");
00139                     $npath = pathinfo($csskey);
00140                     if ((!empty($sb)) && ($sb != 'none')) {
00141                         $filenames[] = stripUrl($sb,$npath['dirname'].'/');
00142                     } else
00143                     if ((!empty($sbl)) && ($sbl != 'none')) {
00144                         $filenames[] = stripUrl($sbl,$npath['dirname'].'/');
00145                     }
00146                 }
00147             }
00148         }
00149 }
 All Data Structures Namespaces Files Functions Variables Enumerations