platform.php
3.42 KB
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
<?php
class N2Platform {
public static $isAdmin = false;
public static $hasPosts = true, $isJoomla = false, $isWordpress = false, $isMagento = false, $isNative = false;
public static $name;
public static function init() {
self::$isJoomla = JVERSION;
if (JFactory::getApplication()
->isAdmin()
) {
self::$isAdmin = true;
}
}
public static function getPlatform() {
return 'joomla';
}
public static function getPlatformName() {
return 'Joomla';
}
public static function getDate() {
$config = JFactory::getConfig();
return JFactory::getDate('now', $config->get('offset'))
->toSql(true);
}
public static function getTime() {
return strtotime(N2Platform::getDate());
}
public static function getPublicDir() {
if (defined('JPATH_MEDIA')) {
return JPATH_SITE . JPATH_MEDIA;
}
return JPATH_SITE . '/media';
}
public static function getUserEmail() {
return JFactory::getUser()->email;
}
public static function adminHideCSS() {
echo '
/*
Joomla 3
*/
.navbar{
display: none;
}
.container-fluid{
padding: 0;
}
.admin #content{
margin: 0;
}
/**
Joomla 2.5
*/
body,
#element-box,
div#element-box div.m{
margin: 0;
padding: 0;
}
#border-top,
#header-box{
display: none;
}
#content-box{
border: 0;
width: 100%;
}
#element-box div.m{
border: 0;
background: transparent;
}
';
}
public static function updateFromZip($fileRaw, $updateInfo) {
N2Loader::import('libraries.zip.reader');
$tmpHandle = tmpfile();
fwrite($tmpHandle, $fileRaw);
$metaData = stream_get_meta_data($tmpHandle);
$tmpFilename = $metaData['uri'];
$files = N2ZipReader::read($tmpFilename);
$updateFolder = N2Filesystem::getNotWebCachePath() . '/update/';
self::recursive_extract($files, $updateFolder);
fclose($tmpHandle);
$installer = JInstaller::getInstance();
$installer->setOverwrite(true);
if (!$installer->install($updateFolder)) {
N2Filesystem::deleteFolder($updateFolder);
return false;
}
N2Filesystem::deleteFolder($updateFolder);
return true;
}
private static function recursive_extract($files, $targetFolder) {
foreach ($files AS $fileName => $file) {
if(empty($fileName) || $fileName == '.' || $fileName == '..') continue;
if (is_array($file)) {
if (N2Filesystem::createFolder($targetFolder . $fileName . '/')) {
self::recursive_extract($file, $targetFolder . $fileName . '/');
} else {
return false;
}
} else {
if (!N2Filesystem::createFile($targetFolder . $fileName, $file)) {
return false;
}
}
}
return true;
}
}
N2Platform::init();