From ff68ea608786a698ad46637ef13854ac1b1e6beb Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 29 Jan 2015 14:51:41 -0800 Subject: more message restrict conversions --- boot.php | 13 +++++++++---- include/items.php | 27 ++++++++++++--------------- include/notifier.php | 9 ++++++--- include/photos.php | 33 ++++++++++++++++----------------- include/taxonomy.php | 2 +- include/text.php | 4 ++-- include/widgets.php | 4 ++-- include/zot.php | 10 +++++----- mod/display.php | 4 ++-- mod/editlayout.php | 2 +- mod/editwebpage.php | 2 +- mod/home.php | 4 ++-- mod/impel.php | 6 +++--- mod/item.php | 9 ++++----- mod/layouts.php | 2 +- mod/like.php | 12 ++++++------ mod/page.php | 8 ++++---- mod/webpages.php | 2 +- 18 files changed, 78 insertions(+), 75 deletions(-) diff --git a/boot.php b/boot.php index bd506db5e..6822e8388 100755 --- a/boot.php +++ b/boot.php @@ -520,20 +520,25 @@ define ( 'ACCOUNT_ROLE_ADMIN', 0x1000 ); */ define ( 'ITEM_VISIBLE', 0x0000); -define ( 'ITEM_HIDDEN', 0x0001); +//define ( 'ITEM_HIDDEN', 0x0001); define ( 'ITEM_BLOCKED', 0x0002); define ( 'ITEM_MODERATED', 0x0004); define ( 'ITEM_SPAM', 0x0008); -define ( 'ITEM_DELETED', 0x0010); +//define ( 'ITEM_DELETED', 0x0010); define ( 'ITEM_UNPUBLISHED', 0x0020); -define ( 'ITEM_WEBPAGE', 0x0040); // is a static web page, not a conversational item +//define ( 'ITEM_WEBPAGE', 0x0040); // is a static web page, not a conversational item define ( 'ITEM_DELAYED_PUBLISH', 0x0080); define ( 'ITEM_BUILDBLOCK', 0x0100); // Named thusly to make sure nobody confuses this with ITEM_BLOCKED -define ( 'ITEM_PDL', 0x0200); // Page Description Language - e.g. Comanche +//define ( 'ITEM_PDL', 0x0200); // Page Description Language - e.g. Comanche define ( 'ITEM_BUG', 0x0400); // Is a bug, can be used by the internal bug tracker define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has lapsed // Don't make us evaluate this same item again. +define ( 'ITEM_TYPE_POST', 0 ); +define ( 'ITEM_TYPE_BLOCK', 1 ); +define ( 'ITEM_TYPE_PDL', 2 ); +define ( 'ITEM_TYPE_WEBPAGE', 3 ); + define ( 'DBTYPE_MYSQL', 0 ); define ( 'DBTYPE_POSTGRES', 1 ); diff --git a/include/items.php b/include/items.php index 916838f3f..224ad72e4 100755 --- a/include/items.php +++ b/include/items.php @@ -841,7 +841,7 @@ function get_item_elements($x) { if(array_key_exists('flags',$x) && in_array('deleted',$x['flags'])) $arr['item_deleted'] = 1; if(array_key_exists('flags',$x) && in_array('hidden',$x['flags'])) - $arr['item_restrict'] = ITEM_HIDDEN; + $arr['item_hidden'] = 1; // Here's the deal - the site might be down or whatever but if there's a new person you've never // seen before sending stuff to your stream, we MUST be able to look them up and import their data from their @@ -1312,7 +1312,7 @@ function encode_item_flags($item) { if(intval($item['item_deleted'])) $ret[] = 'deleted'; - if($item['item_restrict'] & ITEM_HIDDEN) + if(intval($item['item_hidden'])) $ret[] = 'hidden'; if(intval($item['item_thread_top'])) $ret[] = 'thread_parent'; @@ -1916,11 +1916,11 @@ function item_store($arr,$allow_exec = false) { // If a page layout is provided, ensure it exists and belongs to us. if(array_key_exists('layout_mid',$arr) && $arr['layout_mid']) { - $l = q("select item_restrict from item where mid = '%s' and uid = %d limit 1", + $l = q("select item_type from item where mid = '%s' and uid = %d limit 1", dbesc($arr['layout_mid']), intval($arr['uid']) ); - if((! $l) || (! ($l[0]['item_restrict'] & ITEM_PDL))) + if((! $l) || (! ($l[0]['item_type'] != ITEM_TYPE_PDL))) unset($arr['layout_mid']); } @@ -3967,8 +3967,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal // 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_restrict = ( item_restrict | %d ) WHERE id = %d", - intval(ITEM_HIDDEN), + $r = q("UPDATE item SET item_hidden = 1 WHERE id = %d", intval($item['id']) ); } @@ -4041,9 +4040,8 @@ function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL,$force = false) { case DROPITEM_PHASE1: if($linked_item && ! $force) { - $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), + $r = q("UPDATE item SET item_hidden = 1, changed = '%s', edited = '%s' WHERE id = %d", - intval(ITEM_HIDDEN), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item['id']) @@ -4062,9 +4060,8 @@ function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL,$force = false) { case DROPITEM_NORMAL: default: if($linked_item && ! $force) { - $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), + $r = q("UPDATE item SET item_hidden = 1, changed = '%s', edited = '%s' WHERE id = %d", - intval(ITEM_HIDDEN), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item['id']) @@ -4522,9 +4519,9 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C $sql_extra .= item_permissions_sql($channel['channel_id']); if($arr['pages']) - $item_restrict = " AND (item_restrict & " . ITEM_WEBPAGE . ") "; + $item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " "; else - $item_restrict = " AND item_restrict = 0 "; + $item_restrict = " AND item_type = 0 "; if($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD) && $channel) { @@ -4629,11 +4626,11 @@ function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remo $page_type = ''; - if($webpage & ITEM_WEBPAGE) + if($webpage == ITEM_TYPE_WEBPAGE) $page_type = 'WEBPAGE'; - elseif($webpage & ITEM_BUILDBLOCK) + elseif($webpage == ITEM_TYPE_BLOCK) $page_type = 'BUILDBLOCK'; - elseif($webpage & ITEM_PDL) + elseif($webpage == ITEM_TYPE_PDL) $page_type = 'PDL'; elseif($namespace && $remote_id) { $page_type = $namespace; diff --git a/include/notifier.php b/include/notifier.php index 6a6879ebb..79be25621 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -316,9 +316,12 @@ function notifier_run($argv, $argc){ if(intval($target_item['item_deleted'])) logger('notifier: target item ITEM_DELETED', LOGGER_DEBUG); - $unforwardable = ITEM_UNPUBLISHED|ITEM_DELAYED_PUBLISH|ITEM_WEBPAGE|ITEM_BUILDBLOCK|ITEM_PDL; - if($target_item['item_restrict'] & $unforwardable) { - logger('notifier: target item not forwardable: flags ' . $target_item['item_restrict'], LOGGER_DEBUG); + if(intval($target_item['item_type']) != ITEM_TYPE_POST) { + logger('notifier: target item not forwardable: type ' . $target_item['item_type'], LOGGER_DEBUG); + return; + } + if(intval($target_item['item_unpublished']) || intval($target_item['item_delayed_publish'])) { + logger('notifier: target item not published, so not forwardable', LOGGER_DEBUG); return; } diff --git a/include/photos.php b/include/photos.php index f52b08473..43386d626 100644 --- a/include/photos.php +++ b/include/photos.php @@ -225,7 +225,7 @@ function photo_upload($channel, $observer, $args) { // Create item container - $item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN); + $item_hidden = (($visible) ? 0 : 1 ); $title = ''; $mid = item_message_id(); @@ -235,8 +235,7 @@ function photo_upload($channel, $observer, $args) { $arr['uid'] = $channel_id; $arr['mid'] = $mid; $arr['parent_mid'] = $mid; - $arr['item_flags'] = $item_flags; - $arr['item_restrict'] = $item_restrict; + $arr['item_hidden'] = $item_hidden; $arr['resource_type'] = 'photo'; $arr['resource_id'] = $photo_hash; $arr['owner_xchan'] = $channel['channel_hash']; @@ -446,7 +445,7 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { // Create item container - $item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN); + $item_hidden = (($visible) ? 0 : 1 ); $title = ''; $mid = item_message_id(); @@ -460,20 +459,20 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr['item_wall'] = 1; $arr['item_origin'] = 1; $arr['item_thread_top'] = 1; - $arr['item_restrict'] = $item_restrict; - $arr['resource_type'] = 'photo'; - $arr['resource_id'] = $photo['resource_id']; - $arr['owner_xchan'] = $channel['channel_hash']; - $arr['author_xchan'] = $creator_hash; - - $arr['allow_cid'] = $photo['allow_cid']; - $arr['allow_gid'] = $photo['allow_gid']; - $arr['deny_cid'] = $photo['deny_cid']; - $arr['deny_gid'] = $photo['deny_gid']; - - $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; + $arr['item_hidden'] = $item_hidden; + $arr['resource_type'] = 'photo'; + $arr['resource_id'] = $photo['resource_id']; + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $creator_hash; + + $arr['allow_cid'] = $photo['allow_cid']; + $arr['allow_gid'] = $photo['allow_gid']; + $arr['deny_cid'] = $photo['deny_cid']; + $arr['deny_gid'] = $photo['deny_gid']; + + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/zmg]' . '[/zrl]'; diff --git a/include/taxonomy.php b/include/taxonomy.php index a5ccada62..9be04e16c 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -116,7 +116,7 @@ function tagadelic($uid, $count = 0, $authors = '', $flags = 0, $restrict = 0, $ // Fetch tags $r = q("select term, count(term) as total from term left join item on term.oid = item.id where term.uid = %d and term.type = %d - and otype = %d and item_restrict = %d and item_private = 0 + and otype = %d and item_type = %d and item_private = 0 $sql_options group by term order by total desc %s", intval($uid), diff --git a/include/text.php b/include/text.php index 9a13e5e72..3258faeec 100644 --- a/include/text.php +++ b/include/text.php @@ -1549,9 +1549,9 @@ function unamp($s) { } function layout_select($channel_id, $current = '') { - $r = q("select mid,sid from item left join item_id on iid = item.id where service = 'PDL' and item.uid = item_id.uid and item_id.uid = %d and (item_restrict & %d)>0", + $r = q("select mid,sid from item left join item_id on iid = item.id where service = 'PDL' and item.uid = item_id.uid and item_id.uid = %d and item_type = %d ", intval($channel_id), - intval(ITEM_PDL) + intval(ITEM_TYPE_PDL) ); if($r) { $o = t('Select a page layout: '); diff --git a/include/widgets.php b/include/widgets.php index d4888789f..c5ccb9216 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -29,7 +29,7 @@ function widget_tagcloud($args) { $type = TERM_CATEGORY; // FIXME there exists no $authors variable - $r = tagadelic($uid, $count, $authors, $flags, ITEM_WEBPAGE, $type); + $r = tagadelic($uid, $count, $authors, $flags, ITEM_TYPE_WEBPAGE, $type); if($r) { $o = '

