1
1
Fork 0

Merge pull request #1044 from annando/master

Better user agent string, suppress flooding of the community page by single users
This commit is contained in:
Tobias Diekershoff 2014-07-11 07:55:44 +02:00
commit 85fede486e
4 changed files with 52 additions and 36 deletions

View file

@ -488,10 +488,10 @@ function bb_ShareAttributes($share, $simplehtml) {
$text = $preshare."&gt;&gt; @".$userid_compact.": <br />".$share[3]; $text = $preshare."&gt;&gt; @".$userid_compact.": <br />".$share[3];
break; break;
case 7: case 7:
$text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')." @".$userid_compact." ".$share[3]; $text = $preshare.html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')." @".$userid_compact.": ".$share[3];
break; break;
case 8: case 8:
$text = $preshare."RT @".$userid_compact." ".$share[3]; $text = $preshare."RT @".$userid_compact.": ".$share[3];
break; break;
default: default:
$headline = trim($share[1]).'<div class="shared_header">'; $headline = trim($share[1]).'<div class="shared_header">';
@ -525,8 +525,12 @@ function GetProfileUsername($profile, $username, $compact = false) {
} }
$gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile); $gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile);
if ($gplus != $profile) if ($gplus != $profile) {
if ($compact)
return($gplususername." (".$username.")");
else
return($username." (".$gplus.")"); return($username." (".$gplus.")");
}
$friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile); $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile);
if ($friendica != $profile) { if ($friendica != $profile) {

View file

@ -35,7 +35,6 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
} }
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
//@curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)"); @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
@ -135,7 +134,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_USERAGENT, "Friendica"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
if(intval($timeout)) { if(intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
@ -1164,7 +1163,8 @@ function original_url($url, $depth=1, $fetchbody = false) {
curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'); //curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
$header = curl_exec($ch); $header = curl_exec($ch);
$curl_info = @curl_getinfo($ch); $curl_info = @curl_getinfo($ch);

View file

@ -65,25 +65,7 @@ function community_content(&$a, $update = 0) {
} }
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, $r = community_getitems($a->pager['start'], $a->pager['itemspage']);
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
`user`.`nickname`, `user`.`hidewall`
FROM `thread` FORCE INDEX (`wall_private_received`)
INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
AND `thread`.`private` = 0 AND `thread`.`wall` = 1
ORDER BY `thread`.`received` DESC LIMIT %d, %d ",
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
if(! count($r)) { if(! count($r)) {
info( t('No results.') . EOL); info( t('No results.') . EOL);
@ -93,10 +75,12 @@ function community_content(&$a, $update = 0) {
$maxpostperauthor = get_config('system','max_author_posts_community_page'); $maxpostperauthor = get_config('system','max_author_posts_community_page');
if ($maxpostperauthor != 0) { if ($maxpostperauthor != 0) {
$count = 1;
$previousauthor = ""; $previousauthor = "";
$numposts = 0; $numposts = 0;
$s = array(); $s = array();
do {
foreach ($r AS $row=>$item) { foreach ($r AS $row=>$item) {
if ($previousauthor == $item["author-link"]) if ($previousauthor == $item["author-link"])
++$numposts; ++$numposts;
@ -105,9 +89,13 @@ function community_content(&$a, $update = 0) {
$previousauthor = $item["author-link"]; $previousauthor = $item["author-link"];
if ($numposts < $maxpostperauthor) if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage']))
$s[] = $item; $s[] = $item;
} }
if ((sizeof($s) < $a->pager['itemspage']))
$r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
} while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
} else } else
$s = $r; $s = $r;
@ -125,3 +113,26 @@ function community_content(&$a, $update = 0) {
return $o; return $o;
} }
function community_getitems($start, $itemspage) {
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
`user`.`nickname`, `user`.`hidewall`
FROM `thread` FORCE INDEX (`wall_private_received`)
INNER JOIN `user` ON `user`.`uid` = `thread`.`uid` AND `user`.`hidewall` = 0
INNER JOIN `item` ON `item`.`id` = `thread`.`iid`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `contact`.`self`
WHERE `thread`.`visible` = 1 AND `thread`.`deleted` = 0 and `thread`.`moderated` = 0
AND `thread`.`private` = 0 AND `thread`.`wall` = 1
ORDER BY `thread`.`received` DESC LIMIT %d, %d ",
intval($start),
intval($itemspage)
);
return($r);
}

View file

@ -66,7 +66,8 @@ function parseurl_getsiteinfo($url, $no_guessing = false, $do_oembed = true) {
curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_USERAGENT,' Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'); //curl_setopt($ch,CURLOPT_USERAGENT,' Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0');
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
$header = curl_exec($ch); $header = curl_exec($ch);
$curl_info = @curl_getinfo($ch); $curl_info = @curl_getinfo($ch);