Index: userpoints.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.module,v retrieving revision 1.30.2.18 diff -u -r1.30.2.18 userpoints.module --- userpoints.module 26 Jan 2007 02:56:40 -0000 1.30.2.18 +++ userpoints.module 19 Feb 2007 02:49:02 -0000 @@ -1,6 +1,6 @@ variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'), - '%points' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), - '%point' => variable_get(USERPOINTS_TRANS_LCPOINT, 'point') + '!Points' => variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'), + '!points' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), + '!point' => variable_get(USERPOINTS_TRANS_LCPOINT, 'point') ); } return $trans; @@ -46,15 +46,23 @@ ); } +/** + * Implementation of hook_help(). + */ function userpoints_help($section) { switch ($section) { - case 'admin/modules#description': - $output = t('UP: An API for users to earn %points as they perform certain actions', userpoints_translation()); + case 'admin/settings/userpoints': + $output = t('Configure userpoints moderation and branding translation', userpoints_translation()); break; + case 'admin/help#userpoints': + $output = t('Users earn !points as they post nodes, comments, and vote on nodes', userpoints_translation()); } return $output; } +/** + * Implementation of hook_menu(). + */ function userpoints_menu($may_cache) { $items = array(); @@ -62,42 +70,57 @@ $items[] = array( 'path' => 'userpoints', 'callback' => 'userpoints_list_users', - 'title' => t('users by %points', userpoints_translation()), + 'title' => t('users by !points', userpoints_translation()), + 'description' => t('List users by !points', userpoints_translation()), 'access' => user_access(USERPOINTS_PERM_VIEW), 'type' => MENU_NORMAL_ITEM, ); $items[] = array( - 'path' => 'admin/userpoints/manage', + 'path' => 'admin/settings/userpoints', + 'callback' => 'drupal_get_form', + 'callback arguments' => array('userpoints_admin_settings'), + 'title' => t('Userpoints settings'), + 'description' => t('Congigure userpoints settings'), + 'access' => user_access(USERPOINTS_PERM_ADMIN), + 'type' => MENU_NORMAL_ITEM, + ); + + $items[] = array( + 'path' => 'admin/user/userpoints/manage', 'callback' => 'userpoints_admin_manage', - 'title' => t('%Points', userpoints_translation()), + 'title' => t('!Points', userpoints_translation()), + 'description' => t('Manage userpoints'), 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_NORMAL_ITEM, ); $items[] = array( - 'path' => 'admin/userpoints/manage/add', - 'callback' => 'userpoints_admin_txn', + 'path' => 'admin/user/userpoints/manage/add', + 'callback' => 'drupal_get_form', + 'callback arguments' => array('userpoints_admin_txn'), 'title' => t('add'), + 'description' => t('Admin add/delete userpoints'), 'access' => user_access(USERPOINTS_PERM_ADMIN), - 'type' => MENU_NORMAL_ITEM, + 'type' => MENU_NORMAL_ITEM, ); $items[] = array( - 'path' => 'admin/userpoints/manage/edit', - 'callback' => 'userpoints_admin_txn', + 'path' => 'admin/user/userpoints/manage/edit', + 'callback' => 'drupal_get_form', + 'callback arguments' => array('userpoints_admin_txn'), 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_CALLBACK, ); $items[] = array( - 'path' => 'admin/userpoints/approve', + 'path' => 'admin/user/userpoints/approve', 'callback' => 'userpoints_admin_approve', 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_CALLBACK, ); $items[] = array( - 'path' => 'admin/userpoints/decline', + 'path' => 'admin/user/userpoints/decline', 'callback' => 'userpoints_admin_approve', 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_CALLBACK, @@ -108,11 +131,17 @@ return $items; } +/** + * Implementation of hook_perm(). + */ function userpoints_perm() { return array (USERPOINTS_PERM_VIEW, USERPOINTS_PERM_USE, USERPOINTS_PERM_ADMIN); } -function userpoints_settings() { +/** + * menu callback for settings form. + */ +function userpoints_admin_settings() { $form['status'] = array( '#type' => 'fieldset', '#title' => t('Moderation'), @@ -126,7 +155,7 @@ '#title' => t('Transaction status'), '#default_value' => variable_get(USERPOINTS_POINTS_MODERATION, 0), '#options' => array(t('Approved'), t('Moderated')), - '#description' => t('Select whether all %points should be approved automatically, or moderated, and require admin approval', userpoints_translation()), + '#description' => t('Select whether all !points should be approved automatically, or moderated, and require admin approval', userpoints_translation()), ); $group = 'renaming'; @@ -139,7 +168,7 @@ $form[$group][USERPOINTS_TRANS_UCPOINTS] = array( '#type' => 'textfield', - '#title' => t('Word to use in the interface for the upper case plural word %Points', userpoints_translation()), + '#title' => t('Word to use in the interface for the upper case plural word !Points', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'), '#size' => 20, '#maxlength' => 20, @@ -147,7 +176,7 @@ $form[$group][USERPOINTS_TRANS_LCPOINTS] = array( '#type' => 'textfield', - '#title' => t('Word to use in the interface for the lower case plural word %points', userpoints_translation()), + '#title' => t('Word to use in the interface for the lower case plural word !points', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), '#size' => 20, '#maxlength' => 20, @@ -155,7 +184,7 @@ $form[$group][USERPOINTS_TRANS_LCPOINT] = array( '#type' => 'textfield', - '#title' => t('Word to use in the interface for the lower case singular word %point', userpoints_translation()), + '#title' => t('Word to use in the interface for the lower case singular word !point', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_TRANS_LCPOINT, 'point'), '#size' => 20, '#maxlength' => 20, @@ -163,7 +192,7 @@ $form['setting'] = module_invoke_all('userpoints', 'setting'); - return $form; + return system_settings_form($form); } /** @@ -186,7 +215,7 @@ * @param points: number of points to add (if positive) or subtract (if negative) * @param uid: user id of the user to get or lose the points * @param event: optional event ID - * @param description: optional description + * @param event: optional description * * @return FALSE when no action is take, TRUE when points are credited or debited */ @@ -228,7 +257,7 @@ $moderation = userpoints_transaction($points, $uid, $event, $description); if ($moderation) { // Points are moderated, so we do nothing for now. - drupal_set_message(t('User %uname %op %pointsvalue %points, pending administrator approval.', + drupal_set_message(t('User %uname %op %pointsvalue !points, pending administrator approval.', array_merge(userpoints_translation(), array( '%uname' => $user->name, '%op' => $msg, @@ -249,7 +278,7 @@ $max_points = $current_points + (int)$max_points; } - drupal_set_message(t('User %uname %op %pointsvalue %points! Total now is %total points.', + drupal_set_message(t('User %uname %op %pointsvalue !points! Total now is %total points.', array_merge(userpoints_translation(), array( '%uname' => $user->name, '%op' => $msg, @@ -304,10 +333,10 @@ case 'view': $points = (int)db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)); $disp_points[] = array( - 'title' => t('User %points', userpoints_translation()), + 'title' => t('User !points', userpoints_translation()), 'value' => $points, ); - return array(t('%Points', userpoints_translation()) => $disp_points); + return array(t('!Points', userpoints_translation()) => $disp_points); break; } } @@ -316,7 +345,7 @@ $header = array( array('data' => t('User'), 'field' => 'uid', 'sort' => 'desc'), array('data' => t('Time stamp'), 'field' => 'time_stamp'), - array('data' => t('%Points', userpoints_translation()), 'field' => 'points'), + array('data' => t('!Points', userpoints_translation()), 'field' => 'points'), array('data' => t('Event'), 'field' => 'event'), array('data' => t('Operation', userpoints_translation())), ); @@ -332,9 +361,9 @@ array('data' => format_date($data->time_stamp, 'custom', 'Y-m-d H:i')), array('data' => $data->points, 'align' => 'right'), array('data' => $data->event), - array('data' => l('approve', "admin/userpoints/approve/$data->txn_id") . - ' ' . l('decline', "admin/userpoints/decline/$data->txn_id") . - ' ' . l('edit', "admin/userpoints/manage/edit/$data->txn_id") + array('data' => l('approve', "admin/user/userpoints/approve/$data->txn_id") . + ' ' . l('decline', "admin/user/userpoints/decline/$data->txn_id") . + ' ' . l('edit', "admin/user/userpoints/manage/edit/$data->txn_id") ), ); } @@ -347,8 +376,8 @@ function userpoints_admin_approve() { global $user; - $op = arg(2); - $txn_id = (int)arg(3); + $op = arg(3); + $txn_id = (int)arg(4); if ($txn_id) { switch($op) { case 'approve': @@ -377,15 +406,15 @@ break; } } - drupal_goto('admin/userpoints/manage'); + drupal_goto('admin/user/userpoints/manage'); } function userpoints_admin_txn() { - $mode = arg(3); + $mode = arg(4); $timestamp = format_date(time(), 'custom', 'Y-m-d H:i O'); if ($mode == 'edit') { - $txn_id = (int)arg(4); + $txn_id = (int)arg(5); if ($txn_id) { $result = db_query('SELECT * FROM {userpoints_txn} WHERE txn_id = %d', $txn_id); $txn = db_fetch_object($result); @@ -419,7 +448,7 @@ '#maxlength' => 30, '#description' => t('Date and time of this transaction, in the form YYYY-MM-DD HH:MM +ZZZZ'), ); - + $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), @@ -495,8 +524,8 @@ '#type' => 'submit', '#value' => t('Save'), ); - - return drupal_get_form('userpoints_admin_txn', $form); + + return $form; } function userpoints_admin_txn_submit($form_id, $form = NULL) { @@ -525,7 +554,7 @@ drupal_set_message(t('Transaction has been updated.')); } - drupal_goto('admin/userpoints/manage'); + drupal_goto('admin/user/userpoints/manage'); } function userpoints_list_users() { @@ -535,7 +564,7 @@ $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {userpoints}"; $header = array( array('data' => t('User'), 'field' => 'u.name'), - array('data' => t('%Points', userpoints_translation()), 'field' => 'p.points', 'sort' => 'desc'), + array('data' => t('!Points', userpoints_translation()), 'field' => 'p.points', 'sort' => 'desc'), ); $sql .= tablesort_sql($header); $result = pager_query($sql, 30, 0, $sql_cnt); @@ -558,7 +587,7 @@ $num = 5; $block_title = array(); - $block_title[] = t('%user\'s %points', array_merge(array('%user' => $user->name), userpoints_translation())); + $block_title[] = t('%user\'s !points', array_merge(array('%user' => $user->name), userpoints_translation())); $block_title[] = t('Highest Users'); switch ($op) { @@ -574,12 +603,12 @@ $title = $block_title[$delta]; if ($user->uid) { $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)); - $singular = t('%point', userpoints_translation()); - $plural = t('%points', userpoints_translation()); + $singular = t('!point', userpoints_translation()); + $plural = t('!points', userpoints_translation()); $content = t('You have %p %c', array('%p' => $points, '%c' => format_plural($points, $singular, $plural))); } else { - $content = t('%Points are visible to logged in users only',userpoints_translation()); + $content = t('!Points are visible to logged in users only',userpoints_translation()); } break; @@ -595,9 +624,9 @@ array('data' => theme('username', $data)), array('data' => $data->points, 'align' => 'right')); } - $header = array(t('User'), t('%Points', userpoints_translation())); + $header = array(t('User'), t('!Points', userpoints_translation())); $content = theme('table', $header, $rows); - $content .= ''; + $content .= ''; break; }