viewExtensions() public static method

Get list of allowed view extensions
public static viewExtensions ( boolean $fresh = false ) : array
$fresh boolean
return array list of extensions
Example #1
0
 /**
  * Get the path to a view.
  *
  * @param string $view the name of the view.
  * @param string $controller the name of the controller invoking the view or blank.
  * @param string $folder the application folder or plugins/<plugin> folder.
  * @param array|null $extensions optional. list of extensions to allow
  * @return string|false The path to the view or false if it wasn't found.
  */
 public static function viewLocation($view, $controller, $folder, $extensions = null)
 {
     $paths = [];
     // If the first character is a forward slash, this is an absolute path
     if (strpos($view, '/') === 0) {
         // This is a path to the view from the root.
         $paths[] = $view;
     } else {
         $view = strtolower($view);
         // Trim "controller" from the end of controller name, if its there
         $controller = strtolower(stringEndsWith($controller, 'Controller', true, true));
         if ($controller) {
             $controller = '/' . $controller;
         }
         // Get list of permitted view extensions
         if (is_null($extensions)) {
             $extensions = AssetModel::viewExtensions();
         }
         // 1. Gather paths from the theme, if enabled
         if (Gdn::controller() instanceof Gdn_Controller) {
             $theme = Gdn::controller()->Theme;
             if ($theme) {
                 foreach ($extensions as $ext) {
                     $paths[] = PATH_THEMES . "/{$theme}/views{$controller}/{$view}.{$ext}";
                 }
             }
         }
         // 2a. Gather paths from the plugin, if the folder is a plugin folder
         if (stringBeginsWith($folder, 'plugins/')) {
             // This is a plugin view.
             foreach ($extensions as $ext) {
                 $paths[] = PATH_ROOT . "/{$folder}/views{$controller}/{$view}.{$ext}";
             }
             // 2b. Gather paths from the application as a fallback
         } else {
             // This is an application view.
             $folder = strtolower($folder);
             foreach ($extensions as $ext) {
                 $paths[] = PATH_APPLICATIONS . "/{$folder}/views{$controller}/{$view}.{$ext}";
             }
             if ($folder != 'dashboard' && stringEndsWith($view, '.master')) {
                 // This is a master view that can always fall back to the dashboard.
                 foreach ($extensions as $ext) {
                     $paths[] = PATH_APPLICATIONS . "/dashboard/views{$controller}/{$view}.{$ext}";
                 }
             }
         }
     }
     // Now let's search the paths for the view.
     foreach ($paths as $path) {
         if (file_exists($path)) {
             return $path;
         }
     }
     trace(['view' => $view, 'controller' => $controller, 'folder' => $folder], 'View');
     trace($paths, __METHOD__);
     return false;
 }