Commit c6704cf9 authored by floh1111's avatar floh1111

Moved the last parts of reports code from tikilib to reportslib, need to be reviewd eventually

parent 72c90eb8
......@@ -6,6 +6,8 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
exit;
}
include_once('lib/reportslib.php');
class ArtLib extends TikiLib {
//Special parsing for multipage articles
function get_number_of_pages($data) {
......@@ -64,7 +66,7 @@ class ArtLib extends TikiLib {
}
function remove_article($articleId, $article_data='') {
global $smarty, $tikilib, $user, $prefs;
global $smarty, $tikilib, $user, $prefs, $reportslib;
if ($articleId) {
if (empty($article_data)) $article_data = $this->get_article($articleId);
......@@ -94,7 +96,7 @@ class ArtLib extends TikiLib {
}
if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>'article_deleted', "articleId"=>$articleId, "articleTitle"=>$article_data['title'], "authorName"=>$article_data['authorName'], "user"=>$user));
$reportslib->makeReportCache($nots, array("event"=>'article_deleted', "articleId"=>$articleId, "articleTitle"=>$article_data['title'], "authorName"=>$article_data['authorName'], "user"=>$user));
}
if (count($nots) || is_array($emails)) {
......@@ -234,7 +236,7 @@ class ArtLib extends TikiLib {
$heading, $body, $publishDate, $expireDate, $user, $articleId, $image_x, $image_y, $type,
$topline, $subtitle, $linkto, $image_caption, $lang, $rating = 0, $isfloat = 'n', $emails='', $from='') {
global $smarty, $tikilib;
global $smarty, $tikilib, $reportslib;
if ($expireDate < $publishDate) {
$expireDate = $publishDate;
......@@ -313,7 +315,7 @@ class ArtLib extends TikiLib {
global $prefs;
if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>$event, "articleId"=>$articleId, "articleTitle"=>$title, "authorName"=>$authorName, "user"=>$user));
$reportslib->makeReportCache($nots, array("event"=>$event, "articleId"=>$articleId, "articleTitle"=>$title, "authorName"=>$authorName, "user"=>$user));
}
if (count($nots) || is_array($emails)) {
......
......@@ -6,6 +6,8 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
exit;
}
include_once('lib/reportslib.php');
class BlogLib extends TikiLib {
//Special parsing for multipage articles
......@@ -264,7 +266,7 @@ class BlogLib extends TikiLib {
function blog_post($blogId, $data, $user, $title = '', $contributions='', $priv='n') {
// update tiki_blogs and call activity functions
global $smarty, $tikilib, $prefs;
global $smarty, $tikilib, $prefs, $reportslib;
$data = strip_tags($data, '<a><b><i><h1><h2><h3><h4><h5><h6><ul><li><ol><br><p><table><tr><td><img><pre>');
$query = "insert into `tiki_blog_posts`(`blogId`,`data`,`created`,`user`,`title`,`priv`) values(?,?,?,?,?,?)";
......@@ -284,7 +286,7 @@ class BlogLib extends TikiLib {
if ($prefs['feature_daily_report_watches'] == 'y') {
$query = "select `title` from `tiki_blogs` where `blogId`=?";
$blogTitle = $this->getOne($query, array((int)$blogId));
$tikilib->makeReportCache($nots, array("event"=>'blog_post', "blogId"=>$blogId, "blogTitle"=>$blogTitle, "postId"=>$id, "user"=>$user));
$reportslib->makeReportCache($nots, array("event"=>'blog_post', "blogId"=>$blogId, "blogTitle"=>$blogTitle, "postId"=>$id, "user"=>$user));
}
if (count($nots)) {
......
......@@ -7,6 +7,8 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
exit;
}
include_once('lib/reportslib.php');
class ImageGalsLib extends TikiLib {
function __construct() {
parent::__construct();
......@@ -892,7 +894,7 @@ class ImageGalsLib extends TikiLib {
$nots = $this->get_event_watches($event, $galleryId);
if ($prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>$event, "imageId"=>$imageId, "imageName"=>$name, "fileName"=>$filename, "galleryId"=>$galleryId, "galleryName"=>$galleryName, "action"=>$action, "user"=>$user));
$reportslib->makeReportCache($nots, array("event"=>$event, "imageId"=>$imageId, "imageName"=>$name, "fileName"=>$filename, "galleryId"=>$galleryId, "galleryName"=>$galleryName, "action"=>$action, "user"=>$user));
}
include_once('lib/notifications/notificationemaillib.php');
......
......@@ -8,7 +8,7 @@
* \param $title of the message
* \param $topicName name of the parent topic
*/
function sendForumEmailNotification($event, $object, $forum_info, $title, $data, $author, $topicName, $messageId='', $inReplyTo='', $threadId, $parentId, $contributions='', $postId='') {
global $tikilib, $prefs, $smarty, $userlib;
......@@ -102,8 +102,10 @@ function sendForumEmailNotification($event, $object, $forum_info, $title, $data,
$nots[] = $not;
}
include_once('lib/reportslib.php');
if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>$event, "forumId"=>$forum_info['forumId'], "forumName"=>$forum_info['name'], "topicId"=>$threadId, "threadId"=>$postId, "threadName"=>$topicName, "user"=>$author));
$reportslib->makeReportCache($nots, array("event"=>$event, "forumId"=>$forum_info['forumId'], "forumName"=>$forum_info['name'], "topicId"=>$threadId, "threadId"=>$postId, "threadName"=>$topicName, "user"=>$author));
}
if (count($nots)) {
......@@ -215,9 +217,12 @@ function sendWikiEmailNotification($event, $pageName, $edit_user, $edit_comment,
}
if ($edit_user=='') $edit_user = tra('Anonymous');
include_once('lib/reportslib.php');
global $reportslib;
if ($prefs['feature_user_watches'] == 'y' && $prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>$event, "pageName"=>$pageName, "object"=>$pageName, "editUser"=>$edit_user, "editComment"=>$edit_comment, "oldVer"=>$oldver));
$reportslib->makeReportCache($nots, array("event"=>$event, "pageName"=>$pageName, "object"=>$pageName, "editUser"=>$edit_user, "editComment"=>$edit_comment, "oldVer"=>$oldver));
}
if (count($nots)) {
......@@ -352,9 +357,11 @@ function sendFileGalleryEmailNotification($event, $galleryId, $galleryName, $nam
for ($i = count($nots) - 1; $i >=0; --$i) {
$nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
}
include_once('lib/reportslib.php');
if ($prefs['feature_daily_report_watches'] == 'y') {
$tikilib->makeReportCache($nots, array("event"=>$event, "name"=>$name, "fileId"=>$fileId, "fileName"=>$filename, "galleryId"=>$galleryId, "galleryName"=>$galleryName, "action"=>$action, "user"=>$user));
$reportslib->makeReportCache($nots, array("event"=>$event, "name"=>$name, "fileId"=>$fileId, "fileName"=>$filename, "galleryId"=>$galleryId, "galleryName"=>$galleryName, "action"=>$action, "user"=>$user));
}
}
......@@ -435,14 +442,15 @@ function sendCategoryEmailNotification($values) {
for ($i = count($nots) - 1; $i >=0; --$i) {
$nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage);
}
include_once('lib/reportslib.php');
if ($prefs['feature_daily_report_watches'] == 'y') {
$cache_data = $values;
$cache_data['user'] = $user;
$cache_data['event'] = $event;
$tikilib->makeReportCache($nots, $cache_data);
$reportslib->makeReportCache($nots, $cache_data);
}
}
if (count($nots)) {
......
......@@ -185,5 +185,123 @@ class reportsLib extends TikiLib{
return $body;
}
}
//--------------------------------------------------------------------
function add_user_report($user, $interval, $view, $type, $always_email) {
if(!isset($always_email))
$always_email = 0;
if (!$this->get_report_preferences_by_user($user)) {
//Add new report entry
$query = "insert into `tiki_user_reports`(`user`, `interval`, `view`, `type`, `always_email`, `last_report`) ";
$query.= "values(?,?,?,?,?,NOW())";
$this->query($query,array($user,$interval,$view,$type,$always_email));
} else {
//Update report entry
$query = "update `tiki_user_reports` set `interval`=?, `view`=?, `type`=?, `always_email`=? where `user`=?";
$this->query($query,array($interval,$view,$type,$always_email,$user));
}
return true;
}
function delete_user_report($user) {
$query = "delete from `tiki_user_reports` where `user`=?";
$this->query($query,array($user));
$this->deleteUsersReportCache($user);
return true;
}
function get_report_preferences_by_user($user) {
$query = "select `id`, `interval`, `view`, `type`, `always_email`, `last_report` from `tiki_user_reports` where `user` = ?";
$result = $this->query($query, array($user));
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
$ret = $res;
}
return $ret;
}
function getUsersForSendingReport() {
$query = "select `user`, `interval`, UNIX_TIMESTAMP(`last_report`) as last_report from tiki_user_reports";
$result = $this->query($query);
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
if ($res['interval']=="daily" AND ($res['last_report']+86400)<=time()) {
$ret[] = $res['user'];
}
if ($res['interval']=="weekly" AND ($res['last_report']+604800)<=time()) {
$ret[] = $res['user'];
}
if ($res['interval']=="monthly" AND ($res['last_report']+2419200)<=time()) {
$ret[] = $res['user'];
}
}
return $ret;
}
function makeReportCache(&$nots, $cache_data) {
//Get all users that have enabled reports
$query = "select `user` from tiki_user_reports";
$result = $this->query($query);
$report_users = array();
while ($res = $result->fetchRow()) {
$report_users[] = $res['user'];
}
foreach ($nots as $key=>$not) {
//If user in $nots has enabled reports
if (in_array($not['user'], $report_users)) {
//dump the report-data to the report cache
$query = "insert into `tiki_user_reports_cache`(`user`, `event`, `data`,`time`) ";
$query.= "values(?,?,?,NOW())";
$this->query($query,array($not['user'], $cache_data['event'], serialize($cache_data)));
//and reove the user from $nots so that he doesn´t get a notification for the event
unset($nots[$key]);
}
}
}
function get_report_cache_entries_by_user($user, $order_by) {
$query = "select `user`, `event`, `data`, `time` from `tiki_user_reports_cache` where `user` = ? ORDER BY $order_by";
$result = $this->query($query, array($user));
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
$res['data'] = unserialize($res['data']);
$ret[] = $res;
}
return $ret;
}
function deleteUsersReportCache($user) {
$query = "delete from `tiki_user_reports_cache` where `user`=?";
$this->query($query,array($user));
return true;
}
function updateLastSent($user) {
$query = "update `tiki_user_reports` set last_report = NOW() where `user`=?";
$this->query($query,array($user));
return true;
}
//-----------------------------
}
$reportslib = new reportsLib;
......@@ -525,120 +525,7 @@ class TikiLib extends TikiDb {
}
return $ret;
}
function add_user_report($user, $interval, $view, $type, $always_email) {
if(!isset($always_email))
$always_email = 0;
if (!$this->get_report_preferences_by_user($user)) {
//Add new report entry
$query = "insert into `tiki_user_reports`(`user`, `interval`, `view`, `type`, `always_email`, `last_report`) ";
$query.= "values(?,?,?,?,?,NOW())";
$this->query($query,array($user,$interval,$view,$type,$always_email));
} else {
//Update report entry
$query = "update `tiki_user_reports` set `interval`=?, `view`=?, `type`=?, `always_email`=? where `user`=?";
$this->query($query,array($interval,$view,$type,$always_email,$user));
}
return true;
}
function delete_user_report($user) {
$query = "delete from `tiki_user_reports` where `user`=?";
$this->query($query,array($user));
$this->deleteUsersReportCache($user);
return true;
}
function get_report_preferences_by_user($user) {
$query = "select `id`, `interval`, `view`, `type`, `always_email`, `last_report` from `tiki_user_reports` where `user` = ?";
$result = $this->query($query, array($user));
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
$ret = $res;
}
return $ret;
}
function getUsersForSendingReport() {
$query = "select `user`, `interval`, UNIX_TIMESTAMP(`last_report`) as last_report from tiki_user_reports";
$result = $this->query($query);
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
if ($res['interval']=="daily" AND ($res['last_report']+86400)<=time()) {
$ret[] = $res['user'];
}
if ($res['interval']=="weekly" AND ($res['last_report']+604800)<=time()) {
$ret[] = $res['user'];
}
if ($res['interval']=="monthly" AND ($res['last_report']+2419200)<=time()) {
$ret[] = $res['user'];
}
}
return $ret;
}
function makeReportCache(&$nots, $cache_data) {
//Get all users that have enabled reports
$query = "select `user` from tiki_user_reports";
$result = $this->query($query);
$report_users = array();
while ($res = $result->fetchRow()) {
$report_users[] = $res['user'];
}
foreach ($nots as $key=>$not) {
//If user in $nots has enabled reports
if (in_array($not['user'], $report_users)) {
//dump the report-data to the report cache
$query = "insert into `tiki_user_reports_cache`(`user`, `event`, `data`,`time`) ";
$query.= "values(?,?,?,NOW())";
$this->query($query,array($not['user'], $cache_data['event'], serialize($cache_data)));
//and reove the user from $nots so that he doesn´t get a notification for the event
unset($nots[$key]);
}
}
}
function get_report_cache_entries_by_user($user, $order_by) {
$query = "select `user`, `event`, `data`, `time` from `tiki_user_reports_cache` where `user` = ? ORDER BY $order_by";
$result = $this->query($query, array($user));
if (!$result->numRows()) {
return false;
}
$ret = array();
while ($res = $result->fetchRow()) {
$res['data'] = unserialize($res['data']);
$ret[] = $res;
}
return $ret;
}
function deleteUsersReportCache($user) {
$query = "delete from `tiki_user_reports_cache` where `user`=?";
$this->query($query,array($user));
return true;
}
function updateLastSent($user) {
$query = "update `tiki_user_reports` set last_report = NOW() where `user`=?";
$this->query($query,array($user));
return true;
}
/*shared*/
function dir_stats() {
$aux = array();
......
......@@ -2,6 +2,8 @@
// Copyright (c) 2009, Clemens John
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
include_once ('tiki-setup.php');
include_once('lib/reportslib.php');
if (!$user) {
$smarty->assign('msg', tra("You must log in to use this feature"));
$smarty->assign('errortype', '402');
......@@ -16,13 +18,13 @@ if ($prefs['feature_daily_report_watches'] != 'y') {
include_once ('lib/reportslib.php');
//Enable User Reports
if (isset($_POST['report_preferences']) && $_POST['use_daily_reports'] == "true") {
$tikilib->add_user_report($user, $_POST['interval'], $_POST['view'], $_POST['type'], $_POST['always_email']);
$reportslib->add_user_report($user, $_POST['interval'], $_POST['view'], $_POST['type'], $_POST['always_email']);
header('Location: tiki-user_watches.php');
die;
}
//Disable User Reports
if (isset($_POST['report_preferences']) && $_POST['use_daily_reports'] != "true") {
$tikilib->delete_user_report($user);
$reportslib->delete_user_report($user);
header('Location: tiki-user_watches.php');
die;
}
......@@ -11,19 +11,19 @@ if ($prefs['feature_daily_report_watches'] != 'y') {
}
include_once ('lib/tikilib.php');
include_once ('lib/reportslib.php');
foreach($tikilib->getUsersForSendingReport() as $key => $user) {
$report_preferences = $tikilib->get_report_preferences_by_user($user);
foreach($reportslib->getUsersForSendingReport() as $key => $user) {
$report_preferences = $reportslib->get_report_preferences_by_user($user);
$user_data = $userlib->get_user_info($user);
//If Emailadress isn´t set, do nothing but clear the cache
if (!empty($user_data['email'])) {
//Fetch cache
$report_cache = $tikilib->get_report_cache_entries_by_user($user, "time ASC");
$report_cache = $reportslib->get_report_cache_entries_by_user($user, "time ASC");
//Send email if there is a cache or if always_email = true
if ($report_cache OR (!$report_cache && $report_preferences['always_email'])) $reportslib->sendEmail($user_data, $report_preferences, $report_cache);
}
//Update Database
//$tikilib->updateLastSent($user_data['login']);
//$reportslib->updateLastSent($user_data['login']);
//Empty cache
//$tikilib->deleteUsersReportCache($user_data['login']);
//$reportslib->deleteUsersReportCache($user_data['login']);
}
......@@ -6,6 +6,8 @@
// $Id: /cvsroot/tikiwiki/tiki/tiki-user_watches.php,v 1.21.2.1 2008-03-13 21:00:48 sylvieg Exp $
$section = 'mytiki';
include_once ('tiki-setup.php');
include_once('lib/reportslib.php');
if ($prefs['feature_ajax'] == "y") {
require_once ('lib/ajax/ajaxlib.php');
}
......@@ -144,6 +146,6 @@ if ($prefs['feature_ajax'] == "y") {
user_watches_ajax();
$smarty->assign("mootab", 'y');
}
$smarty->assign_by_ref('report_preferences', $tikilib->get_report_preferences_by_user($user));
$smarty->assign_by_ref('report_preferences', $reportslib->get_report_preferences_by_user($user));
$smarty->assign('mid', 'tiki-user_watches.tpl');
$smarty->display("tiki.tpl");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment