View source
<?php
module_load_include('php', 'mostpopular', 'mostpopular.api');
define('MOSTPOPULAR_STYLE_NONE', 0);
define('MOSTPOPULAR_STYLE_BASIC', 1);
define('MOSTPOPULAR_STYLE_FULL', 2);
function mostpopular_perm() {
return array(
'administer mostpopular',
);
}
function mostpopular_theme() {
return array(
'mostpopular_config_intervals_form' => array(
'arguments' => array(
'form' => NULL,
),
'file' => 'mostpopular.admin.inc',
),
'mostpopular_config_services_form' => array(
'arguments' => array(
'form' => NULL,
),
'file' => 'mostpopular.admin.inc',
),
'mostpopular_config_service_form_throttles' => array(
'arguments' => array(
'form' => NULL,
),
'file' => 'mostpopular.admin.inc',
),
'mostpopular_service_status' => array(
'arguments' => array(
'status' => 0,
),
'file' => 'mostpopular.admin.inc',
),
'mostpopular_page' => array(
'arguments' => array(
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_block' => array(
'arguments' => array(
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_services' => array(
'arguments' => array(
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_intervals' => array(
'arguments' => array(
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_items' => array(
'arguments' => array(
'items' => array(),
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_item' => array(
'arguments' => array(
'item' => NULL,
'sid' => 1,
'iid' => 1,
),
'file' => 'mostpopular.block.inc',
),
'mostpopular_items_none' => array(
'file' => 'mostpopular.block.inc',
),
);
}
function mostpopular_menu() {
$items = array();
$items['admin/settings/mostpopular'] = array(
'title' => 'Most Popular settings',
'description' => 'Configure the Most Popular functionality',
'page callback' => 'drupal_get_form',
'file' => 'mostpopular.admin.inc',
'page arguments' => array(
'mostpopular_settings_form',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/mostpopular/main'] = array(
'title' => 'Settings',
'description' => 'Configure the Most Popular functionality',
'file' => 'mostpopular.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mostpopular_settings_form',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/mostpopular/intervals'] = array(
'title' => 'Intervals',
'description' => 'Configure the intervals of time used by the Most Popular feature',
'file' => 'mostpopular.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mostpopular_intervals_form',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['admin/settings/mostpopular/services'] = array(
'title' => 'Services',
'description' => 'Configure the services available to the Most Popular feature',
'file' => 'mostpopular.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mostpopular_services_form',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$i = 0;
$services = MostPopularService::fetchSorted();
foreach ($services as $service) {
$items["admin/settings/mostpopular/services/{$service->sid}"] = array(
'title' => $service->name,
'description' => "Configure the {$service->title} service",
'file' => 'mostpopular.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mostpopular_service_config_form',
4,
),
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_LOCAL_TASK,
'weight' => $i++,
);
}
$items['admin/settings/mostpopular/refresh'] = array(
'title' => 'Refresh Stats',
'description' => 'Refresh the Most Popular stats',
'file' => 'mostpopular.admin.inc',
'page callback' => 'mostpopular_refresh',
'access callback' => 'user_access',
'access arguments' => array(
'administer mostpopular',
),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['mostpopular/items/%/%'] = array(
'title' => 'Most Popular Pages',
'file' => 'mostpopular.block.inc',
'page callback' => 'mostpopular_items_page',
'page arguments' => array(
2,
3,
),
'access callback' => 'user_access',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
$items['mostpopular/ajax/%/%'] = array(
'title' => 'Get the most popular stats via AJAX',
'file' => 'mostpopular.block.inc',
'page callback' => 'mostpopular_items_ajax',
'page arguments' => array(
2,
3,
),
'access callback' => 'user_access',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function mostpopular_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
return array(
0 => array(
'info' => t('Most Popular'),
'cache' => BLOCK_NO_CACHE,
),
);
case 'view':
switch ($delta) {
case 0:
global $is_page_authcache;
if ($is_page_authcache) {
$sid = 0;
$iid = 0;
}
else {
if (arg(0) == 'mostpopular' && arg(1) == 'items') {
$service = MostPopularService::fetch(arg(2));
$interval = MostPopularInterval::fetch(arg(3));
}
elseif (isset($_COOKIE['mostpopular'])) {
$cookie = $_COOKIE['mostpopular'];
$parts = split('/', $cookie);
if (count($parts) != 2) {
drupal_set_message(t('You have an invalid cookie for the most popular service'), 'error');
}
else {
$service = MostPopularService::fetch($parts[0]);
$interval = MostPopularInterval::fetch($parts[1]);
}
}
if (!isset($service)) {
$service = MostPopularService::getDefault();
}
if (!isset($interval)) {
$interval = MostPopularInterval::getDefault();
}
$sid = $service->sid;
$iid = $interval->iid;
}
return array(
'subject' => t('Most Popular'),
'content' => theme('mostpopular_block', $sid, $iid),
);
}
break;
}
}