Difference between revisions of "Email-article.php"

From Organic Design wiki
m
m
Line 87: Line 87:
 
# Send message and redirect client back to article or raise error
 
# Send message and redirect client back to article or raise error
 
if ($mail->Send()) {
 
if ($mail->Send()) {
 +
global $xwUserName;
 
$msg = count($GLOBALS['sa-email']).' recipient(s)';
 
$msg = count($GLOBALS['sa-email']).' recipient(s)';
 
xwLog("[[$title]] sent to $msg by [[$xwUserName]]");
 
xwLog("[[$title]] sent to $msg by [[$xwUserName]]");

Revision as of 00:35, 1 February 2007

<?

if ($event == 'data') {

# Capture the List-Cat.php functionality in this function function xweaListCat(&$properties, $cat) { xwSetProperty($properties, 'list-cat', $cat); eval( '?>'.xwArticleContent('List-Cat.php').'<?' ); return $article; }

# All done? if (xwGetProperty($properties, 'sendarticle/sent', $sent)) ereg('^ERROR', $sent) ? xwMessage($sent, 'red') : xwMessage("Article sent to $sent", 'green');

# If mail not sent, process form (prepare for sending on view-event) elseif (xwGetProperty($properties, 'sendarticle/to', $to)) {

# Put mailer-class-declaration and this transform onto view-stack xwSetProperty($properties, 'xpath:/properties:view', 'class.phpmailer.php'); xwSetProperty($properties, 'xpath:/properties:view', $tTitle); $_REQUEST['printable'] = true;

# If a Contact List is specified, extract email addressable from contact's articles $GLOBALS['sa-email'] = ereg('@',$to) ? split( '[,;]', $to ) : array(); if (xwGetProperty($properties, 'sendarticle/list', $list)) { $list = xweaListCat($properties, $list); $list = str_replace('*[[', , trim($list)); $list = str_replace(']]', , $list); foreach ( explode("\n", $list) as $contact ) { $contact = ereg_replace("\\|.+", , $contact); $content = xwArticleContent( $contact, true ); if (preg_match("/^\\*\\s*Email\\s*:\\s*\\[ \\]/im", $content, $m)) $GLOBALS['sa-email'][] = $m[1]; } } }

# Not sent and no details either, render input form else {

$msg = "

Email-article.php

\nArticle source : https://organicdesign.nz/Email-article.php\n"; # default message

xwSetProperty($properties, 'language', 'raw'); if (in_array('postmasters', $GLOBALS['xwUserGroups'])) { # Get available mail-lists from Contact Lists category using List-Cat code $lists = xweaListCat($properties, 'Contact Lists'); $lists = preg_replace("/\\*\\s*\\[\\[:Category:/", '<option>', $lists); $lists = preg_replace("/(\\|.+?)?]]/", '</option>', $lists); $lists = "<option selected value=\"\">or select a Contact List</option>\n$lists"; $lists = "   <select name=xpath:/properties/sendarticle:list>$lists</select>"; } else $lists = ; $article = "<form action=\"$script\" method=\"GET\"> <input type=hidden name=title value=\"$title\"> <input type=hidden name=xpath:/properties:data value=\"$tTitle\"> <input type=hidden name=xpath:/properties:sendarticle> <input type=text name=xpath:/properties/sendarticle:to size=30 value=\"Enter email address\"> $lists   <input type=checkbox value=no name=xpath:/properties/sendarticle:textonly>text-only

You can also include a message before the article here if you like: <textarea name=xpath:/properties/sendarticle:msg rows=5 cols=30>$msg</textarea>

<input type=submit value=\" Send \"></form>"; } } else { # Replace msg-token with user article url and msg $utitle = urlencode($title); xwGetProperty($properties, 'sendarticle/msg', $msg); if ( xwGetProperty($properties, 'sendarticle/textonly', $textonly) ) $article = "$msg\n\n".xwArticleContent($title, true); else { $article = str_replace($GLOBALS['xwMsgToken'], xwWikiParse($msg), $article); # Replace stylesheet-token with embedded stylesheets xwReplaceTokens($article, true); # Absoluterise relative urls Absolute url of wiki $article = str_replace('"/wiki/', '"http://'.$_SERVER['HTTP_HOST'].'/wiki/', $article); # Add margin $article = str_replace('<body ', '<body style="margin:8px" ', $article); }

# Set up new mailer instance $mail = new PHPMailer(); $mail->From = $GLOBALS['wgUser']->mEmail; $mail->FromName = $GLOBALS['xwUserName']; $mail->IsHTML(!$textonly); foreach ( $GLOBALS['sa-email'] as $i ) $mail->AddAddress( trim($i) ); $mail->Subject = $title; $mail->Body = $article;

# Send message and redirect client back to article or raise error if ($mail->Send()) { global $xwUserName; $msg = count($GLOBALS['sa-email']).' recipient(s)'; xwLog("$title sent to $msg by $xwUserName"); } else xwLog($msg = 'ERROR: '.$mail->ErrorInfo); header("Location: $script?title=$utitle&xpath:/properties:data=$tTitle&xpath:/properties:sendarticle&xpath:/properties/sendarticle:sent=$msg"); } ?>