Page 1 of 1
{postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Fri Sep 07, 2018 12:21 pm
by thecoalman
Is there an easy way to make this template variable that is available in viewtopic_body.html also available in attachment.html?
I'm aware of the template variables for attachments around line 1186 of functions_content.php but as far as I can tell there is no source for the post author.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Fri Sep 07, 2018 1:24 pm
by Brf
I was thinking the loop variables were only available in the file the loop existed in.
The "postrow" loop exists in the viewtopic_body template, so is not available in the attachment template which is included there.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 6:03 am
by 3Di
functions_content.php, find... #1138
Code: Select all
$row['attach_comment'] = $attachments[$attach_ids[$row['attach_id']]]['attach_comment'];
after add
Code: Select all
$row['poster_id'] = $attachments[$attach_ids[$row['attach_id']]]['poster_id'];
find
Code: Select all
$comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
after add
Code: Select all
global $db;
$sql = 'SELECT user_id, username, user_colour
FROM ' . USERS_TABLE . '
WHERE user_id = ' . (int) $attachment['poster_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$post_author_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
find
after add
Code: Select all
'POST_AUTHOR_FULL' => $post_author_full,
in attachment.html you can use now
{_file.POST_AUTHOR_FULL}
where you want..
.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 11:01 am
by RMcGirr83
Did you just suggest he add a query within a loop?
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 11:04 am
by 3Di
Did I? If so... my bad.
Feel free to correct my suggestion then.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 11:13 am
by RMcGirr83
3Di wrote: ↑Sat Sep 08, 2018 6:03 am
Code: Select all
global $db;
$sql = 'SELECT user_id, username, user_colour
FROM ' . USERS_TABLE . '
WHERE user_id = ' . (int) $attachment['poster_id'];
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$post_author_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
find
Is in loop and you should correct it yourself.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 12:19 pm
by 3Di
The @event core.parse_attachments_modify_template_data
is the best bet at the end of all, so an extension.
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 6:02 pm
by Kailey
That's still within the loop. Maybe modify the
query itself with a left join?
Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html
Posted: Sat Sep 08, 2018 8:22 pm
by thecoalman
Thanks 3Di, I already considered doing a query in the function but the attachment feature is quite popular on my forum so not really a great idea. I also considered adding an argument to the function but that function is used in a lot of places so not really a great idea either.
The reason I wanted it was because I'm using a "copy to clipboard" link that holds a BBcode for linking to local uploaded images. I wanted to include the post author withe some "posted by" text. It's not that important so I'll just skip it.