diff options
Diffstat (limited to 'application/ApplicationUtils.php')
-rw-r--r-- | application/ApplicationUtils.php | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index 911873a0..7fe3cb32 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php | |||
@@ -1,4 +1,9 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli; | ||
3 | |||
4 | use Exception; | ||
5 | use Shaarli\Config\ConfigManager; | ||
6 | |||
2 | /** | 7 | /** |
3 | * Shaarli (application) utilities | 8 | * Shaarli (application) utilities |
4 | */ | 9 | */ |
@@ -24,7 +29,7 @@ class ApplicationUtils | |||
24 | * | 29 | * |
25 | * @return mixed the version code from the repository if available, else 'false' | 30 | * @return mixed the version code from the repository if available, else 'false' |
26 | */ | 31 | */ |
27 | public static function getLatestGitVersionCode($url, $timeout=2) | 32 | public static function getLatestGitVersionCode($url, $timeout = 2) |
28 | { | 33 | { |
29 | list($headers, $data) = get_http_response($url, $timeout); | 34 | list($headers, $data) = get_http_response($url, $timeout); |
30 | 35 | ||
@@ -51,7 +56,7 @@ class ApplicationUtils | |||
51 | return false; | 56 | return false; |
52 | } | 57 | } |
53 | } else { | 58 | } else { |
54 | if (! is_file($remote)) { | 59 | if (!is_file($remote)) { |
55 | return false; | 60 | return false; |
56 | } | 61 | } |
57 | $data = file_get_contents($remote); | 62 | $data = file_get_contents($remote); |
@@ -86,17 +91,18 @@ class ApplicationUtils | |||
86 | * | 91 | * |
87 | * @return mixed the new version code if available and greater, else 'false' | 92 | * @return mixed the new version code if available and greater, else 'false' |
88 | */ | 93 | */ |
89 | public static function checkUpdate($currentVersion, | 94 | public static function checkUpdate( |
90 | $updateFile, | 95 | $currentVersion, |
91 | $checkInterval, | 96 | $updateFile, |
92 | $enableCheck, | 97 | $checkInterval, |
93 | $isLoggedIn, | 98 | $enableCheck, |
94 | $branch='stable') | 99 | $isLoggedIn, |
95 | { | 100 | $branch = 'stable' |
101 | ) { | ||
96 | // Do not check versions for visitors | 102 | // Do not check versions for visitors |
97 | // Do not check if the user doesn't want to | 103 | // Do not check if the user doesn't want to |
98 | // Do not check with dev version | 104 | // Do not check with dev version |
99 | if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { | 105 | if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { |
100 | return false; | 106 | return false; |
101 | } | 107 | } |
102 | 108 | ||
@@ -110,7 +116,7 @@ class ApplicationUtils | |||
110 | return false; | 116 | return false; |
111 | } | 117 | } |
112 | 118 | ||
113 | if (! in_array($branch, self::$GIT_BRANCHES)) { | 119 | if (!in_array($branch, self::$GIT_BRANCHES)) { |
114 | throw new Exception( | 120 | throw new Exception( |
115 | 'Invalid branch selected for updates: "' . $branch . '"' | 121 | 'Invalid branch selected for updates: "' . $branch . '"' |
116 | ); | 122 | ); |
@@ -122,7 +128,7 @@ class ApplicationUtils | |||
122 | self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE | 128 | self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE |
123 | ); | 129 | ); |
124 | 130 | ||
125 | if (! $latestVersion) { | 131 | if (!$latestVersion) { |
126 | // Only update the file's modification date | 132 | // Only update the file's modification date |
127 | file_put_contents($updateFile, $currentVersion); | 133 | file_put_contents($updateFile, $currentVersion); |
128 | return false; | 134 | return false; |
@@ -151,9 +157,9 @@ class ApplicationUtils | |||
151 | if (version_compare($curVersion, $minVersion) < 0) { | 157 | if (version_compare($curVersion, $minVersion) < 0) { |
152 | $msg = t( | 158 | $msg = t( |
153 | 'Your PHP version is obsolete!' | 159 | 'Your PHP version is obsolete!' |
154 | . ' Shaarli requires at least PHP %s, and thus cannot run.' | 160 | . ' Shaarli requires at least PHP %s, and thus cannot run.' |
155 | . ' Your PHP version has known security vulnerabilities and should be' | 161 | . ' Your PHP version has known security vulnerabilities and should be' |
156 | . ' updated as soon as possible.' | 162 | . ' updated as soon as possible.' |
157 | ); | 163 | ); |
158 | throw new Exception(sprintf($msg, $minVersion)); | 164 | throw new Exception(sprintf($msg, $minVersion)); |
159 | } | 165 | } |
@@ -173,50 +179,50 @@ class ApplicationUtils | |||
173 | 179 | ||
174 | // Check script and template directories are readable | 180 | // Check script and template directories are readable |
175 | foreach (array( | 181 | foreach (array( |
176 | 'application', | 182 | 'application', |
177 | 'inc', | 183 | 'inc', |
178 | 'plugins', | 184 | 'plugins', |
179 | $rainTplDir, | 185 | $rainTplDir, |
180 | $rainTplDir.'/'.$conf->get('resource.theme'), | 186 | $rainTplDir . '/' . $conf->get('resource.theme'), |
181 | ) as $path) { | 187 | ) as $path) { |
182 | if (! is_readable(realpath($path))) { | 188 | if (!is_readable(realpath($path))) { |
183 | $errors[] = '"'.$path.'" '. t('directory is not readable'); | 189 | $errors[] = '"' . $path . '" ' . t('directory is not readable'); |
184 | } | 190 | } |
185 | } | 191 | } |
186 | 192 | ||
187 | // Check cache and data directories are readable and writable | 193 | // Check cache and data directories are readable and writable |
188 | foreach (array( | 194 | foreach (array( |
189 | $conf->get('resource.thumbnails_cache'), | 195 | $conf->get('resource.thumbnails_cache'), |
190 | $conf->get('resource.data_dir'), | 196 | $conf->get('resource.data_dir'), |
191 | $conf->get('resource.page_cache'), | 197 | $conf->get('resource.page_cache'), |
192 | $conf->get('resource.raintpl_tmp'), | 198 | $conf->get('resource.raintpl_tmp'), |
193 | ) as $path) { | 199 | ) as $path) { |
194 | if (! is_readable(realpath($path))) { | 200 | if (!is_readable(realpath($path))) { |
195 | $errors[] = '"'.$path.'" '. t('directory is not readable'); | 201 | $errors[] = '"' . $path . '" ' . t('directory is not readable'); |
196 | } | 202 | } |
197 | if (! is_writable(realpath($path))) { | 203 | if (!is_writable(realpath($path))) { |
198 | $errors[] = '"'.$path.'" '. t('directory is not writable'); | 204 | $errors[] = '"' . $path . '" ' . t('directory is not writable'); |
199 | } | 205 | } |
200 | } | 206 | } |
201 | 207 | ||
202 | // Check configuration files are readable and writable | 208 | // Check configuration files are readable and writable |
203 | foreach (array( | 209 | foreach (array( |
204 | $conf->getConfigFileExt(), | 210 | $conf->getConfigFileExt(), |
205 | $conf->get('resource.datastore'), | 211 | $conf->get('resource.datastore'), |
206 | $conf->get('resource.ban_file'), | 212 | $conf->get('resource.ban_file'), |
207 | $conf->get('resource.log'), | 213 | $conf->get('resource.log'), |
208 | $conf->get('resource.update_check'), | 214 | $conf->get('resource.update_check'), |
209 | ) as $path) { | 215 | ) as $path) { |
210 | if (! is_file(realpath($path))) { | 216 | if (!is_file(realpath($path))) { |
211 | # the file may not exist yet | 217 | # the file may not exist yet |
212 | continue; | 218 | continue; |
213 | } | 219 | } |
214 | 220 | ||
215 | if (! is_readable(realpath($path))) { | 221 | if (!is_readable(realpath($path))) { |
216 | $errors[] = '"'.$path.'" '. t('file is not readable'); | 222 | $errors[] = '"' . $path . '" ' . t('file is not readable'); |
217 | } | 223 | } |
218 | if (! is_writable(realpath($path))) { | 224 | if (!is_writable(realpath($path))) { |
219 | $errors[] = '"'.$path.'" '. t('file is not writable'); | 225 | $errors[] = '"' . $path . '" ' . t('file is not writable'); |
220 | } | 226 | } |
221 | } | 227 | } |
222 | 228 | ||