From d4627a0b1c1a0e08bb0606cf4b6ba4823b7a2862 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 6 Jul 2016 21:31:05 +0200 Subject: [PATCH 1/8] fix /cloud after recent changes --- Zotlabs/Module/Cloud.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index 833b1b493..2ef67a3f3 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -23,7 +23,6 @@ require_once('vendor/autoload.php'); class Cloud extends \Zotlabs\Web\Controller { function init() { - require_once('include/reddav.php'); if (! is_dir('store')) os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false); @@ -81,7 +80,7 @@ class Cloud extends \Zotlabs\Web\Controller { if($_SERVER['REQUEST_METHOD'] === 'GET') { try { - $x = RedFileData('/' . \App::$cmd, $auth); + $x = $rootDirectory->CollectionData('/' . \App::$cmd, $auth); } catch(\Exception $e) { if($e instanceof Sabre\DAV\Exception\Forbidden) { From 581a3c532303c008390a2851a1e42c6f5de390b1 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 6 Jul 2016 22:02:06 -0700 Subject: [PATCH 2/8] expire crashing on shared hosting from memory exhaustion. Lower the expire limit. Also the sys channel was being expired with everybody else due to a flag change regression. --- Zotlabs/Daemon/Expire.php | 2 +- include/items.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 0ba83b240..215513e87 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -38,7 +38,7 @@ class Expire { logger('site_expire: ' . $site_expire); - $r = q("SELECT channel_id, channel_address, channel_pageflags, channel_expire_days from channel where true"); + $r = q("SELECT channel_id, channel_system, channel_address, channel_expire_days from channel where true"); if ($r) { foreach ($r as $rr) { diff --git a/include/items.php b/include/items.php index 48358c0e4..fd0cfff32 100755 --- a/include/items.php +++ b/include/items.php @@ -3282,7 +3282,7 @@ function item_expire($uid,$days) { $expire_limit = get_config('system','expire_limit'); if(! intval($expire_limit)) - $expire_limit = 5000; + $expire_limit = 2500; $item_normal = item_normal(); From 3bee6543fbd339adf9b9993269b6a46bec27f05e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 6 Jul 2016 22:19:05 -0700 Subject: [PATCH 3/8] reduce the memory usage of the expire query dramatically. --- include/items.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/include/items.php b/include/items.php index fd0cfff32..72f0896ad 100755 --- a/include/items.php +++ b/include/items.php @@ -3282,19 +3282,21 @@ function item_expire($uid,$days) { $expire_limit = get_config('system','expire_limit'); if(! intval($expire_limit)) - $expire_limit = 2500; + $expire_limit = 5000; $item_normal = item_normal(); - $r = q("SELECT * FROM `item` - WHERE `uid` = %d - AND `created` < %s - INTERVAL %s - AND `id` = `parent` - $sql_extra + $r = q("SELECT id FROM item + WHERE uid = %d + AND created < %s - INTERVAL %s AND item_retained = 0 - $item_normal LIMIT $expire_limit ", + AND item_thread_top = 1 + AND resource_type = '' + AND item_starred = 0 + $sql_extra $item_normal LIMIT $expire_limit ", intval($uid), - db_utcnow(), db_quoteinterval(intval($days).' DAY') + db_utcnow(), + db_quoteinterval(intval($days).' DAY') ); if(! $r) @@ -3312,17 +3314,6 @@ function item_expire($uid,$days) { continue; } - // Only expire posts, not photos and photo comments - - if($item['resource_type'] === 'photo') { - retain_item($item['id']); - continue; - } - if(intval($item['item_starred'])) { - retain_item($item['id']); - continue; - } - drop_item($item['id'],false); } From 227320f6f01dec264de820863f971d3e92a486ff Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 7 Jul 2016 20:16:27 +0200 Subject: [PATCH 4/8] more fixes for /cloud and /dav --- Zotlabs/Module/Cloud.php | 11 ----------- Zotlabs/Module/Dav.php | 2 -- Zotlabs/Storage/Directory.php | 2 ++ 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index 2ef67a3f3..9845c5658 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -78,17 +78,6 @@ class Cloud extends \Zotlabs\Web\Controller { $is_readable = false; - if($_SERVER['REQUEST_METHOD'] === 'GET') { - try { - $x = $rootDirectory->CollectionData('/' . \App::$cmd, $auth); - } - catch(\Exception $e) { - if($e instanceof Sabre\DAV\Exception\Forbidden) { - http_status_exit(401, 'Permission denied.'); - } - } - } - // provide a directory view for the cloud in Hubzilla $browser = new \Zotlabs\Storage\Browser($auth); $auth->setBrowserPlugin($browser); diff --git a/Zotlabs/Module/Dav.php b/Zotlabs/Module/Dav.php index 6528e0271..9b4b576c8 100644 --- a/Zotlabs/Module/Dav.php +++ b/Zotlabs/Module/Dav.php @@ -44,8 +44,6 @@ class Dav extends \Zotlabs\Web\Controller { } } - require_once('include/reddav.php'); - if (! is_dir('store')) os_mkdir('store', STORAGE_DEFAULT_PERMISSIONS, false); diff --git a/Zotlabs/Storage/Directory.php b/Zotlabs/Storage/Directory.php index 7a2d9e68b..b524b3cab 100644 --- a/Zotlabs/Storage/Directory.php +++ b/Zotlabs/Storage/Directory.php @@ -206,6 +206,8 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota { throw new DAV\Exception\Forbidden('Permission denied.'); } + require_once('include/attach.php'); + $mimetype = z_mime_content_type($name); $c = q("SELECT * FROM channel WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", From 233cfc29d6e68f8a8453fab2ebb733ab35fa4b67 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 7 Jul 2016 17:23:52 -0700 Subject: [PATCH 5/8] hide the redeliver option one level down since it should rarely be needed by folks outside of shared hosting. --- Zotlabs/Module/Dreport.php | 1 + view/tpl/dreport.tpl | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Dreport.php b/Zotlabs/Module/Dreport.php index 17ed6515e..d2933b464 100644 --- a/Zotlabs/Module/Dreport.php +++ b/Zotlabs/Module/Dreport.php @@ -146,6 +146,7 @@ class Dreport extends \Zotlabs\Web\Controller { '$title' => sprintf( t('Delivery report for %1$s'),substr($mid,0,32)) . '...', '$table' => $table, '$mid' => urlencode($mid), + '$options' => t('Options'), '$push' => t('Redeliver'), '$entries' => $entries )); diff --git a/view/tpl/dreport.tpl b/view/tpl/dreport.tpl index 7d5524a6a..8aa5e2cd1 100644 --- a/view/tpl/dreport.tpl +++ b/view/tpl/dreport.tpl @@ -1,7 +1,14 @@
{{if $table == 'item'}} - + {{/if}}

{{$title}}

From eef40cb3fdb119425848e5e6cfa4680a2b5d85d9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 7 Jul 2016 18:47:18 -0700 Subject: [PATCH 6/8] duplicate supression SQL query was horribly inefficient and could cause issues in resource deprived environments. --- Zotlabs/Module/Item.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 369dd3948..7167d218e 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -93,7 +93,7 @@ class Item extends \Zotlabs\Web\Controller { $origin = (($api_source && array_key_exists('origin',$_REQUEST)) ? intval($_REQUEST['origin']) : 1); - // To represent message-ids on other networks - this will create an item_id record + // To represent message-ids on other networks - this will create an iconfig record $namespace = (($api_source && array_key_exists('namespace',$_REQUEST)) ? strip_tags($_REQUEST['namespace']) : ''); $remote_id = (($api_source && array_key_exists('remote_id',$_REQUEST)) ? strip_tags($_REQUEST['remote_id']) : ''); @@ -535,7 +535,7 @@ class Item extends \Zotlabs\Web\Controller { } /** - * fix naked links by passing through a callback to see if this is a red site + * fix naked links by passing through a callback to see if this is a hubzilla site * (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both. * First protect any url inside certain bbcode tags so we don't double link it. */ @@ -834,21 +834,23 @@ class Item extends \Zotlabs\Web\Controller { if($orig_post) $datarray['edit'] = true; + // suppress duplicates, *unless* you're editing an existing post. This could get picked up + // as a duplicate if you're editing it very soon after posting it initially and you edited + // some attribute besides the content, such as title or categories. + if(feature_enabled($profile_uid,'suppress_duplicates') && (! $orig_post)) { - $z = q("select created from item where uid = %d and body = '%s'", + $z = q("select created from item where uid = %d and created > %s - INTERVAL %s and body = '%s' limit 1", intval($profile_uid), - dbesc($body) + dbutcnow(), + db_quoteinterval('2 MINUTE'), + dbesc($body), ); if($z) { - foreach($z as $zz) { - if($zz['created'] > datetime_convert('UTC','UTC', 'now - 2 minutes')) { - $datarray['cancel'] = 1; - notice( t('Duplicate post suppressed.') . EOL); - logger('Duplicate post. Faking plugin cancel.'); - } - } + $datarray['cancel'] = 1; + notice( t('Duplicate post suppressed.') . EOL); + logger('Duplicate post. Faking plugin cancel.'); } } From 3b17dca25216c4e7cca11b00008b9a5ea2855480 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 7 Jul 2016 18:51:56 -0700 Subject: [PATCH 7/8] typo --- Zotlabs/Module/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 7167d218e..6eae02692 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -844,7 +844,7 @@ class Item extends \Zotlabs\Web\Controller { intval($profile_uid), dbutcnow(), db_quoteinterval('2 MINUTE'), - dbesc($body), + dbesc($body) ); if($z) { From ee1ec0428b21cadb324de44f2cd70c3e8403100a Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 7 Jul 2016 18:53:09 -0700 Subject: [PATCH 8/8] gak one more typo --- Zotlabs/Module/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 6eae02692..58d39da83 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -842,7 +842,7 @@ class Item extends \Zotlabs\Web\Controller { $z = q("select created from item where uid = %d and created > %s - INTERVAL %s and body = '%s' limit 1", intval($profile_uid), - dbutcnow(), + db_utcnow(), db_quoteinterval('2 MINUTE'), dbesc($body) );