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
|
|||
2 | require('servicemain.php'); |
||
3 | |||
4 | //Include xhelp Related Includes |
||
5 | require_once(XHELP_INCLUDE_PATH.'/events.php'); |
||
6 | require(XHELP_CLASS_PATH.'/mailboxPOP3.php'); |
||
7 | require(XHELP_CLASS_PATH.'/msgParser.php'); |
||
8 | require(XHELP_CLASS_PATH.'/msgStore.php'); |
||
9 | require(XHELP_CLASS_PATH.'/validator.php'); |
||
10 | |||
11 | //Initialize xhelp objects |
||
12 | $msgParser = new xhelpEmailParser(); |
||
13 | $msgStore = new xhelpEmailStore(); |
||
14 | $hDeptBoxes =& xhelpGetHandler('departmentMailBox'); |
||
15 | $hMailEvent =& xhelpGetHandler('mailEvent'); |
||
16 | $hTicket =& xhelpGetHandler('ticket'); |
||
17 | |||
18 | $_eventsrv->advise('new_user_by_email', xhelpNotificationService::singleton(), 'new_user_activation'.$xoopsConfigUser['activation_type']); |
||
19 | |||
20 | //Get All Department Mailboxes |
||
21 | $deptmboxes =& $hDeptBoxes->getActiveMailboxes(); |
||
22 | |||
23 | //Loop Through All Department Mailboxes |
||
24 | foreach($deptmboxes as $mbox) { |
||
25 | $deptid = $mbox->getVar('departmentid'); |
||
26 | //Connect to the mailbox |
||
27 | if ($mbox->connect()) { |
||
28 | //Check for new messages |
||
29 | if ($mbox->hasMessages()) { |
||
30 | //Retrieve / Store each message |
||
31 | while ($msg =& $mbox->getMessage()) { |
||
32 | $msg_logs = array(); |
||
33 | $skip_msg = false; |
||
34 | |||
35 | //Check if there are any errors parsing msg |
||
36 | if ($parsed =& $msgParser->parseMessage($msg)) { |
||
37 | |||
38 | //Sanity Check: Disallow emails from other department mailboxes |
||
39 | if (_isDepartmentEmail($parsed->getEmail())) { |
||
40 | $msg_logs[_XHELP_MAIL_CLASS3][] = sprintf(_XHELP_MESSAGE_EMAIL_DEPT_MBOX, $parsed->getEmail()); |
||
41 | } else { |
||
42 | |||
43 | //Create new user account if necessary |
||
44 | |||
45 | if (!$xoopsUser =& xhelpEmailIsXoopsUser($parsed->getEmail())) { |
||
46 | |||
47 | if ($xoopsModuleConfig['xhelp_allowAnonymous']) { |
||
48 | View Code Duplication | switch($xoopsConfigUser['activation_type']){ |
|
49 | case 1: |
||
50 | $level = 1; |
||
51 | break; |
||
52 | |||
53 | case 0: |
||
54 | case 2: |
||
55 | default: |
||
56 | $level = 0; |
||
57 | } |
||
58 | $xoopsUser =& xhelpXoopsAccountFromEmail($parsed->getEmail(), $parsed->getName(), $password, $level); |
||
59 | $_eventsrv->trigger('new_user_by_email', array($password, $xoopsUser)); |
||
60 | } else { |
||
61 | $msg_logs[_XHELP_MAIL_CLASS3][] = sprintf(_XHELP_MESSAGE_NO_ANON, $parsed->getEmail()); |
||
62 | $skip_msg = true; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if ($skip_msg == false) { |
||
0 ignored issues
–
show
|
|||
67 | //Store Message In Server |
||
68 | if($obj =& $msgStore->storeMsg($parsed, $xoopsUser, $mbox, $errors)) { |
||
69 | switch ($parsed->getMsgType()) { |
||
70 | case _XHELP_MSGTYPE_TICKET: |
||
71 | //Trigger New Ticket Events |
||
72 | $_eventsrv->trigger('new_ticket', $obj); |
||
73 | break; |
||
74 | case _XHELP_MSGTYPE_RESPONSE: |
||
75 | //Trigger New Response Events |
||
76 | $_eventsrv->trigger('new_response', $obj); |
||
77 | break; |
||
78 | } |
||
79 | //} else { // If message not stored properly, log event |
||
80 | // $storeEvent =& $hMailEvent->newEvent($mbox->getVar('id'), _XHELP_MAILEVENT_DESC2, _XHELP_MAILEVENT_CLASS2); |
||
81 | } else { |
||
82 | $msg_logs[_XHELP_MAILEVENT_CLASS2] =& $errors; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } else { |
||
87 | $msg_logs[_XHELP_MAILEVENT_CLASS1][] = _XHELP_MAILEVENT_DESC1; |
||
88 | } |
||
89 | //Remove Message From Server |
||
90 | $mbox->deleteMessage($msg); |
||
91 | |||
92 | //Log Any Messages |
||
93 | _logMessages($mbox->getVar('id'),$msg_logs); |
||
94 | |||
95 | } |
||
96 | } |
||
97 | //Disconnect from Server |
||
98 | $mbox->disconnect(); |
||
99 | } else { // If mailbox not connected properly, log event |
||
100 | $connEvent =& $hMailEvent->newEvent($mbox->getVar('id'), _XHELP_MAILEVENT_DESC0, _XHELP_MAILEVENT_CLASS0); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | function _logMessages($mbox, $arr) |
||
105 | { |
||
106 | global $hMailEvent; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
107 | foreach ($arr as $class=>$msg) { |
||
108 | if (is_array($msg)) { |
||
109 | $msg = implode("\r\n", $msg); |
||
110 | } |
||
111 | $event =& $hMailEvent->newEvent($mbox, $msg, $class); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | function _isDepartmentEmail($email) |
||
116 | { |
||
117 | static $email_arr; |
||
118 | |||
119 | if (!isset($email_arr)) { |
||
120 | global $hDeptBoxes; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
121 | $deptmboxes =& $hDeptBoxes->getObjects(); |
||
122 | $email_arr = array(); |
||
123 | foreach($deptmboxes as $obj) { |
||
124 | $email_arr[] = $obj->getVar('emailaddress'); |
||
125 | } |
||
126 | unset($deptmboxes); |
||
127 | } |
||
128 | |||
129 | $ret = in_array($email, $email_arr); |
||
130 | |||
131 | return $ret; |
||
132 | } |
||
133 |
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.