Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Now Available => Topic started by: Owdy on January 09, 2005, 05:01:30 PM

Title: How to create custom 'action'
Post by: Owdy 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 (http://mods.simplemachines.org/index.php?mod=331). 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 (http://docs.simplemachines.org/index.php?board=49.0).

To download the modification package, please click here (http://mods.simplemachines.org/index.php?mod=331).

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 :)
Title: Re: How to create custom 'action'
Post by: [Unknown] 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]
Title: Re: How to create custom 'action'
Post by: CapriSkye on January 09, 2005, 10:19:01 PM
is there an example of this?
Title: Re: How to create custom 'action'
Post by: Kirby 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
Title: Re: How to create custom 'action'
Post by: Jerry on January 10, 2005, 02:27:19 AM
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');
}
?>
Title: Re: How to create custom 'action'
Post by: Owdy on January 10, 2005, 02:31:28 AM
True. Thanks J! :) I changed that to first post.
Title: Re: How to create custom 'action'
Post by: Owdy on January 10, 2005, 12:39:43 PM
Added demo.
Title: Re: How to create custom 'action'
Post by: Fizzy 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.
Title: Re: How to create custom 'action'
Post by: Tim 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?
Title: Re: How to create custom 'action'
Post by: Owdy on February 01, 2005, 04:26:42 PM
Ad this to Modifications.english.php
$txt['whoall_customaction'] = 'Do something in <a href="' . $scripturl . '?action=customaction">custom area</a>.';
Title: Re: How to create custom 'action'
Post by: Red 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?


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

?>


Title: Re: How to create custom 'action'
Post by: Kirby on April 22, 2005, 07:10:51 PM
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'] == 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 />'
;

}

?>


[Edit: fixed a typo.]
Title: Re: How to create custom 'action'
Post by: Red on April 22, 2005, 08:49:04 PM


Thank You Kirby  Much appreciated.  :D
Title: Re: How to create custom 'action'
Post by: Kirby on April 22, 2005, 09:14:08 PM
No problem :)
Title: Re: How to create custom 'action'
Post by: guppy on June 18, 2005, 09:47:31 AM
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..
Title: Re: How to create custom 'action'
Post by: [Unknown] on June 18, 2005, 09:48:40 AM
Is $txt['mypage'] defined?  Did you add $txt to the global line?

-[Unknown]
Title: Re: How to create custom 'action'
Post by: guppy on June 18, 2005, 09:56:54 AM
ah.. spot on! thanks  :D
Title: Re: How to create custom 'action'
Post by: Metal_GunBlade on July 25, 2005, 07:57:51 AM
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???
Title: Re: How to create custom 'action'
Post by: Owdy on July 25, 2005, 08:05:34 AM
Its just an example. You can put them anywhere yoy want.
Title: Re: How to create custom 'action'
Post by: Metal_GunBlade on July 25, 2005, 02:37:27 PM
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...
Title: Re: How to create custom 'action'
Post by: sebz2005 on December 09, 2005, 04:04:33 AM
Owdy: Have you got that theme on your SMF forum avaliable?
Title: Re: How to create custom 'action'
Post by: Owdy on December 09, 2005, 02:35:52 PM
If you saw that brown theme, its for ubuntu finland site: http://forum.ubuntu-fi.org/
Title: Re: How to create custom 'action'
Post by: sebz2005 on December 10, 2005, 01:55:02 AM
Have you got it as in, packaged? or will I have to create it myself?
Title: Re: How to create custom 'action'
Post by: Owdy on December 10, 2005, 03:17:38 AM
No, that theme is not shared. Its for Ubuntu site only.
Title: Re: How to create custom 'action'
Post by: sebz2005 on December 11, 2005, 02:07:28 AM
Oh... Ok! :)

Edit: I'm following your instuctions, but how do I make the id= part:

http://localhost/LbaX/forum/downloads.php?id=04

instead of:

http://localhost/LbaX/forum/downloads.php?04

???
Title: Re: How to create custom 'action'
Post by: McNeo2 on January 12, 2006, 07:10:01 AM
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. /../

Thnx Owdy. I got it to work.

But now another question. I want that script to open inside the same page, where from I called it out. Like shoutbox. Example; if I include shoutbox to main template and then shout, it does not open page only with shoutbox, but with (within) page where it was. I tryed to look into shout.php and shout.template.php, but I did'nt get, how it works. How it remembers the page, where from it was called out.

