8 use Elgg\Traits\Loggable;
20 const VIEW_HOOK =
'view';
21 const VIEW_VARS_HOOK =
'view_vars';
22 const OUTPUT_KEY =
'__view_output';
23 const BASE_VIEW_PRIORITY = 500;
28 protected array $file_exists_cache = [];
33 protected array $locations = [];
40 protected array $overrides = [];
50 protected array $fallbacks = [];
54 protected bool $locations_loaded_from_cache =
false;
81 $this->viewtype =
null;
101 if (!isset($this->viewtype)) {
102 $this->viewtype = $this->resolveViewtype();
114 if ($this->request) {
115 $view = $this->request->getParam(
'view',
'',
false);
116 if ($this->isValidViewtype(
$view) && !empty($this->locations[
$view])) {
121 $view = (string) $this->config->view;
122 if ($this->isValidViewtype(
$view) && !empty($this->locations[
$view])) {
155 if ($this->isViewLocationsLoadedFromCache()) {
164 if (!is_file($file)) {
168 $spec = Includer::includeFile($file);
169 if (is_array($spec)) {
171 if ($this->config->font_awesome_zip) {
175 $this->mergeViewsSpec($spec);
189 $folder =
Paths::sanitize($folder);
190 $view_base = Paths::sanitize($view_base,
false);
191 $view_base = $view_base ? $view_base .
'/' : $view_base;
194 $dir = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($folder, \RecursiveDirectoryIterator::SKIP_DOTS));
195 }
catch (\Throwable $t) {
196 $this->getLogger()->error($t->getMessage());
201 foreach ($dir as $file) {
202 $path = $file->getPath() .
'/' . $file->getBasename(
'.php');
206 $view = $view_base . substr(
$path, strlen($folder));
269 $rendered = $this->renderView(
$view,
$vars,
'', false);
271 $this->logDeprecatedMessage(
"The '{$view}' view has been deprecated. {$suggestion}",
$version);
303 public function renderView(
string $view, array
$vars = [],
string $viewtype =
'', ?
bool $issue_missing_notice =
null, array $extensions_tree = []): string {
305 if (str_contains(
$view,
'..')) {
310 if (in_array(
$view, $extensions_tree)) {
311 $this->getLogger()->error(
"View {$view} is detected as an extension of itself. This is not allowed");
316 $extensions_tree[] =
$view;
323 if (!isset($issue_missing_notice)) {
324 $issue_missing_notice =
$viewtype ===
'default';
328 $vars_event_params = [
333 $vars = $this->events->triggerResults(self::VIEW_VARS_HOOK,
$view, $vars_event_params,
$vars);
336 if (isset(
$vars[self::OUTPUT_KEY])) {
337 return (
string)
$vars[self::OUTPUT_KEY];
340 $viewlist = $this->getViewList(
$view);
343 foreach ($viewlist as
$priority => $view_name) {
344 if (
$priority !== self::BASE_VIEW_PRIORITY) {
351 $rendering = $this->renderViewFile($view_name,
$vars,
$viewtype, $issue_missing_notice);
352 if ($rendering !==
false) {
359 $rendering = $this->renderViewFile($view_name,
$vars,
'default', $issue_missing_notice);
360 if ($rendering !==
false) {
384 if (!isset($this->file_exists_cache[
$path])) {
385 $this->file_exists_cache[
$path] = file_exists(
$path);
388 return $this->file_exists_cache[
$path];
404 if ($issue_missing_notice) {
405 $this->getLogger()->notice(
"{$viewtype}/{$view} view does not exist.");
411 if (pathinfo($file, PATHINFO_EXTENSION) ===
'php') {
418 return ob_get_clean();
419 }
catch (\Exception $e) {
425 return file_get_contents($file);
457 if ($recurse && isset($this->
extensions[$view])) {
458 foreach ($this->
extensions[$view] as $view_extension) {
460 if ($this->viewExists($view_extension,
$viewtype,
false)) {
468 return $this->viewExists(
$view,
'default');
486 if (
$view === $view_extension) {
543 if (!is_dir(
$path)) {
548 $dir = new \DirectoryIterator(
$path);
549 }
catch (\Throwable $t) {
550 $this->getLogger()->error($t->getMessage());
554 foreach ($dir as $folder) {
555 $folder_name = $folder->getBasename();
556 if (!$folder->isDir() || str_starts_with($folder_name,
'.')) {
560 if (!$this->autoregisterViews(
'', $folder->getPathname(), $folder_name)) {
586 if (!preg_match(
'~^([/\\\\]|[a-zA-Z]\:)~',
$path)) {
591 if (str_ends_with(
$view,
'/')) {
619 $cached_overrides = $this->server_cache->load(
'view_overrides');
622 'locations' => $this->locations,
623 'overrides' => is_array($cached_overrides) ? $cached_overrides : $this->overrides,
625 'simplecache' =>
_elgg_services()->simpleCache->getCacheableViews(),
635 if (!$this->server_cache->isEnabled()) {
639 $data = $this->server_cache->
load(
'view_locations');
640 if (!is_array(
$data)) {
644 $this->locations =
$data[
'locations'];
645 $this->locations_loaded_from_cache =
true;
654 if (!$this->server_cache->isEnabled()) {
659 if ($this->isViewLocationsLoadedFromCache()) {
663 if (empty($this->locations)) {
664 $this->server_cache->delete(
'view_locations');
668 $this->server_cache->save(
'view_locations', [
'locations' => $this->locations]);
671 $this->server_cache->save(
'view_overrides', $this->overrides);
681 return $this->locations_loaded_from_cache;
690 $modules = $this->server_cache->load(
'esmodules');
691 if (is_array($modules)) {
696 foreach ($this->locations[
'default'] as
$name =>
$path) {
697 if (!str_ends_with(
$name,
'.mjs')) {
704 $this->server_cache->save(
'esmodules', $modules);
$content
Set robots.txt action.
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
$params
Saves global plugin settings.
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/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['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'], '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
$paths
We handle here two possible locations of composer-generated autoload file.
foreach( $paths as $path)
load(stdClass $row)
Loads attributes from the entities table into the object.
Find Elgg and project paths.
viewExists(string $view, string $viewtype='', bool $recurse=true)
Returns whether the specified view exists.
getViewList(string $view)
Get the views, including extensions, used to render a view.
findViewFile(string $view, string $viewtype)
Find the view file.
getESModules()
Returns an array of names of ES modules detected based on view location.
extendView(string $view, string $view_extension, int $priority=501)
Extends a view with another view.
getViewtype()
Get the viewtype.
fileExists(string $path)
Wrapper for file_exists() that caches false results (the stat cache only caches true results).
renderView(string $view, array $vars=[], string $viewtype='', ?bool $issue_missing_notice=null, array $extensions_tree=[])
Renders a view.
isViewLocationsLoadedFromCache()
Checks if view_locations have been loaded from cache.
registerViewsFromPath(string $path)
Register all views in a given path.
configureFromCache()
Configure locations from the cache.
registerCoreViews()
Discover the core views if the system cache did not load.
setViewLocation(string $view, string $viewtype, string $path)
Update the location of a view file.
renderDeprecatedView(string $view, array $vars, string $suggestion, string $version)
Display a view with a deprecation notice.
listViews(string $viewtype='default')
List all views in a viewtype.
mergeViewsSpec(array $spec)
Merge a specification of absolute view paths.
__construct(protected EventsService $events, protected HttpRequest $request, protected Config $config, protected ServerCache $server_cache)
Constructor.
registerViewtypeFallback(string $viewtype)
Register a viewtype to fall back to a default view if a view isn't found for that viewtype.
unextendView(string $view, string $view_extension)
Unextends a view.
doesViewtypeFallback(string $viewtype)
Checks if a viewtype falls back to default.
cacheConfiguration()
Cache the configuration.
isValidViewtype(string $viewtype)
Checks if $viewtype is a string suitable for use as a viewtype name.
setViewtype(string $viewtype='')
Set the viewtype.
getInspectorData()
Get inspector data.
renderViewFile(string $view, array $vars, string $viewtype, bool $issue_missing_notice)
Includes view PHP or static file.
autoregisterViews(string $view_base, string $folder, string $viewtype)
Auto-registers views from a location.
resolveViewtype()
Resolve the initial viewtype.
elgg_get_data_path()
Get the data directory path for this installation, ending with slash.
$config
Advanced site settings, debugging section.
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
_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.