diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 362fdc4b7..b111311e1 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -376,14 +376,16 @@ class news_admin_ui extends e_admin_ui 'news_author' => array('title' => LAN_AUTHOR, 'type' => 'method', 'tab'=>0, 'readParms'=>'idField=user_id&nameField=user_name', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'tab'=>2, 'writeParms'=>'type=datetime', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y', 'filter'=>true), 'news_category' => array('title' => NWSLAN_6, 'type' => 'dropdown', 'tab'=>0, 'data' => 'int', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true), - 'news_start' => array('title' => LAN_START, 'type' => 'datestamp', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'), + 'news_start' => array('title' => LAN_START, 'type' => 'datestamp', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'), 'news_end' => array('title' => LAN_END, 'type' => 'datestamp', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'parms' => 'mask=%A %d %B %Y'), 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclasses','tab'=>2, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'batch'=>true, 'filter'=>true), 'news_render_type' => array('title' => LAN_TEMPLATE, 'type' => 'dropdown', 'tab'=>0, 'data'=> 'str', 'inline'=>false, 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true), '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'] = "".LAN_CONFIGURE.""; + + // e107::getMessage()->addDebug(print_a($_POST,true)); if($this->getAction() == 'create' || $this->getAction() == 'edit') diff --git a/e107_admin/notify.php b/e107_admin/notify.php index 2cfc8c5a8..a2bc49c75 100644 --- a/e107_admin/notify.php +++ b/e107_admin/notify.php @@ -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); //
+ $text2 = $frm->open('scanform', 'post', e_REQUEST_URL); // $text2 .= $frm->tabs($tab); $text2 .= "
". $frm->admin_button('update', LAN_UPDATE,'update') . "
"; $text2 .= $frm->close(); @@ -405,11 +410,13 @@ class notify_config { $description = constant($description); } - + + + $highlight = varset($_GET['type']) == $id ? " class='text-warning'" : ''; $text = " - ".$description.": + ".$description.": ".$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'); } diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index 9d1687708..dad45d30c 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -203,8 +203,45 @@ $EMAIL_TEMPLATE['notify']['header'] = " @@ -212,9 +249,10 @@ $EMAIL_TEMPLATE['notify']['header'] = "
"; -$EMAIL_TEMPLATE['notify']['body'] = "
{MEDIA1}{BODY}
"; +$EMAIL_TEMPLATE['notify']['body'] = "

{SITENAME=link} {DATE_LONG}

{MEDIA1}{BODY}
"; $EMAIL_TEMPLATE['notify']['footer'] = "

- {SITENAME=link} + +
{UNSUBSCRIBE_MESSAGE}
diff --git a/e107_handlers/event_class.php b/e107_handlers/event_class.php index 03731674b..be4ff7229 100644 --- a/e107_handlers/event_class.php +++ b/e107_handlers/event_class.php @@ -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, ), diff --git a/e107_handlers/notify_class.php b/e107_handlers/notify_class.php index 1b8ca6d07..e0b023ffa 100644 --- a/e107_handlers/notify_class.php +++ b/e107_handlers/notify_class.php @@ -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 unsubscribe."; @@ -191,13 +191,18 @@ class notify 'mail_recipient_name' => $row['user_name'], // Should this use realname? 'mail_recipient_email' => $row['user_email'], 'mail_target_info' => array( - 'USERID' => $row['user_id'], - 'DISPLAYNAME' => $row['user_name'], - // 'SIGNUP_LINK' => '', - 'USERNAME' => $row['user_name'], - 'USERLASTVISIT' => $row['user_lastvisit'], - 'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '', - 'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : '' + 'USERID' => $row['user_id'], + 'DISPLAYNAME' => $row['user_name'], + 'SUBJECT' => $subject, + 'USERNAME' => $row['user_name'], + 'USERLASTVISIT' => $row['user_lastvisit'], + 'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '', + '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 = "".$tp->toHtml($data['news_title']).""; + $sql = e107::getDb(); + + $author = $sql->retrieve('user','user_name','user_id = '.intval($data['news_author'])." LIMIT 1"); + + + $template = "

{NEWS_TITLE}

+
{NEWS_SUMMARY}
+
by {NEWS_AUTHOR}
+
View now
+ "; + + $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 .= '

'.$tp->toEmail($data['news_summary']); } - - $message .= "View now"; - - $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); } diff --git a/e107_plugins/social/e_admin.php b/e107_plugins/social/e_admin.php index afdd9158e..e140abb2f 100644 --- a/e107_plugins/social/e_admin.php +++ b/e107_plugins/social/e_admin.php @@ -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; }