Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 3.58 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         // Count posts since last vivist
  2.         if ($user->data['is_registered'] && $config['load_search'] && $auth->acl_get('u_search') && $auth->acl_getf_global('f_search'))
  3.         {
  4.                 /*$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
  5.                
  6.                 if ($auth->acl_get('m_approve'))
  7.                 {
  8.                         $m_approve_fid_ary = array(-1);
  9.                         $m_approve_fid_sql = '';
  10.                 }
  11.                 else if ($auth->acl_getf_global('m_approve'))
  12.                 {
  13.                         $m_approve_fid_ary = array_diff(array_keys($auth->acl_getf('!m_approve', true)), $ex_fid_ary);
  14.                         $m_approve_fid_sql = ' AND (p.post_approved = 1' . ((sizeof($m_approve_fid_ary)) ? ' OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) : '') . ')';
  15.                 }
  16.                 else
  17.                 {
  18.                         $m_approve_fid_ary = array();
  19.                         $m_approve_fid_sql = ' AND p.post_approved = 1';
  20.                 }
  21.                
  22.                 // New posts count
  23.                 $sql = 'SELECT COUNT(t.topic_id) as count
  24.                         FROM ' . TOPICS_TABLE . ' t
  25.                         WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
  26.                                 AND t.topic_moved_id = 0' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
  27.                 $result = $db->sql_query($sql);
  28.                 $new_posts_count = (int) $db->sql_fetchfield('count');
  29.                
  30.                 // Unread posts count
  31.                 $sql_where = 'AND t.topic_moved_id = 0' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
  32.                 $unread_list = array();
  33.                 $unread_list = get_unread_topics($user->data['user_id'], $sql_where, 'ORDER BY t.topic_id DESC');
  34.                
  35.                 if (!empty($unread_list))
  36.                 {
  37.                         $sql = 'SELECT COUNT(t.topic_id) as count
  38.                                 FROM ' . TOPICS_TABLE . ' t
  39.                                 WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list));
  40.                         $result = $db->sql_query($sql);
  41.                         $unread_posts_count = (int) $db->sql_fetchfield('count');
  42.                 }
  43.                 else
  44.                 {
  45.                         $unread_posts_count = 0;
  46.                 }
  47.                
  48.                 $template->assign_vars(array(
  49.                         'NEW_POSTS_COUNT'               => $new_posts_count,
  50.                         'UNREAD_POSTS_COUNT'    => $unread_posts_count,
  51.                 ));
  52.         }*/
  53.                 // Include forum_id 0 (globals) in the list and then look up and include all other forums the user is authorized to read
  54.                 if (!isset($forum_ids))
  55.                 {
  56.                         $forum_ids[] = 0;
  57.                        
  58.                         $sql = 'SELECT forum_id
  59.                                 FROM ' . FORUMS_TABLE;
  60.                         $result = $db->sql_query($sql);
  61.                        
  62.                         while ($row = $db->sql_fetchrow($result))
  63.                         {
  64.                                 if ($auth->acl_get('f_read', $row['forum_id']))
  65.                                 {
  66.                                         $forum_ids[] = $row['forum_id'];
  67.                                 }
  68.                         }
  69.                        
  70.                         $db->sql_freeresult($result);
  71.                 }
  72.                
  73.                 $unread_posts_count = 0;
  74.                
  75.                 // Unread posts count
  76.                 $sql = $db->sql_build_query('SELECT', array(
  77.                         'SELECT'        => 'COUNT(p.post_id) as total',
  78.                        
  79.                         'FROM'          => array(
  80.                                 POSTS_TABLE => 'p'
  81.                         ),
  82.                        
  83.                         'LEFT_JOIN'     => array(
  84.                                 array(
  85.                                         'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
  86.                                         'ON'    => 'p.forum_id = ft.forum_id AND ft.user_id = ' . $user->data['user_id']
  87.                                 ),
  88.                                 array(
  89.                                         'FROM'  => array(TOPICS_TRACK_TABLE => 'tt'),
  90.                                         'ON'    => 'p.topic_id = tt.topic_id AND tt.user_id = ' . $user->data['user_id']
  91.                                 )
  92.                         ),
  93.                        
  94.                         'WHERE'         => '(p.post_time > tt.mark_time
  95.                                 OR (tt.mark_time IS NULL AND p.post_time > ft.mark_time)
  96.                                 OR (ft.mark_time IS NULL AND p.post_time > ' . $user->data['user_lastmark'] . '))
  97.                                 AND ' . $db->sql_in_set('p.forum_id', $forum_ids)
  98.                 ));
  99.                
  100.                 $result = $db->sql_query($sql);
  101.                 $unread_posts_count = $db->sql_fetchfield('total', false, $result);
  102.                 $db->sql_freeresult($result);
  103.                
  104.                 $template->assign_vars(array(
  105.                         //'NEW_POSTS_COUNT'             => $new_posts_count,
  106.                         'UNREAD_POSTS_COUNT'    => $unread_posts_count,
  107.                 ));
  108.         }