Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: cicka on July 11, 2010, 12:40:47 PM

Title: Adding a custom page manually for Smf 2.0. rc 3
Post by: cicka on July 11, 2010, 12:40:47 PM
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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on July 11, 2010, 02:30:28 PM
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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 02:37:35 PM
I HOPE that doing this all again solves my problems...

Added above code ^.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: 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
   
}

?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: cicka on July 11, 2010, 03:25:08 PM
That extra code it is not really necessary in my opinion :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 03:25:30 PM
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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 03:31:45 PM
*sigh

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

http://smftools.comlu.com/about.php
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: 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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: 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....
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 03:59:44 PM
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
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on July 11, 2010, 04:12:49 PM
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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 04:17:31 PM
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?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: 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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 11, 2010, 04:32:31 PM
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.
/me tries to translate that into normal language but fails...

Will try.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Matthew K. on July 11, 2010, 04:40:26 PM
Another easy way you can accomplish a "Custom Page" is by creating a custom action...very simple with no SSI necessary.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: cicka on July 11, 2010, 04:44:04 PM
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 :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on July 11, 2010, 05:10:23 PM
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
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 12, 2010, 04:30:10 AM
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?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on July 12, 2010, 06:51:51 AM
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

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 12, 2010, 06:58:41 AM
@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.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: cicka on July 12, 2010, 10:26:34 AM
I changed the ban part spottedhog, thank you for the reminder :)

Yoshi2889, there is no need to install a mod for this because if the edits are done properly there will be no errors at all :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on July 12, 2010, 10:36:15 AM
Quote from: cicka on July 12, 2010, 10:26:34 AM
I changed the ban part spottedhog, thank you for the reminder :)

Yoshi2889, there is no need to install a mod for this because if the edits are done properly there will be no errors at all :)
I mean if a mod modifies Subs.php it will be all fine when you get errors.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: divecall on August 02, 2010, 04:16:46 AM
How i can do, that this new page is only visible for logged members, not guests ?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on August 02, 2010, 06:35:15 AM
Enclose the page content with:

global $context;
if($context['user']['is_logged'])
{

// page content here

} else {
ssi_login();
}


Of course you can replace ssi_login(); with whatever you wish to use there.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Matthew K. on August 02, 2010, 10:18:16 AM
If the page uses a Source File, it is better to do it in the source file, rather than the template.
Quote from: spottedhog on August 02, 2010, 06:35:15 AM
Enclose the page content with:

global $context;
if($context['user']['is_logged'])
{

// page content here

} else {
ssi_login();
}


Of course you can replace ssi_login(); with whatever you wish to use there.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: cicka on August 02, 2010, 11:57:54 AM
Quote from: divecall on August 02, 2010, 04:16:46 AM
How i can do, that this new page is only visible for logged members, not guests ?


If you are using the codes from my original post find this code:

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




And change it to this code

global $context;
if($context['user']['is_guest']){
echo
fatal_lang_error('no_access', false);
}else{
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>';   
}

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: KensonPlays on August 02, 2010, 04:07:09 PM
Quote from: Labradoodle-360 on July 11, 2010, 04:40:26 PM
Another easy way you can accomplish a "Custom Page" is by creating a custom action...very simple with no SSI necessary.

Yes, that mod works well! Although for some reason it doesn't work on my end the add action button doesn't work as well a sub-action link. :(
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: yfleury on August 23, 2010, 08:04:03 PM
I need permission or membergroup to show different content to guest, regularmember and specialmember

I use this
global $context;
if($context['user']['is_guest']){
      echo 'this is for guest';

}else{
      echo 'this is for regular member';   
      // I have to do a if here to show a content for special member
     if (What to put here){
            echo 'this is for special member';
     }
}
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: yfleury on August 24, 2010, 01:44:09 PM
I find it myself.... look like this

global $context;
if($context['user']['is_guest']){

      echo 'this is for guest';

}elseif(in_array(1,$user_info["groups"] )==1) { // number 1 = admin

       echo 'this is for admin';

}elseif(in_array(9,$user_info["groups"] )==9){ // number 9 = special member

echo 'this is for special member';

}else{

        echo 'this is for other member';

}


To find what number for different member groups, look at smf_membergroups table in the database  and when you find a member groups you want, take the number in id_group.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: RoflGuy on October 27, 2010, 11:46:34 AM
how do i add the page i made to the menu bar , which got Home , Forums and others?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on October 27, 2010, 03:49:33 PM
This forum just knows what I want to read...then my SMFTools topic pops up as unread when I want to review it and then this topic pops up when I need it :P

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: DutchJam on November 19, 2010, 03:59:49 AM
Hi,

Created a custom page with the code above and it works perfect.

But when I installed the SimpleAds mod to dislplay ads on my site I get this error message on my static page:

Fatal error: Call to undefined function template_ad_position() in /public_html/Sources/Load.php(2156) : eval()'d code  on line 228

This message only appears on the static page. All others work perfect.

Anyone know how to solve this?

Thanks!
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 19, 2010, 07:36:30 AM
You will need to "include" the file that contains the SimpleAds function.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: DutchJam on November 19, 2010, 08:39:05 AM
Quote from: spottedhog on November 19, 2010, 07:36:30 AM
You will need to "include" the file that contains the SimpleAds function.

Into the static page?

And how?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 19, 2010, 08:57:15 AM
I just took a look at that mod and here is what I see:

require_once($sourcedir . '/Subs-Ads.php');

Where $sourcedir = path to the Sources folder.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: DutchJam on November 19, 2010, 09:22:09 AM
Quote from: spottedhog on November 19, 2010, 08:57:15 AM
I just took a look at that mod and here is what I see:

require_once($sourcedir . '/Subs-Ads.php');
   load_ads();

Where $sourcedir = path to the Sources folder.

Oh, I get it. I added the code to the static page and now it works again.

But I have to do this to every static page of course.

Tnx Spottedhog, problem solved!

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 19, 2010, 11:41:59 AM
:)  OK, consider this...  using the same principle, you can now use any of the SMF functions on your static pages.  Keep in mind that SSI.php only pulls in variables and the functions within that file. Soooo, you can find functions you may need in one of the Sources files, require/include it, and then be able to use the function.

