Overview

Classes

  • Bright
  • BrightWoocommerceConstants
  • BrightWoocommerceIntegration
  • WoocommerceExtensions

Functions

  • bright_add_quicktags
  • bright_add_token_tag
  • bright_call_api_for_course
  • bright_check_compat
  • bright_curl
  • bright_curl_error
  • bright_echo_message
  • bright_extract_embed_code
  • bright_fetch_template_text
  • bright_fetch_user_attributes
  • bright_get_authentication_code_for_user
  • bright_get_avatar_url
  • bright_get_course_data
  • bright_get_course_list_with_registrations
  • bright_get_course_providers
  • bright_get_registration_data
  • bright_get_registration_list
  • bright_get_reportage_urls
  • bright_get_template_data
  • bright_get_user
  • bright_learning_paths_load_bright_customization_scripts
  • bright_load_custom_wp_admin_style
  • bright_load_scripts
  • bright_log
  • bright_manage_woocommerce_order
  • bright_menu_admin
  • bright_menu_overview
  • bright_menu_settings
  • bright_menu_sync
  • bright_message
  • bright_register_user_to_course
  • bright_render_as_javascript
  • bright_reset_token
  • bright_results_matrix
  • bright_return_as_javascript
  • bright_rewrite_embed_code
  • bright_run_stored_query
  • bright_set_current_course_provider
  • bright_shortcode_func
  • bright_stop
  • bright_stub
  • bright_support
  • bright_template_pack_load_bright_customization_scripts
  • bright_template_pack_load_bright_customization_styles
  • bright_update_all_users
  • bright_update_realmuser_meta
  • bright_update_user_licenses
  • bright_update_user_meta
  • btp_create_header_text
  • dump_bright_js_for_footer
  • setup_bright_menu
  • Overview
  • Class
  1: <?php
  2: 
  3: global $bright_user_registration_cache;
  4: 
  5: class Bright {
  6: 
  7:   /* nodelay ... don't create a background job */
  8:   public static function add_learner_to_invitation($learner_id,$invitation_name,$nodelay=false) {
  9:     $api_root = get_option('bright_api_url');
 10:     $query_data=array();
 11: 
 12:     $query_data['format'] = 'json';
 13:     $query_data['realm_guid'] = get_option('bright_realm_guid');
 14:     $query_data['realm_secret_key'] = get_option('bright_secret_key');
 15:     $query_data['name'] = $invitation_name;
 16:     $query_data['learners'] = json_encode(array($learner_id));
 17:     if ($nodelay)
 18:       $query_data['nodelay'] = 'true';
 19: 
 20:     $url = $api_root.'/invitation/add_learners?' . http_build_query($query_data);
 21: 
 22:     $json = bright_curl($url);
 23:     $json_data = json_decode($json);
 24:     return $json_data;
 25:   }
 26:   
 27:   public static function create_invitation($query_data) {
 28:     $api_root = get_option('bright_api_url');
 29:     $query_data['format'] = 'json';
 30:     $query_data['realm_guid'] = get_option('bright_realm_guid');
 31:     $query_data['realm_secret_key'] = get_option('bright_secret_key');
 32:     $query_data['course_guids'] = json_encode($query_data['course_guids']);
 33:     $query_data['license_data'] = json_encode($query_data['license_data']);
 34:     
 35:     $url = $api_root.'/invitation';
 36:     
 37:     $json = bright_curl($url, 'POST', $query_data);
 38:     $json_data = json_decode($json);
 39:     return $json_data;
 40:   }
 41:   
 42:   public static function _get_api_key($email,$course_provider_id=null) {
 43:     $api_root = get_option('bright_api_url');
 44:     $bright_realm_guid = get_option('bright_realm_guid');
 45:     $bright_secret_key = get_option('bright_secret_key');
 46:     $query_data = array(
 47:                         'format' => 'json',
 48:                         'realm_guid' => $bright_realm_guid,
 49:                         'realm_secret_key' => $bright_secret_key,
 50:                         'user_email' => $email);
 51:     
 52:     if (!empty($course_provider_id))
 53:       $query_data['course_provider_id'] = $course_provider_id;
 54:     
 55:     if (!empty($bright_realm_guid) && !empty($bright_secret_key)) {
 56:       $query_data['realm_guid'] = $bright_realm_guid;
 57:       $query_data['realm_secret_key'] = $bright_secret_key;
 58:     }
 59:     
 60:     $auth_url = $api_root.'/api_key';
 61:     
 62:     $json = bright_curl($auth_url, 'POST', $query_data);
 63:     $json_data = json_decode($json);
 64:     return $json_data->access_token;
 65:   }
 66:   
 67:   public static function register_user_to_course($api_key,$user_email,$course,$first_name=null,$last_name=null) {
 68:     $api_call = 'registration';
 69:     if (strstr($api_root,"v1")) {
 70:       $api_call = 'scorm_cloud_registration';
 71:     }
 72:     $api_root = get_option('bright_api_url');
 73:     
 74:     /* $current_user = bright_get_user(); */
 75:     
 76:     /* if (empty($first_name)) { */
 77:     /*   $first_name = get_user_meta($current_user->ID, "first_name",true); */
 78:     /* } */
 79:     /* if (empty($last_name)) { */
 80:     /*   $last_name = get_user_meta($current_user->ID, "last_name",true); */
 81:     /* } */
 82:     
 83:     $query_params = array(
 84:                           'api_key' => $api_key,
 85:                           'dont_duplicate' => 1,
 86:                           'format' => 'json',
 87:                           'course_guid' => $course
 88:                           );
 89:     
 90:     if (!empty($first_name)) 
 91:       $query_params['fname'] = $first_name;
 92:     if (!empty($last_name)) 
 93:       $query_params['lname'] = $last_name;
 94:     
 95:     if (!empty($user_email)) 
 96:       $query_params['learner_id'] = $user_email;
 97:     
 98:     $auth_url = $api_root . '/' . $api_call . '/gcreate?' . http_build_query($query_params);
 99:     return bright_curl($auth_url);
100:   }
101:   
102:   
103:   /*
104:    * fetch_bright_realm_key
105:    *
106:    * Useful to acquire "realm-wide" permissions.
107:    */
108:   
109:   public static function fetch_bright_realm_key($course_provider_id=false) {
110:     if (! $course_provider_id) 
111:       $course_provider_id =get_user_option('bright_course_provider_id',
112:                                            bright_get_user()->ID);
113:     
114:     $api_root = get_option('bright_api_url');
115:     $bright_realm_guid = get_option('bright_realm_guid');
116:     $bright_secret_key = get_option('bright_secret_key');
117:     
118:     if (empty($bright_secret_key) || empty($bright_realm_guid))
119:       throw new Exception("realm guid and secret key not set in your Bright settings");
120:     
121:     $query_data = array(
122:                         'format' => 'json',
123:                         'realm_guid' => $bright_realm_guid,
124:                         'realm_secret_key' => $bright_secret_key);
125:     
126:     if ($course_provider_id) 
127:       $query_data['course_provider_id'] = $course_provider_id;
128:     
129:     $auth_url = $api_root.'/api_key';
130:     $json = bright_curl($auth_url, 'POST', $query_data);
131:     $json_data = json_decode($json);
132:     return $json_data->access_token;
133:   }
134:   
135:   public static function json_encode_unicode($data) {
136:     if (defined('JSON_UNESCAPED_UNICODE')) {
137:       return json_encode($data, JSON_UNESCAPED_UNICODE);
138:     }
139:     return preg_replace_callback('/(?<!\\\\)\\\\u([0-9a-f]{4})/i',
140:                                  function ($m) {
141:                                    $d = pack("H*", $m[1]);
142:                                    $r = mb_convert_encoding($d, "UTF8", "UTF-16BE");
143:                                    return $r!=="?" && $r!=="" ? $r : $m[0];
144:                                  }, json_encode($data)
145:                                  );
146:   }
147:   
148:   public static  function json_cb(&$item, $key) { 
149:     if (is_string($item)) $item = mb_encode_numericentity($item, array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); 
150:   }
151:   
152:   public static  function my_json_encode($arr){
153:     //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
154:     array_walk_recursive($arr, 'Bright::json_cb');
155:     return mb_decode_numericentity(json_encode($arr), array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
156:     
157:   }
158:   
159:   public static function realm_user_gcustom($learner_id,$data) {
160:     $api_root = get_option('bright_api_url');
161:     $bright_realm_guid = get_option('bright_realm_guid');
162:     $bright_secret_key = get_option('bright_secret_key');
163:     
164:     $url = get_site_url();
165:     $find = array( 'http://', 'https://' );
166:     $replace = '';
167:     $without_protocol = str_replace( $find, $replace, $url );
168:     
169:     $query_data = array(
170:                         'format' => 'json',
171:                         'realm_guid' => $bright_realm_guid,
172:                         'email' => $learner_id,
173:                         'key' => 'hostdata',
174:                         'php_json_encoded' => "1",
175:                         $without_protocol => Bright::my_json_encode($data),
176:                         'realm_secret_key' => $bright_secret_key);
177:     
178:     $url = $api_root.'/realm_user/gcustom' . '?'. http_build_query($query_data);
179:     $json = file_get_contents($url);
180:     $json_data = json_decode($json);
181:     return $json_data;
182:   }
183:   
184:   public static function is_user_registered_to_course($course_id,$use_cache=true) {
185:     global $bright_user_registration_cache;
186:     
187:     if (empty($bright_user_registration_cache)) {
188:       $bright_user_registration_cache = array();
189:     }
190:     
191:     if ($bright_user_registration_cache[$course_id] && $use_cache) {
192:       return $bright_user_registration_cache[$course_id];
193:     }
194:     
195:     $user_is_registered = false;
196:     if ( is_user_logged_in() ) {
197:       $bright_key=bright_get_authentication_code_for_user(bright_get_user());
198:       $registration = bright_get_registration_data($bright_key,$course_id);
199:       if ($registration) {
200:         $json_data = json_decode($registration);
201:         if ($json_data[0] && ! $json_data[0]->deleted) {
202:           $user_is_registered = true;
203:         }
204:       }
205:     } 
206:     $bright_user_registration_cache[$course_id] = $user_is_registered;
207:     return $user_is_registered;
208:   }
209: }
210: 
API documentation generated by ApiGen