Advertisement:

Author Topic: How to create custom 'action'  (Read 172447 times)

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,550
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
How to create custom 'action'
« on: January 09, 2005, 05:01:30 PM »
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:

Code: [Select]
'activate' => array('Register.php', 'Activate'),
ad after:

Code: [Select]
'downloads' => array('Downloads.php', 'Downloads'),
Then create 'Downloads.php' like this:
Code: [Select]
<?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:

Code: [Select]
<?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 :)
« Last Edit: December 09, 2006, 07:23:03 PM by 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

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: How to create custom 'action'
« Reply #1 on: January 09, 2005, 06:07:00 PM »
Also read this, which is related but tied to themes:

http://www.simplemachines.org/community/index.php?action=dlattach;topic=7703.0;id=3102

-[Unknown]

Offline CapriSkye

  • Full Member
  • ***
  • Posts: 574
    • Open
Re: How to create custom 'action'
« Reply #2 on: January 09, 2005, 10:19:01 PM »
is there an example of this?

Offline Kirby

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,040
  • Gender: Male
Re: How to create custom 'action'
« Reply #3 on: January 10, 2005, 12:31:26 AM »
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

Offline Jerry

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,903
  • Gender: Male
  • What? I can't hear you over my awesomeness!!
    • PlanetSMF
Re: How to create custom 'action'
« Reply #4 on: January 10, 2005, 02:27:19 AM »
Then create 'Downloads.php' like this:
Code: [Select]
<?php
if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

function Downloads() {
// This is gonna be needed...
loadTemplate(&#39;Downloads&#39;);
}
?>
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:
Code: [Select]
<?php
if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

function Downloads() {
global 
$context;
$context[&#39;page_title&#39;] = &#39;My Actions title!&#39;;
// This is gonna be needed...
loadTemplate(&#39;Downloads&#39;);
}
?>
- Jerry
Find me on:
Facebook
Twitter
PlanetSMF

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

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,550
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: How to create custom 'action'
« Reply #5 on: January 10, 2005, 02:31:28 AM »
True. Thanks J! :) I changed that to first post.
« Last Edit: January 10, 2005, 12:18:28 PM by 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

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,550
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: How to create custom 'action'
« Reply #6 on: January 10, 2005, 12:39:43 PM »
Added demo.
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

Offline Fizzy

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,676
  • Gender: Male
  • SMF World Domination
Re: How to create custom 'action'
« Reply #7 on: January 11, 2005, 08:45:23 AM »
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.


Offline Tim

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,855
  • Gender: Male
  • Marketing Consultant
    • tim.ceuppens on Facebook
    • http://www.linkedin.com/in/timceuppens on LinkedIn
    • @timcbe on Twitter
    • Tim Ceuppens
Re: How to create custom 'action'
« Reply #8 on: February 01, 2005, 04:17:21 PM »
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?

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,550
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: How to create custom 'action'
« Reply #9 on: February 01, 2005, 04:26:42 PM »
Ad this to Modifications.english.php
Code: [Select]
$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

  • Guest
Re: How to create custom 'action'
« Reply #10 on: April 21, 2005, 11:45:26 PM »

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: [Select]
<?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 />
';
}

?>


Offline Kirby

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,040
  • Gender: Male
Re: How to create custom 'action'
« Reply #11 on: April 22, 2005, 07:10:51 PM »
I'd use:

Code: [Select]
<?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;;

}

?>


[Edit: fixed a typo.]
« Last Edit: April 22, 2005, 07:13:47 PM by [Unknown] »

Red

  • Guest
Re: How to create custom 'action'
« Reply #12 on: April 22, 2005, 08:49:04 PM »


Thank You Kirby  Much appreciated.  :D

Offline Kirby

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,040
  • Gender: Male
Re: How to create custom 'action'
« Reply #13 on: April 22, 2005, 09:14:08 PM »
No problem :)

Offline guppy

  • Full Member
  • ***
  • Posts: 400
  • I am guppy!
Re: How to create custom 'action'
« Reply #14 on: June 18, 2005, 09:47:31 AM »
how can i reflect mypage to the tree link?

i've tried adding

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

after the page title but i only get a separator..
Somewhere between belief and doubt lies faith ~ Jodi Picoult in Keeping Faith, 1999

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: How to create custom 'action'
« Reply #15 on: June 18, 2005, 09:48:40 AM »
Is $txt['mypage'] defined?  Did you add $txt to the global line?

-[Unknown]

Offline guppy

  • Full Member
  • ***
  • Posts: 400
  • I am guppy!
Re: How to create custom 'action'
« Reply #16 on: June 18, 2005, 09:56:54 AM »
ah.. spot on! thanks  :D
Somewhere between belief and doubt lies faith ~ Jodi Picoult in Keeping Faith, 1999

Offline Metal_GunBlade

  • Jr. Member
  • **
  • Posts: 134
  • Gender: Male
  • Life is ours to be spent, not to be saved
Re: How to create custom 'action'
« Reply #17 on: July 25, 2005, 07:57:51 AM »
If you need your custom action, here's howto. Lets say you want own dowload area.

index.php find:

Code: [Select]
'activate' => array('Register.php', 'Activate'),
ad after:

Code: [Select]
'downloads' => array('Downloads.php', 'Downloads'),
Then create 'Downloads.php' like this:
Code: [Select]
<?php
if (!defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

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

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

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

?>

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

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,550
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @@jaoler on Twitter
Re: How to create custom 'action'
« Reply #18 on: July 25, 2005, 08:05:34 AM »
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

Offline Metal_GunBlade

  • Jr. Member
  • **
  • Posts: 134
  • Gender: Male
  • Life is ours to be spent, not to be saved
Re: How to create custom 'action'
« Reply #19 on: July 25, 2005, 02:37:27 PM »
ok, these are my current files:

Downloads.template.php
Code: [Select]
<?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" >Download area</td>
</
tr><tr>
<
td class="windowbg">&#39;;

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

?>

Sources/Downloads.php
Code: [Select]
<?php
global $context;
if (!
defined(&#39;SMF&#39;))
die(&#39;Hacking attempt...&#39;);

Function Downloads()
{

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

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

isAllowedTo(&#39;view_downloads&#39;);
}

?>

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...
« Last Edit: July 25, 2005, 02:52:17 PM by Metal_GunBlade »
Life is ours to be spent, not to be saved