allow_url_fopen = yes in your php.ini file. If that is not possible, Altos Connect can also use the cURL extension for PHP, if your hosting provider installs it. Please contact your hosting provider to resolve this problem. *Tip* all of the hosting providers recommended by WordPress®, support one of these two methods; by default.', true);
}
}
/**/
function on_plugin_action_links ($links = array (), $file = "")
{
if (preg_match ("/" . preg_quote ($file, "/") . "$/", __FILE__) && is_array ($links))
{
$settings = 'Settings';
array_unshift ($links, $settings);
}
/**/
return $links;
}
/**/
function on_options_page () /* Handles General Options. */
{
$options = $this->update_all_options ();
include_once dirname (__FILE__) . "/altos-options.php";
}
/**/
function update_all_options () /* Used with option forms. */
{
$options = $this->get_backward_compatible_options ();
/**/
if ($_POST["altos_connect_options_save"])
{
$_POST = stripslashes_deep ($_POST);
/**/
foreach ($_POST as $key => $value)
{
if ($key !== "altos_connect_options_save")
if (preg_match ("/^" . preg_quote ("altos_connect_", "/") . "/", $key))
{
(is_array ($value)) ? array_shift ($value) : null;
$options[preg_replace ("/^" . preg_quote ("altos_connect_", "/") . "/", "", $key)] = $value;
}
}
/**/
$options["pai"] = strip_tags (stripslashes ($this->auth ($options["username"], $options["password"])));
/**/
update_option ("altos_connect_options", $options);
update_option ("altos_global_options", array ("username" => $options["username"], "password" => $options["password"], "pai" => $options["pai"]));
/**/
if (!$this->validate_pai ($options["pai"])) /* Validate the newly obtained pai value. */
{
$this->display_admin_notice ('Invalid login credentials, please try again.', true);
}
else /* Otherwise, everything looks good! */
$this->display_admin_notice ('Options saved.');
}
/**/
return $options;
}
/*
These acquire options w/backward compatiblity.
*/
function get_backward_compatible_widget_options ()
{
$widget_options = get_option ("altos_connect_widget_options");
$widget_options = (!is_array ($widget_options) || empty ($widget_options)) ? get_option ("widget_altos") : $widget_options;
$widget_options = (!is_array ($widget_options) || empty ($widget_options)) ? array (): $widget_options;
/**/
return $widget_options;
}
/**/
function get_backward_compatible_options ()
{
$options = get_option ("altos_connect_options");
$options = (!is_array ($options) || empty ($options)) ? get_option ("altos_global_options") : $options;
$options = (!is_array ($options) || empty ($options)) ? get_option ("widget_altos") : $options;
$options = (!is_array ($options) || empty ($options)) ? array (): $options;
/**/
return $options;
}
/*
Displays admin notifications.
*/
function display_admin_notice ($notice = FALSE, $error = FALSE)
{
if ($notice && $error) /* Special format for errors. */
{
echo '' . $notice . '
' . $notice . '
' . $this->on_submit_altos_connect ($_POST) . '
'; } else { echo ''; } /**/ echo $after_widget; } } /* The widget control function. */ function on_widget_control () { $options = $this->get_backward_compatible_options (); $widget_options = $this->get_backward_compatible_widget_options (); /**/ if (isset ($_POST["altos-submit"])) { $widget_options["title"] = strip_tags (stripslashes ($_POST["altos-title"])); $options["username"] = strip_tags (stripslashes ($_POST["altos-username"])); $options["password"] = strip_tags (stripslashes ($_POST["altos-password"])); $options["pai"] = strip_tags (stripslashes ($this->auth ($options["username"], $options["password"]))); /**/ update_option ("altos_connect_options", $options); update_option ("altos_connect_widget_options", $widget_options); update_option ("altos_global_options", array ("username" => $options["username"], "password" => $options["password"], "pai" => $options["pai"])); } /**/ $title = attribute_escape ($widget_options["title"]); $username = attribute_escape ($options["username"]); $password = attribute_escape ($options["password"]); $pai = attribute_escape ($options["pai"]); /**/ if ($this->validate_pai ($pai)) { echo ''; echo ''; echo '
'; } else { echo ''; echo ''; echo '
'; } /**/ echo ''; echo ''; echo '
'; /**/ echo ''; echo ''; echo '
'; /**/ echo ''; echo ''; echo '
'; /**/ echo ''; } /* Required scripts. */ function on_wp_print_scripts () { wp_enqueue_script("jquery"); wp_enqueue_script ("jquery.sha1", WP_PLUGIN_URL . "/" . basename (dirname (__FILE__)) . "/jquery-sha1/jquery.sha1-min.js", array ("jquery")); wp_enqueue_script ("jquery.validate", WP_PLUGIN_URL . "/" . basename (dirname (__FILE__)) . "/jquery-validate/jquery.validate.js", array ("jquery")); wp_enqueue_script ("jquery.autotab", WP_PLUGIN_URL . "/" . basename (dirname (__FILE__)) . "/jquery-autotab/jquery.autotab.js", array ("jquery")); } /* Required header additions. */ function on_wp_head () { echo ''; /**/ echo ''; } /* These are utitlity functions. */ function on_submit_altos_connect ($post) { $options = $this->get_backward_compatible_options (); /**/ $post["pai"] = $options["pai"]; /**/ if (trim (stripslashes ($post["altos-connect-captcha"])) !== sha1 (trim (stripslashes ($_POST["EMAIL1"])) . trim (stripslashes ($_POST["cityzip"])))) return 'Thanks for your interest! — I\'ll be sure to follow up with you right away.'; /**/ return strip_tags ($this->crmpost ($post)); } /**/ function get_available_locations () { $options = $this->get_backward_compatible_options (); /**/ $available = $this->listreports ($options["pai"]); /**/ preg_match_all ('/label="(.+?)".+value="(.+?)"/', $available, $matches); /**/ $locations = array (); /**/ foreach ($matches[1] as $key => $name) { $locations[trim ($name)] = $matches[2][$key]; } /**/ return $locations; } /**/ function print_locations_select_box () { foreach ($this->get_available_locations () as $name => $value) { print ''; } } /**/ function validate_pai ($pai) { if (is_numeric ($pai) && $pai > 0) { return true; } } /**/ function auth ($username, $password) { $data = http_build_query (array ("service" => "auth", "username" => $username, "password" => $password)); /**/ $context_options = array ("http" => array ("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen ($data) . "\r\n", "content" => $data)); /**/ $context = stream_context_create ($context_options); $json = $this->fetch_url_contents ($this->webservice, false, $context); $response = json_decode ($json); /**/ return $response; } /**/ function listreports ($account_id) { $data = http_build_query (array ("service" => "listreports", "pai" => $account_id)); /**/ $context_options = array ("http" => array ("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen ($data) . "\r\n", "content" => $data)); /**/ $context = stream_context_create ($context_options); /**/ return $this->fetch_url_contents ($this->webservice, false, $context); } /**/ function crmpost ($post) { $params = $post; /**/ $options = $this->get_backward_compatible_options (); /**/ $params["service"] = "crmpost"; $params["pai"] = $options["pai"]; $params["FROM_WP"] = "true"; /**/ $data = http_build_query ($params); /**/ $context_options = array ("http" => array ("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen ($data) . "\r\n", "content" => $data)); /**/ $context = stream_context_create ($context_options); /**/ return $this->fetch_url_contents ($this->webservice, false, $context); } /**/ function fetch_url_contents ($url = "", $flags = 0, $context = NULL) { if ($url && preg_match ("/^http(s)?\:/", $url)) { if (ini_get ("allow_url_fopen")) return@file_get_contents ($url, $flags, $context); /**/ else if (function_exists ("curl_init")) { $c = (is_resource ($context)) ? stream_context_get_options ($context) : ""; return $this->curlpsr ($url, $c["http"]["content"]); } /**/ else /* Both disabled! */ return false; } /**/ return false; } /**/ function curlpsr ($url = FALSE, $vars = FALSE) { if ($url && ($connection = @curl_init ())) { @curl_setopt ($connection, CURLOPT_URL, $url); @curl_setopt ($connection, CURLOPT_POST, true); @curl_setopt ($connection, CURLOPT_TIMEOUT, 20); @curl_setopt ($connection, CURLOPT_CONNECTTIMEOUT, 20); @curl_setopt ($connection, CURLOPT_FOLLOWLOCATION, false); @curl_setopt ($connection, CURLOPT_MAXREDIRS, 0); @curl_setopt ($connection, CURLOPT_HEADER, false); @curl_setopt ($connection, CURLOPT_VERBOSE, true); @curl_setopt ($connection, CURLOPT_ENCODING, ""); @curl_setopt ($connection, CURLOPT_SSL_VERIFYPEER, false); @curl_setopt ($connection, CURLOPT_RETURNTRANSFER, true); @curl_setopt ($connection, CURLOPT_FORBID_REUSE, true); @curl_setopt ($connection, CURLOPT_FAILONERROR, true); @curl_setopt ($connection, CURLOPT_POSTFIELDS, $vars); /**/ $output = trim (@curl_exec ($connection)); /**/ @curl_close($connection); } /**/ return (strlen ($output)) ? $output : false; } } /* New instance of Altos Connect class. */ $Altos_Connect_Widget = new Altos_Connect_Widget (); ?>