News:

Wondering if this will always be free?  See why free is better.

Main Menu

Adding a custom page manually for Smf 2.0. rc 3

Started by cicka, July 11, 2010, 12:40:47 PM

Previous topic - Next topic

cicka

I came up with this after a equest at this other thread.

http://www.simplemachines.org/community/index.php?topic=387010

This is a short basic guide on how to create custom pages manually. I will package it into an add on at a later time with some extra options.

Anywayz, create a file and rename it custom.php or give it whatever name you want. Then open it up with a php editor and enter this code
<?php 
//Set the banning active
$ssi_ban true;

//Path to SSI.php
require(dirname(__FILE__) . '/SSI.php');

//Page title. This will appear in the browser
$context['page_title_html_safe'] = 'Custom Page';

//This is self explanatory
template_header(); 

//Here we define the link tree
$context['linktree'] = array(
  
'href' => $scripturl,
  );
  
//Here is the content, such as the title and the body message of the custom page.

echo'
<span class="clear upperframe"><span></span></span>
<div class="roundframe"><div class="innerframe">'
;
echo'
<div class="cat_bar">
<h3 class="catbg">Hello everyone</h3>
</div>
    <p>This is a custom page example. pretty cool, huh.</p>'
;
echo'
   </div></div>
  <span class="lowerframe"><span></span></span>'
;

//This is self explanatory too.   
template_footer(); 

?>



In comments is explained what each code does. Change the title and message with your own that you want to use at your custom page. If you want to add permissions for groups then please post here.

To enter the button at the menu for the custom page, at the Subs.php file in the Sources folder find this code

'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => $context['allow_search'],
'sub_buttons' => array(
),
),


And add this code

'custompage' => array(
'title' => $txt['cpage'],
'href' => 'custom.php',
'show' => true,
// 'target' => '_blank',
'sub_buttons' => array(
),
),

         
This will add it after the Search button. If you want it to add it somewhere else, then place the code above after or before the menu button code that you want the custom page to appear.         

If you want the custom page button to open in a new window , uncomment this part

// 'target' => '_blank',

Then as last we will add the language text. At the Modification.english.php file place this code.

$txt['cpage'] = 'Announcement';

And replace Announcement with whatever word you want your custom page button to say.

Save the changes and upload the custom.php file in the root of your forum folder.

If you want to have it outside the forum, then change this code

require(dirname(__FILE__) . '/SSI.php');

to this

require("/full/path/to/SSI.php");

And enter your full path to SSI.php

Below you can see a screenshot how the custom page will look like.

spottedhog

Here is code that can also be added before calling SSI.php.  These lines came from [Unknown] a long time ago.

$ssi_gzip = true;  //true--means gzip is turned on.
$ssi_ban = true;  //true--means a banned forum user will be banned also in the SSI page.
// Comment out the line below to use the default theme.
$ssi_theme = 5;  //uses the theme [images, buttons, colors] Specifiy theme ID here.


This makes your custom page able to use a different theme.

NanoSector

I HOPE that doing this all again solves my problems...

Added above code ^.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

spottedhog

#3
Here...   Let's take this a step further and make it usable for SMF 1.1.x and 2.x:

<?php

$ssi_gzip 
true;  //true--means gzip is turned on.
$ssi_ban true;  //true--means a banned forum user will be banned also in the SSI page.
// Comment out the line below to use the forum's default theme. (what the Admin has set)
$ssi_theme 5;  //uses the theme [images, buttons, colors] Specifiy theme ID here.
ob_start();  //is needed not to get errors.
require('path/to/SSI.php'); //add ../ if page is outside Root directory

//Let's set the Page Title...  for both SMF 1.1.x and SMF 2.x 
// $mbname is the forum name

if(isset($context['page_title_html_safe']))
{
$context['page_title_html_safe'] = $mbname '&nbsp;-&nbsp;PageTitleHere'
} else {
$context['page_title'] = $mbname '&nbsp;-&nbsp;PageTitleHere';
}

    
// SMF header section coded for both versions 1.1.x and 2.0
    
if(!function_exists('template_header'))
    {
    
template_main_above(); // SMF 1.1.x header section
    
}  else {
       
template_header();  //SMF 2.x header section
    
}

//Content Section
    
if(!function_exists('template_header'))
    {

    echo 
'Your SMF 1.1.x content here.';

    }  else {

     
// If SMF 2.x, place content here.

     
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">'
;
         echo
'
         <div class="cat_bar">
         <h3 class="catbg">Hello everyone</h3>
         </div>
          <p>This is a custom page example. pretty cool, huh.</p>'
;
         echo
'
         </div></div>
        <span class="lowerframe"><span></span></span>'
;    

    }


   
// SMF footer section coded for both versions 1.1.x and 2.0
    
if(!function_exists('template_footer'))
    {
    
template_main_below(); // SMF 1.1.x header section
    
}  else {
       
template_footer();  //SMF 2.x header section
    
}

?>

cicka

That extra code it is not really necessary in my opinion :)

