public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Fixes from rebase


git-svn-id: http://svn.cmsmadesimple.org/svn/cmsmadesimple/trunk@4092 
3d254a34-79dc-0310-9e5f-be208747d8a0
tedkulp (author)
Sun Aug 26 17:41:26 -0700 2007
commit  a4d47daea46de4e337cd13b8d02d56c02fa9c001
tree    33a9a145188c3ba39ba03f418f61be6b9536e159
parent  09fdef96e22dbd784297428f29f7a63448baab19
...
53
54
55
56
 
 
57
58
59
...
98
99
100
 
101
102
103
...
53
54
55
 
56
57
58
59
60
...
99
100
101
102
103
104
105
0
@@ -53,7 +53,8 @@ debug_buffer('', 'Start of include');
0
 array_walk_recursive($_GET, 'sanitize_get_var');
0
 
0
 #Make a new CMS object
0
-require(cms_join_path($dirname,'lib','classes','class.global.inc.php'));
0
+require_once(cms_join_path($dirname,'lib','classes','class.object.php'));
0
+require_once(cms_join_path($dirname,'lib','classes','class.global.inc.php'));
0
 $gCms =& new CmsObject();
0
 if (isset($starttime))
0
 {
0
@@ -98,6 +99,7 @@ debug_buffer('loading translation functions');
0
 require_once(cms_join_path($dirname,'lib','translation.functions.php'));
0
 debug_buffer('loading events functions');
0
 require_once(cms_join_path($dirname,'lib','classes','class.events.inc.php'));
0
+require_once(cms_join_path($dirname,'lib','classes','class.cms_object_relational_mapping.php'));
0
 
0
 if (isset($config['backwards_compatible']) && $config['backwards_compatible'] == true)
0
 {
...
301
302
303
304
 
305
306
307
...
301
302
303
 
304
305
306
307
0
@@ -301,7 +301,7 @@ if ($config["debug"] == true)
0
 }
0
 
0
 echo "<!-- Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple using ".(isset($db->query_count)?$db->query_count:'')." SQL queries -->\n";
0
-#echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple (".$cached."cached) using ".(isset($db->query_count)?$db->query_count:'')." SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>";
0
+echo "<p>Generated in ".microtime_diff($starttime,$endtime)." seconds by CMS Made Simple (".$cached."cached) using ".(isset($db->query_count)?$db->query_count:'')." SQL queries and ".(function_exists('memory_get_usage')?memory_get_usage():'n/a')." bytes of memory</p>";
0
 echo "<!-- CMS Made Simple - Released under the GPL - http://cmsmadesimple.org -->\n";
0
 
0
 if (get_site_preference('enablesitedownmessage') == "1" || $config['debug'] == true)
...
23
24
25
 
 
 
 
 
 
 
 
 
 
 
26
27
28
...
32
33
34
35
 
36
37
38
...
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
122
123
124
125
126
127
128
 
129
130
131
...
142
143
144
145
146
 
 
147
148
149
...
338
339
340
341
 
342
343
344
...
365
366
367
368
 
369
...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
43
44
45
 
46
47
48
49
...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
 
172
173
174
175
...
186
187
188
 
 
189
190
191
192
193
...
382
383
384
 
385
386
387
388
...
409
410
411
 
412
413
0
@@ -23,6 +23,17 @@
0
  * @package CMS
0
  */
0
 
0
+if (phpversion() < 5)
0
+{
0
+ include_once('class.overloader.php4.php');
0
+}
0
+else
0
+{
0
+ include_once('class.overloader.php5.php');
0
+}
0
+
0
+include_once('class.ormholder.php');
0
+
0
 /**
0
  * Simple global object to hold references to other objects
0
  *
0
@@ -32,7 +43,7 @@
0
  *
0
  * @since 0.5
0
  */
0
-class CmsObject {
0
+class CmsObject extends Object {
0
 
0
   /**
0
    * Config object - hash containing variables from config.php
0
@@ -118,14 +129,47 @@ class CmsObject {
0
    * content types array - List of available content types
0
    */
0
   var $contenttypes;
0
+
0
+ var $ormclasses;
0
+
0
+ var $moduleloader;
0
+
0
+ var $globalcontentoperations;
0
+
0
+ var $bookmarkoperations;
0
+
0
+ var $templateoperations;
0
+
0
+ var $contentoperations;
0
+
0
+ var $usertagoperations;
0
+
0
+ var $useroperations;
0
+
0
+ var $groupoperations;
0
+
0
+ var $moduleoperations;
0
+
0
+ var $hrinstance;
0
+
0
+ var $params = array();
0
+
0
+ var $desccache = array();
0
+
0
+ var $modules;
0
+
0
+ var $StylesheeteCache;
0
+
0
+ var $userpluginfunctions;
0
+
0
+ var $orm;
0
 
0
   /**
0
    * Constructor
0
    */
0
   function CmsObject()
0
   {
0
- $this->cmssystemmodules =
0
- array( 'nuSOAP', 'MenuManager', 'ModuleManager' );
0
+ $this->cmssystemmodules = array( 'nuSOAP', 'MenuManager', 'ModuleManager' );
0
     $this->modules = array();
0
     $this->errors = array();
0
     $this->nls = array();
0
@@ -142,8 +186,8 @@ class CmsObject {
0
     $this->userpluginfunctions = array();
0
     $this->cmsplugins = array();
0
     $this->siteprefs = array();
0
-
0
- register_shutdown_function(array(&$this, 'dbshutdown'));
0
+
0
+ $this->orm = new OrmHolder();
0
   }
0
 
0
   function & GetDb()
0
@@ -338,7 +382,7 @@ class CmsObject {
0
         return $this->hrinstance;
0
   }
0
 
0
- function dbshutdown()
0
+ function __destruct()
0
   {
0
     if (isset($this->db))
0
     {
0
@@ -365,4 +409,4 @@ class CmsContentTypePlaceholder
0
 }
0
 
0
 # vim:ts=4 sw=4 noet
0
-?>
0
+?>
0
\ No newline at end of file
...
24
25
26
27
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
96
97
98
 
 
 
99
 
100
101
102
 
103
...
24
25
26
 
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
32
33
34
 
 
35
36
37
38
39
40
41
 
42
43
0
@@ -24,79 +24,19 @@
0
  * @since    0.11
0
  * @package    CMS
0
  */
0
-class Stylesheet
0
+class Stylesheet extends CmsObjectRelationalMappting
0
 {
0
- var $id;
0
- var $name;
0
- var $value;
0
- var $media_type;
0
-
0
- function Stylesheet()
0
- {
0
- $this->SetInitialValues();
0
- }
0
-
0
- function SetInitialValues()
0
- {
0
- $this->id = -1;
0
- $this->name = '';
0
- $this->value = '';
0
- $this->media_type = '';
0
- }
0
-
0
- function Id()
0
- {
0
- return $this->id;
0
- }
0
-
0
- function Name()
0
- {
0
- return $this->name;
0
- }
0
-
0
- function Save()
0
- {
0
- $result = false;
0
-
0
- global $gCms;
0
- $styleops =& $gCms->GetStylesheetOperations();
0
-
0
- if ($this->id > -1)
0
- {
0
- $result = $styleops->UpdateStylesheet($this);
0
- }
0
- else
0
- {
0
- $newid = $styleops->InsertStylesheet($this);
0
- if ($newid > -1)
0
- {
0
- $this->id = $newid;
0
- $result = true;
0
- }
0
-
0
- }
0
-
0
- return $result;
0
- }
0
-
0
- function Delete()
0
- {
0
- $result = false;
0
-
0
- if ($this->id > -1)
0
- {
0
- global $gCms;
0
- $styleops =& $gCms->GetStylesheetOperations();
0
- $result = $styleops->DeleteStylesheetByID($this->id);
0
- if ($result)
0
- {
0
- $this->SetInitialValues();
0
- }
0
- }
0
+ var $params = array('id' => -1, 'name' => '', 'value' => '', 'media_type' => '');
0
+ var $field_maps = array('css_id' => 'id', 'css_name' => 'name', 'css_text' => 'value');
0
+ var $table = 'css';
0
+ var $sequence = 'css_seq';
0
+}
0
 
0
- return $result;
0
- }
0
+if (function_exists("overload") && phpversion() < 5)
0
+{
0
+ overload("Stylesheet");
0
 }
0
+Stylesheet::register_orm_class('Stylesheet');
0
 
0
 # vim:ts=4 sw=4 noet
0
-?>
0
+?>
0
\ No newline at end of file
...
29
30
31
32
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
53
54
55
...
88
89
90
91
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
 
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
 
181
182
183
...
199
200
201
 
202
203
...
29
30
31
 
32
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
36
37
38
39
...
72
73
74
 
75
76
 
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
 
 
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
...
115
116
117
118
119
120
0
@@ -29,27 +29,11 @@ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.stylesheet.inc.php
0
 
0
 class StylesheetOperations
0
 {
0
- function & LoadStylesheets()
0
+ function &LoadStylesheets()
0
   {
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $result = array();
0
-
0
- $query = "SELECT css_id, css_name, css_text, media_type, modified_date FROM ".cms_db_prefix()."css ORDER BY css_id";
0
- $dbresult = $db->Execute($query);
0
-
0
- while ($dbresult && $row = $dbresult->FetchRow())
0
- {
0
- $onestylesheet = new Stylesheet();
0
- $onestylesheet->id = $row['css_id'];
0
- $onestylesheet->name = $row['css_name'];
0
- $onestylesheet->value = $row['css_text'];
0
- $onestylesheet->media_type = $row['media_type'];
0
- $onestylesheet->modified_date = $db->UnixTimeStamp($row['modified_date']);
0
- $result[] = $onestylesheet;
0
- }
0
- return $result;
0
+ $stylesheet = $gCms->orm->stylesheet;
0
+ return $stylesheet->find_all(array('order' => 'css_id'));
0
   }
0
 
0
 
0
@@ -88,96 +72,28 @@ class StylesheetOperations
0
   }
0
 
0
 
0
- function & LoadStylesheetByID($id)
0
+ function &LoadStylesheetByID($id)
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
- $cache = &$gCms->StylesheetCache;
0
-
0
- if (isset($cache[$id]))
0
- {
0
- return $cache[$id];
0
- }
0
-
0
- $query = "SELECT css_id, css_name, css_text, media_type FROM ".cms_db_prefix()."css WHERE css_id = ?";
0
- $dbresult = $db->Execute($query, array($id));
0
-
0
- while ($dbresult && $row = $dbresult->FetchRow())
0
- {
0
- $onestylesheet = new Stylesheet();
0
- $onestylesheet->id = $row['css_id'];
0
- $onestylesheet->name = $row['css_name'];
0
- $onestylesheet->value = $row['css_text'];
0
- $onestylesheet->media_type = $row['media_type'];
0
- $result =& $onestylesheet;
0
-
0
- if (!isset($cache[$onestylesheet->id]))
0
- {
0
- $cache[$onestylesheet->id] =& $onestylesheet;
0
- }
0
- }
0
-
0
- return $result;
0
+ $stylesheet = $gCms->orm->stylesheet;
0
+ return $stylesheet->find_by_id($id);
0
   }
0
 
0
   function InsertStylesheet($stylesheet)
0
   {
0
- $result = -1;
0
-
0
- global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $new_stylesheet_id = $db->GenID(cms_db_prefix()."css_seq");
0
- $time = $db->DBTimeStamp(time());
0
- $query = "INSERT INTO ".cms_db_prefix()."css (css_id, css_name, css_text, media_type, create_date, modified_date) VALUES (?,?,?,?,".$time.",".$time.")";
0
- $dbresult = $db->Execute($query, array($new_stylesheet_id, $stylesheet->name, $stylesheet->value, $stylesheet->media_type));
0
- if ($dbresult !== false)
0
- {
0
- $result = $new_stylesheet_id;
0
- }
0
-
0
- return $result;
0
+ return $stylesheet->save();
0
   }
0
 
0
   function UpdateStylesheet($stylesheet)
0
   {
0
- $result = false;
0
-
0
- global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $time = $db->DBTimeStamp(time());
0
- $query = "UPDATE ".cms_db_prefix()."css SET css_name = ?,css_text = ?, media_type = ?, modified_date = ".$time." WHERE css_id = ?";
0
- $dbresult = $db->Execute($query, array($stylesheet->name, $stylesheet->value, $stylesheet->media_type, $stylesheet->id));
0
- if ($dbresult !== false)
0
- {
0
- $result = true;
0
- }
0
-
0
- return $result;
0
+ return $stylesheet->save();
0
   }
0
 
0
   function DeleteStylesheetByID($id)
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $query = "DELETE FROM ".cms_db_prefix()."css_assoc where assoc_css_id = ?";
0
- $dbresult = $db->Execute($query, array($id));
0
-
0
- $query = "DELETE FROM ".cms_db_prefix()."css where css_id = ?";
0
- $dbresult = $db->Execute($query, array($id));
0
-
0
- if ($dbresult !== false)
0
- {
0
- $result = true;
0
- }
0
-
0
- return $result;
0
+ $stylesheet = $gCms->orm->stylesheet;
0
+ return $stylesheet->delete($id);
0
   }
0
 
0
   function CheckExistingStylesheetName($name)
0
@@ -199,4 +115,5 @@ class StylesheetOperations
0
   }
0
 }
0
 
0
+# vim:ts=4 sw=4 noet
0
 ?>
0
\ No newline at end of file
...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
 
 
 
 
 
62
63
64
...
69
70
71
 
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
 
 
115
 
116
117
118
...
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
30
31
32
33
34
35
...
40
41
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
48
49
50
51
52
0
@@ -24,41 +24,12 @@
0
  * @since    0.6
0
  * @package    CMS
0
  */
0
-class Template
0
-{
0
- var $id;
0
- var $name;
0
- var $content;
0
- var $stylesheet;
0
- var $encoding;
0
- var $active;
0
- var $default;
0
-
0
- function Template()
0
- {
0
- $this->SetInitialValues();
0
- }
0
-
0
- function SetInitialValues()
0
- {
0
- $this->id = -1;
0
- $this->name = '';
0
- $this->content = '';
0
- $this->stylesheet = '';
0
- $this->encoding = '';
0
- $this->active = false;
0
- $this->default = false;
0
- }
0
-
0
- function Id()
0
- {
0
- return $this->id;
0
- }
0
-
0
- function Name()
0
- {
0
- return $this->name;
0
- }
0
+class Template extends CmsObjectRelationalMappting
0
+{
0
+ var $params = array('id' => -1, 'name' => '', 'content' => '', 'stylesheet' => '', 'encoding' => '', 'active' => true, 'default' => false);
0
+ var $field_maps = array('template_id' => 'id', 'template_name' => 'name', 'default_template' => 'default', 'template_content' => 'content');
0
+ var $table = 'templates';
0
+ var $sequence = 'templates_seq';
0
 
0
   function UsageCount()
0
   {
0
@@ -69,50 +40,13 @@ class Template
0
     else
0
       return 0;
0
   }
0
+}
0
 
0
- function Save()
0
- {
0
- $result = false;
0
-
0
- global $gCms;
0
- $templateops =& $gCms->GetTemplateOperations();
0
-
0
- if ($this->id > -1)
0
- {
0
- $result = $templateops->UpdateTemplate($this);
0
- }
0
- else
0
- {
0
- $newid = $templateops->InsertTemplate($this);
0
- if ($newid > -1)
0
- {
0
- $this->id = $newid;
0
- $result = true;
0
- }
0
-
0
- }
0
-
0
- return $result;
0
- }
0
-
0
- function Delete()
0
- {
0
- $result = false;
0
-
0
- if ($this->id > -1)
0
- {
0
- global $gCms;
0
- $templateops =& $gCms->GetTemplateOperations();
0
- $result = $templateops->DeleteTemplateByID($this->id);
0
- if ($result)
0
- {
0
- $this->SetInitialValues();
0
- }
0
- }
0
-
0
- return $result;
0
- }
0
+if (function_exists("overload") && phpversion() < 5)
0
+{
0
+ overload("Template");
0
 }
0
+Template::register_orm_class('Template');
0
 
0
 # vim:ts=4 sw=4 noet
0
 ?>
...
30
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
 
60
61
62
 
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
 
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 
 
125
126
127
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
 
173
174
175
...
194
195
196
197
198
 
199
200
201
202
203
204
205
206
207
 
 
208
209
210
...
214
215
216
217
218
 
219
220
221
222
223
224
225
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
 
 
252
253
254
...
30
31
32
 
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
36
37
38
 
39
40
 
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
45
46
47
 
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
52
53
...
74
75
76
 
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
...
101
102
103
 
 
104
105
 
 
 
 
106
107
 
 
108
109
110
111
112
...
116
117
118
 
 
119
120
 
 
 
121
122
123
...
129
130
131
 
 
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
136
137
0
@@ -30,98 +30,24 @@ include_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.template.inc.php')
0
 class TemplateOperations
0
 {
0
   function LoadTemplates()
0
- {
0
+ {
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $result = array();
0
-
0
- $query = "SELECT template_id, template_name, template_content, stylesheet, encoding, active, default_template, modified_date FROM ".cms_db_prefix()."templates ORDER BY template_name";
0
- $dbresult = &$db->Execute($query);
0
-
0
- while ($dbresult && !$dbresult->EOF)
0
- {
0
- $onetemplate = new Template();
0
- $onetemplate->id = $dbresult->fields['template_id'];
0
- $onetemplate->name = $dbresult->fields['template_name'];
0
- $onetemplate->active = $dbresult->fields['active'];
0
- $onetemplate->default = $dbresult->fields['default_template'];
0
- $onetemplate->content = $dbresult->fields['template_content'];
0
- $onetemplate->encoding = $dbresult->fields['encoding'];
0
- $onetemplate->stylesheet = $dbresult->fields['stylesheet'];
0
- $onetemplate->modified_date = $db->UnixTimeStamp($dbresult->fields['modified_date']);
0
- $result[] = $onetemplate;
0
- $dbresult->MoveNext();
0
- }
0
-
0
- if ($dbresult) $dbresult->Close();
0
-
0
- return $result;
0
+ $template = $gCms->orm->template;
0
+ return $template->find_all(array('order' => 'template_name ASC'));
0
   }
0
 
0
- function & LoadTemplateByID($id)
0
+ function LoadTemplateByID($id)
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
- $cache = &$gCms->TemplateCache;
0
-
0
- if (isset($cache[$id]))
0
- {
0
- return $cache[$id];
0
- }
0
-
0
- $query = "SELECT template_id, template_name, template_content, stylesheet, encoding, active, default_template, modified_date FROM ".cms_db_prefix()."templates WHERE template_id = ?";
0
- $row = &$db->GetRow($query, array($id));
0
-
0
- if($row)
0
- {
0
- $onetemplate =& new Template();
0
- $onetemplate->id = $row['template_id'];
0
- $onetemplate->name = $row['template_name'];
0
- $onetemplate->content = $row['template_content'];
0
- $onetemplate->stylesheet = $row['stylesheet'];
0
- $onetemplate->encoding = $row['encoding'];
0
- $onetemplate->default = $row['default_template'];
0
- $onetemplate->active = $row['active'];
0
- $onetemplate->modified_date = $db->UnixTimeStamp($row['modified_date']);
0
- $result =& $onetemplate;
0
-
0
- if (!isset($cache[$onetemplate->id]))
0
- {
0
- $cache[$onetemplate->id] =& $onetemplate;
0
- }
0
- }
0
-
0
- return $result;
0
+ $template = $gCms->orm->template;
0
+ return $template->find_by_id($id);
0
   }
0
 
0
   function LoadTemplateByContentAlias($alias)
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $query = "SELECT t.template_id, t.template_name, t.template_content, t.stylesheet, t.encoding, t.active, t.default_template, t.modified_date FROM ".cms_db_prefix()."templates t INNER JOIN ".cms_db_prefix()."content c ON c.template_id = t.template_id WHERE (c.content_alias = ? OR c.content_id = ?) AND c.active = 1";
0
- $row = &$db->GetRow($query, array($alias, $alias));
0
-
0
- if ($row)
0
- {
0
- $onetemplate = new Template();
0
- $onetemplate->id = $row['template_id'];
0
- $onetemplate->name = $row['template_name'];
0
- $onetemplate->content = $row['template_content'];
0
- $onetemplate->stylesheet = $row['stylesheet'];
0
- $onetemplate->encoding = $row['encoding'];
0
- $onetemplate->default = $row['default_template'];
0
- $onetemplate->active = $row['active'];
0
- $onetemplate->modified_date = $db->UnixTimeStamp($row['modified_date']);
0
- $result = $onetemplate;
0
- }
0
-
0
- return $result;
0
+ $template = $gCms->orm->template;
0
+ return $template->find_by_query("SELECT t.* FROM ".cms_db_prefix()."templates t INNER JOIN ".cms_db_prefix()."content c ON c.template_id = t.template_id WHERE (c.content_alias = ? OR c.content_id = ?) AND c.active = 1", array($alias, $alias));
0
   }
0
 
0
   function LoadTemplateAndContentDates($alias)
0
@@ -148,28 +74,9 @@ class TemplateOperations
0
 
0
   function LoadDefaultTemplate()
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $query = "SELECT template_id, template_name, template_content, stylesheet, encoding, active, default_template FROM ".cms_db_prefix()."templates WHERE default_template = 1";
0
- $row = &$db->GetRow($query);
0
-
0
- if($row)
0
- {
0
- $onetemplate = new Template();
0
- $onetemplate->id = $row['template_id'];
0
- $onetemplate->name = $row['template_name'];
0
- $onetemplate->content = $row['template_content'];
0
- $onetemplate->stylesheet = $row['stylesheet'];
0
- $onetemplate->encoding = $row['encoding'];
0
- $onetemplate->default = $row['default_template'];
0
- $onetemplate->active = $row['active'];
0
- $result = $onetemplate;
0
- }
0
-
0
- return $result;
0
+ $template = $gCms->orm->template;
0
+ return $template->find_by_default(1);
0
   }
0
 
0
   function UsageCount($id)
0
@@ -194,17 +101,12 @@ class TemplateOperations
0
   {
0
     $result = -1;
0
 
0
- global $gCms;
0
- $db = &$gCms->GetDb();
0
+ $dbresult = $template->save();
0
 
0
- $time = $db->DBTimeStamp(time());
0
- $new_template_id = $db->GenID(cms_db_prefix()."templates_seq");
0
- $query = "INSERT INTO ".cms_db_prefix()."templates (template_id, template_name, template_content, stylesheet, encoding, active, default_template, create_date, modified_date) VALUES (?,?,?,?,?,?,?,".$time.",".$time.")";
0
- $dbresult = $db->Execute($query, array($new_template_id, $template->name, $template->content, $template->stylesheet, $template->encoding, $template->active, $template->default));
0
     if ($dbresult !== false)
0
     {
0
- $result = $new_template_id;
0
- do_cross_reference($new_template_id, 'template', $template->content);
0
+ $result = $template->id;
0
+ do_cross_reference($result, 'template', $template->content);
0
     }
0
 
0
     return $result;
0
@@ -214,12 +116,8 @@ class TemplateOperations
0
   {
0
     $result = false;
0
 
0
- global $gCms;
0
- $db = &$gCms->GetDb();
0
+ $dbresult = $template->save();
0
 
0
- $time = $db->DBTimeStamp(time());
0
- $query = "UPDATE ".cms_db_prefix()."templates SET template_name = ?, template_content = ?, stylesheet = ?, encoding = ?, active = ?, default_template = ?, modified_date = ".$time." WHERE template_id = ?";
0
- $dbresult = $db->Execute($query,array($template->name,$template->content,$template->stylesheet,$template->encoding,$template->active,$template->default,$template->id));
0
     if ($dbresult !== false)
0
     {
0
       $result = true;
0
@@ -231,24 +129,9 @@ class TemplateOperations
0
 
0
   function DeleteTemplateByID($id)
0
   {
0
- $result = false;
0
-
0
     global $gCms;
0
- $db = &$gCms->GetDb();
0
-
0
- $query = "DELETE FROM ".cms_db_prefix()."css_assoc WHERE assoc_type = 'template' AND assoc_to_id = ?";
0
- $dbresult = $db->Execute($query,array($id));
0
-
0
- $query = "DELETE FROM ".cms_db_prefix()."templates where template_id = ?";
0
- $dbresult = $db->Execute($query,array($id));
0
-
0
- if ($dbresult !== false)
0
- {
0
- $result = true;
0
- remove_cross_references($id, 'template');
0
- }
0
-
0
- return $result;
0
+ $template = $gCms->orm->template;
0
+ return $template->delete($id);
0
   }
0
 
0
   function CountPagesUsingTemplateByID($id)