├── top ├── stats │ ├── xml │ │ └── .gitignore │ ├── cache │ │ └── .gitignore │ ├── js │ │ ├── ajax.js │ │ └── ajax-dynamic-content.js │ ├── sites.bar.png │ ├── moodle2.php │ ├── lib.php │ └── index.php └── sites │ ├── cache │ └── .gitignore │ ├── world.png │ ├── world-big.png │ ├── moodle-growth.gif │ ├── moodle-registered-sites-20091103-large.jpg │ ├── moodle-registered-sites-20091103-small.jpg │ ├── moodle-registered-sites-20061001-large-sm.png │ ├── growth.html │ ├── contact.html │ ├── contact.php │ ├── edit.php │ ├── index.php │ ├── index_norecordset.php │ └── index_norestrictbycountry.php ├── less ├── hub.less ├── Makefile └── top │ └── site.less ├── images ├── addthis.png ├── twitter.png ├── facebook.png └── featured.png ├── .mdtconfig ├── style └── hub.css ├── README.txt ├── version.php ├── db ├── messages.php ├── install.php ├── access.php └── services.php ├── conf └── moodle.net.conf ├── admin ├── cli │ └── syncsubscribers_sendy.php ├── checksiteconnectivity.php ├── checksendystatus.php ├── stolensecret.php ├── confirmregistration.php ├── sitesettings.php ├── managesites.php ├── coursesettings.php ├── settings.php ├── register.php └── managecourses.php ├── webservice ├── webservices.php ├── locallib.php ├── upload.php └── download.php ├── locallib.php ├── settings.php ├── yui └── courses │ └── courses.js ├── sendmessage.php ├── rsslib.php ├── styles.css └── tests └── lib_test.php /top/stats/xml/.gitignore: -------------------------------------------------------------------------------- 1 | *.xml -------------------------------------------------------------------------------- /top/sites/cache/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | -------------------------------------------------------------------------------- /top/stats/cache/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | -------------------------------------------------------------------------------- /less/hub.less: -------------------------------------------------------------------------------- 1 | @maincolr: #944; 2 | @import "top/site.less"; -------------------------------------------------------------------------------- /images/addthis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/images/addthis.png -------------------------------------------------------------------------------- /images/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/images/twitter.png -------------------------------------------------------------------------------- /less/Makefile: -------------------------------------------------------------------------------- 1 | all : 2 | recess --compile --compress hub.less > ../style/hub.css 3 | .PHONY : all 4 | -------------------------------------------------------------------------------- /images/facebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/images/facebook.png -------------------------------------------------------------------------------- /images/featured.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/images/featured.png -------------------------------------------------------------------------------- /top/sites/world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/world.png -------------------------------------------------------------------------------- /top/stats/js/ajax.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/stats/js/ajax.js -------------------------------------------------------------------------------- /top/sites/world-big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/world-big.png -------------------------------------------------------------------------------- /top/stats/sites.bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/stats/sites.bar.png -------------------------------------------------------------------------------- /top/sites/moodle-growth.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/moodle-growth.gif -------------------------------------------------------------------------------- /.mdtconfig: -------------------------------------------------------------------------------- 1 | MDTSITE=moodle.net 2 | MDTVERSION=3.3 3 | MDTCOMPONENT=local_hub 4 | MDTRELPATH=local/hub/ 5 | MDTEXPORT=origin/master 6 | -------------------------------------------------------------------------------- /top/sites/moodle-registered-sites-20091103-large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/moodle-registered-sites-20091103-large.jpg -------------------------------------------------------------------------------- /top/sites/moodle-registered-sites-20091103-small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/moodle-registered-sites-20091103-small.jpg -------------------------------------------------------------------------------- /top/sites/moodle-registered-sites-20061001-large-sm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-local_hub/master/top/sites/moodle-registered-sites-20061001-large-sm.png -------------------------------------------------------------------------------- /style/hub.css: -------------------------------------------------------------------------------- 1 | #page-local-hub-top-sites .activesitesimg,#page-local-hub-top-sites .countrymapimg{width:100%;max-width:600px;max-height:300px}#page-local-hub-top-sites .countrymapimg{width:100%;max-width:440px;max-height:220px} 2 | -------------------------------------------------------------------------------- /less/top/site.less: -------------------------------------------------------------------------------- 1 | #page-local-hub-top-sites { 2 | .navbar { 3 | /*border: 1px @maincolr solid;*/ 4 | } 5 | .activesitesimg, .countrymapimg { 6 | max-height: 300px; 7 | width: 100%; 8 | max-width: 600px; 9 | } 10 | .countrymapimg { 11 | max-height: 220px; 12 | width: 100%; 13 | max-width: 440px; 14 | } 15 | } -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Moodle Community Hub Server 2 | =========================== 3 | 4 | This hub server turns a Moodle site into a Community hub, 5 | where other sites can share courses as downloads (for use 6 | as templates) or links (for enrolling in). 7 | 8 | Development spec: 9 | http://docs.moodle.org/en/Development:Community_hub 10 | 11 | Hub Administration 12 | http://docs.moodle.org/en/Hub_administration 13 | 14 | 15 | 16 | Installation 17 | ------------ 18 | 19 | 1. Place this folder in your Moodle as /local/hub 20 | 2. Visit the Moodle admin page (/admin) to install 21 | 3. Configure via the new Hub item in the Admin menu 22 | 4. Register your hub with the moodle.org hub directory. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /top/sites/growth.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 |


