/** * Returns the location of the view for this module in the filesystem. * * @param string $View * @param string $ApplicationFolder * @return array */ public function fetchViewLocation($View = '', $ApplicationFolder = '') { if ($View == '') { $View = strtolower($this->name()); } if (substr($View, -6) == 'module') { $View = substr($View, 0, -6); } if (substr($View, 0, 4) == 'gdn_') { $View = substr($View, 4); } if ($ApplicationFolder == '') { $ApplicationFolder = strpos($this->_ApplicationFolder, '/') ? $this->_ApplicationFolder : strtolower($this->_ApplicationFolder); } $ThemeFolder = $this->_ThemeFolder; $ViewPath = null; // Try to use Gdn_Controller's FetchViewLocation if (Gdn::controller() instanceof Gdn_Controller) { try { $ViewPath = Gdn::controller()->fetchViewLocation($View, 'modules', $ApplicationFolder); } catch (Exception $Ex) { } } if (!$ViewPath) { $ViewPaths = array(); // 1. An explicitly defined path to a view if (strpos($View, '/') !== false) { $ViewPaths[] = $View; } // 2. A theme if ($ThemeFolder != '') { // a. Application-specific theme view. eg. /path/to/application/themes/theme_name/app_name/views/modules/ $ViewPaths[] = CombinePaths(array(PATH_THEMES, $ThemeFolder, $ApplicationFolder, 'views', 'modules', $View . '.php')); // b. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/modules/ $ViewPaths[] = CombinePaths(array(PATH_THEMES, $ThemeFolder, 'views', 'modules', $View . '.php')); } // 3. Application default. eg. /path/to/application/app_name/views/controller_name/ if ($this->_ApplicationFolder) { $ViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $ApplicationFolder, 'views', 'modules', $View . '.php')); } else { $ViewPaths[] = dirname($this->path()) . "/../views/modules/{$View}.php"; } // 4. Garden default. eg. /path/to/application/dashboard/views/modules/ $ViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', 'modules', $View . '.php')); $ViewPath = Gdn_FileSystem::exists($ViewPaths); } if ($ViewPath === false) { throw new Exception(ErrorMessage('Could not find a `' . $View . '` view for the `' . $this->Name() . '` module in the `' . $ApplicationFolder . '` application.', get_class($this), 'FetchView'), E_USER_ERROR); } return $ViewPath; }