Customizing SMF > Now Available

How to create custom 'action'

<< < (3/22) > >>

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 &#39;


<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>&#39;, theme_linktree(), &#39;</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">&#39;;
echo &#39;<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tr>
<?php

include (&#39;SSI.php&#39;);

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(
      &#39;executor&#39; => $row_karmas[&#39;executorName&#39;],
      &#39;executorID&#39; => $row_karmas[&#39;executorID&#39;],
      &#39;target&#39; => $row_karmas[&#39;targetName&#39;],
      &#39;targetID&#39; => $row_karmas[&#39;targetID&#39;],
      &#39;action&#39; => $row_karmas[&#39;action&#39;] == 1 ? &#39;<font color=green>Applauds&#39; : &#39;<font color=#CC0000>Smites&#39;,
      &#39;time&#39; => timeformat($row_karmas[&#39;logTime&#39;])
   );
mysql_free_result($karma_result);

foreach ($return as $data)
   echo &#39;<a href=&#39;, $scripturl, &#39;?action=profile;u=&#39;, $data[&#39;executorID&#39;], &#39;><font color=#000000>&#39;, $data[&#39;executor&#39;], &#39;</font></a> &#39;, $data[&#39;action&#39;], &#39; <a href=&#39;, $scripturl, &#39;?action=profile;u=&#39;, $data[&#39;targetID&#39;], &#39;>&#39;, $data[&#39;target&#39;], &#39;</a></font> &#39;, $data[&#39;time&#39;], &#39;<br />&#39;;

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 . &#39;/SSI.php&#39;);

echo &#39;
<table width="100%" border="0" cellspacing="0" cellpadding="3" >
<tr>
<td>&#39;, theme_linktree(), &#39;</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>&#39;;

$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(
&#39;executor&#39; => $row_karmas[&#39;executorName&#39;],
&#39;executorID&#39; => $row_karmas[&#39;executorID&#39;],
&#39;target&#39; => $row_karmas[&#39;targetName&#39;],
&#39;targetID&#39; => $row_karmas[&#39;targetID&#39;],
&#39;action&#39; => $row_karmas[&#39;action&#39;] == 1 ? &#39;<font color=green>Applauds&#39; : &#39;<font color=#CC0000>Smites&#39;,
&#39;time&#39; => timeformat($row_karmas[&#39;logTime&#39;])
);
}
mysql_free_result($karma_result);

echo &#39;
<td width="100%" valign="top">&#39;;
foreach ($return as $data)
   echo &#39;<a href=&#39;, $scripturl, &#39;?action=profile;u=&#39;, $data[&#39;executorID&#39;], &#39;><font color=#000000>&#39;, $data[&#39;executor&#39;], &#39;</font></a> &#39;, $data[&#39;action&#39;], &#39; <a href=&#39;, $scripturl, &#39;?action=profile;u=&#39;, $data[&#39;targetID&#39;], &#39;>&#39;, $data[&#39;target&#39;], &#39;</a></font> &#39;, $data[&#39;time&#39;], &#39;<br />&#39;;

echo &#39;
</td>
</tr>
</table>&#39;;
echo &#39;
</td>
</tr>
</table><br /><br />&#39;;

}

?>

--- 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