function mysite_type_popular($get_options = TRUE) {
$type = array(
'name' => t('Most popular'),
'description' => t('<b>Most Popular</b>: The MySite content most requested by users.'),
'include' => 'popular',
'prefix' => t(''),
'suffix' => t(''),
'category' => t('MySite'),
'weight' => 0,
'form' => FALSE,
'label' => t('Add Popular Content'),
'help' => t('Browse the list of the 100 most popular items on personal user pages.'),
'search' => FALSE
);
$basic_settings = variable_get('mysite_basic_popular_settings', array());
$type = array_merge($type, $basic_settings);
if ($get_options) {
$type['options'] = mysite_type_popular_options();
}
return $type;
}
function mysite_type_popular_active($type) {
$count = db_result(db_query("SELECT COUNT(mid) as count FROM {mysite_data}"));
if ($count > 0) {
return array($type => TRUE);
}
else {
return array($type => FALSE, 'message' => t('There is no content stored in MySite pages. Try again later.'));
}
}
function mysite_type_popular_options() {
$options = array();
$cache = cache_get('mysite:popular');
$items = unserialize($cache->data);
if (empty($items)) {
$sql = "SELECT type, type_id FROM {mysite_data}";
$result = db_query($sql);
$items = array();
while ($item = db_fetch_object($result)) {
if ($item->type == 'profile') {
$item->type_id = 0;
}
$items[$item->type .'-'. $item->type_id] = $items[$item->type .'-'. $item->type_id] + 1;
}
arsort($items);
$list = array_chunk($items, 100, TRUE);
$items = $list[0];
cache_set('mysite:popular', 'cache', serialize($items), time() + (3600 * 8));
}
$types = mysite_load_includes('types');
foreach ($items as $key => $value) {
$data = explode('-', $key);
$type = $data[0];
$type_id = $data[1];
if (in_array($type, $types)) {
if ($type == 'profile') {
$type_id = arg(1);
}
$func = 'mysite_type_'. $type .'_title';
$options['name'][] = $func($type_id, NULL);
$options['type_id'][] = $type_id;
$options['type'][] = $type;
$icon = mysite_get_icon($type, $type_id);
$options['icon'][] = $icon;
}
}
return $options;
}
function mysite_type_popular_clear() {
cache_clear_all('mysite:popular', 'cache');
return array();
}