• Welcome to Simple Machines Community Forum. Please login or sign up.
January 29, 2022, 06:58:23 AM

News:

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


Post Notifier

Started by live627, February 09, 2014, 08:25:22 PM

Previous topic - Next topic

live627

February 09, 2014, 08:25:22 PM Last Edit: February 09, 2014, 08:50:21 PM by live627
Link to Mod

Post Notifier 1.0 by live627



This mod will add a ribbon at the top of the topic display that will show only if there are new posts within that topic. This, as you may have guessed, uses AJAX.

It updates every 60 seconds. To change, go and open ./Themes/defautl/scripts/postnotifier.js. Replace

60000

with

30000

and that will set the timer to 30 seconds, or 30,000 milliseconds.

https://github.com/live627/smf-post-notifier

v1.0.1
- Extra whitespace before opening PHP tag
- MIT license added

ApplianceJunk


Gryzor

Very nice, should be built-in functionality... thanks!

GamePersia

Can you make this mod for only pm notify also ??
and this mod only notifies newly made topics ??

eric1234

What shall I do if I want to include additional exclamation mark on the tab of the browser when there are new post that has been make?

Just like in the pic which i taken from another forum which also got the same function. Thank you in advance :)


live627

Go and open ./Themes/defautl/scripts/postnotifier.js. Replace

oDiv.style.display = 'block';

with

oDiv.style.display = 'block';
document.title = '(!!)' + document.title;

eric1234

Quote from: live627 on February 26, 2014, 06:48:39 PM
Go and open ./Themes/defautl/scripts/postnotifier.js. Replace

oDiv.style.display = 'block';

with

oDiv.style.display = 'block';
document.title = '(!!)' + document.title;

Thank you so  much. 1 more question , if i change the number from 60000 to 5000 means it will update every 5 seconds, will it affects the loading time or the server load?

and i notice that it will continue to add the exclamation mark every time it updates. SO is it possible just remain the exclamation mark as 1 set which is (!!) , no matter how many times it updates? 

eric1234


eric1234


eric1234


Gryzor


Storman™

If no one replies then it's usually because no one knows the answer.

margarett

Themes/defautl/scripts/postnotifier.js.
Find:
oDiv.style.display = 'block';
Add after:
var title = document.title;
var prefix = title.slice(0,4);
if (prefix != '(!!)')
document.title = '(!!)' + document.title;

(undo the previous change suggested by live627)

Quoteif i change the number from 60000 to 5000 means it will update every 5 seconds, will it affects the loading time or the server load?
Yes. Each "n" seconds a query at the database will be performed.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

eric1234

Quote from: margarett on March 05, 2014, 06:21:32 PM
Themes/defautl/scripts/postnotifier.js.
Find:
oDiv.style.display = 'block';
Add after:
var title = document.title;
var prefix = title.slice(0,4);
if (prefix != '(!!)')
document.title = '(!!)' + document.title;

(undo the previous change suggested by live627)

Quoteif i change the number from 60000 to 5000 means it will update every 5 seconds, will it affects the loading time or the server load?
Yes. Each "n" seconds a query at the database will be performed.
You the man, Thank you so much for it . :)

Actually mind to explain this part? Thank you in advance
var title = document.title;
var prefix = title.slice(0,4);

margarett

title is a string (actual window title). In JS, string.slice allows you to get a part of that string. So I got the first 4 characters. If they are not (!!), I add it. In the next cycle the first 4 characters are (!!) so I don't add anything anymore.
Just learned it while doing this :P I hate JS!
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

eric1234

Oh I see. Thank you so much for the explanation. Well, at least you learnt something new which I am glad that I asked this question. :)

kimyaci

I'm using SMF 2:07. But the mode does not work.Is there a setting? Thanks.

margarett

It does work, I'm using it (and for sure, other people too) ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

kimyaci

Quote from: margarett on March 23, 2014, 08:48:29 PM
It does work, I'm using it (and for sure, other people too) ;)

I'll follow.Thanks.

mikk

May 24, 2014, 08:59:17 PM #19 Last Edit: May 25, 2014, 07:09:32 AM by mikk
Hi!

Thanks for this mod, this is very good idea.

But I've got problem on SMF 2.0.7 with this mod. Ajax chat (smf version) is installed on my forum. If I install Post Notifier, the Ajax chat is not working anymore, I get error message, when I click to the chat button:

QuoteThis page contains the following errors:

error on line 1 at column 6: XML declaration allowed only at the start of the document

Below is a rendering of the page up to the first error.

chat button only execute this: http://my-web-page/chat
Without this mod, or after I uninstall this mod, the chat it works.

Any idea?

Thanks.

edit1.:
I found this: https://groups.google.com/forum/#!searchin/ajax-chat/XML$20declaration|sort:relevance/ajax-chat/YcYYA_Dn8tU/ge9huolFevUJ

OK, if I change in chat/lib/config.php
$config['contentType'] = null;
to
$config['contentType'] = 'text/html';

the result chat page is displayed without error, but it doesn't work.

edit2.:
I found what is the problem, and I solve it. In the "PostNotifier.php" file in this mod, the first char is space! Only this...

bros

I'm still having the issue I messaged you about after paying for this mod - it doesn't work on my big board - when looking at the network tab of inspect element of Chrome, it shows a space before the XML code starts.

samborabora

This works perfectly on the default theme but doesn't work at all on my custom theme. What should I check in general that might cause this mod to not display properly?

