Beispiel #1
0
/**
 * Upgrade function.
 *
 * @param int $oldversion the version we are upgrading from.
 * @return bool result
 */
function xmldb_repository_alfresco_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2014020301) {
        require_once $CFG->dirroot . '/repository/lib.php';
        require_once $CFG->dirroot . '/repository/alfresco/db/upgradelib.php';
        $params = array();
        $params['context'] = array();
        $params['onlyvisible'] = false;
        $params['type'] = 'alfresco';
        $instances = repository::get_instances($params);
        // Notify the admin about the migration process if they are using the repo.
        if (!empty($instances)) {
            repository_alfresco_admin_security_key_notice();
        }
        upgrade_plugin_savepoint(true, 2014020301, 'repository', 'alfresco');
    }
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
 public function toHtml()
 {
     global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
     $id = $this->_attributes['id'];
     $elname = $this->_attributes['name'];
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     if (!($draftitemid = (int) $this->getValue())) {
         // no existing area info provided - let's use fresh new draft area
         $draftitemid = file_get_unused_draft_itemid();
         $this->setValue($draftitemid);
     }
     if ($COURSE->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($COURSE->id);
     }
     $client_id = uniqid();
     $args = new stdClass();
     // Need these three to filter repositories list.
     $args->accepted_types = $this->_options['accepted_types'] ? $this->_options['accepted_types'] : '*';
     $args->return_types = $this->_options['return_types'];
     $args->itemid = $draftitemid;
     $args->maxbytes = 0;
     $args->context = $PAGE->context;
     $args->buttonname = $elname . 'choose';
     $args->elementname = $elname;
     // We can only tell the filepicker that we want FILE_REFERENCE repos
     // and which specific repo types we don't want. So here we build a list
     // of all FILE_REFERENCE supplying repos that aren't thebox to force
     // it to only display that one.
     $refrepos = repository::get_instances(array('currentcontext' => $PAGE->context, 'return_types' => FILE_REFERENCE));
     $disabled = array();
     foreach ($refrepos as $repo) {
         if (($name = $repo->get_typename()) != $this->repo) {
             $disabled[] = $name;
         }
     }
     $args->disable_types = $disabled;
     $html = $this->_getTabs();
     $fp = new file_picker($args);
     $options = $fp->options;
     $options->context = $PAGE->context;
     $html .= $OUTPUT->render($fp);
     $html .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" value="' . $draftitemid . '" class="filepickerhidden"/>';
     $module = array('name' => 'form_filepicker', 'fullpath' => '/lib/form/filepicker.js', 'requires' => array('core_filepicker', 'node', 'node-event-simulate', 'core_dndupload'));
     $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
     $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array('env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, 'subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1, 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey()));
     // non js file picker
     $html .= '<noscript>';
     $html .= "<div><object type='text/html' data='{$nonjsfilepicker}' height='160' width='600' style='border:1px solid #000'></object></div>";
     $html .= '</noscript>';
     return $html;
 }
Beispiel #3
0
/**
 * Upgrade function.
 *
 * @param int $oldversion the version we are upgrading from.
 * @return bool result
 */
function xmldb_repository_boxnet_upgrade($oldversion)
{
    global $CFG, $DB;
    $dbman = $DB->get_manager();
    if ($oldversion < 2013110503) {
        // Delete old user preferences containing auth tokens.
        $DB->delete_records('user_preferences', array('name' => 'boxnet__auth_token'));
        upgrade_plugin_savepoint(true, 2013110503, 'repository', 'boxnet');
    }
    if ($oldversion < 2013110700) {
        require_once $CFG->dirroot . '/repository/lib.php';
        require_once $CFG->dirroot . '/repository/boxnet/db/upgradelib.php';
        $clientid = get_config('boxnet', 'clientid');
        $clientsecret = get_config('boxnet', 'clientsecret');
        // Only proceed if the repository hasn't been set for APIv2 yet.
        if ($clientid === false && $clientsecret === false) {
            $params = array();
            $params['context'] = array();
            $params['onlyvisible'] = false;
            $params['type'] = 'boxnet';
            $instances = repository::get_instances($params);
            // Notify the admin about the migration process if they are using the repo.
            if (!empty($instances)) {
                repository_boxnet_admin_upgrade_notification();
            }
            // Hide the repository.
            $repositorytype = repository::get_type_by_typename('boxnet');
            if (!empty($repositorytype)) {
                $repositorytype->update_visibility(false);
            }
        }
        upgrade_plugin_savepoint(true, 2013110700, 'repository', 'boxnet');
    }
    // Moodle v2.6.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.7.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.8.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v2.9.0 release upgrade line.
    // Put any upgrade step following this.
    // Moodle v3.0.0 release upgrade line.
    // Put any upgrade step following this.
    return true;
}
    /**
     * Returns HTML for this form element.
     *
     * @return string
     */
    function toHtml()
    {
        global $PAGE, $OUTPUT;
        $id = $this->_attributes['id'];
        $elname = $this->_attributes['name'];
        if ($this->_hiddenLabel) {
            $this->_generateId();
            $str = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
        } else {
            $str = HTML_QuickForm_Text::toHtml();
        }
        if (empty($this->_options['usefilepicker'])) {
            return $str;
        }
        $client_id = uniqid();
        $args = new stdClass();
        $args->accepted_types = '*';
        $args->return_types = FILE_EXTERNAL;
        $args->context = $PAGE->context;
        $args->client_id = $client_id;
        $args->env = 'url';
        $refrepos = repository::get_instances(array('currentcontext' => $PAGE->context, 'return_types' => FILE_EXTERNAL));
        $disabled = array();
        foreach ($refrepos as $repo) {
            if (($name = $repo->get_typename()) != $this->_options['repo']) {
                $disabled[] = $name;
            }
        }
        $args->disable_types = $disabled;
        $fp = new file_picker($args);
        $options = $fp->options;
        if (count($options->repositories) > 0) {
            $straddlink = get_string('choosealink', 'repository');
            $str .= <<<EOD
<button id="filepicker-button-{$client_id}" class="visibleifjs">
{$straddlink}
</button>
EOD;
        }
        // print out file picker
        $str .= $OUTPUT->render($fp);
        $module = array('name' => 'form_url', 'fullpath' => '/lib/form/url.js', 'requires' => array('core_filepicker'));
        $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module);
        return $str;
    }
 /**
  * Installing repository tests
  *
  * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
  */
 public function test_install_repository()
 {
     global $CFG, $DB;
     $this->resetAfterTest(true);
     $syscontext = context_system::instance();
     $repositorypluginname = 'boxnet';
     // override repository permission
     $capability = 'repository/' . $repositorypluginname . ':view';
     $allroles = $DB->get_records_menu('role', array(), 'id', 'archetype, id');
     assign_capability($capability, CAP_ALLOW, $allroles['guest'], $syscontext->id, true);
     $plugintype = new repository_type($repositorypluginname);
     $pluginid = $plugintype->create(false);
     $this->assertInternalType('int', $pluginid);
     $args = array();
     $args['type'] = $repositorypluginname;
     $repos = repository::get_instances($args);
     $repository = reset($repos);
     $this->assertInstanceOf('repository', $repository);
     $info = $repository->get_meta();
     $this->assertEquals($repositorypluginname, $info->type);
 }
