/**
  * Returns a JSON response, and dies.
  *
  * Designed for AJAX functions.
  *
  * @todo Create option to disable database logging
  * @param bool $success 
  * @param string $message
  * @since 1.1
  * @return string 
  */
 function json($success, $message)
 {
     if ($success) {
         $r_success = 'true';
     }
     if (!$success) {
         $r_success = 'false';
     }
     $return = array('success' => $r_success, 'message' => $message);
     // Log in database
     CRM_UD_F::log(__("Automatically logged failed JSON response: ", 'wpp') . $message);
     echo json_encode($return);
     die;
 }
예제 #2
0
 /**
  * Checks for updates against TwinCitiesTech.com Server
  *
  * @since 0.01
  */
 static function feature_check($return = false)
 {
     global $wp_crm;
     $blogname = get_bloginfo('url');
     $blogname = urlencode(str_replace(array('http://', 'https://'), '', $blogname));
     $system = 'wp_crm';
     $wp_crm_version = get_option("wp_crm_version");
     $check_url = "http://updates.usabilitydynamics.com/?system={$system}&site={$blogname}&system_version={$wp_crm_version}";
     $response = @wp_remote_get($check_url);
     if (!$response) {
         return;
     }
     if (is_object($response) && !empty($response->errors)) {
         foreach ($response->errors as $update_errrors) {
             $error_string .= implode(",", $update_errrors);
             CRM_UD_F::log("Feature Update Error: " . $error_string);
         }
         if ($return) {
             return sprintf(__('An error occurred during premium feature check: <b> %s </b>.', 'wp_crm'), $error_string);
         }
         return;
     }
     if ($response['response']['code'] != '200') {
         return;
     }
     $response = @json_decode($response['body']);
     if (is_object($response->available_features)) {
         $response->available_features = CRM_UD_F::objectToArray($response->available_features);
         $wp_crm_settings = get_option('wp_crm_settings');
         $wp_crm_settings['available_features'] = CRM_UD_F::objectToArray($response->available_features);
         update_option('wp_crm_settings', $wp_crm_settings);
     }
     if ($response->features == 'eligible') {
         //** Try to create directory if it doesn't exist */
         if (!is_dir(WP_CRM_Premium)) {
             @mkdir(WP_CRM_Premium, 0755);
         }
         //** Save code */
         if (is_dir(WP_CRM_Premium) && is_object($response->code)) {
             foreach ($response->code as $code) {
                 $filename = $code->filename;
                 $php_code = $code->code;
                 $version = $code->version;
                 $default_headers = array('Name' => __('Feature Name', 'wp_crm'), 'Version' => __('Version', 'wp_crm'), 'Description' => __('Description', 'wp_crm'));
                 $current_file = @get_file_data(WP_CRM_Premium . "/" . $filename, $default_headers, 'plugin');
                 if (@version_compare($current_file['Version'], $version) == '-1') {
                     $this_file = WP_CRM_Premium . "/" . $filename;
                     $fh = @fopen($this_file, 'w');
                     if ($fh) {
                         fwrite($fh, $php_code);
                         fclose($fh);
                         if ($current_file['Version']) {
                             CRM_UD_F::log(sprintf(__('WP-CRM Premium Feature: %s updated to version %s from %s.', 'wp_crm'), $code->name, $version, $current_file['Version']));
                         } else {
                             CRM_UD_F::log(sprintf(__('WP-CRM Premium Feature: %s updated to version %s.', 'wp_crm'), $code->name, $version));
                         }
                         $updated_features[] = $code->name;
                     }
                 } else {
                 }
             }
         }
     }
     //** Update settings */
     WP_CRM_F::settings_action(true);
     if ($return && !empty($wp_crm['configuration']['disable_automatic_feature_update']) && $wp_crm['configuration']['disable_automatic_feature_update'] == 'true') {
         return __('Update ran successfully but no features were downloaded because the setting is disabled.', 'wp_crm');
     } elseif ($return) {
         return __('Update ran successfully.', 'wp_crm');
     }
 }