Using PHP In PLace of Page Content

Re: Using PHP In PLace of Page Content

by PLAYlive Admin -
Number of replies: 0

Thanks for the replies. I didn't check back in this thread early enough before continuing on with my own implementation. It's messy but it works. Here's what I did:

1. Open /moodle/mod/page/view.php
2. Somewhere early in the page add this function:

function safe_string_sanitize($str) {
    $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
    $clean = strtolower(trim($clean, '-'));
    $clean = preg_replace("/[\/_|+ -]+/", '-', $clean);

    return $clean;
}

3. Find the line "echo $OUTPUT->box($content, "generalbox center clearfix");"

4. Replace with:

$dyn_content = $CFG->dirroot . '/dynamic/' . safe_string_sanitize($course->shortname) . '/' . safe_string_sanitize($page->name) . '.php';
if (file_exists($dyn_content)) {
    include($dyn_content);
} else {
    echo $OUTPUT->box($content, "generalbox center clearfix");
}

5. Place the content for your page in "/moodle/dynamic/{course-shortname}/{course-name}.php"

This is just my quick hackish method. Maybe in the future I'll take the time to write a legitimate plugin. I'd love to be able to drop PHP files in course folders and have the site list them as pages but that's for another day.