コード例 #1
0
ファイル: text.lib.php プロジェクト: annickvdp/Chamilo1.9.10
/**
 * Detects encoding of html-formatted text.
 * @param  string $string                The input html-formatted text.
 * @return string                        Returns the detected encoding.
 */
function api_detect_encoding_html($string) {
    if (@preg_match('/<head.*(<meta[^>]*content=[^>]*>).*<\/head>/si', $string, $matches)) {
        if (@preg_match('/<meta[^>]*charset=(.*)["\';][^>]*>/si', $matches[1], $matches)) {
            return api_refine_encoding_id(trim($matches[1]));
        }
    }
    return api_detect_encoding(api_html_to_text($string));
}
コード例 #2
0
 /**
  * Returns sample text based on the imported course content.
  * This sample text is to be used for course language or encoding detection if there is missing (meta)data in the archive.
  * @return string	The resulting sample text extracted from some common resources' data fields.
  */
 public function get_sample_text()
 {
     $sample_text = '';
     foreach ($this->resources as $type => &$resources) {
         if (count($resources) > 0) {
             foreach ($resources as $id => &$resource) {
                 $title = '';
                 $description = '';
                 switch ($type) {
                     case RESOURCE_ANNOUNCEMENT:
                         $title = $resource->title;
                         $description = $resource->content;
                         break;
                     case RESOURCE_DOCUMENT:
                         $title = $resource->title;
                         $description = $resource->comment;
                         break;
                     case RESOURCE_EVENT:
                         $title = $resource->title;
                         $description = $resource->content;
                         break;
                     case RESOURCE_FORUM:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_FORUMCATEGORY:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_FORUMPOST:
                         $title = $resource->title;
                         $description = $resource->text;
                         break;
                     case RESOURCE_FORUMTOPIC:
                         $title = $resource->title;
                         break;
                     case RESOURCE_GLOSSARY:
                         $title = $resource->name;
                         $description = $resource->description;
                         break;
                     case RESOURCE_LEARNPATH:
                         $title = $resource->name;
                         $description = $resource->description;
                         break;
                     case RESOURCE_LINK:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_LINKCATEGORY:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_QUIZ:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_TEST_CATEGORY:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     case RESOURCE_QUIZQUESTION:
                         $title = $resource->question;
                         $description = $resource->description;
                         break;
                     case RESOURCE_SCORM:
                         $title = $resource->title;
                         break;
                     case RESOURCE_SURVEY:
                         $title = $resource->title;
                         $description = $resource->subtitle;
                         break;
                     case RESOURCE_SURVEYQUESTION:
                         $title = $resource->survey_question;
                         $description = $resource->survey_question_comment;
                         break;
                     case RESOURCE_TOOL_INTRO:
                         $description = $resource->intro_text;
                         break;
                     case RESOURCE_WIKI:
                         $title = $resource->title;
                         $description = $resource->content;
                         break;
                     case RESOURCE_THEMATIC:
                         $title = $resource->title;
                         $description = $resource->content;
                         break;
                     case RESOURCE_ATTENDANCE:
                         $title = $resource->params['name'];
                         $description = $resource->params['description'];
                         break;
                     case RESOURCE_WORK:
                         $title = $resource->title;
                         $description = $resource->description;
                         break;
                     default:
                         break;
                 }
                 $title = api_html_to_text($title);
                 $description = api_html_to_text($description);
                 if (!empty($title)) {
                     $sample_text .= $title . "\n";
                 }
                 if (!empty($description)) {
                     $sample_text .= $description . "\n";
                 }
                 if (!empty($title) || !empty($description)) {
                     $sample_text .= "\n";
                 }
             }
         }
     }
     return $sample_text;
 }