root/instantMessenger/files/lib/form/InstantMessengerForm.class.php @ 508

Revision 508, 8.0 kB (checked in by Tatzelwurm, 5 years ago)

Tippfehler in de-informal.xml beseitigt
Mögliche Behebung des Zeilenumbruch Problems

  • Property svn:mime-type set to text/plain
  • Property svn:executable set to *
Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/form/AbstractForm.class.php');
4require_once(WCF_DIR.'lib/data/InstantMessage/IM.class.php');
5require_once(WCF_DIR.'lib/form/MessageForm.class.php');
6require_once(WCF_DIR.'lib/data/user/UserProfile.class.php');
7
8/**
9 * Instant Messenger fÃŒr das WCF
10 * User können anderen Usern Kurznachrichten schicken
11 * User können wÀhlen ob sie IMs empfangen wollen, verweigert ein
12 * User den Empfang, erscheint ein entsprechender Hinweis.
13 * $LastChangedDate: 2008-04-13 23:33 (So, 13 April 2008) $
14 * @author              Robert "Tatzelwurm" Hempel
15 * @copyright   2007/2008 INSIDE das Hörspiel
16 * @license     GNU LGPL http://www.gnu.org/licenses/lgpl.txt
17 * @package             de.inside.wcf.instantMessenger
18 */
19
20class InstantMessengerForm extends MessageForm {
21        public $templateName = 'instantMessengerWrite';
22        public $sender;
23        public $recipient;
24        public $recipientID;
25        public $recipientArray = array();
26        public $errorRecipient;
27        public $subject;
28        public $text;
29        public $sendtime;
30        public $imID;
31        public $RecipientType = 0;
32
33        private $messagePreview = false;
34        public $validate = false;
35
36        /**
37         * @see Page::readParameters()
38         */
39        public function readParameters() {
40                $this->checkAccess();
41                parent::readParameters();
42                // get action
43                if (isset($_REQUEST['action']))         $this->action           = stringUtil::toLowerCase(escapeString($_REQUEST['action']));
44                // Falsche URLs abfangen
45                if (!isset($_REQUEST['action']) || ($this->action != 'forward' && $this->action != 'reply' && $this->action != 'new')) {
46                        require_once(WCF_DIR.'lib/system/exception/IllegalLinkException.class.php');
47                        throw new IllegalLinkException();
48                }
49                if (isset($_REQUEST['imID']))           $this->imID             = intval($_REQUEST['imID']);
50                if (isset($_REQUEST['userID']))         $this->recipientID      = intval($_REQUEST['userID']);
51        }
52
53        /**
54         * @see Form::readFormParameters()
55         */
56        public function readFormParameters() {
57                parent::readFormParameters();
58
59                if (isset($_POST['action']))            $this->action                   = StringUtil::toLowerCase(escapeString($_POST['action']));
60                if (isset($_POST['recipient']))         $this->recipient                = escapeString($_POST['recipient']);
61                if (isset($_POST['subject']))           $this->subject                  = escapeString($_POST['subject']);
62                if (isset($_POST['text']))                      $this->text                     = escapeString($_POST['text']);
63                if (isset($_POST['RecipientType'])) $this->RecipientType        = intval($_POST['RecipientType']);
64                if (!$this->RecipientType){
65                        $this->recipientArray = explode(',', escapeString($this->recipient));
66                        if (count($this->recipientArray) < 2) {
67                                $this->recipientArray = $this->recipient = escapeString($this->recipientArray[0]);
68                        }
69                }else{
70                        $this->recipient = $this->recipientArray = WCF::getLanguage()->get('wcf.acp.InstantMessenger.alleOnlineUser');
71                }
72        }
73       
74        /**
75         * @see Form::validate()
76         */
77        public function validate() {
78                $this->sender = WCF::getUser()->username;
79                if (!count($this->recipientArray) && !$this->recipient) {
80                        throw new UserInputException('recipient', 'empty');
81                }elseif (is_array($this->recipientArray) && $this->recipient != WCF::getLanguage()->get('wcf.acp.InstantMessenger.alleOnlineUser')){
82                        foreach ($this->recipientArray as $user) {
83                                $user = escapeString(StringUtil::trim($user));
84                                // Existiert User ?
85                                $reci = new UserProfile(null, null, $user);
86                                if (!$reci->userID) {
87                                        $this->errorRecipient = $user;
88                                        throw new UserInputException('recipient', 'notFound');
89                                }
90                                // Akzeptiert, nur Freunde, Ignoriert?
91                                $IM = new IM (null, $user);
92                                $fehler = $IM->permissionIM();
93                                if ($fehler) {
94                                        $this->errorRecipient = $user;
95                                        throw new UserInputException('recipient', $fehler);
96                                }
97                        }
98                }elseif (!is_array($this->recipientArray) && $this->recipient != WCF::getLanguage()->get('wcf.acp.InstantMessenger.alleOnlineUser')){
99                        // Existiert User ?
100                        $this->recipientArray = escapeString($this->recipientArray);
101                        $user = new UserProfile(null, null, $this->recipientArray);
102                        if (!$user->userID) {
103                                $this->errorRecipient = $this->recipientArray;
104                                throw new UserInputException('recipient', 'notFound');
105                        }
106                        // Akzeptiert, nur Freunde, Ignoriert?
107                        $IM = new IM (null, $this->recipientArray);
108                        $fehler = $IM->permissionIM();
109                        if ($fehler) {
110                                $this->errorRecipient = $this->recipientArray;
111                                throw new UserInputException('recipient', $fehler);
112                        }
113                }
114                if (empty($this->text)) {
115                        throw new UserInputException('text', 'empty');
116                }
117                $this->valid = true;
118        }
119       
120        /**
121         * Create the IM.
122         */
123        public function save() {
124                //Create new IM
125                if ($this->valid){
126                        if (is_array($this->recipientArray)){
127                                $this->recipient = array();
128                                $this->recipient = $this->recipientArray;
129                        }
130                        // Text vorbereiten
131                        require_once(WCF_DIR.'lib/data/message/bbcode/MessageParser.class.php');
132                        $parser = MessageParser::getInstance();
133                        $parser->setOutputType('text/html');
134                        // IM speichern
135                        $IM = new IM (WCF::getUser()->username, $this->recipient, $this->subject, $parser->parse($this->text, false, false, false, false));
136                        $IM->sendIM();
137                        // forward to IM page
138                        header('Location: index.php?page=InstantMessenger&action=send'.SID_ARG_1ST);
139                        exit;
140                }
141        }
142       
143        /**
144         * @see Page::readData()
145         */
146        public function readData() {
147                parent::readData();
148                if (!$_POST && $this->action == 'forward') {
149                        $IMData = WCF::getSession()->getVar('IMData');
150                        $IMDatas = $IMData[$this->imID];
151                        $this->recipient = $IMDatas['sender'];
152                        $this->subject = "Fw: ".$IMDatas['subject'];
153                        $this->text = "[quote=".$IMDatas['sender'].",'']".StringUtil::unescape($IMDatas['message'])."[/quote]";
154                        unset($IMData[$this->imID]);
155                }
156                if (!$_POST && $this->action == 'reply') {
157                        $IMData = WCF::getSession()->getVar('IMData');
158                        $IMDatas = $IMData[$this->imID];
159                        $this->recipient = $IMDatas['sender'];
160                        $this->subject = "Fw: ".$IMDatas['subject'];
161                        $this->text = "[quote=".$IMDatas['sender'].",'']".StringUtil::unescape($IMDatas['message'])."[/quote]";
162                        unset($IMData[$this->imID]);
163                }
164                if (!$_POST && $this->action == 'new') {
165                        $this->recipient = $this->subject = $this->text = '';
166                        if ($this->recipientID) {
167                                $reci = new user($this->recipientID);
168                                $this->recipient = $reci->username;
169                        }
170                }
171        }
172       
173        /**
174         * @see Page::assignVariables();
175         */
176        public function assignVariables() {
177                parent::assignVariables();
178
179                WCF::getTPL()->assign(array(
180                                'subject' => $this->subject,
181                                'text' => $this->text,
182                                'recipient' => $this->recipient,
183                                'RecipientType' => $this->RecipientType,
184                                'errorRecipient' => $this->errorRecipient,
185                                'sendtime' => $this->sendtime,
186                                'action' => $this->action,
187                                'imID' => $this->imID,
188                                'nutzeWYSIWYG' => WCF::getUser()->nutzeWYSIWYG,
189                                'canUseBBCodes' => WCF::getUser()->{$this->permissionType.'EnableBBCodes'},
190                ));
191        }
192
193        /**
194         * @see ViewablePost::getFormattedMessage()
195         */
196        protected function getFormattedMessage($text) {
197                // parse message
198                require_once(WCF_DIR.'lib/data/message/bbcode/MessageParser.class.php');
199                $parser = MessageParser::getInstance();
200                $parser->setOutputType('text/html');
201                return $parser->parse($text, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, !$this->messagePreview);
202        }
203       
204        public function checkAccess(){
205                // Ist IM eingeschaltet?
206                if (!INSTANTMESSENGER_AKTIV) {
207                        require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php');
208                        throw new NamedUserException(WCF::getLanguage()->get('wcf.instantmessenger.inactiv'));
209                }
210                // GÀste dÃŒrfen aus Prinzip nicht!
211                if (!WCF::getUser()->userID) {
212                        require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php');
213                        throw new PermissionDeniedException();
214                }
215                // Kann User/Gruppe an IM Teilnehmen?
216                if (!WCF::getUser()->getPermission('user.instantmessenger.canUseInstantMessenger') ||
217                        (!WCF::getUser()->userCanIM && !WCF::getUser()->onlyBuddyCanIM && !WCF::getUser()->adminCanIM)) {
218                        require_once(WCF_DIR.'lib/system/exception/PermissionDeniedException.class.php');
219                        throw new PermissionDeniedException();
220                }
221                return;
222        }
223       
224}
225
226?>
Note: See TracBrowser for help on using the browser.