]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
contact edit tool buttons a bit crowded
[friendica.git] / include / items.php
index 9eaee457363f992fce4c90bffcb518112d954c55..3a3085f1b053f4312f899e8ba011a76f313b804f 100644 (file)
@@ -477,10 +477,12 @@ function get_atom_elements($feed,$item) {
        if($attach) {
                $att_arr = array();
                foreach($attach as $att) {
-                       $len = intval($att->get_length());
-                       $link = str_replace(',','%2D', notags(trim($att->get_link())));
-                       $title = str_replace(',','%2D',notags(trim($att->get_title())));
-                       $type = notags(trim($att->get_type()));
+                       $len   = intval($att->get_length());
+                       $link  = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link()))));
+                       $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title()))));
+                       $type  = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type()))));
+                       if(strpos($type,';'))
+                               $type = substr($type,0,strpos($type,';'));
                        if((! $link) || (strpos($link,'http') !== 0))
                                continue;
 
@@ -489,9 +491,7 @@ function get_atom_elements($feed,$item) {
                        if(! $type)
                                $type = 'application/octet-stream';
 
-                       // this isn't legal html - there is no size in an 'a' tag, remember to strip it before display
-
-                       $att_arr[] = '<a href="' . $link . '" size="' . $len . '" type="' . $type . '">' . $title . '</a>'; 
+                       $att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; 
                }
                $res['attach'] = implode(',', $att_arr);
        }
@@ -653,6 +653,7 @@ function item_store($arr,$force_parent = false) {
        $arr['private']       = ((x($arr,'private'))       ? intval($arr['private'])             : 0 );
        $arr['body']          = ((x($arr,'body'))          ? trim($arr['body'])                  : '');
        $arr['tag']           = ((x($arr,'tag'))           ? notags(trim($arr['tag']))           : '');
+       $arr['attach']        = ((x($arr,'attach'))        ? notags(trim($arr['attach']))        : '');
 
        if($arr['parent-uri'] === $arr['uri']) {
                $parent_id = 0;
@@ -700,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');
@@ -866,14 +868,14 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if($dissolve)
                $postvars['dissolve'] = '1';
 
-       if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
-               $postvars['data'] = $atom;
-       }
-       elseif($owner['page-flags'] == PAGE_COMMUNITY) {
+
+       if((($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
                $postvars['data'] = $atom;
+               $postvars['perm'] = 'rw';
        }
        else {
                $postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
+               $postvars['perm'] = 'r';
        }
 
        if($rino && $rino_allowed && (! $dissolve)) {
@@ -915,7 +917,6 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if((! $curl_stat) || (! strlen($xml)))
                return(-1); // timed out
 
-
        if(strpos($xml,'<?xml') === false) {
                logger('dfrn_deliver: phase 2: no valid XML returned');
                logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
@@ -924,8 +925,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 
        $res = parse_xml_string($xml);
 
-       return $res->status;
+       return $res->status; 
 }
 
 
@@ -1368,8 +1368,8 @@ function new_follower($importer,$contact,$datarray,$item) {
                // create contact record - set to readonly
 
                $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`, 
-                       `blocked`, `readonly`, `pending` )
-                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1 ) ",
+                       `blocked`, `readonly`, `pending`, `writable` )
+                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1, 1 ) ",
                        intval($importer['uid']),
                        dbesc(datetime_convert()),
                        dbesc($url),
@@ -1416,7 +1416,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' );
                        
                        }
                }
@@ -1495,10 +1497,17 @@ 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";
 
@@ -1516,8 +1525,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";
@@ -1562,6 +1571,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;
@@ -1589,13 +1630,13 @@ function item_getfeedattach($item) {
        if(count($arr)) {
                foreach($arr as $r) {
                        $matches = false;
-                       $cnt = preg_match('|\<a href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" >(.+?)</a>|',$r,$matches);
+                       $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches);
                        if($cnt) {
-                               $ret .= '<link rel="enclosure" href="' . $matches[1] . '" type="' . $matches[3] . '" ';
+                               $ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
                                if(intval($matches[2]))
                                        $ret .= 'size="' . intval($matches[2]) . '" ';
                                if($matches[4] !== ' ')
-                                       $ret .= 'title="' . $matches[4] . '" ';
+                                       $ret .= 'title="' . xmlify(trim($matches[4])) . '" ';
                                $ret .= ' />' . "\r\n";
                        }
                }