$templates,
[
'cache' => rtrim(GALETTE_CACHE_DIR, DIRECTORY_SEPARATOR),
- 'debug' => (GALETTE_MODE === \Galette\Core\Galette::MODE_DEV),
- 'strict_variables' => (GALETTE_MODE == \Galette\Core\Galette::MODE_DEV)
+ 'debug' => \Galette\Core\Galette::isDebugEnabled(),
+ 'strict_variables' => \Galette\Core\Galette::isDebugEnabled()
]
);
//Twig extensions
$view->addExtension(new \Galette\Twig\CsrfExtension($c->get('csrf')));
- if (GALETTE_MODE === \Galette\Core\Galette::MODE_DEV) {
+ if (\Galette\Core\Galette::isDebugEnabled()) {
$view->addExtension(new \Twig\Extension\DebugExtension());
}
//End Twig extensions
$galette_run_log = null;
if (!defined('GALETTE_LOG_LVL')) {
- if (GALETTE_MODE === 'DEV') {
+ if (\Galette\Core\Galette::isDebugEnabled()) {
define('GALETTE_LOG_LVL', Analog::DEBUG);
} elseif (defined('GALETTE_TESTS')) {
define('GALETTE_LOG_LVL', Analog::NOTICE);
*
* PHP version 5
*
- * Copyright © 2003-2020 The Galette Team
+ * Copyright © 2003-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* @author Frédéric Jacquot <unknown@unknow.com>
* @author Georges Khaznadar (i18n using gettext) <unknown@unknow.com>
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2003-2020 The Galette Team
+ * @copyright 2003-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.62
}
use Analog\Analog;
-use Laminas\Db\Sql\Expression;
-use Galette\Core\L10n;
+use Galette\Core\Galette;
$i18n->updateEnv();
global $language;
if (!$trans) {
$trans = $string;
- if (GALETTE_MODE == 'DEV' && $nt === true) {
+ if (Galette::isDebugEnabled() && $nt === true) {
$trans .= ' (not translated)';
}
}
if (!$trans) {
$trans = ($count > 1 ? $plural : $singular);
- if (GALETTE_MODE == 'DEV' && $nt === true) {
+ if (Galette::isDebugEnabled() && $nt === true) {
$trans .= ' (not translated)';
}
}
if (!$trans) {
$trans = $ret;
- if (GALETTE_MODE == 'DEV' && $nt === true) {
+ if (Galette::isDebugEnabled() && $nt === true) {
$trans .= ' (not translated)';
}
}
if (!$trans) {
$trans = $ret;
- if (GALETTE_MODE == 'DEV' && $nt === true) {
+ if (Galette::isDebugEnabled() && $nt === true) {
$trans .= ' (not translated)';
}
}
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(
- (GALETTE_MODE === 'DEV'),
+ Galette::isDebugEnabled(),
true,
true
);
namespace Galette\Controllers\Crud;
+use Galette\Core\Galette;
use Galette\IO\File;
use Galette\Repository\DynamicFieldsSet;
use Throwable;
$e->getMessage(),
Analog::ERROR
);
- if (GALETTE_MODE == 'DEV') {
+ if (Galette::isDebugEnabled()) {
throw $e;
}
$error_detected[] = _T('An error occurred adding dynamic field :(');
$e->getMessage(),
Analog::ERROR
);
- if (GALETTE_MODE == 'DEV') {
+ if (Galette::isDebugEnabled()) {
throw $e;
}
$error_detected[] = _T('An error occurred editing dynamic field :(');
if (
$this->preferences->pref_mail_method == Mailing::METHOD_DISABLED
- && !(GALETTE_MODE === Galette::MODE_DEMO)
+ && !Galette::isDemo()
) {
$this->history->add(
_T("Trying to load mailing while email is disabled in preferences.")
if (
$this->preferences->pref_mail_method == Mailing::METHOD_DISABLED
- && !(GALETTE_MODE === Galette::MODE_DEMO)
+ && !Galette::isDemo()
) {
$this->history->add(
_T("Trying to load mailing while email is disabled in preferences.")
'pref_card_vspace' => 1
);
- if ($this->login->isSuperAdmin() && GALETTE_MODE !== Galette::MODE_DEMO) {
+ if ($this->login->isSuperAdmin() && !Galette::isDemo()) {
$required['pref_admin_login'] = 1;
}
$warning_detected = array_merge($warning_detected, $this->preferences->checkCardsSizes());
// picture upload
- if (GALETTE_MODE !== Galette::MODE_DEMO && isset($_FILES['logo'])) {
+ if (!Galette::isDemo() && isset($_FILES['logo'])) {
if ($_FILES['logo']['error'] === UPLOAD_ERR_OK) {
if ($_FILES['logo']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['logo']['tmp_name'])) {
}
}
- if (GALETTE_MODE !== Galette::MODE_DEMO && isset($post['del_logo'])) {
+ if (!Galette::isDemo() && isset($post['del_logo'])) {
if (!$this->logo->delete()) {
$error_detected[] = _T("Delete failed");
} else {
}
// Card logo upload
- if (GALETTE_MODE !== Galette::MODE_DEMO && isset($_FILES['card_logo'])) {
+ if (!Galette::isDemo() && isset($_FILES['card_logo'])) {
if ($_FILES['card_logo']['error'] === UPLOAD_ERR_OK) {
if ($_FILES['card_logo']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['card_logo']['tmp_name'])) {
}
}
- if (GALETTE_MODE !== Galette::MODE_DEMO && isset($post['del_card_logo'])) {
+ if (!Galette::isDemo() && isset($post['del_card_logo'])) {
if (!$this->print_logo->delete()) {
$error_detected[] = _T("Delete failed");
} else {
*/
public function togglePlugin(Request $request, Response $response, string $action, string $module_id): Response
{
- if (GALETTE_MODE !== Galette::MODE_DEMO) {
+ if (!Galette::isDemo()) {
$plugins = $this->plugins;
$reload_plugins = false;
if ($action == 'activate') {
*/
public function initPluginDb(Request $request, Response $response, string $id): Response
{
- if (GALETTE_MODE === Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
Analog::log(
'Trying to access plugin database initialization in DEMO mode.',
Analog::WARNING
*/
public function checkDbVersion()
{
- if (GALETTE_MODE === 'DEV') {
+ if (Galette::isDebugEnabled()) {
Analog::log(
'Database version not checked in DEV mode.',
Analog::INFO
*/
protected function log($query)
{
- if (GALETTE_MODE == 'DEV' || defined('GALETTE_SQL_DEBUG')) {
+ if (Galette::isSqlDebugEnabled()) {
$logfile = GALETTE_LOGS_PATH . 'galette_sql.log';
file_put_contents($logfile, $query . "\n", FILE_APPEND);
}
{
$galette_version = GALETTE_VERSION;
- //used for both gith and nightly installs
+ //used for both git and nightly installs
$version = str_replace('-dev', '-git', GALETTE_VERSION);
if (strstr($version, '-git') === false) {
$version .= '-git';
$commitHash,
$commitDate->format(($time ? 'Y-m-d H:i:s T' : 'Y-m-d'))
);
- } elseif (GALETTE_NIGHTLY !== false) {
+ } elseif (static::isNightly()) {
$galette_version = $version . '-' . GALETTE_NIGHTLY;
}
return $galette_version;
}
return $actions;
}
+
+ /**
+ * Is demonstration mode enabled
+ *
+ * @return bool
+ */
+ public static function isDemo(): bool
+ {
+ return GALETTE_MODE === static::MODE_DEMO;
+ }
+
+ /**
+ * Is debug mode enabled
+ *
+ * @return bool
+ */
+ public static function isDebugEnabled(): bool
+ {
+ return GALETTE_MODE === static::MODE_DEV;
+ }
+
+ /**
+ * Is SQL debug mode enabled
+ *
+ * @return bool
+ */
+ public static function isSqlDebugEnabled(): bool
+ {
+ return defined('GALETTE_SQL_DEBUG') || static::isDebugEnabled();
+ }
+
+ /**
+ * Is a nightly build
+ *
+ * @return bool
+ */
+ public static function isNightly(): bool
+ {
+ return GALETTE_NIGHTLY !== false;
+ }
}
//if we want to send emails using a smtp server
$this->mail->IsSMTP();
// enables SMTP debug information
- if (GALETTE_MODE == 'DEV') {
+ if (Galette::isDebugEnabled()) {
$this->mail->SMTPDebug = 4;
//cannot use a callable here; this prevents class to be serialized
//see https://bugs.galette.eu/issues/1468
$builder->useAttributes(true);
$builder->addDefinitions([
'templates.path' => GALETTE_ROOT . GALETTE_THEME,
- 'settings.displayErrorDetails' => (GALETTE_MODE === 'DEV'),
+ 'settings.displayErrorDetails' => Galette::isDebugEnabled(),
'settings.addContentLengthHeader' => false,
'galette' => [
'mode' => $this->mode,
public function check(array $values, Login $login)
{
$insert_values = array();
- if ($login->isSuperAdmin() && GALETTE_MODE !== Galette::MODE_DEMO) {
+ if ($login->isSuperAdmin() && !Galette::isDemo()) {
$this->required[] = 'pref_admin_login';
}
}
//cleanup fields for demo
- if (GALETTE_MODE == Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
unset(
$insert_values['pref_admin_login'],
$insert_values['pref_admin_pass'],
// missing relations
if (
- GALETTE_MODE !== Galette::MODE_DEMO
+ !Galette::isDemo()
&& isset($insert_values['pref_mail_method'])
) {
if ($insert_values['pref_mail_method'] > GaletteMail::METHOD_DISABLED) {
}
}
- if (GALETTE_MODE !== Galette::MODE_DEMO && isset($values['pref_admin_pass_check'])) {
+ if (!Galette::isDemo() && isset($values['pref_admin_pass_check'])) {
// Check passwords. Hash will be done into the Preferences class
if (strcmp($insert_values['pref_admin_pass'], $values['pref_admin_pass_check']) != 0) {
$this->errors[] = _T("Passwords mismatch");
}
break;
case 'pref_admin_login':
- if (GALETTE_MODE === Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
Analog::log(
'Trying to set superadmin login while in DEMO.',
Analog::WARNING
}
break;
case 'pref_admin_pass':
- if (GALETTE_MODE == Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
Analog::log(
'Trying to set superadmin pass while in DEMO.',
Analog::WARNING
foreach (self::$defaults as $k => $v) {
if (
- GALETTE_MODE == Galette::MODE_DEMO
+ Galette::isDemo()
&& in_array($k, ['pref_admin_pass', 'pref_admin_login', 'pref_mail_method'])
) {
continue;
if (!in_array($name, $forbidden) && isset($this->prefs[$name])) {
if (
- GALETTE_MODE === Galette::MODE_DEMO
+ Galette::isDemo()
&& $name == 'pref_mail_method'
) {
return GaletteMail::METHOD_DISABLED;
|| $name == 'pref_email_newadh'
|| $name == 'pref_email_reply_to'
) {
- if (GALETTE_MODE === Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
Analog::log(
'Trying to set pref_email while in DEMO.',
Analog::WARNING
$str = str_pad('Galette version:', 20, '.') . ' ' . \Galette\Core\Galette::gitVersion(true) . "\n";
- if (GALETTE_MODE == \Galette\Core\Galette::MODE_DEMO) {
+ if (Galette::isDemo()) {
$str .= $this->getPluginsInfo($plugins);
return $str;
}
namespace Galette\IO;
+use Galette\Core\Galette;
use Throwable;
use Analog\Analog;
$this->feed_url = $this->getFeedURL($url);
//only if cache should be used
- if ($nocache === false && GALETTE_MODE !== 'DEV') {
+ if ($nocache === false && !Galette::isDebugEnabled()) {
if (!$this->checkCache()) {
$this->makeCache();
} else {
<div class="description">
<div class="ui file action input">
<input id="photo_new" type="file" name="photo"/>
- <label for="photo_new" class="ui button{% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %} disabled{% endif %}">
+ <label for="photo_new" class="ui button{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled{% endif %}">
<i class="blue upload icon" aria-hidden="true"></i>
{% if member.hasPicture() == 1 %}{{ _T("Choose another file") }}{% else %}{{ _T("Choose a file") }}{% endif %}
</label>
{{ _T("Superadmin") }}
</span>
{% endif %}
-{% if constant('GALETTE_MODE') == 'DEMO' %}
+{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<span class="tooltip ui orange icon circular label" title="{{ _T("This application runs under DEMO mode, all features may not be available.") }}">
<i class="gamepad icon" aria-hidden="true"></i>
{{ _T("Demonstration") }}
ui: "dropdown"
} %}
- {% if constant('GALETTE_MODE') == 'DEMO' %}
+ {% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<div class="item">
{% include "elements/modes.html.twig" %}
</div>
<h2 class="ui center aligned header">{{ _T("Application error") }}</h2>
</div>
- {% if login.isLogged() and login.isAdmin() or constant('GALETTE_MODE') == 'DEV' %}
+ {% if login.isLogged() and login.isAdmin() or callstatic('\\Galette\\Core\\Galette', 'isDebugEnabled') %}
{{ _self.render_ex(exception) }}
{% endif %}
{% endblock %}
{% block content %}
<div class="ui grid">
-{% if not hide_telemetry and constant('GALETTE_MODE') != 'DEMO' %}
+{% if not hide_telemetry and not callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<div class="sixteen wide column">
<div class="ui yellow message">
<div class="header">{{ _T("Help us know about you!") }}</div>
{% extends 'page.html.twig' %}
{% block content %}
-{% if preferences.pref_mail_method == constant('Galette\\Core\\Mailing::METHOD_DISABLED') and constant('GALETTE_MODE') != 'DEMO' %}
+{% if preferences.pref_mail_method == constant('Galette\\Core\\Mailing::METHOD_DISABLED') and not callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<div id="errorbox" class="ui negative icon message">
<i class="ban icon" aria-hidden="true"></i>
<div class="content">
<i class="save green icon" aria-hidden="true"></i>
{{ _T("Save") }}
</button>
- <button type="submit" name="mailing_confirm" class="ui labeled icon button {% if constant('GALETTE_MODE') == 'DEMO' %} disabled" disabled="disabled{% endif %}">
+ <button type="submit" name="mailing_confirm" class="ui labeled icon button {% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled" disabled="disabled{% endif %}">
<i class="rocket red icon" aria-hidden="true"></i>
{{ _T("Send") }}
</button>
<i class="backward icon" aria-hidden="true"></i>
{{ _T("Modifiy mailing") }}
</button>
- <button type="submit" name="mailing_confirm"{% if constant('GALETTE_MODE') == 'DEMO' %} class="ui labeled icon button disabled" disabled="disabled"{% else %} class="ui labeled icon button"{% endif %}>
+ <button type="submit" name="mailing_confirm"{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} class="ui labeled icon button disabled" disabled="disabled"{% else %} class="ui labeled icon button"{% endif %}>
<i class="rocket icon" aria-hidden="true"></i>
{{ _T("Send") }}
</button>
{% endblock %}
{% block javascripts %}
-{% if (preferences.pref_mail_method != constant('Galette\\Core\\Mailing::METHOD_DISABLED') or constant('GALETTE_MODE') != 'DEMO') and mailing_saved is not defined %}
+{% if (preferences.pref_mail_method != constant('Galette\\Core\\Mailing::METHOD_DISABLED') or not callstatic('\\Galette\\Core\\Galette', 'isDemo')) and mailing_saved is not defined %}
{% if mailing.current_step != constant('Galette\\Core\\Mailing::STEP_SENT') %}
<script type="text/javascript">
$(function() {
{% block javascripts %}
<script type="text/javascript">
$(function() {
- {% if constant('GALETTE_MODE') == 'DEMO' %}
+ {% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
$('.initdb, a.toggleActivation').click(function(){
{% include "elements/js/modal.js.twig" with {
modal_title_twig: _T("Application runs under demo mode. This functionnality is not enabled, sorry.")|e("js"),
<div class="content">
<div class="description">
<div class="ui file action input">
- <input type="file" name="logo" id="logo_picture"{% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %} disabled="disabled"{% endif %}/>
- <label for="logo_picture" class="ui button{% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %} disabled{% endif %}">
+ <input type="file" name="logo" id="logo_picture"{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled="disabled"{% endif %}/>
+ <label for="logo_picture" class="ui button{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled{% endif %}">
<i class="blue upload icon" aria-hidden="true"></i>
{% if logo.isCustom() %}{{ _T("Choose another file") }}{% else %}{{ _T("Choose a file") }}{% endif %}
</label>
</div>
</div>{# /tab segment #}
<div class="ui{{ tab == 'mail' ? ' active' }} tab segment" data-tab="mail">
- {% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %}
+ {% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<div class="ui icon negative message">
<i class="ban icon" aria-hidden="true"></i>
<div class="content">
<div class="content">
<div class="description">
<div class="ui file action input">
- <input type="file" name="card_logo" id="card_logo"{% if constant('GALETTE_MODE') == constant('Galette\\Core\\Galette::MODE_DEMO') %} disabled="disabled"{% endif %}/>
- <label for="card_logo" class="ui button{% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %} disabled{% endif %}">
+ <input type="file" name="card_logo" id="card_logo"{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled="disabled"{% endif %}/>
+ <label for="card_logo" class="ui button{% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %} disabled{% endif %}">
<i class="blue upload icon" aria-hidden="true"></i>
{% if print_logo.isCustom() %}{{ _T("Choose another file") }}{% else %}{{ _T("Choose a file") }}{% endif %}
</label>
{% endif %}
{% if login.isSuperAdmin() %}
<div class="ui{{ tab == 'admin' ? ' active' }} tab red segment" data-tab="admin">
- {% if constant('GALETTE_MODE') == constant('\\Galette\\Core\\Galette::MODE_DEMO') %}
+ {% if callstatic('\\Galette\\Core\\Galette', 'isDemo') %}
<div class="ui icon negative message">
<i class="ban icon" aria-hidden="true"></i>
<div class="content">