<?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 array Dashboard config
|
*/
|
protected static string $dashboardTitle;
|
|
/**
|
* @var bool $is_directory Whether this is a membership directory
|
*/
|
protected static bool $is_directory = false;
|
protected static string $directory_singular;
|
protected static string $directory_plural;
|
/**
|
* @var bool Whether to add a help menu to the header
|
*/
|
protected static bool $help_menu = 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;
|
protected static string $defaultReferralRole = BASE.'client';
|
/**
|
* @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;
|
}
|
|
public function setDashboardTitle(string $title):void
|
{
|
self::$dashboardTitle = $title;
|
}
|
|
public static function dashboardTitle():bool|string
|
{
|
return self::$dashboardTitle ?? false;
|
}
|
|
public function setDirectorySingular(string $title):void
|
{
|
self::$directory_singular = $title;
|
}
|
public static function getDirectorySingular():bool|string
|
{
|
return self::$directory_singular ?? false;
|
}
|
|
public function setDirectoryPlural(string $title):void
|
{
|
self::$directory_plural = $title;
|
}
|
public static function getDirectoryPlural():bool|string
|
{
|
return self::$directory_plural ?? false;
|
}
|
|
public static function setDefaultReferralRole(string $role):void
|
{
|
self::$defaultReferralRole = $role;
|
}
|
public static function getDefaultReferralRole():string
|
{
|
return self::$defaultReferralRole;
|
}
|
}
|