+ if($search)
+ $search = dbesc($search);
+ $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
+
+ $publish = ((get_config('system','publish_all') || $everything) ? '' : " AND `publish` = 1 " );
+
+
+ $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
+ if(count($r))
+ $a->set_pager_total($r[0]['total']);
+
+ if($everything)
+ $order = " ORDER BY `register_date` DESC ";
+ else
+ $order = " ORDER BY `name` ASC ";
+
+
+ $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
+ intval($a->pager['start']),
+ intval($a->pager['itemspage'])
+ );