sakthi
sakthi

Reputation: 21

Is it possible to display a moodle site inside iframe?

I am trying to integrate moodle with my own PHP application. Is it possible to display a moodle site within a iframe?

Upvotes: 2

Views: 9118

Answers (2)

thundorstorm
thundorstorm

Reputation: 329

My problem was that I could save an iframe in the editor, but that iframe was stripped upon later edit. If you're experiencing problems embedding the iframe in blogs or forums, here is a piece of code that I used in moodle 3.9.1: edit config.php, search for

require_once(__DIR__ . '/lib/setup.php');

then exaclty under it put the following code:

$script_file = realpath($_SERVER['SCRIPT_FILENAME']);
if($script_file){
    $script_file_rel_path = substr($script_file,strlen(__DIR__));
    if(strpos($script_file_rel_path,'/edit.php') !== false){
        $sitecontext = context_system::instance();
        if(has_capability('moodle/site:trustcontent',$sitecontext)){
            require_once __DIR__ . '/lib/htmlpurifier/HTMLPurifier.safe-includes.php';
            require_once __DIR__ . '/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php';
            $definition = HTMLPurifier_ConfigSchema::instance();
            $definition->add('HTML.SafeIframe', true, 'bool', true);
            // Only allow urls from subdomains of google.com and youtube.com
            $definition->add('URI.SafeIframeRegexp', '/:\/\/([^\/]*?)(\.(google|youtube)\.com)\//','string', true);
            // Uncomment the following and remove previous line in order to allow any url in the "src" attribute
            // $definition->add('URI.SafeIframeRegexp', '//','string', true);
        }
    }
}

What this does is: users that have the capability: moodle/site:trustcontent in the system, when accessing edit.php links (editing pages) will be able to embed iframes in their texts editors with urls from specific domains.

Upvotes: 0

rlorenzo
rlorenzo

Reputation: 1368

In your Site administration, check out the config variable "allowframembedding". It is in Site administration > Security > HTTP security.

By default "Allow frame embedding" is set to "No", just click on the checkbox to enable Moodle to be embedded in an iframe.

Upvotes: 4

Related Questions