]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
bug #65 'show all nn comments', 'show more posts like this' are misleading after...
[friendica.git] / include / items.php
index 82752e168809087f33e867a735f44317260d7972..8c2c78696c57fba346fdf7b9b9da950920602f79 100644 (file)
@@ -113,7 +113,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
 
        $items = $r;
 
-       $feed_template = load_view_file('view/atom_feed.tpl');
+       $feed_template = get_markup_template('atom_feed.tpl');
 
        $atom = '';
 
@@ -701,6 +701,7 @@ function item_store($arr,$force_parent = false) {
                                $parent_id = 0;
                                $arr['thr-parent'] = $arr['parent-uri'];
                                $arr['parent-uri'] = $arr['uri'];
+                               $arr['gravity'] = 0;
                        }
                        else {
                                logger('item_store: item parent was not found - ignoring item');
@@ -1204,6 +1205,13 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
                                $item_id  = $item->get_id();
                                $datarray = get_atom_elements($feed,$item);
 
+                               if(! x($datarray,'author-name'))
+                                       $datarray['author-name'] = $contact['name'];
+                               if(! x($datarray,'author-link'))
+                                       $datarray['author-link'] = $contact['url'];
+                               if(! x($datarray,'author-avatar'))
+                                       $datarray['author-avatar'] = $contact['thumb'];
+
                                $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($item_id),
                                        intval($importer['uid'])
@@ -1277,6 +1285,15 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
 
                                $datarray = get_atom_elements($feed,$item);
 
+                               if(is_array($contact)) {
+                                       if(! x($datarray,'author-name'))
+                                               $datarray['author-name'] = $contact['name'];
+                                       if(! x($datarray,'author-link'))
+                                               $datarray['author-link'] = $contact['url'];
+                                       if(! x($datarray,'author-avatar'))
+                                               $datarray['author-avatar'] = $contact['thumb'];
+                               }
+
                                $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($item_id),
                                        intval($importer['uid'])
@@ -1404,7 +1421,7 @@ function new_follower($importer,$contact,$datarray,$item) {
                $a = get_app();
                if(count($r)) {
                        if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
-                               $email_tpl = load_view_file('view/follow_notify_eml.tpl');
+                               $email_tpl = get_intltext_template('follow_notify_eml.tpl');
                                $email = replace_macros($email_tpl, array(
                                        '$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
                                        '$url' => $url,
@@ -1415,7 +1432,9 @@ function new_follower($importer,$contact,$datarray,$item) {
                                $res = mail($r[0]['email'], 
                                        t("You have a new follower at ") . $a->config['sitename'],
                                        $email,
-                                       'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
+                                       'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+                                       . 'Content-type: text/plain; charset=UTF-8' . "\n"
+                                       . 'Content-transfer-encoding: 8bit' );
                        
                        }
                }
@@ -1494,17 +1513,24 @@ function atom_author($tag,$name,$uri,$h,$w,$photo) {
 
 function atom_entry($item,$type,$author,$owner,$comment = false) {
 
+       $a = get_app();
+
        if($item['deleted'])
                return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n";
 
-       $a = get_app();
+
+       if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid'])
+               $body = fix_private_photos($item['body'],$owner['uid']);
+       else
+               $body = $item['body'];
+
 
        $o = "\r\n\r\n<entry>\r\n";
 
        if(is_array($author))
                $o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']);
        else
-               $o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']);
+               $o .= atom_author('author',(($item['author-name']) ? $item['author-name'] : $item['name']),(($item['author-link']) ? $item['author-link'] : $item['url']),80,80,(($item['author-avatar']) ? $item['author-avatar'] : $item['thumb']));
        if(strlen($item['owner-name']))
                $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
 
@@ -1515,8 +1541,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
        $o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
        $o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
-       $o .= '<dfrn:env>' . base64url_encode($item['body'], true) . '</dfrn:env>' . "\r\n";
-       $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
+       $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
+       $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($body) : $body) . '</content>' . "\r\n";
        $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
        if($comment)
                $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
@@ -1561,6 +1587,38 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        return $o;
 }
 
+function fix_private_photos($s,$uid) {
+       $a = get_app();
+       logger('fix_private_photos');
+
+       if(preg_match("/\[img\](.+?)\[\/img\]/is",$s,$matches)) {
+               $image = $matches[1];
+               logger('fix_private_photos: found photo ' . $image);
+               if(stristr($image ,$a->get_baseurl() . '/photo/')) {
+                       $i = basename($image);
+                       $i = str_replace('.jpg','',$i);
+                       $x = strpos($i,'-');
+                       if($x) {
+                               $res = substr($i,$x+1);
+                               $i = substr($i,0,$x);
+                               $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d AND `uid` = %d",
+                                       dbesc($i),
+                                       intval($res),
+                                       intval($uid)
+                               );
+                               if(count($r)) {
+                                       logger('replacing photo');
+                                       $s = str_replace($image, 'data:image/jpg;base64,' . base64_encode($r[0]['data']), $s);
+                               }
+                       }
+                       logger('fix_private_photos: replaced: ' . $s, LOGGER_DATA);
+               }       
+       }
+       return($s);
+}
+
+
+
 function item_getfeedtags($item) {
        $ret = array();
        $matches = false;