public static function mailingOptions($action, $task, $listId, $mailingId, $subscriberId, $listType, $artId, $contentType, $blogId, $blogType, $dealId, $dealType, $tmplid, $flexiid, $flexitype, $captchaWidth = 80, $captchaHeight = 25, $captchaBGColor = '', $captchaFTColor = '') { $Itemid = JRequest::getInt('Itemid'); if (empty($Itemid)) { $Itemid = $GLOBALS[JNEWS . 'itemidAca']; } if (empty($lisType)) { $lisType = 1; } $acl = JFactory::getACL(); $database = JFactory::getDBO(); $my = JFactory::getUser(); $new = false; $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0; $gids = array(); $gids = explode(',', $gid); if (empty($gids)) { $gids = $gid; } if (version_compare(JVERSION, '1.6.0', '<')) { $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid); } else { $groups = JAccess::getGroupsByUser($my->id); $listsAddEdit = jNews_Lists::getIDswithacclevel($groups); } //for popup window JHTML::_('behavior.modal'); if ($listType < 1) { $dropLlistPost = JRequest::getVar('droplist'); if (!empty($dropLlistPost)) { $maliste = explode('-', $dropLlistPost); $listType = $maliste[0]; $listId = $maliste[1]; } elseif ($listId > 0) { $maliste = jNews_Lists::getLists($listId, 0, null, 'listnameA', false, false, false, false); $listType = $maliste[0]->list_type; } } switch ($task) { case 'refreshcaptcha': $newcode = jNews_Captcha::generateCode('5'); $_SESSION['captcha'] = $newcode; $newesc = jNews_Captcha::encryptData($newcode, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code'])); $newdecrypt = jNews_Captcha::decryptData($newesc, crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code'])); $newpath = JNEWS_JPATH_LIVE_NO_HTTPS . '/index.php?option=' . JNEWS_OPTION . '&act=captcha&tmpl=component&width=' . $captchaWidth . '&height=' . $captchaHeight . '&bgcolor=' . $captchaBGColor . '&ftcolor=' . $captchaFTColor . '&characters=5&esc=' . $newesc . '&encpwd=' . crypt($GLOBALS[JNEWS . 'captcha_code'], $GLOBALS[JNEWS . 'captcha_code']); echo '<div id="newcode">' . $newdecrypt . '</div>'; echo '<div id="newesc">' . $newesc . '</div>'; echo '<div id="newdecrypt">' . $newdecrypt . '</div>'; echo '<div id="newpath">' . $newpath . '</div>'; exit; break; case 'blogContent': $artId = $blogId; $contentType = $blogType; case 'flexicontent': $session =& JFactory::getSession(); if ($flexitype == 'country') { $flexCategoriesCountries = $session->get('flexi_countries', array(), 'JNEWLSETTER'); if (isset($flexCategoriesCountries[$flexiid])) { unset($flexCategoriesCountries[$flexiid]); } else { $flexCategoriesCountries[$flexiid] = $flexiid; } //we set this value in the session $session->set('flexi_countries', $flexCategoriesCountries, 'JNEWLSETTER'); } else { $flexCategoriesIndustries = $session->get('flexi_industries', array(), 'JNEWLSETTER'); if (isset($flexCategoriesIndustries[$flexiid])) { unset($flexCategoriesIndustries[$flexiid]); } else { $flexCategoriesIndustries[$flexiid] = $flexiid; } //we set this value in the session $session->set('flexi_industries', $flexCategoriesIndustries, 'JNEWLSETTER'); } break; case 'articleContent': jNews_Mailing::getContent($artId, $contentType, $task, $tmplid); break; case 'dealContent': jNews_Mailing::getDeal($dealId, $dealType, $tmplid); break; case 'listpanel': $listType = JRequest::getVar('listype'); if ($listType == 1 || $listType == 7) { frontHTML::showPanel('list'); } break; case 'cancel': frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); break; case 'delete': JRequest::checkToken() or die('Invalid Token'); if (empty($mailingId)) { echo '<script> javascript:alert("' . _JNEWS_DELETE_MAILING . '"); javascript:history.go(-1); </script>'; } else { $d['mailing'] = jNews_Mailing::getOneMailing('', $mailingId, '', $new); echo jnews::printYN(jNews_Mailing::delete($d), @constant($GLOBALS[JNEWS . 'listname' . $d['mailing']->list_type]) . _JNEWS_SUCCESS_DELETED, _JNEWS_ERROR); frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); } break; case 'togle': // defined toggle for publish and unpublish of mailings $id = JRequest::getVar('mailingid'); $col = JRequest::getVar('col'); $mailingId = !empty($id) && !empty($col) ? $id : $mailingId; $task = !empty($mailingId) && !empty($col) ? $col : $task; switch ($task) { case 'publishMailing': $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new); jNews_Mailing::publishMailing($mailingId); break; case 'unpublishMailing': $mailing = jNews_Mailing::getOneMailing('', $mailingId, '', $new); jNews_Mailing::unpublishMailing($mailingId); break; default: break; } echo '<script> javascript:history.go(-1); </script>'; break; case 'edit': if ($GLOBALS[JNEWS . 'enable_jsub']) { if (!empty($my->id)) { $ownedlists = jNews_Lists::getOwnedlists($my->id); } if (!empty($ownedlists) || jnews::checkPermissions('admin')) { if (empty($mailingId)) { echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>'; } else { frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing'); //savemailing } } } else { //edit a mailing $canAccess = false; if (class_exists('jNews_Pro') && !empty($listId)) { $list = jNews_Lists::getOneList($listId); $accessAuthorizedA = explode(',', $list->acc_id); if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') { if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $usergid = $my->gid; } else { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); } if (is_array($accessAuthorizedA)) { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $accessAuthorizedA); } else { if (!in_array($usergid, $accessAuthorizedA)) { $canAccess = false; } } } else { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $accessAuthorizedA); } else { if ($usergid != $accessAuthorizedA) { $canAccess = false; } } } } } //cehck if I am the owner of the list $archivemailing = jNews_Mailing::getOneMailing(0, $mailingId, 0, $new); if ($archivemailing->author_id == $my->id) { $canAccess = true; } if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) { if (empty($mailingId)) { echo '<script> javascript:alert("' . _JNEWS_SELECT_MAILING . '"); javascript:history.go(-1); </script>'; } else { frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', $canAccess); //savemailing } } } break; case 'new': case 'add': if ($GLOBALS[JNEWS . 'enable_jsub']) { if (!empty($my->id)) { $ownedlists = jNews_Lists::getOwnedlists($my->id); } if (!empty($ownedlists) || jnews::checkPermissions('admin')) { frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing'); //savemailing } } else { //$list = jNews_Lists::getOneList($listId); $canAccess = false; if (class_exists('jNews_Pro') && !empty($listId)) { $list = jNews_Lists::getOneList($listId); $accessAuthorizedA = explode(',', $list->acc_id); if (!is_array($accessAuthorizedA) || $accessAuthorizedA[0] != 'all') { if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $usergid = $my->gid; } else { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); } if (is_array($accessAuthorizedA)) { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $accessAuthorizedA); } else { if (!in_array($usergid, $accessAuthorizedA)) { $canAccess = false; } } } else { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $accessAuthorizedA); } else { if ($usergid != $accessAuthorizedA) { $canAccess = false; } } } } } if ($canAccess || jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) { frontEnd::mailingEdit($subscriberId, $mailingId, $listId, $listType, 'mailing', true); //savemailing } } break; case 'archive': if (class_exists('jNews_Pro')) { $list = jNews_Lists::getOneList($listId); $listIds = explode(',', $list->acc_id); if (!is_array($listIds) || $listIds[0] != 'all') { if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $usergid = $my->gid; } else { if (version_compare(JVERSION, '3.0.0', '>')) { //j3.0 $usergid = JAccess::getGroupsByUser($my->id, false); //this is huck for joomla >3.0 because if you check this link http://joomla.dev/administrator/index.php?option=com_config&view=component&component=com_users&return=aHR0cDovL2pvb21sYS5kZXYvYWRtaW5pc3RyYXRvci9pbmRleC5waHA%2Fb3B0aW9uPWNvbV91c2VycyZ2aWV3PWdyb3Vwcw%3D%3D //you will see Guest User Group = Public by default and into db table #__extensions where element == com_users => params => you will see guest_usergroup == 13 // but if you try to change user group in brovser to registered for example => save=>save again as public => check again db=> you will see guest_usergroup = 1 //i think it is joomla bug because if jommla woks fine needs to be 13 // thants why i created this "if" if ($usergid[0] === '13') { $usergid[0] = '1'; } } else { //j16 $usergid = JAccess::getGroupsByUser($my->id, false); } } if (is_array($listIds)) { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $listIds); if (empty($canAccess)) { break; } } else { if (!in_array($usergid, $listIds)) { break; } } } else { if (is_array($usergid)) { $canAccess = array_intersect($usergid, $listIds); if (empty($canAccess)) { break; } } else { if ($usergid != $listIds) { break; } } } } } frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, true, _JNEWS_MENU_VIEW_ARCHIVE . ' '); break; case 'save': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR); frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); break; case 'savepreview': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Mailing::saveMailing($mailingId, $listId), _JNEWS_MAILING_SAVED, _JNEWS_ERROR); case 'preview': case 'view': if ($mailingId != 0) { if ($listId > 0) { $archivemailing = jNews_Mailing::getMailingView($mailingId, $listId); } else { $archivemailing = jNews_Mailing::getMailingView($mailingId); } $list = jNews_Lists::getOneList($listId); $acc_level = $list->acc_level; jNews_ProcessMail::replaceClass($archivemailing->htmlcontent, $archivemailing->textonly); if (!empty($archivemailing->template_id)) { jNews_Templates::includeStyles($archivemailing->htmlcontent, $archivemailing->template_id); } $archivemailing->htmlcontent = str_replace('{tag:subscriptions}', '', $archivemailing->htmlcontent); $mainLink = JRoute::_('index.php?option=' . JNEWS_OPTION); $forms['main'] = '<form method="post" action="' . $mainLink . '" onsubmit="submitbutton();return false;" name="mosForm" >' . "\n\r"; $forms['main'] .= '<input type="hidden" name="Itemid" value="' . $Itemid . '" />'; //for view it online view $currentUrl = JURI::current(); $gid = !empty($GLOBALS[JNEWS . 'list_creatorfe']) ? $GLOBALS[JNEWS . 'list_creatorfe'] : 0; if (version_compare(JVERSION, '1.6.0', '<')) { $listsAddEdit = jNews_Lists::getIDswithacclevel($my->gid); } else { $groups = JAccess::getGroupsByUser($my->id); if (!$my->id) { $listsAddEdit = array(); } else { $listsAddEdit = jNews_Lists::getIDswithacclevel($groups); } } if (jnews::checkPermissions('admin') || jnews::checkPermissions($gid) || !empty($listsAddEdit)) { $menuA = array(); $onlyPreview = JRequest::getInt('onlypreview'); if (!$onlyPreview) { //menu Preview $menuNew = new stdClass(); $menuNew->popup = new stdClass(); $menuNew->popup->isPop = false; $menuNew->action = 'view'; $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=view&mailingid=' . $mailingId . '&onlypreview=1'); $menuNew->link = $linkBut; $menuNew->onclick = new stdClass(); $menuNew->onclick->custom = true; $menuNew->onclick->js = ''; $menuNew->title = _JNEWS_VIEW_BROWSER; $menuA['view'] = $menuNew; //menu edit $menuNew = new stdClass(); $menuNew->popup = new stdClass(); $menuNew->popup->isPop = false; $menuNew->action = 'edit'; $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=edit&mailingid=' . $mailingId . '&listype=' . $listType); $menuNew->link = $linkBut; $menuNew->onclick = new stdClass(); $menuNew->onclick->custom = true; $menuNew->onclick->js = ''; $menuNew->title = 'Edit'; $menuA['edit'] = $menuNew; //menu send $menuSend = new stdClass(); $menuSend->popup = new stdClass(); $menuSend->popup->isPop = true; $menuSend->popup->rel = true; $menuSend->popup->x = 750; $menuSend->popup->y = 500; $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=sendready&mailingid=' . $mailingId . '&listype=' . $listType, true, false, true); $menuSend->link = $linkBut; $menuSend->action = 'sendready'; $menuSend->onclick = new stdClass(); $menuSend->onclick->custom = false; $menuSend->onclick->js = ""; $menuSend->title = _JNEWS_MENU_SEND; $menuA['sendready'] = $menuSend; // menu back $menuBack = new stdClass(); $menuBack->popup = new stdClass(); $menuBack->popup = new stdClass(); $menuBack->popup->isPop = false; $menuBack->link = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing', false); $menuBack->action = 'back'; $menuBack->onclick = new stdClass(); $menuBack->onclick->custom = true; $menuBack->onclick->js = ''; $menuBack->title = _JNEWS_MENU_BACK; $menuA['back'] = $menuBack; } frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', $menuA); } else { //can be improved where we check if user can edit if (empty($archivemailing->visible) || empty($archivemailing->published) && $task == 'view') { echo '<center>Access to this mailing is restricted!<center>'; break; } frontHTML::formStart(_JNEWS_NEWSLETTER_ARCHIVE, 0, '', null); } jNews_MailingsHTML::viewMailing($archivemailing, $forms); $go[] = jnews::makeObj('act', 'mailing'); $go[] = jnews::makeObj('task', 'viewmailing'); $go[] = jnews::makeObj('listid', $archivemailing->list_id); frontHTML::formEnd('', $go); } else { frontHTML::FEmenu(); frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); } break; case 'sendready': //we update the senddate of the newsletter jNews_Mailing::updatesenddate($mailingId); jNews_MailingsHTML::sendReady($mailingId, $listId, $listType); break; case 'send': if (!(require_once JNEWSPATH_CLASS . 'class.queue.php')) { return false; } $queueC = new jNews_Queue(); $queueC->checkForNewsletters($mailingId); $queueCount = jNews_Queue::getQueueCount($mailingId); $totalSub = JRequest::setVar('totalsend', $queueCount); $linkBut = jNews_Tools::completeLink('option=' . JNEWS_OPTION . '&act=mailing&task=continuesend&mailingid=' . $mailingId . '&totalsend=' . $totalSub, true, false, true); jNews_Tools::redirect($linkBut); //this line was commented out, we need this so that when we click the send button in the frontend the status of the sending will be displayed break; case 'continuesend': if (require_once JNEWSPATH_CLASS . 'class.queue.php') { $queueC = new jNews_Queue(); $totalSend = JRequest::getVar('totalsend', 0, '', 'int'); $alreadySent = JRequest::getVar('alreadysent', 0, '', 'int'); $queueC->start = $alreadySent; $queueC->total = $totalSend; $queueC->pause = $GLOBALS[JNEWS . 'pause_time']; $queueC->sendQueue(false, $mailingId, false, true); } ob_start(); exit; break; case 'unpublished': JRequest::checkToken() or die('Invalid Token'); jNews_Mailing::unpublishMailing($mailingId); frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); break; case 'copy': JRequest::checkToken() or die('Invalid Token'); $message = jnews::printYN(jNews_Mailing::copyMailing($mailingId), _JNEWS_MAILING_COPY, _JNEWS_ERROR); if (empty($listId) or $listId == 0) { $lsid = jNews_Mailing::getListId($mailingId); } jNews_Mailing::insertListMailings($listId); frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, false, _JNEWS_MENU_MAILING); break; case 'cpanel': jNews_Tools::redirect('index.php?option=' . JNEWS_OPTION); break; default: //alex archive // $viewarchive = false; // if(empty($my->id)) $viewarchive = true; $viewarchive = true; frontEnd::showMailingsFront($task, $action, $subscriberId, $listId, $listType, $viewarchive, _JNEWS_MENU_MAILING); break; } return true; }
/** send emails * @param bool $showHTML show report on the screen * @param object $mailing contain the information of mailing * @param objectlist $receivers all receivers * @params $type (1-all types of mailings, 2-confirmation email) */ function send($oneQueue, $receiver) { // we should verify that the data we get is teh proper value if (!is_object($oneQueue)) { return false; } $tags = null; ### create the mail $mail = jNews_ProcessMail::getMailer($oneQueue); //$frompreview param is to determine if the sending is called by 'Send Test Email' if (empty($mail)) { return false; } $tags['issuenb'] = $oneQueue->issue_nb; ### create content $this->getContent($oneQueue->images, $oneQueue->htmlcontent, $oneQueue->textonly, $oneQueue->subject, true, false, $oneQueue); //new $oneQueue->subject if ($this->cancelMailing) { $this->cancelMailing = false; return true; // we return true even though the mail was not sent because empty. Need improvement... } if (!empty($receiver->user_id)) { $tags['user_id'] = $receiver->user_id; } //Forced HTML Mailing Only? if ($GLOBALS[JNEWS . 'forced_html']) { $receiver->receive_html = 1; } $tname = explode(" ", $receiver->name); $firstname = $tname[0]; $toUser = $GLOBALS[JNEWS . 'minisendmail'] ? '' : $receiver->name; $mail->AddAddress($receiver->email, $toUser); $username = empty($receiver->username) ? $firstname : $receiver->username; if (version_compare(JVERSION, '3.0.0', '<')) { $date = JHTML::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET); } else { $date = JHtml::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'), JNEWS_TIME_OFFSET); } $replaceWhat = array('{tag:name}', '{tag:firstname}', '{tag:username}', '{tag:date}'); $replaceBy = array($receiver->name, $firstname, $username, $date); $sujetReplaced = str_replace($replaceWhat, $replaceBy, $oneQueue->subject); if (class_exists('jNews_Auto')) { jNews_Auto::tags($sujetReplaced, $tags); } $mail->Subject = $sujetReplaced; if (!empty($oneQueue->html) && $receiver->receive_html) { $this->html = true; $mail->IsHTML(true); $ashtml = 1; $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->htmlcontent, $receiver, $oneQueue, $ashtml, $tags); $mail->AltBody = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags); //this line is added when jLinks is integrated with jNews //variables used in integration of jLinks static $mailCatID = null; static $convertedLinks = null; if (empty($oneQueue->mailing_type)) { $oneQueue->mailing_type = 1; } $mainframe = JFactory::getApplication(); JPluginHelper::importPlugin('jnews'); $jomsocial = $mainframe->triggerEvent('jnewsbot_jomsocial_members', array(&$mail->Body, &$mail->AltBody, $receiver)); $this->_linkReplacement($oneQueue->mailing_type, $oneQueue->id, $oneQueue->subject, $mail, $mailCatID, $convertedLinks, $receiver->id); jNews_ProcessMail::replaceClass($mail->Body, $mail->AltBody, $receiver); if (!empty($oneQueue->template_id)) { jNews_Templates::includeStyles($mail->Body, $oneQueue->template_id); } } else { //text only email $this->html = false; $mail->IsHTML(false); $mail->AltBody = ''; $ashtml = 0; $mail->Body = jNews_ProcessMail::replaceTags($oneQueue->textonly, $receiver, $oneQueue, $ashtml, $tags); $mail->AltBody = $this->_safe_utf8_encode($mail->Body, $mail->CharSet); $simpleText = ''; jNews_ProcessMail::replaceClass($mail->Body, $simpleText, $receiver); if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $imgfolders = DS . 'images' . DS . 'stories'; } else { //j16 $imgfolders = DS . 'images' . DS . 'sampledata'; } if (!empty($oneQueue->images)) { foreach ($oneQueue->images as $image) { $img = explode('|', $image); $attrib = explode("/", $img[0]); $path = JNEWS_JPATH_ROOT . $imgfolders; if (count($img) == 1) { $imageName = $img[0]; } else { $imageName = $attrib[count($attrib) - 1]; for ($index = 0; $index < sizeof($attrib) - 1; $index++) { $path .= $attrib[$index] . '/'; } } $mail->AddAttachment($path . $imageName); } //endofreach } } jNews_ProcessMail::normalizeURL($mail->Body); if (!empty($oneQueue->html) && $receiver->receive_html) { $this->_addHTMLTagToBody($mail->Body, $sujetReplaced); } if ($GLOBALS[JNEWS . 'embed_images']) { $this->_embedImages($mail); } $mail->addCustomHeader("X-SubscriberID: " . base64_encode($receiver->email)); // DKIM code addition by Amod begins $mail = $this->_addDKIM2($mail); // DKIM code addition by Amod ends $status = $mail->Send(); if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $mailErrorCount = $mail->error_count; } else { //j16 $mailErrorCount = !empty($mail->ErrorInfo) ? 1 : 0; } //we prompt message regarding the status of the sending if there is an error if (!empty($mail->ErrorInfo)) { echo '<br><span style="color:red;">' . $mail->ErrorInfo . '</span>'; } if ($status && $mailErrorCount < 1) { return true; } else { jNews_ProcessMail::failMailReason($mail); return false; } }