29 protected $file_exists_cache = array();
47 $this->hooks = $hooks;
48 $this->logger = $logger;
59 if (
$user !== $this->user_wrapped) {
60 $warning =
'Use elgg_get_logged_in_user_entity() rather than assuming elgg_view() ' 61 .
'populates $vars["user"]';
62 $this->user_wrapper = new \Elgg\DeprecationWrapper(
$user, $warning, 1.8);
64 $user = $this->user_wrapper;
73 $handle = opendir($folder);
75 while (
$view = readdir($handle)) {
76 if (!empty($view_base)) {
77 $view_base_new = $view_base .
"/";
82 if (substr(
$view, 0, 1) !==
'.') {
83 if (is_dir($folder .
"/" .
$view)) {
84 $this->autoregisterViews($view_base_new . $view, $folder .
"/" . $view,
87 $this->setViewLocation($view_base_new . basename($view,
'.php'),
108 if (!isset($this->CONFIG->viewpath)) {
109 return dirname(dirname(dirname(__FILE__))) .
"/views/";
111 return $this->CONFIG->viewpath;
128 if (!isset($this->CONFIG->views)) {
129 $this->CONFIG->views = new \stdClass;
132 if (!isset($this->CONFIG->views->locations)) {
133 $this->CONFIG->views->locations = array(
$viewtype => array(
$view => $location));
135 }
else if (!isset($this->CONFIG->views->locations[
$viewtype])) {
136 $this->CONFIG->views->locations[
$viewtype] = array(
$view => $location);
149 if (!isset($this->CONFIG->viewtype)) {
150 $this->CONFIG->viewtype = new \stdClass;
153 if (!isset($this->CONFIG->viewtype->fallback)) {
154 $this->CONFIG->viewtype->fallback = array();
157 $this->CONFIG->viewtype->fallback[] =
$viewtype;
166 if (isset($this->CONFIG->viewtype) && isset($this->CONFIG->viewtype->fallback)) {
167 return in_array(
$viewtype, $this->CONFIG->viewtype->fallback);
187 $rendered = $this->renderView(
$view, $vars,
false,
'',
false);
201 $this->logger->log(
"View and Viewtype in views must be a strings: $view",
'NOTICE');
205 if (strpos(
$view,
'..') !==
false) {
209 if (!is_array(
$vars)) {
210 $this->logger->log(
"Vars in views must be an array: $view",
'ERROR');
222 if (!isset($this->CONFIG->pagesetupdone) && $this->CONFIG->boot_complete) {
223 $this->CONFIG->pagesetupdone =
true;
230 if (!isset(
$vars[
'user'])) {
231 $vars[
'user'] = $this->getUserWrapper();
233 if (!isset(
$vars[
'config'])) {
234 if (!$this->config_wrapper) {
235 $warning =
'Do not rely on $vars["config"] or $CONFIG being available in views';
236 $this->config_wrapper = new \Elgg\DeprecationWrapper($this->CONFIG, $warning, 1.8);
238 $vars[
'config'] = $this->config_wrapper;
240 if (!isset(
$vars[
'url'])) {
241 if (!$this->site_url_wrapper) {
242 $warning =
'Do not rely on $vars["url"] being available in views';
243 $this->site_url_wrapper = new \Elgg\DeprecationWrapper(
elgg_get_site_url(), $warning, 1.8);
245 $vars[
'url'] = $this->site_url_wrapper;
251 if (isset(
$vars[
'full']) && !isset(
$vars[
'full_view'])) {
255 if (isset(
$vars[
'full_view'])) {
260 if (isset(
$vars[
'internalname']) && !isset(
$vars[
'__ignoreInternalname']) && !isset(
$vars[
'name'])) {
263 } elseif (isset(
$vars[
'name'])) {
264 if (!isset(
$vars[
'internalname'])) {
265 $vars[
'__ignoreInternalname'] =
'';
271 if (isset(
$vars[
'internalid']) && !isset(
$vars[
'__ignoreInternalid']) && !isset(
$vars[
'name'])) {
274 } elseif (isset(
$vars[
'id'])) {
275 if (!isset(
$vars[
'internalid'])) {
276 $vars[
'__ignoreInternalid'] =
'';
282 if ($bypass ==
false && isset($this->CONFIG->template_handler) && !empty($this->CONFIG->template_handler)) {
283 $template_handler = $this->CONFIG->template_handler;
284 if (is_callable($template_handler)) {
285 return call_user_func($template_handler,
$view,
$vars);
290 if (isset($this->CONFIG->views->extensions[
$view])) {
291 $viewlist = $this->CONFIG->views->extensions[
$view];
293 $viewlist = array(500 =>
$view);
297 foreach ($viewlist as
$view) {
299 $rendering = $this->renderViewFile($view,
$vars,
$viewtype, $issue_missing_notice);
300 if ($rendering !==
false) {
308 $rendering = $this->renderViewFile($view,
$vars,
'default', $issue_missing_notice);
309 if ($rendering !==
false) {
338 if (!isset($this->file_exists_cache[
$path])) {
339 $this->file_exists_cache[
$path] = file_exists($path);
341 return $this->file_exists_cache[
$path];
360 $CONFIG = $this->config_wrapper;
362 if ($this->fileExists(
"{$view_location}$viewtype/$view.php")) {
364 include(
"{$view_location}$viewtype/$view.php");
365 return ob_get_clean();
366 }
else if ($this->fileExists(
"{$view_location}$viewtype/$view")) {
367 return file_get_contents(
"{$view_location}$viewtype/$view");
369 if ($issue_missing_notice) {
370 $this->logger->log(
"$viewtype/$view view does not exist.",
'NOTICE');
388 if (!isset($this->CONFIG->viewpath)) {
389 $location = dirname(dirname(dirname(__FILE__))) .
"/views/";
391 $location = $this->CONFIG->viewpath;
397 if ($this->fileExists(
"{$location}$viewtype/$view.php") ||
398 $this->fileExists(
"{$location}$viewtype/$view")) {
404 if ($recurse && isset($this->CONFIG->views->extensions[$view])) {
405 foreach ($this->CONFIG->views->extensions[$view] as $view_extension) {
407 if ($this->viewExists($view_extension,
$viewtype,
false)) {
415 return $this->viewExists($view,
'default');
428 if (!isset($this->CONFIG->views)) {
429 $this->CONFIG->views = (object) array(
430 'extensions' => array(),
432 $this->CONFIG->views->extensions[
$view][500] = (string)
$view;
434 if (!isset($this->CONFIG->views->extensions[
$view])) {
435 $this->CONFIG->views->extensions[
$view][500] = (string)
$view;
440 while (isset($this->CONFIG->views->extensions[
$view][
$priority])) {
444 $this->CONFIG->views->extensions[
$view][
$priority] = (string) $view_extension;
445 ksort($this->CONFIG->views->extensions[
$view]);
455 if (!isset($this->CONFIG->views)) {
459 if (!isset($this->CONFIG->views->extensions)) {
463 if (!isset($this->CONFIG->views->extensions[
$view])) {
467 $priority = array_search($view_extension, $this->CONFIG->views->extensions[
$view]);
483 if (!isset($this->CONFIG->views)) {
484 $this->CONFIG->views = new \stdClass;
487 if (!isset($this->CONFIG->views->simplecache)) {
488 $this->CONFIG->views->simplecache = array();
491 $this->CONFIG->views->simplecache[
$view] =
true;
500 if (!isset($this->CONFIG->views)) {
501 $this->CONFIG->views = new \stdClass;
504 if (!isset($this->CONFIG->views->simplecache)) {
505 $this->CONFIG->views->simplecache = array();
508 if (isset($this->CONFIG->views->simplecache[
$view])) {
512 $viewtypes = array($currentViewtype);
514 if ($this->doesViewtypeFallback($currentViewtype) && $currentViewtype !=
'default') {
515 $viewtypes[] =
'defaut';
520 $view_file = $this->getViewLocation(
$view, $viewtype) .
"$viewtype/$view";
521 if ($this->fileExists($view_file)) {
autoregisterViews($view_base, $folder, $base_location_path, $viewtype)
private
isCacheableView($view)
private
_elgg_is_valid_viewtype($viewtype)
Checks if $viewtype is a string suitable for use as a viewtype name.
registerCacheableView($view)
private
doesViewtypeFallback($viewtype)
private
renderView($view, array $vars=array(), $bypass=false, $viewtype= '', $issue_missing_notice=true)
private
if(!$autoload_available) _elgg_services()
__construct(\Elgg\PluginHooksService $hooks,\Elgg\Logger $logger)
Constructor.
registerViewtypeFallback($viewtype)
private
viewExists($view, $viewtype= '', $recurse=true)
private
getUserWrapper()
Get the user object in a wrapper.
getViewLocation($view, $viewtype= '')
private
elgg_get_viewtype()
Return the current view type.
extendView($view, $view_extension, $priority=501, $viewtype= '')
private
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
setViewLocation($view, $location, $viewtype= '')
private
fileExists($path)
Wrapper for file_exists() that caches false results (the stat cache only caches true results)...
$content
Set robots.txt action.
unextendView($view, $view_extension)
private
renderDeprecatedView($view, array $vars, $suggestion, $version)
Display a view with a deprecation notice.
if(file_exists($welcome)) $vars