本文整理汇总了PHP中post::preload_num_new_comments方法的典型用法代码示例。如果您正苦于以下问题:PHP post::preload_num_new_comments方法的具体用法?PHP post::preload_num_new_comments怎么用?PHP post::preload_num_new_comments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post
的用法示例。
在下文中一共展示了post::preload_num_new_comments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: while
$buff = NULL;
while ($obj = $db2->fetch_object($res)) {
$buff = new post($obj->type, FALSE, $obj);
if ($buff->error) {
continue;
}
$tmpposts[] = $buff;
if ($this->param('from') == 'ajax' && $this->param('onlypost') != "" && $this->param('onlypost') != $buff->post_tmp_id) {
continue;
}
$tmpids[] = $buff->post_tmp_id;
$postusrs[] = $buff->post_user->id;
}
unset($buff);
$postusrs = array_unique($postusrs);
post::preload_num_new_comments($tmpids);
ob_start();
$D->if_follow_me = array();
if (count($postusrs) > 0) {
$r = $db2->query('SELECT who FROM users_followed WHERE who IN (' . implode(',', $postusrs) . ') AND whom="' . $this->user->id . '"');
while ($o = $db2->fetch_object($r)) {
if (isset($D->if_follow_me[$o->who])) {
continue;
}
$D->if_follow_me[$o->who] = 1;
}
}
$D->i_follow = array_fill_keys(array_keys($this->network->get_user_follows($this->user->id, FALSE, 'hefollows')->follow_users), 1);
$D->i_follow[] = $this->user->id;
foreach ($tmpposts as $tmp) {
$D->p = $tmp;
示例2: preload_num_new_comments
public static function preload_num_new_comments($tmpid)
{
global $user, $db2;
if (!$user->is_logged) {
return 0;
}
static $loaded = array();
if (!is_array($tmpid)) {
if (isset($loaded[$tmpid])) {
return $loaded[$tmpid];
}
list($tp, $pid) = explode('_', $tmpid);
$newcomments = $db2->fetch_field('SELECT newcomments FROM ' . ($tp == 'private' ? 'posts_pr_comments_watch' : 'posts_comments_watch') . ' WHERE user_id="' . $user->id . '" AND post_id="' . $pid . '" LIMIT 1');
$loaded[$tmpid] = $newcomments ? intval($newcomments) : 0;
return $loaded[$tmpid];
}
$return = 0;
$publ = array();
$priv = array();
foreach ($tmpid as $i => $tid) {
if (isset($loaded[$tid])) {
$return += $loaded[$tid];
unset($tmpid[$i]);
continue;
}
list($tp, $pid) = explode('_', $tid);
$tp == 'private' ? $priv[] = $pid : ($publ[] = $pid);
}
if (count($publ) == 1) {
$return += post::preload_num_new_comments('public_' . reset($publ));
}
if (count($priv) == 1) {
$return += post::preload_num_new_comments('private_' . reset($priv));
}
$tmp = array();
if (count($publ) > 1) {
$r = $db2->query('SELECT post_id, newcomments FROM posts_comments_watch WHERE user_id="' . $user->id . '" AND post_id IN(' . implode(', ', $publ) . ') LIMIT ' . count($publ), FALSE);
while ($obj = $db2->fetch_object($r)) {
$tmp['public_' . $obj->post_id] = intval($obj->newcomments);
}
}
if (count($priv) > 1) {
$r = $db2->query('SELECT post_id, newcomments FROM posts_pr_comments_watch WHERE user_id="' . $user->id . '" AND post_id IN(' . implode(', ', $priv) . ') LIMIT ' . count($priv), FALSE);
while ($obj = $db2->fetch_object($r)) {
$tmp['private_' . $obj->post_id] = intval($obj->newcomments);
}
}
foreach ($tmpid as $tid) {
$loaded[$tid] = isset($tmp[$tid]) ? $tmp[$tid] : 0;
}
foreach ($tmp as $n) {
$return += $n;
}
return $return;
}