]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
work in progress js_uploader plugin, turn java uploader into plugin - not done yet
[friendica.git] / include / items.php
index 47bc9f15a9230b928f70d547779df351c6606336..7b0ff2ce6b09e0fbd936012674c6f1fe61585335 100644 (file)
@@ -35,6 +35,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
        else
                killme();
 
+
        /**
         *
         * Determine the next birthday, but only if the birthday is published
@@ -182,6 +183,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
 
 
        $atom .= replace_macros($feed_template, array(
+               '$version'      => xmlify(FRIENDIKA_VERSION),
                '$feed_id'      => xmlify($a->get_baseurl() . '/profile/' . $owner_nick),
                '$feed_title'   => xmlify($owner['name']),
                '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
@@ -379,7 +381,7 @@ function get_atom_elements($feed,$item) {
 
        // It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust 
        // the content type. Our own network only emits text normally, though it might have been converted to 
-       // html if we used a pubsubhubbub transport. But if we see even one html open tag in our text, we will
+       // html if we used a pubsubhubbub transport. But if we see even one html tag in our text, we will
        // have to assume it is all html and needs to be purified.
 
        // It doesn't matter all that much security wise - because before this content is used anywhere, we are 
@@ -388,7 +390,7 @@ function get_atom_elements($feed,$item) {
        // html.
 
 
-       if(strpos($res['body'],'<')) {
+       if((strpos($res['body'],'<')) || (strpos($res['body'],'>'))) {
 
                $res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
                        '[youtube]$1[/youtube]', $res['body']);
@@ -402,11 +404,12 @@ function get_atom_elements($feed,$item) {
 
                $purifier = new HTMLPurifier($config);
                $res['body'] = $purifier->purify($res['body']);
-       }
 
+               $res['body'] = html2bbcode($res['body']);
+       }
+       else
+               $res['body'] = escape_tags($res['body']);
        
-       $res['body'] = html2bbcode($res['body']);
-
 
        $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
        if($allow && $allow[0]['data'] == 1)
@@ -420,19 +423,29 @@ function get_atom_elements($feed,$item) {
        else
                $res['private'] = 0;
 
-       $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
-       if($rawcreated)
-               $res['created'] = unxmlify($rawcreated[0]['data']);
 
        $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
        if($rawlocation)
                $res['location'] = unxmlify($rawlocation[0]['data']);
 
 
+       $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
+       if($rawcreated)
+               $res['created'] = unxmlify($rawcreated[0]['data']);
+
+
        $rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
        if($rawedited)
                $res['edited'] = unxmlify($rawcreated[0]['data']);
 
+
+       if(! $res['created'])
+               $res['created'] = $item->get_date();
+
+       if(! $res['edited'])
+               $res['edited'] = $item->get_date();
+
+
        $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
        if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
                $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
@@ -494,7 +507,7 @@ function get_atom_elements($feed,$item) {
                                $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
                        // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
                        $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
-                       if(strpos($body,'<')) {
+                       if((strpos($body,'<')) || (strpos($body,'>'))) {
 
                                $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
                                        '[youtube]$1[/youtube]', $body);
@@ -504,9 +517,11 @@ function get_atom_elements($feed,$item) {
 
                                $purifier = new HTMLPurifier($config);
                                $body = $purifier->purify($body);
+                               $body = html2bbcode($body);
                        }
+                       else
+                               $body = escape_tags($body);
 
-                       $body = html2bbcode($body);
                        $res['object'] .= '<content>' . $body . '</content>' . "\n";
                }
 
@@ -533,7 +548,7 @@ function get_atom_elements($feed,$item) {
                                $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
                        // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
                        $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
-                       if(strpos($body,'<')) {
+                       if((strpos($body,'<')) || (strpos($body,'>'))) {
 
                                $body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
                                        '[youtube]$1[/youtube]', $body);
@@ -543,9 +558,11 @@ function get_atom_elements($feed,$item) {
 
                                $purifier = new HTMLPurifier($config);
                                $body = $purifier->purify($body);
+                               $body = html2bbcode($body);
                        }
+                       else
+                               $body = escape_tags($body);
 
-                       $body = html2bbcode($body);
                        $res['target'] .= '<content>' . $body . '</content>' . "\n";
                }
 
@@ -570,7 +587,7 @@ function encode_rel_links($links) {
                if($link['attribs']['']['type'])
                        $o .= 'type="' . $link['attribs']['']['type'] . '" ';
                if($link['attribs']['']['href'])
-                       $o .= 'type="' . $link['attribs']['']['href'] . '" ';
+                       $o .= 'href="' . $link['attribs']['']['href'] . '" ';
                if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['width'])
                        $o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
                if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['height'])
@@ -629,8 +646,8 @@ function item_store($arr) {
        // they came through. 
 
        $arr['body']          = str_replace(
-                                                               array('&amp;amp;','&amp;gt;','&amp;lt;'),
-                                                               array('&amp;'    ,'&gt;'    ,'&lt;'),
+                                                               array('&amp;amp;', '&amp;gt;', '&amp;lt;', '&amp;quot;'),
+                                                               array('&amp;'    , '&gt;'    , '&lt;',     '&quot;'),
                                                                $arr['body']
                                                        );
 
@@ -739,7 +756,7 @@ function get_item_contact($item,$contacts) {
 }
 
 
-function dfrn_deliver($owner,$contact,$atom) {
+function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 
        $a = get_app();
 
@@ -781,8 +798,8 @@ function dfrn_deliver($owner,$contact,$atom) {
                return (($res->status) ? $res->status : 3);
 
        $postvars     = array();
-       $sent_dfrn_id = hex2bin($res->dfrn_id);
-       $challenge    = hex2bin($res->challenge);
+       $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
+       $challenge    = hex2bin((string) $res->challenge);
        $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
 
        $final_dfrn_id = '';
@@ -810,6 +827,8 @@ function dfrn_deliver($owner,$contact,$atom) {
 
        $postvars['dfrn_id']      = $idtosend;
        $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
+       if($dissolve)
+               $postvars['dissolve'] = '1';
 
        if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
                $postvars['data'] = $atom;
@@ -821,7 +840,7 @@ function dfrn_deliver($owner,$contact,$atom) {
                $postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
        }
 
-       if($rino && $rino_allowed) {
+       if($rino && $rino_allowed && (! $dissolve)) {
                $key = substr(random_string(),0,16);
                $data = bin2hex(aes_encrypt($postvars['data'],$key));
                $postvars['data'] = $data;
@@ -991,7 +1010,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                         *
                         */
                         
-                       $bdtext = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . t('\'s birthday');
+                       $bdtext = t('Birthday:') . ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' ;
 
 
                        $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`)
@@ -1148,6 +1167,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                                        );
                                        $datarray['last-child'] = 1;
                                }
+                               if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+                                       // one way feed - no remote comment ability
+                                       $datarray['last-child'] = 0;
+                               }
                                $datarray['parent-uri'] = $parent_uri;
                                $datarray['uid'] = $importer['uid'];
                                $datarray['contact-id'] = $contact['id'];
@@ -1200,6 +1223,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                                        $datarray['last-child'] = 1;
                                }
 
+                               if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+                                       // one way feed - no remote comment ability
+                                       $datarray['last-child'] = 0;
+                               }
+
                                $datarray['parent-uri'] = $item_id;
                                $datarray['uid'] = $importer['uid'];
                                $datarray['contact-id'] = $contact['id'];
@@ -1209,7 +1237,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                        }
                }
        }
-
 }
 
 function new_follower($importer,$contact,$datarray,$item) {