<commit_before><?php
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// This file is part of Moodle - http://moodle.org/                      //
// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
//                                                                       //
// Moodle is free software: you can redistribute it and/or modify        //
// it under the terms of the GNU General Public License as published by  //
// the Free Software Foundation, either version 3 of the License, or     //
// (at your option) any later version.                                   //
//                                                                       //
// 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/>.       //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

/*
 * @package    moodle
 * @subpackage registration
 * @author     <NAME> <<EMAIL>>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
 *
 * The forms needed by registration pages.
*/


require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot.'/lib/hublib.php');

/**
 * This form display a hub selector.
 * The hub list is retrieved from Moodle.org hub directory.
 * Also displayed, a text field to enter private hub url + its password
 */
class hub_selector_form extends moodleform {

    public function definition() {
        global $CFG;
        $mform =& $this->_form;
        $mform->addElement('header', 'site', get_string('selecthub', 'hub'));

        //retrieve the hub list on the hub directory by web service
        $function = 'hubdirectory_get_hubs';
        $params = array();
        $serverurl = HUB_HUBDIRECTORYURL."/local/hubdirectory/webservice/webservices.php";
        require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
        $xmlrpcclient = new webservice_xmlrpc_client();
        $hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);

        //remove moodle.org from the hub list
        foreach ($hubs as $key => $hub) {
            if ($hub['url'] == HUB_MOODLEORGHUBURL) {
                unset($hubs[$key]);
            }
        }

        //Public hub list
        $options = array();
        foreach ($hubs as $hub) {
            //to not display a name longer than 100 character (too big)
            if (strlen($hub['name'])>100) {
                $hubname = substr($hub['name'],0, 100);
                $hubname = $hubname."...";
            } else {
                $hubname = $hub['name'];
            }
            $options[$hub['url']] = $hubname;
            $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
        }
        $mform->addElement('select', 'publichub', get_string('publichub','hub'),
                $options, array("size" => 15));

        $mform->addElement('static','or' , '', get_string('orenterprivatehub', 'hub'));

        //Private hub
        $mform->addElement('text','unlistedurl' , get_string('privatehuburl', 'hub'));
        $mform->addElement('text','password' , get_string('password'));

        $this->add_action_buttons(false, get_string('selecthub', 'hub'));
    }

    /**
     * Check the unlisted URL is a URL
     */
    function validation($data, $files) {
        global $CFG;
        $errors = parent::validation($data, $files);

        $unlistedurl = $this->_form->_submitValues['unlistedurl'];

        if (!empty($unlistedurl)) {
            $unlistedurltotest = clean_param($unlistedurl, PARAM_URL);
            if (empty($unlistedurltotest)) {
                $errors['unlistedurl'] = get_string('badurlformat', 'hub');
            }
        }

        return $errors;
    }

}


/**
 * The site registration form. Information will be sent to a given hub.
 */
class site_registration_form extends moodleform {

    public function definition() {
        global $CFG, $DB;

        $strrequired = get_string('required');
        $mform =& $this->_form;
        $huburl = $this->_customdata['huburl'];
        $hubname = $this->_customdata['hubname'];
        $password = $this->_customdata['password'];
        $admin = get_admin();
        $site = get_site();

        //retrieve config for this hub and set default if they don't exist
        $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
        $sitename = get_config('hub', 'site_name_'.$cleanhuburl);
        if ($sitename === false) {
            $sitename = $site->fullname;
        }
        $sitedescription = get_config('hub', 'site_description_'.$cleanhuburl);
        if ($sitedescription === false) {
            $sitedescription = $site->summary;
        }
        $contactname = get_config('hub', 'site_contactname_'.$cleanhuburl);
        if ($contactname === false) {
            $contactname = fullname($admin, true);
        }
        $contactemail = get_config('hub', 'site_contactemail_'.$cleanhuburl);
        if ($contactemail === false) {
            $contactemail = $admin->email;
        }
        $contactphone = get_config('hub', 'site_contactphone_'.$cleanhuburl);
        if ($contactphone === false) {
            $contactphone = $admin->phone1;
        }
        $imageurl = get_config('hub', 'site_imageurl_'.$cleanhuburl);
        $privacy = get_config('hub', 'site_privacy_'.$cleanhuburl);
        $address = get_config('hub', 'site_address_'.$cleanhuburl);
        $region = get_config('hub', 'site_region_'.$cleanhuburl);
        $country = get_config('hub', 'site_country_'.$cleanhuburl);
        if ($country === false) {
            $country =  $admin->country;
        }
        $geolocation = get_config('hub', 'site_geolocation_'.$cleanhuburl);
        $contactable = get_config('hub', 'site_contactable_'.$cleanhuburl);
        $emailalert = get_config('hub', 'site_emailalert_'.$cleanhuburl);
        $coursesnumber = get_config('hub', 'site_coursesnumber_'.$cleanhuburl);
        $usersnumber = get_config('hub', 'site_usersnumber_'.$cleanhuburl);
        $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl);
        $postsnumber = get_config('hub', 'site_postsnumber_'.$cleanhuburl);
        $questionsnumber = get_config('hub', 'site_questionsnumber_'.$cleanhuburl);
        $resourcesnumber = get_config('hub', 'site_resourcesnumber_'.$cleanhuburl);
        $mediancoursesize = get_config('hub', 'site_mediancoursesize_'.$cleanhuburl);

        //hidden parameters
        $mform->addElement('hidden', 'huburl', $huburl);
        $mform->addElement('hidden', 'hubname', $hubname);
        $mform->addElement('hidden', 'password', $password);

        //the input parameters
        $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));

        $mform->addElement('text','name' , get_string('fullsitename'));
        $mform->addRule('name', $strrequired, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);
        $mform->setDefault('name', $sitename);

        $options = array();
        $hub = new hub();
        $options[HUB_SITENOTPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENOTPUBLISHED);
        $options[HUB_SITENAMEPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
        $options[HUB_SITELINKPUBLISHED] = $hub->get_site_privacy_string(HUB_SITELINKPUBLISHED);
        $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
        $mform->setDefault('privacy', $privacy);
        $mform->addHelpButton('privacy', 'privacy', 'hub');
        unset($options);

        $mform->addElement('textarea', 'description', get_string('description'), array('rows'=>10));
        $mform->addRule('description', $strrequired, 'required', null, 'client');
        $mform->setDefault('description', $sitedescription);
        $mform->setType('description', PARAM_TEXT);

        $mform->addElement('static', 'urlstring',get_string('siteurl', 'hub'), $CFG->wwwroot);

        $languages = get_string_manager()->get_list_of_languages();
        $mform->addElement('static', 'langstring',get_string('language'), $languages[current_language()]);
        $mform->addElement('hidden', 'language', current_language());

        $mform->addElement('static', 'versionstring',get_string('moodleversion'), $CFG->version);
        $mform->addElement('hidden', 'moodleversion', $CFG->version);

        $mform->addElement('static', 'releasestring',get_string('moodlerelease'), $CFG->release);
        $mform->addElement('hidden', 'moodlerelease', $CFG->release);

        $mform->addElement('textarea','address' , get_string('postaladdress', 'hub'));<commit_msg>Make the description field bigger<commit_after><?php
///////////////////////////////////////////////////////////////////////////
//                                                                       //
// This file is part of Moodle - http://moodle.org/                      //
// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
//                                                                       //
// Moodle is free software: you can redistribute it and/or modify        //
// it under the terms of the GNU General Public License as published by  //
// the Free Software Foundation, either version 3 of the License, or     //
// (at your option) any later version.                                   //
//                                                                       //
// 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/>.       //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

/*
 * @package    moodle
 * @subpackage registration
 * @author     <NAME> <<EMAIL>>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
 *
 * The forms needed by registration pages.
*/


require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot.'/lib/hublib.php');

/**
 * This form display a hub selector.
 * The hub list is retrieved from Moodle.org hub directory.
 * Also displayed, a text field to enter private hub url + its password
 */
class hub_selector_form extends moodleform {

    public function definition() {
        global $CFG;
        $mform =& $this->_form;
        $mform->addElement('header', 'site', get_string('selecthub', 'hub'));

        //retrieve the hub list on the hub directory by web service
        $function = 'hubdirectory_get_hubs';
        $params = array();
        $serverurl = HUB_HUBDIRECTORYURL."/local/hubdirectory/webservice/webservices.php";
        require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
        $xmlrpcclient = new webservice_xmlrpc_client();
        $hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);

        //remove moodle.org from the hub list
        foreach ($hubs as $key => $hub) {
            if ($hub['url'] == HUB_MOODLEORGHUBURL) {
                unset($hubs[$key]);
            }
        }

        //Public hub list
        $options = array();
        foreach ($hubs as $hub) {
            //to not display a name longer than 100 character (too big)
            if (strlen($hub['name'])>100) {
                $hubname = substr($hub['name'],0, 100);
                $hubname = $hubname."...";
            } else {
                $hubname = $hub['name'];
            }
            $options[$hub['url']] = $hubname;
            $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
        }
        $mform->addElement('select', 'publichub', get_string('publichub','hub'),
                $options, array("size" => 15));

        $mform->addElement('static','or' , '', get_string('orenterprivatehub', 'hub'));

        //Private hub
        $mform->addElement('text','unlistedurl' , get_string('privatehuburl', 'hub'));
        $mform->addElement('text','password' , get_string('password'));

        $this->add_action_buttons(false, get_string('selecthub', 'hub'));
    }

    /**
     * Check the unlisted URL is a URL
     */
    function validation($data, $files) {
        global $CFG;
        $errors = parent::validation($data, $files);

        $unlistedurl = $this->_form->_submitValues['unlistedurl'];

        if (!empty($unlistedurl)) {
            $unlistedurltotest = clean_param($unlistedurl, PARAM_URL);
            if (empty($unlistedurltotest)) {
                $errors['unlistedurl'] = get_string('badurlformat', 'hub');
            }
        }

        return $errors;
    }

}