Beispiel #6
0
 /**
  * Testing deleting original files.
  *
  * @copyright 2012 Dongsheng Cai {@link http://dongsheng.org}
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 public function test_delete_original_file_from_draft()
 {
     global $USER, $DB;
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     $user = $generator->create_user();
     $usercontext = context_user::instance($user->id);
     $USER = $DB->get_record('user', array('id' => $user->id));
     $repositorypluginname = 'user';
     $args = array();
     $args['type'] = $repositorypluginname;
     $repos = repository::get_instances($args);
     $userrepository = reset($repos);
     $this->assertInstanceOf('repository', $userrepository);
     $fs = get_file_storage();
     $syscontext = context_system::instance();
     $filecontent = 'User file content';
     // Create a user private file.
     $userfilerecord = new stdClass();
     $userfilerecord->contextid = $usercontext->id;
     $userfilerecord->component = 'user';
     $userfilerecord->filearea = 'private';
     $userfilerecord->itemid = 0;
     $userfilerecord->filepath = '/';
     $userfilerecord->filename = 'userfile.txt';
     $userfilerecord->source = 'test';
     $userfile = $fs->create_file_from_string($userfilerecord, $filecontent);
     $userfileref = $fs->pack_reference($userfilerecord);
     $contenthash = $userfile->get_contenthash();
     $filerecord = array('contextid' => $syscontext->id, 'component' => 'core', 'filearea' => 'phpunit', 'itemid' => 0, 'filepath' => '/', 'filename' => 'test.txt');
     // Create a file reference.
     $fileref = $fs->create_file_from_reference($filerecord, $userrepository->id, $userfileref);
     $this->assertInstanceOf('stored_file', $fileref);
     $this->assertEquals($userrepository->id, $fileref->get_repository_id());
     $this->assertSame($userfile->get_contenthash(), $fileref->get_contenthash());
     $this->assertEquals($userfile->get_filesize(), $fileref->get_filesize());
     $this->assertRegExp('#' . $userfile->get_filename() . '$#', $fileref->get_reference_details());
     $draftitemid = 0;
     file_prepare_draft_area($draftitemid, $usercontext->id, 'user', 'private', 0);
     $draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid);
     $this->assertCount(2, $draftfiles);
     $draftfile = $fs->get_file($usercontext->id, 'user', 'draft', $draftitemid, $userfilerecord->filepath, $userfilerecord->filename);
     $draftfile->delete();
     // Save changed file.
     file_save_draft_area_files($draftitemid, $usercontext->id, 'user', 'private', 0);
     // The file reference should be a regular moodle file now.
     $fileref = $fs->get_file($syscontext->id, 'core', 'phpunit', 0, '/', 'test.txt');
     $this->assertFalse($fileref->is_external_file());
     $this->assertSame($contenthash, $fileref->get_contenthash());
     $this->assertEquals($filecontent, $fileref->get_content());
 }
Beispiel #7
0
    /**
     * Add Plugin settings input to Moodle form
     *
     * @param moodleform $mform
     * @param string $classname
     */
    public static function type_config_form($mform, $classname = 'repository') {
        global $CFG;
        parent::type_config_form($mform);
        $public_account = get_config('boxnet', 'public_account');
        $api_key = get_config('boxnet', 'api_key');
        if (empty($api_key)) {
            $api_key = '';
        }
        $strrequired = get_string('required');
        $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'), array('value'=>$api_key,'size' => '40'));
        $mform->addRule('api_key', $strrequired, 'required', null, 'client');
        $mform->addElement('static', null, '',  get_string('information','repository_boxnet'));

        //retrieve the flickr instances
        $params = array();
        $params['context'] = array();
        //$params['currentcontext'] = $this->context;
        $params['onlyvisible'] = false;
        $params['type'] = 'boxnet';
        $instances = repository::get_instances($params);
        if (empty($instances)) {
            $callbackurl = get_string('callbackwarning', 'repository_boxnet');
            $mform->addElement('static', null, '',  $callbackurl);
        } else {
            $instance = array_shift($instances);
            $callbackurl = $CFG->wwwroot.'/repository/repository_callback.php?repo_id='.$instance->id;
            $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_boxnet', $callbackurl));
        }
    }
Beispiel #8
0
                 echo $client_id;
             } else {
                 echo '';
             }
         } else {
             echo '';
         }
         exit;
     } catch (repository_exception $e) {
         $err->e = $e->getMessage();
         die(json_encode($err));
     }
     break;
 case 'gsearch':
     //  Global Search
     $repos = repository::get_instances(array(get_context_instance_by_id($ctx_id), get_system_context()));
     $list = array();
     foreach ($repos as $repo) {
         if ($repo->global_search()) {
             try {
                 $ret = $repo->search($search_text);
                 array_walk($ret['list'], 'repository_attach_id', $repo->id);
                 // See function below
                 $tmp = array_merge($list, $ret['list']);
                 $list = $tmp;
             } catch (repository_exception $e) {
                 $err->e = $e->getMessage();
                 die(json_encode($err));
             }
         }
     }
