Skip to content

Commit

Permalink
Merge pull request #530 from emanuele45/profile_attachments
Browse files Browse the repository at this point in the history
Profile attachments
  • Loading branch information
norv committed Jun 17, 2013
2 parents 83ba8e4 + 72ec024 commit 393df62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sources/controllers/ProfileInfo.controller.php
Expand Up @@ -197,13 +197,12 @@ function action_summary()

// Load up the most recent attachments for this user for use in profile views etc.
$context['thumbs'] = array();
if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments') && !empty($settings['attachments_on_summary']))
{
$limit = 8;
$boardsAllowed = boardsAllowedTo('view_attachments');
if (empty($boardsAllowed))
$boardsAllowed = array(-1);
$attachments = list_getAttachments(0, $limit, 'm.poster_time DESC', $boardsAllowed , $context['member']['id']);
$attachments = list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed , $context['member']['id']);

// load them in to $context for use in the template
$i = 0;
Expand Down Expand Up @@ -715,7 +714,7 @@ function action_showAttachments()
*/
function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
{
global $board, $modSettings, $context;
global $board, $modSettings, $context, $settings, $scripturl, $txt;

$db = database();

Expand Down Expand Up @@ -750,6 +749,12 @@ function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $me
);
$attachments = array();
while ($row = $db->fetch_assoc($request))
{
if (!$row['approved'])
$row['filename'] = str_replace(array('{attachment_link}', '{txt_awaiting}'), array('<a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . '">' . $row['filename'] . '</a>', $txt['awaiting_approval']), $settings['attachments_awaiting_approval']);
else
$row['filename'] = '<a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . '">' . $row['filename'] . '</a>';

$attachments[] = array(
'id' => $row['id_attach'],
'filename' => $row['filename'],
Expand All @@ -759,14 +764,15 @@ function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $me
'downloads' => $row['downloads'],
'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']),
'id_thumb' => $row['id_thumb'],
'subject' => censorText($row['subject']),
'subject' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . censorText($row['subject']) . '</a>',
'posted' => $row['poster_time'],
'msg' => $row['id_msg'],
'topic' => $row['id_topic'],
'board' => $row['id_board'],
'board_name' => $row['name'],
'approved' => $row['approved'],
);
}

$db->free_result($request);

Expand Down
12 changes: 12 additions & 0 deletions themes/default/ProfileInfo.template.php
Expand Up @@ -14,6 +14,18 @@
* @version 1.0 Alpha
*/

function template_ProfileInfo_init()
{
global $settings;

// This piece is used to style attachments awaiting approval in the list
$settings['attachments_awaiting_approval'] = '{attachment_link}&nbsp;(<em>{txt_awaiting}</em>)';

// This setting is used to load a certain number of attachments
// in the user's profile summary, change it to a number if you need any
$settings['attachments_on_summary'] = 0;
}

/**
* This template displays users details without any option to edit them.
*/
Expand Down

0 comments on commit 393df62

Please sign in to comment.