pm
[ class tree: pm ] [ index: pm ] [ all elements ]

Source for file pm.inc.php

Documentation is available at pm.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2009-08-26 19:19:41 +0200 (Mi, 26 Aug 2009) $
  5.      * @package            pm
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/pm.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_pm extends ipbwi {
  12.         private $ipbwi            null;
  13.         /**
  14.          * @desc            Loads and checks different vars when class is initiating
  15.          * @author            Matthias Reuter
  16.          * @since            2.0
  17.          * @ignore
  18.          */
  19.         public function __construct($ipbwi){
  20.             // loads common classes
  21.             $this->ipbwi $ipbwi;
  22.         }
  23.         /**
  24.          * @desc            Moves a personal message to another folder.
  25.          * @param    int        $messageID Message ID to be moved
  26.          * @param    int        $targetID Target folder ID.
  27.          * @return    bool    true on success, otherwise false
  28.          * @author            Matthias Reuter
  29.          * @sample
  30.          *  <code>
  31.          *  $ipbwi->pm->move(5,4);
  32.          *  </code>
  33.          * @since            2.0
  34.          */
  35.         public function move($messageID$targetID){
  36.             if($this->ipbwi->member->isLoggedIn()){
  37.                 // Grab PM Info
  38.                 if($info $this->info($messageID0)){
  39.                     // Check the Dest Folder Exists
  40.                     if($this->folderExists($targetID)){
  41.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics SET mt_vid_folder="'.$targetID.'" WHERE mt_id="'.$messageID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  42.                         if($this->ipbwi->ips_wrapper->DB->get_affected_rows()){
  43.                             // If you move an unread message from inbox
  44.                             if($info['vid'== 'in' AND $info['read_state'== '0'){
  45.                                 $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET new_msg = new_msg - 1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  46.                             // And if you move a unread message to the inbox
  47.                             }else if($targetID == 'in' AND $info['read_state'== '0'){
  48.                                 $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET new_msg = new_msg + 1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  49.                             }
  50.                             return true;
  51.                         }else{
  52.                             $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMsgNoMove'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  53.                             return false;
  54.                         }
  55.                     }else{
  56.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmFolderNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  57.                         return false;
  58.                     }
  59.                 }else{
  60.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMsgNoMove'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  61.                     return false;
  62.                 }
  63.             }else{
  64.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  65.                 return false;
  66.             }
  67.         }
  68.         /**
  69.          * @desc            Marks a message read/unread.
  70.          * @param    int        $messageID Message ID to be marked
  71.          * @param    int        $isRead Default: 1=mark read, 0=mark unread
  72.          * @return    bool    true on success, otherwise false
  73.          * @author            Matthias Reuter
  74.          * @sample
  75.          *  <code>
  76.          *  $ipbwi->pm->mark(55,0);
  77.          *  </code>
  78.          * @since            2.0
  79.          */
  80.         public function mark($messageID$isRead 1){
  81.             if($this->ipbwi->member->isLoggedIn()){
  82.                 $pm $this->info($messageID);
  83.                 if($isRead && $pm['mt_read'!= 1){
  84.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET new_msg = new_msg-1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" AND new_msg > 0');
  85.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics SET mt_read="1" WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_id="'.intval($messageID).'"');
  86.                     // Return success
  87.                     if($this->ipbwi->ips_wrapper->DB->get_affected_rows()){
  88.                         return true;
  89.                     }else{
  90.                         return false;
  91.                     }
  92.                 }elseif(!$isRead && $pm['mt_read'== 1){
  93.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET new_msg = new_msg+1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  94.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics SET mt_read="0" WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_id="'.intval($messageID).'"');
  95.                     // Return success
  96.                     if($this->ipbwi->ips_wrapper->DB->get_affected_rows()){
  97.                         return true;
  98.                     }else{
  99.                         return false;
  100.                     }
  101.                 }
  102.             }else{
  103.                 return false;
  104.             }
  105.         }
  106.         /**
  107.          * @desc            Removes a personal message folder.
  108.          * @param    int        $folderID folder ID
  109.          * @return    bool    true on success, otherwise false
  110.          * @author            Matthias Reuter
  111.          * @sample
  112.          *  <code>
  113.          *  $ipbwi->pm->removeFolder(55);
  114.          *  </code>
  115.          * @since            2.0
  116.          */
  117.         public function removeFolder($folderID){
  118.             if($this->ipbwi->member->isLoggedIn()){
  119.                 $folders $this->getFolders();
  120.                 $foldersi array();
  121.                 if($this->folderExists($folderID)){
  122.                     // Check if it's Inbox or Sent Items
  123.                     if($folderID != 'in' AND $folderID != 'sent'){
  124.                         // Good. Now, try and delete the messages firstly.
  125.                         $this->emptyFolder($folderID0);
  126.                         // Now Delete the Folder
  127.                         foreach($folders as $m => $i){
  128.                             if($i['id'!= $folderID){
  129.                                 $cur $i['id'].':'.$i['name'].';'.$i['count'];
  130.                                 $foldersi[$i['id']] $cur;
  131.                             }
  132.                         }
  133.                         $newvids implode('|'$foldersi);
  134.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'member_extra SET vdirs="'.$newvids.'" WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  135.                         return true;
  136.                     }else{
  137.                         $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmFolderNoRem'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  138.                         return false;
  139.                     }
  140.                 }else{
  141.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmFolderNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  142.                     return false;
  143.                 }
  144.             }else{
  145.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  146.                 return false;
  147.             }
  148.         }
  149.         /**
  150.          * @desc            Empties PMs in a personal message folder.
  151.          * @param    int        $folderID folder ID
  152.          * @param    int        $keepunread Default: 0=also delete unread msgs, 1=keep unread messages
  153.          * @return    bool    true on success, otherwise false
  154.          * @author            Matthias Reuter
  155.          * @sample
  156.          *  <code>
  157.          *  $ipbwi->pm->emptyFolder(55,1);
  158.          *  </code>
  159.          * @since            2.0
  160.          */
  161.         public function emptyFolder($folderID$keepUnread 0){
  162.             if($this->ipbwi->member->isLoggedIn()){
  163.                 if($this->folderExists($folderID)){
  164.                     if($keepUnread$sql_keep_unread ' AND mt_read="1"';
  165.                     // Just so we can decrement total
  166.                     $this->ipbwi->ips_wrapper->DB->query('SELECT COUNT(mt_id) AS messagescount FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_vid_folder="'.$folderID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'"'.$sql_keep_unread);
  167.                     $row $this->ipbwi->ips_wrapper->DB->fetch();
  168.                     $del $row['messagescount'];
  169.                     // Get message text ids...
  170.                     $this->ipbwi->ips_wrapper->DB->query('SELECT mt_msg_id FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_vid_folder="'.$folderID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'"'.$sql_keep_unread);
  171.                     // Delete from text
  172.                     while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  173.                         $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_text WHERE msg_id = "'.$row['mt_msg_id'].'"');
  174.                     }
  175.                     // Delete from topics
  176.                     $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_vid_folder="'.$folderID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'"'.$sql_keep_unread);
  177.                     // Update Total
  178.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET msg_total=msg_total-'.intval($del).' WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  179.                     // Update Cache
  180.                     $this->cache->updatePM($this->ipbwi->member->myInfo['member_id']);
  181.                     return $del;
  182.                 }else{
  183.                     return false;
  184.                 }
  185.             }else{
  186.                 return false;
  187.             }
  188.         }
  189.         /**
  190.          * @desc            Renames a personal message folder.
  191.          * @param    int        $folderID folder ID
  192.          * @param    string    $newName New folder name
  193.          * @return    bool    true on success, otherwise false
  194.          * @author            Matthias Reuter
  195.          * @sample
  196.          *  <code>
  197.          *  $ipbwi->pm->renameFolder(55,'new folder name');
  198.          *  </code>
  199.          * @since            2.0
  200.          */
  201.         public function renameFolder($folderID$newName){
  202.             if($this->ipbwi->member->isLoggedIn()){
  203.                 // Get Folders
  204.                 $folders $this->getFolders();
  205.                 $info $this->ipbwi->member->info();
  206.                 $foldersi array();
  207.                 foreach($folders as $i){
  208.                     $foldersi[$i['id']] $i['name'];
  209.                 }
  210.                 // Check it exists
  211.                 if($foldersi[$folderID]){
  212.                     $foldersi[$folderID$newName;
  213.                     $newf array();
  214.                     foreach($folders as $i => $m){
  215.                         $newf[$m['id'].':'.$foldersi[$m['id']].';'.$m['count'];
  216.                     }
  217.                     $newFolders implode ('|'$newf);
  218.                     // Rename the Folder
  219.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'member_extra SET vdirs="'.$newFolders.'" WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  220.                     $this->cache->updatePM($this->ipbwi->member->myInfo['member_id']);
  221.                     return true;
  222.                 }else{
  223.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmFolderNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  224.                     return false;
  225.                 }
  226.             }else{
  227.                 return false;
  228.             }
  229.         }
  230.         /**
  231.          * @desc            Creates a personal message folder.
  232.          * @param    int        $folderID folder ID
  233.          * @param    string    $newName folder name
  234.          * @return    bool    true on success, otherwise false
  235.          * @author            Matthias Reuter
  236.          * @sample
  237.          *  <code>
  238.          *  $ipbwi->pm->addFolder('folder name');
  239.          *  </code>
  240.          * @since            2.0
  241.          */
  242.         public function addFolder($name){
  243.             if($this->ipbwi->member->isLoggedIn()){
  244.                 // Get Folders
  245.                 $folders $this->getFolders();
  246.                 $info $this->ipbwi->member->info();
  247.                 $foldersi array();
  248.                 foreach($folders as $i){
  249.                     if(isset($i[0]&& isset($i[1])){
  250.                         $foldersi[$i[0]] $i[1];
  251.                     }
  252.                 }
  253.                 $foldersno count($folders);
  254.                 // Just to check
  255.                 if(empty($foldersi['dir_'.$foldersno])){
  256.                     $newFolders $info['vdirs'].'|dir_'.$foldersno.':'.$name;
  257.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'member_extra SET vdirs="'.$newFolders.'" WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  258.                     return 'dir_'.$foldersno;
  259.                 }else{
  260.                     // Just incase
  261.                     while($foldersno 100){
  262.                         if(!$foldersi['dir_'.$foldersno]){
  263.                             $newFolders $info['vdirs''|dir_'.$foldersno.':'.$name;
  264.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'member_extra SET vdirs="'.$newFolders.'" WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  265.                             return 'dir_'.$foldersno;
  266.                         }
  267.                         ++$foldersno;
  268.                     }
  269.                     return false;
  270.                 }
  271.             }else{
  272.                 return false;
  273.             }
  274.         }
  275.         /**
  276.          * @desc            Returns folder name associated with folder id of a member.
  277.          * @param    int        $folderID folder ID
  278.          * @param    int        $userID If $userID is ommited, the last known member is used.
  279.          * @return    string    Folder Name associated with id
  280.          * @author            Matthias Reuter
  281.          * @sample
  282.          *  <code>
  283.          *  $ipbwi->pm->folderid2name('folder name');
  284.          *  </code>
  285.          * @since            2.0
  286.          */
  287.         public function folderid2name($folderID$userID false){
  288.             $memberInfo $this->ipbwi->member->info($userID);
  289.             $folders $memberInfo['vdirs'];
  290.             $list explode ('|'$folders);
  291.             foreach($list as $i){
  292.                 $j explode (':'$i);
  293.                 $foldersinfo[$j['0']] $j['1'];
  294.             }
  295.             if($foldersinfo[$folderID]){
  296.                 $name explode(';',$foldersinfo[$folderID]);
  297.                 return $name[0];
  298.             }else{
  299.                 return false;
  300.             }
  301.         }
  302.         /**
  303.          * @desc            Returns whether a PM folder exists for a given member.
  304.          * @param    int        $folderID folder ID
  305.          * @param    int        $userID If $userID is ommited, the last known member is used.
  306.          * @return    bool    Folder Existance Status
  307.          * @author            Matthias Reuter
  308.          * @sample
  309.          *  <code>
  310.          *  $ipbwi->pm->folderExists(3,55);
  311.          *  </code>
  312.          * @since            2.0
  313.          */
  314.         public function folderExists($folderID$userID false){
  315.             // Inbox and Sent Items are Good
  316.             if($folderID == 'in' OR $folderID == 'sent'){
  317.                 return true;
  318.             }
  319.             // 'unsent' should be an bad folder name anyway, but put this so as not to screw up other functions
  320.             if($folderID == 'unsent'){
  321.                 return false;
  322.             }
  323.             $folderIDs array();
  324.             $memberInfo $this->ipbwi->member->info($userID);
  325.             $folders $memberInfo['vdirs'];
  326.             $folderslist explode ('|'$folders);
  327.             foreach($folderslist as $i){
  328.                 $j explode (':'$i);
  329.                 $folderIDs[$j['0'];
  330.             }
  331.             if(in_array($folderID$folderIDs)){
  332.                 return true;
  333.             }else{
  334.                 return false;
  335.             }
  336.         }
  337.         /**
  338.          * @desc            Returns the current user's PM folders.
  339.          * @return    array    Current user's PM System Folders
  340.          * @author            Matthias Reuter
  341.          * @sample
  342.          *  <code>
  343.          *  $ipbwi->pm->getFolders();
  344.          *  </code>
  345.          * @since            2.0
  346.          */
  347.         public function getFolders(){
  348.             if($this->ipbwi->member->isLoggedIn(AND $this->ipbwi->permissions->has('g_use_pm')){
  349.                 $folders array();
  350.                 $this->ipbwi->ips_wrapper->DB->query('SELECT vdirs FROM '.$this->ipbwi->board['sql_tbl_prefix'].'member_extra WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  351.                 if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  352.                     $row['vdirs'$row['vdirs'$row['vdirs''in:Inbox|sent:Sent Items';
  353.                     $i explode ('|'$row['vdirs']);
  354.                     foreach($i as $j){
  355.                         $folder array();
  356.                         $k explode (':'$j);
  357.                         $l explode(';'$k[1]);
  358.                         $folder['id'$k[0];
  359.                         $folder['name'$l[0];
  360.                         if(isset($l[1])) $folder['count'$l[1];
  361.                         $folders[$folder;
  362.                     }
  363.                     return $folders;
  364.                 }else{
  365.                     return false;
  366.                 }
  367.             }else{
  368.                 return false;
  369.             }
  370.         }
  371.         /**
  372.          * @desc            Returns PM space usage in percentage.
  373.          * @return    int        PM Space Usage in Percent
  374.          * @author            Matthias Reuter
  375.          * @sample
  376.          *  <code>
  377.          *  $ipbwi->pm->spaceUsage();
  378.          *  </code>
  379.          * @since            2.0
  380.          */
  381.         public function spaceUsage(){
  382.             $PMs $this->numTotalPms();
  383.             $maximumPMs $this->ipbwi->permissions->best('g_max_messages');
  384.             // Remove possible division by zero...
  385.             if($maximumPMs == 0){
  386.                 return 0;
  387.             }
  388.             $percent round(($PMs $maximumPMs100);
  389.             return $percent;
  390.         }
  391.         /**
  392.          * @desc            Returns number of unread PMs in a folder.
  393.          * @param    int        $folderID Folder ID
  394.          * @return    int        Number of unread PMs in Folder
  395.          * @author            Matthias Reuter
  396.          * @sample
  397.          *  <code>
  398.          *  $ipbwi->pm->numFolderUnreadPMs(55);
  399.          *  </code>
  400.          * @since            2.0
  401.          */
  402.         public function numFolderUnreadPMs($folderID){
  403.             if($cache $this->ipbwi->cache->get('numFolderUnreadPMs'$folderID)){
  404.                 return $cache;
  405.             }
  406.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->ipbwi->permissions->has('g_use_pm')){
  407.                 $this->sdkerror($this->lang['sdk_membersOnly']);
  408.                 return false;
  409.             }
  410.             $this->ipbwi->ips_wrapper->DB->query('SELECT COUNT(mt_msg_id) AS messages FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_vid_folder="'.$folderID.'" AND mt_read="0"');
  411.             if($messages $this->ipbwi->ips_wrapper->DB->fetch()){
  412.                 // Save In Cache and Return
  413.                 $this->ipbwi->cache->save('numFolderUnreadPMs'$folderID$messages['messages']);
  414.                 return $messages['messages'];
  415.             }else{
  416.                 return false;
  417.             }
  418.         }
  419.         /**
  420.          * @desc            Returns number of PMs in a folder.
  421.          * @param    int        $folderID Folder ID
  422.          * @return    int        Number of PMs in Folder
  423.          * @author            Matthias Reuter
  424.          * @sample
  425.          *  <code>
  426.          *  $ipbwi->pm->numFolderPMs(55);
  427.          *  </code>
  428.          * @since            2.0
  429.          */
  430.         public function numFolderPMs($folderID){
  431.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->permissions->has('g_use_pm')){
  432.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  433.                 return false;
  434.             }
  435.             $this->ipbwi->ips_wrapper->DB->query('SELECT COUNT(mt_msg_id) AS messages FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_vid_folder="'.$folderID.'"');
  436.             if($messages $this->ipbwi->ips_wrapper->DB->fetch()){
  437.                 return $messages['messages'];
  438.             }else{
  439.                 return false;
  440.             }
  441.         }
  442.         /**
  443.          * @desc            Returns whether a member has blocked another member.
  444.          * @param    int        $by Member ID of receiver (the one who blocked)
  445.          * @param    int        $blocked Member ID of sender (the one who is blocked)
  446.          * @return    bool        Block Status
  447.          * @author            Matthias Reuter
  448.          * @sample
  449.          *  <code>
  450.          *  $ipbwi->pm->isBlocked(55,77);
  451.          *  </code>
  452.          * @since            2.0
  453.          */
  454.         public function isBlocked($by$blocked){
  455.             $this->ipbwi->ips_wrapper->DB->query('SELECT id, allow_msg FROM '.$this->ipbwi->board['sql_tbl_prefix'].'contacts WHERE contact_id="'.$blocked.'" AND member_id="'.$by.'"');
  456.             if($cando $this->ipbwi->ips_wrapper->DB->fetch()){
  457.                 if($cando['allow_msg'== 0){
  458.                     return true;
  459.                 }else{
  460.                     return false;
  461.                 }
  462.             }else{
  463.                 return false;
  464.             }
  465.         }
  466.         /**
  467.          * @desc            Deletes a Personal Message.
  468.          * @param    int        $messageID Message to be deleted
  469.          * @return    bool    true on success, otherwise false
  470.          * @author            Matthias Reuter
  471.          * @sample
  472.          *  <code>
  473.          *  $ipbwi->pm->delete(55);
  474.          *  </code>
  475.          * @since            2.0
  476.          */
  477.         public function delete($messageID){
  478.             if(!$this->member->isLoggedIn()){
  479.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  480.                 return false;
  481.             }
  482.             $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_id="'.$messageID.'"');
  483.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  484.                 $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_text WHERE msg_id="'.$row['mt_msg_id'].'" LIMIT 1');
  485.                 $this->ipbwi->ips_wrapper->DB->query('DELETE FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics WHERE mt_id="'.$messageID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  486.                 if($row['mt_vid_folder'!= 'unsent'){
  487.                     $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET msg_total = msg_total - 1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  488.                 }
  489.                 $this->ipbwi->cache->updatePM($this->ipbwi->member->myInfo['member_id']);
  490.                 return true;
  491.             }else{
  492.                 return false;
  493.             }
  494.         }
  495.         /**
  496.          * @desc            Saves a PM to the sent folder without sending it.
  497.          * @param    int        $toID Member ID to receive the message
  498.          * @param    string    $title Message title
  499.          * @param    string    $message Message body
  500.          * @param    array    $cc Array of ID for carbon copies (CC)
  501.          * @return    bool    true on success, otherwise false
  502.          * @author            Matthias Reuter
  503.          * @sample
  504.          *  <code>
  505.          *  $ipbwi->pm->save(5,'message title','message content,array('55','77'));
  506.          *  </code>
  507.          * @since            2.0
  508.          */
  509.         public function save($toID$title$message$cc array()){
  510.             // Similar to Write PM but code modified for saving
  511.             if(!$this->ipbwi->member->isLoggedIn()){
  512.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  513.                 return false;
  514.             }
  515.             if(!$toID){
  516.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmNoRecipient'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  517.                 return false;
  518.             }
  519.             if(!$title OR strlen($title2){
  520.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmTitle'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  521.                 return false;
  522.             }
  523.             if(!$message OR strlen($message2){
  524.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMessage'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  525.                 return false;
  526.             }
  527.             $sendto array();
  528.             $this->ipbwi->ips_wrapper->DB->query('SELECT m.name, m.id, m.view_pop, m.mgroup, m.email_pm, m.language, m.email, m.msg_total, g.g_use_pm, g.g_max_messages FROM '.$this->ipbwi->board['sql_tbl_prefix'].'groups g, '.$this->ipbwi->board['sql_tbl_prefix'].'members m WHERE m.id="'.intval($toID).'" AND g.g_id=m.mgroup');
  529.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  530.                 // Just incase
  531.                 if(!$row['id']){
  532.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  533.                     return false;
  534.                 }
  535.                 // Permissions Check
  536.                 if(!$this->ipbwi->permissions->has('g_use_pm',$row['id'])){
  537.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemDisAllowed'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  538.                     return false;
  539.                 }
  540.                 // Space Check
  541.                 $space $this->ipbwi->permissions->best('g_max_messages',$row['id']);
  542.                 if($row['msg_total'>= $space AND $space 0){
  543.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemFull'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  544.                     return false;
  545.                 }
  546.                 // Block Check
  547.                 if($this->isBlocked($this->ipbwi->member->myInfo['member_id']intval($toID))){
  548.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemBlocked'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  549.                     return false;
  550.                 }
  551.                 // CC Users
  552.                 $ccusers array();
  553.                 $max $this->ipbwi->permissions->has('g_max_mass_pm','',false);
  554.                 if($max){
  555.                     if(is_array($ccAND count($cc0){
  556.                         if(count($cc$max){
  557.                             $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmCClimit'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  558.                             return false;
  559.                         }
  560.                         foreach($cc AS $i){
  561.                             // Check CC user stuff
  562.                             // I really should clean up the code here, it uses alot of queries in some cases, which isn't good. Should really merge this with the main sending message code instead of replicating stuff for CCs.
  563.                             $this->ipbwi->ips_wrapper->DB->query('SELECT m.name, m.id, m.view_pop, m.mgroup, m.email_pm, m.language, m.email, m.msg_total, g.g_use_pm, g.g_max_messages FROM '.$this->ipbwi->board['sql_tbl_prefix'].'groups g, '.$this->ipbwi->board['sql_tbl_prefix'].'members m WHERE m.id="'.intval($toID).'" AND g.g_id=m.mgroup');
  564.                             if($ccrow $this->ipbwi->ips_wrapper->DB->fetch()){
  565.                                 // Permissions Check
  566.                                 if(!$this->ipbwi->permissions->hast('g_use_pm',$ccrow['id'])){
  567.                                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmRecDisallowed'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  568.                                     return false;
  569.                                 }
  570.                                 // Space Check
  571.                                 $space $this->ipbwi->permissions->best('g_max_messages',$ccrow['id']);
  572.                                 if($ccrow['msg_total'>= $space AND $space 0){
  573.                                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmRecFull'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  574.                                     return false;
  575.                                 }
  576.                                 // Block Check
  577.                                 if($this->isBlocked($this->ipbwi->member->myInfo['member_id']intval($ccrow['id']))){
  578.                                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmRecBlocked'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  579.                                     return false;
  580.                                 }
  581.                             }
  582.                             $ccusers[intval($i);
  583.                         }
  584.                     }
  585.                 }
  586.                 // IPB is a total pain in the butt, hence we need to now change the IDs to names, and stick some <br> in it.
  587.                 if(is_array($ccusersAND count($ccusers1){
  588.                     $ccsql implode('\n'$this->ipbwi->member->id2name($ccusers));
  589.                 }elseif(is_array($ccusersAND count($ccusers== '1'){
  590.                     $ccsql $this->ipbwi->member->id2name($ccusers['0']);
  591.                 }else{
  592.                     $ccsql '';
  593.                 }
  594.                 $msgtxtstring $this->ipbwi->ips_wrapper->DB->compile_db_insert_string(array('msg_author_id' => $this->ipbwi->member->myInfo['member_id'],
  595.                         'msg_date' => time(),
  596.                         'msg_post' => $this->ipbwi->ips_wrapper->remove_tags($message),
  597.                         'msg_sent_to_count' => count($ccusers1,
  598.                         'msg_deleted_count' => 0,
  599.                         'msg_post_key' => 0,
  600.                         'msg_cc_users' => $ccsql
  601.                         ));
  602.                 // Insert
  603.                 $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'message_text (' $msgtxtstring['FIELD_NAMES'') VALUES (' $msgtxtstring['FIELD_VALUES'')');
  604.                 $c $this->ipbwi->ips_wrapper->DB->get_insert_id();
  605.                 $DBstring $this->ipbwi->ips_wrapper->DB->compile_db_insert_string(array('mt_owner_id' => $this->ipbwi->member->myInfo['member_id'],
  606.                         'mt_date' => time(),
  607.                         'mt_read' => '0',
  608.                         'mt_title' => $title,
  609.                         'mt_from_id' => $this->ipbwi->member->myInfo['member_id'],
  610.                         'mt_vid_folder' => 'unsent',
  611.                         'mt_to_id' => $toID,
  612.                         'mt_tracking' => '0',
  613.                         'mt_msg_id' => $c
  614.                         ));
  615.                 $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics (' $DBstring['FIELD_NAMES'') VALUES (' $DBstring['FIELD_VALUES'')');
  616.                 $this->ipbwi->cache->updatePM($this->ipbwi->member->myInfo['member_id']);
  617.                 return true;
  618.             }else{
  619.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  620.                 return false;
  621.             }
  622.         }
  623.         /**
  624.          * @desc            Sends a PM.
  625.          * @param    int        $toID Member ID to receive the message
  626.          * @param    string    $title Message title
  627.          * @param    string    $message Message body
  628.          * @param    array    $cc Array of Display User Names for carbon copies (CC)
  629.          * @param    int        $sentfolder Default: 0=do not save message in Sent folder, 1=save message
  630.          * @return    bool    true on success, otherwise false
  631.          * @author            Matthias Reuter
  632.          * @sample
  633.          *  <code>
  634.          *  $ipbwi->pm->send(5,'message title','message content,array('55','77'),3);
  635.          *  </code>
  636.          * @since            2.0
  637.          */
  638.         public function send($toID$title$message$inviteUsers array()$sentfolder '0'){
  639.             if(!$this->ipbwi->member->isLoggedIn()){
  640.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  641.                 return false;
  642.             }
  643.             if(!$toID){
  644.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmNoRecipient'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  645.                 return false;
  646.             }
  647.             if($toID == $this->ipbwi->member->myInfo['member_id']){
  648.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmCantSendToSelf'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  649.                 return false;
  650.             }
  651.             if(!$title OR strlen($title2){
  652.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmTitle'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  653.                 return false;
  654.             }
  655.             if(!$message OR strlen($message2){
  656.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMessage'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  657.                 return false;
  658.             }
  659.             $this->ipbwi->ips_wrapper->DB->query('SELECT member_id FROM '.$this->ipbwi->board['sql_tbl_prefix'].'members WHERE member_id="'.intval($toID).'"');
  660.             if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  661.                 // Just incase
  662.                 if(!$row['member_id']){
  663.                     $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  664.                     return false;
  665.                 }
  666.                 // Actually send it
  667.                 $this->ipbwi->ips_wrapper->messenger->sendNewPersonalTopic($toID$this->ipbwi->member->myInfo['member_id']$inviteUsers$title$message);
  668.                 return true;
  669.             }else{
  670.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('pmMemNotExist'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  671.                 return false;
  672.             }
  673.         }
  674.         /**
  675.          * @desc            Returns information on a Personal Message.
  676.          * @param    int        $ID PM record ID
  677.          * @param    int        $markRead Default: 0=keep unread, 1=mark read
  678.          * @param    int        $convert Default: 1 convert BBCode to HTML
  679.          * @return    array    Information of a PM
  680.          * @author            Matthias Reuter
  681.          * @sample
  682.          *  <code>
  683.          *  $ipbwi->pm->info(5,true,false);
  684.          *  </code>
  685.          * @since            2.0
  686.          */
  687.         public function info($ID$markRead false$convert true){
  688.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->ipbwi->permissions->has('g_use_pm')){
  689.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  690.                 return false;
  691.             }
  692.             $this->ipbwi->ips_wrapper->DB->query('SELECT m.*, t.*, s.name, r.name AS recipient_name FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics t LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'message_text m ON (t.mt_msg_id=m.msg_id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members s ON (t.mt_from_id=s.id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members r ON (t.mt_to_id=r.id) WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_id="'.intval($ID).'"');
  693.             if($this->ipbwi->ips_wrapper->DB->getTotalRows()){
  694.                 if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  695.                     if($markRead AND !$row['mt_read']){
  696.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics SET mt_read="1", read_date="'.time().'" WHERE mt_msg_id="'.$ID.'" AND mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" LIMIT 1');
  697.                         if($row['vid'== 'in'){
  698.                             $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'members SET new_msg=new_msg-1 WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'" AND new_msg > 0');
  699.                         }
  700.                     }
  701.                     if($convert){
  702.                         $this->ipbwi->ips_wrapper->parser->parse_smilies    1;
  703.                         $this->ipbwi->ips_wrapper->parser->parse_html        0;
  704.                         $this->ipbwi->ips_wrapper->parser->parse_bbcode    1;
  705.                         $this->ipbwi->ips_wrapper->parser->strip_quotes    1;
  706.                         $this->ipbwi->ips_wrapper->parser->parse_nl2br        1;
  707.                         // make proper XHTML
  708.                         $row['msg_post_bbcode']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->html2bbcode($row['msg_post']));
  709.                         $row['msg_post']            $this->ipbwi->ips_wrapper->parser->pre_display_parse($row['msg_post']);
  710.                         $row['msg_post']            $this->ipbwi->properXHTML($row['msg_post']);
  711.                         $row['mt_title']            $this->ipbwi->properXHTML($row['mt_title']);
  712.                         $row['name']                $this->ipbwi->properXHTML($row['name']);
  713.                         $row['mt_vid_folder']        $this->ipbwi->properXHTML($row['mt_vid_folder']);
  714.                         $row['recipient_name']        $this->ipbwi->properXHTML($row['recipient_name']);
  715.                     }
  716.                     return $row;
  717.                 }
  718.             }else{
  719.                 return false;
  720.             }
  721.         }
  722.         /**
  723.          * @desc            Lists PMs in a folder.
  724.          * @param    string    $folder Keyname of Inbox folder, 'in', 'sent'
  725.          * @return    array    Information of PMs in folder.
  726.          * @author            Matthias Reuter
  727.          * @sample
  728.          *  <code>
  729.          *  $ipbwi->pm->getList(5);
  730.          *  </code>
  731.          * @since            2.0
  732.          */
  733.         public function getList($folder 'in'){
  734.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->ipbwi->permissions->has('g_use_pm')){
  735.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  736.                 return false;
  737.             }
  738.             $PMs array();
  739.             $this->ipbwi->ips_wrapper->DB->query('SELECT m.*, t.*, s.name, r.name AS recipient_name FROM '.$this->ipbwi->board['sql_tbl_prefix'].'message_topics t LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'message_text m ON (t.mt_msg_id=m.msg_id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members s ON (t.mt_from_id=s.id) LEFT JOIN '.$this->ipbwi->board['sql_tbl_prefix'].'members r ON (t.mt_to_id=r.id) WHERE mt_owner_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND mt_vid_folder="'.$folder.'" ORDER BY mt_date DESC');
  740.             if($this->ipbwi->ips_wrapper->DB->getTotalRows()){
  741.                 $this->ipbwi->ips_wrapper->parser->parse_smilies    1;
  742.                 $this->ipbwi->ips_wrapper->parser->parse_html        0;
  743.                 $this->ipbwi->ips_wrapper->parser->parse_bbcode    1;
  744.                 $this->ipbwi->ips_wrapper->parser->strip_quotes     1;
  745.                 $this->ipbwi->ips_wrapper->parser->parse_nl2br        1;
  746.                 while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  747.                     // make proper XHTML
  748.                     $row['msg_post_bbcode']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->html2bbcode($row['msg_post']));
  749.                     $row['msg_post']            $this->ipbwi->ips_wrapper->parser->pre_display_parse($row['msg_post']);
  750.                     $row['msg_post']            $this->ipbwi->properXHTML($row['msg_post']);
  751.                     $row['mt_title']            $this->ipbwi->properXHTML($row['mt_title']);
  752.                     $row['name']                $this->ipbwi->properXHTML($row['name']);
  753.                     $row['mt_vid_folder']        $this->ipbwi->properXHTML($row['mt_vid_folder']);
  754.                     $row['recipient_name']        $this->ipbwi->properXHTML($row['recipient_name']);
  755.                     $PMs[$row;
  756.                 }
  757.                 return $PMs;
  758.             }else{
  759.                 return false;
  760.             }
  761.         }
  762.         /**
  763.          * @desc            Gets number of new PMs.
  764.          * @return    int        New Unread Messages Count
  765.          * @author            Matthias Reuter
  766.          * @sample
  767.          *  <code>
  768.          *  $ipbwi->pm->numNewPMs();
  769.          *  </code>
  770.          * @since            2.0
  771.          */
  772.         public function numNewPMs(){
  773.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->ipbwi->permissions->has('g_use_pm')){
  774.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  775.                 return false;
  776.             }
  777.             $this->ipbwi->ips_wrapper->DB->query('SELECT new_msg FROM '.$this->ipbwi->board['sql_tbl_prefix'].'members WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  778.             if($messages $this->ipbwi->ips_wrapper->DB->fetch()){
  779.                 return (int)$messages['new_msg'];
  780.             }else{
  781.                 return false;
  782.             }
  783.         }
  784.         /**
  785.          * @desc            Gets total number of PMs.
  786.          * @return    int        Total Messages Count
  787.          * @author            Matthias Reuter
  788.          * @sample
  789.          *  <code>
  790.          *  $ipbwi->pm->numTotalPMs();
  791.          *  </code>
  792.          * @since            2.0
  793.          */
  794.         public function numTotalPMs(){
  795.             if(!$this->ipbwi->member->isLoggedIn(AND !$this->ipbwi->permissions->has('g_use_pm')){
  796.                 $this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('membersOnly'),'Located in file <strong>'.__FILE__.'</strong> at class <strong>'.__CLASS__.'</strong> in function <strong>'.__FUNCTION__.'</strong> on line #<strong>'.__LINE__.'</strong>');
  797.                 return false;
  798.             }
  799.             $this->ipbwi->ips_wrapper->DB->query('SELECT msg_total FROM '.$this->ipbwi->board['sql_tbl_prefix'].'members WHERE id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  800.             if($messages $this->ipbwi->ips_wrapper->DB->fetch()){
  801.                 return $messages['msg_total'];
  802.             }else{
  803.                 return false;
  804.             }
  805.         }
  806.         /**
  807.          * @desc            Blocks a contact.
  808.          * @param    int        $userID Member ID to be added
  809.          * @param    string    $description Description for the 'Buddy'
  810.          * @return    bool    true on success, otherwise false
  811.          * @author            Matthias Reuter
  812.          * @sample
  813.          *  <code>
  814.          *  $ipbwi->pm->blockContact(55,'do not bother me');
  815.          *  </code>
  816.          * @since            2.0
  817.          */
  818.         public function blockContact($userID$description false){
  819.             if($this->isLoggedIn()){
  820.                 // Check user exists
  821.                 if(!$userID OR !$this->info(intval($userID))){
  822.                     return false;
  823.                 }
  824.                 // o_O. Firstly check if there is already an entry.
  825.                 $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'contacts WHERE contact_id="'.intval($userID).'" AND member_id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  826.                 if($row $this->ipbwi->ips_wrapper->DB->fetch()){
  827.                     if($row['allow_msg'== '0' AND $row['contact_desc'== $description){
  828.                         // Clearly no point of doing anything.
  829.                         return true;
  830.                     }else{
  831.                         // Update record
  832.                         $this->ipbwi->ips_wrapper->DB->query('UPDATE '.$this->ipbwi->board['sql_tbl_prefix'].'contacts SET allow_msg="0", contact_desc="'.$description.'" WHERE contact_id="'.intval($userID).'" AND member_id="'.$this->ipbwi->member->myInfo['member_id'].'"');
  833.                         return true;
  834.                     }
  835.                 }else{
  836.                     // We can just add an entry because theres nothing there.
  837.                     $this->ipbwi->ips_wrapper->DB->query('INSERT INTO '.$this->ipbwi->board['sql_tbl_prefix'].'contacts VALUES ("", "'.intval($userID).'", "'.$this->ipbwi->member->myInfo['member_id'].'", "'.$this->id2name(intval($userID)).'", "1", "'.$description .'")');
  838.                     return true;
  839.                 }
  840.             }else{
  841.                 return false;
  842.             }
  843.         }
  844.         /**
  845.          * @desc            Returns blocked members information.
  846.          * @return    array    Blocked Members Information
  847.          * @author            Matthias Reuter
  848.          * @sample
  849.          *  <code>
  850.          *  $ipbwi->pm->blockedList();
  851.          *  </code>
  852.          * @since            2.0
  853.          */
  854.         public function blockedList(){
  855.             if($this->ipbwi->member->isLoggedIn()){
  856.                 $this->ipbwi->ips_wrapper->DB->query('SELECT contact_id, contact_desc, contact_name FROM '.$this->ipbwi->board['sql_tbl_prefix'].'contacts WHERE member_id="'.$this->ipbwi->member->myInfo['member_id'].'" AND allow_msg="0"');
  857.                 $blocked array();
  858.                 while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  859.                     $blocked[$row['contact_id']] $row;
  860.                 }
  861.                 return $blocked;
  862.             }else{
  863.                 return false;
  864.             }
  865.         }
  866.     }
  867. ?>

Documentation generated on Sat, 23 Oct 2010 23:36:04 +0200 by phpDocumentor 1.4.3