sync
authorAlan Knowles <alan@roojs.com>
Wed, 2 Dec 2020 04:56:46 +0000 (12:56 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 2 Dec 2020 04:56:46 +0000 (12:56 +0800)
DataObjects/Cms_template.php [deleted file]
DataObjects/Cms_template_element.php [deleted file]
DataObjects/Cms_templatestr.php [deleted file]
DataObjects/Core_templatestr.php
DataObjects/pman.links.ini

diff --git a/DataObjects/Cms_template.php b/DataObjects/Cms_template.php
deleted file mode 100644 (file)
index 2382eb8..0000000
+++ /dev/null
@@ -1,483 +0,0 @@
-<?php
-/**
- * Table Definition for cms_template 
- *
- *
- * The idea here is that it contains all the strings in the templates with a language '' (empty)
- * , it then generates a matching set of strings
- * 
- */
-class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
-
-class Pman_Cms_DataObjects_Cms_template  extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'cms_template';         // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $template;                           // string(64)  not_null
-
-    public $updated;                        // blob(65535)  blob
-    public $lang;    // text  NOT NULL;
-    public $view_name; // eg mobile or desktop
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    
-    function applyFilters($q, $au, $roo)
-    {
-        //DB_DataObject::debugLEvel(1);
-//        $x = DB_Dataobject::Factory($this->tableName());
-        
-        
-        // template scanning and syncing should be done by the UpdateDatabase Code.
-        //if (!$x->count() || !empty($q['_rescan'])) {
-            //DB_DataObject::debugLEvel(1);
-            //$tp = DB_DataObject::factory('cms_template');
-            //$opts = HTML_FlexyFramework::get()->Pman_Cms;
-            //$tp->syncTemplateDir(false, '', !empty($q['_rescan']));
-            //if (isset($q['lang'])) {
-            //    $this->syncLang($q['lang']);
-            //}
-        //} 
-//        $this->whereAdd("
-//                join_
-//            ");
-        
-    }
-        
-    function toRooArray($req)
-    {
-        $ret = $this->toArray();
-        if (!empty($req['_clean_name']) ) {
-            $ret['template_clean'] = preg_replace('#\.html$#i', '', $this->template);
-            
-        }
-        return $ret;
-        
-    }
-    
-    /*
-     * @param base (should be full path to template directory)
-     * @param subdir = empty for top or subpath.
-     */
-    function syncTemplateDir($base = false,  $subdir = '', $force = false)
-    {
-        echo "syncTemplateDir: $base , $subdir, $force \n";
-        //print_r(func_get_args());
-        if (!$base) {
-            $ff = HTML_FlexyFramework::get();
-            if (!isset($ff->Pman_Cms)) {
-                echo "[ERROR] Not scanning template directory - no set in Pman_Cms[templateDir]\n";
-                return;
-            }
-            $opts = $ff->Pman_Cms;
-            if (is_array($opts['templateDir'])) {
-                foreach($opts['templateDir'] as $type=>$dir) {
-                    $this->syncTemplateDir($dir, '', $force);
-                }
-                return;
-            }
-            
-            $base = $opts['templateDir'];
-            
-            
-        }
-        if($force){
-            $tmpls = DB_DataObject::factory('cms_template');
-            $this->tmpls = $tmpls->fetchAll('template','id'); // dupes??
-        }
-        
-        $tmp_dir = $base . (empty($subdir) ? '' : '/') . $subdir;
-        
-        if(!is_dir($tmp_dir)){
-            return;
-        }
-        
-        $dh = opendir($tmp_dir);
-        if(!$dh){
-            return; // something went wrong!?
-        }
-        
-        while (($fn = readdir($dh)) !== false) {
-            // do we care that it will try and parse the template directory??? - not really..
-            // as we are only looking for php files..
-            if(empty($fn) || $fn[0] == '.'){
-                continue;
-            }
-
-            $fullpath = $tmp_dir."/".$fn;
-//            echo "filename: ".$fullpath." \n";    
-             
-            $relpath = $subdir . (empty($subdir) ? '' : '/') . $fn;
-            
-            if(is_dir($fullpath)){
-                // then recursively call self...
-//                var_Dump($base);
-//                var_Dump($subdir . (empty($subdir) ? '' : '/') . $fn);
-                $this->syncTemplateDir($base, $subdir . (empty($subdir) ? '' : '/') . $fn );
-                
-                continue;
-            }
-            if (!preg_match('/(\.html|\.txt)$/', $fn)) {
-                continue;
-            }
-            
-             
-//            var_dump($tmp);
-//            var_dump($tmp_path);
-//            $fn = basename($fn);
-            if (isset($this->tmpls[$relpath])) {
-                unset($this->tmpls[$relpath]);
-            }
-            
-            
-            
-               
-            $template = $this->syncTemplate($relpath, true, false);
-//            var_dump($template);
-            if (is_a($template, 'PEAR_Error')) {
-                continue;
-            }
-        }
-        closedir($dh);
-//        
-        if($force){
-            foreach($this->tmpls as $id) {
-                $x = DB_DataObject::factory($this->tableName());
-                if ($x->get($id)) {
-                    $x->delete();
-                }
-            }
-        }
-    }
-    
-    
-       /**
-      *
-      * sync a single template
-      * This should only be called by the UpdateDatabase code.
-      * @param string $n      name of template
-      * @param boolean $force  force parsing.
-      * @param string $link ??? related to CMS page???
-        
-      * @return boolean|PEAR_Error errors if compile fails..
-      *
-      */
-     /*
-    function syncTemplate($n, $force = false, $link = '')
-    {
-        // read the template and extract the translatable strings.
-        ini_set('memory_limit', '512M');
-        
-        //var_dump($n);
-        $n= ltrim($n,'/');  // remove trailing slash..
-        
-        $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
-        $opts = HTML_FlexyFramework::get()->Pman_Cms;
-        //print_R($opts);
-        //$dir = $opts['templateDir'] . '/' . $node;
-        
-        $oo['templateDir'] = $opts['templateDir'] ;
-        $oo['compileDir'] = $fopts['compileDir'] . '_translation_files';
-        $oo['forceCompile'] = true; //?? only for force above???
-         
-        $prefix = explode('/', $link);
-        
-        $n_split  = explode('/', $n);
-        // this is project specific and should not be put in here..
-        // we need a better way to handle it...
-        // if first part of template dire matches an option in our settings...
-        $pf = false;
-        if (is_array($opts['templateDir']) &&  strlen($link) && isset($opts['templateDir'][$prefix[0]] )) {
-            //echo "renaming templatedir/file (2)\n";
-            $pf = $prefix[0];
-            $oo['templateDir'] = $opts['templateDir'][$pf];
-            
-            
-        }
-        
-        if (is_array($opts['templateDir']) &&  count($n_split) > 1 && isset($opts['templateDir'][$n_split[0]] )) {
-            //echo "renaming templatedir/file (2)\n";
-            $pf = $n_split[0];
-            $oo['templateDir'] = $opts['templateDir'][$pf];
-            $n = substr($n,  (strlen($pf)+1));
-            //var_dump($n);
-        }
-        // non-html templates - treat as such..
-        if (!preg_match('/\.html$/i', $n)) {
-            $oo['nonHTML'] = true;
-        }
-        ///print_r(array($oo, $n));
-        
-        
-        $flexy = new HTML_Template_Flexy( $oo );
-          
-        $r = $flexy->compile($n);
-       
-//        print_r( $flexy->compiler);
-      
-        //printf(" %0.3fs : $fname<BR>", $time);
-        if (is_a($r,'PEAR_Error')) {
-            return $r;
-        }
-        //print_R(number_format(memory_get_usage(),0, '.', ','))  ;
-        $words = file_exists($flexy->getTextStringsFile) ?
-                unserialize(file_get_contents($flexy->getTextStringsFile)) :
-                array();
-        
-        $contentStrings =  $flexy->compiler->contentStrings;
-        
-        print_R($contentStrings);
-        $ori_n = $n;
-        if($pf){// support prefix
-            
-            $n = $pf.'/'.$n;
-        }
-        
-        //check the template is static page or not 
-        $link_split = explode('/', $link);
-        $is_static = ($link_split[0] == 'Static') ? 1 : 0;
-        
-        $tmpl = DB_DataObject::Factory($this->tableName());
-        if (!$tmpl->get('template', $n)) {
-            $nn = $n;
-            if($is_static)
-            {
-                $nn = 'static/'.$n;
-            }
-            $tmpl->template = $nn;
-            $tmpl->lang = 'en'; /// ??? hard coded??
-            $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
-            $tmpl->insert();
-        } else {
-            $xx =clone($tmpl);
-            // has it been cahnged...
-            if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
-                // nothing changed..
-                return $tmpl;
-            }
-            if (empty($tmpl->lang))  {
-                //echo "FIX LANG?";exit;
-                $tmpl->lang = 'en'; /// ??? hard coded??
-            }
-            
-            $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
-            $tmpl->update($xx);
-        }
-        $cmsPage = false;
-        
-        
-        
-        if(!empty($link) && empty($is_static)){
-            
-            $page_id = DB_DataObject::factory('core_enum')->lookup('cms_page_type', 'page');
-            echo "$link \n";
-            $cmsPage = DB_DataObject::factory('cms_page');
-            $cmsPage->setFrom(array(
-                'page_link'  => $link,
-                'page_type_id'  => $page_id,
-                'translation_of_id' => 0,
-                'is_element' => 0,
-            ));
-            $parent = 0;
-            if(!$cmsPage->find(true)){
-                $cmsPage = DB_DataObject::factory('cms_page');
-            } else {
-                // existing parent..
-                $parent = $cmsPage->parent_id;
-            }
-            
-            if (!$parent && strpos($link,'/') !== false) {
-                $par = explode('/', $link);
-                array_pop($par);
-                $pname = implode('/', $par);
-                $cmsPageP = DB_DataObject::factory('cms_page');
-                if ($cmsPageP->get('page_link',$pname)) {
-                    $parent = $cmsPageP->id;
-                }
-            }
-            
-            //if not php was found then the page should be a static
-            $php = explode('/', $link);
-            array_shift($php);
-            
-            
-            $file = explode('/', $oo['templateDir']);
-            array_pop($file);
-            $file = implode('/', $file).'/'.implode('/', $php).'.php';
-            
-            $is_static = 1;
-        
-            // not sure how this is supposed to work..
-            // if a tempalte exists then static = 0 ??
-        
-            if(preg_match('/\.html$/', $ori_n) && file_exists($file)){
-                $is_static = 0;
-            }
-
-//            echo "$ori_n <<<< $is_static \n";
-            $run_opts  = HTML_FlexyFramework::get()->page->opts;
-            
-            $cmsPage->setFrom(array(
-                'parent_id' => $parent,
-                'page_link'  => $link,
-                'title' => basename($link),
-                'page_type_id'  => $page_id,
-                'template_id' => $tmpl->id,
-                'language' => 'en',
-                'translation_of_id' => 0,
-                'is_system_page' => 1,
-                'is_element' => 0,
-                'is_static' => $is_static,
-            ));
-            //print_r($contentStrings);
-            
-            if (!empty($run_opts['force-content-update']) || !$cmsPage->id) { // only do this for the initila load
-                foreach( array('title', 'body', 'extended') as $prop) {
-                    if (isset($contentStrings['{page.'. $prop.'}'])) {
-                        $cmsPage->{$prop} = $contentStrings['{page.'. $prop.'}'];
-                    }
-                    if (isset($contentStrings['{page.'. $prop.':h}'])) {
-                        $cmsPage->{$prop} = $contentStrings['{page.'. $prop.':h}'];
-                    }
-                    if (isset($contentStrings['{page.'. $prop.'ToDisplayHtml():h}'])) {
-                        $cmsPage->{$prop} = $contentStrings['{page.'. $prop.'ToDisplayHtml():h}'];
-                    }
-                    echo "cmrpage->{$prop} = ". $cmsPage->{$prop} ."\n";
-                }
-            }   
-            
-             
-            
-            if(!$cmsPage->id){
-                $cmsPage->insert();
-            } else {
-                $cmsPage->update();
-            }
-        }
-        
-        $x = DB_DataObject::Factory('cms_templatestr');
-        $x->syncTemplateWords($tmpl, $words);
-        
-        // if file_exists ( template/path/name.php << eg. a matching view..)
-        // then create a system page for this. 
-        
-        
-        
-        $x = DB_DataObject::Factory('cms_template_element');
-        $x->syncTemplateElement($tmpl, file_get_contents($flexy->currentTemplate), $flexy->compiler->contentStrings, $cmsPage);
-        
-        return $tmpl;
-    
-    }
-    */
-    function syncTemplatePage($pgdata)
-    {
-        $force = true;
-        echo "compiling:"; print_r($pgdata);
-        // read the template and extract the translatable strings.
-        ini_set('memory_limit', '512M');
-        
-        //var_dump($n);
-        $n= $pgdata['template'];  // remove trailing slash..
-        
-        $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
-        $opts = HTML_FlexyFramework::get()->Pman_Cms;
-        //print_R($opts);
-        //$dir = $opts['templateDir'] . '/' . $node;
-        $oo = array(
-            'disableTranslate' => false,
-            'templateDir' => $pgdata['template_dir'],
-            'compileDir' => $fopts['compileDir'] . '_translation_files',
-            'forceCompile' => true, //?? only for force above???
-        );
-         
-        // non-html templates - treat as such..
-        if (!preg_match('/\.html$/i', $pgdata['template'])) {
-            $oo['nonHTML'] = true;
-        }
-        
-        //print_r(array($oo, $n));
-        
-        
-        $flexy = new HTML_Template_Flexy( $oo );
-          
-        if (!$flexy->resolvePath ($pgdata['template'])) {
-            
-            echo "SKIP - could not resolve path?\n";
-            print_r($oo);
-            return false;
-        }
-          
-          
-        $r = $flexy->compile($pgdata['template']);
-       
-        //print_r( $flexy);
-      
-        //printf(" %0.3fs : $fname<BR>", $time);
-        if (is_a($r,'PEAR_Error')) {
-            
-            echo $r->toString(). "\n";
-            return $r;
-        }
-        //print_R(number_format(memory_get_usage(),0, '.', ','))  ;
-         
-        $tmpl = DB_DataObject::Factory($this->tableName());
-        $tmpl->words = file_exists($flexy->getTextStringsFile) ?
-                unserialize(file_get_contents($flexy->getTextStringsFile)) :
-                array();
-        
-        $tmpl->contentStrings   = $flexy->compiler->contentStrings;
-        //var_dump(file_exists($flexy->getTextStringsFile));
-        print_r($tmpl->words);
-        $tmpl->currentTemplate  = $flexy->currentTemplate;
-        
-        $tmpl->view_name = $pgdata['base'];
-        
-        
-        if (!$tmpl->get('template',  $pgdata['template'])) {
-            
-            $tmpl->template = $pgdata['template'];
-            $tmpl->lang = 'en'; /// ??? hard coded??
-            $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
-            $tmpl->insert();
-        } else {
-            $xx =clone($tmpl);
-            // has it been cahnged...
-            //if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
-                // nothing changed..
-            //    return $tmpl;
-            //}
-            if (empty($tmpl->lang))  {
-                //echo "FIX LANG?";exit;
-                $tmpl->lang = 'en'; /// ??? hard coded??
-            }
-            
-            $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
-            $tmpl->update($xx);
-        }
-      
-        
-        $x = DB_DataObject::Factory('cms_templatestr');
-        $x->syncTemplateWords($tmpl);
-        
-        // if file_exists ( template/path/name.php << eg. a matching view..)
-        // then create a system page for this. 
-        
-        
-        
-        $x = DB_DataObject::Factory('cms_template_element');
-        $tmpl->elements = $x->syncTemplateElement($tmpl,
-                file_get_contents($flexy->currentTemplate),
-                $flexy->compiler->contentStrings,
-                false);
-        
-        
-        
-        return clone($tmpl);
-    
-    }
-}
\ No newline at end of file
diff --git a/DataObjects/Cms_template_element.php b/DataObjects/Cms_template_element.php
deleted file mode 100644 (file)
index 6f50afa..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-/**
- * Table Definition for cms_template 
- *
- *
- * The idea here is that it contains all the strings in the templates with a language '' (empty)
- * , it then generates a matching set of strings
- * 
- */
-class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
-
-class Pman_Cms_DataObjects_Cms_template_element  extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'cms_template_element';         // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $template_id;                           // string(64)  not_null
-    public $name;
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    
-    
-    function applyFilters($q, $au, $roo)
-    {
-        if (isset($q['_cms_page_id'] )) {
-            if (empty($q['_cms_page_id'] )) {
-                $this->whereAdd('1=0');
-                return;
-            }
-            $p = DB_DataObject::factory('cms_page');
-            $p->get($q['_cms_page_id']);
-            $this->template_id = $p->template_id;
-            
-            
-        }
-        
-        
-    }
-    /**
-     *
-     *  the purpose of this is to find all the block[xxxx]
-     *  and make a row for then...
-     *
-     * it should return all the 
-     */
-    
-    
-    function syncTemplateElement($template)
-    {
-        $tn = $this->tableName();
-        
-        $contents = file_get_contents($template->currentTemplate);
-        $contentStrings = $template->contentStrings;
-        
-        //print_R($template->contentStrings);
-        
-        // this should also look for <flexy:use\s+content="\{block\[([A-Za-z0-9_]+)\]^+"\s" (default_content) </flexy:use>
-        // if it finds this
-        
-        // -> make sure there is a reference to element in cms_template_element...
-        // -> System PAGE and elements???? with that text as the contents..
-        $cms_page_strings = array();
-        
-        $matches = array();
-        if (preg_match_all('/flexy\:content=\"(\{block\[([A-Za-z0-9_-]+)\]\.([A-Za-z0-9_]+)([^"]*))"/',
-            $contents,
-            $matches
-        )) {
-            // print_R($matches);
-            // remove the full match..
-            // so that the match string matches the old format.
-            // the match[0] will be the one them matches contentStrings
-            array_shift($matches);
-            foreach($matches[0] as $i=>$k) {
-                if (!isset($contentStrings[$k])) {
-                    continue;
-                }
-                //print_R($matches);
-                if (!isset($cms_page_strings[ $matches[1][$i] ])) {
-                    $cms_page_strings[ $matches[1][$i] ] = array();
-                }
-                $cms_page_strings[ $matches[1][$i] ][ $matches[2][$i] ] = trim($contentStrings[$k]);
-//                print_r(trim($contentStrings[$k]));
-            }
-        }
-        
-        
-        
-        $old_matches = array();
-        if (preg_match_all('#\{block\[([A-Za-z0-9_-]+)\]\.#',
-                $contents,
-                $old_matches
-        )) {
-            
-            // pushes old matches onto new ones..
-            foreach($old_matches[0] as $i =>$v) {
-                $matches[0][] = $v;
-                $matches[1][] = $old_matches[1][$i];
-                
-                if (!isset($cms_page_strings[ $matches[1][$i] ])) {
-                    $cms_page_strings[ $matches[1][$i] ] = array(
-                        'title' => trim($matches[1][$i]),
-                        'body' => 'Fill in text here'
-                        
-                    );
-                    
-                }
-//                print_r(trim($matches[1][$i]));
-            }
-        }
-        //print_r($cms_page_strings);
-        // why delete the template???
-        
-        // if (empty($matches[0]) && empty($old_matches[0])) {
-        //     $this->query("
-        //         DELETE FROM {$tn} WHERE template_id = {$template->id}
-        //     ");
-        //     return;
-        // }
-         
-         
-          
-        /// ---- USE THE SAME CODE - 
-        
-        
-        $elements = array_unique($matches[1]);
-        //print_r($elements);
-        
-        $ret = array();
-        
-        $t = DB_DataObject::Factory($tn);
-        $t->template_id = $template->id;
-        $base = clone($t);
-        $old = $t->fetchAll('name', 'id');
-        
-        foreach($elements as $el) {
-            
-            if (!isset($old[$el])) {
-                $t = clone($base);
-                $t->name = $el;
-                $t->content_strings = isset($cms_page_strings[$el]) ? $cms_page_strings[$el] : array();
-                
-                $t->insert();
-                $ret[] = clone($t);
-            } else {
-                $t =DB_DataObject::Factory($tn);
-                $t->get($old[$el]);
-                $t->content_strings = isset($cms_page_strings[$el]) ? $cms_page_strings[$el] : array();
-                unset($old[$el]);
-                $ret[] = clone($t);
-                // got element already.. ignore it..
-                
-            }
-            // add
-            
-        }
-        
-        // delete elements, and  pages pointing to this element.. --- sounds about right..
-        
-        foreach($old as $n=>$id) {
-            $t = DB_DataObject::Factory($tn);
-            $t->get($id);
-            $t->delete();
-            // de'reference the cms_pages that refered to it..
-            $cms = DB_DataObject::factory('cms_page');
-            $cms->query("UPDATE cms_page set is_system_page = 0, element_id= 0 WHERE element_id = {$t->id}");
-            
-        }
-        
-        return $ret;
-        
-    }
-    
-    function syncTemplateFromPage($pgdata)
-    {
-        //print_r($pgdata);
-        if (empty($pgdata['page'])) {
-            return false;
-        }
-        $element_id = DB_DataObject::factory('core_enum')->lookup('cms_page_type', 'element'); 
-
-        $cms = DB_DataObject::factory('cms_page');
-        //DB_DataObject::DebugLevel(1);
-        $cms->setFrom(array(
-                'page_type_id'  => $element_id,
-                'page_link' => $this->name,
-                'parent_id' => $pgdata['page']->id,
-                'is_element' => 1,
-                'element_id' => $this->id,
-                'language' => 'en',
-                'is_system_page' => 1
-        ));
-        if ($cms->count()) {
-            $cms->fetch();
-            $this->page = clone($cms);
-            return;
-        }
-        
-        
-        $cms = DB_DataObject::factory('cms_page');
-        $cms->title = $this->name; /// placeholder..
-         
-       // from parsing earlier..
-        
-        //print_R($this->content_strings);
-        
-        // allow for bodyToDisplayHTML... etc..
-        foreach( array('title', 'body', 'extended') as $prop) {
-            if (isset($this->content_strings[$prop])) {
-                continue;
-            }
-            foreach($this->content_strings as $k=>$v) {
-                if (substr($k,0,strlen($prop)) == $prop) {
-                    $this->content_strings[$prop] = $v;
-                }
-                
-            }
-        }
-        $cms->setFrom($this->content_strings); 
-        
-        $cms->setFrom(array(
-                'page_type_id'  => $element_id,
-                'page_link' => $this->name,
-                'parent_id' => $pgdata['page']->id,
-                'is_element' => 1,
-                'element_id' => $this->id,
-                'language' => 'en',
-                'is_system_page' => 1
-        ));
-        $cms->insert();    
-        
-        $this->page = clone($cms);
-    }
-    
-    
-}
-    
\ No newline at end of file
diff --git a/DataObjects/Cms_templatestr.php b/DataObjects/Cms_templatestr.php
deleted file mode 100644 (file)
index 30235e5..0000000
+++ /dev/null
@@ -1,600 +0,0 @@
-<?php
-/**
- * Table Definition for cms_templatestr
- *
- *
- * The idea here is that it contains all the strings in the templates with a language '' (empty)
- * , it then generates a matching set of strings
- * 
- */
-class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
-
-class Pman_Cms_DataObjects_Cms_templatestr extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'cms_templatestr';         // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $template_id;                           // string(64)  not_null
-    public $txt;                    // datetime(19)  multiple_key binary
-    public $updated;                        // blob(65535)  blob
-    public $src_id;                          // int(11)  not_null
-    public $lang;    // text  NOT NULL;
-    public $mdsum;    // text  NOT NULL;
-    public $active;
-    public $on_table;
-    public $on_id;
-    public $on_col;
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    function beforeInsert($q,$roo)
-    {
-        if(!empty($q['_rescan'])){
-            $this->syncLang($q['_rescan']);
-            $roo->jok('OK');
-        }
-    }
-    
-    
-    function applyFilters($q, $au, $roo)
-    {
-        if (!empty($q['_tree'])) {
-            $this->applyFiltersTree($q,$roo);
-        }
-        
-        if(!empty($q['on_table']) && !is_numeric($q['template_id'])){
-            $this->template_id = 0;
-        }
-        if (!empty($q['_search_txt'])) {
-            $str = $this->escape($q['_search_txt']);
-            $this->whereAdd("cms_templatestr.txt like '%{$str}%' OR join_src_id_id.txt like '%{$str}%'");
-            
-        }
-    }
-    function translateTableCol($obj, $col, $lang)
-    {
-        $cts = DB_DataObject::factory('cms_templatestr');
-        $cts->lang = $lang;
-        $cts->on_table = $obj->tableName();
-        $cts->on_id = $obj->pid();
-        $cc = clone($cts);
-        if(!$cts->find(true)){
-            return $obj->$col;
-        }
-        
-        
-        if(empty($cts->txt)){
-            return $obj->$col;
-        }
-            
-        return $cts->txt;
-    }
-    /**
-     *
-     * insert the origanal table text
-     * 
-     * @param type $roo
-     * @param type $obj
-     * @param type $chg
-     * @return type 
-     */
-    function onTableChange($roo, $obj, $chg)
-    {
-        
-        $ff = HTML_FlexyFramework::get()->Pman_Cms;
-            
-        if(empty($ff['DataObjects_Cms_templatestr']['tables'])){
-            return;
-        }
-        $tn = $obj->tableName();
-        if(empty($ff['DataObjects_Cms_templatestr']['tables'][$tn])){
-            return;
-        }
-        $cols = $ff['DataObjects_Cms_templatestr']['tables'][$tn];
-        
-        
-        foreach($cols as $c) {
-            $x = $this->factory($this->tableName());
-            $x->on_id = $obj->pid();
-            $x->on_table = $tn;
-            $x->on_col = $c;
-            $x->lang = ''; /// eg. base language..
-            $up = $x->find(true);
-            if ($up && $x->txt == $obj->$c) {
-                continue; // update an no change..
-            }
-            $x->active = 1;
-            $x->src_id = 0;
-            $x->txt = $obj->$c;
-            $x->mdsum = md5($obj->$c);
-            $x->template_id = 0;
-            $x->updated = date('Y-m-d H:i:s', strtotime("NOW"));
-            $up ? $x->update() : $x->insert();
-        }
-        
-        
-    }
-    
-    
-    function applyFiltersTree($q,$roo)
-    {
-        if (empty($q['node'])) {
-            $roo->jerr("invalid node");
-        }
-        switch($q['node']) {
-            
-            case 'transtree':
-               // DB_DataObject::debugLevel(1);
-                $x = DB_Dataobject::Factory($this->tableName());
-                $x->selectAdd();
-                $x->selectAdd('distinct(lang) as lang');
-                $x->whereAdd("lang != ''");
-                $ret= array();
-                foreach( $x->fetchAll('lang') as $l) {
-                    $ret[] = array(
-                        'text'=>$l,
-                        'id' =>$l,
-                        'language' => true
-                    );
-                }
-                if (empty($ret)) {
-                    $ret[] = array(
-                        'text'=>'en',
-                        'id' => 'en',
-                        'language' => true
-                    );
-                }
-                $roo->jdata($ret);
-                
-                
-            default:
-                $x = DB_DataObject::factory($this->tableName());
-                $x->selectAdd();
-                $x->selectAdd('distinct(template_id) as template_id');
-                $x->lang = $q['node'];
-                $ids = $x->fetchAll('template_id');
-                
-                $ret= array();
-                //add the table type lists
-                
-                $ff = HTML_FlexyFramework::get()->Pman_Cms;
-                
-                if(!empty($ff['DataObjects_Cms_templatestr']['tables'])){
-                    foreach($ff['DataObjects_Cms_templatestr']['tables'] as $table=>$v){
-                        $ret[] = array(
-                            'text'=> $table,
-                            'on_table' => $table,
-                            'id' => 0,
-                            'leaf' => true
-                        );
-                    }
-                }
-                
-//                $x->orderBy('template ASC');
-//                $x->whereAdd("lang != ''");
-                
-                //below are old code
-                $xx = DB_Dataobject::Factory('cms_template');
-                $xx->whereAddIn('id', $ids, 'int');
-                $xx->selectAdd();
-                $xx->selectAdd("
-                               
-                    id, concat(view_name,':', template) as template_name
-                ");
-                $xx->orderBy('template_name ASC');
-                
-                foreach( $xx->fetchAll('id', 'template_name') as $l =>$n) {
-                    $ret[] = array(
-                        'text'=>$n,
-                        'id' => $l,
-                        'leaf' => true
-                    );
-                }
-                
-                $roo->jdata($ret);
-                $roo->jerr("not yet");
-                break;
-        }
-                
-        
-        
-    }
-    
-    
-    /**
-     *
-     * 
-     * @param object $tmpl cms_template data object
-     * @param array $words array of words 
-     */ 
-    function syncTemplateWords($tmpl, $keyvalue = false)
-    {
-        
-        $words = $tmpl->words;
-        // mapping for template : 
-        //tablename => $n (templatename) 
-        //tableid => $k (key value)
-        //colname => $n (templatename) 
-        // mdsum => md5(sum)
-        //
-        //print_r($words);exit;
-        // grab original
-        $tt = DB_DataObject::factory($this->tableName());
-
-
-        $t = DB_DataObject::factory($this->tableName());
-        $t->template_id = $tmpl->id;
-        $t->whereAdd("lang = ''");
-        
-        
-        // we have a situation where old md sums where created..
-        
-        
-        
-        $cur = $t->fetchAll('mdsum', 'id'); 
-        
-        
-        
-        
-        
-        
-        
-        // now loop through current..
-        $cwords = array();// not in used??
-        $active = array();
-//        echo "sync Template Words... \n";
-//        print_r($words);
-        
-        foreach($words as $k=>$v) {
-            
-            
-            $v = trim($v);
-            
-            $md = $keyvalue ? $k : md5($v);
-            
-            // check to see if there are more that one versions of that md5
-            
-            
-            if (!isset($cur[$md])) {
-                // create a record for it..
-                $t = DB_DataObject::factory($this->tableName());
-                $t->setFrom(array(
-                    'txt' => $v,
-                    'lang' => '',// by default should a english 
-                    'updated' => date('Y-m-d H:i:s', strtotime("YESTERDAY")),
-                    'template_id'=>$tmpl->id,
-                    'mdsum' => $md,
-                    'src_id' => 0,
-                    'active' => 1,
-                ));
-                $active[] =  $t->insert();
-                continue;
-            }  
-            $cur[$md] = $this->checkDupes($tmpl->id, '',  $cur[$md] , $md);
-            
-            $active[] = $cur[$md];
-            
-            // we have it already? - 
-            $tt->query("UPDATE {$this->tableName()}
-                        SET active= 1
-                        WHERE
-                        id = ".$cur[$md]);
-            unset($cur[$md]);
-            
-        }
-        // delete unused.
-        
-        
-        
-
-        $deactive = array();
-        if (count(array_values($cur))) {// de-active unused
-
-            $t = DB_DataObject::factory($this->tableName());
-//            echo "de-active current?? \n";
-//            print_r($cur);
-//            echo "\n";
-            $deactive = array_values($cur);
-            $t->query("UPDATE cms_templatestr
-                      SET active = 0 WHERE id in (" . implode(',' ,$deactive) . ")
-                     ");
-        }
-        
-        // delete all the items that are not relivant.
-        // clear orphaned chidren - it just blanks out the src id, so they can be used as suggestions..?
-        // this does not help - as it just puts random strings in there.. - with no reference to the original text..
-        $t = DB_DataObject::factory($this->tableName());
-    
-        // this will active the child data
-        if (empty($active)) {// set the active array to empty
-            $active = array(-1);
-        }
-        $t->query("UPDATE  cms_templatestr 
-                SET active = 1
-                  WHERE
-                     src_id IN (". implode(',' ,$active) . ")
-                    AND
-                    template_id = {$tmpl->id}
-        ");
-        //deactive the child data
-        if (empty($deactive)) {
-            $deactive = array(-1);
-        }
-        $t->query("UPDATE  cms_templatestr 
-                SET active = 0
-                  WHERE
-                    src_id IN (". implode(',' ,$deactive) . ")
-                    AND
-                    template_id = {$tmpl->id}
-                    AND
-                    lang != ''
-        ");
-    }
-    function checkDupes($tid, $lang, $id, $mdsum) {
-        
-        $t = DB_DataObject::factory($this->tableName());
-        $t->template_id = $tid;
-        $t->mdsum = $mdsum;
-        $t->whereAdd("lang = '{$lang}'");
-        if ($t->count() == 1) {
-            return $id; // only got one ... no issues..
-        }
-        
-        //echo "GOT DUPES : $id, $lang, $id , $mdsum\n";
-        
-        //DB_DataObject::debugLevel(1);
-        // find out if any of them have got translations.
-        $ids = $t->fetchAll('id');
-        
-        
-        $t = DB_DataObject::factory($this->tableName());
-        $t->whereAddIn('src_id', $ids, 'int');
-        $t->whereAdd("txt != ''");
-        $t->orderBy('updated DESC');
-        if ($t->count()) {
-            $t->limit(1);
-            // do any translations exist?
-            $t->find(true);
-            $id = $t->src_id;
-        }
-        
-        
-        // delete all the others...
-        $t = DB_DataObject::factory($this->tableName());
-        $t->whereAddIn('src_id', $ids, 'int');
-        $t->whereAdd("src_id != $id");
-        $t->find();
-        while($t->fetch()) {
-            $tt = clone($t);
-            $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
-            $tt->update($t);
-        }
-        $t = DB_DataObject::factory($this->tableName());
-        $t->whereAddIn('id', $ids, 'int');
-        $t->whereAdd("id != $id");
-        $t->find();
-        while($t->fetch()) {
-            $tt = clone($t);
-            $tt->mdsum = $t->mdsum . '-bad-'. $t->id;
-            $tt->update($t);
-        }
-        // this is done by calling code 
-        //$t = DB_DataObject::factory($this->tableName());
-        //$t->query("update cms_templatestr set active= 1 where src_id = $id");
-        
-        
-        
-       //exit;
-        return $id;
-    
-               
-         
-    }
-    
-    function syncLang($lang)
-    {
-        // bugs with our old code...
-//        die('in?');
-        $tn = $this->tableName();
-        $t = DB_DataObject::factory($tn);
-        $t->query("DELETE FROM {$tn} WHERE lang !='' AND src_id = 0 AND on_table  = ''");
-        
-        // find all the id's from lang that have not been generated..
-        
-        //find the origanal 
-        $t = DB_DataObject::factory($tn);
-        $t->whereAdd("lang = ''");
-        $t->active = 1;
-        
-        //old code, this did not support the on_table
-//        $id_tmp = $t->fetchAll('id','template_id');
-//        $ids = array_keys($id_tmp);
-        $id_tmp = array();
-        //new code for support the sync tables 
-        foreach($t->fetchAll() as $ori){
-            $id_tmp[$ori->id] = $ori;
-        }
-        $ids = array_keys($id_tmp);
-        
-        // matching by language:
-        $t = DB_DataObject::factory($tn);
-        $t->whereAddIn('src_id', $ids , 'int');
-        $t->lang = $lang;
-        //$t->active = 1;
-        $got = $t->fetchAll('src_id');
-        $missing = array_diff($ids, $got);
-        foreach($missing as $id) {
-            
-            $t = DB_DataObject::factory($tn);
-            $t->setFrom(array(
-                'src_id' => $id,
-                'txt' =>  '',
-                'lang' => $lang,
-                'updated' => date('Y-m-d H:i:s', strtotime("NOW")),
-                'template_id'=> $id_tmp[$id]->template_id,
-                'on_table' => $id_tmp[$id]->on_table,
-                'on_id' => $id_tmp[$id]->on_id,
-                'on_col' => $id_tmp[$id]->on_col,
-                'active' => 1,
-                // no md5um
-            ));
-            $t->insert();
-        }
-        
-        
-        
-    }
-    function translateFlexyString($flexy, $string)
-    {
-        //var_dump($string);
-        $debug = false;;
-        //if (!empty($_REQUEST['_debug'])) { $debug= true; }
-        
-        // using $flexy->currentTemplate -> find the template we are looking at..
-        // then find the string for $flexy->options['locale']
-        //DB_DataObject::debugLevel(1);
-        if ($debug) { var_dump($string); }
-        
-        static $cache = array(); // cache of templates..
-        
-        $ff = HTML_FlexyFramework::get();
-        $view_name = isset($ff->Pman_Cms['view_name']) ? $ff->Pman_Cms['view_name'] : false;
-        
-        if ($debug) { var_dump(array('view_name'=> $view_name)); }
-        
-        $tempdir = '';
-        foreach($flexy->options['templateDir'] as $td) {
-            if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
-                $tempdir = $td;
-                break;
-            }
-        }
-        
-        
-        $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
-        
-        if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
-            if ($debug) { echo "from cache no match - $string\n"; }
-            return $string;
-        }
-        
-        if (!isset($cache[$tmpname])) {
-                
-            
-            
-            $tmpl = DB_DataObject::factory('cms_template');
-            if ($view_name !== false) {
-                $tmpl->view_name = $view_name;
-            }
-            if(!$tmpl->get('template', $tmpname)){
-                // strip of site prefix if set...
-                 
-                $tmpl = DB_DataObject::factory('cms_template');
-                if(!$tmpl->get('template', $tmpname)){
-                    //var_dump("no template? {$tmpname} or {$relpath}" );
-                    $cache[$tmpname] = false;
-                    if ($debug) { echo "no template found - no match - $string\n"; }
-                    return $string;
-                }
-            }
-            $cache[$tmpname] = $tmpl;
-        } else {
-            $tmpl = $cache[$tmpname] ;
-        }
-         
-    
-        //get original template id 
-        $orig = DB_DataObject::factory($this->tableName());
-        $orig->lang = '';
-        $orig->template_id = $tmpl->id;
-        $orig->active = 1;
-        if(!$orig->get( 'mdsum' , md5(trim($string)))){
-             //var_dump('no text? '. $string);
-            if ($debug) { echo "no original string found tplid: {$tmpl->id}\n"; }
-            return false;
-        }
-         
-        //find out the text by language
-        $x = DB_DataObject::factory($this->tableName());
-        $x->lang = $flexy->options['locale'];
-        $x->template_id = $tmpl->id;
-        if(!$x->get('src_id', $orig->id)){
-            //var_dump('no trans found' . $orig->id);
-            if ($debug) { echo "no translation found\n"; }
-            return false;
-        }
-        if ($debug) { echo "returning $x->txt\n"; }
-        //var_Dump($x->txt);
-        return empty($x->txt) ? $string : $x->txt;
-    }
-    function translateChanged($flexy)
-    {
-        //return true;
-        // var_dump('check changed?');
-        //DB_DataObject::debugLevel(1);
-        //var_Dump(array($flexy->options['templateDir'][0], $flexy->currentTemplate));
-        
-        //var_dump($flexy->compiledTemplate);
-        $utime = file_exists($flexy->compiledTemplate) ?  filemtime( $flexy->compiledTemplate) : 0;
-        
-        
-        static $cache = array(); // cache of templates..
-        
-        $ff = HTML_FlexyFramework::get();
-        $view_name = isset($ff->Pman_Cms['view_name']) ? $ff->Pman_Cms['view_name'] : false;
-        
-        $tempdir = '';
-        foreach($flexy->options['templateDir'] as $td) {
-            if (substr($flexy->currentTemplate, 0, strlen($td)) == $td) {
-                $tempdir = $td;
-                break;
-            }
-        }
-        
-        
-        $tmpname = substr($flexy->currentTemplate, strlen($td) +1);
-        
-        if (isset($cache[$tmpname]) && $cache[$tmpname] === false) {
-            return false;
-        }
-        
-        if (!isset($cache[$tmpname])) {
-                
-            
-            
-            $tmpl = DB_DataObject::factory('cms_template');
-            if ($view_name !== false) {
-                $tmpl->view_name = $view_name;
-            }
-            if(!$tmpl->get('template', $tmpname)){
-                // strip of site prefix if set...
-                 
-                $tmpl = DB_DataObject::factory('cms_template');
-                if(!$tmpl->get('template', $tmpname)){
-                    //var_dump("no template? {$tmpname} or {$relpath}" );
-                    $cache[$tmpname] = false;
-                    return false;
-                }
-            }
-            $cache[$tmpname] = $tmpl;
-        } else {
-            $tmpl = $cache[$tmpname] ;
-        }
-          
-         
-        
-        $x = DB_DataObject::factory($this->tableName());
-        $x->lang = $flexy->options['locale'];
-        $x->active = 1;
-        $x->template_id = $tmpl->id;
-        $x->whereAdd("updated > '". date('Y-m-d H:i:s', $utime)."'");
-        
-        return $x->count() ? true : false;
-        
-        
-    }
-    
-}
index 1f2ce93..60d4e6f 100644 (file)
@@ -176,6 +176,7 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject
                 
             case  preg_match('/^view:/', $q['node']):
                 
+               
                 $bits= explode(":",preg_replace('/^view:/', '', $q['node']));
                 
                  $x = DB_DataObject::factory($this->tableName());
@@ -361,6 +362,7 @@ class Pman_Core_DataObjects_Core_templatestr extends DB_DataObject
                     lang != ''
         ");
     }
+    
     function checkDupes($tid, $lang, $id, $mdsum) {
         
         $t = DB_DataObject::factory($this->tableName());
index 2aeba9b..6e1c70d 100644 (file)
@@ -83,6 +83,15 @@ updated_by = core_person:id
 [core_person_settings]
 person_id = core_person:id
 
+
+
+[core_templatestr]
+src_id = core_templatestr:id
+template_id = core_template:id
+
+[core_template_element]
+template_id = core_template:id
+
 [database__render]
 core_project = name
 core_company= name