Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   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   * Contains class block_rss_client\output\block_renderer_html
  19   *
  20   * @package   block_rss_client
  21   * @copyright 2015 Howard County Public School System
  22   * @author    Brendan Anderson <brendan_anderson@hcpss.org>
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace block_rss_client\output;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * Renderer for RSS Client block
  32   *
  33   * @package   block_rss_client
  34   * @copyright 2015 Howard County Public School System
  35   * @author    Brendan Anderson <brendan_anderson@hcpss.org>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class renderer extends \plugin_renderer_base {
  39  
  40      /**
  41       * Render an RSS Item
  42       *
  43       * @param templatable $item
  44       * @return string|boolean
  45       */
  46      public function render_item(\templatable $item) {
  47          $data = $item->export_for_template($this);
  48  
  49          return $this->render_from_template('block_rss_client/item', $data);
  50      }
  51  
  52      /**
  53       * Render an RSS Feed
  54       *
  55       * @param templatable $feed
  56       * @return string|boolean
  57       */
  58      public function render_feed(\templatable $feed) {
  59          $data = $feed->export_for_template($this);
  60  
  61          return $this->render_from_template('block_rss_client/feed', $data);
  62      }
  63  
  64      /**
  65       * Render an RSS feeds block
  66       *
  67       * @param \templatable $block
  68       * @return string|boolean
  69       */
  70      public function render_block(\templatable $block) {
  71          $data = $block->export_for_template($this);
  72  
  73          return $this->render_from_template('block_rss_client/block', $data);
  74      }
  75  
  76      /**
  77       * Render the block footer
  78       *
  79       * @param templatable $footer
  80       * @return string|boolean
  81       */
  82      public function render_footer(\templatable $footer) {
  83          $data = $footer->export_for_template($this);
  84  
  85          return $this->render_from_template('block_rss_client/footer', $data);
  86      }
  87  
  88      /**
  89       * Format a timestamp to use as a published date
  90       *
  91       * @param int $timestamp Unix timestamp
  92       * @return string
  93       */
  94      public function format_published_date($timestamp) {
  95          if (empty($timestamp)) {
  96              return '';
  97          } else {
  98              return \core_date::strftime(get_string('strftimerecentfull', 'langconfig'), $timestamp);
  99          }
 100      }
 101  
 102      /**
 103       * Format an RSS item title
 104       *
 105       * @param string $title
 106       * @return string
 107       */
 108      public function format_title($title) {
 109          return break_up_long_words($title, 30);
 110      }
 111  
 112      /**
 113       * Format an RSS item description
 114       *
 115       * @param string $description
 116       * @return string
 117       */
 118      public function format_description($description) {
 119          $description = format_text($description, FORMAT_HTML, array('para' => false));
 120          $description = break_up_long_words($description, 30);
 121  
 122          return $description;
 123      }
 124  }