• Welcome to Simple Machines Community Forum. Please login or sign up.
December 02, 2021, 09:03:18 AM

News:

Wondering if this will always be free?  See why free is better.


More tags in extra info of log actions

Started by davidhs, August 27, 2018, 02:27:31 PM

Previous topic - Next topic

davidhs

Now SMF 2.0.x and 2.1 Beta x have one tag for insert message, topic and board IDs.

One of my mods inserts in Moderation log an action when something is moved from message1 to message2 and uses this:

<?php

// Language string.
$txt['modlog_ac_mymod_move'] = 'Moved the "{something}" by "{member}" from "{topic}" to "{topic2}"';

// Action logged to Moderation log.
$request $smcFunc['db_query']('''
SELECT subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_topic = {int:id_topic}'
,
array(
'id_topic' => $topic_to,
)
);
$row $smcFunc['db_fetch_assoc']($request);
$topic2 '<a href="' $scripturl '?topic=' $topic_to '.msg' $msg_to '#msg' $msg_to '">' $row['subject'] . '</a>';
$smcFunc['db_free_result']($request);

logAction('mymod_move', array('something' => $something_name'member' => $user_info['id'], 'message' => $msg_from'topic' => $topic_from'message2' => $msg_to'topic2' => $topic2));

?>


Can be added more tags to array extra?
- message2, message3,...
- topic2, topic3,...
- board2, board3,...

For example, in SMF 2.1 (GitHub version):
Code (Search in Sources/Logging.php, function logActions() (line 547)) Select
<?php

if (isset($log['extra']['member_affected']))
$memID $log['extra']['member_affected'];
else
$memID $user_info['id'];

?>

Code (Add after) Select
<?php

$fields = array('message''topic''board');
foreach ($fields as $field)
{
for ($i 2; isset($log['extra'][$field $i]); $i++)
{
if (!is_numeric($log['extra'][$field $i]))
{
trigger_error('logActions(): data\'s ' $field $i ' is not a number'E_USER_NOTICE);
unset($log['extra'][$field $i]);
break;
}
}
}

?>


Code (Search in Sources/Modlog.php, function list_getModLogEntries() (line 454)) Select
<?php

// A message?
if (isset($row['extra']['message']))
$messages[(int) $row['extra']['message']][] = $row['id_action'];

?>

Code (Add after) Select
<?php

// More messages, topics and boards. 
$fields = array('message''topic''board');
foreach ($fields as $field => $var)
{
$var $field 's';
for ($i 2; isset($row['extra'][$field $i]); $i++)
$$var[(int) $row['extra'][$field $i]][] = $row['id_action'];
}

?>


Code (Search in Sources/Modlog.php, function list_getModLogEntries() (line 519)) Select
<?php

// Make the board number into a link - dealing with moving too.
if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board'])
$entries[$action]['extra']['board_to'] = '<a href="' $scripturl '?board=' $row['id_board'] . '.0">' $row['name'] . '</a>';
elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board'])
$entries[$action]['extra']['board_from'] = '<a href="' $scripturl '?board=' $row['id_board'] . '.0">' $row['name'] . '</a>';
elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board'])
$entries[$action]['extra']['board'] = '<a href="' $scripturl '?board=' $row['id_board'] . '.0">' $row['name'] . '</a>';

?>

Code (Add after) Select
<?php

else
{
for ($i 2; isset($entries[$action]['extra']['board' $i]); $i++)
{
if ($entries[$action]['extra']['board' $i] == $row['id_board'])
{
$entries[$action]['extra']['board' $i] = '<a href="' $scripturl '?board=' $row['id_board'] . '.0">' $row['name'] . '</a>';
break;
}
}
}

?>


Code (Search in Sources/Modlog.php, function list_getModLogEntries() (line 569)) Select
<?php

// Make the topic number into a link - dealing with splitting too.
if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic'])
$this_action['extra']['topic'] = '<a href="' $scripturl '?topic=' $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' $this_action['extra']['message'] . '#msg' $this_action['extra']['message'] : '0') . '">' $row['subject'] . '</a>';
elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic'])
$this_action['extra']['new_topic'] = '<a href="' $scripturl '?topic=' $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' $this_action['extra']['message'] . '#msg' $this_action['extra']['message'] : '0') . '">' $row['subject'] . '</a>';

?>

Code (Add after) Select
<?php

else
{
for ($i 2; isset($this_action['extra']['topic' $i]); $i++)
{
if ($this_action['extra']['topic' $i] == $row['id_topic'])
{
$this_action['extra']['topic' $i] = '<a href="' $scripturl '?topic=' $row['id_topic'] . '.' . (isset($this_action['extra']['message' $i]) ? 'msg' $this_action['extra']['message' $i] . '#msg' $this_action['extra']['message' $i] : '0') . '">' $row['subject'] . '</a>';
break;
}
}
}

?>


Code (Search in Sources/Modlog.php, function list_getModLogEntries() (line 616)) Select
<?php

// Make the message number into a link.
if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg'])
$this_action['extra']['message'] = '<a href="' $scripturl '?msg=' $row['id_msg'] . '">' $row['subject'] . '</a>';

?>

Code (Add after) Select
<?php

else
{
for ($i 2; isset($this_action['extra']['message' $i]); $i++)
{
if ($this_action['extra']['message' $i] == $row['id_msg'])
{
$this_action['extra']['message' $i] = '<a href="' $scripturl '?msg=' $row['id_msg'] . '">' $row['subject'] . '</a>';
break;
}
}
}

?>

Kindred

At this point, I would say that this is beyond the scope of what remains to be done - we are working on getting an RC ready and there has to be a moratorium on new code and code changes at some point.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.<br /><br />"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: