[SOLVED] viewtopic-body.html - IF user is viewing own post

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
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

[SOLVED] viewtopic-body.html - IF user is viewing own post

Post by Gumboots »

I'm after the right condition to throw in the template to detect if the user who made the post is looking at the page. Essentially...

Code: Select all

<!-- IF MUPPET_STARING_AT_THIS.POSTED_IT -->Do stuff here<!-- ENDIF -->
Reason being that I'm not in the habit of composing love letters to myself (there being some limits to my narcissism) so echoing the standard contact details in my own .postprofile is about as useful as a chocolate teapot. Makes more sense to switch them out for a link to my inbox and .badge with the unread count.

Edited topic title for typo.
Last edited by Gumboots on Tue Aug 20, 2024 12:55 am, edited 3 times in total.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Mike-on-Tour
Registered User
Posts: 567
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: viewtopc-body.html - IF user is viewing own post

Post by Mike-on-Tour »

If it is just for you you can use the template variable USER_ID ( I hope this is right) and check it against yours. If both are Equalizer just display another DIV with the info you like.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

Re: viewtopc-body.html - IF user is viewing own post

Post by Gumboots »

No, I want a general condition that will work for all users. :)
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Mike-on-Tour
Registered User
Posts: 567
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: viewtopc-body.html - IF user is viewing own post

Post by Mike-on-Tour »

That - I am afraid - will need some PHP code, so either you alter a phpBB core file (not recommended) or write a small extension.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
User avatar
cabot
Jr. Style Validator
Posts: 1010
Joined: Sat Jan 07, 2012 4:16 pm

Re: viewtopc-body.html - IF user is viewing own post

Post by cabot »

Hello,

By using Twig same as on POST_AUTHOR_FULL and CURRENT_USERNAME_FULL?

Code: Select all

		{% if S_REGISTERED_USER and S_DISPLAY_PM and (postrow.POST_AUTHOR_FULL is same as(CURRENT_USERNAME_FULL)) %}
			<dd class="profile-pm-inbox">
				<a href="{{ U_PRIVATEMSGS }}">
					<span>{{ lang('PRIVATE_MESSAGES') }}</span>{% if PRIVATE_MESSAGE_COUNT %} <strong class="badge">{{ PRIVATE_MESSAGE_COUNT }}</strong>{% endif %}
				</a>
			</dd>
		{% elseif not S_IS_BOT and postrow.contact %}
			<dd class="profile-contact">
				{# ... #}
			</dd>
		{% endif %}
You'll then need to adjust the style using the .profile-pm-inbox:has(.badge) selector to, among other things, overwrite the overflow/hidden on dd and fine-tune the alignment and colour of the badge.
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

Re: viewtopc-body.html - IF user is viewing own post

Post by Gumboots »

The CSS and markup side of it is no worries. I can do that in my sleep. I just needed the conditional sorted.

Cheers. :)
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
danieltj
Infrastructure Team Member
Infrastructure Team Member
Posts: 690
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by danieltj »

When you say you need the right conditional, do you mean an if statement that checks if the current user is the post author or something else?
MY EXTENSIONS:
Verified Profiles | API | Awesome Payments

Available for paid extension work.
User avatar
cabot
Jr. Style Validator
Posts: 1010
Joined: Sat Jan 07, 2012 4:16 pm

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by cabot »

Yup, comparing user ID would be ideal and safer than comparing those strings returned by template var. :/
User avatar
danieltj
Infrastructure Team Member
Infrastructure Team Member
Posts: 690
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by danieltj »

Apparently it’s solved now as per the title so I guess the OP figured it out.
MY EXTENSIONS:
Verified Profiles | API | Awesome Payments

Available for paid extension work.
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by Gumboots »

cabot wrote: Sun Aug 18, 2024 1:14 pm Yup, comparing user ID would be ideal and safer than comparing those strings returned by template var. :/
Yes, that was what I was expecting. Comparing the whole box of frogs is messy, and ID would be much simpler. Obviously the software keeps track of post author ID and current user ID, so it's just a question of if those variables can be made available directly in the template.

