PHP Forums Archive

New plugin: Moderator Notification

Tags: bbpress, plugin, email, notification, bb_mail, ds

Olaf posted on 2007-12-31 12:19:11 #

My first plugin for bbpress:

Moderator New Post Notification

Description:
Sends a notification e-mail to all moderators and admins if there is a new post from a regular member.

Enjoy and let me know what do you think.

Comments / discussions

Olaf posted on 2008-01-04 08:22:37 #

The plugin is listed now on the bbpress website:

http://bbpress.org/plugins/topic/75?replies=1

don't forget to vote

paulf posted on 2008-07-23 20:29:36 #

I got this installed and I don't get any emails. New users are receiving their emails, but I don't get notifications when anyone posts.

What could be wrong?

Olaf posted on 2008-07-24 08:31:28 #

Hi,

what is your role on your forum? do you tried a second (admin) account?

Erdna posted on 2008-08-11 18:29:10 #

Hi, I have a stand alone installation of bbpress and when I use the plugin I get this error:

bbPress database error: [Table 'db164673748.bb_users' doesn't exist]
SELECT um.meta_value AS role FROM bb_users AS u, bb_usermeta AS um WHERE u.ID = um.user_id AND um.meta_key = 'bbpress_capabilities' AND u.user_status = 0 AND u.ID = 1

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: Invalid argument supplied for foreach() in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 73

Warning: Cannot modify header information - headers already sent by (output started at /homepages/34/d21941373/htdocs/forum/bb-includes/db-mysql.php:130) in /homepages/34/d21941373/htdocs/forum/bb-includes/pluggable.php on line 228

I have read the suggestions, but I still habe no solution for this. Can you help me?

Olaf posted on 2008-08-11 18:35:29 #

I guess you trapped into the table name bug :)

I guess your user table is not bb_user?

Erdna posted on 2008-08-11 19:29:16 #

Well, you are right. My tables name was different.. I changed it, but now I have a different error:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 40

Warning: Invalid argument supplied for foreach() in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 73

Warning: Cannot modify header information - headers already sent by (output started at /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php:40) in /homepages/34/d21941373/htdocs/forum/bb-includes/pluggable.php on line 228

Olaf posted on 2008-08-11 19:46:43 #

first be sure that you have this query in your plugin.

(echo the sql statement, access the plugin file directly and test the output with phpmyadmin) I hope that I don't ask too much ;)

Erdna posted on 2008-08-12 07:08:48 #

I am Sorry, I don't know how to test the plugin with phpmyadmin. I located the term "array_key_exists()" in \bb_includes\template-functions.php, upgrade-functions.php, profile-edit.php and gettext.php.

Olaf posted on 2008-08-12 07:31:33 #

Look, I think you get this error because of an empty array, if you test the SQL statement you know the problem.

btw. I forgot to post the modified function:

function is_moderator($user_id) {
	global $bbdb;
	$mods = array('moderator', 'administrator', 'keymaster');
	$is_mod = false;
	$row = $bbdb->get_row("SELECT um.meta_value AS role
		FROM $bbdb->users AS u, $bbdb->usermeta AS um
		WHERE u.ID = um.user_id
		AND um.meta_key = 'bb_capabilities'
		AND u.user_status = 0
		AND u.ID = $user_id
	");
	$arr = unserialize($row->role);
	if (count($mods) > 0) {
		foreach($mods as $val) {
			if (array_key_exists($val, $arr)) {
				$is_mod = true;
				break;
			}
		}
	}
	return $is_mod;
}

Erdna posted on 2008-08-12 10:39:44 #

Sorry, still the same:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum2/my-plugins/moderator_notification.php on line 41

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum2/my-plugins/moderator_notification.php on line 41

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum2/my-plugins/moderator_notification.php on line 41

Warning: Invalid argument supplied for foreach() in /homepages/34/d21941373/htdocs/forum2/my-plugins/moderator_notification.php on line 76

Warning: Cannot modify header information - headers already sent by (output started at /homepages/34/d21941373/htdocs/forum2/my-plugins/moderator_notification.php:41) in /homepages/34/d21941373/htdocs/forum2/bb-includes/pluggable.php on line 228

could it be the different bbpress version? I use bbpress-0.9.0.2. Did you try it with this version?

Olaf posted on 2008-08-12 11:00:53 #

I use the same version here, btw. if you replace the code I posted one message before the errors should go, check this first.

Erdna posted on 2008-08-12 13:33:36 #

I tried that already and the posting before was the result. Can you post the complete fixed script somewhere ;-)
Many Thanks

