예제 #1
0
파일: lib.php 프로젝트: MarcelvC/phplist3
function parseLogoPlaceholders($content)
{
    ## replace Logo placeholders
    preg_match_all('/\\[LOGO\\:?(\\d+)?\\]/', $content, $logoInstances);
    foreach ($logoInstances[0] as $index => $logoInstance) {
        $size = sprintf('%d', $logoInstances[1][$index]);
        if (!empty($size)) {
            $logoSize = $size;
        } else {
            $logoSize = '500';
        }
        createCachedLogoImage($logoSize);
        $content = str_replace($logoInstance, 'ORGANISATIONLOGO' . $logoSize . '.png', $content);
    }
    return $content;
}
예제 #2
0
function precacheMessage($messageid, $forwardContent = 0)
{
    global $cached;
    $domain = getConfig('domain');
    #    $message = Sql_query("select * from {$GLOBALS["tables"]["message"]} where id = $messageid");
    #    $cached[$messageid] = array();
    #    $message = Sql_fetch_array($message);
    $message = loadMessageData($messageid);
    ## the reply to is actually not in use
    if (preg_match('/([^ ]+@[^ ]+)/', $message['replyto'], $regs)) {
        # if there is an email in the from, rewrite it as "name <email>"
        $message['replyto'] = str_replace($regs[0], '', $message['replyto']);
        $cached[$messageid]['replytoemail'] = $regs[0];
        # if the email has < and > take them out here
        $cached[$messageid]['replytoemail'] = str_replace('<', '', $cached[$messageid]['replytoemail']);
        $cached[$messageid]['replytoemail'] = str_replace('>', '', $cached[$messageid]['replytoemail']);
        # make sure there are no quotes around the name
        $cached[$messageid]['replytoname'] = str_replace('"', '', ltrim(rtrim($message['replyto'])));
    } elseif (strpos($message['replyto'], ' ')) {
        # if there is a space, we need to add the email
        $cached[$messageid]['replytoname'] = $message['replyto'];
        $cached[$messageid]['replytoemail'] = "listmaster@{$domain}";
    } else {
        if (!empty($message['replyto'])) {
            $cached[$messageid]['replytoemail'] = $message['replyto'] . "@{$domain}";
            ## makes more sense not to add the domain to the word, but the help says it does
            ## so let's keep it for now
            $cached[$messageid]['replytoname'] = $message['replyto'] . "@{$domain}";
        }
    }
    $cached[$messageid]['fromname'] = $message['fromname'];
    $cached[$messageid]['fromemail'] = $message['fromemail'];
    $cached[$messageid]['to'] = $message['tofield'];
    #0013076: different content when forwarding 'to a friend'
    $cached[$messageid]['subject'] = $forwardContent ? stripslashes($message['forwardsubject']) : $message['subject'];
    #0013076: different content when forwarding 'to a friend'
    $cached[$messageid]['content'] = $forwardContent ? stripslashes($message['forwardmessage']) : $message['message'];
    if (USE_MANUAL_TEXT_PART && !$forwardContent) {
        $cached[$messageid]['textcontent'] = $message['textmessage'];
    } else {
        $cached[$messageid]['textcontent'] = '';
    }
    #  var_dump($cached);exit;
    #0013076: different content when forwarding 'to a friend'
    $cached[$messageid]['footer'] = $forwardContent ? stripslashes($message['forwardfooter']) : $message['footer'];
    if (strip_tags($cached[$messageid]['footer']) != $cached[$messageid]['footer']) {
        $cached[$messageid]['textfooter'] = HTML2Text($cached[$messageid]['footer']);
        $cached[$messageid]['htmlfooter'] = $cached[$messageid]['footer'];
    } else {
        $cached[$messageid]['textfooter'] = $cached[$messageid]['footer'];
        $cached[$messageid]['htmlfooter'] = parseText($cached[$messageid]['footer']);
    }
    $cached[$messageid]['htmlformatted'] = strip_tags($cached[$messageid]['content']) != $cached[$messageid]['content'];
    $cached[$messageid]['sendformat'] = $message['sendformat'];
    if ($message['template']) {
        $req = Sql_Fetch_Row_Query("select template from {$GLOBALS['tables']['template']} where id = {$message['template']}");
        $cached[$messageid]['template'] = stripslashes($req[0]);
        $cached[$messageid]['templateid'] = $message['template'];
        #   dbg("TEMPLATE: ".$req[0]);
    } else {
        $cached[$messageid]['template'] = '';
        $cached[$messageid]['templateid'] = 0;
    }
    ## @@ put this here, so it can become editable per email sent out at a later stage
    $cached[$messageid]['html_charset'] = 'UTF-8';
    #getConfig("html_charset");
    ## @@ need to check on validity of charset
    if (!$cached[$messageid]['html_charset']) {
        $cached[$messageid]['html_charset'] = 'UTF-8';
        #'iso-8859-1';
    }
    $cached[$messageid]['text_charset'] = 'UTF-8';
    #getConfig("text_charset");
    if (!$cached[$messageid]['text_charset']) {
        $cached[$messageid]['text_charset'] = 'UTF-8';
        #'iso-8859-1';
    }
    ## if we are sending a URL that contains user attributes, we cannot pre-parse the message here
    ## but that has quite some impact on speed. So check if that's the case and apply
    $cached[$messageid]['userspecific_url'] = preg_match('/\\[.+\\]/', $message['sendurl']);
    if (!$cached[$messageid]['userspecific_url']) {
        ## Fetch external content here, because URL does not contain placeholders
        if ($GLOBALS['can_fetchUrl'] && preg_match("/\\[URL:([^\\s]+)\\]/i", $cached[$messageid]['content'], $regs)) {
            $remote_content = fetchUrl($regs[1], array());
            #  $remote_content = fetchUrl($message['sendurl'],array());
            # @@ don't use this
            #      $remote_content = includeStyles($remote_content);
            if ($remote_content) {
                $cached[$messageid]['content'] = str_replace($regs[0], $remote_content, $cached[$messageid]['content']);
                #  $cached[$messageid]['content'] = $remote_content;
                $cached[$messageid]['htmlformatted'] = strip_tags($remote_content) != $remote_content;
                ## 17086 - disregard any template settings when we have a valid remote URL
                $cached[$messageid]['template'] = null;
                $cached[$messageid]['templateid'] = null;
            } else {
                #print Error(s('unable to fetch web page for sending'));
                logEvent('Error fetching URL: ' . $message['sendurl'] . ' cannot proceed');
                return false;
            }
        }
        if (VERBOSE && !empty($GLOBALS['getspeedstats'])) {
            output('fetch URL end');
        }
        /*
        print $message['sendurl'];
        print $remote_content;exit;
        */
    }
    // end if not userspecific url
    if ($cached[$messageid]['htmlformatted']) {
        #   $cached[$messageid]["content"] = compressContent($cached[$messageid]["content"]);
    }
    $cached[$messageid]['google_track'] = $message['google_track'];
    /*
        else {
    print $message['sendurl'];
    exit;
    }
    */
    foreach ($GLOBALS['plugins'] as $plugin) {
        $plugin->processPrecachedCampaign($messageid, $cached[$messageid]);
    }
    if (VERBOSE && !empty($GLOBALS['getspeedstats'])) {
        output('parse config start');
    }
    /*
     * this is not a good idea, as it'll replace eg "unsubscribeurl" with a general one instead of personalised
     *   if (is_array($GLOBALS["default_config"])) {
      foreach($GLOBALS["default_config"] as $key => $val) {
        if (is_array($val)) {
          $cached[$messageid]['content'] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['content']);
          $cached[$messageid]["textcontent"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]["textcontent"]);
          $cached[$messageid]["textfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['textfooter']);
          $cached[$messageid]["htmlfooter"] = str_ireplace("[$key]",getConfig($key),$cached[$messageid]['htmlfooter']);
        }
      }
    }
    */
    if (VERBOSE && !empty($GLOBALS['getspeedstats'])) {
        output('parse config end');
    }
    ## ##17233 not that many fields are actually useful, so don't blatantly use all
    #  foreach($message as $key => $val) {
    foreach (array('subject', 'id', 'fromname', 'fromemail') as $key) {
        $val = $message[$key];
        if (!is_array($val)) {
            $cached[$messageid]['content'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['content']);
            $cached[$messageid]['textcontent'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['textcontent']);
            $cached[$messageid]['textfooter'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['textfooter']);
            $cached[$messageid]['htmlfooter'] = str_ireplace("[{$key}]", $val, $cached[$messageid]['htmlfooter']);
        }
    }
    if (preg_match('/##LISTOWNER=(.*)/', $cached[$messageid]['content'], $regs)) {
        $cached[$messageid]['listowner'] = $regs[1];
        $cached[$messageid]['content'] = str_replace($regs[0], '', $cached[$messageid]['content']);
    } else {
        $cached[$messageid]['listowner'] = 0;
    }
    if (!empty($cached[$messageid]['listowner'])) {
        $att_req = Sql_Query("select name,value from {$GLOBALS['tables']['adminattribute']},{$GLOBALS['tables']['admin_attribute']} where {$GLOBALS['tables']['adminattribute']}.id = {$GLOBALS['tables']['admin_attribute']}.adminattributeid and {$GLOBALS['tables']['admin_attribute']}.adminid = " . $cached[$messageid]['listowner']);
        while ($att = Sql_Fetch_Array($att_req)) {
            $cached[$messageid]['content'] = preg_replace("#\\[LISTOWNER." . strtoupper(preg_quote($att['name'])) . "\\]#", $att['value'], $cached[$messageid]['content']);
        }
    }
    $baseurl = $GLOBALS['website'];
    if (defined('UPLOADIMAGES_DIR') && UPLOADIMAGES_DIR) {
        ## escape subdirectories, otherwise this renders empty
        $dir = str_replace('/', '\\/', UPLOADIMAGES_DIR);
        $cached[$messageid]['content'] = preg_replace('/<img(.*)src="\\/' . $dir . '(.*)>/iU', '<img\\1src="' . $GLOBALS['public_scheme'] . '://' . $baseurl . '/' . UPLOADIMAGES_DIR . '\\2>', $cached[$messageid]['content']);
    }
    ## replace Logo placeholders
    foreach (array('content', 'template', 'htmlfooter') as $element) {
        preg_match_all('/\\[LOGO\\:?(\\d+)?\\]/', $cached[$messageid][$element], $logoInstances);
        foreach ($logoInstances[0] as $index => $logoInstance) {
            $size = sprintf('%d', $logoInstances[1][$index]);
            if (!empty($size)) {
                $logoSize = $size;
            } else {
                $logoSize = '500';
            }
            createCachedLogoImage($logoSize);
            $cached[$messageid][$element] = str_replace($logoInstance, 'ORGANISATIONLOGO' . $logoSize . '.png', $cached[$messageid][$element]);
        }
    }
    return 1;
}