Jake Vanderwerf
4 days ago 747d741293e064a979d7bf6c143ef969ea6d7629
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?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;
    }
}