X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=gpluspost%2Fgpluspost.php;h=a66e1e45ff4c9516207212006188b02769cebdf0;hb=1754b58cd91729b75c038c2b2075df09307c1e3c;hp=db240aa3eeee20229e0645ec3d61ba4237129ffa;hpb=ed96ffa9208b8361766a1f16034ca2cf9e2393dc;p=friendica-addons.git diff --git a/gpluspost/gpluspost.php b/gpluspost/gpluspost.php index db240aa3..a66e1e45 100644 --- a/gpluspost/gpluspost.php +++ b/gpluspost/gpluspost.php @@ -2,7 +2,7 @@ /** * Name: G+ Post - * Description: Posts to a Google+ page with the help of Seesmic + * Description: Posts to a Google+ page with the help of Hootsuite * Version: 0.1 * Author: Michael Vogel */ @@ -42,6 +42,10 @@ function gpluspost_settings(&$a,&$s) { if(! local_user()) return; + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + $enabled = get_pconfig(local_user(),'gpluspost','post'); $checked = (($enabled) ? ' checked="checked" ' : ''); @@ -51,8 +55,17 @@ function gpluspost_settings(&$a,&$s) { $noloop_enabled = get_pconfig(local_user(),'gpluspost','no_loop_prevention'); $noloop_checked = (($noloop_enabled) ? ' checked="checked" ' : ''); - $s .= '
'; + $skip_enabled = get_pconfig(local_user(),'gpluspost','skip_without_link'); + $skip_checked = (($skip_enabled) ? ' checked="checked" ' : ''); + + $s .= ''; $s .= '

' . t('Google+ Post Settings') . '

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

Register an account at Hootsuite, add your G+ page and add the feed-url there.
'; + $s .= 'Feed-url: '.$a->get_baseurl().'/gpluspost/'.urlencode($a->user["nickname"]).'

'; } function gpluspost_settings_post(&$a,&$b) { @@ -81,6 +99,7 @@ function gpluspost_settings_post(&$a,&$b) { set_pconfig(local_user(),'gpluspost','post',intval($_POST['gpluspost'])); set_pconfig(local_user(),'gpluspost','post_by_default',intval($_POST['gpluspost_bydefault'])); set_pconfig(local_user(),'gpluspost','no_loop_prevention',intval($_POST['gpluspost_noloopprevention'])); + set_pconfig(local_user(),'gpluspost','skip_without_link',intval($_POST['gpluspost_skipwithoutlink'])); } } @@ -207,7 +226,7 @@ function gpluspost_original_url($url, $depth=1) { curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_USERAGENT,'Opera/9.64(Windows NT 5.1; U; de) Presto/2.1.1'); + curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'); $header = curl_exec($ch); $curl_info = @curl_getinfo($ch); @@ -254,43 +273,19 @@ function gpluspost_original_url($url, $depth=1) { return($url); } -function gpluspost_ShareAttributes($match) { - - $attributes = $match[1]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $headline = '
'; - - $headline .= sprintf(t('%s:'), $author); - - $headline .= "
"; - - //$text = "
".$headline."
".$match[2]."
"; - //$text = "\n\t".$match[2].":\t"; - $text = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$author.": ".$match[2]; - - return($text); -} - function gpluspost_feeditem($pid, $uid) { global $a; require_once('include/bbcode.php'); require_once("include/html2plain.php"); - $max_char = 140; + $skipwithoutlink = get_pconfig($uid,'gpluspost','skip_without_link'); $items = q("SELECT `uri`, `plink`, `author-link`, `author-name`, `created`, `edited`, `id`, `title`, `body` from `item` WHERE id=%d", intval($pid)); foreach ($items AS $item) { + $item['body'] = bb_CleanPictureLinks($item['body']); + // Looking for the first image $image = ''; if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$item['body'],$matches)) @@ -314,10 +309,13 @@ function gpluspost_feeditem($pid, $uid) { $multiplelinks = (strpos($item['body'], "[bookmark") != strrpos($item['body'], "[bookmark")); $body = $item['body']; - $body = preg_replace_callback("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]/ism","gpluspost_ShareAttributes", $body); - $html = bbcode($body, false, false); + // At first convert the text to html + $html = bbcode($body, false, false, 2); + + // Then convert it to plain text $msg = trim(html2plain($html, 0, true)); + $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8'); // If there is no bookmark element then take the first link if ($link == '') { @@ -349,7 +347,9 @@ function gpluspost_feeditem($pid, $uid) { else if ($image != "") $msglink = $image; - if ($msglink == "") + if (($msglink == "") AND $skipwithoutlink) + continue; + else if ($msglink == "") $msglink = $item["plink"]; // Fetching the title - or the first line