Exemplo n.º 1
0
 /**
  * Checks if the template file exists and returns the template namespace
  *
  * @access private
  * @param  string $file
  * @param  string $group
  * @param  string $element
  * @return string
  */
 private function checkTemplateFile($file, $group, $element)
 {
     $checkSubFiles = false;
     // If file is null, then we generate it based on the event that is triggered
     if (is_null($file) && !empty($this->event)) {
         $file = strtolower(substr($this->event, 2));
         // We only check sub files if we are trying to display an event based theme file
         $checkSubFiles = true;
     }
     do {
         $prefix = 'fields/' . $group . '/' . $element;
         $fieldFile = $prefix . '/' . $file;
         if ($this->theme->exists($fieldFile)) {
             return $fieldFile;
         }
         $generalFieldFile = $prefix . '/event';
         if ($this->theme->exists($generalFieldFile)) {
             return $generalFieldFile;
         }
         if ($checkSubFiles) {
             $filecontent = $file;
             $subFile = 'site/fields/' . $filecontent;
             if ($this->theme->exists($subFile)) {
                 do {
                     $subFieldFile = $prefix . '/' . $filecontent . '_content';
                     if ($this->theme->exists($subFieldFile)) {
                         $this->theme->set('subNamespace', $subFieldFile);
                         return $subFile;
                     }
                     // If reach here, means no subFieldFile is found, then we fallback
                     $subFallback = $this->getFallbackTemplate($filecontent);
                     if ($subFallback !== false) {
                         $filecontent = $subFallback;
                     }
                 } while ($subFallback !== false);
                 $subFieldContent = $prefix . '/content';
                 if ($this->theme->exists($subFieldContent)) {
                     $this->theme->set('subNamespace', $subFieldContent);
                     return $subFile;
                 }
             }
         }
         // If we reach here, means no return is executed, then we try to fallback
         $fallback = $this->getFallbackTemplate($file);
         if ($fallback !== false) {
             $file = $fallback;
         }
     } while ($fallback !== false);
     return false;
 }