Commit 5a062153 authored by chealer's avatar chealer

[ENH] Articles: Add watch event for comments article_commented (global)

[ENH] Articles: Add general watch event article_* (global)
[ENH] Watch articles : add an eye somewhere (Closes: 1755)
[ENH] add group watch to articles (Closes: 3100)
make watch types, titles and URLs generally optional
[ENH] Admin Notifications: improve watch addition
[FIX] Admin Notifications: don't ignore email if user is filled
notificationlib: add get_global_watch_types()
[FIX] Wiki comments notification mails for an event all have the same watchId
optimize Wiki comments notifications
Thanks to Xavier de Pedro
parent 2d074ed9
......@@ -4349,6 +4349,8 @@ templates/mail/user_watch_category_removed.tpl -text
templates/mail/user_watch_category_removed_subject.tpl -text
templates/mail/user_watch_category_updated.tpl -text
templates/mail/user_watch_category_updated_subject.tpl -text
templates/mail/user_watch_comment.tpl -text
templates/mail/user_watch_comment_subject.tpl -text
templates/mail/user_watch_file_gallery_changed_subject.tpl -text
templates/mail/user_watch_file_gallery_remove_file.tpl -text
templates/mail/user_watch_file_gallery_upload.tpl -text
......@@ -4366,8 +4368,6 @@ templates/mail/user_watch_wiki_new_attach.tpl -text
templates/mail/user_watch_wiki_new_attach_subject.tpl -text
templates/mail/user_watch_wiki_page_changed.tpl -text
templates/mail/user_watch_wiki_page_changed_subject.tpl -text
templates/mail/user_watch_wiki_page_comment.tpl -text
templates/mail/user_watch_wiki_page_comment_subject.tpl -text
templates/mail/user_watch_wiki_page_renamed.tpl -text
templates/mail/user_watch_wiki_page_renamed_subject.tpl -text
templates/mail/user_welcome_msg.tpl -text
......
......@@ -211,58 +211,14 @@ if ( isset($_REQUEST['comments_objectId']) && $_REQUEST['comments_objectId'] ==
die;
}
} else {
$threadId = $commentslib->post_in_object($comments_objectId, $_REQUEST, $feedbacks, $errors);
if ((!empty($threadId) && empty($errors) && $prefs['feature_user_watches'] == 'y') && ($prefs['wiki_watch_comments'] == 'y') && (isset($_REQUEST["page"]))) {
include_once ('lib/webmail/tikimaillib.php');
$nots = $commentslib->get_event_watches('wiki_page_changed', $_REQUEST["page"]);
$isBuilt = false;
global $notificationlib; include_once("lib/notifications/notificationlib.php");
$emails = $notificationlib->get_mail_events('wiki_comment_changes', $_REQUEST["page"]);
foreach ($emails as $email) {
$already = false;
foreach ($nots as $not) {
if ($not['email'] == $email) {
$already = true;
break;
}
}
if (!$already)
$nots[] = array("user"=>"", "hash"=>"", "email"=>$email);
}
foreach ($nots as $not) {
if ($prefs['wiki_watch_editor'] != 'y' && $not['user'] == $user) {
continue;
}
if (!$isBuilt) {
$isBuilt = true;
$smarty->assign('mail_page', $_REQUEST["page"]);
$smarty->assign('mail_date', date("U"));
$smarty->assign('mail_user', $user);
$smarty->assign('mail_title', $_REQUEST["comments_title"]);
$smarty->assign('mail_comment', $_REQUEST["comments_data"]);
$smarty->assign('watchId', $not['watchId']);
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = $tikilib->httpPrefix( true ). dirname( $foo["path"] );
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1)
unset ($parts[count($parts) - 1]);
$smarty->assign('mail_machine_raw', $tikilib->httpPrefix( true ). implode('/', $parts));
// TODO: mail_machine_site may be required for some sef url with rewrite to sub-directory. To refine. (nkoth)
$smarty->assign('mail_machine_site', $tikilib->httpPrefix( true ));
$mail = new TikiMail();
}
global $prefs;// TODO: optimise by grouping user by language
$languageEmail = $tikilib->get_user_preference($not['user'], "language", $prefs['site_language']);
$mail->setUser($not['user']);
$mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_wiki_page_comment_subject.tpl');
$mail->setSubject(sprintf($mail_data, $_REQUEST["page"]));
$mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_wiki_page_comment.tpl');
$mail->setText($mail_data);
$mail->buildMessage();
$mail->send(array($not['email']));
$threadId = $commentslib->post_in_object($comments_objectId, $_REQUEST, $feedbacks, $errors);
if (!empty($threadId) && empty($errors) && $prefs['feature_user_watches'] == 'y') {
if ($prefs['wiki_watch_comments'] == 'y' && isset($_REQUEST["page"])) {
global $notificationemaillib; require_once('lib/notifications/notificationemaillib.php');
sendCommentNotification('wiki', $_REQUEST['page'], $_REQUEST['comments_title'], $_REQUEST['comments_data']);
} else if (isset($_REQUEST["articleId"])) {
global $notificationemaillib; require_once('lib/notifications/notificationemaillib.php');
sendCommentNotification('article', $_REQUEST['articleId'], $_REQUEST['comments_title'], $_REQUEST['comments_data']);
}
}
}
......
......@@ -10920,7 +10920,8 @@ $lang=Array(
"The changes in this version follow below, followed after by the current full page text." => "Ci-dessous, les changements de cette version suivis du texte complet de la page.",
"-Lines: {\$oldd} changed to +Lines: {\$newd}" => "-Lignes: {\$oldd} changées en +Lignes: {\$newd}",
"The new page content follows below." => "Ci-dessous, le nouveau contenu de la page.",
"Wiki page %s was commented on by" => "La page Wiki %s a été commentée par",
"The Wiki page {\$mail_objectname} was commented on by" => "La page {\$mail_objectname} a été commentée par",
"The article {\$mail_objectname} was commented on by" => "L'article {\$mail_objectname} a été commenté par",
"an anonymous user" => "un utilisateur anonyme",
"Wiki page renamed" => "Page Wiki renommée",
"Old name" => "Ancien nom",
......@@ -150,19 +150,10 @@ class ArtLib extends TikiLib
$smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
$smarty->assign('mail_title', 'articleId=' . $articleId);
$smarty->assign('mail_postid', $articleId);
$smarty->assign('mail_date', $this->now);
$smarty->assign('mail_user', $user);
$smarty->assign('mail_data', $article_data['heading'] . "\n----------------------\n");
$smarty->assign('mail_heading', $heading);
$smarty->assign('mail_body', $body);
$foo = parse_url($_SERVER['REQUEST_URI']);
$machine = $tikilib->httpPrefix( true ). $foo['path'];
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1) {
unset ($parts[count($parts) - 1]);
}
$smarty->assign('mail_machine_raw', $tikilib->httpPrefix( true ) . implode('/', $parts));
sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl');
}
......@@ -332,8 +323,6 @@ class ArtLib extends TikiLib
}
if ($tiki_p_autoapprove_submission != 'y') {
#workaround to "pass" $topicId to get_event_watches
$GLOBALS['topicId'] = $topicId;
$emails = $tikilib->get_event_watches('article_submitted', '*');
$emails2 = $tikilib->get_event_watches('topic_article_created', $topicId);
$emails3 = array();
......@@ -349,15 +338,11 @@ class ArtLib extends TikiLib
}
if (count($emails)) {
include_once('lib/notifications/notificationemaillib.php');
$foo = parse_url($_SERVER['REQUEST_URI']);
$machine = $tikilib->httpPrefix( true ). $foo['path'];
$smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
$smarty->assign('mail_user', $user);
$smarty->assign('mail_title', $title);
$smarty->assign('mail_heading', $heading);
$smarty->assign('mail_body', $body);
$smarty->assign('mail_date', $this->now);
$smarty->assign('mail_machine', $machine);
$smarty->assign('mail_subId', $id);
sendEmailNotification($emails, 'watch', 'submission_notification_subject.tpl', $_SERVER['SERVER_NAME'], 'submission_notification.tpl');
}
......@@ -516,8 +501,6 @@ class ArtLib extends TikiLib
if ($prefs['feature_score'] == 'y') {
$this->score_event($user, 'article_new');
}
// workaround to "pass" $topicId to get_event_watches
$GLOBALS["topicId"] = $topicId;
$event = 'article_submitted';
$nots = $tikilib->get_event_watches('article_submitted', '*');
$nots2 = $tikilib->get_event_watches('topic_article_created', $topicId);
......@@ -535,7 +518,7 @@ class ArtLib extends TikiLib
if (is_array($emails) && (empty ($from) || $from == $prefs['sender_email'])) {
foreach ($emails as $n) {
if (!in_array($n, $nots3))
$nots[] = array('email' => $n);
$nots[] = array('email' => $n, 'language' => $prefs['site_language']);
}
}
if (!isset($_SERVER['SERVER_NAME'])) {
......@@ -559,24 +542,15 @@ class ArtLib extends TikiLib
$smarty->assign('mail_site', $_SERVER['SERVER_NAME']);
$smarty->assign('mail_title', $title);
$smarty->assign('mail_postid', $articleId);
$smarty->assign('mail_date', $this->now);
$smarty->assign('mail_user', $user);
$smarty->assign('mail_data', $heading."\n----------------------\n" . $body);
$smarty->assign('mail_heading', $heading);
$smarty->assign('mail_body', $body);
$foo = parse_url($_SERVER['REQUEST_URI']);
$machine = $tikilib->httpPrefix( true ). $foo['path'];
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1) {
unset ($parts[count($parts) - 1]);
}
$smarty->assign('mail_machine_raw', $tikilib->httpPrefix( true ). implode('/', $parts));
sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl');
if (is_array($emails) && !empty($from) && $from != $prefs['sender_email']) {
$nots = array();
foreach ($emails as $n) {
$nots[] = array('email' => $n);
$nots[] = array('email' => $n, 'language' => $prefs['site_language']);
}
sendEmailNotification($nots, 'watch', 'user_watch_article_post_subject.tpl', $_SERVER['SERVER_NAME'], 'user_watch_article_post.tpl', $from);
}
......
......@@ -721,13 +721,10 @@ class BlogLib extends TikiDb_Bridge
if (count($nots)) {
include_once("lib/notifications/notificationemaillib.php");
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
$query = "select `title` from `tiki_blogs` where `blogId`=?";
$blogTitle = $this->getOne($query, array((int)$blogId));
$smarty->assign('mail_title', $blogTitle);
$smarty->assign('mail_title', $this->get_title($blogId));
$smarty->assign('mail_post_title', $title);
$smarty->assign('mail_blogid', $blogId);
$smarty->assign('mail_postid', $id);
$smarty->assign('mail_date', $tikilib->now);
$smarty->assign('mail_user', $user);
$smarty->assign('mail_data', $data);
......@@ -735,13 +732,6 @@ class BlogLib extends TikiDb_Bridge
global $contributionlib; include_once('lib/contribution/contributionlib.php');
$smarty->assign('mail_contributions', $contributionlib->print_contributions($contributions));
}
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = $tikilib->httpPrefix(). $foo["path"];
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1)
unset ($parts[count($parts) - 1]);
$smarty->assign('mail_machine_raw', $tikilib->httpPrefix(). implode('/', $parts));
sendEmailNotification($nots, "watch", "user_watch_blog_post_subject.tpl", $_SERVER["SERVER_NAME"], "user_watch_blog_post.tpl");
}
}
......
......@@ -1438,7 +1438,7 @@ class CategLib extends ObjectLib
}
}
function group_watch_category_and_descendants($group, $categId, $categName, $top = true) {
function group_watch_category_and_descendants($group, $categId, $categName = NULL, $top = true) {
global $tikilib, $descendants;
if ($categId != 0 && $top == true) {
......
......@@ -884,11 +884,7 @@ class ImageGalsLib extends TikiLib
include_once('lib/notifications/notificationemaillib.php');
$smarty->assign_by_ref('galleryId', $galleryId);
$smarty->assign_by_ref('galleryName', $galleryName);
$smarty->assign_by_ref('mail_date', date('U'));
$smarty->assign_by_ref('author', $user);
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = $tikilib->httpPrefix( true ). dirname( $foo["path"] );
$smarty->assign_by_ref('mail_machine', $machine);
$smarty->assign_by_ref('fname', $name);
$smarty->assign_by_ref('filename', $filename);
$smarty->assign_by_ref('description', $description);
......
......@@ -299,8 +299,8 @@ function sendWikiEmailNotification($wikiEvent, $pageName, $edit_user, $edit_comm
}
/** \brief Send email notification to a list of emails or a list of (email, user) in a charset+language associated with each email
* \param $list : emails list or (users, email) list
* \param $type: type of the list element = 'email'|'watch'
* \param $watches : bidimensional array of watches. Each watch has user, language, email and watchId keys.
* \param $dummy: unused
* \param $subjectTpl: subject template file or null (ex: "submission_notifcation.tpl")
* \param $subjectParam: le param to be inserted in the subject or null
* \param $txtTpl : texte template file (ex: "submission_notifcation.tpl")
......@@ -308,44 +308,46 @@ function sendWikiEmailNotification($wikiEvent, $pageName, $edit_user, $edit_comm
* \ $smarty is supposed to be already built to fit $txtTpl
* \return the nb of sent emails
*/
function sendEmailNotification($list, $type, $subjectTpl, $subjectParam, $txtTpl, $from='') {
global $smarty, $tikilib, $userlib, $prefs;
function sendEmailNotification($watches, $dummy, $subjectTpl, $subjectParam, $txtTpl, $from='') {
global $smarty, $tikilib;
include_once('lib/webmail/tikimaillib.php');
$mail = new TikiMail(null, $from);
$sent = 0;
$defaultLanguage = $prefs['site_language'];
$languageEmail = $defaultLanguage;
foreach ($list as $elt) {
if ($type == "watch") {
$email = $elt['email'];
$userEmail = $elt['user'];
$smarty->assign('watchId', $elt['watchId']);
}
else {
$email = $elt;
$userEmail = $userlib->get_user_by_email($email);
}
if ($userEmail) {
$mail->setUser($userEmail);
$languageEmail = $tikilib->get_user_preference($userEmail, "language", $defaultLanguage);
$mail = new TikiMail(null, $from);
$smarty->assign('mail_date', $tikilib->now);
$foo = parse_url($_SERVER["REQUEST_URI"]);
$smarty->assign('mail_machine', $tikilib->httpPrefix( true ). $foo["path"] );
$parts = explode('/', $foo['path']);
if (count($parts) > 1)
unset ($parts[count($parts) - 1]);
$smarty->assign('mail_machine_raw', $tikilib->httpPrefix( true ). implode('/', $parts));
// TODO: mail_machine_site may be required for some sef url with rewrite to sub-directory. To refine. (nkoth)
$smarty->assign('mail_machine_site', $tikilib->httpPrefix( true ));
foreach ($watches as $watch) {
$smarty->assign('watchId', $watch['watchId']);
if ($watch['user']) {
$mail->setUser($watch['user']);
}
else
$languageEmail = $defaultLanguage;
if ($subjectTpl) {
$mail_data = $smarty->fetchLang($languageEmail, "mail/".$subjectTpl);
if ($subjectParam)
$mail_data = $smarty->fetchLang($watch['language'], "mail/".$subjectTpl);
if ($subjectParam) {
$mail_data = sprintf($mail_data, $subjectParam);
}
$mail_data = preg_replace('/%[sd]/', '', $mail_data);// partial cleaning if param not supply and %s in text
$mail->setSubject($mail_data);
}
else
} else {
$mail->setSubject($subjectParam);
$mail->setText($smarty->fetchLang($languageEmail, "mail/".$txtTpl));
}
$mail->setText($smarty->fetchLang($watch['language'], "mail/".$txtTpl));
$mail->buildMessage();
if ($mail->send(array($email)))
if ($mail->send(array($watch['email']))) {
$sent++;
}
}
return $sent;
return $sent;
}
function activeErrorEmailNotivation() {
set_error_handler("sendErrorEmailNotification");
......@@ -569,3 +571,41 @@ function sendStructureEmailNotification($params) {
}
}
}
/**
* @param $type Type of the object commented on, 'wiki' or 'article'
* @param $id Identifier of the object commented on. For articles, their id and for wiki pages, their name
* @param $title Comment title
* @param $content Comment content
*/
function sendCommentNotification($type, $id, $title, $content) {
global $user, $tikilib, $smarty, $prefs;
if ($type == 'wiki') {
$event = 'wiki_comment_changes';
} elseif ($type == 'article') {
$event = 'article_commented';
} else {
throw new Exception('Unknown type');
}
$watches = $tikilib->get_event_watches($event, $id);
if (count($watches)) {
if ($type == 'wiki') {
$smarty->assign('mail_objectname', $id);
} elseif ($type == 'article') {
global $artlib; include_once ('lib/articles/artlib.php');
$smarty->assign('mail_objectname', $artlib->get_title($id));
$smarty->assign('mail_objectid', $id);
}
$smarty->assign('objecttype', $type);
$smarty->assign('mail_user', $user);
$smarty->assign('mail_title', $title);
$smarty->assign('mail_comment', $content);
foreach ($watches as $key => $watch) {
if ($watch['user'] == $user && ($type != 'wiki' || $prefs['wiki_watch_editor'] != 'y')) {
unset($watches[$key]);
}
}
sendEmailNotification($watches, null, 'user_watch_comment_subject.tpl', null, 'user_watch_comment.tpl');
}
}
\ No newline at end of file
......@@ -42,8 +42,8 @@ class NotificationLib extends TikiLib
function get_mail_events($event, $object) {
global $tikilib;
global $categlib; require_once('lib/categories/categlib.php');
$query = 'select * from `tiki_user_watches` where `event`=? and (`object`=? or `object`=?)';
$result = $this->query($query, array($event, $object, '*') );
$query = "select * from `tiki_user_watches` where `event`=? and (`object`=? or `object`='*')";
$result = $this->query($query, array($event, $object) );
$ret = array();
$map = CategLib::map_object_type_to_permission();
while ($res = $result->fetchRow()) {
......@@ -54,5 +54,91 @@ class NotificationLib extends TikiLib
return $ret;
}
// Returns an array of notification types
/**
* @param boolean $checkPermission If enabled, only return types for which the user has the permission needed so that they are effective.
* @return A string-indexed bidimensional array of watch types. The first index is the watch event name.
* Second-level array are also string-indexed with elements label (description of the event),
* type (usually the type of watched objects) and url (a relevant script to access when an event happens, if any).
*/
function get_global_watch_types($checkPermission = false) {
global $prefs, $tiki_p_admin, $tiki_p_admin_file_galleries;
$watches['user_registers'] = array(
'label' => tra('A user registers') ,
'type' => 'users',
'url' => 'tiki-adminusers.php',
'available' => $prefs['allowRegister'] == 'y',
'permission' => $tiki_p_admin == 'y'
);
$watches['article_submitted'] = array(
'label' => tra('A user submits an article') ,
'type' => 'article',
'url' => 'tiki-list_submissions.php',
'available' => $prefs['feature_articles'] == 'y'
);
$watches['article_edited'] = array(
'label' => tra('A user edits an article') ,
'type' => 'article',
'url' => 'tiki-list_articles.php',
'available' => $prefs['feature_articles'] == 'y'
);
$watches['article_deleted'] = array(
'label' => tra('A user deletes an article') ,
'type' => 'article',
'url' => 'tiki-list_submissions.php',
'available' => $prefs['feature_articles'] == 'y'
);
$watches['article_*'] = array(
'label' => tra('An article is submitted, edited, deleted or commented on.') ,
'type' => 'article',
'url' => '',
'available' => $prefs['feature_articles'] == 'y'
);
$watches['wiki_page_changes'] = array(
'label' => tra('A wiki page is created, deleted or edited, except for minor changes.') ,
'type' => 'wiki page',
'url' => 'tiki-lastchanges.php',
'available' => $prefs['feature_wiki'] =='y'
);
$watches['wiki_page_changes_incl_minor'] = array(
'label' => tra('A wiki page is created, deleted or edited, even for minor changes.') ,
'type' => 'wiki page',
'url' => 'tiki-lastchanges.php',
'available' => $prefs['feature_wiki'] == 'y'
);
$watches['wiki_comment_changes'] = array(
'label' => tra('A comment in a wiki page is posted or edited') ,
'type' => 'wiki page',
'url' => '',
'available' => $prefs['feature_wiki'] == 'y' && $prefs['feature_wiki_comments'] == 'y'
);
$watches['article_commented'] = array(
'label' => tra('A comment in an article is posted or edited') ,
'type' => 'article',
'url' => '',
'available' => $prefs['feature_articles'] == 'y' && $prefs['feature_article_comments'] == 'y'
);
$watches['fgal_quota_exceeded'] = array(
'label' => tra('File gallery quota exceeded') ,
'type' => 'file gallery',
'url' => '',
'available' => $prefs['feature_file_galleries'] == 'y',
'permission' => $tiki_p_admin == 'y'
);
foreach($watches as $key => $watch) {
if (array_key_exists('available', $watch) && !$watch['available']) {
unset($watches[$key]);
} else {
$watches[$key]['object'] = '*';
unset($watches['available']);
if ($checkPermission && array_key_exists('permission', $watch) && !$watch['permission']) {
unset($watches[$key]);
}
}
}
return $watches;
}
}
$GLOBALS['notificationlib'] = new NotificationLib;
......@@ -347,13 +347,12 @@ class RegistrationLib extends TikiLib
$registration[$customfields[$custpref]['prefName']]);
}
$emails = $notificationlib->get_mail_events('user_registers', '*');
if (count($emails)) {
$watches = $tikilib->get_event_watches('user_registers', '*');
if (count($watches)) {
require_once ("lib/notifications/notificationemaillib.php");
$smarty->assign('mail_user', $registration['name']);
$smarty->assign('mail_date', $tikilib->now);
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
sendEmailNotification($emails, "email", "new_user_notification_subject.tpl", null, "new_user_notification.tpl");
sendEmailNotification($watches, null, "new_user_notification_subject.tpl", null, "new_user_notification.tpl");
}
return $result;
......
......@@ -285,8 +285,8 @@ class TikiLib extends TikiDb_Bridge
/*shared*/
function add_user_watch($user, $event, $object, $type, $title, $url, $email='') {
function add_user_watch($user, $event, $object, $type = NULL, $title = NULL, $url = NULL, $email = NULL) {
// Allow a warning when the watch won't be effective
if (empty($email)) {
global $userlib;
$email = $userlib->get_user_email($user);
......@@ -294,6 +294,7 @@ class TikiLib extends TikiDb_Bridge
return false;
}
}
$this->remove_user_watch( $user, $event, $object, $type );
$query = "insert into `tiki_user_watches`(`user`,`event`,`object`,`email`,`type`,`title`,`url`) ";
$query.= "values(?,?,?,?,?,?,?)";
......@@ -301,7 +302,7 @@ class TikiLib extends TikiDb_Bridge
return true;
}
function add_group_watch($group, $event, $object, $type, $title, $url) {
function add_group_watch($group, $event, $object, $type = NULL, $title = NULL, $url = NULL) {
if ($type == 'Category' && $object == 0) {
return false;
......@@ -347,13 +348,23 @@ class TikiLib extends TikiDb_Bridge
/*shared*/
function remove_user_watch($user, $event, $object, $type = 'wiki page') {
$query = "delete from `tiki_user_watches` where binary `user`=? and `event`=? and `object`=? and `type` = ?";
$this->query($query,array($user,$event,$object,$type));
$query = "delete from `tiki_user_watches` where binary `user`=? and `event`=? and `object`=?";
$bindvars = array($user,$event,$object);
if (isset($type)) {
$query .= " and `type` = ?";
$bindvars[] = $type;
}
$this->query($query, $bindvars);
}
function remove_group_watch($group, $event, $object, $type = 'wiki page') {
$query = "delete from `tiki_group_watches` where binary `group`=? and `event`=? and `object`=? and `type` = ?";
$this->query($query,array($group,$event,$object,$type));
$query = "delete from `tiki_group_watches` where binary `group`=? and `event`=? and `object`=?";
$bindvars = array($group,$event,$object);
if (isset($type)) {
$query .= " and `type`=?";
$bindvars[] = $type;
}
$this->query($query, $bindvars);
}
/*shared*/
......@@ -381,10 +392,15 @@ class TikiLib extends TikiDb_Bridge
}
/*shared*/
function user_watches($user, $event, $object, $type) {
function user_watches($user, $event, $object, $type = NULL) {
if (is_array($event)) {
$query = "select `event` from `tiki_user_watches` where `user`=? and `object`=? and `type`=? and `event` in (".implode(',',array_fill(0, count($event),'?')).")";
$result = $this->fetchAll($query, array_merge(array($user,$object,$type),$event));
$query = "select `event` from `tiki_user_watches` where `user`=? and `object`=? and `event` in (".implode(',',array_fill(0, count($event),'?')).")";
$bindvars = array_merge(array($user, $object), $event);
if ($type) {
$query .= " and `type`=?";
$bindvars[] = $type;
}
$result = $this->fetchAll($query, $bindvars);
if ( count($result) === 0 ) {
return false;
}
......@@ -394,14 +410,24 @@ class TikiLib extends TikiDb_Bridge
}
return $ret;
} else {
$query = "select count(*) from `tiki_user_watches` where `user`=? and `object`=? and `type`=? and `event`=? ";
return $this->getOne($query,array($user,$object,$type,$event));
$query = "select count(*) from `tiki_user_watches` where `user`=? and `object`=? and `event`=?";
$bindvars = array($user, $object, $event);
if ($type) {
$query .= " and `type`=?";
$bindvars[] = $type;
}
return $this->getOne($query, $bindvars);
}
}
function get_groups_watching( $type, $object, $event ) {
$result = $this->fetchAll( 'SELECT `group` FROM `tiki_group_watches` WHERE `object` = ? AND `type` = ? AND `event` = ?',
array( $object, $type, $event ) );
function get_groups_watching( $object, $event, $type = NULL ) {
$query = 'SELECT `group` FROM `tiki_group_watches` WHERE `object` = ? AND `event` = ?';
$bindvars = array( $object, $event);
if ($type) {
$query .= ' AND `type` = ?';
$bindvars[]= $type;
}
$result = $this->fetchAll( $query, $bindvars );
$groups = array();
foreach( $result as $row ) {
......@@ -422,7 +448,7 @@ class TikiLib extends TikiDb_Bridge
/*shared*/
function get_event_watches($event, $object, $info=null) {
global $prefs, $dbTiki;
global $prefs;
$ret = array();
$where = array();
......@@ -463,7 +489,13 @@ class TikiLib extends TikiDb_Bridge
$forumId = $info['forumId'];
$bindvars[] = $forumId;
} else {
$mid = "`event`=? and `object`=?";
$extraEvents = "";
if (substr_count($event, 'article_')) {
$extraEvents = " or `event`='article_*'";
} elseif ($event == 'wiki_comment_changes') {
$extraEvents = " or `event`='wiki_page_changed'";
}
$mid = "(`event`=?$extraEvents) and (`object`=? or `object`='*')";
$bindvars[] = $event;
$bindvars[] = $object;
}
......@@ -494,6 +526,9 @@ class TikiLib extends TikiDb_Bridge
if ( count($result) > 0 ) {
foreach ( $result as $res ) {
if (empty($res['language'])) {
$res['language'] = $this->get_preference('site_language');
}
switch($event) {
case 'wiki_page_changed':
case 'wiki_page_created':
......@@ -531,9 +566,9 @@ class TikiLib extends TikiDb_Bridge
case 'topic_article_edited':
case 'article_deleted':
case 'topic_article_deleted':
global $userlib, $topicId;
global $userlib;
$res['perm']= ($userlib->user_has_permission($res['user'],'tiki_p_read_article') &&
(empty($topicId) || $this->user_has_perm_on_object($res['user'],$topicId,'topic','tiki_p_topic_read')));
(empty($object) || $this->user_has_perm_on_object($res['user'], $object,'topic','tiki_p_topic_read')));
break;
case 'calendar_changed':
$res['perm']= $this->user_has_perm_on_object($res['user'],$object,'calendar','tiki_p_view_calendar');
......@@ -549,6 +584,14 @@ class TikiLib extends TikiDb_Bridge
global $tiki_p_admin_file_galleries;
$res['perm'] = ($tiki_p_admin_file_galleries == 'y');
break;
case 'article_commented':
case 'wiki_comment_changes':
$res['perm'] = $this->user_has_perm_on_object($res['user'],$object,'comments','tiki_p_read_comments');
break;
case 'user_registers':
global $userlib;
$res['perm'] = $userlib->user_has_permission($res['user'], 'tiki_p_admin');