diff options
author | friendica <info@friendica.com> | 2012-07-16 23:14:11 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-07-16 23:14:11 -0700 |
commit | e03da2beba27afa7abb748ad5134215cf6b582a7 (patch) | |
tree | fd5aae08dc093624fa33457271f1031a7ab57d3d /include | |
parent | 54ffc32d7c4d9c9d1231bdfa2147b7dc6ef12743 (diff) | |
download | volse-hubzilla-e03da2beba27afa7abb748ad5134215cf6b582a7.tar.gz volse-hubzilla-e03da2beba27afa7abb748ad5134215cf6b582a7.tar.bz2 volse-hubzilla-e03da2beba27afa7abb748ad5134215cf6b582a7.zip |
first cut at a generalised item query function
Diffstat (limited to 'include')
-rw-r--r-- | include/iquery.php | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/include/iquery.php b/include/iquery.php new file mode 100644 index 000000000..6ec47da8c --- /dev/null +++ b/include/iquery.php @@ -0,0 +1,140 @@ +<?php + + +function network_query($a,$arr) { + + + $parent_options = ''; + $child_options = ''; + + $ordering = (($arr['order'] === 'post') ? "`created`" ? "`commented`") . " DESC"; + + $itemspage = get_pconfig($arr['uid'],'system','itemspage_network'); + $a->set_pager_itemspage(((intval($itemspage_network)) ? $itemspage_network : 40)); + + $pager_sql = ((intval($arr['update'])) ? '' : sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']))); + + $arr['cmin'] = ((x($arr,'cmin')) ? $arr['cmin'] : 0); + $arr['cmax'] = ((x($arr,'cmax')) ? $arr['cmax'] : 0); + + $simple_update = (($arr['update']) ? " and `item`.`unseen` = 1 " : ''); + + if($arr['new']) { + + // "New Item View" - show all items unthreaded in reverse created date order + + $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, + `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`, + `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, + `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + FROM `item`, `contact` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 + AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + $simple_update + AND `contact`.`closeness` >= %d and `contact`.`closeness` <= %d + AND `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + $sql_extra $sql_nets + ORDER BY `item`.`received` DESC $pager_sql ", + intval($arr['uid']), + intval($arr['cmin']), + intval($arr['cmax']) + + ); + + $items = fetch_post_tags($items); + return $items; + + } + if($update) { + $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid` + FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND + `contact`.`closeness` >= %d and `contact`.`closeness` <= %d + (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE ."' OR item.verb = '" . ACTIVITY_DISLIKE . "') + and `item`.`moderated` = 0 $simple_update + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + $sql_extra3 $sql_extra $sql_nets ", + intval($arr['uid']), + intval($arr['cmin']), + intval($arr['cmax']) + ); + } + else { + $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid` + FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 + AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + AND `contact`.`closeness` >= %d and `contact`.`closeness` <= %d + AND `item`.`parent` = `item`.`id` + $sql_extra3 $sql_extra $sql_nets + ORDER BY `item`.$ordering $pager_sql ", + intval($arr['uid']), + intval($arr['cmin']), + intval($arr['cmax']) + ); + } + + // Then fetch all the children of the parents that are on this page + + $parents_arr = array(); + $parents_str = ''; + + if(count($r)) { + foreach($r as $rr) + if(! in_array($rr['item_id'],$parents_arr)) + $parents_arr[] = $rr['item_id']; + $parents_str = implode(', ', $parents_arr); + + $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, + `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, + `contact`.`rel`, `contact`.`writable`, + `contact`.`network`, `contact`.`thumb`, `contact`.`self`, + `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` + FROM `item`, `contact` + WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 + AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id` + AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 + AND `item`.`parent` IN ( %s ) + $sql_extra ", + intval($arr['uid']), + dbesc($parents_str) + ); + + $items = fetch_post_tags($items); + + $items = conv_sort($items,$ordering); + } + else { + $items = array(); + } + + return $items; +} + + + + + + + + + + + + + + + + + + + + + + + + + + +}
\ No newline at end of file |