<?php
|
namespace JVBase\base;
|
|
use JVBase\base\Login;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
/***********************************************
|
* JVB_SITE defines base site options
|
***********************************************/
|
class Site {
|
protected static Login $loginConfig;
|
protected static Membership $membershipConfig;
|
protected static Site $instance;
|
protected static string $icons = 'regular';
|
|
/**
|
* @var bool $is_directory Whether this is a membership directory
|
*/
|
protected static bool $is_directory = false;
|
/**
|
* @var bool $has_membership Whether this site has membership
|
*/
|
protected static bool $membership = false;
|
/**
|
* @var bool $dashboard Whether to implement custom dashboard
|
*/
|
protected static bool $dashboard = false;
|
/**
|
* @var bool $referrals Whether to implement a referral system, with rewards
|
*/
|
protected static bool $referrals = false;
|
/**
|
* @var bool $magic_link Whether users can login without a password
|
*/
|
protected static bool $magic_link = true;
|
/**
|
* @var bool $support Whether to implement the support ticket system
|
*/
|
protected static bool $support = false;
|
/**
|
* @var bool $feed_block Whether to implement the feed block
|
*/
|
protected static bool $feed_block = false;
|
|
/**
|
* @var bool $is_restaurant Whether this is a restaurant
|
*/
|
protected static bool $is_restaurant = false;
|
/**
|
* @var bool $limit_hours Whether things should not be able to be sold outside of business hours.
|
*/
|
protected static bool $limit_hours = false;
|
/**
|
* @var bool $enthusiast Whether to scaffold enthusiasts (users that can interact with and save favourites)
|
*/
|
protected static bool $enthusiast = false;
|
/**
|
* @var bool Optional flag to allow enthusiasts, but not favourites
|
*/
|
protected static bool $favourites = false;
|
|
|
protected static array $integrations = [
|
'bluesky' => false,
|
'cloudflare'=> true,
|
'facebook' => false,
|
'instagram' => false,
|
'maps' => false,
|
'gmb' => false,
|
'helcim' => false,
|
'postmark' => false,
|
'square' => false,
|
'umami' => true,
|
];
|
private function __construct(){
|
|
}
|
|
public static function getInstance():Site {
|
if (!isset(self::$instance)) {
|
self::$instance = new self();
|
do_action('jvbLoadDefinitions');
|
}
|
return self::$instance;
|
}
|
|
public static function set(string $property, ?string $value = null):void
|
{
|
$property = strtolower($property);
|
if (property_exists(self::class, $property)) {
|
switch ($property) {
|
case 'icons':
|
$allowed = ['thin', 'light', 'regular','bold','fill','duotone'];
|
$value = strtolower($value);
|
if (in_array($value, $allowed)) {
|
self::$icons = $value;
|
} else {
|
error_log('[Site]::set Could not set icons to "'.$value.'", setting to default');
|
}
|
break;
|
default:
|
self::${$property} = true;
|
}
|
} else {
|
error_log('[Site]::set Could not set property: '.$property);
|
}
|
}
|
public static function setAll(array $properties):void
|
{
|
foreach ($properties as $property) {
|
self::set($property);
|
}
|
}
|
|
public static function has(string $property):bool
|
{
|
return property_exists(self::class, $property) && self::${$property} === true;
|
}
|
|
public static function hasAny(array $properties):bool
|
{
|
foreach ($properties as $property) {
|
if (self::has($property)) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public static function hasAll(array $properties):bool
|
{
|
foreach ($properties as $property) {
|
if (!self::has($property)) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
public static function icon():string
|
{
|
return self::$icons;
|
}
|
|
public static function setIntegration(string $integration, bool $set = true):void
|
{
|
$integration = strtolower($integration);
|
if (array_key_exists($integration, self::$integrations)) {
|
self::$integrations[$integration] = $set;
|
}else {
|
error_log('[Site]::setIntegration Could not set integration: '.$integration);
|
}
|
}
|
public static function setIntegrations(array $integrations, bool $set = true):void
|
{
|
foreach ($integrations as $integration) {
|
self::setIntegration($integration, $set);
|
}
|
}
|
public static function hasIntegration(string $integration):bool
|
{
|
$integration = strtolower($integration);
|
return array_key_exists($integration, self::$integrations);
|
}
|
|
public static function hasAnyIntegration(array $integrations = []):bool
|
{
|
if (empty($integrations)) {
|
$integrations = array_keys(self::$integrations);
|
}
|
foreach ($integrations as $integration) {
|
if (array_key_exists($integration, self::$integrations) && self::$integrations[$integration] === true) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public static function getIntegrations():array
|
{
|
return array_filter(self::$integrations);
|
}
|
|
public static function login():Login|false
|
{
|
if (!isset(self::$loginConfig)) {
|
self::$loginConfig = new Login();
|
}
|
return self::$loginConfig;
|
}
|
public static function membership():Membership|false
|
{
|
if (!self::$membership) {
|
return false;
|
}
|
if (!isset(self::$membershipConfig)) {
|
self::$membershipConfig = new Membership();
|
}
|
return self::$membershipConfig;
|
}
|
}
|
|
|
$defaults = [
|
'icons' => 'light',
|
'directory' => false, //as in, a membership directory
|
'membership' => false,
|
'has_map' => false, //TODO: migrate to integrations['gmb']
|
'dashboard' => false,
|
'support' => false,
|
'feed_block' => false,
|
'email_notifications' => false,
|
'integrations' => [
|
'bluesky' => false,
|
'cloudflare' => false,
|
'facebook' => false,
|
'maps' => false,
|
'gmb' => false,
|
'helcim' => false,
|
'instagram' => false,
|
'square' => false,
|
'umami' => false,
|
],
|
'is_restaurant' => false,
|
'limit_hours' => false,
|
'enthusiast' => false,
|
'favourites' => false, //optional flag to allow enthusiasts, but not favourites
|
];
|
|
$jvb_site = array_merge($defaults, apply_filters('jvb_site', []));
|
|
define('JVB_SITE', $jvb_site);
|