Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - troubadix

Pages: [1]
1
Discussion & Troubleshooting / Re: smarty + 4images - proof-of-concept
« on: August 22, 2009, 02:59:19 AM »
... otherwise I can't see a significant advantage for a "php-smarty-html version" in relation to the existing "php-html version" ...

???????
... and where's the ultimate reason against smarty?

i only can see lots of benefits:
  • first of all: no loose of performance!!!
  • keep the code clean - really no html in the php-scripts
  • reducing amount of templates: why use two templates (xyz_bit + xyz) when you can do it (very clean) with only one
  • lots of very usable modifiers and functions - and if the desired one ist not available: write a few lines of code and make a new one
  • extend 4images with smarty-functions - instead of 'hacking' into code

All my active websites are actually made with zikula (formerly postnuke).
They use their own smarty-implementation (pnRender) to render templates to html-output.
And i only can say: i love it - it's sooooooo easy to realize my design-ideas with only editing some templates - without any hack into code!


2
Discussion & Troubleshooting / Re: smarty + 4images - proof-of-concept
« on: August 20, 2009, 02:52:32 PM »
Can you provide benchmarks? how much smarty will affect on performance?
I'm still skeptical about smarty and not only because of it's performance but mainly because it's so complex that you'll need learn how to use it and what you learned can only be used in smarty environment.
Giving that and the fact that you can use PHP in 4images template engine, it would be much more practical learning a little PHP itself and use it in the templates...

1.) Performance
OK, here are my stats, generated on my virtual-machine (Windows XP SP3, 1GB-Ram, XAMPP 1.6.3a)
Database contains 15.895 images with 167.471 comments but image-files are not present (test-environment with no media).

With smarty-rendering as figured in post #1 (modified template 'default_full', no smarty-caching):
#1: Page generated in 0.283400 seconds with 2 queries, spending 0.071000 seconds doing MySQL queries and 0.212400 doing PHP things. GZIP compression enable
#2: Page generated in 0.282538 seconds with 2 queries, spending 0.096000 seconds doing MySQL queries and 0.186538 doing PHP things. GZIP compression enabled
#3: Page generated in 0.310904 seconds with 2 queries, spending 0.128000 seconds doing MySQL queries and 0.182904 doing PHP things. GZIP compression enabled
#4: Page generated in 0.289150 seconds with 2 queries, spending 0.101000 seconds doing MySQL queries and 0.188150 doing PHP things. GZIP compression enabled
#5: Page generated in 0.271819 seconds with 2 queries, spending 0.094000 seconds doing MySQL queries and 0.177819 doing PHP things. GZIP compression enabled

Default-rendering with template 'default_full':
#1: Page generated in 0.302153 seconds with 2 queries, spending 0.108000 seconds doing MySQL queries and 0.194153 doing PHP things. GZIP compression enabled
#2: Page generated in 0.315841 seconds with 2 queries, spending 0.124000 seconds doing MySQL queries and 0.191841 doing PHP things. GZIP compression enabled
#3: Page generated in 0.321900 seconds with 2 queries, spending 0.106000 seconds doing MySQL queries and 0.215900 doing PHP things. GZIP compression enabled
#4: Page generated in 0.345551 seconds with 2 queries, spending 0.156000 seconds doing MySQL queries and 0.189551 doing PHP things. GZIP compression enabled
#5: Page generated in 0.255914 seconds with 2 queries, spending 0.089000 seconds doing MySQL queries and 0.166914 doing PHP things. GZIP compression enabled

As you can see, there is no significant difference between rendering with smarty or with default 4images-templating.

2.) Complexity
What's so complicated using smarty-syntax?
  • just replace "{variable}" with "{$variable}" to get the content of a variable
  • just replace "{if variable}...{endif variable}" with "{if $variable} ... {/if}" to test conditions
... and you're done - you are not forced to learn more smarty.

But even: you can - if you like (and ist's really not complicated, because smarty-syntax is very near at php-syntax):
  • you can use "{else}"
  • you can use modifiers to format a variables content
  • you can use loops in your template
etc, etc, etc, ...

3.) Conclusion (just my humble opinion)
  • with smarty, you can completely separate code from presentation. The script-developers don't have to handle with html and design-questions.
  • the 4images developers do not have to spent time for templating - others will do (and provide updates etc.).
  • i think, a lot of 'hacks' and 'mods' for 4images can be made via smarty-plugins
    Example: if you need a value from the users-table thats not yet registered, you have to deal with the script itself to get your desired value.
    With smarty, you can write a little plugin that will get your desired value by quering the database itself.
    This will also make updating 4images very easy, because the 4images-php-files can stay original and no user has to alter the original files to get some extra functions


