/** * Authenticate user from the received hub token * If no token, so we use the "public" hub community token from the system (create one if don't exist) */ protected function authenticate_user() { global $DB; //retrieve hub privacy $privacy = get_config('local_hub', 'privacy'); // hub server public access (search, rate, comment, import) if ($this->token == 'publichub' and $privacy != HUBPRIVATE) { $hub = new local_hub(); $publiccommunication = $hub->get_communication(WSSERVER, PUBLICSITE); if (empty($publiccommunication)) { $capabilities = array('local/hub:view'); $token = $hub->create_hub_token('Public Hub User', 'Public site', 'public_hub_user', $capabilities); $publiccommunication = new stdClass(); $publiccommunication->token = $token->token; $publiccommunication->type = WSSERVER; $publiccommunication->remotename = ''; $publiccommunication->remoteentity = PUBLICSITE; $publiccommunication->confirmed = 1; $publiccommunication->id = $hub->add_communication($publiccommunication); } $this->token = $publiccommunication->token; } parent::authenticate_user(); }
require_once $CFG->dirroot . '/local/hub/admin/forms.php'; require_once $CFG->dirroot . '/webservice/lib.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; admin_externalpage_setup('hubregistration'); //check that the PHP xmlrpc extension is enabled if (!extension_loaded('xmlrpc')) { echo $OUTPUT->header(); $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); $xmlrpcnotification .= get_string('xmlrpcdisabled', 'local_hub'); echo $OUTPUT->notification($xmlrpcnotification); echo $OUTPUT->footer(); die; } $error = optional_param('error', '', PARAM_TEXT); $hub = new local_hub(); $directorytohubcommunication = $hub->get_communication(WSSERVER, HUBDIRECTORY, HUB_HUBDIRECTORYURL); $hubtodirectorycommunication = $hub->get_communication(WSCLIENT, HUBDIRECTORY, HUB_HUBDIRECTORYURL); $hubregistrationform = new hub_registration_form('', array('alreadyregistered' => !empty($hubtodirectorycommunication->confirmed))); /////// UNREGISTER ACTION ////// $unregister = optional_param('unregister', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT); $force = optional_param('force', 0, PARAM_INT); if ($unregister && $confirm && confirm_sesskey()) { if (!$force) { $function = 'hubdirectory_unregister_hub'; $params = array(); $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; require_once $CFG->dirroot . "/webservice/xmlrpc/lib.php"; $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token); try { $result = $xmlrpcclient->call($function, $params);
* @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require '../../../config.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . '/course/publish/lib.php'; //HUB_SCREENSHOT_FILE_TYPE and HUB_BACKUP_FILE_TYPE $token = optional_param('token', '', PARAM_ALPHANUM); $filetype = optional_param('filetype', '', PARAM_ALPHA); //can be screenshots, backup, ... $screenshotnumber = optional_param('screenshotnumber', 1, PARAM_INT); //the screenshot number of this course $courseid = optional_param('courseid', '', PARAM_ALPHANUM); // check the communication token $hub = new local_hub(); $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, '', $token); if (!empty($token) && !empty($communication) and get_config('local_hub', 'hubenabled')) { //retrieve the site $siteurl = $communication->remoteurl; $site = $hub->get_site_by_url($siteurl); //check that the course exist $course = $DB->get_record('hub_course_directory', array('id' => $courseid, 'siteid' => $site->id)); if (!empty($course) && !empty($_FILES)) { switch ($filetype) { case HUB_BACKUP_FILE_TYPE: //check that the backup doesn't already exist $backup = $hub->backup_exits($courseid); if (empty($backup)) { $hub->add_backup($_FILES['file'], $courseid); } break;
/** * Get courses * @return array courses */ public static function get_courses($search, $downloadable, $enrollable, $options = array()) { global $DB, $CFG, $USER; // Ensure the current user is allowed to run this function $context = context_system::instance(); self::validate_context($context); require_capability('local/hub:view', $context); $params = self::validate_parameters(self::get_courses_parameters(), array('search' => $search, 'downloadable' => $downloadable, 'enrollable' => $enrollable, 'options' => $options)); //retieve siteid $onlyvisible = true; $token = optional_param('wstoken', '', PARAM_ALPHANUM); $localhub = new local_hub(); $communication = $localhub->get_communication(WSSERVER, REGISTEREDSITE, null, $token); if (!empty($communication)) { $siteurl = $communication->remoteurl; if (!empty($siteurl)) { $site = $localhub->get_site_by_url($siteurl); if (!empty($site) and !empty($params['options']['allsitecourses'])) { $params['options']['siteid'] = $site->id; $onlyvisible = false; } } } $cleanedoptions = $params['options']; $cleanedoptions['onlyvisible'] = $onlyvisible; $cleanedoptions['search'] = $params['search']; $cleanedoptions['downloadable'] = $params['downloadable']; $cleanedoptions['enrollable'] = $params['enrollable']; //sort method if (!empty($params['options']['orderby'])) { switch ($params['options']['orderby']) { case 'newest': $cleanedoptions['orderby'] = 'timemodified DESC'; break; case 'eldest': $cleanedoptions['orderby'] = 'timemodified ASC'; break; case 'publisher': $cleanedoptions['orderby'] = 'publishername ASC'; break; case 'fullname': $cleanedoptions['orderby'] = 'fullname ASC'; break; case 'ratingaverage': $cleanedoptions['orderby'] = 'ratingaverage DESC'; break; default: unset($cleanedoptions['orderby']); break; } } //retrieve the range of courses to return $maxcourses = get_config('local_hub', 'maxwscourseresult'); if (empty($maxcourses)) { throw new moodle_exception('nocoursereturn', 'local_hub'); } $hub = new local_hub(); //the site is requesting all his own course if (!empty($params['options']['siteid'])) { $maxcourses = 0; $limitfrom = 0; } else { //the site is doing a normal courses request (not focussed on its own courses) //the hub server limit the return number of course $limitfrom = isset($params['options']['givememore']) ? $params['options']['givememore'] : 0; } $courses = $hub->get_courses($cleanedoptions, $limitfrom, $maxcourses); $coursetotal = $hub->get_courses($cleanedoptions, 0, 0, true); //load ratings and comments if (!empty($courses)) { require_once $CFG->dirroot . '/comment/lib.php'; } //create result $coursesresult = array(); foreach ($courses as $course) { $courseinfo = array(); $courseinfo['id'] = $course->id; $courseinfo['fullname'] = $course->fullname; $courseinfo['shortname'] = $course->shortname; $courseinfo['description'] = $course->description; $courseinfo['language'] = $course->language; $courseinfo['publishername'] = $course->publishername; //return publisher email, privacy and site course id // only if the request has been done by the site if (!empty($site) and $course->siteid == $site->id) { $courseinfo['publisheremail'] = $course->publisheremail; $courseinfo['privacy'] = $course->privacy; $courseinfo['sitecourseid'] = $course->sitecourseid; } $courseinfo['contributornames'] = $course->contributornames; $courseinfo['coverage'] = $course->coverage; $courseinfo['creatorname'] = $course->creatorname; $courseinfo['licenceshortname'] = $course->licenceshortname; $courseinfo['subject'] = $course->subject; $courseinfo['audience'] = $course->audience; $courseinfo['educationallevel'] = $course->educationallevel; $courseinfo['creatornotes'] = $course->creatornotes; $courseinfo['creatornotesformat'] = $course->creatornotesformat; $courseinfo['enrollable'] = $course->enrollable; $courseinfo['screenshots'] = $course->screenshots; $courseinfo['timemodified'] = $course->timemodified; if (!empty($course->courseurl)) { $courseinfo['courseurl'] = $course->courseurl; } else { if (!empty($course->demourl)) { //courseurl is mandatory, demo url can be blank $courseinfo['demourl'] = $course->demourl; } else { $courseurl = new moodle_url($CFG->wwwroot, array('sesskey' => sesskey(), 'redirectcourseid' => $course->id)); $courseinfo['demourl'] = $courseurl->out(false); } } //outcomes if (!empty($course->outcomes)) { foreach ($course->outcomes as $outcome) { $courseinfo['outcomes'][] = array('fullname' => $outcome); } } //get content $contents = $hub->get_course_contents($course->id); if (!empty($contents)) { foreach ($contents as $content) { $tmpcontent = array(); $tmpcontent['moduletype'] = $content->moduletype; $tmpcontent['modulename'] = $content->modulename; $tmpcontent['contentcount'] = $content->contentcount; $courseinfo['contents'][] = $tmpcontent; } } //set ratings if ($course->ratingcount) { //$courseinfo['rating']['aggregate'] = (float) $course->ratingaverage; //the ratings has been changed from scale 0 to 10 to a "Featured" award $courseinfo['rating']['aggregate'] = HUB_COURSE_RATING_SCALE; } $courseinfo['rating']['count'] = (int) $course->ratingcount; $courseinfo['rating']['scaleid'] = HUB_COURSE_RATING_SCALE; //get comments $commentoptions->context = context_course::instance(SITEID); $commentoptions->area = 'local_hub'; $commentoptions->itemid = $course->id; $commentoptions->showcount = true; $commentoptions->component = 'local_hub'; $course->comment = new comment($commentoptions); $comments = $course->comment->get_comments(); foreach ($comments as $comment) { $coursecomment = array(); $coursecomment['comment'] = clean_param($comment->content, PARAM_TEXT); $coursecomment['commentator'] = clean_param($comment->fullname, PARAM_TEXT); $coursecomment['date'] = $comment->timecreated; $courseinfo['comments'][] = $coursecomment; } //get backup size $returnthecourse = true; if (!$course->enrollable) { if ($hub->backup_exits($course->id)) { $courseinfo['backupsize'] = $hub->get_backup_size($course->id); } else { // We don't return the course when backup file is not found. $returnthecourse = false; } } if ($returnthecourse) { $coursesresult[] = $courseinfo; } } return array('courses' => $coursesresult, 'coursetotal' => $coursetotal); }