]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
improve performance of photo upload page
[friendica.git] / include / diaspora.php
index baee0420ba6439f907eb8d2bfbab417fa47b9249..c2b2fbcf4e1a71753b1a140ca1d48e5ba4e9678e 100755 (executable)
@@ -16,7 +16,7 @@ function diaspora_dispatch_public($msg) {
                return;
        }
 
-       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 ",
+       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 AND `account_removed` = 0 ",
                dbesc(NETWORK_DIASPORA),
                dbesc($msg['author'])
        );
@@ -141,6 +141,17 @@ function diaspora_get_contact_by_handle($uid,$handle) {
        );
        if($r && count($r))
                return $r[0];
+
+       $handle_parts = explode("@", $handle);
+       $nurl_sql = '%%://' . $handle_parts[1] . '%%/profile/' . $handle_parts[0];
+       $r = q("SELECT * FROM contact WHERE network = '%s' AND uid = %d AND nurl LIKE '%s' LIMIT 1",
+              dbesc(NETWORK_DFRN),
+              intval($uid),
+              dbesc($nurl_sql)
+       );
+       if($r && count($r))
+               return $r[0];
+
        return false;
 }
 
@@ -848,7 +859,8 @@ function diaspora_post($importer,$xml,$msg) {
        $datarray['parent'] = 0;
        $datarray['owner-name'] = $contact['name'];
        $datarray['owner-link'] = $contact['url'];
-       $datarray['owner-avatar'] = $contact['thumb'];
+       //$datarray['owner-avatar'] = $contact['thumb'];
+       $datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']);
        $datarray['author-name'] = $contact['name'];
        $datarray['author-link'] = $contact['url'];
        $datarray['author-avatar'] = $contact['thumb'];
@@ -951,8 +963,8 @@ function diaspora_reshare($importer,$xml,$msg) {
                $details = '[url=' . $person['url'] . ']' . $person['name'] . '[/url]';
        else
                $details = $orig_author;
-       
-       $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n"; 
+
+       $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n";
 
 
        // allocate a guid on our system - we aren't fixing any collisions.
@@ -1010,11 +1022,22 @@ function diaspora_reshare($importer,$xml,$msg) {
        $datarray['parent'] = 0;
        $datarray['owner-name'] = $contact['name'];
        $datarray['owner-link'] = $contact['url'];
-       $datarray['owner-avatar'] = $contact['thumb'];
-       $datarray['author-name'] = $contact['name'];
-       $datarray['author-link'] = $contact['url'];
-       $datarray['author-avatar'] = $contact['thumb'];
-       $datarray['body'] = $prefix . $body;
+       $datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']);
+       if (intval(get_config('system','diaspora_newreshare'))) {
+               // Let reshared messages look like wall-to-wall posts
+               // we have to set an additional value in the item in the future
+               // to distinct the wall-to-wall-posts from reshared/repeated messages
+               $datarray['author-name'] = $person['name'];
+               $datarray['author-link'] = $person['url'];
+               $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
+               $datarray['body'] = $body;
+       } else {
+               $datarray['author-name'] = $contact['name'];
+               $datarray['author-link'] = $contact['url'];
+               $datarray['author-avatar'] = $contact['thumb'];
+               $datarray['body'] = $prefix . $body;
+       }
+
        $datarray['tag'] = $str_tags;
        $datarray['app']  = 'Diaspora';
 
@@ -1105,7 +1128,8 @@ function diaspora_asphoto($importer,$xml,$msg) {
        $datarray['parent'] = 0;
        $datarray['owner-name'] = $contact['name'];
        $datarray['owner-link'] = $contact['url'];
-       $datarray['owner-avatar'] = $contact['thumb'];
+       //$datarray['owner-avatar'] = $contact['thumb'];
+       $datarray['owner-avatar'] = ((x($contact,'thumb')) ? $contact['thumb'] : $contact['photo']);
        $datarray['author-name'] = $contact['name'];
        $datarray['author-link'] = $contact['url'];
        $datarray['author-avatar'] = $contact['thumb'];
@@ -1853,7 +1877,8 @@ EOT;
 
        $arr['owner-name'] = $parent_item['name'];
        $arr['owner-link'] = $parent_item['url'];
-       $arr['owner-avatar'] = $parent_item['thumb'];
+       //$arr['owner-avatar'] = $parent_item['thumb'];
+       $arr['owner-avatar'] = ((x($parent_item,'thumb')) ? $parent_item['thumb'] : $parent_item['photo']);
 
        $arr['author-name'] = $person['name'];
        $arr['author-link'] = $person['url'];
@@ -1949,7 +1974,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
 
        $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
        if(! $contact) {
-               logger('diaspora_signed_retraction: no contact');
+               logger('diaspora_signed_retraction: no contact ' . $diaspora_handle . ' for ' . $importer['uid']);
                return;
        }
 
@@ -2061,11 +2086,20 @@ function diaspora_profile($importer,$xml,$msg) {
        $image_url = unxmlify($xml->image_url);
        $birthday = unxmlify($xml->birthday);
 
-       $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE  `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
+
+       $handle_parts = explode("@", $diaspora_handle);
+       if($name === '') {
+               $name = $handle_parts[0];
+       }
+       if(strpos($image_url, $handle_parts[1]) === false) {
+               $image_url = "http://" . $handle_parts[1] . $image_url;
+       }
+
+/*     $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE  `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
                intval($importer['uid']),
                intval($contact['id'])
        );
-       $oldphotos = ((count($r)) ? $r : null);
+       $oldphotos = ((count($r)) ? $r : null);*/
 
        require_once('include/Photo.php');
 
@@ -2098,7 +2132,7 @@ function diaspora_profile($importer,$xml,$msg) {
                intval($importer['uid'])
        ); 
 
-       if($r) {
+/*     if($r) {
                if($oldphotos) {
                        foreach($oldphotos as $ph) {
                                q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ",
@@ -2108,7 +2142,7 @@ function diaspora_profile($importer,$xml,$msg) {
                                );
                        }
                }
-       }       
+       }       */
 
        return;