PluginProbe
Bookit — Booking & Appointment Calendar / 2.6.0.5
Bookit — Booking & Appointment Calendar v2.6.0.5
2.6.0.5 2.6.0.4 2.6.0.3 2.6.0.2 2.6.0.1 2.6.0 trunk 1.2 1.2.2 1.2.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 All 62 releases
bookit / includes / classes / base / AddonsFactory.php

AddonsFactory.php in Bookit — Booking & Appointment Calendar 2.6.0.5, at includes/classes/base/AddonsFactory.php

161 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Bookit\Classes\Base;
4
5 use Bookit\Classes\Base\Addon;
6 use Bookit\Helpers\FreemiusHelper;
7
8 class FakeAddon extends Addon {
9
10 public function __construct( $name, $settingTab, $link ) {
11 self::$title = $this->generateTitleFromName( $name );
12 self::$link = $link;
13 self::$settingTab = $settingTab;
14
15 $getSettingsFunction = lcfirst(
16 str_replace( '-', '', ucwords( $name . 'Settings', '-' ) )
17 );
18
19 $settings = array();
20 if ( method_exists( __CLASS__, $getSettingsFunction ) ) {
21 $settings = call_user_func( array( __CLASS__, $getSettingsFunction ) );
22 }
23
24 self::$settings = $settings;
25 }
26
27 public function generateTitleFromName( $name ) {
28 return implode( ' ', array_map( 'ucfirst', explode( '-', $name ) ) );
29 }
30
31 /**
32 * Default addon info for plugin
33 *
34 * @return array
35 */
36 public function getAddonData() {
37 return array(
38 'tab' => self::$settingTab,
39 'title' => self::$title,
40 'active' => self::$active,
41 'link' => self::$link,
42 'settings' => self::$settings,
43 'installed' => false, // always false
44 'isCanUse' => ( self::$is_premium && self::$is_paying || ! self::$is_premium ),
45 'activationLink' => self::$activationLink,
46 );
47 }
48
49 private static function googleCalendarSettings() {
50 return array(
51 'enabled' => true,
52 'redirect_url' => get_site_url() . '/wp-admin/admin.php?page=bookit-staff',
53 'client_id' => '',
54 'client_secret' => '',
55 'send_pending' => false,
56 'rm_busy_slots' => false,
57 'customer_as_attendees' => false,
58 'events_limit' => null,
59 'template' => array(
60 'title' => __( 'Appointment #[appointment_id]', 'bookit' ),
61 'body' => __( "Service: [service_title]\nCustomer: [customer_name]\nCustomer phone: [customer_phone]\nCustomer email: [customer_email]\nStart time: [start_time]\nPayment Method: [payment_method]\nPayment Status: [payment_status]\nTotal: [total]\nStatus: [status]", 'bookit' ),
62 ),
63 );
64 }
65
66 /**
67 * Get Pro Settings
68 *
69 * @since 2.5.0
70 *
71 * @return array Pro settings configuration.
72 */
73 private function proSettings() {
74 return [
75 'payments' => [
76 [
77 'name' => 'stripeConnect',
78 'formatted_name' => esc_html_x( 'Stripe Connect', 'Stripe Connect payment singular name.', 'bookit' ),
79 'settings' => [],
80 ],
81 [
82 'name' => 'paypal',
83 'formatted_name' => esc_html_x( 'PayPal - Legacy', 'PayPal Legacy payment singular name.', 'bookit' ),
84 'settings' => [],
85 ],
86 [
87 'name' => 'stripe',
88 'formatted_name' => esc_html_x( 'Stripe - Legacy', 'Stripe Legacy payment singular name.', 'bookit' ),
89 'settings' => [],
90 ],
91 [
92 'name' => 'woocommerce',
93 'formatted_name' => esc_html_x( 'WooCommerce', 'WooCommerce payment singular name.', 'bookit' ),
94 'settings' => [],
95 ],
96 ],
97 ];
98 }
99 }
100
101 /**
102 * Class AddonsFactory
103 * generate data for addons which
104 * is not installed
105 */
106 class AddonsFactory {
107
108 /**
109 * Bookit Addons List
110 *
111 * @var string[]
112 */
113 public static $existAddons = array(
114 array(
115 'name' => 'pro',
116 'tab' => 'payments',
117 'link' => 'https://stylemixthemes.com/wordpress-appointment-plugin/?utm_source=admin&utm_medium=promo&utm_campaign=2020',
118 ),
119 );
120
121
122 /**
123 * Generate empty data for exist addons
124 * used to show all addon abilites to user
125 *
126 * @param array $installedAddons
127 *
128 * @return array
129 */
130 public static function getExistAddonsList( $installedAddons = array() ) {
131 /** clean self::$existAddons from installed */
132 self::removeInstalledAddonsFromExistList( $installedAddons );
133
134 $addons = array();
135 foreach ( self::$existAddons as $addon ) {
136 $fakeAddon = new FakeAddon( $addon['name'], $addon['tab'], $addon['link'] );
137 $addons[] = array(
138 'name' => $addon['name'],
139 'data' => $fakeAddon->getAddonData(),
140 'translations' => array(),
141 'freemius' => FreemiusHelper::get_addon_info( Plugin::$prefix . $addon['name'] ),
142 );
143 }
144 return $addons;
145 }
146
147 /**
148 * remove already exist addons from list
149 *
150 * @param $installedAddons
151 */
152 private static function removeInstalledAddonsFromExistList( $installedAddons ) {
153 self::$existAddons = array_filter(
154 self::$existAddons,
155 function ( $addon ) use ( $installedAddons ) {
156 return array_search( $addon['name'], $installedAddons ) === false;
157 }
158 );
159 }
160 }
161