2021-10-29 13:54:49 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-10-29 13:54:49 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-10-29 13:54:49 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.4.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Easy!Appointments input.
|
|
|
|
*
|
2021-10-29 14:04:26 +03:00
|
|
|
* @property EA_Benchmark $benchmark
|
|
|
|
* @property EA_Cache $cache
|
|
|
|
* @property EA_Calendar $calendar
|
|
|
|
* @property EA_Config $config
|
|
|
|
* @property EA_DB_forge $dbforge
|
|
|
|
* @property EA_DB_query_builder $db
|
|
|
|
* @property EA_DB_utility $dbutil
|
|
|
|
* @property EA_Email $email
|
|
|
|
* @property EA_Encrypt $encrypt
|
|
|
|
* @property EA_Encryption $encryption
|
|
|
|
* @property EA_Exceptions $exceptions
|
|
|
|
* @property EA_Hooks $hooks
|
|
|
|
* @property EA_Input $input
|
|
|
|
* @property EA_Lang $lang
|
|
|
|
* @property EA_Loader $load
|
|
|
|
* @property EA_Log $log
|
|
|
|
* @property EA_Migration $migration
|
|
|
|
* @property EA_Output $output
|
|
|
|
* @property EA_Profiler $profiler
|
|
|
|
* @property EA_Router $router
|
|
|
|
* @property EA_Security $security
|
|
|
|
* @property EA_Session $session
|
|
|
|
* @property EA_Upload $upload
|
|
|
|
* @property EA_URI $uri
|
2021-10-29 13:54:49 +03:00
|
|
|
*
|
|
|
|
* @property string $raw_input_stream
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class EA_Input extends CI_Input
|
|
|
|
{
|
2021-10-29 13:54:49 +03:00
|
|
|
/**
|
|
|
|
* Fetch an item from JSON data.
|
|
|
|
*
|
2021-11-03 10:21:53 +03:00
|
|
|
* @param string|null $index Index for item to be fetched from the JSON payload.
|
2021-10-29 13:54:49 +03:00
|
|
|
* @param bool|false $xss_clean Whether to apply XSS filtering
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
public function json(string $index = null, bool $xss_clean = false)
|
2021-10-29 13:54:49 +03:00
|
|
|
{
|
|
|
|
/** @var EA_Controller $CI */
|
|
|
|
$CI = &get_instance();
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (strpos((string) $CI->input->get_request_header('Content-Type'), 'application/json') === false) {
|
|
|
|
return null;
|
2021-10-29 13:54:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$input_stream = $CI->input->raw_input_stream;
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($input_stream)) {
|
2021-10-29 13:54:49 +03:00
|
|
|
throw new RuntimeException('Cannot get JSON attribute from an empty input stream.');
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$payload = json_decode($input_stream, true);
|
2021-10-29 13:54:49 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if ($xss_clean) {
|
|
|
|
foreach ($payload as $name => $value) {
|
2021-11-03 10:21:53 +03:00
|
|
|
$payload[$name] = $CI->security->xss_clean($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($index)) {
|
2021-11-03 10:21:53 +03:00
|
|
|
return $payload;
|
|
|
|
}
|
2021-10-29 13:54:49 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
return $payload[$index] ?? null;
|
2021-10-29 13:54:49 +03:00
|
|
|
}
|
|
|
|
}
|