This repository has been archived by the owner on Dec 22, 2020. It is now read-only.
/
ModulePMReader.php
executable file
·142 lines (117 loc) · 4.48 KB
/
ModulePMReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
/**
* TYPOlight webCMS
* Copyright (C) 2005 Leo Feyer
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at http://www.gnu.org/licenses/.
*
* PHP version 5
* @copyright Andreas Schempp 2009
* @author Andreas Schempp <andreas@schempp.ch>
* @license http://opensource.org/licenses/lgpl-3.0.html
*/
/**
* class ModulePMReader
* Displays a private message
*/
class ModulePMReader extends ModulePM
{
/**
* Tempalte
*/
protected $strTemplate = 'mod_pm_reader';
/**
* Display wildcard text in backend
*/
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### PRIVATE MESSAGES READER ###';
return $objTemplate->parse();
}
$this->import('FrontendUser', 'User');
if (!$this->User->id || !$this->Input->get('message'))
return '';
return parent::generate();
}
/**
* Generate module
*/
protected function compile()
{
$objMessage = $this->Database->prepare("SELECT * FROM tl_pm WHERE tl_pm.id=?")
->limit(1)
->execute($this->Input->get('message'));
if (!$objMessage->numRows)
{
$this->Template = new FrontendTemplate('mod_message');
$this->Template->mclass = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['MSC']['pm_notfound'];
return;
}
// Check that current user is sender or recipient
if ($objMessage->sender != $this->User->id && $objMessage->recipient != $this->User->id)
{
$this->Template = new FrontendTemplate('mod_message');
$this->Template->mclass = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['ERR']['foreignMessage'];
return;
}
// Fetch member names for later use
$arrMembers = $this->generateRecipientNames();
// Update status if user is recipient
if ($objMessage->recipient == $this->User->id)
{
$this->Database->prepare("UPDATE tl_pm SET status=? WHERE status=? AND id=?")
->execute(1, 0, $this->Input->get('message'));
}
if ($this->Input->post('FORM_SUBMIT') == 'tl_pm_delete')
{
if ($this->User->id == $objMessage->sender)
$strField = 'senderDeleted';
elseif ($this->User->id == $objMessage->recipient)
$strField = 'recipientDeleted';
else
throw new Exception('Trying to delete a foreign message.');
$this->Database->prepare("UPDATE tl_pm SET " . $strField . "=? WHERE id=?")
->execute(1, $this->Input->post('pm_id'));
$arrPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
->limit(1)
->execute($this->pmJumpToList)
->fetchAssoc();
$this->redirect($this->generateFrontendUrl($arrPage));
}
$arrPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
->limit(1)
->execute($this->pmJumpToWriter)
->fetchAssoc();
$this->loadLanguageFile('tl_pm');
$this->Template->label_sender = $GLOBALS['TL_LANG']['tl_pm']['sender'][0];
$this->Template->label_recipient = $GLOBALS['TL_LANG']['tl_pm']['recipient'][0];
$this->Template->label_subject = $GLOBALS['TL_LANG']['tl_pm']['subject'][0];
$this->Template->label_message = $GLOBALS['TL_LANG']['tl_pm']['message'][0];
$this->Template->label_reply = $GLOBALS['TL_LANG']['tl_pm']['reply'];
$this->Template->label_delete = $GLOBALS['TL_LANG']['tl_pm']['delete'];
$this->Template->actionReply = $this->generateFrontendUrl($arrPage, '/reply/' . $this->Input->get('message'));
$this->Template->actionDelete = $this->Environment->request;
$this->Template->pm_id = $objMessage->id;
$this->Template->sender = $arrMembers[$objMessage->sender];
$this->Template->recipient = $arrMembers[$objMessage->recipient];
$this->Template->subject = $objMessage->subject;
$this->Template->message = nl2br($objMessage->message);
}
}