News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How to create custom 'action'

Started by Owdy, January 09, 2005, 05:01:30 PM

Previous topic - Next topic

Owdy

Notice:
This tip has been in some way ported over to be a modification package located on the SMF modsite. Please note, the mod package may not do the exact same function and may not even use any of the code originally written for the tip, but should still hold the same basic functionality of the tip posted here. With the mod package for this tip, you can now let the SMF package manager make the code changes for you without you having to look at the code and edit it manually.

For documentation on using the SMF package manager, view this document.

To download the modification package, please click here.

If you need your custom action, here's howto. Lets say you want own dowload area.

index.php find:

'activate' => array('Register.php', 'Activate'),

ad after:

'downloads' => array('Downloads.php', 'Downloads'),

Then create 'Downloads.php' like this:
<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Downloads() {
global 
$context;
$context['page_title'] = 'My Actions title!';
// This is gonna be needed...
loadTemplate('Downloads');
}
?>
Put that Downloads.php to /Sources/

Then, create to Themes/default/Downloads.template.php, something like this:

<?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" >Download area</td>
</tr><tr>
<td class="windowbg">'
;
 
echo 
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
  MY cool downloads!!!!
</td></tr></table>'
;
echo 
'
</td>
</tr>
</table><br /><br />
'
;
}

?>


Then just do this http://www.example.com/smf/index.php?action=downloads
You can change that 'Downloads' and modify that theme file to fit your needs.

DEMO: http://www.halko.net/smf/index.php?action=test

Enjoy :)
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]


CapriSkye


Kirby

For the themes one, there is in Unknowns guide. I've begun integrating the vCard option that was in IPB to my IPB theme using action wrapping :P

Jerry

Quote from: Owdy on January 09, 2005, 05:01:30 PM
Then create 'Downloads.php' like this:
<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Downloads() {
// This is gonna be needed...
loadTemplate('Downloads');
}
?>
Put that Downloads.php to /Sources/
I don't think this will show a page title (some one stuff a sock in my mouth if  I am wrong ;)) to make the new action have a page title you would need to do this:
<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Downloads() {
global 
$context;
$context['page_title'] = 'My Actions title!';
// This is gonna be needed...
loadTemplate('Downloads');
}
?>


- Jerry
Find me on:
Facebook
Twitter
PlanetSMF

"If all you look for is the negative in things, you will never see the positive."

Owdy

#5
True. Thanks J! :) I changed that to first post.
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Fizzy

Owdy,

Thanks for the excellent 'How to'
I can see that I will be putting this in to practice a lot.
"Reality is merely an illusion, albeit a very persistent one." - A.E.


Tim

A related question

I've got a game that runs of the userbase of SMF, and does this via the SSI. How can I show that a user is at the game page when you get the Users online list, instead f it showing unkown action?

Owdy

Ad this to Modifications.english.php
$txt['whoall_customaction'] = 'Do something in <a href="' . $scripturl . '?action=customaction">custom area</a>.';
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

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?


<?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 />
';
}

?>



Kirby

#11
I'd use:


<?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'] == '<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 />'
;

}

?>



[Edit: fixed a typo.]

Red



Thank You Kirby  Much appreciated.  :D

Kirby


guppy

how can i reflect mypage to the tree link?

i've tried adding

$context['linktree'][] = array(
'url' => $scripturl . '?action=mypage',
'name' => $txt['mypage']
);


after the page title but i only get a separator..

[Unknown]

Is $txt['mypage'] defined?  Did you add $txt to the global line?

-[Unknown]

guppy


Metal_GunBlade

Quote from: Owdy on January 09, 2005, 05:01:30 PM
If you need your custom action, here's howto. Lets say you want own dowload area.

index.php find:

'activate' => array('Register.php', 'Activate'),

ad after:

'downloads' => array('Downloads.php', 'Downloads'),

Then create 'Downloads.php' like this:
<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

function 
Downloads() {
global 
$context;
$context['page_title'] = 'My Actions title!';
// This is gonna be needed...
loadTemplate('Downloads');
}
?>
Put that Downloads.php to /Sources/

Then, create to Themes/default/ 'Downloads.template.php, something like this:

<?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" >Download area</td>
</tr><tr>
<td class="windowbg">'
;
 
echo 
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
  MY cool downloads!!!!
</td></tr></table>'
;
echo 
'
</td>
</tr>
</table><br /><br />
'
;
}

?>


Then just do this http://www.example.com/smf/index.php?action=downloads
You can change that 'Downloads' and modify that theme file to fit your needs.

DEMO: http://www.halko.net/smf/index.php?action=test

Enjoy :)
That's great, I got it up and running on SMF 1.1 Beta 3, but where shall I put the files to be downloaded in???
Life is ours to be spent, not to be saved

Owdy

Its just an example. You can put them anywhere yoy want.
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Metal_GunBlade

#19
ok, these are my current files:

Downloads.template.php
<?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" >Download area</td>
</tr><tr>
<td class="windowbg">'
;

echo 
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
         <tr>
           <td width="100%" valign="top">
  MY cool downloads!!!!
</td></tr></table>'
;
echo 
'
</td>
</tr>
</table><br /><br />
'
;
}

?>


Sources/Downloads.php
<?php
global $context;
if (!
defined('SMF'))
die(
'Hacking attempt...');

Function 
Downloads()
{

global $boardurl,$txt$scripturl,  $db_prefix;
global $ID_MEMBER;
global $context$user_info$db_prefix;
LoadTemplate('Downloads');
Loadlanguage('Downloads');

$context['page_title'] = $txt['downloads_1'];
$context['linktree'][] = array(
'url' => $scripturl '?action=downloads',
'name' => $txt['downloads_1']
);

isAllowedTo('view_downloads');
}

?>


What should I change if the downloadable files are placed in a folder named "downloads" in the root directory...???

P.S: I'm not using the default theme...
Life is ours to be spent, not to be saved

Advertisement: