From: <pk...@us...> - 2011-11-29 21:55:42
|
Revision: 39046 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=39046&view=rev Author: pkdille Date: 2011-11-29 21:55:33 +0000 (Tue, 29 Nov 2011) Log Message: ----------- No changes - code styling only (seen on quality.tiki.org) Modified Paths: -------------- trunk/lib/breadcrumblib.php trunk/lib/logs/logslib.php trunk/lib/logs/logsquerylib.php trunk/lib/notifications/notificationemaillib.php trunk/lib/notifications/notificationlib.php Modified: trunk/lib/breadcrumblib.php =================================================================== --- trunk/lib/breadcrumblib.php 2011-11-29 21:54:00 UTC (rev 39045) +++ trunk/lib/breadcrumblib.php 2011-11-29 21:55:33 UTC (rev 39046) @@ -6,9 +6,9 @@ // $Id$ //this script may only be included - so its better to die if called directly. -if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) { - header("location: index.php"); - exit; +if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { + header("location: index.php"); + exit; } include_once("tikihelplib.php"); @@ -21,44 +21,46 @@ var $helpUrl; var $helpDescription; - function Breadcrumb($title, $desc='', $url='', $helpurl='', $helpdesc='') { - if ($title == '') { - $this->title = 'Home'; + function Breadcrumb($title, $desc='', $url='', $helpurl='', $helpdesc='') + { + if ($title == '') { + $this->title = 'Home'; } else { - $this->title = $title; + $this->title = $title; } $this->description = $desc; $this->url = $url; $this->helpUrl = $helpurl; $this->helpDescription = $helpdesc; - } -/* end of class */ + } + /* end of class */ } /* static */ -function breadcrumb_buildHeadTitle($crumbs) { +function breadcrumb_buildHeadTitle($crumbs) +{ global $prefs; if ($prefs['feature_breadcrumbs'] === 'y') { - if ( _is_assoc($crumbs) ) { - return false; - } - if ( is_array($crumbs) ) { - $ret = array(); - foreach($crumbs as $crumb) { - $ret[] = breadcrumb_buildHeadTitle($crumb); - } - return implode(" : ", $ret); + if ( _is_assoc($crumbs) ) { + return false; + } + if ( is_array($crumbs) ) { + $ret = array(); + foreach ($crumbs as $crumb) { + $ret[] = breadcrumb_buildHeadTitle($crumb); + } + return implode(" : ", $ret); } elseif ($prefs['site_title_breadcrumb'] == 'desc') { return $crumbs->description; - } else { - return htmlspecialchars($crumbs->title); - } + } else { + return htmlspecialchars($crumbs->title); + } } else { - if ( is_array($crumbs) ) { + if ( is_array($crumbs) ) { return $crumbs[count($crumbs) - 1]->title; - } else { - return $crumbs->title; - } + } else { + return $crumbs->title; + } } } @@ -67,75 +69,82 @@ * @param loc where the description will be used: {site|page} site header or page header */ /* static */ -function breadcrumb_buildTrail($crumbs, $loc) { - global $prefs, $info; - if ($prefs['feature_breadcrumbs'] == 'y') { - if ($loc == 'page' && ($prefs['feature_siteloc'] == 'page' || ($prefs['feature_page_title'] == 'y' && $info) ) ) { - return _breadcrumb_buildTrail($crumbs); - } else if (($loc == 'site' || $loc == 'location') && $prefs['feature_siteloc'] == 'y') { - return _breadcrumb_buildTrail($crumbs); - } else if ($loc != 'page' && $loc != 'site' && $loc != 'location' && $loc != 'admin') { - return _breadcrumb_buildTrail($crumbs); - } - } else if ($loc == "admin" && $prefs['feature_breadcrumbs'] == 'y') { - return _breadcrumb_buildTrail($crumbs); - } +function breadcrumb_buildTrail($crumbs, $loc) +{ + global $prefs, $info; + if ($prefs['feature_breadcrumbs'] == 'y') { + if ($loc == 'page' && ($prefs['feature_siteloc'] == 'page' || ($prefs['feature_page_title'] == 'y' && $info) ) ) { + return _breadcrumb_buildTrail($crumbs); + } else if (($loc == 'site' || $loc == 'location') && $prefs['feature_siteloc'] == 'y') { + return _breadcrumb_buildTrail($crumbs); + } else if ($loc != 'page' && $loc != 'site' && $loc != 'location' && $loc != 'admin') { + return _breadcrumb_buildTrail($crumbs); + } + } else if ($loc == "admin" && $prefs['feature_breadcrumbs'] == 'y') { + return _breadcrumb_buildTrail($crumbs); + } } /** * @param crumbs array of breadcrumb instances */ /* private static */ -function _breadcrumb_buildTrail($crumbs, $len=-1, $cnt=-1) { - global $structure, $structure_path, $prefs, $info; +function _breadcrumb_buildTrail($crumbs, $len=-1, $cnt=-1) +{ + global $structure, $structure_path, $prefs, $info; - $seper = ' '.htmlentities($prefs['site_crumb_seper'],ENT_QUOTES,"UTF-8").' '; - switch ($prefs['feature_sitetitle']) { - case ('y'): - $loclass = "pagetitle"; - $hiclass = "pagetitle"; - break; - case ('title'): - $loclass = "crumblink"; - $hiclass = "pagetitle"; - break; - case ('n'): - default: - $loclass = "crumblink"; - $hiclass = "crumblink"; - break; - } - if ($prefs['feature_breadcrumbs'] == 'n') { - $loclass = "crumblink"; - $hiclass = "pagetitle"; - } - if ($len == -1) { - $len = count($crumbs); - } - if ( _is_assoc($crumbs) ) { - return false; - } - if ( is_array($crumbs) ) { - $ret = array(); - if ( ($structure == 'y') && $info ) { - $cnt +=1; - $ret = breadcrumb_buildStructureTrail($structure_path, $cnt, $loclass); - // prepend the root crumb - array_unshift($ret, _breadcrumb_buildCrumb($crumbs[$cnt], $cnt, $loclass)); - } else { - foreach($crumbs as $crumb) { - $cnt+=1; - if ( $len!=$cnt+1 ) { - $ret[] = _breadcrumb_buildCrumb($crumb, $cnt, $loclass); - } else { - $ret[] = ''; - } - } - } - return implode($seper, $ret); - } else { - return _breadcrumb_buildCrumb($crumbs, $cnt, $loclass); - } + $seper = ' ' . htmlentities($prefs['site_crumb_seper'], ENT_QUOTES, "UTF-8") . ' '; + + switch ($prefs['feature_sitetitle']) { + case ('y'): + $loclass = "pagetitle"; + $hiclass = "pagetitle"; + break; + case ('title'): + $loclass = "crumblink"; + $hiclass = "pagetitle"; + break; + case ('n'): + default: + $loclass = "crumblink"; + $hiclass = "crumblink"; + break; + } + + if ($prefs['feature_breadcrumbs'] == 'n') { + $loclass = "crumblink"; + $hiclass = "pagetitle"; + } + + if ($len == -1) { + $len = count($crumbs); + } + + if ( _is_assoc($crumbs) ) { + return false; + } + + if ( is_array($crumbs) ) { + $ret = array(); + if ( ($structure == 'y') && $info ) { + $cnt +=1; + $ret = breadcrumb_buildStructureTrail($structure_path, $cnt, $loclass); + // prepend the root crumb + array_unshift($ret, _breadcrumb_buildCrumb($crumbs[$cnt], $cnt, $loclass)); + } else { + foreach ($crumbs as $crumb) { + $cnt += 1; + if ( $len != $cnt+1 ) { + $ret[] = _breadcrumb_buildCrumb($crumb, $cnt, $loclass); + } else { + $ret[] = ''; + } + } + } + return implode($seper, $ret); + } else { + return _breadcrumb_buildCrumb($crumbs, $cnt, $loclass); + } } /** @@ -144,14 +153,15 @@ * @param cnt the position of this crumb in the trail, starting at 1 */ /* static */ -function _breadcrumb_buildCrumb($crumb, $cnt, $loclass) { - $cnt+=1; - $ret = '<a class="'.$loclass.'" title="'; - $ret .= tra($crumb->description); - $ret .= '" accesskey="'.($cnt); - $ret .= '" href="'.$crumb->url.'">'.tra($crumb->title).'</a>'; - $ret .= help_doclink(array('crumb'=>$crumb)); - return $ret; +function _breadcrumb_buildCrumb($crumb, $cnt, $loclass) +{ + $cnt += 1; + $ret = '<a class="'.$loclass.'" title="'; + $ret .= tra($crumb->description); + $ret .= '" accesskey="'.($cnt); + $ret .= '" href="'.$crumb->url.'">'.tra($crumb->title).'</a>'; + $ret .= help_doclink(array('crumb'=>$crumb)); + return $ret; } /** @@ -161,35 +171,40 @@ * @param loclass the css class */ /* static */ -function breadcrumb_buildStructureTrail($structure_path, $cnt, $loclass) { - global $structure, $info, $page; - $len = count($structure_path) + $cnt; +function breadcrumb_buildStructureTrail($structure_path, $cnt, $loclass) +{ + global $structure, $info, $page; + $len = count($structure_path) + $cnt; - if ($structure != 'y' || !$info) { return false; } - $res = array(); - foreach ($structure_path as $crumb) { - $cnt+=1; - if ( $len!=$cnt ) { + if ($structure != 'y' || !$info) { + return false; + } - $ret = ''; - if ($crumb['pageName'] != $page || $crumb['page_alias'] != $page) { - $ret .= '<a class="'.$loclass.'" accesskey="'.($cnt).'" href="tiki-index.php?page_ref_id='.$crumb['page_ref_id'].'">'; - } - if ($crumb['page_alias']) { - $ret .= $crumb['page_alias']; - } else { - $ret .= $crumb['pageName']; - } - if ($crumb['pageName'] != $page || $crumb['page_alias'] != $page) { - $ret .= '</a>'; - } - $res[] = $ret; + $res = array(); - } else { - $res[] = ''; - } - } - return $res; + foreach ($structure_path as $crumb) { + $cnt += 1; + if ( $len!=$cnt ) { + + $ret = ''; + if ($crumb['pageName'] != $page || $crumb['page_alias'] != $page) { + $ret .= '<a class="'.$loclass.'" accesskey="'.($cnt).'" href="tiki-index.php?page_ref_id='.$crumb['page_ref_id'].'">'; + } + if ($crumb['page_alias']) { + $ret .= $crumb['page_alias']; + } else { + $ret .= $crumb['pageName']; + } + if ($crumb['pageName'] != $page || $crumb['page_alias'] != $page) { + $ret .= '</a>'; + } + $res[] = $ret; + + } else { + $res[] = ''; + } + } + return $res; } /** @@ -198,25 +213,26 @@ * @param loc where the description will be used: {site|page} site header or page header */ /* static */ -function breadcrumb_getTitle($crumbs, $loc) { - global $prefs, $info; +function breadcrumb_getTitle($crumbs, $loc) +{ + global $prefs, $info; - if ($prefs['feature_breadcrumbs'] == 'n' && ($prefs['feature_wiki_description'] == 'y' && $info)) { - return _breadcrumb_getTitle($crumbs, $loc); - } else if ($prefs['feature_breadcrumbs'] == 'n' && $loc == "admin") { - return _breadcrumb_getTitle($crumbs, $loc); - } else if ($prefs['feature_breadcrumbs'] == 'y') { - if ($loc == 'page' && ($prefs['feature_siteloc'] == 'page' || ($prefs['feature_page_title'] == 'y' && $info) ) ) { - return _breadcrumb_getTitle($crumbs, $loc); - } else if (($loc == 'site' || $loc == 'location') && $prefs['feature_siteloc'] == 'y') { - return _breadcrumb_getTitle($crumbs, $loc); - } - } else if ($loc == "admin") { - return _breadcrumb_getTitle($crumbs, 'page'); - } else if ($prefs['feature_breadcrumbs'] != 'y' && $loc == "page" && $prefs['feature_page_title'] == 'y') {// for previous compatibility - return _breadcrumb_getTitle($crumbs, 'page'); - } - return; + if ($prefs['feature_breadcrumbs'] == 'n' && ($prefs['feature_wiki_description'] == 'y' && $info)) { + return _breadcrumb_getTitle($crumbs, $loc); + } else if ($prefs['feature_breadcrumbs'] == 'n' && $loc == "admin") { + return _breadcrumb_getTitle($crumbs, $loc); + } else if ($prefs['feature_breadcrumbs'] == 'y') { + if ($loc == 'page' && ($prefs['feature_siteloc'] == 'page' || ($prefs['feature_page_title'] == 'y' && $info) ) ) { + return _breadcrumb_getTitle($crumbs, $loc); + } else if (($loc == 'site' || $loc == 'location') && $prefs['feature_siteloc'] == 'y') { + return _breadcrumb_getTitle($crumbs, $loc); + } + } else if ($loc == "admin") { + return _breadcrumb_getTitle($crumbs, 'page'); + } else if ($prefs['feature_breadcrumbs'] != 'y' && $loc == "page" && $prefs['feature_page_title'] == 'y') {// for previous compatibility + return _breadcrumb_getTitle($crumbs, 'page'); + } + return; } /** @@ -225,12 +241,13 @@ * @param loc where the description will be used: {site|page} site header or page header */ /* static */ -function _breadcrumb_getTitle($crumbs, $loc) { - global $prefs, $print_page, $info, $structure, $structure_path, $tikilib, $smarty; +function _breadcrumb_getTitle($crumbs, $loc) +{ + global $prefs, $print_page, $info, $structure, $structure_path, $tikilib, $smarty; $len = count($crumbs); - - if ( $prefs['feature_breadcrumbs'] == 'n' || $prefs['feature_sitetitle'] == 'title' ) { + + if ( $prefs['feature_breadcrumbs'] == 'n' || $prefs['feature_sitetitle'] == 'title' ) { require_once 'lib/smarty_tiki/modifier.sefurl.php'; if (! function_exists('smarty_modifier_escape')) { require_once 'lib/smarty_tiki/modifier.escape.php'; @@ -240,19 +257,19 @@ $metadata = ''; $current = current_object(); - $escapedHref = smarty_modifier_escape( smarty_modifier_sefurl( $current['object'], $current['type'] ) ); + $escapedHref = smarty_modifier_escape(smarty_modifier_sefurl($current['object'], $current['type'])); if ($coordinates = TikiLib::lib('geo')->get_coordinates($current['type'], $current['object'])) { $class = ' geolocated primary'; $metadata = " data-geo-lat=\"{$coordinates['lat']}\" data-geo-lon=\"{$coordinates['lon']}\""; - + if (isset($coordinates['zoom'])) { $metadata .= " data-geo-zoom=\"{$coordinates['zoom']}\""; } } $ret = '<strong><a class="'.$class.'"' . $metadata . ' title="'.tra("refresh").'" href="' . $escapedHref . '">'; - } else { + } else { $class = "crumblink"; $ret = '<a class="'.$class.'" title="'; if ( ($structure == 'y') && $info ) { @@ -264,18 +281,19 @@ $ret .= '" accesskey="'.($cnt); include_once('tiki-sefurl.php'); $ret .= '" href="'.filter_out_sefurl($crumbs[$len-1]->url).'">'; - } + } if ($prefs['feature_breadcrumbs'] == 'n' && $loc == "admin") $ret .= tra("Administration:")." "; - if (!empty($prefs['wiki_pagename_strip'])) { - include_once('lib/smarty_tiki/modifier.pagename.php'); - $ret .= tra(smarty_modifier_pagename($crumbs[$len-1]->title)).'</a>'; - } else { - $ret .= htmlentities(tra($crumbs[$len-1]->title), ENT_QUOTES, 'UTF-8').'</a>'; - } + if (!empty($prefs['wiki_pagename_strip'])) { + include_once('lib/smarty_tiki/modifier.pagename.php'); + $ret .= tra(smarty_modifier_pagename($crumbs[$len-1]->title)).'</a>'; + } else { + $ret .= htmlentities(tra($crumbs[$len-1]->title), ENT_QUOTES, 'UTF-8').'</a>'; + } $ret .= help_doclink(array('crumb'=>$crumbs[$len-1])); if ( isset($info['flag']) && $info['flag'] == 'L' && $print_page != 'y' ) { - $ret .= ' <img src="pics/icons/lock.png" height="16" width="16" alt="'.tra('locked').'" title="'.tra('locked by').' '.$info['user'].'" />'; + $ret .= ' <img src="pics/icons/lock.png" height="16" width="16" alt="' . + tra('locked') . '" title="' . tra('locked by') . ' ' . $info['user'] . '" />'; } if ( $prefs['feature_breadcrumbs'] == 'n' || $prefs['feature_sitetitle'] == 'title' ) { $ret .= '</strong>'; @@ -289,7 +307,8 @@ * @param loc where the description will be used: {site|page} site header or page header */ /* static */ -function breadcrumb_getDescription($crumbs, $loc) { +function breadcrumb_getDescription($crumbs, $loc) +{ global $prefs, $info; $len = count($crumbs); if ($prefs['feature_breadcrumbs'] == 'y') { @@ -306,7 +325,8 @@ } /* private */ -function _is_assoc($var) { - return is_array($var) && array_keys($var)!==range(0,count($var)-1); +function _is_assoc($var) +{ + return is_array($var) && array_keys($var) !== range(0, count($var) - 1); } Modified: trunk/lib/logs/logslib.php =================================================================== --- trunk/lib/logs/logslib.php 2011-11-29 21:54:00 UTC (rev 39045) +++ trunk/lib/logs/logslib.php 2011-11-29 21:55:33 UTC (rev 39046) @@ -6,9 +6,9 @@ // $Id$ //this script may only be included - so its better to die if called directly. -if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) { - header("location: index.php"); - exit; +if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { + header("location: index.php"); + exit; } class LogsLib extends TikiLib @@ -37,16 +37,12 @@ if (empty($time)) { $time = $this->now; } - /* - $query = "insert into `tiki_logs` (`logtype`,`logmessage`,`loguser`,`logip`,`logclient`,`logtime`) values (?,?,?,?,?,?)"; - $result = $this->query($query,array($type,$message,$who,$ip,$client,(int)$time)); - */ $this->add_action($type, 'system', 'system', $message, $who, $ip, $client, $time); } function list_logs($type='', $user='', $offset=0, $maxRecords=-1, $sort_mode='lastModif_desc', $find='', $min=0, $max=0) { - $actions = $this->list_actions($type, 'system', $user, $offset, $maxRecords, $sort_mode, $find, $min, $max,'', true); + $actions = $this->list_actions($type, 'system', $user, $offset, $maxRecords, $sort_mode, $find, $min, $max, '', true); return $actions; } @@ -55,6 +51,7 @@ $bindvars = array(); $amid = array(); $mid = ''; + if ($find) { $findesc = '%'.$find.'%'; $amid[] = "`logmessage` like ? or `loguser` like ? or 'logip' like ?"; @@ -62,13 +59,15 @@ $bindvars[] = $findesc; $bindvars[] = $findesc; } + if ($type) { $amid[] = "`logtype` = ?"; $bindvars[] = $type; } + if ($user) { if (is_array($user)) { - $amid[] = '`loguser` in ('.implode(',',array_fill(0,count($user),'?')).')'; + $amid[] = '`loguser` in (' . implode(',', array_fill(0, count($user), '?')) . ')'; foreach ($user as $u) $bindvars[] = $u; } else { @@ -81,44 +80,54 @@ $amid[] = "`logtime` > ?"; $bindvars[] = $min; } + if ($max) { $amid[] = "`logtime` < ?"; $bindvars[] = $max; } + if (count($amid)) { - $mid = " where ".implode(" and ",$amid)." "; + $mid = " where " . implode(" and ", $amid) . " "; } + $query = "select `logId`,`loguser`,`logtype`,`logmessage`,`logtime`,`logip`,`logclient` "; - $query.= " from `tiki_logs` $mid order by ".$this->convertSortMode($sort_mode); + $query.= " from `tiki_logs` $mid order by " . $this->convertSortMode($sort_mode); $query_cant = "select count(*) from `tiki_logs` $mid"; - $ret = $this->fetchAll($query,$bindvars,$maxRecords,$offset); - $cant = $this->getOne($query_cant,$bindvars); + $ret = $this->fetchAll($query, $bindvars, $maxRecords, $offset); + $cant = $this->getOne($query_cant, $bindvars); $retval = array(); $retval["data"] = $ret; $retval["cant"] = $cant; return $retval; } + function clean_logs($date) { $query = "delete from `tiki_actionlog` where `objectType`='system' and `lastModif`<=?"; $this->query($query, array((int)$date)); } - /* action = "Updated", "Created", "Removed", "Viewed", "Removed version $version", "Changed actual version to $version" + /** + * action = "Updated", "Created", "Removed", "Viewed", "Removed version $version", "Changed actual version to $version" * type = 'wiki page', 'category', 'article', 'image gallery', 'tracker', 'forum thread' * TODO: merge $param and $contributions together into a hash and but everything in actionlog_params - */ - function object_must_be_logged($action, $object, $objectType) { + */ + function object_must_be_logged($action, $object, $objectType) + { global $prefs; + if ($objectType == 'wiki page' && $action != 'Viewed') { $logObject = true; // to have the tiki_my_edit, history and mod-last_modif_pages } else { $logObject = $this->action_must_be_logged($action, $objectType); } - $logCateg = $prefs['feature_categories'] == 'y'? $this->action_must_be_logged('*', 'category'): false; + + $logCateg = $prefs['feature_categories'] == 'y' ? $this->action_must_be_logged('*', 'category') : false; + if (!$logObject && !$logCateg) { return 0; } + if ($logCateg) { global $categlib; include_once('lib/categories/categlib.php'); if ($objectType == 'comment') { @@ -132,18 +141,22 @@ function add_action($action, $object, $objectType='wiki page', $param='', $who='', $ip='', $client='', $date='', $contributions='', $hash='') { global $user, $prefs; + if ($objectType == 'wiki page' && $action != 'Viewed') { $logObject = true; // to have the tiki_my_edit, history and mod-last_modif_pages } else { $logObject = $this->action_must_be_logged($action, $objectType); } + $logCateg = $prefs['feature_categories'] == 'y'? $this->action_must_be_logged('*', 'category'): false; if (!$logObject && !$logCateg) { return 0; } + if ($date == '') { $date = $this->now; } + if ($who == '') { global $tokenlib; if ($prefs['auth_token_access'] == 'y' && empty($user) && !empty($tokenlib) && $tokenlib->ok) { @@ -152,18 +165,21 @@ $who = $user; } } + if ($ip == '') { $ip = $this->get_ip_address(); } + if ($client == '') { if (!empty($_SERVER['HTTP_USER_AGENT'])) { - $client = substr($_SERVER['HTTP_USER_AGENT'],0,200); + $client = substr($_SERVER['HTTP_USER_AGENT'], 0, 200); } else { $client = NULL; } } else { - $client = substr($client,0,200); + $client = substr($client, 0, 200); } + if ($logCateg) { global $categlib; include_once('lib/categories/categlib.php'); if ($objectType == 'comment') { @@ -173,21 +189,32 @@ $categs = $categlib->get_object_categories($objectType, $object); } } + $actions = array(); + if ( $logObject ) { - $param = substr( $param, 0, '200' ); + $param = substr($param, 0, '200'); if ($logCateg && count($categs) > 0) { foreach ($categs as $categ) { - $query = "insert into `tiki_actionlog` (`action`, `object`, `lastModif`, `user`, `ip`, `comment`, `objectType`, `categId`, `client`) values(?,?,?,?,?,?,?,?,?)"; + $query = "insert into `tiki_actionlog` " . + " (`action`, `object`, `lastModif`, `user`, `ip`, `comment`, `objectType`, `categId`, `client`) " . + " values(?,?,?,?,?,?,?,?,?)" + ; + $this->query($query, array($action, $object, (int)$date, $who, $ip, $param, $objectType, $categ, $client)); $actions[] = $this->lastInsertId(); } } else { - $query = "insert into `tiki_actionlog` (`action`, `object`, `lastModif`, `user`, `ip`, `comment`, `objectType`, `client`) values(?,?,?,?,?,?,?,?)"; + $query = "insert into `tiki_actionlog`" . + " (`action`, `object`, `lastModif`, `user`, `ip`, `comment`, `objectType`, `client`)" . + " values(?,?,?,?,?,?,?,?)" + ; + $this->query($query, array($action, $object, (int)$date, $who, $ip, $param, $objectType, $client)); $actions[] = $this->lastInsertId(); } } + if (!empty($contributions)) { foreach ($actions as $a) { $query = "insert into `tiki_actionlog_params` (`actionId`, `name`, `value`) values(?,?,?)"; @@ -196,17 +223,20 @@ } } } + if (!empty($hash)) { $query = "insert into `tiki_actionlog_params` (`actionId`, `name`, `value`) values(?,?,?)"; foreach ($actions as $a) { foreach ($hash as $h) { - foreach ($h as $param=>$val) { + foreach ($h as $param=>$val) { $this->query($query, array($a, $param, $val)); } } } } + return isset($actions[0])? $actions[0]: 0; + } function action_must_be_logged($action, $objectType) @@ -252,7 +282,7 @@ { global $actionlogConf; $this->delete_actionlog_conf($action, $objectType); - $action = str_replace('*','%',$action); + $action = str_replace('*', '%', $action); $query = "insert into `tiki_actionlog_conf` (`action`, `objectType`, `status`) values(?, ?, ?)"; $this->query($query, array($action, $objectType, $status)); unset($actionlogConf); @@ -270,48 +300,55 @@ function get_all_actionlog_conf() { global $actionlogConf; + if (!isset($actionlogConf)) { $actionlogConf = self::get_actionlog_conf(); } + return $actionlogConf; } function get_actionlog_conf($type = '%', $action = '%') { - $actionlogconf = array(); - $query = "select * from `tiki_actionlog_conf` where `objectType` like '$type' and `action` like '$action' order by `objectType` desc, `action` asc"; - $result = $this->query($query, array()); - while ($res = $result->fetchRow()) { - if ( $res['action'] == '%' ) { - $res['action'] = '*'; - } - $res['code'] = self::encode_actionlog_conf($res['action'], $res['objectType']); - $actionlogconf[] = $res; + $actionlogconf = array(); + $query = "select * from `tiki_actionlog_conf`" . + " where `objectType` like '$type' and `action` like '$action'" . + " order by `objectType` desc, `action` asc" + ; + $result = $this->query($query, array()); + + while ($res = $result->fetchRow()) { + if ( $res['action'] == '%' ) { + $res['action'] = '*'; } + $res['code'] = self::encode_actionlog_conf($res['action'], $res['objectType']); + $actionlogconf[] = $res; + } + return $actionlogconf; } function get_actionlog_types() { - $actionlogtype = array(); - $query = "select distinct `objectType` from `tiki_actionlog_conf` order by `objectType`"; - $result = $this->query($query, array()); - while ($res = $result->fetchRow()) { - $actionlogtypes[] = $res['objectType']; - } + $actionlogtype = array(); + $query = "select distinct `objectType` from `tiki_actionlog_conf` order by `objectType`"; + $result = $this->query($query, array()); + while ($res = $result->fetchRow()) { + $actionlogtypes[] = $res['objectType']; + } return $actionlogtypes; } function get_actionlog_actions() { - $actionlogactions = array(); - $query = "select distinct `action` from `tiki_actionlog_conf` order by `action`"; - $result = $this->query($query, array()); - while ($res = $result->fetchRow()) { - if ( $res['action'] != '%' ) { - $actionlogactions[] = $res['action']; - } + $actionlogactions = array(); + $query = "select distinct `action` from `tiki_actionlog_conf` order by `action`"; + $result = $this->query($query, array()); + while ($res = $result->fetchRow()) { + if ( $res['action'] != '%' ) { + $actionlogactions[] = $res['action']; } + } return $actionlogactions; } @@ -326,9 +363,10 @@ } function list_actions($action='', $objectType='', $user='', $offset=0 - , $maxRecords=-1, $sort_mode='lastModif_desc', $find='', $start=0 - , $end=0, $categId='', $all=false - ) { + , $maxRecords=-1, $sort_mode='lastModif_desc', $find='', $start=0 + , $end=0, $categId='', $all=false + ) + { global $prefs, $section, $tikilib, $contributionlib; include_once('lib/contribution/contributionlib.php'); @@ -360,31 +398,36 @@ $bindvars[] = '' ; } else if ($user) { if (is_array($user)) { - $mid1 = '`user` in ('.implode(',',array_fill(0,count($user),'?')).')'; - $mid2 = 'ap.`value` in ('.implode(',',array_fill(0,count($user),'?')).') and ap.`name`=? and ap.`actionId`=a.`actionId`'; + $mid1 = '`user` in (' . implode(',', array_fill(0, count($user), '?')) . ')'; + $mid2 = 'ap.`value` in (' . implode(',', array_fill(0, count($user), '?')) . ') and ap.`name`=? and ap.`actionId`=a.`actionId`'; foreach ($user as $u) { $bindvarsU[] = $u; } + foreach ($user as $u) { $bindvarsU[] = $tikilib->get_user_id($u); } + $bindvarsU[] = 'contributor'; } else { $mid1 = '`user` = ?'; $mid2 = 'ap.`value`=? and ap.`name`=? and ap.`actionId`=a.`actionId`'; $bindvarsU[] = $user ; - $bindvarsU[] = $tikilib->get_user_id($user) ; + $bindvarsU[] = $tikilib->get_user_id($user); $bindvarsU[] = 'contributor'; } } + if ($start) { $amid[] = "`lastModif` > ?"; $bindvars[] = $start; } + if ($end) { $amid[] = "`lastModif` < ?"; $bindvars[] = $end; } + if ($categId && $categId != 0) { if (is_array($categId)) { $amid[] = "`categId`in (?)"; @@ -394,58 +437,75 @@ $bindvars[] = $categId; } } + $amid[] = " a.`action` like c.`action` and a.`objectType` = c.`objectType`".($all? "":" and (c.`status` = 'v')"); if (count($amid)) { - $mid = implode(" and ",$amid); + $mid = implode(" and ", $amid); } + if (!empty($bindvarsU)) { $bindvars = array_merge($bindvars, $bindvarsU, $bindvars); $query = "(select distinct a.* from `tiki_actionlog` a ,`tiki_actionlog_conf` c where $mid and $mid1)"; $query .= "union (select distinct a.* from `tiki_actionlog` a ,`tiki_actionlog_conf` c,`tiki_actionlog_params` ap where $mid2 and $mid)"; - $query_cant = "select count(distinct `actionId`) from `tiki_actionlog` where `actionId` in (select distinct a.`actionId` from `tiki_actionlog` a ,`tiki_actionlog_conf` c where $mid and $mid1 union select distinct a.`actionId` from `tiki_actionlog` a ,`tiki_actionlog_conf` c,`tiki_actionlog_params` ap where $mid2 and $mid)"; + + $query_cant = "select count(distinct `actionId`) from `tiki_actionlog`" . + " where `actionId` in" . + " (select distinct a.`actionId` from `tiki_actionlog` a ,`tiki_actionlog_conf` c" . + " where $mid and $mid1 union select distinct a.`actionId`" . + " from `tiki_actionlog` a ,`tiki_actionlog_conf` c,`tiki_actionlog_params` ap where $mid2 and $mid)" + ; + } else { $query = "select distinct a.* from `tiki_actionlog` a ,`tiki_actionlog_conf` c where $mid"; $query_cant = "select count(distinct actionId) from `tiki_actionlog` a ,`tiki_actionlog_conf` c where $mid"; } - $query .= " order by ".$this->convertSortMode($sort_mode); + + $query .= " order by " . $this->convertSortMode($sort_mode); $result = $this->query($query, $bindvars, $maxRecords, $offset); $cant = $this->getOne($query_cant, $bindvars); $ret = array(); + while ($res = $result->fetchRow()) { - if ($prefs['feature_contribution'] == 'y' && ($res['action'] == 'Created' || $res['action'] == 'Updated' || $res['action'] == 'Posted' || $res['action'] == 'Replied')) { - if ($res['objectType'] == 'wiki page') { - $res['contributions'] = $this->get_action_contributions($res['actionId']); - } elseif ($id = $this->get_comment_action($res)) { - $res['contributions'] = $this->get_action_contributions($res['actionId']); - } else { - $res['contributions'] = $contributionlib->get_assigned_contributions($res['object'], $res['objectType']); // todo: do a left join - } + if ($prefs['feature_contribution'] == 'y' && + ($res['action'] == 'Created' || $res['action'] == 'Updated' || $res['action'] == 'Posted' || $res['action'] == 'Replied')) { + + if ($res['objectType'] == 'wiki page') { + $res['contributions'] = $this->get_action_contributions($res['actionId']); + } elseif ($id = $this->get_comment_action($res)) { + $res['contributions'] = $this->get_action_contributions($res['actionId']); + } else { + $res['contributions'] = $contributionlib->get_assigned_contributions($res['object'], $res['objectType']); // todo: do a left join } - if ($prefs['feature_contributor_wiki'] == 'y' && $res['objectType'] == 'wiki page') { - $res['contributors'] = $this->get_contributors($res['actionId']); - $res['nbContributors'] = 1 + count($res['contributors']); + } + + if ($prefs['feature_contributor_wiki'] == 'y' && $res['objectType'] == 'wiki page') { + $res['contributors'] = $this->get_contributors($res['actionId']); + $res['nbContributors'] = 1 + count($res['contributors']); + } + + if ($res['objectType'] == 'comment' && empty($res['categId'])) { + global $categlib; include_once('lib/categories/categlib.php'); + preg_match('/type=([^&]*)/', $res['comment'], $matches); + $categs = $categlib->get_object_categories($matches[1], $res['object']); + $i = 0; + + foreach ($categs as $categId) { + $res['categId'] = $categId; + if ($i++ > 0) + $ret[] = $res; } - // patch for xavi - if ($res['objectType'] == 'comment' && empty($res['categId'])) { - global $categlib; include_once('lib/categories/categlib.php'); - preg_match('/type=([^&]*)/', $res['comment'], $matches); - $categs = $categlib->get_object_categories($matches[1], $res['object']); - $i = 0; - foreach ($categs as $categId) { - $res['categId'] = $categId; - if ($i++ > 0) - $ret[] = $res; - } - } - // For tiki logs - if ( $res['objectType'] === 'system' ) { - $what = $res['object'] === 'system' ? '':$res['object'].' : '; - $res['object'] = $res['action']; - $res['action'] = $what.$res['comment']; - } - $ret[] = $res; + } + + // For tiki logs + if ( $res['objectType'] === 'system' ) { + $what = $res['object'] === 'system' ? '':$res['object'].' : '; + $res['object'] = $res['action']; + $res['action'] = $what.$res['comment']; + } + $ret[] = $res; } + return array('data' => $ret, 'cant' => $cant); } @@ -460,22 +520,25 @@ if ($endDate > $this->now) { $endDate = $this->now; } + $logTimes = array(); + foreach ($logins as $login) { if (!array_key_exists($login['user'], $logTimes)) { if ($login['action'] == 'timeout' || $login['action'] == 'logged out') { $logTimes[$login['user']]['last'] = $startDate; - } else { + } else { $logTimes[$login['user']]['last'] = 0; - } + } $logTimes[$login['user']]['time'] = 0; $logTimes[$login['user']]['nbLogins'] = 0; } + if (strstr($login['action'], 'logged from') || $login['action'] == 'back') { if (strstr($login['action'], 'logged from')) { ++$logTimes[$login['user']]['nbLogins']; } - // can be already log in + // can be already log in if ($logTimes[$login['user']]['last'] == 0) { $logTimes[$login['user']]['last'] = $login['lastModif']; } @@ -484,18 +547,21 @@ $logTimes[$login['user']]['last'] = 0; } } + // update time for those still logged in foreach ($logTimes as $user=>$logTime) { if ($logTime['last']) { $logTimes[$user]['time'] += $endDate - $logTime['last']; } } + // update time for those who were always logged in foreach ($actions as $action) { if ($action['user'] && !array_key_exists($action['user'], $logTimes)) { $logTimes[$action['user']]['time'] = $endDate - $startDate; } } + foreach ($logTimes as $user=>$login) { $nbMin = floor($login['time']/60); $nbHour = floor($nbMin/60); @@ -505,12 +571,15 @@ $logTimes[$user]['hours'] = $nbHour - $nbDay*24; $logTimes[$user]['days'] = $nbDay; } - return $logTimes; + + return $logTimes; + } function get_volume_action($action) { $bytes = array(); + if (preg_match('/bytes=([0-9\-+]+)/', $action['comment'], $matches)) {//old syntax if (preg_match('/\+([0-9]+)/', $matches[1], $m)) { $bytes['add'] = $m[1]; @@ -526,7 +595,9 @@ $bytes['del'] = $matches[1]; } } + return $bytes; + } function get_comment_action($action) @@ -547,6 +618,7 @@ function get_stat_actions_per_user($actions) { $stats = $this->get_stat_actions_per_field($actions, 'user'); + return $stats; } @@ -554,19 +626,19 @@ { $stats = array(); $actions_name = array(); - + $actionlogConf = $this->get_all_actionlog_conf(); foreach ($actions as $action) { - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } $name = $action['action'].'/'.$action['objectType']; $sort = $action['objectType'].'/'.$action['action']; - if ( $this->action_is_viewed($action['action'],$action['objectType']) and !in_array($name, $actions_name)) { + if ( $this->action_is_viewed($action['action'], $action['objectType']) and !in_array($name, $actions_name)) { $actions_name[$sort] = $name; } } @@ -576,19 +648,20 @@ foreach ($actions as $action) { $key = $action[$field]; if ( !isset($stats[$key]) ) { - $stats[$key] = array_fill_keys($actions_name,0); + $stats[$key] = array_fill_keys($actions_name, 0); $stats[$key][$field] = $action[$field]; } - $name = $action['action'].'/'.$action['objectType']; - if ( ($index = array_search($name,$actions_name)) !== false ) { + $name = $action['action'] . '/' . $action['objectType']; + if ( ($index = array_search($name, $actions_name)) !== false ) { if ($field == 'object') { $stats[$key]['link'] = isset($action['link']) ? $action['link'] : null; } ++$stats[$key][$name]; } } - + sort($stats, SORT_STRING); // will sort on the first field + return $stats; } @@ -597,30 +670,41 @@ global $tikilib; $statGroups = array(); foreach ($actions as $action) { - if (!empty($previousAction) && $action['lastModif'] == $previousAction['lastModif'] && $action['user'] == $previousAction['user'] && $action['object'] == $previousAction['object'] && $action['objectType'] == $previousAction['objectType']) { - // differ only by the categories - continue; + if (!empty($previousAction) && + $action['lastModif'] == $previousAction['lastModif'] && + $action['user'] == $previousAction['user'] && + $action['object'] == $previousAction['object'] && + $action['objectType'] == $previousAction['objectType']) { + // differ only by the categories + continue; } - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + $previousAction = $action; + if (empty($action['user'])) { $groups = array('Anonymous'); } else { $groups = $tikilib->get_user_groups($action['user']); $groups = array_diff($groups, array('Anonymous')); } + foreach ($groups as $key=>$group) { if (isset($selectedGroups) && $selectedGroups[$group] != 'y') { continue; } + if (empty($action['contributions'])) { continue; } + foreach ($action['contributions'] as $contribution) { if (!isset($statGroups[$group])) { $statGroups[$group][$contribution['name']]['add'] = 0; @@ -634,6 +718,7 @@ } } ksort($statGroups); + return $statGroups; } @@ -641,16 +726,20 @@ { $stats = array(); $actionlogConf = $this->get_all_actionlog_conf(); + foreach ($actions as $action) { //if ($action['categId'] == 0) print also stat for non categ object // continue; - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } $key = $action['categId']; + if (!array_key_exists($key, $stats)) { $stats[$key]['category'] = $key? $categNames[$key]: ''; foreach ($actionlogConf as $conf) { @@ -663,6 +752,7 @@ ++$stats[$key][$action['action'].'/'.$action['objectType']]; } sort($stats); //sort on the first field category + return $stats; } @@ -670,39 +760,49 @@ { $stats = array(); $actionlogConf = $this->get_all_actionlog_conf(); + foreach ($actions as $action) { //if ($action['categId'] == 0) print also stat for non categ object // continue; - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + if (!($bytes = $this->get_volume_action($action))) { continue; } + $key = $action['categId']; if (!array_key_exists($key, $stats)) { $stats[$key]['category'] = $key? $categNames[$key]: ''; } + if (!isset($stats[$key][$action['objectType']]['add'])) { $stats[$key][$action['objectType']]['add'] = 0; $stats[$key][$action['objectType']]['del'] = 0; $stats[$key][$action['objectType']]['dif'] = 0; } $dif = 0; + if (isset($bytes['add'])) { $stats[$key][$action['objectType']]['add'] += $bytes['add']; $dif = $bytes['add']; } + if (isset($bytes['del'])) { $stats[$key][$action['objectType']]['del'] += $bytes['del']; $dif -= $bytes['del']; } + $stats[$key][$action['objectType']]['dif'] += $dif; } sort($stats); //sort on the first field category + return $stats; } @@ -710,34 +810,42 @@ { $stats = array(); $actionlogConf = $this->get_all_actionlog_conf(); + foreach ($actions as $action) { //if ($action['categId'] == 0) print also stat for non categ object // continue; - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + if ($action['user'] == '' || !($bytes = $this->get_volume_action($action))) { continue; } + $key = $action['categId'].'/'.$action['user']; if (!array_key_exists($key, $stats)) { $stats[$key]['category'] = $action['categId']? $categNames[$action['categId']]: ''; $stats[$key]['user'] = $action['user']; } + if (!isset($stats[$key][$action['objectType']]['add'])) { $stats[$key][$action['objectType']]['add'] = 0; $stats[$key][$action['objectType']]['del'] = 0; $stats[$key][$action['objectType']]['dif'] = 0; } + $dif = 0; if (isset($bytes['add'])) { $stats[$key][$action['objectType']]['add'] += $bytes['add']; $dif = $bytes['add']; } + if (isset($bytes['del'])) { $stats[$key][$action['objectType']]['del'] += $bytes['del']; $dif -= $bytes['del']; @@ -745,6 +853,7 @@ $stats[$key][$action['objectType']]['dif'] += $dif; } sort($stats); //sort on the first field category + return $stats; } @@ -758,8 +867,10 @@ } } } + return $types; } + function get_actions_per_user_categ($actions, $categNames) { $stats = array(); @@ -768,13 +879,17 @@ if (empty($action['categId'])) { continue; } - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + $key = $action['categId'].'/'.$action['user'];; + if (!array_key_exists($key, $stats)) { $stats[$key]['category'] = $categNames[$action['categId']]; $stats[$key]['user'] = $action['user']; @@ -788,6 +903,7 @@ ++$stats[$key][$action['action'].'/'.$action['objectType']]; } sort($stats); // sort on the first fields categ , then user + return $stats; } @@ -807,51 +923,58 @@ function export($actionlogs, $unit = 'b') { - $csv = "user,date,time,action,type,object,category,categId,ip, unit,+,-,contribution\r\n"; - foreach ($actionlogs as $action) { - if (!isset($action['object'])) { - $action['object'] = ''; - } - if (!isset($action['categName'])) { - $action['categName'] = ''; - $action['categId'] = ''; - } - if (!isset($action['add'])) { - $action['add'] = ''; - } - if (!isset($action['del'])) { - $action['del'] = ''; - } - if (!isset($action['ip'])) { - $action['ip'] = ''; - } - $csv.= '"' . $action['user'] - . '","' . $this->date_format("%y%m%d", $action['lastModif']) - . '","' . $this->date_format("%H:%M", $action['lastModif']) - . '","' . $action['action'] - . '","' . $action['objectType'] - . '","' . $action['object'] - . '","' . $action['categName'] - . '","' . $action['categId'] - . '","' . $action['ip'] - . '","' . $unit - . '","' . $action['add'] - . '","' . $action['del'] - .'","' - ; - if (isset($action['contributions'])) { - $i = 0; - foreach ($action['contributions'] as $contribution) { - if ($i++) { - $csv .= ','; + $csv = "user,date,time,action,type,object,category,categId,ip, unit,+,-,contribution\r\n"; + foreach ($actionlogs as $action) { + if (!isset($action['object'])) { + $action['object'] = ''; + } + + if (!isset($action['categName'])) { + $action['categName'] = ''; + $action['categId'] = ''; + } + + if (!isset($action['add'])) { + $action['add'] = ''; + } + + if (!isset($action['del'])) { + $action['del'] = ''; + } + + if (!isset($action['ip'])) { + $action['ip'] = ''; + } + + $csv.= '"' . $action['user'] + . '","' . $this->date_format("%y%m%d", $action['lastModif']) + . '","' . $this->date_format("%H:%M", $action['lastModif']) + . '","' . $action['action'] + . '","' . $action['objectType'] + . '","' . $action['object'] + . '","' . $action['categName'] + . '","' . $action['categId'] + . '","' . $action['ip'] + . '","' . $unit + . '","' . $action['add'] + . '","' . $action['del'] + .'","' + ; + + if (isset($action['contributions'])) { + $i = 0; + foreach ($action['contributions'] as $contribution) { + if ($i++) { + $csv .= ','; + } + $csv .= $contribution['name']; } - $csv .= $contribution['name']; } + $csv .= "\"\n"; } - $csv .= "\"\n"; + + return $csv; } - return $csv; - } function get_action_params($actionId, $name='') { @@ -866,12 +989,14 @@ $ret[] = $res['value']; } } + return $ret; } function get_action_contributions($actionId) { $query = "select tc.* from `tiki_contributions` tc, `tiki_actionlog_params` tp where tp.`actionId`=? and tp.`name`=? and tp.`value`=tc.`contributionId`"; + return $this->fetchAll($query, array($actionId, 'contribution')); } @@ -914,9 +1039,11 @@ function insert_params($actionId, $param, $values) { $query = "insert into `tiki_actionlog_params` (`actionId`, `name`, `value`) values(?,?,?)"; + foreach ($values as $val) { $this->query($query, array($actionId, $param, $val)); } + } function get_stat_contribution($actions, $startDate, $endDate, $unit='w') @@ -933,16 +1060,20 @@ && $action['user'] == $previousAction['user'] && $action['object'] == $previousAction['object'] && $action['objectType'] == $previousAction['objectType'] - ) { + ) { // differ only by the categories continue; } + $previousAction = $action; + foreach ($action['contributions'] as $contrib) { $i = floor(($action['lastModif'] - $startDate) / (60*60*24)); + if ($unit != 'd') { $i = floor($i/7); } + if (empty($contributions[$contrib['contributionId']])) { $contributions[$contrib['contributionId']]['name'] = $contrib['name']; for ($j = 0; $j < $nbCols; ++$j) { @@ -953,48 +1084,57 @@ $contributions[$contrib['contributionId']]['stat'][$j]['nbUpdate'] = 0; } } + if (!empty($action['add'])) { $contributions[$contrib['contributionId']]['stat'][$i]['add'] += $action['add']; if (empty($action['del'])) { ++$contributions[$contrib['contributionId']]['stat'][$i]['nbAdd']; } } + if (!empty($action['del'])) { $contributions[$contrib['contributionId']]['stat'][$i]['del'] += $action['del']; if (empty($action['add'])) { ++$contributions[$contrib['contributionId']]['stat'][$i]['nbDel']; } } + if (!empty($action['add']) && !empty($action['del'])) { ++$contributions[$contrib['contributionId']]['stat'][$i]['nbUpdate']; } } } } + return (array('nbCols'=>$nbCols, 'data'=>$contributions)); } function get_stat_contributions_per_user($actions) { $tab = array(); + foreach ($actions as $action) { - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + if (isset($action['contributions'])) { if (!empty($previousAction) && $action['lastModif'] == $previousAction['lastModif'] && $action['object'] == $previousAction['object'] && $action['objectType'] == $previousAction['objectType'] && $action['categId'] != $previousAction['categId'] - ) { + ) { // differ only by the categories continue; } + $previousAction = $action; + foreach ($action['contributions'] as $contrib) { if (empty($tab[$action['user']]) or empty($tab[$action['user']]['stat'][$contrib['contributionId']])) { $tab[$action['user']][$contrib['contributionId']]['name'] = $contrib['name']; @@ -1004,18 +1144,21 @@ $tab[$action['user']][$contrib['contributionId']]['stat']['nbDel'] = 0; $tab[$action['user']][$contrib['contributionId']]['stat']['nbUpdate'] = 0; } + if ($action['contributorAdd']) { $tab[$action['user']][$contrib['contributionId']]['stat']['add'] += $action['contributorAdd']; if (!$action['contributorDel']) { ++$tab[$action['user']][$contrib['contributionId']]['stat']['nbAdd']; } } + if ($action['contributorDel']) { $tab[$action['user']][$contrib['contributionId']]['stat']['del'] += $action['contributorDel']; if (!$action['contributorAdd']) { ++$tab[$action['user']][$contrib['contributionId']]['stat']['nbDel']; } } + if ($action['contributorAdd'] && $action['contributorDel']) { ++$tab[$action['user']][$contrib['contributionId']]['stat']['nbUpdate']; } @@ -1023,6 +1166,7 @@ } } ksort($tab); + return array('data'=>$tab, 'nbCols'=>count($tab));; } @@ -1041,11 +1185,13 @@ $colors[] = 'purple'; if (!--$nb) return $colors; $colors[] = 'silver'; if (!--$nb) return $colors; $colors[] = 'teal'; if (!--$nb) return $colors; + if ( $nb > 0 ) { while (--$nb) { $colors[] = rand(1, 999999); } } + return $colors; } @@ -1056,6 +1202,7 @@ $ret['x'][] = tra('Contributions'); $ret['color'] = $this->get_colors($contributions['cant']); $iy = 0; + foreach ($contributions['data'] as $contribution) { $ret['label'][] = utf8_decode($contribution['name']); $vol = 0; @@ -1064,10 +1211,12 @@ $vol += $contributionStat['data'][$contribution['contributionId']]['stat'][$ix][$type]; } } + $ret["y$iy"][] = $vol; $ret['totalVol'] += $vol; ++$iy; } + return $ret; } @@ -1075,15 +1224,19 @@ { $ret = array(); $ret['totalVol'] = 0; + for ($i = 1, $nb = $contributionStat['nbCols']; $nb; --$nb) { $ret['x'][] = $i++; } + $ret['color'] = $this->get_colors($contributions['cant']); $iy = 0; + foreach ($contributions['data'] as $contribution) { $ret['label'][] = utf8_decode($contribution['name']); for ($ix = 0; $ix < $contributionStat['nbCols']; ++$ix) { - if (empty($contributionStat['data'][$contribution['contributionId']]) || empty($contributionStat['data'][$contribution['contributionId']]['stat'][$ix])) { + if (empty($contributionStat['data'][$contribution['contributionId']]) || + empty($contributionStat['data'][$contribution['contributionId']]['stat'][$ix])) { $ret["y$iy"][] = 0; } else { $ret["y$iy"][] = $contributionStat['data'][$contribution['contributionId']]['stat'][$ix][$type]; @@ -1092,6 +1245,7 @@ } ++$iy; } + return $ret; } @@ -1099,11 +1253,14 @@ { $ret = array(); $ret['totalVol'] = 0; + foreach ($userStat['data'] as $user=>$stats) { $ret['x'][] = utf8_decode($user); } + $ret['color'] = $this->get_colors($contributions['cant']); $iy = 0; + foreach ($contributions['data'] as $contribution) { $ret['label'][] = utf8_decode($contribution['name']); foreach ($userStat['data'] as $user=>$stats) { @@ -1116,6 +1273,7 @@ } ++$iy; } + return $ret; } @@ -1123,11 +1281,14 @@ { $ret = array(); $ret['totalVol'] = 0; + foreach ($groupContributions as $group=>$stats) { $ret['x'][] = utf8_decode($group); } + $ret['color'] = $this->get_colors($contributions['cant']); $iy = 0; + foreach ($contributions['data'] as $contribution) { $ret['label'][] = utf8_decode($contribution['name']); foreach ($groupContributions as $group=>$stats) { @@ -1140,6 +1301,7 @@ } ++$iy; } + return $ret; } @@ -1149,39 +1311,49 @@ return $this->fetchAll($query, array($actionId, 'contributor')); } - // get the contributors of the last update of a wiki page + /* + * get the contributors of the last update of a wiki page + * + */ function get_wiki_contributors($page_info) { - $query = 'select distinct(uu.`login`), uu.`userId` - from `tiki_actionlog_params` tap, `users_users` uu , `tiki_actionlog` ta - where tap.`actionId`= ta.`actionId` - and tap.`name`=? - and uu.`userId`=tap.`value` - and ta.`object`=? - and ta.`objectType`=? - and ta.`lastModif`=? - order by `login` asc' - ; + $query = 'select distinct(uu.`login`), uu.`userId` ' . + ' from `tiki_actionlog_params` tap, `users_users` uu , `tiki_actionlog` ta' . + ' where tap.`actionId`= ta.`actionId` ' . + ' and tap.`name`=? ' . + ' and uu.`userId`=tap.`value` ' . + ' and ta.`object`=? ' . + ' and ta.`objectType`=? ' . + ' and ta.`lastModif`=? ' . + ' order by `login` asc' + ; + return $this->fetchAll($query, array('contributor', $page_info['pageName'], 'wiki page', $page_info['lastModif'])); } - + function split_actions_per_contributors($actions, $users) { $contributorActions = array(); + foreach ($actions as $action) { $bytes = $this->get_volume_action($action); - if ( strpos($action['action'],'logged from') === 0 ) { - $action['action'] = 'login'; - } - if ( strpos($action['action'],'logged out') === 0 ) { - $action['action'] = 'login'; - } + + if ( strpos($action['action'], 'logged from') === 0 ) { + $action['action'] = 'login'; + } + + if ( strpos($action['action'], 'logged out') === 0 ) { + $action['action'] = 'login'; + } + $nbC = isset($action['nbContributors'])? $action['nbContributors']:1; + if (isset($bytes['add'])) { $action['add'] = $bytes['add']; $action['contributorAdd'] = round($bytes['add']/$nbC); $action['comment'] = 'add='.$action['contributorAdd']; } + if (isset($bytes['del'])) { $action['del'] = $bytes['del']; $action['contributorDel'] = round($bytes['del']/$nbC); @@ -1191,9 +1363,11 @@ $action['comment'] = 'del='.$action['contributorDel']; } } + if (empty($users) || in_array($action['user'], $users)) { $contributorActions[] = $action; } + if (isset($action['contributors'])) { foreach ($action['contributors'] as $contributor) { if (empty($users) || in_array($contributor['login'], $users)) { @@ -1210,11 +1384,13 @@ { global $prefs; $bindvars = array(); + if (!empty($find)) { $findesc = '%'.$find.'%'; $amid = '`sql1` like ? or `params` like ? or `tracer` like ?'; $bindvars[] = $findesc;$bindvars[] = $findesc;$bindvars[] = $findesc; } + $query = 'select * from `adodb_logsql`'.($find?" where $amid":'').' order by '.$this->convertSortMode($sort_mode); $ret = $this->fetchAll($query, $bindvars, $maxRecords, $offset); $query_cant = 'select count(*) from `adodb_logsql`'.($find?" where $amid":''); @@ -1222,6 +1398,7 @@ $retval = array(); $retval['data'] = $ret; $retval['cant'] = $cant; + return $retval; } @@ -1237,179 +1414,224 @@ $jpgraph->setMarginColor($color); $jpgraph->xaxis->SetTickLabels($series['x']); $plot = array(); + for ($i = 0; isset($series["y$i"]); ++$i) { $plot[$i] = new BarPlot($series["y$i"]); $plot[$i]->SetFillColor($series['color'][$i]); $plot[$i]->SetLegend($series['label'][$i]); } + if ($accumulated) { $gbplot = new AccBarPlot($plot); } else { $gbplot = new GroupBarPlot($plot); } - //$jpgraph ->legend->Pos( 0.5,0.5,"right" ,"center"); + $jpgraph->legend->SetFillColor($colorLegend); - $jpgraph->Add( $gbplot); + $jpgraph->Add($gbplot); } function insert_image($galleryId, $graph, $ext, $title, $period) { global $prefs, $user; global $imagegallib; include_once('lib/imagegals/imagegallib.php'); - $filename = $prefs['tmpDir'].'/'.md5(rand().time()).'.'.$ext; + + $filename = $prefs['tmpDir'] . '/' . md5(rand() . time()) . '.' . $ext; $graph->Stroke($filename); $info = getimagesize($filename); $size = filesize($filename); $fp = fopen($filename, "rb"); $data = fread($fp, $size); fclose($fp); - $imagegallib->insert_image($_REQUEST['galleryId'], $title.$period, '', $title.$period.'.'.$ext, 'image/'.$ext, $data, $size, $info[0], $info[1], $user, '', ''); + $imagegallib->insert_image( + $_REQUEST['galleryId'], + $title . $period, + '', + $title . $period . '.' . $ext, + 'image/' . $ext, + $data, + $size, + $info[0], + $info[1], + $user, + '', + '' + ); } function get_more_info($actions, $categNames = array()) { global $tikilib, $prefs; - foreach($actions as &$action) { - if ( empty($action['user']) ) { - $action['user'] = 'Anonymous'; - } - if ($action['categId'] && $categNames) { - $action['categName'] = $categNames[$action['categId']]; - } - if ($bytes = $this->get_volume_action($action)) { - if (isset($bytes['add'] )) { - $action['add'] = $bytes['add']; + + foreach ($actions as &$action) { + if ( empty($action['user']) ) { + $action['user'] = 'Anonymous'; } - if (isset($bytes['del'])) { - $action['del'] = $bytes['del']; + + if ($action['categId'] && $categNames) { + $action['categName'] = $categNames[$action['categId']]; } - } - switch ($action['objectType']) { - case 'wiki page': - if (preg_match("/old=(.*)/", $action['comment'], $matches)) { - $action['link'] = 'tiki-index.php?page='.$action['object'].'&old='.$matches[1]; - } else { - $action['link'] = 'tiki-index.php?page='.$action['object']; - } - break; - case 'article': - global $artlib; require_once 'lib/articles/artlib.php'; - $action['link'] = 'tiki-read_article.php?articleId='.$action['object']; - if (!isset($articleNames)) { - $objects = $artlib->list_articles(0, -1, 'title_asc', '', 0, 0, ''); - $articleNames = array(); - foreach ($objects['data'] as $object) { - $articleNames[$object['articleId']] = $object['title']; + + if ($bytes = $this->get_volume_action($action)) { + if (isset($bytes['add'] )) { + $action['add'] = $bytes['add']; } - } - if (!empty($articleNames[$action['object']])) - $action['object'] = $articleNames[$action['object']]; - break; - case 'category': - $action['link'] = 'tiki-browse_categories.php?parentId='.$action['object']; - if ($categNames && !empty($categNames[$actio... [truncated message content] |