aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/Libzot.php35
-rw-r--r--Zotlabs/Lib/NativeWiki.php2
-rw-r--r--Zotlabs/Module/Channel_calendar.php60
-rw-r--r--include/attach.php7
-rwxr-xr-xinclude/items.php105
-rw-r--r--include/zot.php36
-rwxr-xr-xutil/thumbrepair2
7 files changed, 170 insertions, 77 deletions
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index 976ed22fa..0ad8afc94 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -2037,7 +2037,7 @@ class Libzot {
$item_found = false;
$post_id = 0;
- $r = q("select id, author_xchan, owner_xchan, source_xchan, item_deleted from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
+ $r = q("select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
and mid = '%s' and uid = %d limit 1",
dbesc($sender),
dbesc($sender),
@@ -2047,10 +2047,12 @@ class Libzot {
);
if($r) {
- if($r[0]['author_xchan'] === $sender || $r[0]['owner_xchan'] === $sender || $r[0]['source_xchan'] === $sender)
+ $stored = $r[0];
+
+ if($stored['author_xchan'] === $sender || $stored['owner_xchan'] === $sender || $stored['source_xchan'] === $sender)
$ownership_valid = true;
- $post_id = $r[0]['id'];
+ $post_id = $stored['id'];
$item_found = true;
}
else {
@@ -2074,8 +2076,27 @@ class Libzot {
return false;
}
+ if ($stored['resource_type'] === 'event') {
+ $i = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ dbesc($stored['resource_id']),
+ intval($uid)
+ );
+ if ($i) {
+ if ($i[0]['event_xchan'] === $sender) {
+ q("delete from event where event_hash = '%s' and uid = %d",
+ dbesc($stored['resource_id']),
+ intval($uid)
+ );
+ }
+ else {
+ logger('delete linked event: not owner');
+ return;
+ }
+ }
+ }
+
if($item_found) {
- if(intval($r[0]['item_deleted'])) {
+ if(intval($stored['item_deleted'])) {
logger('delete_imported_item: item was already deleted');
if(! $relay)
return false;
@@ -2087,10 +2108,10 @@ class Libzot {
// back, and we aren't going to (or shouldn't at any rate) delete it again in the future - so losing
// this information from the metadata should have no other discernible impact.
- if (($r[0]['id'] != $r[0]['parent']) && intval($r[0]['item_origin'])) {
+ if (($stored['id'] != $stored['parent']) && intval($stored['item_origin'])) {
q("update item set item_origin = 0 where id = %d and uid = %d",
- intval($r[0]['id']),
- intval($r[0]['uid'])
+ intval($stored['id']),
+ intval($stored['uid'])
);
}
}
diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php
index e2bd07c0d..662fddad0 100644
--- a/Zotlabs/Lib/NativeWiki.php
+++ b/Zotlabs/Lib/NativeWiki.php
@@ -191,7 +191,7 @@ class NativeWiki {
return array('item' => null, 'success' => false);
}
else {
- $drop = drop_item($item['id'], false, DROPITEM_NORMAL, true);
+ $drop = drop_item($item['id'], false, DROPITEM_NORMAL);
}
info( t('Wiki files deleted successfully'));
diff --git a/Zotlabs/Module/Channel_calendar.php b/Zotlabs/Module/Channel_calendar.php
index 4f08eb27c..ac08dfa96 100644
--- a/Zotlabs/Module/Channel_calendar.php
+++ b/Zotlabs/Module/Channel_calendar.php
@@ -422,13 +422,67 @@ class Channel_calendar extends \Zotlabs\Web\Controller {
dbesc($event_id),
intval(local_channel())
);
+
if($r) {
- $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d",
+
+ $sync_event['event_deleted'] = 1;
+ build_sync_packet(0,array('event' => array($sync_event)));
+
+ $i = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d",
dbesc($event_id),
intval(local_channel())
);
- $sync_event['event_deleted'] = 1;
- build_sync_packet(0,array('event' => array($sync_event)));
+
+ if ($i) {
+
+ $can_delete = false;
+ $local_delete = true;
+
+ $ob_hash = get_observer_hash();
+ if($ob_hash && ($ob_hash === $i[0]['author_xchan'] || $ob_hash === $i[0]['owner_xchan'] || $ob_hash === $i[0]['source_xchan'])) {
+ $can_delete = true;
+ }
+
+ // The site admin can delete any post/item on the site.
+ // If the item originated on this site+channel the deletion will propagate downstream.
+ // Otherwise just the local copy is removed.
+
+ if(is_site_admin()) {
+ $local_delete = true;
+ if(intval($i[0]['item_origin']))
+ $can_delete = true;
+ }
+
+ if($can_delete || $local_delete) {
+
+ // if this is a different page type or it's just a local delete
+ // but not by the item author or owner, do a simple deletion
+
+ $complex = false;
+
+ if(intval($i[0]['item_type']) || ($local_delete && (! $can_delete))) {
+ drop_item($i[0]['id']);
+ }
+ else {
+ // complex deletion that needs to propagate and be performed in phases
+ drop_item($i[0]['id'],true,DROPITEM_PHASE1);
+ $complex = true;
+ }
+
+ $ii = q("select * from item where id = %d",
+ intval($i[0]['id'])
+ );
+ if($ii) {
+ xchan_query($ii);
+ $sync_item = fetch_post_tags($ii);
+ build_sync_packet($i[0]['uid'],array('item' => array(encode_item($sync_item[0],true))));
+ }
+
+ if($complex) {
+ tag_deliver($i[0]['uid'],$i[0]['id']);
+ }
+ }
+ }
killme();
}
notice( t('Failed to remove event' ) . EOL);
diff --git a/include/attach.php b/include/attach.php
index f169e0669..80efe0838 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1514,12 +1514,15 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
function attach_drop_photo($channel_id,$resource) {
- $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d",
+ $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'photo' and uid = %d and item_deleted = 0",
dbesc($resource),
intval($channel_id)
);
+
if($x) {
- drop_item($x[0]['id'],false,(($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1),true);
+ $stage = (($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1);
+ $interactive = (($x[0]['item_hidden']) ? false : true);
+ drop_item($x[0]['id'], $interactive, $stage);
}
$r = q("SELECT content FROM photo WHERE resource_id = '%s' AND uid = %d AND os_storage = 1",
diff --git a/include/items.php b/include/items.php
index 95b696034..9ceb91519 100755
--- a/include/items.php
+++ b/include/items.php
@@ -3663,7 +3663,7 @@ function retain_item($id) {
);
}
-function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force = false) {
+function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL) {
$uid = 0;
if(! local_channel() && ! remote_channel())
@@ -3671,7 +3671,7 @@ function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force
if(count($items)) {
foreach($items as $item) {
- $owner = drop_item($item,$interactive,$stage,$force);
+ $owner = drop_item($item,$interactive,$stage);
if($owner && ! $uid)
$uid = $owner;
}
@@ -3694,12 +3694,7 @@ function drop_items($items,$interactive = false,$stage = DROPITEM_NORMAL,$force
// $stage = 1 => set deleted flag on the item and perform intial notifications
// $stage = 2 => perform low level delete at a later stage
-function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = false) {
-
- // These resource types have linked items that should only be removed at the same time
- // as the linked resource; if we encounter one set it to item_hidden rather than item_deleted.
-
- $linked_resource_types = [ 'photo' ];
+function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) {
// locate item to be deleted
@@ -3711,13 +3706,11 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal
if(! $interactive)
return 0;
notice( t('Item not found.') . EOL);
- goaway(z_root() . '/' . $_SESSION['return_url']);
+ //goaway(z_root() . '/' . $_SESSION['return_url']);
}
$item = $r[0];
- $linked_item = (($item['resource_id'] && $item['resource_type'] && in_array($item['resource_type'], $linked_resource_types)) ? true : false);
-
$ok_to_delete = false;
// system deletion
@@ -3743,16 +3736,9 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal
// set the deleted flag immediately on this item just in case the
// hook calls a remote process which loops. We'll delete it properly in a second.
- if(($linked_item) && (! $force)) {
- $r = q("UPDATE item SET item_hidden = 1 WHERE id = %d",
- intval($item['id'])
- );
- }
- else {
- $r = q("UPDATE item SET item_deleted = 1 WHERE id = %d",
- intval($item['id'])
- );
- }
+ $r = q("UPDATE item SET item_deleted = 1 WHERE id = %d",
+ intval($item['id'])
+ );
$arr = [
'item' => $item,
@@ -3792,14 +3778,13 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal
if((intval($item['item_wall']) && ($stage != DROPITEM_PHASE2)) || ($stage == DROPITEM_PHASE1)) {
Master::Summon([ 'Notifier','drop',$notify_id ]);
}
-
- goaway(z_root() . '/' . $_SESSION['return_url']);
+ //goaway(z_root() . '/' . $_SESSION['return_url']);
}
else {
if(! $interactive)
return 0;
notice( t('Permission denied.') . EOL);
- goaway(z_root() . '/' . $_SESSION['return_url']);
+ //goaway(z_root() . '/' . $_SESSION['return_url']);
}
}
@@ -3814,11 +3799,9 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal
* @param boolean $force
* @return boolean
*/
-function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false) {
-
- $linked_item = (($item['resource_id']) ? true : false);
+function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL) {
- logger('item: ' . $item['id'] . ' stage: ' . $stage . ' force: ' . $force, LOGGER_DATA);
+ logger('item: ' . $item['id'] . ' stage: ' . $stage, LOGGER_DATA);
switch($stage) {
case DROPITEM_PHASE2:
@@ -3831,42 +3814,50 @@ function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false) {
break;
case DROPITEM_PHASE1:
- if($linked_item && ! $force) {
- $r = q("UPDATE item SET item_hidden = 1,
- changed = '%s', edited = '%s' WHERE id = %d",
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($item['id'])
- );
- }
- else {
- $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d",
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($item['id'])
- );
- }
-
+ $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($item['id'])
+ );
break;
case DROPITEM_NORMAL:
default:
- if($linked_item && ! $force) {
- $r = q("UPDATE item SET item_hidden = 1,
- changed = '%s', edited = '%s' WHERE id = %d",
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($item['id'])
- );
- }
- else {
- $r = q("DELETE FROM item WHERE id = %d",
- intval($item['id'])
- );
- }
+ $r = q("DELETE FROM item WHERE id = %d",
+ intval($item['id'])
+ );
break;
}
+ // immediately remove local linked resources
+
+ if($item['resource_type'] === 'event') {
+ $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ dbesc($item['resource_id']),
+ intval($item['uid'])
+ );
+
+ $sync_data = $r[0];
+
+ $x = q("delete from event where event_hash = '%s' and uid = %d",
+ dbesc($item['resource_id']),
+ intval($item['uid'])
+ );
+
+ if($x) {
+ $sync_data['event_deleted'] = 1;
+ build_sync_packet($item['uid'], ['event' => [$sync_data]]);
+ }
+ }
+
+ if($item['resource_type'] === 'photo') {
+ attach_delete($item['uid'], $item['resource_id'], true );
+ $channel = channelx_by_n($item['uid']);
+ $sync_data = attach_export_data($channel, $item['resource_id'], true);
+ if($sync_data)
+ build_sync_packet($item['uid'], ['file' => [$sync_data]]);
+ }
+
// immediately remove any undesired profile likes.
q("delete from likes where iid = %d and channel_id = %d",
diff --git a/include/zot.php b/include/zot.php
index a37b7cdb5..5fd900765 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2241,7 +2241,7 @@ function delete_imported_item($sender, $item, $uid, $relay) {
$item_found = false;
$post_id = 0;
- $r = q("select id, author_xchan, owner_xchan, source_xchan, item_deleted from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
+ $r = q("select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )
and mid = '%s' and uid = %d limit 1",
dbesc($sender['hash']),
dbesc($sender['hash']),
@@ -2251,10 +2251,13 @@ function delete_imported_item($sender, $item, $uid, $relay) {
);
if($r) {
- if($r[0]['author_xchan'] === $sender['hash'] || $r[0]['owner_xchan'] === $sender['hash'] || $r[0]['source_xchan'] === $sender['hash'])
+
+ $stored = $r[0];
+
+ if($stored['author_xchan'] === $sender['hash'] || $stored['owner_xchan'] === $sender['hash'] || $stored['source_xchan'] === $sender['hash'])
$ownership_valid = true;
- $post_id = $r[0]['id'];
+ $post_id = $stored['id'];
$item_found = true;
}
else {
@@ -2278,10 +2281,29 @@ function delete_imported_item($sender, $item, $uid, $relay) {
return false;
}
+ if ($stored['resource_type'] === 'event') {
+ $i = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ dbesc($stored['resource_id']),
+ intval($uid)
+ );
+ if ($i) {
+ if ($i[0]['event_xchan'] === $sender['hash']) {
+ q("delete from event where event_hash = '%s' and uid = %d",
+ dbesc($stored['resource_id']),
+ intval($uid)
+ );
+ }
+ else {
+ logger('delete linked event: not owner');
+ return;
+ }
+ }
+ }
+
require_once('include/items.php');
if($item_found) {
- if(intval($r[0]['item_deleted'])) {
+ if(intval($stored['item_deleted'])) {
logger('delete_imported_item: item was already deleted');
if(! $relay)
return false;
@@ -2293,10 +2315,10 @@ function delete_imported_item($sender, $item, $uid, $relay) {
// back, and we aren't going to (or shouldn't at any rate) delete it again in the future - so losing
// this information from the metadata should have no other discernible impact.
- if (($r[0]['id'] != $r[0]['parent']) && intval($r[0]['item_origin'])) {
+ if (($stored['id'] != $stored['parent']) && intval($stored['item_origin'])) {
q("update item set item_origin = 0 where id = %d and uid = %d",
- intval($r[0]['id']),
- intval($r[0]['uid'])
+ intval($stored['id']),
+ intval($stored['uid'])
);
}
}
diff --git a/util/thumbrepair b/util/thumbrepair
index e13a5f24a..6d3eabdbd 100755
--- a/util/thumbrepair
+++ b/util/thumbrepair
@@ -44,6 +44,7 @@ if($x) {
$im->storeThumbnail($nn, PHOTO_RES_320);
break;
case 4:
+ $im->scaleImage(300);
$im->storeThumbnail($nn, PHOTO_RES_PROFILE_300);
break;
case 5:
@@ -55,6 +56,7 @@ if($x) {
$im->storeThumbnail($nn, PHOTO_RES_PROFILE_48);
break;
case 7:
+ $im->doScaleImage(1200,435);
$im->storeThumbnail($nn, PHOTO_RES_COVER_1200);
break;
case 8: