-
Notifications
You must be signed in to change notification settings - Fork 1
/
theme.php
executable file
·117 lines (114 loc) · 4.36 KB
/
theme.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
<?php
if(!defined('CORE_ROOT')) exit();
require CORE_ROOT.'include/admin.inc.php';
require CORE_ROOT.'include/install.func.php';
checkcreator();
$action = '';
if(isset($_GET['action'])) $action = $_GET['action'];
if($action == 'install') {
vc();
setcache('themeinstalling', $get_theme);
$publicip = publicip();
aklocation("http://www.akhtm.com/akcms_soft.php?action=install&key=$get_theme&referer=".$systemurl."&ip=".$publicip.'&r='.random(6));
} elseif($action == 'reinstall') {
$theme = getcache('themeinstalling');
if($theme != $get_theme) aexit('error');
if(!downloadtheme($get_theme, $get_cdkey)) aexit('error2');
emptyalltables();
installinitialdata();
clearfiles();
aklocation('index.php?file=theme');
} elseif($action == 'frame') {
showprocess($lan['importing'], 'index.php?file=theme&action=importdb&r='.random(6), 'index.php?file=theme&action=themeinstall&r='.random(6), 100, $lan['finished']);
} elseif(empty($action)) {
if(!file_exists(AK_ROOT.'install/custom.config.php')) {
aklocation('index.php?new=1');
}
require_once(AK_ROOT.'install/custom.config.php');
$template_path = $themekey;
createconfig(array('template_path' => $themekey));
ak_copy(AK_ROOT.'install/trunk', FORE_ROOT);
ak_copy(AK_ROOT.'install/templates', AK_ROOT.'configs/templates/'.$themekey);
ak_copy(AK_ROOT.'install/systemplates', AK_ROOT.'configs/templates');
ak_copy(AK_ROOT.'install/configs', AK_ROOT.'configs');
if(file_exists(AK_ROOT.'install/apps')) ak_copy(AK_ROOT.'install/apps', AK_ROOT.'apps');
$dbsize = filesize(AK_ROOT.'install/db/db.ak');
setcache('_themedbsize', $dbsize);
setcache('_themedboffset', 0);
setcache('_themedbbatch', 0);
noinstalltemplate();
deletecache('categoryselect');
aklocation('index.php?file=theme&action=frame&r='.random(6));
} elseif($action == 'importdb') {
$dbsize = getcache('_themedbsize');
$dboffset = getcache('_themedboffset');
$dbbatch = getcache('_themedbbatch');
$fp = fopen(AK_ROOT.'install/db/db.ak', 'r');
fseek($fp, $dboffset);
while(!feof($fp)) {
$row = fgets($fp, 1024000);
$dboffset = ftell($fp);
setcache('_themedboffset', $dboffset);
if($row == '') continue;
$value = unserialize(base64_decode($row));
if(empty($value)) continue;
if($value['table'] == 'categories' || $value['table'] == 'modules') {
$db->replaceinto($value['table'], $value['value'], 'id');
} elseif($value['table'] == 'settings') {
$db->replaceinto('settings', $value['value'], 'variable');
} else {
$db->insert($value['table'], $value['value']);
}
if($dboffset >= $dbbatch) {
if($dboffset >= $dbsize) break;
setcache('_themedbbatch', $dbbatch + 100000);
$percent = nb($dboffset * 100/ $dbsize);
fclose($fp);
aexit($percent."\t0\t".nb($dboffset / 1024).'KB');
}
}
fclose($fp);
setsetting('theme', $template_path);
deletecache('_themedbbatch');
deletecache('_themedboffset');
updatecache();
aexit('100');
} elseif($action == 'themeinstall') {
if(!file_exists(AK_ROOT.'install/install.php')) adminmsg($lan['importsuccess'], 'index.php?file=theme&action=finish&r='.random(6));
require(AK_ROOT.'install/install.php');
} elseif($action == 'finish') {
noinstalltemplate();
finishtheme();
themeinstalled();
updatecache();
aklocation("index.php");
}
function downloadtheme($theme, $cdkey = '') {
global $charset;
$themefile = $theme.'.akp';
$themepath = CORE_ROOT.'install/';
$downloadurl = 'http://www.akhtm.com/akcms_soft.php?action=download&key='.$theme.'&r='.random(6).'&charset='.$charset;
if(isset($cdkey)) $downloadurl.='&cdkey='.$cdkey;
$result = readfromurl($downloadurl);
if($result == '') return false;
if(!is_dir($themepath)) ak_mkdir($themepath);
writetofile($result, $themepath.$themefile);
if(!is_dir($themepath.$theme)) ak_mkdir($themepath.$theme);
unzip($themepath.$themefile, $themepath);
akunlink($themepath.$themefile);
return true;
}
function clearfiles() {
akunlink(AK_ROOT.'configs/cphook.php');
akunlink(AK_ROOT.'configs/forehook.php');
akunlink(AK_ROOT.'configs/appmenu.php');
akunlink(AK_ROOT.'configs/custom.menu.xml');
ak_rmdir(AK_ROOT.'configs/apps/_dependhook/');
ak_rmdir(AK_ROOT.'configs/hooks');
ak_rmdir(AK_ROOT.'cache/');
ak_rmdir(AK_ROOT.'configs/apps/');
ak_rmdir(AK_ROOT.'configs/images');
ak_rmdir(AK_ROOT.'configs/language');
emptyfileindir(AK_ROOT.'configs/templates/ak/');
}
?>