SimplePortal

Customization => Custom Coding => Topic started by: 130860 on November 09, 2010, 02:39:49 PM

Title: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 09, 2010, 02:39:49 PM
well this tips is on nneonneo' shoutbox and AjaxChat  so I adapted to SimplePortal shoutbox :)

with this tip you can post notifications on your shout when a new topic is created, also, you can configure it so the notification appears only when a new topic is created on certain board you choose.

I only test it on a RC3 and RC4 board.

lets get started.

first open your  Sources/Post.php  and find:

Code: [Select]
notifyMembersBoard($notifyData);
and add after it:

Code: [Select]
global $user_info, $board, $scripturl, $boardName, $topic;

$smcFunc['db_insert']('',
'{db_prefix}sp_shouts',
array(
'id_shoutbox' => 'int',
'id_member' => 'int',
'member_name' => 'string',
'log_time' => 'int',
'body' => 'string',
),
array(
1,
$user_info['id'],
$user_info['name'],
time(),
'[color=red][b]New Topic: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
),
array('id_shout')
);


you can configure a little bit at this part:


1,    is the shoutbox ID, by default the first shoutbox you create has the ID 1, change it to yours.

Code: [Select]
'[color=red][b]New Topic: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
is the message to be posted, it will look like this:

Username: New Topic: topic name and url

the [color ] [/color] and [b ] [/b ]  tag will only work if you enable this tag in your shout's settings.

if you only want to show notifications from certain board only, use this:

$foros = array (1,2);  // where 1 and 2 are the ID of the boards you want to post notifications from

if (in_array($board, $foros))  // check if its the right board

it will look something like this:

Code: [Select]
$foros = array (1,2);


   if (in_array($board, $foros))
   {
global $user_info, $board, $scripturl, $boardName, $topic;

$smcFunc['db_insert']('',
'{db_prefix}sp_shouts',
array(
'id_shoutbox' => 'int',
'id_member' => 'int',
'member_name' => 'string',
'log_time' => 'int',
'body' => 'string',
),
array(
1,
$user_info['id'],
$user_info['name'],
time(),
'[color=red][b]New Topic: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
),
array('id_shout')
);
}


hope you find it useful, this is not my code, this is just an adaptation from nneonneo' shoutbox and AjaxChat  tips.




Title: Re: [Tip] Post Notifications on shoutbox
Post by: Normally on November 14, 2010, 02:39:09 AM
Great,

Is it possible to open the link in the same window?

