/**
  * Loads theme files in appropriate hierarchy: 1) child theme,
  * 2) parent template, 3) plugin resources. will look in the events/
  * directory in a theme and the views/ directory in the plugin
  *
  * @param string $template template file to search for
  * @param array $args additional arguments to affect the template path
  *  - subfolder
  *  - namespace
  *  - plugin_path
  *  - disable_view_check - bypass the check to see if the view is enabled
  * @return template path
  * @author Matt Wiebe
  **/
 public static function getTemplateHierarchy($template, $args = array())
 {
     if (!is_array($args)) {
         $args = array();
         $passed = func_get_args();
         $backwards_map = array('subfolder', 'namespace', 'plugin_path');
         if (count($passed > 1)) {
             for ($i = 1; $i < count($passed); $i++) {
                 $args[$backwards_map[$i - 1]] = $passed[$i];
             }
         }
     }
     $args = wp_parse_args($args, array('subfolder' => '', 'namespace' => '/', 'plugin_path' => '', 'disable_view_check' => false));
     /**
      * @var string $subfolder
      * @var string $namespace
      * @var string $pluginpath
      * @var bool $disable_view_check
      */
     extract($args);
     $tec = TribeEvents::instance();
     if (substr($template, -4) != '.php') {
         $template .= '.php';
     }
     // setup the meta definitions
     require_once $tec->pluginPath . 'public/advanced-functions/meta.php';
     // Allow base path for templates to be filtered
     $template_base_paths = apply_filters('tribe_events_template_paths', (array) TribeEvents::instance()->pluginPath);
     // backwards compatibility if $plugin_path arg is used
     if ($plugin_path && !in_array($plugin_path, $template_base_paths)) {
         $template_base_paths[] = $plugin_path;
     }
     // ensure that addon plugins look in the right override folder in theme
     $namespace = !empty($namespace) && $namespace[0] != '/' ? '/' . trailingslashit($namespace) : trailingslashit($namespace);
     // setup subfolder options
     $subfolder = !empty($subfolder) ? trailingslashit($subfolder) : $subfolder;
     $file = '';
     foreach ($template_base_paths as $template_base_path) {
         if ($theme_file = locate_template(array('tribe-events' . $namespace . $subfolder . $template), false, false)) {
             $file = $theme_file;
         } else {
             // protect from concat folder with filename
             $subfolder = empty($subfolder) ? trailingslashit($subfolder) : $subfolder;
             $subfolder = $subfolder[0] != '/' ? '/' . $subfolder : $subfolder;
             $file = $template_base_path . 'views' . $subfolder . $template;
             // echo $file;
         }
         if (!$disable_view_check && in_array($tec->displaying, tribe_events_disabled_views())) {
             $file = get_404_template();
         }
         $file = apply_filters('tribe_events_template', $file, $template);
         // return the first one found
         if (file_exists($file)) {
             break;
         }
     }
     return apply_filters('tribe_events_template_' . $template, $file);
 }
 /**
  * Loads theme files in appropriate hierarchy: 1) child theme,
  * 2) parent template, 3) plugin resources. will look in the events/
  * directory in a theme and the views/ directory in the plugin
  *
  * @param string $template template file to search for
  * @param array $args additional arguments to affect the template path
  *  - namespace
  *  - plugin_path
  *  - disable_view_check - bypass the check to see if the view is enabled
  * @return template path
  **/
 public static function getTemplateHierarchy($template, $args = array())
 {
     if (!is_array($args)) {
         $args = array();
         $passed = func_get_args();
         $backwards_map = array('namespace', 'plugin_path');
         if (count($passed > 1)) {
             for ($i = 1; $i < count($passed); $i++) {
                 $args[$backwards_map[$i - 1]] = $passed[$i];
             }
         }
     }
     $args = wp_parse_args($args, array('namespace' => '/', 'plugin_path' => '', 'disable_view_check' => false));
     /**
      * @var string $namespace
      * @var string $pluginpath
      * @var bool $disable_view_check
      */
     extract($args);
     $tec = TribeEvents::instance();
     // append .php to file name
     if (substr($template, -4) != '.php') {
         $template .= '.php';
     }
     // setup the meta definitions
     require_once $tec->pluginPath . 'public/advanced-functions/meta.php';
     // Allow base path for templates to be filtered
     $template_base_paths = apply_filters('tribe_events_template_paths', (array) TribeEvents::instance()->pluginPath);
     // backwards compatibility if $plugin_path arg is used
     if ($plugin_path && !in_array($plugin_path, $template_base_paths)) {
         array_unshift($template_base_paths, $plugin_path);
     }
     // ensure that addon plugins look in the right override folder in theme
     $namespace = !empty($namespace) ? trailingslashit($namespace) : $namespace;
     $file = false;
     // return 404 if curent view is disabled
     if (!$disable_view_check && in_array($tec->displaying, tribe_events_disabled_views())) {
         $file = get_404_template();
     }
     /* potential scenarios:
     
     			- the user has no template overrides
     				-> we can just look in our plugin dirs, for the specific path requested, don't need to worry about the namespace
     			- the user created template overrides without the namespace, which reference non-overrides without the namespace and, their own other overrides without the namespace
     				-> we need to look in their theme for the specific path requested
     				-> if not found, we need to look in our plugin views for the file by adding the namespace
     			- the user has template overrides using the namespace
     				-> we should look in the theme dir, then the plugin dir for the specific path requested, don't need to worry about the namespace
     
     			*/
     // check if there are overrides at all
     if (locate_template(array('tribe-events/'))) {
         $overrides_exist = true;
     } else {
         $overrides_exist = false;
     }
     if ($overrides_exist) {
         // check the theme for specific file requested
         $file = locate_template(array('tribe-events/' . $template), false, false);
         if (!$file) {
             // if not found, it could be our plugin requesting the file with the namespace,
             // so check the theme for the path without the namespace
             $files = array();
             foreach (array_keys($template_base_paths) as $namespace) {
                 if (!empty($namespace) && !is_numeric($namespace)) {
                     $files[] = 'tribe-events' . str_replace($namespace, '', $template);
                 }
             }
             $file = locate_template($files, false, false);
             if ($file) {
                 _deprecated_function(sprintf(__('Template overrides should be moved to the correct subdirectory: %s', 'tribe-events-calendar'), str_replace(get_stylesheet_directory() . '/tribe-events/', '', $file)), '3.2', $template);
             }
         }
     }
     // if the theme file wasn't found, check our plugins views dirs
     if (!$file) {
         foreach ($template_base_paths as $template_base_path) {
             // make sure directories are trailingslashed
             $template_base_path = !empty($template_base_path) ? trailingslashit($template_base_path) : $template_base_path;
             $file = $template_base_path . 'views/' . $template;
             $file = apply_filters('tribe_events_template', $file, $template);
             // return the first one found
             if (file_exists($file)) {
                 break;
             } else {
                 $file = false;
             }
         }
     }
     // file wasn't found anywhere in the theme or in our plugin at the specifically requested path,
     // and there are overrides, so look in our plugin for the file with the namespace added
     // since it might be an old override requesting the file without the namespace
     if (!$file && $overrides_exist) {
         foreach ($template_base_paths as $_namespace => $template_base_path) {
             // make sure directories are trailingslashed
             $template_base_path = !empty($template_base_path) ? trailingslashit($template_base_path) : $template_base_path;
             $_namespace = !empty($_namespace) ? trailingslashit($_namespace) : $_namespace;
             $file = $template_base_path . 'views/' . $_namespace . $template;
             $file = apply_filters('tribe_events_template', $file, $template);
             // return the first one found
             if (file_exists($file)) {
                 _deprecated_function(sprintf(__('Template overrides should be moved to the correct subdirectory: tribe_get_template_part(\'%s\')', 'tribe-events-calendar'), $template), '3.2', 'tribe_get_template_part(\'' . $_namespace . $template . '\')');
                 break;
             }
         }
     }
     return apply_filters('tribe_events_template_' . $template, $file);
 }