3 require_once 'Pman.php'; /// needed as we might not be included from pman..
5 class Pman_Cms_OutputTranslations extends Pman
9 function get($lang = '', $opts = array())
16 foreach ($this->modules() as $m){
17 $projects[] = "Pman.{$m}";
20 $this->getTranslationsCache($projects);
24 function getTranslations($projects = array())
28 $template = DB_DataObject::factory('cms_template');
29 $template->whereAddIn('view_name', $projects, 'string');
30 $template = $template->fetchAll('id');
32 $base = DB_DataObject::factory('cms_templatestr');
37 $base->whereAddIn('template_id', $template, 'int');
39 $base = $base->fetchAll('id', 'template_id');
41 $translation = DB_DataObject::factory('cms_templatestr');
42 $translation->autoJoin();
43 $translation->setFrom(array(
44 'template_id' => array_values($base),
45 'lang' => $this->lang,
48 $translation->whereAddIn('cms_templatestr.src_id', array_keys($base), 'int');
50 $translation->selectAdd();
51 $translation->selectAdd("
52 cms_templatestr.txt AS txt,
53 join_template_id_id.template AS template_id_template,
54 join_src_id_id.mdsum AS src_id_mdsum,
55 join_src_id_id.txt AS src_id_txt
58 foreach ($translation->fetchAll() as $t){
59 if(!isset($ret[$t->template_id_template])){
60 $ret[$t->template_id_template] = array();
63 $ret[$t->template_id_template][$t->src_id_mdsum] = (empty($t->txt)) ? $t->src_id_txt : $t->txt;
69 function getTranslationsCache($projects = array())
75 $this->sessionState(0);
77 $ff = HTML_FlexyFramework::get();
79 $ui = posix_getpwuid(posix_geteuid());
81 $this->cachePath = session_save_path() . '/' .
82 $ui['name'] . '-' . $ff->project . '-templatestr/' .
83 $ff->project . '-' . $ff->version . '-' . $this->lang . '.fulloutput.json';
87 if(!$this->is_cached() ){
89 $translations = $this->getTranslations($projects);
93 foreach ($translations as $file => $trans){
94 $t = json_encode($trans);
96 $cls = str_replace('.bjs', '', $file);
98 $output .= "Roo.apply({$cls}._strings, {$t});";
100 $output .= "catch(e){}; ";
103 file_put_contents($this->cachePath, $output);
106 $last_modified_time = filemtime($this->cachePath);
114 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
115 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
119 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
120 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($this->cachePath)
125 header("HTTP/1.1 304 Not Modified");
129 header('Content-Type: text/javascript');
131 // dont do the 'cachy thing' on dev servers...
132 if (!$this->is_dev()) {
133 header("Pragma: public");
134 header('Content-Length: '. filesize($this->cachePath));
136 header('Cache-Control: max-age=2592000, public');
137 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
138 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
139 header('Etag: '. md5($this->cachePath));
142 $fh = fopen($this->cachePath,'r');
149 if (!empty($_SERVER['HTTP_HOST']) && preg_match('/^dev/', $_SERVER['HTTP_HOST'])) {
157 if (!empty($_GET['no_cache'])) {
160 if ($this->is_dev()) {
165 $dest = dirname($this->cachePath);
167 if (!file_exists($dest)) {
168 mkdir($dest, 0700, true);
171 if(!file_exists($this->cachePath)){
175 $cms_templatestr = DB_DataObject::factory('cms_templatestr');
176 $cms_templatestr->active = 1;
177 $cms_templatestr->selectAdd();
178 $cms_templatestr->selectAdd("MAX(updated) AS latest");
179 $cms_templatestr->find(true);
181 if(filemtime($this->cachePath) < strtotime($cms_templatestr->latest)){