Getting {postrow.POSTER_ID} in the template is a piece of cake. I have already done that. But, there doesn't appear to be any way of getting {CURRENT_USER_ID} - or something functionally similar - in the template. Obviously I could do a core hack and make it available, but I'd prefer not to.

ETA: If there is absolutely no way of getting {CURRENT_USER_ID} in the template with current core code, I think I will suggest it in phpBB Ideas. It's an obvious global variable to have available, with a range of potential uses. Cleaning up useless contact details and replacing them with something useful is just one use case. I'm sure people could think of a dozen more without too much difficulty.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 4032
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by Kailey »

Gumboots wrote: Sun Aug 18, 2024 9:04 pm If there is absolutely no way of getting {CURRENT_USER_ID} in the template with current core code, I think I will suggest it in phpBB Ideas. It's an obvious global variable to have available, with a range of potential uses. Cleaning up useless contact details and replacing them with something useful is just one use case. I'm sure people could think of a dozen more without too much difficulty.
I personally can't think of a use case, but as you said others may have a need. For now, a small extension should be able to accomplish this. All you really need to do is hoot into an event loaded on each page (page_header, for example) and assign code like so:

Code: Select all

$this->template->assign_var('CURRENT_USER_ID', $this->user->data['user_id']);
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

Re: [SOLVED] viewtopc-body.html - IF user is viewing own post

Post by Gumboots »

For the moment I'm going with this. It looks tidy with or without unread PM's.

Code: Select all

			{% if S_REGISTERED_USER and S_DISPLAY_PM and (postrow.POST_AUTHOR_FULL is same as (CURRENT_USERNAME_FULL)) %}				
				<dd class="profile-inbox">
					<a href="{{ U_PRIVATEMSGS }}"><i class="icon fa-inbox fa-fw" aria-hidden="true"></i> {L_PM}{% if PRIVATE_MESSAGE_COUNT %}{L_COLON} <strong>[{{ PRIVATE_MESSAGE_COUNT }}]{% endif %}</strong></a>
				</dd>
			{% elseif not S_IS_BOT and postrow.contact %}
Edit: It actually works better if I remember to put the closing tag on the anchor. :lol:

Edit again: And come to think of it, revamping the contact dd itself to put the icon before the text, and the text inside the trigger anchor, would look better and be more consistent with the rest of the GUI. It'd also provide a saner target size for most users.

Done. :P

Contact_stuff.jpg
You do not have the required permissions to view the files attached to this post.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
User avatar
Gumboots
Registered User
Posts: 821
Joined: Fri Oct 11, 2019 1:59 am

Re: [SOLVED] viewtopic-body.html - IF user is viewing own post

Post by Gumboots »

After figuring this one out - viewtopic.php?t=2655820 - I tried an alternative method of dealing with the lack of a CURRENT_USER_ID variable. This also works...

Code: Select all

			{% set currentUserId = CURRENT_USERNAME_FULL | trim('<a href="./memberlist.php?mode=viewprofile&amp;u=') | split('"')[0] %}

			{% if S_REGISTERED_USER and S_DISPLAY_PM and (postrow.POSTER_ID is same as currentUserId) %}				
				<dd class="profile-inbox">
It's cleaner in one sense, in that it just calls postrow.POSTER_ID instead of postrow.POST_AUTHOR_FULL. On other other hand, it relies on running trim and split on CURRENT_USERNAME_FULL first, before running the comparison with postrow.POSTER_ID, so whether it's actually better or not is anyone's guess.

Obviously you could run trim twice, but the cleaner syntax of split('"')[0] seemed better. It avoids having to use wildcards to deal with the inline style for username colour.

