Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

feed.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 10.29 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\feed\controller;
 015   
 016  use phpbb\auth\auth;
 017  use phpbb\config\config;
 018  use phpbb\db\driver\driver_interface;
 019  use \phpbb\event\dispatcher_interface;
 020  use phpbb\exception\http_exception;
 021  use phpbb\feed\feed_interface;
 022  use phpbb\feed\exception\feed_unavailable_exception;
 023  use phpbb\feed\exception\unauthorized_exception;
 024  use phpbb\feed\helper as feed_helper;
 025  use phpbb\controller\helper as controller_helper;
 026  use phpbb\symfony_request;
 027  use phpbb\user;
 028  use Symfony\Component\DependencyInjection\ContainerInterface;
 029  use Symfony\Component\HttpFoundation\Response;
 030  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 031   
 032  class feed
 033  {
 034      /**
 035       * @var \Twig_Environment
 036       */
 037      protected $template;
 038   
 039      /**
 040       * @var symfony_request
 041       */
 042      protected $request;
 043   
 044      /**
 045       * @var controller_helper
 046       */
 047      protected $controller_helper;
 048   
 049      /**
 050       * @var config
 051       */
 052      protected $config;
 053   
 054      /**
 055       * @var driver_interface
 056       */
 057      protected $db;
 058   
 059      /**
 060       * @var ContainerInterface
 061       */
 062      protected $container;
 063   
 064      /**
 065       * @var feed_helper
 066       */
 067      protected $feed_helper;
 068   
 069      /**
 070       * @var user
 071       */
 072      protected $user;
 073   
 074      /**
 075       * @var auth
 076       */
 077      protected $auth;
 078   
 079      /**
 080       * @var dispatcher_interface
 081       */
 082      protected $phpbb_dispatcher;
 083   
 084      /**
 085       * @var string
 086       */
 087      protected $php_ext;
 088   
 089      /**
 090       * Constructor
 091       *
 092       * @param \Twig_Environment $twig
 093       * @param symfony_request $request
 094       * @param controller_helper $controller_helper
 095       * @param config $config
 096       * @param driver_interface $db
 097       * @param ContainerInterface $container
 098       * @param feed_helper $feed_helper
 099       * @param user $user
 100       * @param auth $auth
 101       * @param dispatcher_interface $phpbb_dispatcher
 102       * @param string $php_ext
 103       */
 104      public function __construct(\Twig_Environment $twig, symfony_request $request, controller_helper $controller_helper, config $config, driver_interface $db, ContainerInterface $container, feed_helper $feed_helper, user $user, auth $auth, dispatcher_interface $phpbb_dispatcher, $php_ext)
 105      {
 106          $this->request = $request;
 107          $this->controller_helper = $controller_helper;
 108          $this->config = $config;
 109          $this->db = $db;
 110          $this->container = $container;
 111          $this->feed_helper = $feed_helper;
 112          $this->user = $user;
 113          $this->auth = $auth;
 114          $this->php_ext = $php_ext;
 115          $this->template = $twig;
 116          $this->phpbb_dispatcher = $phpbb_dispatcher;
 117      }
 118   
 119      /**
 120       * Controller for /feed/forums route
 121       *
 122       * @return Response
 123       *
 124       * @throws http_exception when the feed is disabled
 125       */
 126      public function forums()
 127      {
 128          if (!$this->config['feed_overall_forums'])
 129          {
 130              $this->send_unavailable();
 131          }
 132   
 133          return $this->send_feed($this->container->get('feed.forums'));
 134      }
 135   
 136      /**
 137       * Controller for /feed/news route
 138       *
 139       * @return Response
 140       *
 141       * @throws http_exception when the feed is disabled
 142       */
 143      public function news()
 144      {
 145          // Get at least one news forum
 146          $sql = 'SELECT forum_id
 147                      FROM ' . FORUMS_TABLE . '
 148                      WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
 149          $result = $this->db->sql_query_limit($sql, 1, 0, 600);
 150          $s_feed_news = (int) $this->db->sql_fetchfield('forum_id');
 151          $this->db->sql_freeresult($result);
 152   
 153          if (!$s_feed_news)
 154          {
 155              $this->send_unavailable();
 156          }
 157   
 158          return $this->send_feed($this->container->get('feed.news'));
 159      }
 160   
 161      /**
 162       * Controller for /feed/topics route
 163       *
 164       * @return Response
 165       *
 166       * @throws http_exception when the feed is disabled
 167       */
 168      public function topics()
 169      {
 170          if (!$this->config['feed_topics_new'])
 171          {
 172              $this->send_unavailable();
 173          }
 174   
 175          return $this->send_feed($this->container->get('feed.topics'));
 176      }
 177   
 178      /**
 179       * Controller for /feed/topics_new route
 180       *
 181       * @return Response
 182       *
 183       * @throws http_exception when the feed is disabled
 184       */
 185      public function topics_new()
 186      {
 187          return $this->topics();
 188      }
 189   
 190      /**
 191       * Controller for /feed/topics_active route
 192       *
 193       * @return Response
 194       *
 195       * @throws http_exception when the feed is disabled
 196       */
 197      public function topics_active()
 198      {
 199          if (!$this->config['feed_topics_active'])
 200          {
 201              $this->send_unavailable();
 202          }
 203   
 204          return $this->send_feed($this->container->get('feed.topics_active'));
 205      }
 206   
 207      /**
 208       * Controller for /feed/forum/{forum_id} route
 209       *
 210       * @param int $forum_id
 211       *
 212       * @return Response
 213       *
 214       * @throws http_exception when the feed is disabled
 215       */
 216      public function forum($forum_id)
 217      {
 218          if (!$this->config['feed_forum'])
 219          {
 220              $this->send_unavailable();
 221          }
 222   
 223          return $this->send_feed($this->container->get('feed.forum')->set_forum_id($forum_id));
 224      }
 225   
 226      /**
 227       * Controller for /feed/topic/{topic_id} route
 228       *
 229       * @param int $topic_id
 230       *
 231       * @return Response
 232       *
 233       * @throws http_exception when the feed is disabled
 234       */
 235      public function topic($topic_id)
 236      {
 237          if (!$this->config['feed_topic'])
 238          {
 239              $this->send_unavailable();
 240          }
 241   
 242          return $this->send_feed($this->container->get('feed.topic')->set_topic_id($topic_id));
 243      }
 244   
 245      /**
 246       * Controller for /feed/{mode] route
 247       *
 248       * @return Response
 249       *
 250       * @throws http_exception when the feed is disabled
 251       */
 252      public function overall()
 253      {
 254          if (!$this->config['feed_overall'])
 255          {
 256              $this->send_unavailable();
 257          }
 258   
 259          return $this->send_feed($this->container->get('feed.overall'));
 260      }
 261   
 262      /**
 263       * Display a given feed
 264       *
 265       * @param feed_interface $feed
 266       *
 267       * @return Response
 268       */
 269      protected function send_feed(feed_interface $feed)
 270      {
 271          try
 272          {
 273              return $this->send_feed_do($feed);
 274          }
 275          catch (feed_unavailable_exception $e)
 276          {
 277              throw new http_exception(Response::HTTP_NOT_FOUND, $e->getMessage(), $e->get_parameters(), $e);
 278          }
 279          catch (unauthorized_exception $e)
 280          {
 281              throw new http_exception(Response::HTTP_FORBIDDEN, $e->getMessage(), $e->get_parameters(), $e);
 282          }
 283      }
 284   
 285      /**
 286       * Really send the feed
 287       *
 288       * @param feed_interface $feed
 289       *
 290       * @return Response
 291       *
 292       * @throw exception\feed_exception
 293       */
 294      protected function send_feed_do(feed_interface $feed)
 295      {
 296          $feed_updated_time = 0;
 297          $item_vars = array();
 298   
 299          $board_url = $this->feed_helper->get_board_url();
 300   
 301          // Open Feed
 302          $feed->open();
 303   
 304          // Iterate through items
 305          while ($row = $feed->get_item())
 306          {
 307              /**
 308               * Event to modify the feed row
 309               *
 310               * @event core.feed_modify_feed_row
 311               * @var    int        forum_id    Forum ID
 312               * @var    string    mode        Feeds mode (forums|topics|topics_new|topics_active|news)
 313               * @var    array    row            Array with feed data
 314               * @var    int        topic_id    Topic ID
 315               *
 316               * @since 3.1.10-RC1
 317               */
 318              $vars = array('forum_id', 'mode', 'row', 'topic_id');
 319              extract($this->phpbb_dispatcher->trigger_event('core.feed_modify_feed_row', compact($vars)));
 320   
 321              // BBCode options to correctly disable urls, smilies, bbcode...
 322              if ($feed->get('options') === null)
 323              {
 324                  // Allow all combinations
 325                  $options = 7;
 326   
 327                  if ($feed->get('enable_bbcode') !== null && $feed->get('enable_smilies') !== null && $feed->get('enable_magic_url') !== null)
 328                  {
 329                      $options = (($row[$feed->get('enable_bbcode')]) ? OPTION_FLAG_BBCODE : 0) + (($row[$feed->get('enable_smilies')]) ? OPTION_FLAG_SMILIES : 0) + (($row[$feed->get('enable_magic_url')]) ? OPTION_FLAG_LINKS : 0);
 330                  }
 331              }
 332              else
 333              {
 334                  $options = $row[$feed->get('options')];
 335              }
 336   
 337              $title = (isset($row[$feed->get('title')]) && $row[$feed->get('title')] !== '') ? $row[$feed->get('title')] : ((isset($row[$feed->get('title2')])) ? $row[$feed->get('title2')] : '');
 338   
 339              $published = ($feed->get('published') !== null) ? (int) $row[$feed->get('published')] : 0;
 340              $updated = ($feed->get('updated') !== null) ? (int) $row[$feed->get('updated')] : 0;
 341   
 342              $display_attachments = ($this->auth->acl_get('u_download') && $this->auth->acl_get('f_download', $row['forum_id']) && isset($row['post_attachment']) && $row['post_attachment']) ? true : false;
 343   
 344              $item_row = array(
 345                  'author'        => ($feed->get('creator') !== null) ? $row[$feed->get('creator')] : '',
 346                  'published'        => ($published > 0) ? $this->feed_helper->format_date($published) : '',
 347                  'updated'        => ($updated > 0) ? $this->feed_helper->format_date($updated) : '',
 348                  'link'            => '',
 349                  'title'            => censor_text($title),
 350                  'category'        => ($this->config['feed_item_statistics'] && !empty($row['forum_id'])) ? $board_url . '/viewforum.' . $this->php_ext . '?f=' . $row['forum_id'] : '',
 351                  'category_name'    => ($this->config['feed_item_statistics'] && isset($row['forum_name'])) ? $row['forum_name'] : '',
 352                  'description'    => censor_text($this->feed_helper->generate_content($row[$feed->get('text')], $row[$feed->get('bbcode_uid')], $row[$feed->get('bitfield')], $options, $row['forum_id'], ($display_attachments ? $feed->get_attachments($row['post_id']) : array()))),
 353                  'statistics'    => '',
 354              );
 355   
 356              // Adjust items, fill link, etc.
 357              $feed->adjust_item($item_row, $row);
 358   
 359              $item_vars[] = $item_row;
 360   
 361              $feed_updated_time = max($feed_updated_time, $published, $updated);
 362          }
 363   
 364          // If we do not have any items at all, sending the current time is better than sending no time.
 365          if (!$feed_updated_time)
 366          {
 367              $feed_updated_time = time();
 368          }
 369   
 370          $feed->close();
 371   
 372          $content = $this->template->render('feed.xml.twig', array(
 373              // Some default assignments
 374              // FEED_IMAGE is not used (atom)
 375              'FEED_IMAGE'            => '',
 376              'SELF_LINK'                => $this->controller_helper->route($this->request->attributes->get('_route'), $this->request->attributes->get('_route_params'), true, '', UrlGeneratorInterface::ABSOLUTE_URL),
 377              'FEED_LINK'                => $board_url . '/index.' . $this->php_ext,
 378              'FEED_TITLE'            => $this->config['sitename'],
 379              'FEED_SUBTITLE'            => $this->config['site_desc'],
 380              'FEED_UPDATED'            => $this->feed_helper->format_date($feed_updated_time),
 381              'FEED_LANG'                => $this->user->lang['USER_LANG'],
 382              'FEED_AUTHOR'            => $this->config['sitename'],
 383   
 384              // Feed entries
 385              'FEED_ROWS'                => $item_vars,
 386          ));
 387   
 388          $response = new Response($content);
 389          $response->headers->set('Content-Type', 'application/atom+xml');
 390          $response->setCharset('UTF-8');
 391          $response->setLastModified(new \DateTime('@' . $feed_updated_time));
 392   
 393          if (!empty($this->user->data['is_bot']))
 394          {
 395              // Let reverse proxies know we detected a bot.
 396              $response->headers->set('X-PHPBB-IS-BOT', 'yes');
 397          }
 398   
 399          return $response;
 400      }
 401   
 402      /**
 403       * Throw and exception saying that the feed isn't available
 404       *
 405       * @throw http_exception
 406       */
 407      protected function send_unavailable()
 408      {
 409          throw new http_exception(404, 'FEATURE_NOT_AVAILABLE');
 410      }
 411  }
 412