diff -uPr old/userpoints_top_contributors.module new/userpoints_top_contributors.module --- old/userpoints_top_contributors.module 2008-04-06 17:05:14.000000000 -0400 +++ new/userpoints_top_contributors.module 2008-06-13 08:16:58.250000000 -0400 @@ -11,7 +11,7 @@ $items[] = array( 'path' => 'userpoints/list/all', 'callback' => 'userpoints_top_contributors_list', - 'title' => t('Top Contributors'), + 'title' => t('Top Contributors'), 'access' => user_access(USERPOINTS_PERM_VIEW), 'type' => MENU_CALLBACK, ); @@ -19,7 +19,7 @@ $items[] = array( 'path' => 'userpoints/list/period', 'callback' => 'userpoints_top_contributors_list', - 'title' => t('Top Contributors: '. format_interval(variable_get(userpoints_top_contributors_period, 86400))), + 'title' => t('Top Contributors: '. format_interval(variable_get('userpoints_top_contributors_period', 86400))), 'access' => user_access(USERPOINTS_PERM_VIEW), 'type' => MENU_CALLBACK, ); @@ -33,53 +33,56 @@ } /** - * Implementation of hook_form_alter(). + * Implementation of hook_userpoints(). * * Extends User Points module with Top Contributors settings. */ -function userpoints_top_contributors_form_alter($form_id, &$form) { - 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_userpoints($op, $points = 0, $uid = 0, $operation = '') { + switch ($op) { + case 'setting': + $group = "top_contributors"; + + $form[$group] = array( + '#type' => 'fieldset', + '#title' => t('Top Contributors settings'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $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.'), + ); + + return $form; + break; + } } @@ -99,7 +102,7 @@ $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(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'), ); @@ -108,7 +111,7 @@ $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(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'), ); @@ -119,10 +122,10 @@ $result = pager_query($sql, $usr_cnt, 0, $sql_cnt); while ($data = db_fetch_object($result)) { if ($user->uid == $data->uid) { - $details = "  ". l("(details)", "myuserpoints"); + $details = '  '. l('(details)', 'myuserpoints'); } elseif (user_access(USERPOINTS_ADMIN)) { - $details = "  ". l("(details)", "myuserpoints/$data->uid"); + $details = '  '. l('(details)', "myuserpoints/{$data->uid}"); } else { $details = ''; @@ -136,7 +139,7 @@ ); } - $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(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); @@ -147,7 +150,7 @@ function userpoints_top_contributors_block($op = 'list', $delta = 0, $edit = array()) { global $user; - $usr_cnt = variable_get(userpoints_top_contributors_block_usercount, 10); + $usr_cnt = variable_get('userpoints_top_contributors_block_usercount', 10); switch ($op) { case 'list': @@ -161,17 +164,18 @@ $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); + 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'), - ); + array('data' => theme('username', $data)), + array('data' => number_format($data->lifetime_points), 'style' => 'text-align:right'), + ); } // current user max point total. if ($user->uid) { @@ -192,16 +196,17 @@ else { $title = t('Top Contributors: '. format_interval(variable_get(userpoints_top_contributors_period, 86400))); $result = db_query_range('SELECT p.uid, u.name, p.period_points - FROM {userpoints_top_contributors} p - INNER JOIN {users} u - USING (uid) - GROUP BY p.uid - ORDER BY period_points DESC', 0, $usr_cnt); + FROM {userpoints_top_contributors} p + INNER JOIN {users} u + USING (uid) + GROUP BY p.uid + ORDER BY period_points DESC', 0, $usr_cnt + ); while ($data = db_fetch_object($result)) { $rows[] = array( - array('data' => theme('username', $data)), - array('data' => number_format($data->period_points), 'style' => 'text-align:right'), - ); + array('data' => theme('username', $data)), + array('data' => number_format($data->period_points), 'style' => 'text-align:right'), + ); } $header = array( array('data' => t('User')), @@ -248,7 +253,7 @@ function _userpoints_top_contributors_create_summary_data() { - $period = time() - variable_get(userpoints_top_contributors_period, 86400); + $period = time() - variable_get('userpoints_top_contributors_period', 86400); // Empty the userpoints_top_contributors table db_query("TRUNCATE TABLE {userpoints_top_contributors}");