示例#1
0
文件: Ratings.php 项目: norv/EosAlpha
/**
 * generate the rating widget
 */
function GetRatingWidget()
{
    global $modSettings, $user_info, $context, $txt;
    if ($user_info['is_guest']) {
        AjaxErrorMsg($txt['no_like_for_guests']);
    }
    $xml = isset($_REQUEST['xml']);
    $content_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
    $ctype = isset($_REQUEST['c']) ? (int) $_REQUEST['c'] : 0;
    if (0 == $ctype || 0 == $content_id) {
        AjaxErrorMsg($txt['rating_invalid_params']);
    }
    if ($xml) {
        EoS_Smarty::loadTemplate('xml_blocks');
        $context['template_functions'] = 'ratingwidget';
    } else {
        EoS_Smarty::loadTemplate('ratings/widget');
    }
    // todo: allow rating without ajax / js
    $request = smf_db_query('SELECT m.id_msg, m.id_topic, m.id_board FROM {db_prefix}messages AS m WHERE m.id_msg = {int:id} LIMIT 1', array('id' => $content_id));
    list($id_msg, $id_topic, $id_board) = mysql_fetch_row($request);
    mysql_free_result($request);
    $context['result_count'] = 0;
    $uniques = array(true, false);
    foreach ($uniques as $uniqueness) {
        foreach ($modSettings['ratings'] as $key => $rating) {
            if ($rating['unique'] != $uniqueness) {
                continue;
            }
            if (Ratings::isAllowed($key, $id_board)) {
                $context['result_count']++;
                $context['ratings'][] = array('rtype' => (int) $key, 'label' => $rating['text'], 'unique' => $rating['unique']);
            }
        }
    }
    $context['content_id'] = $content_id;
    $context['json_data'] = htmlspecialchars(json_encode(array('id' => $content_id, 'error_text' => $txt['ratingwidget_error'])));
}
示例#2
0
    /**
     * @param $mid = int message (or content) id
     *
     * handle the ajax request for rating a post. Also handles deletion of 
     * 
     * TODO: remove likes from the database when a user is deleted
     * TODO: make it work without AJAX and JavaScript
     */
    public static function rateIt($mid)
    {
        global $context, $user_info, $sourcedir, $txt, $modSettings;
        $total = array();
        $content_type = 1;
        // > post content type, we should define them elsewhere later when we have more than just this one
        if ((int) $mid > 0) {
            $uid = $user_info['id'];
            $remove_it = isset($_REQUEST['remove']) ? true : false;
            $repair = isset($_REQUEST['repair']) && $user_info['is_admin'] ? true : false;
            $is_xmlreq = $_REQUEST['action'] == 'xmlhttp' ? true : false;
            $update_mode = false;
            $like_type = isset($_REQUEST['r']) && (int) $_REQUEST['r'] > 0 ? $_REQUEST['r'] : '1';
            $comment = isset($_REQUEST['comment']) ? strip_tags($_REQUEST['comment']) : '';
            $rtypes = explode(',', $like_type);
            foreach ($rtypes as $rtype) {
                if (!isset($modSettings['ratings'][$rtype])) {
                    AjaxErrorMsg($txt['unknown_rating_type']);
                }
            }
            if ($user_info['is_guest']) {
                AjaxErrorMsg($txt['no_like_for_guests']);
            }
            $request = smf_db_query('SELECT m.id_msg, m.id_member, m.id_board, m.id_topic, m.subject, l.id_msg AS like_message, l.rtype, l.id_user
					FROM {db_prefix}messages AS m 
					LEFT JOIN {db_prefix}likes AS l ON (l.id_msg = m.id_msg AND l.ctype = {int:content_type} AND l.id_user = {int:id_user})
					WHERE m.id_msg = {int:id_msg} LIMIT 1', array('content_type' => $content_type, 'id_msg' => $mid, 'id_user' => $uid));
            $row = mysql_fetch_assoc($request);
            mysql_free_result($request);
            $like_owner = $row['id_user'];
            if ($row['id_user'] > 0 && !$remove_it && !$repair) {
                // duplicate like (but not when removing it)
                AjaxErrorMsg($txt['like_verify_error']);
            }
            $like_receiver = $row['id_member'];
            EoS_Smarty::loadTemplate('xml_blocks');
            $context['template_functions'] = 'rating_response';
            $context['ratings_output']['mid'] = $mid;
            /*
             * this is a debugging feature and allows the admin to repair
             * the likes for a post.
             * it may go away at a later time.
             */
            if ($repair) {
                if (!$user_info['is_admin']) {
                    obExit(false);
                }
                $total = self::updateForContent($mid);
                $output = '';
                self::generateOutput($total['status'], $output, $mid, $row['id_user'] > 0 ? $row['rtype'] : 0);
                // fix like stats for the like_giver and like_receiver. This might be a very slow query, but
                // since this feature will most likely go away, right now I do not care.
                /*
                				smf_db_query('UPDATE {db_prefix}members AS m
                SET m.likes_given = (SELECT COUNT(l.id_user) FROM {db_prefix}likes AS l WHERE l.id_user = m.id_member),
                	m.likes_received = (SELECT COUNT(l1.id_receiver) FROM {db_prefix}likes AS l1 WHERE l1.id_receiver = m.id_member)
                WHERE m.id_member = {int:owner} OR m.id_member = {int:receiver}', array('owner' => $like_owner, 'receiver' => $like_receiver));
                */
                invalidateMemberData(array($like_owner, $like_receiver));
                if ($is_xmlreq) {
                    $context['ratings_output']['output'] = $output;
                    $context['ratings_output']['likebar'] = '';
                    $context['postratings'] = json_encode($context['ratings_output']);
                    return;
                } else {
                    redirectexit();
                }
            }
            if ($like_receiver == $uid) {
                AjaxErrorMsg($txt['cannot_like_own']);
            }
            if (!allowedTo('like_give', $row['id_board'])) {
                // no permission to give likes in this board
                AjaxErrorMsg($txt['like_no_permission']);
            }
            if ($remove_it && $row['id_user'] > 0) {
                // remove a rating
                if ($like_owner == $uid) {
                    smf_db_query('DELETE FROM {db_prefix}likes WHERE id_msg = {int:id_msg} AND id_user = {int:id_user} AND ctype = {int:ctype}', array('id_msg' => $mid, 'id_user' => $uid, 'ctype' => $content_type));
                    if ($like_receiver) {
                        smf_db_query('UPDATE {db_prefix}members SET likes_received = likes_received - 1 WHERE id_member = {int:id_member}', array('id_member' => $like_receiver));
                    }
                    smf_db_query('UPDATE {db_prefix}members SET likes_given = likes_given - 1 WHERE id_member = {int:id_member}', array('id_member' => $uid));
                    // if we remove a like (unlike) a post, also delete the corresponding activity
                    smf_db_query('DELETE a.*, n.* FROM {db_prefix}log_activities AS a LEFT JOIN {db_prefix}log_notifications AS n ON(n.id_act = a.id_act)
						WHERE a.id_member = {int:id_member} AND a.id_type = 1 AND a.id_content = {int:id_content}', array('id_member' => $uid, 'id_content' => $mid));
                    $context['ratings_output']['likebar'] = self::$rate_bar;
                }
            } else {
                /* store the rating */
                global $memberContext;
                if ($like_receiver) {
                    // we do have a member, but still allow to like posts made by guests
                    loadMemberData($like_receiver);
                    // but banned users shall not receive likes
                    loadMemberContext($like_receiver);
                }
                if ($like_receiver && !$memberContext[$like_receiver]['is_banned'] || $like_receiver == 0) {
                    // posts by guests can be liked
                    smf_db_query('INSERT INTO {db_prefix}likes(id_msg, id_user, id_receiver, updated, ctype, rtype, comment) 
							VALUES({int:id_message}, {int:id_user}, {int:id_receiver}, {int:updated}, {int:ctype}, {string:rtype}, {string:comment})', array('id_message' => $mid, 'id_user' => $uid, 'id_receiver' => $like_receiver, 'updated' => time(), 'ctype' => $content_type, 'rtype' => $like_type, 'comment' => $comment));
                    if ($like_receiver) {
                        smf_db_query('UPDATE {db_prefix}members SET likes_received = likes_received + 1 WHERE id_member = {int:id_member}', array('id_member' => $like_receiver));
                    }
                    smf_db_query('UPDATE {db_prefix}members SET likes_given = likes_given + 1 WHERE id_member = {int:uid}', array('uid' => $uid));
                    $update_mode = $like_type;
                    if ($modSettings['astream_active']) {
                        @(require_once $sourcedir . '/lib/Subs-Activities.php');
                        aStreamAdd($uid, ACT_LIKE, array('member_name' => $context['user']['name'], 'topic_title' => $row['subject'], 'rtype' => $like_type), $row['id_board'], $row['id_topic'], $mid, $like_receiver);
                    }
                } else {
                    AjaxErrorMsg($txt['like_cannot_like']);
                }
                $context['ratings_output']['likebar'] = '<a rel="nofollow" class="givelike" data-fn="remove" href="#" data-id="' . $mid . '">' . $txt['unlike_label'] . '</a>';
            }
            if ($user_info['is_admin'] && self::$show_repair_link) {
                $context['ratings_output']['likebar'] .= ' <a rel="nofollow" class="givelike" data-fn="repair" href="#" data-id="' . $mid . '">Repair ratings</a>';
            }
            $total = self::updateForContent($mid);
            $output = '';
            self::generateOutput($total['status'], $output, $mid, $update_mode);
            $context['ratings_output']['output'] = $output;
            $context['postratings'] = json_encode($context['ratings_output']);
        }
    }
示例#3
0
function DismissNews()
{
    global $context, $user_info, $txt;
    EoS_Smarty::loadTemplate('xml_blocks');
    $context['template_functions'] = array('dismiss_newsitem');
    $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
    $xml = isset($_REQUEST['xml']) ? true : false;
    $context['sub_template'] = 'dismiss_handler' . ($xml ? '_xml' : '');
    $effective_id = 0;
    if ($id) {
        $result = smf_db_query('SELECT id_news, can_dismiss FROM {db_prefix}news WHERE id_news = {int:id}', array('id' => $id));
        if (mysql_num_rows($result) > 0) {
            list($effective_id, $can_dismiss_item) = mysql_fetch_row($result);
        }
        mysql_free_result($result);
        if (!empty($effective_id)) {
            $context['raw_item_id'] = $effective_id;
            if ($user_info['is_admin'] || allowedTo('can_dismiss_news') && $can_dismiss_item != 0) {
                $context['item_to_dismiss'] = json_encode(array('id' => $effective_id));
                if (!isset($user_info['meta']['dismissed_news_items'][$effective_id])) {
                    $user_info['meta']['dismissed_news_items'][$effective_id] = $effective_id;
                    updateMemberData($user_info['id'], array('meta' => @serialize($user_info['meta'])));
                }
                if ($xml) {
                    $context['template_layers'] = array();
                }
                return;
            }
        }
    }
    loadLanguage('Errors');
    if (isset($_REQUEST['xml'])) {
        AjaxErrorMsg($txt['no_access']);
    } else {
        fatal_lang_error('no_access');
    }
}
示例#4
0
文件: Xml.php 项目: norv/EosAlpha
function TopicPeek()
{
    global $context;
    global $user_info, $board, $memberContext, $txt;
    $is_xmlreq = $_REQUEST['action'] == 'xmlhttp' ? true : false;
    if (isset($_REQUEST['t'])) {
        $tid = intval($_REQUEST['t']);
    } else {
        $tid = 0;
    }
    if (!$is_xmlreq) {
        redirectexit();
    }
    // this action is XMLHttp - only
    if ($tid) {
        global $memberContext;
        EoS_Smarty::loadTemplate('topic/preview');
        loadLanguage('index');
        loadLanguage('Errors');
        $result = smf_db_query('
			SELECT b.*, t.id_topic, t.id_board, t.id_first_msg, t.id_last_msg, m.id_member AS member_started, m1.id_member AS member_lastpost, m.subject AS first_subject, m.poster_name AS starter_name, m1.subject AS last_subject,
			m1.poster_name AS last_name, m.body as first_body, m1.body AS last_body, 
			' . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from,
			m.poster_time AS first_time, m1.poster_time AS last_time FROM {db_prefix}topics AS t
			LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
			LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
			LEFT JOIN {db_prefix}boards AS b ON b.id_board = t.id_board
			LEFT JOIN {db_prefix}messages AS m ON m.id_msg = t.id_first_msg 
			LEFT JOIN {db_prefix}messages AS m1 ON m1.id_msg = t.id_last_msg WHERE t.id_topic = {int:topic_id} AND {query_see_board} LIMIT 1', array('topic_id' => $tid, 'current_member' => $user_info['id'], 'current_board' => $board));
        $row = mysql_fetch_assoc($result);
        mysql_free_result($result);
        if (!$row) {
            AjaxErrorMsg($txt['topic_gone'], $txt['error_occured']);
        } else {
            $m = array();
            $m[0] = $row['member_started'];
            if ($row['id_first_msg'] != $row['id_last_msg'] && $row['member_lastpost']) {
                $m[1] = $row['member_lastpost'];
            }
            loadMemberData($m);
            loadMemberContext($m[0]);
            $context['member_started'] =& $memberContext[$row['member_started']];
            if (isset($m[1])) {
                loadMemberContext($m[1]);
                $context['member_lastpost'] =& $memberContext[$row['member_lastpost']];
            } else {
                $context['member_lastpost'] = null;
            }
            $context['preview'] =& $row;
            // truncate, censor and parse bbc
            $_b = commonAPI::substr($context['preview']['first_body'], 0, 300) . '...';
            censorText($_b);
            $context['preview']['first_body'] = parse_bbc($_b, false);
            $context['preview']['first_time'] = timeformat($row['first_time']);
            if ($context['member_lastpost']) {
                $_b = commonAPI::substr($context['preview']['last_body'], 0, 600) . '...';
                censorText($_b);
                $context['preview']['last_body'] = parse_bbc($_b, false);
                $context['preview']['last_time'] = timeformat($row['last_time']);
            }
        }
    }
}