restricted template compiler to admin
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 19 Jul 2010 19:59:45 +0000 (19:59 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 19 Jul 2010 19:59:45 +0000 (19:59 +0000)
fix some typos in template docu

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

doc/template.html
www/inc/rendering/tcompiler.php

index e493526..8deb1d4 100644 (file)
@@ -7,7 +7,7 @@
 
 The web user interface is constructed with templates with just a few dynamic values filled in. Those templates are found in the <tt>template/*</tt> directories. These templates are normal HTML or text with some special constructs to fill in the blanks.<p>
 
-Please see the <a href="twig/index.php">Twig</a> template engine documentation for syntax details.
+Please see the <a href="twig/index.html">Twig</a> template engine documentation for syntax details.
 
 <h2>Template Files</h2>
 
index fb1f5a7..027e60e 100644 (file)
@@ -1,9 +1,13 @@
 <?
 
+/**helper class that compiles templates and caches them*/
 class TemplateCompiler
 {
+       /**public interface for the template compiler, called from index.php?mode=compile */
        static public function execute()
        {
+               self::checkAdmin();
+               //go through directories
                global $template;
                $tpl=$template;
                $d=dir($template);
@@ -13,24 +17,45 @@ class TemplateCompiler
                        echo "<p>entering directory ".$entry."<br>\n";
                        self::compileDir($tpl,$entry);
                }
+               //done
                echo "<p>Done.<p>";
                exit;
        }
 
-       static public function compileDir($template,$lng)
+       /**compiles all template files of one specific directory*/
+       static private function compileDir($template,$lng)
        {
                global $twig,$basevars;
+               //reset the language manager to match the current directories' language
                $lang=LanguageManager::resetLanguage($lng);
+               //go through all files
                $d=dir($template."/".$lng);
                $loader=new Twig_Loader_Filesystem($lang->templateFolders());
                $twig->setLoader($loader);
                while(false !== ($entry = $d->read())) {
+                       //ignore anything that starts with a dot
                        if($entry[0] == ".")continue;
-//                     echo $entry;
+                       //only handle normal files
                        if(!is_file($template."/".$lng."/".$entry))continue;
+                       //actually load and (implicitly) compile it
                        echo " &nbsp; compiling ".$entry."... ";
                        $twig->loadTemplate($entry)->render($basevars);
                        echo "<br>\n";
                }
        }
+       
+       /**check whether the user is admin*/
+       static private function checkAdmin()
+       {
+               global $db;
+               if(!$db->canAdministrate())
+                       die("The Administratpr account is turned off. Sorry. Cannot compile templates for you.");
+               if(!$db->checkAdmin()){
+                       header("HTTP/1.0 401 Unauthorized");
+                       header("WWW-Authenticate: Basic realm=\"Smoke Admin Login\"");
+                       echo "Need to login in order to administrate.";
+                       exit;
+               }else
+                       echo "Compiling all templates I can find...<p>\n";
+       }
 }
\ No newline at end of file