12 use PHPUnit\Util\Json;
13 use Symfony\Component\HttpFoundation\JsonResponse;
51 return $this->request->headers->get(
'X-Elgg-Ajax-API') ===
'2';
64 return !$this->response_sent && $this->isAjax2Request();
75 if (!is_string($string)) {
106 $data = (object) $this->events->triggerResults(
'ajax_results', $event_type, [],
$data);
109 if (!property_exists(
$data,
'value')) {
110 throw new InvalidArgumentException(
'$data must have a property "value"');
113 if ($this->request->getParam(
'elgg_fetch_messages',
true)) {
124 if ($this->request->getParam(
'elgg_fetch_deps',
true)) {
126 'js' => $this->esm->getImports(),
130 foreach ($this->externalFiles->getLoadedResources(
'css',
'head') as
$name =>
$resource) {
131 if (
$name ===
'elgg') {
147 $response->setTtl((
int) $this->request->getParam(
'elgg_response_ttl', 0,
false));
149 $this->response_sent =
true;
161 public function respondWithError(
string $msg =
'',
int $status = 400): JsonResponse|false {
162 $response = new JsonResponse([
'error' => $msg], $status);
165 $this->msgs->dumpRegister();
167 $this->response_sent =
true;
179 $this->allowed_views[
$view] = true;
190 unset($this->allowed_views[
$view]);
199 return array_keys($this->allowed_views);
if(! $user||! $user->canDelete()) $name
if(!empty($avatar) &&! $avatar->isValid()) elseif(empty($avatar)) if(! $owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
catch(AuthenticationException|LoginException $e) if(elgg_is_xhr()) $output
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/clear'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin', 'controller'=> \Elgg\Diagnostics\DownloadController::class,], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
if(! $entity instanceof \ElggUser) $data
Models the Ajax API service.
isAjax2Request()
Did the request come from the elgg/Ajax module?
__construct(protected EventsService $events, protected SystemMessagesService $msgs, protected Request $request, protected ESMService $esm, protected ExternalFiles $externalFiles)
Constructor.
registerView(string $view)
Register a view to be available for ajax calls.
isReady()
Is the service ready to respond to the request?
respondWithError(string $msg='', int $status=400)
Send a JSON HTTP 400 response.
getViews()
Returns an array of views allowed for ajax calls.
respondFromOutput(mixed $output, string $event_type='', bool $try_decode=true)
Send a JSON HTTP response with the given output.
decodeJson($string)
Attempt to JSON decode the given string.
unregisterView(string $view)
Unregister a view for ajax calls.
Exception thrown if an argument is not of the expected type.
Exception thrown if an error which can only be found on runtime occurs.
Keeps track of ES modules.
if($email instanceof \Elgg\Email) $object
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
_elgg_services()
Get the global service provider.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.