mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Prefix all global vars
This commit is contained in:
parent
7f8540ff4e
commit
bcbdf58376
10
app.php
10
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)
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -9,7 +9,7 @@ class ApplicationService extends BaseService
|
||||
*/
|
||||
public function IsDemoInstallation()
|
||||
{
|
||||
return file_exists(DATAPATH . '/demo.txt');
|
||||
return file_exists(GROCY_DATAPATH . '/demo.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ CULTURE }}">
|
||||
<html lang="{{ GROCY_CULTURE }}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
@ -28,8 +28,8 @@
|
||||
<link href="{{ $U('/css/grocy.css?v=', true) }}{{ $version }}" rel="stylesheet">
|
||||
@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
|
||||
|
||||
<script>
|
||||
@ -38,7 +38,7 @@
|
||||
Grocy.BaseUrl = '{{ $U('/') }}';
|
||||
Grocy.LocalizationStrings = {!! json_encode($localizationStrings) !!};
|
||||
Grocy.ActiveNav = '@yield('activeNav', '')';
|
||||
Grocy.Culture = '{{ CULTURE }}';
|
||||
Grocy.Culture = '{{ GROCY_CULTURE }}';
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@ -164,7 +164,7 @@
|
||||
</ul>
|
||||
|
||||
<ul class="navbar-nav ml-auto">
|
||||
@if(AUTHENTICATED === true && $isEmbeddedInstallation === false)
|
||||
@if(GROCY_AUTHENTICATED === true && $isEmbeddedInstallation === false)
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle discrete-link" href="#" data-toggle="dropdown"><i class="fas fa-user"></i> {{ GROCY_USER_USERNAME }}</a>
|
||||
|
||||
@ -256,8 +256,8 @@
|
||||
@stack('componentScripts')
|
||||
<script src="{{ $U('/viewjs', true) }}/@yield('viewJsName').js?v={{ $version }}"></script>
|
||||
|
||||
@if(file_exists(DATAPATH . '/custom_js.html'))
|
||||
@php include DATAPATH . '/custom_js.html' @endphp
|
||||
@if(file_exists(GROCY_DATAPATH . '/custom_js.html'))
|
||||
@php include GROCY_DATAPATH . '/custom_js.html' @endphp
|
||||
@endif
|
||||
</body>
|
||||
|
||||
|
@ -30,8 +30,8 @@
|
||||
<script src="{{ $U('/node_modules/swagger-ui-dist/swagger-ui-standalone-preset.js?v=', true) }}{{ $version }}"></script>
|
||||
<script src="{{ $U('/viewjs', true) }}/openapiui.js?v={{ $version }}"></script>
|
||||
|
||||
@if(file_exists(DATAPATH . '/add_before_end_body.html'))
|
||||
@php include DATAPATH . '/add_before_end_body.html' @endphp
|
||||
@if(file_exists(GROCY_DATAPATH . '/add_before_end_body.html'))
|
||||
@php include GROCY_DATAPATH . '/add_before_end_body.html' @endphp
|
||||
@endif
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user