示例#1
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;
}
 // 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) {
     // replace glossary content package links to real glossary mark-up using [?] [/?]
     // refer to bug 3641, edited by Harris
     $content = preg_replace('/<a href="([.\\w\\d\\s]+[^"]+)" target="body" class="at-term">([.\\w\\d\\s&;"]+|.*)<\\/a>/i', '[?]\\2[/?]', $content);
 }
 /* potential security risk? */
 if (strpos($content_info['href'], '..') === false && !preg_match('/((.*)\\/)*tests\\_[0-9]+\\.xml$/', $content_info['href'])) {
     //				@unlink(AT_CONTENT_DIR . 'import/'.$_SESSION['course_id'].'/'.$content_info['href']);
 }
 /* overwrite content if this is discussion tool. */
 if ($content_info['type'] == 'imsdt_xmlv1p0') {
     $dt_parser = new DiscussionToolsParser();
     $xml_content = @file_get_contents($import_path . $content_info['href']);
     $dt_parser->parse($xml_content);
     $forum_obj = $dt_parser->getDt();
示例#4
0
 case 'save_template_item':
     $task = 'template_item';
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $name = trim($_POST['name']);
         if ($name == '') {
             $feedback = '<p class="Error">' . $error_missing_field . '</p>';
         } else {
             if (isset($_FILES['content_file']) && is_uploaded_file($_FILES['content_file']['tmp_name'])) {
                 $fp = fopen($_FILES['content_file']['tmp_name'], 'r');
                 $_POST['content'] = addslashes(fread($fp, $_FILES['content_file']['size']));
                 fclose($fp);
                 unlink($_FILES['content_file']['tmp_name']);
             } else {
                 $_POST['content'] = smart_addslashes($_POST['content']);
             }
             $content = get_html_body($_POST['content']);
             $template_item_id = isset($_POST['template_item_id']) ? $_POST['template_item_id'] : 0;
             if ($template_item_id > 0) {
                 if ($template_item = $cms->get_template_by_name($template_id, $name) && $template_item['id'] != $template_item_id) {
                     $feedback = '<p class="Error">' . $fbNameExists . '</p>';
                 } else {
                     if (!$cms->update_template_item($template_item_id, $name, $_POST['content'])) {
                         $feedback = '<p class="Error">' . $strSaveError . '</p>';
                     }
                 }
             } else {
                 if ($cms->get_template_item_by_name($template_id, $name)) {
                     $feedback = '<p class="Error">' . $fbNameExists . '</p>';
                 } else {
                     if (!($template_item_id = $cms->add_template_item($template_id, $name, $_POST['content']))) {
                         $feedback = '<p class="Error">' . $strSaveError . '</p>';