From 48b2eafcaaaa8cc05947c4b4b64c3e9daa78c2f4 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Mon, 20 Oct 2014 19:31:47 +0100 Subject: Prevent more than one instance of the poller running at a time. --- include/poller.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/poller.php b/include/poller.php index 61298b0ab..61d8b87cc 100644 --- a/include/poller.php +++ b/include/poller.php @@ -25,6 +25,15 @@ function poller_run($argv, $argc){ if(! $interval) $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval'))); + // Check for a logfile. If it exists, but is over an hour old, it's stale. Ignore it. + $lockfile = 'store/[data]/poller'; + if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))) { + logger("poller: Already running"); + return; + } + + // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. + file_put_contents($lockfile, $x); logger('poller: start'); @@ -254,7 +263,7 @@ function poller_run($argv, $argc){ ); - $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_xchan, abook_channel + $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_channel FROM abook LEFT JOIN account on abook_account = account_id where 1 $sql_extra AND (( abook_flags & %d ) OR ( abook_flags = %d )) @@ -310,17 +319,12 @@ function poller_run($argv, $argc){ // He's dead, Jim if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) { - $n = q("select xchan_network from xchan where xchan_hash = '%s' limit 1", - dbesc($contact['abook_xchan']) + $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1", + intval(ABOOK_FLAG_ARCHIVED), + intval($contact['abook_id']) ); - if($n && $n[0]['xchan_network'] == 'zot') { - $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1", - intval(ABOOK_FLAG_ARCHIVED), - intval($contact['abook_id']) - ); - $update = false; - continue; - } + $update = false; + continue; } if($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) { @@ -375,7 +379,10 @@ function poller_run($argv, $argc){ } } } - + + //All done - clear the lockfile + @unlink($lockfile); + return; } -- cgit v1.2.3 From 58431f948eb5e1d23548b537fdb92dea7d79e196 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Mon, 20 Oct 2014 19:35:02 +0100 Subject: Screwed up merge - put Mike's stuff back. --- include/poller.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/poller.php b/include/poller.php index 61d8b87cc..d18cb1ca6 100644 --- a/include/poller.php +++ b/include/poller.php @@ -263,7 +263,7 @@ function poller_run($argv, $argc){ ); - $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_channel + $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_xchan, abook_channel FROM abook LEFT JOIN account on abook_account = account_id where 1 $sql_extra AND (( abook_flags & %d ) OR ( abook_flags = %d )) @@ -319,12 +319,17 @@ function poller_run($argv, $argc){ // He's dead, Jim if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) { - $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1", - intval(ABOOK_FLAG_ARCHIVED), - intval($contact['abook_id']) + $n = q("select xchan_network from xchan where xchan_hash = '%s' limit 1", + dbesc($contact['abook_xchan']) ); - $update = false; - continue; + if($n && $n[0]['xchan_network'] == 'zot') { + $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1", + intval(ABOOK_FLAG_ARCHIVED), + intval($contact['abook_id']) + ); + $update = false; + continue; + } } if($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) { -- cgit v1.2.3 From cb15c73dae51c7001fa7277ef4d324645f72c5c3 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 20 Oct 2014 16:47:58 -0700 Subject: move all theme initialisation to one place - just after calling module_init. Revert if there are serious issues, but please note the issues in as much detail as possible so we can work through them. --- include/RedDAV/RedBrowser.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/RedDAV/RedBrowser.php b/include/RedDAV/RedBrowser.php index 6ec5c978d..21ea76aed 100644 --- a/include/RedDAV/RedBrowser.php +++ b/include/RedDAV/RedBrowser.php @@ -259,6 +259,7 @@ class RedBrowser extends DAV\Browser\Plugin { $html .= $output; get_app()->page['content'] = $html; + load_pdl(get_app()); construct_page(get_app()); } -- cgit v1.2.3 From 577d84b883b52dde84c18c659a8c4674abe4e94e Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 20 Oct 2014 19:06:02 -0700 Subject: bb2diaspora wallwall comment - match both bits (ITEM_WALL|ITEM_ORIGIN) --- include/bb2diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 9a87de5b2..665fd4622 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -290,7 +290,7 @@ function bb2diaspora_itemwallwall(&$item) { // We have to do something similar for wall-to-wall comments. ITEM_WALL|ITEM_ORIGIN indicates that it was posted on this site. // Regular matrix comments may have one of these bits set, but not both. - if(($item['mid'] != $item['parent_mid']) && ($item['author_xchan'] != $item['owner_xchan']) && ($item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_m']) { + if(($item['mid'] != $item['parent_mid']) && ($item['author_xchan'] != $item['owner_xchan']) && (($item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_m']) { logger('bb2diaspora_itemwallwall: wall to wall comment',LOGGER_DEBUG); // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. $item['body'] = "\n\n" -- cgit v1.2.3 From e8a7fb3d015b36af31312daf50739cf73f0f4368 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 20 Oct 2014 21:15:29 -0700 Subject: strip out the Diaspora quoted reshare markers --- include/bb2diaspora.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 665fd4622..5663ce9ef 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -116,6 +116,8 @@ function diaspora_mention_callback($matches) { function diaspora2bb($s,$use_zrl = false) { + $s = str_replace(" \n>","",$s); + $s = html_entity_decode($s,ENT_COMPAT,'UTF-8'); // Too many new lines. So deactivated the following line -- cgit v1.2.3 From 1fb2de6d55779c853e25d38f5b93133a5414d72a Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Tue, 21 Oct 2014 17:27:13 +0100 Subject: Typo --- include/poller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/poller.php b/include/poller.php index d18cb1ca6..f11618d37 100644 --- a/include/poller.php +++ b/include/poller.php @@ -25,7 +25,7 @@ function poller_run($argv, $argc){ if(! $interval) $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval'))); - // Check for a logfile. If it exists, but is over an hour old, it's stale. Ignore it. + // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))) { logger("poller: Already running"); -- cgit v1.2.3 From ed7712cfbf9835368de79f8686954b536c12e4d1 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 21 Oct 2014 16:33:35 -0700 Subject: private forum issues --- include/identity.php | 3 ++- include/items.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/identity.php b/include/identity.php index 07bfaebbd..8866b4811 100644 --- a/include/identity.php +++ b/include/identity.php @@ -389,7 +389,8 @@ function create_identity($arr) { dbesc( t('Friends') ) ); if($r) { - q("update channel set channel_allow_gid = '%s' where channel_id = %d limit 1", + q("update channel set channel_default_group = '%s', channel_allow_gid = '%s' where channel_id = %d limit 1", + dbesc($r[0]['hash']), dbesc('<' . $r[0]['hash'] . '>'), intval($newuid) ); diff --git a/include/items.php b/include/items.php index 40343d505..75eaecb20 100755 --- a/include/items.php +++ b/include/items.php @@ -98,6 +98,7 @@ function collect_recipients($item,&$private_envelope) { } } + // This is a somewhat expensive operation but important. // Don't send this item to anybody who isn't allowed to see it -- cgit v1.2.3 From d5edd89dd2bcfae198bb316c4f9be212937e9fa5 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 21 Oct 2014 17:04:52 -0700 Subject: when removing a channel, check to see if there are any valid hublocs remaining before marking the xchan deleted. Issue #657 --- include/Contact.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 4440369dc..20e5e1a1e 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -245,11 +245,13 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { intval($channel_id) ); + $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", intval(HUBLOC_FLAGS_DELETED), dbesc($channel['channel_hash']) ); + $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", intval(XCHAN_FLAGS_DELETED), dbesc($channel['channel_hash']) @@ -257,7 +259,6 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { proc_run('php','include/notifier.php','purge_all',$channel_id); - } q("DELETE FROM `groups` WHERE `uid` = %d", intval($channel_id)); @@ -291,11 +292,23 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { dbesc(z_root()) ); - $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' ", - intval(XCHAN_FLAGS_DELETED), - dbesc($channel['channel_hash']) + // Do we have any valid hublocs remaining? + + $hublocs = 0; + + $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d)", + dbesc($channel['channel_hash']), + intval(HUBLOC_FLAGS_DELETED) ); + if($r) + $hublocs = count($r); + if(! $hublocs) { + $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' ", + intval(XCHAN_FLAGS_DELETED), + dbesc($channel['channel_hash']) + ); + } proc_run('php','include/directory.php',$channel_id); -- cgit v1.2.3 From d7cb5c0436081214afefbd876a127173ebfa1b74 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 22 Oct 2014 16:41:06 -0700 Subject: you've gotta' be on your toes to catch this bug... though it's been here for about 2 1/2 years and even survived a rewrite. Symptoms are that the archive widget only lists one month (the month when you first posted), and only if your first post was written between the 28th and 31st of whatever month that was. --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 75eaecb20..a0c81f5ae 100755 --- a/include/items.php +++ b/include/items.php @@ -4131,7 +4131,7 @@ function list_post_dates($uid,$wall) { if(intval(substr($dnow,8)) > 28) $dnow = substr($dnow,0,8) . '28'; if(intval(substr($dthen,8)) > 28) - $dnow = substr($dthen,0,8) . '28'; + $dthen = substr($dthen,0,8) . '28'; $ret = array(); // Starting with the current month, get the first and last days of every @@ -4165,7 +4165,7 @@ function posted_dates($uid,$wall) { if(intval(substr($dnow,8)) > 28) $dnow = substr($dnow,0,8) . '28'; if(intval(substr($dthen,8)) > 28) - $dnow = substr($dthen,0,8) . '28'; + $dthen = substr($dthen,0,8) . '28'; $ret = array(); // Starting with the current month, get the first and last days of every -- cgit v1.2.3 From 902b5c52e5ca9359522f33bbecaf7f2f3c1ba90d Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 22 Oct 2014 18:14:21 -0700 Subject: backtrack on attribution for wall-to-wall comments - triggered too often and unnecessarily. --- include/bb2diaspora.php | 18 +++++++++++------- include/reddav.php | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 5663ce9ef..4f37e5aa8 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -292,14 +292,18 @@ function bb2diaspora_itemwallwall(&$item) { // We have to do something similar for wall-to-wall comments. ITEM_WALL|ITEM_ORIGIN indicates that it was posted on this site. // Regular matrix comments may have one of these bits set, but not both. - if(($item['mid'] != $item['parent_mid']) && ($item['author_xchan'] != $item['owner_xchan']) && (($item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_m']) { - logger('bb2diaspora_itemwallwall: wall to wall comment',LOGGER_DEBUG); + // Update: this is getting triggered way too often and unnecessarily. Commenting out until we find a better solution. + // It's not an easy problem. For now we'll live with the mis-attributions, as wall to wall comments are much less frequent + // than wall-to-wall posts. + +// if(($item['mid'] != $item['parent_mid']) && ($item['author_xchan'] != $item['owner_xchan']) && (($item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_m']) { +// logger('bb2diaspora_itemwallwall: wall to wall comment',LOGGER_DEBUG); // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. - $item['body'] = "\n\n" - . '[img]' . $item['author']['xchan_photo_m'] . '[/img]' - . '[url=' . $item['author']['xchan_url'] . ']' . $item['author']['xchan_name'] . '[/url]' . "\n\n" - . $item['body']; - } +// $item['body'] = "\n\n" +// . '[img]' . $item['author']['xchan_photo_m'] . '[/img]' +// . '[url=' . $item['author']['xchan_url'] . ']' . $item['author']['xchan_name'] . '[/url]' . "\n\n" +// . $item['body']; +// } // $item['author'] might cause a surprise further down the line if it wasn't expected to be here. diff --git a/include/reddav.php b/include/reddav.php index 86b3a00e4..c16e08e27 100644 --- a/include/reddav.php +++ b/include/reddav.php @@ -50,7 +50,7 @@ function RedChannelList(&$auth) { if ($r) { foreach ($r as $rr) { if (perm_is_allowed($rr['channel_id'], $auth->observer, 'view_storage')) { - logger('found channel: /cloud/' . $rr['channel_address'], LOGGER_DEBUG); + logger('found channel: /cloud/' . $rr['channel_address'], LOGGER_DATA); // @todo can't we drop '/cloud'? It gets stripped off anyway in RedDirectory $ret[] = new RedDAV\RedDirectory('/cloud/' . $rr['channel_address'], $auth); } @@ -188,7 +188,7 @@ function RedCollectionData($file, &$auth) { * @throw \Sabre\DAV\Exception\Forbidden */ function RedFileData($file, &$auth, $test = false) { - logger($file . (($test) ? ' (test mode) ' : ''), LOGGER_DEBUG); + logger($file . (($test) ? ' (test mode) ' : ''), LOGGER_DATA); $x = strpos($file, '/cloud'); if ($x === 0) { -- cgit v1.2.3 From 58c692e3897a7807fed23e2633496c4960f022ca Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 22 Oct 2014 20:39:49 -0700 Subject: improved wall-to-wall detection for comments so we can handle Diaspora signing and wall-to-wall attribution correctly. Do it at the point of submission. This also fixes a potential bug in yesterday's wall-to-wall permission setting, if it was a local comment to a remote post. --- include/items.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index a0c81f5ae..e3526b0a5 100755 --- a/include/items.php +++ b/include/items.php @@ -2517,7 +2517,7 @@ function item_store_update($arr,$allow_exec = false) { return $ret; } -function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id) { +function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, $walltowall = false) { // We won't be able to sign Diaspora comments for authenticated visitors // - we don't have their private key @@ -2527,7 +2527,16 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id) require_once('include/bb2diaspora.php'); $signed_body = bb2diaspora_itembody($datarray); - logger('mod_item: storing diaspora comment signature',LOGGER_DEBUG); + if($walltowall) { + logger('wall to wall comment',LOGGER_DEBUG); + // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. + $signed_body = "\n\n" + . '[img]' . $datarray['author']['xchan_photo_m'] . '[/img]' + . '[url=' . $datarray['author']['xchan_url'] . ']' . $datarray['author']['xchan_name'] . '[/url]' . "\n\n" + . $signed_body; + } + + logger('storing diaspora comment signature',LOGGER_DEBUG); $diaspora_handle = $channel['channel_address'] . '@' . get_app()->get_hostname(); -- cgit v1.2.3 From 0ebfee8f87f73111b4de659ee5c97c12ad04b356 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Oct 2014 01:36:01 -0700 Subject: wrong permalink on remote events --- include/event.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/event.php b/include/event.php index 1fe6e6f7f..03ecaa0a7 100644 --- a/include/event.php +++ b/include/event.php @@ -400,8 +400,7 @@ function event_store_item($arr,$event) { } else { - $z = q("select * from channel where channel_hash = '%s' and channel_id = %d limit 1", - dbesc($event['event_xchan']), + $z = q("select * from channel where channel_id = %d limit 1", intval($arr['uid']) ); @@ -413,7 +412,7 @@ function event_store_item($arr,$event) { $item_arr['id'] = $item['id']; } else { - $wall = (($z) ? true : false); + $wall = (($z[0]['channel_hash'] == $event['event_xchan']) ? true : false); $item_flags = ITEM_THREAD_TOP; if($wall) { @@ -455,7 +454,14 @@ function event_store_item($arr,$event) { $item_arr['body'] = $prefix . format_event_bbcode($arr); - $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . $item_arr['mid']; + // if it's local send the permalink to the channel page. + // otherwise we'll fallback to /display/$message_id + + if($wall) + $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . $item_arr['mid']; + else + $item_arr['plink'] = z_root() . '/display/' . $item_arr['mid']; + $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($arr['event_xchan']) -- cgit v1.2.3 From f29c5a35f14f2a49b7c4a56fed577ebcf1010709 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Thu, 23 Oct 2014 21:50:53 +0100 Subject: Provide comment box for PERMS_AUTHED items. Presently only commentable from owners wall. --- include/items.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index e3526b0a5..2805b9b21 100755 --- a/include/items.php +++ b/include/items.php @@ -214,6 +214,7 @@ function can_comment_on_post($observer_xchan,$item) { break; case 'any connections': case 'contacts': + case 'authenticated': case '': if(array_key_exists('owner',$item)) { if(($item['owner']['abook_xchan']) && ($item['owner']['abook_their_perms'] & PERMS_W_COMMENT)) -- cgit v1.2.3 From 1c4bbbd13e35e164c7da96674b3678bb1011b817 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Oct 2014 16:08:29 -0700 Subject: diaspora walltowall comment signature, force update. --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 2805b9b21..8d46f64c1 100755 --- a/include/items.php +++ b/include/items.php @@ -2526,7 +2526,7 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, // since Diaspora doesn't handle edits we can only do this for the original text and not update it. require_once('include/bb2diaspora.php'); - $signed_body = bb2diaspora_itembody($datarray); + $signed_body = bb2diaspora_itembody($datarray,$walltowall); if($walltowall) { logger('wall to wall comment',LOGGER_DEBUG); -- cgit v1.2.3 From 241bb3b94059ac4edfcc3b66e907dbf493dd8b4a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Oct 2014 19:33:47 -0700 Subject: API: xchan get/create --- include/api.php | 12 ++++++++ include/hubloc.php | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/api.php b/include/api.php index 8b52253dd..9fe2ef47d 100644 --- a/include/api.php +++ b/include/api.php @@ -621,7 +621,19 @@ require_once('include/items.php'); api_register_func('api/red/group','api_group', true); + function api_red_xchan(&$a,$type) { + if(api_user() === false) + return false; + require_once('include/hubloc.php'); + if($_SERVER['request_method'] === 'POST') { + $r = xchan_store($_REQUEST); + } + $r = xchan_fetch($_REQUEST); + json_return_and_die($r); + }; + api_register_func('api/red/xchan','api_red_xchan',true); + function api_statuses_mediap(&$a, $type) { if (api_user() === false) { diff --git a/include/hubloc.php b/include/hubloc.php index 04c29315a..df817329f 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -170,4 +170,82 @@ function hubloc_change_primary($hubloc) { return true; } - \ No newline at end of file + + +function xchan_store($arr) { + + if(! $arr['hash']) + $arr['hash'] = $arr['guid']; + if(! $arr['hash']) + return false; + + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($arr['hash']) + ); + if($r) + return true; + + if(! $arr['network']) + $arr['network'] = 'unknown'; + if(! $arr['name']) + $arr['name'] = 'unknown'; + if(! $arr['url']) + $arr['url'] = z_root(); + if(! $arr['photo']) + $arr['photo'] = get_default_profile_photo(); + + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_instance_url, xchan_flags, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s','%s',%d,'%s') ", + dbesc($arr['hash']), + dbesc($arr['guid']), + dbesc($arr['guid_sig']), + dbesc($arr['pubkey']), + dbesc($arr['address']), + dbesc($arr['url']), + dbesc($arr['connurl']), + dbesc($arr['follow']), + dbesc($arr['connpage']), + dbesc($arr['name']), + dbesc($arr['network']), + dbesc($arr['instance_url']), + intval($arr['flags']), + dbesc(datetime_convert()) + ); + if(! $r) + return $r; + + $photos = import_profile_photo($arr['photo'],$arr['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_hash = '%s' limit 1", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($arr['hash']) + ); + return $r; + +} + + +function xchan_fetch($arr) { + + $key = ''; + if($arr['hash']) { + $key = 'xchan_hash'; + $v = $arr['hash']; + } + elseif($arr['guid']) { + $key = 'xchan_guid'; + $v = $arr['guid']; + } + elseif($arr['address']) { + $key = 'xchan_addr'; + $v = $arr['address']; + } + + if(! $key) + return false; + + $r = q("select * from xchan where $key = '$v'"); + return $r; +} \ No newline at end of file -- cgit v1.2.3 From f524fb1f20ec3edb0cf2c486d41f6bb65a60db6a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Oct 2014 19:41:42 -0700 Subject: generalise the output format of xchan_fetch so it matches the input format --- include/hubloc.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/hubloc.php b/include/hubloc.php index df817329f..0a1b51331 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -247,5 +247,15 @@ function xchan_fetch($arr) { return false; $r = q("select * from xchan where $key = '$v'"); - return $r; + if(! $r) + return false; + + $ret = array(); + foreach($r as $k => $v) { + if($k === 'xchan_addr') + $ret['address'] = $v; + else + $ret[str_replace('xchan_','',$k)] = $v; + } + return $ret; } \ No newline at end of file -- cgit v1.2.3 From 34781433c1fabd7a4992497da5ee475db0ada3a8 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 23 Oct 2014 21:20:12 -0700 Subject: I'm speechless. This is just reckless. Set a context flag in text using a context trigger character which is likely to be present in that text already. Without escaping any previous instances of that character. Grrr. --- include/html2bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 6d6e6333b..9ffc85a82 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -16,7 +16,7 @@ function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb) function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) { - $savestart = str_replace('$', '%', $startbb); + $savestart = str_replace('$', '\x01', $startbb); $replace = false; $xpath = new DomXPath($doc); @@ -37,7 +37,7 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb) foreach ($attributes as $attribute => $value) { - $startbb = str_replace('%'.++$i, '$1', $startbb); + $startbb = str_replace('\x01'.++$i, '$1', $startbb); if (strpos('*'.$startbb, '$1') > 0) { -- cgit v1.2.3 From 1845ddc4c3d3f729dde3905f0f87741ac3d3bf66 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 24 Oct 2014 04:17:48 -0700 Subject: don't decrypt the message body more than once. --- include/bb2diaspora.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 4f37e5aa8..d094e33c2 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -340,8 +340,13 @@ function bb2diaspora_itembody($item,$force_update = false) { if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { $key = get_config('system','prvkey'); - $newitem['title'] = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); - $newitem['body'] = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); + $b = json_decode($item['title'],true); + // if called from diaspora_process_outbound, this decoding has already been done. + // Everything else that calls us will not yet be decoded. + if($b && is_array($b) && array_key_exists('iv',$b)) { + $newitem['title'] = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); + $newitem['body'] = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); + } } bb2diaspora_itemwallwall($newitem); -- cgit v1.2.3 From cf05266b15e49020c217107fd81896171d5ef26b Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 24 Oct 2014 14:04:32 -0700 Subject: should probably check the body since the title is only going to be rarely set. --- include/bb2diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index d094e33c2..8a178d1ac 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -340,7 +340,7 @@ function bb2diaspora_itembody($item,$force_update = false) { if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { $key = get_config('system','prvkey'); - $b = json_decode($item['title'],true); + $b = json_decode($item['body'],true); // if called from diaspora_process_outbound, this decoding has already been done. // Everything else that calls us will not yet be decoded. if($b && is_array($b) && array_key_exists('iv',$b)) { -- cgit v1.2.3 From ce8a891682a7d8ceca71ec762063367744428a53 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 24 Oct 2014 14:18:02 -0700 Subject: doh - this needs to be markdown, not bbcode --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 8d46f64c1..41c211953 100755 --- a/include/items.php +++ b/include/items.php @@ -2532,8 +2532,8 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, logger('wall to wall comment',LOGGER_DEBUG); // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. $signed_body = "\n\n" - . '[img]' . $datarray['author']['xchan_photo_m'] . '[/img]' - . '[url=' . $datarray['author']['xchan_url'] . ']' . $datarray['author']['xchan_name'] . '[/url]' . "\n\n" + . '![' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_photo_m'] . ')' + . '[' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_url'] . ')' . "\n\n" . $signed_body; } -- cgit v1.2.3 From 655c3e1b4784f4bc37af1e1db0d7bcf313e71e66 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 26 Oct 2014 19:32:12 -0700 Subject: put privacy role selector in settings page. Change visibility of various permissions items accordingly. --- include/permissions.php | 4 ++++ include/widgets.php | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index 61ac8aea3..4eead563f 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -734,6 +734,10 @@ function get_role_perms($role) { function role_selector($current) { + + if(! $current) + $current = 'custom'; + $roles = array( 'social' => array( t('Social Networking'), array('social' => t('Mostly Public'), 'social_restricted' => t('Restricted'), 'social_private' => t('Private'))), diff --git a/include/widgets.php b/include/widgets.php index 8905df59a..2e406aa77 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -430,6 +430,8 @@ function widget_settings_menu($arr) { // Retrieve the 'self' address book entry for use in the auto-permissions link + $role = get_pconfig(local_user(),'system','permissions_role'); + $abk = q("select abook_id from abook where abook_channel = %d and ( abook_flags & %d ) limit 1", intval(local_user()), intval(ABOOK_FLAG_SELF) @@ -487,14 +489,15 @@ function widget_settings_menu($arr) { 'selected' => '' ), - array( + ); + + if($role === false || $role === 'custom') { + $tabs[] = array( 'label' => t('Automatic Permissions (Advanced)'), 'url' => $a->get_baseurl(true) . '/connedit/' . $abook_self_id, 'selected' => '' - ), - - - ); + ); + } if(feature_enabled(local_user(),'premium_channel')) { $tabs[] = array( -- cgit v1.2.3 From be8a01618e5577e8324ebc59230165f233a20e89 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 26 Oct 2014 21:56:56 -0700 Subject: turn down the preview logging. Haven't needed that level of detail recently. --- include/conversation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index b22b570a1..48fe8af60 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -827,8 +827,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $threads = null; } - if($page_mode === 'preview') - logger('preview: ' . print_r($threads,true)); +// if($page_mode === 'preview') +// logger('preview: ' . print_r($threads,true)); // Do not un-comment if smarty3 is in use // logger('page_template: ' . $page_template); -- cgit v1.2.3 From 583b445bc02c988e808742b16196e0d80391b3cc Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 27 Oct 2014 16:19:30 -0700 Subject: add "repository" permissions role and make sure we have a sane "accept" default for the custom role. --- include/permissions.php | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/permissions.php b/include/permissions.php index 4eead563f..186ba32d8 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -460,6 +460,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -492,6 +493,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -524,6 +526,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_SPECIFIC; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -555,6 +558,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -586,6 +590,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -618,6 +623,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_SPECIFIC; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_CONTACTS; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_CONTACTS; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -649,6 +655,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_NETWORK; @@ -681,6 +688,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = PERMS_CONTACTS; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -710,6 +718,7 @@ function get_role_perms($role) { $ret['channel_w_chat'] = 0; $ret['channel_a_delegate'] = 0; $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = 0; $ret['channel_r_pages'] = PERMS_PUBLIC; $ret['channel_w_pages'] = 0; $ret['channel_a_republish'] = PERMS_SPECIFIC; @@ -717,6 +726,40 @@ function get_role_perms($role) { break; + case 'repository': + $ret['perms_auto'] = true; + $ret['default_collection'] = false; + $ret['directory_publish'] = true; + $ret['online'] = false; + $ret['perms_follow'] = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK + |PERMS_W_STREAM|PERMS_W_WALL|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT + |PERMS_R_STORAGE|PERMS_W_STORAGE|PERMS_R_PAGES|PERMS_A_REPUBLISH|PERMS_W_LIKE|PERMS_W_TAGWALL; + $ret['perms_accept'] = PERMS_R_STREAM|PERMS_R_PROFILE|PERMS_R_PHOTOS|PERMS_R_ABOOK + |PERMS_W_STREAM|PERMS_W_WALL|PERMS_W_COMMENT|PERMS_W_MAIL|PERMS_W_CHAT + |PERMS_R_STORAGE|PERMS_W_STORAGE|PERMS_R_PAGES|PERMS_A_REPUBLISH|PERMS_W_LIKE|PERMS_W_TAGWALL; + $ret['channel_r_stream'] = PERMS_PUBLIC; + $ret['channel_r_profile'] = PERMS_PUBLIC; + $ret['channel_r_photos'] = PERMS_PUBLIC; + $ret['channel_r_abook'] = PERMS_PUBLIC; + $ret['channel_w_stream'] = PERMS_CONTACTS; + $ret['channel_w_wall'] = PERMS_CONTACTS; + $ret['channel_w_tagwall'] = PERMS_CONTACTS; + $ret['channel_w_comment'] = PERMS_CONTACTS; + $ret['channel_w_mail'] = PERMS_CONTACTS; + $ret['channel_w_photos'] = PERMS_CONTACTS; + $ret['channel_w_chat'] = PERMS_CONTACTS; + $ret['channel_a_delegate'] = 0; + $ret['channel_r_storage'] = PERMS_PUBLIC; + $ret['channel_w_storage'] = PERMS_CONTACTS; + $ret['channel_r_pages'] = PERMS_PUBLIC; + $ret['channel_w_pages'] = PERMS_CONTACTS; + $ret['channel_a_republish'] = PERMS_SPECIFIC; + $ret['channel_w_like'] = PERMS_NETWORK; + + break; + + + default: break; @@ -745,8 +788,8 @@ function role_selector($current) { array('forum' => t('Mostly Public'), 'forum_restricted' => t('Restricted'), 'forum_private' => t('Private'))), 'feed' => array( t('Feed Republish'), array('feed' => t('Mostly Public'), 'feed_restricted' => t('Restricted'))), - 'soapbox' => array( t('Celebrity/Soapbox'), - array('soapbox' => t('Mostly Public'))), + 'special' => array( t('Special Purpose'), + array('soapbox' => t('Celebrity/Soapbox'), 'repository' => t('Group Repository'))), 'other' => array( t('Other'), array('custom' => t('Custom/Expert Mode')))); $o = '