first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
<?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/>.
/**
* Contains class block_rss_client\output\block
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Class to help display an RSS Feeds block
*
* @package block_rss_client
* @copyright 2016 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block implements \renderable, \templatable {
/**
* An array of renderable feeds
*
* @var array
*/
protected $feeds;
/**
* Contruct
*
* @param array $feeds An array of renderable feeds
*/
public function __construct(array $feeds = array()) {
$this->feeds = $feeds;
}
/**
* Prepare data for use in a template
*
* @param \renderer_base $output
* @return array
*/
public function export_for_template(\renderer_base $output) {
$data = array('feeds' => array());
foreach ($this->feeds as $feed) {
$data['feeds'][] = $feed->export_for_template($output);
}
return $data;
}
/**
* Add a feed
*
* @param \block_rss_client\output\feed $feed
* @return \block_rss_client\output\block
*/
public function add_feed(feed $feed) {
$this->feeds[] = $feed;
return $this;
}
/**
* Set the feeds
*
* @param array $feeds
* @return \block_rss_client\output\block
*/
public function set_feeds(array $feeds) {
$this->feeds = $feeds;
return $this;
}
/**
* Get feeds
*
* @return array
*/
public function get_feeds() {
return $this->feeds;
}
}
@@ -0,0 +1,151 @@
<?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/>.
/**
* Contains class block_rss_client\output\channel_image
*
* @package block_rss_client
* @copyright 2016 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Class to display RSS channel images
*
* @package block_rss_client
* @copyright 2016 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class channel_image implements \renderable, \templatable {
/**
* The URL location of the image
*
* @var string
*/
protected $url;
/**
* The title of the image
*
* @var string
*/
protected $title;
/**
* The URL of the image link
*
* @var string
*/
protected $link;
/**
* Contructor
*
* @param \moodle_url $url The URL location of the image
* @param string $title The title of the image
* @param \moodle_url $link The URL of the image link
*/
public function __construct(\moodle_url $url, $title, \moodle_url $link = null) {
$this->url = $url;
$this->title = $title;
$this->link = $link;
}
/**
* Export this for use in a mustache template context.
*
* @see templatable::export_for_template()
* @param renderer_base $output
* @return array The data for the template
*/
public function export_for_template(\renderer_base $output) {
return array(
'url' => clean_param($this->url, PARAM_URL),
'title' => $this->title,
'link' => clean_param($this->link, PARAM_URL),
);
}
/**
* Set the URL
*
* @param \moodle_url $url
* @return \block_rss_client\output\channel_image
*/
public function set_url(\moodle_url $url) {
$this->url = $url;
return $this;
}
/**
* Get the URL
*
* @return \moodle_url
*/
public function get_url() {
return $this->url;
}
/**
* Set the title
*
* @param string $title
* @return \block_rss_client\output\channel_image
*/
public function set_title($title) {
$this->title = $title;
return $this;
}
/**
* Get the title
*
* @return string
*/
public function get_title() {
return $this->title;
}
/**
* Set the link
*
* @param \moodle_url $link
* @return \block_rss_client\output\channel_image
*/
public function set_link($link) {
$this->link = $link;
return $this;
}
/**
* Get the link
*
* @return \moodle_url
*/
public function get_link() {
return $this->link;
}
}
+224
View File
@@ -0,0 +1,224 @@
<?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/>.
/**
* Contains class block_rss_client\output\feed
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Class to help display an RSS Feed
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class feed implements \renderable, \templatable {
/**
* The feed's title
*
* @var string
*/
protected $title = null;
/**
* An array of renderable feed items
*
* @var array
*/
protected $items = array();
/**
* The channel image
*
* @var channel_image
*/
protected $image = null;
/**
* Whether or not to show the title
*
* @var boolean
*/
protected $showtitle;
/**
* Whether or not to show the channel image
*
* @var boolean
*/
protected $showimage;
/**
* Contructor
*
* @param string $title The title of the RSS feed
* @param boolean $showtitle Whether to show the title
* @param boolean $showimage Whether to show the channel image
*/
public function __construct($title, $showtitle = true, $showimage = true) {
$this->title = $title;
$this->showtitle = $showtitle;
$this->showimage = $showimage;
}
/**
* Export this for use in a mustache template context.
*
* @see templatable::export_for_template()
* @param \renderer_base $output
* @return array
*/
public function export_for_template(\renderer_base $output) {
$data = array(
'title' => $this->showtitle ? $this->title : null,
'image' => null,
'items' => array(),
);
if ($this->showimage && $this->image) {
$data['image'] = $this->image->export_for_template($output);
}
foreach ($this->items as $item) {
$data['items'][] = $item->export_for_template($output);
}
return $data;
}
/**
* Set the feed title
*
* @param string $title
* @return \block_rss_client\output\feed
*/
public function set_title($title) {
$this->title = $title;
return $this;
}
/**
* Get the feed title
*
* @return string
*/
public function get_title() {
return $this->title;
}
/**
* Add an RSS item
*
* @param \block_rss_client\output\item $item
*/
public function add_item(item $item) {
$this->items[] = $item;
return $this;
}
/**
* Set the RSS items
*
* @param array $items An array of renderable RSS items
*/
public function set_items(array $items) {
$this->items = $items;
return $this;
}
/**
* Get the RSS items
*
* @return array An array of renderable RSS items
*/
public function get_items() {
return $this->items;
}
/**
* Set the channel image
*
* @param \block_rss_client\output\channel_image $image
*/
public function set_image(channel_image $image) {
$this->image = $image;
}
/**
* Get the channel image
*
* @return channel_image
*/
public function get_image() {
return $this->image;
}
/**
* Set showtitle
*
* @param boolean $showtitle
* @return \block_rss_client\output\feed
*/
public function set_showtitle($showtitle) {
$this->showtitle = boolval($showtitle);
return $this;
}
/**
* Get showtitle
*
* @return boolean
*/
public function get_showtitle() {
return $this->showtitle;
}
/**
* Set showimage
*
* @param boolean $showimage
* @return \block_rss_client\output\feed
*/
public function set_showimage($showimage) {
$this->showimage = boolval($showimage);
return $this;
}
/**
* Get showimage
*
* @return boolean
*/
public function get_showimage() {
return $this->showimage;
}
}
+111
View File
@@ -0,0 +1,111 @@
<?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/>.
/**
* Contains class block_rss_client\output\footer
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Class to help display an RSS Block footer
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class footer implements \renderable, \templatable {
/**
* The link provided in the RSS channel
*
* @var \moodle_url|null
*/
protected $channelurl;
/**
* Link to manage feeds, only provided if a feed has failed.
*
* @var \moodle_url|null
*/
protected $manageurl = null;
/**
* Constructor
*
* @param \moodle_url $channelurl (optional) The link provided in the RSS channel
*/
public function __construct($channelurl = null) {
$this->channelurl = $channelurl;
}
/**
* Set the channel url
*
* @param \moodle_url $channelurl
* @return \block_rss_client\output\footer
*/
public function set_channelurl(\moodle_url $channelurl) {
$this->channelurl = $channelurl;
return $this;
}
/**
* Record the fact that there is at least one failed feed (and the URL for viewing
* these failed feeds).
*
* @param \moodle_url $manageurl the URL to link to for more information
*/
public function set_failed(\moodle_url $manageurl) {
$this->manageurl = $manageurl;
}
/**
* Get the channel url
*
* @return \moodle_url
*/
public function get_channelurl() {
return $this->channelurl;
}
/**
* Export context for use in mustache templates
*
* @see templatable::export_for_template()
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
$data->channellink = clean_param($this->channelurl, PARAM_URL);
if ($this->manageurl) {
$data->hasfailedfeeds = true;
$data->manageurl = clean_param($this->manageurl, PARAM_URL);
}
return $data;
}
}
+286
View File
@@ -0,0 +1,286 @@
<?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/>.
/**
* Contains class block_rss_client\output\feed
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Class to help display an RSS Item
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class item implements \renderable, \templatable {
/**
* The unique id of the item
*
* @var string
*/
protected $id;
/**
* The link to the item
*
* @var \moodle_url
*/
protected $link;
/**
* The title of the item
*
* @var string
*/
protected $title;
/**
* The description of the item
*
* @var string
*/
protected $description;
/**
* The item's permalink
*
* @var \moodle_url
*/
protected $permalink;
/**
* The publish date of the item in Unix timestamp format
*
* @var int
*/
protected $timestamp;
/**
* Whether or not to show the item's description
*
* @var string
*/
protected $showdescription;
/**
* Contructor
*
* @param string $id The id of the RSS item
* @param \moodle_url $link The URL of the RSS item
* @param string $title The title pf the RSS item
* @param string $description The description of the RSS item
* @param \moodle_url $permalink The permalink of the RSS item
* @param int $timestamp The Unix timestamp that represents the published date
* @param boolean $showdescription Whether or not to show the description
*/
public function __construct($id, \moodle_url $link, $title, $description, \moodle_url $permalink, $timestamp,
$showdescription = true) {
$this->id = $id;
$this->link = $link;
$this->title = $title;
$this->description = $description;
$this->permalink = $permalink;
$this->timestamp = $timestamp;
$this->showdescription = $showdescription;
}
/**
* Export context for use in mustache templates
*
* @see templatable::export_for_template()
* @param \renderer_base $output
* @return array
*/
public function export_for_template(\renderer_base $output) {
$data = array(
'id' => $this->id,
'permalink' => clean_param($this->permalink, PARAM_URL),
'datepublished' => $output->format_published_date($this->timestamp),
'link' => clean_param($this->link, PARAM_URL),
);
// If the item does not have a title, create one from the description.
$title = $this->title;
if (!$title) {
$title = strip_tags($this->description);
$title = \core_text::substr($title, 0, 20) . '...';
}
// Allow the renderer to format the title and description.
$data['title'] = strip_tags($output->format_title($title));
$data['description'] = $this->showdescription ? $output->format_description($this->description) : null;
return $data;
}
/**
* Set id
*
* @param string $id
* @return \block_rss_client\output\item
*/
public function set_id($id) {
$this->id = $id;
return $this;
}
/**
* Get id
*
* @return string
*/
public function get_id() {
return $this->id;
}
/**
* Set link
*
* @param \moodle_url $link
* @return \block_rss_client\output\item
*/
public function set_link(\moodle_url $link) {
$this->link = $link;
return $this;
}
/**
* Get link
*
* @return \moodle_url
*/
public function get_link() {
return $this->link;
}
/**
* Set title
*
* @param string $title
* @return \block_rss_client\output\item
*/
public function set_title($title) {
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function get_title() {
return $this->title;
}
/**
* Set description
*
* @param string $description
* @return \block_rss_client\output\item
*/
public function set_description($description) {
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function get_description() {
return $this->description;
}
/**
* Set permalink
*
* @param string $permalink
* @return \block_rss_client\output\item
*/
public function set_permalink($permalink) {
$this->permalink = $permalink;
return $this;
}
/**
* Get permalink
*
* @return string
*/
public function get_permalink() {
return $this->permalink;
}
/**
* Set timestamp
*
* @param int $timestamp
* @return \block_rss_client\output\item
*/
public function set_timestamp($timestamp) {
$this->timestamp = $timestamp;
return $this;
}
/**
* Get timestamp
*
* @return string
*/
public function get_timestamp() {
return $this->timestamp;
}
/**
* Set showdescription
*
* @param boolean $showdescription
* @return \block_rss_client\output\item
*/
public function set_showdescription($showdescription) {
$this->showdescription = boolval($showdescription);
return $this;
}
/**
* Get showdescription
*
* @return boolean
*/
public function get_showdescription() {
return $this->showdescription;
}
}
@@ -0,0 +1,124 @@
<?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/>.
/**
* Contains class block_rss_client\output\block_renderer_html
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_rss_client\output;
defined('MOODLE_INTERNAL') || die();
/**
* Renderer for RSS Client block
*
* @package block_rss_client
* @copyright 2015 Howard County Public School System
* @author Brendan Anderson <brendan_anderson@hcpss.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \plugin_renderer_base {
/**
* Render an RSS Item
*
* @param \templatable $item
* @return string
*/
public function render_item(\templatable $item) {
$data = $item->export_for_template($this);
return $this->render_from_template('block_rss_client/item', $data);
}
/**
* Render an RSS Feed
*
* @param \templatable $feed
* @return string
*/
public function render_feed(\templatable $feed) {
$data = $feed->export_for_template($this);
return $this->render_from_template('block_rss_client/feed', $data);
}
/**
* Render an RSS feeds block
*
* @param \templatable $block
* @return string
*/
public function render_block(\templatable $block) {
$data = $block->export_for_template($this);
return $this->render_from_template('block_rss_client/block', $data);
}
/**
* Render the block footer
*
* @param \templatable $footer
* @return string
*/
public function render_footer(\templatable $footer) {
$data = $footer->export_for_template($this);
return $this->render_from_template('block_rss_client/footer', $data);
}
/**
* Format a timestamp to use as a published date
*
* @param int $timestamp Unix timestamp
* @return string
*/
public function format_published_date($timestamp) {
if (empty($timestamp)) {
return '';
} else {
return \core_date::strftime(get_string('strftimerecentfull', 'langconfig'), $timestamp);
}
}
/**
* Format an RSS item title
*
* @param string $title
* @return string
*/
public function format_title($title) {
return break_up_long_words($title, 30);
}
/**
* Format an RSS item description
*
* @param string $description
* @return string
*/
public function format_description($description) {
$description = format_text($description, FORMAT_HTML, array('para' => false));
$description = break_up_long_words($description, 30);
return $description;
}
}