Stef.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: grafitus on November 14, 2010, 03:34:45 AM
Is it possible to open the link in the same window?
Code: (Find (I think that there are two)) [Select]
[url
Code: (Replace) [Select]
[iurl
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Normally on November 14, 2010, 03:47:58 AM
When i kake it like that it shows like this:

 Nieuw Topic: [i url=http://www.spirituelekaarten.nl/index.php?topic=592.new#new]Testen of het in de schreeuw komt.[/i][/color]

Here i maked i url, because here it works, but in the shoutbox i can not not click the link.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: grafitus on November 14, 2010, 04:28:44 AM
Shouldn't be space between "i" and "url".
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Normally on November 14, 2010, 04:35:13 AM
I know, but otherwise i cannot show how it looks in the shoutbox.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: grafitus on November 14, 2010, 04:50:15 AM
Oh, right! "iurl" not in allowed bbc tags. Let's add it:

./Sources/Subs-Portal.php
Code: (Find) [Select]
$row['allowed_bbc']
Code: (Replace) [Select]
$row['allowed_bbc'] . ',iurl'
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Normally on November 14, 2010, 05:00:14 AM
This works, thanks.

Stef.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 21, 2011, 12:37:33 PM
Thank you, nice Tip!

How can i exclude some boards? this "aray"-thing is not working for me...
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 21, 2011, 02:58:45 PM
can you post your full code and tell me the ID of the array you want to exclude.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 21, 2011, 03:13:21 PM
well, the code i was using (in SMF2 RC2!) is:
Code: [Select]
$foros = array (4,5,40,68,60,61,19,14,15,53,50,56,51,62,63,64,65,13,16,43,69,70,71,72,73,58,59,17,66,67);
     
     
      if (in_array($board, $foros))
      {
global $user_info, $board, $scripturl, $boardName, $topic;
     
         $smcFunc['db_insert']('',
      '{db_prefix}sp_shouts',
      array(
         'id_shoutbox' => 'int',
         'id_member' => 'int',
         'member_name' => 'string',
         'log_time' => 'int',
         'body' => 'string',
      ),
      array(
         1,
         $user_info['id'],
         $user_info['name'],
         time(),
         '[color=red][b]Neues Thema: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
      ),
      array('id_shout')
   );
}

I have two boards, that i dont want to show in the shoutbox: board-ID number 42.0 and 54.0
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 21, 2011, 05:32:59 PM
you don't need to listed all your boards,  try this code:

Code: [Select]
$foros = array (42,54);
     
     
      if (in_array($board, $foros))
  return;
 
  else
      {
global $user_info, $board, $scripturl, $boardName, $topic;
     
         $smcFunc['db_insert']('',
      '{db_prefix}sp_shouts',
      array(
         'id_shoutbox' => 'int',
         'id_member' => 'int',
         'member_name' => 'string',
         'log_time' => 'int',
         'body' => 'string',
      ),
      array(
         1,
         $user_info['id'],
         $user_info['name'],
         time(),
         '[color=red][b]Neues Thema: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
      ),
      array('id_shout')
   );
}

Title: Re: [Tip] Post Notifications on shoutbox
Post by: Old Fossil on January 21, 2011, 06:30:44 PM
Hey prisoner 130860

Have been watching this like a hawk.

Is there a way to post links so only certain membergroups can view it.

I have admin only boards and specific boards for certain groups ie subscribers and teenagers.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 22, 2011, 05:28:04 AM
looks like it is (almost) function now.

When i write a new topic in the excluded boards, i have an error after submit: i dont see the new topic, only the head (menu) from the forum. in the error-log there is "could not load the main template"....
please, can you help?

Is there a way to show answers, too - not only the new topic?

Good work and a great tip.

Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 22, 2011, 08:30:28 PM
@Brack1  well, that will be  complicated, it is far better to create another shoutbox and give permisisons to this new shoutbox so only certain membergroups cann see it and shout on it.

 @Divecall  what is the exact error you gave?

attach your  Sources/Post.php  file.

and no, currently this tip is using a function in smf that is used only for new topics.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 24, 2011, 02:43:13 PM
thanks 130860 for your help.

Here is the post.php
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 26, 2011, 12:21:20 PM
Divecall  your file seems fine,  if you remove this tip the error goes away?

can you post the errors on your error log?
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 26, 2011, 02:57:36 PM
Well, my error-log is in german...

but you can see only, that is a Theme-error
and you can read:
http://localhost/myboard/index.php?action=post2;start=0;board=54
Cannot load the 'main' template

No File or number or something....

(like ever: File: [Path]/post.php), line: xxx - THERE IS NOTHING!)

Maybe the error is my XAMPP-Test-Area ???
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 26, 2011, 03:37:46 PM
well, I need to know if the error is related with this tip,  the error still occurs  even if you take away the edits this tip make?

can you post the line you getting the error?  even if it is blank, it gave me an idea on where to look at.
 
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 27, 2011, 10:13:47 AM
Yes, the error is away, when i remove you tip.

Here is the screenshot:
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 28, 2011, 04:36:23 PM
ok, can you tell me the ID of the shout you're modifying?  this tip supose to modify the shout with ID 1, but you need to change that to your actual shout ID
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 28, 2011, 04:49:31 PM
I have only one shoutbox...this is with ID 1
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on January 28, 2011, 07:18:35 PM
ok, try with this one:

Code: [Select]
$foros = array (42,54);
     
     
      if (in_array($board, $foros))
echo '';
 
  else
      {
global $user_info, $board, $scripturl, $boardName, $topic;
     
         $smcFunc['db_insert']('',
      '{db_prefix}sp_shouts',
      array(
         'id_shoutbox' => 'int',
         'id_member' => 'int',
         'member_name' => 'string',
         'log_time' => 'int',
         'body' => 'string',
      ),
      array(
         1,
         $user_info['id'],
         $user_info['name'],
         time(),
         '[color=red][b]Neues Thema: [url=http://'.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
      ),
      array('id_shout')
   );
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Divecall on January 28, 2011, 07:48:29 PM
Wow! Thats amazing!

It is working. THANK YOU SO MUCH!
Title: Re: [Tip] Post Notifications on shoutbox
Post by: robbie93 on February 20, 2011, 02:14:10 PM
Thank you sooooo much for this tip - I am using this code

Code: [Select]
global $user_info, $board, $scripturl, $boardName, $topic;
     
         $smcFunc['db_insert']('',
      '{db_prefix}sp_shouts',
      array(
         'id_shoutbox' => 'int',
         'id_member' => 'int',
         'member_name' => 'string',
         'log_time' => 'int',
         'body' => 'string',
      ),
      array(
         1,
         $user_info['id'],
         $user_info['name'],
         time(),
         '[color=red][b]New Topic: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/b][/color]',
      ),
      array('id_shout')
   );


It is working fine but when I upload a new game and the topic is created it doesnt show up in the sbox

the board for the arcade games is here http://robbie93andhotchildxox.net/index.php/board,4.0.html

how can I get each new topic to show up in the sbox when one is created? thanks.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on February 20, 2011, 10:56:19 PM
does your shoutbox has the ID 1?
Title: Re: [Tip] Post Notifications on shoutbox
Post by: robbie93 on February 21, 2011, 03:26:38 PM
No my sbox has the ID 5 I changed the array to 5 on the code, most topics work but new topics created when a game is installed do not.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on February 22, 2011, 10:12:37 AM
this code will only work for new topics created by members,  if you have a mod that automatically creates a new topic, then this code won't show that topic.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: robbie93 on February 22, 2011, 01:15:49 PM
Ahh, ok no probs - thanks for a great tip anyway.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: phantomm on July 04, 2012, 04:54:45 PM
few questions:

Title: Re: [Tip] Post Notifications on shoutbox
Post by: velorooms on October 19, 2012, 01:59:56 PM
dito the above. i want it to put the topic name rather than just "new topic"
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on October 31, 2012, 02:21:38 PM
Is there a way to show answers, too - not only the new topic?
I would love that  :D
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 06, 2012, 03:43:09 PM
No help ???    :| :| :|
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 27, 2012, 07:51:49 AM
 :'( :'( :'(
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 29, 2012, 04:12:42 PM
Doing it for messages will put a heavy load on your server, it is not recommended.

You can add the same piece of code right after this comment on the same file:

Code: [Select]
// Only send it to everyone if the topic is approved, otherwise just to the topic starter if they want it.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 29, 2012, 04:16:11 PM
Sorry i am dutch where to put that code ?
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 29, 2012, 04:21:47 PM
Open the Sources/Post.php  and find that exact line, put the code on the first message of this topic right after that comment line.

Or just attach the file here.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 29, 2012, 04:25:05 PM
Thnx for the help here is mi attachment
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 29, 2012, 04:27:36 PM
use this one, make a back up of your site before tryig to use this file as its totally untested.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 29, 2012, 04:32:26 PM
Didn`t work sorry ?
Not showing new post in te shoutbox
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 29, 2012, 04:34:39 PM
any error on the error log? this code was made for an old version of SO, perhaps its different on new version, I haven't checked the new version.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 29, 2012, 04:36:52 PM
No errors but just dont show up  ;)
Title: Re: [Tip] Post Notifications on shoutbox
Post by: 130860 on November 29, 2012, 04:40:27 PM
Ok, lets put the query right after the call to createPost() then, not the best place but it should work.
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on November 29, 2012, 04:47:41 PM
No result grrrrrrrrrrrrrrrrrr
Title: Re: [Tip] Post Notifications on shoutbox
Post by: phantomm on November 30, 2012, 10:12:55 AM
I tried to make it work with latest SP and code works partially - shouts are added in database, but shoutbox does not display them :|
Title: Re: [Tip] Post Notifications on shoutbox
Post by: Chen Zhen on November 30, 2012, 03:18:12 PM
  I have only very briefly looked at the edits to Post.php from this thread & can see some possible issues.


SP already has a function to add the shouts to the db and can be called instead of implementing the db edits I see in that file. Imo this is not the issue though.. it is possibly the shoutbox id# (if the user has set up more than 1 shoutbox) & the need for client side js.

Here is a brief example:
Code: [Select]
global $context;

$shout = 'This is a test shout';
$shout_id = 1;
$context['SPortal']['shoutbox'] = sportal_get_shoutbox($shout_id, true);

sportal_create_shout($context['SPortal']['shoutbox'], $shout);
echo '
<script language="Javascript" type="text/javascript"><!-- // --><![CDATA[
sp_submit_shout(', $shout_id, ', \'', $context['session_var'], '\', \'', $context['session_id'], '\');
// ]]></script>';

130860,
  The above uses shoutbox id#1 .. hard code that id#, another id# or create a drop-down option in SP admin menu to opt a specific shoutbox id#.  The sportal_create_shout & sportal_get_shoutbox functions should work without having to include any SP php file as it is already previously loaded/used by SP.

  One can just try adding the js after the db edits & it will probably work if that is the route opted.

Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on February 05, 2013, 06:02:22 PM
Didn`t work sorry ?
Not showing new post in te shoutbox

Any update ???
I love to see any post to show up in the shoutbox please
Title: Re: [Tip] Post Notifications on shoutbox
Post by: weerforum on March 03, 2013, 03:02:10 PM
Please ???
SimplePortal 2.3.8 © 2008-2024, SimplePortal