/** * Display zodiac on viewing user profile * * @param object $event The event object * @return null * @access public */ public function memberlist_view_profile($event) { $user_id = $event['member']['user_id']; $reg_date = $event['member']['user_regdate']; $this->user->add_lang_ext('rmcgirr83/searchusertopics', 'common'); // get all topics started by the user and make sure they are visible $sql = 'SELECT t.*, p.post_visibility FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . POSTS_TABLE . ' p ON t.topic_first_post_id = p.post_id WHERE t.topic_poster = ' . $user_id . ' ORDER BY t.topic_time ASC'; $result = $this->db->sql_query($sql); $topics_num = 0; while ($row = $this->db->sql_fetchrow($result)) { if (!$this->auth->acl_get('f_read', $row['forum_id'])) { continue; } if ($row['post_visibility'] != ITEM_APPROVED && !$this->auth->acl_get('m_approve', $row['forum_id'])) { continue; } ++$topics_num; } $this->db->sql_freeresult($result); if ($topics_num) { // Do the relevant calculations $users_days = max(1, round((time() - $reg_date) / 86400)); $topics_per_day = $topics_num / $users_days; $topics_percent = $this->config['num_topics'] ? min(100, $topics_num / $this->config['num_topics'] * 100) : 0; $this->template->assign_vars(array('TOPICS' => $topics_num, 'L_TOTAL_TOPICS' => $this->user->lang('TOTAL_TOPICS', $topics_num), 'TOPICS_PER_DAY' => $this->user->lang('TOPICS_PER_DAY', $topics_per_day), 'TOPICS_PERCENT' => $this->user->lang('TOPICS_PERCENT', $topics_percent), 'U_SEARCH_TOPICS' => $this->auth->acl_get('u_search') ? append_sid("{$this->root_path}search.{$this->php_ext}", "author_id={$user_id}&sr=topics&sf=firstpost") : '')); } }
/** * Display zodiac on viewing user profile * * @param object $event The event object * @return null * @access public */ public function memberlist_view_profile($event) { $user_id = $event['member']['user_id']; $this->user->add_lang_ext('rmcgirr83/topicsbyuser', 'common'); // get all topics started by the user and make sure they are visible $sql = 'SELECT t.*, p.post_visibility FROM ' . TOPICS_TABLE . ' t LEFT JOIN ' . POSTS_TABLE . ' p ON t.topic_first_post_id = p.post_id WHERE t.topic_poster = ' . $user_id . ' ORDER BY t.topic_time ASC'; $result = $this->db->sql_query($sql); $count = 0; $topic_options = '<option value="">' . $this->user->lang['CHOOSE_A_TOPIC'] . '</option>'; while ($row = $this->db->sql_fetchrow($result)) { if (!$this->auth->acl_get('f_read', $row['forum_id'])) { continue; } if ($row['post_visibility'] != ITEM_APPROVED && !$this->auth->acl_get('m_approve', $row['forum_id'])) { continue; } ++$count; $topic_color = $row['post_visibility'] != ITEM_APPROVED ? 'class="error"' : ''; $topic_options .= '<option value="' . append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']) . '" ' . $topic_color . '> ' . truncate_string($row['topic_title'], 30, 255, false, $this->user->lang['ELLIPSIS']) . '</option>'; } $this->db->sql_freeresult($result); if (!empty($count)) { $this->template->assign_vars(array('HAS_TOPICS' => true, 'S_TOPIC_OPTIONS' => $topic_options)); } }
/** * 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; }
/** * Clear user reputation * * @param int $uid User ID * @return null * @access public */ public function clear_user($uid) { $this->user->add_lang_ext('pico/reputation', 'reputation_system'); $is_ajax = $this->request->is_ajax(); $submit = false; $sql_array = array('SELECT' => 'r.*, ut.username AS username_to', 'FROM' => array($this->reputations_table => 'r'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'ut'), 'ON' => 'r.user_id_to = ut.user_id ')), 'WHERE' => 'r.user_id_to = ' . $uid); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); //We couldn't find this reputation. May be it was deleted meanwhile? if (empty($row)) { $message = $this->user->lang('RS_NO_REPUTATION'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $redirect = $this->helper->route('reputation_details_controller', array('uid' => $uid)); if ($this->request->is_set_post('cancel')) { redirect($redirect); } $post_ids = array(); $post_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql = 'SELECT reputation_item_id FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}\n\t\t\t\tAND reputation_type_id = {$post_type_id}\n\t\t\tGROUP BY reputation_item_id"; $result = $this->db->sql_query($sql); while ($post_row = $this->db->sql_fetchrow($result)) { $post_ids[] = $post_row['reputation_item_id']; } $this->db->sql_freeresult($result); $redirect_text = 'RETURN_PAGE'; if ($this->auth->acl_gets('m_rs_moderate')) { if ($is_ajax) { $submit = true; } else { $s_hidden_fields = build_hidden_fields(array('u' => $uid)); if (confirm_box(true)) { $submit = true; } else { confirm_box(false, $this->user->lang('RS_CLEAR_POST_CONFIRM'), $s_hidden_fields); } } } else { $message = $this->user->lang('RS_USER_CANNOT_DELETE'); $json_data = array('error_msg' => $message); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($submit) { try { $this->reputation_manager->clear_user_reputation($uid, $row, $post_ids); } catch (\pico\reputation\exception\base $e) { // Catch exception trigger_error($e->get_message($this->user)); } $message = $this->user->lang('RS_CLEARED_USER'); $json_data = array('clear_user' => true, 'post_ids' => $post_ids, 'poster_id' => $uid, 'user_reputation' => 0, 'post_reputation' => 0, 'reputation_class' => 'neutral'); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } }
/** * Display reputation toplist * * @return null * @access public */ public function reputation_toplist() { if ($this->config['rs_enable'] && $this->config['rs_enable_toplist'] && $this->config['rs_toplist_num']) { $this->user->add_lang_ext('pico/reputation', 'reputation_toplist'); $sql = 'SELECT user_id, username, user_colour, user_reputation FROM ' . USERS_TABLE . ' WHERE user_reputation > 0 ORDER BY user_reputation DESC'; $result = $this->db->sql_query_limit($sql, $this->config['rs_toplist_num']); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('toplist', array('USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'USER_REPUTATION' => $row['user_reputation'], 'U_VIEW_USER_REPUTATION' => $this->helper->route('reputation_details_controller', array('uid' => $row['user_id'])), 'S_DIRECTION' => $this->config['rs_toplist_direction'] ? true : false)); } $this->db->sql_freeresult($result); $this->template->assign_vars(array('S_RS_TOPLIST' => true, 'S_VIEW_REPUTATION' => $this->auth->acl_get('u_rs_view') ? true : false)); } }
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 display_tpotm($event) { $now = time(); $date_today = gmdate("Y-m-d", $now); list($year_cur, $month_cur, $day1) = split('-', $date_today); // Start time for current month $month_start_cur = gmmktime(0, 0, 0, $month_cur, 1, $year_cur); $month_start = $month_start_cur; $month_end = $now; // group_id 5 = administrators // group_id 4 = global moderators // this groups belong to a Vanilla 3.1.x board $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_type, u.group_id, COUNT(p.post_id) AS total_posts FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p WHERE u.user_id > ' . ANONYMOUS . ' AND u.user_id = p.poster_id AND p.post_time BETWEEN ' . $month_start . ' AND ' . $month_end . ' AND (u.user_type <> ' . USER_FOUNDER . ') AND (u.group_id <> 5) AND (u.group_id <> 4) GROUP BY u.user_id ORDER BY total_posts DESC'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // let's go then.. // posts made into the selected elapsed time $topm_tp = $row['total_posts']; $topm_un = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); // there is not a Top Poster, usually happens with fresh installations, where only the FOUNDER made the first post/topic. Or no normal users already did it. //Here TOPM_UN reflects this state. $this->template->assign_vars(array('TOPM_UN' => $topm_tp < 1 ? $topm_un = $this->user->lang['TOP_USERNAME_NONE'] : $topm_un, 'L_TPOTM' => $this->user->lang['TOP_CAT'], 'L_TOPM_UNA_L' => $this->user->lang['TOP_USERNAME'], 'L_TOPM_UPO_L' => sprintf($this->user->lang['TOP_USER_MONTH_POSTS'], $topm_tp), 'L_TOPM_POSTS_L' => $topm_tp > 1 || $topm_tp == 0 ? $this->user->lang['TOP_POSTS'] : $this->user->lang['TOP_POST'])); }
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')); }
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; }
/** * 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')); }
/** * User 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) * @return Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public */ public function userdetails($uid, $sort_key, $sort_dir) { $this->user->add_lang_ext('pico/reputation', array('reputation_system', 'reputation_rating')); $is_ajax = $this->request->is_ajax(); $referer = $this->symfony_request->get('_referer'); if (empty($this->config['rs_enable'])) { if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('error_msg' => $this->user->lang('RS_DISABLED')); $json_response->send($json_data); } redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); } $sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' WHERE user_type <> 2 AND user_id =' . (int) $uid; $result = $this->db->sql_query($sql); $user_row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (empty($user_row)) { $message = $this->user->lang('RS_NO_USER_ID'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if (!$this->auth->acl_get('u_rs_view')) { $message = $this->user->lang('RS_VIEW_DISALLOWED'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $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'); $reputation_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql_array = array('SELECT' => 'r.*, rt.reputation_type_name, 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' => 'u.user_id = r.user_id_from'), array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 'p.post_id = r.reputation_item_id AND r.reputation_type_id = ' . $reputation_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($sql); 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); $this->template->assign_vars(array('USER_ID' => $uid, 'U_USER_DETAILS' => $this->helper->route('reputation_details_controller', array('uid' => $uid)), 'U_SORT_USERNAME' => $this->helper->route('reputation_user_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_user_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_user_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_user_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)), 'U_REPUTATION_REFERER' => $referer, 'L_RS_USER_REPUTATION' => $this->user->lang('RS_USER_REPUTATION', get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour'])), 'S_RS_AVATAR' => $this->config['rs_display_avatar'] ? true : false, 'S_RS_COMMENT' => $this->config['rs_enable_comment'] ? true : false, 'S_RS_POINTS_IMG' => $this->config['rs_point_type'] ? true : false, 'S_CLEAR' => $this->auth->acl_gets('m_rs_moderate') ? true : false, 'S_IS_AJAX' => $is_ajax ? true : false)); return $this->helper->render('userdetails.html'); }
/** * Get the data for all reportee from the database * * @param array $reportee_ids Array with the user ids of the reportees * * @return array Returns an array with the reportee data */ protected function get_reportee_data(array $reportee_ids) { $reportee_ids = array_unique($reportee_ids); $reportee_data_list = array(); $sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', $reportee_ids); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $reportee_data_list[$row['user_id']] = $row; } $this->db->sql_freeresult($result); return $reportee_data_list; }
/** * 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; }
/** * Get an array of forums * return all forums where the extension is active * * @return forum id array * @access private */ private function get_sfpo_forums() { $forum_ids = array(); $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE sfpo_guest_enable = ' . true; $result = $this->db->sql_query($sql); $forums = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); foreach ($forums as $forum) { foreach ($forum as $id) { $forum_ids[] = $id; } } return $forum_ids; }
public function display_tpotm($event) { $now = time(); $date_today = gmdate("Y-m-d", $now); list($year_cur, $month_cur, $day1) = split('-', $date_today); /* Start time for current month */ $month_start_cur = gmmktime(0, 0, 0, $month_cur, 1, $year_cur); $month_start = $month_start_cur; $month_end = $now; /* * group_id 5 = administrators * group_id 4 = global moderators * per default into a Vanilla 3.1.x board */ $group_ids = array(5, 4); /* * config time for cache, still to be fully implemented thus hardcoded * 900 = 15 minutes */ $config_time_cache = 900; /* Check cached data */ if (($row = $this->cache->get('_tpotm')) === false) { $sql = 'SELECT u.username, u.user_id, u.user_colour, u.user_type, u.group_id, p.poster_id, p.post_time, COUNT(p.post_id) AS total_posts FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . ' p WHERE u.user_id > ' . ANONYMOUS . ' AND u.user_id = p.poster_id AND (u.user_type <> ' . USER_FOUNDER . ') AND ' . $this->db->sql_in_set('u.group_id', $group_ids, true) . ' AND p.post_time BETWEEN ' . $month_start . ' AND ' . $month_end . ' GROUP BY u.user_id ORDER BY total_posts DESC'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); /* caching this data improves performance */ $this->cache->put('_tpotm', $row, (int) $config_time_cache); } /* Let's show the Top Poster then */ $tpotm_tot_posts = (int) $row['total_posts']; $tpotm_un_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); /* Fresh installs or new Month starts give zero posts */ $tpotm_un_nobody = $this->user->lang['TPOTM_NOBODY']; $tpotm_post = $this->user->lang('TPOTM_POST', (int) $tpotm_tot_posts); $tpotm_name = $tpotm_tot_posts < 1 ? $tpotm_un_nobody : $tpotm_un_string; /* you know.. template stuffs */ $this->template->assign_vars(array('TPOTM_NAME' => $tpotm_name, 'L_TPOTM_CAT' => $this->user->lang['TPOTM_CAT'], 'L_TPOTM_NOW' => $this->user->lang['TPOTM_NOW'], 'L_TPOTM_POST' => $tpotm_post)); }
/** * 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; }
/** * Get top_flags * displayed on the index page */ public function top_flags() { // grab all the flags $sql_array = array('SELECT' => 'user_flag, COUNT(user_flag) AS fnum', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => $this->db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . ' AND user_flag > 0', 'GROUP_BY' => 'user_flag', 'ORDER_BY' => 'fnum DESC'); // we limit the number of flags to display to the number set in the ACP settings $result = $this->db->sql_query_limit($this->db->sql_build_query('SELECT', $sql_array), $this->config['flags_num_display']); $count = 0; $flags = $this->cache->get('_user_flags'); while ($row = $this->db->sql_fetchrow($result)) { ++$count; $this->template->assign_block_vars('flag', array('FLAG' => $this->get_user_flag($row['user_flag']), 'FLAG_USERS' => $this->user->lang('FLAG_USERS', (int) $row['fnum']), 'U_FLAG' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $flags[$row['user_flag']]['flag_id'])))); } $this->db->sql_freeresult($result); if ($count) { $this->template->assign_vars(array('U_FLAGS' => $this->helper->route('rmcgirr83_nationalflags_display'), 'S_FLAGS' => true)); } }
/** * Function returns a reputation power used by an user * * @param $user_id User ID * @return int Power used * @access public */ public function used($user_id) { $time = time(); $power_used = 0; if ($this->config['rs_power_renewal']) { // Until what time stamp should we count user votes $renewal_timeout = $time - $this->config['rs_power_renewal'] * 3600; // Let's get all voting data on this user. $sql = 'SELECT reputation_points FROM ' . $this->reputation_table . "\n\t\t\t\tWHERE user_id_from = {$user_id}\n\t\t\t\t\tAND reputation_time > {$renewal_timeout}"; $result = $this->db->sql_query($sql); // Let's run through the rows and make statistics while ($renewal = $this->db->sql_fetchrow($result)) { // How much power a user spent in a specified period of time $power_used += (int) $renewal['reputation_points']; } $this->db->sql_freeresult($result); } return (int) $power_used; }
/** * 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')); }
/** * Display flag * * @param $flag_id int the id of the flag * @param $start int page number we start at * @param $limit int limit to display for pagination * @return null * @access public */ protected function display_flag($flag_id, $start, $limit) { //let's get the flag requested $sql = 'SELECT flag_id, flag_name, flag_image FROM ' . $this->flags_table . ' WHERE flag_id = ' . (int) $flag_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // now users that have the flag $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE user_flag = ' . (int) $row['flag_id'] . ' AND ' . $this->db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . ' ORDER BY username_clean'; $result = $this->db->sql_query_limit($sql, $limit, $start); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); // for counting of total flag users $result = $this->db->sql_query($sql); $row2 = $this->db->sql_fetchrowset($result); $total_users = (int) count($row2); $this->db->sql_freeresult($result); unset($row2); foreach ($rows as $userrow) { $user_id = $userrow['user_id']; $username = $this->auth->acl_get('u_viewprofile') ? get_username_string('full', $user_id, $userrow['username'], $userrow['user_colour']) : get_username_string('no_profile', $user_id, $userrow['username'], $userrow['user_colour']); $this->template->assign_block_vars('user_row', array('JOINED' => $this->user->format_date($userrow['user_regdate']), 'VISITED' => empty($userrow['user_lastvisit']) ? ' - ' : $this->user->format_date($userrow['user_lastvisit']), 'POSTS' => $userrow['user_posts'] ? $userrow['user_posts'] : 0, 'USERNAME_FULL' => $username, 'U_SEARCH_USER' => $this->auth->acl_get('u_search') ? append_sid("{$this->root_path}search.{$this->php_ext}", "author_id={$user_id}&sr=posts") : '')); } $this->pagination->generate_template_pagination(array('routes' => array('rmcgirr83_nationalflags_getflags', 'rmcgirr83_nationalflags_getflags_page'), 'params' => array('flag_id' => $flag_id)), 'pagination', 'page', $total_users, $limit, $start); $flag_image = $this->functions->get_user_flag($row['flag_id']); $users_count = $total_users; $total_users = $this->user->lang('FLAG_USERS', (int) $total_users); $this->template->assign_vars(array('FLAG' => html_entity_decode($row['flag_name']), 'FLAG_IMAGE' => $flag_image, 'TOTAL_USERS' => $total_users, 'S_VIEWONLINE' => $this->auth->acl_get('u_viewonline'), 'S_FLAGS' => true, 'S_FLAG_USERS' => !empty($users_count) ? true : false, 'MESSAGE_TEXT' => empty($users_count) ? $this->user->lang['NO_USER_HAS_FLAG'] : '')); // Assign breadcrumb template vars for the flags page $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('rmcgirr83_nationalflags_display'), 'FORUM_NAME' => $this->user->lang('NATIONAL_FLAGS'))); // Assign breadcrumb template vars for the flags page $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $flag_id)), 'FORUM_NAME' => $row['flag_name'])); }
/** * * @param int $user_id - the id of the user you want to count feedbacks for (or false if all users) * @param int $filter - TOPIC_TYPE_SELL, TOPIC_TYPE_BUY, TOPIC_TYPE_TRADE, TAB_TYPE_ALL, TAB_TYPE_LEFT * specifies the topic type of the feedbacks you want (LEFT meaning those feedbacks which * user_id left for others) * * @return int - count of all users feedbacks if user_id is false, otherwise returns count of all feedbacks * that were given to user with id user_id of filtered type */ public function get_users_feedback_count($user_id = false, $filter = self::TAB_TYPE_ALL, $include_deleted = false) { $sql = 'SELECT count(*) as cnt FROM ' . $this->tables['feedback']; $sql .= ' WHERE 1 '; if ($user_id) { if ($filter == self::TAB_TYPE_LEFT) { $sql .= " AND from_user_id={$user_id} "; } else { $sql .= " AND to_user_id={$user_id} "; } } if (!$include_deleted) { $sql .= ' AND is_deleted=0 '; } if ($filter != self::TAB_TYPE_ALL && $filter != self::TAB_TYPE_LEFT) { $sql .= " AND topic_type= " . $filter; } $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); return $row['cnt']; }
/** * Prevent overrating one user by another user * * @param int $user_id User ID * @access public * @return bool */ public function prevent_rating($user_id) { if (!$this->config['rs_prevent_num'] || !$this->config['rs_prevent_perc']) { return false; } $total_reps = $same_user = 0; $post_type = (int) $this->get_reputation_type_id('post'); $user_type = (int) $this->get_reputation_type_id('user'); $sql = 'SELECT user_id_from FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$user_id}\n\t\t\t\tAND (reputation_type_id = {$post_type} OR reputation_type_id = {$user_type})"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $total_reps++; if ($row['user_id_from'] == $this->user->data['user_id']) { $same_user++; } } $this->db->sql_freeresult($result); if ($total_reps >= $this->config['rs_prevent_num'] && $same_user / $total_reps * 100 >= $this->config['rs_prevent_perc']) { return true; } return false; }
/** * 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)); }
/** * Get all user IDs that have specific ACL for album * * @param string $acl One of the permissions, Exp: i_view; *_count permissions are not allowed! * @param int $album_id Album ID we want info for * * return array $user_ids Return user IDs as array */ public function acl_users_ids($acl, $album_id) { if (strstr($acl, '_count') != 0) { return array(); } // Let's load album data $sql = 'SELECT * FROM ' . $this->table_albums . ' WHERE album_id = ' . (int) $album_id; $result = $this->db->sql_query($sql); $album_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Let's request roles // If album user_id is different then 0 then this is user album. // So we need to request all roles for perm_system -2(own) and -3(user) if ($album_data['album_user_id'] != 0) { $sql = 'SELECT * FROM ' . $this->table_permissions . ' WHERE ' . $this->db->sql_in_set('perm_system', array(-2, -3)); } else { $sql = 'SELECT * FROM ' . $this->table_permissions . ' WHERE perm_album_id = ' . $album_id; } $result = $this->db->sql_query($sql); $roles_id = array(); // Now we build the array to test while ($row = $this->db->sql_fetchrow($result)) { $roles_id['roles'][] = (int) $row['perm_role_id']; $roles_id[$row['perm_role_id']]['user_id'][] = (int) $row['perm_user_id']; $roles_id[$row['perm_role_id']]['group_id'][] = (int) $row['perm_group_id']; } $this->db->sql_freeresult($result); // Now we will select the roles that have the setted ACL $sql = 'SELECT role_id FROM ' . $this->table_roles . ' WHERE ' . $acl . ' = 1 and ' . $this->db->sql_in_set('role_id', $roles_id['roles'], false, true); $result = $this->db->sql_query($sql); $roles = array(); while ($row = $this->db->sql_fetchrow($result)) { $roles[] = (int) $row['role_id']; } $this->db->sql_freeresult($result); // Let's cycle trough roles and build user_ids with user_ids from roles $user_ids = array(); foreach ($roles as $id) { $user_ids = array_merge($user_ids, $roles_id[$id]['user_id']); // Let's query groups $sql = 'SELECT * FROM ' . USER_GROUP_TABLE . ' WHERE ' . $this->db->sql_in_set('group_id', $roles_id[$id]['group_id'], false, true); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { if ($row['user_pending'] == 0) { $user_ids[] = $row['user_id']; } } $this->db->sql_freeresult($result); } // Now we cycle the $user_ids to remove 0 and make ids unique $returning_value = array(); foreach ($user_ids as $id) { if ($id != 0) { $returning_value[$id] = (int) $id; } } $user_ids = array(); foreach ($returning_value as $id) { $user_ids[] = (int) $id; } return $user_ids; }
/** * Display the user rating page * * @param int $uid User ID taken from the URL * @return Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public */ public function user($uid) { $this->user->add_lang_ext('pico/reputation', 'reputation_rating'); // Define some variables $error = ''; $is_ajax = $this->request->is_ajax(); $referer = $this->symfony_request->get('_referer'); if (empty($this->config['rs_enable'])) { if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('error_msg' => $this->user->lang('RS_DISABLED')); $json_response->send($json_data); } redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); } if (!$this->config['rs_user_rating'] || !$this->auth->acl_get('u_rs_rate')) { $message = $this->user->lang('RS_DISABLED'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $sql = 'SELECT user_id, user_type FROM ' . USERS_TABLE . "\n\t\t\tWHERE user_id = {$uid}"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (!$row) { $message = $this->user->lang('RS_NO_USER_ID'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } // Cancel action if ($this->request->is_set_post('cancel')) { redirect(append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid)); } if ($row['user_type'] == USER_IGNORE) { $message = $this->user->lang('RS_USER_ANONYMOUS'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($row['user_id'] == $this->user->data['user_id']) { $message = $this->user->lang('RS_SELF'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } // Disallow rating banned users if ($this->user->check_ban($uid, false, false, true)) { $message = $this->user->lang('RS_USER_BANNED'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $reputation_type_id = (int) $this->reputation_manager->get_reputation_type_id('user'); $sql = 'SELECT reputation_id, reputation_time FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}\n\t\t\t\tAND user_id_from = {$this->user->data['user_id']}\n\t\t\t\tAND reputation_type_id = {$reputation_type_id}\n\t\t\tORDER by reputation_id DESC"; $result = $this->db->sql_query($sql); $check_user = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if ($check_user && !$this->config['rs_user_rating_gap']) { $message = $this->user->lang('RS_SAME_USER'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($this->config['rs_user_rating_gap'] && time() < $check_user['reputation_time'] + $this->config['rs_user_rating_gap'] * 86400) { //Inform user how long he has to wait to rate the user $next_vote_time = $check_user['reputation_time'] + $this->config['rs_user_rating_gap'] * 86400 - time(); $next_vote_in = ''; $next_vote_in .= intval($next_vote_time / 86400) ? intval($next_vote_time / 86400) . ' ' . $this->user->lang('DAYS') . ' ' : ''; $next_vote_in .= intval($next_vote_time / 3600 % 24) ? intval($next_vote_time / 3600 % 24) . ' ' . $this->user->lang('HOURS') . ' ' : ''; $next_vote_in .= intval($next_vote_time / 60 % 60) ? intval($next_vote_time / 60 % 60) . ' ' . $this->user->lang('MINUTES') : ''; $next_vote_in .= intval($next_vote_time) < 60 ? intval($next_vote_time) . ' ' . $this->user->lang('SECONDS') : ''; $message = $this->user->lang('RS_USER_GAP', $next_vote_in); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($this->reputation_manager->prevent_rating($uid)) { $message = $this->user->lang('RS_SAME_USER'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_TOPIC'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } // Request variables $points = $this->request->variable('points', ''); $comment = $this->request->variable('comment', '', true); $error = ''; // Submit vote $submit = false; if ($this->request->is_set_post('submit_vote')) { $submit = true; } // The comment if ($submit && $this->config['rs_enable_comment']) { // The comment is too long if (strlen($comment) > $this->config['rs_comment_max_chars']) { $submit = false; $error = $this->user->lang('RS_COMMENT_TOO_LONG', strlen($comment), $this->config['rs_comment_max_chars']); if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('comment_error' => $error); $json_response->send($json_data); } } // Force the comment if (($this->config['rs_force_comment'] == self::RS_COMMENT_BOTH || $this->config['rs_force_comment'] == self::RS_COMMENT_USER) && empty($comment)) { $submit = false; $error = $this->user->lang('RS_NO_COMMENT'); if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('comment_error' => $error); $json_response->send($json_data); } } } // Get reputation power if ($this->config['rs_enable_power']) { $voting_power_pulldown = ''; // Get details on user voting - how much power was used $used_power = $this->reputation_power->used($this->user->data['user_id']); //Calculate how much maximum power a user has $max_voting_power = $this->reputation_power->get($this->user->data['user_posts'], $this->user->data['user_regdate'], $this->user->data['user_reputation'], $this->user->data['user_warnings'], $this->user->data['group_id']); if ($max_voting_power < 1) { $message = $this->user->lang('RS_NO_POWER'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $voting_power_left = $max_voting_power - $used_power; //Don't allow to vote more than set in ACP per 1 vote $max_voting_allowed = $this->config['rs_power_renewal'] ? min($max_voting_power, $voting_power_left) : $max_voting_power; //If now voting power left - fire error and exit if ($voting_power_left <= 0 && $this->config['rs_power_renewal']) { $message = $this->user->lang('RS_NO_POWER_LEFT', $max_voting_power); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $this->template->assign_vars(array('RS_POWER_POINTS_LEFT' => $this->config['rs_power_renewal'] ? $this->user->lang('RS_VOTE_POWER_LEFT_OF_MAX', $voting_power_left, $max_voting_power, $max_voting_allowed) : '', 'RS_POWER_PROGRESS_EMPTY' => $this->config['rs_power_renewal'] && $max_voting_power ? round(($max_voting_power - $voting_power_left) / $max_voting_power * 100, 0) : '')); //Preparing HTML for voting by manual spending of user power $startpower = $this->config['rs_negative_point'] ? -$max_voting_allowed : 1; for ($i = $max_voting_allowed; $i >= $startpower; $i--) { if ($i == 0) { $voting_power_pulldown = ''; } if ($i > 0) { $voting_power_pulldown = '<option value="' . $i . '">' . $this->user->lang('RS_POSITIVE') . ' (+' . $i . ') </option>'; } if ($i < 0 && $this->auth->acl_get('u_rs_rate_negative') && $this->config['rs_negative_point'] && ($this->config['rs_min_rep_negative'] != 0 ? $this->user->data['user_reputation'] >= $this->config['rs_min_rep_negative'] : true)) { $voting_power_pulldown = '<option value="' . $i . '">' . $this->user->lang('RS_NEGATIVE') . ' (' . $i . ') </option>'; } $this->template->assign_block_vars('reputation', array('REPUTATION_POWER' => $voting_power_pulldown)); } } else { $rs_power = '<option value="1">' . $this->user->lang('RS_POSITIVE') . '</option>'; if ($this->auth->acl_get('u_rs_rate_negative') && $this->config['rs_negative_point'] && ($this->config['rs_min_rep_negative'] != 0 ? $this->user->data['user_reputation'] >= $this->config['rs_min_rep_negative'] : true)) { $rs_power .= '<option value="-1">' . $this->user->lang('RS_NEGATIVE') . '</option>'; } else { if ($this->config['rs_enable_comment']) { $points = 1; } else { $submit = true; $points = 1; } } $this->template->assign_block_vars('reputation', array('REPUTATION_POWER' => $rs_power)); } if ($submit) { //Prevent cheater to break the forum permissions to give negative points or give more points than they can if (!$this->auth->acl_get('u_rs_rate_negative') && $points < 0 || $points < 0 && $this->config['rs_min_rep_negative'] && $this->user->data['user_reputation'] < $this->config['rs_min_rep_negative'] || $this->config['rs_enable_power'] && ($points > $max_voting_allowed || $points < -$max_voting_allowed)) { $submit = false; $error = $this->user->lang('RS_USER_CANNOT_RATE'); if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('comment_error' => $error); $json_response->send($json_data); } } } if (!empty($error)) { $submit = false; } if ($submit) { $data = array('user_id_from' => $this->user->data['user_id'], 'user_id_to' => $uid, 'reputation_type' => 'user', 'reputation_item_id' => $uid, 'reputation_points' => $points, 'reputation_comment' => $comment); try { $this->reputation_manager->store_reputation($data); } catch (\pico\reputation\exception\base $e) { // Catch exception $error = $e->get_message($this->user); } // Prepare notification data and notify user $notification_data = array('user_id_to' => $uid, 'user_id_from' => $this->user->data['user_id']); $this->reputation_manager->add_notification('pico.reputation.notification.type.rate_user', $notification_data); $message = $this->user->lang('RS_VOTE_SAVED'); $json_data = array('user_reputation' => '<strong>' . $this->reputation_manager->get_user_reputation($uid) . '</strong>', 'success_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $this->template->assign_vars(array('ERROR_MSG' => $error, 'S_CONFIRM_ACTION' => $this->helper->route('reputation_user_rating_controller', array('uid' => $uid)), 'S_RS_COMMENT_ENABLE' => $this->config['rs_enable_comment'] ? true : false, 'S_IS_AJAX' => $is_ajax, 'U_RS_REFERER' => $referer)); return $this->helper->render('rateuser.html', $this->user->lang('RS_USER_RATING')); }
/** * 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')); }