[feature/module_services] Move attachments module to services
This commit is contained in:
@@ -54,6 +54,19 @@ services:
|
||||
tags:
|
||||
- { name: board3.module }
|
||||
|
||||
board3.module.attachments:
|
||||
class: \board3\portal\modules\attachments
|
||||
arguments:
|
||||
- @auth
|
||||
- @config
|
||||
- @template
|
||||
- @dbal.conn
|
||||
- %core.php_ext%
|
||||
- %core.root_path%
|
||||
- @user
|
||||
tags:
|
||||
- { name: board3.module }
|
||||
|
||||
board3.module.stylechanger:
|
||||
class: \board3\portal\modules\stylechanger
|
||||
arguments:
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal v2 - Attachments
|
||||
* @package Board3 Portal v2.1
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
namespace board3\portal\modules;
|
||||
|
||||
/**
|
||||
* @package Modulname
|
||||
*/
|
||||
class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
class attachments extends module_base
|
||||
{
|
||||
/**
|
||||
* Allowed columns: Just sum up your options (Exp: left + right = 10)
|
||||
@@ -47,16 +41,68 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
*/
|
||||
public $language = 'portal_attachments_module';
|
||||
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\db\driver */
|
||||
protected $db;
|
||||
|
||||
/** @var php file extension */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var phpbb root path */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Construct an attachments object
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth phpBB auth service
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\template $template phpBB template
|
||||
* @param \phpbb\db\driver $db Database driver
|
||||
* @param string $phpEx php file extension
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $config, $template, $db, $phpEx, $phpbb_root_path, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->template = $template;
|
||||
$this->db = $db;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_template_center($module_id)
|
||||
{
|
||||
return $this->parse_template($module_id, 'center');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_template_side($module_id)
|
||||
{
|
||||
return $this->parse_template($module_id, 'side');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_template_acp($module_id)
|
||||
{
|
||||
return array(
|
||||
@@ -74,7 +120,7 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
}
|
||||
|
||||
/**
|
||||
* API functions
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function install($module_id)
|
||||
{
|
||||
@@ -87,6 +133,9 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function uninstall($module_id, $db)
|
||||
{
|
||||
$del_config = array(
|
||||
@@ -102,26 +151,32 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
return $db->sql_query($sql);
|
||||
}
|
||||
|
||||
// Create select box for attachment filetype
|
||||
/**
|
||||
* Create select box for attachment filetype
|
||||
*
|
||||
* @param mixed $value Value of input
|
||||
* @param string $key Key name
|
||||
* @param int $module_id Module ID
|
||||
*
|
||||
* @return string Forum select box HTML
|
||||
*/
|
||||
public function select_filetype($value, $key, $module_id)
|
||||
{
|
||||
global $db, $user, $config;
|
||||
|
||||
// Get extensions
|
||||
$sql = 'SELECT *
|
||||
FROM ' . EXTENSIONS_TABLE . '
|
||||
ORDER BY extension ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$extensions[] = $row;
|
||||
}
|
||||
|
||||
$selected = array();
|
||||
if(isset($config['board3_attachments_filetype_' . $module_id]) && strlen($config['board3_attachments_filetype_' . $module_id]) > 0)
|
||||
if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0)
|
||||
{
|
||||
$selected = explode(',', $config['board3_attachments_filetype_' . $module_id]);
|
||||
$selected = explode(',', $this->config['board3_attachments_filetype_' . $module_id]);
|
||||
}
|
||||
|
||||
// Build options
|
||||
@@ -135,11 +190,16 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
return $ext_options;
|
||||
}
|
||||
|
||||
// Store selected filetypes
|
||||
/**
|
||||
* Store selected filetypes
|
||||
*
|
||||
* @param string $key Key name
|
||||
* @param int $module_id Module ID
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function store_filetypes($key, $module_id)
|
||||
{
|
||||
global $db, $cache;
|
||||
|
||||
// Get selected extensions
|
||||
$values = request_var($key, array(0 => ''));
|
||||
|
||||
@@ -149,17 +209,23 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
|
||||
}
|
||||
|
||||
// Create forum select box
|
||||
/**
|
||||
* Create forum select box
|
||||
*
|
||||
* @param mixed $value Value of input
|
||||
* @param string $key Key name
|
||||
* @param int $module_id Module ID
|
||||
*
|
||||
* @return string Forum select box HTML
|
||||
*/
|
||||
public function select_forums($value, $key)
|
||||
{
|
||||
global $user, $config;
|
||||
|
||||
$forum_list = make_forum_select(false, false, true, true, true, false, true);
|
||||
|
||||
$selected = array();
|
||||
if(isset($config[$key]) && strlen($config[$key]) > 0)
|
||||
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
|
||||
{
|
||||
$selected = explode(',', $config[$key]);
|
||||
$selected = explode(',', $this->config[$key]);
|
||||
}
|
||||
// Build forum options
|
||||
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
|
||||
@@ -173,11 +239,16 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
|
||||
}
|
||||
|
||||
// Store selected forums
|
||||
/**
|
||||
* Store selected forums
|
||||
*
|
||||
* @param string $key Key name
|
||||
* @param int $module_id Module ID
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function store_selected_forums($key)
|
||||
{
|
||||
global $db, $cache;
|
||||
|
||||
// Get selected extensions
|
||||
$values = request_var($key, array(0 => ''));
|
||||
$news = implode(',', $values);
|
||||
@@ -189,27 +260,28 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
*
|
||||
* @param int $module_id Module ID
|
||||
* @param string $type Module type (center or side)
|
||||
*
|
||||
* @return string Template file name or false if nothing should
|
||||
* be displayed
|
||||
*/
|
||||
protected function parse_template($module_id, $type)
|
||||
{
|
||||
global $config, $template, $db, $user, $auth, $phpEx, $phpbb_root_path;
|
||||
|
||||
$attach_forums = false;
|
||||
$where = '';
|
||||
$filetypes = array();
|
||||
|
||||
// Get filetypes and put them into an array
|
||||
if(isset($config['board3_attachments_filetype_' . $module_id]) && strlen($config['board3_attachments_filetype_' . $module_id]) > 0)
|
||||
if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0)
|
||||
{
|
||||
$filetypes = explode(',', $config['board3_attachments_filetype_' . $module_id]);
|
||||
$filetypes = explode(',', $this->config['board3_attachments_filetype_' . $module_id]);
|
||||
}
|
||||
|
||||
if($config['board3_attachments_forum_ids_' . $module_id] !== '')
|
||||
if($this->config['board3_attachments_forum_ids_' . $module_id] !== '')
|
||||
{
|
||||
$attach_forums_config = (strpos($config['board3_attachments_forum_ids_' . $module_id], ',') !== false) ? explode(',', $config['board3_attachments_forum_ids_' . $module_id]) : array($config['board3_attachments_forum_ids_' . $module_id]);
|
||||
$forum_list = array_unique(array_keys($auth->acl_getf('f_read', true)));
|
||||
$attach_forums_config = (strpos($this->config['board3_attachments_forum_ids_' . $module_id], ',') !== false) ? explode(',', $this->config['board3_attachments_forum_ids_' . $module_id]) : array($this->config['board3_attachments_forum_ids_' . $module_id]);
|
||||
$forum_list = array_unique(array_keys($this->auth->acl_getf('f_read', true)));
|
||||
|
||||
if($config['board3_attachments_forum_exclude_' . $module_id])
|
||||
if($this->config['board3_attachments_forum_exclude_' . $module_id])
|
||||
{
|
||||
$forum_list = array_unique(array_diff($forum_list, $attach_forums_config));
|
||||
}
|
||||
@@ -220,24 +292,24 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_list = array_unique(array_keys($auth->acl_getf('f_read', true)));
|
||||
$forum_list = array_unique(array_keys($this->auth->acl_getf('f_read', true)));
|
||||
}
|
||||
|
||||
if(sizeof($forum_list))
|
||||
{
|
||||
$attach_forums = true;
|
||||
$where = 'AND ' . $db->sql_in_set('t.forum_id', $forum_list);
|
||||
$where = 'AND ' . $this->db->sql_in_set('t.forum_id', $forum_list);
|
||||
}
|
||||
|
||||
if(sizeof($filetypes))
|
||||
{
|
||||
if($config['board3_attachments_exclude_' . $module_id])
|
||||
if($this->config['board3_attachments_exclude_' . $module_id])
|
||||
{
|
||||
$where .= ' AND ' . $db->sql_in_set('a.extension', $filetypes, true);
|
||||
$where .= ' AND ' . $this->db->sql_in_set('a.extension', $filetypes, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$where .= ' AND ' . $db->sql_in_set('a.extension', $filetypes);
|
||||
$where .= ' AND ' . $this->db->sql_in_set('a.extension', $filetypes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,20 +327,20 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
AND a.topic_id = t.topic_id
|
||||
' . $where . '
|
||||
ORDER BY
|
||||
filetime ' . ((!$config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC';
|
||||
$result = $db->sql_query_limit($sql, $config['board3_attachments_number_' . $module_id]);
|
||||
filetime ' . ((!$this->config['display_order']) ? 'DESC' : 'ASC') . ', post_msg_id ASC';
|
||||
$result = $this->db->sql_query_limit($sql, $this->config['board3_attachments_number_' . $module_id]);
|
||||
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MIB'] : (($row['filesize'] >= 1024) ? $user->lang['KIB'] : $user->lang['BYTES']);
|
||||
$size_lang = ($row['filesize'] >= 1048576) ? $this->user->lang['MIB'] : (($row['filesize'] >= 1024) ? $this->user->lang['KIB'] : $this->user->lang['BYTES']);
|
||||
$row['filesize'] = ($row['filesize'] >= 1048576) ? round((round($row['filesize'] / 1048576 * 100) / 100), 2) : (($row['filesize'] >= 1024) ? round((round($row['filesize'] / 1024 * 100) / 100), 2) : $row['filesize']);
|
||||
|
||||
$raw_filename = utf8_substr($row['real_filename'], 0, strrpos($row['real_filename'], '.'));
|
||||
$replace = character_limit($raw_filename, $config['board3_attach_max_length_' . $module_id]);
|
||||
$replace = character_limit($raw_filename, $this->config['board3_attach_max_length_' . $module_id]);
|
||||
|
||||
$template->assign_block_vars('attach_' . $type, array(
|
||||
$this->template->assign_block_vars('attach_' . $type, array(
|
||||
'FILESIZE' => $row['filesize'] . ' ' . $size_lang,
|
||||
'FILETIME' => $user->format_date($row['filetime']),
|
||||
'FILETIME' => $this->user->format_date($row['filetime']),
|
||||
'DOWNLOAD_COUNT' => (int) $row['download_count'], // grab downloads count
|
||||
'FILENAME' => $replace,
|
||||
'REAL_FILENAME' => $row['real_filename'],
|
||||
@@ -276,17 +348,17 @@ class portal_attachments_module extends \board3\portal\modules\module_base
|
||||
'ATTACH_ID' => $row['attach_id'],
|
||||
'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
|
||||
'POST_MSG_ID' => $row['post_msg_id'], // grab post ID to redirect to post
|
||||
'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $row['attach_id']),
|
||||
'U_TOPIC' => append_sid($phpbb_root_path . 'viewtopic.'.$phpEx, 'p='.$row['post_msg_id'].'#p'.$row['post_msg_id']),
|
||||
'U_FILE' => append_sid($this->phpbb_root_path . 'download/file.' . $this->php_ext, 'id=' . $row['attach_id']),
|
||||
'U_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 'p='.$row['post_msg_id'].'#p'.$row['post_msg_id']),
|
||||
));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$template->assign_var('S_DISPLAY_ATTACHMENTS', true);
|
||||
$this->template->assign_var('S_DISPLAY_ATTACHMENTS', true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$template->assign_var('S_DISPLAY_ATTACHMENTS', false);
|
||||
$this->template->assign_var('S_DISPLAY_ATTACHMENTS', false);
|
||||
}
|
||||
|
||||
return 'attachments_' . $type . '.html';
|
||||
Reference in New Issue
Block a user