aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-03-17 23:52:01 +0100
committerJoas Schilling <nickvergessen@gmx.de>2012-08-21 11:59:26 +0200
commit3fbac076ceb4773aa3c985d24eeaf306aa0b6a42 (patch)
tree4ba95b6337c0866ec71038f511034b40e07bd1d2 /phpBB/includes/functions.php
parentcf651ef81d611865a06d93c9db7c4dfcd680405c (diff)
downloadforums-3fbac076ceb4773aa3c985d24eeaf306aa0b6a42.tar
forums-3fbac076ceb4773aa3c985d24eeaf306aa0b6a42.tar.gz
forums-3fbac076ceb4773aa3c985d24eeaf306aa0b6a42.tar.bz2
forums-3fbac076ceb4773aa3c985d24eeaf306aa0b6a42.tar.xz
forums-3fbac076ceb4773aa3c985d24eeaf306aa0b6a42.zip
[ticket/10714] Use new phpbb_log class in add_log function
PHPBB3-10714
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php89
1 files changed, 49 insertions, 40 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index ecec1e5e4a..9a1485f37a 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -3357,65 +3357,74 @@ function parse_cfg_file($filename, $lines = false)
*/
function add_log()
{
- global $db, $user;
+ // This is all just an ugly hack to add "Dependency Injection" to a function
+ // the only real code is the function call which maps this function to a method.
+ static $static_log = null;
+
+ $args = func_get_args();
+ $log = (isset($args[0])) ? $args[0] : false;
- // In phpBB 3.1.x i want to have logging in a class to be able to control it
- // For now, we need a quite hakish approach to circumvent logging for some actions
- // @todo implement cleanly
- if (!empty($GLOBALS['skip_add_log']))
+ if ($log instanceof phpbb_log_interface)
+ {
+ $static_log = $log;
+ return true;
+ }
+ else if ($log === false)
{
return false;
}
- $args = func_get_args();
+ $tmp_log = $static_log;
- $mode = array_shift($args);
- $reportee_id = ($mode == 'user') ? intval(array_shift($args)) : '';
- $forum_id = ($mode == 'mod') ? intval(array_shift($args)) : '';
- $topic_id = ($mode == 'mod') ? intval(array_shift($args)) : '';
- $action = array_shift($args);
- $data = (!sizeof($args)) ? '' : serialize($args);
-
- $sql_ary = array(
- 'user_id' => (empty($user->data)) ? ANONYMOUS : $user->data['user_id'],
- 'log_ip' => $user->ip,
- 'log_time' => time(),
- 'log_operation' => $action,
- 'log_data' => $data,
- );
+ // no log class set, create a temporary one ourselves to keep backwards compatability
+ if ($tmp_log === null)
+ {
+ $tmp_log = new phpbb_log(LOG_TABLE);
+ }
+
+ $mode = array_shift($args);
+ // This looks kind of dirty, but add_log has some additional data before the log_operation
+ $additional_data = array();
switch ($mode)
{
case 'admin':
- $sql_ary['log_type'] = LOG_ADMIN;
+ case 'critical':
break;
-
case 'mod':
- $sql_ary += array(
- 'log_type' => LOG_MOD,
- 'forum_id' => $forum_id,
- 'topic_id' => $topic_id
- );
+ // forum_id
+ $additional_data[] = array_shift($args);
+ // topic_id
+ $additional_data[] = array_shift($args);
break;
-
case 'user':
- $sql_ary += array(
- 'log_type' => LOG_USERS,
- 'reportee_id' => $reportee_id
- );
+ // reportee_id
+ $additional_data[] = array_shift($args);
break;
-
- case 'critical':
- $sql_ary['log_type'] = LOG_CRITICAL;
- break;
-
default:
- return false;
+ /**
+ * @todo: enable when events are merged
+ *
+ global $phpbb_dispatcher;
+
+ if ($phpbb_dispatcher != null)
+ {
+ $vars = array('mode', 'args', 'additional_data');
+ $event = new phpbb_event_data(compact($vars));
+ $phpbb_dispatcher->dispatch('core.function_add_log', $event);
+ extract($event->get_data_filtered($vars));
+ }
+ */
}
+ $log_operation = array_shift($args);
+ $additional_data = array_merge($additional_data, $args);
+
+ global $user;
- $db->sql_query('INSERT INTO ' . LOG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
+ $user_id = (empty($user->data)) ? ANONYMOUS : $user->data['user_id'];
+ $user_ip = (empty($user->ip)) ? '' : $user->ip;
- return $db->sql_nextid();
+ return $tmp_log->add($mode, $user_id, $user_ip, $log_operation, time(), $additional_data);
}
/**