MyBB Community Forums

Full Version: Thread has a new post programmatically
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi everyone,
Just looked into Mybb 1.8 API and unfortunately cannot find anything Sad
I looking for some query or function or any other programmatically way to know: "is there any unread new post in a thread or not?"
Something like Forum has new Posts, but for threads.
So how can I do that?
How exactly do you want to get this information? By PHP or browser end? How do you want to process such data, within a MyBB plugin or any other outside script?
Hey,
as of now, there's no stable free API for MyBB available. There is this, which - while I wouldn't recommend using on live boards - I've been using for some time and it seems to work just fine. Considering its age, you will need to fix a couple of things and there's no telling if there's some huge security flaw, but.. it works.
Though, if all you're looking for is unread posts, then you won't need an API of this scale.
Your desire makes sense for members only.
So the resolution is the header link "View New posts".

You can find the functions in ./search.php (... input['action'] == "getnew")

[ExiTuS]
Actually I want to get those information via PHP, cause I modify some modules which I downloaded from here and there is a lot of problems there which causes server load!! as example:


$query_thread_sub = $db->query ("SELECT subject FROM ".TABLE_PREFIX."threads WHERE tid='$tid'");
$fetch_thread_sub=$db->fetch_array($query_thread_sub);
$thread_sub = htmlspecialchars_uni(substr($fetch_thread_sub['subject'],0,150));


which I replaced with this:

$thread = get_thread($tid);
$thread_sub = htmlspecialchars_uni($thread[subject]);


In part of code, I need to know the thread which is showed is readed by the user or not? of course if current user is guest then all of them will marked as unread. exactly like default behavior of MyBB. but in a stat module.
I'm a bit confused on the reasoning for changing that query. Maybe I'm misunderstanding what you are trying to explain.
(2020-04-03, 11:48 AM)Omar G. Wrote: [ -> ]I'm a bit confused on the reasoning for changing that query. Maybe I'm misunderstanding what you are trying to explain.

All I want is to know thread has new unread posts or not!
I had same thing on VB before migrating to MyBB and this plugin does not working correctly! so users cannot find which topic is still unread and which one is not!
+ this plugin need a lot of improvements cause of queries like what I sent before.


here is the plugin : https://community.mybb.com/mods.php?action=view&pid=93
have you tried using unread posts plugin (suggested in your earlier thread)

also, as [ExiTus] said,
checking new posts or daily posts can be a simple process.
threads with new posts are listed in bold font (can have different color [image])
(2020-04-02, 11:11 PM)sonixax Wrote: [ -> ]I looking for some query or function or any other programmatically way to know: "is there any unread new post in a thread or not?"
Something like Forum has new Posts, but for threads.
So how can I do that?

As far as I am aware, there's no simple function that you can call to get that information. If you wanted to roll your own, you would probably want to duplicate that part of the logic in forumdisplay.php which determines whether or not a green "goto unread" arrow is displayed for each given thread: basically, all of the code that contributes to the determination as to whether the $gotounread variable is set to the eval()uation of the 'forumdisplay_thread_gotounread' template (on line 1232).

Unfortunately, it wouldn't be a simple one- or two-liner function, because the logic is relatively involved and takes into account things like the read date cutoff for the forum in which the thread was posted. Perhaps you could ignore those sort of complexities, although then your function would be giving different results to that of core code.

Whether it would be efficient to roll a simple and "naive" function like that - which presumably would take a single thread ID and a single user ID and return whether or not the thread in question has unread posts for the user in question - would depend on the context(s) from which you were calling it, and in particular whether you were going to be calling it multiple times for multiple threads, because then you would potentially be unnecessarily causing multiple database queries (for each call) when only a few would be necessary - and you do seem to be concerned about efficiency. Potentially, you could do some caching within the function using a static variable to avoid some of those calls.

(2020-04-03, 02:12 PM)Laird Wrote: [ -> ]Unfortunately, it wouldn't be a simple one- or two-liner function, because the logic is relatively involved and takes into account things like the read date cutoff for the forum in which the thread was posted. Perhaps you could ignore those sort of complexities, although then your function would be giving different results to that of core code.

And earlier:

(2020-04-03, 01:48 PM).m. Wrote: [ -> ]have you tried using unread posts plugin (suggested in your earlier thread)

Interestingly, looking at the unread posts plugin, it does seem to ignore some of the logic that is present in forumdisplay.php, and instead uses just a single query to pull out unread threads.

Edit: It seems to be able to get away with this by introducing a 'lastmark' field for users.
You can check how MyBB builds the unread code in the fiollowing lines:
https://github.com/mybb/mybb/blob/featur...#L955-L974

And how to ultimately use it:
https://github.com/mybb/mybb/blob/featur...1201-L1239
Pages: 1 2