From 6f11f20992c88ff48a55929e94d9003fcc437062 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 Jan 2015 15:35:42 -0800 Subject: first cut at unpacking bitfields in hubloc, fixed hubloc_error and hubloc_deleted --- include/Contact.php | 28 +++++++++------------------- include/hubloc.php | 3 +-- include/notifier.php | 7 ++----- include/onedirsync.php | 2 +- include/zot.php | 32 +++++++++++++------------------- mod/locs.php | 6 ++---- mod/post.php | 13 +++++-------- 7 files changed, 33 insertions(+), 58 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 4c80f5d6a..4a016e32f 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -272,8 +272,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { ); - $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_DELETED), + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", dbesc($channel['channel_hash']) ); @@ -312,8 +311,7 @@ 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' and hubloc_url = '%s' ", - intval(HUBLOC_FLAGS_DELETED), + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s' and hubloc_url = '%s' ", dbesc($channel['channel_hash']), dbesc(z_root()) ); @@ -322,9 +320,8 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { $hublocs = 0; - $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d)>0", - dbesc($channel['channel_hash']), - intval(HUBLOC_FLAGS_DELETED) + $r = q("select hubloc_id from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", + dbesc($channel['channel_hash']) ); if($r) $hublocs = count($r); @@ -374,10 +371,8 @@ function mark_orphan_hubsxchans() { if($dirmode == DIRECTORY_MODE_NORMAL) return; - $r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d)>0 + $r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0 and hubloc_network = 'zot' and hubloc_connected < %s - interval %s", - intval(HUBLOC_OFFLINE), - intval(HUBLOC_OFFLINE), db_utcnow(), db_quoteinterval('36 day') ); @@ -394,9 +389,7 @@ function mark_orphan_hubsxchans() { // } - $r = q("select hubloc_id, hubloc_hash from hubloc where (hubloc_status & %d)>0 and not (hubloc_flags & %d)>0", - intval(HUBLOC_OFFLINE), - intval(HUBLOC_FLAGS_ORPHANCHECK) + $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0", ); if($r) { @@ -404,9 +397,8 @@ function mark_orphan_hubsxchans() { // see if any other hublocs are still alive for this channel - $x = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_status & %d)>0", + $x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0", dbesc($rr['hubloc_hash']), - intval(HUBLOC_OFFLINE) ); if($x) { @@ -431,8 +423,7 @@ function mark_orphan_hubsxchans() { // mark that we've checked this entry so we don't need to do it again - $y = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_ORPHANCHECK), + $y = q("update hubloc set hubloc_orphancheck = 1 where hubloc_id = %d", dbesc($rr['hubloc_id']) ); } @@ -501,8 +492,7 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) { // directory servers need to keep the record around for sync purposes - mark it deleted - $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_DELETED), + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_hash = '%s'", dbesc($xchan) ); diff --git a/include/hubloc.php b/include/hubloc.php index b5a3d47c5..92736e090 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -96,8 +96,7 @@ function remove_obsolete_hublocs() { ? intval(get_config('system','delivery_interval')) : 2 ); foreach($r as $rr) { - q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_DELETED), + q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d", intval($rr['hubloc_id']) ); diff --git a/include/notifier.php b/include/notifier.php index 06ef7bc94..0bdc71261 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -497,11 +497,8 @@ function notifier_run($argv, $argc){ where hubloc_hash in (" . implode(',',$recipients) . ") order by hubloc_connected desc limit 1"); } else { - $r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc - where hubloc_hash in (" . implode(',',$recipients) . ") and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0", - intval(HUBLOC_FLAGS_DELETED), - intval(HUBLOC_OFFLINE) - ); + $r = q("select * from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") + and hubloc_error = 0 and hubloc_deleted = 0"); } if(! $r) { diff --git a/include/onedirsync.php b/include/onedirsync.php index a1450e183..c94a1410f 100644 --- a/include/onedirsync.php +++ b/include/onedirsync.php @@ -55,7 +55,7 @@ function onedirsync_run($argv, $argc){ $h = q("select * from hubloc where hubloc_addr = '%s' limit 1", dbesc($r[0]['ud_addr']) ); - if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) { + if(($h) && (intval($h[0]['hubloc_error']))) $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), diff --git a/include/zot.php b/include/zot.php index 384769d61..ac5127f1c 100644 --- a/include/zot.php +++ b/include/zot.php @@ -79,9 +79,8 @@ function zot_get_hublocs($hash) { /** Only search for active hublocs - e.g. those that haven't been marked deleted */ - $ret = q("select * from hubloc where hubloc_hash = '%s' and not ( hubloc_flags & %d )>0 order by hubloc_url ", - dbesc($hash), - intval(HUBLOC_FLAGS_DELETED) + $ret = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted != 0 order by hubloc_url ", + dbesc($hash) ); return $ret; } @@ -1884,9 +1883,8 @@ function sync_locations($sender,$arr,$absolute = false) { // Should we do this? It's basically saying that the channel knows better than // the directory server if the site is alive. - if($r[0]['hubloc_status'] & HUBLOC_OFFLINE) { - q("update hubloc set hubloc_status = (hubloc_status & ~%d) where hubloc_id = %d", - intval(HUBLOC_OFFLINE), + if($r[0]['hubloc_error']) { + q("update hubloc set hubloc_error = 0 where hubloc_id = %d", intval($r[0]['hubloc_id']) ); if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { @@ -1934,10 +1932,10 @@ function sync_locations($sender,$arr,$absolute = false) { $changed = true; } } - if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_DELETED) && (! $location['deleted'])) - || ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_DELETED)) && ($location['deleted']))) { - $n = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", - intval(HUBLOC_FLAGS_DELETED), + if((intval($r[0]['hubloc_deleted']) && (! $location['deleted'])) + || ((! (intval($r[0]['hubloc_deleted']))) && ($location['deleted']))) { + $n = q("update hubloc set hubloc_deleted = %d, hubloc_updated = '%s' where hubloc_id = %d", + intval($location['deleted']), dbesc(datetime_convert()), intval($r[0]['hubloc_id']) ); @@ -1994,8 +1992,7 @@ function sync_locations($sender,$arr,$absolute = false) { foreach($xisting as $x) { if(! array_key_exists('updated',$x)) { logger('sync_locations: deleting unreferenced hub location ' . $x['hubloc_url']); - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", - intval(HUBLOC_FLAGS_DELETED), + $r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d", dbesc(datetime_convert()), intval($x['hubloc_id']) ); @@ -2029,7 +2026,7 @@ function zot_encode_locations($channel) { 'url_sig' => $hub['hubloc_url_sig'], 'callback' => $hub['hubloc_callback'], 'sitekey' => $hub['hubloc_sitekey'], - 'deleted' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false) + 'deleted' => (intval($hub['hubloc_deleted']) ? true : false) ); } } @@ -2917,12 +2914,9 @@ function zot_process_message_request($data) { if($messages) { $env_recips = null; - $r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host - from hubloc where hubloc_hash = '%s' and not (hubloc_flags & %d)>0 - and not (hubloc_status & %d)>0 group by hubloc_sitekey", - dbesc($sender_hash), - intval(HUBLOC_FLAGS_DELETED), - intval(HUBLOC_OFFLINE) + $r = q("select * from hubloc where hubloc_hash = '%s' and not hubloc_error and not hubloc_deleted + group by hubloc_sitekey", + dbesc($sender_hash) ); if(! $r) { logger('no hubs'); diff --git a/mod/locs.php b/mod/locs.php index b1169fcca..352112e3a 100644 --- a/mod/locs.php +++ b/mod/locs.php @@ -50,8 +50,7 @@ function locs_post(&$a) { notice( t('Primary location cannot be removed.') . EOL); return; } - $r = q("update hubloc set hubloc_flags = (hubloc_flags & %d) where hubloc_id = %d and hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_DELETED), + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d and hubloc_hash = '%s'", intval($hubloc_id), dbesc($channel['channel_hash']) ); @@ -66,7 +65,6 @@ function locs_post(&$a) { function locs_content(&$a) { - if(! local_user()) { notice( t('Permission denied.') . EOL); return; @@ -86,7 +84,7 @@ function locs_content(&$a) { for($x = 0; $x < count($r); $x ++) { $r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false); - $r[$x]['deleted'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false); + $r[$x]['deleted'] = (intval($r[$x]['hubloc_deleted']) ? true : false); } diff --git a/mod/post.php b/mod/post.php index 9e818a7e2..338cd71c0 100644 --- a/mod/post.php +++ b/mod/post.php @@ -666,14 +666,12 @@ function post_post(&$a) { // a dead hub came back to life - reset any tombstones we might have - if($hub['hubloc_status'] & HUBLOC_OFFLINE) { - q("update hubloc set hubloc_status = (hubloc_status & ~%d) where hubloc_id = %d", - intval(HUBLOC_OFFLINE), + if(intval($hub['hubloc_error'])) { + q("update hubloc set hubloc_error = 0 where hubloc_id = %d", intval($hub['hubloc_id']) ); - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { - q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_ORPHANCHECK), + if(intval($r[0]['hubloc_orphancheck'])) { + q("update hubloc set hubloc_orhpancheck = 0 where hubloc_id = %d", intval($hub['hubloc_id']) ); } @@ -693,8 +691,7 @@ function post_post(&$a) { * */ - q("update hubloc set hubloc_flags = ( hubloc_flags | %d ) where hubloc_url = '%s' and hubloc_sitekey != '%s' ", - intval(HUBLOC_FLAGS_DELETED), + q("update hubloc set hubloc_deleted = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s' ", dbesc($hub['hubloc_url']), dbesc($hub['hubloc_sitekey']) ); -- cgit v1.2.3 From ee3eee425c92b37fba5a7035d8e9ec0b0b563d0b Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 Jan 2015 16:13:18 -0800 Subject: that should take care of the bitfields in hubloc --- include/Contact.php | 10 ++++---- include/fixd.php | 33 --------------------------- include/hubloc.php | 2 +- include/identity.php | 4 ++-- include/network.php | 5 ++-- include/notifier.php | 2 +- include/onedirsync.php | 2 +- include/text.php | 6 ++--- include/zot.php | 62 ++++++++++++++++++++++---------------------------- mod/import.php | 12 ++++------ mod/locs.php | 13 ++++------- 11 files changed, 51 insertions(+), 100 deletions(-) delete mode 100644 include/fixd.php diff --git a/include/Contact.php b/include/Contact.php index 4a016e32f..c872dc913 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -22,9 +22,8 @@ function rconnect_url($channel_id,$xchan) { if(($r) && ($r[0]['xchan_follow'])) return $r[0]['xchan_follow']; - $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d )>0 limit 1", - dbesc($xchan), - intval(HUBLOC_FLAGS_PRIMARY) + $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 limit 1", + dbesc($xchan) ); if($r) @@ -389,8 +388,7 @@ function mark_orphan_hubsxchans() { // } - $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0", - ); + $r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0"); if($r) { foreach($r as $rr) { @@ -398,7 +396,7 @@ function mark_orphan_hubsxchans() { // see if any other hublocs are still alive for this channel $x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0", - dbesc($rr['hubloc_hash']), + dbesc($rr['hubloc_hash']) ); if($x) { diff --git a/include/fixd.php b/include/fixd.php deleted file mode 100644 index bce5eb348..000000000 --- a/include/fixd.php +++ /dev/null @@ -1,33 +0,0 @@ -get_hostname()), - intval(($primary) ? HUBLOC_FLAGS_PRIMARY : 0), + intval($primary), dbesc(z_root()), dbesc(base64url_encode(rsa_sign(z_root(),$ret['channel']['channel_prvkey']))), dbesc(get_app()->get_hostname()), diff --git a/include/network.php b/include/network.php index 170b77d7d..8082d0217 100644 --- a/include/network.php +++ b/include/network.php @@ -1113,7 +1113,7 @@ function discover_by_webbie($webbie) { if(! $r) { - $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_flags ) values ('%s','%s','%s','%s','%s','%s','%s','%s', %d)", + $r = q("insert into hubloc ( hubloc_guid, hubloc_hash, hubloc_addr, hubloc_network, hubloc_url, hubloc_host, hubloc_callback, hubloc_updated, hubloc_primary ) values ('%s','%s','%s','%s','%s','%s','%s','%s', 1)", dbesc($guid), dbesc($addr), dbesc($addr), @@ -1121,8 +1121,7 @@ function discover_by_webbie($webbie) { dbesc(trim($diaspora_base,'/')), dbesc($hostname), dbesc($notify), - dbescdate(datetime_convert()), - intval(HUBLOC_FLAGS_PRIMARY) + dbescdate(datetime_convert()) ); } $photos = import_profile_photo($vcard['photo'],$addr); diff --git a/include/notifier.php b/include/notifier.php index 0bdc71261..29646fb38 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -493,7 +493,7 @@ function notifier_run($argv, $argc){ // aren't the owner or author. - $r = q("select hubloc_guid, hubloc_url, hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc + $r = q("select * from hubloc where hubloc_hash in (" . implode(',',$recipients) . ") order by hubloc_connected desc limit 1"); } else { diff --git a/include/onedirsync.php b/include/onedirsync.php index c94a1410f..e611492af 100644 --- a/include/onedirsync.php +++ b/include/onedirsync.php @@ -55,7 +55,7 @@ function onedirsync_run($argv, $argc){ $h = q("select * from hubloc where hubloc_addr = '%s' limit 1", dbesc($r[0]['ud_addr']) ); - if(($h) && (intval($h[0]['hubloc_error']))) + if(($h) && (intval($h[0]['hubloc_error']))) { $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), diff --git a/include/text.php b/include/text.php index b6e4abf24..fcd7b422c 100644 --- a/include/text.php +++ b/include/text.php @@ -1890,13 +1890,13 @@ function xchan_query(&$items,$abook = true,$effective_uid = 0) { if(count($arr)) { if($abook) { $chans = q("select * from xchan left join hubloc on hubloc_hash = xchan_hash left join abook on abook_xchan = xchan_hash and abook_channel = %d - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0", + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1", intval($item['uid']) ); } else { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0"); + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1"); } $xchans = q("select * from xchan where xchan_hash in (" . implode(',',$arr) . ") and xchan_network in ('rss','unknown')"); if(! $chans) @@ -1924,7 +1924,7 @@ function xchan_mail_query(&$item) { if(count($arr)) { $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . implode(',', $arr) . ") and ( hubloc_flags & " . intval(HUBLOC_FLAGS_PRIMARY) . " )>0"); + where xchan_hash in (" . implode(',', $arr) . ") and hubloc_primary = 1"); } if($chans) { $item['from'] = find_xchan_in_array($item['from_xchan'],$chans); diff --git a/include/zot.php b/include/zot.php index ac5127f1c..debd2c8a8 100644 --- a/include/zot.php +++ b/include/zot.php @@ -201,9 +201,8 @@ function zot_finger($webbie,$channel,$autofallback = true) { $r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where xchan_addr = '%s' and (hubloc_flags & %d) > 0 limit 1", - dbesc($xchan_addr), - intval(HUBLOC_FLAGS_PRIMARY) + where xchan_addr = '%s' and hubloc_primary = 1 limit 1", + dbesc($xchan_addr) ); if($r) { @@ -300,9 +299,8 @@ function zot_refresh($them,$channel = null, $force = false) { if($them['hubloc_url']) $url = $them['hubloc_url']; else { - $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d ) > 0 limit 1", - dbesc($them['xchan_hash']), - intval(HUBLOC_FLAGS_PRIMARY) + $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and hubloc_primary = 1 limit 1", + dbesc($them['xchan_hash']) ); if($r) $url = $r[0]['hubloc_url']; @@ -1887,9 +1885,8 @@ function sync_locations($sender,$arr,$absolute = false) { q("update hubloc set hubloc_error = 0 where hubloc_id = %d", intval($r[0]['hubloc_id']) ); - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { - q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_ORPHANCHECK), + if(intval($r[0]['hubloc_orphancheck'])) { + q("update hubloc set hubloc_orphancheck = 0 where hubloc_id = %d", intval($r[0]['hubloc_id']) ); } @@ -1911,15 +1908,15 @@ function sync_locations($sender,$arr,$absolute = false) { } } - if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary'])) - || ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)) && ($location['primary']))) { - $m = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_id = %d", - intval(HUBLOC_FLAGS_PRIMARY), + if((intval($r[0]['hubloc_primary']) && (! $location['primary'])) + || ((! intval($r[0]['hubloc_primary'])) && ($location['primary']))) { + $m = q("update hubloc set hubloc_primary = %d, hubloc_updated = '%s' where hubloc_id = %d", + intval($location['primary']), dbesc(datetime_convert()), intval($r[0]['hubloc_id']) ); // make sure hubloc_change_primary() has current data - $r[0]['hubloc_flags'] = $r[0]['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY; + $r[0]['hubloc_primary'] = intval($location['primary']); hubloc_change_primary($r[0]); $what .= 'primary_hub '; $changed = true; @@ -1949,22 +1946,20 @@ function sync_locations($sender,$arr,$absolute = false) { // New hub claiming to be primary. Make it so by removing any existing primaries. if(intval($location['primary'])) { - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d), hubloc_updated = '%s' where hubloc_hash = '%s' and (hubloc_flags & %d )>0", - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1", dbesc(datetime_convert()), - dbesc($sender['hash']), - intval(HUBLOC_FLAGS_PRIMARY) + dbesc($sender['hash']) ); } logger('sync_locations: new hub: ' . $location['url']); - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_updated, hubloc_connected) values ( '%s','%s','%s','%s', '%s', %d ,'%s','%s','%s','%s','%s','%s','%s')", dbesc($sender['guid']), dbesc($sender['guid_sig']), dbesc($sender['hash']), dbesc($location['address']), dbesc('zot'), - intval((intval($location['primary'])) ? HUBLOC_FLAGS_PRIMARY : 0), + intval($location['primary']), dbesc($location['url']), dbesc($location['url_sig']), dbesc($location['host']), @@ -2017,18 +2012,16 @@ function zot_encode_locations($channel) { $x = zot_get_hublocs($channel['channel_hash']); if($x && count($x)) { foreach($x as $hub) { - if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) { - $ret[] = array( - 'host' => $hub['hubloc_host'], - 'address' => $hub['hubloc_addr'], - 'primary' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false), - 'url' => $hub['hubloc_url'], - 'url_sig' => $hub['hubloc_url_sig'], - 'callback' => $hub['hubloc_callback'], - 'sitekey' => $hub['hubloc_sitekey'], - 'deleted' => (intval($hub['hubloc_deleted']) ? true : false) - ); - } + $ret[] = array( + 'host' => $hub['hubloc_host'], + 'address' => $hub['hubloc_addr'], + 'primary' => (intval($hub['hubloc_primary']) ? true : false), + 'url' => $hub['hubloc_url'], + 'url_sig' => $hub['hubloc_url_sig'], + 'callback' => $hub['hubloc_callback'], + 'sitekey' => $hub['hubloc_sitekey'], + 'deleted' => (intval($hub['hubloc_deleted']) ? true : false) + ); } } return $ret; @@ -2843,10 +2836,9 @@ function get_rpost_path($observer) { function import_author_zot($x) { $hash = make_xchan_hash($x['guid'],$x['guid_sig']); - $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and (hubloc_flags & %d)>0 limit 1", + $r = q("select hubloc_url from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_primary = 1 limit 1", dbesc($x['guid']), - dbesc($x['guid_sig']), - intval(HUBLOC_FLAGS_PRIMARY) + dbesc($x['guid_sig']) ); if($r) { diff --git a/mod/import.php b/mod/import.php index c9a4edb67..bd95311df 100644 --- a/mod/import.php +++ b/mod/import.php @@ -200,8 +200,8 @@ function import_post(&$a) { 'url' => $hubloc['hubloc_url'], 'url_sig' => $hubloc['hubloc_url_sig'] ); - if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && ($hubloc['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && ($seize)) - $hubloc['hubloc_flags'] = ($hubloc['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY); + if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) + $hubloc['hubloc_primary'] = 0; if(! zot_gethub($arr)) { unset($hubloc['hubloc_id']); @@ -220,7 +220,7 @@ function import_post(&$a) { // create new hubloc for the new channel at this site - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey ) values ( '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s' )", dbesc($channel['channel_guid']), @@ -228,7 +228,7 @@ function import_post(&$a) { dbesc($channel['channel_hash']), dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), dbesc('zot'), - intval(($seize) ? HUBLOC_FLAGS_PRIMARY : 0), + intval(($seize) ? 1 : 0), dbesc(z_root()), dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), dbesc(get_app()->get_hostname()), @@ -239,9 +239,7 @@ function import_post(&$a) { // reset the original primary hubloc if it is being seized if($seize) - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' and hubloc_url != '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ", dbesc($channel['channel_hash']), dbesc(z_root()) ); diff --git a/mod/locs.php b/mod/locs.php index 352112e3a..deb784100 100644 --- a/mod/locs.php +++ b/mod/locs.php @@ -19,13 +19,10 @@ function locs_post(&$a) { notice( t('Location not found.') . EOL); return; } - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' ", dbesc($channel['channel_hash']) ); - $r = q("update hubloc set hubloc_flags = (hubloc_flags & %d) where hubloc_id = %d and hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 1 where hubloc_id = %d and hubloc_hash = '%s'", intval($hubloc_id), dbesc($channel['channel_hash']) ); @@ -37,7 +34,7 @@ function locs_post(&$a) { if($_REQUEST['drop']) { $hubloc_id = intval($_REQUEST['drop']); if($hubloc_id) { - $r = q("select hubloc_id, hubloc_flags from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", + $r = q("select * from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", intval($hubloc_id), dbesc(z_root()), dbesc($channel['channel_hash']) @@ -46,7 +43,7 @@ function locs_post(&$a) { notice( t('Location not found.') . EOL); return; } - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) { + if(intval($r[0]['hubloc_primary'])) { notice( t('Primary location cannot be removed.') . EOL); return; } @@ -83,7 +80,7 @@ function locs_content(&$a) { for($x = 0; $x < count($r); $x ++) { - $r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false); + $r[$x]['primary'] = (intval($r[$x]['hubloc_primary']) ? true : false); $r[$x]['deleted'] = (intval($r[$x]['hubloc_deleted']) ? true : false); } -- cgit v1.2.3 From 51848c619080e19cace647966a17eb9a1b42ca25 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 Jan 2015 19:33:19 -0800 Subject: working through the xchan table to remove bitfields, mostly complete except for updating the updater --- boot.php | 30 --------------------- include/Contact.php | 16 ++++------- include/dir_fns.php | 16 +++-------- include/group.php | 3 +-- include/hubloc.php | 10 +++++-- include/identity.php | 8 +++--- include/socgraph.php | 12 +++------ include/text.php | 13 +++++---- include/zot.php | 70 ++++++++++++++++++------------------------------- mod/acl.php | 30 +++++++++------------ mod/admin.php | 8 +++--- mod/connections.php | 13 ++++----- mod/dirsearch.php | 22 +++++----------- mod/group.php | 6 ++--- mod/manage.php | 5 ++-- mod/openid.php | 7 +++-- mod/ping.php | 10 +++---- mod/post.php | 16 +++-------- mod/viewconnections.php | 13 +++++---- mod/zfinger.php | 2 +- 20 files changed, 107 insertions(+), 203 deletions(-) diff --git a/boot.php b/boot.php index bca90fd27..95044a63b 100755 --- a/boot.php +++ b/boot.php @@ -401,36 +401,6 @@ define ( 'VNOTIFY_INTRO', 0x0200 ); define ( 'VNOTIFY_REGISTER', 0x0400 ); -// We need a flag to designate that a site is a -// global directory mirror, but probably doesn't -// belong in hubloc. -// This indicates a need for an 'xsite' table -// which contains only sites and not people. -// Then we might have to revisit hubloc as a -// linked structure between xchan and xsite - -define ( 'HUBLOC_FLAGS_PRIMARY', 0x0001); -define ( 'HUBLOC_FLAGS_UNVERIFIED', 0x0002); -define ( 'HUBLOC_FLAGS_ORPHANCHECK', 0x0004); -define ( 'HUBLOC_FLAGS_DELETED', 0x1000); - -define ( 'XCHAN_FLAGS_NORMAL', 0x0000); -define ( 'XCHAN_FLAGS_HIDDEN', 0x0001); -define ( 'XCHAN_FLAGS_ORPHAN', 0x0002); -define ( 'XCHAN_FLAGS_CENSORED', 0x0004); -define ( 'XCHAN_FLAGS_SELFCENSORED', 0x0008); -define ( 'XCHAN_FLAGS_SYSTEM', 0x0010); -define ( 'XCHAN_FLAGS_PUBFORUM', 0x0020); -define ( 'XCHAN_FLAGS_DELETED', 0x1000); -/* - * Traficlights for Administration of HubLoc - * to detect problems in inter server communication - */ -define ('HUBLOC_NOTUSED', 0x0000); -define ('HUBLOC_SEND_ERROR', 0x0001); -define ('HUBLOC_RECEIVE_ERROR', 0x0002); -define ('HUBLOC_WORKS', 0x0004); -define ('HUBLOC_OFFLINE', 0x0008); /** * Tag/term types diff --git a/include/Contact.php b/include/Contact.php index c872dc913..b01ac0174 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -276,8 +276,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { ); - $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", - intval(XCHAN_FLAGS_DELETED), + $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", dbesc($channel['channel_hash']) ); @@ -326,8 +325,7 @@ function channel_remove($channel_id, $local = true, $unset_session=true) { $hublocs = count($r); if(! $hublocs) { - $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' ", - intval(XCHAN_FLAGS_DELETED), + $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s' ", dbesc($channel['channel_hash']) ); } @@ -402,9 +400,7 @@ function mark_orphan_hubsxchans() { // yes - if the xchan was marked as an orphan, undo it - $y = q("update xchan set xchan_flags = (xchan_flags & ~%d) where (xchan_flags & %d)>0 and xchan_hash = '%s'", - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_ORPHAN), + $y = q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'", dbesc($rr['hubloc_hash']) ); @@ -413,8 +409,7 @@ function mark_orphan_hubsxchans() { // nope - mark the xchan as an orphan - $y = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", - intval(XCHAN_FLAGS_ORPHAN), + $y = q("update xchan set xchan_orphan = 1 where xchan_hash = '%s'", dbesc($rr['hubloc_hash']) ); } @@ -494,8 +489,7 @@ function remove_all_xchan_resources($xchan, $channel_id = 0) { dbesc($xchan) ); - $r = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", - intval(XCHAN_FLAGS_DELETED), + $r = q("update xchan set xchan_deleted = 1 where xchan_hash = '%s'", dbesc($xchan) ); } diff --git a/include/dir_fns.php b/include/dir_fns.php index 6d06fddd1..86be8662c 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -295,23 +295,15 @@ function local_dir_update($uid,$force) { logger('hidden: ' . $hidden); - $r = q("select xchan_flags from xchan where xchan_hash = '%s' limit 1", + $r = q("select xchan_hidden from xchan where xchan_hash = '%s' limit 1", dbesc($p[0]['channel_hash']) ); - // Be careful - XCHAN_FLAGS_HIDDEN should evaluate to 1 - if(($r[0]['xchan_flags'] & XCHAN_FLAGS_HIDDEN) != $hidden) - $new_flags = $r[0]['xchan_flags'] ^ XCHAN_FLAGS_HIDDEN; - else - $new_flags = $r[0]['xchan_flags']; - - if($new_flags != $r[0]['xchan_flags']) { - - $r = q("update xchan set xchan_flags = %d where xchan_hash = '%s'", - intval($new_flags), + if(intval($r[0]['xchan_hidden']) != $hidden) { + $r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'", + intval($hidden), dbesc($p[0]['channel_hash']) ); - } $address = $p[0]['channel_address'] . '@' . get_app()->get_hostname(); diff --git a/include/group.php b/include/group.php index 28cf5d80d..08361a81d 100644 --- a/include/group.php +++ b/include/group.php @@ -200,11 +200,10 @@ function group_get_members($gid) { if(intval($gid)) { $r = q("SELECT * FROM `group_member` LEFT JOIN abook ON abook_xchan = `group_member`.`xchan` left join xchan on xchan_hash = abook_xchan - WHERE `gid` = %d AND abook_channel = %d and `group_member`.`uid` = %d and not ( xchan_flags & %d )>0 and not ( abook_flags & %d )>0 and not ( abook_flags & %d )>0 ORDER BY xchan_name ASC ", + WHERE `gid` = %d AND abook_channel = %d and `group_member`.`uid` = %d and xchan_deleted = 0 and not ( abook_flags & %d )>0 and not ( abook_flags & %d )>0 ORDER BY xchan_name ASC ", intval($gid), intval(local_user()), intval(local_user()), - intval(XCHAN_FLAGS_DELETED), intval(ABOOK_FLAG_BLOCKED), intval(ABOOK_FLAG_PENDING) ); diff --git a/include/hubloc.php b/include/hubloc.php index cde166e8d..2367744ec 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -193,7 +193,7 @@ function xchan_store($arr) { 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') ", + $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_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s','%s',%d, %d, %d, %d, %d, %d, %d, '%s') ", dbesc($arr['hash']), dbesc($arr['guid']), dbesc($arr['guid_sig']), @@ -206,7 +206,13 @@ function xchan_store($arr) { dbesc($arr['name']), dbesc($arr['network']), dbesc($arr['instance_url']), - intval($arr['flags']), + intval($arr['hidden']), + intval($arr['orphan']), + intval($arr['censored']), + intval($arr['selfcensored']), + intval($arr['system']), + intval($arr['pubforum']), + intval($arr['deleted']), dbesc(datetime_convert()) ); if(! $r) diff --git a/include/identity.php b/include/identity.php index f5a729573..e196cb247 100644 --- a/include/identity.php +++ b/include/identity.php @@ -99,7 +99,7 @@ function create_sys_channel() { 'name' => 'System', 'pageflags' => PAGE_SYSTEM, 'publish' => 0, - 'xchanflags' => XCHAN_FLAGS_SYSTEM + 'system' => 1 )); } @@ -185,7 +185,7 @@ function create_identity($arr) { $name = escape_tags($arr['name']); $pageflags = ((x($arr,'pageflags')) ? intval($arr['pageflags']) : PAGE_NORMAL); - $xchanflags = ((x($arr,'xchanflags')) ? intval($arr['xchanflags']) : XCHAN_FLAGS_NORMAL); + $system = ((x($arr,'system')) ? intval($arr['system']) : 0); $name_error = validate_channelname($arr['name']); if($name_error) { $ret['message'] = $name_error; @@ -312,7 +312,7 @@ function create_identity($arr) { $newuid = $ret['channel']['channel_id']; - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_flags ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_system ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", dbesc($hash), dbesc($guid), dbesc($sig), @@ -328,7 +328,7 @@ function create_identity($arr) { dbesc('zot'), dbesc(datetime_convert()), dbesc(datetime_convert()), - intval($xchanflags) + intval($system) ); // Not checking return value. diff --git a/include/socgraph.php b/include/socgraph.php index 15ef480f6..466f4212d 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -340,14 +340,12 @@ function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) { and not xlink_link in ( select abook_xchan from abook where abook_channel = %d ) and not xlink_link in ( select xchan from xign where uid = %d ) and xlink_xchan != '' - and not ( xchan_flags & %d )>0 - and not ( xchan_flags & %d )>0 + and xchan_hidden = 0 + and xchan_deleted = 0 group by xchan_hash order by total desc limit %d offset %d ", intval($uid), intval($uid), intval($uid), - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_DELETED), intval($limit), intval($start) ); @@ -360,13 +358,11 @@ function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) { where xlink_xchan = '' and not xlink_link in ( select abook_xchan from abook where abook_channel = %d ) and not xlink_link in ( select xchan from xign where uid = %d ) - and not ( xchan_flags & %d )>0 - and not ( xchan_flags & %d )>0 + and xchan_hidden = 0 + and xchan_deleted = 0 group by xchan_hash order by total desc limit %d offset %d ", intval($uid), intval($uid), - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_DELETED), intval($limit), intval($start) ); diff --git a/include/text.php b/include/text.php index fcd7b422c..720895810 100644 --- a/include/text.php +++ b/include/text.php @@ -728,20 +728,20 @@ function contact_block() { return; $is_owner = ((local_user() && local_user() == $a->profile['uid']) ? true : false); + $sql_extra = ''; $abook_flags = ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF; - $xchan_flags = XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED; + if(! $is_owner) { $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN; - $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN; + $sql_extra = " and xchan_hidden = 0 "; } if((! is_array($a->profile)) || ($a->profile['hide_friends'])) return $o; - $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and not ( abook_flags & %d )>0 and not (xchan_flags & %d)>0", + $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and not ( abook_flags & %d )>0 and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra", intval($a->profile['uid']), - intval($abook_flags), - intval($xchan_flags) + intval($abook_flags) ); if(count($r)) { $total = intval($r[0]['total']); @@ -755,10 +755,9 @@ function contact_block() { } else { $randfunc = 'RAND()'; } - $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND not ( abook_flags & %d)>0 and not (xchan_flags & %d )>0 ORDER BY $randfunc LIMIT %d", + $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND not ( abook_flags & %d)>0 and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra ORDER BY $randfunc LIMIT %d", intval($a->profile['uid']), intval($abook_flags|ABOOK_FLAG_ARCHIVED), - intval($xchan_flags), intval($shown) ); diff --git a/include/zot.php b/include/zot.php index debd2c8a8..9cb6c47d8 100644 --- a/include/zot.php +++ b/include/zot.php @@ -705,43 +705,36 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { $hidden = (1 - intval($arr['searchable'])); - // Be careful - XCHAN_FLAGS_HIDDEN should evaluate to 1 - if(($r[0]['xchan_flags'] & XCHAN_FLAGS_HIDDEN) != $hidden) - $new_flags = $r[0]['xchan_flags'] ^ XCHAN_FLAGS_HIDDEN; - else - $new_flags = $r[0]['xchan_flags']; - - $adult = (($r[0]['xchan_flags'] & XCHAN_FLAGS_SELFCENSORED) ? true : false); - $adult_changed = ((intval($adult) != intval($arr['adult_content'])) ? true : false); - if($adult_changed) - $new_flags = $new_flags ^ XCHAN_FLAGS_SELFCENSORED; + $hidden_changed = $adult_changed = $deleted_changed = $pubforum_changed = 0; - $deleted = (($r[0]['xchan_flags'] & XCHAN_FLAGS_DELETED) ? true : false); - $deleted_changed = ((intval($deleted) != intval($arr['deleted'])) ? true : false); - if($deleted_changed) - $new_flags = $new_flags ^ XCHAN_FLAGS_DELETED; - - $public_forum = (($r[0]['xchan_flags'] & XCHAN_FLAGS_PUBFORUM) ? true : false); - $pubforum_changed = ((intval($public_forum) != intval($arr['public_forum'])) ? true : false); - if($pubforum_changed) - $new_flags = $r[0]['xchan_flags'] ^ XCHAN_FLAGS_PUBFORUM; + if(intval($r[0]['xchan_hidden']) != (1 - intval($arr['searchable']))) + $hidden_changed = 1; + if(intval($r[0]['xchan_selfcensored']) != intval($arr['adult_content'])) + $adult_changed = 1; + if(intval($r[0]['xchan_deleted']) != intval($arr['deleted'])) + $deleted_changed = 1; + if(intval($r[0]['xchan_pubforum']) != intval($arr['public_forum'])) + $pubforum_changed = 1; if(($r[0]['xchan_name_date'] != $arr['name_updated']) || ($r[0]['xchan_connurl'] != $arr['connections_url']) - || ($r[0]['xchan_flags'] != $new_flags) || ($r[0]['xchan_addr'] != $arr['address']) || ($r[0]['xchan_follow'] != $arr['follow_url']) || ($r[0]['xchan_connpage'] != $arr['connect_url']) - || ($r[0]['xchan_url'] != $arr['url'])) { + || ($r[0]['xchan_url'] != $arr['url']) + || $hidden_changed || adult_changed || deleted_changed || $pubforum_changed ) { $r = q("update xchan set xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_follow = '%s', - xchan_connpage = '%s', xchan_flags = %d, + xchan_connpage = '%s', xchan_hidden = %d, xchan_selfcensored = %d, xchan_deleted = %d, xchan_pubforum = %d, xchan_addr = '%s', xchan_url = '%s' where xchan_hash = '%s'", dbesc(($arr['name']) ? $arr['name'] : '-'), dbesc($arr['name_updated']), dbesc($arr['connections_url']), dbesc($arr['follow_url']), dbesc($arr['connect_url']), - intval($new_flags), + intval(1 - intval($arr['searchable'])), + intval($arr['adult_content']), + intval($arr['deleted']), + intval($arr['public_forum']), dbesc($arr['address']), dbesc($arr['url']), dbesc($xchan_hash) @@ -761,20 +754,9 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { && ($arr['site']['url'] != z_root())) $arr['searchable'] = false; - $hidden = (1 - intval($arr['searchable'])); - - if($hidden) - $new_flags = XCHAN_FLAGS_HIDDEN; - else - $new_flags = 0; - if($arr['adult_content']) - $new_flags |= XCHAN_FLAGS_SELFCENSORED; - if(array_key_exists('deleted',$arr) && $arr['deleted']) - $new_flags |= XCHAN_FLAGS_DELETED; - $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, - xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_flags) - values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d) ", + xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_selfcensored, xchan_deleted, xchan_pubforum, ) + values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d) ", dbesc($xchan_hash), dbesc($arr['guid']), dbesc($arr['guid_sig']), @@ -790,7 +772,10 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { dbesc('zot'), dbescdate($arr['photo_updated']), dbescdate($arr['name_updated']), - intval($new_flags) + intval(1 - intval($arr['searchable'])), + intval($arr['adult_content']), + intval($arr['deleted']), + intval($arr['public_forum']) ); $what .= 'new_xchan'; @@ -1433,11 +1418,11 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque if(($channel['channel_pageflags'] & PAGE_SYSTEM) && (! $arr['item_private'])) { $local_public = true; - $r = q("select xchan_flags from xchan where xchan_hash = '%s' limit 1", + $r = q("select xchan_selfcensored from xchan where xchan_hash = '%s' limit 1", dbesc($sender['hash']) ); // don't import sys channel posts from selfcensored authors - if($r && ($r[0]['xchan_flags'] & XCHAN_FLAGS_SELFCENSORED)) { + if($r && (intval($r[0]['xchan_selfcensored']))) { $local_public = false; continue; } @@ -1890,9 +1875,7 @@ function sync_locations($sender,$arr,$absolute = false) { intval($r[0]['hubloc_id']) ); } - q("update xchan set xchan_flags = (xchan_flags & ~%d) where (xchan_flags & %d)>0 and xchan_hash = '%s'", - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_ORPHAN), + q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'", dbesc($sender['hash']) ); } @@ -2078,8 +2061,7 @@ function import_directory_profile($hash,$profile,$addr,$ud_flags = UPDATE_FLAGS_ if(in_arrayi('nsfw',$clean) || in_arrayi('adult',$clean)) { - q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s'", - intval(XCHAN_FLAGS_SELFCENSORED), + q("update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'", dbesc($hash) ); } diff --git a/mod/acl.php b/mod/acl.php index d406942c3..a1ed177c8 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -94,18 +94,17 @@ function acl_init(&$a){ $r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags FROM abook left join xchan on abook_xchan = xchan_hash - WHERE (abook_channel = %d $extra_channels_sql) AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , + WHERE (abook_channel = %d $extra_channels_sql) AND not ( abook_flags & %d )>0 and xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" , intval(local_user()), - intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED), - intval(XCHAN_FLAGS_DELETED) + intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED) ); } else { // Visitors $r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags FROM xchan left join xlink on xlink_link = xchan_hash - WHERE xlink_xchan = '%s' AND NOT (xchan_flags & %d) > 0 $sql_extra2 order by $order_extra2 xchan_name asc" , - dbesc(get_observer_hash()), - intval(XCHAN_FLAGS_DELETED)); + WHERE xlink_xchan = '%s' AND xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" , + dbesc(get_observer_hash()) + ); // Find contacts of extra channels // This is probably more complicated than it needs to be @@ -119,9 +118,8 @@ function acl_init(&$a){ $r2 = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , - intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_HIDDEN), - intval(XCHAN_FLAGS_DELETED) + WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND not ( abook_flags & %d )>0 and xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" , + intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_HIDDEN) ); if($r2) $r = array_merge($r,$r2); @@ -151,8 +149,7 @@ function acl_init(&$a){ if((! $r) && $type == 'c') { $r = q("SELECT substr(xchan_hash,1,18) as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags FROM xchan - WHERE not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , - intval(XCHAN_FLAGS_DELETED) + WHERE xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" ); } } @@ -162,23 +159,20 @@ function acl_init(&$a){ $r = q("SELECT xchan_hash as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and ( (abook_their_perms = null) or (abook_their_perms & %d )>0) - and not (xchan_flags & %d)>0 + and xchan_deleted = 0 $sql_extra3 ORDER BY `xchan_name` ASC ", intval(local_user()), - intval(PERMS_W_MAIL), - intval(XCHAN_FLAGS_DELETED) + intval(PERMS_W_MAIL) ); } elseif(($type == 'a') || ($type == 'p')) { $r = q("SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag , abook_their_perms FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d - and not (xchan_flags & %d)>0 + and xchan_deleted = 0 $sql_extra3 ORDER BY xchan_name ASC ", - intval(local_user()), - intval(XCHAN_FLAGS_DELETED) - + intval(local_user()) ); } elseif($type == 'x') { diff --git a/mod/admin.php b/mod/admin.php index 1503bf18e..a4cb84a42 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -99,7 +99,7 @@ function admin_content(&$a) { 'channels' => Array($a->get_baseurl(true)."/admin/channels/", t("Channels") , "channels"), 'plugins' => Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), - 'hubloc' => Array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), +// 'hubloc' => Array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), 'profs' => array(z_root() . '/admin/profs', t('Profile Config'), 'profs'), 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") ); @@ -152,9 +152,9 @@ function admin_content(&$a) { case 'themes': $o = admin_page_themes($a); break; - case 'hubloc': - $o = admin_page_hubloc($a); - break; +// case 'hubloc': +// $o = admin_page_hubloc($a); +// break; case 'logs': $o = admin_page_logs($a); break; diff --git a/mod/connections.php b/mod/connections.php index d36734ccb..dae6fbd3e 100644 --- a/mod/connections.php +++ b/mod/connections.php @@ -214,11 +214,10 @@ function connections_content(&$a) { nav_set_selected('intros'); break; case 'ifpending': - $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", + $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or xchan_deleted = 1 or xchan_orphan = 1)", intval(local_user()), intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED) ); if($r && $r[0]['total']) { $search_flags = ABOOK_FLAG_PENDING; @@ -343,10 +342,9 @@ function connections_content(&$a) { } $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash - where abook_channel = %d and not (abook_flags & %d)>0 and not (xchan_flags & %d )>0 $sql_extra $sql_extra2 ", + where abook_channel = %d and not (abook_flags & %d)>0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 ", intval(local_user()), - intval(ABOOK_FLAG_SELF), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + intval(ABOOK_FLAG_SELF) ); if($r) { $a->set_pager_total($r[0]['total']); @@ -354,10 +352,9 @@ function connections_content(&$a) { } $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash - WHERE abook_channel = %d and not (abook_flags & %d)>0 and not ( xchan_flags & %d)>0 $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d OFFSET %d ", + WHERE abook_channel = %d and not (abook_flags & %d)>0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d OFFSET %d ", intval(local_user()), intval(ABOOK_FLAG_SELF), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN), intval($a->pager['itemspage']), intval($a->pager['start']) ); diff --git a/mod/dirsearch.php b/mod/dirsearch.php index a88db0a2c..947198466 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -112,7 +112,7 @@ function dirsearch_content(&$a) { $sql_extra .= dir_query_build($joiner,'xprof_keywords',$keywords); if($forums) - $sql_extra .= dir_flag_build($joiner,'xprof_flags',XCHAN_FLAGS_PUBFORUM, $forums); + $sql_extra .= dir_flag_build($joiner,'xchan_pubforum',$forums); // we only support an age range currently. You must set both agege @@ -158,20 +158,16 @@ function dirsearch_content(&$a) { } - $safesql = (($safe > 0) ? " and not ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " )>0 " : ''); + $safesql = (($safe > 0) ? " and xchan_censored = 0 and xchan_selfcensored = 0 " : ''); if($safe < 0) - $safesql = " and ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " )>0 "; + $safesql = " and ( xchan_censored = 1 OR xchan_selfcensored = 1 ) "; if($limit) $qlimit = " LIMIT $limit "; else { $qlimit = " LIMIT " . intval($startrec) . " , " . intval($perpage); if($return_total) { - $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and xchan_network = 'zot' and not ( xchan_flags & %d)>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $safesql ", - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED) - ); + $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and xchan_network = 'zot' and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 $safesql "); if($r) { $ret['total_items'] = $r[0]['total']; } @@ -213,11 +209,7 @@ function dirsearch_content(&$a) { json_return_and_die($spkt); } else { - $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) and xchan_network = 'zot' and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $safesql $order $qlimit ", - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED) - ); + $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) and xchan_network = 'zot' and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 $safesql $order $qlimit "); } $ret['page'] = $page + 1; @@ -234,7 +226,7 @@ function dirsearch_content(&$a) { $entry['name'] = $rr['xchan_name']; $entry['hash'] = $rr['xchan_hash']; - $entry['public_forum'] = (($rr['xchan_flags'] & XCHAN_FLAGS_PUBFORUM) ? true : false); + $entry['public_forum'] = (intval($rr['xchan_pubforum']) ? true : false); $entry['url'] = $rr['xchan_url']; $entry['photo_l'] = $rr['xchan_photo_l']; @@ -282,7 +274,7 @@ function dir_query_build($joiner,$field,$s) { } function dir_flag_build($joiner,$field,$bit,$s) { - return dbesc($joiner) . " ( " . dbesc('xchan_flags') . " & " . intval($bit) . " ) " . ((intval($s)) ? '>' : '=' ) . " 0 "; + return dbesc($joiner) . " ( " . dbesc($field) . " = " . intval($bit) . " ) "; } diff --git a/mod/group.php b/mod/group.php index f67623a83..36c31e355 100644 --- a/mod/group.php +++ b/mod/group.php @@ -117,10 +117,9 @@ function group_content(&$a) { check_form_security_token_ForbiddenOnErr('group_member_change', 't'); - $r = q("SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and not (xchan_flags & %d)>0 and not (abook_flags & %d)>0 and not (abook_flags & %d)>0 limit 1", + $r = q("SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and xchan_deleted = 0 and not (abook_flags & %d)>0 and not (abook_flags & %d)>0 limit 1", dbesc(base64url_decode(argv(2))), intval(local_user()), - intval(XCHAN_FLAGS_DELETED), intval(ABOOK_FLAG_BLOCKED), intval(ABOOK_FLAG_PENDING) ); @@ -211,10 +210,9 @@ function group_content(&$a) { group_rmv_member(local_user(),$group['name'],$member['xchan_hash']); } - $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND not (abook_flags & %d)>0 and not (xchan_flags & %d)>0 and not (abook_flags & %d)>0 order by xchan_name asc", + $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND not (abook_flags & %d)>0 and xchan_deleted = 0 and not (abook_flags & %d)>0 order by xchan_name asc", intval(local_user()), intval(ABOOK_FLAG_BLOCKED), - intval(XCHAN_FLAGS_DELETED), intval(ABOOK_FLAG_PENDING) ); diff --git a/mod/manage.php b/mod/manage.php index b6e10bf46..6797b4892 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -73,11 +73,10 @@ function manage_content(&$a) { } - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", + $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or xchan_deleted = 1 or xchan_orphan = 1)", intval($channels[$x]['channel_id']), intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED) ); if($intr) diff --git a/mod/openid.php b/mod/openid.php index 9752db440..b0f927f34 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -131,8 +131,8 @@ function openid_content(&$a) { $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, - xchan_name_date, xchan_flags) - values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d) ", + xchan_name_date, xchan_hidden) + values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 1) ", dbesc($url), dbesc(''), dbesc(''), @@ -147,8 +147,7 @@ function openid_content(&$a) { dbesc($name), dbesc($network), dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval(XCHAN_FLAGS_HIDDEN) + dbesc(datetime_convert()) ); if($x) { $r = q("select * from xchan where xchan_hash = '%s' limit 1", diff --git a/mod/ping.php b/mod/ping.php index 593ae21f8..e5fc4d930 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -300,11 +300,10 @@ function ping_init(&$a) { if(argc() > 1 && (argv(1) === 'intros')) { $result = array(); - $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0) ORDER BY abook_created DESC", + $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or xchan_deleted = 1 or xchan_orphan = 1) ORDER BY abook_created DESC", intval(local_user()), intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED) ); if($r) { @@ -413,11 +412,10 @@ function ping_init(&$a) { $t2 = dba_timer(); if($vnotify & VNOTIFY_INTRO) { - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0)", + $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or xchan_deleted = 1 or xchan_orphan = 1)", intval(local_user()), intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED) ); $t3 = dba_timer(); diff --git a/mod/post.php b/mod/post.php index 338cd71c0..15fd29607 100644 --- a/mod/post.php +++ b/mod/post.php @@ -260,23 +260,15 @@ function post_init(&$a) { $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); info(sprintf( t('Welcome %s. Remote authentication successful.'),$x[0]['xchan_name'])); logger('mod_zot: auth success from ' . $x[0]['xchan_addr']); - q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", - intval(HUBLOC_WORKS), - intval($x[0]['hubloc_id']) - ); - - } else { + } + else { if($test) { $ret['message'] .= 'auth failure. ' . print_r($_REQUEST,true) . print_r($j,true) . EOL; json_return_and_die($ret); } logger('mod_zot: magic-auth failure - not authenticated: ' . $x[0]['xchan_addr']); - q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", - intval(HUBLOC_RECEIVE_ERROR), - intval($x[0]['hubloc_id']) - ); } // FIXME - we really want to save the return_url in the session before we visit rmagic. @@ -675,9 +667,7 @@ function post_post(&$a) { intval($hub['hubloc_id']) ); } - q("update xchan set xchan_flags = (xchan_flags & ~%d) where (xchan_flags & %d)>0 and xchan_hash = '%s'", - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_ORPHAN), + q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'", dbesc($hub['hubloc_hash']) ); } diff --git a/mod/viewconnections.php b/mod/viewconnections.php index 40d26c823..d4731d8c4 100644 --- a/mod/viewconnections.php +++ b/mod/viewconnections.php @@ -31,25 +31,24 @@ function viewconnections_content(&$a) { $is_owner = ((local_user() && local_user() == $a->profile['uid']) ? true : false); $abook_flags = ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF; - $xchan_flags = XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED; + $sql_extra = ''; + if(! $is_owner) { $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN; - $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN; + $sql_extra = " and xchan_hidden = 0 "; } - $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d )>0 and not ( xchan_flags & %d )>0 ", + $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d )>0 and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra ", intval($a->profile['uid']), - intval($abook_flags), - intval($xchan_flags) + intval($abook_flags) ); if($r) { $a->set_pager_total($r[0]['total']); } - $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d )>0 and not ( xchan_flags & %d )>0 order by xchan_name LIMIT %d OFFSET %d ", + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d )>0 and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra order by xchan_name LIMIT %d OFFSET %d ", intval($a->profile['uid']), intval($abook_flags), - intval($xchan_flags), intval($a->pager['itemspage']), intval($a->pager['start']) ); diff --git a/mod/zfinger.php b/mod/zfinger.php index 6f4febc6f..bd124b951 100644 --- a/mod/zfinger.php +++ b/mod/zfinger.php @@ -103,7 +103,7 @@ function zfinger_init(&$a) { $adult_channel = (($e['channel_pageflags'] & PAGE_ADULT) ? true : false); $censored = (($e['channel_pageflags'] & PAGE_CENSORED) ? true : false); $searchable = (($e['channel_pageflags'] & PAGE_HIDDEN) ? false : true); - $deleted = (($e['xchan_flags'] & XCHAN_FLAGS_DELETED) ? true : false); + $deleted = (intval($e['xchan_deleted']) ? true : false); if($deleted || $censored) $searchable = false; -- cgit v1.2.3 From 29436081a86650e7905a79eba4fdf7dc12f1c7c9 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 21 Jan 2015 16:06:25 -0800 Subject: slow progress removing bitfields on item table --- boot.php | 2 +- include/Import/refimport.php | 8 +++-- include/activities.php | 5 ++- include/attach.php | 9 ++++-- include/bb2diaspora.php | 16 ---------- include/diaspora.php | 15 +++------ include/event.php | 54 ++++++++++++++++--------------- include/externals.php | 20 ------------ include/items.php | 27 ++++++++-------- include/notifier.php | 3 +- include/photos.php | 76 +++++++++++++++++++++++--------------------- include/zot.php | 2 +- mod/connedit.php | 4 ++- mod/item.php | 22 ++++++------- mod/like.php | 11 ++++--- mod/mood.php | 12 +++---- mod/poke.php | 10 ++++-- mod/subthread.php | 29 ++++++++--------- mod/tagger.php | 6 ++-- mod/thing.php | 4 ++- 20 files changed, 156 insertions(+), 179 deletions(-) diff --git a/boot.php b/boot.php index 95044a63b..b3bed8592 100755 --- a/boot.php +++ b/boot.php @@ -536,7 +536,7 @@ define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has * Item Flags */ -define ( 'ITEM_ORIGIN', 0x0001); +//define ( 'ITEM_ORIGIN', 0x0001); define ( 'ITEM_UNSEEN', 0x0002); define ( 'ITEM_STARRED', 0x0004); define ( 'ITEM_UPLINK', 0x0008); diff --git a/include/Import/refimport.php b/include/Import/refimport.php index 181b2b398..a7c0ef4c8 100644 --- a/include/Import/refimport.php +++ b/include/Import/refimport.php @@ -88,7 +88,10 @@ function refimport_content(&$a) { $arr['author_xchan'] = $channel['channel_hash']; $arr['owner_xchan'] = $channel['channel_hash']; $arr['app'] = REFLECT_BLOGNAME; - $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_thread_top'] = 1; + $arr['verb'] = ACTIVITY_POST; // this is an assumption @@ -256,7 +259,8 @@ function reflect_comment_store($channel,$post,$comment,$user) { $arr['edited'] = $comment['created']; $arr['author_xchan'] = $hash; $arr['owner_xchan'] = $channel['channel_hash']; - $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; $arr['verb'] = ACTIVITY_POST; $arr['comment_policy'] = 'contacts'; diff --git a/include/activities.php b/include/activities.php index d770ccb23..ba12bc5d1 100644 --- a/include/activities.php +++ b/include/activities.php @@ -21,7 +21,10 @@ function profile_activity($changed, $value) { $arr['uid'] = local_user(); $arr['aid'] = $self['channel_account_id']; $arr['owner_xchan'] = $arr['author_xchan'] = $self['xchan_hash']; - $arr['item_flags'] = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; + $arr['item_wall'] = 1; + $arr['item_origin'] = 1; + $arr['item_thread_top'] = 1; + $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = ACTIVITY_OBJ_PROFILE; diff --git a/include/attach.php b/include/attach.php index 5ef3bea24..5a945dd66 100644 --- a/include/attach.php +++ b/include/attach.php @@ -954,7 +954,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $mid = item_message_id(); - $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; + $arr['item_wall'] = 1; + $arr['item_origin'] = 1; + $arr['item_unseen'] = 1; if($action == 'post') { //check if activity item exists @@ -975,7 +977,6 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $arr['uid'] = $channel_id; $arr['mid'] = $dmid; $arr['parent_mid'] = $dmid; - $arr['item_flags'] = $item_flags; $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; @@ -1016,7 +1017,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $arr['uid'] = $channel_id; $arr['mid'] = $mid; $arr['parent_mid'] = $mid; - $arr['item_flags'] = $item_flags; + $arr['item_wall'] = 1; + $arr['item_origin'] = 1; + $arr['item_unseen'] = 1; $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 5c93ac3aa..e8f81aec4 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -271,22 +271,6 @@ function bb2diaspora_itemwallwall(&$item) { . $item['body']; } - // 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. - - // 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['author'] might cause a surprise further down the line if it wasn't expected to be here. if(! $author_exists) diff --git a/include/diaspora.php b/include/diaspora.php index e494aac0f..ae405f663 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1414,7 +1414,7 @@ function diaspora_comment($importer,$xml,$msg) { if($result && $result['success']) $message_id = $result['item_id']; - if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { + if(intval($parent_item['item_origin']) && (! $parent_author_signature)) { // if the message isn't already being relayed, notify others // the existence of parent_author_signature means the parent_author or owner // is already relaying. @@ -1996,7 +1996,7 @@ function diaspora_like($importer,$xml,$msg) { // the existence of parent_author_signature means the parent_author or owner // is already relaying. The parent_item['origin'] indicates the message was created on our system - if(($parent_item['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) + if(intval($parent_item['item_origin']) && (! $parent_author_signature)) proc_run('php','include/notifier.php','comment-import',$message_id); return; @@ -2105,19 +2105,12 @@ function diaspora_signed_retraction($importer,$xml,$msg) { $r[0]['parent'] ); if($p) { - if(($p[0]['item_flags'] & ITEM_ORIGIN) && (! $parent_author_signature)) { -// FIXME so we can relay this -// q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", -// $r[0]['id'], -// dbesc($signed_data), -// dbesc($sig), -// dbesc($diaspora_handle) -// ); + if(intval($p[0]['item_origin']) && (! $parent_author_signature)) { // the existence of parent_author_signature would have meant the parent_author or owner // is already relaying. - logger('diaspora_signed_retraction: relaying relayable_retraction'); + logger('diaspora_signed_retraction: relaying relayable_retraction'); proc_run('php','include/notifier.php','drop',$r[0]['id']); } } diff --git a/include/event.php b/include/event.php index 1ed541d99..9da7a42a9 100644 --- a/include/event.php +++ b/include/event.php @@ -456,53 +456,55 @@ function event_store_item($arr,$event) { $private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0); - + + $item_wall = 0; + $item_origin = 0; + $item_thread_top = 0; if($item) { $item_arr['id'] = $item['id']; } else { $wall = (($z[0]['channel_hash'] == $event['event_xchan']) ? true : false); - - $item_flags = ITEM_THREAD_TOP; + $item_thread_top = 1; if($wall) { - $item_flags |= ITEM_WALL; - $item_flags |= ITEM_ORIGIN; + $item_wall = 1; + $item_origin = 1; } - $item_arr['item_flags'] = $item_flags; } if(! $arr['mid']) $arr['mid'] = item_message_id(); - $item_arr['aid'] = $z[0]['channel_account_id']; - $item_arr['uid'] = $arr['uid']; - $item_arr['author_xchan'] = $arr['event_xchan']; - $item_arr['mid'] = $arr['mid']; - $item_arr['parent_mid'] = $arr['mid']; + $item_arr['aid'] = $z[0]['channel_account_id']; + $item_arr['uid'] = $arr['uid']; + $item_arr['author_xchan'] = $arr['event_xchan']; + $item_arr['mid'] = $arr['mid']; + $item_arr['parent_mid'] = $arr['mid']; - $item_arr['owner_xchan'] = (($wall) ? $z[0]['channel_hash'] : $arr['event_xchan']); - $item_arr['author_xchan'] = $arr['event_xchan']; - $item_arr['title'] = $arr['summary']; - $item_arr['allow_cid'] = $arr['allow_cid']; - $item_arr['allow_gid'] = $arr['allow_gid']; - $item_arr['deny_cid'] = $arr['deny_cid']; - $item_arr['deny_gid'] = $arr['deny_gid']; - $item_arr['item_private'] = $private; - $item_arr['verb'] = ACTIVITY_POST; + $item_arr['owner_xchan'] = (($wall) ? $z[0]['channel_hash'] : $arr['event_xchan']); + $item_arr['author_xchan'] = $arr['event_xchan']; + $item_arr['title'] = $arr['summary']; + $item_arr['allow_cid'] = $arr['allow_cid']; + $item_arr['allow_gid'] = $arr['allow_gid']; + $item_arr['deny_cid'] = $arr['deny_cid']; + $item_arr['deny_gid'] = $arr['deny_gid']; + $item_arr['item_private'] = $private; + $item_arr['verb'] = ACTIVITY_POST; + $item_arr['item_wall'] = $item_wall; + $item_arr['item_origin'] = $item_origin; + $item_arr['item_thread_top'] = $item_thread_top;; if(array_key_exists('term',$arr)) $item_arr['term'] = $arr['term']; - $item_arr['resource_type'] = 'event'; - $item_arr['resource_id'] = $event['event_hash']; - - $item_arr['obj_type'] = ACTIVITY_OBJ_EVENT; - - $item_arr['body'] = $prefix . format_event_bbcode($arr); + $item_arr['resource_type'] = 'event'; + $item_arr['resource_id'] = $event['event_hash']; + $item_arr['obj_type'] = ACTIVITY_OBJ_EVENT; + $item_arr['body'] = $prefix . format_event_bbcode($arr); // if it's local send the permalink to the channel page. // otherwise we'll fallback to /display/$message_id diff --git a/include/externals.php b/include/externals.php index b0f853dc6..3b6d170d5 100644 --- a/include/externals.php +++ b/include/externals.php @@ -93,26 +93,6 @@ function externals_run($argv, $argc){ $results = process_delivery(array('hash' => 'undefined'), get_item_elements($message), array(array('hash' => $sys['xchan_hash'])), false, true); $total ++; -// $z = q("select id from item where mid = '%s' and uid = %d limit 1", -// dbesc($message['message_id']), -// intval($sys['channel_id']) -// ); -$z = null; - if($z) { - $flag_bits = ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK; - // preserve the source - - $r = q("update item set source_xchan = owner_xchan where id = %d", - intval($z[0]['id']) - ); - - $r = q("update item set item_flags = ( item_flags | %d ), owner_xchan = '%s' - where id = %d", - intval($flag_bits), - dbesc($sys['xchan_hash']), - intval($z[0]['id']) - ); - } } logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG); } diff --git a/include/items.php b/include/items.php index fb2f2586a..b2fc05f09 100755 --- a/include/items.php +++ b/include/items.php @@ -364,13 +364,12 @@ function post_activity_item($arr) { if((($arr['parent']) && $arr['parent'] != $arr['id']) || (($arr['parent_mid']) && $arr['parent_mid'] != $arr['mid'])) $is_comment = true; - if(! x($arr,'item_flags')) { - if($is_comment) - $arr['item_flags'] = ITEM_ORIGIN; - else - $arr['item_flags'] = ITEM_ORIGIN | ITEM_WALL | ITEM_THREAD_TOP; - } - + if(! array_key_exists('item_origin',$arr)) + $arr['item_origin'] = 1; + if(! array_key_exists('item_wall',$arr) && (! $is_comment)) + $arr['item_wall'] = 1; + if(! array_key_exists('item_thread_top',$arr) && (! $is_comment)) + $arr['item_thread_top'] = 1; $channel = get_app()->get_channel(); $observer = get_app()->get_observer(); @@ -2917,10 +2916,7 @@ function tag_deliver($uid,$item_id) { // prevent delivery looping - only proceed // if the message originated elsewhere and is a top-level post - if(($item['item_flags'] & ITEM_WALL) - || ($item['item_flags'] & ITEM_ORIGIN) - || (!($item['item_flags'] & ITEM_THREAD_TOP)) - || ($item['id'] != $item['parent'])) { + if(intval($item['item_wall']) || intval($item['item_origin']) || (! intval($item['item_thread_top'])) || ($item['id'] != $item['parent'])) { logger('tag_deliver: item was local or a comment. rejected.'); return; } @@ -3039,7 +3035,10 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { if((! $private) && $new_public_policy) $private = 1; - $flag_bits = $item['item_flags'] | ITEM_WALL|ITEM_ORIGIN; + $item_wall = 1; + $item_origin = 1; + + $flag_bits = $item['item_flags']; // unset the nocomment bit if it's there. @@ -3087,7 +3086,7 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { } $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', - deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s' where id = %d", + deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s', item_wall = %d, item_origin = %d where id = %d", intval($flag_bits), dbesc($channel['channel_hash']), dbesc($channel['channel_allow_cid']), @@ -3099,6 +3098,8 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { dbesc(map_scope($channel['channel_w_comment'])), dbesc($title), dbesc($body), + intval($item_wall), + $intval($item_origin), intval($item_id) ); diff --git a/include/notifier.php b/include/notifier.php index 29646fb38..241dffbd1 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -362,7 +362,7 @@ function notifier_run($argv, $argc){ $encoded_item = encode_item($target_item); - $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false); + $relay_to_owner = (((! $top_level_post) && (intval($target_item['item_origin']))) ? true : false); $uplink = false; @@ -371,7 +371,6 @@ function notifier_run($argv, $argc){ logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'), LOGGER_DATA); logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'), LOGGER_DATA); - logger('notifier: target_item_flags: ' . $target_item['item_flags'] . ' ' . (($target_item['item_flags'] & ITEM_ORIGIN ) ? 'true' : 'false'), LOGGER_DATA); // tag_deliver'd post which needs to be sent back to the original author diff --git a/include/photos.php b/include/photos.php index 2393153c6..0ac47f7ba 100644 --- a/include/photos.php +++ b/include/photos.php @@ -225,30 +225,31 @@ function photo_upload($channel, $observer, $args) { // Create item container - $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; $item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN); $title = ''; $mid = item_message_id(); $arr = array(); - $arr['aid'] = $account_id; - $arr['uid'] = $channel_id; - $arr['mid'] = $mid; - $arr['parent_mid'] = $mid; - $arr['item_flags'] = $item_flags; - $arr['item_restrict'] = $item_restrict; - $arr['resource_type'] = 'photo'; - $arr['resource_id'] = $photo_hash; - $arr['owner_xchan'] = $channel['channel_hash']; - $arr['author_xchan'] = $observer['xchan_hash']; - $arr['title'] = $title; - $arr['allow_cid'] = $str_contact_allow; - $arr['allow_gid'] = $str_group_allow; - $arr['deny_cid'] = $str_contact_deny; - $arr['deny_gid'] = $str_group_deny; - $arr['verb'] = ACTIVITY_POST; - + $arr['aid'] = $account_id; + $arr['uid'] = $channel_id; + $arr['mid'] = $mid; + $arr['parent_mid'] = $mid; + $arr['item_flags'] = $item_flags; + $arr['item_restrict'] = $item_restrict; + $arr['resource_type'] = 'photo'; + $arr['resource_id'] = $photo_hash; + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + $arr['title'] = $title; + $arr['allow_cid'] = $str_contact_allow; + $arr['allow_gid'] = $str_group_allow; + $arr['deny_cid'] = $str_contact_deny; + $arr['deny_gid'] = $str_group_deny; + $arr['verb'] = ACTIVITY_POST; + $arr['item_wall'] = 1; + $arr['item_origin'] = 1; + $arr['item_thread_top'] = 1; $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; if ($width_x_height) @@ -431,7 +432,6 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { // Create item container - $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; $item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN); $title = ''; @@ -439,25 +439,27 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr = array(); - $arr['aid'] = $channel['channel_account_id']; - $arr['uid'] = $channel['channel_id']; - $arr['mid'] = $mid; - $arr['parent_mid'] = $mid; - $arr['item_flags'] = $item_flags; - $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['aid'] = $channel['channel_account_id']; + $arr['uid'] = $channel['channel_id']; + $arr['mid'] = $mid; + $arr['parent_mid'] = $mid; + $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['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/zot.php b/include/zot.php index 9cb6c47d8..435592b6a 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1549,7 +1549,7 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque $result[] = array($d['hash'],'update ignored',$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>',$arr['mid']); // We need this line to ensure wall-to-wall comments are relayed (by falling through to the relay bit), // and at the same time not relay any other relayable posts more than once, because to do so is very wasteful. - if(! ($r[0]['item_flags'] & ITEM_ORIGIN)) + if(! intval($r[0]['item_origin'])) continue; } } diff --git a/mod/connedit.php b/mod/connedit.php index c27f4588a..f5dba8a02 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -186,7 +186,9 @@ function connedit_post(&$a) { && (intval(get_pconfig($channel['channel_id'],'system','post_newfriend')))) { $xarr = array(); $xarr['verb'] = ACTIVITY_FRIEND; - $xarr['item_flags'] = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; + $xarr['item_wall'] = 1; + $xarr['item_origin'] = 1; + $xarr['item_thread_top'] = 1; $xarr['owner_xchan'] = $xarr['author_xchan'] = $channel['channel_hash']; $xarr['allow_cid'] = $channel['channel_allow_cid']; $xarr['allow_gid'] = $channel['channel_allow_gid']; diff --git a/mod/item.php b/mod/item.php index b3370fecf..152c10b13 100644 --- a/mod/item.php +++ b/mod/item.php @@ -281,7 +281,7 @@ function item_post(&$a) { // For comments, We need to additionally look at the parent and see if it's a wall post that originated locally. if($observer['xchan_name'] != $owner_xchan['xchan_name']) { - if($parent_item && ($parent_item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) { + if(($parent_item) && ($parent_item['item_wall'] && $parent_item['item_origin'])) { $walltowall_comment = true; $walltowall = true; } @@ -640,14 +640,10 @@ function item_post(&$a) { } } - if(local_user() != $profile_uid) - $item_flags |= ITEM_UNSEEN; - - if($post_type === 'wall' || $post_type === 'wall-comment') - $item_flags = $item_flags | ITEM_WALL; + $item_unseen = ((local_user() != $profile_uid) ? 1 : 0); + $item_wall = (($post_type === 'wall' || $post_type === 'wall-comment') ? 1 : 0); + $item_origin = (($origin) ? 1 : 0); - if($origin) - $item_flags = $item_flags | ITEM_ORIGIN; if($moderated) $item_restrict = $item_restrict | ITEM_MODERATED; @@ -678,11 +674,9 @@ function item_post(&$a) { $datarray = array(); - if(! $parent) { - $item_flags = $item_flags | ITEM_THREAD_TOP; - } + $item_thead_top = ((! $parent) ? 1 : 0); - if ((! $plink) && ($item_flags & ITEM_THREAD_TOP)) { + if ((! $plink) && ($item_thread_top)) { $plink = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $mid; } @@ -717,6 +711,10 @@ function item_post(&$a) { $datarray['postopts'] = $postopts; $datarray['item_restrict'] = $item_restrict; $datarray['item_flags'] = $item_flags; + $datarray['item_unseen'] = $item_unseen; + $datarray['item_wall'] = $item_wall; + $datarray['item_origin'] = $item_origin; + $datarray['item_thread_top'] = $item_thread_top; $datarray['layout_mid'] = $layout_mid; $datarray['public_policy'] = $public_policy; $datarray['comment_policy'] = map_scope($channel['channel_w_comment']); diff --git a/mod/like.php b/mod/like.php index b3afd910f..4d4d4249e 100755 --- a/mod/like.php +++ b/mod/like.php @@ -293,10 +293,12 @@ function like_content(&$a) { } $mid = item_message_id(); + $arr = array(); if($extended_like) { - $item_flags = ITEM_THREAD_TOP|ITEM_ORIGIN|ITEM_WALL; - + $arr['item_thread_top'] = 1; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; } else { $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); @@ -329,7 +331,9 @@ function like_content(&$a) { if(! ($item['item_flags'] & ITEM_THREAD_TOP)) $post_type = 'comment'; - $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; + $arr['item_origin'] = 1; + $arr['item_notshown'] = 1; + if($item['item_flags'] & ITEM_WALL) $item_flags |= ITEM_WALL; @@ -361,7 +365,6 @@ function like_content(&$a) { killme(); - $arr = array(); if($extended_like) { $ulink = '[zrl=' . $ch[0]['xchan_url'] . ']' . $ch[0]['xchan_name'] . '[/zrl]'; diff --git a/mod/mood.php b/mod/mood.php index e6f4760e0..bf59eac1f 100755 --- a/mod/mood.php +++ b/mod/mood.php @@ -61,10 +61,6 @@ function mood_init(&$a) { $mid = item_message_id(); $action = sprintf( t('%1$s is %2$s','mood'), '[zrl=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/zrl]' , $verbs[$verb]); - $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - if(! $parent_mid) - $item_flags |= ITEM_THREAD_TOP; - $arr = array(); @@ -72,7 +68,6 @@ function mood_init(&$a) { $arr['uid'] = $uid; $arr['mid'] = $mid; $arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid); - $arr['item_flags'] = $item_flags; $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = (($parent_mid) ? $r[0]['owner_xchan'] : $poster['xchan_hash']); $arr['title'] = ''; @@ -83,8 +78,13 @@ function mood_init(&$a) { $arr['item_private'] = $private; $arr['verb'] = $activity; $arr['body'] = $action; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_unseen'] = 1; + if(! $parent_mid) + $item['item_thread_top'] = 1; - if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) { + if ((! $arr['plink']) && intval($arr['item_thread_top'])) { $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; } diff --git a/mod/poke.php b/mod/poke.php index b22f7d9d5..9fde46f62 100755 --- a/mod/poke.php +++ b/mod/poke.php @@ -87,9 +87,6 @@ function poke_init(&$a) { $arr = array(); - $arr['item_flags'] = ITEM_WALL | ITEM_ORIGIN; - if($parent_item) - $arr['item_flags'] |= ITEM_THREAD_TOP; $arr['owner_xchan'] = (($parent_item) ? $parent_item['owner_xchan'] : $channel['channel_hash']); $arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid); @@ -115,6 +112,13 @@ function poke_init(&$a) { $arr['object'] = json_encode($obj); + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_unseen'] = 1; + if(! $parent_item) + $item['item_thread_top'] = 1; + + post_activity_item($arr); return; diff --git a/mod/subthread.php b/mod/subthread.php index f0f54f4a6..92ada64ad 100755 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -102,24 +102,23 @@ function subthread_content(&$a) { $bodyverb = t('%1$s is following %2$s\'s %3$s'); - $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; - if($item['item_flags'] & ITEM_WALL) - $item_flags |= ITEM_WALL; - - $arr = array(); - $arr['mid'] = $mid; - $arr['aid'] = $owner_aid; - $arr['uid'] = $owner_uid; - $arr['item_flags'] = $item_flags; - $arr['parent'] = $item['id']; - $arr['parent_mid'] = $item['mid']; - $arr['thr_parent'] = $item['mid']; - $arr['owner_xchan'] = $thread_owner['xchan_hash']; - $arr['author_xchan'] = $observer['xchan_hash']; + $arr['mid'] = $mid; + $arr['aid'] = $owner_aid; + $arr['uid'] = $owner_uid; + $arr['parent'] = $item['id']; + $arr['parent_mid'] = $item['mid']; + $arr['thr_parent'] = $item['mid']; + $arr['owner_xchan'] = $thread_owner['xchan_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + $arr['item_origin'] = 1; + $arr['item_notshown'] = 1; + if(intval($item['item_wall'])) + $arr['item_wall'] = 1; + else + $arr['item_wall'] = 0; - $ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]'; $alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]'; $plink = '[zrl=' . $a->get_baseurl() . '/display/' . $item['mid'] . ']' . $post_type . '[/zrl]'; diff --git a/mod/tagger.php b/mod/tagger.php index bfda114d2..83f6ee029 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -109,10 +109,8 @@ function tagger_content(&$a) { $arr['owner_xchan'] = $item['owner_xchan']; $arr['author_xchan'] = $channel['channel_hash']; - - $arr['item_flags'] = ITEM_ORIGIN; - if($item['item_flags'] & ITEM_WALL) - $arr['item_flags'] |= ITEM_WALL; + $arr['item_origin'] = 1; + $arr['item_wall'] = ((intval($item['item_wall'])) ? 1 : 0); $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; $alink = '[zrl=' . $item['xchan_url'] . ']' . $item['xchan_name'] . '[/zrl]'; diff --git a/mod/thing.php b/mod/thing.php index f53a6ab7b..4896c8a6e 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -182,8 +182,10 @@ function thing_init(&$a) { $arr['owner_xchan'] = $channel['channel_hash']; $arr['author_xchan'] = $channel['channel_hash']; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_thread_top'] = 1; - $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP; $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]'; -- cgit v1.2.3 From e46eba125888704b4381aa8418495e91eeb565c8 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Jan 2015 17:41:16 -0800 Subject: heavy lifting converting item flag bits --- boot.php | 22 ++++----- include/ConversationObject.php | 2 +- include/ItemObject.php | 14 +++--- include/api.php | 17 +++---- include/conversation.php | 2 +- include/diaspora.php | 4 +- include/enotify.php | 2 +- include/identity.php | 3 +- include/items.php | 104 +++++++++++++++++------------------------ include/notifier.php | 9 ++-- include/notify.php | 7 +-- include/statistics_fns.php | 9 ++-- include/taxonomy.php | 6 ++- include/widgets.php | 4 +- include/zot.php | 7 +-- mod/channel.php | 25 +++------- mod/display.php | 5 +- mod/events.php | 2 +- mod/home.php | 2 +- mod/item.php | 2 +- mod/like.php | 6 +-- mod/manage.php | 7 ++- mod/network.php | 16 +++---- mod/p.php | 5 +- mod/photos.php | 6 +-- mod/ping.php | 22 +++------ mod/starred.php | 8 ++-- mod/subthread.php | 3 +- 28 files changed, 129 insertions(+), 192 deletions(-) diff --git a/boot.php b/boot.php index b3bed8592..9544f70af 100755 --- a/boot.php +++ b/boot.php @@ -537,17 +537,17 @@ define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has */ //define ( 'ITEM_ORIGIN', 0x0001); -define ( 'ITEM_UNSEEN', 0x0002); -define ( 'ITEM_STARRED', 0x0004); -define ( 'ITEM_UPLINK', 0x0008); -define ( 'ITEM_CONSENSUS', 0x0010); // an item which may present agree/disagree/abstain options -define ( 'ITEM_WALL', 0x0020); -define ( 'ITEM_THREAD_TOP', 0x0040); -define ( 'ITEM_NOTSHOWN', 0x0080); // technically visible but not normally shown (e.g. like/dislike) -define ( 'ITEM_NSFW', 0x0100); -define ( 'ITEM_RELAY', 0x0200); // used only in the communication layers, not stored -define ( 'ITEM_MENTIONSME', 0x0400); -define ( 'ITEM_NOCOMMENT', 0x0800); // commenting/followups are disabled +//define ( 'ITEM_UNSEEN', 0x0002); +//define ( 'ITEM_STARRED', 0x0004); +//define ( 'ITEM_UPLINK', 0x0008); +//define ( 'ITEM_CONSENSUS', 0x0010); // an item which may present agree/disagree/abstain options +//define ( 'ITEM_WALL', 0x0020); +//define ( 'ITEM_THREAD_TOP', 0x0040); +//define ( 'ITEM_NOTSHOWN', 0x0080); // technically visible but not normally shown (e.g. like/dislike) +//define ( 'ITEM_NSFW', 0x0100); +//define ( 'ITEM_RELAY', 0x0200); // used only in the communication layers, not stored +//define ( 'ITEM_MENTIONSME', 0x0400); +//define ( 'ITEM_NOCOMMENT', 0x0800); // commenting/followups are disabled define ( 'ITEM_OBSCURED', 0x1000); // bit-mangled to protect from casual browsing by site admin define ( 'ITEM_VERIFIED', 0x2000); // Signature verification was successful define ( 'ITEM_RETAINED', 0x4000); // We looked at this item once to decide whether or not to expire it, and decided not to. diff --git a/include/ConversationObject.php b/include/ConversationObject.php index 7dc4c8c19..ada642482 100644 --- a/include/ConversationObject.php +++ b/include/ConversationObject.php @@ -166,7 +166,7 @@ class Conversation extends BaseObject { if(($item->get_data_value('author_xchan') === $ob_hash) || ($item->get_data_value('owner_xchan') === $ob_hash)) $item->set_commentable(true); - if($item->get_data_value('item_flags') & ITEM_NOCOMMENT) { + if(intval($item->get_data_value('item_nocomment'))) { $item->set_commentable(false); } elseif(($this->observer) && (! $item->is_commentable())) { diff --git a/include/ItemObject.php b/include/ItemObject.php index 82a321732..0bb125312 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -179,9 +179,9 @@ class Item extends BaseObject { 'do' => t("Add Star"), 'undo' => t("Remove Star"), 'toggle' => t("Toggle Star Status"), - 'classdo' => (($item['item_flags'] & ITEM_STARRED) ? "hidden" : ""), - 'classundo' => (($item['item_flags'] & ITEM_STARRED) ? "" : "hidden"), - 'isstarred' => (($item['item_flags'] & ITEM_STARRED) ? "starred icon-star" : "unstarred icon-star-empty"), + 'classdo' => (intval($item['item_starred']) ? "hidden" : ""), + 'classundo' => (intval($item['item_starred']) ? "" : "hidden"), + 'isstarred' => (intval($item['item_starred']) ? "starred icon-star" : "unstarred icon-star-empty"), 'starred' => t('starred'), ); @@ -191,9 +191,9 @@ class Item extends BaseObject { } - $verified = (($item['item_flags'] & ITEM_VERIFIED) ? t('Message signature validated') : ''); - $forged = ((($item['sig']) && (! ($item['item_flags'] & ITEM_VERIFIED))) ? t('Message signature incorrect') : ''); - $unverified = '' ; // (($this->is_wall_to_wall() && (! ($item['item_flags'] & ITEM_VERIFIED))) ? t('Message cannot be verified') : ''); + $verified = (intval($item['item_verified']) ? t('Message signature validated') : ''); + $forged = ((($item['sig']) && (! intval($item['item_verified']))) ? t('Message signature incorrect') : ''); + $unverified = '' ; // (($this->is_wall_to_wall() && (! intval($item['item_verified']))) ? t('Message cannot be verified') : ''); @@ -569,7 +569,7 @@ class Item extends BaseObject { if((! visible_activity($child->data)) || array_key_exists('author_blocked',$child->data)) { continue; } - if($child->data['item_flags'] & ITEM_UNSEEN) + if($child->data['item_unseen']) $total ++; } } diff --git a/include/api.php b/include/api.php index 51de412cf..579ae626f 100644 --- a/include/api.php +++ b/include/api.php @@ -336,10 +336,9 @@ require_once('include/items.php'); // count public wall messages $r = q("SELECT COUNT(`id`) as `count` FROM `item` WHERE `uid` = %d - AND ( item_flags & %d )>0 and item_restrict = 0 + AND item_wall = 1 and item_restrict = 0 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", - intval($usr[0]['channel_id']), - intval(ITEM_WALL) + intval($usr[0]['channel_id']) ); $countitms = $r[0]['count']; } @@ -363,9 +362,8 @@ require_once('include/items.php'); $countfollowers = $r[0]['count']; } - $r = q("SELECT count(`id`) as `count` FROM item where ( item_flags & %d )>0 and uid = %d and item_restrict = 0", - intval($uinfo[0]['channel_id']), - intval(ITEM_STARRED) + $r = q("SELECT count(`id`) as `count` FROM item where item_starred = 1 and uid = %d and item_restrict = 0", + intval($uinfo[0]['channel_id']) ); $starred = $r[0]['count']; @@ -1004,10 +1002,7 @@ require_once('include/items.php'); // at the network timeline just mark everything seen. if (api_user() == $user_info['uid']) { - $r = q("UPDATE `item` SET item_flags = ( item_flags & ~%d ) - WHERE (item_flags & %d)>0 and uid = %d", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), + $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 and uid = %d", intval($user_info['uid']) ); } @@ -1615,7 +1610,7 @@ require_once('include/items.php'); 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', - 'favorited' => (($item['item_flags'] & ITEM_STARRED) ? true : false), + 'favorited' => (intval($item['item_starred']) ? true : false), 'user' => $status_user , 'statusnet_html' => trim(prepare_text($item['body'],$item['mimetype'])), diff --git a/include/conversation.php b/include/conversation.php index 25c844fef..e81bb49e0 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -96,7 +96,7 @@ function localize_item(&$item){ if(! $item['object']) return; - if($item['item_flags'] & ITEM_THREAD_TOP) + if(intval($item['item_thread_top'])) return; $obj = json_decode_plus($item['object']); diff --git a/include/diaspora.php b/include/diaspora.php index ae405f663..4e7b968e7 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -893,8 +893,8 @@ function diaspora_post($importer,$xml,$msg) { $datarray['app'] = $app; - $datarray['item_flags'] = ITEM_UNSEEN|ITEM_THREAD_TOP; - + $datarray['item_unseen'] = 1; + $datarray['item_thread_top'] = 1; $result = item_store($datarray); return; diff --git a/include/enotify.php b/include/enotify.php index 6fc771c58..53f1ae5ef 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -157,7 +157,7 @@ function notification($params) { $item_post_type); // "your post" - if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && ($p[0]['item_flags'] & ITEM_WALL)) + if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]your %4$s[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', diff --git a/include/identity.php b/include/identity.php index e196cb247..ce29e71f0 100644 --- a/include/identity.php +++ b/include/identity.php @@ -589,8 +589,7 @@ function identity_basic_export($channel_id, $items = false) { // warning: this may run into memory limits on smaller systems - $r = q("select * from item where (item_flags & %d)>0 and not (item_restrict & %d)>0 and uid = %d", - intval(ITEM_WALL), + $r = q("select * from item where item_wall = 1 and not (item_restrict & %d)>0 and uid = %d", intval(ITEM_DELETED), intval($channel_id) ); diff --git a/include/items.php b/include/items.php index b2fc05f09..2478d773c 100755 --- a/include/items.php +++ b/include/items.php @@ -430,7 +430,7 @@ function post_activity_item($arr) { $arr['comment_policy'] = map_scope($channel['channel_w_comment']); - if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) { + if ((! $arr['plink']) && (intval($arr['item_thread_top']))) { $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; } @@ -835,11 +835,8 @@ function get_item_elements($x) { $arr['item_flags'] = 0; - if(array_key_exists('flags',$x) && in_array('consensus',$x['flags'])) - $arr['item_flags'] |= ITEM_CONSENSUS; - - + $arr['item_consensus'] = 1; if(array_key_exists('flags',$x) && in_array('deleted',$x['flags'])) $arr['item_restrict'] = ITEM_DELETED; @@ -1135,7 +1132,7 @@ function encode_item($item,$mirror = false) { $x['public_scope'] = $scope; - if($item['item_flags'] & ITEM_NOCOMMENT) + if($item['item_nocomment']) $x['comment_scope'] = 'none'; else $x['comment_scope'] = $c_scope; @@ -1317,11 +1314,11 @@ function encode_item_flags($item) { $ret[] = 'deleted'; if($item['item_restrict'] & ITEM_HIDDEN) $ret[] = 'hidden'; - if($item['item_flags'] & ITEM_THREAD_TOP) + if(intval($item['item_thread_top'])) $ret[] = 'thread_parent'; - if($item['item_flags'] & ITEM_NSFW) + if(intval($item['item_nsfw'])) $ret[] = 'nsfw'; - if($item['item_flags'] & ITEM_CONSENSUS) + if(intval($item['item_consensus'])) $ret[] = 'consensus'; if($item['item_private']) $ret[] = 'private'; @@ -2042,12 +2039,11 @@ function item_store($arr,$allow_exec = false) { $arr['comment_policy'] = ((x($arr,'comment_policy')) ? notags(trim($arr['comment_policy'])) : 'contacts' ); - $arr['item_flags'] = $arr['item_flags'] | ITEM_UNSEEN; - - if($arr['comment_policy'] == 'none') - $arr['item_flags'] = $arr['item_flags'] | ITEM_NOCOMMENT; - + if(! array_key_exists('item_unseen',$arr)) + $arr['item_unseen'] = 1; + if((! array_key_exists('item_nocomment',$arr)) && ($arr['comment_policy'] == 'none')) + $arr['item_nocomment'] = 1; // handle time travelers // Allow a bit of fudge in case somebody just has a slightly slow/fast clock @@ -2073,7 +2069,7 @@ function item_store($arr,$allow_exec = false) { $deny_gid = $arr['deny_gid']; $public_policy = $arr['public_policy']; $comments_closed = $arr['comments_closed']; - $arr['item_flags'] = $arr['item_flags'] | ITEM_THREAD_TOP; + $arr['item_thread_top'] = 1; } else { @@ -2121,8 +2117,8 @@ function item_store($arr,$allow_exec = false) { $public_policy = $r[0]['public_policy']; $comments_closed = $r[0]['comments_closed']; - if($r[0]['item_flags'] & ITEM_WALL) - $arr['item_flags'] = $arr['item_flags'] | ITEM_WALL; + if(intval($r[0]['item_wall'])) + $arr['item_wall'] = 1; // An uplinked comment might arrive with a downstream owner. @@ -2142,7 +2138,7 @@ function item_store($arr,$allow_exec = false) { // The original author commented, but as this is a comment, the permissions // weren't fixed up so it will still show the comment as private unless we fix it here. - if((intval($r[0]['item_flags']) & ITEM_UPLINK) && (! $r[0]['item_private'])) + if(intval($r[0]['item_uplink']) && (! $r[0]['item_private'])) $arr['item_private'] = 0; } else { @@ -2337,15 +2333,7 @@ function item_store_update($arr,$allow_exec = false) { // override the unseen flag with the original - if($arr['item_flags'] & ITEM_UNSEEN) - $arr['item_flags'] = $arr['item_flags'] ^ ITEM_UNSEEN; - - if($orig[0]['item_flags'] & ITEM_VERIFIED) - $orig[0]['item_flags'] = $orig[0]['item_flags'] ^ ITEM_VERIFIED; - - if($orig[0]['item_flags'] & ITEM_OBSCURED) - $orig[0]['item_flags'] = $orig[0]['item_flags'] ^ ITEM_OBSCURED; - + $arr['item_unseen'] = $orig[0]['item_unseen']; $arr['item_flags'] = intval($arr['item_flags']) | $orig[0]['item_flags']; $arr['item_restrict'] = intval($arr['item_restrict']) | $orig[0]['item_restrict']; @@ -2371,7 +2359,7 @@ function item_store_update($arr,$allow_exec = false) { $channel = get_app()->get_channel(); if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_flags'] |= ITEM_VERIFIED; + $arr['item_verified'] = 1; } } @@ -2701,8 +2689,8 @@ function tag_deliver($uid,$item_id) { $item = $i[0]; - if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) - && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) { + if(($item['source_xchan']) && intval($item['item_uplink']) + && intval($item['item_thread_top']) && ($item['edited'] != $item['created'])) { // this is an update (edit) to a post which was already processed by us and has a second delivery chain // Just start the second delivery chain to deliver the updated post proc_run('php','include/notifier.php','tgroup',$item['id']); @@ -2800,13 +2788,13 @@ function tag_deliver($uid,$item_id) { // This might be a followup (e.g. comment) by the original post author to a tagged forum // If so setup a second delivery chain - if( ! ($item['item_flags'] & ITEM_THREAD_TOP)) { + if( ! intval($item['item_thread_top'])) { $x = q("select * from item where id = parent and parent = %d and uid = %d limit 1", intval($item['parent']), intval($uid) ); - if(($x) && ($x[0]['item_flags'] & ITEM_UPLINK)) { + if(($x) && intval($x[0]['item_uplink'])) { start_delivery_chain($u[0],$item,$item_id,$x[0]); } } @@ -2836,8 +2824,7 @@ function tag_deliver($uid,$item_id) { if($mention) { logger('tag_deliver: mention found for ' . $u[0]['channel_name']); - $r = q("update item set item_flags = ( item_flags | %d ) where id = %d", - intval(ITEM_MENTIONSME), + $r = q("update item set item_mentionsme = 1 where id = %d", intval($item_id) ); @@ -2948,10 +2935,9 @@ function tgroup_check($uid,$item) { // or is a followup and we have already accepted the top level post as an uplink if($item['mid'] != $item['parent_mid']) { - $r = q("select id from item where mid = '%s' and uid = %d and ( item_flags & %d )>0 limit 1", + $r = q("select id from item where mid = '%s' and uid = %d and item_uplink = 1 limit 1", dbesc($item['parent_mid']), - intval($uid), - intval(ITEM_UPLINK) + intval($uid) ); if($r) return true; @@ -3037,14 +3023,11 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { $item_wall = 1; $item_origin = 1; + $item_uplink = 0; + $item_nocomment = 0; $flag_bits = $item['item_flags']; - // unset the nocomment bit if it's there. - - if($flag_bits & ITEM_NOCOMMENT) - $flag_bits = $flag_bits ^ ITEM_NOCOMMENT; - // maintain the original source, which will be the original item owner and was stored in source_xchan // when we created the delivery fork @@ -3055,7 +3038,7 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { ); } else { - $flag_bits = $flag_bits | ITEM_UPLINK; + $item_uplink = 1; $r = q("update item set source_xchan = owner_xchan where id = %d", intval($item_id) ); @@ -3085,8 +3068,10 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { } } - $r = q("update item set item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + $r = q("update item set item_uplink = %d, item_nocomment = %d, item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s', item_wall = %d, item_origin = %d where id = %d", + intval($item_uplink), + intval($item_nocomment), intval($flag_bits), dbesc($channel['channel_hash']), dbesc($channel['channel_allow_cid']), @@ -3868,7 +3853,7 @@ function item_expire($uid,$days) { $expire_network_only = 1; - $sql_extra = ((intval($expire_network_only)) ? " AND not (item_flags & " . intval(ITEM_WALL) . ")>0 " : ""); + $sql_extra = ((intval($expire_network_only)) ? " AND item_wall = 0 " : ""); $r = q("SELECT * FROM `item` WHERE `uid` = %d @@ -3903,7 +3888,7 @@ function item_expire($uid,$days) { retain_item($item['id']); continue; } - if($item['item_flags'] & ITEM_STARRED) { + if(intval($item['item_starred'])) { retain_item($item['id']); continue; } @@ -4027,7 +4012,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal // We'll rely on the undocumented behaviour that DROPITEM_PHASE1 is (hopefully) only // set if we know we're going to send delete notifications out to others. - if((($item['item_flags'] & ITEM_WALL) && ($stage != DROPITEM_PHASE2)) || ($stage == DROPITEM_PHASE1)) + if((intval($item['item_wall']) && ($stage != DROPITEM_PHASE2)) || ($stage == DROPITEM_PHASE1)) proc_run('php','include/notifier.php','drop',$notify_id); goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); @@ -4132,7 +4117,7 @@ function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL,$force = false) { function first_post_date($uid,$wall = false) { - $wall_sql = (($wall) ? sprintf(" and (item_flags & %d)>0 ", ITEM_WALL) : "" ); + $wall_sql = (($wall) ? " and item_wall = 1 " : "" ); $r = q("select id, created from item where item_restrict = %d and uid = %d and id = parent $wall_sql @@ -4331,19 +4316,17 @@ function zot_feed($uid,$observer_xchan,$arr) { $r = q("SELECT distinct parent, created from item WHERE uid != %d and uid in (" . stream_perms_api_uids(PERMS_PUBLIC) . ") AND item_restrict = 0 - AND (item_flags & %d)>0 + AND item_wall = 1 and item_private = 0 $sql_extra ORDER BY created ASC $limit", - intval($uid), - intval(ITEM_WALL) + intval($uid) ); } else { $r = q("SELECT distinct parent, created from item WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d)>0 + AND item_wall = 1 $sql_extra ORDER BY created ASC $limit", - intval($uid), - intval(ITEM_WALL) + intval($uid) ); } @@ -4403,12 +4386,12 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } if($arr['star']) - $sql_options .= " and (item_flags & " . intval(ITEM_STARRED) . ")>0 "; + $sql_options .= " and item_starred = 1 "; if($arr['wall']) - $sql_options .= " and (item_flags & " . intval(ITEM_WALL) . ")>0 "; + $sql_options .= " and item_wall = 1 "; - $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE (item_flags & " . intval(ITEM_THREAD_TOP) . ")>0 $sql_options ) "; + $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options ) "; if($arr['since_id']) $sql_extra .= " and item.id > " . $since_id . " "; @@ -4486,9 +4469,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } if($arr['conv'] && $channel) { - $sql_extra .= sprintf(" AND parent IN (SELECT distinct parent from item where ( author_xchan like '%s' or ( item_flags & %d )>0)) ", - dbesc(protect_sprintf($uidhash)), - intval(ITEM_MENTIONSME) + $sql_extra .= sprintf(" AND parent IN (SELECT distinct parent from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", + dbesc(protect_sprintf($uidhash)) ); } @@ -4528,7 +4510,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } } - $simple_update = (($client_mode & CLIENT_MODE_UPDATE) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " )>0 " : ''); + $simple_update = (($client_mode & CLIENT_MODE_UPDATE) ? " and item.item_unseen = 1 " : ''); if($client_mode & CLIENT_MODE_LOAD) $simple_update = ''; diff --git a/include/notifier.php b/include/notifier.php index 241dffbd1..092b27498 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -206,10 +206,9 @@ function notifier_run($argv, $argc){ $normal_mode = false; $expire = true; - $items = q("SELECT * FROM item WHERE uid = %d AND ( item_flags & %d )>0 + $items = q("SELECT * FROM item WHERE uid = %d AND item_wall = 1 AND ( item_restrict & %d )>0 AND `changed` > %s - INTERVAL %s", intval($item_id), - intval(ITEM_WALL), intval(ITEM_DELETED), db_utcnow(), db_quoteinterval('10 MINUTE') ); @@ -374,7 +373,7 @@ function notifier_run($argv, $argc){ // tag_deliver'd post which needs to be sent back to the original author - if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post)) { + if(($cmd === 'uplink') && intval($parent_item['item_uplink']) && (! $top_level_post)) { logger('notifier: uplink'); $uplink = true; } @@ -395,7 +394,7 @@ function notifier_run($argv, $argc){ // if our parent is a tag_delivery recipient, uplink to the original author causing // a delivery fork. - if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink')) { + if(intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) { logger('notifier: uplinking this item'); proc_run('php','include/notifier.php','uplink',$item_id); } @@ -408,7 +407,7 @@ function notifier_run($argv, $argc){ // don't send deletions onward for other people's stuff // TODO verify this is needed - copied logic from same place in old code - if(($target_item['item_restrict'] & ITEM_DELETED) && (!($target_item['item_flags'] & ITEM_WALL))) { + if(($target_item['item_restrict'] & ITEM_DELETED) && (! intval($target_item['item_wall']))) { logger('notifier: ignoring delete notification for non-wall item'); return; } diff --git a/include/notify.php b/include/notify.php index aa96fa279..987ca8c0f 100644 --- a/include/notify.php +++ b/include/notify.php @@ -5,9 +5,6 @@ function format_notification($item) { $ret = ''; -// return array(); - - require_once('include/conversation.php'); // Call localize_item with the "brief" flag to get a one line status for activities. @@ -19,7 +16,7 @@ function format_notification($item) { $itemem_text = $item['localize']; } else { - $itemem_text = (($item['item_flags'] & ITEM_THREAD_TOP) + $itemem_text = (($item['item_thread_top']) ? t('created a new post') : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name'])); } @@ -32,7 +29,7 @@ function format_notification($item) { 'url' => $item['author']['xchan_url'], 'photo' => $item['author']['xchan_photo_s'], 'when' => relative_date($item['created']), - 'class' => (($item['item_flags'] & ITEM_UNSEEN) ? 'notify-unseen' : 'notify-seen'), + 'class' => (($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), 'message' => strip_tags(bbcode($itemem_text)) ); diff --git a/include/statistics_fns.php b/include/statistics_fns.php index 288925a2c..ce2eee5e7 100644 --- a/include/statistics_fns.php +++ b/include/statistics_fns.php @@ -23,8 +23,7 @@ function update_channels_active_halfyear_stat() { $s .= ','; $s .= intval($rr['channel_id']); } - $x = q("select uid from item where uid in ( $s ) and (item_flags & %d)>0 and created > %s - INTERVAL %s group by uid", - intval(ITEM_WALL), + $x = q("select uid from item where uid in ( $s ) and item_wall = 1 and created > %s - INTERVAL %s group by uid", db_utcnow(), db_quoteinterval('6 MONTH') ); if($x) { @@ -50,8 +49,7 @@ function update_channels_active_monthly_stat() { $s .= ','; $s .= intval($rr['channel_id']); } - $x = q("select uid from item where uid in ( $s ) and ( item_flags & %d )>0 and created > %s - INTERVAL %s group by uid", - intval(ITEM_WALL), + $x = q("select uid from item where uid in ( $s ) and item_wall = 1 and created > %s - INTERVAL %s group by uid", db_utcnow(), db_quoteinterval('1 MONTH') ); if($x) { @@ -66,8 +64,7 @@ function update_channels_active_monthly_stat() { } function update_local_posts_stat() { - $posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE (item_flags & %d)>0 ", - intval(ITEM_WALL) ); + $posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE item_wall = 1 "); if (is_array($posts)) { $local_posts_stat = intval($posts[0]["local_posts"]); set_config('system','local_posts_stat',$local_posts_stat); diff --git a/include/taxonomy.php b/include/taxonomy.php index be80008df..a5ccada62 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -101,8 +101,10 @@ function tagadelic($uid, $count = 0, $authors = '', $flags = 0, $restrict = 0, $ $sql_options = ''; $count = intval($count); - if($flags) - $sql_options .= " and ((item_flags & " . intval($flags) . ") = " . intval($flags) . ") "; + if($flags) { + if($flags === 'wall') + $sql_options .= " and item_wall = 1 "; + } if($authors) { if(! is_array($authors)) diff --git a/include/widgets.php b/include/widgets.php index 9f9268055..d4888789f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -391,7 +391,7 @@ function widget_tagcloud_wall($arr) { $limit = ((array_key_exists('limit', $arr)) ? intval($arr['limit']) : 50); if(feature_enabled($a->profile['profile_uid'], 'tagadelic')) - return wtagblock($a->profile['profile_uid'], $limit, $a->profile['channel_hash'], ITEM_WALL); + return wtagblock($a->profile['profile_uid'], $limit, $a->profile['channel_hash'], 'wall'); return ''; } @@ -406,7 +406,7 @@ function widget_catcloud_wall($arr) { $limit = ((array_key_exists('limit',$arr)) ? intval($arr['limit']) : 50); - return catblock($a->profile['profile_uid'], $limit, $a->profile['channel_hash'], ITEM_WALL); + return catblock($a->profile['profile_uid'], $limit, $a->profile['channel_hash'], 'wall'); } diff --git a/include/zot.php b/include/zot.php index 435592b6a..07d228ea5 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1436,13 +1436,10 @@ function process_delivery($sender,$arr,$deliveries,$relay,$public = false,$reque // This is our own post, possibly coming from a channel clone if($arr['owner_xchan'] == $d['hash']) { - $arr['item_flags'] = $arr['item_flags'] | ITEM_WALL; + $arr['item_wall'] = 1; } else { - // clear the wall flag if it is set - if($arr['item_flags'] & ITEM_WALL) { - $arr['item_flags'] = ($arr['item_flags'] ^ ITEM_WALL); - } + $arr['item_wall'] = 0; } if((! perm_is_allowed($channel['channel_id'],$sender['hash'],$perm)) && (! $tag_delivery) && (! $local_public)) { diff --git a/mod/channel.php b/mod/channel.php index c8ac83baf..84b302cce 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -147,23 +147,19 @@ function channel_content(&$a, $update = 0, $load = false) { if(($update) && (! $load)) { if ($mid) { $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d AND item_restrict = 0 - AND (item_flags & %d) > 0 AND (item_flags & %d) > 0 $sql_extra limit 1", + AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1", dbesc($mid), - intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ITEM_UNSEEN) + intval($a->profile['profile_uid']) ); } else { $r = q("SELECT distinct parent AS `item_id`, created from item left join abook on item.author_xchan = abook.abook_xchan WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d) > 0 AND ( item_flags & %d ) > 0 + AND item_wall = 1 AND item_unseen = 1 AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) $sql_extra ORDER BY created DESC", intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ITEM_UNSEEN), intval(ABOOK_FLAG_BLOCKED) ); } @@ -192,10 +188,9 @@ function channel_content(&$a, $update = 0, $load = false) { if($load || ($_COOKIE['jsAvailable'] != 1)) { if ($mid) { $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d AND item_restrict = 0 - AND (item_flags & %d)>0 $sql_extra limit 1", + AND item_wall = 1 $sql_extra limit 1", dbesc($mid), - intval($a->profile['profile_uid']), - intval(ITEM_WALL) + intval($a->profile['profile_uid']) ); if (! $r) { notice( t('Permission denied.') . EOL); @@ -205,13 +200,11 @@ function channel_content(&$a, $update = 0, $load = false) { $r = q("SELECT distinct id AS item_id, created FROM item left join abook on item.author_xchan = abook.abook_xchan WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d)>0 and (item_flags & %d)>0 + AND item_wall = 1 and item_thread_top = 1 AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) $sql_extra $sql_extra2 ORDER BY created DESC $pager_sql ", intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ITEM_THREAD_TOP), intval(ABOOK_FLAG_BLOCKED) ); } @@ -317,11 +310,7 @@ function channel_content(&$a, $update = 0, $load = false) { } if($is_owner && $update_unseen) { - $r = q("UPDATE item SET item_flags = (item_flags & ~%d) - WHERE (item_flags & %d) > 0 AND (item_flags & %d) > 0 AND uid = %d $update_unseen", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), - intval(ITEM_WALL), + $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", intval(local_user()) ); } diff --git a/mod/display.php b/mod/display.php index f14aca6da..b9b660fdd 100644 --- a/mod/display.php +++ b/mod/display.php @@ -231,10 +231,7 @@ function display_content(&$a, $update = 0, $load = false) { } if($updateable) { - $x = q("UPDATE item SET item_flags = ( item_flags & ~%d ) - WHERE (item_flags & %d)>0 AND uid = %d and parent = %d ", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), + $x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ", intval(local_user()), intval($r[0]['parent']) ); diff --git a/mod/events.php b/mod/events.php index 28a816ea4..14ff03468 100755 --- a/mod/events.php +++ b/mod/events.php @@ -392,7 +392,7 @@ function events_content(&$a) { $last_date = $d; // FIXME - $edit = (($rr['item_flags'] & ITEM_WALL) ? array($a->get_baseurl().'/events/event/'.$rr['event_hash'],t('Edit event'),'','') : null); + $edit = (intval($rr['item_wall']) ? array($a->get_baseurl().'/events/event/'.$rr['event_hash'],t('Edit event'),'','') : null); $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); if(! $title) { list($title, $_trash) = explode(" 0 " : ''); + $simple_update = (($update) ? " and item.item_unseen = 1 " : ''); if($update && $_SESSION['loadtime']) $simple_update .= " and item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' "; diff --git a/mod/item.php b/mod/item.php index 152c10b13..a6ab99ef5 100644 --- a/mod/item.php +++ b/mod/item.php @@ -809,7 +809,7 @@ function item_post(&$a) { // only send comment notification if this is a wall-to-wall comment, // otherwise it will happen during delivery - if(($datarray['owner_xchan'] != $datarray['author_xchan']) && ($parent_item['item_flags'] & ITEM_WALL)) { + if(($datarray['owner_xchan'] != $datarray['author_xchan']) && (intval($parent_item['item_wall']))) { notification(array( 'type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], diff --git a/mod/like.php b/mod/like.php index 4d4d4249e..968f9c81e 100755 --- a/mod/like.php +++ b/mod/like.php @@ -328,14 +328,14 @@ function like_content(&$a) { ), )); - if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + if(! intval($item['item_thread_top'])) $post_type = 'comment'; $arr['item_origin'] = 1; $arr['item_notshown'] = 1; - if($item['item_flags'] & ITEM_WALL) - $item_flags |= ITEM_WALL; + if(intval($item['item_wall'])) + $arr['item_wall'] = 1; // if this was a linked photo and was hidden, unhide it. diff --git a/mod/manage.php b/mod/manage.php index 6797b4892..4297e8f08 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -56,16 +56,15 @@ function manage_content(&$a) { $channels[$x]['default_links'] = '1'; - $c = q("SELECT id, item_restrict, item_flags FROM item - WHERE (item_restrict = %d) and ( item_flags & %d )>0 and uid = %d", + $c = q("SELECT id, item_restrict, item_wall FROM item + WHERE (item_restrict = %d) and item_unseen = 1 and uid = %d", intval(ITEM_VISIBLE), - intval(ITEM_UNSEEN), intval($channels[$x]['channel_id']) ); if($c) { foreach ($c as $it) { - if($it['item_flags'] & ITEM_WALL) + if(intval($it['item_wall'])) $channels[$x]['home'] ++; else $channels[$x]['network'] ++; diff --git a/mod/network.php b/mod/network.php index 65332e3f6..5e583f657 100644 --- a/mod/network.php +++ b/mod/network.php @@ -154,12 +154,12 @@ function network_content(&$a, $update = 0, $load = false) { $sql_options = (($star) - ? " and (item_flags & " . intval(ITEM_STARRED) . ") > 0" + ? " and item_starred = 1 " : ''); $sql_nets = ''; - $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE (item_flags & " . intval(ITEM_THREAD_TOP) . ")>0 $sql_options ) "; + $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE item_thread_top = 1 $sql_options ) "; if($group) { $contact_str = ''; @@ -291,9 +291,8 @@ function network_content(&$a, $update = 0, $load = false) { } if($conv) { - $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or ( item_flags & %d ) > 0)) ", - dbesc(protect_sprintf($channel['channel_hash'])), - intval(ITEM_MENTIONSME) + $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", + dbesc(protect_sprintf($channel['channel_hash'])) ); } @@ -346,7 +345,7 @@ function network_content(&$a, $update = 0, $load = false) { else $page_mode = 'client'; - $simple_update = (($update) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " ) > 0 " : ''); + $simple_update = (($update) ? " and item.item_unseen = 1 " : ''); // This fixes a very subtle bug so I'd better explain it. You wake up in the morning or return after a day // or three and look at your matrix page - after opening up your browser. The first page loads just as it @@ -465,10 +464,7 @@ function network_content(&$a, $update = 0, $load = false) { } if(($update_unseen) && (! $firehose)) - $r = q("UPDATE item SET item_flags = ( item_flags & ~%d) - WHERE (item_flags & %d) > 0 AND uid = %d $update_unseen ", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), + $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d $update_unseen ", intval(local_user()) ); diff --git a/mod/p.php b/mod/p.php index 9d1c12dbc..80e835a91 100644 --- a/mod/p.php +++ b/mod/p.php @@ -11,9 +11,8 @@ function p_init(&$a) { $mid = str_replace('.xml','',argv(1)); - $r = q("select * from item where mid = '%s' and (item_flags & %d)>0 and item_private = 0 limit 1", - dbesc($mid), - intval(ITEM_WALL) + $r = q("select * from item where mid = '%s' and item_wall = 1 and item_private = 0 limit 1", + dbesc($mid) ); diff --git a/mod/photos.php b/mod/photos.php index b2eb2847f..216a562c7 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -877,11 +877,9 @@ function photos_content(&$a) { } if((local_user()) && (local_user() == $link_item['uid'])) { - q("UPDATE `item` SET item_flags = (item_flags & ~%d) WHERE parent = %d and uid = %d and (item_flags & %d)>0", - intval(ITEM_UNSEEN), + q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), - intval(local_user()), - intval(ITEM_UNSEEN) + intval(local_user()) ); } } diff --git a/mod/ping.php b/mod/ping.php index e5fc4d930..62e8197df 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -151,17 +151,12 @@ function ping_init(&$a) { if(x($_REQUEST, 'markRead') && local_user()) { switch($_REQUEST['markRead']) { case 'network': - $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d) > 0 and uid = %d", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), + $r = q("update item set item_unseen = 0 where item_unseen = 1 and uid = %d", intval(local_user()) ); break; case 'home': - $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d) > 0 and (item_flags & %d) > 0 and uid = %d", - intval(ITEM_UNSEEN), - intval(ITEM_UNSEEN), - intval(ITEM_WALL), + $r = q("update item set item_unseen = 0 where item_unseen = 1 and item_wall = 1 and uid = %d", intval(local_user()) ); break; @@ -188,8 +183,7 @@ function ping_init(&$a) { } if(x($_REQUEST, 'markItemRead') && local_user()) { - $r = q("update item set item_flags = ( item_flags & ~%d ) where parent = %d and uid = %d", - intval(ITEM_UNSEEN), + $r = q("update item set item_unseen = 0 where parent = %d and uid = %d", intval($_REQUEST['markItemRead']), intval(local_user()) ); @@ -276,10 +270,9 @@ function ping_init(&$a) { $result = array(); $r = q("SELECT * FROM item - WHERE item_restrict = %d and ( item_flags & %d ) > 0 and uid = %d + WHERE item_restrict = %d and item_unseen = 1 and uid = %d and author_xchan != '%s' ORDER BY created DESC", intval(ITEM_VISIBLE), - intval(ITEM_UNSEEN), intval(local_user()), dbesc($ob_hash) ); @@ -287,7 +280,7 @@ function ping_init(&$a) { if($r) { xchan_query($r); foreach($r as $item) { - if((argv(1) === 'home') && (! ($item['item_flags'] & ITEM_WALL))) + if((argv(1) === 'home') && (! intval($item['item_wall']))) continue; $result[] = format_notification($item); } @@ -383,10 +376,9 @@ function ping_init(&$a) { if($vnotify & (VNOTIFY_NETWORK|VNOTIFY_CHANNEL)) { $r = q("SELECT id, item_restrict, item_flags FROM item - WHERE (item_restrict = %d) and ( item_flags & %d ) > 0 and uid = %d + WHERE (item_restrict = %d) and item_unseen = 1 and uid = %d and author_xchan != '%s'", intval(ITEM_VISIBLE), - intval(ITEM_UNSEEN), intval(local_user()), dbesc($ob_hash) ); @@ -396,7 +388,7 @@ function ping_init(&$a) { call_hooks('network_ping', $arr); foreach ($r as $it) { - if($it['item_flags'] & ITEM_WALL) + if(intval($it['item_wall'])) $result['home'] ++; else $result['network'] ++; diff --git a/mod/starred.php b/mod/starred.php index 05b45bea3..931b24a71 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -19,15 +19,15 @@ function starred_init(&$a) { if(! count($r)) killme(); - $item_flags = ( $r[0]['item_flags'] ^ ITEM_STARRED ); + $item_starred = (intval($r[0]['item_starred']) ? 0 : 1); - $r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d", - intval($item_flags), + $r = q("UPDATE item SET item_starred = %d WHERE uid = %d and id = %d", + intval($item_starred), intval(local_user()), intval($message_id) ); header('Content-type: application/json'); - echo json_encode(array('result' => (($item_flags & ITEM_STARRED) ? 1 : 0))); + echo json_encode(array('result' => $item_starred)); killme(); } diff --git a/mod/subthread.php b/mod/subthread.php index 92ada64ad..f4472cf05 100755 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -96,10 +96,9 @@ function subthread_content(&$a) { ), )); - if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + if(! intval($item['item_thread_top'])) $post_type = 'comment'; - $bodyverb = t('%1$s is following %2$s\'s %3$s'); $arr = array(); -- cgit v1.2.3 From 6e0e3b2433fc426b758a55811f56536d58705813 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Jan 2015 18:41:10 -0800 Subject: more expanding item flags --- boot.php | 21 --------------------- include/bb2diaspora.php | 2 +- include/conversation.php | 15 +++------------ include/diaspora.php | 2 +- include/enotify.php | 2 +- include/items.php | 46 +++++++++++++++++++++++----------------------- include/text.php | 2 +- mod/editpost.php | 2 +- mod/editwebpage.php | 2 +- mod/filer.php | 3 +-- mod/item.php | 9 ++------- mod/viewsrc.php | 4 ++-- 12 files changed, 37 insertions(+), 73 deletions(-) diff --git a/boot.php b/boot.php index 9544f70af..c52c1bc32 100755 --- a/boot.php +++ b/boot.php @@ -531,27 +531,6 @@ define ( 'ITEM_BUILDBLOCK', 0x0100); // Named thusly to make sure nobody co 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 - -/** - * Item Flags - */ - -//define ( 'ITEM_ORIGIN', 0x0001); -//define ( 'ITEM_UNSEEN', 0x0002); -//define ( 'ITEM_STARRED', 0x0004); -//define ( 'ITEM_UPLINK', 0x0008); -//define ( 'ITEM_CONSENSUS', 0x0010); // an item which may present agree/disagree/abstain options -//define ( 'ITEM_WALL', 0x0020); -//define ( 'ITEM_THREAD_TOP', 0x0040); -//define ( 'ITEM_NOTSHOWN', 0x0080); // technically visible but not normally shown (e.g. like/dislike) -//define ( 'ITEM_NSFW', 0x0100); -//define ( 'ITEM_RELAY', 0x0200); // used only in the communication layers, not stored -//define ( 'ITEM_MENTIONSME', 0x0400); -//define ( 'ITEM_NOCOMMENT', 0x0800); // commenting/followups are disabled -define ( 'ITEM_OBSCURED', 0x1000); // bit-mangled to protect from casual browsing by site admin -define ( 'ITEM_VERIFIED', 0x2000); // Signature verification was successful -define ( 'ITEM_RETAINED', 0x4000); // We looked at this item once to decide whether or not to expire it, and decided not to. -define ( 'ITEM_RSS', 0x8000); // Item comes from a feed. Use this to decide whether to link the title // Don't make us evaluate this same item again. define ( 'DBTYPE_MYSQL', 0 ); diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index e8f81aec4..5b675128f 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -304,7 +304,7 @@ function bb2diaspora_itembody($item,$force_update = false) { $newitem = $item; - if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { + if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { $key = get_config('system','prvkey'); $b = json_decode($item['body'],true); // if called from diaspora_process_outbound, this decoding has already been done. diff --git a/include/conversation.php b/include/conversation.php index e81bb49e0..5a9e4a59e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -357,21 +357,12 @@ function localize_item(&$item){ } } */ - // add sparkle links to appropriate permalinks - -// $x = stristr($item['plink'],'/display/'); -// if($x) { -// $sparkle = false; -// $y = best_link_url($item,$sparkle,true); - // if($sparkle) -// $item['plink'] = $y . '?f=&url=' . $item['plink']; -// } // if item body was obscured and we changed it, re-obscure it // FIXME - we need a better filter than just the string 'data'; try and // match the fact that it's json encoded - if(($item['item_flags'] & ITEM_OBSCURED) + if(intval($item['item_obscured']) && strlen($item['body']) && (! strpos($item['body'],'data'))) { $item['body'] = json_encode(crypto_encapsulate($item['body'],get_config('system','pubkey'))); } @@ -655,8 +646,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $likebuttons = false; $shareable = false; - $verified = (($item['item_flags'] & ITEM_VERIFIED) ? t('Message signature validated') : ''); - $forged = ((($item['sig']) && (! ($item['item_flags'] & ITEM_VERIFIED))) ? t('Message signature incorrect') : ''); + $verified = (intval($item['item_verified']) ? t('Message signature validated') : ''); + $forged = ((($item['sig']) && (! intval($item['item_verified']))) ? t('Message signature incorrect') : ''); $unverified = ''; diff --git a/include/diaspora.php b/include/diaspora.php index 4e7b968e7..b9c6e5c92 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -157,7 +157,7 @@ function diaspora_process_outbound($arr) { $target_item = $arr['target_item']; - if($target_item && array_key_exists('item_flags',$target_item) && ($target_item['item_flags'] & ITEM_OBSCURED)) { + if($target_item && array_key_exists('item_obscured',$target_item) && intval($target_item['item_obscured'])) { $key = get_config('system','prvkey'); if($target_item['title']) $target_item['title'] = crypto_unencapsulate(json_decode($target_item['title'],true),$key); diff --git a/include/enotify.php b/include/enotify.php index 53f1ae5ef..34552cc36 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -65,7 +65,7 @@ function notification($params) { localize_item($i); $title = $i['title']; $body = $i['body']; - $private = (($i['item_private']) || ($i['item_flags'] & ITEM_OBSCURED)); + $private = (($i['item_private']) || intval($i['item_obscured'])); } else { $title = $params['item']['title']; diff --git a/include/items.php b/include/items.php index 2478d773c..43739b605 100755 --- a/include/items.php +++ b/include/items.php @@ -396,13 +396,13 @@ function post_activity_item($arr) { if($channel) { if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_flags'] = $arr['item_flags'] | ITEM_VERIFIED; + $arr['item_verified'] = 1; } } logger('Encrypting local storage'); $key = get_config('system','pubkey'); - $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; + $arr['item_obscured'] = 1; if($arr['title']) $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) @@ -870,7 +870,7 @@ function get_item_elements($x) { dbesc($arr['author_xchan']) ); if($r && rsa_verify($x['body'],base64url_decode($arr['sig']),$r[0]['xchan_pubkey'])) - $arr['item_flags'] |= ITEM_VERIFIED; + $arr['item_verified'] = 1; else logger('get_item_elements: message verification failed.'); } @@ -883,7 +883,7 @@ function get_item_elements($x) { if(intval($arr['item_private'])) { - $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; + $arr['item_obscured'] = 1; if($arr['title']) $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) @@ -1066,7 +1066,7 @@ function encode_item($item,$mirror = false) { $key = get_config('system','prvkey'); - if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { + if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { if($item['title']) $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key); if($item['body']) @@ -1475,7 +1475,7 @@ function get_atom_elements($feed,$item,&$author) { $res['title'] = unxmlify($item->get_title()); $res['body'] = unxmlify($item->get_content()); $res['plink'] = unxmlify($item->get_link(0)); - $res['item_flags'] = ITEM_RSS; + $res['item_rss'] = 1; // removing the content of the title if its identically to the body @@ -1956,7 +1956,7 @@ function item_store($arr,$allow_exec = false) { // only detect language if we have text content, and if the post is private but not yet // obscured, make it so. - if(! ($arr['item_flags'] & ITEM_OBSCURED)) { + if((! array_key_exists('item_obscured',$arr)) || $arr['item_obscured'] == 0) { $arr['lang'] = detect_language($arr['body']); // apply the input filter here - if it is obscured it has been filtered already @@ -1967,7 +1967,7 @@ function item_store($arr,$allow_exec = false) { $channel = get_app()->get_channel(); if($channel['channel_hash'] === $arr['author_xchan']) { $arr['sig'] = base64url_encode(rsa_sign($arr['body'],$channel['channel_prvkey'])); - $arr['item_flags'] |= ITEM_VERIFIED; + $arr['item_verified'] = 1; } } @@ -1985,7 +1985,7 @@ function item_store($arr,$allow_exec = false) { } if($arr['item_private']) { $key = get_config('system','pubkey'); - $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; + $arr['item_obscured'] = 1; if($arr['title']) $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) @@ -2349,7 +2349,7 @@ function item_store_update($arr,$allow_exec = false) { return $ret; } - if(! ($arr['item_flags'] & ITEM_OBSCURED)) { + if((! array_key_exists('item_obscured', $arr)) || $arr['item_obscured'] == 0) { $arr['lang'] = detect_language($arr['body']); // apply the input filter here - if it is obscured it has been filtered already @@ -2377,7 +2377,7 @@ function item_store_update($arr,$allow_exec = false) { } if($arr['item_private']) { $key = get_config('system','pubkey'); - $arr['item_flags'] = $arr['item_flags'] | ITEM_OBSCURED; + $arr['item_obscured'] = 1; if($arr['title']) $arr['title'] = json_encode(crypto_encapsulate($arr['title'],$key)); if($arr['body']) @@ -2834,7 +2834,7 @@ function tag_deliver($uid,$item_id) { $body = ''; - if($item['item_flags'] & ITEM_OBSCURED) { + if(intval($item['item_obscured'])) { $key = get_config('system','prvkey'); if($item['body']) $body = crypto_unencapsulate(json_decode_plus($item['body']),$key); @@ -2981,7 +2981,7 @@ function tgroup_check($uid,$item) { $body = $item['body']; - if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED) && $body) { + if(array_key_exists('item_obscured',$item) && intval($item['item_obscured']) && $body) { $key = get_config('system','prvkey'); $body = crypto_unencapsulate(json_decode($body,true),$key); } @@ -3025,6 +3025,7 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { $item_origin = 1; $item_uplink = 0; $item_nocomment = 0; + $item_obscured = 0; $flag_bits = $item['item_flags']; @@ -3048,30 +3049,31 @@ function start_delivery_chain($channel,$item,$item_id,$parent) { $body = $item['body']; if($private) { - if(!($flag_bits & ITEM_OBSCURED)) { + if(! intval($item['item_obscured'])) { $key = get_config('system','pubkey'); - $flag_bits = $flag_bits|ITEM_OBSCURED; if($title) $title = json_encode(crypto_encapsulate($title,$key)); if($body) $body = json_encode(crypto_encapsulate($body,$key)); + $item_obscured = 1; } } else { - if($flag_bits & ITEM_OBSCURED) { + if(intval($item['item_obscured'])) { $key = get_config('system','prvkey'); - $flag_bits = $flag_bits ^ ITEM_OBSCURED; if($title) $title = crypto_unencapsulate(json_decode($title,true),$key); if($body) $body = crypto_unencapsulate(json_decode($body,true),$key); + $item_obscured = 0; } } - $r = q("update item set item_uplink = %d, item_nocomment = %d, item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', + $r = q("update item set item_uplink = %d, item_nocomment = %d, item_obscured = %d, item_flags = %d, owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d, public_policy = '%s', comment_policy = '%s', title = '%s', body = '%s', item_wall = %d, item_origin = %d where id = %d", intval($item_uplink), intval($item_nocomment), + intval($item_obscured), intval($flag_bits), dbesc($channel['channel_hash']), dbesc($channel['channel_allow_cid']), @@ -3860,11 +3862,10 @@ function item_expire($uid,$days) { AND `created` < %s - INTERVAL %s AND `id` = `parent` $sql_extra - AND NOT ( item_flags & %d )>0 + AND item_retained = 0 AND (item_restrict = 0 ) ", intval($uid), - db_utcnow(), db_quoteinterval(intval($days).' DAY'), - intval(ITEM_RETAINED) + db_utcnow(), db_quoteinterval(intval($days).' DAY') ); if(! $r) @@ -3901,8 +3902,7 @@ function item_expire($uid,$days) { } function retain_item($id) { - $r = q("update item set item_flags = (item_flags | %d ) where id = %d", - intval(ITEM_RETAINED), + $r = q("update item set item_retained = 1 where id = %d", intval($id) ); } diff --git a/include/text.php b/include/text.php index 720895810..101d6ca2e 100644 --- a/include/text.php +++ b/include/text.php @@ -1152,7 +1152,7 @@ function link_compare($a,$b) { function unobscure(&$item) { - if(array_key_exists('item_flags',$item) && ($item['item_flags'] & ITEM_OBSCURED)) { + if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { $key = get_config('system','prvkey'); if($item['title']) $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']),$key); diff --git a/mod/editpost.php b/mod/editpost.php index dfbc8766e..4ea0c9f2b 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -55,7 +55,7 @@ function editpost_content(&$a) { - if($itm[0]['item_flags'] & ITEM_OBSCURED) { + if(intval($itm[0]['item_obscured'])) { $key = get_config('system','prvkey'); if($itm[0]['title']) $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); diff --git a/mod/editwebpage.php b/mod/editwebpage.php index 191c9a9ac..d7969fb2d 100644 --- a/mod/editwebpage.php +++ b/mod/editwebpage.php @@ -95,7 +95,7 @@ function editwebpage_content(&$a) { intval($owner) ); - if($itm[0]['item_flags'] & ITEM_OBSCURED) { + if(intval($itm[0]['item_obscured'])) { $key = get_config('system','prvkey'); if($itm[0]['title']) $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); diff --git a/mod/filer.php b/mod/filer.php index 9a409177c..e243687e3 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -27,8 +27,7 @@ function filer_content(&$a) { intval(local_user()) ); if($r) { - $x = q("update item set item_flags = ( item_flags | %d ) where id = %d and uid = %d", - intval(ITEM_RETAINED), + $x = q("update item set item_retained = 1 where id = %d and uid = %d", intval($r[0]['parent']), intval(local_user()) ); diff --git a/mod/item.php b/mod/item.php index a6ab99ef5..26985dea4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -330,11 +330,6 @@ function item_post(&$a) { $body = $_REQUEST['body']; $item_flags = $orig_post['item_flags']; - // force us to recalculate if we need to obscure this post - - if($item_flags & ITEM_OBSCURED) - $item_flags = ($item_flags ^ ITEM_OBSCURED); - $item_restrict = $orig_post['item_restrict']; $postopts = $orig_post['postopts']; $created = $orig_post['created']; @@ -765,13 +760,13 @@ function item_post(&$a) { if($uid) { if($channel['channel_hash'] === $datarray['author_xchan']) { $datarray['sig'] = base64url_encode(rsa_sign($datarray['body'],$channel['channel_prvkey'])); - $datarray['item_flags'] = $datarray['item_flags'] | ITEM_VERIFIED; + $datarray['item_verified'] = 1; } } logger('Encrypting local storage'); $key = get_config('system','pubkey'); - $datarray['item_flags'] = $datarray['item_flags'] | ITEM_OBSCURED; + $datarray['item_obscured'] = 1; if($datarray['title']) $datarray['title'] = json_encode(crypto_encapsulate($datarray['title'],$key)); if($datarray['body']) diff --git a/mod/viewsrc.php b/mod/viewsrc.php index 982d1c417..83acb1c23 100644 --- a/mod/viewsrc.php +++ b/mod/viewsrc.php @@ -21,14 +21,14 @@ function viewsrc_content(&$a) { } if(local_user() && $item_id) { - $r = q("select item_flags, body from item where item_restrict = 0 and uid in (%d , %d) and id = %d limit 1", + $r = q("select id, item_flags, item_obscured, body from item where item_restrict = 0 and uid in (%d , %d) and id = %d limit 1", intval(local_user()), intval($sys['channel_id']), intval($item_id) ); if($r) { - if($r[0]['item_flags'] & ITEM_OBSCURED) + if(intval($r[0]['item_obscured'])) $r[0]['body'] = crypto_unencapsulate(json_decode($r[0]['body'],true),get_config('system','prvkey')); $o = (($json) ? json_encode($r[0]['body']) : str_replace("\n",'
',$r[0]['body'])); } -- cgit v1.2.3 From 4c2a1e572a03e253f05f03e400af26d403cbda32 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Jan 2015 21:04:54 -0800 Subject: start on item_restrict conversion --- include/diaspora.php | 12 ++++++------ include/expire.php | 3 +-- include/identity.php | 3 +-- include/items.php | 55 +++++++++++++++++++++++++++++++++------------------- include/notifier.php | 7 +++---- include/poller.php | 5 ++--- mod/display.php | 2 +- mod/item.php | 7 +++---- mod/photos.php | 13 +------------ 9 files changed, 53 insertions(+), 54 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index b9c6e5c92..317a4cbf9 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -206,7 +206,7 @@ function diaspora_process_outbound($arr) { if(! $contact['xchan_pubkey']) continue; - if(($target_item['item_restrict'] & ITEM_DELETED) + if(intval($target_item['item_deleted']) && (($target_item['mid'] === $target_item['parent_mid']) || $arr['followup'])) { // send both top-level retractions and relayable retractions for owner to relay diaspora_send_retraction($target_item,$arr['channel'],$contact); @@ -235,8 +235,8 @@ function diaspora_process_outbound($arr) { $contact = $arr['hub']; - if(($target_item['deleted']) - && ($target_item['mid'] === $target_item['parent_mod'])) { + if(intval($target_item['item_deleted']) + && ($target_item['mid'] === $target_item['parent_mid'])) { // top-level retraction logger('delivery: diaspora retract: ' . $loc); diaspora_send_retraction($target_item,$arr['channel'],$contact,true); @@ -2453,7 +2453,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) { $target_type = 'Post'; $positive = 'true'; - if(($item_['item_restrict'] & ITEM_DELETED)) + if(intval($item['item_deleted'])) logger('diaspora_send_followup: received deleted "like". Those should go to diaspora_send_retraction'); } else { @@ -2549,7 +2549,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $relay_retract = false; $sql_sign_id = 'iid'; - if( $item['item_restrict'] & ITEM_DELETED) { + if( intval($item['item_deleted']) { $relay_retract = true; $target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); @@ -2561,7 +2561,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $like = true; $target_type = ( $parent['mid'] === $parent['parent_mid'] ? 'Post' : 'Comment'); -// $positive = (($item['item_restrict'] & ITEM_DELETED) ? 'false' : 'true'); +// $positive = (intval($item['item_deleted']) ? 'false' : 'true'); $positive = 'true'; $tpl = get_markup_template('diaspora_like_relay.tpl'); diff --git a/include/expire.php b/include/expire.php index a229bd4ac..b0bf55e4f 100644 --- a/include/expire.php +++ b/include/expire.php @@ -7,8 +7,7 @@ function expire_run($argv, $argc){ cli_startup(); - $r = q("select id from item where (item_restrict & %d)>0 and not (item_restrict & %d)>0 and changed < %s - INTERVAL %s", - intval(ITEM_DELETED), + $r = q("select id from item where item_deleted = 1 and not (item_restrict & %d)>0 and changed < %s - INTERVAL %s", intval(ITEM_PENDING_REMOVE), db_utcnow(), db_quoteinterval('10 DAY') ); diff --git a/include/identity.php b/include/identity.php index ce29e71f0..028df681e 100644 --- a/include/identity.php +++ b/include/identity.php @@ -589,8 +589,7 @@ function identity_basic_export($channel_id, $items = false) { // warning: this may run into memory limits on smaller systems - $r = q("select * from item where item_wall = 1 and not (item_restrict & %d)>0 and uid = %d", - intval(ITEM_DELETED), + $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d", intval($channel_id) ); if($r) { diff --git a/include/items.php b/include/items.php index 43739b605..180600495 100755 --- a/include/items.php +++ b/include/items.php @@ -839,7 +839,7 @@ function get_item_elements($x) { $arr['item_consensus'] = 1; if(array_key_exists('flags',$x) && in_array('deleted',$x['flags'])) - $arr['item_restrict'] = ITEM_DELETED; + $arr['item_deleted'] = 1; if(array_key_exists('flags',$x) && in_array('hidden',$x['flags'])) $arr['item_restrict'] = ITEM_HIDDEN; @@ -1310,7 +1310,7 @@ function encode_item_flags($item) { $ret = array(); - if($item['item_restrict'] & ITEM_DELETED) + if(intval($item['item_deleted'])) $ret[] = 'deleted'; if($item['item_restrict'] & ITEM_HIDDEN) $ret[] = 'hidden'; @@ -2109,7 +2109,7 @@ function item_store($arr,$allow_exec = false) { } $parent_id = $r[0]['id']; - $parent_deleted = $r[0]['item_restrict'] & ITEM_DELETED; + $parent_deleted = $r[0]['item_deleted']; $allow_cid = $r[0]['allow_cid']; $allow_gid = $r[0]['allow_gid']; $deny_cid = $r[0]['deny_cid']; @@ -2149,7 +2149,7 @@ function item_store($arr,$allow_exec = false) { } if($parent_deleted) - $arr['item_restrict'] = $arr['item_restrict'] | ITEM_DELETED; + $arr['item_deleted'] = 1; $r = q("SELECT `id` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", @@ -3347,7 +3347,7 @@ function consume_feed($xml,$importer,&$contact,$pass = 0) { if($r) { $item = $r[0]; - if(! ($item['item_restrict'] & ITEM_DELETED)) { + if(! intval($item['item_deleted'])) { logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . base64url_decode($item['mid']), LOGGER_DEBUG); drop_item($item['id'],false); } @@ -3948,7 +3948,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal intval($id) ); - if((! $r) || (($r[0]['item_restrict'] & ITEM_DELETED) && ($stage === DROPITEM_NORMAL))) { + if((! $r) || (intval($r[0]['item_deleted']) && ($stage === DROPITEM_NORMAL))) { if(! $interactive) return 0; notice( t('Item not found.') . EOL); @@ -3979,11 +3979,17 @@ 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. - $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ) WHERE id = %d", - intval(($linked_item && ! $force) ? ITEM_HIDDEN : ITEM_DELETED), - intval($item['id']) - ); - + if($linked_item) && ! $force) { + $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ) WHERE id = %d", + intval(ITEM_HIDDEN), + intval($item['id']) + ); + } + else { + $r = q("UPDATE item SET item_deleted = 1 WHERE id = %d", + intval($item['id']) + ); + } $arr = array('item' => $item, 'interactive' => $interactive, 'stage' => $stage); call_hooks('drop_item', $arr ); @@ -4047,13 +4053,23 @@ function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL,$force = false) { break; case DROPITEM_PHASE1: - $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), - changed = '%s', edited = '%s' WHERE id = %d", - intval(($linked_item && ! $force) ? ITEM_HIDDEN : ITEM_DELETED), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($item['id']) - ); + if($linked_item && ! $force) { + $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), + changed = '%s', edited = '%s' WHERE id = %d", + intval(ITEM_HIDDEN), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($item['id']) + ); + } + else { + $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where if = %d", + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($item['id']) + ); + } + break; case DROPITEM_NORMAL: @@ -4068,9 +4084,8 @@ function delete_item_lowlevel($item,$stage = DROPITEM_NORMAL,$force = false) { ); } else { - $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ), body = '', title = '', + $r = q("UPDATE item SET item_deleted = 1, body = '', title = '', changed = '%s', edited = '%s' WHERE id = %d", - intval(ITEM_DELETED), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($item['id']) diff --git a/include/notifier.php b/include/notifier.php index 092b27498..6a6879ebb 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -207,9 +207,8 @@ function notifier_run($argv, $argc){ $normal_mode = false; $expire = true; $items = q("SELECT * FROM item WHERE uid = %d AND item_wall = 1 - AND ( item_restrict & %d )>0 AND `changed` > %s - INTERVAL %s", + AND item_deleted = 1 AND `changed` > %s - INTERVAL %s", intval($item_id), - intval(ITEM_DELETED), db_utcnow(), db_quoteinterval('10 MINUTE') ); $uid = $item_id; @@ -314,7 +313,7 @@ function notifier_run($argv, $argc){ $target_item = $r[0]; - if($target_item['item_restrict'] & ITEM_DELETED) + 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; @@ -407,7 +406,7 @@ function notifier_run($argv, $argc){ // don't send deletions onward for other people's stuff // TODO verify this is needed - copied logic from same place in old code - if(($target_item['item_restrict'] & ITEM_DELETED) && (! intval($target_item['item_wall']))) { + if(intval($target_item['item_deleted']) && (! intval($target_item['item_wall']))) { logger('notifier: ignoring delete notification for non-wall item'); return; } diff --git a/include/poller.php b/include/poller.php index 896553a43..a9647c725 100644 --- a/include/poller.php +++ b/include/poller.php @@ -53,10 +53,9 @@ function poller_run($argv, $argc){ // expire any expired items $r = q("select id from item where expires != '%s' and expires < %s - and ( item_restrict & %d ) = 0 ", + and item_deleted = 0 ", dbesc(NULL_DATE), - db_utcnow(), - intval(ITEM_DELETED) + db_utcnow() ); if($r) { require_once('include/items.php'); diff --git a/mod/display.php b/mod/display.php index b9b660fdd..740050e41 100644 --- a/mod/display.php +++ b/mod/display.php @@ -250,7 +250,7 @@ function display_content(&$a, $update = 0, $load = false) { dbesc($item_hash) ); if($r) { - if($r[0]['item_flags'] & ITEM_DELETED) { + if(intval($r[0]['item_deleted'])) { notice( t('Item has been removed.') . EOL ); } else { diff --git a/mod/item.php b/mod/item.php index 26985dea4..294ee641f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1047,11 +1047,10 @@ 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 not (i.item_restrict & %d)>0 and i.uid= %d ", + and i.parent=i.id and (i.item_restrict & %d)>0 and i.item_deleted = 0 and i.uid= %d ", intval(ITEM_WEBPAGE), - intval(ITEM_DELETED), - intval($channel_id) - ); + intval($channel_id) + ); } else { $r = q("select count(i.id) as total from item i diff --git a/mod/photos.php b/mod/photos.php index 216a562c7..5b86da2a1 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -180,19 +180,8 @@ function photos_post(&$a) { intval($page_owner_uid) ); if(count($i)) { - q("UPDATE `item` SET item_restrict = (item_restrict | %d), `edited` = '%s', `changed` = '%s' WHERE `parent_mid` = '%s' AND `uid` = %d", - intval(ITEM_DELETED), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($i[0]['mid']), - intval($page_owner_uid) - ); - + drop_item($i[0]['id'],true,DROPITEM_PHASE1); $url = $a->get_baseurl(); - $drop_id = intval($i[0]['id']); - - if($i[0]['visible']) - proc_run('php',"include/notifier.php","drop","$drop_id"); } } -- cgit v1.2.3 From e6bfe3f2c10e851ed5ba49886ec8d0a9a9de2296 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 26 Jan 2015 18:09:09 -0800 Subject: onedirsync merge --- include/onedirsync.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/onedirsync.php b/include/onedirsync.php index e611492af..215c90008 100644 --- a/include/onedirsync.php +++ b/include/onedirsync.php @@ -41,11 +41,10 @@ function onedirsync_run($argv, $argc){ intval(UPDATE_FLAGS_UPDATED) ); if($x) { - $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", + $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), - intval(UPDATE_FLAGS_UPDATED), - dbesc($x[0]['ud_date']) + intval(UPDATE_FLAGS_UPDATED) ); return; } -- cgit v1.2.3 From 0bfbe6d61d3c6250a162a29d2cdb0ec78ad02f1d Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 27 Jan 2015 19:58:43 -0800 Subject: sql typo --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zot.php b/include/zot.php index 18565a214..d8b9a1485 100644 --- a/include/zot.php +++ b/include/zot.php @@ -755,7 +755,7 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) { $arr['searchable'] = false; $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, - xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_selfcensored, xchan_deleted, xchan_pubforum, ) + xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_selfcensored, xchan_deleted, xchan_pubforum ) values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d) ", dbesc($xchan_hash), dbesc($arr['guid']), -- cgit v1.2.3 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 From 4a243b63f7019a1e56ecf03b138cd7fc396236c2 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 29 Jan 2015 20:09:48 -0800 Subject: cleanup event form and various required indicators on inputs --- include/datetime.php | 3 ++- mod/events.php | 7 ++++--- view/css/mod_events.css | 20 ++++++++++++++++---- view/theme/redbasic/css/style.css | 2 ++ view/tpl/event_form.tpl | 5 ++++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/datetime.php b/include/datetime.php index 346d03bd4..a387d84c4 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -174,7 +174,7 @@ function timesel($format, $h, $m, $id='timepicker') { * @param $maxfrom * set maximum date from picker with id $maxfrom (none by default) */ -function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '') { +function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '',$required = false) { // Once browser support is better this could probably be replaced with native HTML5 date picker $o = ''; @@ -209,6 +209,7 @@ function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pic $readable_format = str_replace('i','MM',$readable_format); $o .= "
"; + $o .= (($required) ? '*' : ''); $o .= '
'; $o .= ""; return $o; diff --git a/mod/events.php b/mod/events.php index 322106d3f..99e965e90 100755 --- a/mod/events.php +++ b/mod/events.php @@ -577,12 +577,13 @@ function events_content(&$a) { '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$category' => $category, - '$s_text' => t('Event Starts:') . ' *', + '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, + '$required' => '*', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), - '$s_dsel' => datetimesel($f,new DateTime(),DateTime::createFromFormat('Y',$syear+5),DateTime::createFromFormat('Y-m-d H:i',"$syear-$smonth-$sday $shour:$sminute"),'start_text'), + '$s_dsel' => datetimesel($f,new DateTime(),DateTime::createFromFormat('Y',$syear+5),DateTime::createFromFormat('Y-m-d H:i',"$syear-$smonth-$sday $shour:$sminute"),'start_text',true,true,'','',true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), @@ -593,7 +594,7 @@ function events_content(&$a) { '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, - '$t_text' => t('Title:') . ' *', + '$t_text' => t('Title:'), '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, diff --git a/view/css/mod_events.css b/view/css/mod_events.css index 0aef13aa6..8f4a69b4f 100644 --- a/view/css/mod_events.css +++ b/view/css/mod_events.css @@ -2,8 +2,14 @@ width: 400px; } -#event-summary { - width: 400px; +#event-summary-text, #event-start-text, #event-finish-text { + width: 200px; + float: left; +} + +#event-summary, #start_text, #finish_text { + width: 300px; + float: left; } .event-cats { @@ -12,6 +18,12 @@ } .required { - color: #ff0000; - font-size: 1.2rem; + float: left; +} + +#event-datetime-break { + clear: both; +} +#event-nofinish-break { + margin-bottom: 10px; } \ No newline at end of file diff --git a/view/theme/redbasic/css/style.css b/view/theme/redbasic/css/style.css index c95909085..73b13c1bf 100644 --- a/view/theme/redbasic/css/style.css +++ b/view/theme/redbasic/css/style.css @@ -1177,6 +1177,8 @@ nav .acpopup { .required { color: #FF0000; + font-size: 200%; + margin-left: 5px; } #event-start-text, #event-finish-text { diff --git a/view/tpl/event_form.tpl b/view/tpl/event_form.tpl index a4717415e..dbad6579e 100755 --- a/view/tpl/event_form.tpl +++ b/view/tpl/event_form.tpl @@ -14,9 +14,12 @@
{{$t_text}}
- +{{$required}} + +
{{$s_text}}
+ {{$s_dsel}}

-- cgit v1.2.3