Example #1
0
 /**
  * General moodle file url.
  * @param string $urlbase the script serving the file
  * @param string $path
  * @param bool $forcedownload
  * @return moodle_url
  */
 public static function make_file_url($urlbase, $path, $forcedownload = false)
 {
     global $CFG;
     $params = array();
     if ($forcedownload) {
         $params['forcedownload'] = 1;
     }
     $url = new moodle_url($urlbase, $params);
     $url->set_slashargument($path);
     return $url;
 }
 /**
  * Returns the actual url through which a script is served.
  *
  * @param moodle_url|string $url full moodle url, or shortened path to script
  * @return moodle_url
  */
 protected function js_fix_url($url)
 {
     global $CFG;
     if ($url instanceof moodle_url) {
         return $url;
     } else {
         if (strpos($url, '/') === 0) {
             // Fix the admin links if needed.
             if ($CFG->admin !== 'admin') {
                 if (strpos($url, "/admin/") === 0) {
                     $url = preg_replace("|^/admin/|", "/{$CFG->admin}/", $url);
                 }
             }
             if (debugging()) {
                 // Check file existence only when in debug mode.
                 if (!file_exists($CFG->dirroot . strtok($url, '?'))) {
                     throw new coding_exception('Attempt to require a JavaScript file that does not exist.', $url);
                 }
             }
             if (!empty($CFG->cachejs) and !empty($CFG->jsrev) and $CFG->jsrev > 0 and substr($url, -3) === '.js') {
                 if (empty($CFG->slasharguments)) {
                     return new moodle_url($CFG->httpswwwroot . '/lib/javascript.php', array('rev' => $CFG->jsrev, 'jsfile' => $url));
                 } else {
                     $returnurl = new moodle_url($CFG->httpswwwroot . '/lib/javascript.php');
                     $returnurl->set_slashargument('/' . $CFG->jsrev . $url);
                     return $returnurl;
                 }
             } else {
                 return new moodle_url($CFG->httpswwwroot . $url);
             }
         } else {
             throw new coding_exception('Invalid JS url, it has to be shortened url starting with / or moodle_url instance.', $url);
         }
     }
 }
 /**
  * Returns js code to load amd module loader, then insert inline script tags
  * that contain require() calls using RequireJS.
  * @return string
  */
 protected function get_amd_footercode()
 {
     global $CFG;
     $output = '';
     $jsrev = $this->get_jsrev();
     $jsloader = new moodle_url($CFG->httpswwwroot . '/lib/javascript.php');
     $jsloader->set_slashargument('/' . $jsrev . '/');
     $requirejsloader = new moodle_url($CFG->httpswwwroot . '/lib/requirejs.php');
     $requirejsloader->set_slashargument('/' . $jsrev . '/');
     $requirejsconfig = file_get_contents($CFG->dirroot . '/lib/requirejs/moodle-config.js');
     // No extension required unless slash args is disabled.
     $jsextension = '.js';
     if (!empty($CFG->slasharguments)) {
         $jsextension = '';
     }
     $requirejsconfig = str_replace('[BASEURL]', $requirejsloader, $requirejsconfig);
     $requirejsconfig = str_replace('[JSURL]', $jsloader, $requirejsconfig);
     $requirejsconfig = str_replace('[JSEXT]', $jsextension, $requirejsconfig);
     $output .= html_writer::script($requirejsconfig);
     if ($CFG->debugdeveloper) {
         $output .= html_writer::script('', $this->js_fix_url('/lib/requirejs/require.js'));
     } else {
         $output .= html_writer::script('', $this->js_fix_url('/lib/requirejs/require.min.js'));
     }
     // First include must be to a module with no dependencies, this prevents multiple requests.
     $prefix = "require(['core/first'], function() {\n";
     $suffix = "\n});";
     $output .= html_writer::script($prefix . implode(";\n", $this->amdjscode) . $suffix);
     return $output;
 }
 /**
  * Return the URL for a font
  *
  * @param string $font the name of the font (including extension).
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function font_url($font, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name);
     if (empty($component) or $component === 'moodle' or $component === 'core') {
         $params['component'] = 'core';
     } else {
         $params['component'] = $component;
     }
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     $params['font'] = $font;
     $url = new moodle_url("{$CFG->httpswwwroot}/theme/font.php");
     if (!empty($CFG->slasharguments) and $rev > 0) {
         $path = '/' . $params['theme'] . '/' . $params['component'] . '/' . $params['rev'] . '/' . $params['font'];
         $url->set_slashargument($path, 'noparam', true);
     } else {
         $url->params($params);
     }
     return $url;
 }
Example #5
0
 /**
  * Return the URL for an image
  *
  * @param string $imagename the name of the icon.
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function pix_url($imagename, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name);
     $svg = $this->use_svg_icons();
     if (empty($component) or $component === 'moodle' or $component === 'core') {
         $params['component'] = 'core';
     } else {
         $params['component'] = $component;
     }
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     $params['image'] = $imagename;
     $url = new moodle_url("{$CFG->httpswwwroot}/theme/image.php");
     if (!empty($CFG->slasharguments) and $rev > 0) {
         $path = '/' . $params['theme'] . '/' . $params['component'] . '/' . $params['rev'] . '/' . $params['image'];
         if (!$svg) {
             // We add a simple /_s to the start of the path.
             // The underscore is used to ensure that it isn't a valid theme name.
             $path = '/_s' . $path;
         }
         $url->set_slashargument($path, 'noparam', true);
     } else {
         if (!$svg) {
             // We add an SVG param so that we know not to serve SVG images.
             // We do this because all modern browsers support SVG and this param will one day be removed.
             $params['svg'] = '0';
         }
         $url->params($params);
     }
     return $url;
 }
Example #6
0
 * @subpackage tinymce
 * @copyright 1999 onwards Martin Dougiamas   {@link http://moodle.com}
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require dirname(__FILE__) . '/../../../../../../../config.php';
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/editorlib.php';
require_once $CFG->libdir . '/editor/tinymce/lib.php';
// Must be logged in
require_login();
// Require path to draftfile.php file
$path = required_param('path', PARAM_PATH);
$editor = new tinymce_texteditor();
// Now output this file which is super-simple
$PAGE->set_pagelayout('embedded');
$PAGE->set_url(new moodle_url('/lib/editor/tinymce/tiny_mce/' . $editor->version . '/plugins/moodlemedia/preview.php', array('path' => $path)));
$PAGE->set_context(context_system::instance());
$PAGE->add_body_class('core_media_preview');
echo $OUTPUT->header();
$mediarenderer = $PAGE->get_renderer('core', 'media');
$path = '/' . trim($path, '/');
if (empty($CFG->slasharguments)) {
    $url = new moodle_url('/draftfile.php', array('file' => $path));
} else {
    $url = new moodle_url('/draftfile.php');
    $url->set_slashargument($path);
}
if ($mediarenderer->can_embed_url($url)) {
    echo $mediarenderer->embed_url($url);
}
echo $OUTPUT->footer();