Plugin Directory

Changeset 1974773


Ignore:
Timestamp:
11/15/2018 10:17:43 AM (7 years ago)
Author:
darklrd
Message:

Add support for ChatCamp backend (beta)

Location:
iflychat/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • iflychat/trunk/iflychat.php

    r1693640 r1974773  
    22/**
    33 * @package iflychat
    4  * @version 4.3.1
     4 * @version 4.4
    55 */
    66/*
     
    99Description: One on one chat, Multiple chatrooms, Embedded chatrooms
    1010Author: iFlyChat Team
    11 Version: 4.3.1
     11Version: 4.4
    1212Author URI: https://iflychat.com/
    1313*/
     
    4040}
    4141
    42 define('IFLYCHAT_PLUGIN_VERSION', 'WP-4.3.1');
     42if(!defined('CHATCAMP_EXTERNAL_HOST')){
     43  define('CHATCAMP_EXTERNAL_HOST', 'http://api.chatcamp.io');
     44}
     45
     46if(!defined('CHATCAMP_EXTERNAL_PORT')){
     47  define('CHATCAMP_EXTERNAL_PORT', '80');
     48}
     49
     50if(!defined('CHATCAMP_EXTERNAL_A_HOST')){
     51  define('CHATCAMP_EXTERNAL_A_HOST', 'https://api.chatcamp.io');
     52}
     53
     54if(!defined('CHATCAMP_EXTERNAL_A_PORT')){
     55  define('CHATCAMP_EXTERNAL_A_PORT', '443');
     56}
     57
     58if(!defined('CHATCAMP_EXTERNAL_CDN_HOST')){
     59  define('CHATCAMP_EXTERNAL_CDN_HOST', 'cdn.chatcamp.io');
     60}
     61
     62define('IFLYCHAT_PLUGIN_VERSION', 'WP-4.4');
    4363if (!defined('IFLYCHAT_DEBUG')) {
    4464  define('IFLYCHAT_DEBUG',          false);
     
    100120    $user_data = false;
    101121    if(iflychat_check_access()){
    102 
    103       $_iflychat_protocol = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://';
     122           
     123        $_iflychat_protocol = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://';
    104124
    105125        wp_enqueue_script('iflychat-ajax', plugin_dir_url( __FILE__ ) . 'js/iflychat.js', array(), false, true);
     126        wp_localize_script('iflychat-ajax', 'iflychat_chatcamp_check', iflychat_chatcamp_check()?"1":"0");
    106127        wp_localize_script('iflychat-ajax', 'iflychat_app_id', iflychat_get_option('iflychat_app_id'));
    107         wp_localize_script('iflychat-ajax', 'iflychat_external_cdn_host', DRUPALCHAT_EXTERNAL_CDN_HOST);
     128        wp_localize_script('iflychat-ajax', 'iflychat_external_cdn_host', iflychat_chatcamp_check()?CHATCAMP_EXTERNAL_CDN_HOST:DRUPALCHAT_EXTERNAL_CDN_HOST);
    108129        if (is_user_logged_in()) {
    109130            $user_data = json_encode(_iflychat_get_user_auth());
     
    119140        }
    120141       
    121       if(iflychat_get_option('iflychat_popup_chat') == '1'){
    122         wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
    123       }else if(iflychat_get_option('iflychat_popup_chat') == '2' && !is_admin()){
    124         wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
    125       }else if((iflychat_get_option('iflychat_popup_chat') == '3' || iflychat_get_option('iflychat_popup_chat') == '4') && iflychat_path_check()){
    126         wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
    127       }
     142        if(iflychat_get_option('iflychat_popup_chat') == '1'){
     143            wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
     144        }
     145        else if(iflychat_get_option('iflychat_popup_chat') == '2' && !is_admin()){
     146            wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
     147        }
     148        else if((iflychat_get_option('iflychat_popup_chat') == '3' || iflychat_get_option('iflychat_popup_chat') == '4') && iflychat_path_check()){
     149            wp_enqueue_script('iflychat-popup', plugin_dir_url( __FILE__ ) . 'js/iflychat-popup.js', array(), false, true);
     150        }
     151       
    128152
    129153    }
     
    270294    );
    271295
    272     $result = wp_remote_head(iflychat_get_host(TRUE) . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/api/1.1/token/generate', $options);
    273     if (!is_wp_error($result) && $result['response']['code'] == 200) {
    274         $result = json_decode($result['body']);
    275         if (is_user_logged_in()) {
    276             $_SESSION['token'] = $result->key;
    277             //print_r($result);
    278             //print_r(gettype($result->app_id));
    279 
    280           //  if(iflychat_get_option('iflychat_app_id') == ''){
    281           //    iflychat_update_option('iflychat_app_id', $result->app_id);
    282           //  }
    283         }
    284         //print_r(gettype($result));
    285         return $result;
    286     }
    287     //  else {
    288     //   //return null;
    289     //   return $result['response'];
    290     // }
    291     else if(!is_wp_error($result) && $result['response']['code'] != 200){
    292       //return null;
    293       return $result['response'];
    294     } else {
    295       $error = array(
    296         'code' => $result->get_error_code(),
    297         'message' => $result->get_error_message()
    298       );
    299       //print_r($error);
    300       return $error;
    301     }
     296    if(iflychat_chatcamp_check()) {
     297        $options['body'] = json_encode(array('id' => $data['user_id']));
     298        $options['headers'] = array('Content-Type' => 'application/json', 'x-api-key' => $data['api_key']);
     299        $result = wp_remote_head(CHATCAMP_EXTERNAL_A_HOST . ':' . CHATCAMP_EXTERNAL_A_PORT . '/api/1.0/users.get', $options);
     300        if (!is_wp_error($result) && $result['response']['code'] == 200) {
     301            $result = json_decode($result['body']);
     302            if (is_user_logged_in()) {
     303                $_SESSION['token'] = $result->access_token;
     304                // print_r($result);exit;
     305            }
     306            return $result;
     307        }
     308        else if($result['response']['code'] == 404){
     309            $options['body'] = json_encode(iflychat_chatcamp_process_user_data($data));
     310            $result = wp_remote_head(CHATCAMP_EXTERNAL_A_HOST . ':' . CHATCAMP_EXTERNAL_A_PORT . '/api/1.0/users.create', $options);
     311            if (!is_wp_error($result) && $result['response']['code'] == 200) {
     312                $result = json_decode($result['body']);
     313                if (is_user_logged_in()) {
     314                    $_SESSION['token'] = $result->access_token;
     315                    // print_r($result);exit;
     316                }
     317                return $result;
     318            }
     319            else if(!is_wp_error($result) && $result['response']['code'] != 200){
     320                return $result['response'];
     321              } else {
     322                $error = array(
     323                  'code' => $result->get_error_code(),
     324                  'message' => $result->get_error_message()
     325                );
     326                return $error;
     327              }
     328        }
     329        else if(!is_wp_error($result) && $result['response']['code'] != 200){
     330          return $result['response'];
     331        } else {
     332          $error = array(
     333            'code' => $result->get_error_code(),
     334            'message' => $result->get_error_message()
     335          );
     336          return $error;
     337        }
     338    }
     339    else {
     340        $result = wp_remote_head(iflychat_get_host(TRUE) . ':' . DRUPALCHAT_EXTERNAL_A_PORT . '/api/1.1/token/generate', $options);
     341        if (!is_wp_error($result) && $result['response']['code'] == 200) {
     342            $result = json_decode($result['body']);
     343            if (is_user_logged_in()) {
     344                $_SESSION['token'] = $result->key;
     345                // print_r($result);exit;
     346            }
     347            return $result;
     348        }
     349        else if(!is_wp_error($result) && $result['response']['code'] != 200){
     350          return $result['response'];
     351        } else {
     352          $error = array(
     353            'code' => $result->get_error_code(),
     354            'message' => $result->get_error_message()
     355          );
     356          return $error;
     357        }
     358    }
     359
     360   
    302361}
    303362
     
    11351194}
    11361195
     1196function iflychat_chatcamp_check() {
     1197    // return true;
     1198    if(!empty(iflychat_get_option('iflychat_app_id'))) {
     1199        if(strpos(iflychat_get_option('iflychat_app_id'), '-') === false && strlen(iflychat_get_option('iflychat_app_id')) > 10) {
     1200            return true;
     1201        }
     1202    }
     1203    return false;
     1204}
     1205
     1206function iflychat_chatcamp_process_user_data($data) {
     1207    $data['x-api-key'] = $data['api_key'];
     1208    $data['id'] = $data['user_id'];
     1209    $data['display_name'] = $data['user_name'];
     1210    $data['avatar_url'] = $data['user_avatar_url'];
     1211    $data['profile_url'] = $data['user_profile_url'];
     1212    $data['check_access_token'] = true;
     1213    $data['access_token'] = iflychat_get_hash_session();
     1214    return $data;
     1215}
     1216
    11371217?>
  • iflychat/trunk/js/iflychat-popup.js

    r1459195 r1974773  
    1 var iflychat_popup=document.createElement("DIV");
    2 iflychat_popup.className="iflychat-popup";
    3 document.body.appendChild(iflychat_popup);
     1if(typeof(iflychat_chatcamp_check) === "undefined" || iflychat_chatcamp_check === "0") {
     2  var iflychat_popup=document.createElement("DIV");
     3  iflychat_popup.className="iflychat-popup";
     4  document.body.appendChild(iflychat_popup);
     5}
     6else if(iflychat_chatcamp_check === "1") {
     7  var iflychat_popup=document.createElement("DIV");
     8  iflychat_popup.id="cc-app";
     9  document.body.appendChild(iflychat_popup);
     10}
  • iflychat/trunk/js/iflychat.js

    r1589357 r1974773  
    11var iflychat_bundle = document.createElement("SCRIPT");
    2 iflychat_bundle.src = "//"+iflychat_external_cdn_host+"/js/iflychat-v2.min.js?app_id="+iflychat_app_id;
    3 iflychat_bundle.async="async";
    4 document.body.appendChild(iflychat_bundle);
     2if(iflychat_chatcamp_check === "0") {
     3  iflychat_bundle.src = "//"+iflychat_external_cdn_host+"/js/iflychat-v2.min.js?app_id="+iflychat_app_id;
     4  iflychat_bundle.async="async";
     5  document.body.appendChild(iflychat_bundle);
     6}
     7else if(iflychat_chatcamp_check === "1") {
     8  iflychat_bundle.src = "//"+iflychat_external_cdn_host+"/js/chatcamp-ui.min.js";
     9  iflychat_bundle.async="async";
     10  document.body.appendChild(iflychat_bundle);
     11  jQuery(document).ready(function($) {
     12    var data = {
     13      'action': 'iflychat-get'
     14    };
     15    jQuery.post(iflychat_auth_url, data, function(response) {
     16      console.log("RE", response);
     17      // Initialize ChatCamp
     18      window.ChatCampUi.init({
     19        appId: iflychat_app_id,
     20        user: {
     21          id: response.user.id,
     22          accessToken: response.user.access_token // optional
     23        },
     24        ui: {
     25          theme: {
     26            primaryBackground: "#3f45ad",
     27            primaryText: "#ffffff",
     28            secondaryBackground: "#ffffff",
     29            secondaryText: "#000000",
     30            tertiaryBackground: "#f4f7f9",
     31            tertiaryText: "#263238"
     32          },
     33          roster: {
     34            tabs: ['recent', 'rooms', 'users'],
     35            render: true,
     36            defaultMode: 'open', // other possible values are minimize, hidden
     37            showUserAvatarUpload: true
     38          },
     39          channel: {
     40            showAttachFile: true,
     41            showVideoCall: true,
     42            showVoiceRecording: true
     43          }
     44        }
     45      })
     46    });
     47  });
     48}
  • iflychat/trunk/readme.txt

    r1788652 r1974773  
    44Requires at least: 3.0
    55Tested up to: 4.9
    6 Stable tag: 4.3.2
     6Stable tag: 4.4
    77Tags: buddypress, chat, chat room, community, embed chat, friends, group chat, html5 chat, one to one chat, live chat, popup chat, mobile chat, multisite, wordpress chat, wp chat, ultimate member
    88License: GPLv2 or later
     
    138138== Changelog ==
    139139
     140= 4.4 =
     141
     14211/08/2018: Add support for ChatCamp backend (beta).
     143
    140144= 4.3.2 =
    141145
     
    421425== Upgrade Notice ==
    422426
     427= 4.4 =
     428After updating, go to iFlyChat Settings page and click on Update button.
     429
    423430= 4.3.2 =
    424431After updating, go to iFlyChat Settings page and click on Update button.
     
    445452After updating, go to iFlyChat Settings page and click on Update button.
    446453
    447 = 4.2.0 =
    448 After updating, go to iFlyChat Settings page and click on Update button.
    449 
Note: See TracChangeset for help on using the changeset viewer.