Current time: 11-01-2024, 09:36 AM Hello There, Guest! (LoginRegister)


Post Reply 
Convert pTemplates into Smarty Templates
Author Message
zpin Offline
Junior Member
*****
Dev Team

Posts: 160
Joined: Sep 2007
Reputation: 1
Post: #1
Convert pTemplates into Smarty Templates
Hello there
I'm currently rewriting the GUI code to use the Smarty template engine. This will drastically reduce the number and complexity of templates and will make it easier to customize the GUI.
Changing everything will be quite an endeavor so I'd like to know if anyone else is currently working on this to avoid duplicating work and maybe working together on it.
Also, is there interest on the side of the ispCP devs to integrate this into future versions? I'd need to know this because I'm making these changes on top of a set of patches that customize ispCP for my purposes so if you would be interested I'd have to make the changes apply to the base ispCP code.
(This post was last modified: 09-28-2010 01:08 AM by RatS.)
09-22-2010 11:39 PM
Find all posts by this user Quote this message in a reply
Obi_Wan Offline
Junior Member
*****
Dev Team

Posts: 64
Joined: Sep 2007
Reputation: 0
Post: #2
RE: Templates
I started this project once about a year ago but didn't go very far so at my side it is paused. The problem will be that you will have to change many many many templates and if you want to stay with the current trunk you will experience many conflicts with the devs.

Currently I think there are discussions on if any framework should be used in future as I saw there was a branche for ZendFramework. If the ZendFramework is used it is questionable if Smarty should be used in future or something else. So I think the framework question has to be answered prior to the template issue.
09-23-2010 07:37 PM
Find all posts by this user Quote this message in a reply
Zothos Offline
Release Manager
*****
Dev Team

Posts: 1,262
Joined: Feb 2007
Reputation: 10
Post: #3
RE: Templates
We already thought about adding smarty to ispCP. Unfortunatelly we only had some templates rewritten and didnt found the time to continue with this till now. So if will provide a patch i will be happy to test and integrate it if possible Smile


Best regards,
Jochen
09-23-2010 08:52 PM
Find all posts by this user Quote this message in a reply
zpin Offline
Junior Member
*****
Dev Team

Posts: 160
Joined: Sep 2007
Reputation: 1
Post: #4
RE: Templates
About 140 templates to change Smile Fortunately a lot of the changes can be automated, see below.
I'd be glad for any change to the current template/GUI code and I think the switch to smarty is the very simple and already gives a lot of benefit. Plus once everything is converted any additional change gets easier since we have less and smaller templates.
Going with another framework would be more like a complete rewrite.

Since I'd like to have this cleaned up I'll go ahead with the change until there is official word of a framework switch or similar. I'll try to sketch my current plan for you so you can imagine how long it will take and what will change:

- A global smarty object is created in the Initializer.php and put in the registry.

- Upon constuction of the smarty object a few default values like encoding and user logo are passed so this repetition can be eliminated from the .php files.

- The smarty template dir is set to "gui/themes/<theme>/" and "gui/themes/<theme>/<current user level>/". So calling $tpl->display( 'layout' ); in a client .php file and calling $tpl->display( 'client/layout.tpl' ); from a admin.php file will both use the same template: "gui/themes/<theme>/client/layout.tpl"

- For each user level (client, reseller, admin) there are three global base templates: layout.tpl, side_menu.tpl, top_menu.tpl. By default the reseller and admin versions just include the client version since everything uses the same layout in the default theme.

- For every page there is a content template. The "layout.tpl" contains the base page layout and {include}s both of the menu templates as well as the content template.

- The menus are now dynamic. Instead of "hardcoding" the menu items fully in the .tpl we'll have a single menu item in the generic menu templates and only need to fill in a few variables in the .php file to generate the whole menu (this also puts those TR_* in the right place).


This already gets rid of all the menu_ and mainmenu_ templates and it shortens all of the page templates by the header and footer as well as the menu include code.

