News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Post.template + is_first_post

Started by Ncen, June 04, 2011, 05:20:07 PM

Previous topic - Next topic

Ncen

Hi,

I've added:if ($context['is_first_post'] && $context['is_new_post']) to my post.template file, just above the post box, so that i could manipulate the box a little bit. That works well, however that box is the same used in PersonalMessages and while is_new_post is not showing up any errors, the is_first_post does.

I get a "Undefined index: is_first_post" from my "Post.template.php" which indicates that there's an issue, i assume that while is_new_post works well in PM, is_first_post does not. However, i do need to use this code in the post file, and i need to target the textarea with it.

Would it be necessary to duplicate the whole function, and use different "postbox"-functions for PM and boardposting? Or could i somehow teach PM that is_first_post could be ignored?


if ($context['is_first_post'] && $context['is_new_post'])
{
if ($context['current_board'] == '2.0' || $context['current_board'] == '3.0')
{ -redesigned textarea here- }
else
{ -original textarea here- }
}
else
{ -original textarea here- }


I do realize that i could have written that a bit simpler and avoided having the original code twice, but i wasn't sure how to write that. I've learned mostly by trial and error, and not much using a text book.

Thank you for taking the time to read this. :)

I'm using SMF 1.1.13

ascaland

Hmm, ok I thought about this for a bit and came to a single conclusion: singling out $context['is_first_post']. So how about replacing,
if ($context['is_first_post'] && $context['is_new_post'])
Code (With) Select
// Be sure we are in the right place to have $context['is_first_post'] utilized, if not, just set to true so $context['is_new_post'] is the next determinant
$is_first_post = !empty($context['is_first_post']) ? $context['is_first_post'] : true;
if ($is_first_post && $context['is_new_post'])

Ncen

Alright, i tried that and this is what happened:

When PM:ing, i had no issue with is_first_post, but now it reacted to is_new_post instead, and i got an error there instead. Seems both need to be singled out if it's a PM.
And also, it seemed like is_first_post was automatically true if is_new_post was, so in topics it treated all posts as first posts. :/

I want to target only the first post, in only certain board, and only when you first write it, not while editing. Perhaps i need to rework the code somehow? Could i somehow use if action=pm or if action=post. Since PM just seems to tap into the code from Post.template? Not sure how to write that, though.

Ncen

#3
Is this secure?

I opened up:
Subs-Post.php, Post.template.php and PersonalMessage.template.php
And searched for postbox, and in Subs-Post i duplicated the function (copy paste, so i got the same), and named the new one "function theme_postbox($msg)2" and in PersonalMessage i change it to "theme_postbox2($context['message']);" and went over to Post.template, duplicated the postbox function once again, and renamed it also. then i just removed the new code all together and left the normal textarea.
What i thought was, that if it uses a different function i could have PM using a new (but original) code for postbox and Post (topic and reply) would use the one which calls for is_new_post and is_first_post.
What I'm worried about is if I messed up something? So that PM would not work or be unsafe and so on?

Edit:
I would prefer to work out the code so i don't have to use another function for PM, but my members send a lot of personal messages to each other and it was filling up the error log so i tried it out. My solution is more of a temporary fix, and i changed it back.


Right, so i tried that and it seemed to work, but it's a lot of edits, so i thought about that and then changed it back. What i'm thinking of now is. Could i use "if topic?"-something something? :-\ not sure how to do that either though.

ascaland

Oops, forgot momentarily empty() also checks if the variable holds a false/null value which it would if the posts werent new. Makes sense. But since you have a new issue, perhaps you can check to make sure your not in a topic. In that case, perhaps,
// If we arent in a topic, go ahead without the checks. If we are, perform the checks.
if (empty($context['current_topic']) || ($context['is_first_post'] && $context['is_new_post']))


Hopefully this works, not at home at the moment.

Ncen

#5
Thank you! That seemed to work. But the new issues keeps on coming, while that works this part:

if ($context['current_board'] == '2.0' || $context['current_board'] == '3.0' || $context['current_board'] == '8.0' || $context['current_board'] == '9.0')

which comes next is giving me the same error, now with current_board. i thought i would be able to use the same code here, adding empty and that somehow, but that didn't seem to work (might have written it incorrectly though).


Edit:
I changed that code to:
if (!empty($context['current_board']) && ($context['current_board'] == '2.0' || $context['current_board'] == '3.0' || $context['current_board'] == '8.0' || $context['current_board'] == '9.0'))

And now i think it works, but i'm not really sure, it doesn't give me any errors. However i've not completely checked all the boards and so on. Is that correctly written?

ascaland

if (empty($context['current_board']) || ($context['current_board'] == '2.0' || $context['current_board'] == '3.0' || $context['current_board'] == '8.0' || $context['current_board'] == '9.0'))
This if statement will check if there is a $context['current_board'] in existence, if it is, then it will check to see if its one of those in the second bracket. If it doesnt exist, it will immediately execute code in the block. Hopefully thats what you mean.

Ncen

I want it to skip that block  and go to the else tag <b>unless</b> it is a topic, and it is in one of those boards. So if it's a PM it will jump to else, and if its a topic somewhere else (not in those boards) it will also jump to the else tag. :)

ascaland

Then in that case your above code looked correct.

Ncen

It seems to work too, no more errors! :D Alright, thank you for your help! :)

Advertisement: