Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by iSlayter ( 16 years ago )
<?php
ini_set('display_errors',0);
header("Content-Type: text/html; charset=utf-8");
error_reporting(E_ALL);

define('THIS_SCRIPT', 'private');
define('CSRF_PROTECTION', true);

require_once('./global.php');
require_once(DIR . '/includes/functions_user.php');
require_once(DIR . '/includes/functions_misc.php');

class WiseNotify
{
 private $vb;
 
 // RECIPIENTS
 private $toUser; // topicstarter
 private $toTeam = array(); // each element of this array is recipient name (anybody but the topic-starter etc)
 
 // MESSAGE SETTING (titles, texts etc)
 private $titles = array(); 
 private $info   = array();
 
 public function __construct($event, $vbulletin, $info = false)
 {
        $this->vb = $vbulletin;
        if (false !== $info) $this->info = $info;

        $this->toTeam[] = $this->vb->userinfo['username'];
        
        if ($this->vb->userinfo['userid'] != $this->vb->options['wn_adminname']) {
         // Если текущий пользователь - не единственный администратор, получающий копии всех сообщений с уведомлениями,
            // то добавляем его в список получателей копии сообщений.
         $mainAdmin = fetch_userinfo($this->vb->options['wn_adminname']);
         $this->toTeam[] = $mainAdmin['username'];
        }
                 
        if (method_exists($this, $event)) {
            $this->$event();
            $this->postAction();    
        }
 }
 
 /*
  * Уведомление в момент удаления темы.
  * Получатели: совершивший действие, главный администратор (задаётся в настройках), топикстартер
  */
 public function onThreadDelete()
 {
  // {1} -> $thread['title']; {2} -> $forum['title']
  $thread = fetch_threadinfo($this->info['threadid']);
  $forum  = fetch_foruminfo($thread['forumid']);
    
  // TO THE TEAM
  $templater = vB_Template::create('notify_thread_delete');
     $templater->register('thread',  $thread);
     $templater->register('forum',   $forum);
     $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $thread['dateline']));
     $templater->register('deletedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
     $templater->register('firstpost', fetch_postinfo($thread['firstpostid']));
        $templater->register('delinfo', $this->info['delinfo']);
        $templater->register('toTeam', true);
                    
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadDelete_toTeam', 'pm'), $thread['title'], $forum['title']);
        $message = trim(strip_tags($templater->render()));
        $this->composeMessage($title, $message, $this->toTeam);
        unset($templater);
        
        // TO THE TOPIC STARTER
        $templater = vB_Template::create('notify_thread_delete');
        $templater->register('thread',  $thread);
        $templater->register('forum',   $forum);
        $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $thread['dateline']));
        $templater->register('deletedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
        $templater->register('firstpost', fetch_postinfo($thread['firstpostid']));
        $templater->register('delinfo', $this->info['delinfo']);
        $templater->register('toTeam', false);
  
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadDelete_toUser', 'pm'), $thread['title'], $forum['title']);    
        $message = trim(strip_tags($templater->render()));     
        $this->composeMessage($title, $message, $thread['postusername']);
 }
 
    /*
     * Уведомление в момент разделения темы
     */
 public function onThreadSplit()
 {
  // переменные, необходимые в шаблоне: toTeam (true - если команде), firstpost, threadinfo, foruminfo, newthreadinfo, newforuminfo, splittedAt (time() в виде даты), createdAt
        // TO THE TEAM
        $this->info['threadinfo'] = fetch_threadinfo($this->vb->GPC['threadid']);
        $this->info['foruminfo'] = fetch_foruminfo($this->info['threadinfo']['forumid']);

        $templater = vB_Template::create('notify_thread_split');
        $templater->register('threadinfo', $this->info['threadinfo']);
        $templater->register('foruminfo', $this->info['foruminfo']);
        $templater->register('newthreadinfo', $this->info['newthreadinfo']);
        $templater->register('newforuminfo', $this->info['newforuminfo']);
        $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['threadinfo']['dateline']));
        $templater->register('splittedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
        $templater->register('firstpost', fetch_postinfo($this->info['threadinfo']['firstpostid']));
        $templater->register('toTeam', true);
        
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadSplit_toTeam', 'pm'), $this->info['threadinfo']['title']);    
        $message = trim(strip_tags($templater->render()));
        
        $this->composeMessage($title, $message, $this->toTeam);
        unset($templater);
        
        $templater = vB_Template::create('notify_thread_split');
        $templater->register('threadinfo', $this->info['threadinfo']);
        $templater->register('foruminfo', $this->info['foruminfo']);
        $templater->register('newthreadinfo', $this->info['newthreadinfo']);
        $templater->register('newforuminfo', $this->info['newforuminfo']);
        $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['threadinfo']['dateline']));
        $templater->register('splittedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
        $templater->register('firstpost', fetch_postinfo($this->info['threadinfo']['firstpostid']));
        $templater->register('toTeam', false);
        
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadSplit_toUser', 'pm'), $this->info['threadinfo']['title']);    
        $message = trim(strip_tags($templater->render()));

        $this->composeMessage($title, $message, $this->info['threadinfo']['postusername']);
 }

    /*
     * Уведомление в момент перемещения темы.
     * Получатели: совершивший действие, главный администратор (задаётся в настройках), топикстартер
     */
 public function onThreadMove()
 {
  // переменные, необходимые в шаблоне: toTeam (true - если команде), firstpost, thread, forum, destforuminfo, method, movedAt (time() в виде даты), createdAt
        // TO THE TEAM
        $templater = vB_Template::create('notify_thread_moved');
        $templater->register('thread', $this->info['thread']);
        $templater->register('foruminfo', $this->info['foruminfo']);
        $templater->register('destforuminfo', $this->info['destforuminfo']);
        $templater->register('method', $this->info['method']);
        $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['thread']['dateline']));
        $templater->register('movedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
        $templater->register('firstpost', fetch_postinfo($this->info['thread']['firstpostid']));
        $templater->register('toTeam', true);
        
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadMove_toTeam', 'pm'), $this->info['thread']['title'], $this->info['foruminfo']['title'], $this->info['destforuminfo']['title']);    
        $message = trim(strip_tags($templater->render()));
        
        $this->composeMessage($title, $message, $this->toTeam);
        unset($templater);
        
        $templater = vB_Template::create('notify_thread_moved');
        $templater->register('thread', $this->info['thread']);
        $templater->register('foruminfo', $this->info['foruminfo']);
        $templater->register('destforuminfo', $this->info['destforuminfo']);
        $templater->register('method', $this->info['method']);
        $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['thread']['dateline']));
        $templater->register('movedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
        $templater->register('firstpost', fetch_postinfo($this->info['thread']['firstpostid']));
        $templater->register('toTeam', false);
        
        $title   = construct_phrase(fetch_phrase('wn_title_onThreadMove_toUser', 'pm'), $this->info['thread']['title'], $this->info['foruminfo']['title'], $this->info['destforuminfo']['title']);    
        $message = trim(strip_tags($templater->render()));

        $this->composeMessage($title, $message, $this->info['thread']['postusername']);
 }
    
 /*
     * Уведомление в момент склеивания тем.
     * Получатели: совершивший действие, главный администратор (задаётся в настройках), топикстартеры склеиваемых тем
     */
    public function onThreadMerge()
    {
     $this->info['mergethreadinfo'] = fetch_threadinfo($this->vb->GPC['destthreadid']);
        $this->info['mergeforuminfo'] = fetch_foruminfo($this->info['mergethreadinfo']['forumid']);
    
     // Если объединяются несколько тем, то мы должны разослать мессаджи всем
     foreach ($this->info['threadarray'] as $th_info) {
         $this->info['threadinfo'] = fetch_threadinfo($th_info['threadid']);

         // переменные, необходимые в шаблоне: toTeam (true - если команде), firstpost, threadinfo, foruminfo, $mergethreadinfo, $mergeforuminfo, mergedAt (time() в виде даты), createdAt
         // TO THE TEAM
         $templater = vB_Template::create('notify_thread_merge');
         $templater->register('threadinfo', $this->info['threadinfo']);
         $templater->register('foruminfo', $this->info['foruminfo']);
         $templater->register('mergethreadinfo', $this->info['mergethreadinfo']);
         $templater->register('mergeforuminfo', $this->info['mergeforuminfo']);
         $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['threadinfo']['dateline']));
         $templater->register('mergedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
         $templater->register('firstpost', fetch_postinfo($this->info['threadinfo']['firstpostid']));
         $templater->register('toTeam', true);
         
         $title   = construct_phrase(fetch_phrase('wn_title_onThreadMerge_toTeam', 'pm'), $this->info['threadinfo']['title'], $this->info['mergethreadinfo']['title']);    
         $message = trim(strip_tags($templater->render()));
         
         $this->composeMessage($title, $message, $this->toTeam);
         unset($templater);
         
         // TO STARTER OF ONE THREAD
         $templater = vB_Template::create('notify_thread_merge');
         $templater->register('threadinfo', $this->info['threadinfo']);
         $templater->register('foruminfo', $this->info['foruminfo']);
         $templater->register('mergethreadinfo', $this->info['mergethreadinfo']);
         $templater->register('mergeforuminfo', $this->info['mergeforuminfo']);
         $templater->register('createdAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat'], $this->info['threadinfo']['dateline']));
         $templater->register('mergedAt', vbdate($this->vb->options['dateformat']. ' в ' . $this->vb->options['timeformat']));
         $templater->register('firstpost', fetch_postinfo($this->info['threadinfo']['firstpostid']));
         $templater->register('toTeam', false);
         
         $title   = construct_phrase(fetch_phrase('wn_title_onThreadMerge_toUser', 'pm'), $this->info['threadinfo']['title'], $this->info['mergethreadinfo']['title']);    
         $message = trim(strip_tags($templater->render()));
         
         $this->composeMessage($title, $message, $this->info['threadinfo']['postusername']);
     }
    } 
    
    /*
     * Уведомление в момент удаления сообщения.
     * Получатели: совершивший действие, главный администратор (задаётся в настройках), автор сообщения
     */
 public function onPostDelete($doNotSendToAdmin = false)
 {
  
 }
 
 /*
  * Уведомление в момент удаления сообщений, будет вызывать $this->onPostDelete(true) необходимое количество раз
  */
 public function onPostsDelete()
 {
  
 }
 
 private function postAction()
 {
  $this->updateCounters();
 }
 
 /*
  * Parse BB code in the message
  */
 private function bbParse($bbcode, $smilies = true)
 {
  require_once(DIR . '/includes/class_bbcode.php');
        $bbcode_parser = new vB_BbCodeParser($this->vb, fetch_tag_list());
        return $bbcode_parser->parse($bbcode, 'privatemessage', $smilies);
 }
 
 /*
  * After message sending we must to update user counters
  */
 private function updateCounters()
 {
     $pmcount = $this->vb->db->query_first("
         SELECT
             COUNT(pmid) AS pmtotal,
             SUM(IF(messageread = 0 AND folderid >= 0, 1, 0)) AS pmunread
         FROM " . TABLE_PREFIX . "pm AS pm
         WHERE pm.userid = " . $this->vb->userinfo['userid'] . "
     ");
 
     $pmcount['pmtotal'] = intval($pmcount['pmtotal']);
     $pmcount['pmunread'] = intval($pmcount['pmunread']);
 
     if ($this->vb->userinfo['pmtotal'] != $pmcount['pmtotal'] OR $this->vb->userinfo['pmunread'] != $pmcount['pmunread'])
     {
         $userdata =& datamanager_init('User', $this->vb, ERRTYPE_STANDARD);
         $userdata->set_existing($this->vb->userinfo);
         $userdata->set('pmtotal', $pmcount['pmtotal']);
         $userdata->set('pmunread', $pmcount['pmunread']);
         $userdata->save();
     }
 }
 
 private function composeMessage($title, $message, $recipient)
 {
  require_once(DIR . '/includes/functions_newpost.php');

     $pm['parseurl'] = 1;
     $pm['signature'] = 0;
     $pm['disablesmilies'] = 0;
     $pm['sendanyway'] = 1;
     
     $recipients = (is_array($recipient)) ? implode('; ', $recipient) : $recipient;
     
     $pmn_iconid  = 4;
     $pmn_signat  = 1;
     $pmn_smiles  = 1;
 
     // create the DM to do error checking and insert the new PM
     $pmdm =& datamanager_init('PM', $this->vb, ERRTYPE_ARRAY);
 
     $pmdm->set_info('savecopy',      0);
     $pmdm->set_info('receipt',       0);
     $pmdm->set_info('cantrackpm',    0);
     $pmdm->set_info('forward',       '');
     $pmdm->set_info('bccrecipients', '');
     
     // FROM
     $pmdm->set('fromuserid', $this->vb->userinfo['userid']);
     $pmdm->set('fromusername', $this->vb->userinfo['username']);
     
     $pmdm->setr('title', $title);
     $permissions = array('pmsendmax' => 0);
     $pmdm->set_recipients($recipients, &$permissions, 'cc');
     $pmdm->setr('message', convert_url_to_bbcode($message));
     $pmdm->setr('iconid', &$pmn_iconid);
     $pmdm->set('dateline', TIMENOW);
     $pmdm->setr('showsignature', &$pmn_signat);
     $pmdm->set('allowsmilie', &$pmn_smiles);
     $pmdm->set_info('replypmid', '');
     $pmdm->pre_save();
     
     // everything's good!
        $pmdm->save();

        // force pm counters to be rebuilt
        $this->vb->userinfo['pmunread'] = -1;
        $this->updateCounters();
 }

}
global $vbulletin;
if (isset($wn_event) && isset($wn_info)) $oWiseNotify = new WiseNotify($wn_event, $vbulletin, $wn_info);
?>

 

Revise this Paste

Your Name: Code Language: