Exemplo n.º 1
1
 $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;
Exemplo n.º 2
0
 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;
 }