Beispiel #1
0
 /**
  * Finds the path to the requested view, accounting for overrides
  *
  * @param unknown $view            
  * @return Ambigous <boolean, string>
  */
 public function findViewFile($view)
 {
     static $paths;
     if (empty($paths)) {
         $paths = array();
     }
     $view = str_replace("\\", "/", $view);
     $pieces = \Dsc\String::split(str_replace(array("::", ":"), "|", $view));
     if (isset($paths[$view])) {
         return $paths[$view];
     }
     $paths[$view] = false;
     // 1st. Check if the requested $view has *.{lang}.php format
     $lang = $this->app->get('lang');
     $period_pieces = explode(".", $view);
     // if not, and there is a set LANGUAGE, try to find that view
     if (count($period_pieces) == 2 && !empty($lang)) {
         $lang_view = $period_pieces[0] . "." . $lang . "." . $period_pieces[1];
         if ($lang_view_found = static::findViewFile($lang_view)) {
             return $lang_view_found;
         }
     }
     // otherwise, continue doing the *.php format
     // Overrides!
     //If we are overriding the admin, lets look in an admin  folder.
     $currentTheme = $this->getCurrentTheme();
     if ($currentTheme === 'AdminTheme') {
         if ($adminPath = $this->app->get('admin_override')) {
             $dir = $this->app->get('PATH_ROOT') . $adminPath;
         } else {
             $dir = $this->app->get('PATH_ROOT') . 'apps/Admin/Overrides/';
         }
     } else {
         //else lets look inside whatever theme we are in right now.
         // an overrides folder exists in this theme, let's check for the presence of an override for the requested view file
         $dir = \Dsc\Filesystem\Path::clean($this->getThemePath($this->getCurrentTheme()) . "Overrides/");
     }
     if ($dir = \Dsc\Filesystem\Path::real($dir)) {
         if (count($pieces) > 1) {
             // we're looking for a specific view (e.g. Blog/Site/View::posts/category.php)
             $view_string = $pieces[0];
             $requested_file = $pieces[1];
             $requested_folder = dirname($pieces[1]) == "." ? null : dirname($pieces[1]);
             $requested_filename = basename($pieces[1]);
         } else {
             // (e.g. posts/category.php) that has been requested, so look for it in the overrides dir
             $view_string = null;
             $requested_file = $pieces[0];
             $requested_folder = dirname($pieces[0]) == "." ? null : dirname($pieces[0]);
             $requested_filename = basename($pieces[0]);
         }
         $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view_string . "/" . $requested_folder . "/");
         if ($path = \Dsc\Filesystem\Path::real($path)) {
             $path_pattern = $path . $requested_filename;
             if (file_exists($path_pattern)) {
                 $paths[$view] = $path_pattern;
                 return $paths[$view];
             }
         }
     }
     if (count($pieces) > 1) {
         // we're looking for a specific view (e.g. Blog/Site/View::posts/category.php)
         // $view is a specific app's view/template.php, so try to find it
         $view_string = $pieces[0];
         $requested_file = $pieces[1];
         $view_dir = $this->getViewPath($view_string);
         $path_pattern = $view_dir . $requested_file;
         if (file_exists($path_pattern)) {
             $paths[$view] = $path_pattern;
         }
     } else {
         $requested_file = $pieces[0];
         // it's a view in the format 'common/pagination.php'
         // try to find it in the registered paths
         foreach (\Dsc\ArrayHelper::get($this->dsc_theme, 'views.paths') as $view_path) {
             $path_pattern = $view_path . $requested_file;
             if (file_exists($path_pattern)) {
                 $paths[$view] = $path_pattern;
                 break;
             }
         }
     }
     return $paths[$view];
 }