From b8c77bbcfcc5f1f25ff61ac5fc9f284148955221 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 16:06:25 -0700 Subject: use parent_mid --- include/feedutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 02decca69..5e5056f7c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1021,13 +1021,13 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { } } else { - $x = q("select mid from item where mid = '%s' and uid = %d limit 1", + $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) ); if($x) { - $pmid = $x[0]['mid']; + $pmid = $x[0]['parent_mid']; $datarray['parent_mid'] = $pmid; } } -- cgit v1.2.3 From 0d7e7ac657ce4d1e7d2797b565882d3a57dfd8de Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 19:59:25 -0700 Subject: always transmit a valid uri --- include/feedutils.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5e5056f7c..2f3927748 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1505,6 +1505,10 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ if(($item['parent'] != $item['id']) || ($item['parent_mid'] !== $item['mid']) || (($item['thr_parent'] !== '') && ($item['thr_parent'] !== $item['mid']))) { $parent_item = (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']); + // ensure it's a legal uri and not just a message-id + if(! strpos($parent_item,':')) + $parent_item = 'X-ZOT:' . $parent_item; + $o .= '' . "\r\n"; } -- cgit v1.2.3 From bb9557a9ae9bbec806ef6e91c25120df0da8a72e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Jun 2017 20:20:18 -0700 Subject: remove some duplicated code --- include/feedutils.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 2f3927748..0d7e1d6c2 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -259,7 +259,7 @@ function get_atom_elements($feed, $item, &$author) { if(substr($author['author_link'],-1,1) == '/') $author['author_link'] = substr($author['author_link'],0,-1); - $res['mid'] = unxmlify($item->get_id()); + $res['mid'] = normalise_id(unxmlify($item->get_id())); $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); @@ -390,7 +390,7 @@ function get_atom_elements($feed, $item, &$author) { $rawcnv = $item->get_item_tags(NAMESPACE_OSTATUS, 'conversation'); if($rawcnv) { - $ostatus_conversation = unxmlify($rawcnv[0]['attribs']['']['ref']); + $ostatus_conversation = normalise_id(unxmlify($rawcnv[0]['attribs']['']['ref'])); set_iconfig($res,'ostatus','conversation',$ostatus_conversation,true); } @@ -938,7 +938,6 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { foreach($items as $item) { $is_reply = false; - $item_id = normalise_id($item->get_id()); logger('processing ' . $item->get_id(), LOGGER_DEBUG); @@ -955,12 +954,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -987,7 +985,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['owner_xchan'] = $contact['xchan_hash']; $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1010,6 +1008,9 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $pmid = ''; $conv_id = get_iconfig($datarray,'ostatus','conversation'); + // match conversations - first try ostatus:conversation + // next try thr:in_reply_to + if($conv_id) { $c = q("select parent_mid from item left join iconfig on item.id = iconfig.iid where iconfig.cat = 'ostatus' and iconfig.k = 'conversation' and iconfig.v = '%s' and item.uid = %d order by item.id limit 1", dbesc($conv_id), @@ -1020,7 +1021,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['parent_mid'] = $pmid; } } - else { + if(! $pmid) { $x = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($importer['channel_id']) @@ -1056,12 +1057,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { // Head post of a conversation. Have we seen it? If not, import it. - $item_id = normalise_id($item->get_id()); $author = array(); $datarray = get_atom_elements($feed,$item,$author); - if($datarray['mid']) - $datarray['mid'] = normalise_id($item->get_id()); + if(! $datarray['mid']) + continue; if($contact['xchan_network'] === 'rss') { $datarray['public_policy'] = 'specific'; @@ -1116,7 +1116,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", - dbesc($item_id), + dbesc($datarray['mid']), intval($importer['channel_id']) ); @@ -1136,7 +1136,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { continue; } - $datarray['parent_mid'] = $item_id; + $datarray['parent_mid'] = $datarray['mid']; $datarray['uid'] = $importer['channel_id']; $datarray['aid'] = $importer['channel_account_id']; -- cgit v1.2.3 From f25e0c3829abd4a89956773b965e45d0e9db18cc Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 16 Jun 2017 19:30:02 -0700 Subject: testing mastodon boosts/reshares --- include/feedutils.php | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 0d7e1d6c2..158ecb7a3 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -354,6 +354,7 @@ function get_atom_elements($feed, $item, &$author) { // No photo/profile-link on the item - look at the feed level + if((! (x($author,'author_link'))) || (! (x($author,'author_photo')))) { $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author'); if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { @@ -602,6 +603,10 @@ function get_atom_elements($feed, $item, &$author) { if(! $type) $type = 'application/octet-stream'; + if(($ostatus_protocol) && (strpos($type,'image') === 0) && (strpos($res['body'],$link) === false) && (strpos($link,'http') === 0)) { + $res['body'] .= "\n\n" . '[img]' . $link . '[/img]'; + } + $res['attach'][] = array('href' => $link, 'length' => $len, 'type' => $type, 'title' => $title ); } } @@ -683,7 +688,10 @@ function get_atom_elements($feed, $item, &$author) { $res['target'] = $obj; } - if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE) { + + + if(array_key_exists('verb',$res) && $res['verb'] === ACTIVITY_SHARE + && array_key_exists('obj_type',$res) && $res['obj_type'] === ACTIVITY_OBJ_NOTE) { feed_get_reshare($res,$item); } @@ -713,14 +721,14 @@ function feed_get_reshare(&$res,$item) { if($rawobj) { - $rawauthor = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); + $rawauthor = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['author']; if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']) { - $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name']); + $share['author'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']) { - $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri']); + $share['profile'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']); } if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) { @@ -744,9 +752,10 @@ function feed_get_reshare(&$res,$item) { if(x($child[SIMPLEPIE_NAMESPACE_ATOM_10], 'link') && $child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']) - $share['link'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + $share['links'] = encode_rel_links($child[SIMPLEPIE_NAMESPACE_ATOM_10]['link']); + + $rawcreated = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['published']; - $rawcreated = $rawobj->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'); if($rawcreated) $share['created'] = unxmlify($rawcreated[0]['data']); else @@ -766,13 +775,19 @@ function feed_get_reshare(&$res,$item) { } } - $attach = $rawobj->get_enclosures(); + $attach = $share['links']; if($attach) { foreach($attach as $att) { - $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($att['rel'] === 'alternate') { + $share['alternate'] = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + continue; + } + if($att['rel'] !== 'enclosure') + continue; + $len = intval($att['length']); + $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['href'])))); + $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['title'])))); + $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att['type'])))); if(strpos($type,';')) $type = substr($type,0,strpos($type,';')); if((! $link) || (strpos($link,'http') !== 0)) @@ -792,11 +807,12 @@ function feed_get_reshare(&$res,$item) { $res['body'] = "[share author='" . urlencode($share['author']) . "' profile='" . $share['profile'] . "' avatar='" . $share['avatar'] . - "' link='" . $share['link'] . + "' link='" . $share['alternate'] . "' posted='" . $share['created'] . "' message_id='" . $share['message_id'] . "']"; - $o .= $body; - $o .= "[/share]"; + + $res['body'] .= $body; + $res['body'] .= "[/share]"; } } @@ -818,6 +834,10 @@ function encode_rel_links($links) { $l = array(); if($link['attribs']['']['rel']) $l['rel'] = $link['attribs']['']['rel']; + if($link['attribs']['']['length']) + $l['length'] = $link['attribs']['']['length']; + if($link['attribs']['']['title']) + $l['title'] = $link['attribs']['']['title']; if($link['attribs']['']['type']) $l['type'] = $link['attribs']['']['type']; if($link['attribs']['']['href']) @@ -1724,3 +1744,4 @@ function asencode_person($p) { return $ret; } + -- cgit v1.2.3 From 1472f85b162ea6f1ab9e19e94b86fc4a8ef074be Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:25:41 -0700 Subject: allow moderated comments like wordpress if permissions are compatible --- include/channel.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ include/conversation.php | 22 ++++++++++------ include/items.php | 2 +- 3 files changed, 82 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 2284b3004..50cc90178 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2323,3 +2323,70 @@ function channel_codeallowed($channel_id) { return false; } + +function anon_identity_init($reqvars) { + + $x = [ 'request_vars' => $reqvars, 'xchan' => null, 'success' => 'unset' ]; + call_hooks('anon_identity_init',$x); + if($x['success'] !== 'unset' && intval($x['success']) && $x['xchan']) + return $x['xchan']; + + // allow a captcha handler to over-ride + if($x['success'] !== 'unset' && (intval($x['success']) === 0)) + return false; + + + $anon_name = strip_tags(trim($reqvars['anonname'])); + $anon_email = strip_tags(trim($reqvars['anonmail'])); + $anon_url = strip_tags(trim($reqvars['anonurl'])); + + if(! ($anon_name && $anon_email)) { + logger('anonymous commenter did not complete form'); + return false; + } + + if(! validate_email($anon_email)) { + logger('enonymous email not valid'); + return false; + } + + if(! $anon_url) + $anon_url = z_root(); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + if(! $x) { + xchan_store_lowlevel([ + 'xchan_guid' => $anon_email, + 'xchan_hash' => $anon_email, + 'xchan_name' => $anon_name, + 'xchan_url' => $anon_url, + 'xchan_network' => 'unknown', + 'xchan_name_date' => datetime_convert() + ]); + + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", + dbesc($anon_email), + dbesc($anon_email) + ); + + $photo = z_root() . '/' . get_default_profile_photo(300); + $photos = import_xchan_photo($photo,$anon_email); + $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($anon_email), + dbesc($anon_email) + ); + + } + + return $x[0]; + +} diff --git a/include/conversation.php b/include/conversation.php index 3f9ee5cfa..2eac2adde 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -533,6 +533,10 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $live_update_div = '' . "\r\n"; } + elseif ($mode === 'moderate') { + $profile_owner = local_channel(); + } + elseif ($mode === 'photos') { $profile_onwer = App::$profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); @@ -577,7 +581,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($items) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if(in_array($mode, [ 'network-new', 'search', 'community', 'moderate' ])) { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -609,14 +613,14 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; - $nickname = $item['nickname']; +// $nickname = $item['nickname']; } - else - $nickname = App::$user['nickname']; +// else +// $nickname = App::$user['nickname']; - $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) - $profile_name = $item['author-link']; +// $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); +// if($item['author-link'] && (! $item['author-name'])) +// $profile_name = $item['author-link']; $sp = false; $profile_link = best_link_url($item,$sp); @@ -625,7 +629,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ else $profile_link = zid($profile_link); - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); +// $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); $profile_name = $item['author']['xchan_name']; $profile_link = $item['author']['xchan_url']; @@ -679,6 +683,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ 'template' => $tpl, 'toplevel' => 'toplevel_item', 'mode' => $mode, + 'approve' => t('Approve'), + 'delete' => t('Delete'), 'id' => (($preview) ? 'P0' : $item['item_id']), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, $profile_url), 'profile_url' => $profile_link, diff --git a/include/items.php b/include/items.php index fa61d71de..4a028be6e 100755 --- a/include/items.php +++ b/include/items.php @@ -938,7 +938,7 @@ function import_author_unknown($x) { $photos = import_xchan_photo($x['photo']['src'],$x['url']); if($photos) { - $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_url = '%s' and xchan_network = 'unknown'", + $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' and xchan_network = 'unknown'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), -- cgit v1.2.3 From 3b5e1c05b78f72a31eda76b0ff90d08b58ee452d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 18 Jun 2017 22:51:52 -0700 Subject: minor cleanup of moderated comment feature --- include/channel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index 50cc90178..e283ed940 100644 --- a/include/channel.php +++ b/include/channel.php @@ -2353,28 +2353,31 @@ function anon_identity_init($reqvars) { if(! $anon_url) $anon_url = z_root(); + $hash = hash('md5',$anon_email); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); if(! $x) { xchan_store_lowlevel([ 'xchan_guid' => $anon_email, - 'xchan_hash' => $anon_email, + 'xchan_hash' => $hash, 'xchan_name' => $anon_name, 'xchan_url' => $anon_url, 'xchan_network' => 'unknown', 'xchan_name_date' => datetime_convert() ]); + $x = q("select * from xchan where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' limit 1", dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); $photo = z_root() . '/' . get_default_profile_photo(300); - $photos = import_xchan_photo($photo,$anon_email); + $photos = import_xchan_photo($photo,$hash); $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'unknown' ", dbesc(datetime_convert()), dbesc($photos[0]), @@ -2382,7 +2385,7 @@ function anon_identity_init($reqvars) { dbesc($photos[2]), dbesc($photos[3]), dbesc($anon_email), - dbesc($anon_email) + dbesc($hash) ); } -- cgit v1.2.3