";
$theoptions = array();
if (get_option('zopimLang') != "" && get_option('zopimLang') != "--") {
$theoptions[] = " language: '".get_option('zopimLang')."'";
}
if ( isset($current_user) && get_option("zopimGetVisitorInfo") == "checked" )
{
$ul = $current_user->data->first_name;
$useremail = $current_user->data->user_email;
if ($ul!="" && $useremail != "") {
$theoptions[] = "
name: '$ul',
email: '$useremail'
";
}
}
echo "
\n";
}
function zopim_create_menu() {
//create new top-level menu
add_menu_page('Account Configuration', 'Zopim Chat', 'administrator', 'zopim_account_config', 'zopim_account_config', ZOPIM_SMALL_LOGO);
// add_submenu_page('zopim_about', "About", "About", "administrator", 'zopim_about', 'zopim_about');
add_submenu_page('zopim_account_config', 'Account Configuration', 'Account Setup', 'administrator', 'zopim_account_config', 'zopim_account_config');
add_submenu_page('zopim_account_config', 'Customize Widget', 'Customize', 'administrator', 'zopim_customize_widget', 'zopim_customize_widget');
add_submenu_page('zopim_account_config', 'IM Integration', 'IM Chat Bots', 'administrator', 'zopim_instant_messaging', 'zopim_instant_messaging');
add_submenu_page('zopim_account_config', 'Dashboard', 'Dashboard', 'administrator', 'zopim_dashboard', 'zopim_dashboard');
//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}
function check_zopimCode() {
/*
// if (get_option('zopimCode') == '' && ($_GET["page"] != "zopim_account_config")) {
if (ereg("zopim", $_GET["page"] )) {
//add_action( 'admin_notices', create_function( '', 'echo "
";' ) );
add_action( 'admin_notices', create_function( '', 'echo "This Zopim plugin is a work in progress. We will launch on the 25th of January. Thank you for your interest.
";' ) );
}
*/
return false;
}
function zopim_loader() {
add_action( 'admin_menu', 'check_zopimCode' );
}
add_action( 'init', 'zopim_loader' );
function zopim_about() {
echo "about";
}
function zopim_dashboard() {
echo ' You may also access the dashboard in a new window.
';
}
// Register the option settings we will be using
function register_mysettings() {
// Authentication and codes
register_setting( 'zopim-settings-group', 'zopimCode' );
register_setting( 'zopim-settings-group', 'zopimUsername' );
register_setting( 'zopim-settings-group', 'zopimSalt' );
register_setting( 'zopim-settings-group', 'zopimUseSSL' );
// General Widget settings
register_setting( 'zopim-settings-group', 'zopimGetVisitorInfo' );
register_setting( 'zopim-settings-group', 'zopimLang' );
// Chat button settings
register_setting( 'zopim-settings-group', 'zopimPosition' );
register_setting( 'zopim-settings-group', 'zopimHideOnOffline' );
register_setting( 'zopim-settings-group', 'zopimBubbleTitle' );
register_setting( 'zopim-settings-group', 'zopimBubbleText' );
register_setting( 'zopim-settings-group', 'zopimBubbleEnable' );
// Themes / Color
register_setting( 'zopim-settings-group', 'zopimColor' );
register_setting( 'zopim-settings-group', 'zopimTheme' );
// Message Settings
register_setting( 'zopim-settings-group', 'zopimGreetings' );
register_setting( 'zopim-settings-group', 'zopimUseGreetings' );
if (get_option('zopimCode') == "") {
update_option('zopimCode', "zopim");
}
if (get_option('zopimBubbleTitle') == "") {
update_option('zopimBubbleTitle', "Questions?");
}
if (get_option('zopimBubbleText') == "") {
update_option('zopimBubbleText', "Click here to chat with us!");
}
if (get_option('zopimBubbleEnable') == "") {
update_option('zopimBubbleEnable', "checked");
}
if (get_option('zopimUseGreetings') == "") {
update_option('zopimUseGreetings', "disabled");
}
if (get_option('zopimGreetings') == "") {
update_option('zopimGreetings', '{"away":{"window":"If you leave a question or comment, our agents will be notified and will try to attend to you shortly =)","bar":"Click here to chat"},"offline":{"window":"We are offline, but if you leave your message and contact details, we will try to get back to you =)","bar":"Leave a message"},"online":{"window":"Leave a question or comment and our agents will try to attend to you shortly =)","bar":"Click here to chat"}}');
}
}
add_action('get_footer', 'zopimme');
// create custom plugin settings menu
add_action('admin_menu', 'zopim_create_menu');
function do_post_request($url, $_data, $optional_headers = null)
{
if (get_option('zopimUseSSL') != "zopimUseSSL") {
$url = str_replace("https", "http", $url);
}
$data = array();
while(list($n,$v) = each($_data)){
$data[] = urlencode($n)."=".urlencode($v);
}
$data = implode('&', $data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
function json_to_array($json) {
// json_decode does exist but only in php > 5.2.0
require_once('JSON.php');
$jsonparser = new Services_JSON();
return ($jsonparser->decode($json));
}
function to_json($variable) {
// json_decode does exist but only in php > 5.2.0
require_once('JSON.php');
$jsonparser = new Services_JSON();
return ($jsonparser->encode($variable));
}
function getAccountDetails($salt) {
$salty = array(
"salt" => get_option('zopimSalt')
);
return json_to_array(do_post_request(ZOPIM_GETACCOUNTDETAILS_URL, $salty));
}
function curl_get_url($filename) {
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $filename);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
?>