Skip to content

Commit 8574ef8

Browse files
Last fixes (#11)
* Fix invalid config, still have to implement the test isvalid * Separated the class edit into a single class name feed_edit - fixes #6 * Added namespaces for editfeed and form/feed_edit - fixes #5 * Added thirdpartylibs.xml - fixes #3 * Added a check at the start of block_rss_thumbnails::get_content so the method will no longer compute twice - fixes #4 * moodle-plugin-ci validation * Added an upgrade script to ensure keeping block configurations between versions Fixes #8 * Fix caroussel delay & Footer: * Fixed caroussel delay always setting up to default value - Fixes #10 * Added a footer template * Fix multiple feed selection - Fixes #9 * Validated moodle plugin ci * Fixed merge issues * Fix phpdoc * Updated release number
1 parent bb5b58a commit 8574ef8

File tree

7 files changed

+56
-35
lines changed

7 files changed

+56
-35
lines changed

amd/build/glide.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/glide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ define(['jquery', 'block_rss_thumbnails/config'], function($) {
1313
new Glide(locator, config).mount();
1414
});
1515
};
16-
});
16+
});

block_rss_thumbnails.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,16 @@ class block_rss_thumbnails extends block_base {
5151
/** @var int The maximum number of item entries for a feed by default */
5252
const DEFAULT_MAX_ENTRIES = 5;
5353

54-
5554
/** @var bool Track whether any of the output feeds have recorded failures */
5655
private $hasfailedfeeds = false;
5756

58-
/** @var int Defines the delay between two slides of the caroussel (ms) */
59-
private $carousseldelay = self::DEFAULT_CAROUSSEL_DELAY;
60-
6157
/** @var int Defines the number of maximum feeds in the thumbnail */
6258
private $maxentries = self::DEFAULT_MAX_ENTRIES;
6359

64-
6560
/**
6661
* Init function
67-
*
68-
* @param int|null $carousseldelay
69-
* @throws coding_exception
7062
*/
71-
public function init(?int $carousseldelay = null): void {
72-
73-
if (!empty($carousseldelay)) {
74-
$this->carousseldelay = $carousseldelay;
75-
}
63+
public function init(): void {
7664

7765
$this->title = get_string('pluginname', 'block_rss_thumbnails');
7866

@@ -114,8 +102,8 @@ public function get_content() {
114102

115103
return $this->content;
116104
}
117-
118-
$block = new block($this->get_carousseldelay());
105+
$carousseldelay = $this->config->carousseldelay ?? self::DEFAULT_CAROUSSEL_DELAY;
106+
$block = new block($carousseldelay);
119107

120108
if (!empty($this->config->rssid)) {
121109
list($rssidssql, $params) = $DB->get_in_or_equal($this->config->rssid);
@@ -136,8 +124,8 @@ public function get_content() {
136124
$renderer = $this->page->get_renderer('block_rss_thumbnails');
137125

138126
$this->content = (object) [
139-
'text' => $renderer->render($block, $rssfeeds),
140-
'footer' => $footer ?? ''
127+
'text' => $renderer->render($block, $rssfeeds),
128+
'footer' => $footer ? $renderer->render($footer) : ''
141129
];
142130
return $this->content;
143131
}
@@ -154,8 +142,7 @@ protected function get_footer($feedrecords, $maxentries = self::DEFAULT_MAX_ENTR
154142

155143
if (!empty($this->config->show_channel_link)) {
156144
$feedrecord = array_pop($feedrecords);
157-
$feed = feed_creator::create_feed(file_get_contents($feedrecord->url), $maxentries);
158-
$channellink = new moodle_url($feed->get_link());
145+
$channellink = new moodle_url($feedrecord->url);
159146

160147
if (!empty($channellink)) {
161148
$footer = new footer($channellink);
@@ -170,7 +157,7 @@ protected function get_footer($feedrecords, $maxentries = self::DEFAULT_MAX_ENTR
170157
$footer = new footer();
171158
}
172159
$manageurl = new moodle_url('/blocks/rss_thumbnails/managefeeds.php',
173-
['courseid' => $this->page->course->id]);
160+
['courseid' => $this->page->course->id]);
174161
$footer->set_failed($manageurl);
175162
}
176163
}
@@ -211,15 +198,6 @@ public function format_title($title, $max = 64): string {
211198
return (core_text::strlen($title) <= $max) ? $title : core_text::substr($title, 0, $max - 3) . '...';
212199
}
213200

214-
/**
215-
* Gets the caroussel delay between two slides
216-
*
217-
* @return int
218-
*/
219-
public function get_carousseldelay(): int {
220-
return $this->carousseldelay;
221-
}
222-
223201
/**
224202
* Checks wether the configuration of the block is valid or not.
225203
*

edit_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function specific_definition($mform) {
9696
get_string('choosefeedlabel', 'block_rss_thumbnails'),
9797
$rssfeeds
9898
);
99-
$select->setMultiple(true);
99+
$select->setMultiple(false);
100100
} else {
101101
$mform->addElement('static', 'config_rssid_no_feeds', get_string('choosefeedlabel', 'block_rss_thumbnails'),
102102
get_string('nofeeds', 'block_rss_thumbnails'));

templates/block.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
Example context (json):
3232
{
33-
"carousseldelay" : 10,
33+
"carousseldelay" : 100,
3434
"feeds": [
3535
{
3636
"title": "News from around my living room",

templates/footer.mustache

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{{!
2+
This file is part of Moodle - http://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template block_rss_thumbnails/block
19+
20+
Template which defines an RSS Feeds block
21+
22+
Classes required for JS:
23+
* none
24+
25+
Data attributes required for JS:
26+
* none
27+
28+
Context variables required for this template:
29+
* feeds - array: An array of RSS feeds.
30+
31+
Example context (json):
32+
{
33+
"channellink": "https://moodle.org",
34+
"hasfailedfeeds": true,
35+
"manageurl": "https://example.com"
36+
}
37+
}}
38+
<div id="footer">
39+
<a href="{{ channellink }}">Source site</a>
40+
{{#hasfailedfeeds}}
41+
<p>You have some failed feeds. You can <a href="{{manageurl}}">manage your feeds</a> to try to fix this.</p>
42+
{{/hasfailedfeeds}}
43+
</div>

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

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

27-
$plugin->version = 2022120700; // The current plugin version (Date: YYYYMMDDXX).
27+
$plugin->version = 2022120900; // The current plugin version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2012112900; // Requires this Moodle version.
29-
$plugin->release = 1.0;
29+
$plugin->release = 1.1;
3030
$plugin->maturity = MATURITY_STABLE;
3131
$plugin->component = 'block_rss_thumbnails'; // Full name of the plugin (used for diagnostics).
3232
$plugin->dependencies = [];

0 commit comments

Comments
 (0)