You are here

public function mylivechat::getChatCode in My Live Chat 6

Same name and namespace in other branches
  1. 7 mylivechat.php \MyLiveChat::getChatCode()

Returns MyLiveChat button HTML code

File

./mylivechat.php, line 126
MyLiveChat module for Drupal

Class

mylivechat
@file MyLiveChat module for Drupal

Code

public function getChatCode() {
  if ($this
    ->is_installed() == FALSE) {
    return FALSE;
  }
  $mylivechat_id = variable_get('mylivechat_id', '');
  $mylivechat_displaytype = variable_get('mylivechat_displaytype', 'button');
  $mylivechat_membership = variable_get('mylivechat_membership', 'no');
  $mylivechat_encrymode = variable_get('mylivechat_encrymode', 'none');
  $mylivechat_encrykey = variable_get('mylivechat_encrykey', '');
  $isIntegrateUser = false;
  if ($mylivechat_membership == "yes") {
    $isIntegrateUser = true;
  }
  $chat_button = "<div class=\"mod_mylivechat\">";
  if ($mylivechat_displaytype == "button") {
    $chat_button .= "<script type=\"text/javascript\" src=\"https://www.mylivechat.com/chatbutton.aspx?hccid=" . $mylivechat_id . "\"></script>";
  }
  else {
    if ($mylivechat_displaytype == "box") {
      $chat_button .= "<script type=\"text/javascript\" src=\"https://www.mylivechat.com/chatbox.aspx?hccid=" . $mylivechat_id . "\"></script>";
    }
    else {
      $chat_button .= "<script type=\"text/javascript\" src=\"https://www.mylivechat.com/chatlink.aspx?hccid=" . $mylivechat_id . "\"></script>";
    }
  }
  global $user;
  if (in_array('authenticated user', $user->roles) && $isIntegrateUser == true) {
    if ($mylivechat_encrykey == null || strlen($mylivechat_encrykey) == 0) {
      $chat_button .= "<script type=\"text/javascript\">MyLiveChat_SetUserName('" . $this
        ->EncodeJScript($user->name) . "');</script>";
    }
    else {
      $chat_button .= "<script type=\"text/javascript\">MyLiveChat_SetUserName('" . $this
        ->EncodeJScript($user->name) . "','" . $this
        ->GetEncrypt($user->uid . "", $mylivechat_encrymode, $mylivechat_encrykey) . "');</script>";
    }
  }
  $chat_button .= "</div>";

  // Return chat button code
  return $chat_button;
}