PluginProbe
Bookit — Booking & Appointment Calendar / trunk
Bookit — Booking & Appointment Calendar vtrunk
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 2.1.5 All 61 releases
bookit / includes / classes / base / AddonsFactory.php

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

171 lines 4.6 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' => __(
62 'Service: [service_title]' . PHP_EOL . // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
63 'Customer: [customer_name]' . PHP_EOL .
64 'Customer phone: [customer_phone]' . PHP_EOL .
65 'Customer email: [customer_email]' . PHP_EOL .
66 'Start time: [start_time]' . PHP_EOL .
67 'Payment Method: [payment_method]' . PHP_EOL .
68 'Payment Status: [payment_status]' . PHP_EOL .
69 'Total: [total]' . PHP_EOL . 'Status: [status]',
70 'bookit'
71 ),
72 ),
73 );
74 }
75
76 /**
77 * Get Pro Settings
78 *
79 * @since 2.5.0
80 *
81 * @return array Pro settings configuration.
82 */
83 private function proSettings() {
84 return [
85 'payments' => [
86 [
87 'name' => 'stripeConnect',
88 'formatted_name' => esc_html_x( 'Stripe Connect', 'Stripe Connect payment singular name.', 'bookit' ),
89 'settings' => [],
90 ],
91 [
92 'name' => 'paypal',
93 'formatted_name' => esc_html_x( 'PayPal - Legacy', 'PayPal Legacy payment singular name.', 'bookit' ),
94 'settings' => [],
95 ],
96 [
97 'name' => 'stripe',
98 'formatted_name' => esc_html_x( 'Stripe - Legacy', 'Stripe Legacy payment singular name.', 'bookit' ),
99 'settings' => [],
100 ],
101 [
102 'name' => 'woocommerce',
103 'formatted_name' => esc_html_x( 'WooCommerce', 'WooCommerce payment singular name.', 'bookit' ),
104 'settings' => [],
105 ],
106 ],
107 ];
108 }
109 }
110
111 /**
112 * Class AddonsFactory
113 * generate data for addons which
114 * is not installed
115 */
116 class AddonsFactory {
117
118 /**
119 * Bookit Addons List
120 *
121 * @var string[]
122 */
123 public static $existAddons = array(
124 array(
125 'name' => 'pro',
126 'tab' => 'payments',
127 'link' => 'https://stylemixthemes.com/wordpress-appointment-plugin/?utm_source=admin&utm_medium=promo&utm_campaign=2020',
128 ),
129 );
130
131
132 /**
133 * Generate empty data for exist addons
134 * used to show all addon abilites to user
135 *
136 * @param array $installedAddons
137 *
138 * @return array
139 */
140 public static function getExistAddonsList( $installedAddons = array() ) {
141 /** clean self::$existAddons from installed */
142 self::removeInstalledAddonsFromExistList( $installedAddons );
143
144 $addons = array();
145 foreach ( self::$existAddons as $addon ) {
146 $fakeAddon = new FakeAddon( $addon['name'], $addon['tab'], $addon['link'] );
147 $addons[] = array(
148 'name' => $addon['name'],
149 'data' => $fakeAddon->getAddonData(),
150 'translations' => array(),
151 'freemius' => FreemiusHelper::get_addon_info( Plugin::$prefix . $addon['name'] ),
152 );
153 }
154 return $addons;
155 }
156
157 /**
158 * remove already exist addons from list
159 *
160 * @param $installedAddons
161 */
162 private static function removeInstalledAddonsFromExistList( $installedAddons ) {
163 self::$existAddons = array_filter(
164 self::$existAddons,
165 function ( $addon ) use ( $installedAddons ) {
166 return array_search( $addon['name'], $installedAddons ) === false;
167 }
168 );
169 }
170 }
171