{postrow.POST_AUTHOR_FULL} Availability in attachment.html

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 2797
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

{postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by thecoalman » Fri Sep 07, 2018 12:21 pm

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.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51344
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by Brf » Fri Sep 07, 2018 1:24 pm

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.

User avatar
3Di
Registered User
Posts: 12943
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by 3Di » Sat Sep 08, 2018 6:03 am

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

Code: Select all

'COMMENT'			=> $comment,
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..
.
Screenshot_2.png
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20925
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by RMcGirr83 » Sat Sep 08, 2018 11:01 am

Did you just suggest he add a query within a loop?
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
3Di
Registered User
Posts: 12943
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by 3Di » Sat Sep 08, 2018 11:04 am

Did I? If so... my bad. :)
Feel free to correct my suggestion then.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 20925
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by RMcGirr83 » Sat Sep 08, 2018 11:13 am

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.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

User avatar
3Di
Registered User
Posts: 12943
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by 3Di » Sat Sep 08, 2018 12:19 pm

The @event core.parse_attachments_modify_template_data is the best bet at the end of all, so an extension.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1886
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by kinerity » Sat Sep 08, 2018 6:02 pm

That's still within the loop. Maybe modify the query itself with a left join?
Kailey Truscott - Community Team

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 2797
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: {postrow.POST_AUTHOR_FULL} Availability in attachment.html

Post by thecoalman » Sat Sep 08, 2018 8:22 pm

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.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 5 guests