Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Template parser page not woking with login system function calls

    Hi all,
    Thanks for taking the time to read my post.

    I've recently built a php/MySQL CMS and used a simple template parser to create new pages, all based around the same HTML file with placeholders to replace with text/pages to be sucked into these placeholders (<!--main-->).

    Template class:
    PHP Code:
    <?php
    class Page
    {
      var 
    $page;

      function 
    Page($template "assets/templates/template.htm") {
        if (
    file_exists($template))
          
    $this->page join(""file($template));
        else
          die(
    "Template file $template not found.");
      }

      function 
    parse($file) {
        
    ob_start();
        include(
    $file);
        
    $buffer ob_get_contents();
        
    ob_end_clean();
        return 
    $buffer;
      }

      function 
    replace_tags($tags = array()) {
        if (
    sizeof($tags) > 0)
          foreach (
    $tags as $tag => $data) {
            
    $data = (file_exists($data)) ? $this->parse($data) : $data;
            
    $this->page eregi_replace("<!--" $tag "-->"$data,
                          
    $this->page);
            }
        else
          die(
    "No tags designated for replacement.");
      }

      function 
    output() {
        echo 
    $this->page;
      }
    }
    ?>
    Which works perfectly using:

    PHP Code:
    <?php
    require_once("req/template.php");
    $page->replace_tags(array(
      
    "title" => "Categories",
      
    "navigation" => "main/navigation.php",
      
    "main" => "main/category.php"
    ));
    $page->output();
    ?>
    for each page. The functionality is in the "main" placeholder.

    I'm trying to integrate the JpMaster77's login system into this, so i can show logged in and admin only content on the "main" pages.

    However, if i try to use the "if person is logged in/has session, or isAdmin(), it doesn't work when parsed, it just trips over any if(session) etc and goes to the else. When the page being drawn in is viewed by itself, this works.

    PHP Code:
    <?php
    include("req/session.php");
    if(
    $session->logged_in){
    if(
    $session->isAdmin()){
       echo 
    "hello there Admin!";
    }
    }
    The login system itself is from 2004, so i'm not sure whether it's the way the isAdmin() function is called by old PHP syntax, or if the parser is not allowing this to run properly....

    Does anyone have any ideas what could be affecting this working properly please?

    Thank you.

    Martin.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Have you started the session somewhere with session_start()? Also, this is outdated and unnecessary:

    Code:
    $this->page = eregi_replace("<!--" . $tag . "-->", $data, $this->page);
    The eregi_ functions are deprecated and you're working with a known string, so use str_.

    Code:
    $this->page = str_replace('<!--'.$tag.'-->', $data, $this->page);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •