Пример #1
0
     $content = '<embed SRC="' . $content_info['href'] . '" autostart="false" width="145" height="60"><noembed><bgsound src="' . $content_info['href'] . '"></noembed></embed>';
 } else {
     if (in_array($ext, array('txt', 'css', 'html', 'htm', 'csv', 'asc', 'tsv', 'xml', 'xsl'))) {
         if ($content_type == 'IMS Common Cartridge') {
             $content_info['new_path'] = $content_new_path;
         }
         /* this is a plain text file */
         //$content = file_get_contents(AT_CONTENT_DIR . 'import/'.$_SESSION['course_id'].'/'.$content_info['href']);
         $content = file_get_contents($import_path . $content_info['href']);
         if ($content === false) {
             /* if we can't stat() it then we're unlikely to be able to read it */
             /* so we'll never get here. */
             continue;
         }
         // get the contents of the 'head' element
         $head .= get_html_head_by_tag($content, $html_head_tags);
         // Specifically handle eXe package
         // NOTE: THIS NEEDS WORK! TO FIND A WAY APPLY EXE .CSS FILES ONLY ON COURSE CONTENT PART.
         // NOW USE OUR OWN .CSS CREATED SOLELY FOR EXE
         $isExeContent = false;
         // check xml file in eXe package
         if (preg_match("/<organization[ ]*identifier=\"eXe*>*/", $ims_manifest_xml)) {
             $isExeContent = true;
         }
         // use ATutor's eXe style sheet as the ones from eXe conflicts with ATutor's style sheets
         if ($isExeContent) {
             $head = preg_replace('/(<style.*>)(.*)(<\\/style>)/ms', '\\1@import url(/docs/exestyles.css);\\3', $head);
         }
         // end of specifically handle eXe package
         $content = get_html_body($content);
         if ($contains_glossary_terms) {
Пример #2
0
/**
 * Paste_from_file
 * Parses a named uploaded file of html or txt type
 * The function identifies title, head and body for html files,
 * or body for text files.
 * 
 * @return FileData object
 */
function paste_from_file()
{
    $fileData = new FileData();
    if ($_FILES['uploadedfile_paste']['name'] == '') {
        $fileData->setErrorMsg(_AT('TR_ERROR_FILE_NOT_SELECTED'));
    } elseif ($_FILES['uploadedfile_paste']['type'] == 'text/plain' || $_FILES['uploadedfile_paste']['type'] == 'text/html') {
        $path_parts = pathinfo($_FILES['uploadedfile_paste']['name']);
        $ext = strtolower($path_parts['extension']);
        if (in_array($ext, array('html', 'htm'))) {
            $contents = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
            /* get the <title></title> of this page             */
            $start_pos = strpos(strtolower($contents), '<title>');
            $end_pos = strpos(strtolower($contents), '</title>');
            if ($start_pos !== false && $end_pos !== false) {
                $start_pos += strlen('<title>');
                $fileData->setTitle(trim(substr($contents, $start_pos, $end_pos - $start_pos)));
            }
            unset($start_pos);
            unset($end_pos);
            $fileData->setHead(trim(get_html_head_by_tag($contents, array("link", "style", "script"))));
            $fileData->setBody(trim(get_html_body($contents)));
        } else {
            if ($ext == 'txt') {
                $fileData->setBody(trim(file_get_contents($_FILES['uploadedfile_paste']['tmp_name'])));
            }
        }
    } else {
        $fileData->setErrorMsg(_AT('TR_ERROR_BAD_FILE_TYPE'));
    }
    return $fileData;
}
function paste_from_file()
{
    global $msg;
    if ($_FILES['uploadedfile_paste']['name'] == '') {
        $msg->addError('FILE_NOT_SELECTED');
        return;
    }
    if ($_FILES['uploadedfile_paste']['size'] >= memory_get_usage()) {
        $msg->addError(array('TOO_BIG_TO_UPLOAD', $_FILES['uploadedfile_paste']['size']));
        return;
    }
    if ($_FILES['uploadedfile_paste']['name'] && ($_FILES['uploadedfile_paste']['type'] == 'text/plain' || $_FILES['uploadedfile_paste']['type'] == 'text/html')) {
        $path_parts = pathinfo($_FILES['uploadedfile_paste']['name']);
        $ext = strtolower($path_parts['extension']);
        if (in_array($ext, array('html', 'htm'))) {
            $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
            /* get the <title></title> of this page				*/
            $start_pos = strpos(strtolower($_POST['body_text']), '<title>');
            $end_pos = strpos(strtolower($_POST['body_text']), '</title>');
            if ($start_pos !== false && $end_pos !== false) {
                $start_pos += strlen('<title>');
                $_POST['title'] = trim(substr($_POST['body_text'], $start_pos, $end_pos - $start_pos));
            }
            unset($start_pos);
            unset($end_pos);
            $_POST['head'] = get_html_head_by_tag($_POST['body_text'], array("link", "style", "script"));
            if (strlen(trim($_POST['head'])) > 0) {
                $_POST['use_customized_head'] = 1;
            } else {
                $_POST['use_customized_head'] = 0;
            }
            $_POST['body_text'] = get_html_body($_POST['body_text']);
            $msg->addFeedback('FILE_PASTED');
        } else {
            if ($ext == 'txt') {
                $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
                $msg->addFeedback('FILE_PASTED');
            }
        }
    } else {
        $msg->addError('BAD_FILE_TYPE');
    }
    return;
}