-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMSTouch.module.php
286 lines (238 loc) · 7.07 KB
/
CMSTouch.module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
# CMSTouch Project. A module for CMS Made Simple to run also on Iphone and others smartphones.
# Copyright (c) 2011 by Nuno Costa <[email protected]>
# I want thank Morten <[email protected]> for his help and code on the beginning of this module.
#
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp ([email protected])
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id: CMSTouch.module.php 145 2011-05-20 19:48:16Z nuno $:
#
class CMSTouch extends CMSModule {
public function __construct()
{
parent::__construct();
$smarty = cms_utils::get_smarty();
$this->check_compiler();
$smarty->assign('module_url_path',$this->GetModuleURLPath());
$smarty->assign('module_root_path',$this->GetModulePath());
}
function GetName() {
return 'CMSTouch';
}
function GetFriendlyName() {
return $this->Lang('friendlyname');
}
function AllowAutoInstall() {
return false;
}
function AllowAutoUpgrade() {
return false;
}
function IsPluginModule() {
return false;
}
function HasAdmin() {
return true;
}
function MinimumCMSVersion() {
return '1.9.4.1';
}
function GetVersion() {
return '1.0.1-b1';
}
function GetAdminSection() {
return 'layout';
}
function GetAdminDescription() {
return $this->Lang('moddescription');
}
function InstallPostMessage() {
return $this->Lang("postinstall");
}
function UninstallPostMessage() {
return $this->Lang("postuninstall");
}
function VisibleToAdminUser() {
return $this->CheckPermission('Use CMSTouch');
}
function HandlesEvents () {
return true;
}
function SetParameters() {
$this->RestrictUnknownParams();
$this->RegisterModulePlugin();
}
function GetHelp($lang = 'en_US') {
return $this->Lang("help");
}
function GetAuthor() {
return 'Nuno Costa, Morten';
}
function GetAuthorEmail() {
return '[email protected]';
}
function GetChangeLog() {
return $this->ProcessTemplate('changelog.tpl');
}
/**
*
*@return Files in Header CSS, JS on Admin-side
*/
function GetHeaderHTML(){
return $this->ProcessTemplate('admin_ct_headers.tpl');
}
function GetFullTemplateList() {
return array_merge($this->GetThemeList(), $this->GetTemplateList());
}
function GetTemplateList() {
$db = cms_utils::get_db();
$q = "SELECT template_name FROM ".cms_db_prefix()."templates";
$p = array();
$dbresult = $db->Execute($q, $p);
$templatelist=array();
while($dbresult && $row = $dbresult->FetchRow())
{
$templatelist[$row["template_name"]]=$row["template_name"];
}
return $templatelist;
}
function GetDefaultTemplate()
{
$db = cms_utils::get_db();
$q = "SELECT template_name FROM ".cms_db_prefix()."templates WHERE default_template = ?";
$p = array(1);
$dbresult = $db->Execute($q, $p);
if (!$dbresult || !$dbresult->RecordCount()) return false;
$row = $dbresult->FetchRow();
return $row["template_name"];
}
function GetTemplateContent($templatename="")
{
$db = cms_utils::get_db();
if ($templatename=="") $templatename=$this->GetDefaultTemplate();
$q = "SELECT template_content FROM ".cms_db_prefix()."templates WHERE template_name = ?";
//echo $templatename;
$p = array($templatename);
$dbresult = $db->Execute($q, $p);
if (!$dbresult || $dbresult->RecordCount()==0) return false;
$row = $dbresult->FetchRow();
return $row["template_content"];
}
function GetUANameList() {
$uanamelist = array();
$uas = $this->GetPreference("useragents");
$ualines = explode("\n",$uas);
foreach($ualines as $ualine) {
$uaparts = explode("|",$ualine);
if (count($uaparts)!=2) continue;
$uanamelist[$uaparts[0]] = $uaparts[0];
}
return $uanamelist;
}
function GetUAList() {
$ualist = array();
$uas = $this->GetPreference("useragents");
$ualines = explode("\n",$uas);
foreach($ualines as $ualine) {
//echo $ualine."<br>";
$uaparts = explode("|",$ualine);
if (count($uaparts)!=2) continue;
$ualist[$uaparts[0]] = $uaparts[1];
}
return $ualist;
}
function GetUATemplate($ua)
{
$ualist = $this->GetUAList();
foreach ($ualist as $uaid=>$uatemplate) {
if ($uaid ==$ua)
return $uatemplate;
}
return false;
}
function GetThemeList()
{
$themelist = array();
$dir = @opendir(dirname(__FILE__)."/themes/");
if (!$dir) return false;
while ($file = readdir($dir)) {
if (!is_dir(dirname(__FILE__)."/themes/".$file)) continue;
if ($file[0] =="." || $file[0] == "_") continue;
$themelist[$this->Lang("theme").": ".$file]=$file;
}
return $themelist;
}
function GetMatchingUA()
{
$thisuseragent = $_SERVER['HTTP_USER_AGENT'];
$useragents = $this->GetUAList();
foreach($useragents as $useragent => $uatemplate) {
$useragent = trim($useragent);
$uatemplate = trim($uatemplate);
if (preg_match("/$useragent/i", $thisuseragent)) {
return $useragent;
}
}
return "none";
}
/*
// PRE 1.0
function DisableCacheForPages() {
$db = cms_utils::get_db();
$q = "UPDATE ".cms_db_prefix()."content SET cachable=? WHERE active=?";
//echo $templatename;
$p = array(0,1);
$dbresult = $db->Execute($q, $p);
if (!$dbresult || $dbresult->RecordCount()==0) return false;
return true;
}
function CachedPagesExist() {
$db = cms_utils::get_db();
$q = "SELECT * FROM ".cms_db_prefix()."content WHERE cachable=? AND active=?";
//echo $templatename;
$p = array(1,1);
$dbresult = $db->Execute($q, $p);
//echo $dbresult->RecordCount();
if (!$dbresult || $dbresult->RecordCount()==0) return false;
return true;
}
*/
/**
*
* @TODO IMPORTANT, NEED TO APPLY A NEW CONCEPT... if possible
* @return Smarty Compiler
*/
function check_compiler() {
$smarty = cms_utils::get_smarty();
$thisua = $this->GetMatchingUA();
//die($thisua);
$lastua = $this->GetPreference("lastua","none");
if ($lastua != $thisua)
{
//die("!".$thisua);
$smarty->force_compile = true;
$this->SetPreference("lastua", $thisua);
}
else{
//$smarty->force_compile = false;
// if we have more than 1 template set for pages, the compile must always be true, bah
$smarty->force_compile = true;
}
}//end fn
}//end class
?>