NanoSector

Quote from: spottedhog on July 11, 2010, 03:14:16 PM
Here...   Let's take this a step further and make it usable for SMF 1.1.x and 2.x:

<?php

$ssi_gzip 
true;  //true--means gzip is turned on.
$ssi_ban true;  //true--means a banned forum user will be banned also in the SSI page.
// Comment out the line below to use the forum's default theme. (what the Admin has set)
$ssi_theme 5;  //uses the theme [images, buttons, colors] Specifiy theme ID here.
ob_start();  //is needed not to get errors.
require('path/to/SSI.php'); //add ../ if page is outside Root directory

//Let's set the Page Title...  for both SMF 1.1.x and SMF 2.x 
// $mbname is the forum name

if(isset($context['page_title_html_safe']))
{
$context['page_title_html_safe'] = $mbname '&nbsp;-&nbsp;PageTitleHere'
} else {
$context['page_title'] = $mbname '&nbsp;-&nbsp;PageTitleHere';
}

    
// SMF header section coded for both versions 1.1.x and 2.0
    
if(!function_exists('template_header'))
    {
    
template_main_above(); // SMF 1.1.x header section
    
}  else {
       
template_header();  //SMF 2.x header section
    
}

//Content Section
    
if(!function_exists('template_header'))
    {

    echo 
'Your SMF 1.1.x content here.';

    }  else {

     
// If SMF 2.x, place content here.

     
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">'
;
         echo
'
         <div class="cat_bar">
         <h3 class="catbg">Hello everyone</h3>
         </div>
          <p>This is a custom page example. pretty cool, huh.</p>'
;
         echo
'
         </div></div>
        <span class="lowerframe"><span></span></span>'
;    

    }


   
// SMF footer section coded for both versions 1.1.x and 2.0
    
if(!function_exists('template_footer'))
    {
    
template_main_below(); // SMF 1.1.x header section
    
}  else {
       
template_footer();  //SMF 2.x header section
    
}

?>

Thanks, will try that.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

NanoSector

*sigh

Parse error: syntax error, unexpected $end in /home/a9406461/public_html/about.php on line 36

http://smftools.comlu.com/about.php
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

spottedhog

Quote from: cicka on July 11, 2010, 03:25:08 PM
That extra code it is not really necessary in my opinion :)

I am going by what [Unknown] wrote long ago, which is now part of the Expert SSI board.  [Unknown] was the person who made the foundation for what SMF is today.  Now this info may be from 5+ years ago, but is still valid today.

$ssi_ban = 1;    <--- everywhere I have seen this as -->  $ssi_ban = true;    I have done frequent testing to know "true" works.  I am not certain "1" works.

[Unknown] Links:
Please take note of how many posts [Unknown] has (had).  [Unknown] was single handily the only Support Person for SMF for a long time.  There was maybe a 2 year or so stretch where he literally read and replied to every posting.

http://www.simplemachines.org/community/index.php?topic=42460.msg339115#msg339115
http://www.simplemachines.org/community/index.php?topic=13205.msg268482#msg268482
http://www.simplemachines.org/community/index.php?topic=8407.msg79358#msg79358

cicka, I am not saying you are wrong.  I am saying the person who wrote the code and lived it for a long time has said to use certain lines of code written a certain way, and for me, I will listen and trust everything [Unknown] has written.

spottedhog

Yoshi2889,  normal a Parse error: syntax error, unexpected $end means there is a missing curly bracket.

Please check your content inputs to make sure all the original curly brackets are in place.

I just uploaded the bare code as I had posted to a test site and all works fine....

NanoSector

Quote from: spottedhog on July 11, 2010, 03:54:30 PM
Yoshi2889,  normal a Parse error: syntax error, unexpected $end means there is a missing curly bracket.

Please check your content inputs to make sure all the original curly brackets are in place.

I just uploaded the bare code as I had posted to a test site and all works fine....
Yes I fixed it.

Now I'm back at my old error:
Notice: Undefined index: custompage in /home/a9406461/public_html/Sources/Subs.php on line 3905
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

spottedhog

QuoteNow I'm back at my old error:
Notice: Undefined index: custompage in /home/a9406461/public_html/Sources/Subs.php on line 3905

Usually an "Undefined index" error is a variable that has not been declared.  Around the area of the Subs.php file is where the menu button variables are. 

Is line 3905 where you put in a new menu item with maybe $custompage in it somehow?  Maybe you put in a variable without also putting it in the globals line at the beginning of the function.

Around line 3864 is this global line of code:
global $context, $modSettings, $user_info, $txt, $scripturl;

If your menu input uses a variable not listed in this line, this could be the source of your problem.

NanoSector

Yes I changed everything to custompage from cpage, because it is easier to remember xD

Will search that (?)

Found it.

It says this:
global $context, $modSettings, $user_info, $txt, $scripturl;
Sooo....need to modify this?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

spottedhog