This is the base premise for nearly all PHP coded software.  :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 19, 2010, 03:33:54 PM
I've recently got the require(./ssi.php) thing work so it points to the one in my forum folder...no more copying files for me!

For 000webhost members:
require("/home/ayouraccountnumber/public_html/forum/SSI.php");
Where youraccountnumber is your number like 1234567, and forum/ is your directory where SSI.php is located.

Place that in all of your pages and it works fine :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 19, 2010, 05:05:22 PM
A better way is to view your ssi_examples.php file in your web browser and use the path shown in the "Include Code" section (relative to where your static page is installed)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 19, 2010, 05:08:50 PM
Quote from: spottedhog on November 19, 2010, 05:05:22 PM
A better way is to view your ssi_examples.php file in your web browser and use the path shown in the "Include Code" section (relative to where your static page is installed)
.......if you had said that before you would have saved me time..........
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 19, 2010, 05:12:50 PM
Oh and hey, installing the Youtube integration mod seems to crash your custom pages to only say "The page cannot be viewed.".
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 19, 2010, 07:13:23 PM
Here is a link to a PHP Class that displays YouTube videos on web pages:

http://www.phpclasses.org/package/3944-PHP-Embed-YouTube-videos-in-Web-pages.html
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 28, 2010, 06:53:26 AM
I have this error when I try this code:

QuoteF
Warning: Cannot modify header information - headers already sent by (output started at /home/name/public_html/forum/Sources/Subs.php:1) in /home/name/public_html/forum/Sources/Subs.php on line 3343

Warning: Cannot modify header information - headers already sent by (output started at /home/name/public_html/forum/Sources/Subs.php:1) in /home/name/public_html/forum/Sources/Subs.php on line 3344

Warning: Cannot modify header information - headers already sent by (output started at /home/name/public_html/forum/Sources/Subs.php:1) in /home/name/public_html/forum/Sources/Subs.php on line 3350

Warning: Cannot modify header information - headers already sent by (output started at /home/name/public_html/forum/Sources/Subs.php:1) in /home/name/public_html/forum/Sources/Subs.php on line 3353

Here's the full code:

<?php
//Set the banning active
$ssi_ban = true;
$ssi_gzip = true;  //true--means gzip is turned on.
// Comment out the line below to use the default theme.
$ssi_theme = 1;  //uses the theme [images, buttons, colors] Specifiy theme ID here.


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

//Page title. This will appear in the browser
$context['page_title_html_safe'] = 'SMF-HR O Nama';

//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">SMF-HR O Nama</h3>
</div>
   <p>U izradi...</p>'
;
echo'
  </div></div>
 <span class="lowerframe"><span></span></span>'
;

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

?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 28, 2010, 08:08:59 AM
I made a test.php of your code and it worked fine.

However, this piece of code is redundant since it is already called in the template_header();

//Here we define the link tree
$context['linktree'] = array(
  'href' => $scripturl,
  );


Soooo, maybe that is what is throwing the error.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 28, 2010, 11:31:27 AM
I didn't work.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 28, 2010, 12:21:00 PM
hmmmm...  if you copy/paste your page code into a file, and call it alone in a browser, the headers should only be called via SSI.php in the template_header function.

Are you trying to include the file into another file which has header information already being sent?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 29, 2010, 02:23:44 PM
No. It's standalone file.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 29, 2010, 07:19:33 PM
Thanks for this, it came in very handy and made it very easy to add a page.
My page is in a seperate folder as it has it's own dependancies.

But now my problem is, when I visit the page, it looks as if I'm not logged in.
If I click the button login then it simply brings me to the main site, where of course I'm logged in already.

It's not such a big deal, it's just that the links that are only visible to logged in members (or admins) are not visible while on that page.
So in order to go to my profile settings I would have to go Home first before I can click the Profile link.

