-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.php
executable file
·100 lines (79 loc) · 3.42 KB
/
messages.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
<?php
require_once 'protected/core.php';
if (App::$user->isGuest) {
App::redirectTo('auth.php?login');
}
list($id, $action) = explode('/', $_SERVER['QUERY_STRING']);
//list($action, $param) = explode(':', $action);
if((int)$id == 0) {
$action = $id;
$id = 0;
} else {
$id = (int)$id;
}
$storage = new Message(App::$user->uid);
switch($action) {
case 'reply':
if($id != 0) {
if( ($msg = $storage->findById($id)) == false) {
App::error('messages', "Сообщение #$id не найдено");
} else {
$form = array(
'recipient'=>$msg->sender,
'title'=>'Re: ' . $msg->title,
// Сюда можно добавить цитирование сообщения
);
}
}
case 'send': // Отправить сообщение или вывести форму ввода сообещния
if(!isset($form))
$form = array();
// Имена полей, содержащие ошибки будут сохраняться здесь
$errornous = array();
if (App::isPost()) {
// Все поля заполнены, продолжаем проверку
// Убрать потенциально опасные теги. Однако, функция пропустит
// инструкции вроде "javascript:..."
$_POST['body'] = strip_tags_attributes($_POST['body'], '<a><p><ul><li><b><u>', 'href');
if (! $storage->check('body', $_POST['body'], 'messages/send')) {
$errornous[] = 'body';
App::error('messages/send', 'Слишком длинное сообщение. Разрешено не более 2000 символов');
} else {
$form['body'] = $_POST['body'];
}
if (! $storage->check('recipient', $_POST['recipient'], 'messages/send')) {
$errornous[] = 'recipient';
App::error('register', 'Введите допустимое имя учётной записи. '.
'Длина от 4 до 20 символов из набора a-z, A-Z, 0-9, ".", "_"');
} else {
$form['login'] = $_POST['login'];
}
App::notify('notify', array(
'message'=>"Сообщение отправлено"
));
goto list_msgs;
}
App::render('messages/send', array(
'users'=> User::listUsers(true),
'form'=>$form,
));
case 'read': // Прочесть сообщение
if( ($message = $storage->read($id)) != false) {
App::render('messages/read', array(
'msg'=>$message,
));
} else {
App::error('messages', 'Сообщения с таким ID не найдено');
};
// Отобразить список сообщений
case 'outgoing': // Только исходящие
$outgoing = true;
case '': // Показать только входящие
list_msgs:
$list = $storage->listMessages($outgoing);
App::render('messages/list', array(
'list'=>$list,
'empty'=>(! $list),
));
}
?>