]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
more plugin hooks
[friendica.git] / include / items.php
index 04b86ab3fe55605226c3cf98ee21743e7738c885..22d47d44fe6cdb667f01cd341c080b8186c1cc66 100644 (file)
@@ -158,7 +158,12 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
        ));
 
 
+       call_hooks('atom_feed', $atom);
+
        if(! count($items)) {
+
+               call_hooks('atom_feed_end', $atom);
+
                $atom .= '</feed>' . "\r\n";
                return $atom;
        }
@@ -177,7 +182,10 @@ function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
                $atom .= atom_entry($item,$type,null,$owner,true);
        }
 
+       call_hooks('atom_feed_end', $atom);
+
        $atom .= '</feed>' . "\r\n";
+
        return $atom;
 }
 
@@ -367,6 +375,12 @@ function get_atom_elements($feed,$item) {
        else
                $res['last-child'] = 0;
 
+       $private = $item->get_item_tags(NAMESPACE_DFRN,'private');
+       if($private && $private[0]['data'] == 1)
+               $res['private'] = 1;
+       else
+               $res['private'] = 0;
+
        $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
        if($rawcreated)
                $res['created'] = unxmlify($rawcreated[0]['data']);
@@ -485,6 +499,10 @@ function get_atom_elements($feed,$item) {
                $res['target'] .= '</target>' . "\n";
        }
 
+       $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
+
+       call_hooks('parse_atom', $arr);
+
        return $res;
 }
 
@@ -549,13 +567,19 @@ function item_store($arr) {
        $arr['allow_gid']     = ((x($arr,'allow_gid'))     ? trim($arr['allow_gid'])             : '');
        $arr['deny_cid']      = ((x($arr,'deny_cid'))      ? trim($arr['deny_cid'])              : '');
        $arr['deny_gid']      = ((x($arr,'deny_gid'))      ? trim($arr['deny_gid'])              : '');
+       $arr['private']       = ((x($arr,'private'))       ? intval($arr['private'])             : 0 );
        $arr['body']          = ((x($arr,'body'))          ? escape_tags(trim($arr['body']))     : '');
 
        // The content body has been through a lot of filtering and transport escaping by now. 
        // We don't want to skip any filters, however a side effect of all this filtering 
-       // is that ampersands will have been double encoded. 
+       // is that ampersands and <> may have been double encoded, depending on which filter chain
+       // they came through. 
 
-       $arr['body']          = str_replace('&amp;amp;','&amp;',$arr['body']);
+       $arr['body']          = str_replace(
+                                                               array('&amp;amp;','&amp;gt;','&amp;lt;'),
+                                                               array('&amp;'    ,'&gt;'    ,'&lt;'),
+                                                               $arr['body']
+                                                       );
 
 
 
@@ -576,6 +600,16 @@ function item_store($arr) {
                );
 
                if(count($r)) {
+
+                       // is the new message multi-level threaded?
+                       // even though we don't support it now, preserve the info
+                       // and re-attach to the conversation parent.
+
+                       if($r[0]['uri'] != $r[0]['parent-uri']) {
+                               $arr['thr-parent'] = $arr['parent-uri'];
+                               $arr['parent-uri'] = $r[0]['parent-uri'];
+                       }
+
                        $parent_id = $r[0]['id'];
                        $allow_cid = $r[0]['allow_cid'];
                        $allow_gid = $r[0]['allow_gid'];
@@ -588,6 +622,8 @@ function item_store($arr) {
                }
        }
 
+       call_hooks('post_remote',$arr);
+
        dbesc_array($arr);
 
        logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
@@ -616,15 +652,21 @@ function item_store($arr) {
        if($arr['parent-uri'] === $arr['uri'])
                $parent_id = $current_post;
  
+       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+               $private = 1;
+       else
+               $private = $arr['private']; 
+
        // Set parent id - and also make sure to inherit the parent's ACL's.
 
        $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
-               `deny_cid` = '%s', `deny_gid` = '%s' WHERE `id` = %d LIMIT 1",
+               `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
                intval($parent_id),
                dbesc($allow_cid),
                dbesc($allow_gid),
                dbesc($deny_cid),
                dbesc($deny_gid),
+               intval($private),
                intval($current_post)
        );
 
@@ -1201,6 +1243,9 @@ function atom_author($tag,$name,$uri,$h,$w,$photo) {
        $o .= "<uri>$uri</uri>\r\n";
        $o .= '<link rel="photo"  type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
        $o .= '<link rel="avatar" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
+
+       call_hooks('atom_author', $o);
+
        $o .= "</$tag>\r\n";
        return $o;
 }
@@ -1241,6 +1286,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        if($item['coord'])
                $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
 
+       if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
+               $o .= '<dfrn:private>1</dfrn:private>' . "\r\n";
+
        $verb = construct_verb($item);
        $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
        $actobj = construct_activity_object($item);
@@ -1254,6 +1302,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        if($mentioned)
                $o .= $mentioned;
        
+       call_hooks('atom_entry', $o);
+
        $o .= '</entry>' . "\r\n";
        
        return $o;