[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/feed/ -> helper.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\feed;
  15  
  16  use phpbb\config\config;
  17  use phpbb\path_helper;
  18  use phpbb\textformatter\s9e\renderer;
  19  use phpbb\user;
  20  use Symfony\Component\DependencyInjection\ContainerInterface;
  21  
  22  /**
  23   * Class with some helpful functions used in feeds
  24   */
  25  class helper
  26  {
  27      /** @var config */
  28      protected $config;
  29  
  30      /** @var ContainerInterface */
  31      protected $container;
  32  
  33      /** @var path_helper */
  34      protected $path_helper;
  35  
  36      /** @var renderer */
  37      protected $renderer;
  38  
  39      /** @var user */
  40      protected $user;
  41  
  42      /**
  43       * Constructor
  44       *
  45       * @param    config                $config            Config object
  46       * @param    ContainerInterface    $container        Service container object
  47       * @param    path_helper            $path_helper     Path helper object
  48       * @param    renderer            $renderer        TextFormatter renderer object
  49       * @param    user                $user            User object
  50       */
  51  	public function __construct(config $config, ContainerInterface $container, path_helper $path_helper, renderer $renderer, user $user)
  52      {
  53          $this->config = $config;
  54          $this->container = $container;
  55          $this->path_helper = $path_helper;
  56          $this->renderer = $renderer;
  57          $this->user = $user;
  58      }
  59  
  60      /**
  61       * Returns the board url (and caches it in the function)
  62       */
  63  	public function get_board_url()
  64      {
  65          static $board_url;
  66  
  67          if (empty($board_url))
  68          {
  69              $board_url = generate_board_url();
  70          }
  71  
  72          return $board_url;
  73      }
  74  
  75      /**
  76       * Run links through append_sid(), prepend generate_board_url() and remove session id
  77       */
  78  	public function append_sid($url, $params)
  79      {
  80          return append_sid($this->get_board_url() . '/' . $url, $params, true, '');
  81      }
  82  
  83      /**
  84       * Generate ISO 8601 date string (RFC 3339)
  85       */
  86  	public function format_date($time)
  87      {
  88          static $zone_offset;
  89          static $offset_string;
  90  
  91          if (empty($offset_string))
  92          {
  93              $zone_offset = $this->user->create_datetime()->getOffset();
  94              $offset_string = phpbb_format_timezone_offset($zone_offset);
  95          }
  96  
  97          return gmdate("Y-m-d\TH:i:s", $time + $zone_offset) . $offset_string;
  98      }
  99  
 100      /**
 101       * Generate text content
 102       *
 103       * @param string $content is feed text content
 104       * @param string $uid is bbcode_uid
 105       * @param string $bitfield is bbcode bitfield
 106       * @param int $options bbcode flag options
 107       * @param int $forum_id is the forum id
 108       * @param array $post_attachments is an array containing the attachments and their respective info
 109       * @return string the html content to be printed for the feed
 110       */
 111  	public function generate_content($content, $uid, $bitfield, $options, $forum_id, $post_attachments)
 112      {
 113          if (empty($content))
 114          {
 115              return '';
 116          }
 117  
 118          // Setup our own quote_helper to remove all attributes from quotes
 119          $this->renderer->configure_quote_helper($this->container->get('feed.quote_helper'));
 120  
 121          $this->renderer->set_smilies_path($this->get_board_url() . '/' . $this->config['smilies_path']);
 122  
 123          $content = generate_text_for_display($content, $uid, $bitfield, $options);
 124  
 125          // Remove "Select all" link and mouse events
 126          $content = str_replace('<a href="#" onclick="selectCode(this); return false;">' . $this->user->lang['SELECT_ALL_CODE'] . '</a>', '', $content);
 127          $content = preg_replace('#(onkeypress|onclick)="(.*?)"#si', '', $content);
 128  
 129          // Firefox does not support CSS for feeds, though
 130  
 131          // Remove font sizes
 132          //    $content = preg_replace('#<span style="font-size: [0-9]+%; line-height: [0-9]+%;">([^>]+)</span>#iU', '\1', $content);
 133  
 134          // Make text strong :P
 135          //    $content = preg_replace('#<span style="font-weight: bold?">(.*?)</span>#iU', '<strong>\1</strong>', $content);
 136  
 137          // Italic
 138          //    $content = preg_replace('#<span style="font-style: italic?">([^<]+)</span>#iU', '<em>\1</em>', $content);
 139  
 140          // Underline
 141          //    $content = preg_replace('#<span style="text-decoration: underline?">([^<]+)</span>#iU', '<u>\1</u>', $content);
 142  
 143          // Remove embed Windows Media Streams
 144          $content    = preg_replace( '#<\!--\[if \!IE\]>-->([^[]+)<\!--<!\[endif\]-->#si', '', $content);
 145  
 146          // Do not use &lt; and &gt;, because we want to retain code contained in [code][/code]
 147  
 148          // Remove embed and objects
 149          $content    = preg_replace( '#<(object|embed)(.*?) (value|src)=(.*?) ([^[]+)(object|embed)>#si',' <a href=$4 target="_blank"><strong>$1</strong></a> ',$content);
 150  
 151          // Remove some specials html tag, because somewhere there are a mod to allow html tags ;)
 152          $content    = preg_replace( '#<(script|iframe)([^[]+)\1>#siU', ' <strong>$1</strong> ', $content);
 153  
 154          // Parse inline images to display with the feed
 155          if (!empty($post_attachments))
 156          {
 157              $update_count = array();
 158              parse_attachments($forum_id, $content, $post_attachments, $update_count);
 159              $content .= implode('<br />', $post_attachments);
 160  
 161              // Convert attachments' relative path to absolute path
 162              $content = str_replace($this->path_helper->get_web_root_path() . 'download/file.' . $this->path_helper->get_php_ext(), $this->get_board_url() . '/download/file.' . $this->path_helper->get_php_ext(), $content);
 163          }
 164  
 165          // Remove Comments from inline attachments [ia]
 166          $content = preg_replace('#<dd>(.*?)</dd>#','',$content);
 167  
 168          // Replace some entities with their unicode counterpart
 169          $entities = array(
 170              '&nbsp;'    => "\xC2\xA0",
 171              '&bull;'    => "\xE2\x80\xA2",
 172              '&middot;'    => "\xC2\xB7",
 173              '&copy;'    => "\xC2\xA9",
 174          );
 175  
 176          $content = str_replace(array_keys($entities), array_values($entities), $content);
 177  
 178          // Remove CDATA blocks. ;)
 179          $content = preg_replace('#\<\!\[CDATA\[(.*?)\]\]\>#s', '', $content);
 180  
 181          // Other control characters
 182          $content = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $content);
 183  
 184          return $content;
 185      }
 186  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1