| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - E4J srl |
| 6 |
* @copyright Copyright (C) 2026 E4J srl. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access to this file |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* VikBooking Apps controller for third-party applications. |
| 16 |
* |
| 17 |
* @since 1.18.6 (J) - 1.8.6 (WP) |
| 18 |
*/ |
| 19 |
class VikBookingControllerApps extends JControllerAdmin |
| 20 |
{ |
| 21 |
/** |
| 22 |
* OAuth endpoint that will spawn the requested environment. |
| 23 |
* To be used as OAuth redirect URL for third-party Apps. |
| 24 |
*/ |
| 25 |
public function oauth() |
| 26 |
{ |
| 27 |
$app = JFactory::getApplication(); |
| 28 |
|
| 29 |
// access the involved environment of VikBooking to spawn |
| 30 |
$environment = $app->input->getString('env'); |
| 31 |
|
| 32 |
// spawn the requested environment |
| 33 |
switch ($environment) { |
| 34 |
case 'dac': |
| 35 |
// spawn Door Access Control framework |
| 36 |
try { |
| 37 |
VBODooraccessFactory::getInstance()->spawnOAuthCallback(); |
| 38 |
} catch (Exception $e) { |
| 39 |
// send error caught to output |
| 40 |
VBOHttpDocument::getInstance($app)->close($e->getCode(), $e->getMessage()); |
| 41 |
} |
| 42 |
break; |
| 43 |
|
| 44 |
default: |
| 45 |
// spawn nothing |
| 46 |
break; |
| 47 |
} |
| 48 |
|
| 49 |
// trigger event to allow third-party plugins to spawn |
| 50 |
VBOFactory::getPlatform()->getDispatcher()->trigger('onAppsOauthSpawn', [$environment]); |
| 51 |
|
| 52 |
// close the request if unhandled |
| 53 |
VBOHttpDocument::getInstance($app)->close(200, 'OAuth link was reached.'); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Webhook endpoint that will spawn the requested environment. |
| 58 |
* To be used as Webhook endpoint URL for third-party Apps. |
| 59 |
*/ |
| 60 |
public function webhook() |
| 61 |
{ |
| 62 |
$app = JFactory::getApplication(); |
| 63 |
|
| 64 |
// access the involved environment of VikBooking to spawn |
| 65 |
$environment = $app->input->getString('env'); |
| 66 |
|
| 67 |
// spawn the requested environment |
| 68 |
switch ($environment) { |
| 69 |
case 'dac': |
| 70 |
// spawn Door Access Control framework |
| 71 |
try { |
| 72 |
VBODooraccessFactory::getInstance()->spawnWebhookCallback(); |
| 73 |
} catch (Exception $e) { |
| 74 |
// send error caught to output |
| 75 |
VBOHttpDocument::getInstance($app)->close($e->getCode(), $e->getMessage()); |
| 76 |
} |
| 77 |
break; |
| 78 |
|
| 79 |
default: |
| 80 |
// spawn nothing |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
// trigger event to allow third-party plugins to spawn |
| 85 |
VBOFactory::getPlatform()->getDispatcher()->trigger('onAppsWebhookSpawn', [$environment]); |
| 86 |
|
| 87 |
// close the request if unhandled |
| 88 |
VBOHttpDocument::getInstance($app)->close(200, 'Webhook endpoint URL was reached.'); |
| 89 |
} |
| 90 |
} |
| 91 |
|