コード例 #1
0
/**
 * @param $id
 * @throws coding_exception
 */
function get_tab_content($id)
{
    global $DB, $CFG, $tab, $context, $appresponse;
    $appresponse->header('Content-Type', 'application/json');
    $editoroptions = array('subdirs' => 1, 'maxbytes' => $CFG->maxbytes, 'maxfiles' => -1, 'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => true);
    $content = $DB->get_record('tab_content', array('id' => $id));
    $externalurl = $content->externalurl;
    $fileattachment = $content->fileattachment;
    // DR: we need to know if there are files associated with [$index]th tab.
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_tab', 'fileattachment', $content->id, false, false);
    $file = reset($files);
    if (!empty($externalurl)) {
        if (!preg_match('{https?:\\/\\/}', $externalurl)) {
            $externalurl = 'http://' . $externalurl;
        }
    } else {
        if ($file) {
            $filepath = $file->get_filepath();
            $filename = $file->get_filename();
            $fileurlfrewrite = file_rewrite_pluginfile_urls("@@PLUGINFILE@@/" . $file->get_filename(), 'pluginfile.php', $context->id, 'mod_tab', 'fileattachment', $content->id);
            $externalurl = $fileurlfrewrite;
        } else {
            if (empty($content->format)) {
                $content->format = 1;
            }
            $contenttemp = file_rewrite_pluginfile_urls($content->tabcontent, 'pluginfile.php', $context->id, 'mod_tab', 'content', $content->id);
            $content = format_text($contenttemp, $content->format, $editoroptions, $context);
        }
    }
    // Enter into proper div.
    if (!empty($externalurl)) {
        $htmlcontent = tab_embed_general(process_urls($externalurl), '', get_string('embed_fail_msg', 'tab') . "<a href='{$externalurl}' target='_blank' >" . get_string('embed_fail_link_text', 'tab') . '</a>', $file ? $file->get_mimetype() : 'text/html');
    } else {
        $htmlcontent = $content;
    }
    echo json_encode(array("content" => base64_encode($htmlcontent)));
}
コード例 #2
0
    //Eventually give option for height within the form. Pass this by others, because it could be confusing.
    $iframehieght[$key] = '600px';
    if (!empty($externalurl[$key])) {
        //todo check url
        if (!preg_match('{https?:\\/\\/}', $externalurl[$key])) {
            $externalurl[$key] = 'http://' . $externalurl[$key];
        }
    } else {
        if (empty($options[$key]->format)) {
            $options[$key]->format = 1;
        }
        $content[$key] = file_rewrite_pluginfile_urls($options[$key]->tabcontent, 'pluginfile.php', $context->id, 'mod_tab', 'content', $options[$key]->id);
        $content[$key] = format_text($content[$key], FORMAT_MOODLE, $editoroptions, $context);
    }
    //Enter into proper div
    //Check for pdf
    if (!empty($externalurl[$key]) && preg_match('/\\bpdf\\b/i', $externalurl[$key])) {
        debugging("Tabdisplay: Found pdf->external_url=" . $externalurl[$key], DEBUG_DEVELOPER);
        $html_content = tab_embed_general(process_urls($externalurl[$key]), '', get_string('embed_fail_msg', 'tab') . "<a href='{$externalurl[$key]}' target='_blank' >" . get_string('embed_fail_link_text', 'tab') . '</a>', 'application/pdf');
    } elseif (!empty($externalurl[$key])) {
        $html_content = tab_embed_general(process_urls($externalurl[$key]), '', get_string('embed_fail_msg', 'tab') . "<a href='{$externalurl[$key]}' target='_blank' >" . get_string('embed_fail_link_text', 'tab') . '</a>', 'text/html');
    } else {
        $html_content = $content[$key];
    }
    $tabdisplay .= '   <div class="TabbedPanelsContent"><p>' . $html_content . '</p></div>' . "\n";
}
$tabdisplay .= '	</div>' . "\n";
$tabdisplay .= '</div>' . "\n";
$tabdisplay .= '</div>' . "\n";
echo $tabdisplay;
echo $OUTPUT->footer();