Skip to content

Add custom plugin list for not released plugins #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function render_tab_viewtable() {
$result_sitesplugins = $DB->get_records_sql($sql_sitesplugins);

// Get all plugin records and the installation counts from DB ordered by installation count
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, count(pl.frankenstyle)
$sql_plugins = 'SELECT pl.id, pl.frankenstyle, pl.title, pl.pluginurl, count(pl.frankenstyle)
FROM {local_sitestats_plugins} AS pl
JOIN {local_sitestats_plugins_site} AS jointable
ON pl.id = jointable.plugin
Expand Down Expand Up @@ -149,9 +149,14 @@ public function render_tab_viewtable() {
WHERE jointable.plugin = ' . $plugin->id;
$result_pluginsites = $DB->get_records_sql($sql_pluginsites);
// Table row for plugin
$pluginlink = 'https://moodle.org/plugins/view/' . $plugin->frankenstyle;
if (!empty($plugin->pluginurl)) {
$pluginlink = $plugin->pluginurl;
}

$output .= \html_writer::start_tag('tr');
$output .= \html_writer::start_tag('td');
$output .= \html_writer::link('https://moodle.org/plugins/view/' . $plugin->frankenstyle, $plugin->title);
$output .= \html_writer::link($pluginlink, $plugin->title, ['target' => '_blank']);
$output .= \html_writer::empty_tag('br');
$output .= '(' . $plugin->frankenstyle . ')';
$output .= \html_writer::end_tag('td');
Expand Down
23 changes: 23 additions & 0 deletions classes/task/crawl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* @package local_sitestats
* @copyright 2019 Alexander Bias, Ulm University <[email protected]>
* @author 2021 Adrian Perez, Fernfachhochschule Schweiz (FFHS) <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand Down Expand Up @@ -185,13 +186,34 @@ public function execute()
$blacklistedplugins[] = $plugin;
}

// Gather list of custom plugins.
$custompluginsraw = explode("\n", $config->plugincustomlist);
foreach ($custompluginsraw as $plugin) {
// Trim setting lines.
$plugin = trim($plugin);

// Skip empty lines.
if (strlen($plugin) == 0) {
continue;
}

$plugin = explode('|', $plugin);

$customplugin['name'] = $plugin[1];
$customplugin['component'] = $plugin[0];
$customplugin['pluginurl'] = $plugin[2];

$pluginjson['plugins'][] = $customplugin;
}

// Iterate over all plugins in the plugin list.
foreach ($pluginjson['plugins'] as $plugin_info) {
// Generate plugin path.
$plugin_frankenstyle = clean_param($plugin_info['component'], PARAM_COMPONENT);
$plugin_title = clean_param($plugin_info['name'], PARAM_RAW_TRIMMED);
$plugin_component = substr($plugin_frankenstyle, 0, strpos($plugin_frankenstyle, '_'));
$plugin_name = substr($plugin_frankenstyle, strpos($plugin_frankenstyle, '_') + 1);
$plugin_url = isset($plugin_info['pluginurl']) ? clean_param($plugin_info['pluginurl'], PARAM_URL) : '';

// Skip plugin if it is blacklisted in our configuration.
if (in_array($plugin_frankenstyle, $blacklistedplugins)) {
Expand All @@ -215,6 +237,7 @@ public function execute()
$plugin_record->title = $plugin_title;
$plugin_record->frankenstyle = $plugin_frankenstyle;
$plugin_record->pluginpath = $plugin_path;
$plugin_record->pluginurl = $plugin_url;
$plugin_record->blacklisted = $plugin_blacklisted;
$ret = $DB->insert_record('local_sitestats_plugins', $plugin_record, false);
if ($ret === true) {
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<FIELD NAME="title" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="frankenstyle" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="pluginpath" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="pluginurl" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="blacklisted" TYPE="char" LENGTH="1" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
Expand Down
53 changes: 53 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file keeps track of upgrades to the "Site statistics" plugin
*
* @package local_sitestats
* @copyright 2019 Alexander Bias, Ulm University <[email protected]>
* @author 2021 Adrian Perez, Fernfachhochschule Schweiz (FFHS) <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Upgrade the sitestats plugin.
*
* @param int $oldversion
* @return bool
*/
function xmldb_local_sitestats_upgrade($oldversion) {
global $DB;

$dbman = $DB->get_manager();

if ($oldversion < 2019080107) {
// Define field pluginurl to be added to local_sitestats_plugins.
$table = new xmldb_table('local_sitestats_plugins');
$field = new xmldb_field('pluginurl', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, 'pluginpath');

// Conditionally launch add field pluginurl.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Sitestats savepoint reached.
upgrade_plugin_savepoint(true, 2019080107, 'local', 'sitestats');
}

return true;
}
2 changes: 2 additions & 0 deletions lang/en/local_sitestats.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
$string['setting_crawlsites_desc'] = 'This site list will be crawled.<br />Please add one Moodle site URL per line. If you want to provide a title for the Moodle site, you can optionally add it after the URL and a pipe character.';
$string['setting_pluginblacklist'] = 'Moodle plugin blacklist';
$string['setting_pluginblacklist_desc'] = 'This plugin list will be ignored when crawling the sites for plugins, especially because they have been published in the Moodle plugin repo but are shipped with Moodle core in recent versions.<br />Please add one plugin frankenstyle name per line.';
$string['setting_plugincustomlist'] = 'Moodle plugin customlist';
$string['setting_plugincustomlist_desc'] = 'This plugin list will be added to the Moodle plugin list.<br />Please add one plugin per line. Please provide the frankenstyle, title and URL for the plugin. Please separate them by a pipe character, e.g. "local_sitestats|Site statistics|https://github.com/moodleuulm/moodle-local_sitestats".';
$string['setting_pluginchartnumber'] = 'Number of plugins in chart';
$string['setting_pluginchartnumber_desc'] = 'The number of plugins which will be shown as top used plugins after crawling for plugins.';
$string['setting_plugincrawlagaindelay'] = 'Crawl again delay';
Expand Down
46 changes: 28 additions & 18 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* @package local_sitestats
* @copyright 2019 Alexander Bias, Ulm University <[email protected]>
* @author 2021 Adrian Perez, Fernfachhochschule Schweiz (FFHS) <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand All @@ -32,42 +33,42 @@

// Create crawl sites heading.
$page->add(new admin_setting_heading('local_sitestats/crawlsitesheading',
get_string('setting_crawlsites', 'local_sitestats', null, true),
''));
get_string('setting_crawlsites', 'local_sitestats', null, true),
''));

// Create crawl sites widget.
$page->add(new admin_setting_configtextarea('local_sitestats/crawlsites',
get_string('setting_crawlsites', 'local_sitestats', null, true),
get_string('setting_crawlsites_desc', 'local_sitestats', null, true),
'https://sandbox.moodledemo.net|Moodle demo instance
get_string('setting_crawlsites', 'local_sitestats', null, true),
get_string('setting_crawlsites_desc', 'local_sitestats', null, true),
'https://sandbox.moodledemo.net|Moodle demo instance
https://qa.moodledemo.net|Moodle QA instance',
PARAM_RAW));
PARAM_RAW));

