News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

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

NanoSector

Oh and hey, installing the Youtube integration mod seems to crash your custom pages to only say "The page cannot be viewed.".
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."


Masterd

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();

?>

spottedhog

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.


spottedhog

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?

Masterd


dutchbastard

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?

spottedhog

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?

Trekkie101

Excellent stuff here!


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


http://wiki.simplemachines.org




NanoSector

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.
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."

dutchbastard

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

NanoSector

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 ?>
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."

dutchbastard

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
   
}

?>


Masterd


Trekkie101

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.

dutchbastard

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.

Masterd

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();
?>

dutchbastard

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?

NanoSector

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.
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: