NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page im having a hell of a time -_- please help

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-24-2005, 07:35 PM THREAD STARTER               #1 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

im having a hell of a time -_- please help


Alright i know php VERY well but i just DO NOT know what i am doing wrong!!!

PHP Code:
<?php
class template {
    var 
$base_path;
    var 
$reset_vars;
    var 
$ldelim '<';
    var 
$rdelim ' />';
    var 
$BAldelim '<';
    var 
$BArdelim '>';
    var 
$EAldelim '</';
    var 
$EArdelim '>';
    var 
$scalars = array();
    var 
$arrays  = array();
    var 
$carrays = array();
    var 
$ifs     = array();

    function 
template($base_path NULL$reset_vars TRUE) {
        if(
$base_path$this->base_path $base_path;
        
$this->reset_vars $reset_vars;
    }

    function 
set($tag$var$if NULL) {
        if(
is_array($var)) {
            
$this->arrays[$tag] = $var;
            if(
$if) {
                
$result $var TRUE FALSE;
                
$this->ifs[] = $tag;
                
$this->scalars[$tag] = $result;
            }
        }
        else {
            
$this->scalars[$tag] = $var;
            if(
$if$this->ifs[] = $tag;
        }
    }

    function 
set_cloop($tag$array$cases) {
        
$this->carrays[$tag] = array(
            
'array' => $array,
            
'cases' => $cases);
    }

    function 
reset_vars($scalars$arrays$carrays$ifs) {
        if(
$scalars==true) { $this->scalars = array(); }
        if(
$arrays==true)  { $this->arrays  = array(); }
        if(
$carrays==true) { $this->carrays = array(); }
        if(
$ifs==true)     { $this->ifs     = array(); }
    }

    function 
get_tags($tag$directive) {
        
$tags['b'] = $this->BAldelim $directive $tag $this->BArdelim;
        
$tags['e'] = $this->EAldelim $directive $tag $this->EArdelim;
        return 
$tags;
    }

    function 
get_tag($tag) {
        return 
$this->ldelim 'tag:' $tag $this->rdelim;
    }

    function 
get_statement($t, &$contents) {
        
$tag_length strlen($t['b']);
        
$fpos strpos($contents$t['b']) + $tag_length;
        
$lpos strpos($contents$t['e']);
        
$length $lpos $fpos;

        return 
substr($contents$fpos$length);
    }

    function 
parse($contents) {
        if(!empty(
$this->ifs)) {
            foreach(
$this->ifs as $value) {
                
$contents $this->parse_if($value$contents);
            }
        }

        foreach(
$this->scalars as $key => $value) {
            
$contents str_replace($this->get_tag($key), $value$contents);
        }

        foreach(
$this->arrays as $key => $array) {
            
$contents $this->parse_loop($key$array$contents);
        }

        foreach(
$this->carrays as $key => $array) {
            
$contents $this->parse_cloop($key$array$contents);
        }

        if(
$this->reset_vars$this->reset_vars(FALSETRUETRUETRUE);

        return 
$contents;
    }

    function 
parse_if($tag$contents) {
        
$t $this->get_tags($tag'if:');
        
$entire_statement $this->get_statement($t$contents);
        
        
$tags['b'] = NULL;
        
$tags['e'] = $this->BAldelim 'else:' $tag $this->BArdelim;        
        
        if((
$else strpos($entire_statement$tags['e']))) {        
            
$if $this->get_statement($tags$entire_statement);
        
            
$else substr($entire_statement$else strlen($tags['e']));
        }
        else {
            
$else NULL;
            
$if $entire_statement;
        }
        
        
$this->scalars[$tag] ? $replace $if $replace $else;

        return 
str_replace($t['b'] . $entire_statement $t['e'], $replace$contents);
????: NamePros.com http://www.namepros.com/programming/92698-im-having-hell-time-_-please.html
    }
    function 
parse_loop($tag$array$contents) {
        
$t $this->get_tags($tag'loop:');
        
$loop $this->get_statement($t$contents);
        
$parsed NULL;

        foreach(
$array as $key => $value) {
            if(
is_numeric($key) && is_array($value)) {
                
$i $loop;
                foreach(
$value as $key2 => $value2) {
                    if(!
is_array($value2)) {
                        
$i str_replace($this->get_tag($tag '[].' $key2), $value2$i);
                    }
                    else {
                        
$i $this->parse_loop($tag '[].' $key2$value2$i);
                    }
                }
            }
            elseif(
is_string($key) && !is_array($value)) {
                
$contents str_replace($this->get_tag($tag '.' $key), $value$contents);
            }
            elseif(!
is_array($value)) {
                
$i str_replace($this->get_tag($tag '[]'), $value$loop);
            }

            if(isset(
$i)) $parsed .= rtrim($i);
        }

        return 
str_replace($t['b'] . $loop $t['e'], $parsed$contents);
    }

    function 
parse_cloop($tag$array$contents) {
        
$t $this->get_tags($tag'cloop:');
        
$loop $this->get_statement($t$contents);

        
$array['cases'][] = 'default';
        
$case_content = array();
        
$parsed NULL;

        foreach(
$array['cases'] as $case) {
            
$ctags[$case] = $this->get_tags($case'case:');
            
$case_content[$case] = $this->get_statement($ctags[$case], $loop);
        }

        foreach(
$array['array'] as $key => $value) {
            if(
is_numeric($key) && is_array($value)) {
                if(isset(
$value['case'])) $current_case $value['case'];
                else 
$current_case 'default';
                unset(
$value['case']);
                
$i $case_content[$current_case];

                foreach(
$value as $key2 => $value2) {
                    
$i str_replace($this->get_tag($tag '[].' $key2), $value2$i);
                }
            }

            
$parsed .= rtrim($i);
        }

        return 
str_replace($t['b'] . $loop $t['e'], $parsed$contents);
    }

    function 
fetch($file_name) {
        
$file $this->base_path $file_name;

        
$fp fopen($file'rb');
        if(!
$fp) return FALSE;
        if(
filesize($file) > 0)
        {
            
$contents fread($fpfilesize($file));
        }
        else
        {
            return 
"$file_name is empty.";
        }

        
fclose($fp);

        return 
$this->parse($contents);
    }
}
?>
My problem is when i parse a if, i cannot reuse the if in the template file, and i have to creature multiple ifs for each part in a file.

master.tpl:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <
head>
    <
title><tag:cfg.sitename /> : <tag:driver.name /></title>
    <
meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
    <
link rel="stylesheet" type="text/css" media="all" href="<tag:cfg.siteurl />/javascript/style.css" />
    <
link rel="stylesheet" type="text/css" media="print" href="<tag:cfg.siteurl />/javascript/print.css" />
  </
head>

  <
body>

    <
div id="header">
      <
h1><tag:cfg.sitename /></h1>
      <
em><tag:cfg.monthL /> <tag:cfg.day />, <tag:cfg.year /></em>
    </
div>

    <
div id="content">

      <
div class="sidebox">
        <
h2>Navigation</h2>
        <if:
islogged>
        <
ul class="navlist">
            <
li><a href="<tag:cfg.siteurl />?drv=news">News</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">Forums</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">Dueling Arena</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">City</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">Help</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">Earn</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=">Logout</a></li>
        </
ul>
        <else:
islogged>
           <
ul class="navlist">
               <
li><a href="<tag:cfg.siteurl />?drv=news">News</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=auth&args=login">Login</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=auth&args=signup">Signup</a></li>
            <
li><a href="<tag:cfg.siteurl />?drv=auth&args=lostpwd">Lost Password</a></li>
        </
ul>        
        </if:
islogged>
      </
div>
      <
div class="sidebox">
        <
h2>User Information</h2>
       <if:
islogged>    
               <
p>Logged in Nothing happen' here yet!</p>    
       <else:islogged>  
               <p>Not logged in</p>         
       </if:islogged>
      </div>
      <div class="sidebox">
        <h2>Site Stats</h2>
        <p>stats will be here</p>
      </div>

      <div class="sidebox">
        <h2>Ads</h2>
         <div align="center"><script type="text/javascript"><!--
google_ad_client = "pub-4504962435573017";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_type = "image";
google_ad_channel ="";
google_color_border = "578A24";
google_color_bg = "CCFF99";
google_color_link = "00008B";
google_color_url = "00008B";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
      </div>
????: NamePros.com http://www.namepros.com/showthread.php?t=92698
       <h1><tag:driver.name /> <tag:driver.action /></h1>
       <!-- CONTENT -->
       <tag:driver.content />
       <!-- END CONTENT -->
    </div>

    <div id="footer">Copyright &copy; 2005 <a href="<tag:cfg.siteurl />"><tag:cfg.sitename /></a> | Valid <a href="http://validator.w3.org/check?uri=referer" title="Valid XHTML 1.0">XHTML</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer/" title="Valid CSS">CSS</a></div>

  </body>
</html> 
Notice i have <if:islogged> in there in two places. It doesnt parse the second one and i have spent the last 5 hours looking at it. And im hoping to see if someone can point me in the right direction, some new eyes

heres the php code:
PHP Code:
<?PHP
define
("DRIVERCLASS""ED_news");
class 
ED_news
{
    var 
$driver = array();
    function 
ED_display_article($article)
    {
        global 
$cfg,$cls,$driver;
        
    }
    function 
ED_news($driver '',$args '')
    {
        global 
$cfg,$cls,$driver;
        
$this->driver['name'] = "News";
        
$this->driver['action'] = "Home Page";
        
$this->driver['content'] = "Coming Soon";
        
$this->ED_return();        
    }
    function 
ED_return()
    {
        global 
$cfg,$cls,$driver;
        
$driver $this->driver;
        
$loggedon false;
        
$cls[tpl]->set('driver'$driver);
        
$cls[tpl]->set('cfg'$cfg);
        
$cls[tpl]->set('islogged'$loggedontrue);
        print 
$cls[tpl]->fetch("master.tpl");
    }
}
?>
All is written by me. But i just need this part to work

200np will be rewarded for the bug fix!

Cody
axilant is offline  
Old 05-24-2005, 11:36 PM   #2 (permalink)
NamePros Member
 
Icespadez's Avatar
Join Date: Apr 2005
Location: Boston, MA
Posts: 26
Icespadez is an unknown quantity at this point
 



I spent some time reconstructing your code and figuring out what was needed to solve the problem. I changed your get_statment funtion to return an array of tags not just a single tag. Also I made a few changes to parse_if

This is what I came up with. Give it a try:

PHP Code:
<?php

    
class template
    
{
        var 
$base_path;
        var 
$reset_vars;
        var 
$ldelim '<';
        var 
$rdelim ' />';
        var 
$BAldelim '<';
        var 
$BArdelim '>';
        var 
$EAldelim '</';
        var 
$EArdelim '>';
        var 
$scalars = array();
        var 
$arrays  = array();
        var 
$carrays = array();
        var 
$ifs = array();

        function 
template($base_path NULL$reset_vars TRUE) {
            if (
$base_path) {
                
$this->base_path $base_path;
            }
            
$this->reset_vars $reset_vars;
        }

        function 
set($tag$var$if NULL) {
            if (
is_array($var)) {
                
$this->arrays[$tag] = $var;
                if (
$if) {
                    
$result $var TRUE FALSE;
                    
$this->ifs[] = $tag;
                    
$this->scalars[$tag] = $result;
                }
            } else {
                
$this->scalars[$tag] = $var;
                if (
$if) {
                    
$this->ifs[] = $tag;
                }
            }
        }

        function 
set_cloop($tag$array$cases) {
            
$this->carrays[$tag] = array(
                
'array' => $array,
                
'cases' => $cases);
        }
    
        function 
reset_vars($scalars$arrays$carrays$ifs) {
            if (
$scalars==true) { $this->scalars = array(); }
            if (
$arrays==true)  { $this->arrays  = array(); }
            if (
$carrays==true) { $this->carrays = array(); }
            if (
$ifs==true) { $this->ifs = array(); }
        }
    
        function 
get_tags($tag$directive) {
            
$tags['b'] = $this->BAldelim $directive $tag $this->BArdelim;
            
$tags['e'] = $this->EAldelim $directive $tag $this->EArdelim;
            return 
$tags;
        }
    
        function 
get_tag($tag) {
            return 
$this->ldelim 'tag:' $tag $this->rdelim;
        }
    
        function 
get_statement($t, &$contents) {
            
$tag_length strlen($t['b']);
            
$tags = array();
            
            
$fpos strpos($contents$t['b']) + $tag_length;
            
            while (
$fpos) {
                
$lpos strpos($contents$t['e'], $fpos);
                
$length $lpos $fpos;
                
$tags[] = substr($contents$fpos$length);
                
$fpos strpos($contents$t['b'], $lpos);
            }
            return 
$tags;
        }
    
        function 
parse(&$contents) {
            if (!empty(
$this->ifs)) {
                foreach(
$this->ifs as $value) {
                    
$contents $this->parse_if($value$contents);
                }
            }
    
            foreach(
$this->scalars as $key => $value) {
                
$contents str_replace($this->get_tag($key), $value$contents);
            }
    
            foreach(
$this->arrays as $key => $array) {
                
$contents $this->parse_loop($key$array$contents);
            }
    
            foreach(
$this->carrays as $key => $array) {
                
$contents $this->parse_cloop($key$array$contents);
            }
    
            if (
$this->reset_vars) {
                
$this->reset_vars(FALSETRUETRUETRUE);
            }
            return 
$contents;
        }
    
        function 
parse_if($tag, &$contents) {
            
$t $this->get_tags($tag'if:');
            
$entire_statement $this->get_statement($t$contents);
            
$num_statements count($entire_statement);
            
            for(
$x 0$x $num_statements$x++) {
                
$else_tags = array(
                        
'b' => NULL,
                        
'e' => $this->BAldelim 'else:' $tag $this->BArdelim
                    
);

                
$else_pos strpos($entire_statement[$x], $else_tags['e']);
                
                if (
$else_pos) {
                    
$if substr($entire_statement[$x], 0$else_pos);
                    
$else substr($entire_statement[$x], $else_pos strlen($else_tags['e']));
                } else {
                    
$else NULL;
                    
$if $entire_statement[$x];
                }

                
$this->scalars[$tag] ? $replace $if $replace $else;
                
$contents str_replace($entire_statement[$x], $replace$contents);
            }
            return 
$contents;
        }
    
        function 
parse_loop($tag$array$contents) {
            
$t $this->get_tags($tag'loop:');
            
$loop $this->get_statement($t$contents);
            
$parsed NULL;
    
            foreach(
$array as $key => $value) {
                if (
is_numeric($key) && is_array($value)) {
                    
$i $loop;
                    foreach(
$value as $key2 => $value2) {
                        if (!
is_array($value2)) {
                            
$i str_replace($this->get_tag($tag '[].' $key2), $value2$i);
                        } else {
                            
$i $this->parse_loop($tag '[].' $key2$value2$i);
                        }
                    }
                } elseif (
is_string($key) && !is_array($value)) {
                    
$contents str_replace($this->get_tag($tag '.' $key), $value$contents);
                } elseif (!
is_array($value)) {
                    
$i str_replace($this->get_tag($tag '[]'), $value$loop);
                }
    
                if(isset(
$i)) {
                    
$parsed .= rtrim($i);
                }
            }
            return 
str_replace($t['b'] . $loop $t['e'], $parsed$contents);
        }
    
        function 
parse_cloop($tag$array$contents) {
            
$t $this->get_tags($tag'cloop:');
            
$loop $this->get_statement($t$contents);
    
            
$array['cases'][] = 'default';
            
$case_content = array();
            
$parsed NULL;
    
            foreach(
$array['cases'] as $case) {
                
$ctags[$case] = $this->get_tags($case'case:');
                
$case_content[$case] = $this->get_statement($ctags[$case], $loop);
            }
    
            foreach(
$array['array'] as $key => $value) {
                if (
is_numeric($key) && is_array($value)) {
                    if (isset(
$value['case'])) {
                        
$current_case $value['case'];
                    } else {
                        
$current_case 'default';
                    }
                    unset(
$value['case']);
                    
$i $case_content[$current_case];
????: NamePros.com http://www.namepros.com/showthread.php?t=92698
    
                    foreach(
$value as $key2 => $value2) {
                        
$i str_replace($this->get_tag($tag '[].' $key2), $value2$i);
????: NamePros.com http://www.namepros.com/showthread.php?t=92698
                    }
                }
                
$parsed .= rtrim($i);
            }
            return 
str_replace($t['b'] . $loop $t['e'], $parsed$contents);
        }
    
        function 
fetch($file_name) {
            
$file $this->base_path $file_name;
    
            
$fp fopen($file'rb');
            if (!
$fp) {
                return 
FALSE;
            }
            if(
filesize($file) > 0) {
                
$contents fread($fpfilesize($file));
            } else {
                return 
$file_name ' is empty.';
            }
            
fclose($fp);
            return 
$this->parse($contents);
        }
    }

    
define('DRIVERCLASS''ED_news');

    class 
ED_news
    
{
        var 
$driver = array();

        function 
ED_display_article($article)
        {
            global 
$cfg,$cls,$driver;
        }

        function 
ED_news($driver '',$args '')
        {
            global 
$cfg,$cls,$driver;
            
$this->driver['name'] = 'News';
            
$this->driver['action'] = 'Home Page';
            
$this->driver['content'] = 'Coming Soon';
            
$this->ED_return();        
        }

        function 
ED_return()
        {
            global 
$cfg,$cls,$driver;
            
$loggedon false;
            
$cls->set('driver'$this->driver);
            
$cls->set('cfg'$cfg);
            
$cls->set('islogged'$loggedontrue);
            echo 
$cls->fetch('master.tpl');
        }
    }
    
    
$cfg = array(
            
'sitename' => 'Site Name',
            
'siteurl' => './',
            
'monthL' => date('F'),
            
'day' => date('j'),
            
'year' => date('Y')
        );
    
    
$cls =& new template();
    
$ednews =& new ED_News;
?>
Icespadez is offline  
Old 05-25-2005, 12:47 PM THREAD STARTER               #3 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

np sent. Thanks for saving me more time!
axilant is offline  
Old 05-25-2005, 01:26 PM   #4 (permalink)
Account Closed
Join Date: May 2005
Posts: 18
dimwit is an unknown quantity at this point
 



wow, good job ice!
dimwit is offline  
Old 05-25-2005, 01:40 PM THREAD STARTER               #5 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

Originally Posted by dimwit
wow, good job ice!
i just needed new eyes to look at it, and the way he came up with the solutution was great!
axilant is offline  
Old 05-25-2005, 01:43 PM   #6 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
classes, ergh
arrays ERGH
mixed /me dies.
adam_uk is offline  
Old 05-25-2005, 03:11 PM   #7 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



what is wrong with classes and arrays?
eagle12 is offline  
Old 05-25-2005, 03:17 PM THREAD STARTER               #8 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

nvm, i got it fixed. Im just going to use a loop in php itself and call the file multiple times to build up my content
Last edited by axilant; 05-26-2005 at 01:07 PM.
axilant is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
A New Culture At Microsoft? Only Time Will Tell Eric Industry News 1 05-04-2005 06:32 PM
DomainSponsor Landing Page Load Time -ugh Dillpup Parking & Traffic Monetization 3 04-20-2005 07:55 PM
Domain and Online Assistance When You Have No Time rak147 For Sale / Advertising Board 2 02-29-2004 08:43 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 04:31 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger