/**
     * 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'] . '&amp;t=' . $row['topic_id']) . '" ' . $topic_color . '>&nbsp;&nbsp;' . 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));
        }
    }
Esempio n. 3
0
    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']));
    }
Esempio n. 4
0
    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'));
    }
    /**
     * 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));
        }
    }
Esempio n. 6
0
 /**
  * Validates the request's trader type with the forum's trader_type and returns the corresponding (int) $type or null if invalid
  * @param $forum_id
  * @param $type
  * @return int
  */
 public function validateForumType($forum_id, $type, $isStringRep)
 {
     $result = $this->db->sql_query('SELECT enabled_trader_types FROM ' . FORUMS_TABLE . ' WHERE forum_id=' . $forum_id);
     $forum_row = $this->db->sql_fetchrow($result);
     $forum_type = $forum_row['enabled_trader_types'];
     if ($isStringRep) {
         switch ($type) {
             case 'buy':
                 $type = self::TOPIC_TYPE_BUY;
                 break;
             case 'sell':
                 $type = self::TOPIC_TYPE_SELL;
                 break;
             case 'trade':
                 $type = self::TOPIC_TYPE_TRADE;
                 break;
             default:
                 $type = null;
         }
     }
     if (!is_null($type) && $type <= $forum_type) {
         return $type;
     } else {
         return null;
     }
 }
    /**
     * 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);
        }
    }
Esempio n. 8
0
    /**
     *
     * https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php
     *
     * @return boolean
     */
    public function ipn()
    {
        $raw_post_data = file_get_contents('php://input');
        $raw_post_array = explode('&', $raw_post_data);
        $myPost = array();
        foreach ($raw_post_array as $keyval) {
            $keyval = explode('=', $keyval);
            if (count($keyval) == 2) {
                $myPost[$keyval[0]] = urldecode($keyval[1]);
            }
        }
        // read the post from PayPal system and add 'cmd'
        $req = 'cmd=_notify-validate';
        if (function_exists('get_magic_quotes_gpc')) {
            $get_magic_quotes_exists = true;
        }
        foreach ($myPost as $key => $value) {
            if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                $value = urlencode(stripslashes($value));
            } else {
                $value = urlencode($value);
            }
            $req .= "&{$key}={$value}";
        }
        $sql = 'SELECT paypal_sandbox
			FROM ' . $this->table_config;
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $paypal_url = $row['paypal_sandbox'] == 1 ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
        $ch = curl_init($paypal_url);
        if ($ch == false) {
            return false;
        }
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
        $res = curl_exec($ch);
        curl_close($ch);
        // Inspect IPN validation result and act accordingly
        // Split response headers and payload, a better way for strcmp
        $tokens = explode("\r\n\r\n", trim($res));
        $res = trim(end($tokens));
        if (strcmp($res, 'VERIFIED') == 0) {
            $sql_data = array('user_id' => (int) $this->request->variable('custom', '0'), 'item_id' => (int) $this->request->variable('item_number', '0'), 'item_name' => $this->request->variable('item_number', '', true), 'donation_time' => time(), 'donation_amount' => $this->request->variable('mc_gross', '0'));
            $sql = 'INSERT INTO ' . $this->table_donations . '
				' . $this->db->sql_build_array('INSERT', $sql_data);
            $this->db->sql_query($sql);
        }
        $headers = array('Content-Type' => 'application/xml; charset=UTF-8');
        return new Response('', '200', $headers);
    }
    /**
     * 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&amp;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;
    }
Esempio n. 11
0
    /**
     * Update a blog post using the given information
     *
     * @param int $id
     * @param string $title
     * @param string $slug
     * @param int $time
     * @param int $edit_time
     * @param string $edit_reason
     * @param bool $status
     * @param bool $locked
     * @param int $poster_id
     * @param int $comment_count
     * @param string $content
     * @param string $bbcode_uid
     * @param string $bbcode_bitfield
     * @param array $categories Array of category IDs
     * @param array $tags Array of tag IDs
     * @return bool
     */
    public function update($id, $title, $slug, $time, $edit_time, $edit_reason, $status, $locked, $poster_id, $comment_count, $content, $bbcode_uid, $bbcode_bitfield, array $categories, array $tags)
    {
        $sql = 'UPDATE ' . $this->blog_posts_table . ' SET ' . $this->db->sql_build_array('UPDATE', array('title' => $title, 'slug' => $slug, 'time' => (int) $time, 'edit_time' => (int) $edit_time, 'edit_reason' => $edit_reason, 'status' => (bool) $status, 'locked' => (bool) $locked, 'poster_id' => (int) $poster_id, 'comment_count' => (int) $comment_count, 'content' => $content, 'bbcode_uid' => $bbcode_uid, 'bbcode_bitfield' => $bbcode_bitfield)) . ' WHERE id = ' . (int) $id;
        $this->db->sql_query($sql);
        // Handle category changes
        $sql = 'SELECT category_id FROM ' . $this->blog_post_categories_table . ' WHERE post_id = ' . (int) $id;
        $result = $this->db->sql_query($sql);
        $current_categories = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $current_categories[] = $row['category_id'];
        }
        $this->db->sql_freeresult($result);
        $added_categories = array_diff($categories, $current_categories);
        $removed_categories = array_diff($current_categories, $categories);
        foreach ($added_categories as $added_category) {
            $sql = 'INSERT INTO ' . $this->blog_post_categories_table . ' ' . $this->db->sql_build_array('INSERT', array('post_id' => (int) $post_id, 'category_id' => (int) $added_category));
            $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);
        }
        foreach ($removed_categories as $removed_category) {
            $sql = 'DELETE FROM ' . $this->blog_post_categories_table . '
				WHERE post_id = ' . (int) $id . '
					AND category_id = ' . (int) $removed_category;
            $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);
        }
        // Handle tag changes
        $sql = 'SELECT tag_id FROM ' . $this->blog_post_tags_table . ' WHERE post_id = ' . (int) $id;
        $result = $this->db->sql_query($sql);
        $current_tags = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $current_tags[] = $row['tag_id'];
        }
        $this->db->sql_freeresult($result);
        $added_tags = array_diff($tags, $current_tags);
        $removed_categories = array_diff($current_tags, $tags);
        foreach ($added_tags as $added_tag) {
            $sql = 'INSERT INTO ' . $this->blog_post_tags_table . ' ' . $this->db->sql_build_array('INSERT', array('post_id' => (int) $post_id, 'category_id' => (int) $added_tag));
        }
        foreach ($removed_tags as $removed_tag) {
            $sql = 'DELETE FROM ' . $this->blog_post_tags_table . '
				WHERE post_id = ' . (int) $id . '
					AND category_id = ' . (int) $removed_tag;
            $this->db->sql_query($sql);
        }
        return true;
    }
