variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'), '!points' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), '!point' => variable_get(USERPOINTS_TRANS_LCPOINT, 'point') ); } return $trans; } function userpoints_help($section) { switch ($section) { case 'admin/settings/userpoints': $output = t('Users earn !points as they post nodes, comments, and vote on nodes', userpoints_translation()); break; } return $output; } function userpoints_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'userpoints', 'callback' => 'userpoints_list_users', 'title' => t('Users by !Points', userpoints_translation()), 'access' => user_access(USERPOINTS_PERM_VIEW), 'type' => MENU_NORMAL_ITEM); $items[] = array( 'path' => 'admin/settings/userpoints', 'title' => t('Userpoints'), 'description' => t('Userpoints settings.'), 'callback' => 'drupal_get_form', 'callback arguments' => 'userpoints_settings', 'access' => user_access(USERPOINTS_PERM_ADMIN), 'type' => MENU_NORMAL_ITEM,); } return $items; } function userpoints_perm() { return array (USERPOINTS_PERM_VIEW, USERPOINTS_PERM_USE, USERPOINTS_PERM_ADMIN); } function userpoints_settings() { $group = 'points'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#title' => t('!Points for each event', userpoints_translation()), ); foreach(node_get_types() as $type => $name) { $form[$group][USERPOINTS_POST. $type] = array( '#type' => 'textfield', '#title' => t('!Points for posting a !node-name', array_merge(userpoints_translation(), array('!node-name' => $name->name))), '#default_value' => variable_get(USERPOINTS_POST. $type, '0'), '#size' => 5, '#maxlength' => 5, ); } $form[$group][USERPOINTS_POST_COMMENT] = array( '#type' => 'textfield', '#title' => t('!Points for posting a Comment', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_POST_COMMENT, 0), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MODERATE_COMMENT] = array( '#type' => 'textfield', '#title' => t('!Points for moderating a Comment', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_MODERATE_COMMENT, 0), '#size' => 5, '#maxlength' => 5, ); if (module_exists('nodevote')) { $form[$group][USERPOINTS_NODEVOTE] = array( '#type' => 'textfield', '#title' => t('!Points for voting on a node (requires nodevote module)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_NODEVOTE, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exists('referral')) { $form[$group][USERPOINTS_REFERRAL] = array( '#type' => 'textfield', '#title' => t('!Points for referring a user (requires the referral module)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_REFERRAL, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exists('invite')) { $form[$group][USERPOINTS_INVITE_INVITE] = array( '#type' => 'textfield', '#title' => t('!Points for inviting a user (requires the invite module)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_INVITE_INVITE, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exists('invite')) { $form[$group][USERPOINTS_INVITE_REGISTER] = array( '#type' => 'textfield', '#title' => t('!Points when invited user registers (requires the invite module)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_INVITE_REGISTER, 0), '#size' => 5, '#maxlength' => 5, ); } if (module_exists('cart') && module_exists('payment')) { $group = 'ecommerce'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#collapsed' => true, '#title' => t('Ecommerce Options'), ); $form[$group][USERPOINTS_EC_EARN] = array( '#type' => 'textfield', '#title' => t('!Points awarded for buying (multiplied by price)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_EC_EARN, 0), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MIN_PURCHASE] = array( '#type' => 'textfield', '#title' => t('Smallest purchase for which !points are awarded', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_MIN_PURCHASE, '0.00'), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_EC_PAYMENT] = array( '#type' => 'radios', '#title' => t('Accept user !points as payment?', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_EC_PAYMENT, 0), '#options' => array(t('Disable'), t('Enable')), ); $form[$group][USERPOINTS_EC_SPEND] = array( '#type' => 'textfield', '#title' => t('!Points used in payment (for every dollar)', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_EC_SPEND, 1), '#size' => 5, '#maxlength' => 5, ); $form[$group][USERPOINTS_MIN_SPEND] = array( '#type' => 'textfield', '#title' => t('Number of !points that must be spent per purchase', userpoints_translation()), '#default_value' => variable_get(USERPOINTS_MIN_SPEND, 0), '#size' => 5, '#maxlength' => 5, ); } $group = 'advanced'; $form[$group] = array( '#type' => 'fieldset', '#collapsible' => true, '#collapsed' => true, '#title' => t('Advanced Options'), ); $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()), '#default_value' => variable_get(USERPOINTS_TRANS_UCPOINTS, 'Points'), '#size' => 20, '#maxlength' => 20, ); $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()), '#default_value' => variable_get(USERPOINTS_TRANS_LCPOINTS, 'points'), '#size' => 20, '#maxlength' => 20, ); $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()), '#default_value' => variable_get(USERPOINTS_TRANS_LCPOINT, 'point'), '#size' => 20, '#maxlength' => 20, ); return system_settings_form($form); } function userpoints_user($op, &$edit, &$user, $category = '') { switch($op) { case 'delete': db_query('DELETE FROM {userpoints} WHERE uid = %d', $user->uid); break; 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()), 'value' => $points, ); return array(t('!Points', userpoints_translation()) => $disp_points); break; } } function userpoints_list_users() { $sql = "SELECT p.uid, u.name, p.points FROM {userpoints} p INNER JOIN {users} u USING (uid) GROUP BY p.uid,u.name,p.points"; $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'), ); $sql .= tablesort_sql($header); $result = pager_query($sql, 30, 0, $sql_cnt); while ($data = db_fetch_object($result)) { $rows[] = array( array('data' => theme('username', $data)), array('data' => $data->points, 'align' => 'right'), ); } $output = theme('table', $header, $rows); $output .= theme('pager', NULL, 30, 0); return $output; } function userpoints_block($op = 'list', $delta = 0, $edit = array()) { global $user; $num = 5; $block_title = array(); $block_title[] = t('%user\'s !points', array_merge(array('%user' => $user->name), userpoints_translation())); $block_title[] = t('Highest Users'); switch ($op) { case 'list': $blocks[0]['info'] = $block_title[0]; $blocks[1]['info'] = $block_title[1]; return $blocks; case 'view': if (user_access(USERPOINTS_PERM_VIEW)) { switch ($delta) { case 0: $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()); $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()); } break; case 1: $title = $block_title[$delta]; $result = db_query_range('SELECT p.uid, u.name, p.points FROM {userpoints} p INNER JOIN {users} u USING (uid) GROUP BY p.uid ORDER BY p.points DESC', 0, $num); while ($data = db_fetch_object($result)) { $rows[] = array( array('data' => theme('username', $data)), array('data' => $data->points, 'align' => 'right')); } $header = array(t('User'), t('!Points', userpoints_translation())); $content = theme('table', $header, $rows); $content .= '