Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frontainer
#8
(2016-02-22, 23:48:10)Bigin Wrote: ...
Preparing your theme for using Frontainer

Preparing your theme for using Frontainer is really easy. Open template.php file in your editor and add the following lines to the very beginning (first line).

Code:
<?php
if(!defined('IN_GS')) die();
if(!isset($_SESSION)){session_start();}
// Frontainer call
$content = frontainer_get_content();
?>

After that you’ll need to add a single line anywhere within the body of your template.php file for the output of Frontier’s contents:

Code:
<?php echo $content; ?>
 
To access Frontainers sections and to switch between Frontainers pages you can use following navigation structure for example:

Code:
<ul class="nav navbar-nav">
   <li><a href="<?php get_site_url(); ?>forum/">Forum</a></li>
   <?php
   if(!isset($_SESSION['loggedin'])) {
       echo '<li ';
       if($id == LOGIN_SLUG || $id == RECOVERY_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(LOGIN_SLUG)).'">Login</a></li>';
       echo '<li ';
       if($id == SIGNUP_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(SIGNUP_SLUG)).'">Sign up</a></li>';
   } else {
       echo '<li ';
       if($id == ACCOUNTS_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(ACCOUNTS_SLUG)).'">Private</a></li>';
       echo '<li ';
       if($id == LOGOUT_SLUG)
           echo 'class="active"';
       echo ' ><a href="'.htmlspecialchars(get_section_url(LOGOUT_SLUG)).'">Logout</a></li>';
   }
?>
</ul>

And that is all you need to do to run Frontainer!

User's private area

After a successful login the user is redirected by default to www.your_site.com/accounts/ page in the users private section.
To modify this private area, just edit '/plugins/frontainer/loggedin.php' file within the 'build_user_area()' function and put there any content you like, after: //////////   Your can put your content here //////////// comment. You can delete all lines subsequent to that code


Using Frontainer session variables

To check whether the user is logged use code:

Code:
<?php
if(!empty($_SESSION['loggedin'])) {
// This is the theme section for logged in users only
}
?>

You can get the logged in users ID on this way:

Code:
<?php
$user_id = (!empty($_SESSION['userid']) ? (int) $_SESSION['userid'] : false);
?>

Have fun!

I have followed the outlined steps, but I fail to  really understand how I can apply a requirement to login for a given set of pages and subpages. I think the approach is to have a dedicated template for password protected content?
This is a modified template from the bootstrap3 theme. I have managed to make it show two different texts based on login status, but I still cannot show the actual content of the page with the "get_page_content();" that is normally used:

Code:
<?php
if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
if(!isset($_SESSION)){session_start();}
// Frontainer call
$content = frontainer_get_content();

/****************************************************
*
* @File:      templateprotected.php
* @Package:   GetSimple
* @Action:    Bootstrap3 for GetSimple CMS
*
*****************************************************/
?>
<?php include('header.inc.php'); ?>

     <div class="row">
       <div class="col-md-8">
         <h1><?php get_page_title(); ?></h1>
            <?php
                if(!empty($_SESSION['loggedin'])) {
                    // This is the theme section for logged in users only
                    get_page_content(); //This is the normally the way I call the content of the page, I cannot get it to work.
                    echo '<p>You are logged in</p>';
                    echo $content; //Does not seem to do anything
                }
                else {
                    echo '<p>You need to login to see this page</p>';
                }
            ?>
       </div>
       
       <div class="col-md-4">
          <?php get_component('sidenav'); ?>
       </div>
     </div>

<?php include('footer.inc.php'); ?>

I have managed to add frontainer to my navbar - and I have registered a user, I am able to login and logout and go to my account page.

Basically I just want a page and its subpages to require a password. But I do not want to re-enter the password for every resource I access on those pages so it makes sense to have a logged in session.

Any suggestions?
Best regards,
Reply


Messages In This Thread
Frontainer - by Bigin - 2016-02-22, 23:48:10
RE: Frontainer - by Tzvook - 2016-02-24, 07:20:45
RE: Frontainer - by Bigin - 2016-02-24, 07:25:28
RE: Frontainer - by Tzvook - 2016-02-24, 07:39:28
RE: Frontainer - by Bigin - 2016-02-24, 07:50:04
RE: Frontainer - by Tzvook - 2016-02-24, 07:54:03
RE: Frontainer - by Bigin - 2016-02-24, 07:59:36
RE: Frontainer - by DesruX - 2016-04-12, 07:55:41
RE: Frontainer - by Bigin - 2016-04-12, 17:41:37
RE: Frontainer - by Bigin - 2016-04-13, 00:17:33
RE: Frontainer - by DesruX - 2016-04-13, 00:36:22
RE: Frontainer - by Bigin - 2016-04-13, 01:37:49
RE: Frontainer - by DesruX - 2016-04-13, 04:24:49
RE: Frontainer - by Bigin - 2016-04-13, 05:25:05
RE: Frontainer - by DesruX - 2016-04-13, 05:32:45
RE: Frontainer - by Bigin - 2016-04-13, 05:51:48
RE: Frontainer - by DesruX - 2016-04-15, 06:45:34
RE: Frontainer - by Bigin - 2016-04-15, 19:39:53
RE: Frontainer - by Bigin - 2016-04-12, 18:08:27
RE: Frontainer - by DesruX - 2016-04-12, 23:49:06
RE: Frontainer - by Bigin - 2016-04-13, 00:20:00
RE: Frontainer - by DesruX - 2016-04-13, 00:31:16
RE: Frontainer - by Bigin - 2016-04-12, 20:14:09
RE: Frontainer - by Bigin - 2016-04-15, 20:12:41
RE: Frontainer - by jeckyl - 2017-02-07, 01:55:19
RE: Frontainer - by Bigin - 2017-02-07, 03:58:00
RE: Frontainer - by jeckyl - 2017-02-07, 04:36:08
RE: Frontainer - by Bigin - 2017-02-07, 05:16:52
RE: Frontainer - by jeckyl - 2017-02-07, 06:13:24
RE: Frontainer - by Bigin - 2017-02-07, 08:49:33
RE: Frontainer - by jeckyl - 2017-02-07, 09:14:22
RE: Frontainer - by nicco - 2017-05-12, 19:26:45
RE: Frontainer - by Bigin - 2017-05-12, 20:38:15
RE: Frontainer - by nicco - 2017-05-12, 23:28:17
RE: Frontainer - by Bigin - 2017-05-13, 00:58:52
RE: Frontainer - by nicco - 2017-05-13, 02:11:24
RE: Frontainer - by Bigin - 2017-05-13, 02:51:45
RE: Frontainer - by nicco - 2017-05-13, 03:04:30
RE: Frontainer - by Bigin - 2017-05-13, 03:09:48
RE: Frontainer - by Carlos - 2017-05-13, 03:19:09
RE: Frontainer - by Bigin - 2017-05-13, 03:28:10
RE: Frontainer - by Stéphane - 2020-04-13, 03:40:16
RE: Frontainer - by Bigin - 2020-04-13, 04:16:35
RE: Frontainer - by Stéphane - 2020-04-13, 08:02:32
RE: Frontainer - by Bigin - 2020-04-13, 20:32:51
RE: Frontainer - by Stéphane - 2020-04-13, 22:46:48



Users browsing this thread: 1 Guest(s)