3 * Table Definition for core_template
6 * The idea here is that it contains all the strings in the templates with a language '' (empty)
7 * , it then generates a matching set of strings
10 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
12 class Pman_Core_DataObjects_Core_template_element extends DB_DataObject
15 /* the code below is auto generated do not remove the above tag */
17 public $__table = 'core_template_element'; // table name
18 public $id; // int(11) not_null primary_key auto_increment
19 public $template_id; // string(64) not_null
21 /* the code above is auto generated do not remove the tag below */
26 function applyFilters($q, $au, $roo)
28 if (isset($q['_core_page_id'] )) {
29 if (empty($q['_core_page_id'] )) {
30 $this->whereAdd('1=0');
33 $p = DB_DataObject::factory('core_page');
34 $p->get($q['_core_page_id']);
35 $this->template_id = $p->template_id;
44 * the purpose of this is to find all the block[xxxx]
45 * and make a row for then...
47 * it should return all the
51 function syncTemplateElement($template)
53 $tn = $this->tableName();
55 $contents = file_get_contents($template->currentTemplate);
56 $contentStrings = $template->contentStrings;
58 //print_R($template->contentStrings);
60 // this should also look for <flexy:use\s+content="\{block\[([A-Za-z0-9_]+)\]^+"\s" (default_content) </flexy:use>
63 // -> make sure there is a reference to element in core_template_element...
64 // -> System PAGE and elements???? with that text as the contents..
65 $core_page_strings = array();
68 if (preg_match_all('/flexy\:content=\"(\{block\[([A-Za-z0-9_-]+)\]\.([A-Za-z0-9_]+)([^"]*))"/',
73 // remove the full match..
74 // so that the match string matches the old format.
75 // the match[0] will be the one them matches contentStrings
76 array_shift($matches);
77 foreach($matches[0] as $i=>$k) {
78 if (!isset($contentStrings[$k])) {
82 if (!isset($core_page_strings[ $matches[1][$i] ])) {
83 $core_page_strings[ $matches[1][$i] ] = array();
85 $core_page_strings[ $matches[1][$i] ][ $matches[2][$i] ] = trim($contentStrings[$k]);
86 // print_r(trim($contentStrings[$k]));
92 $old_matches = array();
93 if (preg_match_all('#\{block\[([A-Za-z0-9_-]+)\]\.#',
98 // pushes old matches onto new ones..
99 foreach($old_matches[0] as $i =>$v) {
101 $matches[1][] = $old_matches[1][$i];
103 if (!isset($core_page_strings[ $matches[1][$i] ])) {
104 $core_page_strings[ $matches[1][$i] ] = array(
105 'title' => trim($matches[1][$i]),
106 'body' => 'Fill in text here'
111 // print_r(trim($matches[1][$i]));
114 //print_r($core_page_strings);
115 // why delete the template???
117 // if (empty($matches[0]) && empty($old_matches[0])) {
119 // DELETE FROM {$tn} WHERE template_id = {$template->id}
126 /// ---- USE THE SAME CODE -
129 $elements = array_unique($matches[1]);
130 //print_r($elements);
134 $t = DB_DataObject::Factory($tn);
135 $t->template_id = $template->id;
137 $old = $t->fetchAll('name', 'id');
139 foreach($elements as $el) {
141 if (!isset($old[$el])) {
144 $t->content_strings = isset($core_page_strings[$el]) ? $core_page_strings[$el] : array();
149 $t =DB_DataObject::Factory($tn);
151 $t->content_strings = isset($core_page_strings[$el]) ? $core_page_strings[$el] : array();
154 // got element already.. ignore it..
161 // delete elements, and pages pointing to this element.. --- sounds about right..
163 foreach($old as $n=>$id) {
164 $t = DB_DataObject::Factory($tn);
167 // de'reference the core_pages that refered to it..
168 $core = DB_DataObject::factory('core_page');
169 $core->query("UPDATE core_page set is_system_page = 0, element_id= 0 WHERE element_id = {$t->id}");
177 function syncTemplateFromPage($pgdata)
180 if (empty($pgdata['page'])) {
183 $element_id = DB_DataObject::factory('core_enum')->lookup('core_page_type', 'element');
185 $core = DB_DataObject::factory('core_page');
186 //DB_DataObject::DebugLevel(1);
187 $core->setFrom(array(
188 'page_type_id' => $element_id,
189 'page_link' => $this->name,
190 'parent_id' => $pgdata['page']->id,
192 'element_id' => $this->id,
194 'is_system_page' => 1
196 if ($core->count()) {
198 $this->page = clone($core);
203 $core = DB_DataObject::factory('core_page');
204 $core->title = $this->name; /// placeholder..
206 // from parsing earlier..
208 //print_R($this->content_strings);
210 // allow for bodyToDisplayHTML... etc..
211 foreach( array('title', 'body', 'extended') as $prop) {
212 if (isset($this->content_strings[$prop])) {
215 foreach($this->content_strings as $k=>$v) {
216 if (substr($k,0,strlen($prop)) == $prop) {
217 $this->content_strings[$prop] = $v;
222 $core->setFrom($this->content_strings);
224 $core->setFrom(array(
225 'page_type_id' => $element_id,
226 'page_link' => $this->name,
227 'parent_id' => $pgdata['page']->id,
229 'element_id' => $this->id,
231 'is_system_page' => 1
235 $this->page = clone($core);