Beispiel #9
0
 /**
  * Display a repository instance list (with edit/delete/create links)
  * @global object $CFG
  * @global object $USER
  * @param object $context the context for which we display the instance
  * @param string $typename if set, we display only one type of instance
  */
 public static function display_instances_list($context, $typename = null)
 {
     global $CFG, $USER, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     //if the context is SYSTEM, so we call it from administration page
     $admin = $context->id == SYSCONTEXTID ? true : false;
     if ($admin) {
         $baseurl = "{$CFG->httpswwwroot}/{$CFG->admin}/repositoryinstance.php?sesskey=" . sesskey();
         $output .= "<div ><h2 style='text-align: center'>" . get_string('siteinstances', 'repository') . " ";
         $output .= "</h2></div>";
     } else {
         $baseurl = $CFG->httpswwwroot . '/repository/manage_instances.php?contextid=' . $context->id . '&amp;sesskey=' . sesskey();
     }
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'repository');
     $settingsstr = get_string('settings');
     $deletestr = get_string('delete');
     $updown = get_string('updown', 'repository');
     //retrieve list of instances. In administration context we want to display all
     //instances of a type, even if this type is not visible. In course/user context we
     //want to display only visible instances, but for every type types. The repository_get_instances()
     //third parameter displays only visible type.
     $instances = repository::get_instances(array($context), null, !$admin, $typename);
     $instancesnumber = count($instances);
     $alreadyplugins = array();
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, $deletestr, $settingsstr);
     $table->align = array('left', 'left', 'center', 'center');
     $table->data = array();
     $updowncount = 1;
     foreach ($instances as $i) {
         $settings = '';
         $delete = '';
         $settings .= '<a href="' . $baseurl . '&amp;type=' . $typename . '&amp;edit=' . $i->id . '">' . $settingsstr . '</a>' . "\n";
         if (!$i->readonly) {
             $delete .= '<a href="' . $baseurl . '&amp;type=' . $typename . '&amp;delete=' . $i->id . '">' . $deletestr . '</a>' . "\n";
         }
         $type = repository::get_type_by_id($i->options['typeid']);
         $table->data[] = array($i->name, $type->get_readablename(), $delete, $settings);
         //display a grey row if the type is defined as not visible
         if (isset($type) && !$type->get_visible()) {
             $table->rowclasses[] = 'dimmed_text';
         } else {
             $table->rowclasses[] = '';
         }
         if (!in_array($i->name, $alreadyplugins)) {
             $alreadyplugins[] = $i->name;
         }
     }
     $output .= $OUTPUT->table($table);
     $instancehtml = '<div>';
     $addable = 0;
     //if no type is set, we can create all type of instance
     if (!$typename) {
         $instancehtml .= '<h3>';
         $instancehtml .= get_string('createrepository', 'repository');
         $instancehtml .= '</h3><ul>';
         $types = repository::get_editable_types($context);
         foreach ($types as $type) {
             if (!empty($type) && $type->get_visible()) {
                 $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                 if (!empty($instanceoptionnames)) {
                     $instancehtml .= '<li><a href="' . $baseurl . '&amp;new=' . $type->get_typename() . '">' . get_string('createxxinstance', 'repository', get_string('repositoryname', 'repository_' . $type->get_typename())) . '</a></li>';
                     $addable++;
                 }
             }
         }
         $instancehtml .= '</ul>';
     } else {
         $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
         if (!empty($instanceoptionnames)) {
             //create a unique type of instance
             $addable = 1;
             $instancehtml .= "<form action='" . $baseurl . "&amp;new=" . $typename . "' method='post'>\n                    <p style='text-align:center'><input type='submit' value='" . get_string('createinstance', 'repository') . "'/></p>\n                    </form>";
         }
     }
     if ($addable) {
         $instancehtml .= '</div>';
         $output .= $instancehtml;
     }
     $output .= $OUTPUT->box_end();
     //print the list + creation links
     print $output;
 }
Beispiel #10
0
 /**
  * Calling stored_file::delete_reference() on a reference file does not affect other
  * symlinks to the same original
  */
 public function test_delete_reference_one_symlink_does_not_rule_them_all()
 {
     $this->resetAfterTest(true);
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $repo = reset($repos);
     // create two aliases linking the same original
     $originalfile = null;
     foreach ($fs->get_area_files($user->ctxid, 'user', 'private') as $areafile) {
         if (!$areafile->is_directory()) {
             $originalfile = $areafile;
             break;
         }
     }
     $this->assertInstanceOf('stored_file', $originalfile);
     // calling delete_reference() on a non-reference file
     $originalrecord = array('contextid' => $originalfile->get_contextid(), 'component' => $originalfile->get_component(), 'filearea' => $originalfile->get_filearea(), 'itemid' => $originalfile->get_itemid(), 'filepath' => $originalfile->get_filepath(), 'filename' => $originalfile->get_filename());
     $aliasrecord = $this->generate_file_record();
     $aliasrecord->filepath = '/A/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $aliasfile1 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     $aliasrecord->filepath = '/B/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $aliasfile2 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // refetch A/symlink.txt
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertTrue($symlink1->is_external_file());
     // unlink the A/symlink.txt
     $symlink1->delete_reference();
     $this->assertFalse($symlink1->is_external_file());
     // make sure that B/symlink.txt has not been affected
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertTrue($symlink2->is_external_file());
 }
Beispiel #11
0
    echo ' <input name="draftpath" type="hidden" value="'.s($draftpath).'" />';
    echo ' <input name="savepath" type="hidden" value="'.s($savepath).'" />';
    echo ' <input type="submit" value="'.s(get_string('download', 'repository')).'" />';
    echo '</div>';
    echo '</form>';
    echo $OUTPUT->footer();
    break;

default:
case 'plugins':
    $params = array();
    $params['context'] = array($user_context, get_system_context());
    $params['currentcontext'] = $PAGE->context;
    $params['return_types'] = FILE_INTERNAL;

    $repos = repository::get_instances($params);
    echo $OUTPUT->header();
    echo html_writer::link($home_url->out(false), get_string('backtodraftfiles', 'repository'));
    echo '<div>';
    echo '<ul>';
    foreach($repos as $repo) {
        $info = $repo->get_meta();

        $aurl = clone($url);
        $aurl->params(array('savepath'=>$savepath, 'action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));

        echo '<li>';
        echo '<img src="'.$info->icon.'" alt="'.$info->name.'" width="16" height="16" /> ';
        echo html_writer::link($aurl, $info->name);
        echo '</li>';
    }
Beispiel #12
0
 /**
  * Display a repository instance list (with edit/delete/create links)
  *
  * @static
  * @param stdClass $context the context for which we display the instance
  * @param string $typename if set, we display only one type of instance
  */
 public static function display_instances_list($context, $typename = null)
 {
     global $CFG, $USER, $OUTPUT;
     $output = $OUTPUT->box_start('generalbox');
     //if the context is SYSTEM, so we call it from administration page
     $admin = $context->id == SYSCONTEXTID ? true : false;
     if ($admin) {
         $baseurl = new moodle_url('/' . $CFG->admin . '/repositoryinstance.php', array('sesskey' => sesskey()));
         $output .= $OUTPUT->heading(get_string('siteinstances', 'repository'));
     } else {
         $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid' => $context->id, 'sesskey' => sesskey()));
     }
     $namestr = get_string('name');
     $pluginstr = get_string('plugin', 'repository');
     $settingsstr = get_string('settings');
     $deletestr = get_string('delete');
     // Retrieve list of instances. In administration context we want to display all
     // instances of a type, even if this type is not visible. In course/user context we
     // want to display only visible instances, but for every type types. The repository::get_instances()
     // third parameter displays only visible type.
     $params = array();
     $params['context'] = array($context);
     $params['currentcontext'] = $context;
     $params['return_types'] = 0;
     $params['onlyvisible'] = !$admin;
     $params['type'] = $typename;
     $instances = repository::get_instances($params);
     $instancesnumber = count($instances);
     $alreadyplugins = array();
     $table = new html_table();
     $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr);
     $table->align = array('left', 'left', 'center', 'center');
     $table->data = array();
     $updowncount = 1;
     foreach ($instances as $i) {
         $settings = '';
         $delete = '';
         $type = repository::get_type_by_id($i->options['typeid']);
         if ($type->get_contextvisibility($context)) {
             if (!$i->readonly) {
                 $settingurl = new moodle_url($baseurl);
                 $settingurl->param('type', $i->options['type']);
                 $settingurl->param('edit', $i->id);
                 $settings .= html_writer::link($settingurl, $settingsstr);
                 $deleteurl = new moodle_url($baseurl);
                 $deleteurl->param('delete', $i->id);
                 $deleteurl->param('type', $i->options['type']);
                 $delete .= html_writer::link($deleteurl, $deletestr);
             }
         }
         $type = repository::get_type_by_id($i->options['typeid']);
         $table->data[] = array(format_string($i->name), $type->get_readablename(), $settings, $delete);
         //display a grey row if the type is defined as not visible
         if (isset($type) && !$type->get_visible()) {
             $table->rowclasses[] = 'dimmed_text';
         } else {
             $table->rowclasses[] = '';
         }
         if (!in_array($i->name, $alreadyplugins)) {
             $alreadyplugins[] = $i->name;
         }
     }
     $output .= html_writer::table($table);
     $instancehtml = '<div>';
     $addable = 0;
     //if no type is set, we can create all type of instance
     if (!$typename) {
         $instancehtml .= '<h3>';
         $instancehtml .= get_string('createrepository', 'repository');
         $instancehtml .= '</h3><ul>';
         $types = repository::get_editable_types($context);
         foreach ($types as $type) {
             if (!empty($type) && $type->get_visible()) {
                 // If the user does not have the permission to view the repository, it won't be displayed in
                 // the list of instances. Hiding the link to create new instances will prevent the
                 // user from creating them without being able to find them afterwards, which looks like a bug.
                 if (!has_capability('repository/' . $type->get_typename() . ':view', $context)) {
                     continue;
                 }
                 $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                 if (!empty($instanceoptionnames)) {
                     $baseurl->param('new', $type->get_typename());
                     $instancehtml .= '<li><a href="' . $baseurl->out() . '">' . get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_' . $type->get_typename())) . '</a></li>';
                     $baseurl->remove_params('new');
                     $addable++;
                 }
             }
         }
         $instancehtml .= '</ul>';
     } else {
         $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
         if (!empty($instanceoptionnames)) {
             //create a unique type of instance
             $addable = 1;
             $baseurl->param('new', $typename);
             $output .= $OUTPUT->single_button($baseurl, get_string('createinstance', 'repository'), 'get');
             $baseurl->remove_params('new');
         }
     }
     if ($addable) {
         $instancehtml .= '</div>';
         $output .= $instancehtml;
     }
     $output .= $OUTPUT->box_end();
     //print the list + creation links
     print $output;
 }
Beispiel #13
0
 public function test_get_external_files()
 {
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $userrepository = reset($repos);
     $this->assertInstanceOf('repository', $userrepository);
     // This should break on oracle.
     $fs->get_external_files($userrepository->id, 'id');
     // TODO MDL-33368 Verify result!!
 }
Beispiel #14
0
function xmldb_hotpot_locate_externalfile($contextid, $component, $filearea, $itemid, $filepath, $filename)
{
    global $CFG, $DB;
    if (!class_exists('repository')) {
        return false;
        // Moodle <= 2.2 has no repositories
    }
    static $repositories = null;
    if ($repositories === null) {
        $exclude_types = array('recent', 'upload', 'user', 'areafiles');
        $repositories = repository::get_instances();
        foreach (array_keys($repositories) as $id) {
            if (method_exists($repositories[$id], 'get_typename')) {
                $type = $repositories[$id]->get_typename();
            } else {
                $type = $repositories[$id]->options['type'];
            }
            if (in_array($type, $exclude_types)) {
                unset($repositories[$id]);
            }
        }
        // ensure upgraderunning is set
        if (empty($CFG->upgraderunning)) {
            $CFG->upgraderunning = null;
        }
    }
    // get file storage
    $fs = get_file_storage();
    // the following types repository use encoded params
    $encoded_types = array('user', 'areafiles', 'coursefiles');
    foreach ($repositories as $id => $repository) {
        // "filesystem" path is in plain text, others are encoded
        if (method_exists($repositories[$id], 'get_typename')) {
            $type = $repositories[$id]->get_typename();
        } else {
            $type = $repositories[$id]->options['type'];
        }
        $encodepath = in_array($type, $encoded_types);
        // save $root_path, because it may get messed up by
        // $repository->get_listing($path), if $path is non-existant
        if (method_exists($repository, 'get_rootpath')) {
            $root_path = $repository->get_rootpath();
        } else {
            if (isset($repository->root_path)) {
                $root_path = $repository->root_path;
            } else {
                $root_path = false;
            }
        }
        // get repository type
        switch (true) {
            case isset($repository->options['type']):
                $type = $repository->options['type'];
                break;
            case isset($repository->instance->typeid):
                $type = repository::get_type_by_id($repository->instance->typeid);
                $type = $type->get_typename();
                break;
            default:
                $type = '';
                // shouldn't happen !!
        }
        $path = $filepath;
        $source = trim($filepath . $filename, '/');
        // setup $params for path encoding, if necessary
        $params = array();
        if ($encodepath) {
            $listing = $repository->get_listing();
            switch (true) {
                case isset($listing['list'][0]['source']):
                    $param = 'source';
                    break;
                    // file
                // file
                case isset($listing['list'][0]['path']):
                    $param = 'path';
                    break;
                    // dir
                // dir
                default:
                    return false;
                    // shouldn't happen !!
            }
            $params = file_storage::unpack_reference($listing['list'][0][$param], true);
            $params['filepath'] = '/' . $path . ($path == '' ? '' : '/');
            $params['filename'] = '.';
            // "." signifies a directory
            $path = file_storage::pack_reference($params);
        }
        // reset $repository->root_path (filesystem repository only)
        if ($root_path) {
            $repository->root_path = $root_path;
        }
        // unset upgraderunning because it can cause get_listing() to fail
        $upgraderunning = $CFG->upgraderunning;
        $CFG->upgraderunning = null;
        // Note: we use "@" to suppress warnings in case $path does not exist
        $listing = @$repository->get_listing($path);
        // restore upgraderunning flag
        $CFG->upgraderunning = $upgraderunning;
        // check each file to see if it is the one we want
        foreach ($listing['list'] as $file) {
            switch (true) {
                case isset($file['source']):
                    $param = 'source';
                    break;
                    // file
                // file
                case isset($file['path']):
                    $param = 'path';
                    break;
                    // dir
                // dir
                default:
                    continue;
                    // shouldn't happen !!
            }
            if ($encodepath) {
                $file[$param] = file_storage::unpack_reference($file[$param]);
                $file[$param] = trim($file[$param]['filepath'], '/') . '/' . $file[$param]['filename'];
            }
            if ($file[$param] == $source) {
                if ($encodepath) {
                    $params['filename'] = $filename;
                    $source = file_storage::pack_reference($params);
                }
                $file_record = array('contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'sortorder' => 0, 'itemid' => 0, 'filepath' => $filepath, 'filename' => $filename);
                if ($file = $fs->create_file_from_reference($file_record, $id, $source)) {
                    return $file;
                }
                break;
                // try another repository
            }
        }
    }
    // external file not found (or found but not created)
    return false;
}
Beispiel #15
0
     echo '<div><ul>';
     foreach ($repos as $repo) {
         $info = $repo->get_meta();
         $icon = new moodle_action_icon();
         $icon->image->src = $info->icon;
         $icon->image->style = 'height: 16px; width: 16px;';
         $icon->link->url = clone $url;
         $icon->link->url->params(array('action' => 'list', 'repo_id' => $info->id));
         $icon->linktext = $info->name;
         echo '<li>' . $OUTPUT->action_icon($icon) . '</li>';
     }
     echo '</ul></div>';
     break;
 default:
     $user_context = get_context_instance(CONTEXT_USER, $USER->id);
     $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
     print_header();
     $fs = get_file_storage();
     $context = get_context_instance(CONTEXT_USER, $USER->id);
     $files = $fs->get_area_files($context->id, 'user_draft', $itemid);
     if (empty($files)) {
         echo get_string('nofilesattached', 'repository');
     } else {
         echo '<ul>';
         foreach ($files as $file) {
             if ($file->get_filename() != '.') {
                 $drafturl = new moodle_url($CFG->httpswwwroot . '/draftfile.php/' . $context->id . '/user_draft/' . $itemid . '/' . $file->get_filename());
                 echo '<li><a href="' . $drafturl->out() . '">' . $file->get_filename() . '</a> ';
                 echo '<a href="' . $CFG->httpswwwroot . '/repository/filepicker.php?action=deletedraft&amp;itemid=' . $itemid . '&amp;ctx_id=' . $ctx_id . '&amp;title=' . $file->get_filename() . '"><img src="' . $OUTPUT->old_icon_url('t/delete') . '" class="iconsmall" /></a></li>';
             }
         }
/**
 * Morsle plugin cron task
 */
function repository_morsle_cron()
{
    $instances = repository::get_instances(array('type' => 'morsle'));
    foreach ($instances as $instance) {
        $instance->cron();
    }
}
Beispiel #17
0
 /**
  * Returns the localised human-readable name of the file together with virtual path
  *
  * @return string
  */
 public function get_readable_fullname()
 {
     global $CFG;
     // retrieve the readable path with all parents (excluding the top most 'System')
     $fpath = array();
     for ($parent = $this; $parent && $parent->get_parent(); $parent = $parent->get_parent()) {
         array_unshift($fpath, $parent->get_visible_name());
     }
     if ($this->lf->get_component() == 'user' && $this->lf->get_filearea() == 'private') {
         // use the special syntax for user private files - 'USERNAME Private files: PATH'
         $username = array_shift($fpath);
         array_shift($fpath);
         // get rid of "Private Files/" in the beginning of the path
         return get_string('privatefilesof', 'repository', $username) . ': ' . join('/', $fpath);
     } else {
         // for all other files (except user private files) return 'Server files: PATH'
         // first, get and cache the name of the repository_local (will be used as prefix for file names):
         static $replocalname = null;
         if ($replocalname === null) {
             require_once $CFG->dirroot . "/repository/lib.php";
             $instances = repository::get_instances(array('type' => 'local'));
             if (count($instances)) {
                 $firstinstance = reset($instances);
                 $replocalname = $firstinstance->get_name();
             } else {
                 if (get_string_manager()->string_exists('pluginname', 'repository_local')) {
                     $replocalname = get_string('pluginname', 'repository_local');
                 } else {
                     $replocalname = get_string('arearoot', 'repository');
                 }
             }
         }
         return $replocalname . ': ' . join('/', $fpath);
     }
 }
 /**
  * Add Plugin settings input to Moodle form
  * @global <type> $CFG
  * @param <type> $
  */
 public function type_config_form(&$mform)
 {
     global $CFG;
     $api_key = get_config('flickr', 'api_key');
     $secret = get_config('flickr', 'secret');
     if (empty($api_key)) {
         $api_key = '';
     }
     if (empty($secret)) {
         $secret = '';
     }
     $strrequired = get_string('required');
     $mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr'), array('value' => $api_key, 'size' => '40'));
     $mform->addElement('text', 'secret', get_string('secret', 'repository_flickr'), array('value' => $secret, 'size' => '40'));
     //retrieve the flickr instances
     $instances = repository::get_instances(array(), null, false, "flickr");
     if (empty($instances)) {
         $callbackurl = get_string("callbackwarning", "repository_flickr");
         $mform->addElement('static', null, '', $callbackurl);
     } else {
         $callbackurl = $CFG->wwwroot . '/repository/ws.php?callback=yes&amp;repo_id=' . $instances[0]->id;
         $mform->addElement('static', 'callbackurl', '', get_string('callbackurltext', 'repository_flickr', $callbackurl));
     }
     $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     $mform->addRule('secret', $strrequired, 'required', null, 'client');
 }
/**
 * omero plugin cron task
 */
function repository_omero_cron()
{
    $instances = repository::get_instances(array('type' => 'omero'));
    foreach ($instances as $instance) {
        $instance->cron();
    }
}
 /**
  * Make sure that when internal file is updated all references to it are
  * updated immediately. When it is deleted, the references are converted
  * to true copies.
  */
 public function test_update_reference_internal()
 {
     purge_all_caches();
     $this->resetAfterTest(true);
     $user = $this->setup_three_private_files();
     $fs = get_file_storage();
     $repos = repository::get_instances(array('type' => 'user'));
     $repo = reset($repos);
     // Create two aliases linking the same original.
     $areafiles = array_values($fs->get_area_files($user->ctxid, 'user', 'private', false, 'filename', false));
     $originalfile = $areafiles[0];
     $this->assertInstanceOf('stored_file', $originalfile);
     $contenthash = $originalfile->get_contenthash();
     $filesize = $originalfile->get_filesize();
     $substitutefile = $areafiles[1];
     $this->assertInstanceOf('stored_file', $substitutefile);
     $newcontenthash = $substitutefile->get_contenthash();
     $newfilesize = $substitutefile->get_filesize();
     $originalrecord = array('contextid' => $originalfile->get_contextid(), 'component' => $originalfile->get_component(), 'filearea' => $originalfile->get_filearea(), 'itemid' => $originalfile->get_itemid(), 'filepath' => $originalfile->get_filepath(), 'filename' => $originalfile->get_filename());
     $aliasrecord = $this->generate_file_record();
     $aliasrecord->filepath = '/A/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $symlink1 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // Make sure created alias is a reference and has the same size and contenthash as source.
     $this->assertEquals($contenthash, $symlink1->get_contenthash());
     $this->assertEquals($filesize, $symlink1->get_filesize());
     $this->assertEquals($repo->id, $symlink1->get_repository_id());
     $this->assertNotEmpty($symlink1->get_referencefileid());
     $referenceid = $symlink1->get_referencefileid();
     $aliasrecord->filepath = '/B/';
     $aliasrecord->filename = 'symlink.txt';
     $ref = $fs->pack_reference($originalrecord);
     $symlink2 = $fs->create_file_from_reference($aliasrecord, $repo->id, $ref);
     // Make sure created alias is a reference and has the same size and contenthash as source.
     $this->assertEquals($contenthash, $symlink2->get_contenthash());
     $this->assertEquals($filesize, $symlink2->get_filesize());
     $this->assertEquals($repo->id, $symlink2->get_repository_id());
     // Make sure both aliases have the same reference id.
     $this->assertEquals($referenceid, $symlink2->get_referencefileid());
     // Overwrite ofiginal file.
     $originalfile->replace_file_with($substitutefile);
     $this->assertEquals($newcontenthash, $originalfile->get_contenthash());
     $this->assertEquals($newfilesize, $originalfile->get_filesize());
     // References to the internal files must be synchronised immediately.
     // Refetch A/symlink.txt file.
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertTrue($symlink1->is_external_file());
     $this->assertEquals($newcontenthash, $symlink1->get_contenthash());
     $this->assertEquals($newfilesize, $symlink1->get_filesize());
     $this->assertEquals($repo->id, $symlink1->get_repository_id());
     $this->assertEquals($referenceid, $symlink1->get_referencefileid());
     // Refetch B/symlink.txt file.
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertTrue($symlink2->is_external_file());
     $this->assertEquals($newcontenthash, $symlink2->get_contenthash());
     $this->assertEquals($newfilesize, $symlink2->get_filesize());
     $this->assertEquals($repo->id, $symlink2->get_repository_id());
     $this->assertEquals($referenceid, $symlink2->get_referencefileid());
     // Remove original file.
     $originalfile->delete();
     // References must be converted to independend files.
     // Refetch A/symlink.txt file.
     $symlink1 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/A/', 'symlink.txt');
     $this->assertFalse($symlink1->is_external_file());
     $this->assertEquals($newcontenthash, $symlink1->get_contenthash());
     $this->assertEquals($newfilesize, $symlink1->get_filesize());
     $this->assertNull($symlink1->get_repository_id());
     $this->assertNull($symlink1->get_referencefileid());
     // Refetch B/symlink.txt file.
     $symlink2 = $fs->get_file($aliasrecord->contextid, $aliasrecord->component, $aliasrecord->filearea, $aliasrecord->itemid, '/B/', 'symlink.txt');
     $this->assertFalse($symlink2->is_external_file());
     $this->assertEquals($newcontenthash, $symlink2->get_contenthash());
     $this->assertEquals($newfilesize, $symlink2->get_filesize());
     $this->assertNull($symlink2->get_repository_id());
     $this->assertNull($symlink2->get_referencefileid());
 }
Beispiel #21
0
function equella_find_repository()
{
    global $CFG;
    require_once $CFG->dirroot . '/repository/lib.php';
    $instances = repository::get_instances(array('type' => 'equella'));
    foreach ($instances as $e) {
        if ($e->get_option('equella_url') == $CFG->equella_url) {
            return $e;
        }
    }
    return null;
}
Beispiel #22
0
$configstr = get_string('manageuserrepository', 'repository');
$pluginstr = get_string('plugin', 'repository');
require_login($course, false);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
$link = new moodle_url('/user/view.php', array('id' => $user->id));
$PAGE->navbar->add($fullname, $link);
$PAGE->navbar->add($strrepos);
$PAGE->set_title("{$course->fullname}: {$fullname}: {$strrepos}");
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
$currenttab = 'repositories';
include 'tabs.php';
echo $OUTPUT->heading($configstr);
echo $OUTPUT->box_start();
$params = array();
$params['context'] = $coursecontext;
$params['currentcontext'] = $PAGE->context;
$params['userid'] = $USER->id;
if (!($instances = repository::get_instances($params))) {
    print_error('noinstances', 'repository', $CFG->wwwroot . '/user/view.php');
}
$table = new html_table();
$table->head = array($namestr, $pluginstr, '');
$table->data = array();
foreach ($instances as $i) {
    $path = '/repository/' . $i->type . '/settings.php';
    $settings = file_exists($CFG->dirroot . $path);
    $table->data[] = array($i->name, $i->type, $settings ? '<a href="' . $CFG->wwwroot . $path . '">' . get_string('settings', 'repository') . '</a>' : '');
}
echo html_writer::table($table);
echo $OUTPUT->footer();
Beispiel #23
0
/**
 * Cron callback for repository_filesystem. Deletes the thumbnails for deleted or changed files.
 */
function repository_filesystem_cron()
{
    $fs = get_file_storage();
    // Find all generated thumbnails and group them in array by itemid (itemid == repository instance id).
    $allfiles = array_merge($fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb'), $fs->get_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon'));
    $filesbyitem = array();
    foreach ($allfiles as $file) {
        if (!isset($filesbyitem[$file->get_itemid()])) {
            $filesbyitem[$file->get_itemid()] = array();
        }
        $filesbyitem[$file->get_itemid()][] = $file;
    }
    // Find all instances of repository_filesystem.
    $instances = repository::get_instances(array('type' => 'filesystem'));
    // Loop through all itemids of generated thumbnails.
    foreach ($filesbyitem as $itemid => $files) {
        if (!isset($instances[$itemid]) || !$instances[$itemid] instanceof repository_filesystem) {
            // Instance was deleted.
            $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'thumb', $itemid);
            $fs->delete_area_files(SYSCONTEXTID, 'repository_filesystem', 'icon', $itemid);
            mtrace(" instance {$itemid} does not exist: deleted all thumbnails");
        } else {
            // Instance has some generated thumbnails, check that they are not outdated.
            $instances[$itemid]->remove_obsolete_thumbnails($files);
        }
    }
}
Beispiel #24
0
 /**
  * Handle uploads containing files - create the course module, ask the upload repository
  * to process the file, ask the mod to set itself up, then return the result to the browser
  */
 protected function handle_file_upload()
 {
     global $CFG;
     // Add the file to a draft file area.
     $draftitemid = file_get_unused_draft_itemid();
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $this->course->maxbytes);
     $types = $this->dnduploadhandler->get_handled_file_types($this->module->name);
     $repo = repository::get_instances(array('type' => 'upload'));
     if (empty($repo)) {
         throw new moodle_exception('errornouploadrepo', 'moodle');
     }
     $repo = reset($repo);
     // Get the first (and only) upload repo.
     $details = $repo->process_upload(null, $maxbytes, $types, '/', $draftitemid);
     if (empty($this->displayname)) {
         $this->displayname = $this->display_name_from_file($details['file']);
     }
     // Create a course module to hold the new instance.
     $this->create_course_module();
     // Ask the module to set itself up.
     $moduledata = $this->prepare_module_data($draftitemid);
     $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction');
     if ($instanceid === 'invalidfunction') {
         throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function");
     }
     // Finish setting up the course module.
     $this->finish_setup_course_module($instanceid);
 }