think about it ... test it ...
...
and as i said in the wishlist-thread: It's not for the next update - but maybe (as an alternative) provided wiith 1.8 or 2.0


German
P.S.: Sollte jemand Probleme haben, den englischen Text zu verstehen, der melde sich bitte - ich werde dann nochmal übersetzen.

3
Discussion & Troubleshooting / smarty + 4images - proof-of-concept
« on: August 19, 2009, 04:59:24 PM »
OK, damit der Wunschthread nicht zugepflastert wird, hier mal an zentraler Stelle ein "proof-of-concept" zum Thema 4images mit smarty.

Die folgenden Schritte wurden mit 4images 1.7.7 durchgeführt, funktionieren aber prinzipiell auch mit anderen Versionen.

1.) Smarty installieren
Die jeweils aktuelle Version gibts hier: http://smarty.net
Einfach Zip-Archiv herunterladen und aus dem Archiv den Ordner "libs" nach "/4images/includes" entpacken.
Nun noch fix umbenennen von "libs" nach "smarty" -> Fertig!
Smarty befindet sich nun in "/4images/includes/smarty".

2.) Schalter einbauen
Damit wir (mehr oder weniger komfortabel) einstellen können, ob Smarty verwendet werden soll oder nicht, fügen wir in unser Template-Verzeichnis eine Datei "settings.php" ein, die genau eine Zeile enthält:
Code: [Select]
$smarty_active = true;
Nun ändern wir noch die "global.php".
Die Zeilen
Code: [Select]
include_once(ROOT_PATH.'includes/template.php');
$site_template = new Template(TEMPLATE_PATH);
ändern wir wie folgt:
Code: [Select]
if (file_exists(TEMPLATE_PATH.'/settings.php')) {
  include_once(TEMPLATE_PATH.'/settings.php');
} else {
  $smarty_active = false;
}
if ($smarty_active) {
  include_once(ROOT_PATH.'includes/smarty.class.php');
} else {
  include_once(ROOT_PATH.'includes/template.php');
}
$site_template = new Template(TEMPLATE_PATH);

3.) Smarty-Klasse
Die im Folgenden dargestellte Template-Klasse 'includes/smarty.class.php' stellt nur eine wirklich rudimetäre Implementierung dar und ist keineswegs komplett.
Sie sollte also auf keinen Fall in Produktivumgebungen eingesetzt werden.
 
Code: [Select]
<?php
if (!defined('ROOT_PATH')) {
  die(
"Security violation");
}

require_once 
'includes/smarty/Smarty.class.php';

class 
Template extends Smarty {

  var 
$template_extension 'html';
  var 
$start '{';
  var 
$end '}';
  
  function 
__construct($template_path "") {
    if (!@
is_dir($template_path)) {
      
$this->error("Couldn't open Template-Pack ".$template_path1);
    }
    
parent::__construct();
    
$this->template_dir $template_path;
    
$this->compile_dir  ROOT_PATH.'temp/compiled';
  }

  function 
register_vars($var_name$value "") {
    if (
is_array($var_name)) {
      foreach (
$var_name as $key=>$val) {
        
$this->assign($key$val);
      }
    } else {
      
$this->assign($var_name$value);
    }
  }

  function 
un_register_vars($var_list) {
    
$vars explode(","$var_list);
    foreach (
$vars as $val) {
      
$this->clear_assign($val);
    }
  }

  function 
parse_template($template) {
    
$template $template.'.'.$this->template_extension;
    return 
$this->fetch($template);
  }

  function 
parse_array($array) {
    return 
$array;
  }

  function 
print_template($template) {
    
$this->assign('body'$template);
    
$this->display('smarty.html');
  }
  
}

?>


4.) Templates anpassen
Das Anpassen der Template-Dateien ist die eigentliche Arbeit, auch wenn vieles mit Suchen+Ersetzen (z.B. mit PSPad) zu schaffen ist.
- aus "{if variable}" wird "{if $variable}"
- aus "{endif variable}" wird "{/if}"
- aus "{header}" wird {include file='header.html'}
- aus "{footer}" wird {include file='footer.html'}
- JavaScript-Bereiche werden in "{literal} ... {/literal}" eingeschlossen

5.) Status
Was haben wir bis jetzt gewonnen?
Noch nicht soooo viel - insbesondere für "parse_array()" und die parametrisierten Sprachkonstanten habe ich auf die Schnelle noch keine zufriedenstellende Lösung gefunden.

Ein paar schöne Dinge sind aber bereits möglich:
- Statt "{if variable}{endif variable}" können wir "{if $variable}{else}{/if}" einsetzen.
- Statt nur "if" können wir auch "{if $userlevel == 9}" verwenden
- Wir können mit "{include file='template.html'}" ganz einfach Dateien in ein Template einbinden.
- Die Smarty-Modifier funktionieren :-D
  "{$datumsvariable|date_format:'%d.%m.%Y'}"
  "{$smarty.now|date_format:'%d.%m.%Y %H:%M:%S'}" -> aktuelle Uhrzeit
  "{$textvariable|capitalize}"
  Das können auch PHP-Funktionen sein: "{$number|pow:2}"
- Durch einfügen von "{debug}" in ein Template erhalten wir ein Popup-Fenster mit allen Variablen.

Um die Fähigkeiten von Smarty jetzt wirklich ausschöpfen zu können, müssten allerdings tiefere Eingriffe in den Quelltext von 4images vorgenommen werden.
Statt z.B. jeden Kommentar einzeln mit einem Template ("comment_bit.html") zu verarbeiten, könnte man die komplette Liste der Kommentare als Array (oder Objekt) an Smarty übergeben und dann im Haupt-Template mit den Schleifen ("foreach" oder "section") arbeiten.
Sollte hierzu Informationsbedarf bestehen, können wir das gerne vertiefen.

6.) Links
Projektseite: http://smarty.net
Cheat-Sheet: http://www.phpxperts.net/SmartyCheatSheetVersion2.pdf


*** EDIT ***
Was hier natürlich noch fehlte, war die neue Template-Datei "smarty.html":
Code: [Select]
{$body}

 :lol:

4
Schreib doch mal ein HOW-TO wie man das installiert.

Kann ich gerne mal machen.
Wird aber dann sicher nur eine Art "proof-of-concept" und keine fertig installierbare Lösung.

Smarty zu installieren und die Template-Klasse darauf abzustimmen ist auch sicher nicht DIE Arbeit.
Die eigentliche Arbeit dürfte darin bestehen, die Templates nicht nur per Grep-Search grob umzustellen, sondern auf smarty zu optimieren.
Hat man diese Fleissaufgabe aber mal bei einem Template gemacht, dürfte man mit tollen Features und super übersichtlichen Template-Dateien belohnt werden.

Ich finde keiner sollte gezwungen werden sich damit auseinander zu setzen.

Vielleicht sogar in der Konfiguration einstellbar - Die Template-Klasse kann dann je nach gusto entweder selbst rendern oder diese Aufgabe an smarty weiterreichen.

Ich pers. finde Smarty schwer. Wenn sowas wirklich mal geplant sei, dann bitte beide Varianten.

Hmmm, war das Beispiel zu kompliziert? Ich dachte eigentlich, es wäre fast selbsterklärend :wink:
Es gibt einfach eine Liste von n-Kommentaren untereinander aus und bindet Header-, Navigations- und Footer-Template ein.
Einzige Voraussetzung im PHP-Script: Man übergibt smarty ein array mit den anzuzeigenden Kommentaren.

Ein einfaches {$username} im Template ist quasi das Pendant zu {username}
Und if-Statements werden in smarty mit {if $is_admin} ... html ... {else} ... {/if} notiert.
Damit alleine kommt man für's Erste durchaus zurecht - es muss ja nicht gleich ein komplexes Konstrukt ala troubadix sein :roll:

Ich schreib mal was dazu zusammen - dann wird's sicher klarer.
Dann aber in 'nem eigenen Thread - dieser hier ist dazu ja schließlich nicht gedacht.

Kann aber ein paar Tage dauern ...

5
Entgegen genommen und aufgelistet!
Sorry das es gedauert hat!
Kein Problem - besser spät als nie :wink:

Ich hab's übrigens mal auf die Schnelle ausprobiert:
- smarty installiert -> 5 Minuten
- Template-Klasse soweit aufgeräumt, dass alle Aufrufe einfach nur an smarty weitergereicht werden -> ca. 20 Minuten
- Templates (hauptsächlich per Grep-Search (PSPad)) geändert -> 20 Minuten
und siehe da: es funzt :lol:
Einen eklatanten Performanceverlust konnte ich selbst in meiner ziemlich lahmen VM (völlig unoptimiert, ohne smarty-caching etc.) nicht feststellen.

