- $count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND
- (`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR
- `about` REGEXP '%s' OR `keywords` REGEXP '%s')".$extra_sql,
+ $search2 = "%".$search."%";
+
+ $count = q("SELECT count(*) AS `total` FROM `gcontact`
+ LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`
+ AND `contact`.`uid` = %d AND NOT `contact`.`blocked`
+ AND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')
+ WHERE (`contact`.`id` > 0 OR (NOT `gcontact`.`hide` AND `gcontact`.`network` IN ('%s', '%s', '%s') AND
+ ((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)))) AND
+ (`gcontact`.`url` LIKE '%s' OR `gcontact`.`name` LIKE '%s' OR `gcontact`.`location` LIKE '%s' OR
+ `gcontact`.`addr` LIKE '%s' OR `gcontact`.`about` LIKE '%s' OR `gcontact`.`keywords` LIKE '%s') $extra_sql",
+ intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND),