| 103 |
- |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************
|
|
|
4 |
* Copyright (C) 2009-2011 by Geo Varghese(www.seopanel.in) *
|
|
|
5 |
* sendtogeo@gmail.com *
|
|
|
6 |
* *
|
|
|
7 |
* This program is free software; you can redistribute it and/or modify *
|
|
|
8 |
* it under the terms of the GNU General Public License as published by *
|
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
10 |
* (at your option) any later version. *
|
|
|
11 |
* *
|
|
|
12 |
* This program is distributed in the hope that it will be useful, *
|
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
15 |
* GNU General Public License for more details. *
|
|
|
16 |
* *
|
|
|
17 |
* You should have received a copy of the GNU General Public License *
|
|
|
18 |
* along with this program; if not, write to the *
|
|
|
19 |
* Free Software Foundation, Inc., *
|
|
|
20 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
21 |
***************************************************************************/
|
|
|
22 |
|
|
|
23 |
# class defines all themes controller functions
|
|
|
24 |
class ThemesController extends Controller{
|
|
|
25 |
|
|
|
26 |
var $tableName = "themes";
|
|
|
27 |
var $layout = "ajax";
|
|
|
28 |
|
|
|
29 |
# func to get all tools
|
|
|
30 |
function __getAllThemes(){
|
|
|
31 |
$sql = "select * from $this->tableName order by id";
|
|
|
32 |
$themeList = $this->db->select($sql);
|
|
|
33 |
return $themeList;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
# func to list tools
|
|
|
37 |
function listThemes($msg='', $error=false){
|
|
|
38 |
|
|
|
39 |
if(empty($msg)) $this->__updateAllThemes();
|
|
|
40 |
|
|
|
41 |
$userId = isLoggedIn();
|
|
|
42 |
$this->set('msg', $msg);
|
|
|
43 |
$this->set('error', $error);
|
|
|
44 |
|
|
|
45 |
$sql = "select * from $this->tableName order by id";
|
|
|
46 |
|
|
|
47 |
# pagination setup
|
|
|
48 |
$this->db->query($sql, true);
|
|
|
49 |
$this->paging->setDivClass('pagingdiv');
|
|
|
50 |
$this->paging->loadPaging($this->db->noRows, SP_PAGINGNO);
|
|
|
51 |
$pagingDiv = $this->paging->printPages('themes-manager.php?');
|
|
|
52 |
$this->set('pagingDiv', $pagingDiv);
|
|
|
53 |
$sql .= " limit ".$this->paging->start .",". $this->paging->per_page;
|
|
|
54 |
|
|
|
55 |
$themeList = $this->db->select($sql);
|
|
|
56 |
$this->set('pageNo', $_GET['pageno']);
|
|
|
57 |
$this->set('list', $themeList);
|
|
|
58 |
$this->render('theme/listthemes');
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
# function to activate theme
|
|
|
62 |
function activateTheme($themeId){
|
|
|
63 |
$themeId = intval($themeId);
|
|
|
64 |
|
|
|
65 |
// inactivate all themes and then activate current theme
|
|
|
66 |
$sql = "update $this->tableName set status=0";
|
|
|
67 |
$this->db->query($sql);
|
|
|
68 |
$sql = "update $this->tableName set status=1 where id=$themeId";
|
|
|
69 |
$this->db->query($sql);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
#function to change installed status of themes
|
|
|
73 |
function __changeInstallStatus($themeId, $status){
|
|
|
74 |
|
|
|
75 |
$themeId = intval($themeId);
|
|
|
76 |
$sql = "update $this->tableName set installed=$status where id=$themeId";
|
|
|
77 |
$this->db->query($sql);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
# func to get theme info
|
|
|
81 |
function __getThemeInfo($val, $col='id') {
|
|
|
82 |
$sql = "select * from $this->tableName where $col='$val'";
|
|
|
83 |
$themeInfo = $this->db->select($sql, true);
|
|
|
84 |
return $themeInfo;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
# func to get active theme info
|
|
|
88 |
function __getActiveTheme() {
|
|
|
89 |
$themeInfo = $this->dbHelper->getRow($this->tableName, "status=1");
|
|
|
90 |
return $themeInfo;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
# func to list theme info
|
|
|
94 |
function listThemeInfo($themeId){
|
|
|
95 |
$themeId = intval($themeId);
|
|
|
96 |
$this->set('themeInfo', $this->__getThemeInfo($themeId));
|
|
|
97 |
$this->set('pageNo', $_GET['pageno']);
|
|
|
98 |
$this->render('theme/listthemeinfo');
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
function updateThemeInfo($themeId, $themeInfo){
|
|
|
102 |
|
|
|
103 |
$themeId = intval($themeId);
|
|
|
104 |
$sql = "update $this->tableName set
|
|
|
105 |
name='".addslashes($themeInfo['name'])."',
|
|
|
106 |
author='".addslashes($themeInfo['author'])."',
|
|
|
107 |
description='".addslashes($themeInfo['description'])."',
|
|
|
108 |
version='{$themeInfo['version']}',
|
|
|
109 |
website='{$themeInfo['website']}'
|
|
|
110 |
where id=$themeId";
|
|
|
111 |
$this->db->query($sql);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
# func to upgrade theme
|
|
|
115 |
function upgradeTheme($themeId){
|
|
|
116 |
$themeInfo = $this->__getThemeInfo($themeId);
|
|
|
117 |
|
|
|
118 |
if (file_exists(SP_THEMEPATH."/".$themeInfo['folder'])) {
|
|
|
119 |
|
|
|
120 |
# parse theme info
|
|
|
121 |
$themeInfo = $this->parseThemeInfoFile($themeInfo['folder']);
|
|
|
122 |
$this->updateThemeInfo($themeId, $themeInfo);
|
|
|
123 |
|
|
|
124 |
$this->__changeInstallStatus($themeId, 1);
|
|
|
125 |
$this->listThemes("Theme <b>{$themeInfo['name']} {$themeInfo['version']}</b> upgraded successfully!");
|
|
|
126 |
} else {
|
|
|
127 |
$this->__changeInstallStatus($themeId, 0);
|
|
|
128 |
$this->listThemes("Theme <b>{$themeInfo['name']} {$themeInfo['version']}</b> upgrade failed!", true);
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
# func to re install the theme
|
|
|
133 |
function reInstallTheme($themeId){
|
|
|
134 |
$themeInfo = $this->__getThemeInfo($themeId);
|
|
|
135 |
|
|
|
136 |
if(file_exists(SP_THEMEPATH."/".$themeInfo['folder'])){
|
|
|
137 |
|
|
|
138 |
# parse theme info
|
|
|
139 |
$themeInfo = $this->parseThemeInfoFile($themeInfo['name']);
|
|
|
140 |
$this->updateThemeInfo($themeId, $themeInfo);
|
|
|
141 |
|
|
|
142 |
$this->__changeInstallStatus($themeId, 1);
|
|
|
143 |
$this->listThemes("Theme <b>{$themeInfo['name']} {$themeInfo['version']}</b> re-installed successfully!");
|
|
|
144 |
}else{
|
|
|
145 |
$this->__changeInstallStatus($themeId, 0);
|
|
|
146 |
$this->listThemes("Theme <b>{$themeInfo['name']} {$themeInfo['version']}</b> re-installation failed!", true);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
# to check whether the directory is theme
|
|
|
151 |
function isThemeDirectory($file){
|
|
|
152 |
if ( ($file != ".") && ($file != "..") && ($file != ".svn") && is_dir(SP_THEMEPATH."/".$file) ) {
|
|
|
153 |
if(!preg_match('/^\./', $file)){
|
|
|
154 |
return true;
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
return false;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
# func to update themes in db
|
|
|
161 |
function __updateAllThemes(){
|
|
|
162 |
$sql = "update themes set installed=0";
|
|
|
163 |
$this->db->query($sql);
|
|
|
164 |
|
|
|
165 |
if ($handle = opendir(SP_THEMEPATH)) {
|
|
|
166 |
while (false !== ($file = readdir($handle))) {
|
|
|
167 |
if ( $this->isThemeDirectory($file) ) {
|
|
|
168 |
$themeName = $file;
|
|
|
169 |
$themeInfo = $this->__getThemeInfo($themeName, 'name');
|
|
|
170 |
if(empty($themeInfo['id'])){
|
|
|
171 |
|
|
|
172 |
// parse theme info and save details
|
|
|
173 |
$themeInfo = $this->parseThemeInfoFile($file);
|
|
|
174 |
$sql = "insert into $this->tableName(name,folder,author,description,version,website,status,installed)
|
|
|
175 |
values('".addslashes($themeInfo['name'])."', '".addslashes($themeName)."','".addslashes($themeInfo['author'])."','".addslashes($themeInfo['description'])."','{$themeInfo['version']}','{$themeInfo['website']}',0,1)";
|
|
|
176 |
$this->db->query($sql);
|
|
|
177 |
|
|
|
178 |
}else{
|
|
|
179 |
$this->__changeInstallStatus($themeInfo['id'], 1);
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
closedir($handle);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
# func to parse theme info file
|
|
|
188 |
function parseThemeInfoFile($file) {
|
|
|
189 |
$themeInfo = array();
|
|
|
190 |
$themeInfoFile = SP_THEMEPATH."/".$file."/".SP_THEMEINFOFILE;
|
|
|
191 |
if(file_exists($themeInfoFile)){
|
|
|
192 |
$xml = new XMLParser;
|
|
|
193 |
$pInfo = $xml->parse($themeInfoFile);
|
|
|
194 |
if(!empty($pInfo[0]['child'])){
|
|
|
195 |
foreach($pInfo[0]['child'] as $info){
|
|
|
196 |
$infoCol = strtolower($info['name']);
|
|
|
197 |
$themeInfo[$infoCol] = $info['content'];
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
$themeInfo['name'] = empty($themeInfo['name']) ? $file : $themeInfo['name'];
|
|
|
203 |
$themeInfo['version'] = empty($themeInfo['version']) ? '1.0.0' : $themeInfo['version'];
|
|
|
204 |
$themeInfo['author'] = empty($themeInfo['author']) ? 'Seo Panel': $themeInfo['author'];
|
|
|
205 |
$themeInfo['website'] = empty($themeInfo['website']) ? SP_THEMESITE : $themeInfo['website'];
|
|
|
206 |
return $themeInfo;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
?>
|