Difference between revisions of "Email-article.php"

From Organic Design wiki
m
(process Contact List if present)
Line 1: Line 1:
 
<?
 
<?
 +
 +
# 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;
 +
}
 +
 
if ($event == 'data') {
 
if ($event == 'data') {
 +
 +
# If a Contact List is specified, convert to a normal csv list
 +
if (xwGetProperty($properties, 'sendarticle/list', $list)) {
 +
$list = xweaListCat($properties, $list);
 +
$list = str_replace('*[[', '', trim($list));
 +
$list = str_replace(']]', '', $list);
 +
$list = str_replace("\n", ';', $list);
 +
$GLOBALS['sa-email'] = $list;
 +
}
  
 
if (xwGetProperty($properties, 'sendarticle/sent', $sent)) {
 
if (xwGetProperty($properties, 'sendarticle/sent', $sent)) {
if (ereg('@',$sent)) xwMessage("Article sent to $sent", 'green');
+
if (!ereg('^ERROR',$sent)) xwMessage("Article sent to $sent", 'green');
else xwMessage("Error sending article: $sent", 'red');
+
else xwMessage($sent, 'red');
 
}
 
}
  
Line 19: Line 36:
 
if (in_array('postmasters', $GLOBALS['xwUserGroups'])) {
 
if (in_array('postmasters', $GLOBALS['xwUserGroups'])) {
 
# Get available mail-lists from Contact Lists category using List-Cat code
 
# Get available mail-lists from Contact Lists category using List-Cat code
xwSetProperty($properties, 'list-cat', 'Contact Lists');
+
$lists = xweaListCat($properties, 'Contact Lists');
$tmp = $article;
+
$lists = str_replace('*[[', '<option>', $lists);
$article = "<option selected>or select a Contact List</option>\n";
 
eval( '?>'.xwArticleContent('List-Cat.php').'<?' );
 
$lists = str_replace('*[[', '<option>', $article);
 
 
$lists = str_replace(']]', '</option>', $lists);
 
$lists = str_replace(']]', '</option>', $lists);
 +
$lists = "<option selected value=\"\">or select a Contact List</option>\n$lists";
 
$lists = " &nbsp; <select name=xpath:/properties/sendarticle:list>$lists</select>";
 
$lists = " &nbsp; <select name=xpath:/properties/sendarticle:list>$lists</select>";
$article = $tmp;
 
 
} else $lists = '';
 
} else $lists = '';
 
$article = "<form action=\"$script\" method=\"GET\">
 
$article = "<form action=\"$script\" method=\"GET\">
Line 35: Line 49:
 
$lists
 
$lists
 
&nbsp; <input type=checkbox value=no name=xpath:/properties/sendarticle:textonly><i>text-only</i>
 
&nbsp; <input type=checkbox value=no name=xpath:/properties/sendarticle:textonly><i>text-only</i>
<p><b>You can also include a message before the article here if you like:</b></p>
+
<br><br><b>You can also include a message before the article here if you like:</b>
 
<textarea name=xpath:/properties/sendarticle:msg rows=5 cols=30></textarea>
 
<textarea name=xpath:/properties/sendarticle:msg rows=5 cols=30></textarea>
<br><input type=submit value=\" Send \">
+
<br><br><input type=submit value=\" Send \">
 
</form>";
 
</form>";
  
Line 71: Line 85:
  
 
# Send message and redirect client back to article or raise error
 
# Send message and redirect client back to article or raise error
$msg = $mail->Send() ?  $GLOBALS['sa-email'] : $mail->ErrorInfo;
+
$msg = $mail->Send() ?  $GLOBALS['sa-email'] : 'ERROR: '.$mail->ErrorInfo;
 
header("Location: $script?title=$utitle&xpath:/properties:data=$tTitle&xpath:/properties:sendarticle&xpath:/properties/sendarticle:sent=$msg");
 
header("Location: $script?title=$utitle&xpath:/properties:data=$tTitle&xpath:/properties:sendarticle&xpath:/properties/sendarticle:sent=$msg");
 
}
 
}
 
?>
 
?>

Revision as of 09:12, 26 January 2006

<?

  1. 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; }

if ($event == 'data') {

# If a Contact List is specified, convert to a normal csv list if (xwGetProperty($properties, 'sendarticle/list', $list)) { $list = xweaListCat($properties, $list); $list = str_replace('*[[', , trim($list)); $list = str_replace(']]', , $list); $list = str_replace("\n", ';', $list); $GLOBALS['sa-email'] = $list; }

if (xwGetProperty($properties, 'sendarticle/sent', $sent)) { if (!ereg('^ERROR',$sent)) xwMessage("Article sent to $sent", 'green'); else xwMessage($sent, 'red'); }

elseif (xwGetProperty($properties, 'sendarticle/to', $GLOBALS['sa-email'])) { # If mail not sent but we have details, prepare for sending on view event xwSetProperty($properties, 'xpath:/properties:view', 'class.phpmailer.php'); xwSetProperty($properties, 'xpath:/properties:view', $tTitle); $_REQUEST['printable'] = true; }

else { # Not sent and no details either, render input form 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 = str_replace('*[[', '<option>', $lists); $lists = str_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></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); xwGetProperty($properties, 'sendarticle/textonly', $textonly); if ($textonly) { $html = false; $article = "$msg\n\n".xwArticleContent( $title, true ); } else { $html = true; $msg = htmlentities($msg)."
Article source : <a href=\"$script/$utitle\">$script/$utitle</a>";

$article = str_replace($GLOBALS['xwMsgToken'], "$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); }

# Set up new mailer instance $mail = new PHPMailer(); $mail->From = $GLOBALS['wgUser']->mEmail; $mail->FromName = $GLOBALS['xwUserName']; $mail->IsHTML($html); foreach ( split('[,;]', $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 $msg = $mail->Send() ? $GLOBALS['sa-email'] : 'ERROR: '.$mail->ErrorInfo; header("Location: $script?title=$utitle&xpath:/properties:data=$tTitle&xpath:/properties:sendarticle&xpath:/properties/sendarticle:sent=$msg"); } ?>