1
nem2k2
[request] XOOPS notification hack for IPBoard
  • 2004/6/13 23:49

  • nem2k2

  • Just popping in

  • Posts: 14

  • Since: 2003/9/18


Hi,

I'm using XOOPS with the IPBoard module.. one small problem I am having is when users subscribe to notifications (eg. comments added to files in mydownloads module) the PMs are going to the XOOPS PM system instead of the IPBoard PM system. I've tracked down the place where the hacks would be required (xoops/kernel/privmessage.php needs to use code from xoops/modules/ipboard/sources/Messenger.php) but I'm not sure exactly what needs to be done.

I would really like the PMs to be going to the IPBoard PM system... any help is appreciated :)

2
nem2k2
Re: [request] XOOPS notification hack for IPBoard
  • 2004/6/14 4:10

  • nem2k2

  • Just popping in

  • Posts: 14

  • Since: 2003/9/18


Well I got bored and decided to have a go at it myself.. it works pretty well!

I just use this code in my xoops/kernel/privmessage.php in place of the existing insert function:

function insert(&$pm)
    {
        if (
get_class($pm) != 'xoopsprivmessage') {
            return 
false;
        }
        if (!
$pm->isDirty()) {
            return 
true;
        }
        if (!
$pm->cleanVars()) {
            return 
false;
        }
        foreach (
$pm->cleanVars as $k => $v) {
            ${
$k} = $v;
        }
        if (
$pm->isNew()) {
            
            
// ====================================
            // IPBOARD HACK
            // ====================================
            
include(XOOPS_ROOT_PATH."/modules/ipboard/conf_global.php");
            require(
XOOPS_ROOT_PATH."/modules/ipboard/sources/Drivers/mySQL.php");
            require 
XOOPS_ROOT_PATH."/modules/ipboard/sources/functions.php";
            
$std   = new FUNC;
            
$DB = new db_driver;
            
$DB->obj['sql_database']     = $INFO['sql_database'];
            
$DB->obj['sql_user']         = $INFO['sql_user'];
            
$DB->obj['sql_pass']         = $INFO['sql_pass'];
            
$DB->obj['sql_host']         = $INFO['sql_host'];
            
$DB->obj['sql_tbl_prefix']   = $INFO['sql_tbl_prefix'];
            
$DB->obj['debug']            = ($INFO['sql_debug'] == 1) ? $_GET['debug'] : 0;
            
$DB->connect();

         require 
XOOPS_ROOT_PATH."/modules/ipboard/sources/lib/emailer.php";

        
$email = new emailer();

         
//--------------------------------------
         // Attempt to get the reciepient details
         //--------------------------------------

         
$to_member = array();

         
$DB->query("SELECT uname, uid, view_pop, mgroup, email_pm, language, email FROM ibf_members WHERE uid='$to_userid'");
         
$to_member $DB->fetch_row();

         if (empty(
$to_member['uid']))
         {
             
//echo "Member does not exist";
                        
$DB->close_db();
             return;
         }


         
//--------------------------------------
         // Can the reciepient use the PM system?
         //--------------------------------------

         
$DB->query("SELECT m.msg_total, g.g_use_pm, g.g_max_messages FROM ibf_groups g, ibf_members m WHERE m.uid='".$to_member['uid']."' AND g.g_id=m.mgroup");
         
$to_msg_stats $DB->fetch_row();

         if (
$to_msg_stats['g_use_pm'] != 1)
         {
             
//echo "Recipient cannot use PM system";
                        
$DB->close_db();
             return;
         }

         
//--------------------------------------
         // Does the target member have enough room
         // in their inbox for a new message?
         //--------------------------------------

        
if ( (($to_msg_stats['msg_total']) >= $to_msg_stats['g_max_messages']) and ($to_msg_stats['g_max_messages'] > 0) )
        {
            
//echo "No room";
                        
$DB->close_db();
                        return;
        }

         
//--------------------------------------
         // Has the reciepient blocked us?
         //--------------------------------------

         
$DB->query("SELECT contact_id, allow_msg FROM ibf_contacts WHERE contact_id='1' AND member_id='".$to_member['uid']."'");
         
$can_msg $DB->fetch_row();

         if ( (isset(
$can_msg['contact_id'])) and ($can_msg['allow_msg'] != 1) )
         {
             
//echo "blocked";
                        
$DB->close_db();
             return;
         }



         
//-----------------------------------------
         // Add our original ID to the pool and loop
         //-----------------------------------------

         
$cc_array[$to_member['uid']] = $to_member;

         unset(
$to_member);

         foreach (
$cc_array as $user_id => $to_member)
         {

            
//--------------------------------------
            // Sort out tracking and pop us status
            //--------------------------------------

            
$show_popup =  $to_member['view_pop'];

            
//--------------------------------------
            // Enter the info into the DB
            // Target user side.
            //--------------------------------------

            
$db_string $std->compile_db_string( array(
        
'member_id'      => $to_member['uid'],
        
'msg_date'       => time(),
        
'read_state'     => '0',
        
'title'          => $subject,
        
'message'        => $std->remove_tags($msg_text),
        
'from_id'        => 1,
        
'vid'            => 'in',
        
'recipient_id'   => $to_member['uid'],
        
'tracking'       => 0,
                                                )      );

            
$DB->query("INSERT INTO ibf_messages (" .$db_string['FIELD_NAMES']. ") VALUES ("$db_string['FIELD_VALUES'] .")");
            
$new_id $DB->get_insert_id();
            unset(
$db_string);

            
//-----------------------------------------------------

            
$DB->query("UPDATE ibf_members SET ".
                        
"msg_total = msg_total + 1, "                    .
                        
"new_msg = new_msg + 1, "                        .
                        
"msg_from_id='1', ".
                        
"msg_msg_id='"      $new_id                    .  "', ".
                        
"show_popup='"      $show_popup                .  "' ".
                        
"WHERE uid='"        $to_member['uid']           .  "'");
/*
            //-----------------------------------------------------
            // Has this member requested a PM email nofity?
            //-----------------------------------------------------

            if (1)//($to_member['email_pm'] == 1)
            {
                $to_member['language'] = $to_member['language'] == "" ? 'en' : $to_member['language'];

                $email->get_template("pm_notify", $to_member['language']);

                $email->build_message( array(
        'NAME'   => $to_member['uname'],
        'POSTER' => 'Samcrew',
        'TITLE'  => $input['msg_title'],
        'LINK'   => "?act=Msg&CODE=03&VID=in&MSID=$new_id",
                                                  )
                                            );

                //$email->subject = lang['pm_email_subject'];
                $email->to      = $to_member['email'];
                $email->send_mail();

            }
*/
        
}
        
//echo "OK! :)";
                
$DB->close_db();
            
// =====================================
            
            
        
} else {
            
$sql sprintf("UPDATE %s SET msg_image = %s, subject = %s, from_userid = %u, to_userid = %u, msg_text = %s, read_msg = %u WHERE msg_id = %u"$this->db->prefix('priv_msgs'), $this->db->quoteString($msg_image), $this->db->quoteString($subject), $from_userid$to_userid$this->db->quoteString($msg_text), $read_msg$msg_id);
        }
        if (!
$result $this->db->query($sql)) {
            return 
false;
        }
        if (empty(
$msg_id)) {
            
$msg_id $this->db->getInsertId();
        }
        
$pm->assignVar('msg_id'$msg_id);
        return 
true;
    }


Comments/criticism/suggestions welcome :)

Login

Who's Online

401 user(s) are online (272 user(s) are browsing Support Forums)


Members: 0


Guests: 401


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits