[2.0] Smarty3

Mark threads with "[2.0]" for discussions about features in the longer-term future, "[1.6]" is for short-term. This is not the place for general discussions or plugin or template requests. Only features that are approved to happen by the core team should be listed here for better structuring.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

[2.0] Smarty3

Post by garvinhicking »

Smarty 3 is currently still having many point releases to Smarty3. Implement once it has stabilized and maturized more.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

IMHO, it looks like it has stabilized already (we could wait for the 3.0.7, which has some bugfixes too, but most of discovered fixed do not bother smarty features used in serendipity)

* Smarty 3.0.6 (.tar.gz) (.zip) December 13th, 2010

Previous Releases

* Smarty 3.0.5 (.tar.gz) (.zip) November 20th, 2010
* Smarty 3.0.4 (.tar.gz) (.zip) November 13th, 2010
* Smarty 3.0.3 (.tar.gz) (.zip) November 13th, 2010
* Smarty 3.0.2 (.tar.gz) (.zip) November 12th, 2010
* Smarty 3.0.1 (.tar.gz) (.zip) November 12th, 2010
* Smarty 3.0.0 (.tar.gz) (.zip) November 11th, 2010

Its all about the question when stable is stable enough? ;-)
Or do you mean we have to wait for 3.1 at least?

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Hi!

Well, as long as they have a release every 2 or 3 weeks, I'd like to wait a tad more before fiddling with it. It's definitely something we should evaluate for 2.0 though. Have you maybe tried if Smarty3 works, when simply being replaced with our currenty smarty2 directory?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

Shall I give it a try? :P
Is there anything to think of (embedding, configs, wrappers, etc.) before I do so?

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Timbalu wrote:Shall I give it a try? :P
Is there anything to think of (embedding, configs, wrappers, etc.) before I do so?

Ian
Hi!

Well, shouldn't be - we bundle current smarty without any custom modifications...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

intermediate results with s9y 1.5.4 and bulletproof:

Code: Select all

all $serendipity['smarty']->assign_by_ref() calls have to get changed to $serendipity['smarty']->assignByRef()

all $serendipity['smarty']->register_function(..., ...) calls have to get changed to $serendipity['smarty']->registerPlugin('function', ..., ...)

all $serendipity['smarty']->register_modifier(..., ...) calls have to get changed to $serendipity['smarty']->registerPlugin('modifier', ..., ...)

$serendipity['smarty']->register_prefilter(...) has to get changed to $serendipity['smarty']->registerFilter('pre', ...)
Some plugins, like staticpage, need these changes too. But I'd love to to see this one in core anyway. :wink:


There were 2 serendipity functions assign_by_ref() in template_api.inc.php I couldn't find out who is using them, so I renamed them too. But can we have 2 functions with the same name?


I also had some problems using the

Code: Select all

function &serendipity_smarty_fetch($block, $file, $echo = false) {
    global $serendipity;

    $output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null, ($echo === true && $serendipity['smarty_raw_mode']));
    $serendipity['smarty']->assignByRef($block, $output);

    return $output;
}
in functions_smarty.inc.php, which only works by this

Code: Select all

function &serendipity_smarty_fetch($block, $file, $echo = false) {
    global $serendipity;

    $output =& $serendipity['smarty']->fetch('file:'. serendipity_getTemplateFile($file, 'serendipityPath'), null, null);
    $serendipity['smarty']->assignByRef($block, $output);

    return $output;
}
I wonder why the 4th parameter is working with smarty2, since the fetch method hasn't changed
[Smarty2] http://www.smarty.net/docsv2/en/api.fetch.tpl
[Smarty3] http://www.smarty.net/docs/en/api.fetch.tpl
Why is it there and what is it supposed to do?

Smarty3 is more strict, which is good, so we will find bugs somewhere.
I'm not sure if we do need future changes in the templates (like including child tpl files a.s.o), using the benefits of smarty 3 in core more than today.

Please remember this is an intermediate result only...

Regards,
Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Hi!

Aw man, that sucks. We'd then need our own smarty class that rewrites those rules like that:

Code: Select all

class serendipity_smarty extends smarty {
function assign_by_ref() { $this->assignByRef(...) }
...
}
and then instead of $serendipty['smarty'] being a smarty object, it would be a serendipity_smarty object.

Rewriting all plugins and the core is a route we can't really go. I wish, Smarty wouldn't have gone that way, it's a unneccesary BC break. :(

Regards,Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: [2.0] Smarty3

Post by yellowled »

garvinhicking wrote:Aw man, that sucks.
Is it an option to switch to Dwoo since we're likely to move to PHP5 anyway?

YL
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

garvinhicking wrote:Rewriting all plugins and the core is a route we can't really go. I wish, Smarty wouldn't have gone that way, it's a unneccesary BC break.
No, we should not need to, sorry for this mess. These old register methods have their own wrapper and just throw notices. Thats why I changed them to the new writing. I don't think there are much plugins around using these methods (I found staticpage (and bulletproofs config) only). The README says clearly:
However, Smarty 3 works completely different on the inside. Smarty 3 is mostly
backward compatible with Smarty 2, except for the following items:

*) Smarty 3 is PHP 5 only. It will not work with PHP 4.
*) The {php} tag is disabled by default. Enable with $smarty->allow_php_tag=true.
*) Delimiters surrounded by whitespace are no longer treated as Smarty tags.
Therefore, { foo } will not compile as a tag, you must use {foo}. This change
Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
This can be disabled by setting $smarty->auto_literal = false;
*) The Smarty 3 API is a bit different. Many Smarty 2 API calls are deprecated
but still work. You will want to update your calls to Smarty 3 for maximum
efficiency.
PHP5 means we need 5.2+. I use the old methods now and despite of being more strict in some places my test scenario is working.

Does every $serendipity['smarty']->assign_by_ref('foo', $foo); call use the template_api.inc.php functions or the smarty ones? What about my question having 2 functions with the same name?
Edit: I see, template_api file is experimental, and not used by default, right?! Now I now why default-php and default-xml exist....

What about the 4th parameter thing?

Edit2:
The only thing not working (found by now), except of the 4th param thing, is in entries_summary.tpl by these two foreach statements

Code: Select all

        {foreach from=$entries item="entries"}
            {foreach from=$entries.entries item="entry"}
which do not show up, since S3 is more strict. Perhaps YL can make them compatible to both.
Edit3: It looks like they have changed Smarty2 weired behaviour of the starting tier with associative arrays... (still investigating)
Edit4: It seems, we are not allowed to use the same name in constructions like from=$entries item="entries" and the new tier needs an extra loop like

Code: Select all

        {foreach from=$entries item="xentries"}
            {foreach from=$xentries item="xentry"}
                {foreach from=$xentry item="entry"}
                    {if is_array($entry)}
which could be done better, I know.
But even the extra {if is_array()} is needed to avoid the showup of current and unix_1970_start days.
I am not sure about how to make this compatible to the Smarty2 behaviour, but at least we can avoid the same name problem now, thinking forward.

@YL
Dwoo wanted to be earlyier what smarty3 is now, and I think compatibility to S2 is better in Smarty3.

Ian

Sorry for this answer looking like a work and think by progress thread...!
Edit5: some more incompatibilities
default/admin/media_pane.tpl line 123 (closing) smarty tag delimiters are not allowed to have whitespaces.

Edit6: not related to smarty3 - wondering why these did not error
default/admin/media_choose.tpl line 107 closing delimiter need to be {rdelim}
default/admin/media_upload.tpl line 29 closing delimiter need to be {rdelim}
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Hi!

Thanks for digging through this! Youre findings about template_api are correct, it's actually only a wrapper for people who do NOT want to use smarty. Kind of like our own PHP-Template-API ;)

About the suggestion in tpl changes, I'll try to look into this, might take me until end of next week though. If you want to prepare a patch or so, I'd of course like to shift through your findings!

Thanks alot for your work,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

Hi Garvin

What do you mean with "prepare a patch or so"? I never found something modern & useful on MS systems to prepare patches without having to dig deeply into. But maybe the
or so
is something for me! ;-) Posting the lines to change is easy.

Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Hi!

You could do patches easily with TortoiseSVN or any other SVN client? But if that's a hassle for you, simply ZIP up the modified files and I can create a patch :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

Sorry, I have been on the totally wrong way. Thanks to Garvin the entries_summary.tpl was easy to patch.

Code: Select all

{foreach from=$entries item="sentries"}
            {foreach from=$sentries.entries item="entry"}
With this, there is no need for is_array or an extra loop. Hooray! :D

btw $entries|print_r will show what I mean with the weired behaviour in S2 vs S3. But maybe this is just related to the print_r output.

In S2 it looks like

Code: Select all

Array
(
    [date] => 1292256366
    [is_sticky] => 
    [entries] => Array
        (
            [0] => Array
                (
                    [id] => 1
and with S3

Code: Select all

Array
(
    [20100908] => Array
        (
            [date] => 1283952751
            [is_sticky] => 
            [entries] => Array
                (
                    [0] => Array
                        (
                            [id] => 64
Regards,
Ian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: [2.0] Smarty3

Post by Timbalu »

I discovered smarty3 changeing the template fetch file method, adding an additional parameter which breaks old serendipity behaviour.

We came out to prevent this by switching Smarty version information as long as not delivering smarty3 in release versions

Code: Select all

        if(strpos($serendipity['smarty']->_version, '2', 1))
            // compat Smarty2 only
        else
            // compat Smarty3 only
which is one of four methods to diff between these two versions.

In Serendipity 1.6 alpha version this is fixed in core, to have some more people testing (*) smarty3, but as I see now, some additional Plugins using templates need this switch too. While we cannot do this in Spartacus, please replace where $serendipity['smarty']->fetch('file: is called each on your own:

Code: Select all

if(strpos($serendipity['smarty']->_version, '2', 1))
    $content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, false);
else
    $content = $serendipity['smarty']->fetch('file:'. $tfile, null, null, null, false);
if you see a plugin not working any more.

(*) testing smarty 3 howto:
  • - download serendipity nightly
    - download new smarty >= 3.0.6
    - rename old /bundled-libs/smarty/libs to oldlibs and copy new libs dir into smarty dir
Please report any bugs or misbehaviour here.

Regards,
Ian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: [2.0] Smarty3

Post by garvinhicking »

Hi!

Oh. When plugins need this, I believe we must go the route of using our own serendipity_smarty extends smarty class and instanciate this; then our custom fetch() method can reorder parameters and call parent::fetch() (or whatever the notation is, don't remember)...?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Locked