Skip to content
Merged
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
111 changes: 111 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"

ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
moodle-branch: [ 'MOODLE_311_STABLE','MOODLE_400_STABLE' ]
database: [ pgsql, mariadb ]

steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead.
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ always() }}
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() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ always() }}
run: moodle-plugin-ci phpdoc

- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
3 changes: 1 addition & 2 deletions amd/src/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* RSS Thumbnails block
*
* @package block_rss_thumbnails
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['core/config'], function (cfg) {
define(['core/config'], function(cfg) {
window.requirejs.config({
paths: {
"glide":
Expand Down
7 changes: 3 additions & 4 deletions amd/src/glide.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* RSS Thumbnails block
*
* @package block_rss_thumbnails
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([ 'jquery', 'block_rss_thumbnails/config'], function ($) {
return function (locator, config) {
require(['glide'], function (Glide) {
define(['jquery', 'block_rss_thumbnails/config'], function($) {
return function(locator, config) {
require(['glide'], function(Glide) {
// Show the slider now we are initialised.
$(locator).removeClass('d-none');
new Glide(locator, config).mount();
Expand Down
44 changes: 28 additions & 16 deletions block_rss_thumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use block_rss_client\output\channel_image;
use block_rss_client\output\feed;
use block_rss_thumbnails\output\block;
use block_rss_thumbnails\output\item;

defined('MOODLE_INTERNAL') || die();
global $CFG;
Expand All @@ -37,6 +40,7 @@
*/
class block_rss_thumbnails extends block_rss_client {

/** @var int The default caroussel speed */
const DEFAULT_CAROUSSEL_SPEED = 4000;

/** @var bool track whether any of the output feeds have recorded failures */
Expand All @@ -54,7 +58,7 @@ public function init() {
/**
* Content for the block
*
* @return \stdClass|string|null
* @return stdClass|string|null
* @throws coding_exception
*/
public function get_content() {
Expand All @@ -67,7 +71,7 @@ public function get_content() {
return $this->content;
}

// initalise block content object
// Initialise block content object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vu !

$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
Expand All @@ -78,7 +82,7 @@ public function get_content() {

if (!isset($this->config)) {
// The block has yet to be configured - just display configure message in
// the block if user has permission to configure it
// the block if user has permission to configure it.

if (has_capability('block/rss_client:manageanyfeeds', $this->context)) {
$this->content->text = get_string('feedsconfigurenewinstance2', 'block_rss_client');
Expand Down Expand Up @@ -138,7 +142,7 @@ public function get_content() {
* @param array $feedrecords The feed records from the database.
* @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed.
*/
protected function get_footer($feedrecords) {
protected function get_footer($feedrecords) : ?block_rss_client\output\footer {
$footer = null;

if (!empty($this->config->show_channel_link)) {
Expand Down Expand Up @@ -171,12 +175,12 @@ protected function get_footer($feedrecords) {
/**
* Returns the html of a feed to be displaed in the block
*
* @param mixed feedrecord The feed record from the database
* @param int maxentries The maximum number of entries to be displayed
* @param boolean showtitle Should the feed title be displayed in html
* @param mixed $feedrecord The feed record from the database
* @param int $maxentries The maximum number of entries to be displayed
* @param boolean $showtitle Should the feed title be displayed in html
* @return block_rss_client\output\feed|null The renderable feed or null of there is an error
*/
public function get_feed($feedrecord, $maxentries, $showtitle) {
public function get_feed($feedrecord, $maxentries, $showtitle) : ?feed {
global $CFG;
require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');

Expand All @@ -186,7 +190,15 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
return null;
}

$simplepiefeed = new moodle_simplepie($feedrecord->url);
if (!empty($feedrecord->url)) {
$simplepiefeed = new moodle_simplepie($feedrecord->url);
} else {
$simplepiefeed = new moodle_simplepie();
$simplepiefeed->set_file($feedrecord->fileurl);
$simplepiefeed->enable_cache(false);
$simplepiefeed->init();

}

if (isset($CFG->block_rss_client_timeout)) {
$simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60);
Expand All @@ -209,12 +221,12 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
}

if (empty($this->config->title)) {
//NOTE: this means the 'last feed' displayed wins the block title - but
//this is exiting behaviour..
// NOTE: this means the 'last feed' displayed wins the block title - but
// this is exiting behaviour..
$this->title = strip_tags($feedtitle);
}

$feed = new \block_rss_client\output\feed($feedtitle, $showtitle, false);
$feed = new feed($feedtitle, $showtitle, false);

if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) {
foreach ($simplepieitems as $simplepieitem) {
Expand All @@ -231,7 +243,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
return $cat->term;
}, $simplepieitem->get_categories());

$item = new \block_rss_thumbnails\output\item(
$item = new item(
$simplepieitem->get_id(),
new moodle_url($simplepieitem->get_link()),
$simplepieitem->get_title(),
Expand All @@ -247,7 +259,7 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
} catch (moodle_exception $e) {
// If there is an error with the RSS item, we don't
// want to crash the page. Specifically, moodle_url can
// throw an exception of the param is an extremely
// throw an exception if the param is an extremely
// malformed url.
debugging($e->getMessage());
}
Expand All @@ -257,15 +269,15 @@ public function get_feed($feedrecord, $maxentries, $showtitle) {
// Feed image.
if ($imageurl = $simplepiefeed->get_image_url()) {
try {
$image = new \block_rss_client\output\channel_image(
$image = new channel_image(
new moodle_url($imageurl),
$simplepiefeed->get_image_title(),
new moodle_url($simplepiefeed->get_image_link())
);

$feed->set_image($image);
} catch (moodle_exception $e) {
// If there is an error with the RSS image, we don'twant to
// If there is an error with the RSS image, we don't want to
// crash the page. Specifically, moodle_url can throw an
// exception if the param is an extremely malformed url.
debugging($e->getMessage());
Expand Down
15 changes: 9 additions & 6 deletions classes/output/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/

namespace block_rss_thumbnails\output;
defined('MOODLE_INTERNAL') || die();

use renderer_base;

/**
* Class to help display an RSS Feeds block
Expand All @@ -32,26 +33,28 @@
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block extends \block_rss_client\output\block {
class block extends \block_rss_client\output\block {

protected $carousselspeed = 0;
/** @var int The delay between two slides */
protected int $carousselspeed = 0;
/**
* Contruct
*
* @param int $carousselspeed the caroussel speed of the block
* @param array $feeds An array of renderable feeds
*/
public function __construct($carousselspeed, array $feeds = array()) {
$this->feeds = $feeds;
parent::__construct($feeds);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vu!

$this->carousselspeed = $carousselspeed;
}

/**
* Prepare data for use in a template
*
* @param \renderer_base $output
* @param renderer_base $output
* @return array
*/
public function export_for_template(\renderer_base $output) {
public function export_for_template(renderer_base $output): array {
$data = parent::export_for_template($output);
$data['carousselspeed'] = $this->carousselspeed;
return $data;
Expand Down
Loading