fix #7165 - language on email dialog
[Pman.Core] / DataObjects / Core_template.php
index 684d90a..09a9584 100644 (file)
@@ -58,6 +58,39 @@ class Pman_Core_DataObjects_Core_template  extends DB_DataObject
         
     }
     
+    function beforeUpdate($old, $q, $roo)
+    {
+        if (!empty($q['_rescan'])){
+            if ($this->filetype != 'html') {
+                $roo->jerr("can not update a php source file currently - TDOD");
+            }
+            $pg = HTML_FlexyFramework::get()->page;
+            
+            $this->syncTemplatePage(array(
+                'template_dir' => $pg->rootDir . '/'. str_replace('.', '/', $this->view_name). '/templates',
+                'template' => $this->template,
+                'base' => $this->view_name,
+                'force' => true
+            ));
+            // update the different langage versions of this page.
+            $x = DB_Dataobject::Factory('core_templatestr');
+            $x->selectAdd();
+            $x->selectAdd('distinct(lang) as lang');
+            $x->whereAdd("lang != ''");
+            $langs  = $x->fetchAll('lang');
+            foreach($langs as $l) {
+                $x = DB_Dataobject::Factory('core_templatestr');
+                $x->syncLang($l, $this->id);
+            }
+           
+            
+            $roo->jok("updated -" .  $this->template);
+        }
+    }
+   
+    
+    
+    
     /*
      * @param base (should be full path to template directory)
      * @param subdir = empty for top or subpath.
@@ -159,6 +192,7 @@ class Pman_Core_DataObjects_Core_template  extends DB_DataObject
      *  @param template_dir  << the path to the template dir ... Pman/XXX/template ...
      *  @param template   << name of template used by name field)
      *  @param base  << view name (module ? + templates?)
+     *  @param force << optional - forces even if database is newer.
      *  
      *  
      */
@@ -172,7 +206,7 @@ class Pman_Core_DataObjects_Core_template  extends DB_DataObject
         ini_set('memory_limit', '512M');
         
         //var_dump($n);
-        $n= $pgdata['template'];  // remove trailing slash..
+        $n = $pgdata['template'];  // remove trailing slash..
         
         $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
         $opts = HTML_FlexyFramework::get()->Pman_Core;
@@ -214,17 +248,18 @@ class Pman_Core_DataObjects_Core_template  extends DB_DataObject
                     $tmpl->filetype = 'html';
                     $tmpl->update($oo);
                 }
-                
-                
-                
-                return $tmpl;
+                if (empty($pgdata['force'])) {
+                    return $tmpl;
+                }
             }
         }
         
-        
+        //die("got here");
         
         try {
             $r = $flexy->compile($pgdata['template']);
+           
+            
         } catch(Exception $e) {
             $old = clone($tmpl);
             $tmpl->updated   = date('Y-m-d H:i:s',filemtime($flexy->resolvePath ($pgdata['template'])));
@@ -411,11 +446,17 @@ WHERE (
         
 
         if (!empty($done[$clsname.':'.$lang])) {
-            return; // already sent headers and everything.
+            return true; // already sent headers and everything.
         }
         
         putenv("LANGUAGE=$lang");
-        setlocale(LC_ALL, $lang);
+        if ($lang != 'en') {
+            if (!setlocale(LC_ALL, $lang.'.UTF-8')) {
+                $ff->page->jerr("Language is not available {$lang}");
+            }
+        }
+        
+        
         $d = DB_DataObject::factory($this->tableName());
         $d->whereAdd("
             LOWER(
@@ -429,7 +470,7 @@ WHERE (
         $d->filetype = 'php';
         if (! $d->find(true) ){
             $done[$clsname.':'.$lang] = true;
-            return;
+            return false;
         }
         $user = 'www-data'; // ?? do we need other ones
         $compileDir = ini_get('session.save_path') .'/' . 
@@ -464,10 +505,10 @@ WHERE (
         $ts->template_id = $d->id;
         if (!$ts->find(true)) {
             // then in theory there are no translations
-            return;
+            return false;
         }
         if (file_exists($fname) && strtotime($ts->updated) < filemtime($fname)) {
-            return; // file exists and is newer than our updated line.
+            return $fname; // file exists and is newer than our updated line.
         }
         //DB_DataObject::debugLevel(1);
 
@@ -476,6 +517,7 @@ WHERE (
         $ts->selectAdd('join_src_id_id.txt as src_id_txt, core_templatestr.txt as txt');
         $ts->lang = $lang;
         $ts->template_id = $d->id;
+        $ts->whereAdd("LENGTH(join_src_id_id.txt) > 0 AND LENGTH(core_templatestr.txt) > 0");
         $words = $ts->fetchAll('src_id_txt', 'txt' );
                
         if (!file_exists($fdir)) {
@@ -512,7 +554,7 @@ WHERE (
         
          
         
-        return;
+        return $fname;
         
         require_once 'File/Gettext.php';
         $gt = File_Gettext::factory('MO', $fname);