3 require_once 'Pman.php'; /// needed as we might not be included from pman..
5 class Pman_Cms_OutputTranslations extends Pman
15 $this->getTranslationsCache();
19 function getTranslations($project)
23 $view_name = 'Pman.' . $project;
25 $template = DB_DataObject::factory('cms_template');
27 view_name = '{$view_name}'
29 $template = $template->fetchAll('id');
31 $base = DB_DataObject::factory('cms_templatestr');
36 $base->whereAddIn('template_id', $template, 'int');
38 $base = $base->fetchAll('id', 'template_id');
40 $translation = DB_DataObject::factory('cms_templatestr');
41 $translation->autoJoin();
42 $translation->setFrom(array(
43 'template_id' => array_values($base),
44 'lang' => $this->lang,
47 $translation->whereAddIn('cms_templatestr.src_id', array_keys($base), 'int');
49 $translation->selectAdd();
50 $translation->selectAdd("
51 cms_templatestr.txt AS txt,
52 join_template_id_id.template AS template_id_template,
53 join_src_id_id.mdsum AS src_id_mdsum,
54 join_src_id_id.txt AS src_id_txt
57 foreach ($translation->fetchAll() as $t){
58 if(!isset($ret[$t->template_id_template])){
59 $ret[$t->template_id_template] = array();
62 $ret[$t->template_id_template][$t->src_id_mdsum] = (empty($t->txt)) ? $t->src_id_txt : $t->txt;
68 function getTranslationsCache($projects = array())
74 $this->sessionState(0);
76 $ff = HTML_FlexyFramework::get();
78 $ui = posix_getpwuid(posix_geteuid());
80 $this->cachePath = session_save_path() . '/' .
81 $ui['name'] . '-' . $ff->project . '-templatestr/' .
82 $ff->project . '-' . $ff->version . '.fulloutput.json';
86 if(!$this->is_cached() ){
88 $translations = $this->getTranslations($projects);
92 foreach ($translations as $file => $trans){
93 $t = json_encode($trans);
95 $cls = str_replace('.bjs', '', $file);
97 $output .= "Roo.apply({$cls}._strings, {$t});";
99 $output .= "catch(e){}; ";
102 file_put_contents($this->cachePath, $output);
105 $last_modified_time = filemtime($this->cachePath);
113 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
114 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
118 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
119 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($this->cachePath)
124 header("HTTP/1.1 304 Not Modified");
128 header('Content-Type: text/javascript');
130 // dont do the 'cachy thing' on dev servers...
131 if (!$this->is_dev()) {
132 header("Pragma: public");
133 header('Content-Length: '. filesize($this->cachePath));
135 header('Cache-Control: max-age=2592000, public');
136 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
137 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
138 header('Etag: '. md5($this->cachePath));
141 $fh = fopen($this->cachePath,'r');
148 if (!empty($_SERVER['HTTP_HOST']) && preg_match('/^dev/', $_SERVER['HTTP_HOST'])) {
156 if (!empty($_GET['no_cache'])) {
159 if ($this->is_dev()) {
164 $dest = dirname($this->cachePath);
166 if (!file_exists($dest)) {
167 mkdir($dest, 0700, true);
170 if(!file_exists($this->cachePath)){
174 $cms_templatestr = DB_DataObject::factory('cms_templatestr');
175 $cms_templatestr->active = 1;
176 $cms_templatestr->selectAdd();
177 $cms_templatestr->selectAdd("MAX(updated) AS latest");
178 $cms_templatestr->find(true);
180 if(filemtime($this->cachePath) < strtotime($cms_templatestr->latest)){