PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / trunk
Timetics – Appointment Booking Calendar & Scheduling vtrunk
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / timetics.php

timetics.php in Timetics – Appointment Booking Calendar & Scheduling trunk, at timetics.php

407 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Timetics - Appointment Booking Calendar & Scheduling System
5 * Plugin URI: https://arraytics.com/timetics/
6 * Description: Schedule, Appointment and Seat Booking plugin.
7 * Version: 1.0.62
8 * Requires at least: 5.2
9 * Requires PHP: 7.3
10 * Author: Arraytics
11 * Author URI: https://arraytics.com/
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: timetics
15 * Domain Path: /languages
16
17 * Timetics is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 2 of the License, or
20 * any later version.
21
22 * Timetics Essential is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26
27 * You should have received a copy of the GNU General Public License
28 * along with Timetics. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * @package Timetics
31 * @category Core
32 * @author Arraytics
33 * @version 1.0.10
34 */
35
36 // Exit if accessed directly.
37 defined( 'ABSPATH' ) || exit;
38
39 /**
40 * The Main Plugin Requirements Checker
41 *
42 * @since 1.0.0
43 */
44 final class Timetics {
45
46 /**
47 * Static Property To Hold Singleton Instance
48 *
49 * @var Timetics The Timetics Requirement Checker Instance
50 */
51 private static $instance;
52
53 /**
54 * Plugin Current Production Version
55 *
56 * @return string
57 */
58 public static function get_version() {
59 return '1.0.62';
60 }
61
62 /**
63 * Requirements Array
64 *
65 * @since 1.0.0
66 * @var array
67 */
68 private $requirements = array(
69 'php' => array(
70 'name' => 'PHP',
71 'minimum' => '7.3',
72 'exists' => true,
73 'met' => false,
74 'checked' => false,
75 'current' => false,
76 ),
77 'wp' => array(
78 'name' => 'WordPress',
79 'minimum' => '5.2',
80 'exists' => true,
81 'checked' => false,
82 'met' => false,
83 'current' => false,
84 ),
85 );
86
87 /**
88 * Singleton Instance
89 *
90 * @return Timetics
91 */
92 public static function get_instance() {
93 if ( null === self::$instance ) {
94 self::$instance = new self();
95 }
96
97 return self::$instance;
98 }
99
100 /**
101 * Setup Plugin Requirements
102 *
103 * @since 1.0.0
104 */
105 private function __construct() {
106 // Always load translation.
107 add_action( 'init', array( $this, 'load_text_domain' ) );
108
109 // Initialize plugin functionalities or quit.
110 $this->requirements_met() ? $this->initialize_modules() : $this->quit();
111 }
112
113 /**
114 * Load Localization Files
115 *
116 * @since 1.0
117 * @return void
118 */
119 public function load_text_domain() {
120 $locale = determine_locale();
121 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core localization hook.
122 $locale = apply_filters( 'plugin_locale', $locale, 'timetics' );
123 $locale = apply_filters( 'timetics_plugin_locale', $locale, 'timetics' );
124
125 $mofile = 'timetics-' . $locale . '.mo';
126
127 // Loco "Custom" location.
128 if ( file_exists( WP_LANG_DIR . '/loco/plugins/' . $mofile ) ) {
129 load_textdomain( 'timetics', WP_LANG_DIR . '/loco/plugins/' . $mofile );
130 }
131
132 // Loco "System" location.
133 if ( file_exists( WP_LANG_DIR . '/plugins/' . $mofile ) ) {
134 load_textdomain( 'timetics', WP_LANG_DIR . '/plugins/' . $mofile );
135 }
136
137 // Bundled translations remain available while WordPress loads language
138 // packs for this text domain automatically.
139 $bundled_mofile = plugin_dir_path( __FILE__ ) . 'languages/' . $mofile;
140 if ( file_exists( $bundled_mofile ) ) {
141 load_textdomain( 'timetics', $bundled_mofile );
142 }
143 }
144
145 /**
146 * Initialize Plugin Modules
147 *
148 * @since 1.0.0
149 * @return void
150 */
151 private function initialize_modules() {
152 require_once dirname( __FILE__ ) . '/autoloader.php';
153 require_once dirname( __FILE__ ) . '/core/settings/settings.php';
154
155 require_once dirname( __FILE__ ) . '/utils/global-helper.php';
156
157 // block for showing banner.
158 require_once plugin_dir_path( __FILE__ ) . '/utils/notice/notice.php';
159 require_once plugin_dir_path( __FILE__ ) . '/utils/banner/banner.php';
160
161 // Include the bootstrap file if not loaded.
162 if ( ! class_exists( 'Timetics\Bootstrap' ) ) {
163 require_once self::get_plugin_dir() . 'bootstrap.php';
164 }
165
166 // init notice class.
167 \Oxaim\Libs\Notice::init();
168
169 // Initialize the bootstraper if exists.
170 if ( class_exists( 'Timetics\Bootstrap' ) ) {
171
172 // Initialize all modules through plugins_loaded.
173 add_action( 'plugins_loaded', array( $this, 'init' ) );
174
175 register_activation_hook( self::get_plugin_file(), array( $this, 'activate' ) );
176 register_deactivation_hook( self::get_plugin_file(), array( $this, 'deactivate' ) );
177 }
178 }
179
180 /**
181 * Check If All Requirements Are Fulfilled
182 *
183 * @return boolean
184 */
185 private function requirements_met() {
186 $this->prepare_requirement_versions();
187
188 $passed = true;
189 $to_meet = wp_list_pluck( $this->requirements, 'met' );
190
191 foreach ( $to_meet as $met ) {
192 if ( empty( $met ) ) {
193 $passed = false;
194 continue;
195 }
196 }
197
198 return $passed;
199 }
200
201 /**
202 * Requirement Version Prepare
203 *
204 * @since 1.0.0
205 *
206 * @return void
207 */
208 private function prepare_requirement_versions() {
209 foreach ( $this->requirements as $dependency => $config ) {
210 switch ( $dependency ) {
211 case 'php':
212 $version = phpversion();
213 break;
214 case 'wp':
215 $version = get_bloginfo( 'version' );
216 break;
217 default:
218 $version = false;
219 }
220
221 if ( ! empty( $version ) ) {
222 $this->requirements[$dependency]['current'] = $version;
223 $this->requirements[$dependency]['checked'] = true;
224 $this->requirements[$dependency]['met'] = version_compare( $version, $config['minimum'], '>=' );
225 }
226 }
227 }
228
229 /**
230 * Initialize everything
231 *
232 * @since 1.0.0
233 *
234 * @return void
235 */
236 public function init() {
237 Timetics\Bootstrap::instantiate( self::get_plugin_file() );
238
239 // Add autoload from composer for integrating uninstallation form
240 if (file_exists(plugin_dir_path( __FILE__ ) . '/vendor/autoload.php')) {
241 require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload.php';
242 }
243
244 if (class_exists('UninstallerForm\UninstallerForm') && is_callable(['\UninstallerForm\UninstallerForm', 'init'])) {
245
246 $reflection = new ReflectionMethod('\UninstallerForm\UninstallerForm', 'init');
247
248 // Maximum number of parameters allowed
249 $totalParams = $reflection->getNumberOfParameters();
250
251 if($totalParams === 6) {
252 add_filter( 'rest_request_before_callbacks', function( $response, $handler, $request ) {
253 if ( $request->get_route() === '/timetics/v1/feedback' ) {
254 $params = $request->get_json_params();
255
256 if ( empty( $params['email'] ) ) {
257 $params['email'] = get_option( 'admin_email' );
258 $request->set_body( wp_json_encode( $params ) );
259 }
260 }
261 return $response;
262 }, 10, 3 );
263
264 \UninstallerForm\UninstallerForm::init(
265 'Timetics', // Plugin name
266 'timetics', // Plugin Slug
267 __FILE__,
268 'timetics', // Text Domain Name
269 'timetics-feedback-modal', // plugins-admin-script-handler
270 'https://arraytics.com/?fluentcrm=1&route=contact&hash=13cce8a6-c038-4997-91e7-4a2326cc1124'
271 );
272 } else {
273 add_filter( 'rest_request_before_callbacks', function( $response, $handler, $request ) {
274 if ( $request->get_route() === '/timetics/v1/feedback' ) {
275 $params = $request->get_json_params();
276
277 if ( empty( $params['email'] ) ) {
278 $params['email'] = get_option( 'admin_email' );
279 $request->set_body( wp_json_encode( $params ) );
280 }
281 }
282 return $response;
283 }, 10, 3 );
284
285 \UninstallerForm\UninstallerForm::init(
286 'Timetics', // Plugin name
287 'timetics', // Plugin Slug
288 __FILE__,
289 'timetics', // Text Domain Name
290 'timetics-feedback-modal'
291 );
292 }
293 }
294 }
295
296 /**
297 * Called Only Once While Activation
298 *
299 * @return void
300 */
301 public function activate() {
302 // Insert new role.
303 Timetics\Base\Role::instance()->init();
304
305 // Update default settings.
306 timetics_update_default_settings();
307
308 // Register cron
309 timetics_register_cron();
310
311 // Create new woocommerce product category for timetics meeting
312 timetics_add_woocommerce_product_cat();
313
314 // Force rewrite-rule flush on activation; the maybe_flush_rules guard handles subsequent upgrades.
315 delete_option( 'timetics_rewrite_version' );
316
317 // Update option for onboard settings.
318 $timetics_onboard_setup = get_option( 'timetics_onboard_setup' );
319
320 $timetics_demo_data = get_option( 'timetics_demo_data' );
321
322 if ( ! $timetics_demo_data ) {
323 $dummy_data_generator = new Timetics\Core\DummyData\Dummy_Data_Generator();
324 $dummy_data_generator->generate();
325 update_option( 'timetics_demo_data', true );
326 }
327
328 if ( ! $timetics_onboard_setup ) {
329 update_option( 'timetics_onboard_settings', true );
330 }
331 }
332
333 /**
334 * Called Only Once While Deactivation
335 *
336 * @return void
337 */
338 public function deactivate() {
339 }
340
341 /**
342 * Quit Plugin Execution
343 *
344 * @return void
345 */
346 private function quit() {
347 add_action( 'admin_head', array( $this, 'show_plugin_requirements_not_met_notice' ) );
348 }
349
350 /**
351 * Show Error Notice For Missing Requirements
352 *
353 * @return void
354 */
355 public function show_plugin_requirements_not_met_notice() {
356 printf( '<div>Minimum requirements for Timetics are not met. Please update requirements to continue.</div>' );
357 }
358
359 /**
360 * Plugin Main File
361 *
362 * @return string
363 */
364 public static function get_plugin_file() {
365 return __FILE__;
366 }
367
368 /**
369 * Plugin Base Directory Path
370 *
371 * @return string
372 */
373 public static function get_plugin_dir() {
374 return trailingslashit( plugin_dir_path( self::get_plugin_file() ) );
375 }
376 }
377
378 /**
379 * Add a "Go Pro" action link on the Plugins page.
380 * Hidden when the pro plugin already exists.
381 */
382 if ( ! function_exists( 'timetics_add_go_pro_action_link' ) ) {
383 function timetics_add_go_pro_action_link( $links ) {
384 if ( ! function_exists( 'get_plugins' ) ) {
385 require_once ABSPATH . 'wp-admin/includes/plugin.php';
386 }
387
388 foreach ( get_plugins() as $plugin ) {
389 if ( isset( $plugin['TextDomain'] ) && 'timetics-pro' === $plugin['TextDomain'] ) {
390 return $links;
391 }
392 }
393
394 $go_pro = sprintf(
395 '<a href="%1$s" target="_blank" rel="noopener noreferrer" style="color:#e8364c;font-weight:600;">%2$s</a>',
396 esc_url( 'https://arraytics.com/timetics/pricing/' ),
397 esc_html__( 'Go Pro', 'timetics' )
398 );
399
400 $links[] = $go_pro;
401 return $links;
402 }
403 }
404 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'timetics_add_go_pro_action_link' );
405
406 Timetics::get_instance();
407