// Create crawl plugins heading.
$page->add(new admin_setting_heading('local_sitestats/crawlpluginsheading',
get_string('setting_crawlplugins', 'local_sitestats', null, true),
''));
get_string('setting_crawlplugins', 'local_sitestats', null, true),
''));

// Create enable crawl plugins widget.
$page->add(new admin_setting_configcheckbox('local_sitestats/crawlplugins',
get_string('setting_crawlplugins', 'local_sitestats', null, true),
get_string('setting_crawlplugins_desc', 'local_sitestats', null, true),
true));
get_string('setting_crawlplugins', 'local_sitestats', null, true),
get_string('setting_crawlplugins_desc', 'local_sitestats', null, true),
true));

// Create crawl plugins cURL timeout widget.
$page->add(new admin_setting_configtext('local_sitestats/plugincurltimeout',
get_string('setting_plugincurltimeout', 'local_sitestats', null, true),
get_string('setting_plugincurltimeout_desc', 'local_sitestats', null, true),
10));
get_string('setting_plugincurltimeout', 'local_sitestats', null, true),
get_string('setting_plugincurltimeout_desc', 'local_sitestats', null, true),
10));
$page->hide_if('local_sitestats/plugincurltimeout',
'local_sitestats/crawlplugins', 'notchecked');

// Create pluginlist widget.
$page->add(new admin_setting_configtext('local_sitestats/pluginlist',
get_string('setting_pluginlist', 'local_sitestats', null, true),
get_string('setting_pluginlist_desc', 'local_sitestats', null, true),
'https://download.moodle.org/api/1.3/pluglist.php',
PARAM_URL));
get_string('setting_pluginlist', 'local_sitestats', null, true),
get_string('setting_pluginlist_desc', 'local_sitestats', null, true),
'https://download.moodle.org/api/1.3/pluglist.php',
PARAM_URL));
$page->hide_if('local_sitestats/pluginlist',
'local_sitestats/crawlplugins', 'notchecked');

Expand Down Expand Up @@ -98,6 +99,15 @@
$page->hide_if('local_sitestats/pluginblacklist',
'local_sitestats/crawlplugins', 'notchecked');

// Create custom plugin widget.
$page->add(new admin_setting_configtextarea('local_sitestats/plugincustomlist',
get_string('setting_plugincustomlist', 'local_sitestats', null, true),
get_string('setting_plugincustomlist_desc', 'local_sitestats', null, true),
'',
PARAM_RAW));
$page->hide_if('local_sitestats/plugincustomlist',
'local_sitestats/crawlplugins');

// Create crawl plugins crawl again delay widget.
$page->add(new admin_setting_configtext('local_sitestats/plugincrawlagaindelay',
get_string('setting_plugincrawlagaindelay', 'local_sitestats', null, true),
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'local_sitestats';
$plugin->version = 2019080106;
$plugin->version = 2019080107;
$plugin->release = 'v3.7-r1';
$plugin->requires = 2019052000;
$plugin->maturity = MATURITY_RC;