ActiveDEMAND tracking script to your website. Add custom popups, use shortcodes to embed webforms and dynamic website content. * Version: 0.1.39 * Author: JumpDEMAND Inc. * Author URI: https://www2.activedemand.com/s/SW5nU * License:GPL-2.0+ * License URI:http://www.gnu.org/licenses/gpl-2.0.txt */ define('ACTIVEDEMAND_VER', '0.1.39'); define("PLUGIN_VENDOR", "ActiveDEMAND"); define("PLUGIN_VENDOR_LINK", "http://1jp.cc/s/SW5nU"); //--------------- AD update path -------------------------------------------------------------------------- function activedemand_update() { //get ensure a cookie is set. This call creates a cookie if one does not exist activedemand_get_cookie_value(); $key = 'activedemand_version'; $version = get_option($key); if (ACTIVEDEMAND_VER === $version) return; activedemand_plugin_activation(); update_option($key, ACTIVEDEMAND_VER); } add_action('init', 'activedemand_update'); //--------------- AD Server calls ------------------------------------------------------------------------- function activedemand_getHTML($url, $timeout, $args = array()) { $fields_string = activedemand_field_string($args); if (in_array('curl', get_loaded_extensions())) { $ch = curl_init($url . "?" . $fields_string); // initialize curl with given url curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);//force IP4 $result = curl_exec($ch); curl_close($ch); } elseif (function_exists('file_get_contents')) { $result = file_get_contents($url); } return $result; } function activedemand_postHTML($url, $args, $timeout) { $fields_string = activedemand_field_string($args); if (in_array('curl', get_loaded_extensions())) { $ch = curl_init($url); // initialize curl with given url curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);//force IP4 curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); $result = curl_exec($ch); if ($result === false) { error_log(PLUGIN_VENDOR.' Web Form error: ' . curl_error($ch)); } curl_close($ch); } return $result; } //enqueue jQuery for popup purposes add_action('wp_enqueue_scripts', 'activedemand_scripts'); function activedemand_scripts() { wp_enqueue_script('jquery'); } /** * Adds ActiveDEMAND popups if API Key isset and activedemand_server_showpopups is true * * @param string $content * @return string $content with popup prefix */ function activedemand_process_popup($content = '') { $options = get_option('activedemand_options_field'); $show = get_option('activedemand_server_showpopups'); if (is_array($options) && array_key_exists('activedemand_appkey', $options) && $show) { $popup = activedemand_getHTML("https://api.activedemand.com/v1/smart_blocks/popups", 10); //if the string is empty, do not insert the script. SML if ($popup !== '') { $script = ""; return $script . $content; } else { return $content; } } else { return $content; } } function activedemand_frag_cache_popups($content = '') { if (defined('W3TC_DYNAMIC_SECURITY') && function_exists('w3_instance')) { $prefix = '' . ''; return $prefix . $content; } else { return activedemand_process_popup($content); } } add_filter('the_content', 'activedemand_frag_cache_popups'); function activedemand_field_string($args) { $options = get_option('activedemand_options_field'); $fields_string = ""; if (is_array($options) && array_key_exists('activedemand_appkey', $options)) { $activedemand_appkey = $options["activedemand_appkey"]; } else { $activedemand_appkey = ""; } if ("" != $activedemand_appkey) { $cookievalue = activedemand_get_cookie_value(); $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; if (isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; } else { $referrer = ""; } if ($cookievalue != "") { $fields = array( 'api-key' => $activedemand_appkey, 'activedemand_session_guid' => activedemand_get_cookie_value(), 'url' => $url, 'ip_address' => activedemand_get_ip_address(), 'referer' => $referrer ); } else { $fields = array( 'api-key' => $activedemand_appkey, 'url' => $url, 'ip_address' => activedemand_get_ip_address(), 'referer' => $referrer ); } if (is_array($args)) { $fields = array_merge($fields, $args); } $fields_string = http_build_query($fields); } return $fields_string; } function activedemand_get_cookie_value() { $cookieValue = ""; if (false == strpos($_SERVER['REQUEST_URI'], "wp-admin")) { //not editing an options page etc. if (isset($_COOKIE['activedemand_session_guid'])) { $cookieValue = $_COOKIE['activedemand_session_guid']; } else { $urlParms = $_SERVER['HTTP_HOST']; if (NULL != $urlParms) { if (!headers_sent()) { $cookieValue = activedemand_get_GUID(); $basedomain = activedemand_get_basedomain(); setcookie('activedemand_session_guid', $cookieValue, time() + (60 * 60 * 24 * 365 * 10), "/", $basedomain); } } } } return $cookieValue; } function activedemand_get_basedomain() { $result = ""; $urlParms = $_SERVER['HTTP_HOST']; if (NULL != $urlParms) { $result = str_replace('www.', "", $urlParms); } return $result; } // create a session if one doesn't exist function activedemand_get_GUID() { if (function_exists('com_create_guid')) { return com_create_guid(); } else { mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up. $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45);// "-" $uuid = substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12); return $uuid; } } // get the ip address function activedemand_get_ip_address() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } //--------------- Admin Menu ------------------------------------------------------------------------- function activedemand_menu() { global $activedemand_plugin_hook; $activedemand_plugin_hook = add_options_page(PLUGIN_VENDOR.' options', PLUGIN_VENDOR, 'manage_options', 'activedemand_options', 'activedemand_plugin_options'); add_action('admin_init', 'register_activedemand_settings'); } function register_activedemand_settings() { register_setting('activedemand_options', 'activedemand_options_field'); register_setting('activedemand_options', 'activedemand_server_showpopups'); register_setting('activedemand_options', 'activedemand_show_tinymce'); } function activedemand_enqueue_scripts() { wp_enqueue_script('ActiveDEMAND-Track', 'https://activedemand-static.s3.amazonaws.com/public/javascript/jquery.tracker.compiled.js.jgz'); } function activedemand_admin_enqueue_scripts() { global $pagenow; if ('post.php' == $pagenow || 'post-new.php' == $pagenow) { wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_style('wp-jquery-ui-dialog'); } } function activedemand_process_form_shortcode($atts, $content = null) { //[activedemand_form id='123'] $id = ""; //$id exists after this call. extract(shortcode_atts(array('id' => ''), $atts)); $options = get_option('activedemand_options_field'); $activedemand_ignore_form_style = false; if (array_key_exists('activedemand_ignore_form_style', $options)) { $activedemand_ignore_form_style = $options['activedemand_ignore_form_style']; } $form_str = ""; if (is_numeric($id)) { $form_str = activedemand_getHTML("https://api.activedemand.com/v1/forms/" . $id, 10, array('form_id' => $id, 'exclude_css' => $activedemand_ignore_form_style, 'basedomain' => activedemand_get_basedomain())); } if ($form_str != "") { //replace \n to ensure WP auto format does not mess with our CSS $form_str = str_replace("\n", "", $form_str); } return $form_str; } function activedemand_process_block_shortcode($atts, $content = null) { //[activedemand_block id='123'] $id = ""; //$id exists after this call. extract(shortcode_atts(array('id' => ''), $atts)); $options = get_option('activedemand_options_field'); $activedemand_ignore_block_style = false; if (array_key_exists('activedemand_ignore_block_style', $options)) { $activedemand_ignore_block_style = $options['activedemand_ignore_block_style']; } if (array_key_exists('activedemand_appkey', $options)) { $activedemand_appkey = $options['activedemand_appkey']; } $block_str = ""; if (is_numeric($id)) { $block_str = activedemand_getHTML("https://api.activedemand.com/v1/smart_blocks/" . $id, 10, array('block_id' => $id, 'exclude_css' => $activedemand_ignore_block_style)); } if ($block_str != "") { //replace \n to ensure WP auto format does not mess with our CSS $block_str = str_replace("\n", "", $block_str); } return $block_str; } function activedemand_plugin_action_links($links, $file) { static $this_plugin; if (!$this_plugin) { $this_plugin = plugin_basename(__FILE__); } if ($file == $this_plugin) { $settings_link = 'Settings'; array_unshift($links, $settings_link); } return $links; } function activedemand_stale_cart_form($form_xml = NULL) { if (!isset($form_xml)) { $url = "https://api.activedemand.com/v1/forms.xml"; $str = activedemand_getHTML($url, 10); $form_xml = simplexml_load_string($str); } $options = get_option('activedemand_options_field'); $activedemand_form_id = isset($options["activedemand_woocommerce_stalecart_form_id"]) ? $options["activedemand_woocommerce_stalecart_form_id"] : 0; $hours = isset($options['woocommerce_stalecart_hours']) ? $options['woocommerce_stalecart_hours'] : 2; ?>
You will need to enter your application key in order to enable the form shortcodes. Your can find your API key in your account settings:
The plugin adds a tracking script to your WordPress pages. This plugin offers the ability to use web form and content block shortcodes on your pages, posts, and sidebars that will render an Web Form/Dynamic Content block. This allows you to maintain your dynamic content, form styling, and configuration within .
In your visual editor, look for the 'Insert Shortcode' button:
.
Available Web Form Shortcodes
No Web Forms ConfiguredTo use the web form shortcodes, you will first have to add some Web Forms to your account in . Once you do have Web Forms configured, the available shortcodes will be displayed here. |
Available Dynamic Content Block Shortcodes
No Dynamic Blocks ConfiguredTo use the Dynamic Content Block shortcodes, you will first have to add some Dynamic Content Blocks to your account in . Once you do have Dynamic Blocks configured, the available shortcodes will be displayed here. |