當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DocumentManager::parse_HTML_attributes方法代碼示例

本文整理匯總了PHP中DocumentManager::parse_HTML_attributes方法的典型用法代碼示例。如果您正苦於以下問題:PHP DocumentManager::parse_HTML_attributes方法的具體用法?PHP DocumentManager::parse_HTML_attributes怎麽用?PHP DocumentManager::parse_HTML_attributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DocumentManager的用法示例。


在下文中一共展示了DocumentManager::parse_HTML_attributes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_resources_from_source

 /**
  * Gets the list of included resources as a list of absolute or relative paths of
  * resources included in the current item. This allows for a better SCORM export.
  * The list will generally include pictures, flash objects, java applets, or any other
  * stuff included in the source of the current item. The current item is expected
  * to be an HTML file. If it is not, then the function will return and empty list.
  * @param    string    type (one of the Chamilo tools) - optional (otherwise takes the current item's type)
  * @param    string    path (absolute file path) - optional (otherwise takes the current item's path)
  * @param    int        level of recursivity we're in
  * @return    array    List of file paths. An additional field containing 'local' or 'remote' helps determine if the file should be copied into the zip or just linked
  */
 public function get_resources_from_source($type = null, $abs_path = null, $recursivity = 1)
 {
     $max = 5;
     if ($recursivity > $max) {
         return array();
     }
     if (!isset($type)) {
         $type = $this->get_type();
     }
     if (!isset($abs_path)) {
         $path = $this->get_file_path();
         $abs_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $path;
         //echo "Abs path coming from item : ".$abs_path."<br />\n";
     }
     /*
      else {
      echo "Abs path coming from param: ".$abs_path."<br />\n";
      }
     */
     //error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path, 0);
     $files_list = array();
     $type = $this->get_type();
     switch ($type) {
         case TOOL_DOCUMENT:
         case TOOL_QUIZ:
         case 'sco':
             // Get the document and, if HTML, open it.
             if (is_file($abs_path)) {
                 // for now, read the whole file in one go (that's gonna be a problem when the file is too big).
                 $info = pathinfo($abs_path);
                 $ext = $info['extension'];
                 switch (strtolower($ext)) {
                     case 'html':
                     case 'htm':
                     case 'shtml':
                     case 'css':
                         $wanted_attributes = array('src', 'url', '@import', 'href', 'value');
                         // Parse it for included resources.
                         $file_content = file_get_contents($abs_path);
                         // Get an array of attributes from the HTML source.
                         $attributes = DocumentManager::parse_HTML_attributes($file_content, $wanted_attributes);
                         // Look at 'src' attributes in this file
                         foreach ($wanted_attributes as $attr) {
                             if (isset($attributes[$attr])) {
                                 // Find which kind of path these are (local or remote).
                                 $sources = $attributes[$attr];
                                 foreach ($sources as $source) {
                                     // Skip what is obviously not a resource.
                                     if (strpos($source, "+this.")) {
                                         continue;
                                     }
                                     // javascript code - will still work unaltered.
                                     if (strpos($source, '.') === false) {
                                         continue;
                                     }
                                     // No dot, should not be an external file anyway.
                                     if (strpos($source, 'mailto:')) {
                                         continue;
                                     }
                                     // mailto link.
                                     if (strpos($source, ';') && !strpos($source, '&amp;')) {
                                         continue;
                                     }
                                     // Avoid code - that should help.
                                     if ($attr == 'value') {
                                         if (strpos($source, 'mp3file')) {
                                             $files_list[] = array(substr($source, 0, strpos($source, '.swf') + 4), 'local', 'abs');
                                             $mp3file = substr($source, strpos($source, 'mp3file=') + 8);
                                             if (substr($mp3file, 0, 1) == '/') {
                                                 $files_list[] = array($mp3file, 'local', 'abs');
                                             } else {
                                                 $files_list[] = array($mp3file, 'local', 'rel');
                                             }
                                         } elseif (strpos($source, 'flv=') === 0) {
                                             $source = substr($source, 4);
                                             if (strpos($source, '&') > 0) {
                                                 $source = substr($source, 0, strpos($source, '&'));
                                             }
                                             if (strpos($source, '://') > 0) {
                                                 if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($source, 'local', 'url');
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($source, 'remote', 'url');
                                                 }
                                             } else {
                                                 $files_list[] = array($source, 'local', 'abs');
                                             }
//.........這裏部分代碼省略.........
開發者ID:ilosada,項目名稱:chamilo-lms-icpna,代碼行數:101,代碼來源:learnpathItem.class.php


注:本文中的DocumentManager::parse_HTML_attributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。