Any suggestions?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on November 30, 2010, 08:30:01 AM
Do you use code like:  $context['user']['is_admin'], $context['user']['is_logged'], and $context['user']['is_guest'], etc. to distinguish between logged in and guests?  If so, do you have this line:

global $context;

...immediately below the require(SSI.php) line?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Trekkie101 on November 30, 2010, 09:06:16 AM
Excellent stuff here!


Copy some of it over to the wiki... and do a little tutorial or that?


http://wiki.simplemachines.org



Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 30, 2010, 09:28:40 AM
Quote from: spottedhog on November 30, 2010, 08:30:01 AM
Do you use code like:  $context['user']['is_admin'], $context['user']['is_logged'], and $context['user']['is_guest'], etc. to distinguish between logged in and guests?  If so, do you have this line:

global $context;

...immediately below the require(SSI.php) line?
I did do that and it worked fine here.

I needed that for letting users download specific files when they are logged in.

if ($context['user']['is_guest'])
echo'
If the user is a guest, display that info.
Else...

elseif (!$context['user']['is_guest'])
echo'
The user isn't a guest...that means he must be logged in!
Display info for active (logged in) members.
Else...

elseif ($context['user']['is_admin'])
echo'
the user is an administrator!!
Put some actions an admin would like to do in there ;)

Personally I like this one...
elseif ($context['user']['is_developer'])
echo'
If a developer is logged in...display content to him that's of interest to developers.
Needs additional code installed!
Not gonna give ya the code yet since it fails to work at the moment.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 30, 2010, 01:09:06 PM
hmm no I did not
Mind you, my knowledge of php is extremely limited
The only reason I could use the smf theme on my new page was because google gave me this thread ;P

I don't suppose you could tell me the proper way of using context?
The one way I saw was

<?php
if ($context['user']['is_guest'])
{
 
ssi_login();
}
else
{
 
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
  //Hey, username, you have 552 messages, 0 are new.
 
ssi_logout();
}


Which kind of worked because it allowed me to login and stay
But it put an ugly login box top left and edited my tables on my new page.

I'm just a little confused and can't seem to find good docs
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 30, 2010, 01:18:18 PM
Quote from: dutchbastard on November 30, 2010, 01:09:06 PM
hmm no I did not
Mind you, my knowledge of php is extremely limited
The only reason I could use the smf theme on my new page was because google gave me this thread ;P

I don't suppose you could tell me the proper way of using context?
The one way I saw was

<?php
if ($context['user']['is_guest'])
{
 
ssi_login();
}
else
{
 
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
  //Hey, username, you have 552 messages, 0 are new.
 
ssi_logout();
}


Which kind of worked because it allowed me to login and stay
But it put an ugly login box top left and edited my tables on my new page.

I'm just a little confused and can't seem to find good docs
It's the only way.

Btw, you forgot to close your document with ?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 30, 2010, 01:25:53 PM
actually i forgot to take out <?php in my example

I've pasted my full index page below.
To be honest I don't know if I'm using context or how to find out.
Mainly because I don't even know what it does.


<?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.
ob_start();  //is needed not to get errors.
require('../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;Server List';
} else {
$context['page_title'] = $mbname . '&nbsp;-&nbsp;Server List';
}

   
// 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.
//-------------------------------------------------Main Content-----------------------------------------------------------+
   
echo'
       
        '
;
 
//------------------------------------------ServerList Content---------------------------------------------------------------+
 
global $output, $lgsl_server_id;

 
$output = "";

 
$s = isset($_GET['s']) ? $_GET['s'] : "";

 if     (
is_numeric($s)) { $lgsl_server_id = $s; require "lgsl_files/lgsl_details.php"; }
 elseif (
$s == "add")    {                       require "lgsl_files/lgsl_add.php";     }
 else                    {                       require
"lgsl_files/lgsl_list.php";    }

 echo
$output;

 unset(
$output);
//---------------------------------------------------End Serverlist---------------------------------------------------------+
 
        echo
'
       
       '
;    

   }
//---------------------------------------------------End Main content---------------------------------------------------------+

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

?>

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 30, 2010, 01:34:21 PM
Quote from: dutchbastard on November 30, 2010, 01:25:53 PM
To be honest I don't know if I'm using context or how to find out.
Mainly because I don't even know what it does.

http://www.simplemachines.org/community/index.php?board=41.0 (http://www.simplemachines.org/community/index.php?board=41.0)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Trekkie101 on November 30, 2010, 01:38:57 PM
Quote from: dutchbastard on November 30, 2010, 01:09:06 PM
hmm no I did not
Mind you, my knowledge of php is extremely limited
The only reason I could use the smf theme on my new page was because google gave me this thread ;P

I don't suppose you could tell me the proper way of using context?
The one way I saw was

<?php
if ($context['user']['is_guest'])
{
 
ssi_login();
}
else
{
 
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
  //Hey, username, you have 552 messages, 0 are new.
 
ssi_logout();
}


