Completed
Push — master ( 266444...2ebe1b )
by Michael
01:31
created

class/contact.php (18 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 25.

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.

Loading history...
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
use Xmf\Request;
13
14
/**
15
 * Contact module
16
 *
17
 * @copyright     XOOPS Project (https://xoops.org)
18
 * @license       http://www.fsf.org/copyleft/gpl.html GNU public license
19
 * @author        Kazumi Ono (aka Onokazu)
20
 * @author        Trabis <[email protected]>
21
 * @author        Hossein Azizabadi (AKA Voltan)
22
 * @author        Mirza (AKA Bleekk)
23
 */
24
25
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
26
27
/**
28
 * Class contact
29
 */
30
class Contact extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
31
{
32
    private $db;
33
    private $table;
34
35
    /**
36
     * contact constructor.
37
     */
38
    public function __construct()
0 ignored issues
show
__construct uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
39
    {
40
        // parent::__construct();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
        $this->initVar('contact_id', XOBJ_DTYPE_INT, null, false, 11);
42
        $this->initVar('contact_uid', XOBJ_DTYPE_INT, null, false, 11);
43
        $this->initVar('contact_cid', XOBJ_DTYPE_INT, null, false, 11);
44
        $this->initVar('contact_name', XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('contact_subject', XOBJ_DTYPE_TXTBOX, null, false);
46
        $this->initVar('contact_mail', XOBJ_DTYPE_EMAIL, null, false);
47
        $this->initVar('contact_url', XOBJ_DTYPE_TXTBOX, null, false);
48
        $this->initVar('contact_create', XOBJ_DTYPE_INT, null, false);
49
        $this->initVar('contact_icq', XOBJ_DTYPE_TXTBOX, null, false);
50
        $this->initVar('contact_company', XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('contact_location', XOBJ_DTYPE_TXTBOX, null, false);
52
        $this->initVar('contact_phone', XOBJ_DTYPE_TXTBOX, null, false);
53
        $this->initVar('contact_department', XOBJ_DTYPE_TXTBOX, null, false);
54
        $this->initVar('contact_ip', XOBJ_DTYPE_TXTBOX, null, false);
55
        $this->initVar('contact_message', XOBJ_DTYPE_TXTAREA, null, false);
56
        $this->initVar('contact_address', XOBJ_DTYPE_TXTAREA, null, false);
57
        $this->initVar('contact_reply', XOBJ_DTYPE_INT, null, false, 1);
58
        $this->initVar('contact_platform', XOBJ_DTYPE_ENUM, null, false, '', '', ['Android', 'Ios', 'Web']);
59
        $this->initVar('contact_type', XOBJ_DTYPE_ENUM, null, false, '', '', ['Contact', 'Phone', 'Mail']);
60
61
        $this->db    = $GLOBALS ['xoopsDB'];
62
        $this->table = $this->db->prefix('contact');
63
    }
64
65
    /**
66
     * @return XoopsThemeForm
67
     */
68
    public function contactReplyForm()
0 ignored issues
show
contactReplyForm uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
69
    {
70
        //        global $xoopsConfig;
71
        $form = new XoopsThemeForm(_AM_CONTACT_REPLY, 'doreply', 'main.php', 'post', true);
72
        $form->setExtra('enctype="multipart/form-data"');
73
        $form->addElement(new XoopsFormHidden('op', 'doreply'));
74
        $form->addElement(new XoopsFormHidden('contact_id', $this->getVar('contact_id', 'e')));
75
        $form->addElement(new XoopsFormHidden('contact_uid', $this->getVar('contact_uid', 'e')));
76
        $form->addElement(new XoopsFormLabel(_AM_CONTACT_FROM, '', ''));
77
        $form->addElement(new XoopsFormText(_AM_CONTACT_NAMEFROM, 'contact_name', 50, 255, XoopsUser::getUnameFromId($GLOBALS['xoopsUser']->uid())), true);
78
        $form->addElement(new XoopsFormText(_AM_CONTACT_MAILFROM, 'contact_mail', 50, 255, $GLOBALS['xoopsUser']->getVar('email')), true);
79
        $form->addElement(new XoopsFormLabel(_AM_CONTACT_TO, '', ''));
80
        $form->addElement(new XoopsFormText(_AM_CONTACT_NAMETO, 'contact_nameto', 50, 255, $this->getVar('contact_name')), true);
81
        $form->addElement(new XoopsFormText(_AM_CONTACT_MAILTO, 'contact_mailto', 50, 255, $this->getVar('contact_mail')), true);
82
        $form->addElement(new XoopsFormText(_AM_CONTACT_SUBJECT, 'contact_subject', 50, 255, _RE . $this->getVar('contact_subject')), true);
83
        $form->addElement(new XoopsFormTextArea(_AM_CONTACT_MESSAGE, 'contact_message', '', 5, 60), true);
84
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
85
86
        return $form;
87
    }
88
89
    /**
90
     * Returns an array representation of the object
91
     *
92
     * @return array
93
     **/
94
    public function toArray()
95
    {
96
        $ret  = [];
97
        $vars =& $this->getVars();
98
        foreach (array_keys($vars) as $i) {
99
            $ret [$i] = $this->getVar($i);
100
        }
101
102
        return $ret;
103
    }
104
}
105
106
/**
107
 * Class ContactContactHandler
108
 */
109
class ContactContactHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
110
{
111
    /**
112
     * ContactContactHandler constructor.
113
     * @param null|XoopsDatabase $db
114
     */
115
    public function __construct(XoopsDatabase $db)
116
    {
117
        parent::__construct($db, 'contact', 'Contact', 'contact_id', 'contact_mail');
118
    }
119
120
    /**
121
     * Get variables passed by GET or POST method
122
     * @param        $global
123
     * @param        $key
124
     * @param string $default
125
     * @param string $type
126
     * @return false|int|mixed|string
127
     */
128
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
129
    public function contactCleanVars(&$global, $key, $default = '', $type = 'int')
130
    {
131
        switch ($type) {
132
            case 'array':
133
                $ret = (isset($global[$key]) && is_array($global[$key])) ? $global[$key] : $default;
134
                break;
135
            case 'date':
136
                $ret = isset($global[$key]) ? strtotime($global[$key]) : $default;
137
                break;
138
            case 'string':
139
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
140
                break;
141
            case 'mail':
142
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_EMAIL) : $default;
143
                break;
144
            case 'url':
145
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) : $default;
146
                break;
147
            case 'ip':
148
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_VALIDATE_IP) : $default;
149
                break;
150
            case 'amp':
151
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_FLAG_ENCODE_AMP) : $default;
152
                break;
153
            case 'text':
154
                $ret = isset($global[$key]) ? htmlentities($global[$key], ENT_QUOTES, 'UTF-8') : $default;
155
                break;
156
            case 'platform':
157
                $ret = isset($global[$key]) ? $this->contactPlatform($global[$key]) : $this->contactPlatform($default);
158
                break;
159
            case 'type':
160
                $ret = isset($global[$key]) ? $this->contactType($global[$key]) : $this->contactType($default);
161
                break;
162
            case 'int':
163
            default:
164
                $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
165
                break;
166
        }
167
        if ($ret === false) {
168
            return $default;
169
        }
170
171
        return $ret;
172
    }
173
*/
174
175
    /**
176
     * @return array
177
     */
178
    public function contactInfoProcessing()
179
    {
180
        $contact                       = [];
181
        $contact['contact_cid']        = Request::getInt('contact_id', 0, 'POST');
182
        $contact['contact_uid']        = Request::getInt('contact_uid', 0, 'POST');
183
        $contact['contact_name']       = Request::getString('contact_name', '', 'POST');
184
        $contact['contact_nameto']     = Request::getString('contact_nameto', '', 'POST');
185
        $contact['contact_subject']    = Request::getString('contact_subject', '', 'POST');
186
        $contact['contact_mail']       = Request::getString('contact_mail', '', 'POST');
187
        $contact['contact_mailto']     = Request::getEmail('contact_mailto', '', 'POST');
188
        $contact['contact_url']        = Request::getUrl('contact_url', '', 'POST');
189
        $contact['contact_create']     = time();
190
        $contact['contact_icq']        = Request::getString('contact_icq', '', 'POST');
191
        $contact['contact_company']    = Request::getString('contact_company', '', 'POST');
192
        $contact['contact_location']   = Request::getString('contact_location', '', 'POST');
193
        $contact['contact_phone']      = Request::getString('contact_phone', '', 'int');
194
        $contact['contact_department'] = Request::getString('contact_department', _MD_CONTACT_DEFULTDEP, 'POST');
195
        $contact['contact_ip']         = getenv('REMOTE_ADDR');
196
        $contact['contact_message']    = Request::getText('contact_message', '', 'POST');
197
        $contact['contact_address']    = Request::getString('contact_address', '', 'POST');
198
        $contact['contact_platform']   = Request::getString('contact_platform', 'Web', 'POST');
199
        $contact['contact_type']       = Request::getString('contact_type', 'Contact', 'POST');
200
        $contact['contact_reply']      = Request::getInt('contact_reply', 0, 'POST');
201
202
        return $contact;
203
    }
