/** * Clean up the passed tags. Keep only alphanumeric, hyphen and underscore characters. * * @param array|string $tags Tags to be cleaned as array or comma seperated values. * @return array The cleaned tags. */ public function validate_tags(&$tags) { WP2D_Helpers::str_to_arr($tags); $tags = array_map(array($this, 'validate_tag'), array_unique(array_filter($tags, 'trim'))); return $tags; }
/** * Post to diaspora*. * * @param string $text The text to post. * @param array|string $aspects The aspects to post to. Array or comma seperated ids. * @param array $extra_data Any extra data to be added to the post call. * @return boolean|object Return the response data of the new diaspora* post if successfully posted, else false. */ public function post($text, $aspects = 'public', $extra_data = array()) { // Are we logged in? if (!$this->_check_login()) { return false; } // Put the aspects into a clean array. $aspects = array_filter(WP2D_Helpers::str_to_arr($aspects)); // If no aspects have been selected or the public one is also included, choose public only. if (empty($aspects) || in_array('public', $aspects)) { $aspects = 'public'; } // Prepare post data. $post_data = array('aspect_ids' => $aspects, 'status_message' => array('text' => $text, 'provider_display_name' => $this->provider)); // Add any extra data to the post. if (!empty($extra_data)) { $post_data += $extra_data; } // Prepare headers. // MUST fetch new token for this to work! $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-CSRF-Token: ' . $this->_fetch_token(true)); // Submit the post. $req = $this->_http_request('/status_messages', wp_json_encode($post_data), $headers); $response = json_decode($req->response); if (201 !== $req->info['http_code']) { $this->last_error = esc_html(isset($response->error) ? $response->error : _x('Unknown error occurred.', 'When an unknown error occurred in the WP2D_API object.', 'wp-to-diaspora')); return false; } // Add additional info to our response. $response->permalink = $this->get_pod_url('/posts/' . $response->guid); return $response; }