Which kind of worked because it allowed me to login and stay
But it put an ugly login box top left and edited my tables on my new page.

I'm just a little confused and can't seem to find good docs


Depends what you want to do...


You could just make a small static link to the SMF login page, or you can format the ssi_login() function, but thats a little bit harder.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 30, 2010, 01:46:59 PM
well what I want to accomplish is to remain logged in when visiting this new page.
Inside my SMF folder I have a folder called Servers
This folder is where my new index page is and everything else the "servers" script requires.
This topic gave me an easy option to incorporate the global default theme of my SMF install
In other words, my new script is properly integrated to have the look of the rest of the site.

But when I visit my new page I am not logged in.
I have a login box in the header as I do on any other page if not logged in.
When I use it, it brings me to the main page (Home) and when I visit Servers again I am not logged in.
As such I do not have access to my Admin button from the servers page.

Not a big deal really since there is nothign to moderate, but it does look a bit off.
I'd rather have it fully integrated.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 30, 2010, 01:48:44 PM
Quote from: dutchbastard on November 30, 2010, 01:09:06 PM

<?php
if ($context['user']['is_guest'])
{
 
ssi_login();
}
else
{
 
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
  //Hey, username, you have 552 messages, 0 are new.
 
ssi_logout();
}


This should look like this:

<?php
if ($context['user']['is_guest'])

 
ssi_login();

else if (
$context['user']['is_logged'])

 
//You can show other stuff here.  Like ssi_welcome().  That will show a welcome message like.
  //Hey, username, you have 552 messages, 0 are new.
 
ssi_logout();
?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 30, 2010, 01:57:03 PM
Ah I see, that works thank you.

Now let me ask you something else
That code puts a login box (or logout link) at the very top of the page, above the header.

How can I make sure it uses the login box that is already present in the header?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on November 30, 2010, 02:02:44 PM
Quote from: dutchbastard on November 30, 2010, 01:57:03 PM
Ah I see, that works thank you.

Now let me ask you something else
That code puts a login box (or logout link) at the very top of the page, above the header.

How can I make sure it uses the login box that is already present in the header?
You can't.

SMF uses the same code for the SSI login box, and the default SMF login box.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 30, 2010, 02:03:19 PM
That's true, but you can use this instead:


<?php
if (!empty(
$context['show_login_bar']))
echo '
<script type="text/javascript" src="'
, $settings['default_theme_url'], '/scripts/sha1.js"></script>
<form id="guest_form" action="'
, $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '" ', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
<div class="info">'
, $txt['login_or_register'], '</div>
<input type="text" name="user" size="10" class="input_text" />
<input type="password" name="passwrd" size="10" class="input_password" />
<select name="cookielength">
<option value="60">'
, $txt['one_hour'], '</option>
<option value="1440">'
, $txt['one_day'], '</option>
<option value="10080">'
, $txt['one_week'], '</option>
<option value="43200">'
, $txt['one_month'], '</option>
<option value="-1" selected="selected">'
, $txt['forever'], '</option>
</select>
<input type="submit" value="'
, $txt['login'], '" class="button_submit" /><br />
<div class="info">'
, $txt['quick_login_dec'], '</div>';

else if (!empty($modSettings['enableOpenID']))
echo '
<br /><input type="text" name="openid_identifier" id="openid_url" size="25" class="input_text openid_login" />'
;

echo '
<input type="hidden" name="hash_passwrd" value="" />
</form>'
;
?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: dutchbastard on November 30, 2010, 02:08:33 PM
bah
I found that you we're right from the very start
global $context; Did the trick
I must have had some cookies issues because it didn't work before.

http://docs.simplemachines.org/index.php?topic=789.0#post_extras
That describes some of the solution for the redirect after.
Just have to find out how to use it since with this it still points me to smf (Home)

global $context;
$_SESSION['login_url'] = 'http://localhost' . $_SERVER['PHP_SELF'];
$_SESSION['logout_url'] = 'http://localhost' . $_SERVER['PHP_SELF'];


I'm sure I'll figure it out.
In any case, Thanks a lot! for the help, it is greatly appreciated.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Masterd on November 30, 2010, 02:10:28 PM
I'm glad that you solved your problem! :D
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 10, 2010, 08:52:53 PM
Does this not work in 2.0 RC4?

I have everything working until you start to add content. Then you get an error message on the first line you added punctuation like a period or comma or quotes.

Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 04:29:44 AM
Quote from: Mike Stowe on December 10, 2010, 08:52:53 PM
Does this not work in 2.0 RC4?

I have everything working until you start to add content. Then you get an error message on the first line you added punctuation like a period or comma or quotes.
It works on RC4.

You need to transfer all 's in the text only to /'. It's called 'magic quotes' ;)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 11, 2010, 08:12:49 AM
You still need to follow proper PHP rules.  For example, if you are using echo with single quotes, you need to comment out apostrophes like in this code:
echo '';
// note the use of single quotes above

echo 'Here\'s a sentence that\'s going to need what I was talking about.';
// note the backslashes above