Beispiel #25
0
    /**
     * Display a repository instance list (with edit/delete/create links)
     * @global object $CFG
     * @global object $USER
     * @global object $OUTPUT
     * @param object $context the context for which we display the instance
     * @param string $typename if set, we display only one type of instance
     */
    public static function display_instances_list($context, $typename = null) {
        global $CFG, $USER, $OUTPUT;

        $output = $OUTPUT->box_start('generalbox');
        //if the context is SYSTEM, so we call it from administration page
        $admin = ($context->id == SYSCONTEXTID) ? true : false;
        if ($admin) {
            $baseurl = new moodle_url('/'.$CFG->admin.'/repositoryinstance.php', array('sesskey'=>sesskey()));
            $output .= $OUTPUT->heading(get_string('siteinstances', 'repository'));
        } else {
            $baseurl = new moodle_url('/repository/manage_instances.php', array('contextid'=>$context->id, 'sesskey'=>sesskey()));
        }
        $url = $baseurl;

        $namestr = get_string('name');
        $pluginstr = get_string('plugin', 'repository');
        $settingsstr = get_string('settings');
        $deletestr = get_string('delete');
        //retrieve list of instances. In administration context we want to display all
        //instances of a type, even if this type is not visible. In course/user context we
        //want to display only visible instances, but for every type types. The repository::get_instances()
        //third parameter displays only visible type.
        $params = array();
        $params['context'] = array($context, get_system_context());
        $params['currentcontext'] = $context;
        $params['onlyvisible'] = !$admin;
        $params['type']        = $typename;
        $instances = repository::get_instances($params);
        $instancesnumber = count($instances);
        $alreadyplugins = array();

        $table = new html_table();
        $table->head = array($namestr, $pluginstr, $settingsstr, $deletestr);
        $table->align = array('left', 'left', 'center','center');
        $table->data = array();

        $updowncount = 1;

        foreach ($instances as $i) {
            $settings = '';
            $delete = '';

            $type = repository::get_type_by_id($i->options['typeid']);

            if ($type->get_contextvisibility($context)) {
                if (!$i->readonly) {

                    $url->param('type', $i->options['type']);
                    $url->param('edit', $i->id);
                    $settings .= html_writer::link($url, $settingsstr);

                    $url->remove_params('edit');
                    $url->param('delete', $i->id);
                    $delete .= html_writer::link($url, $deletestr);

                    $url->remove_params('type');
                }
            }

            $type = repository::get_type_by_id($i->options['typeid']);
            $table->data[] = array($i->name, $type->get_readablename(), $settings, $delete);

            //display a grey row if the type is defined as not visible
            if (isset($type) && !$type->get_visible()) {
                $table->rowclasses[] = 'dimmed_text';
            } else {
                $table->rowclasses[] = '';
            }

            if (!in_array($i->name, $alreadyplugins)) {
                $alreadyplugins[] = $i->name;
            }
        }
        $output .= html_writer::table($table);
        $instancehtml = '<div>';
        $addable = 0;

        //if no type is set, we can create all type of instance
        if (!$typename) {
            $instancehtml .= '<h3>';
            $instancehtml .= get_string('createrepository', 'repository');
            $instancehtml .= '</h3><ul>';
            $types = repository::get_editable_types($context);
            foreach ($types as $type) {
                if (!empty($type) && $type->get_visible()) {
                    $instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
                    if (!empty($instanceoptionnames)) {
                        $baseurl->param('new', $type->get_typename());
                        $instancehtml .= '<li><a href="'.$baseurl->out().'">'.get_string('createxxinstance', 'repository', get_string('pluginname', 'repository_'.$type->get_typename())).  '</a></li>';
                        $baseurl->remove_params('new');
                        $addable++;
                    }
                }
            }
            $instancehtml .= '</ul>';

        } else {
            $instanceoptionnames = repository::static_function($typename, 'get_instance_option_names');
            if (!empty($instanceoptionnames)) {   //create a unique type of instance
                $addable = 1;
                $baseurl->param('new', $typename);
                $instancehtml .= "<form action='".$baseurl->out()."' method='post'>
                    <p><input type='submit' value='".get_string('createinstance', 'repository')."'/></p>
                    </form>";
                $baseurl->remove_params('new');
            }
        }

        if ($addable) {
            $instancehtml .= '</div>';
            $output .= $instancehtml;
        }

        $output .= $OUTPUT->box_end();

        //print the list + creation links
        print($output);
    }
