/**
  * {@inheritdoc}
  */
 public function display(array $bdata, $edit_mode = false)
 {
     $this->settings = $bdata['settings'];
     $extensions = $this->cache->obtain_attach_extensions(0);
     $ext_groups = $this->_get_extension_groups($extensions);
     $posts_data = $this->_get_posts_data();
     $attachments = $this->forum_data->get_attachments(0, $ext_groups[$this->settings['ext_type']], false, 'download_count DESC');
     $content = '';
     if (sizeof($attachments)) {
         $this->_get_block_content($attachments, $posts_data, $extensions);
         $content = $this->ptemplate->render_view('blitze/sitemaker', 'blocks/attachments.html', 'attachments');
     }
     return array('title' => 'ATTACHMENTS', 'content' => $content);
 }
Beispiel #2
0
 /**
  * Init files upload class
  *
  * @param int $forum_id Forum ID
  * @param bool $is_message Whether attachment is inside PM or not
  */
 protected function init_files_upload($forum_id, $is_message)
 {
     if ($this->config['check_attachment_content'] && isset($this->config['mime_triggers'])) {
         $this->files_upload->set_disallowed_content(explode('|', $this->config['mime_triggers']));
     } else {
         if (!$this->config['check_attachment_content']) {
             $this->files_upload->set_disallowed_content(array());
         }
     }
     $this->extensions = $this->cache->obtain_attach_extensions($is_message ? false : (int) $forum_id);
     $this->files_upload->set_allowed_extensions(array_keys($this->extensions['_allowed_']));
 }
Beispiel #3
0
    /**
     * Executes the command thumbnail:generate.
     *
     * Generate a thumbnail for all attachments which need one and don't have it yet.
     *
     * @param InputInterface $input The input stream used to get the argument and verboe option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
            return 0;
        }
        $extensions = $this->cache->obtain_attach_extensions(true);
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        if (!function_exists('create_thumbnail')) {
            require $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        }
        $progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
        $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $progress->start();
        $thumbnail_created = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) {
                $source = $this->phpbb_root_path . 'files/' . $row['physical_filename'];
                $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
                if (create_thumbnail($source, $destination, $row['mimetype'])) {
                    $thumbnail_created[] = (int) $row['attach_id'];
                    if (count($thumbnail_created) === 250) {
                        $this->commit_changes($thumbnail_created);
                        $thumbnail_created = array();
                    }
                    $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
                } else {
                    $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
                }
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_created)) {
            $this->commit_changes($thumbnail_created);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
        return 0;
    }
Beispiel #4
0
 /**
  * Looks at the list of allowed extensions and generates a string
  * appropriate for use in configuring plupload with
  *
  * @param \phpbb\cache\service $cache
  * @param string $forum_id The ID of the forum
  *
  * @return string
  */
 public function generate_filter_string(\phpbb\cache\service $cache, $forum_id)
 {
     $attach_extensions = $cache->obtain_attach_extensions($forum_id);
     unset($attach_extensions['_allowed_']);
     $groups = array();
     // Re-arrange the extension array to $groups[$group_name][]
     foreach ($attach_extensions as $extension => $extension_info) {
         if (!isset($groups[$extension_info['group_name']])) {
             $groups[$extension_info['group_name']] = array();
         }
         $groups[$extension_info['group_name']][] = $extension;
     }
     $filters = array();
     foreach ($groups as $group => $extensions) {
         $filters[] = sprintf("{title: '%s', extensions: '%s'}", addslashes(ucfirst(strtolower($group))), addslashes(implode(',', $extensions)));
     }
     return implode(',', $filters);
 }
Beispiel #5
0
    /**
     * Executes the command thumbnail:generate.
     *
     * Generate a thumbnail for all attachments which need one and don't have it yet.
     *
     * @param InputInterface $input The input stream used to get the argument and verboe option.
     * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
     *
     * @return int 0.
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        $nb_missing_thumbnails = (int) $this->db->sql_fetchfield('nb_missing_thumbnails');
        $this->db->sql_freeresult($result);
        if ($nb_missing_thumbnails === 0) {
            $io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
            return 0;
        }
        $extensions = $this->cache->obtain_attach_extensions(true);
        $sql = 'SELECT attach_id, physical_filename, extension, real_filename, mimetype
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE thumbnail = 0';
        $result = $this->db->sql_query($sql);
        if (!function_exists('create_thumbnail')) {
            require $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        }
        $progress = $io->createProgressBar($nb_missing_thumbnails);
        if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
            $progress->setFormat('<info>[%percent:3s%%]</info> %message%');
            $progress->setOverwrite(false);
        } else {
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
                $progress->setFormat('<info>[%current:s%/%max:s%]</info><comment>[%elapsed%/%estimated%][%memory%]</comment> %message%');
                $progress->setOverwrite(false);
            } else {
                $io->newLine(2);
                $progress->setFormat("    %current:s%/%max:s% %bar%  %percent:3s%%\n" . "                         %elapsed:6s%/%estimated:-6s% %memory:6s%\n");
                $progress->setBarWidth(60);
            }
        }
        if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
            $progress->setEmptyBarCharacter('░');
            // light shade character \u2591
            $progress->setProgressCharacter('');
            $progress->setBarCharacter('▓');
            // dark shade character \u2593
        }
        $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
        $progress->start();
        $thumbnail_created = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE) {
                $source = $this->phpbb_root_path . 'files/' . $row['physical_filename'];
                $destination = $this->phpbb_root_path . 'files/thumb_' . $row['physical_filename'];
                if (create_thumbnail($source, $destination, $row['mimetype'])) {
                    $thumbnail_created[] = (int) $row['attach_id'];
                    if (count($thumbnail_created) === 250) {
                        $this->commit_changes($thumbnail_created);
                        $thumbnail_created = array();
                    }
                    $progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
                } else {
                    $progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
                }
            }
            $progress->advance();
        }
        $this->db->sql_freeresult($result);
        if (!empty($thumbnail_created)) {
            $this->commit_changes($thumbnail_created);
        }
        $progress->finish();
        $io->newLine(2);
        $io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
        return 0;
    }