ugly postgres fixes

This commit is contained in:
zotlabs 2017-04-30 16:03:01 -07:00 committed by Mario Vavti
parent cbc906c438
commit d3fcef43f8

View File

@ -597,18 +597,24 @@ function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0 ) {
$random_sql = (($rand) ? " ORDER BY " . db_getfunc('RAND') . " " : ''); $random_sql = (($rand) ? " ORDER BY " . db_getfunc('RAND') . " " : '');
if(local_channel()) if(local_channel())
$ret[] = local_channel(); $ret[] = local_channel();
$x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' and ( v & %d ) > 0 ", $x = q("select uid, v from pconfig where cat = 'perm_limits' and k = 'view_stream' ");
intval($perms)
);
if($x) { if($x) {
$ids = ids_to_querystr($x,'uid'); $y = [];
$r = q("select channel_id from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 $random_sql $limit_sql ", foreach($x as $xv) {
intval(PAGE_ADULT|PAGE_CENSORED) if(intval($xv['v']) & $perms) {
); $y[] = $xv;
if($r) { }
foreach($r as $rr) }
if(! in_array($rr['channel_id'], $ret)) if($y) {
$ret[] = $rr['channel_id']; $ids = ids_to_querystr($y,'uid');
$r = q("select channel_id from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 $random_sql $limit_sql ",
intval(PAGE_ADULT|PAGE_CENSORED)
);
if($r) {
foreach($r as $rr)
if(! in_array($rr['channel_id'], $ret))
$ret[] = $rr['channel_id'];
}
} }
} }
@ -635,19 +641,25 @@ function stream_perms_xchans($perms = NULL ) {
if(local_channel()) if(local_channel())
$ret[] = get_observer_hash(); $ret[] = get_observer_hash();
$x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' and ( v & %d ) > 0 ", $x = q("select uid from pconfig where cat = 'perm_limits' and k = 'view_stream' ");
intval($perms)
);
if($x) { if($x) {
$ids = ids_to_querystr($x,'uid'); $y = [];
$r = q("select channel_hash from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 ", foreach($x as $xv) {
intval(PAGE_ADULT|PAGE_CENSORED) if(intval($xv['v']) & $perms) {
); $y[] = $xv;
}
}
if($y) {
$ids = ids_to_querystr($y,'uid');
$r = q("select channel_hash from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 ",
intval(PAGE_ADULT|PAGE_CENSORED)
);
if($r) { if($r) {
foreach($r as $rr) foreach($r as $rr)
if(! in_array($rr['channel_hash'], $ret)) if(! in_array($rr['channel_hash'], $ret))
$ret[] = $rr['channel_hash']; $ret[] = $rr['channel_hash'];
}
} }
} }
$str = ''; $str = '';