phpBBHacks.com - forum notification issue
Rate your favorite (and least favorite) sodas at SodaRatings.com
StatsForums Home   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in
FAQFAQ   SearchSearch   MemberlistMemberlist   TutorialsTutorials   ContactContact Us
Add Us:     MySpace     Facebook     StumbleUpon
Username:    Password:
Remember Me?    
forum notification issue
BlinkList
del.icio.us
Furl
linkaGoGo
reddit
Simpy
Mister Wong
Yahoo! My Web

Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2 Hack Development
 See a User Guidelines violation? Please contact us.
Author Message

Wicher
Well Known User

Joined: 23 Apr 2003
Posts: 223
Location: Netherlands or Holland, your choice..

PostPosted: July 12th 2008, 3:30 pm    Post subject: forum notification issue Reply with quote

Hello, i am trying to figure out why this function does not always pick the correct username for use within a notification email when a new topic was created in a forum where a user has notification turned on.

This function is part of "forum notification" mod, which i took over from some one else.

I hope someone here can tell me what is wrong here.
The mod is to be found here: http://www.detecties.com/modforum/viewtopic.php?t=146 or here: http://www.phpbbhacks.com/download/293

Code:
function user_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)
{
   global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
   global $userdata, $user_ip;

   $current_time = time();

   $script_name = preg_replace('/^\/?(.*?)\/?$/', '\1', trim($board_config['script_path']));
   $script_name_forum = ($script_name != '') ? $script_name . '/viewforum.'.$phpEx : 'viewforum.'.$phpEx;
   $script_name = ($script_name != '') ? $script_name . '/viewtopic.'.$phpEx : 'viewtopic.'.$phpEx;
   $server_name = trim($board_config['server_name']);
   $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://';
   $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) . '/' : '/';

   $sql = "SELECT ban_userid
         FROM " . BANLIST_TABLE;
   if (!($result = $db->sql_query($sql)))
   {
      message_die(GENERAL_ERROR, 'Could not obtain banlist', '', __LINE__, __FILE__, $sql);
   }

   $user_id_sql = '';
   while ($row = $db->sql_fetchrow($result))
   {
      if (isset($row['ban_userid']) && !empty($row['ban_userid']))
      {
         $user_id_sql .= ', ' . $row['ban_userid'];
      }
   }

   //
   // Let's do some checking to make sure that mass mail functions
   // are working in win32 versions of php.
   //
   if (preg_match('/[c-z]:\\\.*/i', getenv('PATH')) && !$board_config['smtp_delivery'])
   {
      $ini_val = (@phpversion() >= '4.0.0') ? 'ini_get' : 'get_cfg_var';

      // We are running on windows, force delivery to use our smtp functions
      // since php's are broken by default
      $board_config['smtp_delivery'] = 1;
      $board_config['smtp_host'] = @$ini_val('SMTP');
   }

   if ($mode == 'delete')
   {
      $delete_sql = (!$post_data['first_post'] && !$post_data['last_post']) ? " AND user_id = " . $userdata['user_id'] : '';
      $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id = $topic_id" . $delete_sql;
      if (!$db->sql_query($sql))
      {
         message_die(GENERAL_ERROR, 'Could not change topic notify data', '', __LINE__, __FILE__, $sql);
      }
   }
   else
   {
      if ($mode == 'reply')
      {
         $sql = "SELECT u.user_id, u.user_email, u.user_lang, u.username, f.forum_name
            FROM " . TOPICS_WATCH_TABLE . " tw, " . USERS_TABLE . " u, " . FORUMS_TABLE . " f
            WHERE tw.topic_id = $topic_id
               AND tw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")
               AND tw.notify_status = " . TOPIC_WATCH_UN_NOTIFIED . "
               AND f.forum_id = $forum_id
               AND u.user_id = tw.user_id";
         if (!($result = $db->sql_query($sql)))
         {
            message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
         }

         $update_watched_sql = '';
         $bcc_list_ary = array();
         $users_ary = array();
         
         if ($row = $db->sql_fetchrow($result))
         {
            // Sixty second limit
            @set_time_limit(60);

            do
            {
               if ($row['user_email'] != '')
               {
                  $bcc_list_ary[$row['user_lang']][] = $row['user_email'];
                  $users_ary[$row['user_email']] = $row['username'];
               }
               $forum_name = $row['forum_name'];
               $update_watched_sql .= ($update_watched_sql != '') ? ', ' . $row['user_id'] : $row['user_id'];
            }
            while ($row = $db->sql_fetchrow($result));

            if (sizeof($bcc_list_ary))
            {
               include_once($phpbb_root_path . 'includes/emailer.'.$phpEx);
               $emailer = new emailer($board_config['smtp_delivery']);

               $orig_word = array();
               $replacement_word = array();
               obtain_word_list($orig_word, $replacement_word);

               $emailer->from($board_config['board_email']);
               $emailer->replyto($board_config['board_email']);

               $topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
               $post_text = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($post_data['message'])) : unprepare_message($post_data['message']);

               @reset($bcc_list_ary);
               while (list($user_lang, $bcc_list) = each($bcc_list_ary))
               {
                  $emailer->use_template('topic_notify', $user_lang);
      
                  for ($i = 0; $i < count($bcc_list); $i++)
                  {
                     $emailer->bcc($bcc_list[$i]);
                  }

                  // The Topic_reply_notification lang string below will be used
                  // if for some reason the mail template subject cannot be read
                  // ... note it will not necessarily be in the posters own language!
                  $emailer->set_subject($lang['Topic_reply_notification']);
                  
                  // This is a nasty kludge to remove the username var ... till (if?)
                  // translators update their templates
                  // $emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);

                  $emailer->assign_vars(array(
                     'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
                     'SITENAME' => $board_config['sitename'],
                     'USERNAME' => $users_ary[$bcc_list['0']],
                     'TOPIC_TITLE' => $topic_title,
                     'POST_TEXT' => $post_text,
                     'POSTERNAME' => $post_data['username'],
                     'FORUM_NAME' => $forum_name,

                     'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
                     'U_STOP_WATCHING_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_TOPIC_URL . "=$topic_id&unwatch=topic")
                  );

                  $emailer->send();
                  $emailer->reset();
               }
            }
         }
         
         $already_mailed = ( trim($update_watched_sql) == '' ) ? "" : "$update_watched_sql, ";
         $db->sql_freeresult($result);

         // start of reply forum notification
         $sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name
            FROM " . USERS_TABLE . " u, " . FORUMS_WATCH_TABLE . " fw, " . FORUMS_TABLE . " f
            WHERE fw.forum_id = $forum_id
               AND fw.user_id NOT IN (" . $already_mailed . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . " )
               AND f.forum_id = $forum_id
               AND f.forum_notify = '1'
               AND u.user_id = fw.user_id";
         if (!($result = $db->sql_query($sql)))
         {
            message_die(GENERAL_ERROR, 'Could not obtain list of topic watchers', '', __LINE__, __FILE__, $sql);
         }

         $bcc_list_ary = array();
         
         $users_ary = array();
         
         if ($row = $db->sql_fetchrow($result))
         {
            // Sixty second limit
            @set_time_limit(60);

            do
            {
               if ($row['user_email'] != '')
               {
                  $bcc_list_ary[$row['user_lang']][] = $row['user_email'];
                  $users_ary[$row['user_email']] = $row['username'];
               }
               $forum_name = $row['forum_name'];
            }
            while ($row = $db->sql_fetchrow($result));

            if (sizeof($bcc_list_ary))
            {
               include_once($phpbb_root_path . 'includes/emailer.'.$phpEx);
               $emailer = new emailer($board_config['smtp_delivery']);

               $orig_word = array();
               $replacement_word = array();
               obtain_word_list($orig_word, $replacement_word);

               $emailer->from($board_config['board_email']);
               $emailer->replyto($board_config['board_email']);

               $topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
               $post_text = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($post_data['message'])) : unprepare_message($post_data['message']);

               $temp_is_auth = array();
               @reset($bcc_list_ary);
               while (list($user_lang, $bcc_list) = each($bcc_list_ary))
               {
                  $temp_userdata = get_userdata($row['user_id']);
                  $temp_is_auth = auth(AUTH_ALL, $forum_id, $temp_userdata, -1);
               
                  // another security check (i.e. the forum might have become private and
                  // there are still users who have notification activated)
                  if( $temp_is_auth['auth_read'] && $temp_is_auth['auth_view'] )
                  {
                     $emailer->use_template('forum_notify', $user_lang);
         
                     for ($i = 0; $i < count($bcc_list); $i++)
                     {
                        $emailer->bcc($bcc_list[$i]);
                     }
   
                     // The Topic_reply_notification lang string below will be used
                     // if for some reason the mail template subject cannot be read
                     // ... note it will not necessarily be in the posters own language!
                     $emailer->set_subject($lang['Topic_reply_notification']);
                     
                     // This is a nasty kludge to remove the username var ... till (if?)
                     // translators update their templates
                     // $emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
   
                     $emailer->assign_vars(array(
                        'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
                        'SITENAME' => $board_config['sitename'],
                        'USERNAME' => $users_ary[$bcc_list['0']],
                        'TOPIC_TITLE' => $topic_title,
                        'POST_TEXT' => $post_text,
                        'POSTERNAME' => $post_data['username'],
                        'FORUM_NAME' => $forum_name,
   
                        'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
                        'U_STOP_WATCHING_FORUM' => $server_protocol . $server_name . $server_port . $script_name_forum . "?" . POST_FORUM_URL . "=$forum_id&unwatch=forum")
                     );
   
                     $emailer->send();
                     $emailer->reset();
                  }
               }
            }
         }
         // end of forum notification on reply
         
         $db->sql_freeresult($result);
         
         if ($update_watched_sql != '')
         {
            $sql = "UPDATE " . TOPICS_WATCH_TABLE . "
               SET notify_status = " . TOPIC_WATCH_NOTIFIED . "
               WHERE topic_id = $topic_id
                  AND user_id IN ($update_watched_sql)";
            $db->sql_query($sql);
         }
         
      }

      //
      // code for newtopic forum notification
      //
      
      if ($mode == 'newtopic')
      {
         $sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name
            FROM " . FORUMS_WATCH_TABLE . " fw, " . USERS_TABLE . " u, " . FORUMS_TABLE . " f
            WHERE fw.forum_id = $forum_id
               AND fw.user_id NOT IN (" . $userdata['user_id'] . ", " . ANONYMOUS . $user_id_sql . ")
               AND f.forum_id = $forum_id
               AND f.forum_notify = '1' 
               AND u.user_id = fw.user_id";
         if (!($result = $db->sql_query($sql)))
         {
            message_die(GENERAL_ERROR, 'Could not obtain list of forum watchers', '', __LINE__, __FILE__, $sql);
         }

         $bcc_list_ary = array();
         $users_ary = array();
         
         if ($row = $db->sql_fetchrow($result))
         {
            // Sixty second limit
            @set_time_limit(60);

            unset($forum_name);
            do
            {
               if ($row['user_email'] != '')
               {
                  $bcc_list_ary[$row['user_lang']][] = $row['user_email'];
                  $users_ary[$row['user_email']] = $row['username'];
               }
               $forum_name = $row['forum_name'];
            }
            while ($row = $db->sql_fetchrow($result));

            if (sizeof($bcc_list_ary))
            {
               include_once($phpbb_root_path . 'includes/emailer.'.$phpEx);
               $emailer = new emailer($board_config['smtp_delivery']);

               $orig_word = array();
               $replacement_word = array();
               obtain_word_list($orig_word, $replacement_word);

               $emailer->from($board_config['board_email']);
               $emailer->replyto($board_config['board_email']);

               $topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($topic_title)) : unprepare_message($topic_title);
               $post_text = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, unprepare_message($post_data['message'])) : unprepare_message($post_data['message']);

               $temp_is_auth = array();
               @reset($bcc_list_ary);
               while (list($user_lang, $bcc_list) = each($bcc_list_ary))
               {
                  $temp_userdata = get_userdata($row['user_id']);
                  $temp_is_auth = auth(AUTH_ALL, $forum_id, $temp_userdata, -1);
               
                  // another security check (i.e. the forum might have become private and
                  // there are still users who have notification activated)
                  if( $temp_is_auth['auth_read'] && $temp_is_auth['auth_view'] )
                  {
                     $emailer->use_template('newtopic_notify', $user_lang);
         
                     for ($i = 0; $i < count($bcc_list); $i++)
                     {
                        $emailer->bcc($bcc_list[$i]);
                     }
   
                     // The Topic_reply_notification lang string below will be used
                     // if for some reason the mail template subject cannot be read
                     // ... note it will not necessarily be in the posters own language!
                     $emailer->set_subject($lang['Topic_reply_notification']);
                     
                     // This is a nasty kludge to remove the username var ... till (if?)
                     // translators update their templates
                     // $emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
   
                     $emailer->assign_vars(array(
                        'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
                        'SITENAME' => $board_config['sitename'],
                        'USERNAME' => $users_ary[$bcc_list['0']],
                        'TOPIC_TITLE' => $topic_title,
                        'POST_TEXT' => $post_text,
                        'POSTERNAME' => $post_data['username'],
                        'FORUM_NAME' => $forum_name,
                        'U_TOPIC' => $server_protocol . $server_name . $server_port . $script_name . '?' . POST_POST_URL . "=$post_id#$post_id",
                        'U_STOP_WATCHING_FORUM' => $server_protocol . $server_name . $server_port . $script_name_forum . "?" . POST_FORUM_URL . "=$forum_id&unwatch=forum")
                     );
   
                     $emailer->send();
                     $emailer->reset();
                  }
               }
            }
         }
         
         $db->sql_freeresult($result);
      }
 
      
      $sql = "SELECT topic_id
         FROM " . TOPICS_WATCH_TABLE . "
         WHERE topic_id = $topic_id
            AND user_id = " . $userdata['user_id'];
      if (!($result = $db->sql_query($sql)))
      {
         message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
      }

      $row = $db->sql_fetchrow($result);

      if (!$notify_user && !empty($row['topic_id']))
      {
         $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
            WHERE topic_id = $topic_id
               AND user_id = " . $userdata['user_id'];
         if (!$db->sql_query($sql))
         {
            message_die(GENERAL_ERROR, 'Could not delete topic watch information', '', __LINE__, __FILE__, $sql);
         }
      }
      else if ($notify_user && empty($row['topic_id']))
      {
         $sql = "INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
            VALUES (" . $userdata['user_id'] . ", $topic_id, 0)";
         if (!$db->sql_query($sql))
         {
            message_die(GENERAL_ERROR, 'Could not insert topic watch information', '', __LINE__, __FILE__, $sql);
         }
      }
   }
}

