Difference between revisions of "Email-article.php"

From Organic Design wiki
m
({{legacy}})
 
(70 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<?
+
{{legacy}}
 +
<php><?
 
if ($event == 'data') {
 
if ($event == 'data') {
  
if (xwGetProperty($properties, 'sendarticle/sent', $sent)) {
+
# Capture the List-Cat.php functionality in this function
if (ereg('@',$sent)) xwMessage("Article sent to $sent", 'green');
+
function xweaListCat(&$properties, $cat) {
else xwMessage("Error sending article: $sent", 'red');
+
xwSetProperty($properties, 'list-cat', $cat);
 +
eval( '?>'.xwArticleContent('List-Cat.php').'<?' );
 +
return $article;
 
}
 
}
  
elseif (xwGetProperty($properties, 'sendarticle/to', $GLOBALS['sa-email'])) {
+
# All done?
# If mail not sent but we have details, prepare for sending on view event
+
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', 'class.phpmailer.php');
 
xwSetProperty($properties, 'xpath:/properties:view', $tTitle);
 
xwSetProperty($properties, 'xpath:/properties:view', $tTitle);
 
$_REQUEST['printable'] = true;
 
$_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*\\[mailto:(.+?)[ \\]]/im", $content, $m))
 +
$GLOBALS['sa-email'][] = $m[1];
 +
}
 +
}
 
}
 
}
  
 +
# Not sent and no details either, render input form
 
else {
 
else {
# Not sent and no details either, render input form
+
$msg = "<h1 class=\"firstHeading\">{{FULLPAGENAME}}</h1>\nArticle source : {{SERVER}}/{{FULLPAGENAMEE}}\n"; # default message
 
xwSetProperty($properties, 'language', 'raw');
 
xwSetProperty($properties, 'language', 'raw');
 
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 = preg_replace("/\\*\\s*\\[\\[:Category:/", '<option>', $lists);
$article = "<option selected>or select a Contact List</option>\n";
+
$lists = preg_replace("/(\\|.+?)?]]/", '</option>', $lists);
eval( '?>'.xwArticleContent('List-Cat.php').'<?' );
+
$lists = "<option selected value=\"\">or select a Contact List</option>\n$lists";
$lists = str_replace('*[[', '<option>', $article);
 
$lists = str_replace(']]', '</option>', $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 33: Line 54:
 
<input type=hidden name=xpath:/properties:sendarticle>
 
<input type=hidden name=xpath:/properties:sendarticle>
 
<input type=text name=xpath:/properties/sendarticle:to size=30 value=\"Enter email address\">
 
<input type=text name=xpath:/properties/sendarticle:to size=30 value=\"Enter email address\">
$lists
+
$lists &nbsp; <input type=checkbox value=no name=xpath:/properties/sendarticle:textonly><i>text-only</i>
<br><br><input type=submit value=\" Send \">
+
<br><br><b>You can also include a message before the article here if you like:</b>
&nbsp; (<input type=checkbox value=no name=xpath:/properties/sendarticle:textonly>
+
<textarea name=xpath:/properties/sendarticle:msg rows=5 cols=30>$msg</textarea>
<i>text-only)</i><br><br>
+
<br><br><input type=submit value=\" Send \"></form>";
<p><b>You can also include a message before the article here if you like:</b></p>
 
<textarea name=xpath:/properties/sendarticle:msg rows=10 cols=50></textarea>
 
</form>";
 
 
 
 
}
 
}
 
}
 
}
Line 47: Line 64:
 
$utitle = urlencode($title);
 
$utitle = urlencode($title);
 
xwGetProperty($properties, 'sendarticle/msg', $msg);
 
xwGetProperty($properties, 'sendarticle/msg', $msg);
xwGetProperty($properties, 'sendarticle/textonly', $textonly);
+
if ( xwGetProperty($properties, 'sendarticle/textonly', $textonly) )
if ($textonly) {
+
$article = "$msg\n\n".xwArticleContent($title, true);
$html = false;
 
$article = "$msg\n\n".xwArticleContent( $title, true );
 
}
 
 
else {
 
else {
$html = true;
+
$article = str_replace($GLOBALS['xwMsgToken'], xwWikiParse($msg), $article);
$msg = htmlentities($msg)."<br>Article source : <a href=\"$script/$utitle\">$script/$utitle</a>";
 
$article = str_replace($GLOBALS['xwMsgToken'], "$msg<br><hr><br>", $article);
 
 
# Replace stylesheet-token with embedded stylesheets
 
# Replace stylesheet-token with embedded stylesheets
 
xwReplaceTokens($article, true);
 
xwReplaceTokens($article, true);
 
# Absoluterise relative urls Absolute url of wiki
 
# Absoluterise relative urls Absolute url of wiki
 
$article = str_replace('"/wiki/', '"http://'.$_SERVER['HTTP_HOST'].'/wiki/', $article);
 
$article = str_replace('"/wiki/', '"http://'.$_SERVER['HTTP_HOST'].'/wiki/', $article);
 +
# Add margin
 +
$article = str_replace('<body ', '<body style="margin:8px" ', $article);
 
}
 
}
  
Line 66: Line 80:
 
$mail->From = $GLOBALS['wgUser']->mEmail;
 
$mail->From = $GLOBALS['wgUser']->mEmail;
 
$mail->FromName = $GLOBALS['xwUserName'];
 
$mail->FromName = $GLOBALS['xwUserName'];
$mail->IsHTML($html);
+
$mail->IsHTML(!$textonly);
foreach ( split('[,;]', $GLOBALS['sa-email']) as $i ) $mail->AddAddress( trim($i) );
+
foreach ( $GLOBALS['sa-email'] as $i ) $mail->AddAddress( trim($i) );
 
$mail->Subject = $title;
 
$mail->Subject = $title;
 
$mail->Body = $article;
 
$mail->Body = $article;
  
 
# 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;
+
$title = preg_replace('/^(?=Category:)/i',':',$title);
 +
if ($mail->Send()) {
 +
global $xwUserName;
 +
$msg = count($GLOBALS['sa-email']).' recipient(s)';
 +
xwLog("[[$title]] sent to $msg by [[$xwUserName]]");
 +
} else xwLog($msg = "Error sending [[$title]] for [[$xwUserName]]: ".$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");
 
}
 
}
?>
+
?></php>

Latest revision as of 00:55, 26 May 2007

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.

<php><? 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 $title = preg_replace('/^(?=Category:)/i',':',$title); if ($mail->Send()) { global $xwUserName; $msg = count($GLOBALS['sa-email']).' recipient(s)'; xwLog("$title sent to $msg by $xwUserName"); } else xwLog($msg = "Error sending $title for $xwUserName: ".$mail->ErrorInfo); header("Location: $script?title=$utitle&xpath:/properties:data=$tTitle&xpath:/properties:sendarticle&xpath:/properties/sendarticle:sent=$msg"); } ?></php>