3 require_once 'Pman.php'; /// needed as we might not be included from pman..
5 class Pman_Cms_OutputTranslations extends Pman
11 function get($lang = '', $opts = array())
18 foreach ($this->modules() as $m){
19 $projects[] = "Pman.{$m}";
22 $this->getTranslationsCache($projects);
26 function getTranslations($projects = array())
30 $template = DB_DataObject::factory('cms_template');
31 $template->whereAddIn('view_name', $projects, 'string');
32 $template = $template->fetchAll('id');
34 $base = DB_DataObject::factory('cms_templatestr');
39 $base->whereAddIn('template_id', $template, 'int');
41 $base = $base->fetchAll('id', 'template_id');
43 $translation = DB_DataObject::factory('cms_templatestr');
44 $translation->autoJoin();
45 $translation->setFrom(array(
46 'template_id' => array_values($base),
47 'lang' => $this->lang,
50 $translation->whereAddIn('cms_templatestr.src_id', array_keys($base), 'int');
52 $translation->selectAdd();
53 $translation->selectAdd("
54 cms_templatestr.txt AS txt,
55 join_template_id_id.template AS template_id_template,
56 join_src_id_id.mdsum AS src_id_mdsum,
57 join_src_id_id.txt AS src_id_txt
60 foreach ($translation->fetchAll() as $t){
61 if(!isset($ret[$t->template_id_template])){
62 $ret[$t->template_id_template] = array();
65 $ret[$t->template_id_template]['_strings'][$t->src_id_mdsum] = (empty($t->txt)) ? $t->src_id_txt : $t->txt;
66 $ret[$t->template_id_template]['_strings_map'][$t->src_id_txt] = $t->src_id_mdsum;
72 function getTranslationsCache($projects = array())
78 $this->sessionState(0);
80 $ff = HTML_FlexyFramework::get();
82 $ui = posix_getpwuid(posix_geteuid());
84 $this->cachePath = session_save_path() . '/' .
85 $ui['name'] . '-' . $ff->project . '-templatestr/' .
86 $ff->project . '-' . $ff->version . '-' . $this->lang . '.fulloutput.json';
90 if(!$this->is_cached() ){
92 $translations = $this->getTranslations($projects);
96 foreach ($translations as $file => $trans){
97 $t = json_encode($trans['_strings']);
98 $tmap = json_encode($trans['_strings_map']);
100 $cls = str_replace('.bjs', '', $file);
102 $output .= "Roo.apply({$cls}._strings, {$t});";
103 $output .= "Roo.apply({$cls}._strings_map, {$tmap});";
105 $output .= "catch(e){}; ";
108 file_put_contents($this->cachePath, $output);
111 $last_modified_time = filemtime($this->cachePath);
119 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
120 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
124 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
125 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($this->cachePath)
130 header("HTTP/1.1 304 Not Modified");
134 header('Content-Type: text/javascript');
136 // dont do the 'cachy thing' on dev servers...
137 if (!$this->is_dev()) {
138 header("Pragma: public");
139 header('Content-Length: '. filesize($this->cachePath));
141 header('Cache-Control: max-age=2592000, public');
142 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
143 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
144 header('Etag: '. md5($this->cachePath));
147 $fh = fopen($this->cachePath,'r');
154 if (!empty($_SERVER['HTTP_HOST']) && preg_match('/^dev/', $_SERVER['HTTP_HOST'])) {
163 if (!empty($_GET['no_cache'])) {
166 if ($this->is_dev()) {
171 $dest = dirname($this->cachePath);
173 if (!file_exists($dest)) {
174 mkdir($dest, 0700, true);
177 if(!file_exists($this->cachePath)){
181 $cms_templatestr = DB_DataObject::factory('cms_templatestr');
182 $cms_templatestr->active = 1;
183 $cms_templatestr->selectAdd();
184 $cms_templatestr->selectAdd("MAX(updated) AS latest");
185 $cms_templatestr->find(true);
189 if(filemtime($this->cachePath) < strtotime($cms_templatestr->latest)){