Hopefully I explained my problem enough clear.

ps. okidoki.. i made picture about I want:
(http://kristus.pri.ee/My_Images/board1.GIF)
Title: Re: How to create custom 'action'
Post by: Gregory on January 18, 2006, 07:33:11 PM
I have used your instructions sucessfully and I'm now very happy with my result.
Just 1 point to improve my 'static' page further: How can I get so on the Who's Online page it says 'Viewing downloads' or something rather than 'Unknown Action' ?
Title: Re: How to create custom 'action'
Post by: JayBachatero on January 18, 2006, 08:13:00 PM
Quote from: Owdy on February 01, 2005, 04:26:42 PM
Ad this to Modifications.english.php
$txt['whoall_customaction'] = 'Do something in <a href="' . $scripturl . '?action=customaction">custom area</a>.';
Title: Re: How to create custom 'action'
Post by: Gregory on January 19, 2006, 08:33:23 AM
Quote from: JayBachatero on January 18, 2006, 08:13:00 PM
Quote from: Owdy on February 01, 2005, 04:26:42 PM
Ad this to Modifications.english.php
$txt['whoall_customaction'] = 'Do something in <a href="' . $scripturl . '?action=customaction">custom area</a>.';
thanks, I must of missed it by mistake  :P

Erm, this may be going off topic too much but could someone tell me if/how I can also show the user is viewing a page that isn't a forum page, it's a seperate page.php not using ?action=  anything, but it is only showing them the content if they're logged in. Or pointing me to the right direction I'd be grateful for as searching hasn't helped.
Title: Re: How to create custom 'action'
Post by: JayBachatero on January 19, 2006, 09:04:38 AM
Search for who action (http://www.simplemachines.org/community/index.php?action=search2;search=who%20action) and you will see a few posts about this.
Title: Re: How to create custom 'action'
Post by: Stuart on January 21, 2006, 06:46:26 AM
Edit  :-[

Didn't realise the templates were case sensitive  :-[

I figured it out and my own integrated FAQ page is a fact from now on  :D
Title: Re: How to create custom 'action'
Post by: Owdy on January 21, 2006, 01:48:38 PM
Stuart, i moved your post because its another issue http://www.simplemachines.org/community/index.php?topic=66969.0
Title: Re: How to create custom 'action'
Post by: Stuart on February 04, 2006, 05:32:07 PM
I actually managed to create 2 custom actions and you can see them on my website:

http://www.astmaforum.nl/index.php?action=links

http://www.astmaforum.nl/index.php?action=faq

I'm quite proud I was able to create these pages. But I couldn't have done it without the clear and easy instructions which were given in this topic. Thanks ever so much for that  :D
Title: Re: How to create custom 'action'
Post by: SleePy on February 19, 2006, 04:25:12 PM
How would i do Sub-Actions? I can't seem to figure it out.. and profile.php in sources is to confusing to try to figure out how it is doing it.
Title: Re: How to create custom 'action'
Post by: InterxWeb on March 01, 2006, 01:00:19 PM
does this automatically create a button on the 1.1rc2 forum index? and can it be set by permissions?
or does this even work in 1.1 rc2 lol.
Title: Re: How to create custom 'action'
Post by: Owdy on March 01, 2006, 01:15:38 PM
It dosnt create any buttons.
Title: Re: How to create custom 'action'
Post by: InterxWeb on March 01, 2006, 01:23:13 PM
ok well, im new to the smf scene here (sorry :P ) so if you could teach me how to add a button at the top for my new custom action. But i only want it to show if they are logged in (if possible)
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 01, 2006, 03:07:34 PM
How to add tabs to Core (NDT)? (http://www.simplemachines.org/community/index.php?topic=63203.0)
Title: Re: How to create custom 'action'
Post by: tarkhorani on March 06, 2006, 04:54:59 PM
if the file is download.htm instead of download.phpthen what we must do?
Title: Re: How to create custom 'action'
Post by: Delayed on March 10, 2006, 05:08:22 AM
What if I want to include a PHP file in the example "download.template.php" file?  Can I use an include method or do I need to paste the entire PHP file? 

It is a tell a friend PHP script that I want to put in the action.

Thanks

Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 11:21:39 AM
You can put an include with the full path to the file.
Title: PHP Include in actions
Post by: Delayed on March 10, 2006, 07:23:20 PM
I have a couple of actions working but I can't get the PHP include to work.  I have it working in another part of my site but for some reason when I do the include all I get is a blank file  I have tried just about everything that I can think of. 

I have already tried this with the PHP tags, without, etc.  What am I doing wrong.

<?php include("../tellafriend/inc.recommend.php");?>

Can anyone point me in the right direction.

Thanks
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 08:43:03 PM
If you just want to include that file use this.


function template_recommend()
{
     //Load the main_above template.  This is the header part
     template_main_above();
     //Load the file needed to be loaded
     include('../tellafriend/inc.recommend.php');
     //Load the copyright and so on.
     template_main_below();
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'blah')
{
     //Make use of SMF's layer system
     $context['template_layers'] = array();
     $context['sub_template'] = 'recommend';
}


You can try using that.  Just add it at the end of index.template.php for your theme.
Title: Re: How to create custom 'action'
Post by: Delayed on March 10, 2006, 09:09:44 PM
Okay I put that at the end of my index.template.php file.  So what do I put in my tellafriend.template.php
that I have in my theme

if it is this then

<?php include("../tellafriend/inc.recommend.php");?>

it still doesn't work.

I must not be getting something.
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 09:16:57 PM
What do you have in the tellafriend.template.php file?  Do you have anything else in there or just the include?
Title: Re: How to create custom 'action'
Post by: Delayed on March 10, 2006, 09:31:09 PM
Here is what I have.  I replaced the My Cool Downloads in the example text with my include.

<?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">
      <?php include("../tellafriend/inc.recommend.php");?>
   </td></tr></table>';
echo '
</td>
</tr>
</table><br /><br />
';
}

?>
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 09:44:01 PM
First thing.  You have the statement enclosed in <?php tags inside <?php tags.
Second the include is inside an echo. 

The method I showed you would do just what you want.  No need for tellafriend.template.php
Title: Re: How to create custom 'action'
Post by: Delayed on March 10, 2006, 09:50:31 PM
So after my index.template file is edited with function template_recommend() like you said then what do I need to do so that my script is called so that it looks like the other actions.
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 10:19:43 PM
It should work just that way.  Give it a try.
Title: Re: How to create custom 'action'
Post by: Delayed on March 10, 2006, 10:38:28 PM
I have edited the index.template.php for my default theme like you said to above.

It still isn't working.

Okay you said that I didn't need the  tellafriend.template.php so I deleted it and now it is loading the page but it says " Unable to load the 'tellafriend' template."  With the  tellafriend.template.php there it doesn't work either.

Do I still use the edited index.php and created tellafriend.php like in the first post?
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 10, 2006, 10:44:14 PM
No you do not need them.
Title: Re: How to create custom 'action'
Post by: Delayed on March 11, 2006, 03:37:19 AM
It still doesn't work.  I think that I am going to give up adding this PHP file as an action.  I am at my wits end on this thing.  I have tried just about everything. 

I got some other stuff to work as you can see in my other posts such as other actions and tab buttons but this include is driving me nuts.

I guess it really isn't a big deal just wanted to give it more room for other options.  I may try again in the morning but who knows.
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 11, 2006, 02:12:21 PM
All you really need to do is add this to the index.template.php  Right before ?>.  You do not need to create a template file, edit index.php, or create a source file. 
Title: Re: How to create custom 'action'
Post by: ArkServer on March 11, 2006, 07:14:24 PM
Quote from: Stuart on February 04, 2006, 05:32:07 PM
I actually managed to create 2 custom actions and you can see them on my website:

http://www.astmaforum.nl/index.php?action=links

http://www.astmaforum.nl/index.php?action=faq

I'm quite proud I was able to create these pages. But I couldn't have done it without the clear and easy instructions which were given in this topic. Thanks ever so much for that  :D

How did you made the faq page? mod?
Title: Re: How to create custom 'action'
Post by: JayBachatero on March 11, 2006, 09:11:10 PM
Ark it's just a page with FAQ's.  It's not a mod.
Title: Re: How to create custom 'action'
Post by: onijin on April 04, 2006, 05:00:07 PM
Well, I tried making my own FAQ page, but I think I'm screwing up somewhere.

When I put the "download" code given up there, it works fine.

I try to replace that with what I want; text, tables, bookmarks, and bookmark links, I get bombarded with "Template Parse Error-parse error, unexpected T_STRING, expecting ',' or ';'".  It's inside an echo, and at the end of all this, there is " '; "  I don't see any flaws and all my tags are properly closed.  Am I doing something wrong?  ^_^

Perhaps I can't put bookmarks?
Title: Re: How to create custom 'action'
Post by: JayBachatero on April 05, 2006, 11:34:25 AM
You need to echo what you are going to add.  echo 'blah';.  Apostrophes (') must be escaped with \ like PC\'s
Title: Re: How to create custom 'action'
Post by: onijin on April 05, 2006, 05:38:12 PM
it is in an echo.

I tried just adding the first 5 lines (all bookmark links) and I still got the parse error.  =/

Perhaps I should just do plain text.  Gawd that's boring...  =/


Well... I'll keep at it and try to figure it out...  ^_^
Title: Re: How to create custom 'action'
Post by: JayBachatero on April 05, 2006, 06:59:27 PM
Can you please post the code you are trying to put in?
Title: Re: How to create custom 'action'
Post by: onijin on April 06, 2006, 09:37:14 AM
You gotta be kidding...

In front page, i used the search string ' and searched for any apostophies, and I found the culprit!

Just one apost. that wasn't \[/color]...

I am dumb!  ^_^

Thanks for the support, Jay   ^_^
Title: Re: How to create custom 'action'
Post by: Stuart on April 08, 2006, 07:01:15 PM
Quote from: ArkServer on March 11, 2006, 07:14:24 PM
Quote from: Stuart on February 04, 2006, 05:32:07 PM
I actually managed to create 2 custom actions and you can see them on my website:

http://www.astmaforum.nl/index.php?action=links

http://www.astmaforum.nl/index.php?action=faq

I'm quite proud I was able to create these pages. But I couldn't have done it without the clear and easy instructions which were given in this topic. Thanks ever so much for that  :D

How did you made the faq page? mod?

Just using HTML and then create the custom action  :D
It's quite simple actually, as long as you be aware of the use of 'apostrophes  ;D
Title: Re: How to create custom 'action'
Post by: onijin on April 09, 2006, 09:45:03 PM
Quote from: Stuart on April 08, 2006, 07:01:15 PM
Just using HTML and then create the custom action  :D
It's quite simple actually, as long as you be aware of the use of 'apostrophes  ;D

damn apostrophes...
Title: Re: How to create custom 'action'
Post by: tX on April 10, 2006, 10:29:47 PM
how can you make pages witin the custom action, like another meber asked "sub custom actions" which i think he was talking about what i am. for example.
http://www.simplemachines.org/community/index.php?action=help
http://www.simplemachines.org/community/index.php?action=help;page=profile
http://www.simplemachines.org/community/index.php?action=help;page=post
How would you get the profile and post pages within the custom action? I am creating a downlaod page and tab(got the auctum action and tab working, jsut need to finsih the page) and would like to do a article page, but i dont want to have a seperate custom action page for each one, i would like to just be able to do something suuch as
http://www.example.org/forum/index.php?action=articles just article page whcih links to the articles
http://www.example.org/forum/index.php?action=articles;page=article1 one of the articles
http://www.example.org/forum/index.php?action=articles;page=article2 another article, ext ext.  Thanks.
Title: Re: How to create custom 'action'
Post by: JayBachatero on April 11, 2006, 09:35:26 AM
You can do something like

<?php
echo 'This is a test for actions.</br>';
echo
'1. <a href="?action=1">Regular action</a><br />';
echo
'2. <a href="?action=1&amp;subaction=2">Subaction</a><br />';

if (isset(
$_REQUEST['action']) && $_REQUEST['action'] == '1')
{
   echo
'This ia a regular action<br />';
   if (isset(
$_REQUEST['subaction']) && $_REQUEST['subaction'] == '2')
   {
     echo
'This is a subaction inside an action<br />';
   }
}
?>

http://www.kevmundial.com/subactions.php

You do that inside the function and you link to it like index.php?action=hello&amp;subaction=test
Title: Re: How to create custom 'action'
Post by: Vinspire on May 10, 2006, 06:16:37 AM
Quote from: Stuart on February 04, 2006, 05:32:07 PM
I actually managed to create 2 custom actions and you can see them on my website:

http://www.astmaforum.nl/index.php?action=links

http://www.astmaforum.nl/index.php?action=faq

I'm quite proud I was able to create these pages. But I couldn't have done it without the clear and easy instructions which were given in this topic. Thanks ever so much for that  :D

Very nice work there Stuart. Can tell me which instruction should i follow to do what you did ?
Title: Re: How to create custom 'action'
Post by: Stuart on May 10, 2006, 08:18:55 AM
Quote from: Vinspire on May 10, 2006, 06:16:37 AM
Quote from: Stuart on February 04, 2006, 05:32:07 PM
I actually managed to create 2 custom actions and you can see them on my website:

http://www.astmaforum.nl/index.php?action=links

http://www.astmaforum.nl/index.php?action=faq

I'm quite proud I was able to create these pages. But I couldn't have done it without the clear and easy instructions which were given in this topic. Thanks ever so much for that  :D

Very nice work there Stuart. Can tell me which instruction should i follow to do what you did ?

Thanks :D Basically you can just do whatever is said in THIS (http://www.simplemachines.org/community/index.php?topic=23864.msg189057#msg189057) post :)

If you cannot figure out how to do it I can give you some help providing you already know what you want. I guess you'll just have to try things out. You can actually create a HTML page and make that into a custom action as long as you're aware that you shouldn't use apostrophes as that might give an error!
Title: Re: How to create custom 'action'
Post by: Rocket 442 on May 19, 2006, 10:17:46 PM
I tried this, and got a couple errors, anyone know what they could be?


Notice: Undefined variable: modSettings in /home/olds442/public_html/smfforum/Sources/Load.php(1040) : eval()'d code on line 196

An Error Has Occurred!
2: smf_main(): Unable to access /home/olds442/public_html/smfforum/Sources/Downloads.php
File: /home/olds442/public_html/smfforum/index.php
Line: 330
Title: Re: How to create custom 'action'
Post by: unrelenting on May 20, 2006, 09:08:43 PM
I tried this and it works like a charm. Thanks.

Now I want to make the download action page only viewable by a certain permission group that I made. I want to set certain people up on a secondary membership group so that they can see the new tab and everyone not in that group can't. Can anyone tell me how I can do this.

I assumed I could just add a line in the admin-general permissions area but I can't figure out what file to edit to add the line. I found the ManagePermissions.english.php file that I would add the txt[] line to.

Is there a different way of doing this?

???
Title: Re: How to create custom 'action'
Post by: woden on May 20, 2006, 11:48:36 PM
I use this:



if (in_array(13, $GLOBALS['user_info']['groups']))     
{ echo ' insert button code here ';}
else
{ echo '';}



in this case the group number was 13
Title: Re: How to create custom 'action'
Post by: unrelenting on May 21, 2006, 12:24:08 AM
Quote from: woden on May 20, 2006, 11:48:36 PM
I use this:



if (in_array(13, $GLOBALS['user_info']['groups']))     
{ echo ' insert button code here ';}
else
{ echo '';}



in this case the group number was 13

That worked perfectly, except that it doesn't keep anyone out if they have a simple link to the page. If I log in as someone without access I don't see the link on my button bar but if I paste a link in my address bar I get right in. I want to guarantee that none of my users share the link if possible.
Title: Re: How to create custom 'action'
Post by: Niteblade on June 04, 2006, 02:36:08 AM
i'm attempting to create a custom action that calls a php file inside an iframe. (similar to but different than the flashchat integration..) i want guests, spiders, etc. to be able to access the function. are the instructions here, or must i do something different ?
Title: Re: How to create custom 'action'
Post by: JayBachatero on June 04, 2006, 03:21:06 AM
Unless you add permission everyone should be able to look at it.
Title: Re: How to create custom 'action'
Post by: Niteblade on June 04, 2006, 05:36:28 PM
I installed the custom action mod .. what a wonderful mod it is. Link here (http://www.simplemachines.org/community/index.php?topic=86793.msg600036#msg600036).

Thanks!
Title: Re: How to create custom 'action'
Post by: Captain_Morrigan on June 14, 2006, 03:55:05 PM
Is there a way to escape the default headers and footers for a custom action?

This is why I ask:
I am trying to create an awards mod that pops up in a tiny window with the awards in it. I want it to escape the headers because when you click on it it should just show the table that has the awards in it.

Anyone that can help I would appreciate it.

You can see what I mean by going here:
http://test.enchantinge.com
Title: Re: How to create custom 'action'
Post by: JayBachatero on June 14, 2006, 04:47:33 PM
Yea you can.  This is what I did for a mod I was working on.

Code (source file) Select

function play_popup()
{
global $txt, $helptxt, $context;

// Load the admin help language file and template.
loadLanguage('Media');

loadTemplate('Media');

// Set the page title to something relevant.
$context['page_title'] = $context['forum_name'] . ' - ' . $txt['media_title'];

// Don't show any template layers, just the popup sub template.
$context['template_layers'] = array();
$context['sub_template'] = 'popup';
}


Code (template file) Select

function template_popup()
{
global $context, $settings, $options, $txt, $scripturl, $row;

// Since this is a popup of its own we need to start the html, etc.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=' ,$context['character_set'], '" />
    <title>' ,$context['page_title'], '</title>';
    </head>

    <body>
        STUFF GOES HERE
    </body>
    </html>';
}


In index.php I added 'play' => array('Media.php', 'play_popup'),
Title: Re: How to create custom 'action'
Post by: Captain_Morrigan on June 14, 2006, 05:01:06 PM
Awesome thank you so much! You rock!
Title: Re: How to create custom 'action'
Post by: Johno69 on August 28, 2006, 09:42:25 PM
Quote from: iwyen on June 18, 2005, 09:47:31 AM
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..

Quote from: [Unknown] on June 18, 2005, 09:48:40 AM
Is $txt['mypage'] defined?  Did you add $txt to the global line?

-[Unknown]

Can you explain where this goes please ? I'd like the tree on my custom page too.
Title: Re: How to create custom 'action'
Post by: JayBachatero on August 28, 2006, 10:03:37 PM
Add that to the source file you made.
Title: Re: How to create custom 'action'
Post by: Johno69 on August 29, 2006, 12:13:31 AM
Sorry not exactly sure where...

<?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" >Photo area</td>
</tr><tr>
<td class="windowbg">'
;

echo
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
        <tr>
          <td width="100%" valign="top"><br>
<center>Content Here</center><br>
</td></tr></table>'
;
echo
'
</td>
</tr>
</table><br /><br />
'
;
}

?>


That is my current code.
Title: Re: How to create custom 'action'
Post by: JayBachatero on August 29, 2006, 12:59:05 AM
You need another file on Sources dir.  Like the example shows.
Title: Re: How to create custom 'action'
Post by: Johno69 on August 29, 2006, 01:09:30 AM
Yes I have... here's the code:

<?php
if (!defined('SMF'))
die(
'Hacking attempt...');

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


Still not exactly sure where to put the tree stuff.
Title: Re: How to create custom 'action'
Post by: JayBachatero on August 29, 2006, 07:33:38 PM

<?php

if (!defined('SMF'))
die('Hacking attempt...');

function
Photos()
{
global $context, $txt;

$context['page_title'] = 'Photos';

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

// This is gonna be needed...
loadTemplate('Photos');
}
?>
Title: Re: How to create custom 'action'
Post by: Johno69 on September 01, 2006, 07:42:29 PM
Many Thanks.

i'm using the helios theme and i'd like the top bar (bg) to show also behind the tree, any idea how to so this.
Title: Re: How to create custom 'action'
Post by: JayBachatero on September 02, 2006, 12:09:15 AM
Not sure sure about that.  Look into the index.template.php file.
Title: Re: How to create custom 'action'
Post by: Carinspixels on September 08, 2006, 02:12:42 AM
Hi I've installed a page using this code but I run into some minor errors.
i've tried adding a linkbutton on the home of my site, in the same style.

Now that works I can call the page as well, but when I go inside the admin panel and view the forum error log I get a load of errors:

http://www.ww/www/index.php 
8: Undefined index: linkbuttons
File: /home/pixellus/public_html/PI/Themes/default/languages/Shop.english.php (eval?)
Line: 473

http://www.www/www/index.php?action=linkbuttons 
8: Undefined index: linkbuttons
File: /home/pixellus/public_html/PI/Themes/default/languages/Shop.english.php (eval?)
Line: 473


Annyone know how I can fix this?

The code for the button I used is this 1 I think that is the error actually:

//linkbuttons

echo "<a href='{$scripturl}?action=linkbuttons'>", ($settings['use_image_buttons'] ? "<img src='{$settings['images_url']}/{$context['user']['language']}/linkbuttons.gif' alt='{$txt['linkbuttons']}' style='margin: 2px 0;' border='0' />" : $txt['linkbuttons']), "</a>{$context['menu_separator']}";

//end linkbuttons

Thanks so much
Title: Re: How to create custom 'action'
Post by: Peter B on December 09, 2006, 03:53:07 PM
Hello,
I followed all the instructions for the first post in the topic and created my Downloads.php and Downloads.template.php.
However, when I try to use downloads as an action, I get the error "Unable to load the 'Downloads' template."
I have tried a variety of changes to the code with no success.
Does anyone recognise this error and it's most likely causes.
thanks
Peter
Title: Re: How to create custom 'action'
Post by: Peter B on December 10, 2006, 10:14:36 AM
Hi, I worked through the problem with not able to load the template.
I added loads of debugging output in Load.php and that highlighted that the path in my default themes setting was wrong!!!
It all works fine now.
thanks
Peter B
Title: Re: How to create custom 'action'
Post by: chig on February 07, 2007, 03:56:30 PM
I just spent hours (well I made some mistakes) to find out how to implement subactions so I thought it might be helpful for others who where searching for the same information...


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

function
Downloads()
{
//Load the main template file
loadtemplate('Downloads');


//Downloads Actions
$subActions = array(
'subdownloads' => 'SubDownloads',
);


// Follow the sa or just go to main function
@$sa = $_GET['sa'];
if (!empty($subActions[$sa]))
$subActions[$sa]();
else
main();

}

function
Main() {
global
$context;

$context['page_title'] = 'My Actions title!';

}

function
SubDownloads(){
global $context;


$context['page_title'] = 'My SubDownloads!';

// This is gonna be needed...
$context['sub_template'] = 'SubDownloads';
}

?>



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!!!!<br>
 <a href="'
, $scripturl, '?action=downloads;sa=subdownloads">SubDownloads</a>
</td></tr></table>'
;
echo
'
</td>
</tr>
</table><br /><br />
'
;
}

function
template_SubDownloads()
{
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" >Sub Downloads area</td>
</tr><tr>
<td class="windowbg">'
;

echo
'<table border="0" cellpadding="0" cellspacing="3" width="100%">
        <tr>
          <td width="100%" valign="top">
This is the SubDownloads page!!!!
</td></tr></table>'
;
echo
'
</td>
</tr>
</table><br /><br />
'
;
}

?>



with this small example it functions like a charm, unfortunatly I didn't get it into my mod I am working on so far  :-[ ... but at least I know now I am on the right track!!  :)

Maybe a moderator might add thisto first post, or a link in the first post to this post as a hint... oh and maybe this moderator might go through the code first to optimize it  ;D
Title: Re: How to create custom 'action'
Post by: Marook on September 09, 2007, 02:40:04 AM
Anyone who can help me with this : http://www.simplemachines.org/community/index.php?topic=193302.0   ???
Title: Re: How to create custom 'action'
Post by: King Steph1 on September 30, 2007, 08:07:23 PM
Quote from: Owdy on January 09, 2005, 05:01:30 PM

index.php find:

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

ad after:

'downloads' => array('Downloads.php', 'Downloads'),
I can't find anything like that.
That's all that shows up on my index.php: <?php


// Try to handle it with the upper level index.php. (it should know what to do.)
if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
  include (
dirname(dirname(__FILE__)) . '/index.php');
else
  exit;

?>
Title: Re: How to create custom 'action'
Post by: codenaught on September 30, 2007, 08:09:49 PM
That's not the correct index.php file. Open the one in the root directory of your forum.

Also, are you aware there is now a mod that you can use to create custom actions?
Title: Re: How to create custom 'action'
Post by: King Steph1 on October 01, 2007, 10:04:13 AM
Thanks!
Everything's working now :]

Yep, but we're trying to make the board mod free.
Thanks again :)
Title: Re: How to create custom 'action'
Post by: shumar on March 24, 2008, 08:01:11 PM
A little help with this ?
http://www.simplemachines.org/community/index.php?topic=63203.msg1470635#msg1470635

I get page that I created above header, and below that header is Can't load main ??

Thank you in advance.
Title: Re: How to create custom 'action'
Post by: morency on March 30, 2008, 11:19:44 AM
how can create the wap/wap2/imode version for action=downloads , from example? :-> action=downloads;imode !
Title: Re: How to create custom 'action'
Post by: morency on June 02, 2008, 03:14:43 PM
 ??? ??? Please help !! any1 ! ????  how can create  the template for that example  "action=downloads" in wireless.template.php?? 
Title: Re: How to create custom 'action'
Post by: heimep on July 30, 2008, 02:10:38 PM
Will the custom action mod work on 1.1.5
Title: Re: How to create custom 'action'
Post by: manuxel on August 19, 2008, 12:49:30 PM
Yes it works, i've tried it...
Title: Re: How to create custom 'action'
Post by: csulok on December 12, 2008, 07:52:17 AM
Hi,

Using the guide posted above (adding the action to the index.php and stuff) I created a custom action.

I don't really understand how to pass info between the action.php and action.template.php so initially I just dumped all my code into action.template.php however when I want to customize the page title I realized it can only be done in the source file, not the template one.

So my question is.. what goes into the source file usually? what goes in the template file usually? I have a few queries and show some tables based on them, how would I pass info from the query done in the source file (where based on the query results I can set the page title) to the template file?

Also, is there a way to set the page title from the template file?

Any help is much appreciated
Title: Re: How to create custom 'action'
Post by: MrMorph on July 13, 2009, 02:17:01 PM
An old thread I know, but still useful.

My question is the same as the one above.  What would the mod makers advise goes in each file ?  And also how to pass data between them ?

Thanks for any help.
Title: Re: How to create custom 'action'
Post by: kingkingston on November 12, 2009, 09:02:56 AM
Quote from: MrMorph on July 13, 2009, 02:17:01 PM
An old thread I know, but still useful.

My question is the same as the one above.  What would the mod makers advise goes in each file ?  And also how to pass data between them ?

Thanks for any help.
Maybe you should try this Mod

http://custom.simplemachines.org/mods/index.php?mod=331
Title: Re: How to create custom 'action'
Post by: Tyilanmenyn on January 28, 2010, 02:31:23 AM
Nice clean tutorial.

But I have an error somehow :|
I've created 2 pages, each with the exact same code. The first page works fine, but in the secpnd page I always get the error Unable to load 'main' template I've been searching around the forums and tried many solutions, but none fixed the error.

Anyone who can help me out? I can post the files if needed.

Thanks in advance,
Tyilanmenyn
Title: Re: How to create custom 'action'
Post by: Arantor on January 28, 2010, 04:18:31 AM
Did you create a template file for your new action? Did you also call loadTemplate with the template's file name?

E.g. Newaction.template.php needs a matching loadTemplate('Newaction') call somewhere in the action's code.
Title: Re: How to create custom 'action'
Post by: MPKaboose on February 25, 2010, 12:47:29 PM
I don't know why but only the header and menu appears nothing else :/
Title: Re: How to create custom 'action'
Post by: Mitii on April 10, 2010, 03:57:54 AM
Hey,

Panels and code blocks don't work while I'm using that mod that you linked, anyone know some reason why? I've tried all the default blocks as well as my regular blocks. The action is set to HTML.

Secondly, I followed the tutorial to the letter but all it does is loop me back to my forum. I'm using my own custom theme, is there something specific I have to do along with that tutorial?
Title: Re: How to create custom 'action'
Post by: thellie on September 12, 2010, 06:28:37 PM
arantor:
QuoteDid you create a template file for your new action? Did you also call loadTemplate with the template's file name?

E.g. Newaction.template.php needs a matching loadTemplate('Newaction') call somewhere in the action's code.

but you only load once if the action has subactions? and it's called in function Main() ....?

i have a page with the main() function, my_function(), and some functions relating to subactions. then on the template page it calls the template_function of each one...

the template_main() comes in fine, but the others (maybe because they are php-coded, not html) come in above the automatic background (smf's header footer etc, which must be auto loaded as we are coming from index.php?action=xxx;sa=yyy)

any idea how i would get the subaction stuff to sit within the auto templates, and not above?

thanks
Title: Re: How to create custom 'action'
Post by: fadmafia on December 07, 2010, 12:15:34 PM
how to have smf 2.0 rc4 redirect the poster back to the last post ?
i have lots of questions to have it in there but dont know how to..... thanks