Unreported: Attachments from specific forum(s) (block and installer)

This commit is contained in:
Ice
2008-02-14 21:52:04 +00:00
parent a6359f9685
commit bb3026f9e6
3 changed files with 72 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
<?php
$current_version = '0.2.1';
$current_version = '0.2.2';
// If only checking version, exit.
if( defined('IN_PHPBB') )

View File

@@ -7,4 +7,7 @@ $sql_update['0.2.0'] = array(
"INSERT INTO phpbb_portal_config (config_name, config_value) VALUES ('portal_birthdays_ahead', '7')",
);
$sql_update['0.2.2'] = array(
"INSERT INTO phpbb_portal_config (config_name, config_value) VALUES ('pportal_attachments_forum_ids', '')",
);
?>

View File

@@ -19,56 +19,87 @@ if (!defined('IN_PORTAL'))
{
exit;
}
$portal_config['portal_attachments_forum_ids'] = '2';
$attach_forums = false;
$where = '';
$allowed_forums = array_unique(array_keys($auth->acl_getf('f_read', true)));
foreach( $allowed_forums as $allowed_id )
if( $portal_config['portal_attachments_forum_ids'] !== '' )
{
$where .= 't.forum_id = \'' . $allowed_id . '\' OR ';
$attach_forums_config = ( strpos($portal_config['portal_attachments_forum_ids'], ',') !== FALSE ) ? explode(',', $portal_config['portal_attachments_forum_ids']) : array($portal_config['portal_attachments_forum_ids']);
$forum_list = array_unique(array_keys($auth->acl_getf('f_read', true)));
$forum_list = array_unique( array_intersect($attach_forums_config, $forum_list) );
}
else
{
$forum_list = array_unique(array_keys($auth->acl_getf('f_read', true)));
}
if( sizeof($forum_list) )
{
foreach($forum_list as $af )
{
$af = (int) trim($af);
$attach_forums = true;
$where .= 't.forum_id = \''.$af.'\' OR ';
}
}
if( $where != '' )
{
$where = 'AND (' . substr($where, 0, -4) . ')';
}
// Just grab all attachment info from database
$sql = 'SELECT
a.*,
t.forum_id
FROM
' . ATTACHMENTS_TABLE . ' a,
' . TOPICS_TABLE . ' t
WHERE
a.topic_id <> 0
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, $portal_config['portal_attachments_number']);
while ($row = $db->sql_fetchrow($result))
if( $attach_forums === TRUE )
{
$size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MB'] : (($row['filesize'] >= 1024) ? $user->lang['KB'] : $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']);
// Just grab all attachment info from database
$sql = 'SELECT
a.*,
t.forum_id
FROM
' . ATTACHMENTS_TABLE . ' a,
' . TOPICS_TABLE . ' t
WHERE
a.topic_id <> 0
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, $portal_config['portal_attachments_number']);
$replace = str_replace(array('_','.zip','.jpg','.gif','.png','.ZIP','.JPG','.GIF','.PNG','.','-'), ' ', $row['real_filename']);
while ($row = $db->sql_fetchrow($result))
{
$size_lang = ($row['filesize'] >= 1048576) ? $user->lang['MB'] : (($row['filesize'] >= 1024) ? $user->lang['KB'] : $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']);
$template->assign_block_vars('attach', array(
'FILESIZE' => $row['filesize'] . ' ' . $size_lang,
'FILETIME' => $user->format_date($row['filetime']),
'DOWNLOAD_COUNT' => (int) $row['download_count'], // grab downloads count
'REAL_FILENAME' => $replace,
'PHYSICAL_FILENAME' => basename($row['physical_filename']),
'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']),
$replace = str_replace(array('_','.zip','.jpg','.gif','.png','.ZIP','.JPG','.GIF','.PNG','.','-'), ' ', $row['real_filename']);
$template->assign_block_vars('attach', array(
'FILESIZE' => $row['filesize'] . ' ' . $size_lang,
'FILETIME' => $user->format_date($row['filetime']),
'DOWNLOAD_COUNT' => (int) $row['download_count'], // grab downloads count
'REAL_FILENAME' => $replace,
'PHYSICAL_FILENAME' => basename($row['physical_filename']),
'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']),
));
}
$db->sql_freeresult($result);
// Assign specific vars
$template->assign_vars(array(
'S_DISPLAY_ATTACHMENTS' => true,
));
} else {
// Assign specific vars
$template->assign_vars(array(
'S_DISPLAY_ATTACHMENTS' => false,
));
}
$db->sql_freeresult($result);
// Assign specific vars
$template->assign_vars(array(
'S_DISPLAY_ATTACHMENTS' => true,
));
?>