| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/data/message/pm/PMEditor.class.php'); |
|---|
| 3 | |
|---|
| 4 | /** |
|---|
| 5 | * |
|---|
| 6 | * @author Tatzelwurm |
|---|
| 7 | * @copyright 2007 INSIDE das Hörspiel |
|---|
| 8 | * @package de.inside.wcf.instantmessenger |
|---|
| 9 | */ |
|---|
| 10 | class IM { |
|---|
| 11 | |
|---|
| 12 | protected $sender; |
|---|
| 13 | protected $senderID; |
|---|
| 14 | protected $recipient; |
|---|
| 15 | protected $recipientID; |
|---|
| 16 | protected $subject; |
|---|
| 17 | protected $message; |
|---|
| 18 | protected $imID; |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Constructs a new IM object. |
|---|
| 23 | */ |
|---|
| 24 | public function __construct($sender = null, $recipient = null, $subject = null, $message = null, $imID = null) { |
|---|
| 25 | if (empty($sender)) $sender = WCF::getUser()->username; |
|---|
| 26 | $this->setSender($sender); |
|---|
| 27 | $this->setRecipient($recipient); |
|---|
| 28 | $this->setSubject($subject); |
|---|
| 29 | $this->setMessage($message); |
|---|
| 30 | if (!empty($imID)) $this->addID($imID); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Sets the sender of this IM. |
|---|
| 35 | * |
|---|
| 36 | * @param mixed $from |
|---|
| 37 | */ |
|---|
| 38 | public function setSender($sender) { |
|---|
| 39 | $this->sender = $sender; |
|---|
| 40 | $sende = new UserSession(null, null, $sender); |
|---|
| 41 | $this->senderID = $sende->userID; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | /** |
|---|
| 45 | * Gets the sender of this IM. |
|---|
| 46 | * |
|---|
| 47 | * @return string (Username) |
|---|
| 48 | */ |
|---|
| 49 | public function getSender() { |
|---|
| 50 | return $this->sender; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Sets the recipient(s) of this IM. |
|---|
| 55 | * |
|---|
| 56 | * @param string/array $recipient |
|---|
| 57 | */ |
|---|
| 58 | public function setRecipient($recipient) { |
|---|
| 59 | if (is_array($recipient)) { |
|---|
| 60 | $this->recipientID = $this->recipient = array(); |
|---|
| 61 | foreach($recipient as $name) { |
|---|
| 62 | $recipi = new UserSession(null, null, $name); |
|---|
| 63 | $this->recipientID[] .= $recipi->userID; |
|---|
| 64 | $this->recipient[] .= $name; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | else |
|---|
| 68 | { |
|---|
| 69 | $recipi = new UserSession(null, null, $recipient); |
|---|
| 70 | $this->recipientID = $recipi->userID; |
|---|
| 71 | $this->recipient = $recipient; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * Gets the recipient(s) of this IM. |
|---|
| 77 | * |
|---|
| 78 | * @return mixed |
|---|
| 79 | */ |
|---|
| 80 | public function getRecipient() { |
|---|
| 81 | return $this->recipient; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Sets the subject of this IM. |
|---|
| 86 | * |
|---|
| 87 | * @param string $subject |
|---|
| 88 | */ |
|---|
| 89 | public function setSubject($subject) { |
|---|
| 90 | $this->subject = $subject; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * Returns the subject of this IM. |
|---|
| 95 | * |
|---|
| 96 | * @return string |
|---|
| 97 | */ |
|---|
| 98 | public function getSubject() { |
|---|
| 99 | return $this->subject; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | /** |
|---|
| 103 | * Sets the message of this IM. |
|---|
| 104 | * |
|---|
| 105 | * @param string $message |
|---|
| 106 | */ |
|---|
| 107 | public function setMessage($message) { |
|---|
| 108 | $this->message = $message; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Returns the message of this IM. |
|---|
| 113 | * |
|---|
| 114 | * @return string |
|---|
| 115 | */ |
|---|
| 116 | public function getMessage() { |
|---|
| 117 | return $this->message; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /** |
|---|
| 121 | * Sets the ID of this IM. |
|---|
| 122 | * |
|---|
| 123 | * @param integer $imID |
|---|
| 124 | */ |
|---|
| 125 | public function addID($imID) { |
|---|
| 126 | $this->imID = $imID; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * IM Senden |
|---|
| 131 | * |
|---|
| 132 | * benötigt: |
|---|
| 133 | * recipientID (auch als Array), |
|---|
| 134 | * senderID (integer) |
|---|
| 135 | * subject (string) |
|---|
| 136 | * message (string) |
|---|
| 137 | */ |
|---|
| 138 | public function sendIM(){ |
|---|
| 139 | // an alle Onlineuser schicken |
|---|
| 140 | if (!is_array($this->recipientID) && $this->recipient == WCF::getLanguage()->get('wcf.acp.InstantMessenger.alleOnlineUser')) { |
|---|
| 141 | // User Online Liste holen |
|---|
| 142 | require_once(WCF_DIR.'lib/data/user/usersOnline/UsersOnlineList.class.php'); |
|---|
| 143 | $usersOnlineList = new UsersOnlineList('', true); |
|---|
| 144 | $usersOnlineList->renderOnlineList(); |
|---|
| 145 | foreach($usersOnlineList->usersOnline as $arrayID => $userName) { |
|---|
| 146 | if ($userName['userID'] != $this->senderID){ |
|---|
| 147 | $this->insertIM($this->senderID, $userName['userID'], $this->subject, $this->message); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | return; |
|---|
| 151 | } |
|---|
| 152 | // an mehrere User schicken |
|---|
| 153 | if (is_array($this->recipientID)) { |
|---|
| 154 | foreach($this->recipientID as $id) { |
|---|
| 155 | $this->insertIM($this->senderID, $id, $this->subject, $this->message); |
|---|
| 156 | } |
|---|
| 157 | return; |
|---|
| 158 | // an einen einzigen User |
|---|
| 159 | } elseif ($this->recipientID) { |
|---|
| 160 | $this->insertIM($this->senderID, $this->recipientID, $this->subject, $this->message); |
|---|
| 161 | return; |
|---|
| 162 | } |
|---|
| 163 | // Versand erfolgt |
|---|
| 164 | return; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | /** |
|---|
| 168 | * Schreibt Sender, EmpfÀnger, Nachricht und Zeit in die DB |
|---|
| 169 | * @param integer $senderID |
|---|
| 170 | * @param integer $recipientID |
|---|
| 171 | * @param varchar $subject |
|---|
| 172 | * @param text $message |
|---|
| 173 | * |
|---|
| 174 | */ |
|---|
| 175 | public function insertIM($senderID, $recipientID, $subject, $message){ |
|---|
| 176 | $sql = "INSERT INTO `wcf".WCF_N."_im` |
|---|
| 177 | (`imID`,`senderid`,`recipientid`,`subject`,`message`,`sendtime`) |
|---|
| 178 | VALUES ('', |
|---|
| 179 | '" . intval($senderID) . "', |
|---|
| 180 | '" . intval($recipientID) . "', |
|---|
| 181 | '" . escapeString($subject) . "', |
|---|
| 182 | '" . escapeString($message) . "', |
|---|
| 183 | '" . TIME_NOW . "')"; |
|---|
| 184 | WCF::getDB()->sendQuery($sql); |
|---|
| 185 | return; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | /** |
|---|
| 189 | * Liest erste ungelesene IM des aktuellen Users aus der DB |
|---|
| 190 | * |
|---|
| 191 | */ |
|---|
| 192 | public static function getFirstIM(){ |
|---|
| 193 | $sql = "SELECT * FROM `wcf".WCF_N."_im` |
|---|
| 194 | WHERE `recipientID` ='" . WCF::getUser()->userID . "' |
|---|
| 195 | ORDER BY `sendtime` |
|---|
| 196 | LIMIT 1"; |
|---|
| 197 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 198 | $firstIM = WCF::getDB()->fetchArray($result); |
|---|
| 199 | return $firstIM; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | /** |
|---|
| 203 | * ZÀhlt ungelesene IM des aktuellen Users |
|---|
| 204 | * |
|---|
| 205 | */ |
|---|
| 206 | public static function countNewIM(){ |
|---|
| 207 | $sql = "SELECT COUNT(`imID`) |
|---|
| 208 | AS ims |
|---|
| 209 | FROM wcf".WCF_N."_im |
|---|
| 210 | WHERE `recipientID` = '" . WCF::getUser()->userID . "'"; |
|---|
| 211 | $row = WCF::getDB()->getFirstRow($sql); |
|---|
| 212 | return $row['ims']; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | /** |
|---|
| 216 | * Löscht gelesene IM |
|---|
| 217 | * |
|---|
| 218 | */ |
|---|
| 219 | public function deleteIM($imID){ |
|---|
| 220 | $sql = "DELETE FROM `wcf".WCF_N."_im` |
|---|
| 221 | WHERE `imID` ='" . $imID . "'"; |
|---|
| 222 | WCF::getDB()->sendQuery($sql); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | /** |
|---|
| 226 | * IM Berechtigung ÃŒberprÃŒfen |
|---|
| 227 | * |
|---|
| 228 | */ |
|---|
| 229 | public function permissionIM(){ |
|---|
| 230 | $permiss = new UserSession($this->recipientID); |
|---|
| 231 | // Kann EmpfÀnger IM nutzen? |
|---|
| 232 | if (!$permiss->getPermission('user.board.instantmessenger.canUseInstantMessenger')) { |
|---|
| 233 | return 'canNotUseIM'; |
|---|
| 234 | } |
|---|
| 235 | // Sender wird ignoriert? |
|---|
| 236 | if ($permiss->ignoredUser){ |
|---|
| 237 | return 'ignoresYou'; |
|---|
| 238 | } |
|---|
| 239 | // Akzeptiert EmpfÀnger IMs von Freunden ? |
|---|
| 240 | if (!$permiss->userCanIM){ |
|---|
| 241 | if ($permiss->onlyBuddyCanIM && !$permiss->buddy){ |
|---|
| 242 | return 'onlyAcceptsIMFromBuddies'; |
|---|
| 243 | } |
|---|
| 244 | return 'wantNoIM'; |
|---|
| 245 | } |
|---|
| 246 | return; // alles OK |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | ?> |
|---|