X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=twitter%2Ftwitter.php;h=6468bba47a397d2e97f58ab00cd1851044d41304;hb=dfa4cfc7cde6c6f755beae5818fe3eee99724c5c;hp=b422838703b0244cd17378bff750684d0516455f;hpb=2774d69b6ac2dd43a87c38b145e0b2d74eabfc4d;p=friendica-addons.git diff --git a/twitter/twitter.php b/twitter/twitter.php index b4228387..6468bba4 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -84,6 +84,7 @@ function twitter_uninstall() { unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets'); unregister_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron'); unregister_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook'); + unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow'); // old setting - remove only unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook'); @@ -228,8 +229,13 @@ function twitter_settings(&$a,&$s) { $create_userenabled = get_pconfig(local_user(),'twitter','create_user'); $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); - $s .= '
'; - $s .= '

'. t('Twitter Posting Settings') .'

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

'. t('Twitter Settings') .'

'; + $s .= '
'; + $s .= '
'; - $s .= '
'; + $s .= '
'; } else { /*** * we have an OAuth key / secret pair for the user @@ -309,7 +315,7 @@ function twitter_settings(&$a,&$s) { $s .= ''; $s .= ''; $s .= '
'; - $s .= '
'; + $s .= '
'; } } $s .= '
'; @@ -862,7 +868,7 @@ function twitter_plugin_admin(&$a, &$o){ $t = get_markup_template( "admin.tpl", "addon/twitter/" ); $o = replace_macros($t, array( - '$submit' => t('Submit'), + '$submit' => t('Save Settings'), // name, label, value, help, [extra values] '$consumerkey' => array('consumerkey', t('Consumer key'), get_config('twitter', 'consumerkey' ), ''), '$consumersecret' => array('consumersecret', t('Consumer secret'), get_config('twitter', 'consumersecret' ), ''), @@ -936,6 +942,8 @@ function twitter_fetchtimeline($a, $uid) { if ($application_name == "") $application_name = $a->get_hostname(); + $has_picture = false; + require_once('mod/item.php'); require_once('library/twitteroauth.php'); @@ -986,13 +994,14 @@ function twitter_fetchtimeline($a, $uid) { foreach($post->retweeted_status->entities->media AS $media) { switch($media->type) { case 'photo': - $_REQUEST['body'] = str_replace($media->url, "\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); + $_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); + $has_picture = true; break; } } } - $converted = twitter_convertmsg($a, $_REQUEST['body'], true); + $converted = twitter_convertmsg($a, $_REQUEST['body'], true, $has_picture); $_REQUEST['body'] = $converted["body"]; $_REQUEST['body'] = "[share author='".$post->retweeted_status->user->name. @@ -1008,13 +1017,14 @@ function twitter_fetchtimeline($a, $uid) { foreach($post->entities->media AS $media) { switch($media->type) { case 'photo': - $_REQUEST['body'] = str_replace($media->url, "\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); + $_REQUEST['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $_REQUEST['body']); + $has_picture = true; break; } } } - $converted = twitter_convertmsg($a, $_REQUEST["body"], true); + $converted = twitter_convertmsg($a, $_REQUEST["body"], true, $has_picture); $_REQUEST['body'] = $converted["body"]; } @@ -1268,6 +1278,9 @@ function twitter_fetchuser($a, $uid, $screen_name = "", $user_id = "") { } function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing_contact) { + + $has_picture = false; + $postarray = array(); $postarray['gravity'] = 0; $postarray['uid'] = $uid; @@ -1362,7 +1375,8 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing foreach($post->entities->media AS $media) { switch($media->type) { case 'photo': - $postarray['body'] = str_replace($media->url, "\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); + $postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); + $has_picture = true; break; default: $postarray['body'] .= print_r($media, true); @@ -1370,7 +1384,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing } } - $converted = twitter_convertmsg($a, $postarray['body']); + $converted = twitter_convertmsg($a, $postarray['body'], false, $has_picture); $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; @@ -1398,7 +1412,8 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing foreach($post->retweeted_status->entities->media AS $media) { switch($media->type) { case 'photo': - $postarray['body'] = str_replace($media->url, "\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); + $postarray['body'] = str_replace($media->url, "\n\n[img]".$media->media_url_https."[/img]\n", $postarray['body']); + $has_picture = true; break; default: $postarray['body'] .= print_r($media, true); @@ -1406,12 +1421,13 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing } } - $converted = twitter_convertmsg($a, $postarray['body']); + $converted = twitter_convertmsg($a, $postarray['body'], false, $has_picture); $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; - if (!intval(get_config('system','wall-to-wall_share'))) { + // Deactivated at the moment, since there are problems with answers to retweets + if (false AND !intval(get_config('system','wall-to-wall_share'))) { $postarray['body'] = "[share author='".$post->retweeted_status->user->name. "' profile='https://twitter.com/".$post->retweeted_status->user->screen_name. "' avatar='".$post->retweeted_status->user->profile_image_url_https. @@ -1516,21 +1532,27 @@ function twitter_fetchhometimeline($a, $uid) { if(count($r)) { $own_id = $r[0]["nick"]; - } else + } else { + logger("twitter_fetchhometimeline: Own twitter contact not found for user ".$uid, LOGGER_DEBUG); return; + } $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); if(count($r)) { $self = $r[0]; - } else + } else { + logger("twitter_fetchhometimeline: Own contact not found for user ".$uid, LOGGER_DEBUG); return; + } $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if(!count($u)) + if(!count($u)) { + logger("twitter_fetchhometimeline: Own user not found for user ".$uid, LOGGER_DEBUG); return; + } $parameters = array("exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true); //$parameters["count"] = 200; @@ -1546,8 +1568,10 @@ function twitter_fetchhometimeline($a, $uid) { $items = $connection->get('statuses/home_timeline', $parameters); - if (!is_array($items)) + if (!is_array($items)) { + logger("twitter_fetchhometimeline: Error fetching home timeline: ".print_r($items, true), LOGGER_DEBUG); return; + } $posts = array_reverse($items); @@ -1587,8 +1611,10 @@ function twitter_fetchhometimeline($a, $uid) { $items = $connection->get('statuses/mentions_timeline', $parameters); - if (!is_array($items)) + if (!is_array($items)) { + logger("twitter_fetchhometimeline: Error fetching mentions: ".print_r($items, true), LOGGER_DEBUG); return; + } $posts = array_reverse($items); @@ -1710,16 +1736,24 @@ function twitter_original_url($url, $depth=1, $fetchbody = false) { return($url); } -function twitter_siteinfo($url) { +function twitter_siteinfo($url, $dontincludemedia) { require_once("mod/parse_url.php"); - $data = parseurl_getsiteinfo($url); + // Fetch site infos - but only from the meta data + $data = parseurl_getsiteinfo($url, true); + + if ($dontincludemedia) + unset($data["images"]); if (!is_string($data["text"]) AND (sizeof($data["images"]) == 0) AND ($data["title"] == $url)) return(""); if (is_string($data["title"])) - $text .= "[bookmark=".$url."]".$data["title"]."[/bookmark]\n"; + $text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]\n"; + + // Add a spoiler to the extra information + //if ((sizeof($data["images"]) > 0) OR is_string($data["text"])) + // $text .= "[spoiler]"; if (sizeof($data["images"]) > 0) { $imagedata = $data["images"][0]; @@ -1729,15 +1763,19 @@ function twitter_siteinfo($url) { if (is_string($data["text"])) $text .= "[quote]".$data["text"]."[/quote]"; + //if ((sizeof($data["images"]) > 0) OR is_string($data["text"])) + // $text .= "[/spoiler]"; + return($text); } -function twitter_convertmsg($a, $body, $no_tags = false) { +function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) { $links = preg_match_all("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", $body,$matches,PREG_SET_ORDER); $footer = ""; + $footerurl = ""; if ($links) { foreach ($matches AS $match) { @@ -1750,7 +1788,9 @@ function twitter_convertmsg($a, $body, $no_tags = false) { $body = str_replace($match[2], "\n[youtube]".$expanded_url."[/youtube]\n", $body); elseif (strstr($expanded_url, "//player.vimeo.com/")) $body = str_replace($match[2], "\n[vimeo]".$expanded_url."[/vimeo]\n", $body); - elseif (strstr($expanded_url, "//instagram.com")) + elseif (strstr($expanded_url, "//twitpic.com/")) // Test + $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); + elseif (strstr($expanded_url, "//instagram.com/")) $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); else { $img_str = fetch_url($expanded_url, true, $redirects, 4); @@ -1760,17 +1800,29 @@ function twitter_convertmsg($a, $body, $no_tags = false) { $mime = image_type_to_mime_type(exif_imagetype($tempfile)); unlink($tempfile); - if (substr($mime, 0, 6) == "image/") + if (substr($mime, 0, 6) == "image/") { $body = str_replace($match[2], "[img]".$expanded_url."[/img]", $body); - else { - $body = str_replace($match[2], "[url=".$expanded_url."]".$expanded_url."[/url]", $body); + $dontincludemedia = true; + } else { + $footerurl = $expanded_url; + $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]"; - if ($footer == "") - $footer = "\n\n".twitter_siteinfo($expanded_url); + $body = str_replace($match[2], $footerlink, $body); } } } - $body .= $footer; + + if ($footerurl != "") + $footer = "\n\n".twitter_siteinfo($footerurl, $dontincludemedia); + + if (($footerlink != "") AND (trim($footer) != "")) { + $removedlink = trim(str_replace($footerlink, "", $body)); + + if (strstr($body, $removedlink)) + $body = $removedlink; + + $body .= $footer; + } } if ($no_tags)