XoopsModules25x /
xnewsletter
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * **************************************************************************** |
||
| 4 | * - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
||
| 5 | * **************************************************************************** |
||
| 6 | * XNEWSLETTER - MODULE FOR XOOPS |
||
| 7 | * Copyright (c) 2007 - 2012 |
||
| 8 | * Goffy ( wedega.com ) |
||
| 9 | * |
||
| 10 | * You may not change or alter any portion of this comment or credits |
||
| 11 | * of supporting developers from this source code or any supporting |
||
| 12 | * source code which is considered copyrighted (c) material of the |
||
| 13 | * original comment or credit authors. |
||
| 14 | * |
||
| 15 | * This program is distributed in the hope that it will be useful, |
||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 18 | * GNU General Public License for more details. |
||
| 19 | * --------------------------------------------------------------------------- |
||
| 20 | * @copyright Goffy ( wedega.com ) |
||
| 21 | * @license GNU General Public License 2.0 |
||
| 22 | * @package xnewsletter |
||
| 23 | * @author Goffy ( [email protected] ) |
||
| 24 | * |
||
| 25 | * Version : 1 Thu 2012/12/06 12:57:01 : Exp $ |
||
| 26 | * **************************************************************************** |
||
| 27 | */ |
||
| 28 | |||
| 29 | use XoopsModules\Xnewsletter; |
||
| 30 | |||
| 31 | // defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined"); |
||
| 32 | require_once __DIR__ . '/common.php'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param int $type |
||
| 36 | * @param int $subscr_id |
||
| 37 | * @param $mailinglist_id |
||
| 38 | * |
||
| 39 | * @return bool|null |
||
| 40 | */ |
||
| 41 | function subscribingMLHandler($type, $subscr_id, $mailinglist_id) |
||
| 42 | { |
||
| 43 | global $xoopsUser, $xoopsConfig; |
||
| 44 | $helper = XoopsModules\Xnewsletter\Helper::getInstance(); |
||
| 45 | |||
| 46 | // get subscriber |
||
| 47 | $subscrObj = $helper->getHandler('Subscr')->get($subscr_id); |
||
| 48 | $subscr_email = $subscrObj->getVar('subscr_email'); |
||
| 49 | |||
| 50 | // get mailinglist |
||
| 51 | $mailinglistObj = $helper->getHandler('Mailinglist')->get($mailinglist_id); |
||
| 52 | $mailinglist_listname = $mailinglistObj->getVar('mailinglist_listname'); |
||
| 53 | $mailinglist_email = $mailinglistObj->getVar('mailinglist_email'); |
||
| 54 | $mailinglist_subscribe = $mailinglistObj->getVar('mailinglist_subscribe'); |
||
| 55 | $mailinglist_unsubscribe = $mailinglistObj->getVar('mailinglist_unsubscribe'); |
||
| 56 | $mailinglist_system = (int)$mailinglistObj->getVar('mailinglist_system'); |
||
| 57 | $mailinglist_target = $mailinglistObj->getVar('mailinglist_target'); |
||
| 58 | $mailinglist_pwd = $mailinglistObj->getVar('mailinglist_pwd'); |
||
| 59 | $mailinglist_notifyowner = $mailinglistObj->getVar('mailinglist_notifyowner'); |
||
| 60 | |||
| 61 | $senderUid = (is_object($xoopsUser) && isset($xoopsUser)) ? $xoopsUser->uid() : 0; |
||
| 62 | |||
| 63 | if ($mailinglist_system === _XNEWSLETTER_MAILINGLIST_TYPE_DEFAULT_VAL) { |
||
| 64 | // this should not happen |
||
| 65 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 66 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 67 | $protocolObj->setVar('protocol_subscriber_id', $subscr_id); |
||
| 68 | $protocolObj->setVar('protocol_status', 'Error adding mailing list: invalid mailing list type'); |
||
| 69 | $protocolObj->setVar('protocol_success', false); |
||
| 70 | $protocolObj->setVar('protocol_submitter', $senderUid); |
||
| 71 | $protocolObj->setVar('protocol_created', time()); |
||
| 72 | |||
| 73 | if ($helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 74 | return true; |
||
| 75 | } |
||
| 76 | return $protocolObj->getHtmlErrors(); |
||
| 77 | } |
||
| 78 | if ($mailinglist_system === _XNEWSLETTER_MAILINGLIST_TYPE_MAJORDOMO_VAL) { |
||
| 79 | |||
| 80 | if (_XNEWSLETTER_MAILINGLIST_SUBSCRIBE == $type) { |
||
| 81 | $action_code = $mailinglist_subscribe; |
||
| 82 | } else { |
||
| 83 | $action_code = $mailinglist_unsubscribe; |
||
| 84 | } |
||
| 85 | $action_code = str_replace('{email}', $subscr_email, $action_code); |
||
| 86 | $action_code = str_replace('{nameofmylist}', $mailinglist_listname, $action_code); |
||
| 87 | |||
| 88 | require_once XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.phpmailer.php'; |
||
| 89 | require_once XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.pop3.php'; |
||
| 90 | require_once XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.smtp.php'; |
||
| 91 | |||
| 92 | try { |
||
| 93 | $xoopsMailer = xoops_getMailer(); |
||
| 94 | $xoopsMailer->reset(); |
||
| 95 | //$xoopsMailer->setTemplateDir(); |
||
| 96 | $xoopsMailer->useMail(); |
||
| 97 | $xoopsMailer->setHTML(false); |
||
| 98 | //$xoopsMailer->setTemplate('activate.tpl'); |
||
| 99 | $xoopsMailer->setToEmails($mailinglist_email); |
||
| 100 | if (isset($xoopsConfig['adminmail'])) { |
||
| 101 | $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
||
| 102 | } |
||
| 103 | if (isset($xoopsConfig['sitename'])) { |
||
| 104 | $xoopsMailer->setFromName($xoopsConfig['sitename']); |
||
| 105 | } |
||
| 106 | //$xoopsMailer->setSubject($subject); |
||
| 107 | $xoopsMailer->setBody($action_code); |
||
| 108 | $xoopsMailer->send(); |
||
| 109 | |||
| 110 | $protocol_status = str_replace('%a', $action_code, _AM_XNEWSLETTER_SEND_SUCCESS_ML_DETAIL); |
||
| 111 | $xoopsMailer->reset(); |
||
| 112 | $protocol_success = true; |
||
| 113 | } catch (\Exception $e) { |
||
| 114 | $protocol_status = _AM_XNEWSLETTER_SEND_ERROR_PHPMAILER . $xoopsMailer->getErrors(); //error messages |
||
| 115 | $protocol_success = false; |
||
| 116 | $helper->addLog($e); |
||
| 117 | } |
||
| 118 | |||
| 119 | //create item in protocol for this email |
||
| 120 | $text_clean = ['<strong>', '</strong>', '<br/>', '<br>']; |
||
| 121 | $protocol_status = str_replace($text_clean, '', $protocol_status); |
||
| 122 | |||
| 123 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 124 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 125 | $protocolObj->setVar('protocol_subscriber_id', $subscr_id); |
||
| 126 | $protocolObj->setVar('protocol_status', $protocol_status); |
||
| 127 | $protocolObj->setVar('protocol_success', $protocol_success); |
||
| 128 | $protocolObj->setVar('protocol_submitter', $senderUid); |
||
| 129 | $protocolObj->setVar('protocol_created', time()); |
||
| 130 | |||
| 131 | if ($helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 132 | return true; |
||
| 133 | } |
||
| 134 | return $protocolObj->getHtmlErrors(); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($mailinglist_system === _XNEWSLETTER_MAILINGLIST_TYPE_MAILMAN_VAL) { |
||
| 138 | |||
| 139 | $action_code = $mailinglist_target; |
||
| 140 | if (substr($action_code, -1) !== '/') { |
||
| 141 | $action_code .= '/'; |
||
| 142 | } |
||
| 143 | $action_code .= 'mailman/admin/'; |
||
| 144 | $action_code .= $mailinglist_listname; |
||
| 145 | $action_code .= '/members/'; |
||
| 146 | |||
| 147 | if (_XNEWSLETTER_MAILINGLIST_SUBSCRIBE == $type) { |
||
| 148 | $action_code .= 'add?subscribe_or_invite=0&send_welcome_msg_to_this_batch=0¬ification_to_list_owner=' . $mailinglist_notifyowner; |
||
| 149 | $action_code .= '&subscribees_upload='; |
||
| 150 | } else { |
||
| 151 | $action_code .= 'remove?send_unsub_ack_to_this_batch=0&send_unsub_notifications_to_list_owner=' . $mailinglist_notifyowner; |
||
| 152 | $action_code .= '&unsubscribees_upload='; |
||
| 153 | } |
||
| 154 | $action_code .= $subscr_email; |
||
| 155 | $action_code .= '&adminpw=' . $mailinglist_pwd; |
||
| 156 | //echo "action_code:".$action_code; |
||
| 157 | |||
| 158 | try { |
||
| 159 | $req = curl_init(); |
||
| 160 | curl_setopt($req, CURLOPT_URL, $action_code); |
||
| 161 | curl_setopt($req, CURLOPT_RETURNTRANSFER, true); |
||
| 162 | |||
| 163 | $res_curl = curl_exec($req); |
||
|
0 ignored issues
–
show
|
|||
| 164 | |||
| 165 | if(!curl_errno($req)){ |
||
| 166 | $status = (int)curl_getinfo($req, CURLINFO_HTTP_CODE); |
||
| 167 | if ($status === 200) { |
||
| 168 | $protocol_status = str_replace('%a', $subscr_email, _AM_XNEWSLETTER_SEND_SUCCESS_ML_DETAIL); |
||
| 169 | $protocol_status = str_replace('%m', $mailinglist_listname, $protocol_status); |
||
| 170 | $protocol_success = true; |
||
| 171 | } else { |
||
| 172 | $protocol_success = false; |
||
| 173 | $protocol_status = 'Curl error: ' . curl_error($req); |
||
| 174 | } |
||
| 175 | } else { |
||
| 176 | $protocol_success = false; |
||
| 177 | $protocol_status = 'Curl error: ' . curl_error($req); |
||
| 178 | } |
||
| 179 | } catch (\Exception $e) { |
||
| 180 | $protocol_status = _AM_XNEWSLETTER_SEND_ERROR_PHPMAILER; //error messages |
||
| 181 | $protocol_success = false; |
||
| 182 | $helper->addLog($e); |
||
| 183 | } |
||
| 184 | curl_close($req); |
||
| 185 | //create item in protocol for this email |
||
| 186 | $text_clean = ['<strong>', '</strong>', '<br/>', '<br>']; |
||
| 187 | $protocol_status = str_replace($text_clean, '', $protocol_status); |
||
| 188 | |||
| 189 | $protocolObj = $helper->getHandler('Protocol')->create(); |
||
| 190 | $protocolObj->setVar('protocol_letter_id', 0); |
||
| 191 | $protocolObj->setVar('protocol_subscriber_id', $subscr_id); |
||
| 192 | $protocolObj->setVar('protocol_status', $protocol_status); |
||
| 193 | $protocolObj->setVar('protocol_success', $protocol_success); |
||
| 194 | $protocolObj->setVar('protocol_submitter', $senderUid); |
||
| 195 | $protocolObj->setVar('protocol_created', time()); |
||
| 196 | |||
| 197 | if ($helper->getHandler('Protocol')->insert($protocolObj)) { |
||
| 198 | return true; |
||
| 199 | } |
||
| 200 | return $protocolObj->getHtmlErrors(); |
||
| 201 | } |
||
| 202 | return null; |
||
| 203 | } |
||
| 204 | |||
| 205 | function getActioncode ($mailinglist_id = 0) { |
||
| 206 | $helper = XoopsModules\Xnewsletter\Helper::getInstance(); |
||
| 207 | |||
| 208 | // get mailinglist |
||
| 209 | $mailinglistObj = $helper->getHandler('Mailinglist')->get($mailinglist_id); |
||
| 210 | $mailinglist_listname = $mailinglistObj->getVar('mailinglist_listname'); |
||
| 211 | $mailinglist_system = (int)$mailinglistObj->getVar('mailinglist_system'); |
||
| 212 | $mailinglist_target = $mailinglistObj->getVar('mailinglist_target'); |
||
| 213 | $mailinglist_pwd = $mailinglistObj->getVar('mailinglist_pwd'); |
||
| 214 | |||
| 215 | if ($mailinglist_system === _XNEWSLETTER_MAILINGLIST_TYPE_MAILMAN_VAL) { |
||
| 216 | |||
| 217 | $action_code = $mailinglist_target; |
||
| 218 | if (substr($action_code, -1) !== '/') { |
||
| 219 | $action_code .= '/'; |
||
| 220 | } |
||
| 221 | $action_code .= 'mailman/admin/'; |
||
| 222 | $action_code .= $mailinglist_listname; |
||
| 223 | $action_code .= '/members/list?adminpw=' . $mailinglist_pwd; |
||
| 224 | |||
| 225 | return $action_code; |
||
| 226 | } |
||
| 227 | return null; |
||
| 228 | } |
||
| 229 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.