X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=libertree%2Flibertree.php;h=d614d758a3ed1ff5e4d292d92b895afce4b9af1d;hb=2e96c60a478156a9dae89d9ab9d35c6eebf543e6;hp=e91996ccad10b850059af2a42ad022abac58e16e;hpb=b6985e0e668cc847967f756701db18d24c92c8b9;p=friendica-addons.git diff --git a/libertree/libertree.php b/libertree/libertree.php index e91996cc..d614d758 100755 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -32,7 +32,7 @@ function libertree_jot_nets(&$a,&$b) { if(intval($ltree_post) == 1) { $ltree_defpost = get_pconfig(local_user(),'libertree','post_by_default'); $selected = ((intval($ltree_defpost) == 1) ? ' checked="checked" ' : ''); - $b .= '
' + $b .= '
' . t('Post to libertree') . '
'; } } @@ -50,8 +50,8 @@ function libertree_settings(&$a,&$s) { /* Get the current state of our config variables */ $enabled = get_pconfig(local_user(),'libertree','post'); - $checked = (($enabled) ? ' checked="checked" ' : ''); + $css = (($enabled) ? '' : '-disabled'); $def_enabled = get_pconfig(local_user(),'libertree','post_by_default'); @@ -63,8 +63,14 @@ function libertree_settings(&$a,&$s) { /* Add some HTML to the existing form */ - $s .= '
'; - $s .= '

' . t('libertree Post Settings') . '

'; + $s .= ''; + $s .= '

'. t('libertree Export').'

'; + $s .= '
'; + $s .= ''; } @@ -118,7 +124,7 @@ function libertree_post_local(&$a,&$b) { if($b['private'] || $b['parent']) return; - $ltree_post = intval(get_pconfig(local_user(),'libertree','post')); + $ltree_post = intval(get_pconfig(local_user(),'libertree','post')); $ltree_enable = (($ltree_post && x($_REQUEST,'libertree_enable')) ? intval($_REQUEST['libertree_enable']) : 0); @@ -139,7 +145,6 @@ function libertree_post_local(&$a,&$b) { function libertree_send(&$a,&$b) { logger('libertree_send: invoked'); - return; if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) return; @@ -154,8 +159,12 @@ function libertree_send(&$a,&$b) { $ltree_api_token = get_pconfig($b['uid'],'libertree','libertree_api_token'); $ltree_url = get_pconfig($b['uid'],'libertree','libertree_url'); $ltree_blog = "$ltree_url/api/v1/posts/create/?token=$ltree_api_token"; + if (isset($a->config['sitename']) AND ($a->config['sitename'] != "")) + $ltree_source = $a->config['sitename']; + else + $ltree_source = "Friendica"; - if($ltree_url && $ltree_api_token && $ltree_blog) { + if($ltree_url && $ltree_api_token && $ltree_blog && $ltree_source) { require_once('include/bb2diaspora.php'); $tag_arr = array(); @@ -168,28 +177,43 @@ function libertree_send(&$a,&$b) { } } 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); + + // Removal of tags and mentions + // #-tags + $body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body); + // @-mentions + $body = preg_replace('/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $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, false, false); + + // Adding the title + if(strlen($title)) + $body = "## ".html_entity_decode($title)."\n\n".$body; $params = array( - 'text' => bb2diaspora($b['body']) + 'text' => $body, + 'source' => $ltree_source // '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); + } }