Dafür würde aber jetzt sowas hier funktionieren:

Code: [Select]
{include file='page_header.html'}
{include file='navigation.html'}
{foreach from=$comments item='comment'}
<div>
  <p>Kommentar von: <strong>{$comment.author}<strong></p>
  <p>{$comment.text}</p> 
</div>
{/foreach}
{include file='page_footer.html'}

Was dieses Konstrukt prinzipiell machen würde, darf jetzt jeder mal raten 8)

Gruß
Bernd

6
1.) Smarty
Ich greife nochmal meinen Wunsch nach Smarty auf: http://www.4homepages.de/forum/index.php?topic=23465.0
Die Argumente "waste of time" und "performance" möchte ich so nicht einfach im Raum stehen lassen.
Die rudimentäre Syntax sollte jeder, der nur halbwegs Ahnung von HTML/PHP hat, in kürzester Zeit verinnerlichen können.
Und das Thema Performance ist IMHO vernachlässigbar, da Smarty nur das HTML rendert.
Ob das nun in 20 oder 40 Millisekunden geschieht, ist doch wohl vollkommen unerheblich - der Flaschenhals besteht doch wohl bei jeder 4Images-Website im Laden der Grafiken und das hat mit Smarty oder nicht nun garnichts zu tun.
Vor allem dann nicht, wenn man noch das Smarty-Caching verwendet.
Die Vorteile, die man durch die komplette Trennung von Programmcode und Darstellung erreicht, dürften den Aufwand auf jeden Fall rechtfertigen.
Ausserdem könnten einige Sub-Templates entfallen und andere wesentlich aufgeräumter gestaltet werden, da Smarty Schleifen und Bedingungen unterstützt.
Vieles, was z.Zt. per MOD eingebaut wird, könnte mit Smarty-Plugins erschlagen werden - ohne in die PHP-Scripte eingreifen zu müssen.

Zu guter Letzt würden letztendlich auch die Entwickler von 4Images davon profitieren, da sie sich um das ganze Templating keine großen Gedanken mehr machen müssten.
Ich bin im Übrigen selbst beruflich Softwareentwickler (Delphi, C#, VBA, PHP) - denke also zu wissen, wovon ich spreche ;-)

Ist natürlich nicht für's nächste Update, sondern eher was für 1.8 oder sogar 2.0.
Mich würde interessieren, was andere erfahrene 4Images-Anwender dazu sagen.

2.) Modularisierung
Wäre schön, wenn man einzelne Module so installieren/(de-)aktivieren könnte, wie das z.B in PostNuke/Zikula, Joomla oder anderen Systemen gemacht wird.
Das beliebte "reinhacken" von Modifikationen wird spätestens beim nächsten Update für jeden zur Tortur, der über kein vernünftiges Merging-Tool verfügt

3.) Web 2.0 / Ajax
An einigen Stellen könnte ich mir gut vorstellen, nicht immer komplette Seiten sondern nur Teile davon per AJAX nachzuladen.
- Kommentarvorschau
- EXIF's ein- und ausblendbar
- Paging der Kommentare zu einem Bild, ohne die ganze Detailseite neu zu laden
etc., etc.

4.) Objektorientierung
Der Quellcode könnte durchaus eine Modernisierung in Richtung Objektorientierung/Klassen vertragen ;-)
Ältere Versionen als PHP 4.0 dürfte wohl keine mehr einsetzen.


Und bitte nicht missverstehen
Das sind lediglich meine Anregungen und Wünsch für kommende Versionen und keine Kritik - 4Images ist immer noch meine Wahl, wenn es um eine Software für Foto-Communities geht.

---
Gruß
Bernd

7
Feedback & Suggestions / Re: integrate smarty templating engine
« on: December 03, 2008, 04:37:43 PM »
... so why waste time learning it when you could benefit more by learning PHP syntax itself and use PHP code instead?
Because i can strictly divide code from presentation.

Nobody forces you to learn the complete syntax of smarty, but you can ... if you like  :mrgreen:

8
Feedback & Suggestions / integrate smarty templating engine
« on: December 02, 2008, 08:46:03 AM »
Why not using the smarty templating engine in the next main-release of 4Images?

That's real templating - no html is needed in the php-sourcecode - never!!!

Have a look - it's very simple to integrate, it's stable and you will no longer have to maintain a templating engine by yourself.
http://smarty.net

Maybe some of the available 4Images-mods could be realized with smarty-plugins, so hacking the 4Images-code will not be needed any longer.

Think about it

---
best regards
Bernd

Pages: [1]