Wie gesagt ich habe nach einer schnellen Lösung gesucht.
Ich weiss, ich gewinne damit keinen "Schönheitspreis" 😉 aber es funzt und war in überschauberer Zeit zu bewerkstelligen. Die SINNLOSE Suche nach etwas, was garnicht geht hatte einfach zu lang dauern müssen.
Die Grundlage für die Erstellung des "Live-Mailers" bildete das Cronjob-Script.
1. file anlegen: ext/chc_forum/mailer/mailer_on_the_fly.php
2. 2x includieren in: ext/chc_forum/pi1/class.tx_chcforum_form.php
zu 1.
<?php
// $dataArr = von includierenden Seite
# Uncomment this if you want to debug
$debug = false;
function getDebugInfo ($line,$str){
global $debug;
if($debug !== true ){
return;//set wen no debug
exit;
}
echo "\n<p style="\"color"><code>#".$line." :: ";
if(is_array($str))print_r($str);
else echo nl2br(htmlentities($str));
echo "</code></p>";
}
require_once('./typo3conf/localconf.php');
// set configuration for this message's forum.
//$pid comes from MotherScript
$fconf = getFconf( $pid );
if($fconf['mailer_disable']['vDEF'] == 1) die('');
if(isset($fconf['mailer_forum_url']['vDEF']))define("DOMAIN",$fconf['mailer_forum_url']['vDEF'].'index.php?id='.$pid );
else die('ERROR : KEINE DOMAIN');
if(isset($fconf['mailer_email']['vDEF']))define("MAIL_FROM", "FORUM-INFO<".$fconf['mailer_email']['vDEF'].">");
if(isset($dataArr['post_author'])){ // NEW POSTING
$mailArr=array(
'text'=>$dataArr["post_text"],
'subject'=>$dataArr["post_subject"],
'user_name'=>$dataArr["post_author_name"],
'user_email'=>$dataArr["post_author_email"] ,
'conference_id'=>$dataArr['conference_id'],
'thread_id'=>$dataArr['thread_id'],
'user_id'=>$dataArr['post_author']
);
}elseif($dataArr['thread_author']){//NEW THREAD
$arAuthor=getAuthor($dataArr['thread_author']);
$mailArr=array(
'text'=>$dataArr["thread_text"],
'subject'=>$dataArr["thread_subject"],
'user_name'=>$arAuthor['name'],
'user_email'=>$arAuthor['email'],
'conference_id'=>$dataArr['conference_id'],
'thread_id'=>$dataArr['thread_id'],
'user_id'=>$dataArr['thread_author']
);
}else{
$mailArr=array(
'text'=>'', 'subject'=>'', 'user_name'=>'', 'user_email'=>'', 'conference_id'=>'', 'thread_id'=>'', 'user_id'=>''
);
}
getDebugInfo(__LINE__,$dataArr);
getDebugInfo(__LINE__,$mailArr);
//-----------------------------
// Get the recipient list
$all_recipients = getRecipients($mailArr);
if($all_recipients){
getDebugInfo(__LINE__,$all_recipients);
// And build the message
$subject = 'NEW: '.$mailArr["subject"].' FROM: '.$mailArr["user_name"];
$day_time = getDayTime(time());
$this_message = makeMessage(
$mailArr["text"],
$mailArr["user_name"],
$mailArr["user_email"],
$day_time,
$mailArr['conference_id'],
$mailArr['thread_id'],
$mailArr['user_id']
);
$arIsSend=array();
// For each recipient, send the message.
foreach ($all_recipients as $recipient) {
if(!isset($arIsSend[$recipient["uid"]])){
$email = $recipient["email"];
$name = $recipient["name"];
if($name == '')$name = $recipient["username"];
if ($debug) {
getDebugInfo(__LINE__,
"Message is being sent to ".$recipient["email"]." : ".$recipient[name]."\n".$this_message.'');
}
// The line that actually sends the message!
mail("$name<$email>", $subject, $this_message,
"From: ".MAIL_FROM."\r\n" . "Reply-To: $email\r\n" . 'X-Mailer: PHP/' . phpversion());
$arIsSend[$recipient["uid"]]=true;
}
}
}
function makeMessage($text, $author_name, $author_email, $day_time, $conf_uid, $thread_uid, $user_id) {
global $fconf;
$message = $fconf['mailer_msg_tmpl']['vDEF'];
if(!$message) {
$message = "Posted by: {author_name}\n"
."Conference: {conference}\n"
."Thread: {thread}\n\n{text}\n\n\n"
."This message was sent because you have opted to receive new posts via email.\n"
."{link}";
}
$conference = getConference($conf_uid);
$thread = getThread($thread_uid);
$link_conf[view] = 'single_thread';
$link_conf[thread_uid] = $thread_uid;
$link_conf[linktext] = 'please click here';
$link = makeLink($link_conf);
$author_name = htmlspecialchars_decode($author_name);
$conference = htmlspecialchars_decode($conference);
$thread = htmlspecialchars_decode($thread);
$text = htmlspecialchars_decode($text);
// escape brackets
$author_name = str_replace('{','{/',$author_name);
$author_name = str_replace('}','\}',$author_name);
$conference =str_replace('{','{/',$conference);
$conference = str_replace('}','\}',$conference);
$thread = str_replace('{','{/',$thread);
$thread = str_replace('}','\}',$thread);
$text = str_replace('{','{/',$text);
$text = str_replace('}','\}',$text);
$message = str_replace('{author_name}',$author_name,$message);
$message = str_replace('{conference}',$conference,$message);
$message = str_replace('{thread}',$thread,$message);
$message = str_replace('{text}',$text,$message);
$message = str_replace('{link}',$link,$message);
$message = str_replace('{/','{',$message);
$message = str_replace('\}','}',$message);
return $message;
}
function makeLink($link_conf) {
global $fconf;
$internal_content = DOMAIN;
if ($link_conf['view'])$add_view = '&view='.makeHash($link_conf['view']);
else $add_view = '';
if ($link_conf['thread_uid'])$add_uid .= '&thread_uid='.makeHash($link_conf['thread_uid']);
if ($link_conf['linktext'])$add_ltext = $link_conf['linktext'];
$flag = '&flag=last';
$internal_content .= '&no_cache=1'.$add_view.$add_uid.$flag;
return $internal_content;
}
function htmlspecialchars_decode($value) {
$value = str_replace('>','>',$value);
$value = str_replace('<','<',$value);
$value = str_replace('"','"',$value);
$value = str_replace('&','&',$value);
return $value;
}
function getConference($id) {
$query = "SELECT conference_name FROM tx_chcforum_conference WHERE uid=$id";
$query_results = @mysql_query($query);
while ($name = @mysql_fetch_assoc($query_results)) {
$data_out = $name[conference_name];
}
return $data_out;
}
function getThread($id) {
$query = "SELECT thread_subject FROM tx_chcforum_thread WHERE uid=$id";
$query_results = @mysql_query($query);
while ($name = @mysql_fetch_assoc($query_results)) {
$data_out = $name[thread_subject];
}
return $data_out;
}
function getAuthor($author_id) {
$data_out=array('username'=>'','name'=>'','email'=>'');
$query = "SELECT username,name,email FROM fe_users WHERE uid=$author_id";
$query_results = @mysql_query($query);
while ($user = @mysql_fetch_assoc($query_results)) {
if($user['name']=='')$user['name']=$user['username'];
$data_out = $user;
getDebugInfo(__LINE__,$data_out);
}
return $data_out;
}
function getDayTime ($tstamp) {
$date = strftime('%b %d %Y', $tstamp);
return $date;
}
function getOneRecipient($feuser_uid) {
$query = "SELECT uid,username,usergroup,name,email FROM fe_users WHERE uid=$feuser_uid";
$query_results = @mysql_query($query);
$user = @mysql_fetch_assoc($query_results);
return $user;
}
function getRecipients( $message ) {
$data_out = array();
$uids = array();
#getDebugInfo(__LINE__,$mailArr);
// get recipients who are watching this conference
$query = "SELECT * from tx_chcforum_user_conf WHERE mailer_confs=".$message["conference_id"]."";
$results = mysql_query($query);
#echo mysql_error().$query ;
while ($uid = mysql_fetch_assoc($results)) {
$query = "SELECT uid,username,usergroup,name,email FROM fe_users WHERE uid=".$uid["user_uid"]."";
#getDebugInfo(__LINE__,$query);
$query_results = @mysql_query($query);
while ($user = @mysql_fetch_assoc($query_results)) {
//keine Mail an Poster selbst
if( $message["user_id"] != $user["uid"]
&& confAuth($user["usergroup"], $user["uid"], $message["conference_id"]) == 'true') {
//ersetze fuer email den nicht vorhandenen Namen durch Nick
if(!isset($user['name']) || trim($user['name'])=='')$user['name']=$user['username'];
$data_out[] = $user;
$uids[] = $user['uid'];
}
}
}
// get recipients who are watching this thread
$query = "SELECT * from tx_chcforum_user_thread WHERE mailer_threads=".$message["thread_id"]."";
#t3lib_div::debug($query);
$results = mysql_query($query);
while ($uid = mysql_fetch_assoc($results)) {
$query = "SELECT uid,username,usergroup,name,email FROM fe_users WHERE uid=".$uid["user_uid"];
#getDebugInfo(__LINE__.'?username ',$query);
$query_results = @mysql_query($query);
while ($user = @mysql_fetch_assoc($query_results)) {
#getDebugInfo(__LINE__,$user);
if (confAuth($user["usergroup"], $user["uid"], $message["conference_id"]) == 'true') {
if (!in_array($user['uid'],$uids)) $data_out[] = $user;
}
}
}
return $data_out;
}
/**
* This function returns true if the logged in user can access the conference with the uid
* of $conf_id. Returns false if user cannot access it -- we probably need to update this to
* reflect the changes that have been made to category access -- this should include a check
* of whether or not the user can access the parent category. Not a major problem, but something
* that should be fixed for the sake of consistency.
*
* @param [type] $user_groups: ...
* @param [type] $user_uid: ...
* @param [type] $conf_uid: ...
* @return [type] ...
*/
function confAuth($user_groups, $user_uid, $conf_uid) {
if (!empty($user_uid)) {
$user_authenticated = 0;
$group_authenticatede = 0;
$success = 'false';
$query = "SELECT * FROM tx_chcforum_conference WHERE uid=$conf_uid";
#getDebugInfo(__LINE__,$query);
$results = @mysql_query($query);
if (!empty($results)) {
while ($row = mysql_fetch_assoc($results)) {
if (!empty($row['auth_forumgroup_r'])) {
// Explode string containing the IDs of the forum groups that can view this conference
$groups = explode(',', $row['auth_forumgroup_r']);
// For each forumgroup attached to the conference, get the info for that forum
foreach ($groups as $value) {
$query1 = "SELECT * FROM tx_chcforum_forumgroup WHERE uid=$value";
$results1 = @mysql_query($query1);
// For each forum group, check and see if this user belongs to it
while ($row1 = mysql_fetch_assoc($results1)) {
// Do the auth for each forum
// Explode string containing users and groups for this forum group
$auth_users = explode(',', $row1['forumgroup_users']);
$auth_groups = explode(',', $row1['forumgroup_groups']);
$user_groups = explode(',', $user_groups);
// Does this user's ID along to the list of user IDs allowed to access this forum (as per the FG)?
if (in_array($user_uid, $auth_users)) {
$fg_user_authenticated = 1;
}
// Does this user belong to all the groups that belong to this forumgroup?
foreach ($auth_groups as $value) {
// For each of the groups belonging to this forumgroup, see if it is contained in the user_groups array
if (!in_array($value, $user_groups)) {
$fg_group_authenticated = 0;
break; // If the group isn't in the user_group array, stop this loop
} else {
// As long as the loop hasn't stopped, continue to authenticate
$fg_group_authenticated = 1;
}
}
}
// If, coming out of the authentication subroutine, the user is authenticated, set $auth to true. This value
// cannot be unset after this, since the user only needs to belong to one forum group to have access to the
// conference (although she must have access to all the groups within the forumgroup to be authenticated.
if ($fg_group_authenticated == 1 or $fg_user_authenticated == 1) {
$conf_auth = 1;
}
}
if ($conf_auth == 1) {
$success = 'true';
}
} else {
$success = 'true';
} // No user groups for the conference. Go ahead and authenticate
} // closes while loop
}
} else {
$success = 'false';
} // closes if loop
return $success;
} // closes function
// Makes a hash out of string -- used to obscure variable data passed through URL.
function makeHash($string) {
$hash = base64_encode(serialize($string));
#return $hash;
return $string;
}
/**
* [Describe function...]
*
* @param [type] $pid: ...
* @return [type] ...
*/
function getFconf($pid) {
# require_once("$path_to_t3lib_div");
// get the forum plugin record where starting pages value is the same
// as the pid for this message
$fields = 'tt_content.pid as forum_instance_pid,tt_content.pi_flexform AS flex';
$tables = 'tt_content';
$where = 'tt_content.list_type="chc_forum_pi1" AND tt_content.deleted=0 AND tt_content.pages='.$pid;
$query = "SELECT ".$fields." FROM ".$tables." WHERE ".$where;
$query_results = @mysql_query($query);
$row = @mysql_fetch_assoc($query_results);
#getDebugInfo(__LINE__.' ? PAGEinfo ? ',$row);
// if starting point didn't return any records, look for general records
// storage page.
if (!$row) {
$tables = 'tt_content LEFT JOIN pages ON tt_content.pid = pages.uid';
$where = 'tt_content.list_type="chc_forum_pi1" AND tt_content.deleted=0 AND pages.storage_pid='.$pid;
$query = "SELECT ".$fields." FROM ".$tables." WHERE ".$where;
$query_results = @mysql_query($query);
// note: it is convievable that someone would set up 2 forums, both pointing
// at the same storage folder. And it's possible that these forums will have
// different settings. However, in this case, we'll just use the first one
// that the mailer finds... I'm not sure how else to deal with this.
$row = @mysql_fetch_assoc($query_results);
}
if ($row['flex']) $flex_arr = t3lib_div::xml2array($row['flex']);
$flex_arr['data']['s_mailer']['lDEF']['forum_instance_pid'] = $row['forum_instance_pid'];
getDebugInfo(__LINE__.' ? t3lib ? ',$flex_arr['data']['s_mailer']['lDEF']);
return $flex_arr['data']['s_mailer']['lDEF'];
}
?>
zu 2.
switch ($this->where) {
case 'single_conf':
[...]
include_once('./typo3conf/ext/chc_forum/mailer/mailer_on_the_fly.php');//send mails
break;
case [...]
case 'single_post':
[...]
include_once('./typo3conf/ext/chc_forum/mailer/mailer_on_the_fly.php');//send mails
break;
case 'edit_post':
[...]
break;
}
Grüße,
Sven H.[/b]