if(intval($ltree_post) == 1) {
$ltree_defpost = get_pconfig(local_user(),'libertree','post_by_default');
$selected = ((intval($ltree_defpost) == 1) ? ' checked="checked" ' : '');
- $b .= '<div class="profile-jot-net"><input type="checkbox" name="libertree_enable"' . $selected . 'value="1" /> '
+ $b .= '<div class="profile-jot-net"><input type="checkbox" name="libertree_enable"' . $selected . ' value="1" /> '
. t('Post to libertree') . '</div>';
}
}
function libertree_send(&$a,&$b) {
logger('libertree_send: invoked');
- return;
if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
return;
}
}
if(count($tag_arr))
- $tags = implode(',',$tag_arr);
+ $tags = implode(',',$tag_arr);
+ $title = $b['title'];
+ $body = $b['body'];
+
+ // Insert a newline before and after a quote
+ $body = str_ireplace("[quote", "\n\n[quote", $body);
+ $body = str_ireplace("[/quote]", "[/quote]\n\n", $body);
+
+ // remove multiple newlines
+ do {
+ $oldbody = $body;
+ $body = str_replace("\n\n\n", "\n\n", $body);
+ } while ($oldbody != $body);
+
+ // convert to markdown
+ $body = bb2diaspora($body);
+
+ // Adding the title
+ if(strlen($title))
+ $body = "## ".html_entity_decode($title)."\n\n".$body;
$params = array(
- 'text' => bb2diaspora($b['body'])
+ 'text' => $body
// 'token' => $ltree_api_token
);
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $ltree_blog);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
-
- $data = curl_exec($ch);
- $result = curl_multi_getcontent($ch);
- curl_close($ch);
-
- logger('libertree_send: ' . $result);
+
+ $result = post_url($ltree_blog,$params);
+ logger('libertree: ' . $result);
+
}
}