Esempio n. 1
0
 /**
  * Obtains the filename from the moodle_url.
  * @param moodle_url $url URL
  * @return string Filename only (not escaped)
  */
 public function get_filename(moodle_url $url)
 {
     // Use the 'file' parameter if provided (for links created when
     // slasharguments was off). If not present, just use URL path.
     $path = $url->get_param('file');
     if (!$path) {
         $path = $url->get_path();
     }
     // Remove everything before last / if present. Does not use textlib as / is UTF8-safe.
     $slash = strrpos($path, '/');
     if ($slash !== false) {
         $path = substr($path, $slash + 1);
     }
     return $path;
 }
Esempio n. 2
0
/**
 * @global object
 * @param string $default
 * @return string
 */
function hsuforum_go_back_to($default)
{
    global $SESSION;
    if (!empty($SESSION->fromdiscussion) && (!defined(AJAX_SCRIPT) || !AJAX_SCRIPT)) {
        // If we have an ajax fromdiscussion session variable then we need to get rid of it because this is not an
        // ajax page and we will end up redirecting incorrectly to route.php.
        $murl = new moodle_url($SESSION->fromdiscussion);
        $path = $murl->get_path();
        if (strpos($path, '/mod/hsuforum/route.php') === 0) {
            // OK - this is bad, we are not using AJAX but the redirect url is an AJAX url, so kill it.
            unset($SESSION->fromdiscussion);
        }
    }
    if (!empty($SESSION->fromdiscussion)) {
        $returnto = $SESSION->fromdiscussion;
        unset($SESSION->fromdiscussion);
        return $returnto;
    } else {
        return $default;
    }
}
 /**
  * Tests moodle_url::get_path().
  */
 public function test_moodle_url_get_path()
 {
     $url = new moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
     $this->assertSame('/my/file/is/here.txt', $url->get_path());
     $url = new moodle_url('http://www.example.org/');
     $this->assertSame('/', $url->get_path());
     $url = new moodle_url('http://www.example.org/pluginfile.php/slash/arguments');
     $this->assertSame('/pluginfile.php/slash/arguments', $url->get_path());
     $this->assertSame('/pluginfile.php', $url->get_path(false));
 }
Esempio n. 4
0
/**
 * Returns navigation controls (tabtree) to be displayed on cohort management pages
 *
 * @param context $context system or category context where cohorts controls are about to be displayed
 * @param moodle_url $currenturl
 * @return null|renderable
 */
function cohort_edit_controls(context $context, moodle_url $currenturl)
{
    $tabs = array();
    $currenttab = 'view';
    $viewurl = new moodle_url('/cohort/index.php', array('contextid' => $context->id));
    if ($searchquery = $currenturl->get_param('search')) {
        $viewurl->param('search', $searchquery);
    }
    if ($context->contextlevel == CONTEXT_SYSTEM) {
        $tabs[] = new tabobject('view', new moodle_url($viewurl, array('showall' => 0)), get_string('systemcohorts', 'cohort'));
        $tabs[] = new tabobject('viewall', new moodle_url($viewurl, array('showall' => 1)), get_string('allcohorts', 'cohort'));
        if ($currenturl->get_param('showall')) {
            $currenttab = 'viewall';
        }
    } else {
        $tabs[] = new tabobject('view', $viewurl, get_string('cohorts', 'cohort'));
    }
    if (has_capability('moodle/cohort:manage', $context)) {
        $addurl = new moodle_url('/cohort/edit.php', array('contextid' => $context->id));
        $tabs[] = new tabobject('addcohort', $addurl, get_string('addcohort', 'cohort'));
        if ($currenturl->get_path() === $addurl->get_path() && !$currenturl->param('id')) {
            $currenttab = 'addcohort';
        }
        $uploadurl = new moodle_url('/cohort/upload.php', array('contextid' => $context->id));
        $tabs[] = new tabobject('uploadcohorts', $uploadurl, get_string('uploadcohorts', 'cohort'));
        if ($currenturl->get_path() === $uploadurl->get_path()) {
            $currenttab = 'uploadcohorts';
        }
    }
    if (count($tabs) > 1) {
        return new tabtree($tabs, $currenttab);
    }
    return null;
}