'userpoints_top_contributors_list', 'title' => t('Top Contributors'), 'access arguments' => array('view userpoints'), 'type' => MENU_CALLBACK, ); $items['userpoints/list/period'] = array( 'title callback' => 'userpoints_top_contributors_list_period_title', 'page callback' => 'userpoints_top_contributors_list', 'access arguments' => array('view userpoints'), 'type' => MENU_CALLBACK, ); return $items; } /** * Title callback for period page title. */ function userpoints_top_contributors_list_period_title() { $period = format_interval(variable_get(userpoints_top_contributors_period, 86400)); return t('Top Contributors: '. $period); } function userpoints_top_contributors_cron() { // Refresh the top users data _userpoints_top_contributors_create_summary_data(); } /** * Implementation of hook_form_alter(). * * Extends User Points module with Top Contributors settings. */ function userpoints_top_contributors_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'userpoints_admin_settings') { // Shift system_settings_form buttons. $weight = $form['buttons']['#weight']; $form['buttons']['#weight'] = $weight + 1; $group = "top_contributors"; $form[$group] = array( '#type' => 'fieldset', '#title' => t('Top Contributors settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t(''), ); $form[$group]['userpoints_top_contributors_block_usercount'] = array( '#type' => 'select', '#title' => t('Users per block'), '#default_value' => variable_get(userpoints_top_contributors_block_usercount, 30), '#options' => array(5 => 5, 10 => 10, 15 => 15), '#description' => t('Limit how many users to display in the Top Contributors block.'), ); $form[$group]['userpoints_top_contributors_period'] = array( '#type' => 'select', '#title' => t('Period for top users block and page'), '#default_value' => variable_get(userpoints_top_contributors_period, 86400), '#options' => drupal_map_assoc( array(86400, 172800, 259200, 259200, 432000, 604800, 1209600, 1814400, 2419200), 'format_interval'), '#description' => t('Time block used to calculate contributions made in a defined period. Set to 1 week, for example, if you want the "Contributions by period" block and page to list the top contributors in the past week.'), ); $form[$group]['userpoints_top_contributors_page_intro'] = array( '#type' => 'textarea', '#title' => t("Page Introduction"), '#default_value' => variable_get(userpoints_top_contributors_page_intro, '
Here\'s a list of our community\'s top contributors. Click any of the column headings to change the sort order of the table.
'), '#cols' => 70, '#rows' => 4, '#description' => t("Text to display at the top of the Top Contributors pages."), ); } } function userpoints_top_contributors_list() { global $user; $list_type = db_escape_string(arg(2)); $cron_last = variable_get('cron_last', NULL); $sql = "SELECT p.uid, p.rank, u.name, p.period_points, p.current_points, p.lifetime_points FROM {userpoints_top_contributors} p INNER JOIN {users} u USING (uid)"; $sql_cnt = "SELECT COUNT(uid) FROM {userpoints_top_contributors}"; if ($list_type == 'all') { $header = array( array('data' => t('Rank'), 'field' => 'p.rank'), array('data' => t('User'), 'field' => 'u.name'), array('data' => t(format_interval(variable_get(userpoints_top_contributors_period, 86400))), 'field' => 'period_points', 'style' => 'text-align:right'), array('data' => t('Current'), 'field' => 'current_points', 'style' => 'text-align:right'), array('data' => t('Lifetime'), 'field' => 'lifetime_points', 'sort' => 'desc', 'style' => 'text-align:right'), ); } else { $header = array( array('data' => t('Rank'), 'field' => 'p.rank'), array('data' => t('User'), 'field' => 'u.name'), array('data' => t(format_interval(variable_get(userpoints_top_contributors_period, 86400))), 'field' => 'period_points', 'sort' => 'desc', 'style' => 'text-align:right'), array('data' => t('Current'), 'field' => 'current_points', 'style' => 'text-align:right'), array('data' => t('Lifetime'), 'field' => 'lifetime_points', 'style' => 'text-align:right'), ); } $sql .= tablesort_sql($header); $usr_cnt = variable_get(USERPOINTS_REPORT_USERCOUNT, 30); $result = pager_query($sql, $usr_cnt, 0, $sql_cnt); while ($data = db_fetch_object($result)) { if ($user->uid == $data->uid) { $details = ' ('. l(t('details'), 'myuserpoints') .')'; } elseif (user_access('administer userpoints')) { $details = ' ('. l(t('details'), 'myuserpoints/'. $data->uid) .')'; } else { $details = ''; } $rows[] = array( array('data' => $data->rank .'.', 'style' => 'text-align:left'), array('data' => theme('username', $data) . $details), array('data' => number_format($data->period_points, 1), 'style' => 'text-align:right'), array('data' => number_format($data->current_points, 1), 'style' => 'text-align:right'), array('data' => number_format($data->lifetime_points, 1), 'style' => 'text-align:right'), ); } $output = t(variable_get(userpoints_top_contributors_page_intro, 'Here\'s a list of our community\'s top contributors. Click any of the column headings to change the sort order of the table.')); $output .= ''. t('Updated !time ago.', array('!time' => format_interval(time() - $cron_last))) .'
'; $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, $usr_cnt, 0); return $output; } function userpoints_top_contributors_block($op = 'list', $delta = 0, $edit = array()) { global $user; $usr_cnt = variable_get(userpoints_top_contributors_block_usercount, 10); switch ($op) { case 'list': $blocks[0]['info'] = t('Top Contributors'); $blocks[1]['info'] = t('Top Contributors by Period'); return $blocks; case 'view': if (user_access('view userpoints')) { if ($delta == 0) { $title = t('Top Contributors'); $result = db_query_range("SELECT p.uid, u.name, p.lifetime_points FROM {userpoints_top_contributors} p INNER JOIN {users} u USING (uid) GROUP BY p.uid ORDER BY p.lifetime_points DESC", 0, $usr_cnt); while ($data = db_fetch_object($result)) { $rows[] = array( array('data' => theme('username', $data)), array('data' => number_format($data->lifetime_points), 'style' => 'text-align:right'), ); } // current user max point total. if ($user->uid) { $data = db_fetch_object(db_query('SELECT * FROM {userpoints_top_contributors} WHERE uid = %d', $user->uid)); $rows[] = array( array('data' => t('Your current points: @cp