Fortunately the existing templates can be reused with very few changes. A simple "s/{([A-Z])/{$\1/" already fixes most of the issues. Then the whole "define_dynamic" stuff can be removed and for the loops we can use "append" instead of "assign" and then loop over it using "{section}". Conditional parts just use {if} now.

This whole conversion process can actually be done gradually, i.e. having both the old and the new template system in use at the same time. There would be a lot of temporary code duplication for all the gen_* functions for which smarty versions would have to be implemented (mostly copies of the original function with minor modifications like getting rid of the "parse" and "define_dynamic" function calls and fixing the loops accordingly). As soon as every page is converted the old functions could be removed.

Now in case you are interested in this change:
I can provide you with a full patch as soon as I'm done, I would only request that there be as few changes as possible to the .php pages (meaning no major refactoring or re-styling) during my efforts in order to make the integration as painless as possible. I would provide status updates so nothing would be on hold with no end in sight.
As stated above this can also be done gradually, so with SVN access I could integrate this in smaller junks.

I can also provide a WIP patch if requested.
09-23-2010 09:01 PM
Find all posts by this user Quote this message in a reply
Obi_Wan Offline
Junior Member
*****
Dev Team

Posts: 64
Joined: Sep 2007
Reputation: 0
Post: #5
RE: Templates
That is about the concept I had for smarty templates Smile
09-23-2010 10:08 PM
Find all posts by this user Quote this message in a reply
Nuxwin
Unregistered

 
Post: #6
RE: Templates
(09-23-2010 07:37 PM)Obi_Wan Wrote:  I started this project once about a year ago but didn't go very far so at my side it is paused. The problem will be that you will have to change many many many templates and if you want to stay with the current trunk you will experience many conflicts with the devs.

Currently I think there are discussions on if any framework should be used in future as I saw there was a branche for ZendFramework. If the ZendFramework is used it is questionable if Smarty should be used in future or something else. So I think the framework question has to be answered prior to the template issue.

Hello ;

I can't really announce this thing officially but normally, for the future ispCP version (ispCP v2) we will use symphony. ispCP v2 will be coded from scratch (with framework). About Smarty, I can 't talk about it since I hate it (language in language...). The internal meetings about ispCP v2 will start the next month.
09-24-2010 10:20 PM
Quote this message in a reply
Obi_Wan Offline
Junior Member
*****
Dev Team

Posts: 64
Joined: Sep 2007
Reputation: 0
Post: #7
RE: Templates
Hm... Symphony is not my favorite framework however it is better than none Smile

As I have more and more time currently I'm trying to write a few patches hoping to help you with it. Will there be some tasks where community members can contribute for ispcp v2? Because I would like to contribute more of my PHP experience.
09-24-2010 10:26 PM
Find all posts by this user Quote this message in a reply
zpin Offline
Junior Member
*****
Dev Team

Posts: 160
Joined: Sep 2007
Reputation: 1
Post: #8
RE: Templates
Using smarty here is really just because it's very easy to convert the existing templates/code and already gives quite a big improvement over the current implementation. As stated above a lot of the conversion can be automated. I even generated the PHP code for the new menu from the old menu templates.

Another framework you might consider for ispCPv2:
http://www.yiiframework.com/

Seems to be considerably faster than Symfony as well.


@Obi_Wan: Do you mean helping with the smarty conversion or helping the ispCP team on v2?

I'll post a preliminary patch soon so everyone who'd like to help can say so here then we could divide the remaining templates. I'm only working on this during some spare time but I'm making good progress. All the main menu points are already converted.
09-25-2010 12:08 AM
Find all posts by this user Quote this message in a reply
Obi_Wan Offline
Junior Member
*****
Dev Team

Posts: 64
Joined: Sep 2007
Reputation: 0
Post: #9
RE: Templates
Quote:@Obi_Wan: Do you mean helping with the smarty conversion or helping the ispCP team on v2?

