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