/** * Update The Slide styles on the SimpleReach site * * @author Eric Lubow <*****@*****.**> * @param Array $styles Style to be converted to JSON * @return String OK or error string */ function srslide_update_slide_styles() { // Pull all the necessary options // Setup our POST parameters $params = array(); $params['ts'] = (int) gmdate('U'); $params['pid'] = get_option('srslide_pid'); $srslide_api_key = get_option('srslide_api_key'); // Handle if the user's API key isn't saved in WP if (strlen($srslide_api_key) == 32) { $params['api_key'] = get_option('srslide_api_key'); } else { $params['login'] = get_option('srslide_sr_login'); $params['pass'] = get_option('srslide_sr_pass'); } $params['style'] = get_option('srslide_styles'); if (!srslide_validate_hex_color($params['style']['link']['color'])) { return __('Please specify a valid link color which starts with a "#" and has 6 of the following characters [A-F], [0-9]', 'srslide'); } $encoded_params = http_build_query($params); $url = 'https://www.simplereach.com/publisher/generate_slide_css'; $response = srslide_post_url($url, $encoded_params); // Decode the JSON $resp = json_decode($response); if ($resp === NULL) { return __('There was an http error contacting SimpleReach. Please try saving your options again.', 'srslide'); } if ($resp->success) { if ($resp->api_key && !srslide_validate_api_key(get_option('srslide_api_key'))) { update_option('srslide_api_key', $resp->api_key); } return 'OK'; } else { $errorResponse = !empty($resp->error) ? strtolower($resp->error) : ''; $errorFooter = sprintf(__("Please try again or contact <a href='mailto:%s'>SimpleReach support</a> if you believe you have received this message in error.", 'srslide'), SRSLIDE_PLUGIN_SUPPORT_EMAIL); switch ($errorResponse) { case 'incorrect timestamp': $errorMessage = __('There was an error while you were attempting to register.', 'srslide'); break; case 'invalid pid': $errorMessage = __('The PID (publisher ID) that you are attempting to sign in with does not exist.', 'srslide'); break; case 'invalid user': $errorMessage = __('The user name that you are attempting to sign in with does not exist.', 'srslide'); break; case 'invalid password': $errorMessage = __('The user name that you are attempting to register with already exists, but the password you entered was incorrect.', 'srslide'); break; case 'invalid api key': $errorMessage = __('The API key that you are using does not have access to this account or is invalid.', 'srslide'); break; case 'invalid user on account': $errorMessage = __('The user name that you are registered with does not have access to this account.', 'srslide'); break; default: $errorMessage = __('There was an error contacting SimpleReach. Please try saving your options again.', 'srslide'); break; } return $errorMessage . " " . $errorFooter; } }
$resp->success = FALSE; } else { // Get the blog name $encoded_params['account_name'] = urlencode(get_option('blogname')); // Get the site URL $encoded_params['website'] = urlencode(get_option('siteurl')); $encoded_params['reg_type'] = 'slide'; $encoded_params['ts'] = (int) gmdate('U'); // Curl call for registration $url = 'https://simplereach.com/wordpress/register'; if ($mock) { $resp = new StdClass(); $resp->success = true; $resp->error = 'Invalid login'; } else { $response = srslide_post_url($url, $encoded_params); $resp = json_decode($response); } } if (!empty($resp->success)) { // Save the PID and the API Key to Wordpress $received_api_key = $received_pid = 0; if (!empty($resp->api_key)) { $received_api_key = 1; update_option('srslide_api_key', $resp->api_key); } if (!empty($resp->pid)) { $received_pid = 1; update_option('srslide_pid', $resp->pid); } if ($received_pid && $received_api_key) {