[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
cabot
Jr. Style Validator
Posts: 990
Joined: Sat Jan 07, 2012 4:16 pm

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

Post by cabot »

In viewtopic_body.html, find:

Code: Select all

		<!-- IF not S_IS_BOT and .postrow.contact -->
			<dd class="profile-contact">
Replace with:

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">
Add at the end of colours.css and adjust to suit your needs:

Code: Select all

.profile-pm-inbox .badge {
	color: #fff;
	float: none;
	font-weight: bold;
	margin: 0.2em 0;
	padding: 2px 4px;
	top: auto;
}
SQLnovice
Registered User
Posts: 159
Joined: Thu Oct 10, 2019 5:03 am

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

Post by SQLnovice »

TY, cabot! What is the 'badge' that's suppose to change, the PM badge? Should I be looking to see if the color changes to something that signifies the the OP is viewing the topic they authored, which is the one that I'm also in viewing?

I double checked that I made those changes or additions to both files, cleared the forum cache and didn't see anything different. A user had just posted, so I was monitoring their status and the topic they authored. Who Is Online showed they were 'reading' a topic in the forum they'd just posted in, so I was certain they were in that topic. But looking at their avatar box, I couldn't tell that there was anything that changed. Nada. :? The changes were made to Prosilver and to our secondary style (PHP 3.3.14, PHP 8.2 or 8.3), so see if perhaps I was missing 'a change' in one or the other. Nothing appeared different.

For now, I left the code changes in place and asked the other moderators to see if they might notice anything different. We may need to test on a new topic too. So, I don't want to say for certain that the code changes didn't work. For now, I'm hopeful something may spring up in future new topics, but as of now, I'm not seeing it.
User avatar
cabot
Jr. Style Validator
Posts: 990
Joined: Sat Jan 07, 2012 4:16 pm

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

Post by cabot »

You won't see any difference in other users' mini-profiles, but in your own. ^^

Look at your own posts. If you're logged in, the contact link is replaced by a link to the PM inbox.
SQLnovice
Registered User
Posts: 159
Joined: Thu Oct 10, 2019 5:03 am

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

Post by SQLnovice »

So as not to carrying on this discussion in a topic that may be asking a very similar question, I've started a new topic. viewtopic-body.html - IF topic author is currently viewing a topic they have authored
SQLnovice
Registered User
Posts: 159
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.
Gumboots, this is on a more advanced level that I can decipher or something else is missing. I tried your code above and not even my PHP editor likes adding it. When forced into around line 177 the forum goes blank.

Can you enlighten us on what solution you found? Cabot has been gracious enough to lend his assistance, but when I'm not able to follow in your footsteps.
User avatar
Gumboots
Registered User
Posts: 812
Joined: Fri Oct 11, 2019 1:59 am

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

Post by Gumboots »

Sorry about the delay in responding.

At the time I made that post I was not giving bulletproof instructions for beginners. It was just a shorthand illustration of the concept, for people who were more experienced with template coding.

<dd class="profile-inbox"> was one of my experimental additions to the template, since the functionality I was adding was not something that was in default. Your problems are due to the fact that the complete markup for that dd does not exist in your template, so apart from anything else the {% endif %} closing tag for the initial {% if does not exist either. This will give you a white page.

The complete code for that dd ended up as follows (and yes, I changed the dd class name).

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-contact">
					<a href="{{ U_PRIVATEMSGS }}" title="{L_PRIVATE_MESSAGES}">
						<i class="icon fa-inbox fa-fw" aria-hidden="true"></i>
						<span class="sr-only">{L_PRIVATE_MESSAGES}</span>
						<strong>{L_PM}{% if PRIVATE_MESSAGE_COUNT %}{L_COLON} [{{ PRIVATE_MESSAGE_COUNT }}]{% endif %}</strong>
					</a>
				</dd>
			{% elseif not S_IS_BOT and postrow.contact %}
				<dd class="profile-contact">
					<!-- BEGIN contact -->
					<a href="{% if postrow.contact.U_CONTACT %} {postrow.contact.U_CONTACT} {% else %} {postrow.U_POST_AUTHOR} {% endif %}" title="{postrow.contact.NAME}">
						<strong aria-hidden="true"><i class="icon fa-commenting-o"></i> {L_CONTACT}</strong>
						<span class="sr-only">{postrow.contact.NAME}</span>
					</a>
					<!-- END contact -->
				</dd>	
			{% endif %}
Do note that this was written for my own preferences, and may change some things you do not want changed. For example, it simplifies the contact options for other members' post profiles, because PM is the only one used on the site I run.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦
SQLnovice
Registered User
Posts: 159
Joined: Thu Oct 10, 2019 5:03 am

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

Post by SQLnovice »

Cool! I'll give it a try later. I'm working through another site project for now.

Thank you for getting back to us with that info!
User avatar
Anișor
Translator
Posts: 361
Joined: Tue Jan 08, 2013 9:36 pm
Location: Angus, Scotland 🏴󠁧󠁢󠁳󠁣󠁴󠁿

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

Post by Anișor »

IDK why y'all complicating this.
Kailey gave you the easiest and cleanest method ever but you've chosen to use this spaghetti instead.
You could literally do a {% if CURRENT_USER_ID == postrow.POSTER_ID %} stuff for me only in my post {% endif %}.
User avatar
Gumboots
Registered User
Posts: 812
Joined: Fri Oct 11, 2019 1:59 am

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

Post by Gumboots »

Doing it with the spaghetti means all the hacks are in one place. No need for another pile of files.
🇺🇦 Слава Україні! 🇺🇦 Героям слава! 🇺🇦

Return to “phpBB Custom Coding”