-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebThemes.php
254 lines (220 loc) · 8.5 KB
/
WebThemes.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
<?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');
/**
* Osclass – software for creating and publishing online classified advertising platforms
*
* Copyright (C) 2012 OSCLASS
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation,
* either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class WebThemes extends Themes
{
private static $instance;
private $pages = array( '404',
'contact',
'alert-form',
'custom',
'footer',
'functions',
'head',
'header',
'inc.search',
'index',
'item-contact',
'item-edit',
'item-post',
'item-send-friend',
'item',
'main',
'page',
'search',
'search_gallery',
'search_list',
'user-alerts',
'user-change_email',
'user-change_password',
'user-dashboard',
'user-forgot_password',
'user-items',
'user-login',
'user-profile',
'user-recover',
'user-register',
);
public static function newInstance()
{
if(!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
public function __construct()
{
parent::__construct();
$this->path = osc_themes_path();
if( Params::getParam('theme') != '' && Session::newInstance()->_get('adminId') != '' ) {
$this->setCurrentTheme( Params::getParam('theme') );
} else {
$this->setCurrentTheme( osc_theme() );
}
$functions_path = $this->getCurrentThemePath() . 'functions.php';
if( file_exists($functions_path) ) {
require_once $functions_path;
}
}
public function setCurrentThemePath()
{
if ( file_exists( $this->path . $this->theme . '/' ) ) {
$this->theme_exists = true;
$this->theme_path = $this->path . $this->theme . '/';
} else {
$this->theme_exists = false;
$this->theme_path = osc_lib_path() . 'osclass/gui/';
}
}
public function setCurrentThemeUrl()
{
if ( $this->theme_exists ) {
$this->theme_url = osc_base_url() . str_replace(osc_base_path(), '', $this->theme_path);
} else {
$this->theme_url = osc_base_url() . 'oc-includes/osclass/gui/';
}
}
/* PUBLIC */
public function setPath($path)
{
if( file_exists($path) ) {
$this->path = $path;
return true;
}
return false;
}
public function setCurrentTheme($theme)
{
$this->theme = $theme;
$this->setCurrentThemePath();
$this->setCurrentThemeUrl();
}
public function setGuiTheme()
{
$this->theme = '';
$this->theme_exists = false;
$this->theme_path = osc_lib_path() . 'osclass/gui/';
$this->theme_url = osc_base_url() . 'oc-includes/osclass/gui/';
$functions_path = $this->getCurrentThemePath() . 'functions.php';
if( file_exists($functions_path) ) {
require_once $functions_path;
}
}
/**
* This function returns an array of themes (those copied in the oc-content/themes folder)
* @return <type>
*/
public function getListThemes()
{
$themes = array();
$dir = opendir( $this->path );
while ($file = readdir($dir)) {
if (preg_match('/^[a-zA-Z0-9_]+$/', $file)) {
$themes[] = $file;
}
}
closedir($dir);
return $themes;
}
/**
*
* @param <type> $theme
* @return <type>
*/
function loadThemeInfo($theme)
{
$path = $this->path . $theme . '/index.php';
if( !file_exists($path) ) {
return false;
}
// NEW CODE FOR THEME INFO
$s_info = file_get_contents($path);
$info = array();
if( preg_match('|Theme Name:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['name'] = trim($match[1]);
} else {
$info['name'] = "";
}
if( preg_match('|Theme URI:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['theme_uri'] = trim($match[1]);
} else {
$info['theme_uri'] = "";
}
if( preg_match('|Theme update URI:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['theme_update_uri'] = trim($match[1]);
} else {
$info['theme_update_uri'] = "";
}
if( preg_match('|Description:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['description'] = trim($match[1]);
} else {
$info['description'] = "";
}
if( preg_match('|Version:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['version'] = trim($match[1]);
} else {
$info['version'] = "";
}
if( preg_match('|Author:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['author_name'] = trim($match[1]);
} else {
$info['author_name'] = "";
}
if( preg_match('|Author URI:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['author_url'] = trim($match[1]);
} else {
$info['author_url'] = "";
}
if( preg_match('|Widgets:([^\\r\\t\\n]*)|i', $s_info, $match) ) {
$info['locations'] = explode(",", str_replace(" ", "", $match[1]));
} else {
$info['locations'] = array();
}
$info['filename'] = $path;
$info['int_name'] = $theme;
if($info['name']!='') {
return $info;
}
// OLD CODE INFO
require_once $path;
$fxName = $theme . '_theme_info';
if (!function_exists($fxName)) {
return false;
}
$result = call_user_func($fxName);
$result['int_name'] = $theme;
return $result;
}
function isValidPage($internal_name)
{
return !in_array($internal_name, $this->pages);
}
function getAvailableTemplates($theme = null)
{
if($theme==null) { $theme = $this->theme; };
$templates = array();
$dir = opendir( $this->path . $theme . "/" );
while ($file = readdir($dir)) {
if (preg_match('/^template-[a-zA-Z0-9_\.]+$/', $file)) {
$templates[] = $file;
}
}
closedir($dir);
return $templates;
}
}
/* file end: ./oc-includes/osclass/WebThemes.php */