Skip to content
Snippets Groups Projects
Commit bd147cbe authored by Prasath Nadarajah's avatar Prasath Nadarajah
Browse files

aligning and code fixes

parent 8d47ed6c
No related branches found
No related tags found
No related merge requests found
......@@ -19,11 +19,10 @@ class WP_REST_Client implements WP_Client{
function __construct( $site_ID, $port = 80, $timeout = 45 ) {
$this->access_token = push_syndicate_decrypt( get_post_meta( $site_ID, 'syn_site_token', true) );
$this->blog_ID = get_post_meta( $site_ID, 'syn_site_id', true);
$this->timeout = $timeout;
$this->useragent = 'push syndication plugin';
$this->port = $port;
$this->blog_ID = get_post_meta( $site_ID, 'syn_site_id', true);
$this->timeout = $timeout;
$this->useragent = 'push-syndication-plugin';
$this->port = $port;
}
......@@ -32,22 +31,21 @@ class WP_REST_Client implements WP_Client{
$post = (array)get_post( $post_ID );
$response = wp_remote_post( 'https://public-api.wordpress.com/rest/v1/sites/' . $this->blog_ID . '/posts/new/', array(
'method' => 'POST',
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'authorization' => 'Bearer ' . $this->access_token,
'Content-Type' => 'application/x-www-form-urlencoded'
'Content-Type' => 'application/x-www-form-urlencoded'
),
'body' => array (
'title' => $post['post_title'],
'content' => $post['post_content'],
'excerpt' => $post['post_excerpt'],
'status' => $post['post_status'],
'password' => $post['post_password'],
'categories' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'category', array('fields' => 'names') ) ),
'tags' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'post_tag', array('fields' => 'names') ) )
'title' => $post['post_title'],
'content' => $post['post_content'],
'excerpt' => $post['post_excerpt'],
'status' => $post['post_status'],
'password' => $post['post_password'],
'categories' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'category', array('fields' => 'names') ) ),
'tags' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'post_tag', array('fields' => 'names') ) )
),
) );
......@@ -73,22 +71,21 @@ class WP_REST_Client implements WP_Client{
$post = (array)get_post( $post_ID );
$response = wp_remote_post( 'https://public-api.wordpress.com/rest/v1/sites/' . $this->blog_ID . '/posts/' . $ext_ID . '/', array(
'method' => 'POST',
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'authorization' => 'Bearer ' . $this->access_token,
'Content-Type' => 'application/x-www-form-urlencoded'
'Content-Type' => 'application/x-www-form-urlencoded'
),
'body' => array (
'title' => $post['post_title'],
'content' => $post['post_content'],
'excerpt' => $post['post_excerpt'],
'status' => $post['post_status'],
'password' => $post['post_password'],
'categories' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'category', array('fields' => 'names') ) ),
'tags' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'post_tag', array('fields' => 'names') ) )
'title' => $post['post_title'],
'content' => $post['post_content'],
'excerpt' => $post['post_excerpt'],
'status' => $post['post_status'],
'password' => $post['post_password'],
'categories' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'category', array('fields' => 'names') ) ),
'tags' => $this->_prepare_terms( wp_get_object_terms( $post_ID, 'post_tag', array('fields' => 'names') ) )
),
) );
......@@ -124,11 +121,10 @@ class WP_REST_Client implements WP_Client{
public function delete_post( $ext_ID ) {
$response = wp_remote_post( 'https://public-api.wordpress.com/rest/v1/sites/' . $this->blog_ID . '/posts/' . $ext_ID . '/delete', array(
'method' => 'POST',
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'authorization' => 'Bearer ' . $this->access_token,
),
) );
......@@ -151,12 +147,11 @@ class WP_REST_Client implements WP_Client{
public function test_connection() {
// @TODo find a better method
$response = wp_remote_post( 'https://public-api.wordpress.com/rest/v1/me/?pretty=1', array(
'method' => 'GET',
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
$response = wp_remote_get( 'https://public-api.wordpress.com/rest/v1/me/?pretty=1', array(
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'authorization' => 'Bearer ' . $this->access_token,
),
) );
......@@ -180,12 +175,11 @@ class WP_REST_Client implements WP_Client{
public function is_post_exists( $post_ID ) {
$response = wp_remote_post( 'https://public-api.wordpress.com/rest/v1/sites/' . $this->blog_ID . '/posts/' . $post_ID . '/?pretty=1', array(
'method' => 'GET',
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
$response = wp_remote_get( 'https://public-api.wordpress.com/rest/v1/sites/' . $this->blog_ID . '/posts/' . $post_ID . '/?pretty=1', array(
'timeout' => $this->timeout,
'user-agent' => $this->useragent,
'sslverify' => false,
'headers' => array (
'authorization' => 'Bearer ' . $this->access_token,
),
) );
......@@ -221,12 +215,13 @@ class WP_REST_Client implements WP_Client{
public static function display_settings( $post ) {
$site_token = push_syndicate_decrypt( get_post_meta( $post->ID, 'syn_site_token', true) );
$site_id = get_post_meta( $post->ID, 'syn_site_id', true);
$site_url = get_post_meta( $post->ID, 'syn_site_url', true);
$site_id = get_post_meta( $post->ID, 'syn_site_id', true);
$site_url = get_post_meta( $post->ID, 'syn_site_url', true);
// @TODO refresh UI
?>
?>
<p>
To generate the following information automatically please visit the <a href="<?php echo get_admin_url(); ?>/options-general.php?page=push-syndicate-settings" target="_blank">settings page</a>
</p>
......@@ -248,7 +243,8 @@ class WP_REST_Client implements WP_Client{
<p>
<input type="text" name="site_url" id="site_url" size="100" value="<?php echo esc_html( $site_url ); ?>" />
</p>
<?php
<?php
}
......
......@@ -13,13 +13,13 @@ class WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements WP_Client {
function __construct( $site_ID ) {
// @TODO check port, timeout etc
$server = untrailingslashit( get_post_meta( $site_ID, 'syn_site_url', true ) );
$server = esc_url_raw( $server . '/xmlrpc.php' );
parent::__construct( $server );
$server = untrailingslashit( get_post_meta( $site_ID, 'syn_site_url', true ) );
$server = esc_url_raw( $server . '/xmlrpc.php' );
$this->username = get_post_meta( $site_ID, 'syn_site_username', true);
$this->password = push_syndicate_decrypt( get_post_meta( $site_ID, 'syn_site_password', true) );
parent::__construct( $server );
}
public function new_post( $post_ID ) {
......@@ -28,15 +28,14 @@ class WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements WP_Client {
// rearranging arguments
$args = array();
$args['post_title'] = $post['post_title'];
$args['post_content'] = $post['post_content'];
$args['post_excerpt'] = $post['post_excerpt'];
$args['post_status'] = $post['post_status'];
$args['post_type'] = $post['post_type'];
$args['wp_password'] = $post['post_password'];
$args['post_title'] = $post['post_title'];
$args['post_content'] = $post['post_content'];
$args['post_excerpt'] = $post['post_excerpt'];
$args['post_status'] = $post['post_status'];
$args['post_type'] = $post['post_type'];
$args['wp_password'] = $post['post_password'];
$args['post_date_gmt'] = $post['post_date_gmt'];
// @TODO add date arguement
// @TODO add featured image
// @TODO extend this to custom taxonomies
$args['terms_names'] = array(
......@@ -45,9 +44,12 @@ class WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements WP_Client {
);
// post meta
$custom_fields= array();
$custom_fields[] = array( 'key' => 'masterpost_url', 'value' => $post['guid'] );
$args['custom_fields'] = $custom_fields;
$args['custom_fields'] = array(
array(
'key' => 'masterpost_url',
'value' => $post['guid']
)
);
$result = $this->query(
'wp.newPost',
......@@ -77,6 +79,7 @@ class WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements WP_Client {
$args['post_status'] = $post['post_status'];
$args['post_type'] = $post['post_type'];
$args['wp_password'] = $post['post_password'];
$args['post_date_gmt'] = $post['post_date_gmt'];
// @TODO extend this to custom taxonomies
$args['terms_names'] = array(
......@@ -85,9 +88,12 @@ class WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements WP_Client {
);
// post meta
$custom_fields= array();
$custom_fields[] = array( 'key' => 'masterpost_url', 'value' => $post['guid'] );
$args['custom_fields'] = $custom_fields;
$args['custom_fields'] = array(
array(
'key' => 'masterpost_url',
'value' => $post['guid']
)
);
$result = $this->query(
'wp.editPost',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment