/** * 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(); }
set_config('description', $fromform->desc, 'local_hub'); set_config('contactname', $fromform->contactname, 'local_hub'); set_config('contactemail', $fromform->contactemail, 'local_hub'); set_config('maxwscourseresult', $fromform->maxwscourseresult, 'local_hub'); set_config('maxcoursesperday', $fromform->maxcoursesperday, 'local_hub'); set_config('searchfornologin', empty($fromform->searchfornologin) ? 0 : 1, 'local_hub'); set_config('enablerssfeeds', empty($fromform->enablerssfeeds) ? 0 : $fromform->enablerssfeeds, 'local_hub'); set_config('rsssecret', empty($fromform->rsssecret) ? '' : $fromform->rsssecret, 'local_hub'); set_config('sendyurl', empty($fromform->sendyurl) ? '' : $fromform->sendyurl, 'local_hub'); set_config('sendylistid', empty($fromform->sendylistid) ? '' : $fromform->sendylistid, 'local_hub'); set_config('sendyapikey', empty($fromform->sendyapikey) ? '' : $fromform->sendyapikey, 'local_hub'); set_config('language', $fromform->lang, 'local_hub'); set_config('password', empty($fromform->password) ? null : $fromform->password, 'local_hub'); //if privacy settings is downgraded to 'private', then unregister from the hub $currentprivacy = get_config('local_hub', 'privacy'); $hubmanager = new local_hub(); $hubtodirectorycommunication = $hubmanager->get_communication(WSCLIENT, HUBDIRECTORY, HUB_HUBDIRECTORYURL); if ($currentprivacy != HUBPRIVATE and $fromform->privacy == HUBPRIVATE and !empty($hubtodirectorycommunication) and !empty($hubtodirectorycommunication->confirmed)) { $directorytohubcommunication = $hubmanager->get_communication(WSSERVER, HUBDIRECTORY, HUB_HUBDIRECTORYURL); $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); } catch (Exception $e) { $error = $OUTPUT->notification(get_string('failunregistrationofprivate', 'local_hub', $e->getMessage())); } if (empty($error)) { //delete the web service token
/** * Optionally subscribe/unsubscribe the contactemail to/from a sendy mailing list. * Loads all sites associated with the supplied site contactemail and passes them to update_sendy_list_batch(). * This is necessary because the emailalert property may be different on the various sites associated with a given email. * We can't subscribe or unsubscribe them based on a single site's value. * * @todo tobe in local_hub class or not? its a helper function for now for any functional expansion.. * * @param $site a row from hub_site_directory */ function update_sendy_list($site) { $hub = new local_hub(); $sites = $hub->get_sites(array('contactemail' => $site->contactemail)); update_sendy_list_batch($sites); }
require '../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . "/local/hub/forms.php"; define('MAXSITES', 100); admin_externalpage_setup('managesites'); //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; } $hub = new local_hub(); /// Check if the page has been called with trust argument $delete = optional_param('delete', -1, PARAM_INTEGER); $confirm = optional_param('confirm', false, PARAM_INTEGER); if ($delete != -1 and $confirm and confirm_sesskey()) { $unregistercourses = optional_param('unregistercourses', false, PARAM_BOOL); $hub->delete_site($delete, $unregistercourses); } /// Check if the page has been called with trust argument $trust = optional_param('trust', -1, PARAM_INTEGER); if ($trust != -1 and confirm_sesskey()) { $id = required_param('id', PARAM_INTEGER); $site = $hub->get_site($id); if (!empty($site)) { $site->trusted = $trust; $hub->update_site($site);
public function definition() { global $CFG; $strrequired = get_string('required'); //retrieve the publication $hub = new local_hub(); $course = $hub->get_course($this->_customdata['id']); $mform =& $this->_form; $mform->addElement('header', 'moodle', get_string('coursesettingsform', 'local_hub', $course->fullname)); $mform->addElement('hidden', 'id', $course->id); $mform->setType('id', PARAM_INT); $mform->addElement('checkbox', 'visible', get_string('coursevisibility', 'local_hub')); $mform->addHelpButton('visible', 'coursevisibility', 'local_hub'); $mform->setDefault('visible', $course->privacy); $mform->addElement('text', 'fullname', get_string('coursename', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('fullname', PARAM_TEXT); $mform->addHelpButton('fullname', 'coursename', 'local_hub'); $mform->setDefault('fullname', $course->fullname); $mform->addRule('fullname', $strrequired, 'required', null, 'client'); if (!empty($course->courseurl)) { $mform->addElement('text', 'courseurl', get_string('courseurl', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('courseurl', PARAM_URL); $mform->addHelpButton('courseurl', 'courseurl', 'local_hub'); $mform->setDefault('courseurl', $course->courseurl); $mform->addRule('courseurl', $strrequired, 'required', null, 'client'); } else { $mform->addElement('text', 'demourl', get_string('demourl', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('demourl', PARAM_URL); $mform->addHelpButton('demourl', 'demourl', 'local_hub'); $mform->setDefault('demourl', $course->demourl); } $mform->addElement('textarea', 'description', get_string('coursedesc', 'local_hub'), array('rows' => 10, 'cols' => 56, 'class' => 'coursesettingstextarea')); $mform->addHelpButton('description', 'coursedesc', 'local_hub'); $mform->addRule('description', $strrequired, 'required', null, 'client'); $mform->setDefault('description', $course->description); $languages = get_string_manager()->get_list_of_languages(); asort($languages, SORT_LOCALE_STRING); $mform->addElement('select', 'language', get_string('courselang', 'local_hub'), $languages); $mform->setDefault('language', $course->language); $mform->addHelpButton('language', 'courselang', 'local_hub'); $mform->addElement('text', 'publishername', get_string('publishername', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('publishername', PARAM_TEXT); $mform->setDefault('publishername', $course->publishername); $mform->addRule('publishername', $strrequired, 'required', null, 'client'); $mform->addHelpButton('publishername', 'publishername', 'local_hub'); $mform->addElement('text', 'publisheremail', get_string('publisheremail', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('publisheremail', PARAM_EMAIL); $mform->setDefault('publisheremail', $course->publisheremail); $mform->addRule('publisheremail', $strrequired, 'required', null, 'client'); $mform->addHelpButton('publisheremail', 'publisheremail', 'local_hub'); $mform->addElement('text', 'creatorname', get_string('creatorname', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->addRule('creatorname', $strrequired, 'required', null, 'client'); $mform->setType('creatorname', PARAM_TEXT); $mform->setDefault('creatorname', $course->creatorname); $mform->addHelpButton('creatorname', 'creatorname', 'local_hub'); $mform->addElement('text', 'contributornames', get_string('contributornames', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('contributornames', PARAM_TEXT); $mform->setDefault('contributornames', $course->contributornames); $mform->addHelpButton('contributornames', 'contributornames', 'local_hub'); $mform->addElement('text', 'coverage', get_string('tags', 'local_hub'), array('class' => 'coursesettingstextfield')); $mform->setType('coverage', PARAM_TEXT); $mform->setDefault('coverage', $course->coverage); $mform->addHelpButton('coverage', 'tags', 'local_hub'); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('licence', 'local_hub'), $options); $mform->setDefault('licence', $course->licenceshortname); unset($options); $mform->addHelpButton('licence', 'licence', 'local_hub'); require_once $CFG->dirroot . "/course/publish/lib.php"; $publicationmanager = new course_publish_manager(); $options = $publicationmanager->get_sorted_subjects(); //prepare data for the smartselect foreach ($options as $key => &$option) { $keylength = strlen($key); if ($keylength == 10) { $option = " " . $option; } else { if ($keylength == 12) { $option = " " . $option; } } } $options = array('none' => get_string('none', 'local_hub')) + $options; $mform->addElement('select', 'subject', get_string('subject', 'local_hub'), $options); unset($options); $mform->addHelpButton('subject', 'subject', 'local_hub'); $mform->setDefault('subject', $course->subject); $mform->addRule('subject', $strrequired, 'required', null, 'client'); $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => false, 'mode' => 'compact')); $options = array(); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'local_hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'local_hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'local_hub'); $mform->addElement('select', 'audience', get_string('audience', 'local_hub'), $options); $mform->setDefault('audience', $course->audience); unset($options); $mform->addHelpButton('audience', 'audience', 'local_hub'); $options = array(); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'local_hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'local_hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'local_hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'local_hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'local_hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'local_hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'local_hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'local_hub'), $options); $mform->setDefault('educationallevel', $course->educationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'local_hub'); //setdefault is currently not supported making this required field not usable MDL-20988 $editoroptions = array('maxfiles' => 0, 'maxbytes' => 0, 'trusttext' => false, 'forcehttps' => false); $mform->addElement('editor', 'creatornotes', get_string('creatornotes', 'hub'), '', $editoroptions); $mform->setType('creatornotes', PARAM_CLEANHTML); $mform->addHelpButton('creatornotes', 'creatornotes', 'hub'); //set default value for creatornotes editor $data = new stdClass(); $data->creatornotes = array(); $data->creatornotes['text'] = $course->creatornotes; $data->creatornotes['format'] = $course->creatornotesformat; $this->set_data($data); //select screenshots to keep for ($screenshotnumber = 1; $screenshotnumber <= $course->screenshots; $screenshotnumber++) { $baseurl = new moodle_url($CFG->wwwroot . '/local/hub/webservice/download.php', array('courseid' => $course->id, 'filetype' => HUB_SCREENSHOT_FILE_TYPE, 'screenshotnumber' => $screenshotnumber, 'alwaysreload' => time())); $screenshothtml = html_writer::empty_tag('img', array('src' => $baseurl, 'alt' => $course->fullname)); $coursescreenshot = html_writer::tag('div', $screenshothtml, array('class' => '')); $mform->addElement('checkbox', 'screenshot_' . $screenshotnumber, get_string('keepscreenshot', 'local_hub'), $coursescreenshot); $mform->addHelpButton('screenshot_' . $screenshotnumber, 'keepscreenshot', 'local_hub'); $mform->setDefault('screenshot_' . $screenshotnumber, 1); } $mform->addElement('filemanager', 'addscreenshots', get_string('addscreenshots', 'local_hub'), null, array('subdirs' => 0, 'maxbytes' => 1000000, 'maxfiles' => MAXSCREENSHOTSNUMBER)); $mform->addHelpButton('addscreenshots', 'addscreenshots', 'local_hub'); $this->add_action_buttons(false, get_string('update')); }
/** * Process the registration - redirect the user to its admin confirmation registration page * * @param object $sitevalues the site values * @param boolean $secretexists true if a site is already registered with the same secret * @param type $urlexists true if a site is already registered with this url * @param type $sitewithsamesecret the DB site already existing for this secret * @param type $sitewithsameurl the DB site already existing for this url address */ function process_registration($sitevalues, $secretexists, $urlexists, $sitewithsamesecret, $sitewithsameurl) { global $CFG; //check that the form has the required data //(to force people that don't call this page from a Moodle registration page to POST correct data. //Note that there is no good reason for people to do it) if (empty($sitevalues->token) or empty($sitevalues->url) or empty($sitevalues->name) or empty($sitevalues->contactname) or empty($sitevalues->contactemail) or empty($sitevalues->description) or empty($sitevalues->language)) { throw new moodle_exception('errorwrongdata', 'local_hub', new moodle_url('/index.php')); } //token is saved as secret in the DB $sitevalues->secret = $sitevalues->token; $hub = new local_hub(); if (!$secretexists and !$urlexists) { $newtoken = $hub->register_site($sitevalues); //log the new site add_to_log(SITEID, 'local_hub', 'new site registration', '', $sitevalues->url); } else { if ($secretexists and $urlexists and $sitewithsamesecret->url == $sitewithsameurl->url) { //the site is already registered //It happens when new fresh site has been installed and the email link //wasn't followed till the end of the registration replacement process. $newtoken = $hub->register_site($sitevalues, $sitevalues->url); //log the overwritting site registration add_to_log(SITEID, 'local_hub', 'site registered a new time', '', $sitevalues->url); } else { //log the code logic error (it should never happen) add_to_log(SITEID, 'local_hub', 'registration code logic error', '', $sitevalues->url); throw new moodle_exception('codelogicerror', 'local_hub'); } } //Redirect to the site with the created token redirect(new moodle_url($sitevalues->url . "/admin/registration/confirmregistration.php", array('newtoken' => $newtoken, 'url' => HUBURL, 'token' => $sitevalues->token, 'hubname' => get_config('local_hub', 'name')))); }
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // // // /////////////////////////////////////////////////////////////////////////// /** * On this page administrator can change site settings * @package localhub * @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require '../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/admin/forms.php'; admin_externalpage_setup('sitesettings'); $id = optional_param('id', 0, PARAM_INT); $hub = new local_hub(); $site = $hub->get_site($id, MUST_EXIST); //define nav bar $PAGE->set_url('/local/hub/admin/sitesettings.php', array('id' => $id)); $PAGE->navbar->ignore_active(true); $PAGE->navbar->add(get_string('administrationsite')); $PAGE->navbar->add(get_string('hub', 'local_hub')); $PAGE->navbar->add(get_string('managesites', 'local_hub'), new moodle_url('/local/hub/admin/managesites.php', array('search' => $site->name, 'sesskey' => sesskey()))); $PAGE->navbar->add(get_string('sitesettings', 'local_hub'), new moodle_url('/local/hub/admin/sitesettings.php', array('id' => $id))); $sitesettingsform = new hub_site_settings_form('', array('id' => $id)); $fromform = $sitesettingsform->get_data(); //Save settings and redirect to search site page if (!empty($fromform)) { if ($fromform->publicationmax === '') { $site->publicationmax = null; } else {
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // // // /////////////////////////////////////////////////////////////////////////// /** * On this page administrator can change site settings * @package localhub * @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require '../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/admin/forms.php'; admin_externalpage_setup('hubcoursesettings'); $id = optional_param('id', 0, PARAM_INT); $hub = new local_hub(); $course = $hub->get_course($id, MUST_EXIST); //define nav bar $PAGE->set_url('/local/hub/admin/coursesettings.php', array('id' => $id)); $PAGE->navbar->ignore_active(true); $PAGE->navbar->add(get_string('administrationsite')); $PAGE->navbar->add(get_string('hub', 'local_hub')); $PAGE->navbar->add(get_string('managecourses', 'local_hub'), new moodle_url('/local/hub/admin/managecourses.php', array('courseid' => $course->id, 'sesskey' => sesskey()))); $PAGE->navbar->add(get_string('coursesettings', 'local_hub'), new moodle_url('/local/hub/admin/coursesettings.php', array('id' => $id))); $coursesettingsform = new hub_course_settings_form('', array('id' => $id)); $fromform = $coursesettingsform->get_data(); //Save settings and redirect to search site page if (!empty($fromform) and confirm_sesskey()) { //update the course values $course->fullname = $fromform->fullname; $course->description = $fromform->description;
public function definition() { global $CFG; $strrequired = get_string('required'); $mform =& $this->_form; //set default value $search = $this->_customdata['search']; if (isset($this->_customdata['coverage'])) { $coverage = $this->_customdata['coverage']; } else { $coverage = 'all'; } if (isset($this->_customdata['licence'])) { $licence = $this->_customdata['licence']; } else { $licence = 'all'; } if (isset($this->_customdata['subject'])) { $subject = $this->_customdata['subject']; } else { $subject = 'all'; } if (isset($this->_customdata['audience'])) { $audience = $this->_customdata['audience']; } else { $audience = 'all'; } if (isset($this->_customdata['language'])) { $language = $this->_customdata['language']; } else { $language = current_language(); } if (isset($this->_customdata['educationallevel'])) { $educationallevel = $this->_customdata['educationallevel']; } else { $educationallevel = 'all'; } if (isset($this->_customdata['visibility'])) { $visibility = $this->_customdata['visibility']; } else { $visibility = COURSEVISIBILITY_NOTVISIBLE; } if (isset($this->_customdata['downloadable'])) { $downloadable = $this->_customdata['downloadable']; } else { $downloadable = 1; } if (isset($this->_customdata['siteid'])) { $siteid = $this->_customdata['siteid']; } else { $siteid = 'all'; } if (isset($this->_customdata['lastmodified'])) { $lastmodified = $this->_customdata['lastmodified']; } else { $lastmodified = HUB_LASTMODIFIED_WEEK; } if (isset($this->_customdata['orderby'])) { $orderby = $this->_customdata['orderby']; } else { $orderby = 'newest'; } $mform->addElement('header', 'site', get_string('search', 'local_hub')); $options = array(0 => get_string('enrollable', 'local_hub'), 1 => get_string('downloadable', 'local_hub')); if (key_exists('adminform', $this->_customdata)) { $options = array('all' => get_string('any')) + $options; } $mform->addElement('select', 'downloadable', get_string('enroldownload', 'local_hub'), $options); $mform->addHelpButton('downloadable', 'enroldownload', 'local_hub'); $mform->setDefault('downloadable', $downloadable); //visible field //Note: doesn't matter if form html is hacked, index script does not return any invisible courses if (key_exists('adminform', $this->_customdata)) { $options = array(); $options[COURSEVISIBILITY_ALL] = get_string('visibilityall', 'local_hub'); $options[COURSEVISIBILITY_VISIBLE] = get_string('visibilityyes', 'local_hub'); $options[COURSEVISIBILITY_NOTVISIBLE] = get_string('visibilityno', 'local_hub'); $mform->addElement('select', 'visibility', get_string('visibility', 'local_hub'), $options); $mform->setDefault('visibility', $visibility); unset($options); $mform->addHelpButton('visibility', 'visibility', 'local_hub'); } $options = array(); $options['all'] = get_string('any'); $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub'); $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub'); $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub'); $mform->addElement('select', 'audience', get_string('audience', 'local_hub'), $options); $mform->setDefault('audience', $audience); unset($options); $mform->addHelpButton('audience', 'audience', 'local_hub'); if (key_exists('adminform', $this->_customdata)) { $options = array(); $options['all'] = '-'; $options[HUB_LASTMODIFIED_WEEK] = get_string('periodweek', 'local_hub'); $options[HUB_LASTMODIFIED_FORTEENNIGHT] = get_string('periodforteennight', 'local_hub'); $options[HUB_LASTMODIFIED_MONTH] = get_string('periodmonth', 'local_hub'); $mform->addElement('select', 'lastmodified', get_string('lastmodified', 'local_hub'), $options); $mform->setDefault('lastmodified', $lastmodified); unset($options); $mform->addHelpButton('lastmodified', 'lastmodified', 'local_hub'); } $options = array(); $options['all'] = get_string('any'); $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub'); $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub'); $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub'); $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub'); $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub'); $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub'); $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub'); $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'local_hub'), $options); $mform->setDefault('educationallevel', $educationallevel); unset($options); $mform->addHelpButton('educationallevel', 'educationallevel', 'local_hub'); require_once $CFG->dirroot . "/course/publish/lib.php"; $publicationmanager = new course_publish_manager(); $options = $publicationmanager->get_sorted_subjects(); foreach ($options as $key => &$option) { $keylength = strlen($key); if ($keylength == 10) { $option = " " . $option; } else { if ($keylength == 12) { $option = " " . $option; } } } $options = array_merge(array('all' => get_string('any')), $options); $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options); $mform->setDefault('subject', $subject); unset($options); $mform->addHelpButton('subject', 'subject', 'local_hub'); $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => true, 'mode' => 'compact')); require_once $CFG->libdir . "/licenselib.php"; $licensemanager = new license_manager(); $licences = $licensemanager->get_licenses(); $options = array(); $options['all'] = get_string('any'); foreach ($licences as $license) { $options[$license->shortname] = get_string($license->shortname, 'license'); } $mform->addElement('select', 'licence', get_string('license'), $options); unset($options); $mform->addHelpButton('licence', 'licence', 'local_hub'); $mform->setDefault('licence', $licence); //search for only language that exist in the course DB require_once $CFG->dirroot . "/local/hub/lib.php"; $hub = new local_hub(); $courseslanguages = $hub->get_courses_languages(); $alllanguages = get_string_manager()->get_list_of_languages(); $languages = array(); foreach ($courseslanguages as $languagecode => $lang) { if (isset($alllanguages[$languagecode])) { $languages[$languagecode] = $alllanguages[$languagecode]; } } asort($languages, SORT_LOCALE_STRING); $languages = array_merge(array('all' => get_string('any')), $languages); $mform->addElement('select', 'language', get_string('language'), $languages); $mform->setDefault('language', $language); $mform->addHelpButton('language', 'language', 'local_hub'); $mform->addElement('select', 'orderby', get_string('orderby', 'local_hub'), array('newest' => get_string('orderbynewest', 'local_hub'), 'eldest' => get_string('orderbyeldest', 'local_hub'), 'fullname' => get_string('orderbyname', 'local_hub'), 'publisher' => get_string('orderbypublisher', 'local_hub'), 'ratingaverage' => get_string('orderbyratingaverage', 'local_hub'))); $mform->setDefault('orderby', $orderby); $mform->setType('orderby', PARAM_ALPHA); $mform->addHelpButton('orderby', 'orderby', 'local_hub'); $mform->setAdvanced('audience'); $mform->setAdvanced('educationallevel'); $mform->setAdvanced('subject'); $mform->setAdvanced('licence'); $mform->setAdvanced('language'); $mform->setAdvanced('orderby'); if (key_exists('adminform', $this->_customdata)) { if ($hub->get_sites(array(), 0, 0, true) < 100) { // field not humanly usable over 100 sites. $sites = $hub->get_sites(); $siteids = array(); foreach ($sites as $site) { $siteids[$site->id] = $site->name; } asort($siteids, SORT_LOCALE_STRING); $siteids = array('all' => get_string('any')) + $siteids; $mform->addElement('select', 'siteid', get_string('site', 'local_hub'), $siteids); $mform->setDefault('siteid', $siteid); $mform->addHelpButton('siteid', 'site', 'local_hub'); } } $mform->addElement('text', 'search', get_string('keywords', 'local_hub')); $mform->setType('search', PARAM_ALPHANUMEXT); $mform->addHelpButton('search', 'keywords', 'local_hub'); $mform->setDefault('search', $search); $mform->addElement('submit', 'submitbutton', get_string('search', 'local_hub')); }
// // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Administrator can manage stolen secret on this page * @package localhub * @copyright 2011 Moodle Pty Ltd (http://moodle.com) * @author Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require '../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . "/local/hub/admin/forms.php"; admin_externalpage_setup('hubstolensecret'); $hub = new local_hub(); $renderer = $PAGE->get_renderer('local_hub'); $stolen = optional_param('stolen', 0, PARAM_INT); if ($stolen and sesskey()) { $confirm = optional_param('confirm', 0, PARAM_INT); if ($confirm) { //mark the token as stolen $hub->marksecretstolen($stolen); //delete site and web service token $hub->delete_site($stolen); $confirmmsg = $OUTPUT->notification(get_string('secretblocked', 'local_hub'), 'notifysuccess'); } else { $hackedsite = $hub->get_site($stolen); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('stolensecret', 'local_hub')); echo $renderer->stolensecret_confirmation($hackedsite);
* @copyright 2010 Moodle Pty Ltd (http://moodle.com) * @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); }
$imageheight = optional_param('imageheight', HUBLOGOIMAGEHEIGHT, PARAM_INT); //the screenshot height if (!empty($courseid) and !empty($filetype) and get_config('local_hub', 'hubenabled')) { switch ($filetype) { case HUB_BACKUP_FILE_TYPE: //check that the file is downloadable / set as visible $course = $DB->get_record('hub_course_directory', array('id' => $courseid)); if (!empty($course) && ($course->privacy or !empty($USER) and is_siteadmin($USER->id))) { //if the hub is set as PRIVATE, allow the download //either if the download is requested by a logged in user, //either if the download is requested by a site (server side request) $hubprivacy = get_config('local_hub', 'privacy'); $token = optional_param('token', '', PARAM_ALPHANUM); if (!empty($token)) { // check the communication token $hub = new local_hub(); $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, '', $token); } if ($hubprivacy != HUBPRIVATE or isloggedin() or !empty($communication)) { $level1 = floor($courseid / 1000) * 1000; $userdir = "hub/{$level1}/{$courseid}"; $remotemoodleurl = optional_param('remotemoodleurl', '', PARAM_URL); if (!empty($remotemoodleurl)) { $remotemoodleurl = ',' . $remotemoodleurl . ',' . getremoteaddr(); } else { $remotemoodleurl = ',' . 'unknown' . ',' . getremoteaddr(); } add_to_log(SITEID, 'local_hub', 'download backup', '', $courseid . $remotemoodleurl); send_file($CFG->dataroot . '/' . $userdir . '/backup_' . $courseid . ".mbz", $course->shortname . ".mbz", 'default', 0, false, true, '', false); } }
*/ require '../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . "/local/hub/forms.php"; admin_externalpage_setup('managecourses'); //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; } $hub = new local_hub(); $renderer = $PAGE->get_renderer('local_hub'); /// BULK OPERATIONS $bulkoperation = optional_param('bulkselect', false, PARAM_ALPHANUM); $confirm = optional_param('confirm', false, PARAM_INTEGER); if (!empty($bulkoperation) and confirm_sesskey()) { //retrieve all ids for ($i = 1; $i <= HUB_COURSE_PER_PAGE; $i = $i + 1) { $selectedcourseid = optional_param('bulk-' . $i, false, PARAM_INTEGER); if (!empty($selectedcourseid)) { $bulkcourses[] = $hub->get_course($selectedcourseid); } } if (!$confirm) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('managecourses', 'local_hub'), 3, 'main');
/** * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary. * The RSS feed content is a course search result. * @param array $args the arguments received in the url * $args[0] => context id = 2 (Front page) - not used * $args[1] => token * $args[2] => module name (it was needed by the rss/file.php to call this function) - not used * $args[3] => downloadable - PARAM_INT * $args[4] => audience - PARAM_ALPHA * $args[5] => educationallevel - PARAM_ALPHA * $args[6] => subject - PARAM_ALPHA * $args[7] => licence - PARAM_ALPHA * $args[8] => language - PARAM_ALPHANUMEXT * $args[9] => search - PARAM_TEXT (url encoded) * $args[10] => orderby - PARAM_ALPHA * @return string the full path to the cached RSS feed directory. Null if there is a problem. */ function hub_rss_get_feed($context, $args) { global $CFG, $DB; require_once $CFG->dirroot . '/local/hub/lib.php'; //are RSS feeds enabled? $enablerssfeeds = get_config('local_hub', 'enablerssfeeds'); if (empty($enablerssfeeds)) { debugging('DISABLED (module configuration)'); return null; } //check capabilities if (!has_capability('local/hub:view', $context)) { return null; } //TODO: cache $filename = 'rsssearch_' . $args[3] . '_' . $args[4] . '_' . $args[5] . '_' . $args[6] . '_' . $args[7] . '_' . $args[8] . '_' . $args[9] . '_' . $args[10]; $cachedfilepath = rss_get_file_full_name('local_hub', $filename); //get the courses from the search if ($args[7] != 'all') { $options['licenceshortname'] = $args[7]; } if ($args[6] != 'all') { $options['subject'] = $args[6]; } if ($args[4] != 'all') { $options['audience'] = $args[4]; } if ($args[5] != 'all') { $options['educationallevel'] = $args[5]; } if ($args[8] != 'all') { $options['language'] = $args[8]; } if ($args[3] != 'all') { $options['downloadable'] = $args[3]; $options['enrollable'] = !$args[3]; } else { $options['downloadable'] = true; $options['enrollable'] = true; } $options['search'] = empty($args[9]) ? '' : urldecode($args[9]); //if the RSS invisible secret is passed as parameter, display not visible course $rsssecret = get_config('local_hub', 'rsssecret'); if (!empty($rsssecret) and $rsssecret == optional_param('rsssecret', false, PARAM_RAW)) { $options['visibility'] = COURSEVISIBILITY_NOTVISIBLE; } else { $options['visibility'] = COURSEVISIBILITY_VISIBLE; } //order by switch ($args[10]) { case 'newest': $options['orderby'] = 'timemodified DESC'; break; case 'eldest': $options['orderby'] = 'timemodified ASC'; break; case 'publisher': $options['orderby'] = 'publishername ASC'; break; case 'fullname': $options['orderby'] = 'fullname ASC'; break; case 'ratingaverage': $options['orderby'] = 'ratingaverage DESC'; break; default: break; } $hub = new local_hub(); $courses = $hub->get_courses($options, 0, 10); //generate the information for rss $rssfeedinfo = local_hub_rss_generate_feed_info($courses); //generate the rss content require_once $CFG->libdir . "/rsslib.php"; //First the RSS header $searchurl = new moodle_url($CFG->wwwroot . '/', array('downloadable' => $args[3], 'audience' => $args[4], 'educationallevel' => $args[5], 'subject' => $args[6], 'licence' => $args[7], 'language' => $args[8], 'search' => $args[9], 'orderby' => $args[10], 'submitbutton' => 'Search+for+courses')); $rsscontent = rss_standard_header(get_config('local_hub', 'name'), $searchurl->out(), get_string('hubcoursessearch', 'local_hub')); $rsscontent .= rss_add_items($rssfeedinfo); //Now the RSS footer $rsscontent .= rss_standard_footer(); if (!empty($rsscontent)) { rss_save_file('local_hub', $filename, $rsscontent); } //return the path to the cached version return $cachedfilepath; }
/** * Basically a batch script to blindly send all current hubsite emails and * contactable/subscribing status to Sendy @ lists.moodle.org. * * This was created since running a long sync like this during a live upgrade * would be a little too silly. Hub will update the list on demand whenever a * site is modified. * * @copyright 2014 Aparup Banerjee */ define('CLI_SCRIPT', true); require '../../../../config.php'; require_once $CFG->libdir . '/clilib.php'; // cli only functions // now get cli options list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help']) { $help = "Execute subscribers sync to sendy on lists.moodle.org enmasse\n\nOptions:\n-h, --help Print out this help\n\nExample:\n\$sudo -u vh-moodlenet /usr/bin/php local/hub/admin/cli/syncsubscribers_sendy.php\n"; echo $help; die; } require $CFG->dirroot . '/local/hub/lib.php'; $hub = new local_hub(); raise_memory_limit(MEMORY_HUGE); $sites = $hub->get_sites(); update_sendy_list_batch($sites);
public function test_add_communication() { global $DB; $this->resetAfterTest(true); $hub = new local_hub(); $sitetohubcommunication = new stdClass(); $sitetohubcommunication->token = '123456'; $sitetohubcommunication->type = WSSERVER; $sitetohubcommunication->remoteentity = REGISTEREDSITE; $sitetohubcommunication->remotename = 'test site'; $sitetohubcommunication->remoteurl = 'http://example.com'; $sitetohubcommunication->confirmed = 1; $sitetohubcommunication->id = $hub->add_communication($sitetohubcommunication); $this->assertTrue($sitetohubcommunication->id > 0); // Deleting a communication just toggles a deleted flage. // Adding another communication with the same details // should result in the ID of the new and old communication matching. $originalID = $sitetohubcommunication->id; $hub->delete_communication($sitetohubcommunication); $newID = $hub->add_communication($sitetohubcommunication); $this->assertTrue($originalID == $newID); }
require_once $CFG->libdir . '/adminlib.php'; 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 {
// Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Administrator can see if server can * @package local_hub * @copyright 2014 Dan Poltawski <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require __DIR__ . '/../../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/local/hub/lib.php'; require_once $CFG->dirroot . "/local/hub/admin/forms.php"; admin_externalpage_setup('checksiteconnectivity'); $hub = new local_hub(); $mform = new local_hub_siteconnectivity_form(); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('checksiteconnectivity', 'local_hub')); if ($data = $mform->get_data()) { if ($hub->is_remote_site_valid($data->url)) { echo $OUTPUT->notification(get_string('urlaccessible', 'local_hub', $data->url), 'notifysuccess'); } else { echo $OUTPUT->notification(get_string('urlnotaccessible', 'local_hub', $data->url), 'notifyproblem'); } } $mform->display(); echo $OUTPUT->footer();
set_user_preference('user_home_page_preference', HOMEPAGE_SITE); } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 1) { redirect($CFG->wwwroot .'/my/'); } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) { $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING); } } if (isloggedin()) { add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID); } /// If the hub plugin is installed then we let it take over the homepage here if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) { require_once($CFG->dirroot.'/local/hub/lib.php'); $hub = new local_hub(); $continue = $hub->display_homepage(); //display_homepage() return true if the hub home page is not displayed //mostly when search form is not displayed for not logged users if (empty($continue)) { exit; } } $PAGE->set_pagetype('site-index'); $PAGE->set_docs_path(''); $PAGE->set_pagelayout('frontpage'); $editing = $PAGE->user_is_editing(); $PAGE->set_title($SITE->fullname); $PAGE->set_heading($SITE->fullname); echo $OUTPUT->header();
/** * Updates sites data (from moodle.org) into {hub_sites_directory} in moodle.net (hub.moodle.org) * @return object */ public static function sync_into_sitesregister($sites) { global $DB; // Ensure the current user is allowed to run this function $context = context_system::instance(); self::validate_context($context); require_capability('local/hub:viewinfo', $context); $returnable = new stdClass(); try { $params = self::validate_parameters(self::sync_into_sitesregister_parameters(), array('newdatasince' => $sites)); } catch (invalid_parameter_exception $ex) { // record and send back later - but try individual records (with individual stricter validation) $returnable->exception = $ex->debuginfo; } //do our own additional validation (to circumvent core and proceed with using/replacing nulls.) $nullablefields = array('hubid', 'url', 'name', 'description', 'moodleversion', 'moodlerelease', 'serverstring', 'host', 'ip', 'language', 'secret', 'countrycode', 'deleted', 'publicationmax', 'regioncode', 'street', 'geolocation', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'confirmed', 'redirectto', 'latitude', 'longitude'); $nullable_map = array('name' => ' ', 'deleted' => 0, 'publicationmax' => null); //what they should be in mdl_hub_site_directory $hub = new local_hub(); $syncerecs = array(); foreach ($params['newdatasince'] as $registrysite) { try { $syncrec = new stdClass(); //used in catch so we'll init here. $registrysite = (object) $registrysite; $syncrec->id = $registrysite->id; $syncrec->hubid = null; $objvars = get_object_vars($registrysite); //convert back to null and run extra validation. foreach ($objvars as $prop => $val) { if ($registrysite->otpnull === $val) { //got a null marker. if (array_key_exists($prop, $nullable_map)) { $registrysite->{$prop} = $nullable_map[$prop]; } else { if (in_array($prop, $nullablefields)) { //check on agreed nullables (remove if this is too restrictive in future) $registrysite->{$prop} = null; } } } } //drop otpnull and revalidate. unset($registrysite->otpnull); try { $registrysite = (object) self::validate_parameters(self::sync_into_sitesregister_parameters_safe(), (array) $registrysite); } catch (invalid_parameter_exception $ex) { //allow if it had been confirmed during moodle.org registration process. if (strpos($ex->debuginfo, 'url') == 0) { //exception starts with fieldname. if ($registrysite->confirmed == 0) { throw $ex; } } else { throw $ex; } } // if not the same, merge legacy 'mailme' into 'contactable' for hub. if ($registrysite->mailme != $registrysite->contactable) { //somewhere contactable was brought to registry@moodle.org. only 1.9 site registration uses mailme. $registrysite->contactable = $registrysite->mailme; // 1.9 changes to mailme brought through to hub. (this is a quick fix to a mess) @todo cleanup } //fix some common data length errors - just truncate (original is stored in moodle.org registry and a 2.x upgrade can fix it at hub) if (strlen($registrysite->moodlerelease) > 50) { $registrysite->moodlerelease = substr($registrysite->moodlerelease, 0, 49); } if (strlen($registrysite->ip) > 45) { $registrysite->ip = substr($registrysite->ip, 0, 44); } if (mb_detect_encoding($registrysite->name) == 'UTF-8' && mb_strlen($registrysite->name) > 255) { $registrysite->name = mb_substr($registrysite->name, 0, 246); //truncate must be mb safe!... } else { if (strlen($registrysite->name) > 255) { $registrysite->name = substr($registrysite->name, 0, 248); } } if (strlen($registrysite->countrycode) > 2) { $registrysite->countrycode = 'ZZ'; //the code for unknown country. solve this later in some checker. } if ($registrysite->hubid > 0) { // update this record $registrysite->id = $registrysite->hubid; unset($registrysite->hubid); // we don't care about registry ids at hub. $registrysite->unreachable = 0; //updated site means we should re-check this. $hub->update_site($registrysite); // has its own timemodified stamp $syncrec->hubid = $registrysite->id; // regsiteid -> hubid } else { if ($registrysite->hubid == null) { // add new unsycned site record // check! (remote may have failed in updating hubid, so this may just be an old skippable update to try again) unset($registrysite->id); unset($registrysite->hubid); $hubsite = $hub->add_site($registrysite, true); // has its own timecreated stamp $syncrec->hubid = $hubsite->id; } else { // just try to see if there is any match by url. (hubid would be < 1 to indicate previously failed syncs) $matchedsite = $hub->get_site_by_url($registrysite->url); if ($matchedsite && $registrysite->hubid < 1 && $matchedsite->secret == $registrysite->secret) { foreach (get_object_vars($registrysite) as $prop => $val) { if (isset($matchedsite->{$prop})) { $matchedsite->{$prop} = $val; } } $hub->update_site($matchedsite); $syncrec->hubid = $matchedsite->id; } } } } catch (Exception $ex) { // don't limit type of exception - carry on for all exceptions since we're working per record now. $syncrec->exception = $ex->debuginfo; } if (isset($syncrec->exception)) { error_log('sync_into_sitesregister() failed processing id ' . $syncrec->id); error_log('hubid ' . $syncrec->hubid); error_log('url ' . $registrysite->url); $syncrec->exception = utf8_encode($syncrec->exception); //avoid character codings (non-utf8) causing response validation errors. error_log('exception: ' . $syncrec->exception); } $syncerecs[] = $syncrec; } $returnable->reghubidmap = $syncerecs; $returnable->timesynced = time(); return $returnable; }