Ejemplo n.º 1
0
$ctx_id = optional_param('ctx_id', SITEID, PARAM_INT);
// context ID
$repo_id = optional_param('repo_id', 1, PARAM_INT);
// repository ID
$req_path = optional_param('p', '', PARAM_RAW);
// path
$save_path = optional_param('savepath', '/', PARAM_PATH);
$callback = optional_param('callback', '', PARAM_CLEANHTML);
$search_text = optional_param('s', '', PARAM_CLEANHTML);
/// Headers to make it not cacheable
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$err = new stdclass();
$err->client_id = $client_id;
/// Check permissions
if (!(isloggedin() && repository::check_context($ctx_id))) {
    $err->e = get_string('nopermissiontoaccess', 'repository');
    die(json_encode($err));
}
/// Wait as long as it takes for this script to finish
set_time_limit(0);
/// Check for actions that do not need repository ID
switch ($action) {
    // delete a file from filemanger
    case 'delete':
        try {
            if (!($context = get_context_instance(CONTEXT_USER, $USER->id))) {
            }
            $contextid = $context->id;
            $fs = get_file_storage();
            if ($file = $fs->get_file($contextid, 'user_draft', $itemid, '/', $title)) {
Ejemplo n.º 2
0
$imgurl = optional_param('url', '', PARAM_URL);
if (empty($imgurl)) {
    $imgurl = '-';
}
$imgdataurl = required_param('dataURL', PARAM_RAW);
$draftitemid = optional_param('draftitemid', '', PARAM_INT);
if (empty($draftitemid)) {
    $draftitemid = (int) substr(hexdec(uniqid()), 0, 9) + rand(1, 100);
}
$context = get_context_instance(CONTEXT_USER, $USER->id);
$contextid = optional_param('contextid', SITEID, PARAM_INT);
$imgurlnew = null;
if (empty($contextid)) {
    $contextid = $context->id;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isloggedin() || !repository::check_context($contextid)) {
    paintweb_send_result($imgurl, $imgurlnew, false, get_string('moodleServer:permissionDenied', 'paintweb'));
}
if (empty($imgdataurl)) {
    paintweb_send_result($imgurl, $imgurlnew, false, get_string('moodleServer:saveEmptyDataUrl', 'paintweb'));
}
// A data URL starts like this:
// data:[<MIME-type>][;charset="<encoding>"][;base64],<data>
// See details at:
// http://en.wikipedia.org/wiki/Data_URI_scheme
$mimetype = 'text/plain';
$base64data = '';
$regex = '/^data:([^;,]+);base64,(.+)$/';
$matches = array();
if (preg_match($regex, $imgdataurl, $matches)) {
    $mimetype = $matches[1];