forked from MitanOmar/plugins_updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_check_plugins_update.php
141 lines (115 loc) · 4.63 KB
/
p_check_plugins_update.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
<?php
// not for directly open
if (!defined('IN_ADMIN'))
{
exit();
}
require_once dirname(__FILE__).'/functions.php';
$stylee = "check_plugin_update";
$styleePath = dirname(__FILE__);
$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general'));
$update_link = $config['siteurl'] . 'install/update.php?lang=' . $config['language'];
if ($current_smt == "check"):
$continue = true;
if(class_exists('ZipArchive'))
{
if(($config['plgupdt_lastcheck'] > 0 && time() - intval($config['plgupdt_lastcheck']) > 3600 * 24)
|| ! file_exists(PATH . 'cache/kleeja-master.zip'))
{
if(file_exists(PATH . 'cache/kleeja-master.zip'))
{
kleeja_unlink(PATH . 'cache/kleeja-master.zip');
delete_plugin_folder(PATH . 'cache/kleeja-master');
}
fetch_remote_file('https://github.com/awssat/kleeja/archive/master.zip', PATH . 'cache/kleeja-master.zip', 60, false, 10, true);
if(! file_exists(PATH . 'cache/kleeja-master.zip'))
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = $olang['ERR_CONN'];
$continue = false;
}
if($continue):
$zip = new ZipArchive;
if ($zip->open(PATH . 'cache/kleeja-master.zip') === true)
{
if(! $zip->extractTo(PATH . 'cache'))
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = sprintf($lang['EXTRACT_ZIP_FAILED'], 'cache');
$continue = false;
}
update_config('plgupdt_lastcheck', time());
$zip->close();
}
else
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = sprintf($lang['EXTRACT_ZIP_FAILED'], 'cache');
$continue = false;
}
endif;
}
}
else
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = $lang['NO_ZIP_ARCHIVE'];
$continue = false;
}
if($continue):
if (! file_exists(PATH . 'cache/kleeja-master/index.php'))
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = $olang['ERR_CONN'];
}
else
{
$current_plugins = get_plugins_list("../" . KLEEJA_PLUGINS_FOLDER);
$check_result = check_plugin_version($current_plugins);
$adminAjaxContent = $check_result;
}
endif;
//show
elseif ($current_smt == "general"):
//nothing ...
// update plugin
elseif($current_smt == "update" && ig('plugin')):
$plugin = g('plugin');
if(file_exists(PATH . 'cache/kleeja-master/plugins/' . $plugin . '/init.php'))
{
if (file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '/init.php'))
{
rename(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin, PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin.'_copy');
if(file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '/init.php'))
{
delete_plugin_folder(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin);
}
copy_plugin_folder(
PATH . 'cache/kleeja-master/plugins/' . $plugin,
PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin
);
if(file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '/init.php'))
{
delete_plugin_folder(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '_copy');
$adminAjaxContent = htmlspecialchars($plugin) . ': ' . $olang['PLG_UPDT_SUCCESS'];
}
else if(file_exists(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '_copy/init.php'))
{
rename(PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin . '_copy', PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin);
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = htmlspecialchars($plugin) . ': '. $olang['PLG_UPDT_ERROR'];
}
}
else
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = htmlspecialchars($plugin) . ': ' . $olang['NOT_U_PLG'];
}
}
// the plugin is not hosted in kleeja , I'm scared to make this option :(
else
{
header('HTTP/1.1 500 Internal Server Error');
$adminAjaxContent = htmlspecialchars($plugin) . ': ' . $olang['NOT_KLEEJA_GIT_PLG'];
}
endif;