Index: trunk/wp-content/plugins/xpressme/include/notify_functions.php
===================================================================
--- trunk/wp-content/plugins/xpressme/include/notify_functions.php	(revision 91)
+++ trunk/wp-content/plugins/xpressme/include/notify_functions.php	(revision 95)
@@ -1,8 +1,7 @@
 <?php
-	
+
 function onaction_publish_post_notify($new_status, $old_status, $post)
 {
 	if ($new_status == 'publish'){
-		include_once dirname(__FILE__) . '/notification.inc.sub.php';
 		do_PostNotifications($post->ID,'newpost');
 	}
@@ -11,5 +10,4 @@
 function onaction_edit_post_notify($post_id)
 {
-	include_once ABSPATH . '/include/notification.inc.sub.php';
 	do_PostNotifications($post_id,'editpost');
 }
@@ -21,10 +19,7 @@
 
 	if ($status ==1){
-		include_once ABSPATH . '/include/notification.inc.sub.php';
 		do_CommentNotifications($commentID, $post_id);
 	} else {
-		require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
-		$notification_handler =& xoops_gethandler( 'notification' ) ;
-		$notification_handler->triggerEvent( 'global' , 0 , 'waiting') ;
+		do_CommentWaiting($commentID, $post_id);
 	}
 }
@@ -35,5 +30,4 @@
 	$status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $commentID");
 	if(is_null($status)) return;
-	//	$status = wp_get_comment_status($commentID);
 	if ($status == 1){
 			onaction_comment_notify($commentID);
@@ -41,3 +35,146 @@
 }
 
+function Notification_triggerEvent($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $omit_user_id=null)
+{
+	global $xoops_db,$xoops_config;
+	//When notifying by a private message, 
+	//it is evaded that the data base becomes read-only as a result of the check on the referrer and the method. 
+	if (is_wp_cron_page_call() ){
+		$_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
+		$_SERVER['REQUEST_METHOD'] = 'POST';
+	}
+	if (is_xmlrpc_call() ){
+		$_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
+		$_SERVER['REQUEST_METHOD'] = 'POST';
+	}
+	
+	include_once $xoops_config->xoops_mainfile_path;	// load XOOPS System
+	include_once $xoops_config->xoops_root_path . '/include/notification_functions.php' ;
+	$module_id = get_xpress_modid() ;
+	$notification_handler =& xoops_gethandler( 'notification' ) ;
+	$notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
+}
+
+function do_CommentWaiting($commentID, $comment_post_ID)
+{
+//	global $xoops_config;
+//	require_once $xoops_config->xoops_mainfile_path;
+//	xoops_mainfile_path;
+//	require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
+//	$notification_handler =& xoops_gethandler( 'notification' ) ;
+	Notification_triggerEvent( 'global' , 0 , 'waiting') ;
+}
+
+
+function do_CommentNotifications($commentID, $comment_post_ID)
+{
+	global $xoops_config , $xoops_db;
+
+	$xpress_prefix = get_wp_prefix() ;
+
+	$table_term_relationships = $xpress_prefix .'term_relationships';
+	$table_term_taxonomy = $xpress_prefix .'term_taxonomy';
+	$table_terms = $xpress_prefix .'terms';
+	$table_categories = $xpress_prefix .'categories';
+	$wp_post = $xpress_prefix .'posts';
+	$wp_options = $xpress_prefix .'options';
+	$wp_users  = $xpress_prefix .'users';
+	$wp_comments  = $xpress_prefix .'comments';
+	$post_id = $comment_post_ID;
+
+	$post_title = get_the_title($post_id);
+	$post_url = get_permalink($post_id). '#comment';
+	$blog_name = get_bloginfo('name');
+
+	// query
+	$sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$comment_post_ID ";
+	$post_author = $xoops_db->get_var($sql);
+
+	$sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
+	$user_name = $xoops_db->get_var($sql);
+
+	$comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
+	Notification_triggerEvent('global' , 0 , 'comment' , $comment_tags , false);
+	Notification_triggerEvent('author' , $post_author , 'comment' , $comment_tags , false);
+	Notification_triggerEvent('post' , $comment_post_ID , 'comment' , $comment_tags , false);
+
+	// categorie notification
+	if (get_xpress_db_version() < 6124){
+		$sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$comment_post_ID;
+	} else {
+		$sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
+		$sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
+		$sql2 .= "WHERE ($table_term_relationships.object_id =" . $comment_post_ID.") AND ($table_term_taxonomy.taxonomy='category')";		
+	}
+	$categories = $xoops_db->get_results($sql);
+	foreach($categories as $categorie){
+		$cat_id = $categorie->cat_ID;
+		$cat_name = $categorie->cat_name;
+		$comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_CAT_TITLE' => $cat_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
+		Notification_triggerEvent('category' , $cat_id , 'comment' , $comment_tags , false);
+
+	}
+}
+
+function do_PostNotifications($post_id,$not_event)
+{
+	global $xoops_config, $xoops_db;
+	xpress_debug();
+	
+
+
+	 // $not_event:		newpost,editpost ; $commentID, $comment_post_ID)
+	 
+	$xpress_prefix = get_wp_prefix() ;
+
+	$table_term_relationships = $xpress_prefix .'term_relationships';
+	$table_term_taxonomy = $xpress_prefix .'term_taxonomy';
+	$table_terms = $xpress_prefix .'terms';
+	$table_categories = $xpress_prefix .'categories';
+	$wp_post = $xpress_prefix .'posts';
+	$wp_options = $xpress_prefix .'options';
+	$wp_users  = $xpress_prefix .'users';
+	$wp_comments  = $xpress_prefix .'comments';
+
+	$post_title = get_the_title($post_id);
+	$post_url = get_permalink($post_id). '#comment';
+	$blog_name = get_bloginfo('name');
+
+	// query
+	$sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$post_id ";
+	$post_author = $xoops_db->get_var($sql);
+
+	$sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
+	$user_name = $xoops_db->get_var($sql);
+
+	$posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
+
+	switch ($not_event) {
+		case 'newpost' :
+			Notification_triggerEvent('global' , 0 , 'newpost' , $posts_tags , false);
+			Notification_triggerEvent('author' , $post_author , 'newpost' , $posts_tags , false);
+
+			// categorie notification
+			if (get_xpress_db_version() < 6124){
+				$sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$post_id;
+			} else {
+				$sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
+				$sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
+				$sql2 .= "WHERE ($table_term_relationships.object_id =" . $post_id.") AND ($table_term_taxonomy.taxonomy='category')";		
+			}
+			$categories = $xoops_db->get_results($sql);
+			foreach($categories as $categorie){
+				$cat_id = $categorie->cat_ID;
+				$cat_name = $categorie->cat_name;
+				$posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_CAT_TITLE' => $cat_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
+				Notification_triggerEvent('category' , $cat_id , 'newpost' , $posts_tags , false);
+			}
+			break;
+		case 'editpost' :
+			Notification_triggerEvent('post' , $post_id , 'editpost' , $posts_tags , false);
+			break;
+		default :
+	}
+}		
+
 ?>
