X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=848c21df366d405d16a00b24eaadbd0b36c58847;hb=5b96c7b3e39a4dd6516115e0fb187cc0ecc0e07d;hp=6ac90bc1c960fd743a271e5848bd0945b955af29;hpb=f7f9529f3bcdb671190b8dee42025dc2c35f171d;p=friendica.git diff --git a/include/items.php b/include/items.php index 6ac90bc1c9..848c21df36 100644 --- a/include/items.php +++ b/include/items.php @@ -9,11 +9,15 @@ require_once('include/tags.php'); require_once('include/files.php'); require_once('include/text.php'); require_once('include/email.php'); -require_once('include/ostatus_conversation.php'); require_once('include/threads.php'); require_once('include/socgraph.php'); +require_once('include/plaintext.php'); +require_once('include/ostatus.php'); require_once('mod/share.php'); +require_once('library/defuse/php-encryption-1.2.1/Crypto.php'); + + function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, $forpubsub = false) { @@ -37,7 +41,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, // default permissions - anonymous user - $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' "; + $sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' "; $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags` FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` @@ -117,9 +121,10 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0, // Include answers to status.net posts in pubsub feeds if($forpubsub) { - $sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` "; - $visibility = sprintf("OR (`item`.`network` = '%s' AND `thread`.`network`='%s')", - dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS)); + $sql_post_table = "INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent` + LEFT JOIN `item` AS `thritem` ON `thritem`.`uri`=`item`.`thr-parent` AND `thritem`.`uid`=`item`.`uid`"; + $visibility = sprintf("AND (`item`.`parent` = `item`.`id`) OR (`item`.`network` = '%s' AND ((`thread`.`network`='%s') OR (`thritem`.`network` = '%s')))", + dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS)); $date_field = "`received`"; $sql_order = "`item`.`received` DESC"; } else { @@ -479,7 +484,6 @@ function get_atom_elements($feed, $item, $contact = array()) { // but for now let's just find any author photo // Additionally we look for an alternate author link. On OStatus this one is the one we want. - // Search for ostatus conversation url $authorlinks = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; if (is_array($authorlinks)) { foreach ($authorlinks as $link) { @@ -884,23 +888,6 @@ function get_atom_elements($feed, $item, $contact = array()) { } } - // Search for ostatus conversation url - $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"]; - - if (is_array($links)) { - foreach ($links as $link) { - $conversation = array_shift($link["attribs"]); - - if ($conversation["rel"] == "ostatus:conversation") { - $res["ostatus_conversation"] = ostatus_convert_href($conversation["href"]); - logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]); - } elseif ($conversation["rel"] == "alternate") { - $res["plink"] = $conversation["href"]; - logger('get_atom_elements: found plink '.$res["plink"]); - } - }; - } - if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) { $preview = ""; @@ -1137,15 +1124,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['plink'] = ostatus_convert_href($arr['uri']); } - // if an OStatus conversation url was passed in, it is stored and then - // removed from the array. - $ostatus_conversation = null; - - if (isset($arr["ostatus_conversation"])) { - $ostatus_conversation = $arr["ostatus_conversation"]; - unset($arr["ostatus_conversation"]); - } - if(x($arr, 'gravity')) $arr['gravity'] = intval($arr['gravity']); elseif($arr['parent-uri'] === $arr['uri']) @@ -1187,6 +1165,21 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } } + // If there is no guid then take the same guid that was taken before for the same plink + if ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "") AND (trim($arr['network']) != "")) { + logger('item_store: checking for an existing guid for plink '.$arr['plink'], LOGGER_DEBUG); + $r = q("SELECT `guid`, `uri` FROM `guid` WHERE `plink` = '%s' AND `network` = '%s' LIMIT 1", + dbesc(trim($arr['plink'])), dbesc(trim($arr['network']))); + + if(count($r)) { + $arr['guid'] = $r[0]["guid"]; + logger('item_store: found guid '.$arr['guid'].' for plink '.$arr['plink'], LOGGER_DEBUG); + + if ($r[0]["uri"] != $arr['uri']) + logger('Different uri for same guid: '.$arr['uri'].' and '.$r[0]["uri"].' - this shouldnt happen!', LOGGER_DEBUG); + } + } + // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) @@ -1385,7 +1378,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['gravity'] = 0; } else { - logger('item_store: item parent was not found - ignoring item'); + logger('item_store: item parent '.$arr['parent-uri'].' for '.$arr['uid'].' was not found - ignoring item'); return 0; } @@ -1523,10 +1516,6 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa intval($current_post) ); - // Complete ostatus threads - if ($ostatus_conversation) - complete_conversation($current_post, $ostatus_conversation); - $arr['id'] = $current_post; $arr['parent'] = $parent_id; $arr['allow_cid'] = $allow_cid; @@ -1997,13 +1986,13 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { if($contact['duplex'] && $contact['issued-id']) $idtosend = '1:' . $orig_id; - $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0); - - $rino_enable = get_config('system','rino_encrypt'); + + $rino = get_config('system','rino_encrypt'); + $rino = intval($rino); - if(! $rino_enable) - $rino = 0; + + $ssl_val = intval(get_config('system','ssl_policy')); $ssl_policy = ''; @@ -2020,7 +2009,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { break; } - $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : ''); + $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino='.$rino : ''); logger('dfrn_deliver: ' . $url); @@ -2051,7 +2040,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { $challenge = hex2bin((string) $res->challenge); $perm = (($res->perm) ? $res->perm : null); $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0); - $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0); + $rino_remote_version = intval($res->rino); $page = (($owner['page-flags'] == PAGE_COMMUNITY) ? 1 : 0); if($owner['page-flags'] == PAGE_PRVGROUP) @@ -2112,11 +2101,46 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { if($page) $postvars['page'] = $page; - if($rino && $rino_allowed && (! $dissolve)) { - $key = substr(random_string(),0,16); - $data = bin2hex(aes_encrypt($postvars['data'],$key)); - $postvars['data'] = $data; - logger('rino: sent key = ' . $key, LOGGER_DEBUG); + + if($rino>0 && $rino_remote_version>0 && (! $dissolve)) { + logger('rino version: '. $rino_remote_version); + + switch($rino_remote_version) { + case 1: + // Deprecated rino version! + $key = substr(random_string(),0,16); + $data = aes_encrypt($postvars['data'],$key); + break; + case 2: + // RINO 2 based on php-encryption + try { + $key = Crypto::createNewRandomKey(); + } catch (CryptoTestFailed $ex) { + logger('Cannot safely create a key'); + return -1; + } catch (CannotPerformOperation $ex) { + logger('Cannot safely create a key'); + return -1; + } + try { + $data = Crypto::encrypt($postvars['data'], $key); + } catch (CryptoTestFailed $ex) { + logger('Cannot safely perform encryption'); + return -1; + } catch (CannotPerformOperation $ex) { + logger('Cannot safely perform encryption'); + return -1; + } + break; + default: + logger("rino: invalid requested verision '$rino_remote_version'"); + return -1; + } + + $postvars['rino'] = $rino_remote_version; + $postvars['data'] = bin2hex($data); + + #logger('rino: sent key = ' . $key, LOGGER_DEBUG); if($dfrn_version >= 2.1) { @@ -2143,6 +2167,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { $postvars['key'] = bin2hex($postvars['key']); } + logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA); @@ -2223,6 +2248,17 @@ function edited_timestamp_is_newer($existing, $update) { */ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) { + if ($contact['network'] === NETWORK_OSTATUS) { + if ($pass < 2) { + // Test - remove before flight + //$tempfile = tempnam(get_temppath(), "ostatus"); + //file_put_contents($tempfile, $xml); + + logger("Consume OStatus messages ", LOGGER_DEBUG); + ostatus_import($xml,$importer,$contact, $hub); + } + return; + } require_once('library/simplepie/simplepie.inc'); require_once('include/contact_selectors.php'); @@ -2232,12 +2268,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) return; } - // Test - remove before flight -// if ($contact['network'] === NETWORK_OSTATUS) { -// $tempfile = tempnam(get_temppath(), "ostatus"); -// file_put_contents($tempfile, $xml); -// } - $feed = new SimplePie(); $feed->set_raw_data($xml); if($datedir) @@ -2947,9 +2977,6 @@ function item_is_remote_self($contact, &$datarray) { $datarray['private'] = 0; } - //if (!isset($datarray["app"]) OR ($datarray["app"] == "")) - // $datarray["app"] = network_to_name($contact['network']); - if ($contact['network'] != NETWORK_FEED) { // Store the original post $r = item_store($datarray2, false, false); @@ -4129,9 +4156,12 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { $name = notags(trim($datarray['author-name'])); $photo = notags(trim($datarray['author-avatar'])); - $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor'); - if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) - $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; + if (is_object($item)) { + $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor'); + if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) + $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; + } else + $nick = $item; if(is_array($contact)) { if(($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING) @@ -4297,10 +4327,48 @@ function atom_author($tag,$name,$uri,$h,$w,$photo) { $o .= "<$tag>\r\n"; - $o .= "$name\r\n"; - $o .= "$uri\r\n"; - $o .= '' . "\r\n"; - $o .= '' . "\r\n"; + $o .= "\t$name\r\n"; + $o .= "\t$uri\r\n"; + $o .= "\t".'' . "\r\n"; + $o .= "\t".'' . "\r\n"; + + if ($tag == "author") { + $r = q("SELECT `profile`.`locality`, `profile`.`region`, `profile`.`country-name`, + `profile`.`name`, `profile`.`pub_keywords`, `profile`.`about`, + `profile`.`homepage`,`contact`.`nick` FROM `profile` + INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` + INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` + WHERE `profile`.`is-default` AND `contact`.`self` AND + NOT `user`.`hidewall` AND `contact`.`nurl`='%s'", + dbesc(normalise_link($uri))); + if ($r) { + $location = ''; + if($r[0]['locality']) + $location .= $r[0]['locality']; + if($r[0]['region']) { + if($location) + $location .= ', '; + $location .= $r[0]['region']; + } + if($r[0]['country-name']) { + if($location) + $location .= ', '; + $location .= $r[0]['country-name']; + } + + $o .= "\t".xmlify($r[0]["nick"])."\r\n"; + $o .= "\t".xmlify($r[0]["name"])."\r\n"; + $o .= "\t".xmlify($r[0]["about"])."\r\n"; + $o .= "\t\r\n"; + $o .= "\t\t".xmlify($location)."\r\n"; + $o .= "\t\r\n"; + $o .= "\t\r\n"; + $o .= "\thomepage\r\n"; + $o .= "\t\t".xmlify($r[0]["homepage"])."\r\n"; + $o .= "\t\ttrue\r\n"; + $o .= "\t\r\n"; + } + } call_hooks('atom_author', $o); @@ -4335,8 +4403,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']); if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { + $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); - $o .= '' . "\r\n"; + $o .= ''."\r\n"; } $htmlbody = $body; @@ -4344,7 +4413,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { if ($item['title'] != "") $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; - $htmlbody = bbcode(bb_remove_share_information($htmlbody), false, false, 7); + $htmlbody = bbcode($htmlbody, false, false, 7); $o .= '' . xmlify($item['uri']) . '' . "\r\n"; $o .= '' . xmlify($item['title']) . '' . "\r\n"; @@ -4352,8 +4421,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n"; $o .= '' . base64url_encode($body, true) . '' . "\r\n"; $o .= '' . xmlify((($type === 'html') ? $htmlbody : $body)) . '' . "\r\n"; - $o .= '' . "\r\n"; + $o .= ''."\r\n"; + $o .= ''."\r\n"; if($comment) $o .= '' . intval($item['last-child']) . '' . "\r\n"; @@ -4396,11 +4466,19 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) { $tags = item_getfeedtags($item); if(count($tags)) { - foreach($tags as $t) { - $o .= '' . "\r\n"; - } + foreach($tags as $t) + if (($type != 'html') OR ($t[0] != "@")) + $o .= '' . "\r\n"; } + // To-Do: + // To support these elements, the API needs to be enhanced + //$o .= ''."\r\n"; + //$o .= "\t".''."\r\n"; + //$o .= "\t".''."\r\n"; + + $o .= item_get_attachment($item); + $o .= item_getfeedattach($item); $mentioned = get_mentions($item); @@ -4578,6 +4656,28 @@ function item_getfeedtags($item) { return $ret; } +function item_get_attachment($item) { + $o = ""; + $siteinfo = get_attached_data($item["body"]); + + switch($siteinfo["type"]) { + case 'link': + $o = ''."\r\n"; + break; + case 'photo': + $imgdata = get_photo_info($siteinfo["image"]); + $o = ''."\r\n"; + break; + case 'video': + $o = ''."\r\n"; + break; + default: + break; + } + + return $o; +} + function item_getfeedattach($item) { $ret = ''; $arr = explode('[/attach],',$item['attach']); @@ -4951,7 +5051,7 @@ function list_post_dates($uid, $wall) { return array(); // Set the start and end date to the beginning of the month - $dnow = substr($dnow,0,8).'01'; + $dnow = substr($dnow,0,8).'01'; $dthen = substr($dthen,0,8).'01'; $ret = array(); @@ -4967,7 +5067,7 @@ function list_post_dates($uid, $wall) { $str = day_translate(datetime_convert('','',$dnow,'F')); if(! $ret[$dyear]) $ret[$dyear] = array(); - $ret[$dyear][] = array($str,$end_month,$start_month); + $ret[$dyear][] = array($str,$end_month,$start_month); $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); } return $ret; @@ -5015,12 +5115,12 @@ function posted_date_widget($url,$uid,$wall) { if(! $visible_years) $visible_years = 5; - $ret = list_post_dates($uid,$wall); + $ret = list_post_dates($uid,$wall); if(! count($ret)) return $o; - $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; + $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; $cutoff = ((array_key_exists($cutoff_year,$ret))? true : false); $o = replace_macros(get_markup_template('posted_date_widget.tpl'),array( @@ -5030,7 +5130,7 @@ function posted_date_widget($url,$uid,$wall) { '$cutoff' => $cutoff, '$url' => $url, '$dates' => $ret, - '$showmore' => t('show more') + '$showmore' => t('show more') )); return $o;