If you are using double quotes, you will need to comment out any double quotes within the echo like this:
echo "";
// note the use of double quotes

echo "Go to Google: <a href=\"http://www.google.com\">Click Here</a>";


As for the wrong placement of periods and/or commas, the error is telling you whatever code you have is not properly formed by PHP rules.

Otherwise, the original external manual page code should work every time.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 08:29:37 AM
Yay! I had a lot of > ' <. Looks like i got them all.  Thanks for your help.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 10:27:37 AM
Just wondering but why does the subject in this topic say manually?

Adding a custom page manually for Smf 2.0. rc 3

Is there an automatic way to do this?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 10:31:55 AM
Quote from: Mike Stowe on December 11, 2010, 10:27:37 AM
Just wondering but why does the subject in this topic say manually?

Adding a custom page manually for Smf 2.0. rc 3

Is there an automatic way to do this?
No, but I'm working on one (but don't expect it to get done right now since..well...I'm a PHP noobie.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 10:42:16 AM
Nice! I think when it's finished the suicide rate of smf users will drop off drastically lol
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 11:04:57 AM
Quote from: Mike Stowe on December 11, 2010, 10:42:16 AM
Nice! I think when it's finished the suicide rate of smf users will drop off drastically lol
LOL yeah that's true.

It's build in Visual Basic, though.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 11:33:28 AM
Would you have any resources or links that might help me figure out how to add css to the content I add to the custom page I've created. I don't know very much about css and I normally get things done by making make and un making 20 changes in dreamweaver using its split screen view before i upload to the site.

The problem i have is that when I add my css to the forums it doesn't apply to my content the same way it does when its on its own page. My dreamweaver doesn't show me a preview of the forum code so i've been having to upload after each change I try to see what it changes. Its a very very painful process and so far i haven't managed to get anywhere with it.

I'm trying to set a div down the left and right side of the page with links and stuff that sit against the left or right edge of the page with another div in between in the center of the page that hold the bulk of my content. I was told I needed to clear floats and i don't really know what that means but from doing some research all it seems to do is stack the left, center, and right div one on top of the other.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 11:41:02 AM
Quote from: Mike Stowe on December 11, 2010, 11:33:28 AM
Would you have any resources or links that might help me figure out how to add css to the content I add to the custom page I've created. I don't know very much about css and I normally get things done by making make and un making 20 changes in dreamweaver using its split screen view before i upload to the site.

The problem i have is that when I add my css to the forums it doesn't apply to my content the same way it does when its on its own page. My dreamweaver doesn't show me a preview of the forum code so i've been having to upload after each change I try to see what it changes. Its a very very painful process and so far i haven't managed to get anywhere with it.

I'm trying to set a div down the left and right side of the page with links and stuff that sit against the left or right edge of the page with another div in between in the center of the page that hold the bulk of my content. I was told I needed to clear floats and i don't really know what that means but from doing some research all it seems to do is stack the left, center, and right div one on top of the other.
No, I'm sorry.

I just create pages with the code Spottedhog posted, and then I'm modifying it to my needs (only showing content to members, etc).
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 11, 2010, 11:50:35 AM
Mike Stowe, this is just my personal opinion, but you might want to consider losing Dreamweaver and replacing it with a PHP/Text/HTML editor like Crimson Editor (for windoz users) or Bluefish (for Linux desktop users).

For coding, you may want to look at some CSS tutorials, etc.  There is an excellent little book that I first used to learn with and still keep it around as a reference:

CSS in easy steps by Mike McGrath  Pub. by Barnes & Noble  ISBN: 0-7607-7859-0 and the price was $9.95

You may also want to take a look at XAMPP which turns your PC into a web server so you can work offline and be able to view your outputs.

Lastly, you can always use inline CSS.  For example:

echo '<div style="font-size:medium;color:navy;width:300px">';
...or you can add a CSS class to the theme's style.css file.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 11:55:01 AM
Quote from: spottedhog on December 11, 2010, 11:50:35 AM
Mike Stowe, this is just my personal opinion, but you might want to consider losing Dreamweaver and replacing it with a PHP/Text/HTML editor like Crimson Editor (for windoz users) or Bluefish (for Linux desktop users).

For coding, you may want to look at some CSS tutorials, etc.  There is an excellent little book that I first used to learn with and still keep it around as a reference:

CSS in easy steps by Mike McGrath  Pub. by Barnes & Noble  ISBN: 0-7607-7859-0 and the price was $9.95

You may also want to take a look at XAMPP which turns your PC into a web server so you can work offline and be able to view your outputs.

Lastly, you can always use inline CSS.  For example:

echo '<div style="font-size:medium;color:navy;width:300px">';
...or you can add a CSS class to the theme's style.css file.
I usez Simple Notes 1.1 Beta 2, my own product :)

Edits HTML, HTML, SHTML, PHP, CSS, JS (plus many more, but that are the web documents) and directly let you view the following formats in a browser: SHTML, HTML and HTM!
No PHP viewing support though.

