aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/ApplicationUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/ApplicationUtils.php')
-rw-r--r--application/ApplicationUtils.php75
1 files changed, 40 insertions, 35 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index a3b2dcb1..7fe3cb32 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -1,4 +1,9 @@
1<?php 1<?php
2namespace Shaarli;
3
4use Exception;
5use Shaarli\Config\ConfigManager;
6
2/** 7/**
3 * Shaarli (application) utilities 8 * Shaarli (application) utilities
4 */ 9 */
@@ -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);
@@ -97,7 +102,7 @@ class ApplicationUtils
97 // Do not check versions for visitors 102 // Do not check versions for visitors
98 // Do not check if the user doesn't want to 103 // Do not check if the user doesn't want to
99 // Do not check with dev version 104 // Do not check with dev version
100 if (! $isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') { 105 if (!$isLoggedIn || empty($enableCheck) || $currentVersion === 'dev') {
101 return false; 106 return false;
102 } 107 }
103 108
@@ -111,7 +116,7 @@ class ApplicationUtils
111 return false; 116 return false;
112 } 117 }
113 118
114 if (! in_array($branch, self::$GIT_BRANCHES)) { 119 if (!in_array($branch, self::$GIT_BRANCHES)) {
115 throw new Exception( 120 throw new Exception(
116 'Invalid branch selected for updates: "' . $branch . '"' 121 'Invalid branch selected for updates: "' . $branch . '"'
117 ); 122 );
@@ -123,7 +128,7 @@ class ApplicationUtils
123 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE 128 self::$GIT_URL . '/' . $branch . '/' . self::$VERSION_FILE
124 ); 129 );
125 130
126 if (! $latestVersion) { 131 if (!$latestVersion) {
127 // Only update the file's modification date 132 // Only update the file's modification date
128 file_put_contents($updateFile, $currentVersion); 133 file_put_contents($updateFile, $currentVersion);
129 return false; 134 return false;
@@ -152,9 +157,9 @@ class ApplicationUtils
152 if (version_compare($curVersion, $minVersion) < 0) { 157 if (version_compare($curVersion, $minVersion) < 0) {
153 $msg = t( 158 $msg = t(
154 'Your PHP version is obsolete!' 159 'Your PHP version is obsolete!'
155 . ' Shaarli requires at least PHP %s, and thus cannot run.' 160 . ' Shaarli requires at least PHP %s, and thus cannot run.'
156 . ' Your PHP version has known security vulnerabilities and should be' 161 . ' Your PHP version has known security vulnerabilities and should be'
157 . ' updated as soon as possible.' 162 . ' updated as soon as possible.'
158 ); 163 );
159 throw new Exception(sprintf($msg, $minVersion)); 164 throw new Exception(sprintf($msg, $minVersion));
160 } 165 }
@@ -174,50 +179,50 @@ class ApplicationUtils
174 179
175 // Check script and template directories are readable 180 // Check script and template directories are readable
176 foreach (array( 181 foreach (array(
177 'application', 182 'application',
178 'inc', 183 'inc',
179 'plugins', 184 'plugins',
180 $rainTplDir, 185 $rainTplDir,
181 $rainTplDir.'/'.$conf->get('resource.theme'), 186 $rainTplDir . '/' . $conf->get('resource.theme'),
182 ) as $path) { 187 ) as $path) {
183 if (! is_readable(realpath($path))) { 188 if (!is_readable(realpath($path))) {
184 $errors[] = '"'.$path.'" '. t('directory is not readable'); 189 $errors[] = '"' . $path . '" ' . t('directory is not readable');
185 } 190 }
186 } 191 }
187 192
188 // Check cache and data directories are readable and writable 193 // Check cache and data directories are readable and writable
189 foreach (array( 194 foreach (array(
190 $conf->get('resource.thumbnails_cache'), 195 $conf->get('resource.thumbnails_cache'),
191 $conf->get('resource.data_dir'), 196 $conf->get('resource.data_dir'),
192 $conf->get('resource.page_cache'), 197 $conf->get('resource.page_cache'),
193 $conf->get('resource.raintpl_tmp'), 198 $conf->get('resource.raintpl_tmp'),
194 ) as $path) { 199 ) as $path) {
195 if (! is_readable(realpath($path))) { 200 if (!is_readable(realpath($path))) {
196 $errors[] = '"'.$path.'" '. t('directory is not readable'); 201 $errors[] = '"' . $path . '" ' . t('directory is not readable');
197 } 202 }
198 if (! is_writable(realpath($path))) { 203 if (!is_writable(realpath($path))) {
199 $errors[] = '"'.$path.'" '. t('directory is not writable'); 204 $errors[] = '"' . $path . '" ' . t('directory is not writable');
200 } 205 }
201 } 206 }
202 207
203 // Check configuration files are readable and writable 208 // Check configuration files are readable and writable
204 foreach (array( 209 foreach (array(
205 $conf->getConfigFileExt(), 210 $conf->getConfigFileExt(),
206 $conf->get('resource.datastore'), 211 $conf->get('resource.datastore'),
207 $conf->get('resource.ban_file'), 212 $conf->get('resource.ban_file'),
208 $conf->get('resource.log'), 213 $conf->get('resource.log'),
209 $conf->get('resource.update_check'), 214 $conf->get('resource.update_check'),
210 ) as $path) { 215 ) as $path) {
211 if (! is_file(realpath($path))) { 216 if (!is_file(realpath($path))) {
212 # the file may not exist yet 217 # the file may not exist yet
213 continue; 218 continue;
214 } 219 }
215 220
216 if (! is_readable(realpath($path))) { 221 if (!is_readable(realpath($path))) {
217 $errors[] = '"'.$path.'" '. t('file is not readable'); 222 $errors[] = '"' . $path . '" ' . t('file is not readable');
218 } 223 }
219 if (! is_writable(realpath($path))) { 224 if (!is_writable(realpath($path))) {
220 $errors[] = '"'.$path.'" '. t('file is not writable'); 225 $errors[] = '"' . $path . '" ' . t('file is not writable');
221 } 226 }
222 } 227 }
223 228