1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Contact module |
14
|
|
|
* |
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
16
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
17
|
|
|
* @author Kazumi Ono (aka Onokazu) |
18
|
|
|
* @author Trabis <[email protected]> |
19
|
|
|
* @author Hossein Azizabadi (AKA Voltan) |
20
|
|
|
* @author Mirza (AKA Bleekk) |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
24
|
|
|
die('XOOPS root path not defined'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class contact |
29
|
|
|
*/ |
30
|
|
|
class Contact extends XoopsObject |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
private $db; |
33
|
|
|
private $table; |
34
|
|
|
/** |
35
|
|
|
* contact constructor. |
36
|
|
|
*/ |
37
|
|
|
public function __construct() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
// $this->XoopsObject(); |
|
|
|
|
40
|
|
|
$this->initVar('contact_id', XOBJ_DTYPE_INT, null, false, 11); |
41
|
|
|
$this->initVar('contact_uid', XOBJ_DTYPE_INT, null, false, 11); |
42
|
|
|
$this->initVar('contact_cid', XOBJ_DTYPE_INT, null, false, 11); |
43
|
|
|
$this->initVar('contact_name', XOBJ_DTYPE_TXTBOX, null, false); |
44
|
|
|
$this->initVar('contact_subject', XOBJ_DTYPE_TXTBOX, null, false); |
45
|
|
|
$this->initVar('contact_mail', XOBJ_DTYPE_EMAIL, null, false); |
46
|
|
|
$this->initVar('contact_url', XOBJ_DTYPE_TXTBOX, null, false); |
47
|
|
|
$this->initVar('contact_create', XOBJ_DTYPE_INT, null, false); |
48
|
|
|
$this->initVar('contact_icq', XOBJ_DTYPE_TXTBOX, null, false); |
49
|
|
|
$this->initVar('contact_company', XOBJ_DTYPE_TXTBOX, null, false); |
50
|
|
|
$this->initVar('contact_location', XOBJ_DTYPE_TXTBOX, null, false); |
51
|
|
|
$this->initVar('contact_phone', XOBJ_DTYPE_TXTBOX, null, false); |
52
|
|
|
$this->initVar('contact_department', XOBJ_DTYPE_TXTBOX, null, false); |
53
|
|
|
$this->initVar('contact_ip', XOBJ_DTYPE_TXTBOX, null, false); |
54
|
|
|
$this->initVar('contact_message', XOBJ_DTYPE_TXTAREA, null, false); |
55
|
|
|
$this->initVar('contact_address', XOBJ_DTYPE_TXTAREA, null, false); |
56
|
|
|
$this->initVar('contact_reply', XOBJ_DTYPE_INT, null, false, 1); |
57
|
|
|
$this->initVar('contact_platform', XOBJ_DTYPE_ENUM, null, false, '', '', array('Android', 'Ios', 'Web')); |
58
|
|
|
$this->initVar('contact_type', XOBJ_DTYPE_ENUM, null, false, '', '', array('Contact', 'Phone', 'Mail')); |
59
|
|
|
|
60
|
|
|
$this->db = $GLOBALS ['xoopsDB']; |
61
|
|
|
$this->table = $this->db->prefix('contact'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return XoopsThemeForm |
66
|
|
|
*/ |
67
|
|
|
public function contactReplyForm() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
// global $xoopsConfig; |
70
|
|
|
$form = new XoopsThemeForm(_AM_CONTACT_REPLY, 'doreply', 'main.php', 'post', true); |
71
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
72
|
|
|
$form->addElement(new XoopsFormHidden('op', 'doreply')); |
73
|
|
|
$form->addElement(new XoopsFormHidden('contact_id', $this->getVar('contact_id', 'e'))); |
74
|
|
|
$form->addElement(new XoopsFormHidden('contact_uid', $this->getVar('contact_uid', 'e'))); |
75
|
|
|
$form->addElement(new XoopsFormLabel(_AM_CONTACT_FROM, '', '')); |
76
|
|
|
$form->addElement( |
77
|
|
|
new XoopsFormText(_AM_CONTACT_NAMEFROM, 'contact_name', 50, 255, XoopsUser::getUnameFromId($GLOBALS['xoopsUser']->uid())), |
78
|
|
|
true |
79
|
|
|
); |
80
|
|
|
$form->addElement(new XoopsFormText(_AM_CONTACT_MAILFROM, 'contact_mail', 50, 255, $GLOBALS['xoopsUser']->getVar('email')), true); |
81
|
|
|
$form->addElement(new XoopsFormLabel(_AM_CONTACT_TO, '', '')); |
82
|
|
|
$form->addElement(new XoopsFormText(_AM_CONTACT_NAMETO, 'contact_nameto', 50, 255, $this->getVar('contact_name')), true); |
83
|
|
|
$form->addElement(new XoopsFormText(_AM_CONTACT_MAILTO, 'contact_mailto', 50, 255, $this->getVar('contact_mail')), true); |
84
|
|
|
$form->addElement(new XoopsFormText(_AM_CONTACT_SUBJECT, 'contact_subject', 50, 255, _RE . $this->getVar('contact_subject')), true); |
85
|
|
|
$form->addElement(new XoopsFormTextArea(_AM_CONTACT_MESSAGE, 'contact_message', '', 5, 60), true); |
86
|
|
|
$form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
87
|
|
|
|
88
|
|
|
return $form; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns an array representation of the object |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
**/ |
96
|
|
|
public function toArray() |
97
|
|
|
{ |
98
|
|
|
$ret = array(); |
99
|
|
|
$vars =& $this->getVars(); |
100
|
|
|
foreach (array_keys($vars) as $i) { |
101
|
|
|
$ret [$i] = $this->getVar($i); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $ret; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Class ContactContactHandler |
110
|
|
|
*/ |
111
|
|
|
class ContactContactHandler extends XoopsPersistableObjectHandler |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
/** |
114
|
|
|
* ContactContactHandler constructor. |
115
|
|
|
* @param null|XoopsDatabase $db |
116
|
|
|
*/ |
117
|
|
|
public function __construct(XoopsDatabase $db) |
118
|
|
|
{ |
119
|
|
|
parent::__construct($db, 'contact', 'contact', 'contact_id', 'contact_mail'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get variables passed by GET or POST method |
124
|
|
|
* @param $global |
125
|
|
|
* @param $key |
126
|
|
|
* @param string $default |
127
|
|
|
* @param string $type |
128
|
|
|
* @return false|int|mixed|string |
129
|
|
|
*/ |
130
|
|
|
/* |
|
|
|
|
131
|
|
|
public function contactCleanVars(&$global, $key, $default = '', $type = 'int') |
132
|
|
|
{ |
133
|
|
|
switch ($type) { |
134
|
|
|
case 'array': |
135
|
|
|
$ret = (isset($global[$key]) && is_array($global[$key])) ? $global[$key] : $default; |
136
|
|
|
break; |
137
|
|
|
case 'date': |
138
|
|
|
$ret = isset($global[$key]) ? strtotime($global[$key]) : $default; |
139
|
|
|
break; |
140
|
|
|
case 'string': |
141
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
142
|
|
|
break; |
143
|
|
|
case 'mail': |
144
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_EMAIL) : $default; |
145
|
|
|
break; |
146
|
|
|
case 'url': |
147
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) : $default; |
148
|
|
|
break; |
149
|
|
|
case 'ip': |
150
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_IP) : $default; |
151
|
|
|
break; |
152
|
|
|
case 'amp': |
153
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_FLAG_ENCODE_AMP) : $default; |
154
|
|
|
break; |
155
|
|
|
case 'text': |
156
|
|
|
$ret = isset($global[$key]) ? htmlentities($global[$key], ENT_QUOTES, 'UTF-8') : $default; |
157
|
|
|
break; |
158
|
|
|
case 'platform': |
159
|
|
|
$ret = isset($global[$key]) ? $this->contactPlatform($global[$key]) : $this->contactPlatform($default); |
160
|
|
|
break; |
161
|
|
|
case 'type': |
162
|
|
|
$ret = isset($global[$key]) ? $this->contactType($global[$key]) : $this->contactType($default); |
163
|
|
|
break; |
164
|
|
|
case 'int': |
165
|
|
|
default: |
166
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default; |
167
|
|
|
break; |
168
|
|
|
} |
169
|
|
|
if ($ret === false) { |
170
|
|
|
return $default; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return $ret; |
174
|
|
|
} |
175
|
|
|
*/ |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return array |
179
|
|
|
*/ |
180
|
|
|
public function contactInfoProcessing() |
181
|
|
|
{ |
182
|
|
|
$contact = array(); |
183
|
|
|
$contact['contact_cid'] = XoopsRequest::getInt('contact_id', 0, 'POST'); |
184
|
|
|
$contact['contact_uid'] = XoopsRequest::getInt('contact_uid', 0, 'POST'); |
185
|
|
|
$contact['contact_name'] = XoopsRequest::getString('contact_name', '', 'POST'); |
186
|
|
|
$contact['contact_nameto'] = XoopsRequest::getString('contact_nameto', '', 'POST'); |
187
|
|
|
$contact['contact_subject'] = XoopsRequest::getString('contact_subject', '', 'POST'); |
188
|
|
|
$contact['contact_mail'] = XoopsRequest::getString('contact_mail', '', 'POST'); |
189
|
|
|
$contact['contact_mailto'] = XoopsRequest::getEmail('contact_mailto', '', 'POST'); |
190
|
|
|
$contact['contact_url'] = XoopsRequest::getUrl('contact_url', '', 'POST'); |
191
|
|
|
$contact['contact_create'] = time(); |
192
|
|
|
$contact['contact_icq'] = XoopsRequest::getString('contact_icq', '', 'POST'); |
193
|
|
|
$contact['contact_company'] = XoopsRequest::getString('contact_company', '', 'POST'); |
194
|
|
|
$contact['contact_location'] = XoopsRequest::getString('contact_location', '', 'POST'); |
195
|
|
|
$contact['contact_phone'] = XoopsRequest::getString('contact_phone', '', 'int'); |
196
|
|
|
$contact['contact_department'] = XoopsRequest::getString('contact_department', _MD_CONTACT_DEFULTDEP, 'POST'); |
197
|
|
|
$contact['contact_ip'] = getenv('REMOTE_ADDR'); |
198
|
|
|
$contact['contact_message'] = XoopsRequest::getText('contact_message', '', 'POST'); |
199
|
|
|
$contact['contact_address'] = XoopsRequest::getString('contact_address', '', 'POST'); |
200
|
|
|
$contact['contact_platform'] = XoopsRequest::getString('contact_platform', 'Web', 'POST'); |
201
|
|
|
$contact['contact_type'] = XoopsRequest::getString('contact_type', 'Contact', 'POST'); |
202
|
|
|
$contact['contact_reply'] = XoopsRequest::getInt('contact_reply', 0, 'POST'); |
203
|
|
|
|
204
|
|
|
return $contact; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param $contact |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
public function contactSendMail($contact) |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
$xoopsMailer =& xoops_getMailer(); |
214
|
|
|
$xoopsMailer->useMail(); |
215
|
|
|
$xoopsMailer->setToEmails($this->contactToEmails($contact['contact_department'])); |
216
|
|
|
$xoopsMailer->setFromEmail($contact['contact_mail']); |
217
|
|
|
$xoopsMailer->setFromName(html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8')); |
218
|
|
|
|
219
|
|
|
$subjectPrefix = ''; |
220
|
|
|
if ($GLOBALS['xoopsModuleConfig']['form_dept'] && $GLOBALS['xoopsModuleConfig']['subject_prefix'] && $GLOBALS['xoopsModuleConfig']['contact_dept']) { |
221
|
|
|
$subjectPrefix = '[' . $GLOBALS['xoopsModuleConfig']['prefix_text'] . ' ' . $contact['contact_department'] . ']: '; |
222
|
|
|
} |
223
|
|
|
$xoopsMailer->setSubject($subjectPrefix . html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8')); |
224
|
|
|
$xoopsMailer->setBody(html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8')); |
225
|
|
|
if ($xoopsMailer->send()) { |
226
|
|
|
$message = _MD_CONTACT_MES_SEND; |
227
|
|
|
} else { |
228
|
|
|
$message = $xoopsMailer->getErrors(); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $message; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param $contact |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function contactSendMailConfirm($contact) |
|
|
|
|
239
|
|
|
{ |
240
|
|
|
$xoopsMailer =& xoops_getMailer(); |
241
|
|
|
$xoopsMailer->useMail(); |
242
|
|
|
$xoopsMailer->setToEmails($contact['contact_mail']); |
243
|
|
|
$xoopsMailer->setFromEmail($this->contactToEmails($contact['contact_department'])); |
244
|
|
|
$xoopsMailer->setFromName(html_entity_decode($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES, 'UTF-8')); |
245
|
|
|
|
246
|
|
|
$xoopsMailer->setSubject(_MD_CONTACT_MAILCONFIRM_SUBJECT); |
247
|
|
|
$body = str_replace('{NAME}', html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8'), _MD_CONTACT_MAILCONFIRM_BODY); |
248
|
|
|
$body = str_replace('{SUBJECT}', html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8'), $body); |
249
|
|
|
$body = str_replace('{BODY}', html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8'), $body); |
250
|
|
|
$xoopsMailer->setBody($body); |
251
|
|
|
if ($xoopsMailer->send()) { |
252
|
|
|
$message = _MD_CONTACT_MES_SEND; |
253
|
|
|
} else { |
254
|
|
|
$message = $xoopsMailer->getErrors(); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
return $message; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @param $contact |
262
|
|
|
* @return string |
263
|
|
|
*/ |
264
|
|
|
public function contactReplyMail($contact) |
265
|
|
|
{ |
266
|
|
|
$xoopsMailer =& xoops_getMailer(); |
267
|
|
|
$xoopsMailer->useMail(); |
268
|
|
|
$xoopsMailer->setToEmails($contact['contact_mailto']); |
269
|
|
|
$xoopsMailer->setFromEmail($contact['contact_mail']); |
270
|
|
|
$xoopsMailer->setFromName($contact['contact_name']); |
271
|
|
|
$xoopsMailer->setSubject($contact['contact_subject']); |
272
|
|
|
$xoopsMailer->setBody($contact['contact_message']); |
273
|
|
|
if ($xoopsMailer->send()) { |
274
|
|
|
$message = _MD_CONTACT_MES_SEND; |
275
|
|
|
} else { |
276
|
|
|
$message = $xoopsMailer->getErrors(); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
return $message; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @param null $department |
284
|
|
|
* @return array |
285
|
|
|
*/ |
286
|
|
|
public function contactToEmails($department = null) |
287
|
|
|
{ |
288
|
|
|
// global $xoopsConfig; |
289
|
|
|
$department_mail[] = xoops_getModuleOption('contact_recipient_std', 'contact'); |
|
|
|
|
290
|
|
|
if (!empty($department)) { |
291
|
|
|
$departments = xoops_getModuleOption('contact_dept', 'contact'); |
292
|
|
|
foreach ($departments as $vals) { |
293
|
|
|
$vale = explode(',', $vals); |
294
|
|
|
if ($department == $vale[0]) { |
295
|
|
|
$department_mail[] = $vale[1]; |
296
|
|
|
} |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
return $department_mail; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param $contact_id |
305
|
|
|
* @return bool |
306
|
|
|
*/ |
307
|
|
|
public function contactAddReply($contact_id) |
308
|
|
|
{ |
309
|
|
|
$obj = $this->get($contact_id); |
310
|
|
|
$obj->setVar('contact_reply', 1); |
311
|
|
|
if (!$this->insert($obj)) { |
312
|
|
|
return false; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
return true; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param $contact_id |
320
|
|
|
* @return array|bool |
321
|
|
|
*/ |
322
|
|
|
public function contactGetReply($contact_id) |
323
|
|
|
{ |
324
|
|
|
$criteria = new CriteriaCompo(); |
325
|
|
|
$criteria->add(new Criteria('contact_cid', $contact_id)); |
326
|
|
|
$criteria->add(new Criteria('contact_type', 'Contact')); |
327
|
|
|
$contacts =& $this->getObjects($criteria, false); |
328
|
|
|
if ($contacts) { |
329
|
|
|
$ret = array(); |
330
|
|
|
/** @var Contact $root */ |
331
|
|
View Code Duplication |
foreach ($contacts as $root) { |
|
|
|
|
332
|
|
|
$tab = array(); |
|
|
|
|
333
|
|
|
$tab = $root->toArray(); |
334
|
|
|
$tab['contact_owner'] = XoopsUser::getUnameFromId($root->getVar('contact_uid')); |
335
|
|
|
$tab['contact_create'] = formatTimestamp($root->getVar('contact_create'), _MEDIUMDATESTRING); |
336
|
|
|
$ret [] = $tab; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
return $ret; |
340
|
|
|
} else { |
341
|
|
|
return false; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @param $contact |
347
|
|
|
* @param $id |
348
|
|
|
* @return array |
349
|
|
|
*/ |
350
|
|
|
public function contactGetAdminList($contact, $id) |
351
|
|
|
{ |
352
|
|
|
$ret = array(); |
353
|
|
|
$criteria = new CriteriaCompo(); |
354
|
|
|
$criteria->add(new Criteria($id, '0')); |
355
|
|
|
$criteria->add(new Criteria('contact_type', 'Contact')); |
356
|
|
|
$criteria->setSort($contact['sort']); |
357
|
|
|
$criteria->setOrder($contact['order']); |
358
|
|
|
$criteria->setStart($contact['start']); |
359
|
|
|
$criteria->setLimit($contact['limit']); |
360
|
|
|
$contacts =& $this->getObjects($criteria, false); |
361
|
|
|
if ($contacts) { |
362
|
|
|
/** @var Contact $root */ |
363
|
|
View Code Duplication |
foreach ($contacts as $root) { |
|
|
|
|
364
|
|
|
$tab = array(); |
|
|
|
|
365
|
|
|
$tab = $root->toArray(); |
366
|
|
|
$tab['contact_owner'] = XoopsUser::getUnameFromId($root->getVar('contact_uid')); |
367
|
|
|
$tab['contact_create'] = formatTimestamp($root->getVar('contact_create'), _MEDIUMDATESTRING); |
368
|
|
|
$ret [] = $tab; |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
return $ret; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* Get file Count |
377
|
|
|
* @param $id |
378
|
|
|
* @return int |
379
|
|
|
*/ |
380
|
|
|
public function contactGetCount($id) |
381
|
|
|
{ |
382
|
|
|
$criteria = new CriteriaCompo(); |
383
|
|
|
$criteria->add(new Criteria($id, '0')); |
384
|
|
|
$criteria->add(new Criteria('contact_type', 'Contact')); |
385
|
|
|
|
386
|
|
|
return $this->getCount($criteria); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Get Insert ID |
391
|
|
|
*/ |
392
|
|
|
public function getInsertId() |
|
|
|
|
393
|
|
|
{ |
394
|
|
|
return $this->db->getInsertId(); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* Contact Prune Count |
399
|
|
|
* @param $timestamp |
400
|
|
|
* @param $onlyreply |
401
|
|
|
* @return int |
402
|
|
|
*/ |
403
|
|
View Code Duplication |
public function contactPruneCount($timestamp, $onlyreply) |
|
|
|
|
404
|
|
|
{ |
405
|
|
|
$criteria = new CriteriaCompo(); |
406
|
|
|
$criteria->add(new Criteria('contact_create', $timestamp, '<=')); |
407
|
|
|
if ($onlyreply) { |
408
|
|
|
$criteria->add(new Criteria('contact_reply', 1)); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
return $this->getCount($criteria); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Contact Delete Before Date |
416
|
|
|
* @param $timestamp |
417
|
|
|
* @param $onlyreply |
418
|
|
|
*/ |
419
|
|
View Code Duplication |
public function contactDeleteBeforeDate($timestamp, $onlyreply) |
|
|
|
|
420
|
|
|
{ |
421
|
|
|
$criteria = new CriteriaCompo(); |
422
|
|
|
$criteria->add(new Criteria('contact_create', $timestamp, '<=')); |
423
|
|
|
if ($onlyreply) { |
424
|
|
|
$criteria->add(new Criteria('contact_reply', 1)); |
425
|
|
|
} |
426
|
|
|
$this->deleteAll($criteria); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* Contact Platform |
431
|
|
|
* @param $platform |
432
|
|
|
* @return string |
433
|
|
|
*/ |
434
|
|
|
public function contactPlatform($platform) |
435
|
|
|
{ |
436
|
|
|
$platform = strtolower($platform); |
437
|
|
|
switch ($platform) { |
438
|
|
|
case 'Android': |
439
|
|
|
$ret = 'Android'; |
440
|
|
|
break; |
441
|
|
|
|
442
|
|
|
case 'Ios': |
443
|
|
|
$ret = 'Ios'; |
444
|
|
|
break; |
445
|
|
|
|
446
|
|
|
case 'Web': |
447
|
|
|
default: |
448
|
|
|
$ret = 'Web'; |
449
|
|
|
break; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
return $ret; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Contact type |
457
|
|
|
* @param $type |
458
|
|
|
* @return string |
459
|
|
|
*/ |
460
|
|
|
public function contactType($type) |
461
|
|
|
{ |
462
|
|
|
$type = strtolower($type); |
463
|
|
|
switch ($type) { |
464
|
|
|
case 'Mail': |
465
|
|
|
$ret = 'Mail'; |
466
|
|
|
break; |
467
|
|
|
|
468
|
|
|
case 'Phone': |
469
|
|
|
$ret = 'Phone'; |
470
|
|
|
break; |
471
|
|
|
|
472
|
|
|
case 'Contact': |
473
|
|
|
default: |
474
|
|
|
$ret = 'Contact'; |
475
|
|
|
break; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
return $ret; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Contact logs |
483
|
|
|
* @param $column |
484
|
|
|
* @param null $timestamp |
485
|
|
|
* @return array |
486
|
|
|
*/ |
487
|
|
|
public function contactLogs($column, $timestamp = null) |
488
|
|
|
{ |
489
|
|
|
$ret = array(); |
490
|
|
|
if (!in_array($column, array('contact_mail', 'contact_url', 'contact_phone'))) { |
491
|
|
|
return $ret; |
492
|
|
|
} |
493
|
|
|
$criteria = new CriteriaCompo(); |
494
|
|
|
$criteria->add(new Criteria('contact_cid', '0')); |
495
|
|
|
if (!empty($timestamp)) { |
496
|
|
|
$criteria->add(new Criteria('contact_create', $timestamp, '<=')); |
497
|
|
|
} |
498
|
|
|
$criteria->setSort('contact_create'); |
499
|
|
|
$criteria->setOrder('DESC'); |
500
|
|
|
$contacts =& $this->getObjects($criteria, false); |
501
|
|
|
if ($contacts) { |
502
|
|
|
/** @var Contact $root */ |
503
|
|
|
foreach ($contacts as $root) { |
504
|
|
|
$rootColumn = $root->getVar($column); |
505
|
|
|
if (!empty($rootColumn)) { |
506
|
|
|
$ret[] = $root->getVar($column); |
507
|
|
|
unset($root); |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
return array_unique($ret); |
513
|
|
|
} |
514
|
|
|
} |
515
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.