http://smftools.co.cc/download/SN1.1B2.zip
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 03:33:29 PM
I'm trying to link my custom page to am image gallery, Normally I put this bit of code where I want the gallery to display.

<?php
$path_to_minigalnano
= "screenshots/"; //     <- Enter RELATIVE path to MiniGal Nano here (eg. "subfolder/minigalnano") - DO NOT END WITH /

// DO NOT EDIT BELOW THIS LINE!
define("GALLERY_ROOT", $path_to_minigalnano);
require(
GALLERY_ROOT . "index.php");
?>


When I add it to my custom page nothing happens. I don't even get an error message saying my path is wrong.vThe custom page is located in the forums dir. The screen shots folder that I'm trying to link to is also in the forums dir.

This the the custom page after i've added the bit of code. Do you see anything out of place?


<?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'] = 'WAR ARMADA: EVE ONLINE';

//This is self explanatory
template_header();

//Here we define the link tree
$context['linktree'] = array(
 
'href' => 'http://www.wararmada.com/forums/screenschots.php',
 );

//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">War Armada: Screenshots</h3>
        </div>






<?php
$path_to_minigalnano = "screenshots/";
define("GALLERY_ROOT", $path_to_minigalnano);
require(GALLERY_ROOT . "index.php");
?>









</div></div>
        <span class="lowerframe"><span></span></span>';

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

?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 11, 2010, 04:16:35 PM
Quote from: Mike Stowe on December 11, 2010, 03:33:29 PM
I'm trying to link my custom page to am image gallery, Normally I put this bit of code where I want the gallery to display.

<?php
$path_to_minigalnano
= "screenshots/"; //     <- Enter RELATIVE path to MiniGal Nano here (eg. "subfolder/minigalnano") - DO NOT END WITH /

// DO NOT EDIT BELOW THIS LINE!
define("GALLERY_ROOT", $path_to_minigalnano);
require(
GALLERY_ROOT . "index.php");
?>


When I add it to my custom page nothing happens. I don't even get an error message saying my path is wrong.vThe custom page is located in the forums dir. The screen shots folder that I'm trying to link to is also in the forums dir.

This the the custom page after i've added the bit of code. Do you see anything out of place?


<?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'] = 'WAR ARMADA: EVE ONLINE';

//This is self explanatory
template_header();

//Here we define the link tree
$context['linktree'] = array(
 
'href' => 'http://www.wararmada.com/forums/screenschots.php',
 );

//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">War Armada: Screenshots</h3>
        </div>






<?php
$path_to_minigalnano = "screenshots/";
define("GALLERY_ROOT", $path_to_minigalnano);
require(GALLERY_ROOT . "index.php");
?>









</div></div>
        <span class="lowerframe"><span></span></span>';

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

?>

You don't need to have the linktree part.

And put in this line:
ob_start();
That is required not to get errors.

Place it somewhere before calling SSI.php.

Oh and why don't you just do this instead of doing path_to_blablabla:
$GALLERY_ROOT = "/images";
Remove the line right under the part that does say do not modify.

So the code does look like:
<?php
$GALLERY_ROOT
= "/images";
require(
$GALLERY_ROOT . "index.php");
?>


AND you didn't do the FULL path to your gallery. IT must be something like this:
/home/sitename/public_html/imgaes.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 04:34:37 PM
Something in this code is turning the php off.

echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

<p>Here is where the code needs to go.<p />

</div></div>
        <span class="lowerframe"><span></span></span>';


I've got a php editor and its showing my code in the wrong colors when its in place. If I add my code outside of the echo thing it works. Is there a way to turn the php back on inside the echo thing?
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 11, 2010, 04:42:51 PM
hmmmmm....  try this code:

<?php
//Set the banning active
$ssi_ban = true;
ob_start();
//Path to SSI.php
require(dirname(__FILE__) . '/SSI.php');

//Page title. This will appear in the browser
$context['page_title_html_safe'] = 'WAR ARMADA: EVE ONLINE';

//This is self explanatory
template_header();

//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">War Armada: Screenshots</h3>
        </
div></div></div>
       <
span class="lowerframe"><span></span></span>';

include("screenshots/index.php");

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

?>


The div's and span's are only for title type stuff, not for content.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 11, 2010, 05:08:12 PM
Are you sure?

It looks like its the horizontal bar that goes across the top over the contact and the a background box that expands with your content.

It works fine when i add my code out side of the divs.

echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

Content goes here to fit inside the box

         </div></div>
        <span class="lowerframe"><span></span></span>';

I think i just need to know the code to turn php back on in that spot.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 11, 2010, 07:47:55 PM
Take a closer look at your code...  You did not end the echo ...  also, there is no need to end/start PHP with the code you listed.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: wodada on December 12, 2010, 02:44:53 AM
change this:

$ssi_ban = 1;

...to this:

$ssi_ban = true;
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 12, 2010, 03:37:47 AM
Quote from: Mike Stowe on December 11, 2010, 05:08:12 PM
Are you sure?

It looks like its the horizontal bar that goes across the top over the contact and the a background box that expands with your content.