/**
 * The site registration form. Information will be sent to a given hub.
 */
class site_registration_form extends moodleform {

    public function definition() {
        global $CFG, $DB;

        $strrequired = get_string('required');
        $mform =& $this->_form;
        $huburl = $this->_customdata['huburl'];
        $hubname = $this->_customdata['hubname'];
        $password = $this->_customdata['password'];
        $admin = get_admin();
        $site = get_site();

        //retrieve config for this hub and set default if they don't exist
        $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
        $sitename = get_config('hub', 'site_name_'.$cleanhuburl);
        if ($sitename === false) {
            $sitename = $site->fullname;
        }
        $sitedescription = get_config('hub', 'site_description_'.$cleanhuburl);
        if ($sitedescription === false) {
            $sitedescription = $site->summary;
        }
        $contactname = get_config('hub', 'site_contactname_'.$cleanhuburl);
        if ($contactname === false) {
            $contactname = fullname($admin, true);
        }
        $contactemail = get_config('hub', 'site_contactemail_'.$cleanhuburl);
        if ($contactemail === false) {
            $contactemail = $admin->email;
        }
        $contactphone = get_config('hub', 'site_contactphone_'.$cleanhuburl);
        if ($contactphone === false) {
            $contactphone = $admin->phone1;
        }
        $imageurl = get_config('hub', 'site_imageurl_'.$cleanhuburl);
        $privacy = get_config('hub', 'site_privacy_'.$cleanhuburl);
        $address = get_config('hub', 'site_address_'.$cleanhuburl);
        $region = get_config('hub', 'site_region_'.$cleanhuburl);
        $country = get_config('hub', 'site_country_'.$cleanhuburl);
        if ($country === false) {
            $country =  $admin->country;
        }
        $geolocation = get_config('hub', 'site_geolocation_'.$cleanhuburl);
        $contactable = get_config('hub', 'site_contactable_'.$cleanhuburl);
        $emailalert = get_config('hub', 'site_emailalert_'.$cleanhuburl);
        $coursesnumber = get_config('hub', 'site_coursesnumber_'.$cleanhuburl);
        $usersnumber = get_config('hub', 'site_usersnumber_'.$cleanhuburl);
        $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl);
        $postsnumber = get_config('hub', 'site_postsnumber_'.$cleanhuburl);
        $questionsnumber = get_config('hub', 'site_questionsnumber_'.$cleanhuburl);
        $resourcesnumber = get_config('hub', 'site_resourcesnumber_'.$cleanhuburl);
        $mediancoursesize = get_config('hub', 'site_mediancoursesize_'.$cleanhuburl);

        //hidden parameters
        $mform->addElement('hidden', 'huburl', $huburl);
        $mform->addElement('hidden', 'hubname', $hubname);
        $mform->addElement('hidden', 'password', $password);

        //the input parameters
        $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));

        $mform->addElement('text','name' , get_string('fullsitename'));
        $mform->addRule('name', $strrequired, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);
        $mform->setDefault('name', $sitename);

        $options = array();
        $hub = new hub();
        $options[HUB_SITENOTPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENOTPUBLISHED);
        $options[HUB_SITENAMEPUBLISHED] = $hub->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
        $options[HUB_SITELINKPUBLISHED] = $hub->get_site_privacy_string(HUB_SITELINKPUBLISHED);
        $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
        $mform->setDefault('privacy', $privacy);
        $mform->addHelpButton('privacy', 'privacy', 'hub');
        unset($options);

        $mform->addElement('textarea', 'description', get_string('description'), array('rows'=>8, 'cols'=>50));
        $mform->addRule('description', $strrequired, 'required', null, 'client');
        $mform->setDefault('description', $sitedescription);
        $mform->setType('description', PARAM_TEXT);

        $mform->addElement('static', 'urlstring',get_string('siteurl', 'hub'), $CFG->wwwroot);

        $languages = get_string_manager()->get_list_of_languages();
        $mform->addElement('static', 'langstring',get_string('language'), $languages[current_language()]);
        $mform->addElement('hidden', 'language', current_language());

        $mform->addElement('static', 'versionstring',get_string('moodleversion'), $CFG->version);
        $mform->addElement('hidden', 'moodleversion', $CFG->version);

        $mform->addElement('static', 'releasestring',get_string('moodlerelease'), $CFG->release);
        $mform->addElement('hidden', 'moodlerelease', $CFG->release);

        $mform->addElement('textarea','address' , get_string('postaladdress', 'hub'));
{'fraction_non_alphanumeric': 0.1652649059838217, 'fraction_numerical': 0.002196389350190175, 'mean_word_length': 2.356346637900036, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 130, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7363060', 'n_tokens_mistral': 5354, 'n_tokens_neox': 5203, 'n_words': 1076}