Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: live627 on February 09, 2014, 08:25:22 PM

Title: Post Notifier
Post by: live627 on February 09, 2014, 08:25:22 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=3826)

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
Title: Re: Post Notifier
Post by: ApplianceJunk on February 09, 2014, 08:29:14 PM
Interesting mod, thanks
Title: Re: Post Notifier
Post by: Gryzor on February 11, 2014, 02:49:14 AM
Very nice, should be built-in functionality... thanks!
Title: Re: Post Notifier
Post by: GamePersia on February 11, 2014, 07:50:00 AM
Can you make this mod for only pm notify also ??
and this mod only notifies newly made topics ??
Title: Re: Post Notifier
Post by: eric1234 on February 26, 2014, 03:09:12 PM
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 :)

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.minus.com%2Fjb1sjENBEOgNbl.png&hash=25a9e33c11d1d05a494ac3aa8b0d7320928a1a6e)
Title: Re: Post Notifier
Post by: 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;
Title: Re: Post Notifier
Post by: eric1234 on February 27, 2014, 02:39:52 AM
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? 
Title: Re: Post Notifier
Post by: eric1234 on February 28, 2014, 01:21:52 AM
BUMP
Title: Re: Post Notifier
Post by: eric1234 on March 04, 2014, 10:53:03 AM
BUMP again.
Title: Re: Post Notifier
Post by: eric1234 on March 05, 2014, 01:24:30 PM
Bump again.
Title: Re: Post Notifier
Post by: Gryzor on March 05, 2014, 01:26:03 PM
Seriously man?
Title: Re: Post Notifier
Post by: Storman™ on March 05, 2014, 02:23:03 PM
If no one replies then it's usually because no one knows the answer.
Title: Re: Post Notifier
Post by: 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.
Title: Re: Post Notifier
Post by: eric1234 on March 07, 2014, 05:00:04 PM
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);
Title: Re: Post Notifier
Post by: margarett on March 07, 2014, 06:15:17 PM
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!
Title: Re: Post Notifier
Post by: eric1234 on March 08, 2014, 05:36:51 PM
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. :)
Title: Re: Post Notifier
Post by: kimyaci on March 23, 2014, 03:12:13 PM
I'm using SMF 2:07. But the mode does not work.Is there a setting? Thanks.
Title: Re: Post Notifier
Post by: margarett on March 23, 2014, 08:48:29 PM
It does work, I'm using it (and for sure, other people too) ;)
Title: Re: Post Notifier
Post by: kimyaci on March 24, 2014, 04:26:47 AM
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.
Title: Re: Post Notifier
Post by: mikk on May 24, 2014, 08:59:17 PM
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 (https://groups.google.com/forum/#!searchin/ajax-chat/XML$20declaration%7Csort: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...
Title: Re: Post Notifier
Post by: bros on May 27, 2014, 10:43:34 PM
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.
Title: Re: Post Notifier
Post by: samborabora on February 05, 2015, 05:17:56 AM
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?
Title: Re: Post Notifier
Post by: samborabora on February 05, 2015, 07:55:30 AM
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?
Title: Re: Post Notifier
Post by: samborabora on February 05, 2015, 01:57:36 PM
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?
Title: Re: Post Notifier
Post by: live627 on February 06, 2015, 01:07:05 AM
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
Title: Re: Post Notifier
Post by: Biology Forums on February 06, 2015, 02:01:30 AM
I like this though I'm concerned about the load. Will try to convert it to work on 1.x.
Title: Re: Post Notifier
Post by: live627 on February 06, 2015, 07:09:26 AM
Shouldn't be hard.
Title: Re: Post Notifier
Post by: samborabora on February 06, 2015, 07:01:42 PM
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?
Title: Re: Post Notifier
Post by: 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)?
Title: Re: Post Notifier
Post by: mnn2 on June 01, 2015, 06:50:23 PM
After installing this mod, the visual verification image (anti-spam) no longer works. Please see following screen shot in attached file.
Title: Re: Post Notifier
Post by: samborabora on June 14, 2015, 04:50:31 PM
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?
Title: Re: Post Notifier
Post by: samborabora on July 01, 2015, 06:16:44 AM
Any ideas how to adjust it so the notification is just above the quick reply on the topic page?
Title: Re: Post Notifier
Post by: samborabora on July 17, 2015, 12:57:16 AM
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?
Title: Re: Post Notifier
Post by: villasg on July 17, 2015, 02:28:55 PM
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>

Title: Re: Post Notifier
Post by: live627 on July 17, 2015, 09:09:32 PM
Quote
I ask if its safe to make edit in install.xml like :
oh yes
Title: Re: Post Notifier
Post by: 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?
Title: Re: Post Notifier
Post by: samborabora on July 18, 2015, 01:20:49 AM
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?
Title: Re: Post Notifier
Post by: 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
Title: Re: Post Notifier
Post by: samborabora on July 18, 2015, 04:34:33 AM
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?
Title: Re: Post Notifier
Post by: 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.
Title: Re: Post Notifier
Post by: samborabora on July 18, 2015, 08:06:20 PM
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?
Title: Re: Post Notifier
Post by: 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>';
Title: Re: Post Notifier
Post by: samborabora on July 19, 2015, 05:52:31 AM
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!!