]> git.mxchange.org Git - friendica.git/blobdiff - include/socgraph.php
Merge branch 'pull'
[friendica.git] / include / socgraph.php
old mode 100644 (file)
new mode 100755 (executable)
index 78a5514..79d7340
@@ -40,16 +40,31 @@ function poco_load($cid,$uid = 0,$url = null) {
        if(! $url)
                return;
 
-       logger('poco_load: ' . $url, LOGGER_DATA);
+       $url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos' : '?fields=displayName,urls,photos') ;
 
+       logger('poco_load: ' . $url, LOGGER_DEBUG);
 
-       $s = fetch_url($url . ($uid) ? '/@me/@all?fields=displayName,urls,photos' : '?fields=displayName,urls,photos' );
+       $s = fetch_url($url);
+
+       logger('poco_load: returns ' . $s, LOGGER_DATA);
+
+       logger('poco_load: return code: ' . $a->get_curl_code(), LOGGER_DEBUG);
 
        if(($a->get_curl_code() > 299) || (! $s))
                return;
+
+
        $j = json_decode($s);
+
+       logger('poco_load: json: ' . print_r($j,true),LOGGER_DATA);
+
+       if(! isset($j->entry))
+               return;
+
+       $total = 0;
        foreach($j->entry as $entry) {
 
+               $total ++;
                $profile_url = '';
                $profile_photo = '';
                $connect_url = '';
@@ -136,6 +151,7 @@ function poco_load($cid,$uid = 0,$url = null) {
                }
 
        }
+       logger("poco_load: loaded $total entries",LOGGER_DEBUG);
 
        q("delete from glink where `cid` = %d and `uid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
                intval($cid),
@@ -231,20 +247,22 @@ function suggestion_query($uid, $start = 0, $limit = 40) {
                intval($limit)
        );
 
-       if(count($r))
+       if(count($r) && count($r) >= ($limit -1))
                return $r;
 
-       $r = q("SELECT gcontact.* from gcontact 
+       $r2 = q("SELECT gcontact.* from gcontact 
                left join glink on glink.gcid = gcontact.id 
-               where uid = 0 and cid = 0 and not gcontact.nurl in ( select nurl from contact where uid = %d)
+               where glink.uid = 0 and glink.cid = 0 and not gcontact.nurl in ( select nurl from contact where uid = %d)
                and not gcontact.id in ( select gcid from gcign where uid = %d )
-               order by rand limit %d, %d ",
+               order by rand() limit %d, %d ",
+               intval($uid),
                intval($uid),
                intval($start),
                intval($limit)
        );
 
-       return $r;
+
+       return array_merge($r,$r2);
 
 }