Olaf posted on 2008-08-12 14:40:16 #

I will post a new release the next days

Erdna posted on 2008-08-18 14:07:07 #

Have you any Idea, when you are ready?

Olaf posted on 2008-08-18 14:08:45 #

thanks for the reminder ;)

paulf posted on 2008-08-18 22:53:08 #

Quote from: Olaf
"Hi,
what is your role on your forum? do you tried a second (admin) account?"

I am the keymaster. I just setup another user as a moderator and now it appears that the checkbox is missing from the profile page, so I'm not sure how to activate this anymore.

paulf posted on 2008-08-18 22:55:57 #

I'd also like to point out that I have this topic as a favorite and I have the 'notify me when a post occurs to my favorites' checked in my profile, but I haven't received any emails with notifications of posts since my first post.

Olaf posted on 2008-08-19 06:03:31 #

I will check this too

paulf posted on 2008-08-26 20:05:16 #

I finally got an email from the forum when I created a new topic under my own username.
However, it came from (unknown sender), which makes me think that may be why my server is blocking the emails most of the time.

Could that be the issue? If so, how do I set it up to send from one of my email addresses or the address that the forum uses for emails?

Olaf posted on 2008-08-26 20:12:15 #

I think it's because the mail function for bbpress is very simple. I'm busy to create a plugin to send mails with phpmailer

Erdna posted on 2008-08-29 20:54:48 #

