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:
<?php
function Inbound_Templating_Engine() {
return Inbound_Templating_Engine::instance();
}
class Inbound_Templating_Engine {
public static $instance;
private $defaults;
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Inbound_Automation_Load_Extensions ) )
{
self::$instance = new Inbound_Templating_Engine;
self::define_default_tokens();
}
return self::$instance;
}
public static function define_default_tokens() {
self::$instance->defaults = array (
'admin-email-address' => get_option( 'admin_email', '' ),
'admin-url' => admin_url(),
'site-name' => get_option( 'blogname', '' ),
'site-tagline' => get_option( 'blogdescription', '' ),
'site-url' => get_option( 'siteurl', '' ) ,
'date-time' => date( 'Y-m-d H:i:s A', current_time( 'timestamp' ) )
);
if ( defined( 'LANDINGPAGES_URLPATH' ) ) {
self::$instance->defaults['landingpages-urlpath'] = LANDINGPAGES_URLPATH;
}
if ( defined( 'WPL_URLPATH' ) ) {
self::$instance->defaults['leads-urlpath'] = WPL_URLPATH;
}
if ( defined( 'WP_CTA_URLPATH' ) ) {
self::$instance->defaults['callstoaction-urlpath'] = WP_CTA_URLPATH;
}
}
public static function replace_tokens( $template, $args ) {
array_unshift( $args, self::$instance->defaults );
foreach ($args as $arg) {
if ( isset($arg['Mapped_Data']) ) {
$arg_json = json_decode( stripslashes($arg['Mapped_Data']), true);
foreach ($arg_json as $k=>$v) {
$arg[$k] = $v;
}
}
if ( isset($arg['mapped_params']) ) {
parse_str( stripslashes($arg['mapped_params']), $arg_parsed);
foreach ($arg_parsed as $k=>$v) {
$arg[$k] = $v;
}
}
foreach ($arg as $key => $value ) {
if ( is_array($value) ) {
continue;
}
$key = str_replace( 'inbound_current_page_url', 'source', $key );
$key = str_replace( 'inbound_form_n', 'form_name', $key );
$key = str_replace( 'inbound_', '', $key );
$key = str_replace( 'wpleads_', 'lead_', $key );
$key = str_replace( '_', '-', $key );
$template = str_replace( '{{'.$key.'}}', $value, $template );
}
}
$template = preg_replace( '/{{(.*?)}}/si', '', $template, -1 );
return do_shortcode($template);
}
}