Anyway, this works. Functionally it's identical to Cabot's solution, but since I had to play with this stuff to figure out something else I thought I'd use this solution.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
SQLnovice
Registered User
Posts: 170
Joined: Thu Oct 10, 2019 5:03 am

Re: [SOLVED] viewtopic-body.html - IF user is viewing own post

Post by SQLnovice »

Gumboots wrote: Tue Aug 20, 2024 3:04 am After figuring this one out - viewtopic.php?t=2655820 - I tried an alternative method of dealing with the lack of a CURRENT_USER_ID variable. This also works...

Code: Select all

			{% set currentUserId = CURRENT_USERNAME_FULL | trim('<a href="./memberlist.php?mode=viewprofile&amp;u=') | split('"')[0] %}

			{% if S_REGISTERED_USER and S_DISPLAY_PM and (postrow.POSTER_ID is same as currentUserId) %}				
				<dd class="profile-inbox">
It's cleaner in one sense, in that it just calls postrow.POSTER_ID instead of postrow.POST_AUTHOR_FULL. On other other hand, it relies on running trim and split on CURRENT_USERNAME_FULL first, before running the comparison with postrow.POSTER_ID, so whether it's actually better or not is anyone's guess.

Obviously you could run trim twice, but the cleaner syntax of split('"')[0] seemed better. It avoids having to use wildcards to deal with the inline style for username colour.

Anyway, this works. Functionally it's identical to Cabot's solution, but since I had to play with this stuff to figure out something else I thought I'd use this solution.
:?: Our moderators have been requesting just this ability. But it doesn't work for me, just shows a ruined forum blank page, like the page's code is incomplete and can't be read correctly.

Although, I wasn't clear on where in viewtopic_body.html to insert this code, so I put it just above the last line, between these two:

Code: Select all

{% EVENT viewtopic_body_online_list_after %}

<!-- INCLUDE overall_footer.html -->
I tried your previous code too in the same place with the same result. The host's text editor seems to proofread the changes too as to whether the syntax belongs. Excluding the <dd class... line, the others appeared with red Xs next to them, so I fully expected the added code insert to fail (PHP 3.3.14).

Forgive me for my lack of PHP code knowledge, but none of the other posts were written in a way I could understand what needed to be changed or which file needed to be modified where. :( I throw my hands up in these cases because my chances of success are about as bright as bringing a retro encabulator online.
SQLnovice
Registered User
Posts: 170
Joined: Thu Oct 10, 2019 5:03 am

Re: viewtopc-body.html - IF user is viewing own post

Post by SQLnovice »

cabot wrote: Sun Aug 18, 2024 10:07 am Hello,

By using Twig same as on POST_AUTHOR_FULL and CURRENT_USERNAME_FULL?

Code: Select all

		{% if S_REGISTERED_USER and S_DISPLAY_PM and (postrow.POST_AUTHOR_FULL is same as(CURRENT_USERNAME_FULL)) %}
			<dd class="profile-pm-inbox">
				<a href="{{ U_PRIVATEMSGS }}">
					<span>{{ lang('PRIVATE_MESSAGES') }}</span>{% if PRIVATE_MESSAGE_COUNT %} <strong class="badge">{{ PRIVATE_MESSAGE_COUNT }}</strong>{% endif %}
				</a>
			</dd>
		{% elseif not S_IS_BOT and postrow.contact %}
			<dd class="profile-contact">
				{# ... #}
			</dd>
		{% endif %}
You'll then need to adjust the style using the .profile-pm-inbox:has(.badge) selector to, among other things, overwrite the overflow/hidden on dd and fine-tune the alignment and colour of the badge.
:?: :? Does it matter where the code is inserted into viewtopic_body.html? And what does the last sentence mean? If it's clear to the others reading this, can you help out with a How-to for accomplishing IF user is viewing own post?

We're very interested in making this change to our forum, but wow! It's like the whole other part of this conversation about how this topic was solved got deleted.

Return to “phpBB Custom Coding”