Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 755
0.00% covered (danger)
0.00%
0 / 56
CRAP
n/a
0 / 0
zeroBSCRM_extensionsInstalled
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extensionsList
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_extensionsListSegmented
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_extensionsListPaid
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
42
zeroBSCRM_activeInstalledProExt
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_installedProExt
0.00% covered (danger)
0.00%
0 / 59
0.00% covered (danger)
0.00%
0 / 1
930
zeroBSCRM_installedWLCore
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 1
506
zeroBSCRM_extensionsInstalledCount
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
jpcrm_core_modules_installed
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
jpcrm_core_modules_installed_count
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
zeroBSCRM_isExtensionInstalled
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_returnExtensionDetails
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_returnExtensionDetailsFromName
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
132
zeroBSCRM_hasSyncExtensionActivated
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_hasPaidExtensionActivated
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_extensions_checkForUpdates
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_serve_cached_extension_block
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extensions_deactivateAll
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
jpcrm_extensions_deactivate_by_key
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_extensions_free
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_extension_name_pdfinv
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_forms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_quotebuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_invbuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_csvimporterlite
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_api
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_cal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_transactions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_jetpackforms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_name_b2bmode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_remove_dl_repo
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_extension_checkinstall_pdfinv
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
56
zeroBSCRM_extension_install_pdfinv
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
182
zeroBSCRM_extension_uninstall_pdfinv
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_transactions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_transactions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_forms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_forms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_jetpackforms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_jetpackforms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_b2bmode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_b2bmode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_cal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_cal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_quotebuilder
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_quotebuilder
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_invbuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_invbuilder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_csvimporterlite
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_csvimporterlite
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_install_api
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_uninstall_api
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_freeExtensionsInit
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
jpcrm_install_core_extension
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
jpcrm_uninstall_core_extension
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
jpcrm_register_external_extension
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/*
3 * Jetpack CRM
4 * https://jetpackcrm.com
5 * V1.1.18
6 *
7 * Copyright 2020 Automattic
8 *
9 * Date: 30/08/16
10 */
11
12/*
13======================================================
14    Breaking Checks ( stops direct access )
15    ====================================================== */
16if ( ! defined( 'ZEROBSCRM_PATH' ) ) {
17    exit( 0 );
18}
19/*
20======================================================
21    / Breaking Checks
22    ====================================================== */
23
24/*
25======================================================
26    EXTENSION Globals
27    ====================================================== */
28
29    // this is filtered in core, so if you want to remove/add to this
30    // hook into zbs_exclude_from_settings filter
31    global $zbsExtensionsExcludeFromSettings;
32$zbsExtensionsExcludeFromSettings = array( 'pdfinv', 'csvimporterlite', 'portal', 'cf7', 'cal', 'batchtagger', 'salesdash', 'envato', 'bulktag', 'clientportalpro', 'mailcampaigns', 'apiconnector', 'contactform7', 'awesomesupport', 'membermouse', 'bulktagger', 'systememailspro', 'woo', 'wpa', 'advancedsegments', 'contactform', 'pay' );
33
34/*
35======================================================
36    EXTENSION Globals
37    ====================================================== */
38
39/*
40======================================================
41    EXTENSION FUNCS
42    ====================================================== */
43
44// } function to detect what extensions are installed
45// } ONLY WORKS after plugins_loaded
46// } see https://codex.wordpress.org/Plugin_API/Action_Reference
47function zeroBSCRM_extensionsInstalled() {
48
49    // } This list var will be populated via do_action at top of every extension
50    global $zeroBSCRM_extensionsInstalledList;
51    return $zeroBSCRM_extensionsInstalledList;
52}
53
54// } function to return all extensions inc what extensions are installed
55// } ONLY WORKS after plugins_loaded
56// } see https://codex.wordpress.org/Plugin_API/Action_Reference
57function zeroBSCRM_extensionsList() {
58    global $zbs;
59
60    // } This list is all extensions + which are free
61    global $zeroBSCRM_extensionsCompleteList;
62
63    // get free
64    $freeExts = zeroBSCRM_extensions_free( true );
65
66    // } Process full list inc what's on/off
67    $ret = array(); foreach ( $zeroBSCRM_extensionsCompleteList as $extKey => $extObj ) {
68
69        // } Get name
70        $extName = $extKey;
71        if ( function_exists( 'zeroBSCRM_extension_name_' . $extKey ) == 'function' ) {
72            $extName = call_user_func( 'zeroBSCRM_extension_name_' . $extKey );
73        }
74        // } if not, usefallback
75        if ( $extName == $extKey && isset( $extObj['fallbackname'] ) ) {
76            $extName = $extObj['fallbackname'];
77        }
78
79        $ret[ $extKey ] = array(
80            'name'      => $extName,
81            'installed' => zeroBSCRM_isExtensionInstalled( $extKey ),
82            'free'      => in_array( $extKey, $freeExts ),
83            'meta'      => $extObj,
84        );
85
86    }
87
88    return $ret;
89}
90
91// } Returns a list split into FREE / PAID
92function zeroBSCRM_extensionsListSegmented() {
93
94    $exts = zeroBSCRM_extensionsList();
95
96    // } Sort em
97    $ret = array(
98        'free' => array(),
99        'paid' => array(),
100    );
101    foreach ( $exts as $extKey => $ext ) {
102
103        if ( $ext['free'] ) {
104            $ret['free'][ $extKey ] = $ext;
105        } else {
106            $ret['paid'][ $extKey ] = $ext;
107        }
108    }
109
110    return $ret;
111}
112
113// } Returns a list of possible PAID exts
114function zeroBSCRM_extensionsListPaid( $onlyInstalledAndActive = false ) {
115
116    $exts = zeroBSCRM_extensionsList();
117
118    // } Sort em
119    $ret = array();
120    foreach ( $exts as $extKey => $ext ) {
121
122        if ( ! $ext['free'] ) {
123
124            if ( $onlyInstalledAndActive ) {
125
126                if ( isset( $ext['installed'] ) && $ext['installed'] ) {
127                    $ret[ $extKey ] = $ext;
128                }
129            } else {
130                $ret[ $extKey ] = $ext;
131            }
132        }
133    }
134
135    return $ret;
136}
137
138// } Returns a list of installed PAID exts
139function zeroBSCRM_activeInstalledProExt() {
140
141    return zeroBSCRM_extensionsListPaid( true );
142}
143
144// This is a meshing of Mikes method + our existing ext system
145// it catches:
146// Installed, branded extensions
147// Installed, rebranded extensions
148// Installed, unactive, branded extensions
149// DOES NOT FIND:
150// Installed, unactive, rebranded extensions
151// ... does this by checking actives for NAMES
152// ... and checking our installed ext func
153// REturns array of arrays(name=>,key=>,slug=>) (where possible)
154/*
155e.g.
156(
157    [Automations] => Array
158        (
159            [name] => Automations
160            [key] => automations
161            [slug] =>
162            [active] => 1
163        )
164
165    [Mail Campaigns] => Array
166        (
167            [name] => Jetpack CRM Extension: Mail Campaigns
168            [key] => mailcampaigns
169            [slug] => zero-bs-extension-mailcamps/ZeroBSCRM_MailCampaigns.php
170            [active] => -1
171        )
172
173)
174
175// note keepAllVars allows stripping of unnecessary vars (pre send to update.)
176*/
177function zeroBSCRM_installedProExt( $ignoreIfCantFindSlug = false, $keepAllVars = false, $ignoreIfCantFindKey = true ) {
178
179    $ret = array();
180
181    // first go through our 'installedExt'
182    $zbsExtInstalled = zeroBSCRM_activeInstalledProExt();
183
184    if ( is_array( $zbsExtInstalled ) ) {
185        foreach ( $zbsExtInstalled as $k => $deets ) {
186
187            // will have all but only slug where ext's have this:
188            $slug = '';
189            $file = ''; if ( function_exists( 'zeroBSCRM_extension_file_' . $k ) ) {
190                        $file = call_user_func( 'zeroBSCRM_extension_file_' . $k );
191                        $slug = plugin_basename( $file );
192            }
193
194            // if here, MUST be active :)
195            $ret[ $deets['name'] ] = array(
196                'name'   => $deets['name'],
197                'key'    => $k,
198                'slug'   => $slug,
199                'active' => 1,
200                'ver'    => '',
201                'file'   => $file,
202            );
203
204        }
205    }
206
207    // from: https://codex.wordpress.org/Function_Reference/get_plugins
208    // Check if get_plugins() function exists. This is required on the front end of the
209    // site, since it is in a file that is normally only loaded in the admin.
210    if ( ! function_exists( 'get_plugins' ) ) {
211        require_once ABSPATH . 'wp-admin/includes/plugin.php';
212    }
213
214    // then go through installed plugins and try and grab any deactivated via name
215    $zbs_all = get_plugins();
216
217    if ( is_array( $zbs_all ) ) {
218        foreach ( $zbs_all as $slug => $v ) {
219
220            // } JetpackRebrandRelook
221            if ( $v['Name'] !== 'Jetpack CRM' && stripos( '#' . $v['Name'], 'Jetpack CRM' ) > 0 ) {
222
223                // is a branded one of ours (probably)
224
225                // cleaned name
226                $cleanName = str_replace( 'Jetpack CRM Extension: ', '', $v['Name'] );
227
228                if ( ! isset( $ret[ $cleanName ] ) ) {
229
230                    // attempt to find deets
231                    $key           = '';
232                    $potentialItem = zeroBSCRM_returnExtensionDetailsFromName( $cleanName );
233                    if ( is_array( $potentialItem ) ) {
234                        $key = $potentialItem['key'];
235                    }
236
237                    $active = -1;
238                    if ( is_plugin_active( $slug ) ) {
239                        $active = 1;
240                    }
241
242                    $ret[ $cleanName ] = array(
243                        'name'   => $v['Name'],
244                        'key'    => $key,
245                        'slug'   => $slug,
246                        'active' => $active,
247                        'ver'    => $v['Version'],
248                        'file'   => '',
249                    );
250
251                } else {
252
253                    // was set by zeroBSCRM_activeInstalledProExt() above, so fill in any missing details :)
254                    if ( empty( $ret[ $cleanName ]['ver'] ) ) {
255                        $ret[ $cleanName ]['ver'] = $v['Version'];
256                    }
257                }
258            } else {
259
260                // either CORE crm, or other plugin, or REBRANDED ver of ext
261                // try to catch deactivated rebranded vers?
262                // LICENSING3.0 TODO
263
264            }
265        } // / foreach plugin
266    }
267
268    // go through RET + get versions where needed :) + weed out $ignoreIfCantFindSlug
269    $finalReturn = array();
270
271    foreach ( $ret as $extName => $ext ) {
272
273        $extA = $ext;
274        if ( empty( $ext['ver'] ) && ! empty( $ext['file'] ) ) {
275            $pluginFullDeets = get_plugin_data( $ext['file'] );
276            if ( is_array( $pluginFullDeets ) && isset( $pluginFullDeets['Version'] ) ) {
277                $extA['ver'] = $pluginFullDeets['Version'];
278            }
279            // might as well copy over name if here too :)
280            if ( is_array( $pluginFullDeets ) && isset( $pluginFullDeets['Name'] ) ) {
281                $extA['name'] = $pluginFullDeets['Name'];
282            }
283        }
284
285        // strip these (unnecessary vars)
286        if ( ! $keepAllVars ) {
287            unset( $extA['file'] );
288        }
289
290        // finally, clean any slugs which are coming through as zero-bs-extension-csv-importer/ZeroBSCRM_CSVImporter.php instaed of ZeroBSCRM_CSVImporter.php
291        // (but keep full in 'path')
292        if ( strpos( $extA['slug'], '/' ) > 0 ) {
293
294            $extA['path'] = $extA['slug'];
295            $extA['slug'] = substr( $extA['slug'], strrpos( $extA['slug'], '/' ) + 1 );
296
297        }
298
299        if (
300            ( ! $ignoreIfCantFindSlug || ( $ignoreIfCantFindSlug && isset( $extA['slug'] ) && ! empty( $extA['slug'] ) ) )
301            &&
302            ( ! $ignoreIfCantFindKey || ( $ignoreIfCantFindKey && isset( $extA['key'] ) && ! empty( $extA['key'] ) ) )
303            ) {
304
305            $finalReturn[ $extName ] = $extA;
306
307        }
308    }
309
310    return $finalReturn;
311}
312
313// as above (zeroBSCRM_installedProExt) but returns a single arr for WL Core, if installed
314function zeroBSCRM_installedWLCore( $ignoreIfCantFindSlug = false, $keepAllVars = false, $ignoreIfCantFindKey = true ) {
315
316    if ( ! zeroBSCRM_isWL() ) {
317        return false;
318    }
319
320    $ret = false;
321
322    // then go through installed plugins and try and grab any deactivated via name
323    $zbs_all = get_plugins();
324    if ( is_array( $zbs_all ) ) {
325        foreach ( $zbs_all as $slug => $v ) {
326
327            // if is core :) + WL
328            if ( $slug == plugin_basename( ZBS_ROOTFILE ) ) {
329
330                // is rebranded core :)
331
332                // cleaned name
333                $cleanName = $v['Name'];
334
335                // attempt to find deets
336                $key    = 'core';
337                $active = -1;
338                if ( is_plugin_active( $slug ) ) {
339                    $active = 1;
340                }
341
342                $ret = array(
343                    'name'   => $v['Name'],
344                    'key'    => $key,
345                    'slug'   => $slug,
346                    'active' => $active,
347                    'ver'    => $v['Version'],
348                    'file'   => '',
349                );
350
351            }
352        } // / foreach plugin
353    }
354
355    // go through RET + get versions where needed :) + weed out $ignoreIfCantFindSlug
356    $finalReturn = array();
357
358    $extA = $ret;
359    if ( empty( $ret['ver'] ) && ! empty( $ret['file'] ) ) {
360        $pluginFullDeets = get_plugin_data( $ret['file'] );
361        if ( is_array( $pluginFullDeets ) && isset( $pluginFullDeets['Version'] ) ) {
362            $extA['ver'] = $pluginFullDeets['Version'];
363        }
364        // might as well copy over name if here too :)
365        if ( is_array( $pluginFullDeets ) && isset( $pluginFullDeets['Name'] ) ) {
366            $extA['name'] = $pluginFullDeets['Name'];
367        }
368    }
369
370    // strip these (unnecessary vars)
371    if ( ! $keepAllVars ) {
372        unset( $extA['file'] );
373    }
374
375    // finally, clean any slugs which are coming through as zero-bs-extension-csv-importer/ZeroBSCRM_CSVImporter.php instaed of ZeroBSCRM_CSVImporter.php
376    // (but keep full in 'path')
377    if ( strpos( $extA['slug'], '/' ) > 0 ) {
378
379        $extA['path'] = $extA['slug'];
380        $extA['slug'] = substr( $extA['slug'], strrpos( $extA['slug'], '/' ) + 1 );
381
382    }
383
384    if (
385        ( ! $ignoreIfCantFindSlug || ( $ignoreIfCantFindSlug && isset( $extA['slug'] ) && ! empty( $extA['slug'] ) ) )
386        &&
387        ( ! $ignoreIfCantFindKey || ( $ignoreIfCantFindKey && isset( $extA['key'] ) && ! empty( $extA['key'] ) ) )
388        ) {
389
390        $finalReturn = $extA;
391
392    }
393
394    return $finalReturn;
395}
396
397function zeroBSCRM_extensionsInstalledCount( $activatedOnly = false ) {
398
399    // grabs all extensions (rebrander only grabs active, rest grabs active + deactive)
400    $exts = zeroBSCRM_installedProExt();
401
402    if ( ! $activatedOnly ) {
403        return count( $exts );
404    }
405
406    $c = 0;
407    // typo - should have been $exts not $ext.
408    foreach ( $exts as $e ) {
409
410        if ( $e['active'] == '1' ) {
411            ++$c;
412        }
413    }
414    return $c;
415}
416
417/*
418* Returns array of installed (active) core module keys
419*/
420function jpcrm_core_modules_installed() {
421
422    $modules           = zeroBSCRM_extensions_free();
423    $modules_installed = array();
424
425    foreach ( $modules as $module_key => $module ) {
426
427        if ( is_array( $module ) && zeroBSCRM_isExtensionInstalled( $module_key ) ) {
428
429            $modules_installed[] = $module_key;
430
431        }
432    }
433
434    return $modules_installed;
435}
436
437/*
438* Returns count of installed (active) core modules
439*/
440function jpcrm_core_modules_installed_count() {
441
442    $modules      = zeroBSCRM_extensions_free();
443    $module_count = 0;
444
445    foreach ( $modules as $module_key => $module ) {
446
447        if ( is_array( $module ) && zeroBSCRM_isExtensionInstalled( $module_key ) ) {
448
449            ++$module_count;
450
451        }
452    }
453
454    return $module_count;
455}
456
457// } MS - 27th Feb 2019. This is bugged.
458// } function to detect if a specific extension is installed
459// } ONLY WORKS after plugins_loaded
460// } see https://codex.wordpress.org/Plugin_API/Action_Reference
461function zeroBSCRM_isExtensionInstalled( $extKey = '' ) {
462
463    // } This list var will be populated via do_action at top of every extension
464    global $zeroBSCRM_extensionsInstalledList, $zbs;
465
466    if ( count( $zeroBSCRM_extensionsInstalledList ) > 0 ) {
467
468        foreach ( $zeroBSCRM_extensionsInstalledList as $ext ) {
469            if ( ! empty( $ext ) && $ext == $extKey ) {
470                return true;
471            }
472        }
473    }
474
475    // } Otherwise it's not!
476    return false;
477}
478
479// } function to return a specific extension details
480// } ONLY WORKS after plugins_loaded
481// } see https://codex.wordpress.org/Plugin_API/Action_Reference
482function zeroBSCRM_returnExtensionDetails( $extKey = '' ) {
483
484    // } list
485    global $zeroBSCRM_extensionsCompleteList;
486
487    // get free
488    $freeExts = zeroBSCRM_extensions_free( true );
489
490    if ( array_key_exists( $extKey, $zeroBSCRM_extensionsCompleteList ) ) {
491
492        $extObj = $zeroBSCRM_extensionsCompleteList[ $extKey ];
493
494        // } Get name
495        $extName = $extKey;
496        if ( function_exists( 'zeroBSCRM_extension_name_' . $extKey ) == 'function' ) {
497            $extName = call_user_func( 'zeroBSCRM_extension_name_' . $extKey );
498        }
499        // } if not, usefallback
500        if ( $extName == $extKey && isset( $extObj['fallbackname'] ) ) {
501            $extName = $extObj['fallbackname'];
502        }
503
504        return array(
505            'key'       => $extKey,
506            'name'      => $extName,
507            'installed' => zeroBSCRM_isExtensionInstalled( $extKey ),
508            'free'      => in_array( $extKey, $freeExts ),
509            'meta'      => $extObj,
510        );
511
512    }
513
514    // } Otherwise it's not!
515    return false;
516}
517
518// brutal check through list for 'Automations' etc.
519function zeroBSCRM_returnExtensionDetailsFromName( $extName = '' ) {
520
521    // } list
522    global $zeroBSCRM_extensionsCompleteList;
523
524    // get free
525    $freeExts = zeroBSCRM_extensions_free( true );
526
527    if ( is_array( $zeroBSCRM_extensionsCompleteList ) ) {
528        foreach ( $zeroBSCRM_extensionsCompleteList as $key => $deets ) {
529
530            // check against names
531            $thisIsIt = false;
532
533            if ( $deets['fallbackname'] == $extName ) {
534                $thisIsIt = true;
535            }
536            if ( isset( $deets['name'] ) && $deets['name'] == $extName ) {
537                $thisIsIt = true;
538            }
539
540            // aliases (where we've changed names, e.g. PayPal Sync -> PayPal Connect)
541            if ( isset( $deets['aliases'] ) && is_array( $deets['aliases'] ) ) {
542                foreach ( $deets['aliases'] as $alias ) {
543                    if ( $alias == $extName ) {
544                        $thisIsIt = true;
545                    }
546                }
547            }
548
549            if ( $thisIsIt ) {
550
551                return array(
552                    'key'       => $key,
553                    'name'      => $extName,
554                    'installed' => zeroBSCRM_isExtensionInstalled( $key ),
555                    'free'      => in_array( $key, $freeExts ),
556                );
557            }
558        }
559    }
560
561    // } Otherwise it's not!
562    return false;
563}
564
565function zeroBSCRM_hasSyncExtensionActivated() {
566
567    // tries several plugins to see if installed
568    $hasExtension   = false;
569    $syncExtensions = array( 'pay', 'woosync', 'stripesync', 'worldpay', 'groovesync', 'googlesync', 'envato' );
570    foreach ( $syncExtensions as $ext ) {
571
572        if ( zeroBSCRM_isExtensionInstalled( $ext ) ) {
573
574            $hasExtension = true;
575            break;
576
577        }
578    }
579
580    return $hasExtension;
581}
582
583function zeroBSCRM_hasPaidExtensionActivated() {
584
585    $list = zeroBSCRM_extensionsListSegmented();
586    if ( is_array( $list['paid'] ) && count( $list['paid'] ) > 0 ) {
587        foreach ( $list['paid'] as $extKey => $extDeet ) {
588
589            // test
590            if ( zeroBSCRM_isExtensionInstalled( $extKey ) ) {
591                return true;
592            }
593        }
594    }
595
596    return false;
597}
598
599// } Check update - DEFUNCT - moved to transient checks
600function zeroBSCRM_extensions_checkForUpdates() {
601}
602
603/*
604======================================================
605    / EXTENSION FUNCS
606    ====================================================== */
607
608/*
609======================================================
610    EXTENSION DETAILS / FREE/included EXTENSIONS
611    ====================================================== */
612
613// } JSON short description only
614// REFRESH this is ever update woo/products: From: https://jetpackcrm.com/wp-json/zbsextensions/v1/extensions/0
615function zeroBSCRM_serve_cached_extension_block() {
616    // a localhosted version of the extensions array. Loading images from local.
617    $plugin_url = plugins_url( '', ZBS_ROOTFILE ) . '/';
618
619    $imgs = array(
620        'ph'             => $plugin_url . 'i/ext/1px.png',
621        'rm'             => $plugin_url . 'i/ext/registration-magic.png',
622        'live'           => $plugin_url . 'i/ext/livestorm.png',
623        'exit'           => $plugin_url . 'i/ext/exit-bee.png',
624        'wp'             => $plugin_url . 'i/ext/wordpress-utilities.png',
625        'as'             => $plugin_url . 'i/ext/advanced-segments.png',
626        'aweb'           => $plugin_url . 'i/ext/aweber.png',
627        'mm'             => $plugin_url . 'i/ext/member-mouse.png',
628        'auto'           => $plugin_url . 'i/ext/automations.png',
629        'api'            => $plugin_url . 'i/ext/api.png',
630        'cpp'            => $plugin_url . 'i/ext/client-portal-pro.png',
631        'passw'          => $plugin_url . 'i/ext/client-password-manager.png',
632        'twilio'         => $plugin_url . 'i/ext/twillo.png',
633        'mailchimp'      => $plugin_url . 'i/ext/mailchip.png',
634        'awesomesupport' => $plugin_url . 'i/ext/awesome-support.png',
635        'convertkit'     => $plugin_url . 'i/ext/convertkit.png',
636        'batchtag'       => $plugin_url . 'i/ext/bulk-tagger.png',
637        'googlecontact'  => $plugin_url . 'i/ext/google-contacts.png',
638        'groove'         => $plugin_url . 'i/ext/groove.png',
639        'contactform'    => $plugin_url . 'i/ext/contact-form-7.png',
640        'stripe'         => $plugin_url . 'i/ext/stripe.png',
641        'worldpay'       => $plugin_url . 'i/ext/world-pay.png',
642        'invpro'         => $plugin_url . 'i/ext/invoicing-pro.png',
643        'gravity'        => $plugin_url . 'i/ext/gravity-forms.png',
644        'csvpro'         => $plugin_url . 'i/ext/csv-importer-pro.png',
645        'mailcamp'       => $plugin_url . 'i/ext/mail-campaigns.png',
646        'paypal'         => $plugin_url . 'i/ext/paypal.png',
647        'salesdash'      => $plugin_url . 'i/ext/sales-dashboard.png',
648
649    );
650
651    $json = '{"data":{},"count":29,"paid":[{"id":26172,"name":"Registration Magic Connect","short_desc":"Capture your Registration Magic sign ups into Jetpack CRM. Including First Name and Last Name.","date":{"date":"2019-01-08 12:57:32.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"59","regular_price":"59","image":"' . $imgs['rm'] . '","extkey":"registrationmagic"},{"id":25432,"name":"Livestorm","short_desc":"The Jetpack CRM livestorm connector automatically adds your Livestorm webinar sign ups into Jetpack CRM.","date":{"date":"2018-12-02 22:03:07.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['live'] . '","extkey":"livestorm"},{"id":25431,"name":"ExitBee Connect","short_desc":"Exit Bee Connect automatically adds your Exit Bee form completions into Jetpack CRM.","date":{"date":"2018-12-02 21:59:18.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['exit'] . '","extkey":"exitbee"},{"id":25336,"name":"WordPress Utilities","short_desc":"The Jetpack CRM WordPress utilities extension adds your website registrations to your Jetpack CRM.","date":{"date":"2018-11-19 22:50:37.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"59","regular_price":"59","image":"' . $imgs['wp'] . '","extkey":"wordpressutilities"},{"id":25174,"name":"Advanced Segments","short_desc":"Easily divide your contacts into dynamic subgroups and manage your contacts effectively","date":{"date":"2018-09-21 10:44:24.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['as'] . '","extkey":"advancedsegments"},{"id":24955,"name":"AWeber Connect","short_desc":"Connect your aWeber to your Jetpack CRM and add new Jetpack CRM contacts to your aWeber list.","date":{"date":"2018-07-26 05:02:28.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39","regular_price":"39","image":"' . $imgs['aweb'] . '","extkey":"aweber"},{"id":24763,"name":"Membermouse Connect","short_desc":"Enhance your MemberMouse subscription website by integrating your data with Jetpack CRM","date":{"date":"2018-07-24 17:29:28.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['mm'] . '","extkey":"membermouse"},{"id":24696,"name":"Automations","short_desc":"Let Automations handle the mundane tasks within your CRM and save yourself time.","date":{"date":"2018-07-22 15:24:14.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['auto'] . '","extkey":"automations"},{"id":24692,"name":"API Connector","short_desc":"Connects your website to Jetpack CRM via the API. Supports Forms, Website Registrations. Use on as many external sites as you like.","date":{"date":"2018-07-09 00:46:59.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"59","regular_price":"59","image":"' . $imgs['api'] . '","extkey":"apiconnector"},{"id":24676,"name":"Client Portal Pro","short_desc":"Customise your Client Portal, Allow File Downloads, Display Tasks and Tickets plus much more","date":{"date":"2018-07-06 17:40:11.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['cpp'] . '","extkey":"clientportalpro"},{"id":24569,"name":"Client Password Manager","short_desc":"Securely manage usernames and passwords for your clients websites, servers, and other logins.","date":{"date":"2018-05-28 14:09:12.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39","regular_price":"39","image":"' . $imgs['passw'] . '","extkey":"passwordmanager"},{"id":20570,"name":"Twilio Connect","short_desc":"Send SMS messages to your contacts, leads, and customers","date":{"date":"2017-11-24 11:53:18.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['twilio'] . '","extkey":"twilio"},{"id":18274,"name":"MailChimp","short_desc":"Subscribe your Jetpack CRM contacts to your MailChimp email marketing list automatically.","date":{"date":"2017-07-27 09:35:08.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39","regular_price":"39","image":"' . $imgs['mailchimp'] . '","extkey":"mailchimp"},{"id":18221,"name":"Awesome Support","short_desc":"Integrate Jetpack CRM with Awesome Support Plugin and see your Contacts support ticket information within your CRM.","date":{"date":"2017-07-24 19:49:23.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"29","regular_price":"29","image":"' . $imgs['awesomesupport'] . '","extkey":"awesomesupport"},{"id":17921,"name":"ConvertKit","short_desc":"Subscribe your contacts to your ConvertKit list automatically. Subscribe to a form, add a tag or subscribe to a sequence","date":{"date":"2017-07-10 10:25:41.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39","regular_price":"39","image":"' . $imgs['convertkit'] . '","extkey":"convertkit"},{"id":17692,"name":"Bulk Tagger","short_desc":"Bulk tag your contacts based on transaction keywords. Target contacts based on their transaction tags.","date":{"date":"2017-07-02 10:09:47.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"29.00","regular_price":"29.00","image":"' . $imgs['batchtag'] . '","extkey":"batchtag"},{"id":17425,"name":"Google Contacts Sync","short_desc":"Retrieve all contact data from Google Contacts. Keep all Leads in your CRM and start managing your contacts effectively.","date":{"date":"2017-06-05 12:32:02.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39.00","regular_price":"39.00","image":"' . $imgs['googlecontact'] . '","extkey":"googlecontact"},{"id":17413,"name":"Groove Sync","short_desc":"Retrieve all contact data from Groove\u00a0automatically. Keep all Leads in your CRM.","date":{"date":"2017-06-02 16:25:18.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"39.00","regular_price":"39.00","image":"' . $imgs['groove'] . '","extkey":"groove"},{"id":17409,"name":"Contact Form 7","short_desc":"Use Contact Form 7 to collect leads and contact info. Save time by automating your lead generation process.","date":{"date":"2017-06-01 13:05:12.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['contactform'] . '","extkey":"contactform"},{"id":17378,"name":"Stripe Sync","short_desc":"Retrieve all customer data from Stripe automatically.","date":{"date":"2017-05-30 18:30:29.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49.00","regular_price":"49.00","image":"' . $imgs['stripe'] . '","extkey":"stripe"},{"id":17356,"name":"WorldPay Sync","short_desc":"Retrieve all customer data from WorldPay\u00a0automatically. Works great with Sales Dashboard.","date":{"date":"2017-05-24 12:25:12.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49.00","regular_price":"49.00","image":"' . $imgs['worldpay'] . '","extkey":"worldpay"},{"id":17067,"name":"Invoicing PRO","short_desc":"Invoicing PRO lets your\u00a0customers pay their invoices right from your Client Portal using either PayPal or Stripe.","date":{"date":"2017-02-21 11:06:47.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['invpro'] . '","extkey":"invpro"},{"id":17030,"name":"Gravity Forms Connect","short_desc":"Use Gravity Forms to collect leads and contact info. Save time by automating your lead generation process.","date":{"date":"2017-01-25 03:31:56.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['gravity'] . '","extkey":"gravity"},{"id":16690,"name":"CSV Importer PRO","short_desc":"Import your existing contact data into the Jetpack CRM system with our super simple CSV importer extension.","date":{"date":"2016-06-20 23:02:27.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"29","regular_price":"29","image":"' . $imgs['csvpro'] . '","extkey":"csvpro"},{"id":16688,"name":"Mail Campaigns","short_desc":"Send emails to targeted segments of contacts with this easy to use, powerful mail extension. Contact your contacts easily.","date":{"date":"2016-06-20 22:53:09.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"79","regular_price":"79","image":"' . $imgs['mailcamp'] . '","extkey":"mailcamp"},{"id":16685,"name":"PayPal Sync","short_desc":"Retrieve all customer data from PayPal automatically. Works great with Sales Dashboard.","date":{"date":"2016-06-16 23:00:34.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"49","regular_price":"49","image":"' . $imgs['paypal'] . '","extkey":"paypal"},{"id":16609,"name":"Sales Dashboard","short_desc":"<p class=\"p1\"><span class=\"s1\">The ultimate sales dashboard. Track Gross Revenue, Net Revenue, Customer growth right from your CRM.<\/span><\/p>","date":{"date":"2016-06-05 14:04:16.000000","timezone_type":3,"timezone":"Europe\/London"},"price":"129","regular_price":"129","image":"' . $imgs['salesdash'] . '","extkey":"salesdash"}]}';
652    return $json;
653}
654
655// } Vars
656global $zeroBSCRM_extensionsInstalledList, $zeroBSCRM_extensionsCompleteList, $jpcrm_core_extension_setting_map;
657
658$jpcrm_core_extension_setting_map = array(
659    'forms'           => 'feat_forms',
660    'pdfinv'          => 'feat_pdfinv',
661    'quotebuilder'    => 'feat_quotes',
662    'invbuilder'      => 'feat_invs',
663    'csvimporterlite' => 'feat_csvimporterlite',
664    'api'             => 'feat_api',
665    'cal'             => 'feat_calendar',
666    'transactions'    => 'feat_transactions',
667    'jetpackforms'    => 'feat_jetpackforms',
668    'b2bmode'         => 'companylevelcustomers',
669);
670
671// } Fill out full list - NOTE: this is currently only used for extra info for extensions page
672// } Sould still use the functions like "zeroBSCRM_extension_name_mailcampaigns" for names etc.
673$zeroBSCRM_extensionsCompleteList = array(
674
675    // MS 15th Oct. This list needs to be maintained as it drives the update check
676    // Probably need a more central (i.e. on jetpackcrm.com) list of these
677    // As per the above comments, we should consolidate this whole system, with
678    // one central location holding extension meta (along with a fallback cache)
679
680    // Paid extensions; last updated 21 March 1922
681    'advancedsegments'   => array(
682        'fallbackname' => 'Advanced Segments',
683        'desc'         => __( 'Easily divide your contacts into dynamic subgroups and manage your contacts effectively.', 'zero-bs-crm' ),
684        'url'          => 'https://jetpackcrm.com/product/advanced-segments/',
685        'colour'       => '#aa73ac',
686        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/advanced-segments/',
687    ),
688    'apiconnector'       => array(
689        'fallbackname' => 'API Connector',
690        'desc'         => __( 'Connects your website to Jetpack CRM via the API. Supports Forms & Registrations.', 'zero-bs-crm' ),
691        'url'          => 'https://jetpackcrm.com/product/api-connector/',
692        'colour'       => '#11ABCC',
693        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/api-connector/',
694
695    ),
696    'automations'        => array(
697        'fallbackname' => 'Automations',
698        'desc'         => __( 'Let our Automations do the mundane tasks for you.', 'zero-bs-crm' ),
699        'url'          => 'https://jetpackcrm.com/extensions/automations/',
700        'colour'       => '#009cde',
701        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/automations/',
702    ),
703    'aweber'             => array(
704        'fallbackname' => 'AWeber Connect',
705        'desc'         => __( 'Send Jetpack CRM contacts to your AWeber list.', 'zero-bs-crm' ),
706        'url'          => 'https://jetpackcrm.com/product/aweber-connect/',
707        'colour'       => '#aa73ac',
708        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/aweber-connect/',
709    ),
710    'awesomesupport'     => array(
711        'fallbackname' => 'Awesome Support Connector',
712        'desc'         => __( 'See your contacts support ticket overview.', 'zero-bs-crm' ),
713        'url'          => 'https://jetpackcrm.com/product/awesome-support/',
714        'colour'       => '#11ABCC',
715        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/awesome-support/',
716    ),
717    'batchtag'           => array(
718        'fallbackname' => 'Bulk Tagger',
719        'desc'         => __( 'Bulk Tag your contacts based on their transaction strings', 'zero-bs-crm' ),
720        'url'          => 'https://jetpackcrm.com/product/bulk-tagger/',
721        'colour'       => '#11ABCC',
722        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/bulk-tagger/',
723    ),
724    'passwordmanager'    => array(
725        'fallbackname' => 'Client Password Manager',
726        'desc'         => __( 'Securely manage usernames and passwords for your clients websites, servers, and other logins.', 'zero-bs-crm' ),
727        'url'          => 'https://jetpackcrm.com/product/client-password-manager/',
728        'colour'       => '#11ABCC',
729        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/client-password-manager/',
730    ),
731    'clientportalpro'    => array(
732        'fallbackname' => 'Client Portal Pro',
733        'desc'         => __( 'Customise your Client Portal, Allow File Downloads, Display Tasks and more', 'zero-bs-crm' ),
734        'url'          => 'https://jetpackcrm.com/product/client-portal-pro/',
735        'colour'       => '#11ABCC',
736        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/client-portal-pro/',
737    ),
738    'contactform'        => array(
739
740        'fallbackname' => 'Contact Form 7 Connector',
741        'desc'         => __( 'Use Contact Form 7 to collect leads and contact info.', 'zero-bs-crm' ),
742        'url'          => 'https://jetpackcrm.com/product/contact-form-7/',
743        'colour'       => '#e2ca00',
744        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/contact-form-7/',
745    ),
746    'convertkit'         => array(
747        'fallbackname' => 'ConvertKit Connector',
748        'desc'         => __( 'Add your Jetpack CRM Contacts to your ConvertKit list.', 'zero-bs-crm' ),
749        'url'          => 'https://jetpackcrm.com/product/convertkit/',
750        'colour'       => '#11ABCC',
751        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/convertkit/',
752    ),
753    'csvpro'             => array(
754        'fallbackname' => 'CSV Importer PRO',
755        'desc'         => __( 'Import existing contact data from CSV (Pro Version)', 'zero-bs-crm' ),
756        'url'          => 'https://jetpackcrm.com/extensions/simple-csv-importer/',
757        'colour'       => 'green',
758        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/csv-importer-pro/',
759        'shortname'    => 'CSV Imp. PRO', // used where long name won't fit
760    ),
761    'exitbee'            => array(
762        'fallbackname' => 'Exit Bee Connect',
763        'desc'         => __( 'Convert abandoning visitors into contacts.', 'zero-bs-crm' ),
764        'url'          => 'https://jetpackcrm.com/product/exitbee-connect/',
765        'colour'       => '#aa73ac',
766        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/exit-bee/',
767    ),
768    'funnels'            => array(
769        'fallbackname' => 'Funnels',
770    ),
771    'googlecontact'      => array(
772        'fallbackname' => 'Google Contacts',
773        'desc'         => __( 'Retrieve all contact data from Google Contacts.', 'zero-bs-crm' ),
774        'url'          => 'https://jetpackcrm.com/product/google-contacts-sync/',
775        'colour'       => '#91a8ad',
776        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/google-contacts-sync/',
777        'aliases'      => array( 'Google Contact Sync', 'Google Contact Connect' ),
778    ),
779    'gravity'            => array(
780        'fallbackname' => 'Gravity Connect',
781        'desc'         => __( 'Create Contacts from Gravity Forms (Integration).', 'zero-bs-crm' ),
782        'url'          => 'https://jetpackcrm.com/extensions/gravity-forms/',
783        'colour'       => '#91a8ad', // grav forms :) #91a8ad
784        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/gravity-forms/',
785        'aliases'      => array( 'Gravity Forms' ),
786    ),
787    'groove'             => array(
788        'fallbackname' => 'Groove Connect',
789        'desc'         => __( 'Retrieve all contact data from Groove automatically.', 'zero-bs-crm' ),
790        'url'          => 'https://jetpackcrm.com/product/groove-sync/',
791        'colour'       => '#11ABCC',
792        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/groove-sync/',
793        'aliases'      => array( 'Groove Sync' ),
794    ),
795    'invpro'             => array(
796        'fallbackname' => 'Invoicing Pro',
797        'desc'         => __( 'Collect invoice payments directly from your CRM with PayPal or Stripe.', 'zero-bs-crm' ),
798        'url'          => 'https://jetpackcrm.com/extensions/invoicing-pro/',
799        'colour'       => '#1e0435',
800        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/invoicing-pro/',
801    ),
802    'livestorm'          => array(
803        'fallbackname' => 'Livestorm Connect',
804        'desc'         => __( 'Capture webinar sign ups to your CRM.', 'zero-bs-crm' ),
805        'url'          => 'https://jetpackcrm.com/product/livestorm-connect/',
806        'colour'       => '#aa73ac',
807        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/livestorm/',
808        'aliases'      => array( 'Live Storm Connect' ),
809    ),
810    'mailcamp'           => array(
811        'fallbackname' => 'Mail Campaigns',
812        'desc'         => __( 'Send emails to targeted segments of contacts.', 'zero-bs-crm' ),
813        'url'          => 'https://jetpackcrm.com/extensions/mail-campaigns/',
814        'colour'       => 'rgb(173, 210, 152)',
815        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/mail-campaigns-v2/',
816        'aliases'      => array( '[BETA] v2.0 Mail Campaigns' ),
817    ),
818    'mailchimp'          => array(
819        'fallbackname' => 'MailChimp Connector',
820        'desc'         => __( 'Add your Jetpack CRM Contacts to your Mailchimp email list.', 'zero-bs-crm' ),
821        'url'          => 'https://jetpackcrm.com/product/mailchimp/',
822        'colour'       => '#11ABCC',
823        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/mailchimp/',
824    ),
825    'membermouse'        => array(
826        'fallbackname' => 'Member Mouse',
827        'desc'         => __( 'Imports your Membermouse user data to your CRM.', 'zero-bs-crm' ),
828        'url'          => 'https://jetpackcrm.com/product/membermouse/',
829        'colour'       => '#f01e14',
830        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/member-mouse/',
831    ),
832    'optinmonster'       => array(
833        'fallbackname' => 'OptinMonster',
834        'aliases'      => array( 'Optin Monster' ),
835    ),
836    'paypal'             => array(
837        'fallbackname' => 'PayPal Connect',
838        'desc'         => __( 'Retrieve all contact data from PayPal automatically.', 'zero-bs-crm' ),
839        'url'          => 'https://jetpackcrm.com/extensions/paypal-sync/',
840        'colour'       => '#009cde',
841        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/paypal-sync/',
842        'aliases'      => array( 'PayPal Sync' ),
843    ),
844    'registrationmagic'  => array(
845        'fallbackname' => 'Registration Magic',
846    ),
847    'salesdash'          => array(
848        'fallbackname' => 'Sales Dashboard',
849        'desc'         => __( 'The ultimate sales dashboard. See sales trends and more', 'zero-bs-crm' ),
850        'url'          => 'https://jetpackcrm.com/extensions/sales-dashboard/',
851        'colour'       => 'black',
852        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/sales-dashboard/',
853    ),
854    'stripe'             => array(
855        'fallbackname' => 'Stripe Connect',
856        'desc'         => __( 'Retrieve all customer data from Stripe automatically.', 'zero-bs-crm' ),
857        'url'          => 'https://jetpackcrm.com/product/stripe-sync/',
858        'colour'       => '#5533ff',
859        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/stripe-sync/',
860        'aliases'      => array( 'Stripe Sync' ),
861    ),
862    'systememail'        => array(
863        'fallbackname' => 'System Emails Pro',
864        'aliases'      => array( 'System Email Pro' ),
865    ),
866    'twilio'             => array(
867        'fallbackname' => 'Twilio Connect',
868        'desc'         => __( 'Send SMS from your Twilio Account.', 'zero-bs-crm' ),
869        'url'          => 'https://jetpackcrm.com/product/twilio/',
870        'colour'       => '#11ABCC',
871        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/twilio-connector/',
872    ),
873    'wordpressutilities' => array(
874        'fallbackname' => 'WordPress Utilities',
875        'desc'         => __( 'Capture website sign ups into Jetpack CRM.', 'zero-bs-crm' ),
876        'url'          => 'https://jetpackcrm.com/product/wordpress-utilities/',
877        'colour'       => '#aa73ac',
878        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/wordpress-utilities/',
879    ),
880    'worldpay'           => array(
881        'fallbackname' => 'WorldPay Sync',
882        'desc'         => __( 'Create Contacts from World Pay Sync.', 'zero-bs-crm' ),
883        'url'          => 'https://jetpackcrm.com/product/worldpay-sync/',
884        'colour'       => '#f01e14',
885        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/worldpay-sync/',
886    ),
887
888    // } ============= Free =====
889
890    'api'                => array(
891
892        'fallbackname' => 'API', // This is if no name func is found...
893        'imgstr'       => '<i class="fa fa-random" aria-hidden="true"></i>',
894        'desc'         => __( 'Enable the API area of your CRM.', 'zero-bs-crm' ),
895        'url'          => 'https://jetpackcrm.com/feature/api/',
896        'colour'       => '#000000',
897        'helpurl'      => 'https://automattic.github.io/jetpack-crm-api-docs/',
898
899        'shortName'    => 'API',
900
901    ),
902
903    'cal'                => array(
904
905        'fallbackname' => __( 'Task Scheduler', 'zero-bs-crm' ), // This is if no name func is found...
906        'imgstr'       => '<i class="fa fa-calendar" aria-hidden="true"></i>',
907        'desc'         => __( 'Enable Jetpack CRM Task Scheduler.', 'zero-bs-crm' ),
908        'url'          => 'https://jetpackcrm.com/feature/tasks/',
909        'colour'       => '#ad6d0d',
910        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/calendar/',
911
912        'shortName'    => 'Calendar',
913
914    ),
915
916    'quotebuilder'       => array(
917
918        'fallbackname' => 'Quote Builder', // This is if no name func is found...
919        'imgstr'       => '<i class="fa fa-file-text-o" aria-hidden="true"></i>',
920        'desc'         => __( 'Write and send professional proposals from your CRM.', 'zero-bs-crm' ),
921        'url'          => 'https://jetpackcrm.com/feature/quotes/',
922        'colour'       => '#1fa67a',
923        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/quotes/',
924
925    ),
926
927    'invbuilder'         => array(
928
929        'fallbackname' => 'Invoice Builder', // This is if no name func is found...
930        'imgstr'       => '<i class="fa fa-file-text-o" aria-hidden="true"></i>',
931        'desc'         => __( 'Write and send professional invoices from your CRM.', 'zero-bs-crm' ),
932        'url'          => 'https://jetpackcrm.com/feature/invoices/',
933        'colour'       => '#2a044a',
934        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/invoices/',
935
936    ),
937
938    'pdfinv'             => array(
939
940        'fallbackname' => 'PDF Invoicing', // This is if no name func is found...
941        'imgstr'       => '<i class="fa fa-file-pdf-o" aria-hidden="true"></i>',
942        'desc'         => __( 'Want PDF Invoices? Get this installed.', 'zero-bs-crm' ),
943        // 'url' => 'https://jetpackcrm.com/feature/',
944        'colour'       => 'green',
945        // 'helpurl' => 'https://kb.jetpackcrm.com/'
946
947    ),
948
949    'transactions'       => array(
950
951        'fallbackname' => 'Transactions', // This is if no name func is found...
952        'imgstr'       => '<i class="fa fa-file-shopping-cart" aria-hidden="true"></i>',
953        'desc'         => __( 'Log transactions in your CRM.', 'zero-bs-crm' ),
954        'url'          => 'https://jetpackcrm.com/feature/transactions/',
955        'colour'       => 'green',
956        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/transactions/',
957
958    ),
959
960    'forms'              => array(
961
962        'fallbackname' => 'Front-end Forms', // This is if no name func is found...
963        'imgstr'       => '<i class="fa fa-keyboard-o" aria-hidden="true"></i>',
964        'desc'         => __( 'Useful front-end forms to capture leads.', 'zero-bs-crm' ),
965        'url'          => 'https://jetpackcrm.com/feature/forms/',
966        'colour'       => 'rgb(126, 88, 232)',
967        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/forms/',
968        'shortname'    => 'Forms', // used where long name won't fit
969
970    ),
971
972    // } Free ver
973    'csvimporterlite'    => array(
974
975        'fallbackname' => 'CSV Importer LITE', // This is if no name func is found...
976        'imgstr'       => '<i class="fa fa-upload" aria-hidden="true"></i>',
977        'desc'         => __( 'Lite Version of CSV Customer Importer', 'zero-bs-crm' ),
978        // 'url' => 'https://jetpackcrm.com/extensions/simple-csv-importer/',
979        'colour'       => 'green',
980        // 'helpurl' => 'https://kb.jetpackcrm.com/',
981        'shortname'    => 'CSV Imp. LITE', // used where long name won't fit
982        'prover'       => 'csvpro', // } if this is set, and 'csvimporter' ext exists, it'll default to "PRO installed"
983
984    ),
985
986    'b2bmode'            => array(
987
988        'fallbackname' => 'B2B Mode', // This is if no name func is found...
989        'imgstr'       => '<i class="building outline icon"></i>',
990        'desc'         => __( 'Manage Contacts at Companies or Organisations', 'zero-bs-crm' ),
991        'url'          => 'https://jetpackcrm.com/feature/b2b-mode/',
992        'colour'       => 'rgb(117 184 231)',
993        'helpurl'      => 'https://kb.jetpackcrm.com/knowledge-base/how-to-assign-a-contact-to-a-company/',
994        'shortname'    => 'B2B Mode', // used where long name won't fit
995
996    ),
997
998    'jetpackforms'       => array(
999
1000        'fallbackname' => 'Jetpack Forms', // This is if no name func is found...
1001        'imgstr'       => '<i class="fa fa-keyboard-o" aria-hidden="true"></i>',
1002        'desc'         => __( 'Capture leads from Jetpack Forms', 'zero-bs-crm' ),
1003        // 'url' => 'https://jetpackcrm.com/feature/',
1004        'colour'       => 'rgb(126, 88, 232)',
1005        'helpurl'      => 'https://kb.jetpackcrm.com/knowledge-base/jetpack-contact-forms/',
1006        'shortname'    => 'Jetpack Forms', // used where long name won't fit
1007
1008    ),
1009
1010    'woo-sync'           => array(
1011        'fallbackname' => 'WooSync',
1012        'desc'         => __( 'Retrieve all customer data from WooCommerce.', 'zero-bs-crm' ),
1013        'url'          => 'https://jetpackcrm.com/woocommerce/',
1014        'colour'       => 'rgb(216, 187, 73)',
1015        'helpurl'      => 'https://kb.jetpackcrm.com/article-categories/woocommerce-sync/',
1016        'aliases'      => array( 'WooSync', 'Woo Sync' ),
1017    ),
1018
1019    // Legacy keys used to identify obsolete extensions
1020    'woosync'            => array(
1021        'fallbackname' => 'WooSync',
1022    ),
1023
1024); // } #coreintegration
1025
1026// This deactivates all active ZBS extensions (used by migration routine for v3.0 - be careful if alter as back-compat may be comprimised)
1027function zeroBSCRM_extensions_deactivateAll() {
1028
1029    // count
1030    $c = 0;
1031
1032    // retrieve extensions
1033    $extensions = zeroBSCRM_installedProExt();
1034
1035    // Disable extensions
1036    if ( is_array( $extensions ) ) {
1037        foreach ( $extensions as $shortName => $e ) {
1038
1039            if ( isset( $e['path'] ) ) {
1040                deactivate_plugins( plugin_basename( $e['path'] ) );
1041            }
1042            ++$c;
1043        }
1044    }
1045
1046    return $c;
1047}
1048
1049/*
1050*   Deactivates specific extension based on its key
1051*
1052*   @param string $key - e.g. 'woosync'
1053*
1054*   @return bool - (approximate) success
1055*/
1056function jpcrm_extensions_deactivate_by_key( $key ) {
1057
1058    // Most reliable way I found to do this is using our internal extension register
1059    $installed_extensions = zeroBSCRM_installedProExt();
1060
1061    foreach ( $installed_extensions as $name => $extension ) {
1062
1063        if ( $extension['key'] == $key && $extension['active'] == 1 ) {
1064
1065            // deactivate the extension
1066            if ( isset( $extension['path'] ) ) {
1067
1068                deactivate_plugins( plugin_basename( $extension['path'] ) );
1069
1070                return ! is_plugin_active( plugin_basename( $extension['path'] ) );
1071
1072            }
1073        }
1074    }
1075
1076    return false;
1077}
1078
1079// } This activates a given extension
1080// No point, just use activate_plugin vanilla. function zeroBSCRM_extensions_activate($path=false){}
1081
1082// } Free Array
1083// this is a simpler version, with better icons (from the welcome to ZBS page and a description)
1084// have also added "transactions" to here. CSVimporterLite I would not see as a "module" to disable. Think should be the areas
1085function zeroBSCRM_extensions_free( $justKeys = false ) {
1086
1087    $exts = array(
1088
1089        'csvimporterlite' => false, // false = doesn't show on ext manager page
1090
1091        'api'             => array(
1092            'name'       => __( 'API', 'zero-bs-crm' ),
1093            'i'          => 'api.png',
1094            'short_desc' => __( 'The CRM API lets you interact with Jetpack CRM via the application program interface.', 'zero-bs-crm' ),
1095        ),
1096        'cal'             => array(
1097            'name'       => __( 'Tasks', 'zero-bs-crm' ),
1098            'i'          => 'task-cal.png',
1099            'short_desc' => __( 'Manage tasks for your contacts and what you need to do for them.', 'zero-bs-crm' ),
1100        ),
1101        'quotebuilder'    => array(
1102            'name'       => __( 'Quotes', 'zero-bs-crm' ),
1103            'i'          => 'quotes.png',
1104            'short_desc' => __( 'Offer Quotes for your contacts to help you win more business.', 'zero-bs-crm' ),
1105        ),
1106        'invbuilder'      => array(
1107            'name'       => __( 'Invoices', 'zero-bs-crm' ),
1108            'i'          => 'invoices.png',
1109            'short_desc' => __( 'Send invoices to your clients and allow them to pay online.', 'zero-bs-crm' ),
1110        ),
1111        'pdfinv'          => array(
1112            'name'       => __( 'PDF Engine', 'zero-bs-crm' ),
1113            'i'          => 'pdf.png',
1114            'short_desc' => __( 'Supports PDF invoicing and PDF quotes (plus more).', 'zero-bs-crm' ),
1115        ),
1116        'forms'           => array(
1117            'name'       => __( 'Forms', 'zero-bs-crm' ),
1118            'i'          => 'form.png',
1119            'short_desc' => __( 'Capture contacts into your CRM using our simple form solutions.', 'zero-bs-crm' ),
1120        ),
1121        'transactions'    => array(
1122            'name'       => __( 'Transactions', 'zero-bs-crm' ),
1123            'i'          => 'transactions.png',
1124            'short_desc' => __( 'Log transactions against contacts and see their total value in the CRM.', 'zero-bs-crm' ),
1125        ),
1126        'b2bmode'         => array(
1127            'name'       => __( 'B2B Mode', 'zero-bs-crm' ),
1128            'i'          => 'customers.png',
1129            'short_desc' => __( 'Manage Contacts at Companies or Organisations', 'zero-bs-crm' ),
1130        ),
1131        'jetpackforms'    => array(
1132            'name'       => __( 'Jetpack Forms', 'zero-bs-crm' ),
1133            'i'          => 'form.png',
1134            'short_desc' => __( 'Capture contacts from Jetpack forms into your CRM.', 'zero-bs-crm' ),
1135        ),
1136        'woo-sync'        => array(
1137            'name'       => 'WooSync',
1138            'i'          => 'auto.png',
1139            'short_desc' => __( 'Retrieve all customer data from WooCommerce into your CRM.', 'zero-bs-crm' ),
1140        ),
1141
1142    );
1143
1144    $exts = apply_filters( 'jpcrm_register_free_extensions', $exts );
1145
1146    if ( $justKeys ) {
1147        return array_keys( $exts );
1148    }
1149
1150    return $exts;
1151}
1152
1153// } Free extensions name funcs
1154function zeroBSCRM_extension_name_pdfinv() {
1155    return __( 'PDF Engine', 'zero-bs-crm' ); }
1156function zeroBSCRM_extension_name_forms() {
1157    return __( 'Front-end Forms', 'zero-bs-crm' ); }
1158function zeroBSCRM_extension_name_quotebuilder() {
1159    return __( 'Quotes', 'zero-bs-crm' ); }
1160function zeroBSCRM_extension_name_invbuilder() {
1161    return __( 'Invoicing', 'zero-bs-crm' ); }
1162function zeroBSCRM_extension_name_csvimporterlite() {
1163    return __( 'CSV Importer LITE', 'zero-bs-crm' ); }
1164function zeroBSCRM_extension_name_api() {
1165    return __( 'API', 'zero-bs-crm' ); }
1166function zeroBSCRM_extension_name_cal() {
1167    return __( 'Tasks', 'zero-bs-crm' ); }
1168
1169function zeroBSCRM_extension_name_transactions() {
1170    return __( 'Transactions', 'zero-bs-crm' ); }
1171function zeroBSCRM_extension_name_jetpackforms() {
1172    return __( 'Jetpack Forms', 'zero-bs-crm' ); }
1173function zeroBSCRM_extension_name_b2bmode() {
1174    return __( 'B2B Mode', 'zero-bs-crm' ); }
1175
1176// } Settings page for PDF Invoicing (needs writing)
1177// } function zeroBSCRM_html_settings_pdfinv
1178
1179// hard deletes any extracted repo (e.g. dompdf)
1180function zeroBSCRM_extension_remove_dl_repo( $repoName = '' ) {
1181
1182    if ( in_array( $repoName, array( 'dompdf' ) ) ) {
1183
1184        // this is here to stop us ever accidentally using zeroBSCRM_del
1185        define( 'ZBS_OKAY_TO_PROCEED', time() );
1186        zeroBSCRM_del( ZEROBSCRM_INCLUDE_PATH . $repoName );
1187
1188    }
1189}
1190
1191// } WH 2.0.6 - added to check installed pre-use, auto-installs if not present (or marks uninstalled + returns false)
1192// } $checkInstallFonts allows you to just check dompdf, not the piggy-backed pdf fonts installer too (as PDFBuilder needs this)
1193function zeroBSCRM_extension_checkinstall_pdfinv( $checkInstallFonts = true ) {
1194
1195    global $zbs;
1196
1197    // retrieve lib path
1198    $includeFile = $zbs->libInclude( 'dompdf' );
1199
1200    $shouldBeInstalled = zeroBSCRM_getSetting( 'feat_pdfinv' );
1201
1202    if ( $shouldBeInstalled == '1' && ! empty( $includeFile ) && ! file_exists( $includeFile ) ) {
1203
1204        // } Brutal really, just set the setting
1205        global $zbs;
1206        $zbs->settings->update( 'feat_pdfinv', 0 );
1207
1208        // } Returns true/false
1209        zeroBSCRM_extension_install_pdfinv();
1210
1211    }
1212
1213    $fontsInstalled = zeroBSCRM_getSetting( 'pdf_fonts_installed' );
1214    if ( $checkInstallFonts && $shouldBeInstalled == '1' && $fontsInstalled !== 1 ) {
1215
1216        // check fonts
1217        $fonts = $zbs->get_fonts();
1218        $fonts->extract_and_install_default_fonts();
1219
1220    }
1221}
1222
1223// } Install funcs for free exts
1224function zeroBSCRM_extension_install_pdfinv() {
1225
1226    global $zbs;
1227
1228    if ( ! zeroBSCRM_checkSystemFeat_mb_internal_encoding() ) {
1229        global $zbsExtensionInstallError;
1230        $zbsExtensionInstallError = __( 'Please ensure the mbstring PHP module is enabled on your server prior to installing the PDF Engine.', 'zero-bs-crm' );
1231        return false;
1232    }
1233
1234    // retrieve lib path
1235    $includeFilePath = $zbs->libPath( 'dompdf' );
1236    $includeFile     = $zbs->libInclude( 'dompdf' );
1237
1238    // } Check if already downloaded libs:
1239    if ( ! empty( $includeFile ) && ! file_exists( $includeFile ) ) {
1240
1241        global $zbs;
1242
1243        // } Libs appear to need downloading..
1244
1245            // } dirs
1246            $workingDir = ZEROBSCRM_PATH . 'temp' . time();
1247        if ( ! file_exists( $workingDir ) ) {
1248            wp_mkdir_p( $workingDir );
1249        }
1250            $endingDir = $includeFilePath;
1251        if ( ! file_exists( $endingDir ) ) {
1252            wp_mkdir_p( $endingDir );
1253        }
1254
1255        if ( file_exists( $endingDir ) && file_exists( $workingDir ) ) {
1256
1257            // } Retrieve zip
1258            $libs = zeroBSCRM_retrieveFile( $zbs->urls['extdlrepo'] . 'pdfinv.zip', $workingDir . '/pdfinv.zip' );
1259
1260            // } Expand
1261            if ( file_exists( $workingDir . '/pdfinv.zip' ) ) {
1262
1263                // } Should checksum?
1264
1265                // } For now, expand zip
1266                $expanded = zeroBSCRM_expandArchive( $workingDir . '/pdfinv.zip', $endingDir . '/' );
1267
1268                // } Check success?
1269                if ( file_exists( $includeFile ) ) {
1270
1271                    // } All appears good, clean up
1272                    if ( file_exists( $workingDir . '/pdfinv.zip' ) ) {
1273                        unlink( $workingDir . '/pdfinv.zip' );
1274                    }
1275                    if ( file_exists( $workingDir ) ) {
1276                        rmdir( $workingDir );
1277                    }
1278
1279                    jpcrm_install_core_extension( 'pdfinv' );
1280
1281                    // Also install pdf fonts
1282                    $fonts = $zbs->get_fonts();
1283                    $fonts->extract_and_install_default_fonts();
1284
1285                    return true;
1286
1287                } else {
1288
1289                    // } Add error msg
1290                    global $zbsExtensionInstallError;
1291                    $zbsExtensionInstallError = __( 'Jetpack CRM was not able to extract the libraries it needs to in order to install PDF Engine.', 'zero-bs-crm' );
1292
1293                }
1294            } else {
1295
1296                // } Add error msg
1297                global $zbsExtensionInstallError;
1298                $zbsExtensionInstallError = __( 'Jetpack CRM was not able to download the libraries it needs to in order to install PDF Engine.', 'zero-bs-crm' );
1299
1300            }
1301        } else {
1302
1303            // } Add error msg
1304            global $zbsExtensionInstallError;
1305            $zbsExtensionInstallError = __( 'Jetpack CRM was not able to create the directories it needs to in order to install PDF Engine.', 'zero-bs-crm' );
1306
1307        }
1308    } else {
1309
1310        // } Already exists...
1311
1312        // } Brutal really, just set the setting
1313        global $zbs;
1314        $zbs->settings->update( 'feat_pdfinv', 1 );
1315
1316        // } Make it show up in the array again
1317        global $zeroBSCRM_extensionsInstalledList;
1318        if ( ! is_array( $zeroBSCRM_extensionsInstalledList ) ) {
1319            $zeroBSCRM_extensionsInstalledList = array();
1320        }
1321        $zeroBSCRM_extensionsInstalledList[] = 'pdfinv';
1322
1323        // Also install pdf fonts
1324        $fonts = $zbs->get_fonts();
1325        $fonts->extract_and_install_default_fonts();
1326
1327        return true;
1328
1329    }
1330
1331    // } Return fail
1332    return false;
1333}
1334
1335// } Uninstall funcs for free exts
1336function zeroBSCRM_extension_uninstall_pdfinv() {
1337    return jpcrm_uninstall_core_extension( 'pdfinv' );
1338}
1339
1340// } Transactions: New 2.98.2
1341function zeroBSCRM_extension_install_transactions() {
1342    return jpcrm_install_core_extension( 'transactions' );
1343}
1344function zeroBSCRM_extension_uninstall_transactions() {
1345    return jpcrm_uninstall_core_extension( 'transactions' );
1346}
1347
1348function zeroBSCRM_extension_install_forms() {
1349    return jpcrm_install_core_extension( 'forms' );
1350}
1351
1352function zeroBSCRM_extension_uninstall_forms() {
1353    return jpcrm_uninstall_core_extension( 'forms' );
1354}
1355
1356function zeroBSCRM_extension_install_jetpackforms() {
1357    return jpcrm_install_core_extension( 'jetpackforms' );
1358}
1359function zeroBSCRM_extension_uninstall_jetpackforms() {
1360    return jpcrm_uninstall_core_extension( 'jetpackforms' );
1361}
1362
1363function zeroBSCRM_extension_install_b2bmode() {
1364    return jpcrm_install_core_extension( 'b2bmode' );
1365}
1366function zeroBSCRM_extension_uninstall_b2bmode() {
1367    return jpcrm_uninstall_core_extension( 'b2bmode' );
1368}
1369
1370function zeroBSCRM_extension_install_cal() {
1371    return jpcrm_install_core_extension( 'cal' );
1372}
1373
1374function zeroBSCRM_extension_uninstall_cal() {
1375    return jpcrm_uninstall_core_extension( 'cal' );
1376}
1377
1378function zeroBSCRM_extension_install_quotebuilder() {
1379    $result = jpcrm_install_core_extension( 'quotebuilder', true );
1380    return $result;
1381}
1382
1383function zeroBSCRM_extension_uninstall_quotebuilder() {
1384    $result = jpcrm_uninstall_core_extension( 'quotebuilder', true );
1385    return $result;
1386}
1387
1388function zeroBSCRM_extension_install_invbuilder() {
1389    return jpcrm_install_core_extension( 'invbuilder', true );
1390}
1391
1392function zeroBSCRM_extension_uninstall_invbuilder() {
1393    return jpcrm_uninstall_core_extension( 'invbuilder', true );
1394}
1395
1396function zeroBSCRM_extension_install_csvimporterlite() {
1397    return jpcrm_install_core_extension( 'csvimporterlite' );
1398}
1399
1400function zeroBSCRM_extension_uninstall_csvimporterlite() {
1401    return jpcrm_uninstall_core_extension( 'csvimporterlite' );
1402}
1403
1404function zeroBSCRM_extension_install_api() {
1405    return jpcrm_install_core_extension( 'api', true );
1406}
1407
1408function zeroBSCRM_extension_uninstall_api() {
1409    return jpcrm_uninstall_core_extension( 'api', true );
1410}
1411
1412// } Free extensions init
1413function zeroBSCRM_freeExtensionsInit() {
1414
1415    global $zeroBSCRM_extensionsInstalledList, $jpcrm_core_extension_setting_map;
1416
1417    $zeroBSCRM_extensionsInstalledList = array();
1418
1419    foreach ( $jpcrm_core_extension_setting_map as $ext_name => $setting_name ) {
1420        if ( zeroBSCRM_getSetting( $setting_name ) == 1 ) {
1421            $zeroBSCRM_extensionsInstalledList[] = $ext_name;
1422        }
1423    }
1424}
1425
1426/**
1427 * @param $ext_name Extension name
1428 * @return bool
1429 */
1430function jpcrm_install_core_extension( $ext_name, $flag_for_flush_rewrite = false ) {
1431
1432    global $zbs, $zeroBSCRM_extensionsInstalledList, $jpcrm_core_extension_setting_map;
1433
1434    $ext_setting = $jpcrm_core_extension_setting_map[ $ext_name ];
1435
1436    $zbs->settings->update( $ext_setting, 1 );
1437
1438    // Add to the installed extension list
1439    $is_installed = array_search( $ext_name, $zeroBSCRM_extensionsInstalledList );
1440
1441    if ( ! $is_installed ) {
1442        $zeroBSCRM_extensionsInstalledList[] = $ext_name;
1443
1444        // flush rewrite rules as needed
1445        if ( $flag_for_flush_rewrite ) {
1446            jpcrm_flag_for_flush_rewrite();
1447        }
1448        return true;
1449    }
1450    return false;
1451}
1452
1453/**
1454 * @param $ext_name Extension name
1455 * @return bool
1456 */
1457function jpcrm_uninstall_core_extension( $ext_name, $flag_for_flush_rewrite = false ) {
1458    global $zbs, $zeroBSCRM_extensionsInstalledList, $jpcrm_core_extension_setting_map;
1459
1460    $ext_setting = $jpcrm_core_extension_setting_map[ $ext_name ];
1461
1462    $zbs->settings->update( $ext_setting, -1 );
1463
1464    // Remove from the installed extension list
1465    $idx = array_search( $ext_name, $zeroBSCRM_extensionsInstalledList );
1466
1467    if ( $idx !== false ) {
1468        array_splice( $zeroBSCRM_extensionsInstalledList, $idx, 1 );
1469
1470        // flush rewrite rules as needed
1471        if ( $flag_for_flush_rewrite ) {
1472            jpcrm_flag_for_flush_rewrite();
1473        }
1474
1475        return true;
1476    }
1477
1478    return false;
1479}
1480
1481/**
1482 * Registers an external extension, (adds to our global list, for now)
1483 *
1484 * @param $ext_name Extension name
1485 * @return bool
1486 */
1487function jpcrm_register_external_extension( $ext_name ) {
1488
1489    if ( ! empty( $ext_name ) ) {
1490
1491        global $zeroBSCRM_extensionsInstalledList;
1492
1493        if ( ! is_array( $zeroBSCRM_extensionsInstalledList ) ) {
1494            $zeroBSCRM_extensionsInstalledList = array();
1495        }
1496
1497        $zeroBSCRM_extensionsInstalledList[] = $ext_name;
1498
1499        return true;
1500
1501    }
1502
1503    return false;
1504}
1505
1506/*
1507======================================================
1508    EXTENSION DETAILS / FREE/included EXTENSIONS
1509    ====================================================== */