mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-03 14:17:56 +02:00
[ticket/16820] Move ATTACHMENT_CATEGORY_ constants to attachment namespace
PHPBB3-16820
This commit is contained in:
parent
ddf8e8c9d1
commit
b99cfd5caa
@ -15,6 +15,7 @@
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
use phpbb\attachment\manager;
|
||||
use phpbb\config\config;
|
||||
use phpbb\controller\helper;
|
||||
@ -163,7 +164,7 @@ class acp_attachments
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode($user->lang['COMMA_SEPARATOR'], $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
|
||||
$l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[attachment_category::IMAGE])) ? implode($user->lang['COMMA_SEPARATOR'], $s_assigned_groups[attachment_category::IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
|
||||
|
||||
$display_vars = array(
|
||||
'title' => 'ACP_ATTACHMENT_SETTINGS',
|
||||
@ -584,7 +585,7 @@ class acp_attachments
|
||||
|
||||
$group_ary = array(
|
||||
'group_name' => $group_name,
|
||||
'cat_id' => $request->variable('special_category', ATTACHMENT_CATEGORY_NONE),
|
||||
'cat_id' => $request->variable('special_category', attachment_category::NONE),
|
||||
'allow_group' => ($allow_group) ? 1 : 0,
|
||||
'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
|
||||
'max_filesize' => $max_filesize,
|
||||
@ -634,10 +635,10 @@ class acp_attachments
|
||||
}
|
||||
|
||||
$cat_lang = array(
|
||||
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
|
||||
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
|
||||
ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'),
|
||||
ATTACHMENT_CATEGORY_VIDEO => $user->lang('CAT_VIDEO_FILES'),
|
||||
attachment_category::NONE => $user->lang['NO_FILE_CAT'],
|
||||
attachment_category::IMAGE => $user->lang['CAT_IMAGES'],
|
||||
attachment_category::AUDIO => $user->lang('CAT_AUDIO_FILES'),
|
||||
attachment_category::VIDEO => $user->lang('CAT_VIDEO_FILES'),
|
||||
);
|
||||
|
||||
$group_id = $request->variable('g', 0);
|
||||
@ -1268,8 +1269,8 @@ class acp_attachments
|
||||
|
||||
$row['extension'] = strtolower(trim((string) $row['extension']));
|
||||
$comment = ($row['attach_comment'] && !$row['in_message']) ? str_replace(array("\n", "\r"), array('<br />', "\n"), $row['attach_comment']) : '';
|
||||
$display_cat = isset($extensions[$row['extension']]['display_cat']) ? $extensions[$row['extension']]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
|
||||
$l_downloaded_viewed = ($display_cat == ATTACHMENT_CATEGORY_NONE) ? 'DOWNLOAD_COUNTS' : 'VIEWED_COUNTS';
|
||||
$display_cat = isset($extensions[$row['extension']]['display_cat']) ? $extensions[$row['extension']]['display_cat'] : attachment_category::NONE;
|
||||
$l_downloaded_viewed = ($display_cat == attachment_category::NONE) ? 'DOWNLOAD_COUNTS' : 'VIEWED_COUNTS';
|
||||
|
||||
$template->assign_block_vars('attachments', array(
|
||||
'ATTACHMENT_POSTER' => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']),
|
||||
@ -1410,10 +1411,10 @@ class acp_attachments
|
||||
global $db, $user;
|
||||
|
||||
$types = array(
|
||||
ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
|
||||
ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
|
||||
ATTACHMENT_CATEGORY_AUDIO => $user->lang('CAT_AUDIO_FILES'),
|
||||
ATTACHMENT_CATEGORY_VIDEO => $user->lang('CAT_VIDEO_FILES'),
|
||||
attachment_category::NONE => $user->lang['NO_FILE_CAT'],
|
||||
attachment_category::IMAGE => $user->lang['CAT_IMAGES'],
|
||||
attachment_category::AUDIO => $user->lang('CAT_AUDIO_FILES'),
|
||||
attachment_category::VIDEO => $user->lang('CAT_VIDEO_FILES'),
|
||||
);
|
||||
|
||||
if ($group_id)
|
||||
@ -1423,13 +1424,13 @@ class acp_attachments
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
|
||||
$cat_type = (!($row = $db->sql_fetchrow($result))) ? attachment_category::NONE : $row['cat_id'];
|
||||
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cat_type = ATTACHMENT_CATEGORY_NONE;
|
||||
$cat_type = attachment_category::NONE;
|
||||
}
|
||||
|
||||
$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
|
||||
|
@ -158,10 +158,15 @@ define('CONFIRM_POST', 3);
|
||||
define('CONFIRM_REPORT', 4);
|
||||
|
||||
// Categories - Attachments
|
||||
/* @deprecated Replaced by \phpbb\attachment\attachment_category constants in 4.0.0-a1, to be removed in 4.1.0-a1 */
|
||||
define('ATTACHMENT_CATEGORY_NONE', 0);
|
||||
/* @deprecated Replaced by \phpbb\attachment\attachment_category constants in 4.0.0-a1, to be removed in 4.1.0-a1 */
|
||||
define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images
|
||||
/* @deprecated Replaced by \phpbb\attachment\attachment_category constants in 4.0.0-a1, to be removed in 4.1.0-a1 */
|
||||
define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts
|
||||
/* @deprecated Replaced by \phpbb\attachment\attachment_category constants in 4.0.0-a1, to be removed in 4.1.0-a1 */
|
||||
define('ATTACHMENT_CATEGORY_AUDIO', 7); // Browser-playable audio files
|
||||
/* @deprecated Replaced by \phpbb\attachment\attachment_category constants in 4.0.0-a1, to be removed in 4.1.0-a1 */
|
||||
define('ATTACHMENT_CATEGORY_VIDEO', 8); // Browser-playable video files
|
||||
|
||||
// BBCode UID length
|
||||
|
@ -14,6 +14,9 @@
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
@ -1248,11 +1251,11 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
{
|
||||
$display_cat = $extensions[$attachment['extension']]['display_cat'];
|
||||
|
||||
if ($display_cat == ATTACHMENT_CATEGORY_IMAGE)
|
||||
if ($display_cat == attachment_category::IMAGE)
|
||||
{
|
||||
if ($attachment['thumbnail'])
|
||||
{
|
||||
$display_cat = ATTACHMENT_CATEGORY_THUMB;
|
||||
$display_cat = attachment_category::THUMB;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1264,25 +1267,25 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
{
|
||||
$file_info = $storage_attachment->file_info($filename);
|
||||
|
||||
$display_cat = ($file_info->image_width <= $config['img_link_width'] && $file_info->image_height <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE;
|
||||
$display_cat = ($file_info->image_width <= $config['img_link_width'] && $file_info->image_height <= $config['img_link_height']) ? attachment_category::IMAGE : attachment_category::NONE;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$display_cat = ATTACHMENT_CATEGORY_NONE;
|
||||
$display_cat = attachment_category::NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$display_cat = ATTACHMENT_CATEGORY_NONE;
|
||||
$display_cat = attachment_category::NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make some descisions based on user options being set.
|
||||
if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg'))
|
||||
if (($display_cat == attachment_category::IMAGE || $display_cat == attachment_category::THUMB) && !$user->optionget('viewimg'))
|
||||
{
|
||||
$display_cat = ATTACHMENT_CATEGORY_NONE;
|
||||
$display_cat = attachment_category::NONE;
|
||||
}
|
||||
|
||||
$download_link = $controller_helper->route('phpbb_storage_attachment', ['file' => (int) $attachment['attach_id']]);
|
||||
@ -1291,7 +1294,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
switch ($display_cat)
|
||||
{
|
||||
// Images
|
||||
case ATTACHMENT_CATEGORY_IMAGE:
|
||||
case attachment_category::IMAGE:
|
||||
$inline_link = $controller_helper->route('phpbb_storage_attachment', ['file' => (int) $attachment['attach_id']]);
|
||||
|
||||
$block_array += array(
|
||||
@ -1303,7 +1306,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
break;
|
||||
|
||||
// Images, but display Thumbnail
|
||||
case ATTACHMENT_CATEGORY_THUMB:
|
||||
case attachment_category::THUMB:
|
||||
$thumbnail_link = $controller_helper->route('phpbb_storage_attachment', ['file' => (int) $attachment['attach_id'], 't' => 1]);
|
||||
|
||||
$block_array += array(
|
||||
@ -1315,7 +1318,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
break;
|
||||
|
||||
// Audio files
|
||||
case ATTACHMENT_CATEGORY_AUDIO:
|
||||
case attachment_category::AUDIO:
|
||||
$block_array += [
|
||||
'S_AUDIO_FILE' => true,
|
||||
];
|
||||
@ -1324,7 +1327,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
break;
|
||||
|
||||
// Video files
|
||||
case ATTACHMENT_CATEGORY_VIDEO:
|
||||
case attachment_category::VIDEO:
|
||||
$block_array += [
|
||||
'S_VIDEO_FILE' => true,
|
||||
];
|
||||
|
@ -11,6 +11,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
@ -1393,7 +1395,7 @@ function phpbb_attachment_category($cat_id)
|
||||
switch ($cat_id)
|
||||
{
|
||||
case 1:
|
||||
return ATTACHMENT_CATEGORY_IMAGE;
|
||||
return attachment_category::IMAGE;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@ -1401,7 +1403,7 @@ function phpbb_attachment_category($cat_id)
|
||||
break;
|
||||
}
|
||||
|
||||
return ATTACHMENT_CATEGORY_NONE;
|
||||
return attachment_category::NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
32
phpBB/phpbb/attachment/attachment_category.php
Normal file
32
phpBB/phpbb/attachment/attachment_category.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\attachment;
|
||||
|
||||
abstract class attachment_category
|
||||
{
|
||||
/** @var int None category */
|
||||
public const NONE = 0;
|
||||
|
||||
/** @var int Inline images */
|
||||
public const IMAGE = 1;
|
||||
|
||||
/** @var int Not used within the database, only while displaying posts */
|
||||
public const THUMB = 4;
|
||||
|
||||
/** @var int Browser-playable audio files */
|
||||
public const AUDIO = 7;
|
||||
|
||||
/** @var int Browser-playable video files */
|
||||
public const VIDEO = 8;
|
||||
}
|
@ -131,7 +131,7 @@ class upload
|
||||
}
|
||||
|
||||
// Whether the uploaded file is in the image category
|
||||
$is_image = (isset($this->extensions[$this->file->get('extension')]['display_cat'])) ? $this->extensions[$this->file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false;
|
||||
$is_image = (isset($this->extensions[$this->file->get('extension')]['display_cat'])) ? $this->extensions[$this->file->get('extension')]['display_cat'] == \phpbb\attachment\attachment_category::IMAGE : false;
|
||||
|
||||
if (!$this->auth->acl_get('a_') && !$this->auth->acl_get('m_', $forum_id))
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ class generate extends \phpbb\console\command\command
|
||||
$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)
|
||||
if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == \phpbb\attachment\attachment_category::IMAGE)
|
||||
{
|
||||
$source = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $row['physical_filename'];
|
||||
$destination = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename'];
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\db\migration\data\v400;
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
|
||||
class add_audio_files_attachment_group extends \phpbb\db\migration\migration
|
||||
{
|
||||
public static function depends_on()
|
||||
@ -40,7 +42,7 @@ class add_audio_files_attachment_group extends \phpbb\db\migration\migration
|
||||
{
|
||||
$sql = 'INSERT INTO ' . $this->table_prefix . 'extension_groups ' . $this->db->sql_build_array('INSERT', [
|
||||
'group_name' => 'AUDIO_FILES',
|
||||
'cat_id' => ATTACHMENT_CATEGORY_AUDIO,
|
||||
'cat_id' => attachment_category::AUDIO,
|
||||
'allow_group' => 0,
|
||||
'upload_icon' => '',
|
||||
'max_filesize' => 0,
|
||||
@ -51,7 +53,7 @@ class add_audio_files_attachment_group extends \phpbb\db\migration\migration
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . ATTACHMENT_CATEGORY_AUDIO . '
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . attachment_category::AUDIO . '
|
||||
WHERE ' . $this->db->sql_build_array('SELECT', ['group_id' => $audio_group_id]);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\db\migration\data\v400;
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
|
||||
class add_video_files_attachment_group extends \phpbb\db\migration\migration
|
||||
{
|
||||
public static function depends_on()
|
||||
@ -40,7 +42,7 @@ class add_video_files_attachment_group extends \phpbb\db\migration\migration
|
||||
{
|
||||
$sql = 'INSERT INTO ' . $this->table_prefix . 'extension_groups ' . $this->db->sql_build_array('INSERT', [
|
||||
'group_name' => 'VIDEO_FILES',
|
||||
'cat_id' => ATTACHMENT_CATEGORY_VIDEO,
|
||||
'cat_id' => attachment_category::VIDEO,
|
||||
'allow_group' => 0,
|
||||
'upload_icon' => '',
|
||||
'max_filesize' => 0,
|
||||
@ -51,7 +53,7 @@ class add_video_files_attachment_group extends \phpbb\db\migration\migration
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . ATTACHMENT_CATEGORY_VIDEO . '
|
||||
$sql = 'UPDATE ' . $this->table_prefix . 'extension_groups SET cat_id = ' . attachment_category::VIDEO . '
|
||||
WHERE ' . $this->db->sql_build_array('SELECT', ['group_id' => $video_group_id]);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
namespace phpbb\storage\controller;
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\cache\service;
|
||||
use phpbb\config\config;
|
||||
@ -183,9 +184,9 @@ class attachment extends controller
|
||||
{
|
||||
$attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
|
||||
}
|
||||
else if ($display_cat == ATTACHMENT_CATEGORY_NONE && !$attachment['is_orphan'])
|
||||
else if ($display_cat == attachment_category::NONE && !$attachment['is_orphan'])
|
||||
{
|
||||
if (!(($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$this->user->optionget('viewimg')))
|
||||
if (!(($display_cat == attachment_category::IMAGE || $display_cat == attachment_category::THUMB) && !$this->user->optionget('viewimg')))
|
||||
{
|
||||
// Update download count
|
||||
$this->phpbb_increment_downloads($attachment['attach_id']);
|
||||
|
@ -11,6 +11,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
use phpbb\attachment\attachment_category;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use phpbb\console\command\thumbnail\generate;
|
||||
@ -57,8 +58,8 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case
|
||||
|
||||
$this->cache = $this->createMock('\phpbb\cache\service');
|
||||
$this->cache->expects(self::any())->method('obtain_attach_extensions')->will(self::returnValue(array(
|
||||
'png' => array('display_cat' => ATTACHMENT_CATEGORY_IMAGE),
|
||||
'txt' => array('display_cat' => ATTACHMENT_CATEGORY_NONE),
|
||||
'png' => array('display_cat' => attachment_category::IMAGE),
|
||||
'txt' => array('display_cat' => attachment_category::NONE),
|
||||
)));
|
||||
|
||||
$this->application = new Application();
|
||||
|
Loading…
x
Reference in New Issue
Block a user