Beispiel #26
0
/**
 * Dropbox plugin cron task
 */
function repository_dropbox_cron()
{
    $instances = repository::get_instances(array('type' => 'dropbox'));
    foreach ($instances as $instance) {
        $instance->cron();
    }
}
    print_error('invalidcourseid');
}
$user = $USER;
$baseurl = $CFG->wwwroot . '/user/repository.php';
$namestr = get_string('name');
$fullname = fullname($user);
$strrepos = get_string('repositories', 'repository');
$configstr = get_string('manageuserrepository', 'repository');
$pluginstr = get_string('plugin', 'repository');
require_login($course, false);
$navlinks[] = array('name' => $fullname, 'link' => $CFG->wwwroot . '/user/view.php?id=' . $user->id, 'type' => 'misc');
$navlinks[] = array('name' => $strrepos, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("{$course->fullname}: {$fullname}: {$strrepos}", $course->fullname, $navigation, "", "", true, "&nbsp;", navmenu($course));
$currenttab = 'repositories';
include 'tabs.php';
print_heading($configstr);
print_simple_box_start();
if (!($instances = repository::get_instances($COURSE->context, $USER->id))) {
    print_error('noinstances', 'repository', $CFG->wwwroot . '/user/view.php');
}
$table = new StdClass();
$table->head = array($namestr, $pluginstr, '');
$table->data = array();
foreach ($instances as $i) {
    $path = '/repository/' . $i->type . '/settings.php';
    $settings = file_exists($CFG->dirroot . $path);
    $table->data[] = array($i->name, $i->type, $settings ? '<a href="' . $CFG->wwwroot . $path . '">' . get_string('settings', 'repository') . '</a>' : '');
}
print_table($table);
print_footer();