X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tumblr%2Ftumblr.php;h=650e0b183d73a54a5a1a5d855422fecf928c6bfa;hb=71ec9fdd9893ad429898dd5a6a0b5d1d1ed481c6;hp=25a0287cd6d7631a404cd11f54f0b6043cd140ba;hpb=591fa095aa86f15fd43a3969f63ea85a0bb0889c;p=friendica-addons.git diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php old mode 100644 new mode 100755 index 25a0287c..650e0b18 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -2,6 +2,7 @@ /** * Name: Tumblr Post Connector + * Description: Post to Tumblr * Version: 1.0 * Author: Mike Macgirvin */ @@ -155,15 +156,65 @@ function tumblr_send(&$a,&$b) { require_once('include/bbcode.php'); + $tag_arr = array(); + $tags = ''; + $x = preg_match_all('/\#\[(.*?)\](.*?)\[/',$b['tag'],$matches,PREG_SET_ORDER); + + if($x) { + foreach($matches as $mtch) { + $tag_arr[] = $mtch[2]; + } + } + if(count($tag_arr)) + $tags = implode(',',$tag_arr); + + $link = ""; + $video = false; + + // Checking for a bookmark + if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) { + $link = $matches[1]; + if ($b['title'] == '') + $b['title'] = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'); + + $body = $b['body']; + // splitting the text in two parts: + // before and after the bookmark + $pos = strpos($body, "[bookmark"); + $body1 = substr($body, 0, $pos); + $body2 = substr($body, $pos); + + // Removing the bookmark + $body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2); + $body = $body1.$body2; + + $video = ((stristr($link,'youtube')) || (stristr($link,'youtu.be')) || (stristr($mtch[1],'vimeo'))); + } + $params = array( 'email' => $tmbl_username, 'password' => $tmbl_password, - 'title' => (($b['title']) ? $b['title'] : t('Post from Friendica')), - 'type' => 'regular', 'format' => 'html', 'generator' => 'Friendica', - 'body' => bbcode($b['body']) - ); + 'tags' => $tags); + + if (($link != '') and $video) { + $params['type'] = "video"; + $params['embed'] = $link; + if ($b['title'] != '') + $params['caption'] = '

'.$b['title']."

".bbcode($body); + else + $params['caption'] = bbcode($body); + } else if (($link != '') and !$video) { + $params['type'] = "link"; + $params['name'] = $b['title']; + $params['url'] = $link; + $params['description'] = bbcode($body); + } else { + $params['type'] = "regular"; + $params['title'] = $b['title']; + $params['body'] = bbcode($b['body']); + } $x = post_url($tmbl_blog,$params); $ret_code = $a->get_curl_code(); @@ -172,7 +223,7 @@ function tumblr_send(&$a,&$b) { elseif($ret_code == 403) logger('tumblr_send: authentication failure'); else - logger('tumblr_send: general error: ' . print_r($x,true)); + logger('tumblr_send: general error: ' . print_r($x,true)); } }