It works fine when i add my code out side of the divs.

echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

Content goes here to fit inside the box

         </div></div>
        <span class="lowerframe"><span></span></span>';

I think i just need to know the code to turn php back on in that spot.
The code should be this:

echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

Content goes here to fit inside the box';
echo'
         </div></div>
        <span class="lowerframe"><span></span></span>';
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: Mike Stowe on December 12, 2010, 02:22:54 PM
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

include("screenshots/index.php");  <<<<<<<<<<<<<This is still showing up as plain code instead of php code.
echo'
         </div></div>    <<<<<<<<<<<<< I get an error on this line Parse error: syntax error, unexpected '/' in /home/barons/public_html/forums/screenshots.php on line 29
        <span class="lowerframe"><span></span></span>';


I also tried using my code in place of the include code with the same effect.

<?php
$path_to_minigalnano
= "screenshots/"; //     <- Enter RELATIVE path to MiniGal Nano here (eg. "subfolder/minigalnano") - DO NOT END WITH /

// DO NOT EDIT BELOW THIS LINE!
define("GALLERY_ROOT", $path_to_minigalnano);
require(
GALLERY_ROOT . "index.php");
?>


and

$path_to_minigalnano = "screenshots/";
define("GALLERY_ROOT", $path_to_minigalnano);
require(GALLERY_ROOT . "index.php");
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 12, 2010, 02:44:57 PM
Quote from: Mike Stowe on December 12, 2010, 02:22:54 PM
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>

include("screenshots/index.php");  <<<<<<<<<<<<<This is still showing up as plain code instead of php code.
echo'
         </div></div>    <<<<<<<<<<<<< I get an error on this line Parse error: syntax error, unexpected '/' in /home/barons/public_html/forums/screenshots.php on line 29
        <span class="lowerframe"><span></span></span>';


I also tried using my code in place of the include code with the same effect.

<?php
$path_to_minigalnano
= "screenshots/"; //     <- Enter RELATIVE path to MiniGal Nano here (eg. "subfolder/minigalnano") - DO NOT END WITH /

// DO NOT EDIT BELOW THIS LINE!
define("GALLERY_ROOT", $path_to_minigalnano);
require(
GALLERY_ROOT . "index.php");
?>


and

$path_to_minigalnano = "screenshots/";
define("GALLERY_ROOT", $path_to_minigalnano);
require(GALLERY_ROOT . "index.php");

You may NOT end the path with a /, either begin with it and have it in the midway as you wish, but do NOT end with it.

And use this:
<?php
$GALLERY_ROOT
= "/screenshots";
require(
$GALLERY_ROOT . "index.php");
?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 12, 2010, 04:19:09 PM
This:
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>


...needs to be this:
echo'
         <span class="clear upperframe"><span></span></span>
         <div class="roundframe"><div class="innerframe">';
         echo'
         <div class="cat_bar">
         <h3 class="catbg">War Armada: Screenshots</h3>
         </div>';


In other words, you did not close out the echo
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: MLM on December 12, 2010, 06:09:49 PM
Thank you so much! ;)

Confirmed works on 2.0 RC4

I used this exact code:
<?php
//Set the banning active
$ssi_ban = true;

//Path to SSI.php
require("forums/SSI.php");

//Page title. This will appear in the browser
$context['page_title_html_safe'] = '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();

?>
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 13, 2010, 02:55:42 PM
I've managed to build an autenticating (or however you write it lol) system, like if an admin is logged on it transforms into a control panel and for members/guests it shows page content.

It will require a bit of php knowledge since many things can go wrong.

if ($context['user']['is_admin'])
echo'
<p>Your content here. Only showed for ADMINS.</p>';
elseif ($context['user']['is_logged'])
echo'
<p>Your content here. Only showed for NORMAL MEMBERS.</p>';
elseif ($context['user']['is_guest'])
echo'
<p>Your content here. Only showed for GUESTS.</p>';
else
echo'
<p>Acts the same as the code for guests; if the user ain\'t admin, nor member, it must be a guest.</p>';

You will need to global CONTEXT, like here;
require('/home/yoursite/www/smf/SSI.php');
global $context;
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 14, 2010, 08:07:07 AM
Here, let us get everything included:

global $user_info, $context;
$memberGroupID = '';  // insert the memberGroup ID # you wish to be able to view the page.
// Multiple Groups use an array. Example:  $memberGroupID = array(1, 7, 10, 12, 15);

if (in_array($memberGroupID, $user_info['groups']) || $context['user']['is_admin'])
{

// content for Member Group and/or Admin

} elseif ($context['user']['is_admin']) {

// content for Admin only

} elseif($context['user']['is_logged']) {

// content for registered and logged in users

} else {

// content for Guests

}
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 14, 2010, 09:55:33 AM
Quote from: spottedhog on December 14, 2010, 08:07:07 AM
Here, let us get everything included:

global $user_info, $context;
$memberGroupID = '';  // insert the memberGroup ID # you wish to be able to view the page.
// Multiple Groups use an array. Example:  $memberGroupID = array(1, 7, 10, 12, 15);

if (in_array($memberGroupID, $user_info['groups']) || $context['user']['is_admin'])
{

// content for Member Group and/or Admin

} elseif ($context['user']['is_admin']) {

// content for Admin only

} elseif($context['user']['is_logged']) {

// content for registered and logged in users

} else {

// content for Guests

}

The code I posted works perfectly fine.

http://smftools.co.cc/forums/docs/index.php

Admin has a few more wrench icons (to allow easy editing of the pages).
Member has "paperclip" icons (to download the documentation in RTF format).
Guest has neither.

Don't mind the database error -- I'll get that sorted out later.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 14, 2010, 10:44:11 AM
I never said your code did not work. I just added another permission layer so the code would be complete.  Your code did not allow for permissions for MemberGroups. 

Since you put up code for permissions, I thought it would be best to add an additional parameter so that all permissions would be covered.

The code I posted works "perfectly fine" also.  :)  ...without any database error... ;)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 14, 2010, 11:12:46 AM
Quote from: spottedhog on December 14, 2010, 10:44:11 AM
I never said your code did not work. I just added another permission layer so the code would be complete.  Your code did not allow for permissions for MemberGroups. 

Since you put up code for permissions, I thought it would be best to add an additional parameter so that all permissions would be covered.

The code I posted works "perfectly fine" also.  :)  ...without any database error... ;)
That database error comes from a few tweaks I made elsewhere (like the tweak I added to integrate SMFTools Page Manager).
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 14, 2010, 11:27:34 AM
apples and oranges...

This thread is about adding a custom page manually for SMF, not how to use it with your custom code.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 14, 2010, 11:54:00 AM
Quote from: spottedhog on December 14, 2010, 11:27:34 AM
apples and oranges...

This thread is about adding a custom page manually for SMF, not how to use it with your custom code.
It is a custom page :P

require('/home/smftools/public_html/smftoolspm/integrate.php');
global $pagemanagerpath, $pagemanagerindex, $user_enabled, $use, $currentpage;
require($pagemanagerindex);
$use(createpageindex_$currentpage);
if ($user_enabled(pagegroup_admin)) {
echo'
<p>SMFTools Page Manager ', $smftpm_ver, ' notice: ACP enabled for remote access.</p>';
}

That is almost the correct code to merge SMFTools Page Manager into your page (and let it build it).
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 14, 2010, 01:01:03 PM
Quoterequire('/home/smftools/public_html/smftoolspm/integrate.php');
global $pagemanagerpath, $pagemanagerindex, $user_enabled, $use, $currentpage;
require($pagemanagerindex);
$use(createpageindex_$currentpage);
if ($user_enabled(pagegroup_admin)) {
echo'
<p>SMFTools Page Manager ', $smftpm_ver, ' notice: ACP enabled for remote access.</p>';
}

That is almost the correct code to merge SMFTools Page Manager into your page (and let it build it).

Thank you for making my point.

Yoshi, you may need to consider who is reading these posts.  You keep bringing up unrelated code which in turn can confuse some users.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on December 14, 2010, 01:39:15 PM
Quote from: spottedhog on December 14, 2010, 01:01:03 PM
Quoterequire('/home/smftools/public_html/smftoolspm/integrate.php');
global $pagemanagerpath, $pagemanagerindex, $user_enabled, $use, $currentpage;
require($pagemanagerindex);
$use(createpageindex_$currentpage);
if ($user_enabled(pagegroup_admin)) {
echo'
<p>SMFTools Page Manager ', $smftpm_ver, ' notice: ACP enabled for remote access.</p>';
}

That is almost the correct code to merge SMFTools Page Manager into your page (and let it build it).

Thank you for making my point.

Yoshi, you may need to consider who is reading these posts.  You keep bringing up unrelated code which in turn can confuse some users.
I know I know, just saying that SMFTPM is indeed related to custom pages :)
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: spottedhog on December 14, 2010, 02:03:57 PM
Yoshi,

What you are talking about is off topic.  If you wish to discuss your specific code in relation to what can be done with a custom manual page, please start a new topic.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: EpicS on February 22, 2013, 07:40:59 AM
Hello, sorry for the bump.
I'm new here, and I have a small mistake wile creating a new page..

I made a page, and I edited everything in Subs, but it gave me this too..:

Notice: Use of undefined constant Donate - assumed 'Donate' in /home/joker/public_html/Sources/Subs.php on line 4089

Notice: Use of undefined constant Wiki - assumed 'Wiki' in /home/joker/public_html/Sources/Subs.php on line 4098

Please help me,
Thanks.
Title: Re: Adding a custom page manually for Smf 2.0. rc 3
Post by: NanoSector on February 22, 2013, 11:13:50 AM
Ughh, the code I posted in here is ugly :-\
Please ignore my posts in here.

EpicS: You should put the button names in single quotes like 'Donate' instead of Donate and 'Wiki' instead of Wiki