-
Notifications
You must be signed in to change notification settings - Fork 0
/
ncenterlite.model.php
316 lines (262 loc) · 9.02 KB
/
ncenterlite.model.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
<?php
class ncenterliteModel extends ncenterlite
{
var $config;
function getConfig()
{
if(!$this->config)
{
$oModuleModel = getModel('module');
$config = $oModuleModel->getModuleConfig('ncenterlite');
if(!$config->use) $config->use = 'Y';
if(!$config->display_use) $config->display_use = 'Y';
if(!$config->mention_names) $config->mention_names = 'nick_name';
if(!$config->message_notify) $config->message_notify = 'Y';
if(!$config->mention_format && !is_array($config->mention_format)) $config->mention_format = array('respect');
if(!is_array($config->mention_format)) $config->mention_format = explode('|@|', $config->mention_format);
if(!$config->document_notify) $config->document_notify = 'direct-comment';
if(!$config->hide_module_srls) $config->hide_module_srls = array();
if(!is_array($config->hide_module_srls)) $config->hide_module_srls = explode('|@|', $config->hide_module_srls);
if(!$config->document_read) $config->document_read = 'N';
if(!$config->voted_format) $config->voted_format = 'N';
if(!$config->skin) $config->skin = 'default';
if(!$config->colorset) $config->colorset = 'black';
$this->config = $config;
}
return $this->config;
}
function getMemberConfig($member_srl=null)
{
if(!$member_srl)
{
$logged_info = Context::get('logged_info');
$member_srl = $logged_info->member_srl;
}
$args = new stdClass();
$args->member_srl = $member_srl;
$output = executeQuery('ncenterlite.getUserConfig', $args);
if(!$output->data) return $output->data;
return $output;
}
function getAllMemberConfig()
{
$output = executeQueryArray('ncenterlite.getAllUserConfig');
return $output;
}
function getMyNotifyList($member_srl=null, $page=1, $readed='N')
{
$oNcenterliteModel = getModel('ncenterlite');
$config = $oNcenterliteModel->getConfig();
global $lang;
$act = Context::get('act');
if($act=='dispNcenterliteNotifyList')
{
$output = $this->getMyDispNotifyList($member_srl);
}
else
{
$output = $this->_getMyNotifyList($member_srl, $page, $readed);
}
$oMemberModel = getModel('member');
$list = $output->data;
foreach($list as $k => $v)
{
$target_member = $v->target_nick_name;
switch($v->type)
{
case 'D':
$type = $lang->ncenterlite_document; //$type = '글';
break;
case 'C':
$type = $lang->ncenterlite_comment; //$type = '댓글';
break;
// 메시지. 쪽지
case 'E':
$type = $lang->ncenterlite_type_message; //$type = '쪽지';
break;
}
switch($v->target_type)
{
case 'C':
$str = sprintf($lang->ncenterlite_commented, $target_member, $type, $v->target_summary);
//$str = sprintf('<strong>%s</strong>님이 회원님의 %s에 <strong>"%s" 댓글</strong>을 남겼습니다.', $target_member, $type, $v->target_summary);
break;
case 'A':
$str = sprintf('<strong>%s</strong>님이 <strong>"%s"</strong>게시판에 <strong>"%s"</strong>댓글을 남겼습니다. ', $target_member, $v->target_browser, $v->target_summary);
//$str = sprintf('<strong>%s</strong>님이 회원님의 %s에 <strong>"%s" 댓글</strong>을 남겼습니다.', $target_member, $type, $v->target_summary);
break;
case 'M':
$str = sprintf($lang->ncenterlite_mentioned, $target_member, $v->target_summary, $type);
//$str = sprintf('<strong>%s</strong>님이 <strong>"%s" %s</strong>에서 회원님을 언급하였습니다.', $target_member, $v->target_summary, $type);
break;
// 메시지. 쪽지
case 'E':
if(version_compare(__XE_VERSION__, '1.7.4', '>='))
{
$str = sprintf('<strong>%s</strong>님께서 <strong>%s</strong> 메세지를 보내셨습니다.',$target_member, $v->target_summary);
}
else
{
$str = sprintf($lang->ncenterlite_message_string, $v->target_summary);
}
break;
case 'T':
$str = sprintf('<strong>%s</strong>님! 스킨 테스트 알림을 완료했습니다.', $target_member);
break;
case 'P':
$str = sprintf('<strong>%s</strong>님이 <strong>"%s"</strong>게시판에 <strong>%s</strong>글을 남겼습니다.', $target_member, $v->target_browser, $v->target_summary);
break;
case 'S':
if($v->target_browser)
{
$str = sprintf('<strong>%s</strong>님이 <strong>"%s"</strong>게시판에 <strong>"%s"</strong>글을 남겼습니다.', $target_member, $v->target_browser, $v->target_summary);
}
else
{
$str = sprintf('<strong>%s</strong>님이 <strong>"%s"</strong>글을 남겼습니다.', $target_member, $v->target_summary);
}
break;
case 'V':
$str = sprintf('<strong>%s</strong>님이 <strong>"%s"</strong>글을 추천하였습니다.', $target_member, $v->target_summary);
break;
}
$v->text = $str;
$v->ago = $this->getAgo($v->regdate);
$v->url = getUrl('','act','procNcenterliteRedirect', 'notify', $v->notify, 'url', $v->target_url);
if($v->target_member_srl)
{
$profileImage = $oMemberModel->getProfileImage($v->target_member_srl);
$v->profileImage = $profileImage->src;
}
$list[$k] = $v;
}
$output->data = $list;
return $output;
}
function getMyNotifyListTpl()
{
$logged_info = Context::get('logged_info');
if(!$logged_info) return new Object(-1, 'msg_not_permitted');
$oMemberModel = getModel('member');
$memberConfig = $oMemberModel->getMemberConfig();
$page = Context::get('page');
$member_srl = $logged_info->member_srl;
$tmp = $this->getMyNotifyList($member_srl, $page);
foreach($tmp->data as $key => $obj)
{
$tmp->data[$key]->url = str_replace('&', '&', $obj->url);
}
$list->data = $tmp->data;
$list->page = $tmp->page_navigation;
$this->add('list', $list);
$this->add('useProfileImage', $memberConfig->profile_image);
}
function _getMyNotifyList($member_srl=null, $page=1, $readed='N')
{
if(!$member_srl)
{
$logged_info = Context::get('logged_info');
if(!$logged_info) return array();
$member_srl = $logged_info->member_srl;
}
$args = new stdClass();
$args->member_srl = $member_srl;
$args->page = $page ? $page : 1;
if($readed) $args->readed = $readed;
$output = executeQueryArray('ncenterlite.getNotifyList', $args);
if(!$output->data) $output->data = array();
return $output;
}
function getMyDispNotifyList($member_srl)
{
$logged_info = Context::get('logged_info');
$member_srl = $logged_info->member_srl;
$args = new stdClass();
$args->page = Context::get('page');
$args->list_count = '20';
$args->page_count = '10';
$args->member_srl = $member_srl;
$output = executeQueryArray('ncenterlite.getDispNotifyList', $args);
if(!$output->data) $output->data = array();
return $output;
}
function getNcenterliteAdminList($member_srl)
{
$logged_info = Context::get('logged_info');
$member_srl = $logged_info->member_srl;
$args = new stdClass();
$args->page = Context::get('page');
$args->list_count = '20';
$args->page_count = '10';
$output = executeQueryArray('ncenterlite.getAdminNotifyList', $args);
if(!$output->data) $output->data = array();
return $output;
}
function getMemberAdmins()
{
$args->is_admin = 'Y';
$output = executeQueryArray('ncenterlite.getMemberAdmins', $args);
if(!$output->data) $output->data = array();
return $output;
}
function _getNewCount($member_srl=null)
{
if(!$member_srl)
{
$logged_info = Context::get('logged_info');
if(!$logged_info) return 0;
$member_srl = $logged_info->member_srl;
}
$args->member_srl = $member_srl;
$output = executeQuery('ncenterlite.getNotifyNewCount', $args);
if(!$output->data) return 0;
return $output->data->cnt;
}
function getColorsetList()
{
$oModuleModel = getModel('module');
$skin = Context::get('skin');
$skin_info = $oModuleModel->loadSkinInfo($this->module_path, $skin);
for($i=0, $c=count($skin_info->colorset); $i<$c; $i++)
{
$colorset = sprintf('%s|@|%s', $skin_info->colorset[$i]->name, $skin_info->colorset[$i]->title);
$colorset_list[] = $colorset;
}
if(count($colorset_list)) $colorsets = implode("\n", $colorset_list);
$this->add('colorset_list', $colorsets);
}
/**
* @brief 주어진 시간이 얼마 전 인지 반환
* @param string YmdHis
* @return string
**/
function getAgo($datetime)
{
global $lang;
$lang_type = Context::getLangType();
$display = $lang->ncenterlite_date; // array('Year', 'Month', 'Day', 'Hour', 'Minute', 'Second')
$ago = $lang->ncenterlite_ago; // 'Ago'
$date = getdate(strtotime(zdate($datetime, 'Y-m-d H:i:s')));
$current = getdate();
$p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
$factor = array(0, 12, 30, 24, 60, 60);
for($i = 0; $i < 6; $i++)
{
if($i > 0)
{
$current[$p[$i]] += $current[$p[$i - 1]] * $factor[$i];
$date[$p[$i]] += $date[$p[$i - 1]] * $factor[$i];
}
if($current[$p[$i]] - $date[$p[$i]] > 1)
{
$value = $current[$p[$i]] - $date[$p[$i]];
if($lang_type == 'en')
{
return $value . ' ' . $display[$i] . (($value != 1) ? 's' : '') . ' ' . $ago;
}
return $value . $display[$i] . ' ' . $ago;
}
}
return zdate($datetime, 'Y-m-d');
}
}