/** * Get MVC view object * * Get a view object using specified view file and data array. * @param string $file MVC view file pathname. * @param array $data View's data. * @param int $_callerDepth * @return \Ip\View * @throws \Ip\Exception\View */ function ipView($file, $data = array(), $_callerDepth = 0) { if ($file[0] == '/' || $file[1] == ':') { // Absolute filename return new \Ip\View($file, $data); } if (preg_match('%^(Plugin|Theme|file|Ip)/%', $file)) { $relativePath = $file; } else { $relativePath = \Ip\Internal\PathHelper::ipRelativeDir($_callerDepth + 1) . $file; } $fileInThemeDir = ipThemeFile(\Ip\View::OVERRIDE_DIR . '/' . $relativePath); if (is_file($fileInThemeDir)) { return new \Ip\View($fileInThemeDir, $data); } $absolutePath = ipFile($relativePath); if (file_exists($absolutePath)) { // The most common case return new \Ip\View($absolutePath, $data); } // File was not found, check whether it is in theme override dir. if (strpos($relativePath, 'Theme/' . ipConfig()->theme() . '/override/') !== 0) { $file = esc($file); throw new \Ip\Exception\View("View {$file} not found."); } $pathFromWebsiteRoot = str_replace(ipFile('Theme/' . ipConfig()->theme() . '/override/'), '', $absolutePath); return ipView($pathFromWebsiteRoot); }