24 | mouse over the image to change.
25 | red = 2006
26 | yellow = 2009
27 | 28 | 29 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | $plugin->component = 'local_hub'; 18 | $plugin->release = '3.3.0'; 19 | $plugin->version = 2017052400; 20 | $plugin->requires = 2017051500; 21 | $plugin->maturity = MATURITY_STABLE; 22 | $plugin->cron = 0; 23 | -------------------------------------------------------------------------------- /db/messages.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Hub message provider 20 | * @package localhub 21 | * @copyright 2013 Moodle Pty Ltd (http://moodle.com) 22 | * @author Jerome Mouneyrac 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | $messageproviders = array ('coursehubmessage' => array ()); 28 | -------------------------------------------------------------------------------- /conf/moodle.net.conf: -------------------------------------------------------------------------------- 1 | # Include this file into the apache vhost configuration file 2 | # for this site. 3 | 4 | #ErrorDocument 401 "/error/index.php?status=401" 5 | #ErrorDocument 403 "/error/index.php?status=403" 6 | #ErrorDocument 404 "/error/index.php?status=404" 7 | #ErrorDocument 408 "/error/index.php?status=408" 8 | #ErrorDocument 500 "/error/index.php?status=500" 9 | #ErrorDocument 501 "/error/index.php?status=501" 10 | #ErrorDocument 502 "/error/index.php?status=502" 11 | #ErrorDocument 503 "/error/index.php?status=503" 12 | #ErrorDocument 504 "/error/index.php?status=504" 13 | #ErrorDocument 505 "/error/index.php?status=505" 14 | 15 | RewriteEngine On 16 | 17 | # When attempting to access the site configuration files, throw 404 18 | RewriteCond %{REQUEST_URI} ^/local/hub/conf/(.*)$ [NC] 19 | RewriteRule . - [R=404,L] 20 | 21 | RewriteCond %{REQUEST_URI} ^/sites(/|$) [NC,OR] 22 | RewriteCond %{REQUEST_URI} ^/stats(/|$) [NC] 23 | RewriteRule ^(.*)$ /local/hub/top$1 [L] 24 | 25 | #RewriteCond %{REQUEST_URI} ^/error(/|$) [NC] 26 | #RewriteRule ^/error(.*)$ /local/moodleorg/top/error$1 [L] 27 | 28 | #RewriteCond %{REQUEST_URI} ^/\.git(/|$) [NC] 29 | #RewriteRule . - [R=404,L] 30 | -------------------------------------------------------------------------------- /admin/cli/syncsubscribers_sendy.php: -------------------------------------------------------------------------------- 1 | libdir.'/clilib.php'); // cli only functions 18 | 19 | 20 | // now get cli options 21 | list($options, $unrecognized) = cli_get_params(array('help'=>false), 22 | array('h'=>'help')); 23 | 24 | if ($unrecognized) { 25 | $unrecognized = implode("\n ", $unrecognized); 26 | cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 27 | } 28 | 29 | if ($options['help']) { 30 | $help = 31 | "Execute subscribers sync to sendy on lists.moodle.org enmasse 32 | 33 | Options: 34 | -h, --help Print out this help 35 | 36 | Example: 37 | \$sudo -u vh-moodlenet /usr/bin/php local/hub/admin/cli/syncsubscribers_sendy.php 38 | "; 39 | 40 | echo $help; 41 | die; 42 | } 43 | 44 | require($CFG->dirroot. '/local/hub/lib.php'); 45 | $hub = new local_hub(); 46 | raise_memory_limit(MEMORY_HUGE); 47 | $sites = $hub->get_sites(); 48 | update_sendy_list_batch($sites); 49 | -------------------------------------------------------------------------------- /webservice/webservices.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Hub XML-RPC web service entry point. The authentication is done via hub tokens (hidden). 20 | * 21 | * @package localhub 22 | * @copyright 2009 Moodle Pty Ltd (http://moodle.com) 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | // disable moodle specific debug messages and any errors in output 27 | define('NO_DEBUG_DISPLAY', true); 28 | define('NO_MOODLE_COOKIES', true); 29 | 30 | require('../../../config.php'); 31 | require_once($CFG->dirroot."/local/hub/webservice/locallib.php"); 32 | 33 | if (!webservice_protocol_is_enabled('xmlrpc') and !get_config('local_hub', 'hubenabled')) { 34 | die; 35 | } 36 | 37 | $server = new hub_webservice_xmlrpc_server(WEBSERVICE_AUTHMETHOD_PERMANENT_TOKEN); 38 | $server->run(); 39 | die; 40 | 41 | 42 | -------------------------------------------------------------------------------- /top/sites/contact.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 |
32 | -------------------------------------------------------------------------------- /admin/checksiteconnectivity.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Administrator can see if server can 20 | * @package local_hub 21 | * @copyright 2014 Dan Poltawski 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | require(__DIR__.'/../../../config.php'); 25 | 26 | require_once($CFG->libdir . '/adminlib.php'); 27 | require_once($CFG->dirroot . '/local/hub/lib.php'); 28 | require_once($CFG->dirroot . "/local/hub/admin/forms.php"); 29 | 30 | admin_externalpage_setup('checksiteconnectivity'); 31 | 32 | 33 | $hub = new local_hub(); 34 | $mform = new local_hub_siteconnectivity_form(); 35 | 36 | 37 | echo $OUTPUT->header(); 38 | echo $OUTPUT->heading(get_string('checksiteconnectivity', 'local_hub')); 39 | 40 | if ($data = $mform->get_data()) { 41 | if ($hub->is_remote_site_valid($data->url)) { 42 | echo $OUTPUT->notification(get_string('urlaccessible', 'local_hub', $data->url), 'notifysuccess'); 43 | } else { 44 | echo $OUTPUT->notification(get_string('urlnotaccessible', 'local_hub', $data->url), 'notifyproblem'); 45 | } 46 | } 47 | 48 | $mform->display(); 49 | 50 | echo $OUTPUT->footer(); -------------------------------------------------------------------------------- /locallib.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Library of functions for local_hub 20 | * 21 | * @package local_hub 22 | * @copyright 2015 Andrew Davis 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | /** 29 | * Construct an object to supply to email_to_user() 30 | * 31 | * @param string $email the required email address 32 | * @param string $firstname The desired user first name 33 | * @return stdClass An object that can be supplied to email_to_user() 34 | */ 35 | function local_hub_create_contact_user($email, $firstname) { 36 | $contactuser = new stdClass(); 37 | 38 | // Need an id, can't use id=0. would rather not use id=1, lets fool the api while we're still trying to use a fake user to send to. 39 | $contactuser->id = 2; // Used to retrieve the mailcharset user preference which defaults to 0. 40 | 41 | $contactuser->email = $email; 42 | $contactuser->firstname = $firstname; 43 | $contactuser->lastname = ''; 44 | 45 | foreach (get_all_user_name_fields() as $namefield) { 46 | if (!isset($contactuser->$namefield)) { 47 | $contactuser->$namefield = ''; 48 | } 49 | } 50 | 51 | return $contactuser; 52 | } 53 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Hub install 20 | * @package localhub 21 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 22 | * @author Jerome Mouneyrac 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | //This is temporary till MDL-25115 is implemented 27 | function xmldb_local_hub_install() { 28 | global $DB; 29 | 30 | //create a new scale called featured, at this moment moment we have no alternative than adding it to the DB 31 | //core TODO: better way to create a scale or adding a scale MDL-21631, MDL-16474 32 | $scale = new stdClass(); 33 | $scale->courseid = 0; 34 | $admin = get_admin(); 35 | $scale->userid = empty($admin)?2:$admin->id; //if the script is run before an admin has ever been created, assign userid = 2 (usual admin default) 36 | $scale->name = 'coursefeatured'; 37 | $scale->scale = get_string('featured', 'local_hub'); 38 | $scale->description = get_string('featureddesc', 'local_hub'); 39 | $scale->descriptionformat = 1; 40 | $scale->timemodified = time(); 41 | $scale->id = $DB->insert_record('scale', $scale); 42 | //save the scale id into the config table 43 | set_config('courseratingscaleid', $scale->id, 'local_hub'); 44 | 45 | // Set the extendedusernamechars option to true 46 | set_config('extendedusernamechars', 1); 47 | } 48 | -------------------------------------------------------------------------------- /admin/checksendystatus.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Administrator can check the status of an email address in Sendy 20 | * @package local_hub 21 | * @copyright 2015 Andrew Davis 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | require(__DIR__.'/../../../config.php'); 25 | 26 | require_once($CFG->libdir . '/adminlib.php'); 27 | require_once($CFG->dirroot . '/local/hub/lib.php'); 28 | require_once($CFG->dirroot . "/local/hub/admin/forms.php"); 29 | 30 | admin_externalpage_setup('checkemailsendystatus'); 31 | 32 | $hub = new local_hub(); 33 | $mform = new local_hub_checkemailsendystatus_form(); 34 | 35 | echo $OUTPUT->header(); 36 | echo $OUTPUT->heading(get_string('checkemailsendystatus', 'local_hub')); 37 | 38 | if ($data = $mform->get_data()) { 39 | $sendyurl = get_config('local_hub', 'sendyurl'); 40 | $sendylistid = get_config('local_hub', 'sendylistid'); 41 | $sendyapikey = get_config('local_hub', 'sendyapikey'); 42 | 43 | // Check for config.php overrides. 44 | if (isset($CFG->sendyurl)) { 45 | $sendyurl = $CFG->sendyurl; 46 | } 47 | if (isset($CFG->sendylistid)) { 48 | $sendylistid = $CFG->sendylistid; 49 | } 50 | if (isset($CFG->sendyapikey)) { 51 | $sendyapikey = $CFG->sendyapikey; 52 | } 53 | 54 | if (empty($sendyurl) || empty($sendylistid) || empty($sendyapikey)) { 55 | print_error('mailinglistnotconfigured', 'local_hub'); 56 | } 57 | 58 | $a = new stdClass(); 59 | $a->email = $data->email; 60 | $a->status = get_sendy_status($sendyurl, $sendyapikey, $sendylistid, $data->email); 61 | echo $OUTPUT->notification(get_string('emailsendystatus', 'local_hub', $a), 'notifysuccess'); 62 | } 63 | 64 | $mform->display(); 65 | 66 | echo $OUTPUT->footer(); 67 | -------------------------------------------------------------------------------- /webservice/locallib.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | require_once($CFG->dirroot."/webservice/xmlrpc/locallib.php"); 19 | require_once($CFG->dirroot."/local/hub/lib.php"); 20 | 21 | /** 22 | * Hub XML-RPC web server. 23 | * 24 | * @package localhub 25 | * @copyright 2009 Moodle Pty Ltd (http://moodle.com) 26 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 | */ 28 | 29 | class hub_webservice_xmlrpc_server extends webservice_xmlrpc_server { 30 | 31 | /** 32 | * Authenticate user from the received hub token 33 | * If no token, so we use the "public" hub community token from the system (create one if don't exist) 34 | */ 35 | protected function authenticate_user() { 36 | global $DB; 37 | 38 | //retrieve hub privacy 39 | $privacy = get_config('local_hub', 'privacy'); 40 | 41 | // hub server public access (search, rate, comment, import) 42 | if ($this->token == 'publichub' and $privacy != HUBPRIVATE) { 43 | 44 | $hub = new local_hub(); 45 | $publiccommunication = $hub->get_communication(WSSERVER, PUBLICSITE); 46 | 47 | if (empty($publiccommunication)) { 48 | $capabilities = array('local/hub:view'); 49 | $token = $hub->create_hub_token('Public Hub User', 50 | 'Public site', 'public_hub_user', $capabilities); 51 | $publiccommunication = new stdClass(); 52 | $publiccommunication->token = $token->token; 53 | $publiccommunication->type = WSSERVER; 54 | $publiccommunication->remotename = ''; 55 | $publiccommunication->remoteentity = PUBLICSITE; 56 | $publiccommunication->confirmed = 1; 57 | $publiccommunication->id = $hub->add_communication($publiccommunication); 58 | } 59 | 60 | $this->token = $publiccommunication->token; 61 | } 62 | 63 | parent::authenticate_user(); 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | : 18 | // 19 | // component_name should be the same as the directory name of the mod or block. 20 | // 21 | // Core moodle capabilities are defined thus: 22 | // moodle/: 23 | // 24 | // Examples: mod/forum:viewpost 25 | // block/recent_activity:view 26 | // moodle/site:deleteuser 27 | // 28 | // The variable name for the capability definitions array is $capabilities 29 | 30 | /** 31 | * Hub capabilities 32 | * @package localhub 33 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 34 | * @author Jerome Mouneyrac 35 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 | */ 37 | 38 | 39 | $capabilities = array( 40 | 'local/hub:viewinfo' => array( 41 | 'riskbitmask' => RISK_PERSONAL, 42 | 'captype' => 'read', 43 | 'contextlevel' => CONTEXT_SYSTEM, 44 | ), 45 | 'local/hub:viewsmallinfo' => array( 46 | 'captype' => 'read', 47 | 'contextlevel' => CONTEXT_SYSTEM, 48 | ), 49 | 'local/hub:updateinfo' => array( 50 | 'riskbitmask' => RISK_SPAM | RISK_DATALOSS, 51 | 'captype' => 'write', 52 | 'contextlevel' => CONTEXT_SYSTEM, 53 | ), 54 | 'local/hub:registercourse' => array( 55 | 'riskbitmask' => RISK_SPAM | RISK_DATALOSS, 56 | 'captype' => 'write', 57 | 'contextlevel' => CONTEXT_SYSTEM 58 | ), 59 | 'local/hub:view' => array( 60 | 'riskbitmask' => RISK_PERSONAL, 61 | 'captype' => 'read', 62 | 'contextlevel' => CONTEXT_SYSTEM, 63 | 'archetypes' => array( 64 | 'guest' => CAP_ALLOW, 65 | 'user' => CAP_ALLOW 66 | ) 67 | ), 68 | 'local/hub:unregistercourse' => array( 69 | 'riskbitmask' => RISK_DATALOSS, 70 | 'captype' => 'write', 71 | 'contextlevel' => CONTEXT_SYSTEM 72 | ), 73 | 74 | 75 | ); 76 | -------------------------------------------------------------------------------- /webservice/upload.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * this is a temporary file to manage upload till file upload design is done (most probably ws) 20 | * no time spend on identified the right course ID (we will probably need a new course secret string and 21 | * a new db field, or maybe return the real id during metadata record) 22 | * @package localhub 23 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 24 | * @author Jerome Mouneyrac 25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 | */ 27 | require('../../../config.php'); 28 | require_once($CFG->dirroot . '/local/hub/lib.php'); 29 | require_once($CFG->dirroot . '/course/publish/lib.php'); //HUB_SCREENSHOT_FILE_TYPE and HUB_BACKUP_FILE_TYPE 30 | 31 | 32 | $token = optional_param('token', '', PARAM_ALPHANUM); 33 | $filetype = optional_param('filetype', '', PARAM_ALPHA); //can be screenshots, backup, ... 34 | $screenshotnumber = optional_param('screenshotnumber', 1, PARAM_INT); //the screenshot number of this course 35 | $courseid = optional_param('courseid', '', PARAM_ALPHANUM); 36 | 37 | // check the communication token 38 | $hub = new local_hub(); 39 | $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, '', $token); 40 | if (!empty($token) && !empty($communication) and get_config('local_hub', 'hubenabled')) { 41 | 42 | //retrieve the site 43 | $siteurl = $communication->remoteurl; 44 | $site = $hub->get_site_by_url($siteurl); 45 | 46 | //check that the course exist 47 | $course = $DB->get_record('hub_course_directory', 48 | array('id' => $courseid, 'siteid' => $site->id)); 49 | 50 | if (!empty($course) && !empty($_FILES)) { 51 | switch ($filetype) { 52 | case HUB_BACKUP_FILE_TYPE: 53 | //check that the backup doesn't already exist 54 | $backup = $hub->backup_exits($courseid); 55 | if (empty($backup)) { 56 | $hub->add_backup($_FILES['file'], $courseid); 57 | } 58 | break; 59 | case HUB_SCREENSHOT_FILE_TYPE: 60 | $hub->add_screenshot($_FILES['file'], $courseid, $screenshotnumber); 61 | break; 62 | } 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /admin/stolensecret.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Administrator can manage stolen secret on this page 20 | * @package localhub 21 | * @copyright 2011 Moodle Pty Ltd (http://moodle.com) 22 | * @author Jerome Mouneyrac 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | require('../../../config.php'); 26 | 27 | require_once($CFG->libdir . '/adminlib.php'); 28 | require_once($CFG->dirroot . '/local/hub/lib.php'); 29 | require_once($CFG->dirroot . "/local/hub/admin/forms.php"); 30 | 31 | admin_externalpage_setup('hubstolensecret'); 32 | 33 | $hub = new local_hub(); 34 | $renderer = $PAGE->get_renderer('local_hub'); 35 | 36 | $stolen = optional_param('stolen', 0, PARAM_INT); 37 | if ($stolen and sesskey()) { 38 | $confirm = optional_param('confirm', 0, PARAM_INT); 39 | if ($confirm) { 40 | //mark the token as stolen 41 | $hub->marksecretstolen($stolen); 42 | 43 | //delete site and web service token 44 | $hub->delete_site($stolen); 45 | 46 | $confirmmsg = $OUTPUT->notification( 47 | get_string('secretblocked', 'local_hub'), 'notifysuccess'); 48 | } else { 49 | $hackedsite = $hub->get_site($stolen); 50 | echo $OUTPUT->header(); 51 | echo $OUTPUT->heading(get_string('stolensecret', 'local_hub')); 52 | echo $renderer->stolensecret_confirmation($hackedsite); 53 | echo $OUTPUT->footer(); 54 | die(); 55 | } 56 | } 57 | 58 | $mform = new hub_search_stolen_secret(); 59 | if ($data = $mform->get_data()) { 60 | $sites = array(); 61 | 62 | //search site 63 | if (!empty($data->secret)) { //by token 64 | $site = $hub->get_site_by_secret($data->secret); 65 | if (!empty($site)) { 66 | $search = $data->secret; 67 | $sites[] = $site; 68 | } 69 | } else if (!empty($data->sitename)) { //by site name 70 | $sites = $hub->get_sites(array('search' => $data->sitename)); 71 | $search = $data->sitename; 72 | } 73 | } 74 | 75 | /// OUTPUT 76 | echo $OUTPUT->header(); 77 | echo $OUTPUT->heading(get_string('stolensecret', 'local_hub')); 78 | if (!empty($confirmmsg)) { 79 | echo $confirmmsg; 80 | } 81 | $mform->display(); 82 | 83 | if (isset($sites)) { 84 | if (empty($sites)) { 85 | echo get_string('nosite', 'local_hub'); 86 | } else { 87 | echo highlight($search, $renderer->site_list($sites, true, true)); 88 | } 89 | } 90 | echo $OUTPUT->footer(); -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Add hub administration menu settings 19 | * @package localhub 20 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | 25 | /// Add hub administration pages to the Moodle administration menu 26 | $ADMIN->add('root', new admin_category('local_hub', get_string('hub', 'local_hub'))); 27 | 28 | $ADMIN->add('local_hub', new admin_externalpage('hubsettings', get_string('settings', 'local_hub'), 29 | $CFG->wwwroot."/local/hub/admin/settings.php", 30 | 'moodle/site:config')); 31 | 32 | $ADMIN->add('local_hub', new admin_externalpage('managesites', get_string('managesites', 'local_hub'), 33 | $CFG->wwwroot."/local/hub/admin/managesites.php", 34 | 'moodle/site:config')); 35 | 36 | $ADMIN->add('local_hub', new admin_externalpage('managecourses', get_string('managecourses', 'local_hub'), 37 | $CFG->wwwroot."/local/hub/admin/managecourses.php", 38 | 'moodle/site:config')); 39 | 40 | $ADMIN->add('local_hub', new admin_externalpage('hubregistration', get_string('registration', 'local_hub'), 41 | $CFG->wwwroot."/local/hub/admin/register.php", 42 | 'moodle/site:config')); 43 | 44 | $ADMIN->add('local_hub', new admin_externalpage('registrationconfirmed', 45 | get_string('registrationconfirmed', 'local_hub'), 46 | $CFG->wwwroot."/local/hub/admin/confirmregistration.php", 47 | 'moodle/site:config', true)); 48 | 49 | $ADMIN->add('local_hub', new admin_externalpage('sitesettings', get_string('sitesettings', 'local_hub'), 50 | $CFG->wwwroot."/local/hub/admin/sitesettings.php", 51 | 'moodle/site:config', true)); 52 | 53 | $ADMIN->add('local_hub', new admin_externalpage('hubcoursesettings', get_string('coursesettings', 'local_hub'), 54 | $CFG->wwwroot."/local/hub/admin/coursesettings.php", 55 | 'moodle/site:config', true)); 56 | 57 | $ADMIN->add('local_hub', new admin_externalpage('hubstolensecret', get_string('stolensecret', 'local_hub'), 58 | $CFG->wwwroot."/local/hub/admin/stolensecret.php", 59 | 'moodle/site:config')); 60 | 61 | $ADMIN->add('local_hub', new admin_externalpage('checksiteconnectivity', get_string('checksiteconnectivity', 'local_hub'), 62 | "/local/hub/admin/checksiteconnectivity.php", 63 | 'moodle/site:config')); 64 | 65 | $ADMIN->add('local_hub', new admin_externalpage('checkemailsendystatus', get_string('checkemailsendystatus', 'local_hub'), 66 | "/local/hub/admin/checksendystatus.php", 67 | 'moodle/site:config')); 68 | 69 | -------------------------------------------------------------------------------- /admin/confirmregistration.php: -------------------------------------------------------------------------------- 1 | . // 19 | // // 20 | /////////////////////////////////////////////////////////////////////////// 21 | 22 | /** 23 | * This is the page where the admin is redirected to from the hub directory once 24 | * the hub directory saved the hub information. 25 | * This page save the token that the hub directory gave us, in order to call the hub 26 | * directory later by web service. 27 | * @package localhub 28 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 29 | * @author Jerome Mouneyrac 30 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 | */ 32 | 33 | require('../../../config.php'); 34 | require_once($CFG->libdir.'/adminlib.php'); 35 | require_once($CFG->dirroot.'/local/hub/lib.php'); 36 | 37 | admin_externalpage_setup('hubregistration'); 38 | 39 | $newtoken = optional_param('newtoken', '', PARAM_ALPHANUM); 40 | $url = optional_param('url', '', PARAM_URL); 41 | $token = optional_param('token', '', PARAM_ALPHANUM); 42 | 43 | $hub = new local_hub(); 44 | 45 | //check that the token/url couple exist and is not confirmed 46 | $directorytohubcommunication = $hub->get_communication(WSSERVER, HUBDIRECTORY, $url); 47 | if (!empty($directorytohubcommunication) and $directorytohubcommunication->confirmed == 0 48 | and $directorytohubcommunication->token == $token) { 49 | 50 | $hub->confirm_communication($directorytohubcommunication); 51 | 52 | $hubtodirectorycommunication = new stdClass(); 53 | $hubtodirectorycommunication->token = $newtoken; 54 | $hubtodirectorycommunication->type = WSCLIENT; 55 | $hubtodirectorycommunication->remotename = 'Moodle.org hub directory'; 56 | $hubtodirectorycommunication->remoteentity = HUBDIRECTORY; 57 | $hubtodirectorycommunication->remoteurl = HUB_HUBDIRECTORYURL; 58 | $hubtodirectorycommunication->confirmed = 1; 59 | $hubtodirectorycommunication->id = $hub->add_communication($hubtodirectorycommunication); 60 | 61 | echo $OUTPUT->header(); 62 | echo $OUTPUT->notification(get_string('registrationconfirmed', 'local_hub'), 'notifysuccess'); 63 | echo $OUTPUT->footer(); 64 | } else { 65 | throw new moodle_exception('wrongtoken'); 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /admin/sitesettings.php: -------------------------------------------------------------------------------- 1 | . // 20 | // // 21 | /////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * On this page administrator can change site settings 25 | * @package localhub 26 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 27 | * @author Jerome Mouneyrac 28 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 | */ 30 | require('../../../config.php'); 31 | require_once($CFG->libdir . '/adminlib.php'); 32 | require_once($CFG->dirroot . '/local/hub/admin/forms.php'); 33 | 34 | admin_externalpage_setup('sitesettings'); 35 | 36 | $id = optional_param('id', 0, PARAM_INT); 37 | $hub = new local_hub(); 38 | $site = $hub->get_site($id, MUST_EXIST); 39 | 40 | //define nav bar 41 | $PAGE->set_url('/local/hub/admin/sitesettings.php', array('id' => $id)); 42 | $PAGE->navbar->ignore_active(true); 43 | $PAGE->navbar->add(get_string('administrationsite')); 44 | $PAGE->navbar->add(get_string('hub', 'local_hub')); 45 | $PAGE->navbar->add(get_string('managesites', 'local_hub'), 46 | new moodle_url('/local/hub/admin/managesites.php', 47 | array('search' => $site->name, 'sesskey' => sesskey()))); 48 | $PAGE->navbar->add(get_string('sitesettings', 'local_hub'), 49 | new moodle_url('/local/hub/admin/sitesettings.php', array('id' => $id))); 50 | 51 | 52 | $sitesettingsform = new hub_site_settings_form('', 53 | array('id' => $id)); 54 | $fromform = $sitesettingsform->get_data(); 55 | 56 | //Save settings and redirect to search site page 57 | if (!empty($fromform)) { 58 | if ($fromform->publicationmax === '') { 59 | $site->publicationmax = null; 60 | } else { 61 | $site->publicationmax = $fromform->publicationmax; 62 | } 63 | $site->name = $fromform->name; 64 | $site->description = $fromform->description; 65 | $site->contactname = $fromform->contactname; 66 | $site->contactemail = $fromform->contactemail; 67 | $site->language = $fromform->language; 68 | $site->countrycode = $fromform->countrycode; 69 | $site->url = $fromform->url; 70 | 71 | $hub->update_site($site); 72 | 73 | redirect(new moodle_url('/local/hub/admin/managesites.php', 74 | array('sitesettings' => $site->name, 'sesskey' => sesskey(), 75 | 'search' => $site->name))); 76 | } 77 | 78 | //OUTPUT 79 | echo $OUTPUT->header(); 80 | $sitesettingsform->display(); 81 | echo $OUTPUT->footer(); 82 | 83 | -------------------------------------------------------------------------------- /top/stats/moodle2.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * @package moodle-dot-org 20 | * @subpackage stats 21 | * @copyright 2011 Martin Dougiamas 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | require('../../../../config.php'); 26 | 27 | error_reporting(E_ALL); 28 | ini_set('display_errors', true); 29 | 30 | $PAGE->set_context(context_system::instance()); 31 | $PAGE->set_title(get_string('aboutstatisticstitle', 'local_hub')); 32 | $PAGE->set_heading('Registered sites: Moodle 2.0.x'); 33 | $PAGE->set_url(new moodle_url('/stats/moodle2.php')); 34 | $PAGE->navbar->add($PAGE->heading, $PAGE->url); 35 | 36 | echo $OUTPUT->header(); 37 | echo $OUTPUT->heading($PAGE->heading. ' ('.userdate(time()).')'); 38 | 39 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 40 | 41 | $table = new html_table(); 42 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 43 | $table->width = '400px'; 44 | $table->align = array('left','right'); 45 | $table->data = array( 46 | array('Users >= 50000', 47 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND users >= 50000")), 48 | array('20000 <= Users < 50000', 49 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 20000) AND (users < 50000)")), 50 | array('10000 <= Users < 20000', 51 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 10000) AND (users < 20000)")), 52 | array('5000 <= Users < 10000', 53 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 5000) AND (users < 10000)")), 54 | array('2000 <= Users < 5000', 55 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 2000) AND (users < 5000)")), 56 | array('1000 <= Users < 2000', 57 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 1000) AND (users < 2000)")), 58 | array('500 <= Users < 1000', 59 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 500) AND (users < 1000)")), 60 | array('200 <= Users < 500', 61 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 200) AND (users < 500)")), 62 | array('100 <= Users < 200', 63 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 100) AND (users < 200)")), 64 | array('50 <= Users < 100', 65 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 50) AND (users < 100)")), 66 | array('20 <= Users < 50', 67 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users >= 20) AND (users < 50)")), 68 | array('Users < 20', 69 | $DB->count_records_select('registry', "(moodlerelease LIKE '%2.0%') AND (users < 20)")), 70 | array('Total 2.0 sites', 71 | $DB->count_records_select('registry', "moodlerelease LIKE '%2.0%'")), 72 | ); 73 | echo html_writer::table($table); 74 | 75 | echo html_writer::end_tag('div'); 76 | 77 | echo $OUTPUT->footer(); 78 | -------------------------------------------------------------------------------- /yui/courses/courses.js: -------------------------------------------------------------------------------- 1 | // This file is part of Moodle - http://moodle.org/ 2 | // 3 | // Moodle is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // Moodle is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | // 13 | // You should have received a copy of the GNU General Public License 14 | // along with Moodle. If not, see . 15 | 16 | /** 17 | * Bulk operation redirection 18 | * @author Jerome Mouneyrac 19 | */ 20 | 21 | YUI.add('moodle-local_hub-courses', function(Y) { 22 | var HUBCOURSESNAME = 'local_hub_courses'; 23 | var HUBCOURSES = function() { 24 | HUBCOURSES.superclass.constructor.apply(this, arguments); 25 | } 26 | Y.extend(HUBCOURSES, Y.Base, { 27 | initializer : function(config) { //'config' contains the parameter values 28 | Y.all('select.menubulkselect').each(this.attach_hub_events, this); 29 | 30 | //hide the submit buttons 31 | Y.all('input.bulksubmitbutton').setStyle('display', 'none'); 32 | }, 33 | 34 | attach_hub_events : function(selectnode) { 35 | selectnode.on('change', this.submit_hub_action, this, selectnode); 36 | }, 37 | 38 | submit_hub_action : function(e, selectnode){ 39 | 40 | //retrieve parameters (which checkboxes is checked and what kind of action is trigger) 41 | var theinputs = Y.all('input.hubmanagecoursecheckbox'); 42 | 43 | //retrieve bulk action 44 | var bulkaction = 'bulkselect='+Y.one('select.menubulkselect').get('value'); 45 | 46 | //build the course ids param url 47 | var inputssize = theinputs.size(); 48 | var courseidparams = ''; 49 | for ( var i=0; iget_record('hub_site_directory', array('id'=>$siteid))) { 17 | redirect('../sites/', 'You can\'t call this script directly'); 18 | } 19 | 20 | $PAGE->set_context(context_system::instance()); 21 | $PAGE->set_url(new moodle_url('/sites/contact.php', array('siteid'=>$siteid))); 22 | $PAGE->set_title('Contact a Moodle site'); 23 | $PAGE->set_heading($PAGE->title); 24 | $PAGE->navbar->add('Sites', new moodle_url('/sites/')); 25 | $PAGE->navbar->add($PAGE->title); 26 | 27 | echo $OUTPUT->header(); 28 | 29 | $currentaddress = getremoteaddr(); 30 | $exceptions = array( 31 | '203.29.181.6' // Chad Outten 32 | ); 33 | if (in_array($currentaddress, $exceptions)) { 34 | $SESSION->registrycontactmessagesent = 0; 35 | } 36 | 37 | 38 | if (isset($SESSION->registrycontactmessagesent) && $SESSION->registrycontactmessagesent >= 3) { 39 | print_error('errormaxmessages', 'local_hub'); 40 | } 41 | 42 | // You'll need to build a little fake $userto object to pass to email_to_user() 43 | // using adminname and adminuser 44 | 45 | if (!$site) { 46 | 47 | echo $OUTPUT->box('The site you requested cannot be found or displayed. Please contact the administrator if you believe this is an error.'); 48 | 49 | } else if ($site->contactable != 1) { 50 | 51 | /* there shouldn't be a link to this script if $site->contactable isn't on.. but just 52 | * in case people fool around with the siteid variable... 53 | */ 54 | 55 | $error_message = 'This site doesn\'t wish to be contacted directly.'; 56 | if (!empty($site->public) && $site->url) { 57 | $error_message .= 'Please
visit the site : you may find the contact information there.'; 58 | } 59 | echo $OUTPUT->box($error_message); 60 | /* 61 | * This is in case we let not lo 62 | */ 63 | 64 | } else if (($frm = data_submitted()) && confirm_sesskey()) { 65 | require_once($CFG->dirroot.'/local/hub/locallib.php'); 66 | $userto = local_hub_create_contact_user($site->contactemail, $site->contactname); 67 | 68 | /* following code strongly inspired by message/lib.php */ 69 | $message = clean_text($frm->contacttext, FORMAT_PLAIN); 70 | $messagesubject = clean_text($frm->contactsubject, FORMAT_PLAIN); 71 | $messagetext = format_text_email($message, FORMAT_PLAIN) ."\n\n--\nThis message was sent to you via the contact form at http://moodle.org/sites, where you are registered as site administrator for a Moodle site ({$site->url}) who doesn't mind being contacted. To change these settings, use the registration button in your Moodle on the Admin page.\n"; 72 | 73 | $userfrom = clone($USER); 74 | $userfrom->maildisplay = true; 75 | 76 | if (email_to_user($userto, $userfrom, $messagesubject, $messagetext)) { 77 | if (isset($SESSION->registrycontactmessagesent)) { 78 | $SESSION->registrycontactmessagesent++; 79 | } else { 80 | $SESSION->registrycontactmessagesent = 1; 81 | } 82 | 83 | } else { 84 | print_error('errorsendingmail', 'local_hub'); 85 | } 86 | 87 | /* will have to choose the right way to end... */ 88 | /* Do an automatic redirect after 2 seconds. */ 89 | //redirect('/sites', 'Your message was sent, thanks.', 2); 90 | /* Display a close button, if we're in a popup */ 91 | //close_window_button(); 92 | /* Do a non-automatic redirect */ 93 | echo $OUTPUT->box('Your message was sent via email to that site administrator.', 'generalbox', 'notice'); 94 | echo $OUTPUT->continue_button(new moodle_url('/sites/')); 95 | 96 | } else { 97 | /* print out the form */ 98 | echo $OUTPUT->heading('Send a private email to the administrator of: '.$site->name); 99 | echo $OUTPUT->box('Your name and email address will be automatically included as the sender', 'generalbox', 'notice'); 100 | include('contact.html'); 101 | 102 | } 103 | 104 | echo $OUTPUT->footer(); 105 | -------------------------------------------------------------------------------- /top/sites/edit.php: -------------------------------------------------------------------------------- 1 | dirroot.'/local/hub/top/sites/siteslib.php'); 5 | 6 | require_login(); 7 | 8 | if (!ismoodlesiteadmin()) { 9 | print_error('erroradminonly', 'local_hub'); 10 | } 11 | 12 | $cool = optional_param('cool', '', PARAM_INT); 13 | $uncool = optional_param('uncool', '', PARAM_INT); 14 | $edit = optional_param('edit', '', PARAM_INT); 15 | $delete = optional_param('delete', '', PARAM_INT); 16 | 17 | if (!empty($cool) and confirm_sesskey()) { 18 | if ($site = $DB->get_record("hub_site_directory", array("id"=>$cool))) { 19 | $site->cool = MAXVOTES; 20 | $site->cooldate = time(); 21 | $DB->update_record("hub_site_directory", $site); 22 | add_to_log($SITE->id, "resource", "cool", "view.php?id=380", "COOL: $site->url, $site->sitename", 380, $USER->id); 23 | redirect("index.php?country=$site->country", "$site->sitename marked as COOL!", 1); 24 | } 25 | } 26 | 27 | if (!empty($uncool) and confirm_sesskey()) { 28 | if ($site = $DB->get_record("hub_site_directory", array("id" => $uncool))) { 29 | $site->cool = 0; 30 | $site->cooldate = 0; 31 | $DB->update_record("hub_site_directory", $site); 32 | add_to_log($SITE->id, "resource", "uncool", "view.php?id=380", "UNCOOL: $site->url, $site->sitename", 380, $USER->id); 33 | redirect("index.php?country=$site->country", "$site->sitename suddenly seems NOT SO COOL! ", 1); 34 | } 35 | } 36 | 37 | if (!empty($delete) and confirm_sesskey()) { 38 | if ($site = $DB->get_record("hub_site_directory", array("id"=>$delete))) { 39 | $DB->delete_records("hub_site_directory", array("id"=>$delete)); 40 | } 41 | add_to_log($SITE->id, "resource", "delete", "view.php?id=380", "DELETE: $site->url, $site->sitename", 380, $USER->id); 42 | $SESSION->lang = "en"; 43 | redirect("index.php?country=$site->country", "$site->sitename has been completely DELETED!", 1); 44 | } 45 | 46 | if ($site = data_submitted() and confirm_sesskey()) { 47 | $DB->update_record("hub_site_directory", $site); 48 | add_to_log($SITE->id, "resource", "edit", "view.php?id=380", "UPDATE: $site->url, $site->sitename", 380, $USER->id); 49 | $SESSION->lang = "en"; 50 | redirect("index.php?country=$site->country", "$site->sitename has been UPDATED!", 1); 51 | } 52 | 53 | if (empty($edit)) { 54 | redirect("index.php", "Edit who?", 1); 55 | } 56 | 57 | if (!$site = $DB->get_record("hub_site_directory", array("id"=>$edit))) { 58 | redirect("index.php", "Edit who?", 1); 59 | } 60 | 61 | $SESSION->lang = $site->lang; 62 | 63 | /// Print headings 64 | 65 | $url = new moodle_url('/sites/edit.php', array()); 66 | if (!empty($cool)) { 67 | $url->param('cool', $cool); 68 | } 69 | if (!empty($uncool)) { 70 | $url->param('uncool', $uncool); 71 | } 72 | if (!empty($edit)) { 73 | $url->param('edit', $edit); 74 | } 75 | if (!empty($delete)) { 76 | $url->param('delete', $delete); 77 | } 78 | $PAGE->set_url($url); 79 | $PAGE->set_context(context_system::instance()); 80 | $PAGE->set_title('moodle.net: Moodle sites management'); 81 | $PAGE->set_heading('Moodle sites management'); 82 | 83 | $PAGE->navbar->add('Sites', new moodle_url('/sites/')); 84 | $PAGE->navbar->add('Edit site'); 85 | 86 | echo $OUTPUT->header(); 87 | echo $OUTPUT->heading($PAGE->heading); 88 | 89 | echo html_writer::start_tag('div', array('class'=>'mdl-align')); 90 | echo html_writer::start_tag('form', array('method'=>'post', 'action'=>'', 'name'=>'form')); 91 | echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>s($site->id))); 92 | echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey())); 93 | 94 | $table = new html_table(); 95 | $table->cellpadding = 9; 96 | $table->data = array(); 97 | $table->attributes = array('class'=>'generaltable', 'style'=>'margin:1em auto;border:1px solid #ddd;'); 98 | unset($site->id); 99 | foreach ($site as $name => $value) { 100 | if (strlen($name) > 2) { 101 | $table->data[] = array( 102 | $name, 103 | html_writer::empty_tag('input', array('type'=>'text', 'name'=>$name, 'value'=>$value, 'style'=>'width:400px')) 104 | ); 105 | } 106 | } 107 | echo html_writer::table($table); 108 | echo html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('submit'))); 109 | echo html_writer::end_tag('div'); 110 | 111 | echo $OUTPUT->footer(); 112 | -------------------------------------------------------------------------------- /db/services.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Hub external functions and service definitions. 20 | * 21 | * @package localhub 22 | * @copyright 2010 Jerome Mouneyrac 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $functions = array( 27 | 28 | 'hub_get_info' => array( 29 | 'classname' => 'local_hub_external', 30 | 'methodname' => 'get_info', 31 | 'classpath' => 'local/hub/externallib.php', 32 | 'description' => 'Get hub information', 33 | 'type' => 'read', 34 | ), 35 | 36 | 'hub_update_site_info' => array( 37 | 'classname' => 'local_hub_external', 38 | 'methodname' => 'update_site_info', 39 | 'classpath' => 'local/hub/externallib.php', 40 | 'description' => 'Update the site information and call confirmation', 41 | 'type' => 'write', 42 | ), 43 | 44 | 'hub_register_courses' => array( 45 | 'classname' => 'local_hub_external', 46 | 'methodname' => 'register_courses', 47 | 'classpath' => 'local/hub/externallib.php', 48 | 'description' => 'Register multiple courses', 49 | 'type' => 'write', 50 | ), 51 | 52 | 'hub_unregister_courses' => array( 53 | 'classname' => 'local_hub_external', 54 | 'methodname' => 'unregister_courses', 55 | 'classpath' => 'local/hub/externallib.php', 56 | 'description' => 'Unregister multiple courses', 57 | 'type' => 'write', 58 | ), 59 | 60 | 'hub_unregister_site' => array( 61 | 'classname' => 'local_hub_external', 62 | 'methodname' => 'unregister_site', 63 | 'classpath' => 'local/hub/externallib.php', 64 | 'description' => 'Unregister a site (the caller)', 65 | 'type' => 'write', 66 | ), 67 | 68 | 'hub_get_courses' => array( 69 | 'classname' => 'local_hub_external', 70 | 'methodname' => 'get_courses', 71 | 'classpath' => 'local/hub/externallib.php', 72 | 'description' => 'Get multiple courses', 73 | 'type' => 'read', 74 | ), 75 | 76 | 'hub_get_sitesregister' => array( 77 | 'classname' => 'local_hub_external', 78 | 'methodname' => 'get_sitesregister', 79 | 'classpath' => 'local/hub/externallib.php', 80 | 'description' => 'Get multiple sites', 81 | 'type' => 'read', 82 | 'capabilities' => 'local/hub:viewinfo' 83 | ), 84 | 'hub_sync_into_sitesregister' => array( 85 | 'classname' => 'local_hub_external', 86 | 'methodname' => 'sync_into_sitesregister', 87 | 'classpath' => 'local/hub/externallib.php', 88 | 'description' => 'Register multiple sites (for moodle.org sync to hub)', 89 | 'type' => 'write', 90 | 'capabilities' => 'local/hub:viewinfo' 91 | ), 92 | ); 93 | 94 | $services = array( 95 | 'Hub directory' => array( 96 | 'functions' => array ('hub_get_info'), 97 | 'enabled'=>1, 98 | ), 99 | 100 | 'Registered site' => array( 101 | 'functions' => array ('hub_update_site_info', 'hub_register_courses', 102 | 'hub_get_courses', 'hub_unregister_courses', 'hub_unregister_site', 'hub_get_info'), 103 | 'enabled'=>1, 104 | ), 105 | 106 | 'Public site' => array( 107 | 'functions' => array ('hub_get_courses'), 108 | 'enabled'=>1, 109 | ), 110 | 111 | 'Moodle.org statistics' => array( 112 | 'functions' => array ('hub_get_sitesregister', 'hub_sync_into_sitesregister'), 113 | 'enabled'=>1, 114 | ), 115 | ); -------------------------------------------------------------------------------- /top/stats/lib.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * @package moodle-dot-org 20 | * @subpackage stats 21 | * @copyright 2009 Sam Hemelryk 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | define('STATS_MAX_UNREACHABLE', 3); 28 | 29 | /** 30 | * 31 | * @global moodle_database $DB 32 | */ 33 | function local_hub_stats_get_registry_stats() { 34 | global $DB; 35 | list($where, $params) = local_hub_stats_get_confirmed_sql(); 36 | $sql = 'SELECT 37 | COUNT(DISTINCT r.id) AS registrycount, 38 | SUM(case when r.courses > -1 then r.courses else 0 end) courses, 39 | SUM(case when r.users > -1 then r.users else 0 end) users, 40 | SUM(case when r.enrolments > -1 then r.enrolments else 0 end) enrolments, 41 | SUM(case when r.posts > -1 then r.posts else 0 end) posts, 42 | SUM(case when r.resources > -1 then r.resources else 0 end) resources, 43 | SUM(case when r.questions > -1 then r.questions else 0 end) questions, 44 | COUNT(DISTINCT (case when r.countrycode <> \'\' then r.countrycode else \'AU\' end)) AS countrycount 45 | FROM {hub_site_directory} r 46 | WHERE '.$where; 47 | $stats = $DB->get_record_sql($sql, $params); 48 | 49 | return $stats; 50 | } 51 | 52 | /** 53 | * 54 | * @global moodle_database $DB 55 | */ 56 | function local_hub_stats_top_10_sites_by_users() { 57 | global $DB; 58 | list($where, $params) = local_hub_stats_get_confirmed_sql(); 59 | $sql = 'SELECT r.* 60 | FROM {hub_site_directory} r 61 | WHERE '.$where.' AND r.public IN (1, 2) 62 | ORDER BY r.users DESC 63 | LIMIT 10' ; 64 | return $DB->get_records_sql($sql, $params); 65 | } 66 | 67 | /** 68 | * 69 | * @global moodle_database $DB 70 | */ 71 | function local_hub_stats_top_10_sites_by_courses() { 72 | global $DB; 73 | list($where, $params) = local_hub_stats_get_confirmed_sql(); 74 | $sql = 'SELECT r.* 75 | FROM {hub_site_directory} r 76 | WHERE '.$where.' AND r.public IN (1, 2) 77 | ORDER BY r.courses DESC 78 | LIMIT 10' ; 79 | return $DB->get_records_sql($sql, $params); 80 | } 81 | 82 | /** 83 | * 84 | * @global moodle_database $DB 85 | */ 86 | function local_hub_stats_top_10_countries() { 87 | global $DB; 88 | list($where, $params) = local_hub_stats_get_confirmed_sql(); 89 | $sql = 'SELECT r.countrycode, COUNT(DISTINCT r.id) AS countrycount 90 | FROM {hub_site_directory} r 91 | WHERE '.$where.' AND r.countrycode <> \'\' 92 | GROUP BY r.countrycode 93 | ORDER BY countrycount DESC 94 | LIMIT 10'; 95 | return $DB->get_records_sql($sql, $params); 96 | } 97 | 98 | function local_hub_stats_get_confirmed_sql($prefix = 'r', $aliassuffix = '') { 99 | if (empty($prefix)) { 100 | $prefix = ''; 101 | } else { 102 | $prefix = $prefix.'.'; 103 | } 104 | // score > 3 allows for a number of rules (or major rules) to be matched at least. When score<1, we include all reached sites that are also not seen as moodle (see linkchecker rules). 105 | $sql = "{$prefix}timeregistered > 0 AND 106 | {$prefix}score > 3 AND 107 | ({$prefix}unreachable <= :maxunreachable{$aliassuffix} OR {$prefix}override BETWEEN 1 AND 3)"; 108 | $params = array( 109 | 'maxunreachable'.$aliassuffix => STATS_MAX_UNREACHABLE 110 | ); 111 | return array($sql, $params); 112 | } 113 | 114 | /** 115 | * Update the hub's own count of users in the hub site directory. 116 | * @return int The count of users. Zero if this site is not registered with the hub. 117 | */ 118 | function local_hub_stats_update_moodle_users() { 119 | global $DB, $CFG; 120 | $siterecord = $DB->get_record('hub_site_directory', array('url' => $CFG->wwwroot), 'id, users'); 121 | if ($siterecord) { 122 | // This site is registered in its own hub. 123 | $siterecord->users = $DB->count_records('user', array('deleted' => 0)); 124 | $DB->set_field('hub_site_directory', 'users', $siterecord->users, array('url' => $CFG->wwwroot)); 125 | return $siterecord->users; 126 | } 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /top/stats/js/ajax-dynamic-content.js: -------------------------------------------------------------------------------- 1 | /************************************************************************************************************ 2 | Ajax dynamic content 3 | Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Dhtmlgoodies.com., hereby disclaims all copyright interest in this script 20 | written by Alf Magne Kalleland. 21 | 22 | Alf Magne Kalleland, 2006 23 | Owner of DHTMLgoodies.com 24 | 25 | 26 | ************************************************************************************************************/ 27 | 28 | var enableCache = true; 29 | var jsCache = new Array(); 30 | 31 | var dynamicContent_ajaxObjects = new Array(); 32 | 33 | function ajax_showContent(divId,ajaxIndex,url,callbackOnComplete) 34 | { 35 | var targetObj = document.getElementById(divId); 36 | targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response; 37 | if(enableCache){ 38 | jsCache[url] = dynamicContent_ajaxObjects[ajaxIndex].response; 39 | } 40 | dynamicContent_ajaxObjects[ajaxIndex] = false; 41 | 42 | ajax_parseJs(targetObj); 43 | 44 | if(callbackOnComplete) { 45 | executeCallback(callbackOnComplete); 46 | } 47 | } 48 | 49 | function executeCallback(callbackString) { 50 | if(callbackString.indexOf('(')==-1) { 51 | callbackString = callbackString + '()'; 52 | } 53 | try{ 54 | eval(callbackString); 55 | }catch(e){ 56 | 57 | } 58 | 59 | 60 | } 61 | 62 | function ajax_loadContent(divId,url,callbackOnComplete) 63 | { 64 | if(enableCache && jsCache[url]){ 65 | document.getElementById(divId).innerHTML = jsCache[url]; 66 | ajax_parseJs(document.getElementById(divId)) 67 | evaluateCss(document.getElementById(divId)) 68 | if(callbackOnComplete) { 69 | executeCallback(callbackOnComplete); 70 | } 71 | return; 72 | } 73 | 74 | var ajaxIndex = dynamicContent_ajaxObjects.length; 75 | document.getElementById(divId).innerHTML = 'Loading content - please wait'; 76 | dynamicContent_ajaxObjects[ajaxIndex] = new sack(); 77 | 78 | if(url.indexOf('?')>=0){ 79 | dynamicContent_ajaxObjects[ajaxIndex].method='GET'; 80 | var string = url.substring(url.indexOf('?')); 81 | url = url.replace(string,''); 82 | string = string.replace('?',''); 83 | var items = string.split(/&/g); 84 | for(var no=0;no=0){ 115 | jsCode = jsCode + scriptTags[no].text + '\n'; 116 | } 117 | else 118 | jsCode = jsCode + scriptTags[no].innerHTML; 119 | } 120 | 121 | } 122 | 123 | if(jsCode)ajax_installScript(jsCode); 124 | } 125 | 126 | 127 | function ajax_installScript(script) 128 | { 129 | if (!script) 130 | return; 131 | if (window.execScript){ 132 | window.execScript(script) 133 | }else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery 134 | window.setTimeout(script,0); 135 | }else{ 136 | window.setTimeout( script, 0 ); 137 | } 138 | } 139 | 140 | 141 | function evaluateCss(obj) 142 | { 143 | var cssTags = obj.getElementsByTagName('STYLE'); 144 | var head = document.getElementsByTagName('HEAD')[0]; 145 | for(var no=0;no. 17 | 18 | 19 | /** 20 | * Administrator can manage sites on this page. 21 | * Trust, Prioritise, Delete, Hide... 22 | * @package localhub 23 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 24 | * @author Jerome Mouneyrac 25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 | */ 27 | require('../../../config.php'); 28 | 29 | require_once($CFG->libdir . '/adminlib.php'); 30 | require_once($CFG->dirroot . '/local/hub/lib.php'); 31 | require_once($CFG->dirroot . "/local/hub/forms.php"); 32 | 33 | define('MAXSITES', 100); 34 | 35 | admin_externalpage_setup('managesites'); 36 | 37 | //check that the PHP xmlrpc extension is enabled 38 | if (!extension_loaded('xmlrpc')) { 39 | echo $OUTPUT->header(); 40 | $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 41 | $xmlrpcnotification .= get_string('xmlrpcdisabled', 'local_hub'); 42 | echo $OUTPUT->notification($xmlrpcnotification); 43 | echo $OUTPUT->footer(); 44 | die(); 45 | } 46 | 47 | $hub = new local_hub(); 48 | 49 | /// Check if the page has been called with trust argument 50 | $delete = optional_param('delete', -1, PARAM_INTEGER); 51 | $confirm = optional_param('confirm', false, PARAM_INTEGER); 52 | if ($delete != -1 and $confirm and confirm_sesskey()) { 53 | $unregistercourses = optional_param('unregistercourses', false, PARAM_BOOL); 54 | $hub->delete_site($delete, $unregistercourses); 55 | } 56 | 57 | 58 | /// Check if the page has been called with trust argument 59 | $trust = optional_param('trust', -1, PARAM_INTEGER); 60 | if ($trust != -1 and confirm_sesskey()) { 61 | $id = required_param('id', PARAM_INTEGER); 62 | $site = $hub->get_site($id); 63 | if (!empty($site)) { 64 | $site->trusted = $trust; 65 | $hub->update_site($site); 66 | } 67 | } 68 | 69 | $search = optional_param('search', '', PARAM_TEXT); 70 | $renderer = $PAGE->get_renderer('local_hub'); 71 | $contenthtml = ""; 72 | $moresiteshtml = ""; 73 | if ($delete != -1 and !$confirm) { //we want to display delete confirmation page 74 | $site = $hub->get_site($delete); 75 | $contenthtml = $renderer->delete_confirmation($site); 76 | } else { //all other cases we go back to site list page (no need confirmation) 77 | //forms 78 | $sitesearchform = new site_search_form('', array('search' => $search, 'adminform' => 1)); 79 | $fromform = $sitesearchform->get_data(); 80 | 81 | $limitfrom = optional_param('limitfrom', 0, PARAM_INTEGER); 82 | 83 | //if the page result from any action from the renderer, set data to the previous search in order to 84 | //display the same result 85 | if (((!empty($limitfrom) or !empty($search) or $trust != -1 or $delete != -1) /*or $visible != -1 or $prioritise != -1*/) 86 | and confirm_sesskey()) { 87 | $fromformdata['trusted'] = optional_param('trusted', 'all', PARAM_ALPHANUMEXT); 88 | $fromformdata['countrycode'] = optional_param('countrycode', 'all', PARAM_ALPHANUMEXT); 89 | $fromformdata['language'] = optional_param('language', 'all', PARAM_ALPHANUMEXT); 90 | $fromformdata['search'] = $search; 91 | $sitesearchform->set_data($fromformdata); 92 | $fromform = (object) $fromformdata; 93 | } 94 | 95 | //Retrieve courses by web service 96 | $sites = null; 97 | $options = array(); 98 | if (!empty($fromform)) { 99 | 100 | if ($fromform->trusted != 'all') { 101 | $options['trusted'] = $fromform->trusted; 102 | } 103 | 104 | if ($fromform->countrycode != 'all') { 105 | $options['countrycode'] = $fromform->countrycode; 106 | } 107 | if ($fromform->language != 'all') { 108 | $options['language'] = $fromform->language; 109 | } 110 | 111 | //get courses 112 | $options['search'] = $search; 113 | 114 | $limitnum = MAXSITES; 115 | $sites = $hub->get_sites($options, $limitfrom, $limitnum); 116 | $limitfrom = $limitfrom + MAXSITES; 117 | $sitestotal = $hub->get_sites($options, 0, 0, true); 118 | if ($sitestotal > $limitfrom) { 119 | $urlparams = (array)$fromform; 120 | $urlparams['limitfrom'] = $limitfrom; 121 | $urlparams['submitbutton'] = 1; 122 | $urlparams['sesskey'] = sesskey(); 123 | $managesitesurl = new moodle_url('/local/hub/admin/managesites.php', $urlparams); 124 | $moresiteshtml = html_writer::link($managesitesurl, 'More sites'); 125 | } 126 | } 127 | 128 | //(search, none language, no onlyvisible) 129 | $contenthtml = $renderer->site_list($sites, true); 130 | } 131 | 132 | echo $OUTPUT->header(); 133 | 134 | //display a message if we come back from site settings page 135 | $updatesite = optional_param('sitesettings', '', PARAM_TEXT); 136 | if (!empty($updatesite) and confirm_sesskey()) { 137 | echo $OUTPUT->notification(get_string('sitesettingsupdated', 'local_hub', $updatesite), 'notifysuccess'); 138 | } 139 | 140 | if (!($delete != -1 and !$confirm)) { 141 | echo $OUTPUT->heading(get_string('managesites', 'local_hub'), 3, 'main'); 142 | $sitesearchform->display(); 143 | } else { 144 | echo $OUTPUT->heading(get_string('deletesite', 'local_hub', $site->name), 3, 'main'); 145 | } 146 | echo $contenthtml; 147 | echo $moresiteshtml; 148 | echo $OUTPUT->footer(); 149 | -------------------------------------------------------------------------------- /admin/coursesettings.php: -------------------------------------------------------------------------------- 1 | . // 20 | // // 21 | /////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * On this page administrator can change site settings 25 | * @package localhub 26 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 27 | * @author Jerome Mouneyrac 28 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 | */ 30 | require('../../../config.php'); 31 | require_once($CFG->libdir . '/adminlib.php'); 32 | require_once($CFG->dirroot . '/local/hub/admin/forms.php'); 33 | 34 | admin_externalpage_setup('hubcoursesettings'); 35 | 36 | $id = optional_param('id', 0, PARAM_INT); 37 | $hub = new local_hub(); 38 | $course = $hub->get_course($id, MUST_EXIST); 39 | 40 | //define nav bar 41 | $PAGE->set_url('/local/hub/admin/coursesettings.php', array('id' => $id)); 42 | $PAGE->navbar->ignore_active(true); 43 | $PAGE->navbar->add(get_string('administrationsite')); 44 | $PAGE->navbar->add(get_string('hub', 'local_hub')); 45 | $PAGE->navbar->add(get_string('managecourses', 'local_hub'), 46 | new moodle_url('/local/hub/admin/managecourses.php', 47 | array('courseid' => $course->id, 'sesskey' => sesskey()))); 48 | $PAGE->navbar->add(get_string('coursesettings', 'local_hub'), 49 | new moodle_url('/local/hub/admin/coursesettings.php', array('id' => $id))); 50 | 51 | 52 | $coursesettingsform = new hub_course_settings_form('', 53 | array('id' => $id)); 54 | $fromform = $coursesettingsform->get_data(); 55 | 56 | //Save settings and redirect to search site page 57 | if (!empty($fromform) and confirm_sesskey()) { 58 | 59 | //update the course values 60 | $course->fullname = $fromform->fullname; 61 | $course->description = $fromform->description; 62 | $course->language = $fromform->language; 63 | if (isset($fromform->courseurl)) { 64 | $course->courseurl = $fromform->courseurl; 65 | } else { 66 | $course->demourl = $fromform->demourl; 67 | } 68 | $course->publishername = $fromform->publishername; 69 | $course->publisheremail = $fromform->publisheremail; 70 | $course->creatorname = $fromform->creatorname; 71 | $course->contributornames = $fromform->contributornames; 72 | $course->coverage = $fromform->coverage; 73 | $course->licenceshortname = $fromform->licence; 74 | $course->subject = $fromform->subject; 75 | $course->audience = $fromform->audience; 76 | $course->educationallevel = $fromform->educationallevel; 77 | $course->creatornotes = $fromform->creatornotes['text']; 78 | $course->creatornotesformat = $fromform->creatornotes['format']; 79 | $course->privacy = empty($fromform->visible)?0:$fromform->visible; 80 | 81 | //delete screenshots that are not needed anymore 82 | for ($screenshotnumber = 1; $screenshotnumber <= $course->screenshots; $screenshotnumber++) { 83 | if(!isset($fromform->{'screenshot_' . $screenshotnumber})) { 84 | if ($hub->screenshot_exists($course->id, $screenshotnumber)) { 85 | $hub->delete_screenshot($course->id, $screenshotnumber); 86 | } 87 | } 88 | } 89 | 90 | //sanitize course screenshots 91 | $screenshottotal = $hub->sanitize_screenshots($course->id); 92 | 93 | //save the new screenshots and update the course screenshots value 94 | if (!empty($fromform->addscreenshots)) { 95 | $screenshots = $fromform->addscreenshots; 96 | $fs = get_file_storage(); 97 | $ctx = context_user::instance($USER->id); 98 | $files = $fs->get_area_files( $ctx->id, 'user', 'draft', $screenshots); 99 | if (!empty($files)) { 100 | $level1 = floor($course->id / 1000) * 1000; 101 | $directory = "hub/$level1/$course->id"; 102 | foreach ($files as $file) { 103 | if ($file->is_valid_image()) { 104 | $screenshottotal = $screenshottotal + 1; 105 | if ($screenshottotal <= MAXSCREENSHOTSNUMBER) { 106 | $pathname = $CFG->dataroot . '/' . $directory . '/screenshot_' . $course->id . "_" . $screenshottotal; 107 | $file->copy_content_to($pathname); 108 | } else { 109 | throw new moodle_exception('trytoaddtoomanyscreenshots', 'local_hub'); 110 | } 111 | } 112 | } 113 | } 114 | } 115 | $course->screenshots = $screenshottotal; 116 | 117 | //update the course in the DB 118 | $hub->update_course($course); 119 | 120 | //redirect to the search form 121 | redirect(new moodle_url('/local/hub/admin/managecourses.php', 122 | array('coursesettings' => $course->fullname, 123 | 'sesskey' => sesskey(), 'courseid' => $course->id))); 124 | } 125 | 126 | //OUTPUT 127 | echo $OUTPUT->header(); 128 | $coursesettingsform->display(); 129 | echo $OUTPUT->footer(); 130 | 131 | -------------------------------------------------------------------------------- /sendmessage.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | 19 | /** 20 | * User send message to the publisher on this page 21 | * @package localhub 22 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 23 | * @author Jerome Mouneyrac 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | require('../../config.php'); 27 | 28 | require_once($CFG->dirroot . '/local/hub/lib.php'); 29 | require_once($CFG->dirroot . "/local/hub/forms.php"); 30 | 31 | require_login(); 32 | if (isguestuser()) { //guest can't send messages 33 | redirect(get_login_url()); 34 | } 35 | $id = optional_param('id', 0, PARAM_INT); 36 | $admin = optional_param('admin', 0, PARAM_INT); //access from admin page 37 | 38 | $PAGE->set_context(get_system_context()); 39 | $PAGE->set_url('/local/hub/sendmessage.php', array('id' => $id)); 40 | $PAGE->set_heading($SITE->fullname); 41 | $PAGE->set_pagelayout('frontpage'); 42 | 43 | //Spam detection (only 10 messages to publishers per day per user) 44 | if (!is_siteadmin ()) { 45 | $sentmessagestotal = $DB->count_records_select('hub_course_feedbacks', 46 | 'userid = :userid AND time > :time', 47 | array('userid' => $USER->id, 'time' => strtotime("-1 day"))); 48 | if ($sentmessagestotal > 9) { 49 | echo $OUTPUT->header(); 50 | echo $OUTPUT->notification(get_string('maxmessagesent', 'local_hub')); 51 | echo $OUTPUT->footer(); 52 | exit(); 53 | } 54 | } 55 | 56 | $hub = new local_hub(); 57 | if (!empty($id)) { 58 | $hubcourse = $hub->get_course($id); 59 | $publishername = $hubcourse->publishername; 60 | } else { 61 | $publishername = ''; 62 | $hubcourse->fullname = $SITE->fullname; 63 | } 64 | $coursename = $hubcourse->fullname; 65 | $sendmessageform = new send_message_form('', array('id' => $id, 'admin' => $admin, 66 | 'publishername' => $publishername, 'coursename' => $coursename)); 67 | 68 | //Cancel operation => redirect to the index/admin course page 69 | $cancel = optional_param('cancel', null, PARAM_ALPHA); 70 | if (!empty($cancel)) { 71 | if ($admin) { 72 | redirect(new moodle_url('/local/hub/admin/managecourses.php', 73 | array('sesskey' => sesskey(), 'courseid' => $id))); 74 | } else { 75 | redirect(new moodle_url('/', array('courseid' => $id))); 76 | } 77 | } 78 | 79 | //Send email operation => redirect to the index/admin course page 80 | $data = $sendmessageform->get_data(); 81 | if (!empty($data) and confirm_sesskey()) { 82 | 83 | //create feedback 84 | $feedback = new stdClass(); 85 | $feedback->courseid = $id; 86 | $feedback->type = $data->type; 87 | $feedback->text = $data->message; 88 | 89 | //force the user email adress to be displayed: 90 | //the publisher doesn't have to be a hub user so the email address is his only way to contact back the sender 91 | //and hub administrator can see all email addresses. 92 | $fromuser = $USER; 93 | $fromuser->maildisplay = true; 94 | 95 | switch ($data->sentto) { 96 | case 'publisher': 97 | //send email to publisher (message API does not support email as recipient) 98 | //TODO: if the email exist in user database, send message to the user using message API 99 | // => create new kind of message for it: $eventdata->name = 'messageforpublisher'; 100 | require_once($CFG->dirroot.'/local/hub/locallib.php'); 101 | $contactuser = local_hub_create_contact_user($hubcourse->publisheremail, 102 | $hubcourse->publishername); 103 | 104 | $hubcourse->hubname = $SITE->fullname; 105 | $hubcourse->sitename = $hub->get_site($hubcourse->siteid)->name; 106 | $hubcourse->huburl = new moodle_url('/'); 107 | $hubcourse->huburl = $hubcourse->huburl->out(); 108 | $hubcourse->hubcourseurl = new moodle_url('/', array('courseid' => $hubcourse->id)); 109 | $hubcourse->hubcourseurl = $hubcourse->hubcourseurl->out(); 110 | $hubcourse->userurl = new moodle_url('/message/index.php', array('id' => $fromuser->id)); 111 | $hubcourse->userurl = $hubcourse->userurl->out(); 112 | $hubcourse->userfullname = $fromuser->firstname . ' ' . $fromuser->lastname; 113 | $hubcourse->message = $data->message; 114 | 115 | $feedback->senttoemail = $contactuser->email; 116 | 117 | email_to_user($contactuser, $fromuser, get_string('msgforcoursetitle', 'local_hub', $hubcourse->fullname), 118 | get_string('msgforcourse', 'local_hub', $hubcourse)); 119 | break; 120 | case 'hub': 121 | //send message by message API 122 | $courseurl = new moodle_url('/local/hub/admin/managecourses.php', array('courseid' => $id)); 123 | $courselink = html_writer::tag('a', $hubcourse->fullname, array('href' => $courseurl)); 124 | $eventdata = new stdClass(); 125 | $eventdata->component = 'local_hub'; 126 | $eventdata->name = 'coursehubmessage'; 127 | $eventdata->userfrom = $fromuser; 128 | $eventdata->userto = get_admin(); 129 | $eventdata->subject = get_string('msgforcoursetitle', 'local_hub', $hubcourse->fullname); 130 | $eventdata->fullmessage = $data->message . ' ' . $courseurl; 131 | $eventdata->fullmessageformat = FORMAT_PLAIN; 132 | $eventdata->fullmessagehtml = $data->message . html_writer::empty_tag('br') . $courselink; 133 | $eventdata->smallmessage = get_string('msgforcoursetitle', 'local_hub', $courselink) 134 | . ': ' .$data->message; 135 | $eventdata->timecreated = time(); 136 | $feedback->senttouserid = $eventdata->userto->id; 137 | message_send($eventdata); 138 | break; 139 | default: 140 | break; 141 | } 142 | 143 | //add feedback 144 | $hub->add_feedback($feedback); 145 | 146 | //redirect either to the courses manage page either to the front page 147 | if ($admin) { 148 | redirect(new moodle_url('/local/hub/admin/managecourses.php', 149 | array('sesskey' => sesskey(), 'messagesent' => 1, 'courseid' => $id))); 150 | } else { 151 | redirect(new moodle_url('/', array('messagesent' => 1, 'courseid' => $id))); 152 | } 153 | } 154 | 155 | //OUTPUT the contact form 156 | echo $OUTPUT->header(); 157 | echo $sendmessageform->display(); 158 | echo $OUTPUT->footer(); 159 | -------------------------------------------------------------------------------- /webservice/download.php: -------------------------------------------------------------------------------- 1 | . 17 | //this is a temporary file to manage download till file download design is done (most probably ws) 18 | 19 | /** 20 | * This page display content of a course backup (if public only) 21 | * @package localhub 22 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 23 | * @author Jerome Mouneyrac 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | require('../../../config.php'); 27 | require_once($CFG->dirroot . '/course/publish/lib.php'); //HUB_SCREENSHOT_FILE_TYPE and HUB_BACKUP_FILE_TYPE 28 | require_once($CFG->libdir . '/filelib.php'); 29 | require_once($CFG->dirroot . '/local/hub/lib.php'); //HUBLOGOIMAGEWIDTH, HUBLOGOIMAGEHEIGHT 30 | 31 | $courseid = optional_param('courseid', '', PARAM_INTEGER); 32 | $filetype = optional_param('filetype', '', PARAM_ALPHA); //can be screenshots, backup, ... 33 | $screenshotnumber = optional_param('screenshotnumber', 1, PARAM_INT); //the screenshot number of this course 34 | $imagewidth = optional_param('imagewidth', HUBLOGOIMAGEWIDTH, PARAM_ALPHANUM); //the screenshot width, can be set to 'original' to forcce original size 35 | $imageheight = optional_param('imageheight', HUBLOGOIMAGEHEIGHT, PARAM_INT); //the screenshot height 36 | 37 | if (!empty($courseid) and !empty($filetype) and get_config('local_hub', 'hubenabled')) { 38 | 39 | switch ($filetype) { 40 | 41 | case HUB_BACKUP_FILE_TYPE: 42 | //check that the file is downloadable / set as visible 43 | $course = $DB->get_record('hub_course_directory', array('id' => $courseid)); 44 | if (!empty($course) && 45 | ($course->privacy or (!empty($USER) and is_siteadmin($USER->id)))) { 46 | 47 | //if the hub is set as PRIVATE, allow the download 48 | //either if the download is requested by a logged in user, 49 | //either if the download is requested by a site (server side request) 50 | $hubprivacy = get_config('local_hub', 'privacy'); 51 | $token = optional_param('token', '', PARAM_ALPHANUM); 52 | if (!empty($token)) { 53 | // check the communication token 54 | $hub = new local_hub(); 55 | $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, '', $token); 56 | } 57 | if ($hubprivacy != HUBPRIVATE or isloggedin() or !empty($communication)) { 58 | $level1 = floor($courseid / 1000) * 1000; 59 | $userdir = "hub/$level1/$courseid"; 60 | $remotemoodleurl = optional_param('remotemoodleurl', '', PARAM_URL); 61 | if (!empty($remotemoodleurl)) { 62 | $remotemoodleurl = ',' . $remotemoodleurl . ',' . getremoteaddr(); 63 | } else { 64 | $remotemoodleurl = ',' . 'unknown' . ',' . getremoteaddr(); 65 | } 66 | add_to_log(SITEID, 'local_hub', 'download backup', '', $courseid . $remotemoodleurl); 67 | send_file($CFG->dataroot . '/' . $userdir . '/backup_' . $courseid . ".mbz", $course->shortname . ".mbz", 68 | 'default', 0, false, true, '', false); 69 | } 70 | } 71 | break; 72 | 73 | case HUB_SCREENSHOT_FILE_TYPE: 74 | //check that the file is downloadable 75 | $course = $DB->get_record('hub_course_directory', array('id' => $courseid)); 76 | if (!empty($course) && 77 | ($course->privacy or (!empty($USER) and is_siteadmin($USER->id)))) { 78 | 79 | $level1 = floor($courseid / 1000) * 1000; 80 | $userdir = "hub/$level1/$courseid"; 81 | $filepath = $CFG->dataroot . '/' . $userdir . '/screenshot_' . $courseid . "_" . $screenshotnumber; 82 | $imageinfo = getimagesize($filepath, $info); 83 | 84 | //TODO: make a way better check the requested size 85 | if (($imagewidth != HUBLOGOIMAGEWIDTH and $imageheight != HUBLOGOIMAGEHEIGHT) 86 | and $imagewidth != 'original') { 87 | throw new moodle_exception('wrongimagesize'); 88 | } 89 | 90 | //check if the screenshot exists in the requested size 91 | require_once($CFG->dirroot . "/repository/flickr_public/image.php"); 92 | if ($imagewidth == 'original') { 93 | $newfilepath = $filepath . "_original"; //need to be done if ever the picture changed 94 | } else { 95 | $newfilepath = $filepath . "_" . $imagewidth . "x" . $imageheight; 96 | } 97 | 98 | //if the date of original newer than thumbnail all recreate a thumbnail 99 | if (!file_exists($newfilepath) or 100 | (filemtime($filepath) > filemtime($newfilepath))) { 101 | $image = new moodle_image($filepath); 102 | if ($imagewidth != 'original') { 103 | $image->resize($imagewidth, $imageheight); 104 | } 105 | $image->saveas($newfilepath); 106 | } 107 | send_file($newfilepath, 'image', 'default', 0, false, true, $imageinfo['mime'], false); 108 | } 109 | break; 110 | } 111 | } else { 112 | //always give hub logo to anybody 113 | if ($filetype == HUB_HUBSCREENSHOT_FILE_TYPE) { 114 | $userdir = "hub/0"; 115 | $filepath = $CFG->dataroot . '/' . $userdir . '/hublogo'; 116 | $imageinfo = getimagesize($filepath, $info); 117 | 118 | //check if the screenshot exists in the requested size 119 | require_once($CFG->dirroot . "/repository/flickr_public/image.php"); 120 | $newfilepath = $filepath . "_" . HUBLOGOIMAGEWIDTH . "x" . HUBLOGOIMAGEHEIGHT; 121 | 122 | if (!file_exists($newfilepath) or 123 | (filemtime($filepath) > filemtime($newfilepath))) { 124 | $image = new moodle_image($filepath); 125 | 126 | //scale to the max width/height dimension 127 | $imagewidth = $imageinfo[0]; 128 | $imageheight = $imageinfo[1]; 129 | if ($imagewidth > HUBLOGOIMAGEWIDTH) { 130 | $imagewidth = $imagewidth / ($imagewidth / HUBLOGOIMAGEWIDTH); 131 | $imageheight = $imageheight / ($imagewidth / HUBLOGOIMAGEWIDTH); 132 | } 133 | if ($imageheight > HUBLOGOIMAGEHEIGHT) { 134 | $imageheight = $imageheight / ($imageheight / HUBLOGOIMAGEWIDTH); 135 | $imagewidth = $imagewidth / ($imageheight / HUBLOGOIMAGEWIDTH); 136 | } 137 | 138 | $image->resize($imagewidth, $imageheight); 139 | $image->saveas($newfilepath); 140 | } 141 | 142 | send_file($newfilepath, 'image', 'default', 0, false, true, $imageinfo['mime'], false); 143 | } 144 | } 145 | 146 | -------------------------------------------------------------------------------- /admin/settings.php: -------------------------------------------------------------------------------- 1 | . // 20 | // // 21 | /////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * On this page administrator can change hub settings 25 | * @package localhub 26 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 27 | * @author Jerome Mouneyrac 28 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 29 | */ 30 | require('../../../config.php'); 31 | require_once($CFG->libdir . '/adminlib.php'); 32 | require_once($CFG->dirroot . '/local/hub/admin/forms.php'); 33 | require_once($CFG->dirroot . '/webservice/lib.php'); 34 | 35 | admin_externalpage_setup('hubsettings'); 36 | 37 | $hubsettingsform = new hub_settings_form(); 38 | $fromform = $hubsettingsform->get_data(); 39 | 40 | echo $OUTPUT->header(); 41 | 42 | //check that the PHP xmlrpc extension is enabled 43 | if (!extension_loaded('xmlrpc')) { 44 | $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 45 | $xmlrpcnotification .= get_string('xmlrpcdisabled', 'local_hub'); 46 | echo $OUTPUT->notification($xmlrpcnotification); 47 | echo $OUTPUT->footer(); 48 | die(); 49 | } 50 | 51 | if (!empty($fromform) and confirm_sesskey()) { 52 | if ($fromform->privacy != HUBPRIVATE and !empty($fromform->password)) { 53 | $fromform->password = null; 54 | } 55 | 56 | //Save settings 57 | set_config('name', $fromform->name, 'local_hub'); 58 | set_config('hubenabled', 59 | empty($fromform->enabled)?0:$fromform->enabled, 'local_hub'); 60 | set_config('hubrecaptcha', 61 | empty($fromform->recaptchaenabled)?0:$fromform->recaptchaenabled, 'local_hub'); 62 | set_config('description', $fromform->desc, 'local_hub'); 63 | set_config('contactname', $fromform->contactname, 'local_hub'); 64 | set_config('contactemail', $fromform->contactemail, 'local_hub'); 65 | set_config('maxwscourseresult', $fromform->maxwscourseresult, 'local_hub'); 66 | set_config('maxcoursesperday', $fromform->maxcoursesperday, 'local_hub'); 67 | set_config('searchfornologin', empty($fromform->searchfornologin)?0:1, 'local_hub'); 68 | 69 | set_config('enablerssfeeds', empty($fromform->enablerssfeeds)?0:$fromform->enablerssfeeds, 'local_hub'); 70 | set_config('rsssecret', empty($fromform->rsssecret)?'':$fromform->rsssecret, 'local_hub'); 71 | 72 | set_config('sendyurl', empty($fromform->sendyurl)?'':$fromform->sendyurl, 'local_hub'); 73 | set_config('sendylistid', empty($fromform->sendylistid)?'':$fromform->sendylistid, 'local_hub'); 74 | set_config('sendyapikey', empty($fromform->sendyapikey)?'':$fromform->sendyapikey, 'local_hub'); 75 | 76 | set_config('language', $fromform->lang, 'local_hub'); 77 | 78 | set_config('password', 79 | empty($fromform->password)?null:$fromform->password, 'local_hub'); 80 | 81 | 82 | //if privacy settings is downgraded to 'private', then unregister from the hub 83 | $currentprivacy = get_config('local_hub', 'privacy'); 84 | $hubmanager = new local_hub(); 85 | $hubtodirectorycommunication = $hubmanager->get_communication(WSCLIENT, HUBDIRECTORY, HUB_HUBDIRECTORYURL); 86 | if (($currentprivacy != HUBPRIVATE and $fromform->privacy == HUBPRIVATE) and !empty($hubtodirectorycommunication) 87 | and !empty($hubtodirectorycommunication->confirmed)) { 88 | 89 | $directorytohubcommunication = $hubmanager->get_communication(WSSERVER, HUBDIRECTORY, HUB_HUBDIRECTORYURL); 90 | 91 | $function = 'hubdirectory_unregister_hub'; 92 | $params = array(); 93 | $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; 94 | require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 95 | $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token); 96 | try { 97 | $result = $xmlrpcclient->call($function, $params); 98 | } catch (Exception $e) { 99 | $error = $OUTPUT->notification(get_string('failunregistrationofprivate', 'local_hub', $e->getMessage())); 100 | } 101 | 102 | if (empty($error)) { 103 | //delete the web service token 104 | $webservice_manager = new webservice(); 105 | $tokentodelete = $webservice_manager->get_user_ws_token($directorytohubcommunication->token); 106 | $webservice_manager->delete_user_ws_token($tokentodelete->id); 107 | 108 | //delete the communication 109 | $hubmanager->delete_communication($directorytohubcommunication); 110 | $hubmanager->delete_communication($hubtodirectorycommunication); 111 | echo $OUTPUT->notification(get_string('unregistrationofprivate', 'local_hub'), 'notifysuccess'); 112 | } else { 113 | echo $error; 114 | } 115 | } 116 | set_config('privacy', $fromform->privacy, 'local_hub'); 117 | 118 | //save the hub logo 119 | if (empty($fromform->keepcurrentimage)) { 120 | $file = $hubsettingsform->save_temp_file('hubimage'); 121 | 122 | if (!empty($file)) { 123 | 124 | $userdir = "hub/0/"; 125 | 126 | //create directory if doesn't exist 127 | $directory = make_upload_directory($userdir); 128 | 129 | //save the image into the directory 130 | copy($file, $directory . 'hublogo'); 131 | 132 | set_config('hublogo', true, 'local_hub'); 133 | 134 | $updatelogo = true; 135 | 136 | } else { 137 | if (file_exists($CFG->dataroot . '/hub/0/hublogo')) { 138 | unlink($CFG->dataroot . '/hub/0/hublogo'); 139 | } 140 | } 141 | } 142 | 143 | if (empty($updatelogo) and empty($fromform->keepcurrentimage)) { 144 | set_config('hublogo', false, 'local_hub'); 145 | } 146 | 147 | $hubsettingsform->update_hublogo(); 148 | 149 | //display confirmation 150 | echo $OUTPUT->notification(get_string('settingsupdated', 'local_hub'), 'notifysuccess'); 151 | } 152 | 153 | //display a warning if Recaptcha is enabled and not set 154 | if (get_config('local_hub', 'hubrecaptcha') 155 | && (!$CFG->recaptchapublickey or !$CFG->recaptchaprivatekey)) { 156 | $recaptchaurl = new moodle_url('/' . $CFG->admin . '/search.php', array('query' => 'recaptcha')); 157 | $recaptchalink = html_writer::tag('a', 158 | get_string('recaptcha', 'local_hub'), 159 | array('href' => $recaptchaurl)); 160 | echo $OUTPUT->notification(get_string('recaptchadisable', 'local_hub', $recaptchalink)); 161 | } 162 | 163 | if (!get_config('moodle', 'extendedusernamechars')) { 164 | echo $OUTPUT->notification(get_string('noextendedusernamechars', 'local_hub')); 165 | } 166 | 167 | $hubsettingsform->display(); 168 | 169 | echo $OUTPUT->footer(); 170 | 171 | -------------------------------------------------------------------------------- /rsslib.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Hub rss library 20 | * @package localhub 21 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 22 | * @author Jerome Mouneyrac 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | /** 27 | * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary. 28 | * The RSS feed content is a course search result. 29 | * @param array $args the arguments received in the url 30 | * $args[0] => context id = 2 (Front page) - not used 31 | * $args[1] => token 32 | * $args[2] => module name (it was needed by the rss/file.php to call this function) - not used 33 | * $args[3] => downloadable - PARAM_INT 34 | * $args[4] => audience - PARAM_ALPHA 35 | * $args[5] => educationallevel - PARAM_ALPHA 36 | * $args[6] => subject - PARAM_ALPHA 37 | * $args[7] => licence - PARAM_ALPHA 38 | * $args[8] => language - PARAM_ALPHANUMEXT 39 | * $args[9] => search - PARAM_TEXT (url encoded) 40 | * $args[10] => orderby - PARAM_ALPHA 41 | * @return string the full path to the cached RSS feed directory. Null if there is a problem. 42 | */ 43 | function hub_rss_get_feed($context, $args) { 44 | global $CFG, $DB; 45 | 46 | require_once($CFG->dirroot . '/local/hub/lib.php'); 47 | 48 | //are RSS feeds enabled? 49 | $enablerssfeeds = get_config('local_hub', 'enablerssfeeds'); 50 | 51 | if (empty($enablerssfeeds)) { 52 | debugging('DISABLED (module configuration)'); 53 | return null; 54 | } 55 | 56 | //check capabilities 57 | if (!has_capability('local/hub:view', $context)) { 58 | return null; 59 | } 60 | 61 | //TODO: cache 62 | $filename = 'rsssearch_' . $args[3] . '_' . $args[4] . '_' . $args[5] 63 | . '_' . $args[6] . '_' . $args[7] . '_' . $args[8] . '_' . $args[9] . '_' . $args[10]; 64 | $cachedfilepath = rss_get_file_full_name('local_hub', $filename); 65 | 66 | //get the courses from the search 67 | if ($args[7] != 'all') { 68 | $options['licenceshortname'] = $args[7]; 69 | } 70 | if ($args[6] != 'all') { 71 | $options['subject'] = $args[6]; 72 | } 73 | if ($args[4] != 'all') { 74 | $options['audience'] = $args[4]; 75 | } 76 | if ($args[5] != 'all') { 77 | $options['educationallevel'] = $args[5]; 78 | } 79 | if ($args[8] != 'all') { 80 | $options['language'] = $args[8]; 81 | } 82 | if ($args[3] != 'all') { 83 | $options['downloadable'] = $args[3]; 84 | $options['enrollable'] = !$args[3]; 85 | } else { 86 | $options['downloadable'] = true; 87 | $options['enrollable'] = true; 88 | } 89 | $options['search'] = empty($args[9]) ? '' : urldecode($args[9]); 90 | 91 | //if the RSS invisible secret is passed as parameter, display not visible course 92 | $rsssecret = get_config('local_hub', 'rsssecret'); 93 | if (!empty($rsssecret) and 94 | ($rsssecret == optional_param('rsssecret', false, PARAM_RAW))) { 95 | $options['visibility'] = COURSEVISIBILITY_NOTVISIBLE; 96 | } else { 97 | $options['visibility'] = COURSEVISIBILITY_VISIBLE; 98 | } 99 | 100 | //order by 101 | switch ($args[10]) { 102 | case 'newest': 103 | $options['orderby'] = 'timemodified DESC'; 104 | break; 105 | case 'eldest': 106 | $options['orderby'] = 'timemodified ASC'; 107 | break; 108 | case 'publisher': 109 | $options['orderby'] = 'publishername ASC'; 110 | break; 111 | case 'fullname': 112 | $options['orderby'] = 'fullname ASC'; 113 | break; 114 | case 'ratingaverage': 115 | $options['orderby'] = 'ratingaverage DESC'; 116 | break; 117 | default: 118 | break; 119 | } 120 | 121 | $hub = new local_hub(); 122 | $courses = $hub->get_courses($options, 0 , 10); 123 | 124 | //generate the information for rss 125 | $rssfeedinfo = local_hub_rss_generate_feed_info($courses); 126 | 127 | //generate the rss content 128 | require_once($CFG->libdir . "/rsslib.php"); 129 | 130 | 131 | //First the RSS header 132 | $searchurl = new moodle_url($CFG->wwwroot . '/', array('downloadable' => $args[3], 133 | 'audience' => $args[4], 'educationallevel' => $args[5], 'subject' => $args[6], 134 | 'licence' => $args[7], 'language' => $args[8], 'search' => $args[9], 'orderby' => $args[10], 135 | 'submitbutton' => 'Search+for+courses')); 136 | $rsscontent = rss_standard_header(get_config('local_hub', 'name'), 137 | $searchurl->out(), 138 | get_string('hubcoursessearch', 'local_hub')); 139 | 140 | $rsscontent .= rss_add_items($rssfeedinfo); 141 | 142 | //Now the RSS footer 143 | 144 | $rsscontent .= rss_standard_footer(); 145 | 146 | 147 | if (!empty($rsscontent)) { 148 | rss_save_file('local_hub', $filename, $rsscontent); 149 | } 150 | 151 | //return the path to the cached version 152 | return $cachedfilepath; 153 | } 154 | 155 | /** 156 | * Generate courses feed content 157 | * @param object $courses 158 | * @return array 159 | */ 160 | function local_hub_rss_generate_feed_info($courses) { 161 | global $CFG; 162 | 163 | $rssfeedinfo = array(); 164 | foreach ($courses as $course) { 165 | $courserss = new stdClass(); 166 | $courserss->title = $course->fullname; 167 | $courserss->author = $course->creatorname; 168 | $courserss->pubdate = $course->timemodified; 169 | 170 | $courseurl = new moodle_url($CFG->wwwroot . '/index.php', 171 | array('courseid' => $course->id, 'rss' => true)); 172 | 173 | $courserss->link = $courseurl->out(false); 174 | 175 | //create description 176 | $course->subject = get_string($course->subject, 'edufields'); 177 | $course->audience = get_string('audience' . $course->audience, 'hub'); 178 | $course->educationallevel = get_string('edulevel' . $course->educationallevel, 'hub'); 179 | 180 | //add course type (enrollable/downloadable) 181 | $typetext = empty($course->enrollable)? 182 | get_string('typedownloadable', 'local_hub'):get_string('typeenrollable', 'local_hub'); 183 | $deschtml = get_string('coursetype', 'local_hub', $typetext); 184 | $deschtml .= html_writer::empty_tag('br'); 185 | $deschtml .= $course->description; //the description 186 | 187 | //create the additional description 188 | $additionaldesc = html_writer::empty_tag('br'); 189 | $additionaldesc .= get_string('userinfo', 'local_hub', $course); 190 | if ($course->contributornames) { 191 | $additionaldesc .= ' - '; 192 | $additionaldesc .= get_string('contributors', 'local_hub', $course->contributornames); 193 | } 194 | 195 | if (empty($course->coverage)) { 196 | $course->coverage = ''; 197 | } else { 198 | $additionaldesc .= ' - '; 199 | $additionaldesc .= get_string('coverage', 'local_hub', $course->coverage); 200 | } 201 | 202 | //retrieve language string 203 | //construct languages array 204 | if (!empty($course->language)) { 205 | $languages = get_string_manager()->get_list_of_languages(); 206 | $course->lang = $languages[$course->language]; 207 | } else { 208 | $course->lang = ''; 209 | } 210 | //licence 211 | require_once($CFG->libdir . "/licenselib.php"); 212 | $licensemanager = new license_manager(); 213 | $licenses = $licensemanager->get_licenses(); 214 | foreach ($licenses as $license) { 215 | if ($license->shortname == $course->licenceshortname) { 216 | $course->license = $license->fullname; 217 | } 218 | } 219 | //time modified 220 | $course->timeupdated = userdate($course->timemodified); 221 | $additionaldesc .= ' - ' . get_string('fileinfo', 'local_hub', $course); 222 | //subject/audience/level 223 | $additionaldesc .= ' - ' . get_string('contentinfo', 'local_hub', $course); 224 | $deschtml .= html_writer::tag('span', $additionaldesc, array('class' => 'additionaldesc')); 225 | 226 | $courserss->description = $deschtml; 227 | 228 | $rssfeedinfo[] = $courserss; 229 | } 230 | return $rssfeedinfo; 231 | } 232 | 233 | -------------------------------------------------------------------------------- /admin/register.php: -------------------------------------------------------------------------------- 1 | . // 20 | // // 21 | /////////////////////////////////////////////////////////////////////////// 22 | 23 | /** 24 | * On this page the hub administrator register on the hub directory. 25 | * It redirects the admin on a confirmation page on the hub directory. 26 | * This page also handles update by web services. 27 | * @package localhub 28 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 29 | * @author Jerome Mouneyrac 30 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 | */ 32 | require('../../../config.php'); 33 | require_once($CFG->libdir . '/adminlib.php'); 34 | require_once($CFG->dirroot . '/local/hub/admin/forms.php'); 35 | require_once($CFG->dirroot . '/webservice/lib.php'); 36 | require_once($CFG->dirroot . '/local/hub/lib.php'); 37 | 38 | admin_externalpage_setup('hubregistration'); 39 | 40 | //check that the PHP xmlrpc extension is enabled 41 | if (!extension_loaded('xmlrpc')) { 42 | echo $OUTPUT->header(); 43 | $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 44 | $xmlrpcnotification .= get_string('xmlrpcdisabled', 'local_hub'); 45 | echo $OUTPUT->notification($xmlrpcnotification); 46 | echo $OUTPUT->footer(); 47 | die(); 48 | } 49 | 50 | $error = optional_param('error', '', PARAM_TEXT); 51 | 52 | $hub = new local_hub(); 53 | 54 | $directorytohubcommunication = $hub->get_communication(WSSERVER, HUBDIRECTORY, HUB_HUBDIRECTORYURL); 55 | 56 | $hubtodirectorycommunication = $hub->get_communication(WSCLIENT, HUBDIRECTORY, HUB_HUBDIRECTORYURL); 57 | 58 | $hubregistrationform = new hub_registration_form('', 59 | array('alreadyregistered' => !empty($hubtodirectorycommunication->confirmed))); 60 | 61 | 62 | /////// UNREGISTER ACTION ////// 63 | $unregister = optional_param('unregister', 0, PARAM_INT); 64 | $confirm = optional_param('confirm', 0, PARAM_INT); 65 | $force = optional_param('force', 0, PARAM_INT); 66 | if ($unregister && $confirm && confirm_sesskey()) { 67 | 68 | if (!$force) { 69 | $function = 'hubdirectory_unregister_hub'; 70 | $params = array(); 71 | $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; 72 | require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 73 | $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token); 74 | try { 75 | $result = $xmlrpcclient->call($function, $params); 76 | } catch (Exception $e) { 77 | $error = get_string('errorunregistration', 'local_hub', $e->getMessage()); 78 | } 79 | } 80 | 81 | if (empty($error)) { 82 | if (!empty($directorytohubcommunication)) { 83 | //delete the web service token 84 | $webservice_manager = new webservice(); 85 | $tokentodelete = $webservice_manager->get_user_ws_token($directorytohubcommunication->token); 86 | $webservice_manager->delete_user_ws_token($tokentodelete->id); 87 | 88 | //delete the communication 89 | $hub->delete_communication($directorytohubcommunication); 90 | } 91 | 92 | if (!empty($hubtodirectorycommunication)) { 93 | $hub->delete_communication($hubtodirectorycommunication); 94 | } 95 | } 96 | 97 | redirect(new moodle_url('/local/hub/admin/register.php', 98 | array('sesskey' => sesskey(), 'error' => $error))); 99 | } 100 | 101 | 102 | /////// UPDATE ACTION //////// 103 | // update the hub registration (in fact it is a new registration) 104 | $update = optional_param('update', 0, PARAM_INT); 105 | if ($update && confirm_sesskey()) { 106 | //update the registration 107 | $function = 'hubdirectory_update_hub_info'; 108 | $hubinfo = $hub->get_info(); 109 | $hubinfo['name'] = clean_param($hubinfo['name'], PARAM_TEXT); 110 | $hubinfo['description'] = clean_param($hubinfo['description'], PARAM_TEXT); 111 | $hubinfo['contactname'] = clean_param($hubinfo['contactname'], PARAM_TEXT); 112 | $params = array('hubinfo' => $hubinfo); 113 | $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; 114 | require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); 115 | $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hubtodirectorycommunication->token); 116 | try { 117 | $result = $xmlrpcclient->call($function, $params); 118 | } catch (Exception $e) { 119 | $error = get_string('errorregistration', 'local_hub', $e->getMessage()); 120 | } 121 | } 122 | 123 | 124 | /////// FORM REGISTRATION ACTION ////// 125 | // retrieve the privacy setting 126 | $privacy = get_config('local_hub', 'privacy'); 127 | $fromform = $hubregistrationform->get_data(); 128 | if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked 129 | //we are using the form input as the redirection parameters 130 | //(token, url and name) 131 | $params = (array) $fromform; 132 | //first time we press the registration button (and only time if no failure) 133 | if (empty($directorytohubcommunication)) { 134 | 135 | //create new token for the hub directory to call the hub 136 | $capabilities = array('local/hub:viewinfo'); 137 | $token = $hub->create_hub_token('Moodle.org Hub Directory', 'Hub directory', 138 | HUB_HUBDIRECTORYURL . '_directory_user', $capabilities); 139 | 140 | //we save the token into the communication table in order to have a reference to the hidden token 141 | $directorytohubcommunication = new stdClass(); 142 | $directorytohubcommunication->token = $token->token; 143 | $directorytohubcommunication->type = WSSERVER; 144 | $directorytohubcommunication->remotename = 'Moodle.org hub directory'; 145 | $directorytohubcommunication->remoteentity = HUBDIRECTORY; 146 | $directorytohubcommunication->remoteurl = HUB_HUBDIRECTORYURL; 147 | $directorytohubcommunication->confirmed = 0; 148 | $directorytohubcommunication->id = $hub->add_communication($directorytohubcommunication); 149 | 150 | $params['token'] = $token->token; 151 | } else { 152 | $params['token'] = $directorytohubcommunication->token; 153 | } 154 | 155 | //if the hub is private do not redirect to moodle.org 156 | if ($privacy != HUBPRIVATE) { 157 | redirect(new moodle_url(HUB_HUBDIRECTORYURL . '/local/hubdirectory/hubregistration.php', $params)); 158 | } 159 | } 160 | 161 | 162 | /////// OUTPUT SECTION ///////////// 163 | echo $OUTPUT->header(); 164 | $renderer = $PAGE->get_renderer('local_hub'); 165 | //unregister confirmation page 166 | if ($unregister && empty($confirm)) { 167 | echo $renderer->unregistration_confirmation($force); 168 | } else { 169 | $hubregistrationform->display(); 170 | 171 | //if the hub is private, do not display the register button 172 | if ($privacy == HUBPRIVATE) { 173 | echo $OUTPUT->notification(get_string('cannotregisterprivatehub', 'local_hub')); 174 | } 175 | 176 | //Display update single button if needed 177 | if (!empty($hubtodirectorycommunication->confirmed) and $privacy != HUBPRIVATE) { 178 | 179 | //display update result 180 | if (!empty($result)) { 181 | echo $OUTPUT->notification(get_string('registrationupdated', 'local_hub'), 'notifysuccess'); 182 | } 183 | 184 | if (!empty($error) and confirm_sesskey()) { 185 | echo $OUTPUT->notification($error); 186 | } 187 | 188 | $url = new moodle_url("/local/hub/admin/register.php", 189 | array('sesskey' => sesskey(), 'update' => 1)); 190 | $button = new single_button($url, get_string('hubregisterupdate', 'local_hub')); 191 | $button->class = "buttoncenter"; 192 | echo $OUTPUT->render($button); 193 | 194 | $url = new moodle_url("/local/hub/admin/register.php", 195 | array('confirm' => 0, 'unregister' => 1)); 196 | $button = new single_button($url, get_string('hubunregister', 'local_hub')); 197 | $button->class = "buttoncenter"; 198 | echo $OUTPUT->render($button); 199 | } 200 | } 201 | 202 | echo $OUTPUT->footer(); 203 | 204 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Moodle - http://moodle.org/ 3 | Moodle is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | Moodle is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with Moodle. If not, see .*//* 15 | */ 16 | 17 | /* ADMIN: stolen secret */ 18 | #page-admin-local-hub-admin-stolensecret .admintextfield {width: 400px;} 19 | #page-admin-local-hub-admin-stolensecret .sitesecret {display: block; margin-top: 6px;} 20 | #page-admin-local-hub-admin-stolensecret .markasstolen {display: block;} 21 | /* ADMIN: registration */ 22 | #page-admin-local-hub-admin-register .buttoncenter {text-align: center} 23 | 24 | /* ADMIN: hub settings */ 25 | #page-admin-local-hub-admin-settings .adminhubdescription {width: 400px; height: 120px; padding: 2px;} 26 | #page-admin-local-hub-admin-settings .admintextfield {width: 400px;} 27 | #page-admin-local-hub-admin-settings .admincurrentimage {vertical-align: top;} 28 | 29 | /* Site registration page */ 30 | #page-admin-local-registration-index .centeredbutton {text-align: center} 31 | #page-admin-local-registration-index .cell {border-width: 0 1px;} 32 | #page-admin-local-registration-index .justifytext {text-align: justify} 33 | 34 | 35 | /* ADMIN: manage sites */ 36 | #page-admin-local-hub-admin-managesites .trustedtr {background-color: #ffe1c3;} 37 | #page-admin-local-hub-admin-managesites .prioritisetr {background-color: #ffd4ff;} 38 | #page-admin-local-hub-admin-managesites .additionaldesc {font-size: 80%; color: #B8860B;} 39 | #page-admin-local-hub-admin-managesites .additionaladmindesc {font-size: 80%; color: #6666ff;} 40 | 41 | 42 | /*ADMIN: manage courses */ 43 | #page-admin-local-hub-admin-managecourses .additionaldesc {font-size: 80%; color: #B8860B;} 44 | #page-admin-local-hub-admin-managecourses .coursesitelink {font-size: 80%;} 45 | #page-admin-local-hub-admin-managecourses .coursecomment {float: right;} 46 | #page-admin-local-hub-admin-managecourses .courselinks {float: right;width: 180px} 47 | #page-admin-local-hub-admin-managecourses .hubadminoperations {} 48 | #page-admin-local-hub-admin-managecourses .courseoperations {margin-top:9px; text-align:center} 49 | #page-admin-local-hub-admin-managecourses .coursescreenshot {text-align:center; cursor: pointer;} 50 | #page-admin-local-hub-admin-managecourses .fullhubcourse {margin-bottom: 20px;} 51 | #page-admin-local-hub-admin-managecourses .hubcoursedelete {float: left;} 52 | #page-admin-local-hub-admin-managecourses .hubcoursevisible {float: left;padding-right: 4px;} 53 | #page-admin-local-hub-admin-managecourses .pagingbar {text-align: center;} 54 | #page-admin-local-hub-admin-managecourses .hubcoursemail {margin-left: 5px; vertical-align: middle;} 55 | #page-admin-local-hub-admin-managecourses .fradio input {margin-right: 3px;} 56 | #page-admin-local-hub-admin-managecourses .hubcoursedownload:hover {background-color: #fdc332;} 57 | #page-admin-local-hub-admin-managecourses .hubcoursedownload { 58 | display: inline-block; 59 | padding: 5px 8px 6px; 60 | color: #000; 61 | text-decoration: none; 62 | -moz-border-radius: 6px; 63 | -webkit-border-radius: 6px; 64 | -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6); 65 | -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6); 66 | text-shadow: 0 -1px 1px rgba(0,0,0,0.25); 67 | border-bottom: 1px solid rgba(0,0,0,0.25); 68 | position: relative; 69 | cursor: pointer; 70 | background-color: #ffdf8e; 71 | margin-left: 6px; 72 | font-size: 95%; 73 | } 74 | #page-admin-local-hub-admin-managecourses .coursedescription {float: left; width: 70%;} 75 | #page-admin-local-hub-admin-managecourses .hubcoursetitle { 76 | -webkit-box-shadow: rgba(0, 0, 0, 0.546875) 0px 0px 4px; 77 | -moz-box-shadow: rgba(0, 0, 0, 0.546875) 0px 0px 4px; 78 | background: #ebb42b; 79 | left: -15px; 80 | position: relative; 81 | z-index: 100; 82 | border: 0px; 83 | font-size: 100%; 84 | margin: 0px; 85 | outline: 0px; 86 | padding: 0px; 87 | vertical-align: baseline; 88 | font-size: 30px; 89 | color: #fff; 90 | padding-top: 6px; 91 | padding-bottom: 6px; 92 | text-shadow: 1px 1px 2px rgba(0,0,0,0.2); 93 | text-align: left; 94 | font-style:italic; 95 | font-weight:normal; 96 | line-height:1.2em; 97 | font-size: 140%; 98 | color: #fff; 99 | width: 102%; 100 | text-indent: 15px; 101 | } 102 | #page-admin-local-hub-admin-managecourses .hubcourseresult { 103 | background:none repeat scroll 0 0 #FFFFFF; 104 | clear:both; 105 | margin:30px auto 0; 106 | z-index:90; 107 | width: 95%; 108 | padding: 10px 10px 10px 10px; 109 | border-style: solid; 110 | border-width: 1px; 111 | } 112 | #page-admin-local-hub-admin-managecourses .hubcourseinfo {} 113 | #page-admin-local-hub-admin-managecourses .hubcoursesettings {} 114 | #page-admin-local-hub-admin-managecourses .hubbulkselect {margin-top: 13px; margin-left: 15px; float: left;} 115 | #page-admin-local-hub-admin-managecourses .hubbulkbutton { margin-left: 15px; margin-top: 13px;} 116 | #page-admin-local-hub-admin-managecourses .hubcourseoutcomes {} 117 | #page-admin-local-hub-admin-managecourses .hubcoursetitlepanel{margin-bottom: 6px;} 118 | #page-admin-local-hub-admin-managecourses .pagingbar a {padding-left: 0px;} 119 | #page-admin-local-hub-admin-managecourses .creatornotestitle { 120 | color:#B8860B; 121 | font-size:80%; 122 | font-weight:bold; 123 | margin-top:5px; 124 | } 125 | #page-admin-local-hub-admin-managecourses .creatornotes { 126 | color:#B8860B; 127 | font-size:80%; 128 | } 129 | #page-admin-local-hub-admin-managecourses .seecreatornotes { 130 | color:#B8860B; 131 | font-size:80%; 132 | font-weight:bold; 133 | cursor: pointer; 134 | } 135 | 136 | /* COURSE SETTINGS */ 137 | #page-admin-local-hub-admin-coursesettings .coursesettingstextarea {padding: 2px;} 138 | #page-admin-local-hub-admin-coursesettings .coursesettingstextfield {width: 400px;} 139 | 140 | 141 | /* FRONT PAGE */ 142 | #page-site-index .additionaldesc {font-size: 80%; color: #B8860B;} 143 | #page-site-index .comment-link {font-size: 80%; color: #555555;} 144 | #page-site-index .coursescreenshot {text-align:center; cursor: pointer;} 145 | #page-site-index .pagingbar {text-align: center;} 146 | #page-site-index .coursecomment {float: right;} 147 | #page-site-index .courseoperations {margin-top:9px; text-align:center} 148 | #page-site-index .hubcoursedownload:hover {background-color: #fdc332;} 149 | #page-site-index .courselinks {float: right;width: 180px} 150 | #page-site-index .ratingaggregate {float: left; padding-right: 4px;} 151 | #page-site-index .hubcourserating { padding-top: 3px; font-size: 80%; font-weight: bold; 152 | color:#8B8989;} 153 | #page-site-index .hubcoursecomments { padding-top: 3px; 154 | color:#8B8989;} 155 | #page-site-index .coursedescription {width: 70%; float: left;} 156 | #page-site-index .hubcoursetitle { 157 | -webkit-box-shadow: rgba(0, 0, 0, 0.546875) 0px 0px 4px; 158 | -moz-box-shadow: rgba(0, 0, 0, 0.546875) 0px 0px 4px; 159 | background: #ebb42b; 160 | left: -15px; 161 | position: relative; 162 | z-index: 0; 163 | border: 0px; 164 | font-size: 100%; 165 | margin: 0px; 166 | outline: 0px; 167 | padding: 0px; 168 | vertical-align: baseline; 169 | font-size: 30px; 170 | color: #fff; 171 | padding-top: 6px; 172 | padding-bottom: 6px; 173 | text-shadow: 1px 1px 2px rgba(0,0,0,0.2); 174 | text-align: left; 175 | font-style:italic; 176 | font-weight:normal; 177 | line-height:1.2em; 178 | font-size: 140%; 179 | color: #fff; 180 | width: 102%; 181 | text-indent: 15px; 182 | } 183 | 184 | #page-site-index .fullhubcourse {margin-bottom: 20px;} 185 | #page-site-index .hubcoursedownload { 186 | display: inline-block; 187 | padding: 5px 8px 6px; 188 | color: #000; 189 | text-decoration: none; 190 | -moz-border-radius: 6px; 191 | -webkit-border-radius: 6px; 192 | -moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6); 193 | -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6); 194 | border-bottom: 1px solid rgba(0,0,0,0.25); 195 | position: relative; 196 | cursor: pointer; 197 | background-color: #ffdf8e; 198 | margin-left: 6px; 199 | font-size: 95%; 200 | } 201 | #page-site-index .comment-list li { 202 | background-color:#ffdf8e !important; 203 | color: #000; 204 | -moz-border-radius: 6px; 205 | -webkit-border-radius: 6px; 206 | padding-right: 4px; 207 | padding-bottom: 2px; 208 | } 209 | #page-site-index .hubcourseresult { 210 | background:none repeat scroll 0 0 #FFFFFF; 211 | clear:both; 212 | margin:30px auto 0; 213 | z-index:90; 214 | width: 95%; 215 | padding: 10px 10px 10px 10px; 216 | border-style: solid; 217 | border-width: 1px; 218 | } 219 | #page-site-index .hubcourseinfo {margin-left: 15px;} 220 | #page-site-index .coursesitelink {} 221 | 222 | #page-site-index .norating { 223 | font-weight: bold; 224 | color:#8B8989; 225 | font-size: 80%; 226 | } 227 | 228 | #page-site-index .nocomments { 229 | font-weight: bold; 230 | color:#8B8989; 231 | font-size: 80%; 232 | } 233 | 234 | #page-site-index .hubcoursemail { 235 | margin-left: 5px; 236 | vertical-align: middle; 237 | } 238 | 239 | #page-site-index .hubemailsubject { 240 | width:439px; 241 | } 242 | 243 | #page-site-index .hubcourseoutcomes {} 244 | 245 | #page-site-index .fradio input {margin-right: 3px;} 246 | #page-site-index .hubrsslink { 247 | float:right; 248 | margin-right:15px; 249 | margin-top:15px; 250 | text-align:right; 251 | } 252 | #page-site-index .hubcoursepermalink{ 253 | float:right; 254 | margin-right:6px; 255 | margin-top:15px; 256 | } 257 | #page-site-index .hubcoursetitlepanel{margin-bottom: 6px;} 258 | 259 | #page-site-index .moodle-dialogue { 260 | -moz-border-radius:12px 12px 12px 12px; 261 | -moz-box-shadow:0 1px 3px rgba(0, 0, 0, 0.6); 262 | -webkit-border-radius:12px 12px 12px 12px; 263 | -webkit-box-shadow:0 1px 3px rgba(0, 0, 0, 0.6); 264 | border-width:0 0 0 0; 265 | } 266 | 267 | #page-site-index .moodle-dialogue-base .moodle-dialogue-wrap { 268 | -moz-border-radius:12px 12px 0px 0px; 269 | -webkit-border-radius:12px 12px 0px 0px; 270 | background-color:#FFFFFF; 271 | border:1px solid #555555; 272 | } 273 | 274 | #page-site-index .moodle-dialogue-base .moodle-dialogue-hd { 275 | -moz-border-radius:12px 12px 0 0; 276 | -webkit-border-radius:12px 12px 0 0; 277 | background-color:#F6F6F6; 278 | border:1px solid #CCCCCC; 279 | overflow: auto; 280 | } 281 | 282 | #page-site-index .moodle-dialogue-base .moodle-dialogue-bd { 283 | padding:0px; 284 | margin-bottom: -5px; 285 | } 286 | 287 | #page-site-index .moodle-dialogue-base .closebutton { 288 | margin-top:4px; 289 | width:30px; 290 | } 291 | 292 | #page-site-index .pagingbar a {padding-left: 0px;} 293 | #page-site-index .creatornotestitle { 294 | color:#B8860B; 295 | font-size:80%; 296 | font-weight:bold; 297 | margin-top:5px; 298 | } 299 | #page-site-index .creatornotes { 300 | color:#B8860B; 301 | font-size:80%; 302 | } 303 | #page-site-index .seecreatornotes { 304 | color:#B8860B; 305 | font-size:80%; 306 | font-weight:bold; 307 | cursor: pointer; 308 | } 309 | 310 | #page-site-index .mform .fitem .felement { 311 | margin-left: 150px; 312 | } 313 | 314 | #page-site-index .mform .fitem .fitemtitle { 315 | width: 140px; 316 | } 317 | 318 | .hubcoursetotal {text-align: center;} 319 | 320 | .featuredimg {margin-top: 20px; text-align: center;} 321 | .addthis {margin-top:10px;} 322 | -------------------------------------------------------------------------------- /top/stats/index.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * @package moodle-dot-org 20 | * @subpackage stats 21 | * @copyright 2009 Sam Hemelryk 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | //echo "Sorry, this page is temporarily down for updates"; 26 | //exit; 27 | 28 | /** Include the nessecary config file :) */ 29 | 30 | define('STATS_DIR', 'local/hub/top/stats'); 31 | 32 | require('../../../../config.php'); 33 | require_once($CFG->dirroot.'/'.STATS_DIR.'/lib.php'); 34 | require_once($CFG->dirroot.'/'.STATS_DIR.'/graphlib.php'); 35 | require_once($CFG->dirroot.'/'.STATS_DIR.'/googlecharts.php'); 36 | 37 | error_reporting(E_ALL); 38 | ini_set('display_errors', true); 39 | 40 | $stats = local_hub_stats_get_registry_stats(); 41 | 42 | $PAGE->set_context(context_system::instance()); 43 | $PAGE->set_title(get_string('aboutstatisticstitle', 'local_hub')); 44 | $PAGE->set_heading(get_string('aboutstatisticsheading', 'local_hub')); 45 | $PAGE->set_url(new moodle_url('/stats/')); 46 | $PAGE->navbar->add($PAGE->heading, $PAGE->url); 47 | 48 | echo $OUTPUT->header(); 49 | echo $OUTPUT->heading($PAGE->heading); 50 | 51 | /** 52 | * Display the all registered sites graph 53 | */ 54 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 55 | //echo html_writer::start_tag('p', array('class'=>'mdl-align')); 56 | //echo html_writer::empty_tag('img', array('src'=>all_sites_graph(), 'alt'=>get_string('registrationgraphalt', 'local_hub'))); 57 | //echo html_writer::end_tag('p'); 58 | 59 | $table = new html_table(); 60 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 61 | $table->width = '400px'; 62 | $table->align = array('left','right'); 63 | $table->data = array( 64 | array(get_string('registeredsitestitle','local_hub'), ''.number_format($stats->registrycount).''), 65 | array(get_string('statscountries', 'local_hub'), ''.number_format($stats->countrycount).""), 66 | array(get_string('statscourses', 'local_hub'), number_format($stats->courses)), 67 | array(get_string('statsusers', 'local_hub'), number_format($stats->users)), 68 | array(get_string('statsenrolments', 'local_hub'), number_format($stats->enrolments)), 69 | array(get_string('statsposts', 'local_hub'), number_format($stats->posts)), 70 | array(get_string('statsresources', 'local_hub'), number_format($stats->resources)), 71 | array(get_string('statsquestions', 'local_hub'), number_format($stats->questions)) 72 | ); 73 | echo html_writer::table($table); 74 | 75 | echo html_writer::tag('p', get_string('registrationgraphdesc', 'local_hub'), array('class'=>'mdl-align', 'style'=>'font-size:0.8em;')); 76 | 77 | echo html_writer::end_tag('div'); 78 | 79 | 80 | /** 81 | * Display the implementation map chart 82 | */ 83 | echo $OUTPUT->heading(get_string('top10countriesbyregistration', 'local_hub')); 84 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 85 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 86 | echo html_writer::empty_tag('img', array('src'=>moodle_implementation_map_graph(), 'alt'=>get_string('graphregistrationmap', 'local_hub'))); 87 | echo html_writer::end_tag('p'); 88 | $table = new html_table(); 89 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 90 | $table->width = '400px'; 91 | $table->head = array('Country', 'Registrations'); 92 | $table->data = array(); 93 | $table->align = array('left','right'); 94 | $top10countries = local_hub_stats_top_10_countries(); 95 | $countrynames = get_string_manager()->get_list_of_countries(); 96 | foreach ($top10countries as $row) { 97 | if (!empty($row->countrycode)) { 98 | $data = Array($countrynames[$row->countrycode], number_format($row->countrycount)); 99 | $table->data[] = $data; 100 | } 101 | } 102 | echo html_writer::table($table); 103 | if ($stats->countrycount) { 104 | echo html_writer::tag('p', get_string('graphregistrationmapdesc','local_hub',$stats->countrycount), array('class'=>'mdl-align', 'style'=>'font-size:0.8em;color:#555;')); 105 | } 106 | echo html_writer::end_tag('div'); 107 | 108 | 109 | 110 | /** 111 | * Display the new registrations graph 112 | */ 113 | if (is_siteadmin()) { 114 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 115 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 116 | echo html_writer::empty_tag('img', array('src'=>new_registrations_graph(), 'alt'=>get_string('newregistrations', 'local_hub'))); 117 | echo html_writer::end_tag('p'); 118 | echo html_writer::end_tag('div'); 119 | } 120 | 121 | /** 122 | * Display the download summary graph 123 | */ 124 | //if (is_siteadmin()) { 125 | // echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 126 | // echo html_writer::start_tag('p', array('class'=>'mdl-align')); 127 | // echo html_writer::empty_tag('img', array('src'=>download_summary_graph(), 'alt'=>get_string('namedownloads', 'local_hub'))); 128 | // echo html_writer::end_tag('p'); 129 | // echo html_writer::end_tag('div'); 130 | //} 131 | 132 | /** 133 | * Users to site number graph 134 | */ 135 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 136 | echo html_writer::start_tag('p', array('class'=>'mdl-align', 'style'=>'font-size:0.8em;color:#555;')); 137 | //echo html_writer::empty_tag('img', array('src'=>'sites.bar.png', 'alt'=>get_string('registeredsitestitle', 'local_hub'))); 138 | echo ' '; 139 | echo html_writer::empty_tag('img', array('src'=>moodle_users_per_site(), 'alt'=>get_string('graphusersites', 'local_hub'))); 140 | echo html_writer::end_tag('p'); 141 | 142 | /* 143 | echo $OUTPUT->heading(get_string('top10sitesbyusers', 'local_hub')); 144 | $table = new html_table(); 145 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 146 | $table->width = '800px'; 147 | $table->size = array('360px','80px','80px','280px'); 148 | $table->head = array(get_string('site'), get_string('statsusers', 'local_hub'), get_string('statscourses', 'local_hub')); 149 | $table->align = array('left','right','right'); 150 | $table->data = array(); 151 | 152 | $top10usersitesresults = local_hub_stats_top_10_sites_by_users(); 153 | foreach ($top10usersitesresults as $row) { 154 | $data = array(); 155 | if ($row->public=='2') { 156 | $data[] = html_writer::link(htmlspecialchars($row->url), clean_text($row->sitename)); 157 | } else { 158 | $data[] = clean_text($row->sitename); 159 | } 160 | $data[] = number_format($row->users); 161 | $data[] = number_format($row->courses); 162 | $table->data[] = $data; 163 | } 164 | echo html_writer::table($table); 165 | 166 | echo $OUTPUT->heading(get_string('top10sitesbycourses', 'local_hub')); 167 | $table = new html_table(); 168 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 169 | $table->width = '800px'; 170 | $table->size = array('360px','80px','80px','280px'); 171 | $table->head = array(get_string('site'), get_string('statsusers', 'local_hub'), get_string('statscourses', 'local_hub')); 172 | $table->align = array('left','right','right'); 173 | $table->data = array(); 174 | 175 | $top10coursesitesresults = local_hub_stats_top_10_sites_by_courses(); 176 | foreach ($top10coursesitesresults as $row) { 177 | $data = array(); 178 | if ($row->public=='2') { 179 | $data[] = html_writer::link(htmlspecialchars($row->url), clean_text($row->sitename)); 180 | } else { 181 | $data[] = clean_text($row->sitename); 182 | } 183 | $data[] = number_format($row->users); 184 | $data[] = number_format($row->courses); 185 | $table->data[] = $data; 186 | } 187 | echo html_writer::table($table); 188 | */ 189 | echo html_writer::end_tag('div'); 190 | 191 | /** 192 | * Display the major and minor registrations for the past 6 months 193 | */ 194 | echo $OUTPUT->heading(get_string('versionsused', 'local_hub')); 195 | $partialminorchartexists = check_for_existing_cached_chart($CFG->dirroot.'/'.STATS_DIR.'/cache/partial.minor.versions.'.date('Ymd').'.png'); 196 | $fullminorchartexists = check_for_existing_cached_chart($CFG->dirroot.'/'.STATS_DIR.'/cache/full.minor.versions.'.date('Ymd').'.png'); 197 | if (!$partialminorchartexists || !$fullminorchartexists) { 198 | // This is a VERY costly query... VERRRRRRRRY costly 199 | // Only run this query is we NEED to generate 200 | $versioninfo = gather_version_information(0,2,0); // Last 2 months 201 | $fullversioninfo = gather_version_information(99,0,0); // Last 99 years 202 | } else { 203 | // Generate a dummy array we won't generate the graph anyway 204 | $tempversion = Array(); 205 | $tempversion['version'] = '2.0.0'; 206 | $tempversion['major'] = '2'; 207 | $tempversion['minor'] = '0'; 208 | $tempversion['release'] = '0'; 209 | $tempversion['count'] = 1; 210 | $versioninfo = array($tempversion); 211 | $fullversioninfo = array($tempversion); 212 | } 213 | 214 | $minorversiongraph = minor_version_pie_graph($versioninfo, 'New Moodle registrations in the last two months'); 215 | $fullminorversiongraph = minor_version_pie_graph($fullversioninfo, 'All Moodle registrations by version', 'full'); 216 | 217 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 218 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 219 | echo html_writer::empty_tag('img', array('src'=>$minorversiongraph, 'alt'=>get_string('registrationslastmonths', 'local_hub', 6))); 220 | echo html_writer::empty_tag('img', array('src'=>$fullminorversiongraph, 'alt'=>get_string('registrationstotal', 'local_hub'))); 221 | echo html_writer::end_tag('p'); 222 | echo html_writer::end_tag('div'); 223 | 224 | /** 225 | * Display the moodle (moodle.net users!) population graph 226 | */ 227 | 228 | if (is_siteadmin()) { 229 | // Update this site's own number of users. 230 | $usercount = local_hub_stats_update_moodle_users(); 231 | 232 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter', 'style'=>'background-color:#FFF;padding:20px;')); 233 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 234 | echo html_writer::empty_tag('img', array('src'=>moodle_population(), 'alt'=>get_string('graphpopulation', 'local_hub'))); 235 | echo html_writer::end_tag('p'); 236 | $lastday = time() - (24 * 3600); 237 | $lastmonth = time() - (30 * 24 * 3600); 238 | $table = new html_table(); 239 | $table->attributes = array('class'=>'generaltable boxaligncenter'); 240 | $table->width ='400px'; 241 | $table->align = array('left','right'); 242 | $table->data = array(); 243 | $table->data[] = array(get_string('registereduserstotal', 'local_hub'), number_format($usercount)); 244 | $table->data[] = array(get_string('registereduserslastday', 'local_hub'), number_format($DB->count_records_select('user', 'firstaccess > ?', array($lastday)))); 245 | $table->data[] = array(get_string('activeusers24hours', 'local_hub'), number_format($DB->count_records_select('user', 'lastaccess > ?', array($lastday)))); 246 | $table->data[] = array(get_string('activeuserspastmonth', 'local_hub'), number_format($DB->count_records_select('user', 'lastaccess > ?', array($lastmonth)))); 247 | echo html_writer::table($table); 248 | echo html_writer::end_tag('div'); 249 | } 250 | 251 | echo $OUTPUT->footer(); 252 | -------------------------------------------------------------------------------- /top/sites/index.php: -------------------------------------------------------------------------------- 1 | dirroot.'/local/hub/top/sites/siteslib.php'); 5 | require_once($CFG->dirroot.'/local/hub/top/stats/lib.php'); 6 | require_once($CFG->dirroot.'/local/hub/top/stats/graphlib.php'); 7 | require_once($CFG->dirroot.'/local/hub/top/stats/googlecharts.php'); 8 | 9 | define('STATS_DIR', 'local/hub/top/sites'); 10 | 11 | $countries = get_string_manager()->get_list_of_countries(); 12 | $countryarray = get_combined_country_info(); 13 | $totalcountryinfo = $countryarray['TOTAL']; 14 | unset($countryarray['TOTAL']); 15 | 16 | $country = optional_param('country', '', PARAM_ALPHA); 17 | $cool = optional_param('cool', 0, PARAM_INT); 18 | $uncool = optional_param('uncool', 0, PARAM_INT); 19 | $sitevoting = optional_param('voting', 0, PARAM_INT); 20 | //disable this on live until MDLSITE-2787 gets resolved 21 | $sitevoting = 0; 22 | $USER->sitevoting = false; 23 | 24 | $edit = optional_param('edit', '', PARAM_ALPHA); 25 | 26 | $PAGE->set_context(context_system::instance()); 27 | $PAGE->set_url(new moodle_url('/local/hub/top/sites')); 28 | $PAGE->requires->css('/local/hub/style/hub.css'); 29 | 30 | $isadmin = ismoodlesiteadmin(); 31 | $USER->siteediting = false; 32 | if ($isadmin && $edit == "on") { 33 | $USER->siteediting = true; 34 | } 35 | 36 | // If no specific country was requested. 37 | if (empty($country)) { 38 | $usercountry = ""; 39 | if (!empty($USER->country)) { 40 | // Logged in user so get their country from their profile. 41 | $usercountry = $USER->country; 42 | } else { 43 | // User is not logged in so try to guess their country based on their IP. 44 | 45 | $ip = (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 46 | 47 | if(strpos($ip, ':') !== FALSE) { 48 | // IPv6. 49 | // MDLSITE-4084 - Implement location guessing in IPv6. 50 | } else { 51 | // IPv4. 52 | 53 | // Previously we used the msql function inet_aton() within the below query. 54 | // the PHP function ip2long() should be equivalent with the benefit of being database independent. 55 | $ip = ip2long($ip); 56 | 57 | if ($countryinfo = $DB->get_record_sql("SELECT * FROM {countries} WHERE ipfrom <= $ip AND $ip <= ipto ")) { 58 | $usercountry = $countryinfo->code2; 59 | } 60 | } 61 | } 62 | 63 | if ($usercountry) { 64 | $country = $usercountry; 65 | } 66 | } 67 | 68 | $list = null; 69 | 70 | if ($country!==null && array_key_exists($country, $countries)) { 71 | 72 | if (!isloggedin() || isguestuser()) { 73 | unset($USER->sitevoting); 74 | } 75 | 76 | if (!empty($cool)) { 77 | $votesiteid = $cool; 78 | $votemodifier = 1; 79 | } else if (!empty($uncool)) { 80 | $votesiteid = $uncool; 81 | $votemodifier = -1; 82 | } 83 | if (isset($votesiteid) && isloggedin() && confirm_sesskey()) { 84 | $message = vote_for_site($votesiteid, $votemodifier); 85 | } 86 | 87 | $sites = get_sites_for_country($country); 88 | 89 | if ($sitevoting) { 90 | if ($sitevoting == 1) { 91 | $USER->sitevoting = true; 92 | } else { 93 | $USER->sitevoting = false; 94 | } 95 | } 96 | 97 | $graph = new google_charts_map_graph(); 98 | $graph->force_generation(true); 99 | $graph->set_chart_title($countries[$country]." map"); 100 | $graph->set_default_colour('FFEAB3'); 101 | $filename = 'country.map.'.$country.'.png'; 102 | $graph->set_filename($filename); 103 | $graph->add_value($country, 100); 104 | 105 | $graph = html_writer::empty_tag('img', array('src'=>new moodle_url($graph), 'alt'=>$countries[$country]." map", 'class'=>'countrymapimg')); 106 | 107 | $list = new stdClass; 108 | $list->printanchors = true; 109 | $list->width = '100%'; 110 | if ($sites->privatesites>0) { 111 | $list->heading = $countries[$country]." $sites->totalsites sites total ($sites->privatesites are private and are not shown)$graph"; 112 | } else { 113 | $list->heading = $countries[$country]." $sites->totalsites sites total$graph"; 114 | } 115 | $list->data = Array(); 116 | 117 | // Get old voting records 118 | if (!empty($USER->sitevoting)) { 119 | $oldvotes = $DB->get_records_menu('registry_votes', array('userid'=>$USER->id), '', 'siteid, vote'); 120 | $countvotes = $DB->get_records_select_menu('registry_votes', 'siteid > 0 GROUP BY siteid', null, '', 'siteid, count(*) number'); 121 | } 122 | 123 | $newtimestamp = time() - (60*60*24*14); 124 | if (!is_array($sites->sites)) $sites->sites = Array(); 125 | foreach ($sites->sites as $site) { 126 | if (trim($site->name) == '') { 127 | $name = $site->url; 128 | } else { 129 | $name = $site->name; 130 | } 131 | 132 | if ($site->cool >= MAXVOTES) { 133 | $name = "$name"; 134 | } 135 | 136 | $properties=''; 137 | if ($site->timeregistered>$newtimestamp) { 138 | $properties .= " (new)"; 139 | } 140 | 141 | if (isloggedin() && !isguestuser() && ((int)$site->contactable === 1) && (!isset($SESSION->registrycontactmessagesent) || $SESSION->registrycontactmessagesent < 4)) { 142 | $properties .= ' '; 143 | $properties .= $OUTPUT->action_icon(new moodle_url('/sites/contact.php', array('siteid'=>$site->id, 'sesskey'=>sesskey())), new pix_icon('t/email', 'Send mail', 'moodle', array('style'=>'height:11px;width:11px;border:0;'))); 144 | } 145 | 146 | if ($site->cool <= - MAXVOTES) { 147 | $properties .= ' Uncool!'; 148 | } else if ($site->cool >= MAXVOTES) { 149 | $properties .= ' Cool!'; 150 | } 151 | 152 | if (!empty($USER->sitevoting) && $site->privacy) { 153 | $properties .= '   '; 154 | if (!isset($oldvotes[$site->id])) { 155 | $properties .= ''; 156 | $properties .= ' '; 157 | } else if ($oldvotes[$site->id] >= 0) { 158 | $properties .= ''; 159 | } else { 160 | $properties .= ''; 161 | } 162 | if ($isadmin && $USER->siteediting) { 163 | if (!empty($countvotes[$site->id])) { 164 | if ($site->cool >= 0) { 165 | $properties .= ' ('; 166 | } else { 167 | $properties .= ' ('; 168 | } 169 | 170 | $url = new moodle_url('/sites/showvotes.php', array('id'=>$site->id)); 171 | 172 | $properties .= $OUTPUT->action_link($url, 'votes', new popup_action('click', $url, 'votes')); 173 | 174 | //$properties .= link_to_popup_window('/sites/showvotes.php?id='.$site->id, 'votes', $countvotes[$site->id].'»'.$site->cool,400,500,'votes','',true); 175 | $properties .= ')'; 176 | } 177 | } 178 | } 179 | 180 | if ($isadmin && $USER->siteediting) { 181 | $properties .= '   '; 182 | $properties .= $OUTPUT->action_icon(new moodle_url('/sites/edit.php', array('edit'=>$site->id, 'sesskey'=>sesskey())), new pix_icon('t/edit', 'edit', null, array('style'=>'height:11px;width:11px;border:0;'))); 183 | $properties .= ' '; 184 | $properties .= $OUTPUT->action_icon(new moodle_url('/sites/edit.php', array('delete'=>$site->id, 'sesskey'=>sesskey())), new pix_icon('t/delete', 'delete', 'moodle', array('style'=>'height:11px;width:11px;border:0;'))); 185 | 186 | //$properties .= '   edit'; 187 | //$properties .= ' delete'; 188 | } 189 | 190 | if ($site->privacy=='linked') { 191 | $list->data[] = "$name$properties"; 192 | } else if ($USER->siteediting===true) { 193 | $list->data[] = "$name$properties"; 194 | } else { 195 | $list->data[] = $name.$properties; 196 | } 197 | } 198 | } 199 | 200 | 201 | $PAGE->navbar->add('Registered sites', new moodle_url('/sites/')); 202 | $PAGE->set_title(get_string('registeredmoodlesites_moodlenet', 'local_hub')); 203 | $PAGE->set_heading(get_string('registeredmoodlesites', 'local_hub')); 204 | $PAGE->set_button(edit_button($isadmin, $country)); 205 | 206 | echo $OUTPUT->header(); 207 | if (isset($message) && $message!==false) { 208 | echo $message; 209 | } 210 | echo html_writer::start_tag('div', array('class'=>'boxwidthwide boxaligncenter', 'style'=>'padding:20px;')); 211 | echo $OUTPUT->heading($PAGE->heading); 212 | 213 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 214 | echo get_string('moodlesiteslistintro', 'local_hub'); 215 | echo html_writer::end_tag('p'); 216 | 217 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 218 | echo html_writer::empty_tag('img', array('src'=>$CFG->wwwroot.'/sites/moodle-registered-sites-20091103-small.jpg', 'class'=>'activesitesimg')); 219 | echo html_writer::end_tag('p'); 220 | 221 | echo html_writer::start_tag('p', array('class'=>'mdl-align')); 222 | echo get_string('moodlesiteslistnumbers', 'local_hub', $totalcountryinfo); 223 | echo html_writer::end_tag('p'); 224 | 225 | echo prepare_country_tag_cloud($countryarray, ($isadmin && $USER->siteediting), 500); 226 | echo html_writer::end_tag('div'); 227 | 228 | if (isset($list)) { 229 | echo html_writer::start_tag('div', array('class'=>'boxwidthwide boxaligncenter', 'style'=>'padding:20px;')); 230 | if ($sitevoting) { 231 | echo '
'; 232 | if (!isloggedin() || isguestuser()) { 233 | echo 'Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To vote on sites you need to be logged in.'; 234 | echo "
"; 235 | } else { 236 | $options = array(); 237 | $options['country'] = $country; 238 | if ($isadmin && $USER->siteediting) { 239 | $options['edit']='on'; 240 | } 241 | if (empty($USER->sitevoting)) { 242 | echo 'Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To see the voting controls, use this button:

'; 243 | $options['voting'] = 1; 244 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Show voting buttons for these sites'); 245 | } else { 246 | $options['voting'] = -1; 247 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Hide voting buttons for these sites'); 248 | } 249 | $OUTPUT->render($button); 250 | } 251 | echo "
"; 252 | } 253 | 254 | print_list($list); 255 | echo "

\"Up

"; 256 | echo html_writer::end_tag('div'); 257 | } 258 | 259 | echo $OUTPUT->footer(); 260 | -------------------------------------------------------------------------------- /admin/managecourses.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Administrator can manage registered course on this page 20 | * Delete, Hide,... 21 | * @package localhub 22 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) 23 | * @author Jerome Mouneyrac 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | require('../../../config.php'); 27 | 28 | require_once($CFG->libdir . '/adminlib.php'); 29 | require_once($CFG->dirroot . '/local/hub/lib.php'); 30 | require_once($CFG->dirroot . "/local/hub/forms.php"); 31 | 32 | admin_externalpage_setup('managecourses'); 33 | 34 | //check that the PHP xmlrpc extension is enabled 35 | if (!extension_loaded('xmlrpc')) { 36 | echo $OUTPUT->header(); 37 | $xmlrpcnotification = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', ''); 38 | $xmlrpcnotification .= get_string('xmlrpcdisabled', 'local_hub'); 39 | echo $OUTPUT->notification($xmlrpcnotification); 40 | echo $OUTPUT->footer(); 41 | die(); 42 | } 43 | 44 | $hub = new local_hub(); 45 | $renderer = $PAGE->get_renderer('local_hub'); 46 | 47 | /// BULK OPERATIONS 48 | $bulkoperation = optional_param('bulkselect', false, PARAM_ALPHANUM); 49 | $confirm = optional_param('confirm', false, PARAM_INTEGER); 50 | if (!empty($bulkoperation) and confirm_sesskey()) { 51 | //retrieve all ids 52 | for ($i = 1; $i <= HUB_COURSE_PER_PAGE; $i = $i + 1) { 53 | $selectedcourseid = optional_param('bulk-' . $i, false, PARAM_INTEGER); 54 | if (!empty($selectedcourseid)) { 55 | $bulkcourses[] = $hub->get_course($selectedcourseid); 56 | } 57 | } 58 | if (!$confirm) { 59 | echo $OUTPUT->header(); 60 | echo $OUTPUT->heading(get_string('managecourses', 'local_hub'), 3, 'main'); 61 | echo $renderer->course_bulk_operation_confirmation($bulkcourses, $bulkoperation); 62 | echo $OUTPUT->footer(); 63 | die(); 64 | } else if ($bulkoperation == 'bulkdelete') { 65 | foreach ($bulkcourses as $bulkcourse) { 66 | $hub->delete_course($bulkcourse->id); 67 | } 68 | } else { 69 | foreach ($bulkcourses as $bulkcourse) { 70 | if ($bulkoperation == 'bulkvisible') { 71 | $bulkcourse->privacy = COURSEVISIBILITY_VISIBLE; 72 | } else if ($bulkoperation == 'bulknotvisible') { 73 | $bulkcourse->privacy = COURSEVISIBILITY_NOTVISIBLE; 74 | } 75 | $hub->update_course($bulkcourse); 76 | } 77 | } 78 | } 79 | 80 | 81 | /// VISIBLE OPERATION 82 | $courseid = optional_param('courseid', null, PARAM_INT); 83 | $visible = optional_param('visible', -1, PARAM_INTEGER); 84 | if ($visible != -1 and confirm_sesskey()) { 85 | $course = $hub->get_course($courseid); 86 | if (!empty($course)) { 87 | $course->privacy = $visible; 88 | $hub->update_course($course); 89 | if (!empty($course->privacy)) { 90 | $notificationstring = get_string('coursevisible', 'local_hub', $course->fullname); 91 | } else { 92 | $notificationstring = get_string('coursenotvisible', 'local_hub', $course->fullname); 93 | } 94 | $notification = $OUTPUT->notification($notificationstring, 'notifysuccess'); 95 | } 96 | } 97 | 98 | $search = optional_param('search', '', PARAM_TEXT); 99 | $options = array(); 100 | $courses = null; 101 | 102 | /// FORM DATA 103 | $fromformdata['coverage'] = optional_param('coverage', 'all', PARAM_TEXT); 104 | $fromformdata['licence'] = optional_param('licence', 'all', PARAM_ALPHANUMEXT); 105 | $fromformdata['subject'] = optional_param('subject', 'all', PARAM_ALPHANUMEXT); 106 | $fromformdata['siteid'] = optional_param('siteid', 'all', PARAM_ALPHANUMEXT); 107 | $fromformdata['lastmodified'] = optional_param('lastmodified', HUB_LASTMODIFIED_WEEK, PARAM_ALPHANUMEXT); 108 | $fromformdata['audience'] = optional_param('audience', 'all', PARAM_ALPHANUMEXT); 109 | $fromformdata['language'] = optional_param('language', 'all', PARAM_ALPHANUMEXT); 110 | $fromformdata['educationallevel'] = optional_param('educationallevel', 'all', PARAM_ALPHANUMEXT); 111 | $fromformdata['visibility'] = optional_param('visibility', COURSEVISIBILITY_NOTVISIBLE, PARAM_ALPHANUMEXT); 112 | $fromformdata['downloadable'] = optional_param('downloadable', 'all', PARAM_ALPHANUM); 113 | $fromformdata['orderby'] = optional_param('orderby', 'newest', PARAM_ALPHA); 114 | $fromformdata['adminform'] = 1; 115 | $fromformdata['search'] = $search; 116 | 117 | $coursesearchform = new course_search_form('', $fromformdata); 118 | $fromform = $coursesearchform->get_data(); 119 | 120 | $coursesearchform->set_data($fromformdata); 121 | $fromform = (object) $fromformdata; 122 | 123 | 124 | /// COURSE DATA 125 | if (!empty($courseid)) { 126 | $options['ids'] = array($courseid); 127 | $options['downloadable'] = true; 128 | $options['enrollable'] = true; 129 | $courses = $hub->get_courses($options); 130 | unset($options['ids']); 131 | unset($options['downloadable']); 132 | unset($options['enrollable']); 133 | $coursetotal = 1; 134 | } else { 135 | if (!empty($fromform->coverage)) { 136 | $options['coverage'] = $fromform->coverage; 137 | } 138 | if ($fromform->licence != 'all') { 139 | $options['licenceshortname'] = $fromform->licence; 140 | } 141 | if ($fromform->subject != 'all') { 142 | $options['subject'] = $fromform->subject; 143 | } 144 | if ($fromform->audience != 'all') { 145 | $options['audience'] = $fromform->audience; 146 | } 147 | if ($fromform->educationallevel != 'all') { 148 | $options['educationallevel'] = $fromform->educationallevel; 149 | } 150 | if ($fromform->language != 'all') { 151 | $options['language'] = $fromform->language; 152 | } 153 | if ($fromform->siteid != 'all') { 154 | $options['siteid'] = $fromform->siteid; 155 | } 156 | if ($fromform->lastmodified != 'all') { 157 | switch ($fromform->lastmodified) { 158 | case HUB_LASTMODIFIED_WEEK: 159 | $lastmodified = strtotime("-7 day"); 160 | break; 161 | case HUB_LASTMODIFIED_FORTEENNIGHT: 162 | $lastmodified = strtotime("-14 day"); 163 | break; 164 | case HUB_LASTMODIFIED_MONTH: 165 | $lastmodified = strtotime("-30 day"); 166 | break; 167 | } 168 | 169 | $options['lastmodified'] = $lastmodified; 170 | } 171 | 172 | $options['visibility'] = $fromform->visibility; 173 | 174 | //sort method 175 | switch ($fromform->orderby) { 176 | case 'newest': 177 | $options['orderby'] = 'timemodified DESC'; 178 | break; 179 | case 'eldest': 180 | $options['orderby'] = 'timemodified ASC'; 181 | break; 182 | case 'publisher': 183 | $options['orderby'] = 'publishername ASC'; 184 | break; 185 | case 'fullname': 186 | $options['orderby'] = 'fullname ASC'; 187 | break; 188 | default: 189 | break; 190 | } 191 | 192 | //get courses 193 | $options['search'] = $search; 194 | $options['onlyvisible'] = false; 195 | if ($fromform->downloadable != 'all') { 196 | $options['downloadable'] = $fromform->downloadable; 197 | $options['enrollable'] = !$fromform->downloadable; 198 | } else { 199 | $options['downloadable'] = 1; 200 | $options['enrollable'] = 1; 201 | } 202 | 203 | $page = optional_param('page', 0, PARAM_INT); 204 | 205 | $courses = $hub->get_courses($options, 206 | $page * HUB_COURSE_PER_PAGE, HUB_COURSE_PER_PAGE); 207 | 208 | $coursetotal = $hub->get_courses($options, 0, 0, true); 209 | 210 | //$options will be reused to call the same url with same GET param, 211 | //need to reinitialize 212 | $options['downloadable'] = $fromform->downloadable; 213 | $options['lastmodified'] = $fromform->lastmodified; 214 | $options['orderby'] = $fromform->orderby; 215 | } 216 | 217 | 218 | //complete course data with site name and course content 219 | $courseids = array(); 220 | $courseimagenumbers = array(); //number of screenshots of all courses (must be exact same order than $courseids) 221 | 222 | if (!empty($courses)) { 223 | foreach ($courses as $tmpcourse) { 224 | $courseids[] = $tmpcourse->id; 225 | } 226 | $courseidslist = implode(',', $courseids); 227 | $sites = $DB->get_records_sql('SELECT site.* FROM {hub_course_directory} course, {hub_site_directory} site WHERE ' 228 | . 'course.id IN (' . $courseidslist . ') AND site.id = course.siteid GROUP BY site.id'); 229 | 230 | foreach ($courses as &$course) { 231 | //get site name for each courses 232 | $course->site = $sites[$course->siteid]; 233 | 234 | //get course content for each course 235 | $contents = $hub->get_course_contents($course->id); 236 | if (!empty($contents)) { 237 | foreach ($contents as $content) { 238 | $course->contents[] = $content; 239 | } 240 | } 241 | 242 | //some information for the YUI imagegallery javascript 243 | $courseimagenumbers[] = $course->screenshots; 244 | } 245 | 246 | //add rating information to the course 247 | require_once($CFG->dirroot . '/rating/lib.php'); 248 | $ratingoptions = new stdclass(); 249 | $ratingoptions->context = context_course::instance(SITEID); //front page course 250 | $ratingoptions->items = $courses; 251 | $ratingoptions->aggregate = RATING_AGGREGATE_COUNT; //the aggregation method 252 | $ratingoptions->scaleid = 0 - get_config('local_hub', 'courseratingscaleid'); //rating API is expecting "minus scaleid" 253 | $ratingoptions->userid = $USER->id; 254 | $ratingoptions->returnurl = $CFG->wwwroot . "/local/hub/admin/managecourses.php"; 255 | $ratingoptions->component = 'local_hub'; 256 | $ratingoptions->ratingarea = 'featured'; 257 | $rm = new rating_manager(); 258 | $courses = $rm->get_ratings($ratingoptions); //this function return $ratingoptions->items with information about the ratings 259 | 260 | //load javascript for YUI imagegallery javascript screenshot 261 | $PAGE->requires->yui_module('moodle-block_community-imagegallery', 262 | 'M.blocks_community.init_imagegallery', 263 | array(array('imageids' => $courseids, 264 | 'imagenumbers' => $courseimagenumbers, 265 | 'huburl' => $CFG->wwwroot))); 266 | } 267 | 268 | //display header 269 | echo $OUTPUT->header(); 270 | 271 | //display a message if we come back from site settings page 272 | $updatecourse = optional_param('coursesettings', '', PARAM_TEXT); 273 | if (!empty($updatecourse) and confirm_sesskey()) { 274 | echo $OUTPUT->notification(get_string('coursesettingsupdated', 'local_hub', $updatecourse), 275 | 'notifysuccess'); 276 | } 277 | 278 | //display some notification 279 | if (!empty($notification)) { 280 | echo $notification; 281 | } 282 | 283 | //display heading title 284 | echo $OUTPUT->heading(get_string('managecourses', 'local_hub'), 3, 'main'); 285 | 286 | //display course search form 287 | $coursesearchform->display(); 288 | 289 | if (isset($courses) and empty($courseid)) { 290 | if (empty($coursetotal)) { 291 | $coursetotalhtml = get_string('nocourse', 'local_hub'); 292 | } else { 293 | $coursetotalhtml = get_string('coursetotal', 'local_hub', $coursetotal); 294 | } 295 | echo html_writer::tag('div', $coursetotalhtml, array('class' => 'hubcoursetotal')); 296 | } 297 | 298 | //display the top paging bar 299 | if ($coursetotal > HUB_COURSE_PER_PAGE) { 300 | $baseurl = new moodle_url('', $options); 301 | $pagingbarhtml = $OUTPUT->paging_bar($coursetotal, $page, HUB_COURSE_PER_PAGE, $baseurl); 302 | $pagingbarhtml = html_writer::tag('div', $pagingbarhtml, array('class' => 'pagingbar')); 303 | echo $pagingbarhtml; 304 | } 305 | 306 | //display course result list 307 | echo $renderer->course_list($courses, true, $options); 308 | 309 | //display the bottom paging bar 310 | if (!empty($pagingbarhtml)) { 311 | echo $pagingbarhtml; 312 | } 313 | 314 | $PAGE->requires->string_for_js('nocourseselected', 'local_hub'); 315 | $PAGE->requires->yui_module('moodle-local_hub-courses', 'M.local_hub.init_hubcourses', 316 | array(array('scriptname' => 'local/hub/admin/managecourses.php'))); 317 | 318 | //display footer 319 | echo $OUTPUT->footer(); -------------------------------------------------------------------------------- /top/sites/index_norecordset.php: -------------------------------------------------------------------------------- 1 | dirroot.'/local/hub/top/sites/siteslib.php'); 5 | 6 | $country = optional_param('country', '', PARAM_ALPHA); 7 | $cool = optional_param('cool', 0, PARAM_INT); 8 | $uncool = optional_param('uncool', 0, PARAM_INT); 9 | $sitevoting = optional_param('voting', 0, PARAM_INT); 10 | $edit = optional_param('edit', '', PARAM_ALPHA); 11 | 12 | $isadmin = ismoodlesiteadmin(); 13 | 14 | $USER->siteediting = ($isadmin && $edit == "on"); 15 | 16 | /// Try to get the country, from USER, IP or request 17 | $usercountry = ""; 18 | if (!empty($USER->country)) { 19 | $usercountry = $USER->country; 20 | } else { 21 | $ip = $_SERVER['REMOTE_ADDR']; 22 | if ($countryinfo = $DB->get_record_sql("SELECT * FROM {countries} WHERE ipfrom <= inet_aton('$ip') AND inet_aton('$ip') <= ipto ")) { 23 | $usercountry = $countryinfo->code2; 24 | } 25 | } 26 | 27 | if (empty($country) and $usercountry) { 28 | $country = $usercountry; 29 | } 30 | 31 | $hide_all_links = false; 32 | $mostrecent = 0; 33 | $strresources = get_string("modulenameplural", "resource"); 34 | 35 | $PAGE->set_context(context_system::instance()); 36 | $PAGE->set_url(new moodle_url('/sites/index_norecordset.php')); 37 | $PAGE->set_title('Moodle: Moodle sites'); 38 | $PAGE->set_heading('Moodle sites'); 39 | $PAGE->set_button(edit_button($isadmin, $country)); 40 | $PAGE->navbar->add($strresources.' '.$PAGE->heading, new moodle_url('/mod/resource/index.php', array('id'=>SITEID))); 41 | 42 | echo $OUTPUT->header(); 43 | 44 | /// Process cool / uncool 45 | if ($cool or $uncool) { 46 | if (isloggedin() and confirm_sesskey()) { 47 | if ($site = $DB->get_record('registry', array('id'=>$cool+$uncool))) { // site exists 48 | $country = $site->country; 49 | if ($DB->record_exists('hub_site_directory_votes', array('userid'=>$USER->id, 'siteid'=>$site->id))) { 50 | echo $OUTPUT->notification(get_string('erroralreadyvoted', 'local_hub', s($site->sitename))); 51 | } else { 52 | if ($cool) { 53 | $site->cool = $site->cool + 1; 54 | } else if ($uncool) { 55 | $site->cool = $site->cool - 1; 56 | } 57 | $coolsite = new stdClass; 58 | $coolsite->id = $site->id; 59 | $coolsite->cool = $site->cool; 60 | $coolsite->cooldate = time(); 61 | $DB->update_record('registry', $coolsite); 62 | 63 | $vote = new stdClass; 64 | $vote->userid = $USER->id; 65 | $vote->siteid = $site->id; 66 | $vote->vote = $cool ? 1 : -1; 67 | $vote->timevoted = time(); 68 | $DB->insert_record('registry_votes', $vote); 69 | 70 | if ($cool) { 71 | echo $OUTPUT->notification('Your positive feeling for "'.s($site->sitename).'" has been recorded', 'notifysuccess'); 72 | } else { 73 | echo $OUTPUT->notification('Your negative feeling against "'.s($site->sitename).'" has been recorded', 'notifysuccess'); 74 | } 75 | } 76 | } 77 | } 78 | } 79 | 80 | echo ""; 81 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter boxwidthwide', 'style'=>'padding:20px;')); 82 | 83 | echo "

Moodle Sites

\n"; 84 | 85 | echo "

Some of the growing community of Moodle users are listed below.

"; 86 | echo "

To add or update your site, just use the \"Registration\" button on your Moodle admin page.

"; 87 | echo "

(Note: sites that are unreachable or obviously just for testing are not accepted)

"; 88 | 89 | echo "

"; 90 | 91 | 92 | /// Sort the sites 93 | 94 | $countries = get_string_manager()->get_list_of_countries(); 95 | foreach ($countries as $code => $fullname) { 96 | $list[$code]->name = $fullname; 97 | $list[$code]->count = 0; 98 | } 99 | 100 | $counthidden = 0; 101 | 102 | $usedcountry = array(); 103 | 104 | $sites = $DB->get_records_select('hub_site_directory', '', null, 'sitename', 'id, country, sitename, public, url, timecreated, timeupdated, lang, cool'); 105 | foreach ($sites as $key => $site) { 106 | if (empty($list[$site->country]->name)) { /// Unknown country 107 | $list[$site->country]->name = $site->country; 108 | } 109 | if (!isset($list[$site->country]->count)) { 110 | $list[$site->country]->count = 0; 111 | } 112 | $list[$site->country]->count++; 113 | $usedcountry[$site->country] = true; 114 | if ($site->public > 0 or !empty($USER->siteediting)) { 115 | $list[$site->country]->sites[$site->url] = $site; 116 | } 117 | if ($site->timeupdated > $mostrecent) { 118 | $mostrecent = $site->timeupdated; 119 | } 120 | if (!$site->public) { 121 | $counthidden++; 122 | } 123 | } 124 | 125 | echo "

Currently there are ".$DB->count_records("hub_site_directory")." sites from ".count($usedcountry)." countries who have registered.
"; 126 | 127 | echo "$counthidden of these have requested privacy and are not shown in the lists below.

"; 128 | 129 | if ($hide_all_links) { 130 | echo "

(Links have been temporarily switched off)

"; 131 | } 132 | 133 | echo "

"; 134 | $startlist = true; 135 | foreach ($list as $code => $acountry) { 136 | if ($acountry->count) { 137 | if ($startlist) { 138 | $startlist = false; 139 | } else { 140 | echo " | "; 141 | } 142 | if ($code == $usercountry) { 143 | echo "$acountry->name "; 144 | } else { 145 | echo "$acountry->name "; 146 | } 147 | } 148 | } 149 | echo "| SHOW ALL"; 150 | echo "

"; 151 | 152 | echo html_writer::end_tag('div'); 153 | echo "
"; 154 | 155 | 156 | 157 | if ($sitevoting) { 158 | if ($sitevoting == 1) { 159 | $USER->sitevoting = true; 160 | } else { 161 | $USER->sitevoting = false; 162 | } 163 | } 164 | 165 | echo '
'; 166 | if (!isloggedin() || isguestuser()) { 167 | echo '
Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To vote on sites you need to be logged in.
'; 168 | echo "
"; 169 | if (isguestuser()) { 170 | unset($USER->sitevoting); 171 | } 172 | } else { 173 | if (empty($USER->sitevoting)) { 174 | echo '
Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To see the voting controls, use this button:
'; 175 | $options = array('voting'=>1); 176 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Show voting buttons for these sites'); 177 | } else { 178 | $options = array('voting'=>-1); 179 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Hide voting buttons for these sites'); 180 | } 181 | echo $OUTPUT->single_button($button); 182 | echo '
'; 183 | } 184 | echo '
'; 185 | 186 | $timenow = time(); 187 | 188 | if (!empty($country)) { 189 | 190 | if (($country != 'all' and isset($list[$country]))) { 191 | $newlist[$country] = $list[$country]; 192 | $list = $newlist; 193 | 194 | // Get old voting records 195 | if (!empty($USER->sitevoting)) { 196 | $oldvotes = $DB->get_records_menu('registry_votes', array('userid'=>$USER->id), '', 'siteid, vote'); 197 | $countvotes = $DB->get_records_select_menu('registry_votes', 'siteid > 0 GROUP BY siteid', null, '', 'siteid, COUNT(*) number'); 198 | } 199 | } 200 | 201 | foreach ($list as $code => $country) { 202 | if ($country->count) { 203 | if ($country->count == 1) { 204 | $strsite = "$country->count site"; 205 | } else { 206 | $strsite = "$country->count sites"; 207 | } 208 | 209 | if (!empty($country->sites)) { 210 | $countsites = count($country->sites); 211 | } else { 212 | $countsites = 0; 213 | } 214 | if ($countsites < $country->count) { 215 | $countsites = $country->count - $countsites; 216 | $strsite .= " ($countsites not shown here)"; 217 | } 218 | 219 | echo ""; 220 | echo ""; 221 | echo ""; 222 | echo "
$country->name$strsite
\n"; 223 | if (!empty($country->sites)) { 224 | echo "
    \n"; 225 | #uksort($country->sites, 'strnatcasecmp'); 226 | foreach ($country->sites as $site) { 227 | if (empty($site->lang)) { 228 | echo '
  • '; 229 | } else { 230 | $site->lang = str_replace('_', '-', $site->lang); 231 | echo '
  • '; 232 | } 233 | if (trim($site->sitename) == '') { 234 | $site->sitename = $site->url; 235 | } 236 | if ($site->cool >= MAXVOTES) { 237 | echo ''; 238 | } 239 | if ($USER->siteediting) { 240 | if ($site->public ==2) { 241 | $class = ''; 242 | } else { 243 | $class = 'class=dimmed'; 244 | } 245 | echo ''.$site->sitename.''; 246 | } else if ($site->public == 1 or ! $site->url or $hide_all_links ) { 247 | echo $site->sitename; 248 | } else if ($site->public == 2) { 249 | echo ''.$site->sitename.''; 250 | } 251 | if ($site->timecreated) { 252 | if ($timenow - $site->timecreated < 609600) { // two weeks 253 | echo ' (new)'; 254 | } 255 | } 256 | if ($site->cool <= - MAXVOTES) { 257 | echo ''; 258 | echo ' Uncool!'; 259 | } else if ($site->cool >= MAXVOTES) { 260 | echo ''; 261 | echo ' Cool!'; 262 | } 263 | 264 | if ($isadmin and $USER->siteediting) { 265 | echo '   edit'; 266 | echo ' delete'; 267 | } 268 | 269 | if (!empty($USER->sitevoting) && $site->public) { 270 | echo '   '; 271 | if (!isset($oldvotes[$site->id])) { 272 | echo ''; 273 | echo ' '; 274 | } else if ($oldvotes[$site->id] >= 0) { 275 | echo ''; 276 | 277 | } else { 278 | echo ''; 279 | } 280 | if ($isadmin and $USER->siteediting) { 281 | if (!empty($countvotes[$site->id])) { 282 | if ($site->cool >= 0) { 283 | $class = 'highlight'; 284 | } else { 285 | $class = 'highlightbad'; 286 | } 287 | echo ' ('; 288 | link_to_popup_window('/sites/showvotes.php?id='.$site->id, 'votes', $countvotes[$site->id].'»'.$site->cool); 289 | echo ')'; 290 | } 291 | } 292 | } 293 | echo "
  • \n"; 294 | } 295 | echo "
\n"; 296 | } else { 297 | echo "
  • None of the registered sites have been made public
"; 298 | } 299 | echo "

\"Up

"; 300 | echo "

\n"; 301 | } 302 | } 303 | } 304 | 305 | echo "
"; 306 | 307 | echo "

Page last updated: "; 308 | echo userdate($mostrecent); 309 | echo "

"; 310 | 311 | echo $OUTPUT->footer(); 312 | -------------------------------------------------------------------------------- /top/sites/index_norestrictbycountry.php: -------------------------------------------------------------------------------- 1 | siteediting = ($isadmin && $edit == "on"); 16 | 17 | /// Try to get the country, from USER, IP or request 18 | $usercountry = ""; 19 | if (!empty($USER->country)) { 20 | $usercountry = $USER->country; 21 | } else { 22 | $ip = $_SERVER['REMOTE_ADDR']; 23 | if ($countryinfo = $DB->get_record_sql("SELECT * FROM {countries} WHERE ipfrom <= inet_aton('$ip') AND inet_aton('$ip') <= ipto ")) { 24 | $usercountry = $countryinfo->code2; 25 | } 26 | } 27 | 28 | if (empty($country) and $usercountry) { 29 | $country = $usercountry; 30 | } 31 | 32 | $hide_all_links = false; 33 | $mostrecent = 0; 34 | $strresources = get_string("modulenameplural", "resource"); 35 | 36 | $PAGE->set_context(context_system::instance()); 37 | $PAGE->set_url(new moodle_url('/sites/index_norecordset.php')); 38 | $PAGE->set_title('Moodle: Moodle sites'); 39 | $PAGE->set_heading('Moodle sites'); 40 | $PAGE->set_button(edit_button($isadmin, $country)); 41 | $PAGE->navbar->add($strresources.' '.$PAGE->heading, new moodle_url('/mod/resource/index.php', array('id'=>SITEID))); 42 | 43 | echo $OUTPUT->header(); 44 | 45 | /// Process cool / uncool 46 | if ($cool or $uncool) { 47 | if (isloggedin() and confirm_sesskey()) { 48 | if ($site = $DB->get_record('hub_site_directory', array('id'=>$cool+$uncool))) { // site exists 49 | $country = $site->country; 50 | if ($DB->record_exists('registry_votes', array('userid'=>$USER->id, 'siteid'=>$site->id))) { 51 | echo $OUTPUT->notification(get_string('erroralreadyvoted', 'local_hub', s($site->sitename))); 52 | } else { 53 | if ($cool) { 54 | $site->cool = $site->cool + 1; 55 | } else if ($uncool) { 56 | $site->cool = $site->cool - 1; 57 | } 58 | $coolsite = new stdClass; 59 | $coolsite->id = $site->id; 60 | $coolsite->cool = $site->cool; 61 | $coolsite->cooldate = time(); 62 | $DB->update_record('hub_site_directory', $coolsite); 63 | 64 | $vote = new stdClass; 65 | $vote->userid = $USER->id; 66 | $vote->siteid = $site->id; 67 | $vote->vote = $cool ? 1 : -1; 68 | $vote->timevoted = time(); 69 | $DB->insert_record('registry_votes', $vote); 70 | 71 | if ($cool) { 72 | echo $OUTPUT->notification('Your positive feeling for "'.s($site->sitename).'" has been recorded', 'notifysuccess'); 73 | } else { 74 | echo $OUTPUT->notification('Your negative feeling against "'.s($site->sitename).'" has been recorded', 'notifysuccess'); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | 81 | echo ""; 82 | echo html_writer::start_tag('div', array('class'=>'boxaligncenter boxwidthwide', 'style'=>'padding:20px;')); 83 | 84 | echo "

Moodle Sites

\n"; 85 | 86 | echo "

Some of the growing community of Moodle users are listed below.

"; 87 | echo "

To add or update your site, just use the \"Registration\" button on your Moodle admin page.

"; 88 | echo "

(Note: sites that are unreachable or obviously just for testing are not accepted)

"; 89 | 90 | echo "

"; 91 | 92 | 93 | /// Sort the sites 94 | 95 | $countries = get_string_manager()->get_list_of_countries(); 96 | foreach ($countries as $code => $fullname) { 97 | $list[$code]->name = $fullname; 98 | $list[$code]->count = 0; 99 | } 100 | 101 | $counthidden = 0; 102 | $usedcountry = array(); 103 | 104 | 105 | $sitesrs = $DB->get_recordset_select('hub_site_directory', '', null, 'sitename', "id, country, sitename, public, url, timecreated, timeupdated, lang, cool"); 106 | foreach ($sitesrs as $site) { 107 | if (empty($list[$site->country]->name)) { /// Unknown country 108 | $list[$site->country]->name = $site->country; 109 | } 110 | if (!isset($list[$site->country]->count)) { 111 | $list[$site->country]->count = 0; 112 | } 113 | $list[$site->country]->count++; 114 | $usedcountry[$site->country] = true; 115 | if ($site->public > 0 or !empty($USER->siteediting)) { 116 | $list[$site->country]->sites[$site->url] = $site; 117 | } 118 | if ($site->timeupdated > $mostrecent) { 119 | $mostrecent = $site->timeupdated; 120 | } 121 | if (!$site->public) { 122 | $counthidden++; 123 | } 124 | } 125 | $sitesrs->close(); 126 | 127 | echo "

Currently there are ".$DB->count_records("hub_site_directory")." sites from ".count($usedcountry)." countries who have registered.
"; 128 | 129 | echo "$counthidden of these have requested privacy and are not shown in the lists below.

"; 130 | 131 | if ($hide_all_links) { 132 | echo "

(Links have been temporarily switched off)

"; 133 | } 134 | 135 | echo "

"; 136 | $startlist = true; 137 | foreach ($list as $code => $acountry) { 138 | if ($acountry->count) { 139 | if ($startlist) { 140 | $startlist = false; 141 | } else { 142 | echo " | "; 143 | } 144 | if ($code == $usercountry) { 145 | echo "$acountry->name "; 146 | } else { 147 | echo "$acountry->name "; 148 | } 149 | } 150 | } 151 | echo "| SHOW ALL"; 152 | echo "

"; 153 | 154 | echo htnl_writer::end_tag('div'); 155 | echo "
"; 156 | 157 | 158 | 159 | if ($sitevoting) { 160 | if ($sitevoting == 1) { 161 | $USER->sitevoting = true; 162 | } else { 163 | $USER->sitevoting = false; 164 | } 165 | } 166 | 167 | echo '
'; 168 | if (!isloggedin() || isguestuser()) { 169 | echo '
Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To vote on sites you need to be logged in.
'; 170 | echo "
"; 171 | if (isguestuser()) { 172 | unset($USER->sitevoting); 173 | } 174 | } else { 175 | if (empty($USER->sitevoting)) { 176 | echo '
Sites can be marked "Cool" if three or more people vote for them. Cool sites are promoted around moodle.org and other places. To see the voting controls, use this button:
'; 177 | $options = array('voting'=>1); 178 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Show voting buttons for these sites'); 179 | } else { 180 | $options = array('voting'=>-1); 181 | $button = new single_button(new moodle_url('/sites/index.php', $options), 'Hide voting buttons for these sites'); 182 | } 183 | echo $OUTPUT->single_button($button); 184 | echo '
'; 185 | } 186 | echo '
'; 187 | 188 | $timenow = time(); 189 | 190 | if (!empty($country)) { 191 | 192 | if (($country != 'all' and isset($list[$country]))) { 193 | $newlist[$country] = $list[$country]; 194 | $list = $newlist; 195 | 196 | // Get old voting records 197 | if (!empty($USER->sitevoting)) { 198 | $oldvotes = $DB->get_records_menu('registry_votes', array('userid'=>$USER->id), '', 'siteid, vote'); 199 | $countvotes = $DB->get_records_select_menu('registry_votes', 'siteid > 0 GROUP BY siteid', null, '', 'siteid, COUNT(*) number'); 200 | } 201 | } 202 | 203 | foreach ($list as $code => $country) { 204 | if ($country->count) { 205 | if ($country->count == 1) { 206 | $strsite = "$country->count site"; 207 | } else { 208 | $strsite = "$country->count sites"; 209 | } 210 | 211 | if (!empty($country->sites)) { 212 | $countsites = count($country->sites); 213 | } else { 214 | $countsites = 0; 215 | } 216 | if ($countsites < $country->count) { 217 | $countsites = $country->count - $countsites; 218 | $strsite .= " ($countsites not shown here)"; 219 | } 220 | 221 | echo ""; 222 | echo ""; 223 | echo ""; 224 | echo "
$country->name$strsite
\n"; 225 | if (!empty($country->sites)) { 226 | echo "
    \n"; 227 | #uksort($country->sites, 'strnatcasecmp'); 228 | foreach ($country->sites as $site) { 229 | if (empty($site->lang)) { 230 | echo '
  • '; 231 | } else { 232 | $site->lang = str_replace('_', '-', $site->lang); 233 | echo '
  • '; 234 | } 235 | if (trim($site->sitename) == '') { 236 | $site->sitename = $site->url; 237 | } 238 | if ($site->cool >= MAXVOTES) { 239 | echo ''; 240 | } 241 | if ($USER->siteediting) { 242 | if ($site->public ==2) { 243 | $class = ''; 244 | } else { 245 | $class = 'class=dimmed'; 246 | } 247 | echo ''.$site->sitename.''; 248 | } else if ($site->public == 1 or ! $site->url or $hide_all_links ) { 249 | echo $site->sitename; 250 | } else if ($site->public == 2) { 251 | echo ''.$site->sitename.''; 252 | } 253 | if ($site->timecreated) { 254 | if ($timenow - $site->timecreated < 609600) { // two weeks 255 | echo ' (new)'; 256 | } 257 | } 258 | if ($site->cool <= - MAXVOTES) { 259 | echo ''; 260 | echo ' Uncool!'; 261 | } else if ($site->cool >= MAXVOTES) { 262 | echo ''; 263 | echo ' Cool!'; 264 | } 265 | 266 | if ($isadmin and $USER->siteediting) { 267 | echo '   edit'; 268 | echo ' delete'; 269 | } 270 | 271 | if (!empty($USER->sitevoting) && $site->public) { 272 | echo '   '; 273 | if (!isset($oldvotes[$site->id])) { 274 | echo ''; 275 | echo ' '; 276 | } else if ($oldvotes[$site->id] >= 0) { 277 | echo ''; 278 | 279 | } else { 280 | echo ''; 281 | } 282 | if ($isadmin and $USER->siteediting) { 283 | if (!empty($countvotes[$site->id])) { 284 | if ($site->cool >= 0) { 285 | $class = 'highlight'; 286 | } else { 287 | $class = 'highlightbad'; 288 | } 289 | echo ' ('; 290 | link_to_popup_window('/sites/showvotes.php?id='.$site->id, 'votes', $countvotes[$site->id].'»'.$site->cool); 291 | echo ')'; 292 | } 293 | } 294 | } 295 | echo "
  • \n"; 296 | } 297 | echo "
\n"; 298 | } else { 299 | echo "
  • None of the registered sites have been made public
"; 300 | } 301 | echo "

\"Up

"; 302 | echo "

\n"; 303 | } 304 | } 305 | } 306 | 307 | echo "
"; 308 | 309 | echo "

Page last updated: "; 310 | echo userdate($mostrecent); 311 | echo "

"; 312 | 313 | 314 | echo "
"; 315 | 316 | echo $OUTPUT->footer(); 317 | -------------------------------------------------------------------------------- /tests/lib_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Unit tests for hub 19 | * 20 | * @package local_hub 21 | * @copyright 2014 Dan Poltawski 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | require_once(__DIR__ . '/../lib.php'); 28 | 29 | class local_hub_lib_testcase extends advanced_testcase 30 | { 31 | 32 | public function test_is_remote_site_valid() { 33 | $hub = new local_hub(); 34 | 35 | // TODO: move to: https://github.com/moodlehq/moodle-exttests 36 | $invalidsites = array( 37 | 'http://localhost', 38 | 'http://127.0.0.1', 39 | 'https://download.moodle.org/does-not-exist', 40 | ); 41 | 42 | foreach ($invalidsites as $site) { 43 | $this->assertFalse($hub->is_remote_site_valid($site), "$site reported valid"); 44 | } 45 | 46 | $validsites = array( 47 | 'http://download.moodle.org', // NOTE the http redirect. 48 | 'http://learn.moodle.net', // More tests. 49 | 'https://learn.gold.ac.uk', // Normal site dan worked with. 50 | 'http://devmooc.net/', // Problem site MDLSITE-3433. 51 | 'http://englishwat.com/qvilearn/', // Problem site which doesn't like header requests MDLSITE-3920. 52 | ); 53 | 54 | foreach ($validsites as $site) { 55 | $this->assertTrue($hub->is_remote_site_valid($site), "$site reported invalid"); 56 | } 57 | 58 | } 59 | 60 | public function test_check_secret_validity() { 61 | global $DB; 62 | 63 | $this->resetAfterTest(true); 64 | $hub = new local_hub(); 65 | 66 | $token = 'this is my token'; 67 | $md5 = md5($token); 68 | $this->assertTrue($hub->check_secret_validity($md5)); 69 | 70 | // Mark it stolen. 71 | $stolensecret = new stdClass(); 72 | $stolensecret->secret = $md5; 73 | $stolensecret->siteurl = 'http://example.com'; 74 | $stolensecret->blockeddate = time(); 75 | $DB->insert_record('hub_stolen_site_secrets', $stolensecret); 76 | 77 | $this->assertFalse($hub->check_secret_validity($md5)); 78 | } 79 | 80 | public function test_create_hub_token() { 81 | $this->resetAfterTest(true); 82 | 83 | $hub = new local_hub(); 84 | $url = 'http://example.com'; 85 | 86 | // These capabilities and the arguments to create_hub_token() are modeled 87 | // on the call in register_site() in lib.php. 88 | 89 | $capabilities = array('local/hub:updateinfo', 'local/hub:registercourse', 90 | 'local/hub:view', 'local/hub:unregistercourse', 'local/hub:viewsmallinfo'); 91 | 92 | $tokenusedbysite = $hub->create_hub_token('Registered Hub User', 93 | 'Registered site', 94 | $url . '_registered_site_user', 95 | $capabilities); 96 | 97 | // If it already exists, the existing token should be found. 98 | $foundtoken = $hub->create_hub_token('Registered Hub User', 99 | 'Registered site', 100 | $url . '_registered_site_user', 101 | $capabilities); 102 | $this->assertEquals($foundtoken->id, $tokenusedbysite->id); 103 | } 104 | 105 | public function test_register_site() { 106 | global $DB; 107 | $this->resetAfterTest(true); 108 | 109 | $hub = new local_hub(); 110 | $originalurl = 'http://example.com'; 111 | $changedurl = 'http://example2.com'; 112 | 113 | $sitevalues = $this->get_sitevalues($originalurl); 114 | 115 | // Missing language code. 116 | $sitevalues['language'] = ''; 117 | try { 118 | $token = $hub->register_site($sitevalues); 119 | $this->fail('Exception expected due to invalid language code.'); 120 | } catch (moodle_exception $e) { 121 | $this->assertEquals('errorlangnotrecognized', $e->errorcode); 122 | } 123 | 124 | // Should succeed. 125 | $sitevalues['language'] = 'en'; 126 | $token = $hub->register_site($sitevalues); 127 | $siterecord = $DB->get_record('hub_site_directory', array('name' => $sitevalues['name']), '*', MUST_EXIST); 128 | $this->assertEquals($siterecord->url, $originalurl); 129 | 130 | $this->check_tokens($hub, $sitevalues['url']); 131 | 132 | // Trying to register the same site a second time should fail. 133 | try { 134 | $hub->register_site($sitevalues); 135 | $this->fail('Exception expected due to duplicate secret/token.'); 136 | } catch (moodle_exception $e) { 137 | $this->assertEquals('sitesecretalreadyexist', $e->errorcode); 138 | } 139 | 140 | // Re-registering with a different URL. 141 | $sitevalues['url'] = $changedurl; 142 | $tokenupdated = $hub->register_site($sitevalues, $originalurl); 143 | $this->assertEquals($token, $tokenupdated); // Token should remain unchanged. 144 | $siterecord = $DB->get_record('hub_site_directory', array('name' => $sitevalues['name']), '*', MUST_EXIST); 145 | $this->assertEquals($siterecord->url, $changedurl); 146 | } 147 | 148 | public function test_unregister_site() { 149 | global $DB; 150 | $this->resetAfterTest(true); 151 | 152 | $hub = new local_hub(); 153 | $url = "http://example.com"; 154 | $sitevalues = $this->get_sitevalues($url); 155 | 156 | // Not sure why this behaviour is important but unregister_site() specificaly supports it. 157 | $hub->unregister_site(null); 158 | 159 | $token = $hub->register_site($sitevalues); 160 | 161 | $this->check_tokens($hub, $sitevalues['url']); 162 | 163 | $site = $hub->get_site_by_url($url); 164 | $hub->unregister_site($site); 165 | $this->assertEquals($site->deleted, 1); 166 | // Note that lib.php unregister_site() does not do anything but mark the site as deleted. 167 | // Deleting tokens is done by externallib.php local_hub_external::unregister_site() and lib.php delete_site(). 168 | // Should externallib.php unregister_site() be calling lib.php delete_site() instead of lib.php unregister_site()? 169 | } 170 | 171 | public function test_get_site_by_url() { 172 | global $DB; 173 | $this->resetAfterTest(true); 174 | 175 | $hub = new local_hub(); 176 | $url = "http://example.com"; 177 | $sitevalues = $this->get_sitevalues($url); 178 | 179 | $token = $hub->register_site($sitevalues); 180 | 181 | $this->check_tokens($hub, $sitevalues['url']); 182 | 183 | // Try (and fail) to find a deleted site. 184 | $site = $hub->get_site_by_url($url, 1); 185 | $this->assertTrue($site == null); 186 | 187 | // Find a not deleted site. 188 | $site = $hub->get_site_by_url($url, 0); 189 | $this->assertTrue($site != null); 190 | // Should work the same with the default second parameter. 191 | $site = $hub->get_site_by_url($url); 192 | $this->assertTrue($site != null); 193 | // Find the not deleted site regardless of deletion status. 194 | $site = $hub->get_site_by_url($url, null); 195 | $this->assertTrue($site != null); 196 | 197 | // Delete the site. 198 | $hub->unregister_site($site); 199 | 200 | // Finding the deleted site should not happen without providing 1 as the second param. 201 | $site = $hub->get_site_by_url($url, 0); 202 | $this->assertTrue($site == null); 203 | $site = $hub->get_site_by_url($url); 204 | $this->assertTrue($site == null); 205 | 206 | // Explicitly request a deleted site. 207 | $site = $hub->get_site_by_url($url, 1); 208 | $this->assertTrue($site != null); 209 | 210 | // Find the deleted site regardless of deletion status. 211 | $site = $hub->get_site_by_url($url, null); 212 | $this->assertTrue($site != null); 213 | } 214 | 215 | public function test_get_sites() { 216 | global $DB; 217 | $this->resetAfterTest(true); 218 | set_config('noemailever', 1); 219 | 220 | $hub = new local_hub(); 221 | $url = "http://example.com"; 222 | $sitevalues = $this->get_sitevalues($url); 223 | 224 | $token = $hub->register_site($sitevalues); 225 | $this->check_tokens($hub, $sitevalues['url']); 226 | 227 | $sites = $hub->get_sites(array('urls' => array($url, 'http://doesntexist.com'))); 228 | $this->assertTrue(count($sites) == 1); 229 | 230 | $sites = $hub->get_sites(array('contactemail' => $sitevalues['contactemail'])); 231 | $this->assertTrue(count($sites) == 1); 232 | 233 | $sites = $hub->get_sites(array('contactemail' => 'doesntexist' . $sitevalues['contactemail'])); 234 | $this->assertTrue(count($sites) == 0); 235 | } 236 | 237 | public function test_add_site() { 238 | global $DB; 239 | $this->resetAfterTest(true); 240 | 241 | $hub = new local_hub(); 242 | $url = "http://example.com"; 243 | $sitevalues = $this->get_sitevalues($url); 244 | 245 | $token = $hub->register_site($sitevalues); 246 | 247 | $this->check_tokens($hub, $sitevalues['url']); 248 | 249 | // Delete the site then re-add and check the deleted site is found. 250 | $site = $hub->get_site_by_url($url); 251 | $hub->delete_site($site->id); 252 | 253 | $oldid = $site->id; 254 | $site = $hub->add_site($site); 255 | $this->assertEquals($site->id, $oldid); 256 | 257 | // Attempt to re-add a not deleted site and check that the old one is found. 258 | $site = $hub->add_site($site); 259 | $this->assertEquals($site->id, $oldid); 260 | } 261 | 262 | public function test_delete_site() { 263 | global $DB; 264 | $this->resetAfterTest(true); 265 | 266 | $hub = new local_hub(); 267 | $url = "http://example.com"; 268 | $sitevalues = $this->get_sitevalues($url); 269 | 270 | $token = $hub->register_site($sitevalues); 271 | 272 | $this->check_tokens($hub, $sitevalues['url']); 273 | 274 | $site = $hub->get_site_by_url($url); 275 | $hub->delete_site($site->id); 276 | 277 | $site = $hub->get_site($site->id); // Should we be able to retrieve deleted sites like this? 278 | $this->assertEquals($site->deleted, 1); 279 | 280 | // Verify the tokens are either deleted or marked as deleted. 281 | $username = $url . '_registered_site_user'; 282 | $user = $DB->get_record('user', array('username' => $username, 'idnumber' => $username)); 283 | $service = $DB->get_record('external_services', array('name' => 'Registered site')); 284 | 285 | $this->assertEquals($this->get_external_token($user, $service), null); 286 | $this->assertEquals($hub->get_communication(WSSERVER, REGISTEREDSITE, $sitevalues['url']), null); 287 | } 288 | 289 | public function test_add_communication() { 290 | global $DB; 291 | $this->resetAfterTest(true); 292 | 293 | $hub = new local_hub(); 294 | 295 | $sitetohubcommunication = new stdClass(); 296 | $sitetohubcommunication->token = '123456'; 297 | $sitetohubcommunication->type = WSSERVER; 298 | $sitetohubcommunication->remoteentity = REGISTEREDSITE; 299 | $sitetohubcommunication->remotename = 'test site'; 300 | $sitetohubcommunication->remoteurl = 'http://example.com'; 301 | $sitetohubcommunication->confirmed = 1; 302 | $sitetohubcommunication->id = $hub->add_communication($sitetohubcommunication); 303 | $this->assertTrue($sitetohubcommunication->id > 0); 304 | 305 | // Deleting a communication just toggles a deleted flage. 306 | // Adding another communication with the same details 307 | // should result in the ID of the new and old communication matching. 308 | $originalID = $sitetohubcommunication->id; 309 | $hub->delete_communication($sitetohubcommunication); 310 | $newID = $hub->add_communication($sitetohubcommunication); 311 | $this->assertTrue($originalID == $newID); 312 | } 313 | 314 | private function get_sitevalues($url) { 315 | $sitevalues = array( 316 | 'name' => 'test site', 317 | 'url' => $url, 318 | 'token' => '', 319 | 'secret' => '', 320 | 'description' => 'this is a test site', 321 | 'contactname' => 'Fictional Fred', 322 | 'contactemail' => 'fred@example.com', 323 | 'contactphone' => '', 324 | 'imageurl' => '', 325 | 'privacy' => '', 326 | 'language' => 'en', 327 | 'users' => '', 328 | 'courses' => '', 329 | 'street' => '', 330 | 'regioncode' => '', 331 | 'countrycode' => '', 332 | 'geolocation' => '', 333 | 'contactable' => '', 334 | 'emailalert' => '', 335 | 'enrolments' => '', 336 | 'posts' => '', 337 | 'questions' => '', 338 | 'resources' => '', 339 | 'participantnumberaverage' => '', 340 | 'modulenumberaverage' => '', 341 | 'moodleversion' => '', 342 | 'moodlerelease' => '', 343 | 'password' => '', 344 | 'badges' => '', 345 | 'issuedbadges' => ''); 346 | 347 | return $sitevalues; 348 | } 349 | 350 | private function check_tokens($hub, $url) { 351 | global $DB; 352 | 353 | // Check a token was created and inserted into external_tokens and hub_communications. 354 | $username = $url . '_registered_site_user'; 355 | $user = $DB->get_record('user', array('username' => $username, 'idnumber' => $username)); 356 | $service = $DB->get_record('external_services', array('name' => 'Registered site')); 357 | 358 | $externaltoken = $this->get_external_token($user, $service); 359 | $communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, $url); 360 | $this->assertTrue($externaltoken->token == $communication->token); 361 | } 362 | 363 | private function get_external_token($user, $service) { 364 | global $DB; 365 | 366 | $resulttoken = new stdClass(); 367 | $resulttoken->userid = $user->id; 368 | $resulttoken->tokentype = EXTERNAL_TOKEN_PERMANENT; 369 | $resulttoken->externalserviceid = $service->id; 370 | $resulttoken->contextid = context_system::instance()->id; 371 | $resulttoken->creatorid = $user->id; 372 | return $DB->get_record('external_tokens', (array) $resulttoken); 373 | } 374 | } 375 | --------------------------------------------------------------------------------