samborabora

I've checked both default and my custom theme in chrome developer tools, and the whole postnotifier script doesn't appear to be working, whereas it refreshes perfectly on the default theme. Is there a way I can check the script is being called?

samborabora

I'm getting this error, if it helps:

Uncaught TypeError: Cannot set property 'innerHTML' of nullscript.js?fin20:479 setInnerHTMLscript.js?fin20:1017 JumpTo.showSelectscript.js?fin20:1008 JumpToindex.php?topic=198.msg400:1140 (anonymous function)

I don't get this with default theme and I assume this is causing the trouble?

live627

Your theme is  messed.

Quote from: samborabora on February 05, 2015, 07:55:30 AM
Is there a way I can check the script is being called?
./Themes/defautl/scripts/postnotifier.js

Biology Forums

I like this though I'm concerned about the load. Will try to convert it to work on 1.x.

live627


samborabora

Quote from: live627 on February 06, 2015, 01:07:05 AM
Your theme is  messed.
Yup!

Quote from: live627 on February 06, 2015, 01:07:05 AM
Quote from: samborabora on February 05, 2015, 07:55:30 AM
Is there a way I can check the script is being called?
./Themes/defautl/scripts/postnotifier.js
So, how can I see it's being loaded or not? What would the default theme call upon that a messed theme would cause it to not load?

samborabora

Is there a way of moving the position where the ribbon appears? Since the ribbon is only fixed to the top via css, how can I put the actual <div> somewhere else on the Display page (like above the submit button of the quick reply)?

mnn2

After installing this mod, the visual verification image (anti-spam) no longer works. Please see following screen shot in attached file.

samborabora

Quote from: samborabora on June 01, 2015, 02:20:26 PM
Is there a way of moving the position where the ribbon appears? Since the ribbon is only fixed to the top via css, how can I put the actual <div> somewhere else on the Display page (like above the submit button of the quick reply)?

Again, how do I put it somewhere else in the page?

samborabora

Any ideas how to adjust it so the notification is just above the quick reply on the topic page?

samborabora

So, let's say below: <a id="lastPost"></a> and <div class="pagesection"> I want it to generate: <div id="newmsg" style="display: block;">
<a href="/forum/index.php?msg=223609913"><span>X</span> new replies</a>
</div>
how exactly would I get it to appear there? I can find the hook alright: echo '
<script type="text/javascript">
var iLastMsg = ' . $context['topic_last_message'] . ';
</script>
<div id="topbar">
</div>';
but where do I define WHERE this hooks into?

villasg

Hi .
In my smf 2.0.10 with SimplePortal 2.3.6 have error in edit index.php .

My index.php have:

// Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc.
if (empty($_REQUEST['action']) || !($_REQUEST['action'] == 'portal' && isset($_GET['xml'])) && !in_array($_REQUEST['action'], array('dlattach', 'findmember', 'jseditor', 'jsoption', 'requestmembers', 'smstats', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile')))



I ask if its safe to make edit in install.xml like :

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>live6627:post_notifier</id>

<file name="$boarddir/index.php">
<operation>
<search position="before"><![CDATA[if (empty($_REQUEST['action']) || !($_REQUEST['action'] == 'portal' && isset($_GET['xml'])) && !in_array($_REQUEST['action'], array(]]></search>
<add><![CDATA['postnotifier', ]]></add>
</operation>
</file>

</modification>


live627

Quote
I ask if its safe to make edit in install.xml like :
oh yes

live627

Quotebut where do I define WHERE this hooks into?
I'm confused here....

Couldn't you move that code into your display file?

samborabora

Quote from: live627 on July 17, 2015, 09:16:43 PM
Quotebut where do I define WHERE this hooks into?
I'm confused here....

Couldn't you move that code into your display file?
Sorry, I'm not sure how post notifier knows where to put the div layer on the page, I think the javascript places it at the top of the page under the head? How would I move this into my display.template?

live627

Ah, it does  that with a template layer inserted between html and body.

https://github.com/live627/smf-post-notifier/blob/master/PostNotifier.php#L18

samborabora

Quote from: live627 on July 18, 2015, 03:24:03 AM
Ah, it does  that with a template layer inserted between html and body.

https://github.com/live627/smf-post-notifier/blob/master/PostNotifier.php#L18

Ahh, I see that now, so is there a way of inserting it between two html sections? What defines the two insertion points?

live627

You can grab the html from that template at the bottom of the file and move it where you want.

samborabora

Quote from: live627 on July 18, 2015, 07:01:23 PM
You can grab the html from that template at the bottom of the file and move it where you want.

So, if I put this: function template_post_notifier_above()
{
global $context;
echo '
<script type="text/javascript">
var iLastMsg = ' . $context['topic_last_message'] . ';
</script>
<div id="topbar">
&nbsp;
</div>';
}
function template_post_notifier_below() {}


into display.template.php, it should work?

live627

Just the echo statement


echo '
<script type="text/javascript">
var iLastMsg = ' . $context['topic_last_message'] . ';
</script>
<div id="topbar">
&nbsp;
</div>';

samborabora

Quote from: live627 on July 18, 2015, 11:40:01 PM
Just the echo statement


echo '
<script type="text/javascript">
var iLastMsg = ' . $context['topic_last_message'] . ';
</script>
<div id="topbar">
&nbsp;
</div>';


OMG thank you sooo much, this is finally just how I need it!!

Advertisement: