Customizing SMF > Now Available
How to create custom 'action'
Red:
nice idea, im thinkin of using it for a karma log, but im stuck on a small problem
ive a few custom actions done, one is action=karmalog to show who Applauds/Smites but i cant get it to work right, could someone help me out on the script? im new to php..
this is the code i wanna use for the template but its wrong somewhere, any ideas?
--- Code: ---<?php
function template_main()
{
global $context, $settings, $options, $txt, $scripturl;
echo '
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>', theme_linktree(), '</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg">
<td align="center">Karma Log</td>
</tr><tr>
<td class="windowbg">';
echo '<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr>
<?php
include ('SSI.php');
global $db_prefix;
$karma_result = db_query("
SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, memt.realName AS targetName, meme.realName AS executorName, meme.ID_MEMBER as executorID, memt.ID_MEMBER as targetID
FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme
WHERE memt.ID_MEMBER = lk.ID_TARGET
AND meme.ID_MEMBER = lk.ID_EXECUTOR
ORDER BY logTime DESC
LIMIT 100", __FILE__, __LINE__);
$return = array();
while ($row_karmas = mysql_fetch_assoc($karma_result))
$return[] = array(
'executor' => $row_karmas['executorName'],
'executorID' => $row_karmas['executorID'],
'target' => $row_karmas['targetName'],
'targetID' => $row_karmas['targetID'],
'action' => $row_karmas['action'] == 1 ? '<font color=green>Applauds' : '<font color=#CC0000>Smites',
'time' => timeformat($row_karmas['logTime'])
);
mysql_free_result($karma_result);
foreach ($return as $data)
echo '<a href=', $scripturl, '?action=profile;u=', $data['executorID'], '><font color=#000000>', $data['executor'], '</font></a> ', $data['action'], ' <a href=', $scripturl, '?action=profile;u=', $data['targetID'], '>', $data['target'], '</a></font> ', $data['time'], '<br />';
unset($return);
?>
<td width="100%" valign="top">
</td></tr></table>';
echo '
</td>
</tr>
</table><br /><br />
';
}
?>
--- End code ---
Kirby:
I'd use:
--- Code: ---<?php
function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $boarddir, $db_prefix;
include($boarddir . '/SSI.php');
echo '
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>', theme_linktree(), '</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" class="tborder">
<tr class="titlebg">
<td align="center">Karma Log</td>
</tr>
<tr>
<td class="windowbg">
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr>';
$karma_result = db_query("
SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, memt.realName AS targetName, meme.realName AS executorName, meme.ID_MEMBER as executorID, memt.ID_MEMBER as targetID
FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme
WHERE memt.ID_MEMBER = lk.ID_TARGET
AND meme.ID_MEMBER = lk.ID_EXECUTOR
ORDER BY logTime DESC
LIMIT 100", __FILE__, __LINE__);
$return = array();
while ($row_karmas = mysql_fetch_assoc($karma_result))
{
$return[] = array(
'executor' => $row_karmas['executorName'],
'executorID' => $row_karmas['executorID'],
'target' => $row_karmas['targetName'],
'targetID' => $row_karmas['targetID'],
'action' => $row_karmas['action'] == 1 ? '<font color=green>Applauds' : '<font color=#CC0000>Smites',
'time' => timeformat($row_karmas['logTime'])
);
}
mysql_free_result($karma_result);
echo '
<td width="100%" valign="top">';
foreach ($return as $data)
echo '<a href=', $scripturl, '?action=profile;u=', $data['executorID'], '><font color=#000000>', $data['executor'], '</font></a> ', $data['action'], ' <a href=', $scripturl, '?action=profile;u=', $data['targetID'], '>', $data['target'], '</a></font> ', $data['time'], '<br />';
echo '
</td>
</tr>
</table>';
echo '
</td>
</tr>
</table><br /><br />';
}
?>
--- End code ---
[Edit: fixed a typo.]
Red:
Thank You Kirby Much appreciated. :D
Kirby:
No problem :)
guppy:
how can i reflect mypage to the tree link?
i've tried adding
--- Code: --- $context['linktree'][] = array(
'url' => $scripturl . '?action=mypage',
'name' => $txt['mypage']
);
--- End code ---
after the page title but i only get a separator..
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version