add template compiler
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 18 Jul 2010 19:48:25 +0000 (19:48 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 18 Jul 2010 19:48:25 +0000 (19:48 +0000)
allow language reset
add .htaccess to web installation
add some docu to config template

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@566 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/config.php.template
www/inc/classes/language_manager.php
www/inc/rendering/autoload.php
www/inc/rendering/tcompiler.php [new file with mode: 0644]
www/inc/rendering/twig_extensions.php
www/index.php
www/install.sh
www/template/en/cart.html

index b794aaa..5fe8be3 100644 (file)
 //MySQL
 
 /*
-// create engine: server, user, password
+//create engine: server-host, user, password
 $db = new MysqlEngine("localhost","smoke","");
-// set database name
+//set database name
 $db->setDbName("smoke");
-// set table-prefix (must be non-empty)
+//set table-prefix (must be non-empty, leave the default if in doubt)
 $db->setPrefix("smoke2_");
 //set this to one of the supported MySQL storage engines for DB creation
+// only change this if your server does not support InnoDB,
+// much of MagicSmoke assumes that the underlying database supports transactions!
 $db->setStorageEngine("InnoDB");
 //set default character set
+// only change if your database does not support Unicode
 $db->setCharacterSet("utf8");
 */
 
@@ -27,11 +30,19 @@ $db->setCharacterSet("utf8");
 //PGSQL
 
 /*
-// create engine: connection string
+//create engine: connection string, the sub-parameters are:
+// dbname - name of the database
+// user - DB user that is used to log in to the DB server
+// password - DB user password to use (leave out if the user is identified via ident or trust method)
+// host, hostaddr - host on which the DB server runs
+// port - port on that host (leave out for default port)
+// for more see:
+//  http://www.php.net/manual/en/function.pg-connect.php
+//  http://www.postgresql.org/docs/8.4/interactive/libpq-connect.html
 $db = new PGsqlEngine("dbname='smoke' user='smoke'");
-// set table-prefix (must be non-empty)
+//set table-prefix (must be non-empty, leave the default if in doubt)
 $db->setPrefix("smoke2_");
-//set this only if you want debug messages on error:
+//set this only if you want debug messages on error (developers only):
 //$db->setDebugMode();
 */
 
index 336ec5b..ee12055 100644 (file)
@@ -48,7 +48,7 @@ class LanguageManager
        private $timezone;
        
        /** private constructor */
-       private function __construct()
+       private function __construct($xlang=false)
        {       
                global $template;
                
@@ -61,6 +61,8 @@ class LanguageManager
                        $this->templateFolder .= "/";
                //collect possible languages for this user
                $langs=array();
+               //resetLanguage call
+               if($xlang!==false) $langs[]=$xlang;
                // check if cookie is set
                if (isset($_COOKIE[COOKIE_LANGUAGE])) {
                        $langs[]= $_COOKIE[COOKIE_LANGUAGE];
@@ -104,6 +106,13 @@ class LanguageManager
                return self::$instance;
        }
        
+       /** resets the singleton instance to a different language */
+       public static function resetLanguage($lang)
+       {
+               self::$instance = new LanguageManager($lang);
+               return self::$instance;
+       }
+       
        /** returns the configured language template folder*/
        public function templateFolder()
        {
index f42aed8..86a5d7f 100644 (file)
@@ -11,6 +11,7 @@
 $d=dirname(__FILE__);
 wob_autoclass("EventRender",$d.'/event_listing.php');
 wob_autoclass("WebCart",$d.'/cart_listing.php');
+wob_autoclass("TemplateCompiler",$d.'/tcompiler.php');
 
 wob_autoclass("LangFilterExtension",$d.'/twig_extensions.php');
 wob_autoclass("SmokeFilterExtension",$d.'/twig_extensions.php');
diff --git a/www/inc/rendering/tcompiler.php b/www/inc/rendering/tcompiler.php
new file mode 100644 (file)
index 0000000..fb1f5a7
--- /dev/null
@@ -0,0 +1,36 @@
+<?
+
+class TemplateCompiler
+{
+       static public function execute()
+       {
+               global $template;
+               $tpl=$template;
+               $d=dir($template);
+               while(false !== ($entry = $d->read())) {
+                       if($entry == "." || $entry == ".." || $entry == ".svn")continue;
+                       if(!is_dir($template."/".$entry))continue;
+                       echo "<p>entering directory ".$entry."<br>\n";
+                       self::compileDir($tpl,$entry);
+               }
+               echo "<p>Done.<p>";
+               exit;
+       }
+
+       static public function compileDir($template,$lng)
+       {
+               global $twig,$basevars;
+               $lang=LanguageManager::resetLanguage($lng);
+               $d=dir($template."/".$lng);
+               $loader=new Twig_Loader_Filesystem($lang->templateFolders());
+               $twig->setLoader($loader);
+               while(false !== ($entry = $d->read())) {
+                       if($entry[0] == ".")continue;
+//                     echo $entry;
+                       if(!is_file($template."/".$lng."/".$entry))continue;
+                       echo " &nbsp; compiling ".$entry."... ";
+                       $twig->loadTemplate($entry)->render($basevars);
+                       echo "<br>\n";
+               }
+       }
+}
\ No newline at end of file
index 2c7a352..0dd6d7d 100644 (file)
@@ -15,9 +15,13 @@ class LangFilterExtension extends Twig_Extension
 {
        private $lang;
        
-       public function getFilters()
+       public function __construct()
        {
                $this->lang=LanguageManager::singleton();
+       }
+       
+       public function getFilters()
+       {
                return array(
                        'asMoney' => new Twig_Filter_Method($this, 'getPrice'),
                        'asDate'  => new Twig_Filter_Method($this, 'getDate'),
@@ -42,9 +46,13 @@ class LangFilterExtension extends Twig_Extension
 
 class SmokeFilterExtension extends Twig_Extension
 {
-       public function getFilters()
+       public function __construct()
        {
                $this->lang=LanguageManager::singleton();
+       }
+
+       public function getFilters()
+       {
                return array(
                        'isObject' => new Twig_Filter_Method($this, 'isObject'),
                        'isFalse'  => new Twig_Filter_Method($this, 'isFalse'),
index 02aaaa7..ecd043b 100644 (file)
@@ -101,6 +101,9 @@ try{
                case "setlanguage":
                        LanguageManager::setLanguage();
                        break;
+               case "compile":
+                       TemplateCompiler::execute();
+                       break;
                default:
                        $page=EventRender::createEventList();
                        break;
index eacf31c..0c97f54 100755 (executable)
@@ -26,6 +26,7 @@ xln admin.php
 xln index.php
 xln machine.php
 xln translations
+xln .htaccess
 
 xcp(){
  a=$TARGET/$1
@@ -39,4 +40,4 @@ xcp(){
 
 xcp styles
 xcp template
-xcp config.php config.php.template
\ No newline at end of file
+xcp config.php config.php.template
index 70abf5c..1ee15f7 100644 (file)
@@ -1,6 +1,6 @@
 {# Example Template for MagicSmoke
    ================================
-   this one is called to show the cart
+   this one is called to show the cart of a customer
 #}
 {% extends 'layout.html' %}