/**
*
-
+ * simlar to Pman/Admin/UpdateBjsTemplates...
+ *
+ * scan BJS files
+ * scans JS (for ._("...") )
+ * scan PHP for
*
*/
-require_once 'Pman.php';
-class Pman_Cms_UpdateBjsTemplates extends Pman
+require_once 'Pman/Admin/UpdateBjsTemplates.php';
+class Pman_Cms_UpdateBjsTemplates extends Pman_Admin_UpdateBjsTemplates
{
static $cli_desc = "Update BJS Templates";
function updateData()
{
- $this->scanTemplates();
+ $this->scanFiles();
$this->scanTables();
-
$this->syncLanguage();
+
$this->jok('OK');
}
- function scanTemplates()
+ function scanFiles()
{
$ff = HTML_FlexyFramework::get();
$this->jerr("config[Pman_Cms] is not set");
}
- $base = $ff->Pman_Cms['project_name'];
+
+ foreach(explode(',', $ff->Pman_Cms['project_name']) as $base) {
+ $this->scanFilesBase($base);
+ }
+ }
+
+ /*
+ * this does all the scan work.
+ * it's pretty simple (does not do subdirectories...)
+ *
+ * only supports BJS / PHP / JS currently.
+ *
+ */
+
+
+ function scanFilesBase($base)
+ {
+
+ $ff = HTML_FlexyFramework::get();
+
$dir = $ff->Pman_Cms['site_dir'][$base];
+ //var_dump($dir);
$dh = opendir($dir);
+ $tp = DB_DAtaObject::Factory('cms_template');
+
$ret = array();
if(!$dh){
while (($fn = readdir($dh)) !== false) {
- if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
+ if(empty($fn) || $fn[0] == '.') {
+ continue;
+ }
+ $fp = $dir . '/'. $fn;
+ //var_dump($fp);
+ if (is_dir($fp)) {
+ continue;
+ }
+ if (is_link($fp)) {
+ continue;
+ }
+ if (preg_match('/\.js$/', $fn) && !file_exists($dir.'/'. preg_replace('/\.js$/', '.bjs', $fn))) {
+ $temp = $tp->syncJsWords(array(
+ 'base' => $base,
+ 'template_dir' => $dir,
+ 'template' => $fn
+ ));
+ if ($temp) {
+ $ids[] = $temp->id;
+ }
+ continue;
+ }
+ if (preg_match('/\.php$/', $fn)) {
+ $temp = $tp->syncPhpGetText(array(
+ 'base' =>$base,
+ 'template_dir' => $dir,
+ 'template' => $fn
+ ));
+ if ($temp) {
+ $ids[] = $temp->id;
+ }
+ continue;
+ }
+
+ if (!preg_match('/\.bjs$/', $fn)){
continue;
}
// var_dump($fn);exit;
echo "Processing {$fn} \n";
}
+
+
+
$template = DB_DataObject::factory('cms_template');
$template->setFrom(array(
'template' => $fn,
if($template->find(true)){
$o = clone ($template);
}
+ $template->filetype = 'bjs';
$template->updated = $template->sqlValue("NOW()");
- (empty($o)) ? $template->insert() : $template->update($o);
+ if (empty($o)) {
+ $ids[] = $template->insert() ;
+ } else {
+ $template->update($o);
+ $ids[] = $o->id;
+ }
+
+
$data = json_decode(file_get_contents($base . '/' . $fn), true);
$x = DB_DataObject::Factory('cms_templatestr');
$x->syncTemplateWords($template, false);
}
- // pman templates are done via core templates
- // $this->scanPmanTemplates();
- }
-
- function scanPmanTemplates()
- {
- foreach ($this->modules() as $m){
- $view_name = "Pman.$m";
-
- $dh = opendir("Pman/$m");
- $ret = array();
-
- if(!$dh){
- continue;
- }
-
- while (($fn = readdir($dh)) !== false) {
-
- if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
- continue;
- }
-
- if($this->cli){
- echo "Processing {$fn} \n";
- }
-
- $template = DB_DataObject::factory('cms_template');
- $template->setFrom(array(
- 'template' => $fn,
- 'lang' => 'en',
- 'view_name' => $view_name
- ));
-
- $o = false;
-
- if($template->find(true)){
- $o = clone ($template);
- }
-
- $template->updated = $template->sqlValue("NOW()");
-
- (empty($o)) ? $template->insert() : $template->update($o);
-
- $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
-
- $template->words = empty($data['strings']) ? array() : $data['strings'];
-
- $x = DB_DataObject::Factory('cms_templatestr');
- $x->syncTemplateWords($template, false);
- }
+ $del = DB_DataObject::factory('cms_template');
+ $del->whereAddIn('!id', $ids, 'int');
+ $del->view_name = $base;
+ $del->whereAddIn('filetype' , array( 'php', 'bjs' , 'js' ), 'string');
+ $delids = $del->fetchAll('id');
+ if ($delids) {
+ DB_DataObject::factory('core_template')->query(
+ 'update cms_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
+ );
}
}
+
function scanTables()
{
{
$ff = HTML_FlexyFramework::get();
- if (empty($ff->Pman_Cms)) {
- $this->jerr("config[Pman_Cms] is not set");
+ if (empty($ff->Pman_Cms) || empty($ff->Pman_Cms['languages']) || !is_array($ff->Pman_Cms['languages']) ) {
+ $this->jerr("config[Pman_Cms][languages] is not set");
}
- $opt_lang = empty($ff->Pman_Core_I18n) ? array( 'l' => array()) : $ff->Pman_Core_I18n;
if($this->cli){
echo "Sync the Languages template.....\n";
}
- foreach($opt_lang['l'] as $l) {
+ foreach($ff->Pman_Cms['languages'] as $l) {
if($this->cli){
echo "Sync $l Language.....\n";
}