This repository has been archived by the owner on Feb 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathboard.controller.php
435 lines (367 loc) · 11.2 KB
/
board.controller.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* @class boardController
* @author NAVER (developers@xpressengine.com)
* @brief board module Controller class
**/
class boardController extends board
{
/**
* @brief initialization
**/
function init()
{
}
/**
* @brief insert document
**/
function procBoardInsertDocument()
{
// check grant
if($this->module_info->module != "board")
{
return new Object(-1, "msg_invalid_request");
}
if(!$this->grant->write_document)
{
return new Object(-1, 'msg_not_permitted');
}
$logged_info = Context::get('logged_info');
// setup variables
$obj = Context::getRequestVars();
$obj->module_srl = $this->module_srl;
if($obj->is_notice!='Y'||!$this->grant->manager) $obj->is_notice = 'N';
$obj->commentStatus = $obj->comment_status;
settype($obj->title, "string");
if($obj->title == '') $obj->title = cut_str(strip_tags($obj->content),20,'...');
//setup dpcument title tp 'Untitled'
if($obj->title == '') $obj->title = 'Untitled';
// unset document style if the user is not the document manager
if(!$this->grant->manager)
{
unset($obj->title_color);
unset($obj->title_bold);
}
// generate document module model object
$oDocumentModel = getModel('document');
// generate document module의 controller object
$oDocumentController = getController('document');
// check if the document is existed
$oDocument = $oDocumentModel->getDocument($obj->document_srl, $this->grant->manager);
// if use anonymous is true
if($this->module_info->use_anonymous == 'Y')
{
$this->module_info->admin_mail = '';
$obj->notify_message = 'N';
$obj->member_srl = -1*$logged_info->member_srl;
$obj->email_address = $obj->homepage = $obj->user_id = '';
$obj->user_name = $obj->nick_name = 'anonymous';
$bAnonymous = true;
$oDocument->add('member_srl', $obj->member_srl);
}
else
{
$bAnonymous = false;
}
// update the document if it is existed
if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
{
if(!$oDocument->isGranted())
{
return new Object(-1,'msg_not_permitted');
}
if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
{
return new Object(-1,'msg_protect_content');
}
if(!$this->grant->manager)
{
// notice & document style same as before if not manager
$obj->is_notice = $oDocument->get('is_notice');
$obj->title_color = $oDocument->get('title_color');
$obj->title_bold = $oDocument->get('title_bold');
}
$output = $oDocumentController->updateDocument($oDocument, $obj);
$msg_code = 'success_updated';
// insert a new document otherwise
} else {
$output = $oDocumentController->insertDocument($obj, $bAnonymous);
$msg_code = 'success_registed';
$obj->document_srl = $output->get('document_srl');
// send an email to admin user
if($output->toBool() && $this->module_info->admin_mail)
{
$oMail = new Mail();
$oMail->setTitle($obj->title);
$oMail->setContent( sprintf("From : <a href=\"%s\">%s</a><br/>\r\n%s", getFullUrl('','document_srl',$obj->document_srl), getFullUrl('','document_srl',$obj->document_srl), $obj->content));
$oMail->setSender($obj->user_name, $obj->email_address);
$target_mail = explode(',',$this->module_info->admin_mail);
for($i=0;$i<count($target_mail);$i++)
{
$email_address = trim($target_mail[$i]);
if(!$email_address) continue;
$oMail->setReceiptor($email_address, $email_address);
$oMail->send();
}
}
}
// if there is an error
if(!$output->toBool())
{
return $output;
}
// return the results
$this->add('mid', Context::get('mid'));
$this->add('document_srl', $output->get('document_srl'));
// alert a message
$this->setMessage($msg_code);
}
/**
* @brief delete the document
**/
function procBoardDeleteDocument()
{
// get the document_srl
$document_srl = Context::get('document_srl');
// if the document is not existed
if(!$document_srl)
{
return $this->doError('msg_invalid_document');
}
$oDocumentModel = &getModel('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
// check protect content
if($this->module_info->protect_content=="Y" && $oDocument->get('comment_count')>0 && $this->grant->manager==false)
{
return new Object(-1, 'msg_protect_content');
}
// generate document module controller object
$oDocumentController = getController('document');
// delete the document
$output = $oDocumentController->deleteDocument($document_srl, $this->grant->manager);
if(!$output->toBool())
{
return $output;
}
// alert an message
$this->add('mid', Context::get('mid'));
$this->add('page', $output->get('page'));
$this->setMessage('success_deleted');
}
/**
* @brief vote
**/
function procBoardVoteDocument()
{
// generate document module controller object
$oDocumentController = getController('document');
$document_srl = Context::get('document_srl');
return $oDocumentController->updateVotedCount($document_srl);
}
/**
* @brief insert comments
**/
function procBoardInsertComment()
{
// check grant
if(!$this->grant->write_comment)
{
return new Object(-1, 'msg_not_permitted');
}
$logged_info = Context::get('logged_info');
// get the relevant data for inserting comment
$obj = Context::getRequestVars();
$obj->module_srl = $this->module_srl;
// check if the doument is existed
$oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($obj->document_srl);
if(!$oDocument->isExists())
{
return new Object(-1,'msg_not_permitted');
}
// For anonymous use, remove writer's information and notifying information
if($this->module_info->use_anonymous == 'Y')
{
$this->module_info->admin_mail = '';
$obj->notify_message = 'N';
$obj->member_srl = -1*$logged_info->member_srl;
$obj->email_address = $obj->homepage = $obj->user_id = '';
$obj->user_name = $obj->nick_name = 'anonymous';
$bAnonymous = true;
}
else
{
$bAnonymous = false;
}
// generate comment module model object
$oCommentModel = getModel('comment');
// generate comment module controller object
$oCommentController = getController('comment');
// check the comment is existed
// if the comment is not existed, then generate a new sequence
if(!$obj->comment_srl)
{
$obj->comment_srl = getNextSequence();
} else {
$comment = $oCommentModel->getComment($obj->comment_srl, $this->grant->manager);
}
// if comment_srl is not existed, then insert the comment
if($comment->comment_srl != $obj->comment_srl)
{
// parent_srl is existed
if($obj->parent_srl)
{
$parent_comment = $oCommentModel->getComment($obj->parent_srl);
if(!$parent_comment->comment_srl)
{
return new Object(-1, 'msg_invalid_request');
}
$output = $oCommentController->insertComment($obj, $bAnonymous);
// parent_srl is not existed
} else {
$output = $oCommentController->insertComment($obj, $bAnonymous);
}
// update the comment if it is not existed
} else {
// check the grant
if(!$comment->isGranted())
{
return new Object(-1,'msg_not_permitted');
}
$obj->parent_srl = $comment->parent_srl;
$output = $oCommentController->updateComment($obj, $this->grant->manager);
$comment_srl = $obj->comment_srl;
}
if(!$output->toBool())
{
return $output;
}
$this->setMessage('success_registed');
$this->add('mid', Context::get('mid'));
$this->add('document_srl', $obj->document_srl);
$this->add('comment_srl', $obj->comment_srl);
}
/**
* @brief delete the comment
**/
function procBoardDeleteComment()
{
// get the comment_srl
$comment_srl = Context::get('comment_srl');
if(!$comment_srl)
{
return $this->doError('msg_invalid_request');
}
// generate comment controller object
$oCommentController = getController('comment');
$output = $oCommentController->deleteComment($comment_srl, $this->grant->manager);
if(!$output->toBool())
{
return $output;
}
$this->add('mid', Context::get('mid'));
$this->add('page', Context::get('page'));
$this->add('document_srl', $output->get('document_srl'));
$this->setMessage('success_deleted');
}
/**
* @brief delete the tracjback
**/
function procBoardDeleteTrackback()
{
$trackback_srl = Context::get('trackback_srl');
// generate trackback module controller object
$oTrackbackController = getController('trackback');
if(!$oTrackbackController) return;
$output = $oTrackbackController->deleteTrackback($trackback_srl, $this->grant->manager);
if(!$output->toBool())
{
return $output;
}
$this->add('mid', Context::get('mid'));
$this->add('page', Context::get('page'));
$this->add('document_srl', $output->get('document_srl'));
$this->setMessage('success_deleted');
}
/**
* @brief check the password for document and comment
**/
function procBoardVerificationPassword()
{
// get the id number of the document and the comment
$password = Context::get('password');
$document_srl = Context::get('document_srl');
$comment_srl = Context::get('comment_srl');
$oMemberModel = getModel('member');
// if the comment exists
if($comment_srl)
{
// get the comment information
$oCommentModel = getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl);
if(!$oComment->isExists())
{
return new Object(-1, 'msg_invalid_request');
}
// compare the comment password and the user input password
if(!$oMemberModel->isValidPassword($oComment->get('password'),$password))
{
return new Object(-1, 'msg_invalid_password');
}
$oComment->setGrant();
} else {
// get the document information
$oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists())
{
return new Object(-1, 'msg_invalid_request');
}
// compare the document password and the user input password
if(!$oMemberModel->isValidPassword($oDocument->get('password'),$password))
{
return new Object(-1, 'msg_invalid_password');
}
$oDocument->setGrant();
}
}
/**
* @brief the trigger for displaying 'view document' link when click the user ID
**/
function triggerMemberMenu(&$obj)
{
$member_srl = Context::get('target_srl');
$mid = Context::get('cur_mid');
if(!$member_srl || !$mid)
{
return new Object();
}
$logged_info = Context::get('logged_info');
// get the module information
$oModuleModel = getModel('module');
$columnList = array('module');
$cur_module_info = $oModuleModel->getModuleInfoByMid($mid, 0, $columnList);
if($cur_module_info->module != 'board')
{
return new Object();
}
// get the member information
if($member_srl == $logged_info->member_srl)
{
$member_info = $logged_info;
} else {
$oMemberModel = getModel('member');
$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
}
if(!$member_info->user_id)
{
return new Object();
}
//search
$url = getUrl('','mid',$mid,'search_target','nick_name','search_keyword',$member_info->nick_name);
$oMemberController = getController('member');
$oMemberController->addMemberPopupMenu($url, 'cmd_view_own_document', '');
return new Object();
}
}