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: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201:
<?php
class Inbound_Mailer_Load_Templates {
private static $instance;
public $template_definitions;
public $definitions;
public $template_categories;
public static function instance() {
if (!isset(self::$instance) && !(self::$instance instanceof Inbound_Mailer_Load_Templates)) {
self::$instance = new Inbound_Mailer_Load_Templates;
self::$instance->load_template_config_files();
self::$instance->load_definitions();
self::$instance->read_template_categories();
}
return self::$instance;
}
public static function load_template_config_files() {
$core_templates = self::$instance->get_core_templates();
foreach ($core_templates as $name) {
if ($name != ".svn") {
include_once(INBOUND_EMAIL_PATH . "templates/$name/config.php");
}
}
$uploaded_templates = self::$instance->get_uploaded_templates();
foreach ($uploaded_templates as $name) {
include_once(INBOUND_EMAIL_UPLOADS_PATH . "$name/config.php");
}
$included_templates = self::$instance->get_theme_included_templates();
foreach ($included_templates as $name) {
include_once(INBOUND_EMAIL_THEME_TEMPLATES_PATH . "$name/config.php");
}
include_once( INBOUND_EMAIL_PATH . 'assets/acf/smartbar.php');
self::$instance->template_definitions = $inbound_email_data;
}
public static function get_core_templates() {
$core_templates = array();
$template_path = INBOUND_EMAIL_PATH . "templates/";
$results = scandir($template_path);
foreach ($results as $name) {
if ($name === '.' or $name === '..' or $name === '__MACOSX') continue;
if (is_dir($template_path . '/' . $name)) {
$core_templates[] = $name;
}
}
return $core_templates;
}
public static function get_uploaded_templates() {
$uploaded_templates = array();
if (!is_dir(INBOUND_EMAIL_UPLOADS_PATH)) {
wp_mkdir_p(INBOUND_EMAIL_UPLOADS_PATH);
}
$templates = scandir(INBOUND_EMAIL_UPLOADS_PATH);
foreach ($templates as $name) {
if ($name === '.' or $name === '..' or $name === '__MACOSX') continue;
if (is_dir(INBOUND_EMAIL_UPLOADS_PATH . '/' . $name)) {
$uploaded_templates[] = $name;
}
}
return $uploaded_templates;
}
public static function get_theme_included_templates() {
$included_templates = array();
if (!is_dir(INBOUND_EMAIL_THEME_TEMPLATES_PATH)) {
return $included_templates;
}
$templates = scandir(INBOUND_EMAIL_THEME_TEMPLATES_PATH);
foreach ($templates as $name) {
if ($name === '.' or $name === '..' or $name === '__MACOSX') continue;
if (is_dir(INBOUND_EMAIL_THEME_TEMPLATES_PATH . '/' . $name)) {
$included_templates[] = $name;
}
}
return $included_templates;
}
public static function read_template_categories() {
$template_cats = array();
if (!isset(self::$instance->definitions)) {
return;
}
foreach (self::$instance->definitions as $key => $val) {
if (strstr($key, 'inbound-email') || !isset($val['info']['category'])) continue;
if (isset($val['category'])) {
$cats = $val['category'];
} else {
if (isset($val['info']['category'])) {
$cats = $val['info']['category'];
}
}
$cats = explode(',', $cats);
foreach ($cats as $cat_value) {
$cat_value = trim($cat_value);
$name = str_replace(array('-', '_'), ' ', $cat_value);
$name = ucwords($name);
if (!isset($template_cats[$cat_value])) {
$template_cats[$cat_value]['count'] = 1;
} else {
$template_cats[$cat_value]['count']++;
}
$template_cats[$cat_value]['value'] = $cat_value;
$template_cats[$cat_value]['label'] = "$name";
}
}
self::$instance->template_categories = $template_cats;
}
public static function load_definitions() {
$inbound_email_data = self::$instance->template_definitions;
self::$instance->definitions = apply_filters('inbound_email_template_data', $inbound_email_data);
}
}
function Inbound_Mailer_Load_Templates() {
return Inbound_Mailer_Load_Templates::instance();
}
function inbound_email_load_templates() {
Inbound_Mailer_Load_Templates::instance();
}
add_action('admin_init', 'inbound_email_load_templates');