From bcbdf58376c21a6a4e210f66d29064bf0bac2f8a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 24 Jul 2018 19:41:35 +0200 Subject: [PATCH] Prefix all global vars --- app.php | 10 +++++----- controllers/BaseController.php | 2 +- helpers/UrlManager.php | 2 +- helpers/extensions.php | 8 ++++---- middleware/SessionAuthMiddleware.php | 10 +++++----- services/ApplicationService.php | 2 +- services/BaseService.php | 2 +- services/DatabaseService.php | 2 +- services/DemoDataGeneratorService.php | 4 ++-- services/LocalizationService.php | 4 ++-- services/StockService.php | 4 ++-- views/layout/default.blade.php | 14 +++++++------- views/openapiui.blade.php | 4 ++-- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app.php b/app.php index 7e2c48db..10a3a65e 100644 --- a/app.php +++ b/app.php @@ -8,15 +8,15 @@ use \Grocy\Controllers\LoginController; if (file_exists(__DIR__ . '/embedded.txt')) { - define('DATAPATH', file_get_contents(__DIR__ . '/embedded.txt')); + define('GROCY_DATAPATH', file_get_contents(__DIR__ . '/embedded.txt')); } else { - define('DATAPATH', __DIR__ . '/data'); + define('GROCY_DATAPATH', __DIR__ . '/data'); } require_once __DIR__ . '/vendor/autoload.php'; -require_once DATAPATH . '/config.php'; +require_once GROCY_DATAPATH . '/config.php'; require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones // Setup base application @@ -27,7 +27,7 @@ $appContainer = new \Slim\Container([ ], 'view' => function($container) { - return new \Slim\Views\Blade(__DIR__ . '/views', DATAPATH . '/viewcache'); + return new \Slim\Views\Blade(__DIR__ . '/views', GROCY_DATAPATH . '/viewcache'); }, 'LoginControllerInstance' => function($container) { @@ -35,7 +35,7 @@ $appContainer = new \Slim\Container([ }, 'UrlManager' => function($container) { - return new UrlManager(BASE_URL); + return new UrlManager(GROCY_BASE_URL); }, 'ApiKeyHeaderName' => function($container) { diff --git a/controllers/BaseController.php b/controllers/BaseController.php index 47853f2c..6ba1da22 100644 --- a/controllers/BaseController.php +++ b/controllers/BaseController.php @@ -12,7 +12,7 @@ class BaseController $databaseService = new DatabaseService(); $this->Database = $databaseService->GetDbConnection(); - $localizationService = new LocalizationService(CULTURE); + $localizationService = new LocalizationService(GROCY_CULTURE); $this->LocalizationService = $localizationService; $applicationService = new ApplicationService(); diff --git a/helpers/UrlManager.php b/helpers/UrlManager.php index b7b0f765..aa5d1b9a 100644 --- a/helpers/UrlManager.php +++ b/helpers/UrlManager.php @@ -20,7 +20,7 @@ class UrlManager public function ConstructUrl($relativePath, $isResource = false) { - if (DISABLE_URL_REWRITING === false || $isResource === true) + if (GROCY_DISABLE_URL_REWRITING === false || $isResource === true) { return rtrim($this->BasePath, '/') . $relativePath; } diff --git a/helpers/extensions.php b/helpers/extensions.php index 2b551363..c000d088 100644 --- a/helpers/extensions.php +++ b/helpers/extensions.php @@ -130,17 +130,17 @@ function BoolToString(bool $bool) function Setting(string $name, $value) { - if (!defined($name)) + if (!defined('GROCY_' . $name)) { // The content of a $name.txt file in /data/settingoverrides can overwrite the given setting (for embedded mode) - $settingOverrideFile = DATAPATH . '/settingoverrides/' . $name . '.txt'; + $settingOverrideFile = GROCY_DATAPATH . '/settingoverrides/' . $name . '.txt'; if (file_exists($settingOverrideFile)) { - define($name, file_get_contents($settingOverrideFile)); + define('GROCY_' . $name, file_get_contents($settingOverrideFile)); } else { - define($name, $value); + define('GROCY_' . $name, $value); } } } diff --git a/middleware/SessionAuthMiddleware.php b/middleware/SessionAuthMiddleware.php index e10b6a0f..5324994d 100644 --- a/middleware/SessionAuthMiddleware.php +++ b/middleware/SessionAuthMiddleware.php @@ -24,9 +24,9 @@ class SessionAuthMiddleware extends BaseMiddleware { if ($this->ApplicationService->IsDemoInstallation() || $this->ApplicationService->IsEmbeddedInstallation()) { - define('AUTHENTICATED', true); + define('GROCY_AUTHENTICATED', true); - $localizationService = new LocalizationService(CULTURE); + $localizationService = new LocalizationService(GROCY_CULTURE); define('GROCY_USER_USERNAME', $localizationService->Localize('Demo User')); define('GROCY_USER_ID', -1); } @@ -38,7 +38,7 @@ class SessionAuthMiddleware extends BaseMiddleware $sessionService = new SessionService(); if ((!isset($_COOKIE[$this->SessionCookieName]) || !$sessionService->IsValidSession($_COOKIE[$this->SessionCookieName])) && $routeName !== 'login') { - define('AUTHENTICATED', false); + define('GROCY_AUTHENTICATED', false); $response = $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl('/login')); } else @@ -46,13 +46,13 @@ class SessionAuthMiddleware extends BaseMiddleware if ($routeName !== 'login') { $user = $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]); - define('AUTHENTICATED', true); + define('GROCY_AUTHENTICATED', true); define('GROCY_USER_USERNAME', $user->username); define('GROCY_USER_ID', $user->id); } else { - define('AUTHENTICATED', false); + define('GROCY_AUTHENTICATED', false); } $response = $next($request, $response); diff --git a/services/ApplicationService.php b/services/ApplicationService.php index d92c4acd..4895b3b2 100644 --- a/services/ApplicationService.php +++ b/services/ApplicationService.php @@ -9,7 +9,7 @@ class ApplicationService extends BaseService */ public function IsDemoInstallation() { - return file_exists(DATAPATH . '/demo.txt'); + return file_exists(GROCY_DATAPATH . '/demo.txt'); } /** diff --git a/services/BaseService.php b/services/BaseService.php index 43c0af4e..cc6afeeb 100644 --- a/services/BaseService.php +++ b/services/BaseService.php @@ -11,7 +11,7 @@ class BaseService $this->DatabaseService = new DatabaseService(); $this->Database = $this->DatabaseService->GetDbConnection(); - $localizationService = new LocalizationService(CULTURE); + $localizationService = new LocalizationService(GROCY_CULTURE); $this->LocalizationService = $localizationService; } diff --git a/services/DatabaseService.php b/services/DatabaseService.php index f3d25102..dc726d87 100644 --- a/services/DatabaseService.php +++ b/services/DatabaseService.php @@ -14,7 +14,7 @@ class DatabaseService { if ($this->DbConnectionRaw == null) { - $pdo = new \PDO('sqlite:' . DATAPATH . '/grocy.db'); + $pdo = new \PDO('sqlite:' . GROCY_DATAPATH . '/grocy.db'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->DbConnectionRaw = $pdo; } diff --git a/services/DemoDataGeneratorService.php b/services/DemoDataGeneratorService.php index 2afd57d8..03a68e4b 100644 --- a/services/DemoDataGeneratorService.php +++ b/services/DemoDataGeneratorService.php @@ -8,7 +8,7 @@ class DemoDataGeneratorService extends BaseService { public function PopulateDemoData() { - $localizationService = new LocalizationService(CULTURE); + $localizationService = new LocalizationService(GROCY_CULTURE); $rowCount = $this->DatabaseService->ExecuteDbQuery('SELECT COUNT(*) FROM migrations WHERE migration = -1')->fetchColumn(); if (intval($rowCount) === 0) @@ -125,7 +125,7 @@ class DemoDataGeneratorService extends BaseService public function RecreateDemo() { - unlink(DATAPATH . '/grocy.db'); + unlink(GROCY_DATAPATH . '/grocy.db'); $this->PopulateDemoData(); } } diff --git a/services/LocalizationService.php b/services/LocalizationService.php index f8b6f40e..35f4789a 100644 --- a/services/LocalizationService.php +++ b/services/LocalizationService.php @@ -36,7 +36,7 @@ class LocalizationService private function LogMissingLocalization(string $culture, string $text) { - $file = DATAPATH . "/missing_translations_$culture.json"; + $file = GROCY_DATAPATH . "/missing_translations_$culture.json"; $missingTranslations = array(); if (file_exists($file)) @@ -57,7 +57,7 @@ class LocalizationService public function Localize(string $text, ...$placeholderValues) { - if (MODE === 'dev') + if (GROCY_MODE === 'dev') { if (!array_key_exists($text, $this->StringsDefaultCulture)) { diff --git a/services/StockService.php b/services/StockService.php index 4b419944..9f545eb1 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -216,13 +216,13 @@ class StockService extends BaseService private function LoadBarcodeLookupPlugin() { - $pluginName = defined('STOCK_BARCODE_LOOKUP_PLUGIN') ? STOCK_BARCODE_LOOKUP_PLUGIN : ''; + $pluginName = defined('GROCY_STOCK_BARCODE_LOOKUP_PLUGIN') ? GROCY_STOCK_BARCODE_LOOKUP_PLUGIN : ''; if (empty($pluginName)) { throw new \Exception('No barcode lookup plugin defined'); } - $path = DATAPATH . "/plugins/$pluginName.php"; + $path = GROCY_DATAPATH . "/plugins/$pluginName.php"; if (file_exists($path)) { require_once $path; diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 4241b167..8035a4a8 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -1,5 +1,5 @@ - + @@ -28,8 +28,8 @@ @stack('pageStyles') - @if(file_exists(DATAPATH . '/custom_css.html')) - @php include DATAPATH . '/custom_css.html' @endphp + @if(file_exists(GROCY_DATAPATH . '/custom_css.html')) + @php include GROCY_DATAPATH . '/custom_css.html' @endphp @endif @@ -164,7 +164,7 @@