Depends where help is needed. Currently I'm working on another patch for ispCP 1.0.8.

I'm just having a look at the Yii Framework and I think I'll try that one out for some own projects. Sounds very interesting Smile
(This post was last modified: 09-25-2010 06:45 PM by Obi_Wan.)
09-25-2010 06:44 PM
Find all posts by this user Quote this message in a reply
zpin Offline
Junior Member
*****
Dev Team

Posts: 160
Joined: Sep 2007
Reputation: 1
Post: #10
RE: Templates
Ok, so here's what I've done so far:

- Implemented menus in include/client-functions.php, include/reseller-functions.php, include/admin-functions.php, include/commom-functions.php (new file).
- Wrote scripts to convert .php and .tpl files
- Converted all files

A few things couldn't be converted automatically, so basically the manual part of the conversion is to check every page for errors and fix them.

In the .php files this involves:
- Removing "$tpl->parse" lines (intentionally not removed by the conversion script to throw an error, because the parse function mostly means that there is a loop involved)
- Changing "$tpl->assign" to "$tpl->append" in loops
- Some "if (X) $tpl->assign('VAR', '');" that are used to control the display of a section need to be changed to either "if (!X) $tpl->assign('VAR', true);" or "if (X) $tpl->assign('VAR', 'no');" depending on how you want to handle the variable in the template. In the first case you use "{if $VAR}", in the second case "{if $VAR != 'no'}" in the template.

In the .tpl files:
- Copy over inline javascript from the old template where it's missing
- Fix loops ("<!-- BDP: * -->...<!-- EDP: * -->" to "{section *}...{/section}" and the vars inside from "{$VAR}" to "{$VAR[i]}")
- Fix conditionals ("<!-- BDP: * -->...<!-- EDP: * -->" to "{if *}...{/if}") where needed

Fixing up these things is mostly a very quick process. There are some templates which take a bit longer due to lots of loops/conditionals or variable name collisions.

Attached you will find a first draft of the patch, it should apply fine to the current trunk (r3342). If you only get a white page make sure the directory "gui/themes/omega_original/compiled" exists and is writable by the master fcgi user.
Half of the reseller section and the whole client section are still unchecked, but most of the menu points seem to work more or less already. The files I have already checked briefly:
Quote:admin/password_change.php
admin/personal_change.php
admin/language.php
admin/server_status.php
admin/admin_log.php
admin/admin_add.php
admin/reseller_add.php
admin/manage_reseller_owners.php
admin/manage_reseller_users.php
admin/circular.php
admin/settings_maintenance_mode.php
admin/ispcp_updates.php
admin/database_update.php
admin/ispcp_debugger.php
admin/rootkit_log.php
admin/reseller_statistics.php
admin/reseller_user_statistics.php
admin/ticket_closed.php
admin/multilanguage.php
admin/settings_layout.php
admin/custom_menus.php
admin/ip_manage.php
admin/settings_server_traffic.php
admin/settings_welcome_mail.php
admin/settings_lostpassword.php
admin/settings_ports.php
admin/reseller_edit.php
admin/user_delete.php
admin/domain_details.php
admin/server_statistic_day.php
admin/domain_statistics.php

reseller/language.php
reseller/settings_layout.php
reseller/domain_edit.php
reseller/user_edit.php
reseller/domain_statistics.php
reseller/domain_delete.php
reseller/user_add1.php
reseller/user_add2.php
reseller/user_add3.php
reseller/user_add4.php
reseller/alias.php
reseller/alias_add.php
reseller/alias_edit.php
reseller/settings_welcome_mail.php
reseller/settings_lostpassword.php

If anyone wants to help: Please just start in the client section from the last menu point and announce it here so we don't do duplicate work.


Attached File(s)
.gz  smarty_patch.tar.gz (Size: 254.16 KB / Downloads: 14)
09-27-2010 10:55 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 3 Guest(s)