diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4fe17c..4406550 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: test: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest services: mysql: @@ -18,13 +18,27 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1] - moodle-branch: [MOODLE_401_STABLE, MOODLE_402_STABLE, master] - database: [mysqli] + include: + # Always the max supported PHP version on every branch. + - php: 8.3 + moodle-branch: main + database: mysqli + - php: 8.3 + moodle-branch: MOODLE_404_STABLE + database: mysqli + - php: 8.2 + moodle-branch: MOODLE_403_STABLE + database: mysqli + - php: 8.2 + moodle-branch: MOODLE_402_STABLE + database: mysqli + - php: 8.1 + moodle-branch: MOODLE_401_STABLE + database: mysqli steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -53,48 +67,42 @@ jobs: IGNORE_PATHS: tests/fixtures - name: PHP Lint - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - continue-on-error: true # This step will show errors but will not fail - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector continue-on-error: true # This step will show errors but will not fail - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phpmd - name: Moodle Code Checker - if: ${{ always() }} - run: moodle-plugin-ci codechecker - - # Disabled, it needs real fixes. - #- name: Moodle PHPDoc Checker - # if: ${{ always() }} - # run: moodle-plugin-ci phpdoc + if: ${{ !cancelled() }} + run: moodle-plugin-ci codechecker --max-warnings 0 - name: Validating - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci validate - name: Check upgrade savepoints - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci savepoints - name: Mustache Lint - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci mustache - name: Grunt - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci grunt --max-lint-warnings 0 - name: PHPUnit tests - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci phpunit - name: Behat features - if: ${{ always() }} + if: ${{ !cancelled() }} run: moodle-plugin-ci behat --profile chrome + + - name: Mark cancelled jobs as failed. + if: ${{ cancelled() }} + run: exit 1 diff --git a/admin/jabber-aliases-search.php b/admin/jabber-aliases-search.php index b269014..2e069dc 100644 --- a/admin/jabber-aliases-search.php +++ b/admin/jabber-aliases-search.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * AJAX search for the user on jabber aliases search.. @@ -21,7 +21,7 @@ * * @package local_chatlogs * @copyright 2012 David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('AJAX_SCRIPT', true); @@ -44,7 +44,7 @@ $response = new stdClass(); $response->status = 'ok'; $response->query = $query; -$response->results = array(); +$response->results = []; if (!empty($query)) { @@ -63,33 +63,33 @@ FROM {user} WHERE ".$DB->sql_like("firstname", "?", false, false)." AND ".$DB->sql_like("lastname", "?", false, false); - $params = array( + $params = [ $DB->sql_like_escape($parts[0]).'%', - $DB->sql_like_escape($parts[1]).'%' - ); + $DB->sql_like_escape($parts[1]).'%', + ]; } else { $sql = "SELECT id, firstname, lastname, email FROM {user} WHERE ".$DB->sql_like("firstname", "?", false, false)." OR ".$DB->sql_like("lastname", "?", false, false)." OR ".$DB->sql_like("email", "?", false, false); - $params = array( + $params = [ '%'.$DB->sql_like_escape($query).'%', '%'.$DB->sql_like_escape($query).'%', - '%'.$DB->sql_like_escape($query).'%' - ); + '%'.$DB->sql_like_escape($query).'%', + ]; } $rs = $DB->get_recordset_sql($sql, $params, 0, 10); foreach ($rs as $r) { - $response->results[] = (object)array( + $response->results[] = (object)[ 'userid' => $r->id, 'firstname' => $r->firstname, 'lastname' => $r->lastname, 'email' => $r->email, 'signature' => sprintf('%s <%s>', fullname($r), $r->email), - ); + ]; } $rs->close(); diff --git a/admin/jabber-aliases.php b/admin/jabber-aliases.php index a05a6be..8873d62 100644 --- a/admin/jabber-aliases.php +++ b/admin/jabber-aliases.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Displays the list of jabber users and lets the user to assign them to real user accounts @@ -21,7 +21,7 @@ * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); @@ -45,7 +45,7 @@ if (!empty($userid)) { $status = link_jabberid_to_user($jabberid, $userid); if ($status === false) { - print_error('failed'); + throw new moodle_exception('failed'); } } redirect($PAGE->url); @@ -64,32 +64,32 @@ $table = new html_table(); $table->id = 'aliaseseditor'; -$table->head = array( +$table->head = [ get_string('jabberfullname', 'local_chatlogs'), get_string('jabberid', 'local_chatlogs'), get_string('jabberaliasesassign', 'local_chatlogs'), -); +]; foreach ($rs as $record) { - $table->data[] = array( - html_writer::tag('div', s($record->nickname), array('class' => 'aliasdata-authorname')), - html_writer::tag('div', s($record->fromemail), array('class' => 'aliasdata-authoremail')), + $table->data[] = [ + html_writer::tag('div', s($record->nickname), ['class' => 'aliasdata-authorname']), + html_writer::tag('div', s($record->fromemail), ['class' => 'aliasdata-authoremail']), html_writer::tag('form', html_writer::tag('div', - html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'jabbernick', 'value' => $record->nickname)). - html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'jabberid', 'value' => $record->fromemail)). - html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())). - html_writer::empty_tag('input', array('type' => 'text', 'name' => 'search', 'class' => 'aliasdata-search', - 'maxlength' => 100, 'size' => 50)). - html_writer::empty_tag('input', array('type' => 'text', 'name' => 'userid', 'class' => 'aliasdata-userid', - 'maxlength' => 100, 'size' => 5)). - html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('submit'))). - html_writer::empty_tag('input', array('type' => 'reset', 'value' => get_string('reset'))). - html_writer::tag('span', ' ', array('class' => 'aliasdata-icon')) + html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'jabbernick', 'value' => $record->nickname]). + html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'jabberid', 'value' => $record->fromemail]). + html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]). + html_writer::empty_tag('input', ['type' => 'text', 'name' => 'search', 'class' => 'aliasdata-search', + 'maxlength' => 100, 'size' => 50]). + html_writer::empty_tag('input', ['type' => 'text', 'name' => 'userid', 'class' => 'aliasdata-userid', + 'maxlength' => 100, 'size' => 5]). + html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('submit')]). + html_writer::empty_tag('input', ['type' => 'reset', 'value' => get_string('reset')]). + html_writer::tag('span', ' ', ['class' => 'aliasdata-icon']) ), - array('method' => 'post', 'action' => $PAGE->url->out())) - ); + ['method' => 'post', 'action' => $PAGE->url->out()]), + ]; } echo html_writer::table($table); $rs->close(); @@ -105,11 +105,11 @@ function link_jabberid_to_user($jabberid, $userid) { global $DB; - if (is_null($userid) or is_null($jabberid)) { + if (is_null($userid) || is_null($jabberid)) { throw new coding_exception('NULL parameter values not allowed here'); } - $record = $DB->get_record('local_chatlogs_participants', array('fromemail' => $jabberid)); + $record = $DB->get_record('local_chatlogs_participants', ['fromemail' => $jabberid]); if ($record) { $record->userid = $userid; diff --git a/adminlib.php b/adminlib.php index 9b605c8..d298828 100644 --- a/adminlib.php +++ b/adminlib.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** - * Admin tree class for lazyloading config box - * - * @package local_chatlogs - * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * admin_setting_configselect for the seleted cohort - * simply so we can lazy-load the choices. + * admin_setting_configselect for the seleted cohort, so we can lazy-load the choices. * + * @package local_chatlogs * @copyright Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_chatlogs_cohort_selector extends admin_setting_configselect { - /** Lazy-load the available choices for the select box */ + /** + * Lazy-load the available choices for the select box + */ public function load_choices() { global $DB; - $this->choices = array(0 => get_string('none')); - if ($cohorts = $DB->get_records_menu('cohort', array('contextid' => context_system::instance()->id), 'name', 'id, name')) { + $this->choices = [0 => get_string('none')]; + if ($cohorts = $DB->get_records_menu('cohort', ['contextid' => context_system::instance()->id], 'name', 'id, name')) { foreach ($cohorts as $key => $value) { $this->choices[$key] = $value; } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 849ff29..6261363 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** - * Defines {@link \local_chatlogs\privacy\provider} class. + * Defines {@see \local_chatlogs\privacy\provider} class. * * @package local_chatlogs * @category privacy * @copyright 2018 David Mudrák - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace local_chatlogs\privacy; -defined('MOODLE_INTERNAL') || die(); - use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\contextlist; @@ -38,7 +36,7 @@ * Privacy API implementation for the Developer chat plugin. * * @copyright 2018 David Mudrák - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements \core_privacy\local\metadata\provider, @@ -50,7 +48,7 @@ class provider implements * @param collection $collection Collection of items to add metadata to. * @return collection Collection with our added items. */ - public static function get_metadata(collection $collection) : collection { + public static function get_metadata(collection $collection): collection { $collection->add_database_table('local_chatlogs_messages', [ 'conversationid' => 'privacy:metadata:db:messages:conversationid', @@ -76,7 +74,7 @@ public static function get_metadata(collection $collection) : collection { * @param int $userid ID of the user. * @return contextlist List of contexts containing the user's personal data. */ - public static function get_contexts_for_userid(int $userid) : contextlist { + public static function get_contexts_for_userid(int $userid): contextlist { $contextlist = new contextlist(); $contextlist->add_system_context(); diff --git a/classes/task/sync_chatlogs.php b/classes/task/sync_chatlogs.php index 06170d0..8772763 100644 --- a/classes/task/sync_chatlogs.php +++ b/classes/task/sync_chatlogs.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * A scheduled task for syning chatlogs from the remote api. * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace local_chatlogs\task; -defined('MOODLE_INTERNAL') || die(); /** * A scheduled task for syning chatlogs from the remote api. * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class sync_chatlogs extends \core\task\scheduled_task { /** diff --git a/classes/telegram_importer.php b/classes/telegram_importer.php index 992a267..1561a9e 100644 --- a/classes/telegram_importer.php +++ b/classes/telegram_importer.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Imports logs from a simple json api provided by hubot-log-to-pgsql. * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace local_chatlogs; @@ -33,7 +33,7 @@ * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class telegram_importer { /** @var int Number of seconds between conversations to start a new one */ @@ -114,7 +114,7 @@ public function import() { /** * Utility to strip probematic 4-byte utf8 chars for use in MDL-48228 workaround. * - * Thanks http://stackoverflow.com/a/16496799 + * Thanks https://stackoverflow.com/a/16496799 * * @param string $string to strip 4-byte utf8 count_chars * @param string $replacement @@ -190,8 +190,8 @@ protected function format_telegram_message($input) { // the timestamp stored with microseconds precision, which is important // for ensuring that we don't retrieve the same chat message twice. // $message->timestamp - traditional Moodle timestamp (Seconds since the Unix Epoch) - // $message->timejava - microseconds since unix epoch (so that we can later) - $d = new \DateTime($input->timestamp); // Input is ISO-8601 formated timestamp + // $message->timejava - microseconds since unix epoch (so that we can later). + $d = new \DateTime($input->timestamp); // Input is ISO-8601 formated timestamp. $timestamp = $d->format('U'); // Time since epoch. $miliseconds = $d->format('u') / 1000; // If php7 we could use ->format('v'). $milisecondepoch = floor(($timestamp * 1000) + $miliseconds); diff --git a/classes/urlfilter.php b/classes/urlfilter.php index dce651b..83ea838 100644 --- a/classes/urlfilter.php +++ b/classes/urlfilter.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Wrapper around urltolink filter to access its abilities. * * @package local_chatlogs * @copyright 2015 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace local_chatlogs; @@ -30,16 +30,26 @@ /** * Lang import controller * - * @package tool_langimport + * @package local_chatlogs * @copyright 2014 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class urlfilter extends \filter_urltolink { + + /** + * Create a new instance + */ public function __construct() { self::$globalconfig = new \stdClass(); self::$globalconfig->embedimages = false; } - public function convert_urls_into_links(&$text) { + + /** + * Convert all the URLs in a text to working links. + * + * @param string $text The text which URLs have to be converted to working links. By reference. + */ + public function convert_urls_into_links(&$text) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found parent::convert_urls_into_links($text); } } diff --git a/cli/dumpconversation.php b/cli/dumpconversation.php index 81d2035..fcc95ba 100644 --- a/cli/dumpconversation.php +++ b/cli/dumpconversation.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** + * CLI script to dump a given conversation to standard output. + * * @package local_chatlogs * @subpackage cli * @copyright 2014 David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); @@ -42,15 +44,16 @@ "; list($options, $unrecognized) = cli_get_params( - array( + [ 'help' => false, 'format' => 'mediawiki', - ), array( + ], + [ 'h' => 'help', - ) + ], ); -if (!empty($options['help']) or count($unrecognized) <> 1) { +if (!empty($options['help']) || count($unrecognized) <> 1) { cli_error($usage); } @@ -74,7 +77,7 @@ WHERE m.conversationid = :conversationid ORDER BY m.timesent"; -$rs = $DB->get_recordset_sql($sql, array('conversationid' => $conversationid)); +$rs = $DB->get_recordset_sql($sql, ['conversationid' => $conversationid]); if (!$rs->valid()) { cli_error('No data found'); @@ -108,6 +111,8 @@ */ /** + * Return the formatted header. + * * @param string $format * @return string */ @@ -119,6 +124,8 @@ function local_chatlogs_dumpconversation_header($format) { } /** + * Return the formatted footer. + * * @param string $format * @return string */ @@ -130,6 +137,8 @@ function local_chatlogs_dumpconversation_footer($format) { } /** + * Return a formatted message. + * * @param stdClass $message * @param string $format * @return string diff --git a/db/access.php b/db/access.php index fe38a29..4dafd0a 100644 --- a/db/access.php +++ b/db/access.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Capability definitions for the chat logs plugin @@ -20,25 +20,25 @@ * @package local_chatlogs * @category access * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ // Ability to view chatlogs irrespective of cohort memebership. - 'local/chatlogs:view' => array( + 'local/chatlogs:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'legacy' => array() - ), + 'legacy' => [], + ], // Ability to view chatlogs if developer cohort. - 'local/chatlogs:viewifdeveloper' => array( + 'local/chatlogs:viewifdeveloper' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_SYSTEM, - 'legacy' => array() - ), + 'legacy' => [], + ], -); +]; diff --git a/db/install.php b/db/install.php index 57a3bdc..aab996f 100644 --- a/db/install.php +++ b/db/install.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Post installation and migration code. * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die; - /** * Installation step for chatlogs plugin. * diff --git a/db/install.xml b/db/install.xml index 4799935..341a861 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,6 +1,6 @@ diff --git a/db/tasks.php b/db/tasks.php index e63b178..b38d30b 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Definition of partner block tasks * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'local_chatlogs\task\sync_chatlogs', 'blocking' => 0, 'minute' => '*/5', 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' - ) -); + 'month' => '*', + ], +]; diff --git a/index.php b/index.php index 4a4daf2..28360c5 100755 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Displays list of conversations or a specific covnersation depending on params * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../../config.php'); diff --git a/info.php b/info.php index 62045d1..5998fc0 100644 --- a/info.php +++ b/info.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Displays info of how to get to the chat logs * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require(dirname(dirname(dirname(__FILE__))).'/config.php'); @@ -36,16 +36,10 @@ echo $OUTPUT->header(); echo $OUTPUT->heading('Moodle developers chat'); echo $OUTPUT->box_start('text-center lead'); -?> +echo html_writer::tag('p', get_string('infohistory', 'local_chatlogs')); -

