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