$oLnk->setCustom("idnewsletter", $idnewsletter);
 $oMenu->setTitle($iMenu, $sName);
 $oMenu->setLink($iMenu, $oLnk);
 if ($perm->have_perm_area_action($area, "news_add_job") || $perm->have_perm_area_action($area, "news_create") || $perm->have_perm_area_action($area, "news_save")) {
     // Rights: If you are able to add a job, you should be able to test it
     //         If you are able to add or change a newsletter, you should be able to test it
     // Usability: If no e-mail has been specified, you can't send a test newsletter
     if (isValidMail($oNewsletter->get("newsfrom")) && $lIDCatArt > 0) {
         $sLnkSendTest = '<a title="' . $aMsg["SendTestTitle"] . '" href="javascript://" onclick="showSendTestMsg(' . $idnewsletter . ')"><img src="' . $cfg['path']['images'] . 'newsletter_sendtest_16.gif" border="0" title="' . $aMsg["SendTestTitle"] . '" alt="' . $aMsg["SendTestTitle"] . '" /></a>';
     } else {
         $sLnkSendTest = '<img src="' . $cfg['path']['images'] . 'newsletter_sendtest_16_off.gif" border="0" title="' . $aMsg["SendTestTitleOff"] . '" alt="' . $aMsg["SendTestTitleOff"] . '" />';
     }
     $oMenu->setActions($iMenu, 'test', $sLnkSendTest);
 }
 if ($perm->have_perm_area_action($area, "news_add_job")) {
     if (isValidMail($oNewsletter->get("newsfrom")) && $lIDCatArt > 0) {
         $oLnkAddJob = new Link();
         $oLnkAddJob->setMultiLink("news", "", "news", "news_add_job");
         $oLnkAddJob->setCustom("idnewsletter", $idnewsletter);
         $oLnkAddJob->setAlt($aMsg["AddJobTitle"]);
         $oLnkAddJob->setContent('<img src="' . $cfg['path']['images'] . 'newsletter_dispatch_16.gif" border="0" title="' . $aMsg["AddJobTitle"] . '" alt="' . $aMsg["AddJobTitle"] . '">');
         $sLnkAddJob = $oLnkAddJob->render();
     } else {
         $sLnkAddJob = '<img src="' . $cfg['path']['images'] . 'newsletter_dispatch_16_off.gif" border="0" title="' . $aMsg["AddJobTitleOff"] . '" alt="' . $aMsg["AddJobTitleOff"] . '" />';
     }
     $oMenu->setActions($iMenu, 'dispatch', $sLnkAddJob);
 }
 if ($perm->have_perm_area_action($area, "news_create")) {
     $oLnkCopy = new Link();
     $oLnkCopy->setMultiLink("news", "", "news", "news_duplicate");
     $oLnkCopy->setCustom("idnewsletter", $idnewsletter);
    $recipient = new Recipient();
    $oPage->setReload();
} else {
    $recipient = new Recipient($idrecipient);
}
if ($recipient->virgin == false && $recipient->get("idclient") == $client && $recipient->get("idlang") == $lang) {
    if ($action == "recipients_save" && $perm->have_perm_area_action($area, $action)) {
        $oPage->setReload();
        $aMessages = array();
        $name = stripslashes($name);
        $email = stripslashes($email);
        $confirmed = (int) $confirmed;
        $deactivated = (int) $deactivated;
        $newstype = (int) $newstype;
        $recipient->set("name", $name);
        if (!isValidMail($email)) {
            $aMessages[] = i18n("Please specify a valid e-mail address", $plugin_name);
        } else {
            $email = strtolower($email);
            // e-mail always in lower case
            if ($recipient->get("email") != $email) {
                $oRecipients->resetQuery();
                $oRecipients->setWhere("email", $email);
                $oRecipients->setWhere("idclient", $client);
                $oRecipients->setWhere("idlang", $lang);
                $oRecipients->setWhere($recipient->primaryKey, $recipient->get($recipient->primaryKey), "!=");
                $oRecipients->query();
                if ($oRecipients->next()) {
                    $aMessages[] = i18n("Could not set new e-mail adress: Other recipient with same e-mail address already exists", $plugin_name);
                } else {
                    $recipient->set("email", $email);
 /**
  * Sends test newsletter directly to specified recipients (single or group)
  *
  * Note: Sending in chunks not supported! Only usable for tests and only a few
  * recipients.
  *
  * @param integer  $iIDCatArt     idcatart of newsletter handler article
  * @param integer  $iIDNewsRcp    If specified, newsletter recipient id, ignored, if group specified
  * @param integer  $iIDNewsGroup  If specified, newsletter recipient group id
  * @param array    $aSendRcps     As reference: Filled with a list of succesfull recipients
  * @param string   $sEncoding     Message (and header) encoding, e.g. iso-8859-1
  */
 public function sendDirect($iIDCatArt, $iIDNewsRcp = false, $iIDNewsGroup = false, &$aSendRcps, $sEncoding = "iso-8859-1")
 {
     global $lang, $client, $cfg, $cfgClient, $contenido, $recipient;
     // Initialization
     $aMessages = array();
     $oLanguage = new cApiLanguage($lang);
     $sFormatDate = $oLanguage->getProperty("dateformat", "date");
     $sFormatTime = $oLanguage->getProperty("dateformat", "time");
     unset($oLanguage);
     if ($sFormatDate == "") {
         $sFormatDate = 'Y-m-d';
     }
     if ($sFormatTime == "") {
         $sFormatTime = 'h:i a';
     }
     #$sPath = $cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang."&idcatart=".$iIDCatArt."&";
     $sPath = Contenido_Url::getInstance()->build(array('idcatart' => $iIDCatArt, 'client' => $client, 'lang' => $lang), true);
     $sPath .= strpos($sPath, '?') === false ? '?' : '&';
     // Get newsletter data
     $sFrom = $this->get("newsfrom");
     $sFromName = $this->get("newsfromname");
     if ($sFromName == "") {
         $sFromName = $sFrom;
     }
     $sSubject = $this->get("subject");
     $sMessageText = $this->get("message");
     $bIsHTML = false;
     if ($this->get("type") == "html") {
         $sMessageHTML = $this->getHTMLMessage();
         if ($sMessageHTML === false) {
             // There was a problem getting the html message (maybe article
             // deleted). Exit with error instead of sending as text message only
             if ($contenido) {
                 // Use i18n only in backend
                 $sError = i18n("Newsletter could not be sent: No html message available", $plugin_name);
             } else {
                 $sError = "Newsletter could not be sent: No html message available";
             }
             $this->_sError = $sError;
             return false;
         } else {
             $bIsHTML = true;
         }
     }
     // Preventing double lines in mail, you may wish to disable this function on windows servers
     if (!getSystemProperty("newsletter", "disable-rn-replacement")) {
         $sMessageText = str_replace("\r\n", "\n", $sMessageText);
     }
     // Single replacements
     // Replace message tags (text message)
     $this->_replaceTag($sMessageText, false, "date", date($sFormatDate));
     $this->_replaceTag($sMessageText, false, "time", date($sFormatTime));
     // Replace message tags (html message)
     if ($bIsHTML) {
         $this->_replaceTag($sMessageHTML, true, "date", date($sFormatDate));
         $this->_replaceTag($sMessageHTML, true, "time", date($sFormatTime));
     }
     // Enabling plugin interface
     if (getSystemProperty("newsletter", "newsletter-recipients-plugin") == "true") {
         $bPluginEnabled = true;
         $aPlugins = array();
         if (is_array($cfg['plugins']['recipients'])) {
             foreach ($cfg['plugins']['recipients'] as $sPlugin) {
                 plugin_include("recipients", $sPlugin . "/" . $sPlugin . ".php");
                 if (function_exists("recipients_" . $sPlugin . "_wantedVariables")) {
                     $aPlugins[$sPlugin] = call_user_func("recipients_" . $sPlugin . "_wantedVariables");
                 }
             }
         }
     } else {
         setSystemProperty("newsletter", "newsletter-recipients-plugin", "false");
         $bPluginEnabled = false;
     }
     $aRecipients = array();
     if ($iIDNewsGroup !== false) {
         $oGroupMembers = new RecipientGroupMemberCollection();
         $aRecipients = $oGroupMembers->getRecipientsInGroup($iIDNewsGroup, false);
     } else {
         if ($iIDNewsRcp !== false) {
             $aRecipients[] = $iIDNewsRcp;
         }
     }
     $iCount = count($aRecipients);
     if ($iCount > 0) {
         $this->_replaceTag($sMessageText, false, "number", $iCount);
         // Replace message tags (html message)
         if ($bIsHTML) {
             $this->_replaceTag($sMessageHTML, true, "number", $iCount);
         }
         foreach ($aRecipients as $iID) {
             $sRcpMsgText = $sMessageText;
             $sRcpMsgHTML = $sMessageHTML;
             // Don't change name of $recipient variable as it is used in plugins!
             $recipient = new Recipient();
             $recipient->loadByPrimaryKey($iID);
             $sEMail = $recipient->get("email");
             $sName = $recipient->get("name");
             if (empty($sName)) {
                 $sName = $sEMail;
             }
             $sKey = $recipient->get("hash");
             $bSendHTML = false;
             if ($recipient->get("news_type") == 1) {
                 $bSendHTML = true;
                 // Recipient accepts html newsletter
             }
             $this->_replaceTag($sRcpMsgText, false, "name", $sName);
             $this->_replaceTag($sRcpMsgText, false, "unsubscribe", $sPath . "unsubscribe=" . $sKey);
             $this->_replaceTag($sRcpMsgText, false, "change", $sPath . "change=" . $sKey);
             $this->_replaceTag($sRcpMsgText, false, "stop", $sPath . "stop=" . $sKey);
             $this->_replaceTag($sRcpMsgText, false, "goon", $sPath . "goon=" . $sKey);
             // Replace message tags (html message)
             if ($bIsHTML && $bSendHTML) {
                 $this->_replaceTag($sRcpMsgHTML, true, "name", $sName);
                 $this->_replaceTag($sRcpMsgHTML, true, "unsubscribe", $sPath . "unsubscribe=" . $sKey);
                 $this->_replaceTag($sRcpMsgHTML, true, "change", $sPath . "change=" . $sKey);
                 $this->_replaceTag($sRcpMsgHTML, true, "stop", $sPath . "stop=" . $sKey);
                 $this->_replaceTag($sRcpMsgHTML, true, "goon", $sPath . "goon=" . $sKey);
                 # Link to online article -->
                 if (!is_object($db)) {
                     $db = new DB_Contenido();
                 }
                 $sql = 'SELECT idart
                         FROM ' . $cfg['tab']['news'] . '
                         WHERE (idnews=' . $this->get('idnews') . ')';
                 $db->query($sql);
                 $db->next_record();
                 $news_idart = $db->f('idart');
                 $link = Contenido_Url::getInstance()->build(array('idart' => $news_idart, 'client' => $this->get('idclient'), 'lang' => $this->get("idlang"), 'rcp' => $sKey), true);
                 $p1 = strpos($sMessageHTML, '<body');
                 if ($p1 !== false) {
                     $p1 = strpos($sMessageHTML, '>', $p1) + 1;
                 } else {
                     $p1 = 0;
                 }
                 $sOnlineText = getEffectiveSetting('newsletter-online-text', $this->get("idlang"), 'If the newsletter is not shown properly, please click here to view the online version.');
                 $sMessageHTML = substr($sMessageHTML, 0, $p1) . '<div style="text-align: center; background-color: #FFF;"><a href="' . $link . '" style="font-weight: bold;">' . $sOnlineText . '</a></div>' . substr($sMessageHTML, $p1);
                 # <-- Link to online article
                 // Remove base tag
                 $sMessageHTML = preg_replace('/<base href=(.*?)>/is', '', $sMessageHTML, 1);
                 // Fix source path
                 // TODO: Test any URL specification that may exist under the sun...
                 $sMainURL = Contenido_Url::getInstance()->build(array('idcat' => getEffectiveSetting('navigation', 'idcat-home', 1), 'client' => $this->get('idclient'), 'lang' => $this->get("idlang")), true);
                 $sSelfURL = Contenido_Url::getInstance()->build(array('idart' => $this->get("idart"), 'client' => $this->get('idclient'), 'lang' => $this->get("idlang")), true);
                 $sMessageHTML = preg_replace("/(href|src)\\=(\"|\\')([^(http|#)])(\\/)?/", "\$1=" . "\$2" . $sMainURL . "\$3", $sMessageHTML);
                 $sMessageHTML = preg_replace('/url\\([\\"\'](.*)[\\"\']\\)/', 'url(\'' . $sMainURL . '$1\')', $sMessageHTML);
                 $sMessageHTML = str_replace('/cms//', '/', $sMessageHTML);
                 // Now replace anchor tags to the newsletter article itself just by the anchor
                 $sMessageHTML = preg_replace("/(href|src)\\=(\"|\\')" . str_replace('/', '\\/', $sSelfURL) . "(.*)#(.*)(\"|\\')/", "\$1=" . "\$2" . "#" . "\$4" . "\$5", $sMessageHTML);
                 // Now correct mailto tags
                 $sMessageHTML = str_replace($sMainURL . 'mailto:', 'mailto:', $sMessageHTML);
                 # Remove the <noscript> info from the newsletter message
                 $sMessageHTML = str_replace(array('This website is powered by drugCMS, the Content Management System with addictive potential.', 'For more info and download visit <a href="http://www.drugcms.org">www.drugcms.org</a>.', 'drugCMS is made in Germany.'), '', $sMessageHTML);
             }
             if ($bPluginEnabled) {
                 foreach ($aPlugins as $sPlugin => $aPluginVar) {
                     foreach ($aPluginVar as $sPluginVar) {
                         // Replace tags in text message
                         $this->_replaceTag($sRcpMsgText, false, $sPluginVar, call_user_func("recipients_" . $sPlugin . "_getvalue", $sPluginVar));
                         // Replace tags in html message
                         if ($bIsHTML && $bSendHTML) {
                             $this->_replaceTag($sRcpMsgHTML, true, $sPluginVar, call_user_func("recipients_" . $sPlugin . "_getvalue", $sPluginVar));
                         }
                     }
                 }
             }
             if (strlen($sKey) != 30) {
                 // Prevents sending without having a key
                 if ($contenido) {
                     // Use i18n only in backend
                     $sError = i18n("Newsletter to %s could not be sent: Recipient has an incompatible or empty key", $plugin_name);
                 } else {
                     $sError = "Newsletter to %s could not be sent: Recipient has an incompatible or empty key";
                 }
                 $aMessages[] = $sName . " (" . $sEMail . "): " . sprintf($sError, $sEMail);
             } else {
                 if (!isValidMail($sEMail)) {
                     if ($contenido) {
                         // Use i18n only in backend
                         $sError = i18n("Newsletter to %s could not be sent: No valid e-mail address specified", $plugin_name);
                     } else {
                         $sError = "Newsletter to %s could not be sent: No valid e-mail address specified";
                     }
                     $aMessages[] = $sName . " (" . $sEMail . "): " . sprintf($sError, $sEMail);
                 } else {
                     $oMail = new PHPMailer();
                     $oMail->CharSet = $sEncoding;
                     $oMail->IsHTML($bIsHTML && $bSendHTML);
                     $oMail->From = $sFrom;
                     $oMail->FromName = $sFromName;
                     $oMail->AddAddress($sEMail);
                     # Mailer Configuration -->
                     $sMailer = strtolower(getEffectiveSetting('newsletter', 'mailer'));
                     $sHost = getEffectiveSetting('newsletter', 'host');
                     $iPort = intval(getEffectiveSetting('newsletter', 'port'));
                     $sUsername = getEffectiveSetting('newsletter', 'username');
                     $sPassword = getEffectiveSetting('newsletter', 'password');
                     if (strlen($sMailer) == 0) {
                         $sMailer = strtolower(getEffectiveSetting('email', 'mailer'));
                         $sHost = getEffectiveSetting('email', 'host');
                         $iPort = intval(getEffectiveSetting('email', 'port'));
                         $sUsername = getEffectiveSetting('email', 'username');
                         $sPassword = getEffectiveSetting('email', 'password');
                     }
                     if (strlen($sMailer) == 0) {
                         setClientProperty('email', 'mailer', 'mail');
                         $sMailer = 'mail';
                     }
                     if (strlen($sHost) == 0) {
                         setClientProperty('email', 'host', '');
                     }
                     if ($iPort == 0) {
                         setClientProperty('email', 'port', '25');
                         $iPort = 25;
                     }
                     if (strlen($sUsername) == 0) {
                         setClientProperty('email', 'username', '');
                     }
                     if (strlen($sPassword) == 0) {
                         setClientProperty('email', 'password', '');
                     }
                     $oMail->Mailer = $sMailer;
                     if ($sMailer == 'smtp') {
                         $oMail->SMTPAuth = true;
                         $oMail->Host = $sHost;
                         $oMail->Port = $iPort;
                         $oMail->Username = $sUsername;
                         $oMail->Password = $sPassword;
                     }
                     # <-- Mailer Configuration
                     $oMail->Subject = $sSubject;
                     if ($bIsHTML && $bSendHTML) {
                         $oMail->Body = $sRcpMsgHTML;
                         $oMail->AltBody = $sRcpMsgText . "\n\n";
                     } else {
                         $oMail->Body = $sRcpMsgText . "\n\n";
                     }
                     if ($oMail->Send()) {
                         $aSendRcps[] = $sName . " (" . $sEMail . ")";
                     } else {
                         if ($contenido) {
                             // Use i18n only in backend
                             $sError = i18n("Newsletter to %s could not be sent", $plugin_name);
                         } else {
                             $sError = "Newsletter to %s could not be sent";
                         }
                         $aMessages[] = $sName . " (" . $sEMail . "): " . sprintf($sError, $sEMail);
                     }
                 }
             }
         }
     } else {
         if ($contenido) {
             // Use i18n only in backend
             $sError = i18n("No recipient with specified recipient/group id %s/%s found", $plugin_name);
         } else {
             $sError = "No recipient with specified recpient/group id %s/%s found";
         }
         $aMessages[] = sprintf($sError, $iIDNewsRcp, $iIDNewsGroup);
     }
     if (count($aMessages) > 0) {
         $this->_sError = implode("<br />", $aMessages);
         return false;
     } else {
         return true;
     }
 }
Пример #4
0
ob_start();
include_once '_includes/functions.php';
include_once '_includes/init.php';
$email = trim(strip_tags($_POST['email']));
$mailError = 'Adresse mail invalid';
$errors = array();
if (!empty($_POST)) {
    $link = 'http://romaindubay.be/php/mailinglist/confirmation.php/?email=' . $email;
    // $link = 'http://localhost:8888/php:mailinglist/confirmation.php/?email='.$email;
    if ($_POST['messagespam'] != '') {
        die("Tu n'es pas humain!");
    } else {
        if (empty($_POST['email'])) {
            $errors['mail'] = $mailError;
        } else {
            if (isValidMail($email) == false) {
                $errors['mail'] = $mailError;
            }
        }
    }
    if (empty($errors)) {
        // $time =  date("Y-m-d h:i:s");
        $time = time();
        $sql = 'INSERT INTO users(mail, role, time, valid)
			VALUES(:mail, :role, :time, :valid)';
        $preparedStatement = $connexion->prepare($sql);
        $preparedStatement->bindValue(':mail', $email);
        $preparedStatement->bindValue(':role', 'lecteur');
        $preparedStatement->bindValue(':time', $time);
        $preparedStatement->bindValue(':valid', '0');
        if ($preparedStatement->execute()) {
 } else {
     $sEMail = trim($aParts[$aFieldDetails["email"]["col"]]);
     if ($aFieldDetails["name"]["col"] > -1) {
         $sName = trim($aParts[$aFieldDetails["name"]["col"]]);
         if ($sName == "") {
             $sName = $sEMail;
         }
     } else {
         $sName = $sEMail;
     }
     if ($sEMail == "") {
         $aMessage[] = sprintf(i18n("Item with empty mail address found, item ignored (name: %s, row: %s)", $plugin_name), $sName, $iRow);
         $aInvalidLines[] = $sLine;
         $iInvalid++;
     } else {
         if (!isValidMail($sEMail)) {
             $aMessage[] = sprintf(i18n("Mail address '%s' is invalid, item ignored (row: %s)", $plugin_name), $sEMail, $iRow);
             $aInvalidLines[] = $sLine;
             $iInvalid++;
         } else {
             if ($oRecipients->emailExists($sEMail)) {
                 $aMessage[] = sprintf(i18n("Recipient with mail address '%s' already exists, item skipped (row: %s)", $plugin_name), $sEMail, $iRow);
                 $aInvalidLines[] = $sLine;
                 $iDublettes++;
             } else {
                 unset($sLine);
                 // Must be $recipient for plugins
                 if ($recipient = $oRecipients->create($sEMail, $sName, 0, '', 0, false)) {
                     $iID = $recipient->get($recipient->primaryKey);
                     $iAdded++;
                     unset($aPluginValue);