Historically, Moodle developers used a Jabber chat room for synchronous -discussions. Since February 1st 2017, the chat has been moved to Telegram. Developers are encouraged to join -the chat at telegram.me/moodledev.

+echo html_writer::tag('hr', ''); -
- -pix_icon('telegram', 'Moodle dev and Telegram logos', 'local_chatlogs', ['width' => 118, 'class' => 'img-responsive']); echo $OUTPUT->box_end(); diff --git a/lang/en/local_chatlogs.php b/lang/en/local_chatlogs.php index e447688..553f30d 100644 --- a/lang/en/local_chatlogs.php +++ b/lang/en/local_chatlogs.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Lang file for local_chatlogs plugin @@ -20,7 +20,7 @@ * @package local_chatlogs * @category string * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); @@ -33,14 +33,20 @@ $string['chatlogs:manage'] = 'Manage the developer chat logs plugin'; $string['chatlogs:view'] = 'View developer chat logs irrespective of cohort membership'; $string['chatlogs:viewifdeveloper'] = 'View developer chat logs if in developer cohort'; -$string['developerconversations'] = 'Chat history'; $string['developercohort'] = 'Developer cohort'; $string['developercohortdescription'] = 'Select the cohort which developers are in. Users in this cohort and with the local/chatlogs:viewifdeveloper capability will be able to view the chatlogs'; +$string['developerconversations'] = 'Chat history'; $string['info'] = 'Info'; +$string['infohistory'] = 'Historically, Moodle developers used a Jabber chat room for synchronous +discussions. Since 2017, the chat was moved to Telegram. +And later, in 2022, it was decided to move everything to Matrix. +Developers are encouraged to join the chat at telegram.me/moodledev or +matrix.to/#/#moodledev:moodle.com. +Both rooms are bridged, so you can use either one.'; $string['jabberaliases'] = 'Aliases'; $string['jabberaliasesassign'] = 'Assign user'; -$string['jabberid'] = 'ID'; $string['jabberfullname'] = 'Nick'; +$string['jabberid'] = 'ID'; $string['pluginname'] = 'Developer chat'; $string['privacy:metadata:db:messages'] = 'Stores copies of developer chat discussions'; $string['privacy:metadata:db:messages:conversationid'] = 'Internal identifier of the conversation'; diff --git a/lib.php b/lib.php index c4e6420..8c8a912 100644 --- a/lib.php +++ b/lib.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * The plugin's external API is defined here * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Determines whether the current user can access chatlogs * @@ -43,7 +41,7 @@ function local_chatlogs_can_access() { if ($cohortid = get_config('local_chatlogs', 'cohortid')) { if ($cohortid > 0) { // Only allowed to view if in developer cohort. - if ($DB->get_record('cohort_members', array('cohortid' => $cohortid, 'userid' => $USER->id))) { + if ($DB->get_record('cohort_members', ['cohortid' => $cohortid, 'userid' => $USER->id])) { return true; } } diff --git a/locallib.php b/locallib.php index 6619c19..85db752 100644 --- a/locallib.php +++ b/locallib.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Provides library functions used by plugin * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); @@ -31,7 +31,7 @@ * Table listing jabber conversations * * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_chatlogs_converations_table extends table_sql { @@ -49,10 +49,10 @@ public function __construct($uniqueid) { $this->sql->fields = 'conversationid, messagecount, timestart, timeend, (timestart - timeend) AS duration'; $this->sql->from = '{local_chatlogs_conversations}'; $this->sql->where = 'messagecount > 0'; - $this->sql->params = array(); + $this->sql->params = []; - $this->define_columns(array('conversationid', 'participants', 'messagecount', 'timestart', 'timeend', 'duration')); - $this->define_headers(array('ID', 'Participants', 'Messages', 'Start', 'End', 'Duration')); + $this->define_columns(['conversationid', 'participants', 'messagecount', 'timestart', 'timeend', 'duration']); + $this->define_headers(['ID', 'Participants', 'Messages', 'Start', 'End', 'Duration']); $this->no_sorting('participants'); $this->collapsible(false); $this->sortable(true, 'timeend', SORT_DESC); @@ -77,7 +77,7 @@ public function col_participants($row) { LEFT JOIN {user} u ON p.userid = u.id WHERE m.conversationid = ? GROUP BY p.fromemail, p.nickname, u.firstname, u.lastname'; - $participants = $DB->get_records_sql_menu($sql, array($row->conversationid)); + $participants = $DB->get_records_sql_menu($sql, [$row->conversationid]); $participants = implode(', ', $participants); return $this->conversation_link($row->conversationid, $participants); @@ -141,7 +141,7 @@ public function col_timeend($row) { * @return string HTML of link */ private function conversation_link($id, $text) { - $url = new moodle_url('/local/chatlogs/index.php', array('conversationid' => $id)); + $url = new moodle_url('/local/chatlogs/index.php', ['conversationid' => $id]); return html_writer::link($url, $text); } @@ -152,7 +152,7 @@ private function conversation_link($id, $text) { * A jabber conversation * * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_chatlogs_conversation { /** @var object From from the chatlogs_conversations table */ @@ -183,7 +183,7 @@ public function __construct($conversationid) { $this->urlfilter = new local_chatlogs\urlfilter(); $this->conversation = $DB->get_record('local_chatlogs_conversations', - array('conversationid' => $conversationid), '*', MUST_EXIST); + ['conversationid' => $conversationid], '*', MUST_EXIST); } /** @@ -202,13 +202,13 @@ private function get_previous_link() { $sql = 'SELECT * FROM {local_chatlogs_conversations} WHERE id != ? AND timeend < ? AND messagecount > 0 ORDER BY timeend DESC LIMIT 1'; - $previous = $DB->get_record_sql($sql, array($this->conversation->id, $this->conversation->timeend)); + $previous = $DB->get_record_sql($sql, [$this->conversation->id, $this->conversation->timeend]); if ($previous) { $url = new moodle_url('/local/chatlogs/index.php', - array('conversationid' => $previous->conversationid)); + ['conversationid' => $previous->conversationid]); $this->previouslink = html_writer::link($url, '◄ '.$previous->messagecount.' messages', - array('class' => 'previouslink')); + ['class' => 'previouslink']); } return $this->previouslink; @@ -230,12 +230,12 @@ private function get_next_link() { $sql = 'SELECT * FROM {local_chatlogs_conversations} WHERE id != ? AND timeend > ? AND messagecount > 0 ORDER BY timeend ASC LIMIT 1'; - $next = $DB->get_record_sql($sql, array($this->conversation->id, $this->conversation->timeend)); + $next = $DB->get_record_sql($sql, [$this->conversation->id, $this->conversation->timeend]); if ($next) { - $url = new moodle_url('/local/chatlogs/index.php', array('conversationid' => $next->conversationid)); + $url = new moodle_url('/local/chatlogs/index.php', ['conversationid' => $next->conversationid]); $this->nextlink = html_writer::link($url, $next->messagecount.' messages ►', - array('class' => 'nextlink')); + ['class' => 'nextlink']); } return $this->nextlink; @@ -254,13 +254,13 @@ public function conversation_header() { $header = new html_table(); $header->width = '100%'; - $header->wrap = array('nowrap', '', 'nowrap'); - $header->size = array('', '100%', ''); - $header->data[] = array( + $header->wrap = ['nowrap', '', 'nowrap']; + $header->size = ['', '100%', '']; + $header->data[] = [ $OUTPUT->heading($this->get_previous_link()), $OUTPUT->heading("$starttime, for $duration"), $OUTPUT->heading($this->get_next_link()), - ); + ]; return html_writer::table($header); } @@ -274,15 +274,15 @@ public function conversation_footer() { global $OUTPUT; $footer = new html_table(); - $footer->wrap = array('nowrap', '', 'nowrap'); + $footer->wrap = ['nowrap', '', 'nowrap']; $footer->width = '100%'; - $footer->size = array('', '100%', ''); - $footer->data[] = array( + $footer->size = ['', '100%', '']; + $footer->data[] = [ $OUTPUT->heading($this->get_previous_link()), $OUTPUT->heading(html_writer::link(new moodle_url('/local/chatlogs/index.php'), get_string('allconversations', 'local_chatlogs'))), $OUTPUT->heading($this->get_next_link()), - ); + ]; return html_writer::table($footer); } @@ -308,12 +308,12 @@ public function render() { WHERE m.conversationid = :conversationid ORDER BY m.timesent'; - $rs = $DB->get_recordset_sql($sql, array('conversationid' => $this->conversation->conversationid)); + $rs = $DB->get_recordset_sql($sql, ['conversationid' => $this->conversation->conversationid]); echo $this->conversation_header(); $table = new html_table(); $table->attributes['class'] = 'devchat'; - $table->wrap = array('nowrap', 'nowrap', ''); + $table->wrap = ['nowrap', 'nowrap', '']; foreach ($rs as $message) { $time = userdate($message->timesent, "%I:%M:%S %P"); @@ -326,7 +326,7 @@ public function render() { } else { $namecell->text = $message->nickname . html_writer::empty_tag('br'); } - $namecell->text .= html_writer::link('#c'.$message->messageid, $time, array('class' => 'jabbertime')); + $namecell->text .= html_writer::link('#c'.$message->messageid, $time, ['class' => 'jabbertime']); $messagecell = new html_table_cell(); $messagecell->attributes['class'] = 'talkmessage'; @@ -339,7 +339,7 @@ public function render() { } // This is a bit of a hack to make the format plain, but have clickable links.. - $formatedmessage = format_text($message->message, FORMAT_PLAIN, array('para' => false)); + $formatedmessage = format_text($message->message, FORMAT_PLAIN, ['para' => false]); $this->urlfilter->convert_urls_into_links($formatedmessage); $messagecell->text .= $formatedmessage; @@ -351,7 +351,7 @@ public function render() { $row = new html_table_row(); $row->id = 'c'.$message->messageid; - $row->cells = array($imagecell, $namecell, $messagecell); + $row->cells = [$imagecell, $namecell, $messagecell]; $table->data[] = $row; } $rs->close(); @@ -363,12 +363,15 @@ public function render() { } /** - * Table listing jabber search results + * Table listing chat search results * * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_chatlogs_search_table extends table_sql { + /** + * @var string Search term used to search the logs. + */ private $searchterm = null; /** @@ -399,10 +402,10 @@ public function __construct($uniqueid, $searchterm) { LEFT JOIN {user} u ON p.userid = u.id'; $this->sql->where = $DB->sql_like('m.message', ':search'); - $this->sql->params = array('search' => '%'.$searchterm.'%'); + $this->sql->params = ['search' => '%'.$searchterm.'%']; - $this->define_columns(array('timesent', 'userpic', 'userid', 'message')); - $this->define_headers(array('Timesent', '', 'User', 'Message')); + $this->define_columns(['timesent', 'userpic', 'userid', 'message']); + $this->define_headers(['Timesent', '', 'User', 'Message']); $this->column_class('timesent', 'userinfo'); $this->column_class('userpic', 'userpic'); $this->column_class('userid', 'userinfo usersays'); @@ -420,10 +423,10 @@ public function __construct($uniqueid, $searchterm) { */ public function col_timesent($row) { $link = new moodle_url('/local/chatlogs/index.php'); - $link->params( array('conversationid' => $row->conversationid)); + $link->params( ['conversationid' => $row->conversationid]); $link->set_anchor('c'.$row->messageid); - return html_writer::link($link, userdate($row->timesent), array('class' => 'jabbertime')); + return html_writer::link($link, userdate($row->timesent), ['class' => 'jabbertime']); } /** @@ -469,7 +472,7 @@ public function col_message($row) { $row->message = substr(trim($row->message), 4); } - $message = format_text($row->message, FORMAT_MOODLE, array('para' => false)); + $message = format_text($row->message, FORMAT_MOODLE, ['para' => false]); $text .= highlight($this->searchterm, $message); return $text; @@ -486,11 +489,11 @@ public static function form($searchtext = '') { $url = new moodle_url('/local/chatlogs/index.php'); - $o .= html_writer::start_tag('div', array('class' => 'searchform')); - $o .= html_writer::start_tag('form', array('method' => 'get', 'action' => $url->out())); - $o .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'q', - 'value' => $searchtext, 'maxlength' => 100, 'size' => 20)); - $o .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('searchmessages', 'local_chatlogs'))); + $o .= html_writer::start_tag('div', ['class' => 'searchform']); + $o .= html_writer::start_tag('form', ['method' => 'get', 'action' => $url->out()]); + $o .= html_writer::empty_tag('input', ['type' => 'text', 'name' => 'q', + 'value' => $searchtext, 'maxlength' => 100, 'size' => 20]); + $o .= html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('searchmessages', 'local_chatlogs')]); $o .= html_writer::end_tag('form'); $o .= html_writer::end_tag('div'); @@ -506,7 +509,7 @@ public static function form($searchtext = '') { */ function local_chatlogs_require_capability() { if (!local_chatlogs_can_access()) { - print_error('nopermissions', 'error', '', get_string('viewchatlogs', 'local_chatlogs')); + throw new moodle_exception('nopermissions', 'error', '', get_string('viewchatlogs', 'local_chatlogs')); die; } } diff --git a/settings.php b/settings.php index 9323687..281a6e2 100644 --- a/settings.php +++ b/settings.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Settings for local_chatlogs plugin * * @package local_chatlogs * @copyright 2012 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/syncchatlogs.php b/syncchatlogs.php index 2ec115c..9945204 100644 --- a/syncchatlogs.php +++ b/syncchatlogs.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . + +/** + * CLI script to perform the fetch all the new chat logs to the plugin + * + * @package local_chatlogs + * @copyright 2012 Dan Poltawski + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ define('CLI_SCRIPT', true); require(__DIR__.'/../../config.php'); @@ -20,7 +28,7 @@ // Only php cli allowed. if (isset($_SERVER['REMOTE_ADDR'])) { if ($_SERVER['REMOTE_ADDR'] != "174.123.154.58") { - print_error('cronerrorclionly', 'admin'); + throw new moodle_exception('cronerrorclionly', 'admin'); exit; } else { $ismoodlebot = true; @@ -87,7 +95,7 @@ $message->conversationid = $lastmessage->conversationid; // Same. $conversation = $DB->get_record('local_chatlogs_conversations', - array('conversationid' => $message->conversationid), '*', MUST_EXIST); + ['conversationid' => $message->conversationid], '*', MUST_EXIST); $conversation->timeend = $message->timesent; $conversation->messagecount = $conversation->messagecount + 1; if (!$DB->update_record('local_chatlogs_conversations', $conversation)) { @@ -120,7 +128,7 @@ // Now check that they have a registered name and if not, register them. if (empty($currentparticipant[$message->fromemail])) { - if (!$participant = $DB->get_record('local_chatlogs_participants', array('fromemail' => $message->fromemail))) { + if (!$participant = $DB->get_record('local_chatlogs_participants', ['fromemail' => $message->fromemail])) { $participant = new object; $participant->fromemail = $message->fromemail; $participant->nickname = $message->fromnick; @@ -140,7 +148,7 @@ } else { $conversationid = $DB->get_field_sql( "SELECT conversationid FROM {local_chatlogs_conversations} ORDER BY conversationid desc LIMIT 1"); - echo "Synchronised chat logs ($count new messages) - URL: http://moodle.org/local/chatlogs/index.php?conversationid=" . + echo "Synchronised chat logs ($count new messages) - URL: https://moodle.org/local/chatlogs/index.php?conversationid=" . $conversationid."\n"; } @@ -156,10 +164,10 @@ if ($pushtonext) { // Copy those to this. $DB->execute( "UPDATE {local_chatlogs_messages} SET conversationid = $conversation->conversationid WHERE conversationid = ?", - array($pushtonext)); + [$pushtonext]); $DB->execute( "UPDATE {local_chatlogs_conversations} SET messagecount = 0 WHERE conversationid = ?", - array($pushtonext)); + [$pushtonext]); $pushtonext = 0; } diff --git a/tests/telegram_importer_test.php b/tests/telegram_importer_test.php index 82c82c1..6caa29c 100644 --- a/tests/telegram_importer_test.php +++ b/tests/telegram_importer_test.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . + +/** + * Telegram importer tests. + * + * @package local_chatlogs + * @copyright 2017 Dan Poltawski + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_chatlogs; defined('MOODLE_INTERNAL') || die(); @@ -23,11 +33,12 @@ * * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \local_chatlogs_testable_telegram_importer */ -class local_chatlogs_telegram_importer_test extends advanced_testcase { +final class telegram_importer_test extends \advanced_testcase { - public function test_import_when_empty() { + public function test_import_when_empty(): void { $this->resetAfterTest(); $importer = new local_chatlogs_testable_telegram_importer(); @@ -36,16 +47,16 @@ public function test_import_when_empty() { $this->assertEmpty($importedcount); } - public function test_import_fails_on_bad_json() { + public function test_import_fails_on_bad_json(): void { $this->resetAfterTest(); $importer = new local_chatlogs_testable_telegram_importer(); $importer->set_mock_response('{sdfs:sdf'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $importer->import(); } - public function test_import() { + public function test_import(): void { global $DB; $this->resetAfterTest(); @@ -109,7 +120,7 @@ public function test_import() { $this->assertSame(2, $DB->count_records('local_chatlogs_conversations')); } - public function test_import_with_existing_data() { + public function test_import_with_existing_data(): void { global $DB; $this->resetAfterTest(); // Insert some chatlog data. @@ -157,7 +168,7 @@ public function test_import_with_existing_data() { $this->assertSame(2, $DB->count_records('local_chatlogs_participants')); } - public function test_problematic_mysql_emojis() { + public function test_problematic_mysql_emojis(): void { global $DB; $this->resetAfterTest(); @@ -180,9 +191,9 @@ public function test_problematic_mysql_emojis() { * Testable importer which generates mock server response. * @package local_chatlogs * @copyright 2017 Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class local_chatlogs_testable_telegram_importer extends local_chatlogs\telegram_importer { +class local_chatlogs_testable_telegram_importer extends telegram_importer { /** @var string|array mock response */ private $mockresponse = null; @@ -206,9 +217,9 @@ protected function call_api(\moodle_url $url) { // Simulate server-side filtering of timestamp. if ($timestamp = $url->param('aftertimestamp')) { - $afterdate = new DateTime($timestamp); + $afterdate = new \DateTime($timestamp); $resp = array_filter($this->mockresponse, function ($row) use($afterdate) { - return new DateTime($row->timestamp) > $afterdate; + return new \DateTime($row->timestamp) > $afterdate; }); return json_encode(array_values($resp)); } diff --git a/version.php b/version.php index 5a9932b..4428b75 100644 --- a/version.php +++ b/version.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * Version details. * * @package local_chatlogs * @copyright Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; @@ -29,6 +29,6 @@ $plugin->version = 2021051000; $plugin->requires = 2021050700; $plugin->maturity = MATURITY_STABLE; -$plugin->dependencies = array( +$plugin->dependencies = [ 'filter_urltolink' => ANY_VERSION, -); +]; diff --git a/yui/jabberaliases/jabberaliases.js b/yui/jabberaliases/jabberaliases.js index 354c46c..5e0e562 100644 --- a/yui/jabberaliases/jabberaliases.js +++ b/yui/jabberaliases/jabberaliases.js @@ -3,7 +3,7 @@ * Shamelessly stolen from the dev plugin by Dan * * @author David Mudrak - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ YUI.add('moodle-local_chatlogs-jabberaliases', function(Y) { diff --git a/yui/keyboard/keyboard.js b/yui/keyboard/keyboard.js index 89d5656..d83fd99 100644 --- a/yui/keyboard/keyboard.js +++ b/yui/keyboard/keyboard.js @@ -3,7 +3,7 @@ * between chats. * * @author Dan Poltawski - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ YUI.add('moodle-local_chatlogs-keyboard', function(Y) {