$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
+ // splitted into two queries for performance issues
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
+ intval($datarray['uid']),
+ intval($datarray['contact-id']),
+ dbesc($datarray['verb']),
+ dbesc($parent_uri)
+ );
+ if($r && count($r))
+ continue;
+
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
dbesc($datarray['verb']),
- dbesc($parent_uri),
dbesc($parent_uri)
);
if($r && count($r))
$datarray['gravity'] = GRAVITY_LIKE;
$datarray['last-child'] = 0;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
+ // splitted into two queries for performance issues
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`parent-uri` = '%s') and deleted = 0 limit 1",
+ intval($datarray['uid']),
+ intval($datarray['contact-id']),
+ dbesc($datarray['verb']),
+ dbesc($datarray['parent-uri'])
+
+ );
+ if($r && count($r))
+ continue;
+
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s') and deleted = 0 limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
dbesc($datarray['verb']),
- dbesc($datarray['parent-uri']),
dbesc($datarray['parent-uri'])
);
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
+ // splitted into two queries for performance issues
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s') limit 1",
+ intval($datarray['uid']),
+ intval($datarray['contact-id']),
+ dbesc($datarray['verb']),
+ dbesc($parent_uri)
+ );
+ if($r && count($r))
+ continue;
+
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`thr-parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
dbesc($datarray['verb']),
- dbesc($parent_uri),
dbesc($parent_uri)
);
if($r && 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`.`dfrn-id`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM $sql_table 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 `item`.`parent` IN ( %s )
- $sql_extra ",
- intval(local_user()),
- dbesc($parents_str)
- );
+ //$parents_str = implode(', ', $parents_arr);
+ // splitted into separate queries to avoid the problem with very long threads
+ // so always the last X comments are loaded
+ // This problem can occur expecially with imported facebook posts
+ $max_comments = get_config("system", "max_comments");
+ if ($max_comments == 0)
+ $max_comments = 1000;
+
+ $items = array();
+
+ foreach ($parents_arr AS $parents_str) {
+
+ $thread_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`.`dfrn-id`, `contact`.`self`,
+ `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
+ FROM $sql_table 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 `item`.`parent` IN ( %s )
+ $sql_extra ORDER BY `item`.`commented` DESC LIMIT %d",
+ intval(local_user()),
+ dbesc($parents_str),
+ intval($max_comments + 1)
+ );
+ $items = array_merge($items, $thread_items);
+ }
$items = conv_sort($items,$ordering);
} else {
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
-
+
if(! count($user))
killme();
- $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
+ $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
dbesc($register[0]['hash'])
);
- $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
+ $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
intval($register[0]['uid'])
);
-
+
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
intval($user[0]['uid'])
);
if($res) {
info( t('Account approved.') . EOL );
return true;
- }
+ }
}
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid'])
);
-
- $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
+
+ $r = q("DELETE FROM `user` WHERE `uid` = %d",
intval($register[0]['uid'])
);
- $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
+ $r = q("DELETE FROM `contact` WHERE `uid` = %d",
intval($register[0]['uid'])
- );
- $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
+ );
+ $r = q("DELETE FROM `profile` WHERE `uid` = %d",
intval($register[0]['uid'])
- );
+ );
- $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
+ $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
dbesc($register[0]['hash'])
);
notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
return true;
-
+
}
function regmod_content(&$a) {