[ Index ]

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


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1