TinyPortal

Development => Support => Topic started by: Inge Jones on May 12, 2012, 09:44:37 AM

Title: Get message/post id while editing post
Post by: Inge Jones on May 12, 2012, 09:44:37 AM
I want a TP php block to appear when a user is posting, and I want this block to know what the message number is.  (I do realise this is not possible when posting a new message, as the message number has not yet been allocated.  )  But anyway this block is meant be used during an *edit* of an existing post, to offer various things that need to know the message number (I won't bore you with details unless asked).

I have tried the established $context['message']['id'] and variations on that.  I have also tried $message = $context['get_message']() and then testing $message['id'] etc  but it all comes back empty, even though the function call itself returns true!

Any other ideas for detecting the number of the post you're editing - or even viewing!
Title: Re: Get message/post id while editing post
Post by: Inge Jones on May 12, 2012, 06:01:14 PM
Ok I decided to do it by topic number instead, which can be accessed easily :)
Title: Re: Get message/post id while editing post
Post by: IchBin on May 13, 2012, 12:02:56 AM
If you do a print_r($context) you'll probably see that there is a key some where in the array that shows you the id of the message that you are editing.
Title: Re: Get message/post id while editing post
Post by: Inge Jones on May 13, 2012, 10:03:57 AM
I did that but I could still only find the message number itself in $context['querystring'] which I have to say surprised me - and I didn't fancy having to parse out that string.  Anyway fortunately when I rethought the project, connecting the procedure with the topic did actually make more sense :)
Title: Re: Get message/post id while editing post
Post by: Inge Jones on May 14, 2012, 10:09:25 PM
...However, now I would really like to find out if current user was author of first post in thread.  Any ideas?  $context['current_topic'] has no subkeys, so I hit a dead end using that to get to first post in the topic.

Later:  Ok I am getting the result by using this:

$previous = $context['previous_posts'];
$lastpos = count($previous) - 1;
$firstpost = $previous[$lastpos];
$topic_owner = $firstpost['poster'];