aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-11-26 17:02:49 -0800
committerfriendica <info@friendica.com>2013-11-26 17:02:49 -0800
commitef53c72a708ed2b1ba4cc1ffc6a926a33ba6a2f2 (patch)
treec897038356ad4d32fbcd0867a350e1aed8425dd5
parent6f6fcddfc3fc9bb2e63dd615f29116ced49838d5 (diff)
downloadvolse-hubzilla-ef53c72a708ed2b1ba4cc1ffc6a926a33ba6a2f2.tar.gz
volse-hubzilla-ef53c72a708ed2b1ba4cc1ffc6a926a33ba6a2f2.tar.bz2
volse-hubzilla-ef53c72a708ed2b1ba4cc1ffc6a926a33ba6a2f2.zip
delete from the wp side as well as from the red side
-rw-r--r--include/api.php38
-rw-r--r--util/wp/post_to_red/post_to_red.php52
2 files changed, 65 insertions, 25 deletions
diff --git a/include/api.php b/include/api.php
index 717f1572a..ca5592d08 100644
--- a/include/api.php
+++ b/include/api.php
@@ -1080,19 +1080,35 @@ require_once('include/photos.php');
// params
$id = intval(argv(3));
+ if($id) {
+ // first prove that we own the item
- // first prove that we own the item
+ $r = q("select * from item where id = %d and uid = %d limit 1",
+ intval($id),
+ intval($user_info['uid'])
+ );
+ if(! $r)
+ return false;
+ }
+ else {
+ if($_REQUEST['namespace'] && $_REQUEST['remote_id']) {
+ $r = q("select * from item_id where service = '%s' and sid = '%s' and uid = %d limit 1",
+ dbesc($_REQUEST['namespace']),
+ dbesc($_REQUEST['remote_id']),
+ intval($user_info['uid'])
+ );
+ if(! $r)
+ return false;
+ $id = $r[0]['iid'];
+ }
+ }
+ if(! $id)
+ return false;
- $r = q("select * from item where id = %d and uid = %d limit 1",
- intval($id),
- intval($user_info['uid'])
- );
+ logger('API: api_statuses_destroy: '.$id);
+ require_once('include/items.php');
+ drop_item($id, false);
- if($r) {
- logger('API: api_statuses_destroy: '.$id);
- require_once('include/items.php');
- drop_item($id, false);
- }
if ($type == 'xml')
$ok = "true";
@@ -1114,7 +1130,7 @@ require_once('include/photos.php');
if (api_user()===false) return false;
$user_info = api_get_user($a);
- // get last newtork messages
+ // get last network messages
// params
diff --git a/util/wp/post_to_red/post_to_red.php b/util/wp/post_to_red/post_to_red.php
index 4c353468c..d89ab91be 100644
--- a/util/wp/post_to_red/post_to_red.php
+++ b/util/wp/post_to_red/post_to_red.php
@@ -85,12 +85,8 @@ function post_to_red_post($post_id) {
}
}
- $message_namespace = 'wordpress';
-
$message_id = site_url() . '/' . $post_id;
- $message = $post->post_title . "<br /><br />" . $message;
-
if (isset($tag_string)) {
$message .= "<br />$tag_string";
}
@@ -98,8 +94,6 @@ function post_to_red_post($post_id) {
$bbcode = xpost_to_html2bbcode($message);
$url = $seed_location . '/api/statuses/update';
-
-
$headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password"));
$body = array(
@@ -117,20 +111,49 @@ function post_to_red_post($post_id) {
$request = new WP_Http;
$result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers));
-// if($result['response']['code'] == 200) {
-// $j = json_decode($result['body'],true);
-// if($j && $j['id']) {
-// // store the red id in case we need to delete it in the future.
-//
-// }
-// }
-// logger('post_to_red returns: ' . print_r($result,true));
+ }
+
+ }
+}
+
+
+function post_to_red_delete_post($post_id) {
+
+ $post = get_post($post_id);
+
+ // if meta has been set
+ if (get_post_meta($post_id, "post_to_red", true) == 1) {
+
+ $user_name = post_to_red_get_acct_name();
+ $password = post_to_red_get_password();
+ $seed_location = post_to_red_get_seed_location();
+ $channel = post_to_red_get_channel_name();
+
+ if ((isset($user_name)) && (isset($password)) && (isset($seed_location))) {
+
+ $message_id = site_url() . '/' . $post_id;
+ $url = $seed_location . '/api/statuses/destroy';
+
+ $headers = array('Authorization' => 'Basic '.base64_encode("$user_name:$password"));
+ $body = array(
+ 'namespace' => 'wordpress',
+ 'remote_id' => $message_id,
+ );
+ if($channel)
+ $body['channel'] = $channel;
+
+ // post:
+ $request = new WP_Http;
+ $result = $request->request($url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers));
}
}
}
+
+
+
function post_to_red_displayAdminContent() {
$seed_url = post_to_red_get_seed_location();
@@ -239,6 +262,7 @@ add_action("admin_menu", "post_to_red_admin");
add_action('publish_post', 'post_to_red_post');
add_action('add_meta_boxes', 'post_to_red_post_checkbox');
add_action('save_post', 'post_to_red_post_field_data');
+add_action('before_delete_post', 'post_to_red_delete_post');
// from:
// http://www.docgate.com/tutorial/php/how-to-convert-html-to-bbcode-with-php-script.html