TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Closed Thread
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-01-2008, 12:54 PM   #1 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Help Template Class Issues

Hey,

Okay, so, we have a template class (wrote from scratch) but the issue lies in the if statement parsing, the issue there is that if there's an if statement within an if statement (html if statement as in {if name='blah'}content{/endif} etc..) then the second if statement will get prematurely cut off, i think it's due to the regex on line 143. Any ideas anybody?

Code: [nvm]

Thanks!

Last edited by WinSrev : 11-03-2008 at 06:55 AM.
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-01-2008, 01:24 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

First thing that crosses my mind, is why you mix PHP5 with PHP4?
PHP Code:
//PHP4
var $output;

//PHP5
public function newTemplate($templateFile) {
// ...

__________________
Tanax is offline  
Old 11-01-2008, 01:27 PM   #3 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

Well, var is in PHP5 aswell you know? that's not the issue at all and what you said doesn't make sense.
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-01-2008, 02:13 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.
From PHP: Visibility - Manual

var is just an alias for public, but it would make more sense to use visibility keywords to keep your code consistent, as you have used them elsewhere.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Old 11-01-2008, 02:27 PM   #5 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

Hmm, okay, i admit that's a flaw with the script but, not that severe.
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-01-2008, 03:09 PM   #6 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

I'm not addressing the if statement issue because I feel that the template class needs to be rewritten. it needs a cache system, especially if the site will be large and have lots of forums/topics. Parsing LARGE quantities of data repeatedly would put a strain on the site's loading time.
Enfernikus is offline  
Old 11-01-2008, 03:14 PM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

I didn't say that it was a FLAW with that part. It was just a question, because TO ME it's weird to see them mixed. Sure it WORKS, but it's weird.

And I mean, if you use public function, then why not public $var ?
And about that, in this case you should use private $output which would actually be better.
__________________
Tanax is offline  
Old 11-01-2008, 03:19 PM   #8 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

Okay, Enfernikus: So, whenever you write any system, the first lines of code you write are for a cache system? That's pretty weird.

Tanax: Okay, yes, i agree with what you're saying and i will make sure i go through all the files and make changes as appropriate. Thanks.

Any ideas on the if statement issue though? Thanks
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-01-2008, 03:41 PM   #9 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

I do write my first lines of code with caching in mind, when ever doing any parsing or database related things.
Enfernikus is offline  
Old 11-01-2008, 05:20 PM   #10 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

It's quite hard to cache something that doesn't work properly anyway, so, anychance of going back on topic please? thanks.
Send a message via ICQ to WinSrev
WinSrev is offline  
The Following User Says Thank You to WinSrev For This Useful Post:
codefreek (11-01-2008)
Old 11-02-2008, 01:08 PM   #11 (permalink)
The Wanderer
 
Join Date: Oct 2008
Posts: 9
Thanks: 0
kjarli is on a distinguished road
Default

Why do you want a template class if php is a template engine on it's own?
kjarli is offline  
Old 11-02-2008, 02:17 PM   #12 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

What are you even talking about?
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-02-2008, 04:40 PM   #13 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

Quote:
Originally Posted by kjarli View Post
Why do you want a template class if php is a template engine on it's own?
mate, you are totally of topic ;P
codefreek is offline  
Old 11-02-2008, 09:42 PM   #14 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
mate, you are totally of topic ;P
Not really, whats wrong with something like this:

PHP Code:
<?php
class template
{
    private 
$aVarStack = array();
    private 
$szTplFile;
    
    public function 
__construct($szTplFile)
    {
        
$this->szTplFile $szTplFile;
    }
    public function 
__set($szKey$mValue)
    {
        
$this->aVarStack[$szKey] = $mValue;
    }
    public function 
__get($szKey)
    {
        if(!
array_key_exists($szKey$this->aVarStack))
        {
            throw new 
Exception($szKey 'is an invalid template variable');
        }
        return 
$this->aVarStack[$szKey];
    }
    public function 
display()
    {
        include 
$this->szTplFile '.phtml';
    }
}
Now the tpl file:
PHP Code:
<h1><?php echo $this->header?></h1>
<p><?php echo $this->content?></p>
And now the driver:
PHP Code:
<?php
require('template.php');
try
{
    
$tmp = new template('template');
    
$tmp->header 'this is a header';
    
$tmp->content 'This is some content';
    
$tmp->display();
}
catch(
Exception $e)
{
    echo 
'Error in template: '$e->getMessage(); 
}
Its not perfect but at least you don't need to waste the time parsing tpl files for special tokens and then injecting data into them, after all ZendFramework seems to be ok with it.

For if statements/loops etc just use PHP:

PHP Code:
<html>
...
<?php if($name == 'Sam'):?>
<p>Do something here for Sam?</p>
<?php endif;?>

...
</html>
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
The Following User Says Thank You to sketchMedia For This Useful Post:
codefreek (11-02-2008)
Old 11-03-2008, 06:55 AM   #15 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

Okay, you're an idiot, it's offical, the reason people use template classes it to keep php and html seperate, with open source software someone could download a template with malicious php code in and they wouldn't know any different. All everyone in this topic has done is overlooked the problem, you're finding ways around it instead of finding a solution.

Can a moderator please close this topic? the people on this forum are incredibly stupid.
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-03-2008, 10:34 AM   #16 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I'll agree that the folks posting in this topic haven't directly commented on the original question. Some good points have been raised but they're not really related to what WinSrev's looking for, feel free to discuss those ideas (code consistency, caching, templating appropaches) in other topics but not here.

If anyone does have any comments on parsing the {if} blocks the they're very much welcome.

P.S. WinSrev, please don't get upset if people can't stick to the topic at hand or take wider viewpoints than asked for. That's no reason to label the members of an entire forum as "incredibly stupid", however frustrating it is to have a question repeatedly ignored.
Salathe is offline  
Old 11-03-2008, 10:45 AM   #17 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Ok heres your solution: Smarty : Template Engine

I dont suppose you know of the old phrase: JFGI. I'll let you work that out O' clever one.

Quote:
the reason people use template classes it to keep php and html seperate
And to add yet another language adding confusion, Im a PHP developer not a Smarty developer. It also adds more unnecessary parsing for the PHP engine to do and dont bring caching into the equasion because its easy enough without a templating language.

Quote:
with open source software someone could download a template with malicious php code in and they wouldn't know any different
If that is the real reason for templating languages, go tell WordPress, ZendFramework and many more systems that use more or less this approach of templates

If you had been a little nicer and less actually flaming me like a petty forum troll then I may have had a friendly debate with you on the subject, but currently I'd rather you grow up first.

Ok, I'm done with you, I suggest you learn some manners before posting anything related to this forum, this isn't behavior people have in community and it isn't the attitude that I am willing to tolerate.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 11-03-2008 at 11:24 AM.
sketchMedia is offline  
Old 11-03-2008, 07:23 PM   #18 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

JFGI = Just Fucking Google It.

If you don't find your answers here, just search for it yourself. I mean, if you're so lazy you can't even search for it, then don't get angry and upset when you don't get any response to the problem in here.
__________________
Tanax is offline  
Old 11-04-2008, 11:59 AM   #19 (permalink)
The Acquainted
Inquisitive 
 
WinSrev's Avatar
 
Join Date: Sep 2007
Posts: 133
Thanks: 6
WinSrev is on a distinguished road
Default

Of course, because i had no idea google exist, i'm not sure how to use a search engine, can someone please advise me? thanks. And Smarty isn't the answer, what a fucking stupid thing to say.

(that was sarcasm)

Can a moderator lock this topic please? thanks.
Send a message via ICQ to WinSrev
WinSrev is offline  
Old 11-04-2008, 04:12 PM   #20 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Of course, because i had no idea google exist, i'm not sure how to use a search engine, can someone please advise me? thanks. And Smarty isn't the answer, what a fucking stupid thing to say.

(that was sarcasm)
So smarty is the answer then, and not a 'f**king' stupid thing to say, I'm glad I was able to help.

Would be a good idea to read: TalkPHP - Rules before making any further posts, specifically these rules perhaps:
Quote:
  • No profanities to be used in your posts. Although these will be starred out, it does look rather immature nonetheless.
  • Debates are welcomed, however, do not reduce the debate to a personal level where personal insults are thrown about.
I regard 'Okay, you're an idiot, it's offical' as a personal attack.

Stop being so infantile.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Closed Thread



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

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:42 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design