/** * Get the total points the specified member has used (spent). * * @param MEMBER The member * @return integer The number of points the member has spent */ function points_used($member) { global $POINTS_USED_CACHE; if (array_key_exists($member, $POINTS_USED_CACHE)) { return $POINTS_USED_CACHE[$member]; } $_points = point_info($member); $points = array_key_exists('points_used', $_points) ? $_points['points_used'] : 0; $POINTS_USED_CACHE[$member] = $points; return $points; }
/** * Transfer gift-points into the specified member's account, courtesy of the system. * * @param SHORT_TEXT The reason for the transfer * @param integer The size of the transfer * @param MEMBER The member the transfer is to */ function system_gift_transfer($reason, $amount, $member_id) { require_lang('points'); require_code('points'); if (is_guest($member_id)) { return; } if ($amount == 0) { return; } $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'gift_to' => $member_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => 1)); $_before = point_info($member_id); $before = array_key_exists('points_gained_given', $_before) ? $_before['points_gained_given'] : 0; $new = strval($before + $amount); $GLOBALS['FORUM_DRIVER']->set_custom_field($member_id, 'points_gained_given', $new); global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE; if (array_key_exists($member_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$member_id] += $amount; } if (array_key_exists($member_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$member_id])) { $POINT_INFO_CACHE[$member_id]['points_gained_given'] += $amount; } //start add to mentor points if needed //$mentor_id=$GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id,'u_mentor'); $mentor_id = $GLOBALS['SITE_DB']->query_value_null_ok('members_mentors', 'mentor_id', array('member_id' => $member_id), '', true); if (isset($mentor_id) && !is_null($mentor_id) && intval($mentor_id) != 0) { //give points to mentor too $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'gift_to' => $mentor_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => 1)); $_before = point_info($mentor_id); $before = array_key_exists('points_gained_given', $_before) ? $_before['points_gained_given'] : 0; $new = strval($before + $amount); $GLOBALS['FORUM_DRIVER']->set_custom_field($mentor_id, 'points_gained_given', $new); if (array_key_exists($mentor_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$mentor_id] += $amount; } if (array_key_exists($mentor_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$mentor_id])) { $POINT_INFO_CACHE[$mentor_id]['points_gained_given'] += $amount; } } if (get_forum_type() == 'ocf') { require_code('ocf_posts_action'); require_code('ocf_posts_action2'); ocf_member_handle_promotion($member_id); } }
/** * Charge points from a specified member's account. * * @param MEMBER The member that is being charged * @param integer The amount being charged * @param SHORT_TEXT The reason for the charging */ function charge_member($member_id, $amount, $reason) { require_lang('points'); require_code('points'); $_before = point_info($member_id); $before = array_key_exists('points_used', $_before) ? intval($_before['points_used']) : 0; $new = $before + $amount; $GLOBALS['FORUM_DRIVER']->set_custom_field($member_id, 'points_used', strval($new)); add_to_charge_log($member_id, $amount, $reason); global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE; if (array_key_exists($member_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$member_id] -= $amount; } if (array_key_exists($member_id, $POINT_INFO_CACHE) && array_key_exists('points_used', $POINT_INFO_CACHE[$member_id])) { $POINT_INFO_CACHE[$member_id]['points_used'] += $amount; } }
/** * The UI for a points profile. * * @param MEMBER The ID of the member who is being viewed * @param ?MEMBER The ID of the member who is doing the viewing (NULL: current member) * @return tempcode The UI */ function points_profile($member_id_of, $member_id_viewing) { require_code('points'); require_css('points'); require_lang('points'); require_javascript('javascript_validation'); // Get info about viewing/giving user if (!is_guest($member_id_viewing)) { $viewer_gift_points_available = get_gift_points_to_give($member_id_viewing); } // Get info about viewed user $name = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of); if (is_null($name) || is_guest($member_id_of)) { warn_exit(do_lang_tempcode('USER_NO_EXIST')); } $title = get_page_title('_POINTS', true, array(escape_html($name))); $profile_link = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id_of, false, true); // Show stats about $member_id_of $post_count = $GLOBALS['FORUM_DRIVER']->get_post_count($member_id_of); $_point_info = point_info($member_id_of); $points_gained_given = array_key_exists('points_gained_given', $_point_info) ? $_point_info['points_gained_given'] : 0; $points_gained_rating = array_key_exists('points_gained_rating', $_point_info) ? $_point_info['points_gained_rating'] : 0; $points_gained_voting = array_key_exists('points_gained_voting', $_point_info) ? $_point_info['points_gained_voting'] : 0; $cedi_post_count = array_key_exists('points_gained_seedy', $_point_info) ? $_point_info['points_gained_seedy'] : 0; $chat_post_count = array_key_exists('points_gained_chat', $_point_info) ? $_point_info['points_gained_chat'] : 0; $points_used = points_used($member_id_of); $remaining = available_points($member_id_of); $gift_points_used = get_gift_points_used($member_id_of); //$_point_info['gift_points_used']; $gift_points_available = get_gift_points_to_give($member_id_of); $points_posting = intval(get_option('points_posting')); $points_rating = intval(get_option('points_rating')); $points_voting = intval(get_option('points_voting')); $points_joining = intval(get_option('points_joining')); $points_cedi_posting = intval(get_option('points_cedi', true)); $points_chat_posting = intval(get_option('points_chat', true)); $points_per_day = intval(get_option('points_per_day', true)); $points_per_daily_visit = intval(get_option('points_per_daily_visit', true)); $days_joined = intval(floor(floatval(time() - $GLOBALS['FORUM_DRIVER']->get_member_join_timestamp($member_id_of)) / (60.0 * 60.0 * 24.0))); $points_gained_auto = $points_per_day * $days_joined; $to = points_get_transactions('to', $member_id_of, $member_id_viewing); $from = points_get_transactions('from', $member_id_of, $member_id_viewing); // If we're staff, we can show the charge log too $chargelog_details = new ocp_tempcode(); if (has_specific_permission($member_id_viewing, 'view_charge_log')) { global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'charge_start'; $NON_CANONICAL_PARAMS[] = 'charge_sort'; $start = get_param_integer('charge_start', 0); $max = get_param_integer('charge_max', 10); $sortables = array('date_and_time' => do_lang_tempcode('DATE'), 'amount' => do_lang_tempcode('AMOUNT')); $test = explode(' ', get_param('charge_sort', 'date_and_time DESC'), 2); if (count($test) == 1) { $test[1] = 'DESC'; } list($sortable, $sort_order) = $test; if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) { log_hack_attack_and_exit('ORDERBY_HACK'); } $max_rows = $GLOBALS['SITE_DB']->query_value('chargelog', 'COUNT(*)', array('user_id' => $member_id_of)); $rows = $GLOBALS['SITE_DB']->query_select('chargelog c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND t.id=c.reason', array('*'), array('user_id' => $member_id_of), 'ORDER BY ' . $sortable . ' ' . $sort_order, $max, $start); $charges = new ocp_tempcode(); $fromname = get_site_name(); $toname = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of); if (is_null($toname)) { $toname = do_lang('UNKNOWN'); } require_code('templates_results_table'); $fields_title = results_field_title(array(do_lang_tempcode('DATE'), do_lang_tempcode('AMOUNT'), do_lang_tempcode('FROM'), do_lang_tempcode('TO'), do_lang_tempcode('REASON')), $sortables, 'charge_sort', $sortable . ' ' . $sort_order); foreach ($rows as $myrow) { $date = get_timezoned_date($myrow['date_and_time']); $amount = $myrow['amount']; if (get_page_name() != 'search' && array_key_exists('text_parsed', $myrow) && !is_null($myrow['text_parsed']) && $myrow['text_parsed'] != '' && $myrow['reason'] != 0) { $reason = new ocp_tempcode(); if (!$reason->from_assembly($myrow['text_parsed'], true)) { $reason = get_translated_tempcode($myrow['reason']); } } else { $reason = get_translated_tempcode($myrow['reason']); } $charges->attach(results_entry(array(escape_html($date), escape_html(integer_format($amount)), escape_html($fromname), escape_html($toname), $reason))); } $chargelog_details = results_table(do_lang_tempcode('CHARGES'), $start, 'charge_start', $max, 'charge_max', $max_rows, $fields_title, $charges, $sortables, $sortable, $sort_order, 'charge_sort', NULL, NULL, NULL, 8, 'fgfdgfdgfdgfdger4gtrhg', false, 'tab__points'); $chargelog_details->attach(do_template('POINTS_CHARGE', array('_GUID' => 'f1e2d45a7d920ab91553a5fd0728a5ad', 'URL' => build_url(array('page' => 'admin_points', 'type' => 'charge', 'redirect' => get_self_url(true)), get_module_zone('admin_points')), 'USER' => strval($member_id_of)))); } // Show giving form if (is_guest($member_id_viewing)) { $give_template = do_lang_tempcode('POINTS_MUST_LOGIN'); } else { $have_negative_gift_points = has_specific_permission($member_id_viewing, 'have_negative_gift_points'); $enough_ok = $viewer_gift_points_available > 0 || $have_negative_gift_points; $give_ok = $member_id_viewing != $member_id_of || has_specific_permission($member_id_viewing, 'give_points_self'); if ($enough_ok && $give_ok) { // Show how many points are available also $give_url = build_url(array('page' => 'points', 'type' => 'give', 'id' => $member_id_of), get_module_zone('points')); $give_template = do_template('POINTS_GIVE', array('_GUID' => 'fa1749d5a803d86b1efbcfde2ad81702', 'GIVE_URL' => $give_url, 'USER' => strval($member_id_of), 'VIEWER_GIFT_POINTS_AVAILABLE' => $have_negative_gift_points ? '' : integer_format($viewer_gift_points_available))); } else { $give_template = do_lang_tempcode('PE_LACKING_GIFT_POINTS'); } if (!$give_ok) { $give_template = new ocp_tempcode(); } if (!has_specific_permission($member_id_of, 'use_points')) { $give_template = new ocp_tempcode(); } } return do_template('POINTS_PROFILE', array('_GUID' => 'f91208ef0f9a1e1a8633ce307a778a8d', 'TITLE' => $title, 'MEMBER' => strval($member_id_of), 'PROFILE_LINK' => $profile_link, 'NAME' => $name, 'POINTS_JOINING' => integer_format($points_joining), 'POST_COUNT' => integer_format($post_count), 'POINTS_POSTING' => integer_format($points_posting), 'MULT_POINTS_POSTING' => integer_format($points_posting * $post_count), 'POINTS_PER_DAY' => integer_format($points_per_day), 'DAYS_JOINED' => integer_format($days_joined), 'MULT_POINTS_PER_DAY' => integer_format($points_per_day * $days_joined), 'POINTS_GAINED_AUTO' => integer_format($points_gained_auto), 'CEDI_POST_COUNT' => integer_format($cedi_post_count), 'POINTS_CEDI_POSTING' => integer_format($points_cedi_posting), 'MULT_POINTS_CEDI_POSTING' => integer_format($cedi_post_count * $points_cedi_posting), 'CHAT_POST_COUNT' => integer_format($chat_post_count), 'POINTS_CHAT_POSTING' => integer_format($points_chat_posting), 'MULT_POINTS_CHAT_POSTING' => integer_format($chat_post_count * $points_chat_posting), 'POINTS_RATING' => integer_format($points_rating), 'POINTS_GAINED_RATING' => integer_format($points_gained_rating), 'MULT_POINTS_RATING' => integer_format($points_rating * $points_gained_rating), 'POINTS_VOTING' => integer_format($points_voting), 'POINTS_GAINED_VOTING' => integer_format($points_gained_voting), 'MULT_POINTS_VOTING' => integer_format($points_voting * $points_gained_voting), 'POINTS_PER_DAILY_VISIT' => integer_format($points_per_daily_visit), 'POINTS_GAINED_GIVEN' => integer_format($points_gained_given), 'POINTS_USED' => integer_format($points_used), 'REMAINING' => integer_format($remaining), 'GIFT_POINTS_USED' => integer_format($gift_points_used), 'GIFT_POINTS_AVAILABLE' => integer_format($gift_points_available), 'TO' => $to, 'FROM' => $from, 'CHARGELOG_DETAILS' => $chargelog_details, 'GIVE' => $give_template)); }
/** * Standard modular UI/actualiser to edit an entry. * * @return tempcode The UI */ function __ed() { $id = mixed(); // Define type as mixed $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id')); $doing = 'EDIT_' . $this->lang_type; if ($this->catalogue && get_param('catalogue_name', '') != '') { $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name')))); if ($this->type_code == 'd') { $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title)); } elseif ($this->type_code == 'c') { $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title)); } } $title = get_page_title($doing); if ($this->second_stage_preview && get_param_integer('preview', 0) == 1) { return $this->preview_intercept($title); } if (method_exists($this, 'get_submitter')) { list($submitter, $date_and_time) = $this->get_submitter($id); if (!is_null($date_and_time) && addon_installed('points')) { $reverse = post_param_integer('reverse_point_transaction', 0); if ($reverse == 1) { $points_test = $GLOBALS['SITE_DB']->query_select('gifts', array('*'), array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id())); if (array_key_exists(0, $points_test)) { $amount = $points_test[0]['amount']; $sender_id = $points_test[0]['gift_from']; $recipient_id = $points_test[0]['gift_to']; $GLOBALS['SITE_DB']->query_delete('gifts', array('id' => $points_test[0]['id']), '', 1); if (!is_guest($sender_id)) { $_sender_gift_points_used = point_info($sender_id); $sender_gift_points_used = array_key_exists('gift_points_used', $_sender_gift_points_used) ? $_sender_gift_points_used['gift_points_used'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used - $amount)); } require_code('points'); $temp_points = point_info($recipient_id); $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) - $amount)); } } } } else { $submitter = NULL; } breadcrumb_set_parents(array_merge($GLOBALS['BREADCRUMB_SET_PARENTS'], array(array('_SELF:_SELF:_e' . $this->type_code . ':' . $id, strpos($doing, ' ') !== false ? protect_from_escaping($doing) : do_lang_tempcode($doing))))); $delete = post_param_integer('delete', 0); if ($delete == 1 || $delete == 2) { if (!is_null($this->permissions_require)) { check_delete_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name); } $doing = 'DELETE_' . $this->lang_type; if ($this->catalogue && get_param('catalogue_name', '') != '') { $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name')))); if ($this->type_code == 'd') { $doing = do_lang('CATALOGUE_GENERIC_DELETE', escape_html($catalogue_title)); } elseif ($this->type_code == 'c') { $doing = do_lang('CATALOGUE_GENERIC_DELETE_CATEGORY', escape_html($catalogue_title)); } } $title = get_page_title($doing); $test = $this->handle_confirmations($title); if (!is_null($test)) { return $test; } $this->delete_actualisation($id); // Delete custom fields if ($this->has_tied_catalogue()) { require_code('fields'); delete_form_custom_fields($this->award_type, $id); } /*if ((!is_null($this->redirect_type)) || ((!is_null(get_param('redirect',NULL))))) No - resource is gone now, and redirect would almost certainly try to take us back there { $url=(($this->redirect_type=='!') || (is_null($this->redirect_type)))?get_param('redirect'):build_url(array('page'=>'_SELF','type'=>$this->redirect_type),'_SELF'); return redirect_screen($title,$url,do_lang_tempcode('SUCCESS')); }*/ clear_ocp_autosave(); $description = is_null($this->do_next_description) ? do_lang_tempcode('SUCCESS') : $this->do_next_description; return $this->do_next_manager($title, $description, NULL); } else { if (!is_null($this->permissions_require)) { check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name); } $test = $this->handle_confirmations($title); if (!is_null($test)) { return $test; } if ($this->user_facing && !is_null($this->permissions_require) && array_key_exists('validated', $_POST)) { if (!has_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? '' : post_param($this->permissions_cat_name), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? '' : post_param($this->permissions_cat_name_b)))) { $_POST['validated'] = '0'; } } if (!is_null($this->upload)) { require_code('uploads'); } $description = $this->edit_actualisation($id); if (!is_null($this->new_id)) { $id = $this->new_id; } // Save custom fields if ($this->has_tied_catalogue()) { require_code('fields'); save_form_custom_fields($this->award_type, $id); } if ($this->output_of_action_is_confirmation && !is_null($description)) { return $description; } if (is_null($description)) { $description = do_lang_tempcode('SUCCESS'); } if (addon_installed('awards')) { if (!is_null($this->award_type)) { require_code('awards'); handle_award_setting($this->award_type, $id); } } if ($this->user_facing) { if ($this->check_validation && post_param_integer('validated', 0) == 0) { require_code('submit'); if ($this->send_validation_request) { $edit_url = build_url(array('page' => '_SELF', 'type' => '_e' . $this->type_code, 'id' => $id, 'validated' => 1), '_SELF', NULL, false, false, true); if (addon_installed('unvalidated')) { send_validation_request($doing, $this->table, $this->non_integer_id, $id, $edit_url); } } $description->attach(paragraph(do_lang_tempcode('SUBMIT_UNVALIDATED'))); } } } if (!is_null($this->redirect_type) || !is_null(get_param('redirect', NULL))) { $url = $this->redirect_type == '!' || is_null($this->redirect_type) ? make_string_tempcode(get_param('redirect')) : build_url(array('page' => '_SELF', 'type' => $this->redirect_type), '_SELF'); return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); } clear_ocp_autosave(); decache('main_awards'); return $this->do_next_manager($title, $description, $id); }
/** * Assign points to the current member for rating. */ function actualise_give_rating_points() { if (!is_guest() && addon_installed('points')) { require_code('points'); $_count = point_info(get_member()); $count = array_key_exists('points_gained_rating', $_count) ? $_count['points_gained_rating'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_rating', $count + 1); } }
/** * Edit a CEDI post * * @param AUTO_LINK The page ID * @param string The new post * @param BINARY Whether the post will be validated * @param ?MEMBER The member doing the action (NULL: current member) * @param boolean Whether to send out a staff e-mail about the new CEDI post * @return AUTO_LINK The post ID */ function cedi_add_post($page_id, $message, $validated = 1, $member = NULL, $send_mail = true) { if (is_null($member)) { $member = get_member(); } require_code('comcode_check'); check_comcode($message, NULL, false, NULL, true); if (!addon_installed('unvalidated')) { $validated = 1; } $id = $GLOBALS['SITE_DB']->query_insert('seedy_posts', array('validated' => $validated, 'edit_date' => NULL, 'the_message' => 0, 'the_user' => $member, 'date_and_time' => time(), 'page_id' => $page_id, 'seedy_views' => 0), true); require_code('attachments2'); $the_message = insert_lang_comcode_attachments(2, $message, 'cedi_post', strval($id)); $GLOBALS['SITE_DB']->query_update('seedy_posts', array('the_message' => $the_message), array('id' => $id), '', 1); // Log $GLOBALS['SITE_DB']->query_insert('seedy_changes', array('the_action' => 'CEDI_MAKE_POST', 'the_page' => $page_id, 'ip' => get_ip_address(), 'the_user' => $member, 'date_and_time' => time())); // Update post count if (addon_installed('points')) { require_code('points'); $_count = point_info($member); $count = array_key_exists('points_gained_seedy', $_count) ? $_count['points_gained_seedy'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_seedy', $count + 1); } // Stat update_stat('num_seedy_posts', 1); //update_stat('num_seedy_files',count($_FILES)); // Send e-mail to the staff. These exist because CEDI exists in the 'space' between a forum, and a website- usually there is no validation, but the content does need moderation (and unlike a forum, staff are unlikely to 'lurk') if ($send_mail) { dispatch_cedi_post_notification($id, 'ADD'); } if (get_option('show_post_validation') == '1') { decache('main_staff_checklist'); } return $id; }
/** * The actualiser for a gift point transaction. * * @return tempcode The UI */ function do_give() { $member_id_of = get_param_integer('id'); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('USER_POINT_FIND')), array('_SELF:_SELF:member:id=' . strval($member_id_of), do_lang_tempcode('_POINTS', escape_html($GLOBALS['FORUM_DRIVER']->get_username($member_id_of)))))); $title = get_page_title('POINTS'); $trans_type = post_param('trans_type', 'gift'); $amount = post_param_integer('amount'); $reason = post_param('reason'); $worked = false; $member_id_viewing = get_member(); if ($member_id_of == $member_id_viewing && !has_specific_permission($member_id_viewing, 'give_points_self')) { $message = do_lang_tempcode('PE_SELF'); } elseif (is_guest($member_id_viewing)) { $message = do_lang_tempcode('MUST_LOGIN'); } else { if ($trans_type == 'gift') { $anonymous = post_param_integer('anonymous', 0); $viewer_gift_points_available = get_gift_points_to_give($member_id_viewing); //$viewer_gift_points_used=get_gift_points_used($member_id_viewing); if ($viewer_gift_points_available < $amount && !has_specific_permission($member_id_viewing, 'have_negative_gift_points')) { $message = do_lang_tempcode('PE_LACKING_GIFT_POINTS'); } elseif ($amount < 0 && !has_specific_permission($member_id_viewing, 'give_negative_points')) { $message = do_lang_tempcode('PE_NEGATIVE_GIFT'); } elseif ($reason == '') { $message = do_lang_tempcode('IMPROPERLY_FILLED_IN'); } else { // Write transfer require_code('points2'); give_points($amount, $member_id_of, $member_id_viewing, $reason, $anonymous == 1); // Randomised gifts if (mt_rand(0, 4) == 1) { $message = do_lang_tempcode('PR_LUCKY'); $_current_gift = point_info($member_id_viewing); $current_gift = array_key_exists('points_gained_given', $_current_gift) ? $_current_gift['points_gained_given'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field($member_id_viewing, 'points_gained_given', $current_gift + 25); // TODO: 25 should be a config option } else { $message = do_lang_tempcode('PR_NORMAL'); } $worked = true; } } if ($trans_type == 'refund') { $trans_type = 'charge'; $amount = -$amount; } if ($trans_type == 'charge') { if (has_actual_page_access($member_id_viewing, 'adminzone')) { require_code('points2'); charge_member($member_id_of, $amount, $reason); $left = available_points($member_id_of); $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of); if (is_null($username)) { $username = do_lang('UNKNOWN'); } $message = do_lang_tempcode('USER_HAS_BEEN_CHARGED', escape_html($username), escape_html(integer_format($amount)), escape_html(integer_format($left))); $worked = true; } else { access_denied('I_ERROR'); } } } if ($worked) { // Show it worked / Refresh $url = build_url(array('page' => '_SELF', 'type' => 'member', 'id' => $member_id_of), '_SELF'); return redirect_screen($title, $url, $message); } else { return warn_screen($title, $message); } }
/** * Show poll block. * * @param boolean Whether to get the output instead of outputting it directly * @param ?AUTO_LINK Poll ID (NULL: read from environment) * @return ?object Output (NULL: outputted it already) */ function poll_script($ret = false, $param = NULL) { require_lang('polls'); require_css('polls'); if (is_null($param)) { $param = get_param_integer('param'); } $zone = get_param('zone', get_module_zone('polls')); if ($param == -1) { $rows = persistant_cache_get('POLL'); if (is_null($rows)) { $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('is_current' => 1), 'ORDER BY id DESC', 1); persistant_cache_set('POLL', $rows); } } else { $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('id' => $param), '', 1); } if (has_actual_page_access(NULL, 'cms_polls', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_polls')) { $submit_url = build_url(array('page' => 'cms_polls', 'type' => 'ad', 'redirect' => get_self_url(true, false)), get_module_zone('cms_polls')); } else { $submit_url = new ocp_tempcode(); } if (!array_key_exists(0, $rows)) { $content = do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'fdc85bb2e14bdf00830347e52f25cdac', 'HIGH' => true, 'TITLE' => do_lang_tempcode('POLL'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_POLL'), 'SUBMIT_URL' => $submit_url)); } else { $myrow = $rows[0]; $ip = get_ip_address(); // Show the poll normally $show_poll_results = get_param_integer('show_poll_results_' . strval($myrow['id']), 0); if ($show_poll_results == 0) { $content = show_poll(false, $myrow, $zone); } else { // Voting $cast = post_param_integer('cast_' . strval($myrow['id']), -1); if ($cast != -1) { if (may_vote_in_poll($myrow)) { if (addon_installed('points')) { require_code('points'); $_before = point_info(get_member()); $before = array_key_exists('points_gained_voting', $_before) ? $_before['points_gained_voting'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_voting', $before + 1); } $GLOBALS['SITE_DB']->query_update('poll', array('votes' . strval($cast) => $myrow['votes' . strval($cast)] + 1), array('id' => $myrow['id']), '', 1); $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => $cast)); $myrow['votes' . strval($cast)]++; } } else { // Viewing the results if (may_vote_in_poll($myrow)) { $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => is_guest() ? NULL : get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => NULL)); } } // Show poll, with results $content = show_poll(true, $myrow, $zone); } } if ($ret) { return $content; } // Display $echo = do_template('STYLED_HTML_WRAP', array('TITLE' => do_lang_tempcode('POLL'), 'FRAME' => true, 'CONTENT' => $content)); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); return NULL; }
/** * Set up a new session / Restore an existing one that was lost. * * @param MEMBER Logged in member * @param BINARY Whether the session should be considered confirmed * @param boolean Whether the session should be invisible * @return AUTO_LINK New session ID */ function create_session($member, $session_confirmed = 0, $invisible = false) { global $SESSION_CACHE; global $MEMBER_CACHED; $MEMBER_CACHED = $member; if ($invisible && get_option('is_on_invisibility') == '0') { $invisible = false; } $new_session = mixed(); $restored_session = delete_expired_sessions_or_recover($member); if (is_null($restored_session)) { // Generate random session $new_session = mt_rand(0, mt_getrandmax() - 1); // Store session $username = $GLOBALS['FORUM_DRIVER']->get_username($member); $new_session_row = array('the_session' => $new_session, 'last_activity' => time(), 'the_user' => $member, 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed, 'session_invisible' => $invisible ? 1 : 0, 'cache_username' => $username, 'the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => substr(get_page_name(), 0, 80), 'the_type' => substr(get_param('type', '', true), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80)); $GLOBALS['SITE_DB']->query_insert('sessions', $new_session_row, false, true); $SESSION_CACHE[$new_session] = $new_session_row; $big_change = true; } else { $new_session = $restored_session; $prior_session_row = $SESSION_CACHE[$new_session]; $new_session_row = array('the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => get_page_name(), 'the_type' => substr(either_param('type', ''), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80), 'last_activity' => time(), 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed); $big_change = $prior_session_row['last_activity'] < time() - 10 || $prior_session_row['session_confirmed'] != $session_confirmed || $prior_session_row['ip'] != $new_session_row['ip']; if ($big_change) { $GLOBALS['SITE_DB']->query_update('sessions', $new_session_row, array('the_session' => $new_session), '', 1, NULL, false, true); } $SESSION_CACHE[$new_session] = array_merge($SESSION_CACHE[$new_session], $new_session_row); } if ($big_change) { if (get_value('session_prudence') !== '1') { // With session prudence we don't store all these in persistant cache due to the size of it all. So only re-save if that's not on. persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } set_session_id($new_session); // We won't set it true here, but something that really needs it to persist might come back and re-set it // New sessions = Login points if (!is_null($member) && addon_installed('points') && addon_installed('stats') && !is_guest($member)) { $points_per_daily_visit = intval(get_option('points_per_daily_visit', true)); if ($points_per_daily_visit != 0) { // See if this is the first visit today $test = $GLOBALS['SITE_DB']->query_value('stats', 'MAX(date_and_time)', array('the_user' => $member)); if (!is_null($test)) { require_code('temporal'); require_code('tempcode'); if (date('d/m/Y', tz_time($test, get_site_timezone())) != date('d/m/Y', tz_time(time(), get_site_timezone()))) { require_code('points'); $_before = point_info($member); if (array_key_exists('points_gained_given', $_before)) { $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_given', strval(intval($_before['points_gained_given']) + $points_per_daily_visit)); } } } } } $GLOBALS['SESSION_CONFIRMED'] = $session_confirmed; return $new_session; }
/** * The actualiser to reverse a point gift transaction. * * @return tempcode The UI */ function reverse() { $title = get_page_title('REVERSE_TITLE'); $id = post_param_integer('id'); $rows = $GLOBALS['SITE_DB']->query_select('gifts', array('*'), array('id' => $id), '', 1); if (!array_key_exists(0, $rows)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $myrow = $rows[0]; $amount = $myrow['amount']; $sender_id = $myrow['gift_from']; $recipient_id = $myrow['gift_to']; $confirm = get_param_integer('confirm', 0); if ($confirm == 0) { $_sender_id = is_guest($sender_id) ? get_site_name() : $GLOBALS['FORUM_DRIVER']->get_username($sender_id); $_recipient_id = is_guest($recipient_id) ? get_site_name() : $GLOBALS['FORUM_DRIVER']->get_username($recipient_id); if (is_null($_sender_id)) { $_sender_id = do_lang('UNKNOWN'); } if (is_null($_recipient_id)) { $_recipient_id = do_lang('UNKNOWN'); } $preview = do_lang_tempcode('ARE_YOU_SURE_REVERSE', escape_html(integer_format($amount)), escape_html($_sender_id), escape_html($_recipient_id)); return do_template('CONFIRM_SCREEN', array('_GUID' => 'd3d654c7dcffb353638d08b53697488b', 'TITLE' => $title, 'PREVIEW' => $preview, 'URL' => get_self_url(false, false, array('confirm' => 1)), 'FIELDS' => build_keep_post_fields())); } $GLOBALS['SITE_DB']->query_delete('gifts', array('id' => $id), '', 1); if (!is_guest($sender_id)) { $_sender_gift_points_used = point_info($sender_id); $sender_gift_points_used = array_key_exists('gift_points_used', $_sender_gift_points_used) ? $_sender_gift_points_used['gift_points_used'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used - $amount)); } $temp_points = point_info($recipient_id); $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) - $amount)); // Show it worked / Refresh $url = get_param('redirect', NULL); if (is_null($url)) { $_url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Enter a message into the database for the specified room, and with the specified parameters. The message is filtered for banned words, and is compressed into a tempcode storage format. * * @param AUTO_LINK The room ID for the message to be posted in * @param LONG_TEXT The message body * @param SHORT_TEXT The font name for the message * @param SHORT_TEXT The text colour for the message * @param SHORT_INTEGER The wrap position for the message * @return boolean Whether the message was successfully posted or not */ function chat_post_message($room_id, $message, $font_name, $text_colour, $wrap_pos = 60) { // If it contains chatcode then we'll need to disable the word-filter if (strpos($message, '[') !== false && strpos($message, ']') !== false) { $wrap_pos = NULL; } // Have we been blocked by flood control? $is_im = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'is_im', array('id' => $room_id)); if ($is_im) { $time_last_message = NULL; } else { if (is_guest()) { $time_last_map = array('ip_address' => get_ip_address(), 'system_message' => 0); } else { $time_last_map = array('user_id' => get_member(), 'system_message' => 0); } $time_last_message = $GLOBALS['SITE_DB']->query_value_null_ok('chat_messages', 'MAX(date_and_time)', $time_last_map); if (!is_null($time_last_message)) { $time_left = $time_last_message - time() + intval(get_option('chat_flood_timelimit')); } } if (is_null($time_last_message) || $time_left <= 0) { // Check colour and font if ($text_colour == '') { $text_colour = get_option('chat_default_post_colour'); } if ($font_name == '') { $font_name = get_option('chat_default_post_font'); } // Decode colour code if (substr($text_colour, 0, 2) == '0x') { $text_colour = '#' . substr($text_colour, 2, strlen($text_colour) - 2); } // Store as assembled tempcode $_message_parsed = insert_lang_comcode(wordfilter_text($message), 4, NULL, false, NULL, $wrap_pos); $message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => get_ip_address(), 'room_id' => $room_id, 'user_id' => get_member(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => $text_colour, 'font_name' => $font_name), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); fwrite($myfile, strval($message_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); // Bot support $hooks = find_all_hooks('modules', 'chat_bots'); foreach (array_keys($hooks) as $hook) { require_code('hooks/modules/chat_bots/' . filter_naughty_harsh($hook)); $ob = object_factory('Hook_chat_bot_' . $hook, true); if (!is_null($ob) && method_exists($ob, 'reply_to_any_communication')) { $response = $ob->reply_to_any_communication($room_id, $message); if (!is_null($response)) { // Store bots message $_message_parsed = insert_lang_comcode(wordfilter_text($response), 4, NULL, false, NULL, $wrap_pos); $bot_message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => $hook, 'room_id' => $room_id, 'user_id' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); fwrite($myfile, strval($bot_message_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); } } } // Update points if (addon_installed('points')) { require_code('points'); $_count = point_info(get_member()); $count = array_key_exists('points_gained_chat', $_count) ? $_count['points_gained_chat'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_chat', $count + 1); } decache('side_shoutbox'); return true; } // Flood prevention has blocked us. Send a PM about it require_lang('chat'); $_message_parsed = insert_lang_comcode('[private="' . $GLOBALS['FORUM_DRIVER']->get_username(get_member()) . '"]' . do_lang('FLOOD_CONTROL_BLOCKED', integer_format($time_left)) . '[/private]', 4, NULL, false, NULL); // Can't wrap system messages, the Comcode parser won't know 'private' is a real tag so will wrap inside it's definition $message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 1, 'ip_address' => get_ip_address(), 'room_id' => $room_id, 'user_id' => get_member(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); fwrite($myfile, strval($message_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); return false; }