1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<?php
namespace hji\geofarms\controllers;
use \hji\geofarms\GeoFarms;
use \hji\geofarms\models\Settings as SettingsModel;
use \hji\geofarms\models\CMB as CMBModel;
include_once(GeoFarms::$third_party . '/geoPHP/geoPHP.inc');
class FrontEnd
{
static $cmb_model;
public function __construct()
{
self::$cmb_model = new CMBModel();
add_filter('template_include', array($this, 'area_template'));
}
public function area_template($template)
{
global $wp;
$templatepath = get_stylesheet_directory();
$settings = new SettingsModel();
$area_main_page = $settings->getOption('hji_geo_farms_main_page_slug', 'general') ? get_post($settings->getOption('hji_geo_farms_main_page_slug', 'general'))->post_name : 0;
if ( isset($wp->query_vars["pagename"]) ) {
$nameofpage = $wp->query_vars["pagename"];
}
if ( isset($wp->query_vars["post_type"]) && $wp->query_vars["post_type"] === GeoFarms::$post_type ) {
$file = 'single-area.php';
if (file_exists(get_stylesheet_directory() . '/' . $file)) {
$template = get_stylesheet_directory() . '/' . $file;
} else if (file_exists(get_template_directory() . '/' . $file)) {
$template = get_template_directory() . '/' . $file;
} else {
$template = GeoFarms::$views . '/' . $file;
}
return $template;
}
else if ( isset($nameofpage) && $nameofpage === $area_main_page ) {
$file = 'archive-area.php';
if (file_exists(get_stylesheet_directory() . '/' . $file)) {
$template = get_stylesheet_directory() . '/' . $file;
} else if (file_exists(get_template_directory() . '/' . $file)) {
$template = get_template_directory() . '/' . $file;
} else {
$template = GeoFarms::$views . '/' . $file;
}
}
return $template;
}
public static function getAreaVars()
{
global $post;
$vars = array();
$vars['cmb_prefix'] = self::$cmb_model->cmb_prefix;
$vars['cmb_start_fields'] = self::$cmb_model->cmb_start_fields;
$vars['cmb_total_fields'] = self::$cmb_model->cmb_total_fields;
$vars['hood_meta'] = get_post_meta($post->ID);
return $vars;
}
public static function getAreaTabName($i)
{
return self::$cmb_model->cmb_tab_name($i);
}
public static function getAreaShortcode($i)
{
return self::$cmb_model->cmb_tab_shortcode($i);
}
public static function getFeaturedListingsName()
{
return self::$cmb_model->cmb_featured_listings_name();
}
}