From: konrad Date: Sun, 18 Jul 2010 19:48:25 +0000 (+0000) Subject: add template compiler X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=e420025672f8141fb113213aa246b9c7cf81da56;p=web%2Fkonrad%2Fsmoke.git add template compiler 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 --- diff --git a/www/config.php.template b/www/config.php.template index b794aaa..5fe8be3 100644 --- a/www/config.php.template +++ b/www/config.php.template @@ -11,15 +11,18 @@ //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(); */ diff --git a/www/inc/classes/language_manager.php b/www/inc/classes/language_manager.php index 336ec5b..ee12055 100644 --- a/www/inc/classes/language_manager.php +++ b/www/inc/classes/language_manager.php @@ -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() { diff --git a/www/inc/rendering/autoload.php b/www/inc/rendering/autoload.php index f42aed8..86a5d7f 100644 --- a/www/inc/rendering/autoload.php +++ b/www/inc/rendering/autoload.php @@ -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 index 0000000..fb1f5a7 --- /dev/null +++ b/www/inc/rendering/tcompiler.php @@ -0,0 +1,36 @@ +read())) { + if($entry == "." || $entry == ".." || $entry == ".svn")continue; + if(!is_dir($template."/".$entry))continue; + echo "

entering directory ".$entry."
\n"; + self::compileDir($tpl,$entry); + } + echo "

Done.

"; + 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 "   compiling ".$entry."... "; + $twig->loadTemplate($entry)->render($basevars); + echo "
\n"; + } + } +} \ No newline at end of file diff --git a/www/inc/rendering/twig_extensions.php b/www/inc/rendering/twig_extensions.php index 2c7a352..0dd6d7d 100644 --- a/www/inc/rendering/twig_extensions.php +++ b/www/inc/rendering/twig_extensions.php @@ -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'), diff --git a/www/index.php b/www/index.php index 02aaaa7..ecd043b 100644 --- a/www/index.php +++ b/www/index.php @@ -101,6 +101,9 @@ try{ case "setlanguage": LanguageManager::setLanguage(); break; + case "compile": + TemplateCompiler::execute(); + break; default: $page=EventRender::createEventList(); break; diff --git a/www/install.sh b/www/install.sh index eacf31c..0c97f54 100755 --- a/www/install.sh +++ b/www/install.sh @@ -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 diff --git a/www/template/en/cart.html b/www/template/en/cart.html index 70abf5c..1ee15f7 100644 --- a/www/template/en/cart.html +++ b/www/template/en/cart.html @@ -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' %}