Hi Olaf, this script is still not working well;-(

Olaf posted on 2008-08-29 21:10:19 #

it works here fine since many weeks...

Erdna posted on 2008-08-31 12:30:30 #

Please post the working code or a link here again, because I have still problems to get any mail from my bbpress.

all4yourwebsite posted on 2008-08-31 13:20:17 #

don't forget that receiving auto generated email messages are a common problem these days

Olaf posted on 2008-08-31 13:35:55 #

I uploaded the fixed version (replaced the static database table names)

you can download the version 1.02 from here:
http://www.finalwebsites.com/bbpress/moderator-notification.php

Note this version will use the bbpress mail function instead of the native PHP mail function. If you still have problems with receiving emails, you should have the same problem with registrations and other mails send by bbpress.

Olaf posted on 2008-08-31 13:37:05 #

Quote from: Erdna
"Please post the working code or a link here again, because I have still problems to get any mail from my bbpress."

btw. do you activated the option from your profile?

from the readme file:

Every Key Master, Administrator and Moderator has check the option Moderator Post Notification via the Edit profile option to get e-mails from every regular member post.

Erdna posted on 2008-08-31 19:16:55 #

Sorry, but I get still an error when I want to check the admin box to receive mails.

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 49

Olaf posted on 2008-08-31 19:22:04 #

just created an administrator account and checked also the notification option, result:

it works, maybe you should check the data via phpmyadmin, it looks to me that the roles doesn't exists.

btw. do you use bbpress together with wordpress?

Erdna posted on 2008-09-01 11:47:23 #

I use bbpress as standalone forum.
I tried the script at two different webhoster (strato and 1und1) at my strato-vserver it works fine (and it really sends mails!!) and on 1und1 I even cannot see the checkbox to make my hock. On this page I see this error..

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 49

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 49

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/34/d21941373/htdocs/forum/my-plugins/moderator_notification.php on line 49

Olaf posted on 2008-09-01 11:51:40 #

If it works with strato and not with 1 and 1, it's bad for 1 and 1 customers but I don't understand why for the plugin?

next you can try the strato database on you 1 and 1 hosting account.

Erdna posted on 2008-09-02 07:26:27 #

Does the php version matter? At the 1und1 server (plugin not working) is php 4.4.9, and on the strato server runs 5.1.2.

Olaf posted on 2008-09-02 13:25:10 #

No, I don't think it's the PHP version but maybe some other php setting like magic quotes

Erdna posted on 2008-09-03 06:27:03 #

Magic_quotes_ are the same settings at 1und1 and Strato :-(

rfc137 posted on 2009-03-27 15:43:18 #

The plugin has the name "bb_capabilities" hardcoded but if the installation has a prefix defined then it will fail because prefix is added to the capabilities also thus becoming "somePrefix_bb_capabilities".

Olaf posted on 2009-03-27 15:45:19 #

Quote from: rfc137
"The plugin has the name "bb_capabilities" hardcoded but if the installation has a prefix defined then it will fail because prefix is added to the capabilities also thus becoming "somePrefix_bb_capabilities"."

yes right that was posted here before, we will fix this with an update later

satmaster posted on 2009-11-22 23:08:02 #

I can not activate it in bbPress 1.0.2 I get
Plugin could not be activated, it produced a Fatal Error. The error is shown below.

Fatal error: Cannot redeclare is_moderator() (previously declared in /xxx/bbpress/my-plugins/bb-seo-tools.php:166) in /xxx/bbpress/my-plugins/moderator_notification.php on line 56

Olaf posted on 2009-11-23 05:28:09 #

Hi Satmaster,

thats possible, you need to use a function_exists statement (check the PHP manual how-to do this)

I will update the code to fix this in future versions
Thanks

paulf posted on 2009-11-23 05:32:11 #

Quote from: paulf
"I'd also like to point out that I have this topic as a favorite and I have the 'notify me when a post occurs to my favorites' checked in my profile, but I haven't received any emails with notifications of posts since my first post."

Wow I just started getting notifications of this thread. Too bad I'm using a completely different system now.

Olaf posted on 2009-11-23 05:34:14 #

you mean you removed bbpress?

TrishaM posted on 2009-11-24 01:27:25 #

Hi Olaf

I'm having the same problem - when I activate the plugin (version 1.0.1) I get the error message:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /homepages/25/d263871326/htdocs/FSPW_NewWP/Forum/my-plugins/moderator-new-post-notification/moderator_notification.php on line 40

Repeated three times - this occurs where I assume the checkbox to receive notifications should be.

If I try to edit the user and click on Update Profile, I get a blank page with that error repeated again three times followed by the headers already sent error message, telling me that the headers were already sent by /bb-includes/functions.bb-pluggable.php

I'm using bbPress version 1.0.2 and I have it integrated with WordPress, so my users table is NOT bb_users, it's wp_users.

Can you help with this?

Olaf posted on 2009-11-24 05:57:12 #

Hello TrishaM,

I never tried, the plugin together with Wordpress, since all users are shared with WP it might be a problem. Since I can't track down this problem (no wordpress + bbpress setup), I can't fix it for you.

TrishaM posted on 2009-11-24 17:27:29 #

I think the problem is here in your code - it has hard coded to pull users from bb_users, but that is not the table name for my users - instead it is wp_users. So can I just change this code below to replace bb_users and bb_usermeta with wp_users and wp_usermeta? I don't know how to tell it to use the right tables in the bb-config.php file and can't find any info on how to do that.

function is_moderator($user_id) {
global $bbdb;
$mods = array('moderator', 'administrator', 'keymaster');
$is_mod = false;
$row = $bbdb->get_row("SELECT um.meta_value AS role
FROM bb_users AS u, bb_usermeta AS um
WHERE u.ID = um.user_id
AND um.meta_key = 'bb_capabilities'
AND u.user_status = 0
AND u.ID = $user_id
");

TrishaM posted on 2009-11-24 17:32:39 #

Well that seems to work. So the problem is caused by the fact that the plugin is looking for a user table called bb_users and bb_usermeta, which don't exist, since I have bbPress integrated with Wordpress to share the user table.

I suggest then that you modify the plugin to have an admin setting for folks who are using it in a WP integrated setup and sharing a user table to tell the plugin that fact.

Cheers!

Olaf posted on 2009-11-24 18:02:20 #

Hey Trish, the information is here available now, so people can change it (if needed).
I don't modify the plugins for wordpress until the bbpress/wordpress connection works for 100%.

There are so many complains that WP/bpress stuff is not working. I'm happy with bbpress (standalone)...

Olaf posted on 2009-11-24 18:04:45 #

btw. the current version has already dynamic table names, you should use the version from this website ;)