_________________
My little mods | Statistics Mod 4.x.x (revision of 2.1.5) | My hacks at phpbbhacks
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    phpBBHacks.com Support Forums Forum Index -> phpBB 2 Hack Development All times are GMT - 6 Hours
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Links: Big Message Boards - Free JavaScript - phpBB2 - phpbb styles - Suporte phpBB - phpBB.it - phpBB Česky - phpBB Turkiye - phpBBArabia.com - phpBB-fr.com - Romanian phpBB online community - phpBB-TW.net - phpBBservice.nl - phpBB Brasil

Network: iFroggy Network Blog - iFroggy Hosting - SportsForums.net - KarateForums.com - YanksBlog.com - PhotoshopForums.com - DeveloperCube - Managing Online Forums - ManagingCommunities.com - CommunityAdmins.com - DrGregHouse.com - Bad Boy Blog - BadBoyForums.com - SodaRatings.com - Patrick O'Keefe

< Advertising - Contact Us - Staff - User Guidelines >

Copyright © 2001-2008. iFroggy Network, phpBBHacks.com. All Rights Reserved. Privacy Policy. We Support phpBBHacks.com (of course!).
Powered by phpBB © phpBB Group. phpBB SEO. Hosted by 100MegsWebHosting. We are in no way affiliated with the phpBB Group. phpBB is copyright to the phpBB Group.