#12
'custompage' => array(
            'title' => $txt['cpage'],
            'href' => 'custom.php',
            'show' => true,
            // 'target' => '_blank',
            'sub_buttons' => array(
            ),
         ),


I have a feeling you may not have put $txt['cpage'] in the Modifications.english.php file of the default theme.  OR, if you did that already, and then you changed the $txt variable name in Subs.php but not in the language file, this could also throw that error.

If this is the issue, then there is nothing to change in the global line.

arrgghhhhh...  what I am trying to say is, if you now have $txt['custompage'], it must also correspond with the same variable name in the Modifications.english.php language file, otherwise it will throw a Notice error.

NanoSector

Quote from: spottedhog on July 11, 2010, 04:24:47 PM
'custompage' => array(
            'title' => $txt['cpage'],
            'href' => 'custom.php',
            'show' => true,
            // 'target' => '_blank',
            'sub_buttons' => array(
            ),
         ),


I have a feeling you may not have put $txt['cpage'] in the Modifications.english.php file of the default theme.  OR, if you did that already, and then you changed the $txt variable name in Subs.php but not in the language file, this could also throw that error.

If this is the issue, then there is nothing to change in the global line.

arrgghhhhh...  what I am trying to say is, if you now have $txt['custompage'], it must also correspond with the same variable name in the Modifications.english.php language file, otherwise it will throw a Notice error.
* Yoshi2889 tries to translate that into normal language but fails...

Will try.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Matthew K.

Another easy way you can accomplish a "Custom Page" is by creating a custom action...very simple with no SSI necessary.

cicka

Quote from: spottedhog on July 11, 2010, 03:49:11 PM
Quote from: cicka on July 11, 2010, 03:25:08 PM
That extra code it is not really necessary in my opinion :)

I am going by what [Unknown] wrote long ago, which is now part of the Expert SSI board.  [Unknown] was the person who made the foundation for what SMF is today.  Now this info may be from 5+ years ago, but is still valid today.

$ssi_ban = 1;    <--- everywhere I have seen this as -->  $ssi_ban = true;    I have done frequent testing to know "true" works.  I am not certain "1" works.

[Unknown] Links:
Please take note of how many posts [Unknown] has (had).  [Unknown] was single handily the only Support Person for SMF for a long time.  There was maybe a 2 year or so stretch where he literally read and replied to every posting.

http://www.simplemachines.org/community/index.php?topic=42460.msg339115#msg339115
http://www.simplemachines.org/community/index.php?topic=13205.msg268482#msg268482
http://www.simplemachines.org/community/index.php?topic=8407.msg79358#msg79358

cicka, I am not saying you are wrong.  I am saying the person who wrote the code and lived it for a long time has said to use certain lines of code written a certain way, and for me, I will listen and trust everything [Unknown] has written.

I only stated that the added code is not necessary. Because the template_header(); and template_footer(); echo perfectly their part and in between comes the code to be echoed as the content of the custom page. Short, nice, sweet and to the point. I do not see the need to complicate it with extra stuff.

I hope you will not mind me saying this, but you should think for yourself on your own and not copy and paste what someone else says. No matter how good they are or whatever :)

spottedhog

You may say whatever you wish, no problem.

Obviously you were not here at SMF when [Unknown] was here or you would not make such a statement.

3+ years ago I first created the custom page code like what you have here, so yes, I do think on my own.    And yes, I posted it here long ago.  http://www.simplemachines.org/community/index.php?topic=182269.msg1174724#msg1174724

NanoSector

#17
Hm.

If you have undefined index errors install a mod and you are fine xD

ALSO!!

If you have for example your SMF installation in / and the file is in /html, modify Subs.php and add the COMPLETE URL to:
'custompage' => array(
'title' => $txt['custompage'],
// Modify the below code.
'href' => 'http://completeurl.com/yourfile.php',

And do that by ALL that code.

SMF will then go to that url without problems (else you got errors).

EDIT:
You can add sub-buttons if you like.
I have not tested this yet, but I'm sure it will work.
Code (Subs.php) Select

// Add this code after your button's code.
// Start the sub-button's.
'sub_buttons' => array(
// Button 1.
'blabla' => array(
'title' => $txt['blabla'],
'href' => $scripturl . 'http://blabla.com/blabla/blabla.php',
'show' => true,
),
// Button 2.
'lol' => array(
'title' => $txt['lol'],
'href' => $scripturl . 'http://lol.com/lol/lol.php',
'is_last' => true,
),


Who said novice users cannot code with examples?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

spottedhog

cicka, can you please change your code in your original posting so when others read and try it, they will not have a problem?

Please change this:

$ssi_ban = 1;

...to this:

$ssi_ban = true;

If you have doubts about why, please look at this recent thread:

http://www.simplemachines.org/community/index.php?topic=390093


NanoSector

@spottedhog:
Your code works like a charm.
The ssi-ban code is really handy, as banned users cannot download SMFTools when banned lol

@cicka:
Please add that when you get undefined index errors installing a mod will help.
I've got 3 custom pages now and all of them are solved by installing a new mod.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Advertisement: