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

data_access.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 5.42 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\textformatter;
 015   
 016  /**
 017  * Data access layer that fetchs BBCodes, smilies and censored words from the database.
 018  * To be extended to include insert/update/delete operations.
 019  *
 020  * Also used to get templates.
 021  */
 022  class data_access
 023  {
 024      /**
 025      * @var string Name of the BBCodes table
 026      */
 027      protected $bbcodes_table;
 028   
 029      /**
 030      * @var \phpbb\db\driver\driver_interface
 031      */
 032      protected $db;
 033   
 034      /**
 035      * @var string Name of the smilies table
 036      */
 037      protected $smilies_table;
 038   
 039      /**
 040      * @var string Name of the styles table
 041      */
 042      protected $styles_table;
 043   
 044      /**
 045      * @var string Path to the styles dir
 046      */
 047      protected $styles_path;
 048   
 049      /**
 050      * @var string Name of the words table
 051      */
 052      protected $words_table;
 053   
 054      /**
 055      * Constructor
 056      *
 057      * @param \phpbb\db\driver\driver_interface $db Database connection
 058      * @param string $bbcodes_table Name of the BBCodes table
 059      * @param string $smilies_table Name of the smilies table
 060      * @param string $styles_table  Name of the styles table
 061      * @param string $words_table   Name of the words table
 062      * @param string $styles_path   Path to the styles dir
 063      */
 064      public function __construct(\phpbb\db\driver\driver_interface $db, $bbcodes_table, $smilies_table, $styles_table, $words_table, $styles_path)
 065      {
 066          $this->db = $db;
 067   
 068          $this->bbcodes_table = $bbcodes_table;
 069          $this->smilies_table = $smilies_table;
 070          $this->styles_table  = $styles_table;
 071          $this->words_table   = $words_table;
 072   
 073          $this->styles_path = $styles_path;
 074      }
 075   
 076      /**
 077      * Return the list of custom BBCodes
 078      *
 079      * @return array
 080      */
 081      public function get_bbcodes()
 082      {
 083          $sql = 'SELECT bbcode_match, bbcode_tpl FROM ' . $this->bbcodes_table;
 084          $result = $this->db->sql_query($sql);
 085          $rows = $this->db->sql_fetchrowset($result);
 086          $this->db->sql_freeresult($result);
 087   
 088          return $rows;
 089      }
 090   
 091      /**
 092      * Return the list of smilies
 093      *
 094      * @return array
 095      */
 096      public function get_smilies()
 097      {
 098          // NOTE: smilies that are displayed on the posting page are processed first because they're
 099          //       typically the most used smilies and it ends up producing a slightly more efficient
 100          //       renderer
 101          $sql = 'SELECT code, emotion, smiley_url, smiley_width, smiley_height
 102              FROM ' . $this->smilies_table . '
 103              ORDER BY display_on_posting DESC';
 104          $result = $this->db->sql_query($sql);
 105          $rows = $this->db->sql_fetchrowset($result);
 106          $this->db->sql_freeresult($result);
 107   
 108          return $rows;
 109      }
 110   
 111      /**
 112      * Return the list of installed styles
 113      *
 114      * @return array
 115      */
 116      protected function get_styles()
 117      {
 118          $sql = 'SELECT style_id, style_path, style_parent_id, bbcode_bitfield FROM ' . $this->styles_table;
 119          $result = $this->db->sql_query($sql);
 120          $rows = $this->db->sql_fetchrowset($result);
 121          $this->db->sql_freeresult($result);
 122   
 123          return $rows;
 124      }
 125   
 126      /**
 127      * Return the bbcode.html template for every installed style
 128      *
 129      * @return array 2D array. style_id as keys, each element is an array with a "template" element that contains the style's bbcode.html and a "bbcodes" element that contains the name of each BBCode that is to be stylised
 130      */
 131      public function get_styles_templates()
 132      {
 133          $templates = array();
 134   
 135          $bbcode_ids = array(
 136              'quote' => 0,
 137              'b'     => 1,
 138              'i'     => 2,
 139              'url'   => 3,
 140              'img'   => 4,
 141              'size'  => 5,
 142              'color' => 6,
 143              'u'     => 7,
 144              'code'  => 8,
 145              'list'  => 9,
 146              '*'     => 9,
 147              'email' => 10,
 148              'flash' => 11,
 149              'attachment' => 12,
 150          );
 151   
 152          $styles = array();
 153          foreach ($this->get_styles() as $row)
 154          {
 155              $styles[$row['style_id']] = $row;
 156          }
 157   
 158          foreach ($styles as $style_id => $style)
 159          {
 160              $bbcodes = array();
 161   
 162              // Collect the name of the BBCodes whose bit is set in the style's bbcode_bitfield
 163              $template_bitfield = new \bitfield($style['bbcode_bitfield']);
 164              foreach ($bbcode_ids as $bbcode_name => $bit)
 165              {
 166                  if ($template_bitfield->get($bit))
 167                  {
 168                      $bbcodes[] = $bbcode_name;
 169                  }
 170              }
 171   
 172              $filename = $this->resolve_style_filename($styles, $style);
 173              if ($filename === false)
 174              {
 175                  // Ignore this style, it will use the default templates
 176                  continue;
 177              }
 178   
 179              $templates[$style_id] = array(
 180                  'bbcodes'  => $bbcodes,
 181                  'template' => file_get_contents($filename),
 182              );
 183          }
 184   
 185          return $templates;
 186      }
 187   
 188      /**
 189      * Resolve inheritance for given style and return the path to their bbcode.html file
 190      *
 191      * @param  array       $styles Associative array of [style_id => style] containing all styles
 192      * @param  array       $style  Style for which we resolve
 193      * @return string|bool         Path to this style's bbcode.html, or FALSE
 194      */
 195      protected function resolve_style_filename(array $styles, array $style)
 196      {
 197          // Look for a bbcode.html in this style's dir
 198          $filename = $this->styles_path . $style['style_path'] . '/template/bbcode.html';
 199          if (file_exists($filename))
 200          {
 201              return $filename;
 202          }
 203   
 204          // Resolve using this style's parent
 205          $parent_id = $style['style_parent_id'];
 206          if ($parent_id && !empty($styles[$parent_id]))
 207          {
 208              return $this->resolve_style_filename($styles, $styles[$parent_id]);
 209          }
 210   
 211          return false;
 212      }
 213   
 214      /**
 215      * Return the list of censored words
 216      *
 217      * @return array
 218      */
 219      public function get_censored_words()
 220      {
 221          $sql = 'SELECT word, replacement FROM ' . $this->words_table;
 222          $result = $this->db->sql_query($sql);
 223          $rows = $this->db->sql_fetchrowset($result);
 224          $this->db->sql_freeresult($result);
 225   
 226          return $rows;
 227      }
 228  }
 229