204
205
    /**
206
     * @param $contact
207
     * @return string
208
     */
209
    public function contactSendMail($contact)
0 ignored issues
show
contactSendMail uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
210
    {
211
        $xoopsMailer = xoops_getMailer();
212
        $xoopsMailer->useMail();
213
        $xoopsMailer->setToEmails($this->contactToEmails($contact['contact_department']));
214
        $xoopsMailer->setFromEmail($contact['contact_mail']);
215
        $xoopsMailer->setFromName(html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8'));
216
217
        $subjectPrefix = '';
218
        if ($GLOBALS['xoopsModuleConfig']['form_dept'] && $GLOBALS['xoopsModuleConfig']['subject_prefix'] && $GLOBALS['xoopsModuleConfig']['contact_dept']) {
219
            $subjectPrefix = '[' . $GLOBALS['xoopsModuleConfig']['prefix_text'] . ' ' . $contact['contact_department'] . ']: ';
220
        }
221
        $xoopsMailer->setSubject($subjectPrefix . html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8'));
222
        $xoopsMailer->setBody(html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8'));
223
        if ($xoopsMailer->send()) {
224
            $message = _MD_CONTACT_MES_SEND;
225
        } else {
226
            $message = $xoopsMailer->getErrors();
227
        }
228
229
        return $message;
230
    }
231
232
    /**
233
     * @param $contact
234
     * @return string
235
     */
236
    public function contactSendMailConfirm($contact)
0 ignored issues
show
contactSendMailConfirm uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
237
    {
238
        $xoopsMailer = xoops_getMailer();
239
        $xoopsMailer->useMail();
240
        $xoopsMailer->setToEmails($contact['contact_mail']);
241
        $xoopsMailer->setFromEmail($this->contactToEmails($contact['contact_department']));
242
        $xoopsMailer->setFromName(html_entity_decode($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES, 'UTF-8'));
243
244
        $xoopsMailer->setSubject(_MD_CONTACT_MAILCONFIRM_SUBJECT);
245
        $body = str_replace('{NAME}', html_entity_decode($contact['contact_name'], ENT_QUOTES, 'UTF-8'), _MD_CONTACT_MAILCONFIRM_BODY);
246
        $body = str_replace('{SUBJECT}', html_entity_decode($contact['contact_subject'], ENT_QUOTES, 'UTF-8'), $body);
247
        $body = str_replace('{BODY}', html_entity_decode($contact['contact_message'], ENT_QUOTES, 'UTF-8'), $body);
248
        $xoopsMailer->setBody($body);
249
        if ($xoopsMailer->send()) {
250
            $message = _MD_CONTACT_MES_SEND;
251
        } else {
252
            $message = $xoopsMailer->getErrors();
253
        }
254
255
        return $message;
256
    }
257
258
    /**
259
     * @param $contact
260
     * @return string
261
     */
262
    public function contactReplyMail($contact)
263
    {
264
        $xoopsMailer = xoops_getMailer();
265
        $xoopsMailer->useMail();
266
        $xoopsMailer->setToEmails($contact['contact_mailto']);
267
        $xoopsMailer->setFromEmail($contact['contact_mail']);
268
        $xoopsMailer->setFromName($contact['contact_name']);
269
        $xoopsMailer->setSubject($contact['contact_subject']);
270
        $xoopsMailer->setBody($contact['contact_message']);
271
        if ($xoopsMailer->send()) {
272
            $message = _MD_CONTACT_MES_SEND;
273
        } else {
274
            $message = $xoopsMailer->getErrors();
275
        }
276
277
        return $message;
278
    }
279
280
    /**
281
     * @param null $department
282
     * @return array
283
     */
284
    public function contactToEmails($department = null)
285
    {
286
        //        global $xoopsConfig;
287
        $department_mail[] = xoops_getModuleOption('contact_recipient_std', 'contact');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$department_mail was never initialized. Although not strictly required by PHP, it is generally a good practice to add $department_mail = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
288
        if (!empty($department)) {
289
            $departments = xoops_getModuleOption('contact_dept', 'contact');
290
            foreach ($departments as $vals) {
291
                $vale = explode(',', $vals);
292
                if ($department == $vale[0]) {
293
                    $department_mail[] = $vale[1];
294
                }
295
            }
296
        }
297
298
        return $department_mail;
299
    }
300
301
    /**
302
     * @param $contact_id
303
     * @return bool
304
     */
305
    public function contactAddReply($contact_id)
306
    {
307
        $obj = $this->get($contact_id);
308
        $obj->setVar('contact_reply', 1);
309
        if (!$this->insert($obj)) {
310
            return false;
311
        }
312
313
        return true;
314
    }
315
316
    /**
317
     * @param $contact_id
318
     * @return array|bool
319
     */
320
    public function contactGetReply($contact_id)
321
    {
322
        $ret      = false;
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 View Code Duplication
        if ($contacts) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
329
            $ret = [];
330
            /** @var Contact $root */
331
            foreach ($contacts as $root) {
332
                $tab                   = [];
0 ignored issues
show
$tab is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
340
        return $ret;
341
    }
342
343
    /**
344
     * @param $contact
345
     * @param $id
346
     * @return array
347
     */
348
    public function contactGetAdminList($contact, $id)
349
    {
350
        $ret      = [];
351
        $criteria = new CriteriaCompo();
352
        $criteria->add(new Criteria($id, '0'));
353
        $criteria->add(new Criteria('contact_type', 'Contact'));
354
        $criteria->setSort($contact['sort']);
355
        $criteria->setOrder($contact['order']);
356
        $criteria->setStart($contact['start']);
357
        $criteria->setLimit($contact['limit']);
358
        $contacts =& $this->getObjects($criteria, false);
359 View Code Duplication
        if ($contacts) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360
            /** @var Contact $root */
361
            foreach ($contacts as $root) {
362
                $tab                   = [];
0 ignored issues
show
$tab is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
363
                $tab                   = $root->toArray();
364
                $tab['contact_owner']  = XoopsUser::getUnameFromId($root->getVar('contact_uid'));
365
                $tab['contact_create'] = formatTimestamp($root->getVar('contact_create'), _MEDIUMDATESTRING);
366
                $ret []                = $tab;
367
            }
368
        }
369
370
        return $ret;
371
    }
372
373
    /**
374
     * Get file Count
375
     * @param $id
376
     * @return int
377
     */
378
    public function contactGetCount($id)
379
    {
380
        $criteria = new CriteriaCompo();
381
        $criteria->add(new Criteria($id, '0'));
382
        $criteria->add(new Criteria('contact_type', 'Contact'));
383
384
        return $this->getCount($criteria);
385
    }
386
387
    /**
388
     * Get Insert ID
389
     */
390
    public function getInsertId()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
391
    {
392
        return $this->db->getInsertId();
393
    }
394
395
    /**
396
     * Contact Prune Count
397
     * @param $timestamp
398
     * @param $onlyreply
399
     * @return int
400
     */
401 View Code Duplication
    public function contactPruneCount($timestamp, $onlyreply)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
402
    {
403
        $criteria = new CriteriaCompo();
404
        $criteria->add(new Criteria('contact_create', $timestamp, '<='));
405
        if ($onlyreply) {
406
            $criteria->add(new Criteria('contact_reply', 1));
407
        }
408
409
        return $this->getCount($criteria);
410
    }
411
412
    /**
413
     * Contact Delete Before Date
414
     * @param $timestamp
415
     * @param $onlyreply
416
     */
417 View Code Duplication
    public function contactDeleteBeforeDate($timestamp, $onlyreply)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
418
    {
419
        $criteria = new CriteriaCompo();
420
        $criteria->add(new Criteria('contact_create', $timestamp, '<='));
421
        if ($onlyreply) {
422
            $criteria->add(new Criteria('contact_reply', 1));
423
        }
424
        $this->deleteAll($criteria);
425
    }
426
427
    /**
428
     * Contact Platform
429
     * @param $platform
430
     * @return string
431
     */
432
    public function contactPlatform($platform)
433
    {
434
        $platform = strtolower($platform);
435
        switch ($platform) {
436
            case 'Android':
437
                $ret = 'Android';
438
                break;
439
440
            case 'Ios':
441
                $ret = 'Ios';
442
                break;
443
444
            case 'Web':
445
            default:
446
                $ret = 'Web';
447
                break;
448
        }
449
450
        return $ret;
451
    }
452
453
    /**
454
     * Contact type
455
     * @param $type
456
     * @return string
457
     */
458
    public function contactType($type)
459
    {
460
        $type = strtolower($type);
461
        switch ($type) {
462
            case 'Mail':
463
                $ret = 'Mail';
464
                break;
465
466
            case 'Phone':
467
                $ret = 'Phone';
468
                break;
469
470
            case 'Contact':
471
            default:
472
                $ret = 'Contact';
473
                break;
474
        }
475
476
        return $ret;
477
    }
478
479
    /**
480
     * Contact logs
481
     * @param      $column
482
     * @param null $timestamp
483
     * @return array
484
     */
485
    public function contactLogs($column, $timestamp = null)
486
    {
487
        $ret = [];
488
        if (!in_array($column, ['contact_mail', 'contact_url', 'contact_phone'])) {
489
            return $ret;
490
        }
491
        $criteria = new CriteriaCompo();
492
        $criteria->add(new Criteria('contact_cid', '0'));
493
        if (!empty($timestamp)) {
494
            $criteria->add(new Criteria('contact_create', $timestamp, '<='));
495
        }
496
        $criteria->setSort('contact_create');
497
        $criteria->setOrder('DESC');
498
        $contacts =& $this->getObjects($criteria, false);
499
        if ($contacts) {
500
            /** @var Contact $root */
501
            foreach ($contacts as $root) {
502
                $rootColumn = $root->getVar($column);
503
                if (!empty($rootColumn)) {
504
                    $ret[] = $root->getVar($column);
505
                    unset($root);
506
                }
507
            }
508
        }
509
510
        return array_unique($ret);
511
    }
512
}
513