]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
track whether contact is a community page or not
[friendica.git] / include / items.php
index 5268dfc1d8bb859bfa66e898bd89f43ed40b710f..68acb45f9b6fc7bbf86183316421dd3587b2bf3d 100755 (executable)
@@ -1046,6 +1046,22 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if(! $rino_enable)
                $rino = 0;
 
+       $ssl_val = intval(get_config('system','ssl_policy'));
+       $ssl_policy = '';
+
+       switch($ssl_val){
+               case SSL_POLICY_FULL:
+                       $ssl_policy = 'full';
+                       break;
+               case SSL_POLICY_SELFSIGN:
+                       $ssl_policy = 'self';
+                       break;                  
+               case SSL_POLICY_NONE:
+               default:
+                       $ssl_policy = 'none';
+                       break;
+       }
+
        $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
 
        logger('dfrn_deliver: ' . $url);
@@ -1077,6 +1093,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        $challenge    = hex2bin((string) $res->challenge);
        $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
        $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
+       $page         = (($owner['page-flags'] == PAGE_COMMUNITY) ? 1 : 0);
 
        $final_dfrn_id = '';
 
@@ -1118,6 +1135,11 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
                $postvars['perm'] = 'r';
        }
 
+       $postvars['ssl_policy'] = $ssl_policy;
+
+       if($page)
+               $postvars['page'] = '1';
+       
        if($rino && $rino_allowed && (! $dissolve)) {
                $key = substr(random_string(),0,16);
                $data = bin2hex(aes_encrypt($postvars['data'],$key));
@@ -1598,6 +1620,14 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -1750,6 +1780,18 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                $datarray['parent-uri'] = $item_id;
                                $datarray['uid'] = $importer['uid'];
                                $datarray['contact-id'] = $contact['id'];
+
+                               if(! link_compare($datarray['owner-link'],$contact['url'])) {
+                                       // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, 
+                                       // but otherwise there's a possible data mixup on the sender's system.
+                                       // the tgroup delivery code called from item_store will correct it if it's a forum,
+                                       // but we're going to unconditionally correct it here so that the post will always be owned by our contact. 
+                                       logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
+                                       $datarray['owner-name']   = $contact['name'];
+                                       $datarray['owner-link']   = $contact['url'];
+                                       $datarray['owner-avatar'] = $contact['thumb'];
+                               }
+
                                $r = item_store($datarray);
                                continue;
 
@@ -2139,6 +2181,14 @@ function local_delivery($importer,$data) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                        $datarray['last-child'] = 0;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -2288,6 +2338,15 @@ function local_delivery($importer,$data) {
                                if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
                                        $datarray['type'] = 'activity';
                                        $datarray['gravity'] = GRAVITY_LIKE;
+                                       // only one like or dislike per person
+                                       $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+                                               intval($datarray['uid']),
+                                               intval($datarray['contact-id']),
+                                               dbesc($datarray['verb'])
+                                       );
+                                       if($r && count($r))
+                                               continue; 
+
                                }
 
                                if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
@@ -2328,35 +2387,44 @@ function local_delivery($importer,$data) {
 
                                        if(count($myconv)) {
                                                $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
-                                               foreach($myconv as $conv) {
 
-                                                       if(! link_compare($conv['author-link'],$importer_url))
-                                                               continue;
+                                               // first make sure this isn't our own post coming back to us from a wall-to-wall event
+                                               if(! link_compare($datarray['author-link'],$importer_url)) {
 
-                                                       require_once('include/enotify.php');
                                                        
-                                                       $conv_parent = $conv['parent'];
-
-                                                       notification(array(
-                                                               'type'         => NOTIFY_COMMENT,
-                                                               'notify_flags' => $importer['notify-flags'],
-                                                               'language'     => $importer['language'],
-                                                               'to_name'      => $importer['username'],
-                                                               'to_email'     => $importer['email'],
-                                                               'uid'          => $importer['importer_uid'],
-                                                               'item'         => $datarray,
-                                                               'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
-                                                               'source_name'  => stripslashes($datarray['author-name']),
-                                                               'source_link'  => $datarray['author-link'],
-                                                               'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) 
-                                                                       ? $importer['thumb'] : $datarray['author-avatar']),
-                                                               'verb'         => ACTIVITY_POST,
-                                                               'otype'        => 'item',
-                                                               'parent'       => $conv_parent,
+                                                       foreach($myconv as $conv) {
 
-                                                       ));
+                                                               // now if we find a match, it means we're in this conversation
+       
+                                                               if(! link_compare($conv['author-link'],$importer_url))
+                                                                       continue;
 
-                                                       break;
+                                                               require_once('include/enotify.php');
+                                                               
+                                                               $conv_parent = $conv['parent'];
+
+                                                               notification(array(
+                                                                       'type'         => NOTIFY_COMMENT,
+                                                                       'notify_flags' => $importer['notify-flags'],
+                                                                       'language'     => $importer['language'],
+                                                                       'to_name'      => $importer['username'],
+                                                                       'to_email'     => $importer['email'],
+                                                                       'uid'          => $importer['importer_uid'],
+                                                                       'item'         => $datarray,
+                                                                       'link'             => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
+                                                                       'source_name'  => stripslashes($datarray['author-name']),
+                                                                       'source_link'  => $datarray['author-link'],
+                                                                       'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) 
+                                                                               ? $importer['thumb'] : $datarray['author-avatar']),
+                                                                       'verb'         => ACTIVITY_POST,
+                                                                       'otype'        => 'item',
+                                                                       'parent'       => $conv_parent,
+
+                                                               ));
+
+                                                               // only send one notification
+                                                               break;
+                                                       }
                                                }
                                        }
                                }
@@ -2427,12 +2495,24 @@ function local_delivery($importer,$data) {
                        // This is my contact on another system, but it's really me.
                        // Turn this into a wall post.
 
-                       if($contact['remote_self'])
+                       if($importer['remote_self'])
                                $datarray['wall'] = 1;
 
                        $datarray['parent-uri'] = $item_id;
                        $datarray['uid'] = $importer['importer_uid'];
                        $datarray['contact-id'] = $importer['id'];
+
+                       if(! link_compare($datarray['owner-link'],$contact['url'])) {
+                               // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, 
+                               // but otherwise there's a possible data mixup on the sender's system.
+                               // the tgroup delivery code called from item_store will correct it if it's a forum,
+                               // but we're going to unconditionally correct it here so that the post will always be owned by our contact. 
+                               logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
+                               $datarray['owner-name']   = $importer['senderName'];
+                               $datarray['owner-link']   = $importer['url'];
+                               $datarray['owner-avatar'] = $importer['thumb'];
+                       }
+
                        $r = item_store($datarray);
                        continue;
                }