mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 22:27:34 +02:00
Added 'opt-in' admin news-trigger for emailing notifications to users.
This commit is contained in:
@@ -383,7 +383,9 @@ class news_admin_ui extends e_admin_ui
|
||||
'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'tab'=>2, 'data' => 'int' , 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'batch'=>true, 'filter'=>true),
|
||||
'news_allow_comments' => array('title' => NWSLAN_15, 'type' => 'boolean', 'tab'=>2, 'writeParms'=>'inverse=1', 'data' => 'int', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false,'batch'=>true, 'filter'=>true,'readParms'=>'reverse=1','writeParms'=>'inverse=1'),
|
||||
'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'tab'=>2, 'noedit'=>true, 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false),
|
||||
'submitted_id' => array('title' => LAN_NEWS_68, 'type' => 'hidden', 'data'=>false, 'writeParms'=>'show=1'),
|
||||
// admin_news_notify
|
||||
'news_email_notify' => array('title' => "Email notification", 'type' => 'checkbox', 'tab'=>2, 'data'=>false, 'writeParms'=>array('show'=>1), 'help'=>'Trigger an email notification when you submit this form.'),
|
||||
'submitted_id' => array('title' => LAN_NEWS_68, 'type' => 'hidden', 'tab'=>2, 'data'=>false, 'writeParms'=>'show=0'),
|
||||
'options' => array('title' => LAN_OPTIONS, 'type' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE)
|
||||
|
||||
);
|
||||
@@ -457,6 +459,11 @@ class news_admin_ui extends e_admin_ui
|
||||
public function afterCreate($new_data, $old_data, $id)
|
||||
{
|
||||
|
||||
if(!empty($_POST['news_email_notify']))
|
||||
{
|
||||
$this->triggerNotify($new_data);
|
||||
}
|
||||
|
||||
if(!empty($new_data['submitted_id']))
|
||||
{
|
||||
e107::getDb()->update('submitnews', "submitnews_auth = 1 WHERE submitnews_id = ".intval($new_data['submitted_id'])." LIMIT 1");
|
||||
@@ -475,6 +482,14 @@ class news_admin_ui extends e_admin_ui
|
||||
|
||||
public function afterUpdate($new_data, $old_data, $id)
|
||||
{
|
||||
|
||||
// e107::getMessage()->addInfo(print_a($new_data,true));
|
||||
|
||||
if(!empty($_POST['news_email_notify']))
|
||||
{
|
||||
$this->triggerNotify($new_data);
|
||||
}
|
||||
|
||||
$this->processPings();
|
||||
|
||||
e107::getEvent()->trigger('newsupd', $new_data);
|
||||
@@ -492,6 +507,27 @@ class news_admin_ui extends e_admin_ui
|
||||
|
||||
|
||||
|
||||
|
||||
// Trigger the news email notification trigger. (@see admin->notify )
|
||||
private function triggerNotify($new_data)
|
||||
{
|
||||
$visibility = explode(",", $new_data['news_class']);
|
||||
|
||||
if(in_array(e_UC_PUBLIC, $visibility))
|
||||
{
|
||||
e107::getEvent()->trigger('admin_news_notify',$new_data);
|
||||
e107::getMessage()->addSuccess("Email notification triggered");
|
||||
}
|
||||
else
|
||||
{
|
||||
e107::getMessage()->addWarning("News item visibility must include 'everyone' for email notifications to work.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function afterDelete()
|
||||
{
|
||||
$this->clearCache();
|
||||
@@ -592,6 +628,11 @@ class news_admin_ui extends e_admin_ui
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$this->fields['news_email_notify']['writeParms']['post'] = "<span class='radio inline'><a class='e-modal btn btn-mini btn-primary' data-modal-caption='".ADLAN_149."' href='notify.php?iframe=1&type=admin_news_notify#/tab-news-events'>".LAN_CONFIGURE."</a></span>";
|
||||
|
||||
|
||||
// e107::getMessage()->addDebug(print_a($_POST,true));
|
||||
|
||||
if($this->getAction() == 'create' || $this->getAction() == 'edit')
|
||||
|
@@ -36,6 +36,11 @@ $nc = new notify_config;
|
||||
$uc = new user_class;
|
||||
$mes = e107::getMessage();
|
||||
|
||||
if(!empty($_GET['iframe']))
|
||||
{
|
||||
define('e_IFRAME', true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($_POST['update']))
|
||||
@@ -228,7 +233,7 @@ class notify_config
|
||||
|
||||
|
||||
|
||||
$text2 = $frm->open('scanform', 'post', e_SELF); // <form action='".e_SELF."?results' method='post' id='scanform'>
|
||||
$text2 = $frm->open('scanform', 'post', e_REQUEST_URL); // <form action='".e_SELF."?results' method='post' id='scanform'>
|
||||
$text2 .= $frm->tabs($tab);
|
||||
$text2 .= "<div class='buttons-bar center'>". $frm->admin_button('update', LAN_UPDATE,'update') . "</div>";
|
||||
$text2 .= $frm->close();
|
||||
@@ -407,9 +412,11 @@ class notify_config
|
||||
}
|
||||
|
||||
|
||||
$highlight = varset($_GET['type']) == $id ? " class='text-warning'" : '';
|
||||
|
||||
$text = "
|
||||
<tr>
|
||||
<td title='".$id."'>".$description.": </td>
|
||||
<td title='".$id."'><span{$highlight}>".$description.":</span></td>
|
||||
<td class='form-inline nowrap'>
|
||||
".$uc->uc_dropdown('event['.$id.'][class]', varset($this->notify_prefs['event'][$id]['class'], e_UC_NOBODY), "nobody,main,admin,member,classes,email","onchange=\"mail_field(this.value,'event_".$id."');\" ");
|
||||
|
||||
@@ -429,7 +436,7 @@ class notify_config
|
||||
$text .= $frm->hidden("event[".$id."][include]", $include);
|
||||
$text .= $frm->hidden("event[".$id."][legacy]", $legacy); // function or method
|
||||
|
||||
if($this->notify_prefs['event'][$id]['class'] != e_UC_NOBODY)
|
||||
if(isset($this->notify_prefs['event'][$id]['class']) && $this->notify_prefs['event'][$id]['class'] != e_UC_NOBODY)
|
||||
{
|
||||
$text .= $frm->button('test['.$id.']', $id, 'confirm', 'Test');
|
||||
}
|
||||
|
@@ -203,8 +203,45 @@ $EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//
|
||||
body { padding:10px; background-color: #E1E1E1 }
|
||||
div#body { padding:10px; width: 93%; max-width:800px; background-color: #FFFFFF; border-radius: 5px; font-family: helvetica,arial }
|
||||
.video-thumbnail { max-width: 400px }
|
||||
.media img { max-width:200px; }
|
||||
td.body { padding:5px; vertical-align: top }
|
||||
.media img { max-width:200px; border-radius:5px }
|
||||
.text-right { text-align: right }
|
||||
.text-muted { color: #cccccc; }
|
||||
h1,h2,h3,h4 { margin-top:0; }
|
||||
h2 small { font-size: 50%; padding-left:20px }
|
||||
h2 { margin-bottom: 5px }
|
||||
h2 a { text-decoration: none; margin-bottom:5px }
|
||||
h4 { margin-bottom: 3px }
|
||||
a { color: #428BCA }
|
||||
.datestamp { float: right; padding-top:8px }
|
||||
.author { font-style: italic ; color: #cccccc}
|
||||
.summary { padding:5px 0; }
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 6px 12px;
|
||||
margin-bottom: 0px;
|
||||
margin-top:10px;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 1.42857;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
-moz-user-select: none;
|
||||
background-image: none;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
text-decoration: none;
|
||||
}
|
||||
.btn-primary {
|
||||
color: #FFF;
|
||||
background-color: #428BCA;
|
||||
border-color: #357EBD;
|
||||
}
|
||||
|
||||
td { padding:5px; vertical-align: top }
|
||||
td.media { width: 200px }
|
||||
table { width: 100%; margin-top:8px; border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc;padding:10px }
|
||||
.unsubscribe { font-size:11px; color:#aaaaaa; margin-top:20px; padding:20px 0; border-top:solid 1px #e5e5e5; }
|
||||
</style>
|
||||
</head>
|
||||
@@ -212,9 +249,10 @@ $EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//
|
||||
<body>
|
||||
<div id='body'>
|
||||
";
|
||||
$EMAIL_TEMPLATE['notify']['body'] = "<table><tr><td>{MEDIA1}</td><td class='body'>{BODY}</td></tr></table>";
|
||||
$EMAIL_TEMPLATE['notify']['body'] = "<h2>{SITENAME=link} <small class='text-muted datestamp'>{DATE_LONG}</small></h2><table><tr><td class='media'>{MEDIA1}</td><td>{BODY}</td></tr></table>";
|
||||
$EMAIL_TEMPLATE['notify']['footer'] = "<br /><br />
|
||||
{SITENAME=link}
|
||||
|
||||
|
||||
<div class='unsubscribe'>{UNSUBSCRIBE_MESSAGE}</div>
|
||||
</div>
|
||||
</body>
|
||||
|
@@ -66,7 +66,7 @@ class e107_event
|
||||
'admin_news_created' => NN_LAN_3,
|
||||
'admin_news_updated' => NN_LAN_4,
|
||||
'admin_news_deleted' => NN_LAN_5,
|
||||
'admin_news_subscribers' => "Notification of News Subscribers", // TODO LAN
|
||||
'admin_news_notify' => "News notification triggered", // TODO LAN
|
||||
'user_news_submit' => NN_LAN_2,
|
||||
|
||||
),
|
||||
|
@@ -123,7 +123,7 @@ class notify
|
||||
$tp = e107::getParser();
|
||||
$sql = e107::getDb();
|
||||
|
||||
$subject = $tp->toEmail(SITENAME.': '.$subject);
|
||||
$subject = $tp->toEmail($subject);
|
||||
$message = $tp->replaceConstants($message, "full");
|
||||
// $message = $tp->toEmail($message);
|
||||
$emailFilter = '';
|
||||
@@ -181,7 +181,7 @@ class notify
|
||||
|
||||
$unsubscribe = array('date'=>$row['user_join'],'email'=>$row['user_email'],'id'=>$row['user_id'], 'plugin'=>'user', 'userclass'=>$notifyTarget);
|
||||
$urlQuery = http_build_query($unsubscribe,null,'&');
|
||||
$exclude = array(e_UC_MEMBER,e_UC_ADMIN, e_UC_MAINADMIN); // no unsubscribe for these classes.
|
||||
$exclude = array(e_UC_MEMBER,e_UC_ADMIN, e_UC_MAINADMIN); // no unsubscribing from these classes.
|
||||
$unsubUrl = SITEURL."unsubscribe.php?id=".base64_encode($urlQuery);
|
||||
$unsubMessage = "This message was sent to ".$row['user_email'].". If you don't want to receive these emails in the future, please <a href='".$unsubUrl."'>unsubscribe</a>.";
|
||||
|
||||
@@ -193,11 +193,16 @@ class notify
|
||||
'mail_target_info' => array(
|
||||
'USERID' => $row['user_id'],
|
||||
'DISPLAYNAME' => $row['user_name'],
|
||||
// 'SIGNUP_LINK' => '',
|
||||
'SUBJECT' => $subject,
|
||||
'USERNAME' => $row['user_name'],
|
||||
'USERLASTVISIT' => $row['user_lastvisit'],
|
||||
'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '',
|
||||
'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : ''
|
||||
'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : '',
|
||||
'USERCLASS' => $notifyTarget,
|
||||
'DATE_SHORT' => $tp->toDate(time(),'short'),
|
||||
'DATE_LONG' => $tp->toDate(time(),'long'),
|
||||
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -245,6 +250,7 @@ class notify
|
||||
}
|
||||
|
||||
$result = $mailer->sendEmails('notify', $mailData, $recipients);
|
||||
|
||||
e107::getLog()->e_log_event(10,-1,'NOTIFY',$subject,$message,FALSE,LOG_TO_ROLLING);
|
||||
}
|
||||
else
|
||||
@@ -376,23 +382,34 @@ class notify
|
||||
}
|
||||
|
||||
|
||||
function notify_admin_news_subscribers($data)
|
||||
function notify_admin_news_notify($data)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
$url = e107::getUrl()->create('news/view/item', $data,'full=1');
|
||||
$message = "<b><a href='".$url."'>".$tp->toHtml($data['news_title'])."</a></b>";
|
||||
$sql = e107::getDb();
|
||||
|
||||
$author = $sql->retrieve('user','user_name','user_id = '.intval($data['news_author'])." LIMIT 1");
|
||||
|
||||
|
||||
$template = "<h4><a href='{NEWS_URL}'>{NEWS_TITLE}</a></h4>
|
||||
<div class='summary'>{NEWS_SUMMARY}</div>
|
||||
<div class='author'>by {NEWS_AUTHOR}</div>
|
||||
<div><a class='btn btn-primary' href='{NEWS_URL}'>View now</a></div>
|
||||
";
|
||||
|
||||
$shortcodes = array(
|
||||
'NEWS_URL' => e107::getUrl()->create('news/view/item', $data,'full=1'),
|
||||
'NEWS_TITLE' => $tp->toHtml($data['news_title']),
|
||||
'NEWS_SUMMARY' => $tp->toEmail($data['news_summary']),
|
||||
'NEWS_AUTHOR' => $tp->toHtml($author)
|
||||
);
|
||||
|
||||
$img = explode(",",$data['news_thumbnail']);
|
||||
|
||||
$message = $tp->simpleParse($template, $shortcodes);
|
||||
|
||||
if (vartrue($data['news_summary'])){ $message .= '<br /><br />'.$tp->toEmail($data['news_summary']); }
|
||||
|
||||
$message .= "<a href='".$url."'>View now</a>";
|
||||
|
||||
$this->send('admin_news_updated', $data['news_title'], $message, $img);
|
||||
|
||||
print_a($message);
|
||||
return $message;
|
||||
$this->send('admin_news_notify', $data['news_title'], $message, $img);
|
||||
|
||||
// print_a($message);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -41,7 +41,7 @@ class social_admin
|
||||
|
||||
if($this->twitterActive == true)
|
||||
{
|
||||
$config['fields']['twitter'] = array ( 'title' =>"Post to Twitter", 'type' => 'text', 'tab'=>1, 'writeParms'=> array('size'=>'xxlarge', 'placeholder'=>'Type your tweet here.'), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', );
|
||||
$config['fields']['twitter'] = array ( 'title' =>"Post to Twitter", 'type' => 'text', 'tab'=>2, 'writeParms'=> array('size'=>'xxlarge', 'placeholder'=>'Type your tweet here.'), 'width' => 'auto', 'help' => '', 'readParms' => '', 'class' => 'left', 'thclass' => 'left', );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user