X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=cbf5e4d24dd49113514f0d86e6cf8355fae18642;hb=73b4faca5c7af506558eba6b7317d23551f1aefa;hp=5969466813a0d1b406a8319c3802abfc4ef6a007;hpb=cc45ac14b5ec2e37ef9d021642a4916877c8bacf;p=friendica.git diff --git a/include/items.php b/include/items.php index 5969466813..cbf5e4d24d 100644 --- a/include/items.php +++ b/include/items.php @@ -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 = ''; @@ -354,6 +354,9 @@ function get_atom_elements($feed,$item) { $res['body'] = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $res['body']); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $res['body'] = oembed_html2bbcode($res['body']); $config = HTMLPurifier_Config::createDefault(); @@ -381,6 +384,9 @@ function get_atom_elements($feed,$item) { else $res['private'] = 0; + $extid = $item->get_item_tags(NAMESPACE_DFRN,'extid'); + if($extid && $extid[0]['data']) + $res['extid'] = $extid[0]['data']; $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location'); if($rawlocation) @@ -477,10 +483,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 +497,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[] = '' . $title . ''; + $att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; } $res['attach'] = implode(',', $att_arr); } @@ -521,6 +527,10 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); @@ -560,6 +570,9 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); @@ -624,6 +637,7 @@ function item_store($arr,$force_parent = false) { $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string()); + $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : ''); $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : ''); $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : ''); $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : ''); @@ -701,6 +715,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'); @@ -867,14 +882,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('1','0',$atom); + $postvars['perm'] = 'r'; } if($rino && $rino_allowed && (! $dissolve)) { @@ -916,7 +931,6 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { if((! $curl_stat) || (! strlen($xml))) return(-1); // timed out - if(strpos($xml,'status; - + return $res->status; } @@ -1206,6 +1219,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']) @@ -1279,6 +1299,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']) @@ -1369,8 +1398,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), @@ -1406,7 +1435,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, @@ -1417,7 +1446,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' ); } } @@ -1496,17 +1527,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 '' . "\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\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']); @@ -1517,8 +1555,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { $o .= '' . xmlify($item['title']) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; - $o .= '' . base64url_encode($item['body'], true) . '' . "\r\n"; - $o .= '' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '' . "\r\n"; + $o .= '' . base64url_encode($body, true) . '' . "\r\n"; + $o .= '' . xmlify(($type === 'html') ? bbcode($body) : $body) . '' . "\r\n"; $o .= '' . "\r\n"; if($comment) $o .= '' . intval($item['last-child']) . '' . "\r\n"; @@ -1534,6 +1572,10 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) $o .= '1' . "\r\n"; + if($item['extid']) + $o .= '' . $item['extid'] . '' . "\r\n"; + + $verb = construct_verb($item); $o .= '' . xmlify($verb) . '' . "\r\n"; $actobj = construct_activity_object($item); @@ -1563,6 +1605,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; @@ -1590,13 +1664,13 @@ function item_getfeedattach($item) { if(count($arr)) { foreach($arr as $r) { $matches = false; - $cnt = preg_match('|\(.+?)|',$r,$matches); + $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches); if($cnt) { $ret .= '