| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2025 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Help wizard controller. |
| 16 |
* |
| 17 |
* @since 1.18.2 (J) - 1.8.2 (WP) |
| 18 |
*/ |
| 19 |
class VikBookingControllerHelpwizard extends JControllerAdmin |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Show the details of the first eligible instruction. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function show() |
| 27 |
{ |
| 28 |
$app = JFactory::getApplication(); |
| 29 |
|
| 30 |
if (!JSession::checkToken()) { |
| 31 |
// missing CSRF-proof token |
| 32 |
VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN')); |
| 33 |
} |
| 34 |
|
| 35 |
/** @var VBOHelpWizard */ |
| 36 |
$helpWizard = VBOFactory::getHelpWizard(); |
| 37 |
|
| 38 |
/** @var VBOHelpWizardInstruction|null */ |
| 39 |
$instruction = $helpWizard->getNextInstruction(); |
| 40 |
|
| 41 |
if ($instruction) |
| 42 |
{ |
| 43 |
$resp = [ |
| 44 |
'has' => true, |
| 45 |
'id' => $instruction->getID(), |
| 46 |
'title' => $instruction->getTitle(), |
| 47 |
'icon' => $instruction->getIcon(), |
| 48 |
'html' => $instruction->show(), |
| 49 |
'dismissible' => $instruction->isDismissible(), |
| 50 |
'processable' => $instruction->isProcessable($btnText), |
| 51 |
'processtext' => $btnText, |
| 52 |
]; |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
$resp = [ |
| 57 |
'has' => false, |
| 58 |
]; |
| 59 |
} |
| 60 |
|
| 61 |
// send the response to output |
| 62 |
VBOHttpDocument::getInstance($app)->json($resp); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Dismisses the specified instruction. |
| 67 |
* |
| 68 |
* @return void |
| 69 |
*/ |
| 70 |
public function dismiss() |
| 71 |
{ |
| 72 |
$app = JFactory::getApplication(); |
| 73 |
|
| 74 |
if (!JSession::checkToken()) { |
| 75 |
// missing CSRF-proof token |
| 76 |
VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN')); |
| 77 |
} |
| 78 |
|
| 79 |
$id = $app->input->get('instruction', ''); |
| 80 |
$datetime = $app->input->getString('datetime'); |
| 81 |
|
| 82 |
/** @var VBOHelpWizard */ |
| 83 |
$helpWizard = VBOFactory::getHelpWizard(); |
| 84 |
|
| 85 |
/** @var VBOHelpWizardInstruction|null */ |
| 86 |
$instruction = $helpWizard->getInstruction($id); |
| 87 |
|
| 88 |
if (!$instruction) { |
| 89 |
VBOHttpDocument::getInstance($app)->close(404, 'Help wizard instruction not found.'); |
| 90 |
} |
| 91 |
|
| 92 |
$helpWizard->dismiss($instruction, $datetime); |
| 93 |
|
| 94 |
$app->close(); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Processes the specified instruction. |
| 99 |
* |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
public function process() |
| 103 |
{ |
| 104 |
$app = JFactory::getApplication(); |
| 105 |
|
| 106 |
if (!JSession::checkToken()) { |
| 107 |
// missing CSRF-proof token |
| 108 |
VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN')); |
| 109 |
} |
| 110 |
|
| 111 |
$id = $app->input->get('instruction', ''); |
| 112 |
$args = $app->input->get('args', [], 'array'); |
| 113 |
|
| 114 |
/** @var VBOHelpWizard */ |
| 115 |
$helpWizard = VBOFactory::getHelpWizard(); |
| 116 |
|
| 117 |
/** @var VBOHelpWizardInstruction|null */ |
| 118 |
$instruction = $helpWizard->getInstruction($id); |
| 119 |
|
| 120 |
if (!$instruction) { |
| 121 |
VBOHttpDocument::getInstance($app)->close(404, 'Help wizard instruction not found.'); |
| 122 |
} |
| 123 |
|
| 124 |
try { |
| 125 |
if (!$instruction->isProcessable()) { |
| 126 |
throw new RuntimeException('The instruction [' . $id . '] cannot be processed!', 403); |
| 127 |
} |
| 128 |
|
| 129 |
$return = $instruction->process($args); |
| 130 |
|
| 131 |
if ($return) { |
| 132 |
VBOHttpDocument::getInstance($app)->json($return); |
| 133 |
} |
| 134 |
} catch (Exception $error) { |
| 135 |
VBOHttpDocument::getInstance($app)->close($error->getCode() ?: 500, $error->getMessage() ?: 'An error has occurred.'); |
| 136 |
} |
| 137 |
|
| 138 |
$app->close(); |
| 139 |
} |
| 140 |
} |
| 141 |
|