-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification.controller.php
More file actions
511 lines (438 loc) · 16.2 KB
/
notification.controller.php
File metadata and controls
511 lines (438 loc) · 16.2 KB
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<?php
/**
* vi:set sw=4 ts=4 noexpandtab fileencoding=utf8:
* @class notificationController
* @author contact@nurigo.net
* @brief notificationController
*/
class notificationController extends notification
{
/**
* send SMS
*/
function sendMobileMessage($recipientNumber, $senderNumber, $message, &$config)
{
$oTextmessageController = &getController('textmessage');
if(!$oTextmessageController) return;
if($config->sms_method == 2 && mb_strlen($message) > 89) $args->type = "lms";
if($config->sms_method == 3)
{
$args->type = "ata";
$args->sender_key = $config->sender_key;
$args->template_code = $config->template_code;
}
$args->recipient_no = $recipientNumber;
$args->sender_no = $senderNumber;
$args->content = $message;
$output = $oTextmessageController->sendMessage($args);
if(!$output->toBool()) return $output;
}
/**
* send email
*/
function sendMailMessage($title, $message, $recipientName, $recipientEmailAddress, $senderName, $senderEmailAddress)
{
$oMail = new Mail();
$oMail->setTitle($title);
$oMail->setContent($message);
$oMail->setSender($senderName, $senderEmailAddress);
$oMail->setReceiptor($recipientName, $recipientEmailAddress);
$oMail->send();
}
/**
* get phone number from authentication module's table.
*/
function getRecipientNumberFromAuthentication($member_srl)
{
$oAuthenticationModel = &getModel('authentication');
if(!$oAuthenticationModel) return;
$authinfo = $oAuthenticationModel->getAuthenticationMember($member_srl);
if($authinfo) return $authinfo->clue;
}
/**
* get writer's phone number
*/
function getRecipientNumberForWriter(&$member_info, &$oDocument, &$config)
{
// get the references of modules' instances
$oNotificationModel = &getModel('notification');
// search from member data fields
$phone_number = array();
if(isset($config->cellphone_fieldname) && $member_info)
{
$phone_number['member'] = $oNotificationModel->getConfigValue($member_info, $config->cellphone_fieldname, 'tel');
}
// search from authentication module table.
if($config->use_authdata=='Y' && $member_info)
{
$phone_number['auth'] = $this->getRecipientNumberFromAuthentication($member_info->member_srl);
}
// search from document's extra vars
if($config->use_extravar)
{
$return_value = $oDocument->getExtraValue($config->use_extravar);
if(is_array($return_value))
{
$phone_number['use_extravar'] = $return_value[0].$return_value[1].$return_value[2];
}
else if(is_array($return_value) && count($return_value) === 1)
{
$phone_number['use_extravar'] = $return_value[0];
}
else
{
$phone_number['use_extravar'] = $return_value;
}
}
return $phone_number;
}
/**
* get upper replier's phone number
*/
function getRecipientNumberForUpperReplier(&$member_info, &$config)
{
// get the references of modules' instances
$oNotificationModel = &getModel('notification');
// search from member data fields
if(isset($config->cellphone_fieldname) && $member_info && $member_info->member_srl)
{
return $oNotificationModel->getConfigValue($member_info, $config->cellphone_fieldname, 'tel');
}
// search from authentication module table.
if($config->use_authdata=='Y' && $member_info && $member_info->member_srl)
{
return $this->getRecipientNumberFromAuthentication($member_info->member_srl);
}
return NULL;
}
/**
* get writer's email address
*/
function getEmailAddressForWriter(&$member_info, &$oDocument, &$config)
{
$emailAddress = NULL;
if($member_info) $emailAddress = $member_info->email_address;
// search from document's extra vars
if($config->use_extravar_email)
{
$emailAddress = $oDocument->getExtraValue($config->use_extravar_email);
}
return $emailAddress;
}
/**
* get upper replier's email address
*/
function getEmailAddressForUpperReplier(&$upperReplier)
{
$emailAddress = NULL;
if($member_info) $emailAddress = $member_info->email_address;
if(!$emailAddress) $emailAddress = $upperReplier->email_address;
return $emailAddress;
}
/**
* get writer's nick name
*/
function getWriterNickName(&$member_info, &$oDocument)
{
$nickName = NULL;
if($member_info) $nickName = $member_info->nick_name;
if(!$nickName) $nickName = $oDocument->getNickName();
return $nickName;
}
/**
* get writer's nick name
*/
function getNickNameForUpperReplier(&$upperReplier, &$oDocument)
{
$nickName = NULL;
if($member_info) $nickName = $member_info->nick_name;
if(!$nickName) $nickName = $oDocument->getNickName();
return $nickName;
}
/**
* @param $receiver contains the member information. (like a logged_info)
*/
function sendMessages($recipientNumber, $senderNumber
, $recipientEmailAddress, $recipientName, $senderEmailAddress, $senderName
, $mobileContent, $mailContent, $title, &$config, &$commentInfo)
{
// SMS
if(!is_array($recipientNumber)) $recipientNumber = array($recipientNumber);
if(in_array($config->sending_method,array('1','2')))
{
foreach($recipientNumber as $phoneNumber)
{
if(!$phoneNumber) continue;
$this->sendMobileMessage($phoneNumber, $senderNumber, $mobileContent, $config);
}
}
// MAIL
if(!is_array($recipientEmailAddress)) $recipientEmailAddress = array($recipientEmailAddress);
if(in_array($config->sending_method,array('1','3')))
{
foreach($recipientEmailAddress as $emailAddress)
{
$this->sendMailMessage($title, $mailContent, $recipientName, $emailAddress, $senderName, $senderEmailAddress);
}
}
}
/**
* @return TRUE(notification required) or FALSE(notification not required)
*/
function checkNotificationRequired(&$commentInfo, &$oDocument, &$config)
{
$notificationRequired = TRUE;
// 1. 게시물의 알림이 체크되어 있으면 발송
if($oDocument->useNotify())
{
$notificationRequired = TRUE;
}
else
{
$notificationRequired = FALSE;
}
// 2. 역알림 사용이면서 현재 comment의 notify_message가 'Y'이면 발송
if($config->reverse_notify == 'Y')
{
if($commentInfo->notify_message == 'Y')
{
$notificationRequired = TRUE;
}
else
{
$notificationRequired = FALSE;
}
}
// 3. force_notify설정이 Y이면 1, 2 무시하고 무조건 보냄
if($config->force_notify == 'Y') $notificationRequired = TRUE;
return $notificationRequired;
}
/**
* check for sending to writer
*/
function checkNotificationRequiredForWriter(&$commentInfo, &$oDocument, &$config)
{
// check basical things.
$notificationRequired = $this->checkNotificationRequired($commentInfo, $oDocument, $config);
debugPrint($notificationRequired);
// do not send messages if the writer and the replier is the same person.
if($commentInfo->member_srl != 0 && $oDocument->get('member_srl') == $commentInfo->member_srl)
{
$notificationRequired = FALSE;
}
return $notificationRequired;
}
/**
* @return upper comment information.
*/
function getUpperComment(&$commentInfo)
{
if(!$commentInfo->parent_srl) return NULL;
// get the references of module MVC instances.
$oCommentModel = &getModel('comment');
// get upper replier information using parent_srl.
return $oCommentModel->getComment($commentInfo->parent_srl);
}
/**
* @return the member_info object of the upper replier.
*/
function getCommentMemberInfo(&$commentInfo)
{
$memberInfo = NULL;
// get member information.
$oMemberModel = &getModel('member');
$member_srl = $commentInfo->getMemberSrl();
if($member_srl) $memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
// for comment from guest
if(!$memberInfo)
{
$memberInfo = new stdClass();
$memberInfo->nick_name = $commentInfo->nick_name;
$memberInfo->email_address = $commentInfo->email_address;
}
return $memberInfo;
}
/**
* @return the member_info object of the upper replier.
*/
function getUpperReplier(&$commentInfo)
{
if(!$commentInfo->parent_srl) return NULL;
// get the references of module MVC instances.
$oMemberModel = &getModel('member');
// get upper comment
$upperComment = $this->getUpperComment($commentInfo);
if(!$upperComment) return NULL;
// get member information.
$member_srl = $upperComment->getMemberSrl();
$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
return $memberInfo;
}
/**
* check for sending to upper replier
*/
function checkNotificationRequiredForUpperReplier(&$commentInfo, &$upperComment, &$oDocument, &$config)
{
if(!$commentInfo->parent_srl) return FALSE;
// check notification required.
$notificationRequired = $this->checkNotificationRequired($commentInfo, $oDocument, $config);
// 상위댓글자가 본인이면 보내지 않음
if($upperComment->member_srl == $commentInfo->member_srl) $notificationRequired = FALSE;
// 게시자와 상위댓글자가 같으면 보내지 않음.(중복으로 보내지 않음)
if($oDocument->getMemberSrl() == $commentInfo->member_srl) $notificationRequired = FALSE;
return $notificationRequired;
}
/**
* send to administrator
*/
function sendToAdministrator($mobileContent, $mailContent, $title, &$commentInfo, &$config)
{
if(!$config->admin_phones) return;
$recipientNumber = explode(',', $config->admin_phones);
$senderNumber = $config->sender_phone;
$recipientEmailAddress = explode(',', $config->admin_emails);
$senderEmailAddress = $config->email_sender_address;
$senderName = $config->email_sender_name;
if(!$senderEmailAddress) $senderEmailAddress = $commentInfo->email_address;
if(!$senderName) $senderName = $commentInfo->nick_name;
if(!$senderEmailAddress) $senderEmailAddress = $recipientEmailAddress;
$tmpObj->article_url = getFullUrl('','document_srl', $commentInfo->document_srl);
$tmpContent = $this->mergeKeywords($mailContent, $tmpObj);
$tmpMessage = $this->mergeKeywords($mobileContent, $tmpObj);
$this->sendMessages($recipientNumber, $senderNumber
, $recipientEmailAddress, NULL, $senderEmailAddress, $senderName
, $tmpMessage, $tmpContent, $title, $config, $commentInfo);
}
/**
* sending to writer
*/
function sendToWriter($mobileContent, $mailContent, $title, &$commentInfo, &$config)
{
// get the references of module MVC instances.
$oMemberModel = &getModel('member');
$oDocumentModel = &getModel('document');
// get document info.
$oDocument = $oDocumentModel->getDocument($commentInfo->document_srl);
// writer's member_srl
$writer_member_srl = $oDocument->getMemberSrl();
// get member_info
$member_info = $oMemberModel->getMemberInfoByMemberSrl($writer_member_srl);
$recipientNumberArray = $this->getRecipientNumberForWriter($member_info, $oDocument, $config);
$senderNumber = $config->sender_phone;
$recipientEmailAddress = $this->getEmailAddressForWriter($member_info, $oDocument, $config);
$recipientName = $this->getWriterNickName($member_info, $oDocument);
$senderEmailAddress = $config->email_sender_address;
$senderName = $config->email_sender_name;
if(!$senderEmailAddress) $senderEmailAddress = $commentInfo->email_address;
if(!$senderName) $senderName = $commentInfo->nick_name;
if(!$senderEmailAddress) $senderEmailAddress = $recipientEmailAddress;
if(!$senderName) $senderName = $recipientName;
$tmpObj = new stdClass();
$tmpObj->article_url = getFullUrl('','document_srl', $commentInfo->document_srl);
$tmpContent = $this->mergeKeywords($mailContent, $tmpObj);
$tmpMessage = $this->mergeKeywords($mobileContent, $tmpObj);
if(count($recipientNumberArray) > 0)
{
if(count($recipientNumberArray) >= 2 && $config->frist_number !== 'notuse' && $config->frist_number)
{
$this->sendMessages($recipientNumberArray[$config->frist_number], $senderNumber, $recipientEmailAddress, $recipientName, $senderEmailAddress, $senderName, $tmpMessage, $tmpContent, $title, $config, $commentInfo);
}
else
{
foreach($recipientNumberArray as $number)
{
$this->sendMessages($number, $senderNumber, $recipientEmailAddress, $recipientName, $senderEmailAddress, $senderName, $tmpMessage, $tmpContent, $title, $config, $commentInfo);
}
}
}
}
/**
* send to upper repliers
*/
function sendToUpperReplier($upperComment, $mobileContent, $mailContent, $title, &$commentInfo, &$config)
{
// get the references of module MVC instances.
$oMemberModel = &getModel('member');
// get member_info
$member_info = $oMemberModel->getMemberInfoByMemberSrl($upperComment->member_srl);
$upperReplier = $this->getCommentMemberInfo($upperComment);
$recipientNumber = $this->getRecipientNumberForUpperReplier($member_info, $config);
$senderNumber = $config->sender_phone;
$recipientEmailAddress = $upperReplier->email_address;
$recipientName = $upperReplier->nick_name;
if(!$senderEmailAddress) $senderEmailAddress = $commentInfo->email_address;
if(!$senderName) $senderName = $commentInfo->nick_name;
$senderEmailAddress = $config->email_sender_address;
$senderName = $config->email_sender_name;
if(!$senderEmailAddress) $senderEmailAddress = $recipientEmailAddress;
if(!$senderName) $senderName = $recipientName;
$tmpObj->article_url = getFullUrl('','document_srl', $commentInfo->document_srl).'#comment_'.$commentInfo->parent_srl;
$tmpContent = $this->mergeKeywords($mailContent, $tmpObj);
$tmpMessage = $this->mergeKeywords($mobileContent, $tmpObj);
$this->sendMessages($recipientNumber, $senderNumber
, $recipientEmailAddress, $recipientName, $senderEmailAddress, $senderName
, $tmpMessage, $tmpContent, $title, $config, $commentInfo);
}
/**
* @param $config is an object which consists of sending_method, sender_phone, admin_phones, admin_emails, use_authdata, reverse_notify, and etc.
* @param $commentInfo is an object which consists of comment_srl, content, parent_srl, user_id, nick_name, email_address, and etc.
* @param $sender is an object which includes nick_name, email_address. if the user logged in, $sender equals $logged_info.
* @param $module_info is a board module's instance information.
*/
function processNotification(&$config, &$commentInfo, &$module_info)
{
// get the reference of modules' instances.
$oMemberModel = &getModel('member');
// get document info.
$oDocumentModel = &getModel('document');
$oDocument = $oDocumentModel->getDocument($commentInfo->document_srl);
$commentInfo->writer_nick_name = $oDocument->getNickName();
$title = $oDocument->getTitleText();
// message content
$mobileContent = $this->mergeKeywords($config->content, $commentInfo);
$mobileContent = $this->mergeKeywords($mobileContent, $module_info);
$mobileContent = str_replace(" ", "", strip_tags($mobileContent));
// mail content
$mailContent = $this->mergeKeywords($config->mail_content, $commentInfo);
$mailContent = $this->mergeKeywords($mailContent, $module_info);
// send to administrator
$this->sendToAdministrator($mobileContent, $mailContent, $title, $commentInfo, $config);
// send to writer
$writer_check = $this->checkNotificationRequiredForWriter($commentInfo, $oDocument, $config);
debugPrint($writer_check);
if($writer_check)
{
$this->sendToWriter($mobileContent, $mailContent, $title, $commentInfo, $config);
}
// send to upper replier
$upperComment = $this->getUpperComment($commentInfo);
if($upperComment && $this->checkNotificationRequiredForUpperReplier($commentInfo, $upperComment, $oDocument, $config))
{
$this->sendToUpperReplier($upperComment, $mobileContent, $mailContent, $title, $commentInfo, $config);
}
}
/**
* @brief comment registration trigger
* @param $obj : comment info object
**/
function triggerInsertComment(&$commentInfo)
{
// get the references of modules' instances
$oNotificationModel = &getModel('notification');
$oModuleModel = &getModel('module');
// if module_srl not set, just return with success;
if(!$commentInfo->module_srl) return;
// if module_srl is wrong, just return with success
$module_info = $oModuleModel->getModuleInfoByModuleSrl($commentInfo->module_srl);
if(!$module_info) return;
// get configuration info. no configuration? just return.
$configList = $oNotificationModel->getNotiConfig($commentInfo->module_srl);
if(!$configList) return;
foreach($configList as $config)
{
$this->processNotification($config, $commentInfo, $module_info);
}
}
}
/* End of file notification.controller.php */
/* Location: ./modules/notification/notification.controller.php */