function herfablife_base_posts_page($uid = NULL) { $args = array(); $current_time = time(); // Handle single user stats. if (is_numeric($uid)) { $account = user_load(array('uid' => $uid)); if ($account->uid) { $args[] = $uid; $uid_where = " WHERE n.uid = %d"; $output .= '

Member: '. theme('username', $account) .'

'; $cid = 'herfablife_post_stats_for_'. $account->uid; $cache = cache_get($cid); } } else { $cid = 'herfablife_post_stats'; $cache = cache_get($cid); } $output .= $cache->data .'
'; $output .= 'expires on: '. $cache->expire .'
'; $output .= 'current time:'. time() .'

'; // If we find a cached version that has not yet expired. if ($cache->data) { $output .= 'cached content
'; $cache = $cache->data; $stats = unserialize($cache) .'
'; } else { cache_set($cid, 'cache', ''); } // If no cache version available. if (!$stats) { $sql = "SELECT n.nid, n.uid, n.type, n.status FROM {node} n" . $uid_where; $result = db_query($sql, $args); $stats = array(); $stats['total'] = db_num_rows($result); // Loop through the nodes and add counts where needed. while ($row = db_fetch_object($result)) { // Create stats array for node type. if (empty($stats[$row->type])) { $stats[$row->type] = array('published' => 0, 'unpublished' => 0); } // Add one for this node. if ($row->status) { $stats[$row->type]['published']++; $stats['published']++; } else { $stats[$row->type]['unpublished']++; $stats['unpublished']++; } // If not a user stats page, collect invidiual user totals. if (!$account->uid) { if (!$stats['users'][$row->uid]) { $stats['users'][$row->uid] = 0; } $stats['users'][$row->uid]++; } } // Cache results for 5 minutes. cache_set($cid, 'cache', serialize($stats), time() + (60 * 5)); } // Total overall. $output .= '
'; $output .= '

'. t('Total Posts: !t', array('!t' => (int) $stats['total'])) .'

'; $output .= '
'. t('Published: !t', array('!t' => (int) $stats['published'])) .'
'; $output .= '
'. t('Unpublished: !t', array('!t' => (int) $stats['unpublished'])) .'
'; $output .= '
'; $output .= '

'. t('Post By Type') .'

'; // Total for each node type. foreach ($stats as $type => $row) { if (is_array($row)) { $output .= '
'; $output .= '

'. ucwords(str_replace('_', ' ', $type)) .'s

'; $output .= '
'. t('Published: !t', array('!t' => $row['published'])) .'
'; $output .= '
'. t('Unpublished: !t', array('!t' => $row['unpublished'])) .'
'; $output .= '
'; } } // Total for each user. if (!empty($stats['users'])) { $users = array(); // Sort users by posts DESC. //arsort($stats['users']); foreach ($stats['users'] as $uid_stat => $uid_total) { $stat_account = user_load(array('uid' => $uid_stat)); $uid_link = l($stat_account->name, 'user/'. $stat_account->uid .'/stats/posts'); $users[] = t('!u: !t', array('!u' => $uid_link, '!t' => $uid_total)); } } if (!empty($users)) { $output .= theme('item_list', $users, t('By User')); } $output .= '

'. t('Please note that this page caches its results for 5 minutes at a time to save load on the server.') .'

'; print theme('page', $output); }