Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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          return strftime(get_string('strftimerecentfull', 'langconfig'), $timestamp);
  96          return date('j F Y, g:i a', $timestamp);
  97      }
  98  
  99      /**
 100       * Format an RSS item title
 101       *
 102       * @param string $title
 103       * @return string
 104       */
 105      public function format_title($title) {
 106          return break_up_long_words($title, 30);
 107      }
 108  
 109      /**
 110       * Format an RSS item description
 111       *
 112       * @param string $description
 113       * @return string
 114       */
 115      public function format_description($description) {
 116          $description = format_text($description, FORMAT_HTML, array('para' => false));
 117          $description = break_up_long_words($description, 30);
 118  
 119          return $description;
 120      }
 121  }