/** * First function of WP_CRM_Core to be loaded, called by: plugins_loaded hook. * * @since 0.01 * * @uses $wp_crm WP-CRM configuration array * */ function WP_CRM_Core() { global $wpdb; do_action('wp_crm_pre_load'); add_filter('wp_crm_settings_save', array('WP_CRM_F', 'wp_crm_settings_save_email_required'), 10, 2); //* Process settings updates */ WP_CRM_F::settings_action(); // Load third-party plugin load_plugin_compatibility */ WP_CRM_F::load_plugin_compatibility(); //** Hook in upper init */ add_action('init', array($this, 'init_upper'), 0); /** Default init hook */ add_action('init', array($this, 'init')); //** Hook in lower init */ add_action('init', array($this, 'init_lower'), 100); if (empty($wpdb->crm_log)) { $wpdb->crm_log = $wpdb->base_prefix . 'crm_log'; } if (empty($wpdb->crm_log_meta)) { $wpdb->crm_log_meta = $wpdb->crm_log . '_meta'; } }
/** * First function of WP_CRM_Core to be loaded, called by: plugins_loaded hook. * * Load premium features. * * @since 0.01 * * @uses $wp_crm WP-CRM configuration array * */ function WP_CRM_Core() { global $wp_crm, $wp_roles, $wpdb; do_action('wp_crm_pre_load'); //* Process settings updates */ WP_CRM_F::settings_action(); //* Load premium features */ WP_CRM_F::load_premium(); // Load third-party plugin load_plugin_compatibility */ WP_CRM_F::load_plugin_compatibility(); //** Hook in upper init */ add_action('init', array($this, 'init_upper'), 0); /** Default init hook */ add_action('init', array($this, 'init')); //** Hook in lower init */ add_action('init', array($this, 'init_lower'), 100); if (!$wpdb->crm_log) { $wpdb->crm_log = $wpdb->base_prefix . 'crm_log'; } if (!$wpdb->crm_log_meta) { $wpdb->crm_log_meta = $wpdb->crm_log . '_meta'; } }
/** * 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'); } }