Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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

generate.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 4.83 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\console\command\thumbnail;
 015   
 016  use Symfony\Component\Console\Input\InputInterface;
 017  use Symfony\Component\Console\Output\OutputInterface;
 018  use Symfony\Component\Console\Style\SymfonyStyle;
 019   
 020  class generate extends \phpbb\console\command\command
 021  {
 022      /**
 023      * @var \phpbb\config\config
 024      */
 025      protected $config;
 026   
 027      /**
 028      * @var \phpbb\db\driver\driver_interface
 029      */
 030      protected $db;
 031   
 032      /**
 033      * @var \phpbb\cache\service
 034      */
 035      protected $cache;
 036   
 037      /**
 038      * phpBB root path
 039      * @var string
 040      */
 041      protected $phpbb_root_path;
 042   
 043      /**
 044      * PHP extension.
 045      *
 046      * @var string
 047      */
 048      protected $php_ext;
 049   
 050      /**
 051      * Constructor
 052      *
 053      * @param \config\config $config The config
 054      * @param \phpbb\user $user The user object (used to get language information)
 055      * @param \phpbb\db\driver\driver_interface $db Database connection
 056      * @param \phpbb\cache\service $cache The cache service
 057      * @param string $phpbb_root_path Root path
 058      * @param string $php_ext PHP extension
 059      */
 060      public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext)
 061      {
 062          $this->config = $config;
 063          $this->db = $db;
 064          $this->cache = $cache;
 065          $this->phpbb_root_path = $phpbb_root_path;
 066          $this->php_ext = $php_ext;
 067   
 068          parent::__construct($user);
 069      }
 070   
 071      /**
 072      * Sets the command name and description
 073      *
 074      * @return null
 075      */
 076      protected function configure()
 077      {
 078          $this
 079              ->setName('thumbnail:generate')
 080              ->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE'))
 081          ;
 082      }
 083   
 084      /**
 085      * Executes the command thumbnail:generate.
 086      *
 087      * Generate a thumbnail for all attachments which need one and don't have it yet.
 088      *
 089      * @param InputInterface $input The input stream used to get the argument and verboe option.
 090      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
 091      *
 092      * @return int 0.
 093      */
 094      protected function execute(InputInterface $input, OutputInterface $output)
 095      {
 096          $io = new SymfonyStyle($input, $output);
 097   
 098          $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
 099   
 100          $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
 101              FROM ' . ATTACHMENTS_TABLE . '
 102              WHERE thumbnail = 0';
 103          $result = $this->db->sql_query($sql);
 104          $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
 105          $this->db->sql_freeresult($result);
 106   
 107          if ($nb_missing_thumbnails === 0)
 108          {
 109              $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
 110              return 0;
 111          }
 112   
 113          $extensions = $this->cache->obtain_attach_extensions(true);
 114   
 115          $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
 116              FROM ' . ATTACHMENTS_TABLE . '
 117              WHERE thumbnail = 0';
 118          $result = $this->db->sql_query($sql);
 119   
 120          if (!function_exists('create_thumbnail'))
 121          {
 122              require($this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext);
 123          }
 124   
 125          $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
 126   
 127          $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
 128   
 129          $progress->start();
 130   
 131          $thumbnail_created = array();
 132          while ($row = $this->db->sql_fetchrow($result))
 133          {
 134              if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE)
 135              {
 136                  $source = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $row['physical_filename'];
 137                  $destination = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename'];
 138   
 139                  if (create_thumbnail($source, $destination, $row['mimetype']))
 140                  {
 141                      $thumbnail_created[] = (int) $row['attach_id'];
 142   
 143                      if (count($thumbnail_created) === 250)
 144                      {
 145                          $this->commit_changes($thumbnail_created);
 146                          $thumbnail_created = array();
 147                      }
 148   
 149                      $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
 150                  }
 151                  else
 152                  {
 153                      $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
 154                  }
 155              }
 156   
 157              $progress->advance();
 158          }
 159          $this->db->sql_freeresult($result);
 160   
 161          if (!empty($thumbnail_created))
 162          {
 163              $this->commit_changes($thumbnail_created);
 164          }
 165   
 166          $progress->finish();
 167   
 168          $io->newLine(2);
 169          $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
 170   
 171          return 0;
 172      }
 173   
 174      /**
 175      * Commits the changes to the database
 176      *
 177      * @param array $thumbnail_created
 178      */
 179      protected function commit_changes(array $thumbnail_created)
 180      {
 181          $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
 182                  SET thumbnail = 1
 183                  WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created);
 184          $this->db->sql_query($sql);
 185      }
 186  }
 187