]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
prevent duplicate @ tags
[friendica.git] / include / diaspora.php
index fa5973e7b90e453b6cc97429f3dc9b4cb16dae8b..ac78beb2f9e58a9d2037307d01e19e577a71a7ac 100644 (file)
@@ -92,12 +92,14 @@ function find_diaspora_person_by_handle($handle) {
                dbesc($handle)
        );
        if(count($r)) {
+               logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
                // update record occasionally so it doesn't get stale
                $d = strtotime($r[0]['updated'] . ' +00:00');
                if($d > strtotime('now - 14 days'))
                        return $r[0];
                $update = true;
        }
+       logger('find_diaspora_person_by_handle: refresh',LOGGER_DEBUG);
        require_once('include/Scrape.php');
        $r = probe_url($handle, PROBE_DIASPORA);
        if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
@@ -449,13 +451,14 @@ function diaspora_request($importer,$xml) {
 
        $batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public');
 
-       $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
-               VALUES ( %d, '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
+       $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
+               VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
                intval($importer['uid']),
                dbesc($ret['network']),
                dbesc($ret['addr']),
                datetime_convert(),
                dbesc($ret['url']),
+               dbesc(normalise_link($ret['url'])),
                dbesc($batch),
                dbesc($ret['name']),
                dbesc($ret['nick']),
@@ -633,12 +636,18 @@ function diaspora_reshare($importer,$xml) {
        $x = str_replace(array('<activity_streams-photo>','</activity_streams-photo>'),array('<asphoto>','</asphoto>'),$x);
        $source_xml = parse_xml_string($x,false);
 
-       if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url))
+       if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) {
                $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
-       elseif($source_xml->post->asphoto->image_url)
+               $body = scale_diaspora_images($body,false);
+       }
+       elseif($source_xml->post->asphoto->image_url) {
                $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
+               $body = scale_diaspora_images($body);
+       }
        elseif($source_xml->post->status_message) {
                $body = diaspora2bb($source_xml->post->status_message->raw_message);
+               $body = scale_diaspora_images($body);
+
        }
        else {
                logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml,true));
@@ -769,16 +778,19 @@ function diaspora_asphoto($importer,$xml) {
        $created = unxmlify($xml->created_at);
        $private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
 
-       if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url))
+       if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url)) {
                $body = '[url=' . notags(unxmlify($xml->image_url)) . '][img]' . notags(unxmlify($xml->objectId)) . '[/img][/url]' . "\n";
-       elseif($xml->image_url)
+               $body = scale_diaspora_images($body,false);
+       }
+       elseif($xml->image_url) {
                $body = '[img]' . notags(unxmlify($xml->image_url)) . '[/img]' . "\n";
+               $body = scale_diaspora_images($body);
+       }
        else {
                logger('diaspora_asphoto: no photo url found.');
                return;
        }
 
-
        $datarray = array();
 
        
@@ -947,7 +959,10 @@ function diaspora_comment($importer,$xml,$msg) {
        $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
        $datarray['body'] = $body;
        $datarray['tag'] = $str_tags;
-       $datarray['app']  = 'Diaspora';
+
+       // We can't be certain what the original app is if the message is relayed.
+       if(($parent_item['origin']) && (! $parent_author_signature)) 
+               $datarray['app']  = 'Diaspora';
 
        $message_id = item_store($datarray);
 
@@ -1014,6 +1029,8 @@ function diaspora_photo($importer,$xml,$msg) {
 
        $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
 
+       $link_text = scale_diaspora_images($link_text);
+
        if(strpos($parent_item['body'],$link_text) === false) {
                $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
                        dbesc($link_text . $parent_item['body']),
@@ -1376,6 +1393,14 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
 
        $body = $item['body'];
 
+/*
+       // We're trying to match Diaspora's split message/photo protocol but
+       // all the photos are displayed on D* as links and not img's - even
+       // though we're sending pretty much precisely what they send us when
+       // doing the same operation.  
+       // Commented out for now, we'll use bb2diaspora to convert photos to markdown
+       // which seems to get through intact.
+
        $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER);
        if($cnt) {
                foreach($matches as $mtch) {
@@ -1389,9 +1414,21 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
                        $body = str_replace($detail['str'],$mtch[1],$body);
                }
        }       
+*/
 
        $body = xmlify(html_entity_decode(bb2diaspora($body)));
 
+       if($item['attach']) {
+               $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER);
+               if(cnt) {
+                       $body .= "\n" . t('Attachments:') . "\n";
+                       foreach($matches as $mtch) {
+                               $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n";
+                       }
+               }
+       }       
+
+
        $public = (($item['private']) ? 'false' : 'true');
 
        require_once('include/datetime.php');