/** * Get nru group id * * @return int group id */ public function getnruid() { $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_name = 'NEWLY_REGISTERED'\n\t\t\t\t\tAND group_type = " . GROUP_SPECIAL; $result = $this->db->sql_query($sql); $group_id = $this->db->sql_fetchfield('group_id'); $this->db->sql_freeresult($result); if (!$group_id) { return false; } return (int) $group_id; }
private function obtain_guest_count_24() { $total_guests_online_24 = 0; // Get number of online guests for the past 24 hours // caching and main sql if none yet if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) { // teh time $interval = time() - 86400; if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') { $sql = 'SELECT COUNT(session_ip) as num_guests_24 FROM ( SELECT DISTINCT session_ip FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($interval - (int) ($interval % 60)) . ')'; } else { $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24 FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($interval - (int) ($interval % 60)); } $result = $this->db->sql_query($sql); $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24'); $this->db->sql_freeresult($result); // cache this stuff for, ohhhh, how about 5 minutes // change 300 to whatever number to reduce or increase the cache time $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300); } return $total_guests_online_24; }
private function obtain_guest_count_24() { $total_guests_online_24 = 0; if ($this->config['load_online_guests']) { // Get number of online guests for the past 24 hours // caching and main sql if none yet if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) { if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') { $sql = 'SELECT COUNT(session_ip) as num_guests_24 FROM ( SELECT DISTINCT session_ip FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($this->interval - (int) ($this->interval % 60)) . ')'; } else { $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24 FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($this->interval - (int) ($this->interval % 60)); } $result = $this->db->sql_query($sql); $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24'); $this->db->sql_freeresult($result); // cache this data for 5 minutes, this improves performance $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300); } } return $total_guests_online_24; }
public function search($start = 1) { if (!$this->auth->acl_get('u_usermap_search')) { trigger_error('NOT_AUTHORISED'); } $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang('USERMAP_TITLE'), 'U_VIEW_FORUM' => $this->helper->route('tas2580_usermap_index', array()))); $lon = substr($this->request->variable('lon', ''), 0, 10); $lat = substr($this->request->variable('lat', ''), 0, 10); $dst = $this->request->variable('dst', $this->config['tas2580_usermap_search_distance']); $alpha = 180 * $dst / (6378137 / 1000 * 3.14159); $min_lon = $this->db->sql_escape($lon - $alpha); $max_lon = $this->db->sql_escape($lon + $alpha); $min_lat = $this->db->sql_escape($lat - $alpha); $max_lat = $this->db->sql_escape($lat + $alpha); $where = " WHERE ( user_usermap_lon >= '{$min_lon}' AND user_usermap_lon <= '{$max_lon}') AND ( user_usermap_lat >= '{$min_lat}' AND user_usermap_lat<= '{$max_lat}')"; $limit = (int) $this->config['topics_per_page']; $sql = 'SELECT COUNT(user_id) AS num_users FROM ' . USERS_TABLE . $where; $result = $this->db->sql_query($sql); $total_users = (int) $this->db->sql_fetchfield('num_users'); $this->db->sql_freeresult($result); $sql = 'SELECT user_id, username, user_colour, user_regdate, user_posts, group_id, user_usermap_lon, user_usermap_lat FROM ' . USERS_TABLE . $where; $result = $this->db->sql_query_limit($sql, $limit, ($start - 1) * $limit); while ($row = $this->db->sql_fetchrow($result)) { $distance = $this->get_distance($lon, $lat, $row['user_usermap_lon'], $row['user_usermap_lat']); $this->template->assign_block_vars('memberrow', array('USER_ID' => $row['user_id'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'JOINED' => $this->user->format_date($row['user_regdate']), 'POSTS' => $row['user_posts'], 'GROUP_ID' => $row['group_id'], 'DISTANCE' => $distance)); } $this->pagination->generate_template_pagination(array('routes' => array('tas2580_usermap_search', 'tas2580_usermap_search_page'), 'params' => array()), 'pagination', 'start', $total_users, $limit, ($start - 1) * $limit); $this->template->assign_vars(array('TOTAL_USERS' => $this->user->lang('TOTAL_USERS', (int) $total_users), 'L_SEARCH_EXPLAIN' => $this->user->lang('SEARCH_EXPLAIN', $dst, $lon, $lat))); return $this->helper->render('usermap_search.html', $this->user->lang('USERMAP_SEARCH')); }
/** * Function returns maximum reputation power of one user * * @param int $posts User posts * @param timestamp $regdate User registration date * @param int $reputation User reputation * @param int $warnings User warnings * @param int $user_group_id User group ID * @return int User power reputation * @access public */ public function get($posts, $regdate, $reputation, $warnings, $user_group_id) { $now = time(); $user_power = array(); // Increasing power for number of posts if ($this->config['rs_total_posts']) { $user_power['FOR_NUMBER_OF_POSTS'] = intval($posts / $this->config['rs_total_posts']); } // Increasing power for the age of the user if ($this->config['rs_membership_days']) { $user_power['FOR_USER_AGE'] = intval(intval(($now - $regdate) / 86400) / $this->config['rs_membership_days']); } // Increasing power for total reputation if ($this->config['rs_power_rep_point']) { $user_power['FOR_REPUTATION'] = intval($reputation / $this->config['rs_power_rep_point']); } // Decreasing power for warnings if ($this->config['rs_power_lose_warn'] > 0) { $user_power['FOR_WARNINGS'] = -$warnings * $this->config['rs_power_lose_warn']; } // Max user power if (empty($user_power)) { $user_max_power = $this->config['rs_max_power']; } else { $user_max_power = array_sum($user_power); $user_max_power = $user_max_power + $this->config['rs_min_power']; } // Check min power - if it is set, inform about it if ($this->config['rs_min_power']) { $user_power['MINIMUM_VOTING_POWER'] = $this->config['rs_min_power']; } // Checking if user reputation power is not lower than minimum power set in ACP if ($user_max_power < $this->config['rs_min_power']) { $user_max_power = max($this->config['rs_min_power'], $user_max_power); } // Checking if user reputation power is not higher than maximum power set in ACP if ($user_max_power > $this->config['rs_max_power']) { $user_power['MAXIMUM_VOTING_POWER'] = $this->config['rs_max_power']; $user_max_power = min($this->config['rs_max_power'], $user_max_power); } // Group reputation power // Calculating group power, if necessary if ($user_group_id) { $sql = 'SELECT group_reputation_power FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_id = {$user_group_id}"; $result = $this->db->sql_query($sql); $group_power = (int) $this->db->sql_fetchfield('group_reputation_power'); $this->db->sql_freeresult($result); if (!empty($group_power)) { unset($user_power); $user_power = array(); $user_max_power = $user_power['GROUP_VOTING_POWER'] = $group_power; } } // Put the structure of the user power into $this->explanation $this->explanation = $user_power; return $user_max_power; }
/** * Display the form * * @access public */ public function displayform() { $this->user->add_lang_ext('rmcgirr83/applicationform', 'application'); // user can't be a guest and can't be a bot if ($this->user->data['is_bot'] || $this->user->data['user_id'] == ANONYMOUS) { throw new http_exception(401, 'LOGIN_APPLICATION_FORM'); } add_form_key('appform'); if ($this->request->is_set_post('submit')) { // Test if form key is valid if (!check_form_key('appform')) { trigger_error($this->user->lang['FORM_INVALID'], E_USER_WARNING); } if (utf8_clean_string($this->request->variable('name', '')) === '' || utf8_clean_string($this->request->variable('why', '')) === '') { trigger_error($this->user->lang['APP_NOT_COMPLETELY_FILLED'], E_USER_WARNING); } $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $this->config['appform_forum_id']; $result = $this->db->sql_query($sql); $forum_name = $this->db->sql_fetchfield('forum_name'); $this->db->sql_freeresult($result); // Setting the variables we need to submit the post to the forum where all the applications come in $subject = sprintf($this->user->lang['APPLICATION_SUBJECT'], $this->user->data['username']); $apply_post = sprintf($this->user->lang['APPLICATION_MESSAGE'], get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']), utf8_normalize_nfc($this->request->variable('name', '', true)), $this->user->data['user_email'], $this->request->variable('postion', '', true), utf8_normalize_nfc($this->request->variable('why', '', true))); // variables to hold the parameters for submit_post $uid = $bitfield = $options = ''; generate_text_for_storage($apply_post, $uid, $bitfield, $options, true, true, true); $data = array('forum_id' => $this->config['appform_forum_id'], 'icon_id' => false, 'poster_id' => $this->user->data['user_id'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $apply_post, 'message_md5' => md5($apply_post), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'poster_ip' => $this->user->ip, 'post_edit_locked' => 0, 'topic_title' => $subject, 'notify_set' => false, 'notify' => false, 'post_time' => time(), 'forum_name' => $forum_name, 'enable_indexing' => true, 'force_approved_state' => true, 'force_visibility' => true); $poll = array(); // Submit the post! submit_post('post', $subject, $this->user->data['username'], POST_NORMAL, $poll, $data); $message = $this->user->lang['APPLICATION_SEND']; $message = $message . '<br /><br />' . sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}") . '">', '</a>'); trigger_error($message); } $this->template->assign_vars(array('APPLICATION_POSITIONS' => $this->display_positions(explode("\n", $this->config['appform_positions'])))); // Send all data to the template file return $this->helper->render('appform_body.html', $this->user->lang('APPLICATION_PAGETITLE')); }
/** * Delete a comment * * @param int $id * @return bool */ public function delete($id) { $sql = 'SELECT post_id FROM ' . $this->blog_comments_table . 'WHERE id = ' . (int) $id; $result = $this->db->sql_query($sql); $post_id = $this->db->sql_fetchfield('post_id'); $this->db->sql_freeresult($result); if (!$post_id) { return false; } $sql = 'DELETE FROM ' . $this->blog_comments_table . ' WHERE id = ' . (int) $id; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->blog_posts_table . ' SET comment_count = comment_count - 1 WHERE id = ' . (int) $post_id; $this->db->sql_query($sql); return true; }
/** * @param $report_ids - an array of report ids to check for * @return bool - true iff there is an existing report for given report_id */ public function feedbackReportsExist(array $report_ids) { // no ids given if (!$report_ids) { return false; } // SQL escape ids $ids = array(); foreach ($report_ids as $id) { $ids[] = $this->db->sql_escape($id); } $sql = 'SELECT COUNT(*) AS num_reports FROM ' . $this->tables['reports'] . ' WHERE report_id IN (' . implode(', ', $ids) . ")"; $result = $this->db->sql_query($sql); return (int) $this->db->sql_fetchfield('num_reports') == count($report_ids); }
/** * Delete * * @param int $id * @return bool */ protected function delete($id) { $sql = 'SELECT category_id FROM ' . $this->blog_post_table . 'WHERE id = ' . (int) $id; $result = $this->db->sql_query($sql); $category_id = $this->db->sql_fetchfield('category_id'); $this->db->sql_freeresult($result); if (!$category_id) { return false; } $sql = 'DELETE FROM ' . $this->blog_posts_table . ' WHERE id = ' . (int) $id; $this->db->sql_query($sql); $sql = 'DELETE FROM ' . $this->blog_comments_table . ' WHERE post_id = ' . (int) $id; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->blog_categories_table . ' SET post_count = post_count - 1 WHERE id = ' . (int) $category_id; $this->db->sql_query($sql); return true; }
/** * Check user reputation * * If it is higher than allowed, decrease it to maximum. * If it is lower than allowed, increase it to minimum. * * @param int $user_id User ID * @access public * @return null */ private function check_max_min($user_id) { $sql = 'SELECT SUM(reputation_points) AS points FROM ' . $this->reputations_table . ' WHERE user_id_to = ' . (int) $user_id; $result = $this->db->sql_query($sql); $points = $this->db->sql_fetchfield('points'); $this->db->sql_freeresult($result); // Maximum user reputation if ($points > $this->config['rs_max_point'] && $this->config['rs_max_point']) { $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_reputation = {$this->config['rs_max_point']}\n\t\t\t\tWHERE user_id = {$user_id}"; $this->db->sql_query($sql); } // Minimum user reputation if ($points < $this->config['rs_min_point'] && $this->config['rs_min_point']) { $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_reputation = {$this->config['rs_min_point']}\n\t\t\t\tWHERE user_id = {$user_id}"; $this->db->sql_query($sql); } }
/** * Display the search page * * @param type $start * @return type */ public function search($start = 1) { if (!$this->auth->acl_get('u_usermap_search')) { trigger_error('NOT_AUTHORISED'); } $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang('USERMAP_TITLE'), 'U_VIEW_FORUM' => $this->helper->route('tas2580_usermap_index', array()))); $data = array('lon' => substr($this->request->variable('lon', ''), 0, 10), 'lat' => substr($this->request->variable('lat', ''), 0, 10), 'dst' => (int) $this->request->variable('dst', $this->config['tas2580_usermap_search_distance'])); $validate_array = array('lon' => array('match', false, self::REGEX_LON), 'lat' => array('match', false, self::REGEX_LAT)); if (!function_exists('validate_data')) { include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } $error = validate_data($data, $validate_array); if (sizeof($error)) { $error = array_map(array($this->user, 'lang'), $error); trigger_error(implode('<br>', $error) . '<br><br><a href="' . $this->helper->route('tas2580_usermap_index', array()) . '">' . $this->user->lang('BACK_TO_USERMAP') . '</a>'); } $alpha = 180 * $data['dst'] / (6378137 / 1000 * 3.14159); $min_lon = (double) ($data['lon'] - $alpha); $max_lon = (double) ($data['lon'] + $alpha); $min_lat = (double) ($data['lat'] - $alpha); $max_lat = (double) ($data['lat'] + $alpha); $where = " WHERE ( user_usermap_lon >= {$min_lon} AND user_usermap_lon <= {$max_lon}) AND ( user_usermap_lat >= {$min_lat} AND user_usermap_lat<= {$max_lat})"; $limit = (int) $this->config['topics_per_page']; $sql = 'SELECT COUNT(user_id) AS num_users FROM ' . USERS_TABLE . $where; $result = $this->db->sql_query($sql); $total_users = (int) $this->db->sql_fetchfield('num_users'); $this->db->sql_freeresult($result); $sql = 'SELECT user_id, username, user_colour, user_regdate, user_posts, group_id, user_usermap_lon, user_usermap_lat FROM ' . USERS_TABLE . $where; $result = $this->db->sql_query_limit($sql, $limit, ($start - 1) * $limit); while ($row = $this->db->sql_fetchrow($result)) { $distance = $this->get_distance($data['lon'], $data['lat'], $row['user_usermap_lon'], $row['user_usermap_lat']); $this->template->assign_block_vars('memberrow', array('USER_ID' => $row['user_id'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'JOINED' => $this->user->format_date($row['user_regdate']), 'POSTS' => $row['user_posts'], 'GROUP_ID' => $row['group_id'], 'DISTANCE' => $distance)); } $this->pagination->generate_template_pagination(array('routes' => array('tas2580_usermap_search', 'tas2580_usermap_search_page'), 'params' => array()), 'pagination', 'start', $total_users, $limit, ($start - 1) * $limit); $this->template->assign_vars(array('TOTAL_USERS' => $this->user->lang('TOTAL_USERS', (int) $total_users), 'L_SEARCH_EXPLAIN' => $this->user->lang('SEARCH_EXPLAIN', $data['dst'], $data['lon'], $data['lat']))); return $this->helper->render('usermap_search.html', $this->user->lang('USERMAP_SEARCH')); }
/** * Rate user * * @return null * @access public */ public function rate_user() { add_form_key('rate'); //$this->user->add_lang_ext('pico/reputation', 'reputation_common'); $submit = $this->request->is_set_post('submit'); $username = $this->request->variable('username', '', true); $points = $this->request->variable('points', ''); $comment = $this->request->variable('comment', '', true); $errors = array(); if ($submit) { if (!check_form_key('rate')) { $errors[] = $this->user->lang('FORM_INVALID'); } $sql = 'SELECT user_id FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'"; $result = $this->db->sql_query($sql); $user_id_to = (int) $this->db->sql_fetchfield('user_id'); $this->db->sql_freeresult($result); if (!$user_id_to) { $errors[] = $this->user->lang('NO_USER'); } if (!is_numeric($points)) { $errors[] = $this->user->lang('POINTS_INVALID'); } } if ($submit && empty($errors)) { $data = array('user_id_from' => $this->user->data['user_id'], 'user_id_to' => $user_id_to, 'reputation_type' => 'user', 'reputation_item_id' => $user_id_to, 'reputation_points' => $points, 'reputation_comment' => $comment); try { $this->reputation_manager->store_reputation($data); trigger_error($this->user->lang('RS_VOTE_SAVED') . adm_back_link($this->u_action)); } catch (\pico\reputation\exception\base $e) { // Catch exceptions and add them to errors array $errors[] = $e->get_message($this->user); } } $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => implode('<br />', $errors), 'U_ACTION' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=searchuser&form=rate&field=username&select_single=true'), 'RS_USERNAME' => $username, 'RS_POINTS' => $points, 'RS_COMMENT' => $comment)); }
/** * {@inheritDoc} */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { $this->entry_count = 0; $this->last_page_offset = $offset; $topic_id_list = $reportee_id_list = array(); $profile_url = $this->get_is_admin() && $this->phpbb_admin_path ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile'); switch ($mode) { case 'admin': $log_type = LOG_ADMIN; $sql_additional = ''; break; case 'mod': $log_type = LOG_MOD; $sql_additional = ''; if ($topic_id) { $sql_additional = 'AND l.topic_id = ' . (int) $topic_id; } else { if (is_array($forum_id)) { $sql_additional = 'AND ' . $this->db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); } else { if ($forum_id) { $sql_additional = 'AND l.forum_id = ' . (int) $forum_id; } } } break; case 'user': $log_type = LOG_USERS; $sql_additional = 'AND l.reportee_id = ' . (int) $user_id; break; case 'users': $log_type = LOG_USERS; $sql_additional = ''; break; case 'critical': $log_type = LOG_CRITICAL; $sql_additional = ''; break; default: $log_type = false; $sql_additional = ''; } /** * Overwrite log type and limitations before we count and get the logs * * NOTE: if log_type is false, no entries will be returned. * * @event core.get_logs_modify_type * @var string mode Mode of the entries we display * @var bool count_logs Do we count all matching entries? * @var int limit Limit the number of entries * @var int offset Offset when fetching the entries * @var mixed forum_id Limit entries to the forum_id, * can also be an array of forum_ids * @var int topic_id Limit entries to the topic_id * @var int user_id Limit entries to the user_id * @var int log_time Limit maximum age of log entries * @var string sort_by SQL order option * @var string keywords Will only return entries that have the * keywords in log_operation or log_data * @var string profile_url URL to the users profile * @var int log_type Limit logs to a certain type. If log_type * is false, no entries will be returned. * @var string sql_additional Additional conditions for the entries, * e.g.: 'AND l.forum_id = 1' * @since 3.1.0-a1 */ $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); extract($this->dispatcher->trigger_event('core.get_logs_modify_type', compact($vars))); if ($log_type === false) { $this->last_page_offset = 0; return array(); } $sql_keywords = ''; if (!empty($keywords)) { // Get the SQL condition for our keywords $sql_keywords = $this->generate_sql_keyword($keywords); } $get_logs_sql_ary = array('SELECT' => 'l.*, u.username, u.username_clean, u.user_colour', 'FROM' => array($this->log_table => 'l', USERS_TABLE => 'u'), 'WHERE' => 'l.log_type = ' . (int) $log_type . "\n\t\t\t\t\tAND l.user_id = u.user_id\n\t\t\t\t\t{$sql_keywords}\n\t\t\t\t\t{$sql_additional}", 'ORDER_BY' => $sort_by); if ($log_time) { $get_logs_sql_ary['WHERE'] = 'l.log_time >= ' . (int) $log_time . ' AND ' . $get_logs_sql_ary['WHERE']; } /** * Modify the query to obtain the logs data * * @event core.get_logs_main_query_before * @var array get_logs_sql_ary The array in the format of the query builder with the query * to get the log count and the log list * @var string mode Mode of the entries we display * @var bool count_logs Do we count all matching entries? * @var int limit Limit the number of entries * @var int offset Offset when fetching the entries * @var mixed forum_id Limit entries to the forum_id, * can also be an array of forum_ids * @var int topic_id Limit entries to the topic_id * @var int user_id Limit entries to the user_id * @var int log_time Limit maximum age of log entries * @var string sort_by SQL order option * @var string keywords Will only return entries that have the * keywords in log_operation or log_data * @var string profile_url URL to the users profile * @var int log_type Limit logs to a certain type. If log_type * is false, no entries will be returned. * @var string sql_additional Additional conditions for the entries, * e.g.: 'AND l.forum_id = 1' * @since 3.1.5-RC1 */ $vars = array('get_logs_sql_ary', 'mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); extract($this->dispatcher->trigger_event('core.get_logs_main_query_before', compact($vars))); if ($count_logs) { $count_logs_sql_ary = $get_logs_sql_ary; $count_logs_sql_ary['SELECT'] = 'COUNT(l.log_id) AS total_entries'; unset($count_logs_sql_ary['ORDER_BY']); $sql = $this->db->sql_build_query('SELECT', $count_logs_sql_ary); $result = $this->db->sql_query($sql); $this->entry_count = (int) $this->db->sql_fetchfield('total_entries'); $this->db->sql_freeresult($result); if ($this->entry_count == 0) { // Save the queries, because there are no logs to display $this->last_page_offset = 0; return array(); } // Return the user to the last page that is valid while ($this->last_page_offset >= $this->entry_count) { $this->last_page_offset = max(0, $this->last_page_offset - $limit); } } $sql = $this->db->sql_build_query('SELECT', $get_logs_sql_ary); $result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset); $i = 0; $log = array(); while ($row = $this->db->sql_fetchrow($result)) { $row['forum_id'] = (int) $row['forum_id']; if ($row['topic_id']) { $topic_id_list[] = (int) $row['topic_id']; } if ($row['reportee_id']) { $reportee_id_list[] = (int) $row['reportee_id']; } $log_entry_data = array('id' => (int) $row['log_id'], 'reportee_id' => (int) $row['reportee_id'], 'reportee_username' => '', 'reportee_username_full' => '', 'user_id' => (int) $row['user_id'], 'username' => $row['username'], 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), 'ip' => $row['log_ip'], 'time' => (int) $row['log_time'], 'forum_id' => (int) $row['forum_id'], 'topic_id' => (int) $row['topic_id'], 'viewforum' => $row['forum_id'] && $this->auth->acl_get('f_read', $row['forum_id']) ? append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']) : false, 'action' => isset($this->user->lang[$row['log_operation']]) ? $row['log_operation'] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}'); /** * Modify the entry's data before it is returned * * @event core.get_logs_modify_entry_data * @var array row Entry data from the database * @var array log_entry_data Entry's data which is returned * @since 3.1.0-a1 */ $vars = array('row', 'log_entry_data'); extract($this->dispatcher->trigger_event('core.get_logs_modify_entry_data', compact($vars))); $log[$i] = $log_entry_data; if (!empty($row['log_data'])) { $log_data_ary = unserialize($row['log_data']); $log_data_ary = $log_data_ary !== false ? $log_data_ary : array(); if (isset($this->user->lang[$row['log_operation']])) { // Check if there are more occurrences of % than // arguments, if there are we fill out the arguments // array. It doesn't matter if we add more arguments than // placeholders. $num_args = 0; if (!is_array($this->user->lang[$row['log_operation']])) { $num_args = substr_count($this->user->lang[$row['log_operation']], '%'); } else { foreach ($this->user->lang[$row['log_operation']] as $case => $plural_string) { $num_args = max($num_args, substr_count($plural_string, '%')); } } if ($num_args - sizeof($log_data_ary) > 0) { $log_data_ary = array_merge($log_data_ary, array_fill(0, $num_args - sizeof($log_data_ary), '')); } $lang_arguments = array_merge(array($log[$i]['action']), $log_data_ary); $log[$i]['action'] = call_user_func_array(array($this->user, 'lang'), $lang_arguments); // If within the admin panel we do not censor text out if ($this->get_is_admin()) { $log[$i]['action'] = bbcode_nl2br($log[$i]['action']); } else { $log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action'])); } } else { if (!empty($log_data_ary)) { $log[$i]['action'] .= '<br />' . implode('', $log_data_ary); } } /* Apply make_clickable... has to be seen if it is for good. :/ // Seems to be not for the moment, reconsider later... $log[$i]['action'] = make_clickable($log[$i]['action']); */ } else { $log[$i]['action'] = $this->user->lang($log[$i]['action']); } $i++; } $this->db->sql_freeresult($result); /** * Get some additional data after we got all log entries * * @event core.get_logs_get_additional_data * @var array log Array with all our log entries * @var array topic_id_list Array of topic ids, for which we * get the permission data * @var array reportee_id_list Array of additional user IDs we * get the username strings for * @since 3.1.0-a1 */ $vars = array('log', 'topic_id_list', 'reportee_id_list'); extract($this->dispatcher->trigger_event('core.get_logs_get_additional_data', compact($vars))); if (sizeof($topic_id_list)) { $topic_auth = $this->get_topic_auth($topic_id_list); foreach ($log as $key => $row) { $log[$key]['viewtopic'] = isset($topic_auth['f_read'][$row['topic_id']]) ? append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&t=' . $row['topic_id']) : false; $log[$key]['viewlogs'] = isset($topic_auth['m_'][$row['topic_id']]) ? append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $this->user->session_id) : false; } } if (sizeof($reportee_id_list)) { $reportee_data_list = $this->get_reportee_data($reportee_id_list); foreach ($log as $key => $row) { if (!isset($reportee_data_list[$row['reportee_id']])) { continue; } $log[$key]['reportee_username'] = $reportee_data_list[$row['reportee_id']]['username']; $log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_data_list[$row['reportee_id']]['username'], $reportee_data_list[$row['reportee_id']]['user_colour'], false, $profile_url); } } /** * Allow modifying or execute extra final filter on log entries * * @event core.get_logs_after * @var array log Array with all our log entries * @var array topic_id_list Array of topic ids, for which we * get the permission data * @var array reportee_id_list Array of additional user IDs we * get the username strings for * @var string mode Mode of the entries we display * @var bool count_logs Do we count all matching entries? * @var int limit Limit the number of entries * @var int offset Offset when fetching the entries * @var mixed forum_id Limit entries to the forum_id, * can also be an array of forum_ids * @var int topic_id Limit entries to the topic_id * @var int user_id Limit entries to the user_id * @var int log_time Limit maximum age of log entries * @var string sort_by SQL order option * @var string keywords Will only return entries that have the * keywords in log_operation or log_data * @var string profile_url URL to the users profile * @var int log_type The type of logs it was filtered * @since 3.1.3-RC1 */ $vars = array('log', 'topic_id_list', 'reportee_id_list', 'mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type'); extract($this->dispatcher->trigger_event('core.get_logs_after', compact($vars))); return $log; }
/** * Display the form * * @access public */ public function displayform() { $nru_group_id = $this->applicationform->getnruid(); if ($this->user->data['is_bot'] || $this->user->data['user_id'] == ANONYMOUS || !$this->config['appform_nru'] && $nru_group_id === (int) $this->user->data['group_id']) { throw new http_exception(401, 'NOT_AUTHORISED'); } $this->user->add_lang('posting'); $this->user->add_lang_ext('rmcgirr83/applicationform', 'application'); $attachment_allowed = $this->config['allow_attachments'] && $this->config['appform_attach'] ? true : false; $attachment_req = $this->config['appform_attach_req']; add_form_key('applicationform'); $data = array('name' => $this->request->variable('name', '', true), 'why' => $this->request->variable('why', '', true), 'position' => $this->request->variable('position', '', true)); if ($this->request->is_set_post('submit')) { $error = array(); // Test if form key is valid if (!check_form_key('applicationform')) { $error[] = $this->user->lang['FORM_INVALID']; } $message_parser = new \parse_message(); $message_parser->parse_attachments('fileupload', 'post', $this->config['appform_forum_id'], true, false, false); $error = array(); // Test if form key is valid if (!check_form_key('applicationform')) { $error[] = $this->user->lang['FORM_INVALID']; } if ($data['name'] === '' || $data['why'] === '') { $error[] = $this->user->lang['APP_NOT_COMPLETELY_FILLED']; } if (empty($message_parser->attachment_data) && $attachment_req && $attachment_allowed) { $error[] = $this->user->lang['APPLICATION_REQUIRES_ATTACHMENT']; } // Setting the variables we need to submit the post to the forum where all the applications come in $message = censor_text(trim('[quote] ' . $data['why'] . '[/quote]')); $subject = sprintf($this->user->lang['APPLICATION_SUBJECT'], $this->user->data['username']); $url = generate_board_url() . '/memberlist.' . $this->php_ext . '?mode=viewprofile&u=' . $this->user->data['user_id']; $color = $this->user->data['user_colour']; $user_name = $this->user->data['is_registered'] ? '[url=' . $url . '][color=#' . $color . ']' . $this->user->data['username'] . '[/color][/url]' : $data['username']; $apply_post = sprintf($this->user->lang['APPLICATION_MESSAGE'], $user_name, $this->request->variable('name', '', true), $data['position'], $message); $message_parser->message = $apply_post; $message_md5 = md5($message_parser->message); if (sizeof($message_parser->warn_msg)) { $error[] = implode('<br />', $message_parser->warn_msg); } $message_parser->parse(true, true, true, true, false, true, true); // no errors, let's proceed if (!sizeof($error)) { $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $this->config['appform_forum_id']; $result = $this->db->sql_query($sql); $forum_name = $this->db->sql_fetchfield('forum_name'); $this->db->sql_freeresult($result); $data = array('forum_id' => $this->config['appform_forum_id'], 'icon_id' => false, 'poster_id' => $this->user->data['user_id'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $message_parser->message, 'message_md5' => $message_md5, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'poster_ip' => $this->user->ip, 'post_edit_locked' => 0, 'topic_title' => $subject, 'notify_set' => false, 'notify' => true, 'post_time' => time(), 'forum_name' => $forum_name, 'enable_indexing' => true, 'force_approved_state' => true, 'force_visibility' => true); $poll = array(); if ($this->topicdescription !== null) { $data['topic_desc'] = ''; } // Submit the post! submit_post('post', $subject, $this->user->data['username'], POST_NORMAL, $poll, $data); $message = $this->user->lang['APPLICATION_SEND']; $message = $message . '<br /><br />' . sprintf($this->user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}") . '">', '</a>'); trigger_error($message); } } $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' ? '' : ' enctype="multipart/form-data"'; $this->template->assign_vars(array('REALNAME' => isset($data['name']) ? $data['name'] : '', 'APPLICATION_POSITIONS' => $this->display_positions(explode("\n", $this->config['appform_positions']), $data['position']), 'WHY' => isset($data['why']) ? $data['why'] : '', 'S_FORM_ENCTYPE' => $form_enctype, 'S_ERROR' => isset($error) && sizeof($error) ? implode('<br />', $error) : '', 'S_ATTACH_BOX' => $attachment_allowed && $form_enctype ? true : false, 'S_ATTACH_REQ' => $attachment_req)); // Send all data to the template file return $this->helper->render('appform_body.html', $this->user->lang('APPLICATION_PAGETITLE')); }
/** * Main reputation details controller * * @param int $uid User ID taken from the URL * @param string $sort_key Sort key: id|username|time|point|action (default: id) * @param string $sort_dir Sort direction: dsc|asc (descending|ascending) (default: dsc) * @param int $page Page number taken from the URL * @return Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public */ public function details($uid, $sort_key, $sort_dir, $page) { $this->user->add_lang_ext('pico/reputation', array('reputation_system', 'reputation_rating')); // Check user permissions - if user can not view reputation details, throw the error if (!$this->auth->acl_get('u_rs_view')) { $meta_info = append_sid("{$this->root_path}index.{$this->php_ext}", ""); $message = $user->lang['RS_VIEW_DISALLOWED'] . '<br /><br />' . $this->user->lang('RETURN_INDEX', '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}", "") . '">', '</a>'); meta_refresh(3, $meta_info); trigger_error($message); } // User data $sql = 'SELECT * FROM ' . USERS_TABLE . "\n\t\t\tWHERE user_type <> 2\n\t\t\t\tAND user_id = {$uid}"; $result = $this->db->sql_query($sql); $user_row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Check if an user exists - if not, throw the error and return to the index page if (empty($user_row)) { $meta_info = append_sid("{$this->root_path}index.{$this->php_ext}", ""); $message = $this->user->lang['RS_NO_USER_ID'] . '<br /><br />' . $this->user->lang('RETURN_INDEX', '<a href="' . append_sid("{$this->root_path}index.{$this->php_ext}", "") . '">', '</a>'); meta_refresh(3, $meta_info); trigger_error($message); } // Count reputation rows for the current user $sql = 'SELECT COUNT(reputation_id) AS total_reps FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}"; $result = $this->db->sql_query($sql); $total_reps = (int) $this->db->sql_fetchfield('total_reps'); $this->db->sql_freeresult($result); // Sort keys $sort_key_sql = array('username' => 'u.username_clean', 'time' => 'r.reputation_time', 'point' => 'r.reputation_points', 'action' => 'rt.reputation_type_name', 'id' => 'r.reputation_id'); // Sql order depends on sort key $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'dsc' ? 'DESC' : 'ASC'); // Start value - it is based on page $start = ($page - 1) * $this->config['rs_per_page']; $post_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql_array = array('SELECT' => 'r.*, rt.reputation_type_name, u.group_id, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.post_id, p.forum_id, p.post_subject', 'FROM' => array($this->reputations_table => 'r', $this->reputation_types_table => 'rt'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'r.user_id_from = u.user_id '), array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 'p.post_id = r.reputation_item_id AND r.reputation_type_id = ' . $post_type_id)), 'WHERE' => 'r.user_id_to = ' . $uid . ' AND r.reputation_type_id = rt.reputation_type_id', 'ORDER_BY' => $order_by); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $this->config['rs_per_page'], $start); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('reputation', array('ID' => $row['reputation_id'], 'USERNAME' => get_username_string('full', $row['user_id_from'], $row['username'], $row['user_colour']), 'ACTION' => $this->user->lang('RS_' . strtoupper($row['reputation_type_name']) . '_RATING'), 'AVATAR' => phpbb_get_user_avatar($row), 'TIME' => $this->user->format_date($row['reputation_time']), 'COMMENT' => $row['reputation_comment'], 'POINTS' => $row['reputation_points'], 'POINTS_CLASS' => $this->reputation_helper->reputation_class($row['reputation_points']), 'POINTS_TITLE' => $this->user->lang('RS_POINTS_TITLE', $row['reputation_points']), 'U_DELETE' => $this->helper->route('reputation_delete_controller', array('rid' => $row['reputation_id'])), 'S_COMMENT' => !empty($row['reputation_comment']), 'S_DELETE' => $this->auth->acl_get('m_rs_moderate') || $row['user_id_from'] == $this->user->data['user_id'] && $this->auth->acl_get('u_rs_delete') ? true : false)); // Generate post url $this->reputation_manager->generate_post_link($row); } $this->db->sql_freeresult($result); // User reputation rank if (!function_exists('phpbb_get_user_rank')) { include $this->root_path . 'includes/functions_display.' . $this->php_ext; } $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); // Reputation statistics $positive_count = $negative_count = 0; $positive_sum = $negative_sum = 0; $positive_week = $negative_week = 0; $positive_month = $negative_month = 0; $positive_6months = $negative_6months = 0; $post_count = $user_count = 0; $last_week = time() - 604800; $last_month = time() - 2678400; $last_6months = time() - 16070400; $user_type_id = (int) $this->reputation_manager->get_reputation_type_id('user'); $sql = 'SELECT reputation_time, reputation_type_id, reputation_points FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}"; $result = $this->db->sql_query($sql); while ($reputation_vote = $this->db->sql_fetchrow($result)) { if ($reputation_vote['reputation_points'] > 0) { $positive_count++; $positive_sum += $reputation_vote['reputation_points']; if ($reputation_vote['reputation_time'] >= $last_week) { $positive_week++; } if ($reputation_vote['reputation_time'] >= $last_month) { $positive_month++; } if ($reputation_vote['reputation_time'] >= $last_6months) { $positive_6months++; } } else { if ($reputation_vote['reputation_points'] < 0) { $negative_count++; $negative_sum += $reputation_vote['reputation_points']; if ($reputation_vote['reputation_time'] >= $last_week) { $negative_week++; } if ($reputation_vote['reputation_time'] >= $last_month) { $negative_month++; } if ($reputation_vote['reputation_time'] >= $last_6months) { $negative_6months++; } } } if ($reputation_vote['reputation_type_id'] == $post_type_id) { $post_count += $reputation_vote['reputation_points']; } else { if ($reputation_vote['reputation_type_id'] == $user_type_id) { $user_count += $reputation_vote['reputation_points']; } } } $this->db->sql_freeresult($result); // User reputation power if ($this->config['rs_enable_power']) { $used_power = $this->reputation_power->used($user_row['user_id']); $user_max_voting_power = $this->reputation_power->get($user_row['user_posts'], $user_row['user_regdate'], $user_row['user_reputation'], $user_row['user_warnings'], $user_row['group_id']); $user_power_explain = $this->reputation_power->explain(); $voting_power_left = ''; if ($this->config['rs_power_renewal']) { $voting_power_left = $user_max_voting_power - $used_power; if ($voting_power_left < 0) { $voting_power_left = 0; } } $this->template->assign_vars(array('S_RS_POWER_EXPLAIN' => $this->config['rs_power_explain'] ? true : false, 'S_RS_GROUP_POWER' => isset($user_power_explain['GROUP_VOTING_POWER']) ? true : false, 'RS_POWER' => $user_max_voting_power, 'RS_POWER_LEFT' => $this->config['rs_power_renewal'] ? $this->user->lang('RS_VOTE_POWER_LEFT', $voting_power_left, $user_max_voting_power) : '', 'RS_CFG_TOTAL_POSTS' => $this->config['rs_total_posts'] ? true : false, 'RS_CFG_MEMBERSHIP_DAYS' => $this->config['rs_membership_days'] ? true : false, 'RS_CFG_REP_POINT' => $this->config['rs_power_rep_point'] ? true : false, 'RS_CFG_LOOSE_WARN' => $this->config['rs_power_lose_warn'] ? true : false)); $this->template->assign_vars($user_power_explain); } // Generate pagination $this->pagination->generate_template_pagination(array('routes' => 'reputation_details_controller', 'params' => array('uid' => $uid, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir)), 'pagination', 'page', $total_reps, $this->config['rs_per_page'], $start); $this->template->assign_vars(array('USER_ID' => $user_row['user_id'], 'USERNAME' => get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour'], true), 'USERNAME_FULL' => get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']), 'REPUTATION' => $user_row['user_reputation'], 'AVATAR_IMG' => phpbb_get_user_avatar($user_row), 'RANK_IMG' => $user_rank_data['img'], 'RANK_IMG_SRC' => $user_rank_data['img_src'], 'RANK_TITLE' => $user_rank_data['title'], 'REPUTATION_CLASS' => $this->reputation_helper->reputation_class($user_row['user_reputation']), 'PAGE_NUMBER' => $this->pagination->on_page($total_reps, $this->config['rs_per_page'], $start), 'TOTAL_REPS' => $this->user->lang('LIST_REPUTATIONS', $total_reps), 'U_SORT_USERNAME' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'username', 'sort_dir' => $sort_key == 'username' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_TIME' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'time', 'sort_dir' => $sort_key == 'time' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_POINT' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'point', 'sort_dir' => $sort_key == 'point' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_ACTION' => $this->helper->route('reputation_details_controller', array('uid' => $uid, 'sort_key' => 'action', 'sort_dir' => $sort_key == 'action' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_CLEAR' => $this->helper->route('reputation_clear_user_controller', array('uid' => $uid)), 'POST_COUNT' => $post_count, 'USER_COUNT' => $user_count, 'POSITIVE_COUNT' => $positive_count, 'POSITIVE_SUM' => $positive_sum, 'POSITIVE_WEEK' => $positive_week, 'POSITIVE_MONTH' => $positive_month, 'POSITIVE_6MONTHS' => $positive_6months, 'NEGATIVE_COUNT' => $negative_count, 'NEGATIVE_SUM' => $negative_sum, 'NEGATIVE_WEEK' => $negative_week, 'NEGATIVE_MONTH' => $negative_month, 'NEGATIVE_6MONTHS' => $negative_6months, 'S_RS_POST_RATING' => $this->config['rs_post_rating'] ? true : false, 'S_RS_USER_RATING' => $this->config['rs_user_rating'] ? true : false, 'S_RS_AVATAR' => $this->config['rs_display_avatar'] ? true : false, 'S_RS_COMMENT' => $this->config['rs_enable_comment'] ? true : false, 'S_RS_NEGATIVE' => $this->config['rs_negative_point'] ? true : false, 'S_RS_POWER_ENABLE' => $this->config['rs_enable_power'] ? true : false, 'S_CLEAR' => $this->auth->acl_gets('m_rs_moderate') ? true : false)); return $this->helper->render('details.html', $this->user->lang('RS_DETAILS')); }