Esempio n. 12
0
    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));
    }
 /**
  * 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));
     }
 }
 /**
  * Obtain an array of active users over the last 24 hours.
  *
  * @return array
  */
 private function obtain_active_user_data()
 {
     if (($active_users = $this->cache->get('_24hour_users')) === false) {
         $active_users = array();
         // grab a list of users who are currently online
         // and users who have visited in the last 24 hours
         $sql_ary = array('SELECT' => 'u.user_id, u.user_colour, u.username, u.user_type, u.user_lastvisit, MAX(s.session_time) as session_time', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array(SESSIONS_TABLE => 's'), 'ON' => 's.session_user_id = u.user_id')), 'WHERE' => 'u.user_lastvisit > ' . (time() - 86400) . ' OR s.session_user_id <> ' . ANONYMOUS, 'GROUP_BY' => 'u.user_id', 'ORDER_BY' => 'u.username');
         $result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary));
         while ($row = $this->db->sql_fetchrow($result)) {
             $active_users[$row['user_id']] = $row;
         }
         $this->db->sql_freeresult($result);
         // cache this data for 1 hour, this improves performance
         $this->cache->put('_24hour_users', $active_users, 3600);
     }
     return $active_users;
 }
Esempio n. 15
0
    /**
     * Add map to users profile
     *
     * @param	object	$event	The event object
     * @return	null
     * @access	public
     */
    public function memberlist_view_profile($event)
    {
        if ($this->config['tas2580_usermap_map_in_viewprofile'] == 0) {
            return false;
        }
        $data = $event['member'];
        $this->user->add_lang_ext('tas2580/usermap', 'controller');
        $distance = $this->get_distance($this->user->data['user_usermap_lon'], $this->user->data['user_usermap_lat'], $data['user_usermap_lon'], $data['user_usermap_lat']);
        // Center the map to user
        $this->template->assign_vars(array('S_IN_USERMAP' => true, 'USERMAP_CONTROLS' => 'false', 'USERNAME' => get_username_string('full', $data['user_id'], $data['username'], $data['user_colour']), 'USERMAP_LON' => $data['user_usermap_lon'], 'USERMAP_LAT' => $data['user_usermap_lat'], 'USERMAP_ZOOM' => (int) 10, 'DISTANCE' => $distance, 'MARKER_PATH' => $this->path_helper->update_web_root_path($this->phpbb_extension_manager->get_extension_path('tas2580/usermap', true) . 'marker'), 'MAP_TYPE' => $this->config['tas2580_usermap_map_type'], 'GOOGLE_API_KEY' => $this->config['tas2580_usermap_google_api_key']));
        $sql = 'SELECT group_id, group_usermap_marker
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . (int) $data['group_id'];
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->template->assign_vars(array('USERMAP_MARKER' => $row['group_usermap_marker']));
    }
    /**
     * 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 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}&amp;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']));
    }
Esempio n. 18
0
    /**
     * 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'));
    }
    /**
     * 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;
    }
Esempio n. 20
0
 private function getTopic($topic_id)
 {
     $topic_id = (int) $topic_id;
     $result = $this->db->sql_query('SELECT topic_id, topic_trader_type, topic_title, topic_poster FROM ' . TOPICS_TABLE . ' WHERE topic_id=' . $topic_id);
     return $this->db->sql_fetchrow($result);
 }
    /**
     * 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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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&amp;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'));
    }
Esempio n. 22
0
 /**
  * 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;
 }