' . t('Categories') . '

'; @@ -688,7 +688,7 @@ function widget_item($arr) { require_once('include/security.php'); $sql_extra = item_permissions_sql($uid); - $r = q("select * from item where mid = '%s' and uid = %d and item_restrict = " . intval(ITEM_WEBPAGE) . " $sql_extra limit 1", + $r = q("select * from item where mid = '%s' and uid = %d and item_type = " . intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1", dbesc($arr['mid']), intval($uid) ); diff --git a/include/zot.php b/include/zot.php index 7bdde836f..2bc54e6f3 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1532,7 +1532,7 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque } } - if($arr['item_restrict'] & ITEM_DELETED) { + if(intval($arr['item_deleted'])) { // remove_community_tag is a no-op if this isn't a community tag activity remove_community_tag($sender,$arr,$channel['channel_id']); @@ -1549,14 +1549,14 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque continue; } - $r = q("select id, edited, item_restrict, item_flags, mid, parent_mid from item where mid = '%s' and uid = %d limit 1", + $r = q("select * from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval($channel['channel_id']) ); if($r) { // We already have this post. $item_id = $r[0]['id']; - if($r[0]['item_restrict'] & ITEM_DELETED) { + if(intval($r[0]['item_deleted'])) { // It was deleted locally. $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); continue; @@ -1686,7 +1686,7 @@ function delete_imported_item($sender,$item,$uid) { logger('delete_imported_item invoked',LOGGER_DEBUG); - $r = q("select id, item_restrict from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' ) + $r = q("select id, item_deleted 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']), @@ -1700,7 +1700,7 @@ function delete_imported_item($sender,$item,$uid) { return false; } - if($r[0]['item_restrict'] & ITEM_DELETED) { + if(intval($r[0]['item_deleted'])) { logger('delete_imported_item: item was already deleted'); return false; } diff --git a/mod/display.php b/mod/display.php index 740050e41..b61931169 100644 --- a/mod/display.php +++ b/mod/display.php @@ -77,7 +77,7 @@ function display_content(&$a, $update = 0, $load = false) { $target_item = null; - $r = q("select id, uid, mid, parent_mid, item_restrict from item where mid like '%s' limit 1", + $r = q("select id, uid, mid, parent_mid, item_type, item_deleted from item where mid like '%s' limit 1", dbesc($item_hash . '%') ); @@ -87,7 +87,7 @@ function display_content(&$a, $update = 0, $load = false) { $r = null; - if($target_item['item_restrict'] & ITEM_WEBPAGE) { + if($target_item['item_type'] == ITEM_TYPE_WEBPAGE) { $x = q("select * from channel where channel_id = %d limit 1", intval($target_item['uid']) ); diff --git a/mod/editlayout.php b/mod/editlayout.php index d76aa484d..bd5063aee 100644 --- a/mod/editlayout.php +++ b/mod/editlayout.php @@ -135,7 +135,7 @@ function editlayout_content(&$a) { $o .= replace_macros($tpl,array( '$return_path' => $rp, '$action' => 'item', - '$webpage' => ITEM_PDL, + '$webpage' => ITEM_TYPE_PDL, '$share' => t('Edit'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), diff --git a/mod/editwebpage.php b/mod/editwebpage.php index d7969fb2d..4cedcd65f 100644 --- a/mod/editwebpage.php +++ b/mod/editwebpage.php @@ -166,7 +166,7 @@ function editwebpage_content(&$a) { $o .= replace_macros($tpl,array( '$return_path' => $rp, - '$webpage' => ITEM_WEBPAGE, + '$webpage' => ITEM_TYPE_WEBPAGE, '$placeholdpagetitle' => t('Page link title'), '$pagetitle' => $page_title, diff --git a/mod/home.php b/mod/home.php index 648a8ff4f..13b5b2905 100644 --- a/mod/home.php +++ b/mod/home.php @@ -74,10 +74,10 @@ function home_content(&$a, $update = 0, $load = false) { $r = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and - item_restrict = %d limit 1", + item_type = %d limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_WEBPAGE) + intval(ITEM_TYPE_WEBPAGE) ); if($r) { diff --git a/mod/impel.php b/mod/impel.php index 60e80ff9f..927cb11c6 100644 --- a/mod/impel.php +++ b/mod/impel.php @@ -28,17 +28,17 @@ function impel_init(&$a) { switch($j['type']) { case 'webpage': - $arr['item_restrict'] = ITEM_WEBPAGE; + $arr['item_type'] = ITEM_TYPE_WEBPAGE; $namespace = 'WEBPAGE'; $installed_type = t('webpage'); break; case 'block': - $arr['item_restrict'] = ITEM_BUILDBLOCK; + $arr['item_type'] = ITEM_TYPE_BLOCK; $namespace = 'BUILDBLOCK'; $installed_type = t('block'); break; case 'layout': - $arr['item_restrict'] = ITEM_PDL; + $arr['item_type'] = ITEM_TYPE_PDL; $namespace = 'PDL'; $installed_type = t('layout'); break; diff --git a/mod/item.php b/mod/item.php index 294ee641f..e983b63ef 100644 --- a/mod/item.php +++ b/mod/item.php @@ -839,9 +839,8 @@ function item_post(&$a) { // This way we don't see every picture in your new photo album posted to your wall at once. // They will show up as people comment on them. - if($parent_item['item_restrict'] & ITEM_HIDDEN) { - $r = q("UPDATE `item` SET `item_restrict` = %d WHERE `id` = %d", - intval($parent_item['item_restrict'] - ITEM_HIDDEN), + if(intval($parent_item['item_hidden'])) { + $r = q("UPDATE item SET item_hidden = 0 WHERE id = %d", intval($parent_item['id']) ); } @@ -1047,8 +1046,8 @@ function item_check_service_class($channel_id,$iswebpage) { if ($iswebpage) { $r = q("select count(i.id) as total from item i right join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) - and i.parent=i.id and (i.item_restrict & %d)>0 and i.item_deleted = 0 and i.uid= %d ", - intval(ITEM_WEBPAGE), + and i.parent=i.id and i.item_type = %d and i.item_deleted = 0 and i.uid= %d ", + intval(ITEM_TYPE_WEBPAGE), intval($channel_id) ); } diff --git a/mod/layouts.php b/mod/layouts.php index aaf5db0ef..712cfc4cb 100644 --- a/mod/layouts.php +++ b/mod/layouts.php @@ -119,7 +119,7 @@ function layouts_content(&$a) { // This lets you post pages at other people's channels. $x = array( - 'webpage' => ITEM_PDL, + 'webpage' => ITEM_TYPE_PDL, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), diff --git a/mod/like.php b/mod/like.php index 968f9c81e..6316b38f9 100755 --- a/mod/like.php +++ b/mod/like.php @@ -229,9 +229,10 @@ function like_content(&$a) { // get the item. Allow linked photos (which are normally hidden) to be liked - $r = q("SELECT * FROM item WHERE id = %d and (item_restrict = 0 or item_restrict = %d) LIMIT 1", - intval($item_id), - intval(ITEM_HIDDEN) + $r = q("SELECT * FROM item WHERE id = %d + and item_blocked = 0 and item_moderated = 0 and item_spam = 0 + and item_deleted = 0 and item_unpublished = 0 and item_delayed_publish = 0 LIMIT 1", + intval($item_id) ); if(! $item_id || (! $r)) { @@ -339,9 +340,8 @@ function like_content(&$a) { // if this was a linked photo and was hidden, unhide it. - if($item['item_restrict'] & ITEM_HIDDEN) { - $r = q("update item set item_restrict = (item_restrict ^ %d) where id = %d", - intval(ITEM_HIDDEN), + if(intval($item['item_hidden'])) { + $r = q("update item set item_hidden = 0 where id = %d", intval($item['id']) ); } diff --git a/mod/page.php b/mod/page.php index e8f17ebda..1830b964b 100644 --- a/mod/page.php +++ b/mod/page.php @@ -56,10 +56,10 @@ function page_init(&$a) { $r = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and - item_restrict = %d $sql_options $revision limit 1", + item_type = %d $sql_options $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_WEBPAGE) + intval(ITEM_TYPE_WEBPAGE) ); if(! $r) { @@ -68,10 +68,10 @@ function page_init(&$a) { $x = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and - item_restrict = %d $revision limit 1", + item_type = %d $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_WEBPAGE) + intval(ITEM_TYPE_WEBPAGE) ); if($x) { // Yes, it's there. You just aren't allowed to see it. diff --git a/mod/webpages.php b/mod/webpages.php index baddebec8..48dfe4920 100644 --- a/mod/webpages.php +++ b/mod/webpages.php @@ -106,7 +106,7 @@ function webpages_content(&$a) { $o = profile_tabs($a,true); $x = array( - 'webpage' => ITEM_WEBPAGE, + 'webpage' => ITEM_TYPE_WEBPAGE, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), -- cgit v1.2.3