function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $selchildid, $answers)
{
    $oldselchildid = $oldquestion['selchildid'];
    qa_db_post_set_selchildid($oldquestion['postid'], isset($selchildid) ? $selchildid : null);
    qa_db_points_update_ifuser($oldquestion['userid'], 'aselects');
    if (isset($oldselchildid)) {
        if (isset($answers[$oldselchildid])) {
            qa_db_points_update_ifuser($answers[$oldselchildid]['userid'], 'aselecteds');
            qa_report_event('a_unselect', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $oldselchildid));
        }
    }
    if (isset($selchildid)) {
        $answer = $answers[$selchildid];
        qa_db_points_update_ifuser($answer['userid'], 'aselecteds');
        if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
            require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
            require_once QA_INCLUDE_DIR . 'qa-app-options.php';
            require_once QA_INCLUDE_DIR . 'qa-util-string.php';
            require_once QA_INCLUDE_DIR . 'qa-app-format.php';
            $blockwordspreg = qa_get_block_words_preg();
            $sendtitle = qa_block_words_replace($oldquestion['title'], $blockwordspreg);
            $sendcontent = qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
            qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array('^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendcontent, '^url' => qa_path(qa_q_request($oldquestion['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $selchildid))));
        }
        qa_report_event('a_select', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $selchildid));
    }
}
Example #2
0
function qa_priv_notification($uid, $oid, $badge_slug)
{
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    if (QA_FINAL_EXTERNAL_USERS) {
        $publictohandle = qa_get_public_from_userids(array($uid));
        $handle = @$publictohandle[$uid];
    } else {
        $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
        $handle = @$user['handle'];
    }
    $subject = qa_opt('badge_email_subject');
    $body = qa_opt('badge_email_body');
    $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body);
    // if post text
    $site_url = qa_opt('site_url');
    $profile_url = qa_path_html('user/' . $handle, null, $site_url);
    if ($oid) {
        $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true);
        if ($post['parentid']) {
            $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true);
        }
        if (isset($parent)) {
            $anchor = urlencode(qa_anchor($post['basetype'], $oid));
            $post_title = $parent['title'];
            $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
        } else {
            $post_title = $post['title'];
            $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url'));
        }
    }
    $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url);
    qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
}
 public function process_event($event, $userid, $handle, $cookieid, $params)
 {
     switch ($event) {
         case 'q_post':
             $this->send_hipchat_notification($this->build_new_question_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $params['title'], qa_q_path($params['postid'], $params['title'], true)));
             break;
         case 'a_post':
             $parentpost = qa_post_get_full($params['parentid']);
             $this->send_hipchat_notification($this->build_new_answer_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $parentpost['title'], qa_path(qa_q_request($params['parentid'], $parentpost['title']), null, qa_opt('site_url'), null, qa_anchor('A', $params['postid']))));
             break;
     }
 }
Example #4
0
    require_once QA_INCLUDE_DIR . 'pages/question-view.php';
    require_once QA_INCLUDE_DIR . 'pages/question-submit.php';
    require_once QA_INCLUDE_DIR . 'util/sort.php';
    //	Try to create the new comment
    $usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question));
    $commentid = qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors);
    //	If successful, page content will be updated via Ajax
    if (isset($commentid)) {
        $children = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid));
        $parent = $parent + qa_page_q_post_rules($parent, $questionid == $parentid ? null : $question, null, $children);
        // in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant
        foreach ($children as $key => $child) {
            $children[$key] = $child + qa_page_q_post_rules($child, $parent, $children, null);
        }
        $usershtml = qa_userids_handles_html($children, true);
        qa_sort_by($children, 'created');
        $c_list = qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
        $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
        echo "QA_AJAX_RESPONSE\n1\n";
        //	Send back the ID of the new comment
        echo qa_anchor('C', $commentid) . "\n";
        //	Send back the HTML
        $themeclass->c_list_items($c_list['cs']);
        return;
    }
}
echo "QA_AJAX_RESPONSE\n0\n";
// fall back to non-Ajax submission if there were any problems
/*
	Omit PHP closing tag to help avoid accidental output
*/
    function process_request($request)
    {
        // we received post data, it is the ajax call!
        $transferString = qa_post_text('ajax');
        if ($transferString !== null) {
            // prevent empty userid
            $userid = qa_get_logged_in_userid();
            if (empty($userid)) {
                echo 'Userid is empty!';
                return;
            }
            // this is echoed via ajax success data
            $notifyBoxEvents = '';
            // ajax return all user events
            if (isset($userid) && $transferString == 'receiveNotify') {
                $last_visit = qa_db_read_one_value(qa_db_query_sub('SELECT UNIX_TIMESTAMP(meta_value) FROM ^usermeta WHERE user_id=# AND meta_key="visited_profile"', $userid), true);
                $maxEvents = qa_opt('q2apro_onsitenotifications_maxevshow');
                // maximal events to show
                // query all new events of user
                $event_query = qa_db_query_sub('SELECT 
							e.event, 
							e.userid, 
							BINARY e.params as params, 
							UNIX_TIMESTAMP(e.datetime) AS datetime
						FROM 
							^eventlog AS e
						WHERE
							FROM_UNIXTIME(#) <= datetime
							AND
							(e.userid=# AND e.event LIKE "in_%")
							OR ((e.event LIKE "u_message" OR e.event LIKE "u_wall_post") AND e.params LIKE "userid=#\\t%")
						ORDER BY datetime DESC
						LIMIT #', qa_opt('q2apro_onsitenotifications_maxage'), $userid, $userid, $maxEvents);
                $events = array();
                $postids = array();
                $count = 0;
                while (($event = qa_db_read_one_assoc($event_query, true)) !== null) {
                    if (preg_match('/postid=([0-9]+)/', $event['params'], $m) === 1) {
                        $event['postid'] = (int) $m[1];
                        $postids[] = (int) $m[1];
                        $events[$m[1] . '_' . $count++] = $event;
                    }
                    // private message
                    if ($event['event'] == 'u_message') {
                        // example of $event['params']: userid=1  handle=admin  messageid=4  message=hi admin, how are you?
                        $ustring = $event['params'];
                        // get messageid
                        if (preg_match('/messageid=([0-9]+)/', $ustring, $m) === 1) {
                            $event['messageid'] = (int) $m[1];
                        }
                        // needed for function qa_post_userid_to_handle()
                        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                        // get handle from userid, memo: userid from receiver is saved in params (the acting userid is the sender)
                        $event['handle'] = qa_post_userid_to_handle($event['userid']);
                        // get message preview by cutting out the string
                        $event['message'] = substr($ustring, strpos($ustring, 'message=') + 8, strlen($ustring) - strpos($ustring, 'message=') + 8);
                        $events[$m[1] . '_' . $count++] = $event;
                    } else {
                        if ($event['event'] == 'u_wall_post') {
                            // example of $event['params']: userid=1	handle=admin	messageid=8	content=hi admin!	format=	text=hi admin!
                            $ustring = $event['params'];
                            // get messageid
                            if (preg_match('/messageid=([0-9]+)/', $ustring, $m) === 1) {
                                $event['messageid'] = (int) $m[1];
                            }
                            // needed for function qa_post_userid_to_handle()
                            require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                            // get handle from userid, memo: userid from receiver is saved in params (the acting userid is the sender)
                            $event['handle'] = qa_post_userid_to_handle($event['userid']);
                            // get message preview by cutting out the string
                            $event['message'] = substr($ustring, strpos($ustring, 'text=') + 5, strlen($ustring) - strpos($ustring, 'text=') + 5);
                            $events[$m[1] . '_' . $count++] = $event;
                        }
                    }
                }
                // get post info, also make sure that post exists
                $posts = null;
                if (!empty($postids)) {
                    $post_query = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, type, parentid, BINARY title as title FROM ^posts 
									WHERE postid IN (' . implode(',', $postids) . ')'));
                    foreach ($post_query as $post) {
                        // save postids as index in array $posts with the $post content
                        $posts[(string) $post['postid']] = $post;
                    }
                }
                // List all events
                $notifyBoxEvents = '<div id="nfyWrap" class="nfyWrap">
						<div class="nfyTop">' . qa_lang('q2apro_onsitenotifications_lang/my_notifications') . ' <a id="nfyReadClose">' . qa_lang('q2apro_onsitenotifications_lang/close') . ' | × |</a> </div>
						<div class="nfyContainer">
							<div id="nfyContainerInbox">
						';
                // BIG FOREACH
                foreach ($events as $postid_string => $event) {
                    // $postid_string, e.g. 32_1 (32 is postid, 1 is global event count)
                    $type = $event['event'];
                    if ($type == 'u_message') {
                        $eventName = qa_lang('q2apro_onsitenotifications_lang/you_received') . ' ';
                        $itemIcon = '<div class="nicon nmessage"></div>';
                        $activity_url = qa_path_absolute('message') . '/' . $event['handle'];
                        $linkTitle = qa_lang('q2apro_onsitenotifications_lang/message_from') . ' ' . $event['handle'];
                    } else {
                        if ($type == 'u_wall_post') {
                            $eventName = qa_lang('q2apro_onsitenotifications_lang/you_received') . ' ';
                            $itemIcon = '<div class="nicon nwallpost"></div>';
                            // create link to own wall, needs handle
                            require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
                            $userhandle = qa_post_userid_to_handle($userid);
                            // from v1.7 require_once QA_INCLUDE_DIR.'qa-app-users.php'; and qa_userid_to_handle($userid);
                            $activity_url = qa_path_absolute('user') . '/' . $userhandle . '/wall';
                            $linkTitle = qa_lang('q2apro_onsitenotifications_lang/wallpost_from') . ' ' . $event['handle'];
                        } else {
                            // a_post, c_post, q_vote_up, a_vote_up, q_vote_down, a_vote_down
                            $postid = preg_replace('/_.*/', '', $postid_string);
                            $post = null;
                            // assign post content (postid,type,parentid,title) if available
                            $post = @$posts[$postid];
                            $params = array();
                            // explode string to array with values (memo: leave "\t", '\t' will cause errors)
                            $paramsa = explode("\t", $event['params']);
                            foreach ($paramsa as $param) {
                                $parama = explode('=', $param);
                                if (isset($parama[1])) {
                                    $params[$parama[0]] = $parama[1];
                                } else {
                                    $params[$param] = $param;
                                }
                            }
                            $link = '';
                            $linkTitle = '';
                            $activity_url = '';
                            // comment or answer
                            if (isset($post) && strpos($event['event'], 'q_') !== 0 && strpos($event['event'], 'in_q_') !== 0) {
                                if (!isset($params['parentid'])) {
                                    $params['parentid'] = $post['parentid'];
                                }
                                $parent = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $params['parentid']));
                                if ($parent['type'] == 'A') {
                                    $parent = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $parent['parentid']));
                                }
                                $anchor = qa_anchor(strpos($event['event'], 'a_') === 0 || strpos($event['event'], 'in_a_') === 0 ? 'A' : 'C', $params['postid']);
                                $activity_url = qa_path_absolute(qa_q_request($parent['postid'], $parent['title']), null, $anchor);
                                $linkTitle = $parent['title'];
                                $link = '<a target="_blank" href="' . $activity_url . '">' . $parent['title'] . '</a>';
                            } else {
                                if (isset($post)) {
                                    // question
                                    if (!isset($params['title'])) {
                                        $params['title'] = $posts[$params['postid']]['title'];
                                    }
                                    if ($params['title'] !== null) {
                                        $qTitle = qa_db_read_one_value(qa_db_query_sub("SELECT title FROM `^posts` WHERE `postid` = " . $params['postid'] . " LIMIT 1"), true);
                                        if (!isset($qTitle)) {
                                            $qTitle = '';
                                        }
                                        $activity_url = qa_path_absolute(qa_q_request($params['postid'], $qTitle), null, null);
                                        $linkTitle = $qTitle;
                                        $link = '<a target="_blank" href="' . $activity_url . '">' . $qTitle . '</a>';
                                    }
                                }
                            }
                            // event name
                            $eventName = '';
                            $itemIcon = '';
                            if ($type == 'in_c_question' || $type == 'in_c_answer' || $type == 'in_c_comment') {
                                // added in_c_comment
                                $eventName = qa_lang('q2apro_onsitenotifications_lang/in_comment');
                                $itemIcon = '<div class="nicon ncomment"></div>';
                            } else {
                                if ($type == 'in_q_vote_up' || $type == 'in_a_vote_up') {
                                    $eventName = qa_lang('q2apro_onsitenotifications_lang/in_upvote');
                                    $itemIcon = '<div class="nicon nvoteup"></div>';
                                } else {
                                    if ($type == 'in_q_vote_down' || $type == 'in_a_vote_down') {
                                        $eventName = qa_lang('q2apro_onsitenotifications_lang/in_downvote');
                                        $itemIcon = '<div class="nicon nvotedown"></div>';
                                    } else {
                                        if ($type == 'in_a_question') {
                                            $eventName = qa_lang('q2apro_onsitenotifications_lang/in_answer');
                                            $itemIcon = '<div class="nicon nanswer"></div>';
                                        } else {
                                            if ($type == 'in_a_select') {
                                                $eventName = qa_lang('q2apro_onsitenotifications_lang/in_bestanswer');
                                                $itemIcon = '<div class="nicon nbestanswer"></div>';
                                            } else {
                                                // ignore other events such as in_c_flag
                                                continue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // end a_post, c_post, q_vote_up, a_vote_up, q_vote_down, a_vote_down
                    $eventtime = $event['datetime'];
                    $whenhtml = qa_html(qa_time_to_string(qa_opt('db_time') - $eventtime));
                    $when = qa_lang_html_sub('main/x_ago', $whenhtml);
                    // extra CSS for highlighting new events
                    $cssNewEv = '';
                    if ($eventtime > $last_visit) {
                        $cssNewEv = '-new';
                    }
                    // if post has been deleted there is no link, dont output
                    if ($activity_url == '') {
                        continue;
                    } else {
                        $notifyBoxEvents .= '<div class="itemBox' . $cssNewEv . '">
								' . $itemIcon . '
								<div class="nfyItemLine">
									<p class="nfyWhat">' . $eventName . ' 
										<a ' . ($type == 'u_message' || $type == 'u_wall_post' ? 'title="' . $event['message'] . '" ' : '') . 'href="' . $activity_url . '"' . (qa_opt('q2apro_onsitenotifications_newwindow') ? ' target="_blank"' : '') . '>' . $linkTitle . '</a>
									</p>
									<p class="nfyTime">' . $when . '</p>
								</div>
							</div>';
                    }
                }
                // END FOREACH
                $notifyBoxEvents .= '</div>
						</div>
						<div class="nfyFooter">
							<a href="http://www.q2apro.com/">by q2apro.com</a>
						</div>
					</div>
					';
                header('Access-Control-Allow-Origin: ' . qa_path(null));
                echo $notifyBoxEvents;
                // update database entry so that all user notifications are seen as read
                qa_db_query_sub('INSERT INTO ^usermeta (user_id,meta_key,meta_value) VALUES(#,$,NOW()) ON DUPLICATE KEY UPDATE meta_value=NOW()', $userid, 'visited_profile');
                exit;
            } else {
                echo 'Unexpected problem detected! No userid, no transfer string.';
                exit;
            }
        }
        /* start */
        $qa_content = qa_content_prepare();
        $qa_content['title'] = '';
        // page title
        // return if not admin!
        if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
            $qa_content['error'] = '<p>Access denied</p>';
            return $qa_content;
        } else {
            $qa_content['custom'] = '<p>Hi Admin, it actually makes no sense to call the Ajax URL directly.</p>';
        }
        return $qa_content;
    }
Example #6
0
function qa_flag_set_tohide($post, $userid, $handle, $cookieid, $question)
{
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    qa_db_userflag_set($post['postid'], $userid, true);
    qa_db_post_recount_flags($post['postid']);
    switch ($post['basetype']) {
        case 'Q':
            $action = 'q_flag';
            break;
        case 'A':
            $action = 'a_flag';
            break;
        case 'C':
            $action = 'c_flag';
            break;
    }
    qa_report_write_action($userid, null, $action, $post['basetype'] == 'Q' ? $post['postid'] : null, $post['basetype'] == 'A' ? $post['postid'] : null, $post['basetype'] == 'C' ? $post['postid'] : null);
    qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid']));
    $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $post['postid']));
    $flagcount = $post['flagcount'];
    $notifycount = $flagcount - qa_opt('flagging_notify_first');
    if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        require_once QA_INCLUDE_DIR . 'qa-app-format.php';
        $anchor = $post['basetype'] == 'Q' ? null : qa_anchor($post['basetype'], $post['postid']);
        qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($post['handle']) ? $post['handle'] : qa_lang('main/anonymous'), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$post['title'] . "\n\n" . qa_viewer_text($post['content'], $post['format'])), '^url' => qa_path(qa_q_request($question['postid'], $question['title']), null, qa_opt('site_url'), null, $anchor)));
    }
    if ($flagcount >= qa_opt('flagging_hide_after') && !$post['hidden']) {
        return true;
    }
    return false;
}
Example #7
0
function qa_q_path($questionid, $title, $absolute = false, $showtype = null, $showid = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (($showtype == 'Q' || $showtype == 'A' || $showtype == 'C') && isset($showid)) {
        $params = array('show' => $showid);
        // due to pagination
        $anchor = qa_anchor($showtype, $showid);
    } else {
        $params = null;
        $anchor = null;
    }
    return qa_path(qa_q_request($questionid, $title), $params, $absolute ? qa_opt('site_url') : null, null, $anchor);
}
Example #8
0
function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $options = array())
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'app/updates.php';
    if (isset($options['blockwordspreg'])) {
        require_once QA_INCLUDE_DIR . 'util/string.php';
    }
    $fields = array('raw' => $post);
    //	Useful stuff used throughout function
    $postid = $post['postid'];
    $isquestion = $post['basetype'] == 'Q';
    $isanswer = $post['basetype'] == 'A';
    $isbyuser = qa_post_is_by_user($post, $userid, $cookieid);
    $anchor = urlencode(qa_anchor($post['basetype'], $postid));
    $elementid = isset($options['elementid']) ? $options['elementid'] : $anchor;
    $microformats = @$options['microformats'];
    $isselected = @$options['isselected'];
    $favoritedview = @$options['favoritedview'];
    $favoritemap = $favoritedview ? qa_get_favorite_non_qs_map() : array();
    //	High level information
    $fields['hidden'] = @$post['hidden'];
    $fields['tags'] = 'id="' . qa_html($elementid) . '"';
    $fields['classes'] = $isquestion && $favoritedview && @$post['userfavoriteq'] ? 'qa-q-favorited' : '';
    if ($isquestion && isset($post['closedbyid'])) {
        $fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed');
    }
    if ($microformats) {
        $fields['classes'] .= ' hentry ' . ($isquestion ? 'question' : ($isanswer ? $isselected ? 'answer answer-selected' : 'answer' : 'comment'));
    }
    //	Question-specific stuff (title, URL, tags, answer count, category)
    if ($isquestion) {
        if (isset($post['title'])) {
            $fields['url'] = qa_q_path_html($postid, $post['title']);
            if (isset($options['blockwordspreg'])) {
                $post['title'] = qa_block_words_replace($post['title'], $options['blockwordspreg']);
            }
            $fields['title'] = qa_html($post['title']);
            if ($microformats) {
                $fields['title'] = '<span class="entry-title">' . $fields['title'] . '</span>';
            }
            /*if (isset($post['score'])) // useful for setting match thresholds
            		$fields['title'].=' <small>('.$post['score'].')</small>';*/
        }
        if (@$options['tagsview'] && isset($post['tags'])) {
            $fields['q_tags'] = array();
            $tags = qa_tagstring_to_tags($post['tags']);
            foreach ($tags as $tag) {
                if (isset($options['blockwordspreg']) && count(qa_block_words_match_all($tag, $options['blockwordspreg']))) {
                    // skip censored tags
                    continue;
                }
                $fields['q_tags'][] = qa_tag_html($tag, $microformats, @$favoritemap['tag'][qa_strtolower($tag)]);
            }
        }
        if (@$options['answersview'] && isset($post['acount'])) {
            $fields['answers_raw'] = $post['acount'];
            $fields['answers'] = $post['acount'] == 1 ? qa_lang_html_sub_split('main/1_answer', '1', '1') : qa_lang_html_sub_split('main/x_answers', number_format($post['acount']));
            $fields['answer_selected'] = isset($post['selchildid']);
        }
        if (@$options['viewsview'] && isset($post['views'])) {
            $fields['views_raw'] = $post['views'];
            $fields['views'] = $post['views'] == 1 ? qa_lang_html_sub_split('main/1_view', '1', '1') : qa_lang_html_sub_split('main/x_views', number_format($post['views']));
        }
        if (@$options['categoryview'] && isset($post['categoryname']) && isset($post['categorybackpath'])) {
            $favoriteclass = '';
            if (count(@$favoritemap['category'])) {
                if (@$favoritemap['category'][$post['categorybackpath']]) {
                    $favoriteclass = ' qa-cat-favorited';
                } else {
                    foreach ($favoritemap['category'] as $categorybackpath => $dummy) {
                        if (substr('/' . $post['categorybackpath'], -strlen($categorybackpath)) == $categorybackpath) {
                            $favoriteclass = ' qa-cat-parent-favorited';
                        }
                    }
                }
            }
            $fields['where'] = qa_lang_html_sub_split('main/in_category_x', '<a href="' . qa_path_html(@$options['categorypathprefix'] . implode('/', array_reverse(explode('/', $post['categorybackpath'])))) . '" class="qa-category-link' . $favoriteclass . '">' . qa_html($post['categoryname']) . '</a>');
        }
    }
    //	Answer-specific stuff (selection)
    if ($isanswer) {
        $fields['selected'] = $isselected;
        if ($isselected) {
            $fields['select_text'] = qa_lang_html('question/select_text');
        }
    }
    //	Post content
    if (@$options['contentview'] && isset($post['content'])) {
        $viewer = qa_load_viewer($post['content'], $post['format']);
        $fields['content'] = $viewer->get_html($post['content'], $post['format'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
        if ($microformats) {
            $fields['content'] = '<div class="entry-content">' . $fields['content'] . '</div>';
        }
        $fields['content'] = '<a name="' . qa_html($postid) . '"></a>' . $fields['content'];
        // this is for backwards compatibility with any existing links using the old style of anchor
        // that contained the post id only (changed to be valid under W3C specifications)
    }
    //	Voting stuff
    if (@$options['voteview']) {
        $voteview = $options['voteview'];
        //	Calculate raw values and pass through
        if (@$options['ovoteview'] && isset($post['opostid'])) {
            $upvotes = (int) @$post['oupvotes'];
            $downvotes = (int) @$post['odownvotes'];
            $fields['vote_opostid'] = true;
            // for voters/flaggers layer
        } else {
            $upvotes = (int) @$post['upvotes'];
            $downvotes = (int) @$post['downvotes'];
        }
        $netvotes = (int) ($upvotes - $downvotes);
        $fields['upvotes_raw'] = $upvotes;
        $fields['downvotes_raw'] = $downvotes;
        $fields['netvotes_raw'] = $netvotes;
        //	Create HTML versions...
        $upvoteshtml = qa_html($upvotes);
        $downvoteshtml = qa_html($downvotes);
        if ($netvotes >= 1) {
            $netvoteshtml = '+' . qa_html($netvotes);
        } elseif ($netvotes <= -1) {
            $netvoteshtml = '&ndash;' . qa_html(-$netvotes);
        } else {
            $netvoteshtml = '0';
        }
        //	...with microformats if appropriate
        if ($microformats) {
            $netvoteshtml .= '<span class="votes-up"><span class="value-title" title="' . $upvoteshtml . '"></span></span>' . '<span class="votes-down"><span class="value-title" title="' . $downvoteshtml . '"></span></span>';
            $upvoteshtml = '<span class="votes-up">' . $upvoteshtml . '</span>';
            $downvoteshtml = '<span class="votes-down">' . $downvoteshtml . '</span>';
        }
        //	Pass information on vote viewing
        //	$voteview will be one of:
        //	updown, updown-disabled-page, updown-disabled-level, updown-uponly-level, updown-disabled-approve, updown-uponly-approve
        //	net, net-disabled-page, net-disabled-level, net-uponly-level, net-disabled-approve, net-uponly-approve
        $fields['vote_view'] = substr($voteview, 0, 6) == 'updown' ? 'updown' : 'net';
        $fields['vote_on_page'] = strpos($voteview, '-disabled-page') ? 'disabled' : 'enabled';
        $fields['upvotes_view'] = $upvotes == 1 ? qa_lang_html_sub_split('main/1_liked', $upvoteshtml, '1') : qa_lang_html_sub_split('main/x_liked', $upvoteshtml);
        $fields['downvotes_view'] = $downvotes == 1 ? qa_lang_html_sub_split('main/1_disliked', $downvoteshtml, '1') : qa_lang_html_sub_split('main/x_disliked', $downvoteshtml);
        $fields['netvotes_view'] = abs($netvotes) == 1 ? qa_lang_html_sub_split('main/1_vote', $netvoteshtml, '1') : qa_lang_html_sub_split('main/x_votes', $netvoteshtml);
        //	Voting buttons
        $fields['vote_tags'] = 'id="voting_' . qa_html($postid) . '"';
        $onclick = 'onclick="return qa_vote_click(this);"';
        if ($fields['hidden']) {
            $fields['vote_state'] = 'disabled';
            $fields['vote_up_tags'] = 'title="' . qa_lang_html($isanswer ? 'main/vote_disabled_hidden_a' : 'main/vote_disabled_hidden_q') . '"';
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif ($isbyuser) {
            $fields['vote_state'] = 'disabled';
            $fields['vote_up_tags'] = 'title="' . qa_lang_html($isanswer ? 'main/vote_disabled_my_a' : 'main/vote_disabled_my_q') . '"';
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif (strpos($voteview, '-disabled-')) {
            $fields['vote_state'] = @$post['uservote'] > 0 ? 'voted_up_disabled' : (@$post['uservote'] < 0 ? 'voted_down_disabled' : 'disabled');
            if (strpos($voteview, '-disabled-page')) {
                $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_disabled_q_page_only') . '"';
            } elseif (strpos($voteview, '-disabled-approve')) {
                $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_disabled_approve') . '"';
            } else {
                $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_disabled_level') . '"';
            }
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif (@$post['uservote'] > 0) {
            $fields['vote_state'] = 'voted_up';
            $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/voted_up_popup') . '" name="' . qa_html('vote_' . $postid . '_0_' . $elementid) . '" ' . $onclick;
            $fields['vote_down_tags'] = ' ';
        } elseif (@$post['uservote'] < 0) {
            $fields['vote_state'] = 'voted_down';
            $fields['vote_up_tags'] = ' ';
            $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/voted_down_popup') . '" name="' . qa_html('vote_' . $postid . '_0_' . $elementid) . '" ' . $onclick;
        } else {
            $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_up_popup') . '" name="' . qa_html('vote_' . $postid . '_1_' . $elementid) . '" ' . $onclick;
            if (strpos($voteview, '-uponly-level')) {
                $fields['vote_state'] = 'up_only';
                $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_disabled_down') . '"';
            } elseif (strpos($voteview, '-uponly-approve')) {
                $fields['vote_state'] = 'up_only';
                $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_disabled_down_approve') . '"';
            } else {
                $fields['vote_state'] = 'enabled';
                $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_down_popup') . '" name="' . qa_html('vote_' . $postid . '_-1_' . $elementid) . '" ' . $onclick;
            }
        }
    }
    //	Flag count
    if (@$options['flagsview'] && @$post['flagcount']) {
        $fields['flags'] = $post['flagcount'] == 1 ? qa_lang_html_sub_split('main/1_flag', '1', '1') : qa_lang_html_sub_split('main/x_flags', $post['flagcount']);
    }
    //	Created when and by whom
    $fields['meta_order'] = qa_lang_html('main/meta_order');
    // sets ordering of meta elements which can be language-specific
    if (@$options['whatview']) {
        $fields['what'] = qa_lang_html($isquestion ? 'main/asked' : ($isanswer ? 'main/answered' : 'main/commented'));
        if (@$options['whatlink'] && strlen(@$options['q_request'])) {
            $fields['what_url'] = $post['basetype'] == 'Q' ? qa_path_html($options['q_request']) : qa_path_html($options['q_request'], array('show' => $postid), null, null, qa_anchor($post['basetype'], $postid));
        }
    }
    if (isset($post['created']) && @$options['whenview']) {
        $fields['when'] = qa_when_to_html($post['created'], @$options['fulldatedays']);
        if ($microformats) {
            $fields['when']['data'] = '<span class="published"><span class="value-title" title="' . gmdate('Y-m-d\\TH:i:sO', $post['created']) . '">' . $fields['when']['data'] . '</span></span>';
        }
    }
    if (@$options['whoview']) {
        $fields['who'] = qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? @$post['createip'] : null, $microformats, $post['name']);
        if (isset($post['points'])) {
            if (@$options['pointsview']) {
                $fields['who']['points'] = $post['points'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($post['points'])));
            }
            if (isset($options['pointstitle'])) {
                $fields['who']['title'] = qa_get_points_title_html($post['points'], $options['pointstitle']);
            }
        }
        if (isset($post['level'])) {
            $fields['who']['level'] = qa_html(qa_user_level_string($post['level']));
        }
    }
    if (@$options['avatarsize'] > 0) {
        if (QA_FINAL_EXTERNAL_USERS) {
            $fields['avatar'] = qa_get_external_avatar_html($post['userid'], $options['avatarsize'], false);
        } else {
            $fields['avatar'] = qa_get_user_avatar_html(@$post['flags'], @$post['email'], @$post['handle'], @$post['avatarblobid'], @$post['avatarwidth'], @$post['avatarheight'], $options['avatarsize']);
        }
    }
    //	Updated when and by whom
    if (@$options['updateview'] && isset($post['updated']) && ($post['updatetype'] != QA_UPDATE_SELECTED || $isselected) && (!isset($post['created']) || $post['hidden'] && $post['updatetype'] == QA_UPDATE_VISIBLE || isset($post['closedbyid']) && $post['updatetype'] == QA_UPDATE_CLOSED || abs($post['updated'] - $post['created']) > 300 || $post['lastuserid'] != $post['userid'])) {
        switch ($post['updatetype']) {
            case QA_UPDATE_TYPE:
            case QA_UPDATE_PARENT:
                $langstring = 'main/moved';
                break;
            case QA_UPDATE_CATEGORY:
                $langstring = 'main/recategorized';
                break;
            case QA_UPDATE_VISIBLE:
                $langstring = $post['hidden'] ? 'main/hidden' : 'main/reshown';
                break;
            case QA_UPDATE_CLOSED:
                $langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened';
                break;
            case QA_UPDATE_TAGS:
                $langstring = 'main/retagged';
                break;
            case QA_UPDATE_SELECTED:
                $langstring = 'main/selected';
                break;
            default:
                $langstring = 'main/edited';
                break;
        }
        $fields['what_2'] = qa_lang_html($langstring);
        if (@$options['whenview']) {
            $fields['when_2'] = qa_when_to_html($post['updated'], @$options['fulldatedays']);
            if ($microformats) {
                $fields['when_2']['data'] = '<span class="updated"><span class="value-title" title="' . gmdate('Y-m-d\\TH:i:sO', $post['updated']) . '">' . $fields['when_2']['data'] . '</span></span>';
            }
        }
        if (isset($post['lastuserid']) && @$options['whoview']) {
            $fields['who_2'] = qa_who_to_html(isset($userid) && $post['lastuserid'] == $userid, $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false);
        }
    } elseif ($microformats && @$options['whenview']) {
        // quick fix for incorrect microformats (missing 'updated' class)
        $fields['when']['data'] = str_replace('<span class="published">', '<span class="published updated">', $fields['when']['data']);
    }
    //	That's it!
    return $fields;
}
Example #9
0
function qa_badge_plugin_user_form($userid)
{
    $handles = qa_userids_to_handles(array($userid));
    $handle = $handles[$userid];
    // displays badge list in user profile
    $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT badge_slug as slug, object_id AS oid FROM ^userbadges WHERE user_id=#', $userid));
    $fields = array();
    if (count($result) > 0) {
        // count badges
        $bin = qa_get_badge_list();
        $badges = array();
        foreach ($result as $info) {
            $slug = $info['slug'];
            $type = $bin[$slug]['type'];
            if (isset($badges[$type][$slug])) {
                $badges[$type][$slug]['count']++;
            } else {
                $badges[$type][$slug]['count'] = 1;
            }
            if ($info['oid']) {
                $badges[$type][$slug]['oid'][] = $info['oid'];
            }
        }
        foreach ($badges as $type => $badge) {
            $typea = qa_get_badge_type($type);
            $types = $typea['slug'];
            $typed = $typea['name'];
            $output = '
							<table>
								<tr>
									<td class="qa-form-wide-label">
										<h3 class="badge-title" title="' . qa_lang('badges/' . $types . '_desc') . '">' . $typed . '</h3>
									</td>
								</tr>';
            foreach ($badge as $slug => $info) {
                $badge_name = qa_lang('badges/' . $slug);
                if (!qa_opt('badge_' . $slug . '_name')) {
                    qa_opt('badge_' . $slug . '_name', $badge_name);
                }
                $name = qa_opt('badge_' . $slug . '_name');
                $count = $info['count'];
                if (qa_opt('badge_show_source_posts')) {
                    $oids = @$info['oid'];
                } else {
                    $oids = null;
                }
                $var = qa_opt('badge_' . $slug . '_var');
                $desc = qa_badge_desc_replace($slug, $var, $name);
                // badge row
                $output .= '
								<tr>
									<td class="badge-container">
										<div class="badge-container-badge">
											<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span>&nbsp;<span onclick="jQuery(\'.badge-container-sources-' . $slug . '\').slideToggle()" class="badge-count' . (is_array($oids) ? ' badge-count-link" title="' . qa_lang('badges/badge_count_click') : '') . '">x&nbsp;' . $count . '</span>
										</div>';
                // source row(s) if any
                if (is_array($oids)) {
                    $output .= '
										<div class="badge-container-sources-' . $slug . '" style="display:none">';
                    foreach ($oids as $oid) {
                        $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $oid));
                        $title = $post['title'];
                        $anchor = '';
                        if ($post['parentid']) {
                            $anchor = urlencode(qa_anchor($post['type'], $oid));
                            $oid = $post['parentid'];
                            $title = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY title as title FROM ^posts WHERE postid=#', $oid), true);
                        }
                        $length = 30;
                        $text = qa_strlen($title) > $length ? qa_substr($title, 0, $length) . '...' : $title;
                        $output .= '
											<div class="badge-source"><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></div>';
                    }
                }
                $output .= '
									</td>
								</tr>';
            }
            $output .= '
							</table>';
            $outa[] = $output;
        }
        $fields[] = array('value' => '<table class="badge-user-tables"><tr><td class="badge-user-table">' . implode('</td><td class="badge-user-table">', $outa) . '</td></tr></table>', 'type' => 'static');
    }
    $ok = null;
    $tags = null;
    $buttons = array();
    if ((bool) qa_opt('badge_email_notify') && qa_get_logged_in_handle() == $handle) {
        // add badge notify checkbox
        if (qa_clicked('badge_email_notify_save')) {
            qa_opt('badge_email_notify_id_' . $userid, (bool) qa_post_text('badge_notify_email_me'));
            $ok = qa_lang('badges/badge_notified_email_me');
        }
        $select = (bool) qa_opt('badge_email_notify_id_' . $userid);
        $tags = 'id="badge-form" action="' . qa_self_html() . '#signature_text" method="POST"';
        $fields[] = array('type' => 'blank');
        $fields[] = array('label' => qa_lang('badges/badge_notify_email_me'), 'type' => 'checkbox', 'tags' => 'NAME="badge_notify_email_me"', 'value' => $select);
        $buttons[] = array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="badge_email_notify_save"');
    }
    return array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'tall', 'tags' => $tags, 'title' => qa_lang('badges/badges'), 'fields' => $fields, 'buttons' => $buttons);
}
Example #10
0
 function list_vote_buttons($post)
 {
     $onclick = 'onclick="return qa_vote_click(this);"';
     $anchor = urlencode(qa_anchor($post['raw']['type'], $post['raw']['postid']));
     //v($post['vote_up_tags']);
     //v($post['vote_down_tags']);
     if ($post['vote_up_tags'] == ' ') {
         $post['vote_up_tags'] = 'title="' . qa_lang_html('main/voted_up_popup') . '" name="' . qa_html('vote_' . $post['raw']['postid'] . '_0_' . $anchor) . '" ' . $onclick;
     }
     if ($post['vote_down_tags'] == ' ') {
         $post['vote_down_tags'] = 'title="' . qa_lang_html('main/voted_down_popup') . '" name="' . qa_html('vote_' . $post['raw']['postid'] . '_0_' . $anchor) . '" ' . $onclick;
     }
     switch (@$post['vote_state']) {
         case 'voted_up':
             $this->post_hover_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-one-button qa-voted-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_hover_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-one-button qa-vote-down');
             break;
         case 'voted_up_disabled':
             $this->post_disabled_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-one-button qa-vote-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_hover_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-one-button qa-voted-down');
             break;
         case 'voted_down':
             $this->post_hover_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-one-button qa-vote-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_hover_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-one-button qa-voted-down');
             break;
         case 'voted_down_disabled':
             $this->post_hover_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-one-button qa-voted-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_disabled_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-one-button qa-vote-down');
             break;
         case 'up_only':
             $this->post_hover_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-first-button qa-vote-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_disabled_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-second-button qa-vote-down');
             break;
         case 'enabled':
             $this->post_hover_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-first-button qa-vote-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_hover_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-second-button qa-vote-down');
             break;
         default:
             $this->post_disabled_button($post, 'vote_up_tags', '&#xf087;', 'fa btn btn-success qa-item-vote-first-button qa-vote-up');
             $this->output('<div class="qa-list-vote-count">' . $post['netvotes_view']['data'] . '</div>');
             $this->post_disabled_button($post, 'vote_down_tags', '&#xf088;', 'fa btn btn-danger qa-item-vote-second-button qa-vote-down');
             break;
     }
 }
Example #11
0
    function activitylist()
    {
        // get points for each activity
        require_once QA_INCLUDE_DIR . 'qa-db-points.php';
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        $optionnames = qa_db_points_option_names();
        $options = qa_get_options($optionnames);
        $multi = (int) $options['points_multiple'];
        $upvote = '';
        $downvote = '';
        if (@$options['points_per_q_voted_up']) {
            $upvote = '_up';
            $downvote = '_down';
        }
        $event_point['in_q_vote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi;
        $event_point['in_q_vote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi * -1;
        $event_point['in_q_unvote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi * -1;
        $event_point['in_q_unvote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi;
        $event_point['in_a_vote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi;
        $event_point['in_a_vote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi * -1;
        $event_point['in_a_unvote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi * -1;
        $event_point['in_a_unvote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi;
        $event_point['in_a_select'] = (int) $options['points_a_selected'] * $multi;
        $event_point['in_a_unselect'] = (int) $options['points_a_selected'] * $multi * -1;
        $event_point['q_post'] = (int) $options['points_post_q'] * $multi;
        $event_point['a_post'] = (int) $options['points_post_a'] * $multi;
        $event_point['a_select'] = (int) $options['points_select_a'] * $multi;
        $event_point['q_vote_up'] = (int) $options['points_vote_up_q'] * $multi;
        $event_point['q_vote_down'] = (int) $options['points_vote_down_q'] * $multi;
        $event_point['a_vote_up'] = (int) $options['points_vote_up_a'] * $multi;
        $event_point['a_vote_down'] = (int) $options['points_vote_down_a'] * $multi;
        /*
        // Exclude Activities
        $exclude = array(
        	'u_login',
        	'u_logout',
        	'u_password',
        	'u_reset',
        	'u_save',
        	'u_edit',
        	'u_block',
        	'u_unblock',
        	'feedback',
        	'search',
        	'badge_awarded',
        );
        $excludes = "'".implode("','",$exclude)."'";
        $eventslist = qa_db_read_all_assoc(
        	qa_db_query_sub( 
        		'SELECT UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params FROM ^userlog WHERE userid=# AND 
        		DATE_SUB(CURDATE(),INTERVAL # DAY) <= datetime
        		AND event NOT IN (' . $excludes .') ORDER BY datetime DESC'.(qa_opt('qat_activity_number')?' LIMIT '.(int)qa_opt('qat_activity_number'):''),
        		$userid, qa_opt('qat_activity_age')
        	)
        );
        */
        // Get Events
        $userid = qa_get_logged_in_userid();
        $eventslist = qa_db_read_all_assoc(qa_db_query_sub('SELECT UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params FROM ^userlog WHERE effecteduserid=# AND 
				DATE_SUB(CURDATE(),INTERVAL # DAY) <= datetime
				ORDER BY datetime DESC' . (qa_opt('qat_activity_number') ? ' LIMIT ' . (int) qa_opt('qat_activity_number') : ''), $userid, qa_opt('qat_activity_age')));
        $event = array();
        $output = '';
        $i = 0;
        //
        $userids = array();
        foreach ($eventslist as $event) {
            $userids[$event['userid']] = $event['userid'];
            $userids[$event['effecteduserid']] = $event['effecteduserid'];
        }
        $handles = qa_db_user_get_userid_handles($userids);
        // get event's: time, type, parameters
        // get post id of questions
        foreach ($eventslist as $event) {
            $title = '';
            $link = '';
            $vote_status = '';
            $handle = $handles[$event['userid']];
            $user_link = qa_path('user/' . $handle);
            $datetime = $event['datetime'];
            $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
            $event['params'] = json_decode($event['params'], true);
            $output .= '<li>';
            switch ($event['event']) {
                case 'related':
                    // related question to an answer
                    $url = qa_path_html(qa_q_request($event['postid'], $event['params']['title']), null, qa_opt('site_url'), null, null);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title"><strong class="avatar"><a href="' . $user_link . '">' . $handle . '</a></strong>
									<span class="what">Asked a question related to your answer</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['title'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'a_post':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title"><strong class="avatar"><a href="' . $user_link . '">' . $handle . '</a></strong>
									<span class="what">Answered</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'c_post':
                    // user's question had been commented
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title"><strong class="avatar"><a href="' . $user_link . '">' . $handle . '</a></strong>
									<span class="what">Commented</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'q_reshow':
                    // user's question had been answered
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, null);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">your question had been accepted</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'a_reshow':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">your answer had been made visible</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'c_reshow':
                    // user's question had been answered
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">your comment had been accepted</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'a_select':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title"><strong class="avatar"><a href="' . $user_link . '">' . $handle . '</a></strong>
										<span class="what">selected your answer</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'in_q_vote':
                    // user's question had been answered
                    $anchor = qa_anchor('Q', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    if ($event['params']['q_vote_up']) {
                        $vote_status .= '<span>' . $event['params']['q_vote_up'] . ' upvotes</span>';
                    }
                    if ($event['params']['q_vote_down']) {
                        if (isset($vote_status)) {
                            $vote_status .= ' - ';
                        }
                        $vote_status .= '<span>' . $event['params']['q_vote_down'] . ' downvotes</span>';
                    }
                    if ($event['params']['favorite'] && $event['params']['favorite'] >= 1) {
                        if (isset($vote_status)) {
                            $vote_status .= ' - ';
                        }
                        $vote_status .= '<span>' . $event['params']['favorite'] . ' favourites</span>';
                    }
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">your question received new votes: ' . $vote_status . '</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'in_a_vote':
                    // user's question had been answered
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    if ($event['params']['a_vote_up']) {
                        $vote_status = '<span>' . $event['params']['a_vote_up'] . ' upvotes</span>';
                    }
                    if ($event['params']['a_vote_down']) {
                        if (isset($vote_status)) {
                            $vote_status .= ' - ';
                        }
                        $vote_status .= '<span>' . $event['params']['a_vote_down'] . ' downvotes</span>';
                    }
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">your answer received new votes: ' . $vote_status . '</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'q_approve':
                    $anchor = qa_anchor('Q', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
									<span class="what">your question was approved</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'a_approve':
                    $anchor = qa_anchor('A', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
									<span class="what">your answer was approved</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'c_approve':
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
									<span class="what">your comment was approved</span>
									</p>
									<a class="title" href="' . $url . '">' . $event['params']['qtitle'] . '</a>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'q_reject':
                    $anchor = qa_anchor('C', $event['postid']);
                    $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), null, qa_opt('site_url'), null, $anchor);
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
									<span class="what">your question was rejected</span>
									</p>
									<span class="title">' . $event['params']['qtitle'] . '</span>
									<span class="date"> ' . $event['date'] . '</span>
								</div>';
                    break;
                case 'a_reject':
                case 'c_reject':
                    break;
                case 'u_level':
                    $output .= '<div class="event-icon pull-left icon-chat"></div>
								<div class="event-content">
									<p class="title">
										<span class="what">You level had been changed from' . qa_html(qa_user_level_string($event['params']['oldlevel'])) . ' to ' . qa_html(qa_user_level_string($event['params']['level'])) . '</span>
									</p>
								</div>';
                    break;
                case 'a_post':
                    break;
            }
        }
        $output .= '</li>';
        return $output;
    }
function qa_news_plugin_createNewsletter($send)
{
    $news = qa_opt('news_plugin_template');
    // static replacements
    $news = str_replace('[css]', qa_opt('news_plugin_css'), $news);
    $lastdate = time() - qa_opt('news_plugin_send_days') * 24 * 60 * 60;
    if (qa_opt('news_plugin_max_q') > 0) {
        $selectspec = "SELECT postid, BINARY title AS title, BINARY content AS content, format, netvotes, userid FROM ^posts WHERE type='Q' AND FROM_UNIXTIME(#) <= created AND netvotes > 0 ORDER BY netvotes DESC, created ASC LIMIT " . (int) qa_opt('news_plugin_max_q');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $qcontent = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $one = str_replace('[question-title]', $post['title'], qa_opt('news_plugin_template_question'));
            $one = str_replace('[anchor]', 'question' . $post['postid'], $one);
            $one = str_replace('[url]', qa_html(qa_q_request($post['postid'], $post['title'])), $one);
            $one = str_replace('[question]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $qhtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_a') > 0) {
        $selectspec = "SELECT a.postid AS postid, a.parentid AS parentid, BINARY a.content AS content, a.format AS format, a.netvotes AS netvotes, a.userid as userid, q.title AS qtitle FROM ^posts AS q, ^posts AS a WHERE a.type='A' AND q.postid=a.parentid AND FROM_UNIXTIME(#) <= a.created AND a.netvotes > 0 ORDER BY a.netvotes DESC, a.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_question', '<a href="' . $purl . '">' . $post['qtitle'] . '</a>');
            $response = str_replace('[url]', $url, $response);
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_answer'));
            $one = str_replace('[anchor]', 'answer' . $post['postid'], $one);
            $one = str_replace('[answer]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $ahtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_c') > 0) {
        $selectspec = "SELECT c.postid AS postid, c.parentid AS parentid, BINARY c.content AS content, c.format AS format, c.netvotes AS netvotes, c.userid as userid, p.title AS ptitle, p.parentid AS gpostid, g.title AS gtitle FROM ^posts AS c INNER JOIN ^posts AS p ON c.type='C' AND p.postid=c.parentid AND FROM_UNIXTIME(#) <= c.created LEFT JOIN ^posts AS g ON g.postid=p.parentid AND g.type='Q' AND c.netvotes > 0 ORDER BY c.netvotes DESC, c.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            if (isset($post['gtitle'])) {
                $parent = 'answer';
                $title = $post['gtitle'];
                $parentid = $post['gpostid'];
                $aurl = qa_path_html(qa_q_request($post['parentid'], $title), null, qa_opt('site_url'), null, qa_anchor('A', $post['parentid']));
            } else {
                $parent = 'question';
                $title = $post['ptitle'];
                $parentid = $post['parentid'];
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_' . $parent, '<a href="' . $purl . '">' . $title . '</a>');
            $response = str_replace('[url]', $url, $response);
            if (isset($aurl)) {
                $response = str_replace('[aurl]', $aurl, $response);
            }
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_comment'));
            $one = str_replace('[anchor]', 'comment' . $post['postid'], $one);
            $one = str_replace('[comment]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $chtml[] = $one;
        }
    }
    $news = str_replace('[questions]', implode('<hr class="inner">', $qhtml), $news);
    $news = str_replace('[answers]', implode('<hr class="inner">', $ahtml), $news);
    $news = str_replace('[comments]', implode('<hr class="inner">', $chtml), $news);
    // misc subs
    $news = str_replace('[intro]', qa_lang('newsletter/intro'), $news);
    $news = str_replace('[footer]', qa_lang('newsletter/footer'), $news);
    $news = str_replace('[site-title]', qa_opt('site_title'), $news);
    $news = str_replace('[site-url]', qa_opt('site_url'), $news);
    $news = str_replace('[last-date]', date('M j, Y', $lastdate), $news);
    $news = str_replace('[date]', date('M j, Y'), $news);
    $news = str_replace('[days]', qa_opt('news_plugin_send_days'), $news);
    $news = str_replace('[profile-url]', qa_path('my-profile'), $news);
    error_log('Q2A Newsletter Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    file_put_contents(qa_opt('news_plugin_loc'), $news);
    if (qa_opt('news_plugin_pdf')) {
        qa_news_plugin_create_pdf();
    }
    if ($send) {
        qa_news_plugin_send_newsletter($news);
        qa_opt('news_plugin_send_last', time());
        return 'Newsletter Sent';
    }
    return 'Newsletter Created';
    //return 'Error creating '.qa_opt('news_plugin_loc').'; check the error log.';
}
Example #13
0
function qa_search_max_match_anchor($question)
{
    $anchorscore = array();
    $matchparts = explode(',', $question['matchparts']);
    foreach ($matchparts as $matchpart) {
        if (sscanf($matchpart, '%1s:%f:%f', $matchposttype, $matchpostid, $matchscore) == 3) {
            @($anchorscore[qa_anchor($matchposttype, $matchpostid)] += $matchscore);
        }
    }
    if (count($anchorscore)) {
        $anchor = array_search(max($anchorscore), $anchorscore);
        if ($anchor != qa_anchor('Q', $question['postid'])) {
            return $anchor;
        }
    }
    return null;
}
Example #14
0
qa_base_db_disconnect();
//	Prepare the XML output
$lines = array();
$lines[] = '<?xml version="1.0" encoding="UTF-8"?>';
$lines[] = '<rss version="2.0">';
$lines[] = '<channel>';
$lines[] = '<title>' . qa_html($sitetitle . ' - ' . $title) . '</title>';
$lines[] = '<link>' . qa_path_html($linkrequest, $linkparams, $siteurl) . '</link>';
$lines[] = '<description>Powered by Question2Answer</description>';
foreach ($questions as $question) {
    //	Determine whether this is a question, answer or comment, and act accordingly
    $options = array('blockwordspreg' => @$blockwordspreg, 'showurllinks' => $showurllinks);
    $anchor = null;
    if (isset($question['opostid'])) {
        if ($question['obasetype'] != 'Q') {
            $anchor = qa_anchor($question['obasetype'], $question['opostid']);
        }
        $time = $question['otime'];
        if ($full) {
            $htmlcontent = qa_viewer_html($question['ocontent'], $question['oformat'], $options);
        }
    } else {
        $time = $question['created'];
        if ($full) {
            $htmlcontent = qa_viewer_html($question['content'], $question['format'], $options);
        }
    }
    switch (@$question['obasetype']) {
        case 'A':
            $titleprefix = @$question['oedited'] ? qa_lang('misc/feed_a_edited_prefix') : qa_lang('misc/feed_a_prefix');
            break;
    function user_activity_form()
    {
        $handle = $this->_user_handle();
        if (!$handle) {
            return;
        }
        $userid = $this->getuserfromhandle($handle);
        if (!$userid) {
            return;
        }
        // update last visit
        if ($userid == qa_get_logged_in_userid() && qa_opt('user_act_list_new')) {
            qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usermeta (
				meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
				user_id bigint(20) unsigned NOT NULL,
				meta_key varchar(255) DEFAULT NULL,
				meta_value longtext,
				PRIMARY KEY (meta_id),
				UNIQUE (user_id,meta_key)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8');
            $last_visit = qa_db_read_one_value(qa_db_query_sub('SELECT UNIX_TIMESTAMP(meta_value) FROM ^usermeta WHERE user_id=# AND meta_key=$', qa_get_logged_in_userid(), 'visited_profile'), true);
            qa_db_query_sub('INSERT INTO ^usermeta (user_id,meta_key,meta_value) VALUES(#,$,NOW()) ON DUPLICATE KEY UPDATE meta_value=NOW()', $userid, 'visited_profile');
        } else {
            $last_visit = time();
        }
        $event_query = qa_db_query_sub("SELECT \n\t\t\t\te.event, \n\t\t\t\tBINARY e.params as params, \n\t\t\t\tUNIX_TIMESTAMP(e.datetime) AS datetime\n\t\t\tFROM \n\t\t\t\t^eventlog AS e\n\t\t\tWHERE\n\t\t\t\te.userid=#\n\t\t\t\tAND\n\t\t\t\tDATE_SUB(CURDATE(),INTERVAL # DAY) <= datetime\n\t\t\tORDER BY datetime DESC" . (qa_opt('user_act_list_max') ? " LIMIT " . (int) qa_opt('user_act_list_max') : ""), $userid, qa_opt('user_act_list_age'));
        // no post
        $nopost = array('u_password', 'u_reset', 'u_save', 'u_confirmed', 'u_edit', 'u_level', 'u_block', 'u_unblock', 'u_register', 'in_u_edit', 'in_u_level', 'in_u_block', 'in_u_unblock', 'feedback', 'search');
        // points
        require_once QA_INCLUDE_DIR . 'qa-db-points.php';
        $optionnames = qa_db_points_option_names();
        $options = qa_get_options($optionnames);
        $multi = (int) $options['points_multiple'];
        // compat fudge
        $upvote = '';
        $downvote = '';
        if (@$options['points_per_q_voted_up']) {
            $upvote = '_up';
            $downvote = '_down';
        }
        $option_events['in_q_vote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi;
        $option_events['in_q_vote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi * -1;
        $option_events['in_q_unvote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi * -1;
        $option_events['in_q_unvote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi;
        $option_events['in_a_vote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi;
        $option_events['in_a_vote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi * -1;
        $option_events['in_a_unvote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi * -1;
        $option_events['in_a_unvote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi;
        $option_events['in_a_select'] = (int) $options['points_a_selected'] * $multi;
        $option_events['in_a_unselect'] = (int) $options['points_a_selected'] * $multi * -1;
        $option_events['q_post'] = (int) $options['points_post_q'] * $multi;
        $option_events['a_post'] = (int) $options['points_post_a'] * $multi;
        $option_events['a_select'] = (int) $options['points_select_a'] * $multi;
        $option_events['q_vote_up'] = (int) $options['points_vote_up_q'] * $multi;
        $option_events['q_vote_down'] = (int) $options['points_vote_down_q'] * $multi;
        $option_events['a_vote_up'] = (int) $options['points_vote_up_a'] * $multi;
        $option_events['a_vote_down'] = (int) $options['points_vote_down_a'] * $multi;
        $fields = array();
        $events = array();
        $postids = array();
        $count = 0;
        while (($event = qa_db_read_one_assoc($event_query, true)) !== null) {
            if (preg_match('/postid=([0-9]+)/', $event['params'], $m) === 1) {
                $event['postid'] = (int) $m[1];
                $postids[] = (int) $m[1];
                $events[$m[1] . '_' . $count++] = $event;
            } else {
                $events['nopost_' . $count++] = $event;
            }
        }
        // get post info, also makes sure post exists
        $posts = null;
        if (!empty($postids)) {
            $post_query = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, type, parentid, BINARY title as title FROM ^posts WHERE postid IN (' . implode(',', $postids) . ')'));
            foreach ($post_query as $post) {
                $posts[(string) $post['postid']] = $post;
            }
        }
        foreach ($events as $postid_string => $event) {
            $type = $event['event'];
            $postid = preg_replace('/_.*/', '', $postid_string);
            $post = null;
            $post = @$posts[$postid];
            // these calls allow you to deal with deleted events;
            // uncomment the first one to skip them
            // uncomment the second one to build your own routine based on whether they are deleted.
            if (!in_array($type, $nopost) && $post == null) {
                continue;
            }
            // $deleted = (!in_array($type, $nopost) && $post == null);
            // hide / show exceptions
            if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
                if ($userid != qa_get_logged_in_userid()) {
                    // show public
                    $types = explode("\n", qa_opt('user_act_list_show'));
                    if (!in_array($type, $types)) {
                        continue;
                    }
                } else {
                    // hide from owner
                    $types = explode("\n", qa_opt('user_act_list_hide'));
                    if (in_array($type, $types)) {
                        continue;
                    }
                }
            }
            if (!qa_opt('user_act_list_' . $type)) {
                continue;
            }
            $params = array();
            $paramsa = explode("\t", $event['params']);
            foreach ($paramsa as $param) {
                $parama = explode('=', $param);
                if (isset($parama[1])) {
                    $params[$parama[0]] = $parama[1];
                } else {
                    $params[$param] = $param;
                }
            }
            $link = '';
            if (in_array($type, $nopost)) {
                if ($type == 'search') {
                    if ((int) $params['start'] != 0) {
                        continue;
                    }
                    $link = '<a href="' . qa_path_html('search', array('q' => $params['query'])) . '">' . qa_html($params['query']) . '</a>';
                } else {
                    if (in_array($type, array('u_edit', 'u_level', 'u_block', 'u_unblock'))) {
                        $ohandle = $this->getHandleFromID($params['userid']);
                        $link = '<a href="' . qa_path_html('user/' . $ohandle, null, qa_opt('site_url')) . '">' . $ohandle . '</a>';
                    } else {
                        $link = '';
                    }
                }
            } else {
                if ($type == 'badge_awarded') {
                    if (!qa_opt('badge_active') || !function_exists('qa_get_badge_type')) {
                        continue;
                    }
                    if ($post != null) {
                        if (strpos($post['type'], 'Q') !== 0) {
                            $anchor = qa_anchor(strpos($post['type'], 'A') === 0 ? 'A' : 'C', $params['postid']);
                            $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT parentid,type,BINARY title as title,postid FROM ^posts WHERE postid=#', $post['parentid']), true);
                            if ($parent['type'] == 'A') {
                                $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY title as title,postid FROM ^posts WHERE postid=#', $parent['parentid']), true);
                            }
                            $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
                            $link = '<a href="' . $activity_url . '">' . $parent['title'] . '</a>';
                        } else {
                            $activity_url = qa_path_html(qa_q_request($params['postid'], $post['title']), null, qa_opt('site_url'), null, null);
                            $link = '<a href="' . $activity_url . '">' . $post['title'] . '</a>';
                        }
                    }
                } else {
                    if ($post != null && strpos($event['event'], 'q_') !== 0 && strpos($event['event'], 'in_q_') !== 0) {
                        // comment or answer
                        if (!isset($params['parentid'])) {
                            $params['parentid'] = $post['parentid'];
                        }
                        $parent = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $params['parentid']));
                        if ($parent['type'] == 'A') {
                            $parent = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $parent['parentid']));
                        }
                        $anchor = qa_anchor(strpos($event['event'], 'a_') === 0 || strpos($event['event'], 'in_a_') === 0 ? 'A' : 'C', $params['postid']);
                        $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
                        $link = '<a href="' . $activity_url . '">' . $parent['title'] . '</a>';
                    } else {
                        if ($post != null) {
                            // question
                            if (!isset($params['title'])) {
                                $params['title'] = $posts[$params['postid']]['title'];
                            }
                            if ($params['title'] !== null) {
                                $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
                                $link = '<a href="' . $activity_url . '">' . $params['title'] . '</a>';
                            }
                        }
                    }
                }
            }
            $time = $event['datetime'];
            if (qa_opt('user_act_list_shading')) {
                $days = (qa_opt('db_time') - $time) / 60 / 60 / 24;
                $col = round($days / qa_opt('user_act_list_age') * 255 / 2);
                $bkg = 255 - round($days / qa_opt('user_act_list_age') * 255 / 8);
                $bkg = dechex($bkg);
                $col = dechex($col);
                if (strlen($col) == 1) {
                    $col = '0' . $col;
                }
                if (strlen($bkg) == 1) {
                    $bkg = '0' . $bkg;
                }
                $col = '#' . $col . $col . $col;
                $bkg = '#' . $bkg . $bkg . $bkg;
            }
            $whenhtml = qa_html(qa_time_to_string(qa_opt('db_time') - $time));
            $when = qa_lang_html_sub('main/x_ago', $whenhtml);
            $when = str_replace(' ', '<br/>', $when);
            $when = preg_replace('/([0-9]+)/', '<span class="qa-history-item-date-no">$1</span>', $when);
            if (strpos($type, '_vote_nil') == 4) {
                if ($params['oldvote'] == '1') {
                    // unvoting an upvote
                    $points = @$option_events[str_replace('_vote_nil', '_unvote_up', $type)];
                } else {
                    // unvoting a downvote
                    $points = @$option_events[str_replace('_vote_nil', '_unvote_down', $type)];
                }
            } else {
                $points = @$option_events[$type];
            }
            $string = qa_opt('user_act_list_' . $type);
            if ($type == 'badge_awarded') {
                $slug = $params['badge_slug'];
                $typea = qa_get_badge_type_by_slug($slug);
                if (!$typea) {
                    continue;
                }
                $types = $typea['slug'];
                $typed = $typea['name'];
                $badge_name = qa_badge_name($slug);
                if (!qa_opt('badge_' . $slug . '_name')) {
                    qa_opt('badge_' . $slug . '_name', $badge_name);
                }
                $var = qa_opt('badge_' . $slug . '_var');
                $name = qa_opt('badge_' . $slug . '_name');
                $desc = qa_badge_desc_replace($slug, $var, false);
                $string = str_replace('^badge', '<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span>', $string);
            }
            $fields[] = array('type' => 'static', 'label' => '<div class="qa-history-item-date' . ($time >= $last_visit && strpos($type, 'in_') === 0 ? ' qa-history-item-date-new' : '') . '"' . (qa_opt('user_act_list_shading') ? ' style="color:' . $col . ';background-color:' . $bkg . '"' : '') . '>' . $when . '</div>', 'value' => '<table class="qa-history-item-table"><tr><td class="qa-history-item-type-cell"><div class="qa-history-item-type qa-history-item-' . $type . '">' . $string . '</div></td><td class="qa-history-item-title-cell"><div class="qa-history-item-title">' . $link . '</div></td class="qa-history-item-points-cell"><td align="right">' . ($points ? '<div class="qa-history-item-points qa-history-item-points-' . ($points < 0 ? 'neg">' : 'pos">+') . $points . '</div>' : '&nbsp') . '</td></tr></table>');
        }
        if (empty($fields)) {
            return;
        }
        return array('style' => 'wide', 'title' => qa_opt('user_act_list_title'), 'fields' => $fields);
    }
Example #16
0
 function get_full_post($post, $options, $usershtml)
 {
     $fields['raw'] = $post;
     $userid = qa_get_logged_in_userid();
     $cookieid = qa_cookie_get();
     $fields['netvotes_raw'] = (int) $post['netvotes'];
     $postid = $post['postid'];
     $isquestion = $post['basetype'] == 'Q';
     $isanswer = $post['basetype'] == 'A';
     $isbyuser = @$post['userid'] == $userid;
     $anchor = urlencode(qa_anchor($post['basetype'], $postid));
     $elementid = isset($options['elementid']) ? $options['elementid'] : $anchor;
     $microformats = false;
     $isselected = @$options['isselected'];
     // content
     if (@$options['contentview'] && !empty($post['content'])) {
         $viewer = qa_load_viewer($post['content'], $post['format']);
         $fields['content'] = $viewer->get_html($post['content'], $post['format'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
     }
     if ($post['hidden']) {
         $fields['vote_state'] = 'disabled';
     } elseif ($isbyuser) {
         $fields['vote_state'] = 'disabled';
     } elseif (@$post['uservote'] > 0) {
         $fields['vote_state'] = 'voted_up';
     } elseif (@$post['uservote'] < 0) {
         $fields['vote_state'] = 'voted_down';
     } else {
         if (strpos($options['voteview'], '-uponly-level')) {
             $fields['vote_state'] = 'up_only';
         } else {
             $fields['vote_state'] = 'enabled';
         }
     }
     //	Created when and by whom
     $fields['meta_order'] = qa_lang_html('main/meta_order');
     // sets ordering of meta elements which can be language-specific
     if (@$options['whatview']) {
         $fields['what'] = qa_lang_html($isquestion ? 'main/asked' : ($isanswer ? 'main/answered' : 'main/commented'));
         if (@$options['whatlink'] && !$isquestion) {
             $fields['what_url'] = qa_path_html(qa_request(), array('show' => $postid), null, null, qa_anchor($post['basetype'], $postid));
         }
     }
     if (isset($post['created']) && @$options['whenview']) {
         $fields['when'] = qa_when_to_html($post['created'], @$options['fulldatedays']);
     }
     if (@$options['whoview']) {
         $fields['who'] = qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? @$post['createip'] : null, $microformats);
         if (isset($post['points'])) {
             if (@$options['pointsview']) {
                 $fields['who']['points'] = $post['points'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($post['points'])));
             }
             if (isset($options['pointstitle'])) {
                 $fields['who']['title'] = qa_get_points_title_html($post['points'], $options['pointstitle']);
             }
         }
         if (isset($post['level'])) {
             $fields['who']['level'] = qa_html(qa_user_level_string($post['level']));
         }
     }
     $isselected = @$options['isselected'];
     //	Updated when and by whom
     if (isset($post['opostid'])) {
         // updated meta
         switch ($post['obasetype'] . '-' . @$post['oupdatetype']) {
             case 'Q-':
                 $langstring = 'main/asked';
                 break;
             case 'Q-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['hidden'] ? 'main/hidden' : 'main/reshown';
                 break;
             case 'Q-' . QA_UPDATE_CLOSED:
                 $langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened';
                 break;
             case 'Q-' . QA_UPDATE_TAGS:
                 $langstring = 'main/retagged';
                 break;
             case 'Q-' . QA_UPDATE_CATEGORY:
                 $langstring = 'main/recategorized';
                 break;
             case 'A-':
                 $langstring = 'main/answered';
                 break;
             case 'A-' . QA_UPDATE_SELECTED:
                 $langstring = 'main/answer_selected';
                 break;
             case 'A-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['ohidden'] ? 'main/hidden' : 'main/answer_reshown';
                 break;
             case 'A-' . QA_UPDATE_CONTENT:
                 $langstring = 'main/answer_edited';
                 break;
             case 'Q-' . QA_UPDATE_FOLLOWS:
                 $langstring = 'main/asked_related_q';
                 break;
             case 'C-':
                 $langstring = 'main/commented';
                 break;
             case 'C-' . QA_UPDATE_TYPE:
                 $langstring = 'main/comment_moved';
                 break;
             case 'C-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['ohidden'] ? 'main/hidden' : 'main/comment_reshown';
                 break;
             case 'C-' . QA_UPDATE_CONTENT:
                 $langstring = 'main/comment_edited';
                 break;
             case 'Q-' . QA_UPDATE_CONTENT:
             default:
                 $langstring = 'main/edited';
                 break;
         }
         $fields['what_2'] = qa_lang_html($langstring);
         if ($post['obasetype'] != 'Q' || @$post['oupdatetype'] == QA_UPDATE_FOLLOWS) {
             $fields['what_2_url'] = qa_q_path_html($post['postid'], $post['title'], false, $post['obasetype'], $post['opostid']);
         }
         if (@$options['contentview'] && !empty($post['ocontent'])) {
             $viewer = qa_load_viewer($post['ocontent'], $post['oformat']);
             $fields['content_2'] = $viewer->get_html($post['ocontent'], $post['oformat'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
         }
         if (@$options['whenview']) {
             $fields['when_2'] = qa_when_to_html($post['otime'], @$options['fulldatedays']);
         }
         if (@$options['whoview']) {
             $isbyuser = qa_post_is_by_user(array('userid' => $post['ouserid'], 'cookieid' => @$post['ocookieid']), $userid, $cookieid);
             $fields['who_2'] = qa_who_to_html($isbyuser, $post['ouserid'], $usershtml, @$options['ipview'] ? @$post['oip'] : null, false);
             if (isset($post['opoints'])) {
                 if (@$options['pointsview']) {
                     $fields['who_2']['points'] = $post['opoints'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($post['opoints'])));
                 }
                 if (isset($options['pointstitle'])) {
                     $fields['who_2']['title'] = qa_get_points_title_html($post['opoints'], $options['pointstitle']);
                 }
             }
             if (isset($post['olevel'])) {
                 $fields['who_2']['level'] = qa_html(qa_user_level_string($post['olevel']));
             }
         }
     } else {
         if (@$options['updateview'] && isset($post['updated']) && ($post['updatetype'] != QA_UPDATE_SELECTED || $isselected) && (!isset($post['created']) || $post['hidden'] && $post['updatetype'] == QA_UPDATE_VISIBLE || isset($post['closedbyid']) && $post['updatetype'] == QA_UPDATE_CLOSED || abs($post['updated'] - $post['created']) > 300 || $post['lastuserid'] != $post['userid'])) {
             switch ($post['updatetype']) {
                 case QA_UPDATE_TYPE:
                 case QA_UPDATE_PARENT:
                     $langstring = 'main/moved';
                     break;
                 case QA_UPDATE_CATEGORY:
                     $langstring = 'main/recategorized';
                     break;
                 case QA_UPDATE_VISIBLE:
                     $langstring = $post['hidden'] ? 'main/hidden' : 'main/reshown';
                     break;
                 case QA_UPDATE_CLOSED:
                     $langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened';
                     break;
                 case QA_UPDATE_TAGS:
                     $langstring = 'main/retagged';
                     break;
                 case QA_UPDATE_SELECTED:
                     $langstring = 'main/selected';
                     break;
                 default:
                     $langstring = 'main/edited';
                     break;
             }
             $fields['what_2'] = qa_lang_html($langstring);
             if (@$options['whenview']) {
                 $fields['when_2'] = qa_when_to_html($post['updated'], @$options['fulldatedays']);
             }
             if (isset($post['lastuserid']) && @$options['whoview']) {
                 $fields['who_2'] = qa_who_to_html(isset($userid) && $post['lastuserid'] == $userid, $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false);
             }
         }
     }
     $fields['avatar'] = $this->get_post_avatar($post);
     return $fields;
 }
Example #17
0
function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $dummy, $options)
{
    $fields = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $options);
    switch ($question['obasetype']) {
        case 'Q':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/edited') : null;
            break;
        case 'A':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/answer_edited') : qa_lang_html('main/answered');
            break;
        case 'C':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/comment_edited') : qa_lang_html('main/commented');
            break;
    }
    if ($question['obasetype'] != 'Q') {
        $fields['what_url'] = $fields['url'] . '#' . qa_html(urlencode(qa_anchor($question['obasetype'], $question['opostid'])));
    }
    if (@$options['whenview']) {
        $fields['when'] = qa_lang_html_sub_split('main/x_ago', qa_html(qa_time_to_string(qa_opt('db_time') - $question['otime'])));
    }
    if (@$options['whoview']) {
        $isbyuser = qa_post_is_by_user(array('userid' => $question['ouserid'], 'cookieid' => $question['ocookieid']), $userid, $cookieid);
        $fields['who'] = qa_who_to_html($isbyuser, $question['ouserid'], $usershtml, @$options['ipview'] ? $question['oip'] : null, false);
        if (isset($question['opoints'])) {
            if (@$options['pointsview']) {
                $fields['who']['points'] = $question['opoints'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($question['opoints'])));
            }
            if (isset($options['pointstitle'])) {
                $fields['who']['title'] = qa_get_points_title_html($question['opoints'], $options['pointstitle']);
            }
        }
        if (isset($question['olevel'])) {
            $fields['who']['level'] = qa_html(qa_user_level_string($question['olevel']));
        }
    }
    unset($fields['flags']);
    if (@$options['flagsview'] && @$post['oflagcount']) {
        $fields['flags'] = $post['oflagcount'] == 1 ? qa_lang_html_sub_split('main/1_flag', '1', '1') : qa_lang_html_sub_split('main/x_flags', $post['oflagcount']);
    }
    unset($fields['avatar']);
    if (!QA_FINAL_EXTERNAL_USERS && @$options['avatarsize'] > 0) {
        $fields['avatar'] = qa_get_user_avatar_html($question['oflags'], $question['oemail'], $question['ohandle'], $question['oavatarblobid'], $question['oavatarwidth'], $question['oavatarheight'], $options['avatarsize']);
    }
    return $fields;
}
        }
        if ($question['claimable']) {
            $qa_content['q_view']['form']['buttons']['claim'] = array('tags' => 'NAME="doclaimq"', 'label' => qa_lang_html('question/claim_button'));
        }
        if ($question['answerbutton'] && $formtype != 'a_add') {
            // don't show if shown by default
            $qa_content['q_view']['form']['buttons']['answer'] = array('tags' => 'NAME="doanswerq"', 'label' => qa_lang_html('question/answer_button'), 'popup' => qa_lang_html('question/answer_q_popup'));
        }
        if ($question['commentbutton']) {
            $qa_content['q_view']['form']['buttons']['comment'] = array('tags' => 'NAME="docommentq"', 'label' => qa_lang_html('question/comment_button'), 'popup' => qa_lang_html('question/comment_q_popup'));
        }
    }
    //	Information about the question of the answer that this question follows on from (or a question directly)
    if (isset($parentquestion)) {
        $parentquestion['title'] = qa_block_words_replace($parentquestion['title'], qa_get_block_words_preg());
        $qa_content['q_view']['follows'] = array('label' => qa_lang_html($question['parentid'] == $parentquestion['postid'] ? 'question/follows_q' : 'question/follows_a'), 'title' => qa_html($parentquestion['title']), 'url' => qa_path_html(qa_q_request($parentquestion['postid'], $parentquestion['title']), null, null, null, $question['parentid'] == $parentquestion['postid'] ? null : qa_anchor('A', $question['parentid'])));
    }
}
//	Prepare content for an answer being edited (if any)
if ($formtype == 'a_edit') {
    $qa_content['q_view']['a_form'] = qa_page_q_edit_a_form($formpostid);
}
//	Prepare content for comments on the question, plus add or edit comment forms
$qa_content['q_view']['c_list'] = qa_page_q_comment_follow_list($question);
// ...for viewing
if ($formtype == 'c_add' && $formpostid == $questionid) {
    // ...to be added
    $qa_content['q_view']['c_form'] = qa_page_q_add_c_form(null);
} elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $questionid) {
    // ...being edited
    $qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($formpostid, null);
 function doctype()
 {
     //qa_error_log($this->content);
     if ($this->request == 'admin/permissions' && function_exists('qa_register_plugin_phrases') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
         $permits[] = 'expert_question_ask';
         $permits[] = 'expert_question_roles';
         foreach ($permits as $optionname) {
             $value = qa_opt($optionname);
             $optionfield = array('id' => $optionname, 'label' => qa_lang_html('expert_question/' . $optionname) . ':', 'tags' => 'NAME="option_' . $optionname . '" ID="option_' . $optionname . '"', 'error' => qa_html(@$errors[$optionname]));
             $widest = QA_PERMIT_USERS;
             $narrowest = QA_PERMIT_ADMINS;
             $permitoptions = qa_admin_permit_options($widest, $narrowest, !QA_FINAL_EXTERNAL_USERS && qa_opt('confirm_user_emails'));
             if (count($permitoptions) > 1) {
                 qa_optionfield_make_select($optionfield, $permitoptions, $value, $value == QA_PERMIT_CONFIRMED ? QA_PERMIT_USERS : min(array_keys($permitoptions)));
             }
             $this->content['form']['fields'][$optionname] = $optionfield;
             $this->content['form']['fields'][$optionname . '_points'] = array('id' => $optionname . '_points', 'tags' => 'NAME="option_' . $optionname . '_points" ID="option_' . $optionname . '_points"', 'type' => 'number', 'value' => qa_opt($optionname . '_points'), 'prefix' => qa_lang_html('admin/users_must_have') . '&nbsp;', 'note' => qa_lang_html('admin/points'));
             $checkboxtodisplay[$optionname . '_points'] = '(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS) . ') ||(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS_CONFIRMED) . ')';
         }
         qa_set_display_rules($this->content, $checkboxtodisplay);
     }
     $this->expert_user = $this->is_expert_user();
     if (!$this->expert_user) {
         foreach ($this->content['navigation']['main'] as $key => $nav) {
             if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                 unset($this->content['navigation']['main'][$key]);
             }
         }
     }
     if (qa_clicked('do_expert_answeradd') && ($this->expert_user || $this->content['q_view']['raw']['userid'] === qa_get_logged_in_userid())) {
         global $qa_login_userid, $questionid, $question, $answers, $question, $qa_request;
         $innotify = qa_post_text('notify') ? true : false;
         $inemail = qa_post_text('email');
         qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext);
         $isduplicate = false;
         foreach ($answers as $answer) {
             if (!$answer['hidden']) {
                 if (implode(' ', qa_string_to_words($answer['content'])) == implode(' ', qa_string_to_words($incontent))) {
                     $isduplicate = true;
                 }
             }
         }
         if (!$isduplicate) {
             if (!isset($qa_login_userid)) {
                 $qa_cookieid = qa_cookie_get_create();
             }
             // create a new cookie if necessary
             $answerid = qa_answer_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incontent, $informat, $intext, $innotify, $inemail, $question);
             qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_post', $questionid, $answerid, null);
             qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid));
         } else {
             $pageerror = qa_lang_html('question/duplicate_content');
         }
         qa_page_q_load_q();
         // reload since we may have changed something
     }
     if (qa_opt('expert_question_enable')) {
         if ($this->expert_user && qa_opt('expert_question_show_count')) {
             $this->expertcount = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^postmeta, ^posts WHERE ^postmeta.meta_key='is_expert_question' AND ^postmeta.post_id=^posts.postid AND ^posts.acount=0" . (is_array($this->expert_user) ? " AND ^posts.categoryid IN (#)" : " AND \$"), $this->expert_user), true);
             if ($this->expertcount) {
                 foreach ($this->content['navigation']['main'] as $key => $nav) {
                     if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                         $this->content['navigation']['main'][$key]['label'] .= ' (' . $this->expertcount . ')';
                     }
                 }
             }
         }
         global $qa_request;
         if ($qa_request == qa_opt('expert_question_page_url')) {
             $this->content['navigation']['sub'] = array('special' => 1);
         }
         if ($this->template == 'ask' && in_array(qa_opt('expert_question_type'), array(0, 2)) && !qa_user_permit_error('permit_post_q') && !qa_permit_value_error(qa_opt('expert_question_ask'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()) && !qa_opt('site_maintenance')) {
             $this->content['form']['fields'][] = array('tags' => 'NAME="is_expert_question" ID="is_expert_question"', 'value' => qa_get(qa_opt('expert_question_page_url')) == 'true' ? qa_opt('expert_question_yes') : qa_opt('expert_question_no'), 'type' => 'select-radio', 'options' => array('no' => qa_opt('expert_question_no'), 'yes' => qa_opt('expert_question_yes')));
         }
         if ($this->template == 'user' && qa_get_logged_in_handle() === $this->_user_handle()) {
             if (!isset($this->content['navigation']['sub'])) {
                 $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), qa_opt('expert_question_page_url') => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false));
             } else {
                 $this->content['navigation']['sub'][qa_opt('expert_question_page_url')] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false);
             }
         }
         if ($this->template == 'question') {
             $qid = $this->content['q_view']['raw']['postid'];
             $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $qid), true);
             if ($expert) {
                 // is expert question
                 $this->expert_question = 1;
                 // modify post elements
                 // title
                 $this->content['title'] .= ' ' . qa_opt('expert_question_title');
                 // css class
                 $this->content['q_view']['tags'] .= ' class="qa-expert-question"';
                 // remove hidden stuff
                 unset($this->content['q_view']['hidden']);
                 unset($this->content['hidden']);
             }
         }
     }
     qa_html_theme_base::doctype();
 }
Example #20
0
 function post($event, $userid, $handle, $params, $type)
 {
     // remove mentions
     if (!qa_opt('buddypress_mentions')) {
         remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates');
     }
     switch ($type) {
         case 'Q':
             $suffix = ' question ';
             break;
         case 'A':
             $suffix = 'n %answer% to the question ';
             break;
         case 'C':
             $suffix = ' %comment% on the question ';
             break;
     }
     // poll integration
     if (qa_post_text('is_poll')) {
         if ($type == 'A') {
             return;
         }
         if ($type == 'Q') {
             $suffix = str_replace('question', 'poll', $suffix);
         } else {
             $suffix = str_replace('question', 'poll', $suffix);
         }
     }
     $content = $params['content'];
     // activity post
     if ($event != 'q_post') {
         $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $params['parentid']), true);
         if ($parent['type'] == 'A') {
             $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $parent['parentid']), true);
         }
         $anchor = qa_anchor($event == 'a_post' ? 'A' : 'C', $params['postid']);
         $suffix = preg_replace('/%([^%]+)%/', '<a href="' . qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor) . '">$1</a>', $suffix);
         $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $parent['title'] . '</a>"';
     } else {
         $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $params['title'] . '</a>"';
     }
     if (qa_opt('buddypress_display_names')) {
         $name = bp_core_get_user_displayname($handle) ? bp_core_get_user_displayname($handle) : $handle;
     } else {
         $name = $handle;
     }
     $action = '<a href="' . bp_core_get_user_domain($userid) . '" rel="nofollow">' . $name . '</a> posted a' . $context . ' at <a href="' . qa_opt('site_url') . '">' . qa_opt('site_title') . '</a>';
     if (qa_opt('buddypress_integration_include_content')) {
         $informat = $params['format'];
         $viewer = qa_load_viewer($content, $informat);
         if (qa_opt('buddypress_integration_max_post_length') && strlen($content) > (int) qa_opt('buddypress_integration_max_post_length')) {
             $content = substr($content, 0, (int) qa_opt('buddypress_integration_max_post_length'));
             $content = $content . ' ...';
         }
         $content = $viewer->get_html($content, $informat, array());
     } else {
         $content = null;
     }
     global $phpmailer;
     if (class_exists('PHPMailer') && !is_object($phpmailer)) {
         $phpmailer = new PHPMailer(true);
     }
     $act_id = qa_buddypress_activity_post(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-qa', 'type' => 'activity_qa_' . $type, 'user_id' => $userid, 'item_id' => null));
 }
Example #21
0
function ra_user_badges_list($userid)
{
    if (!qa_opt('badge_active')) {
        return;
    }
    $handles = qa_userids_to_handles(array($userid));
    $handle = $handles[$userid];
    // displays badge list in user profile
    $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT badge_slug as slug, object_id AS oid FROM ^userbadges WHERE user_id=#', $userid));
    if (count($result) > 0) {
        // count badges
        $bin = qa_get_badge_list();
        $badges = array();
        foreach ($result as $info) {
            $slug = $info['slug'];
            $type = $bin[$slug]['type'];
            if (isset($badges[$type][$slug])) {
                $badges[$type][$slug]['count']++;
            } else {
                $badges[$type][$slug]['count'] = 1;
            }
            if ($info['oid']) {
                $badges[$type][$slug]['oid'][] = $info['oid'];
            }
        }
        foreach ($badges as $type => $badge) {
            $typea = qa_get_badge_type($type);
            $types = $typea['slug'];
            $typed = $typea['name'];
            $output = '';
            //$output = '<h3 class="badge-title" title="'.qa_lang('badges/'.$types.'_desc').'">'.$typed.'</h3>';
            foreach ($badge as $slug => $info) {
                $badge_name = qa_badge_name($slug);
                if (!qa_opt('badge_' . $slug . '_name')) {
                    qa_opt('badge_' . $slug . '_name', $badge_name);
                }
                $name = qa_opt('badge_' . $slug . '_name');
                $count = $info['count'];
                if (qa_opt('badge_show_source_posts')) {
                    $oids = @$info['oid'];
                } else {
                    $oids = null;
                }
                $var = qa_opt('badge_' . $slug . '_var');
                $desc = qa_badge_desc_replace($slug, $var, false);
                // badge row
                $output .= '<div class="badge-container-badge">
									<span class="user-badge ' . $types . ' icon-badge" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span>&nbsp;<span class="badge-count">x&nbsp;' . $count . '</span>' . (is_array($oids) ? '<i class="icon-chevron-down"></i>' : '');
                // source row(s) if any
                if (is_array($oids)) {
                    $output .= '
								<div class="badge-sources ' . $slug . '"><ul>';
                    foreach ($oids as $oid) {
                        $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $oid));
                        $title = $post['title'];
                        $anchor = '';
                        if ($post['parentid']) {
                            $anchor = urlencode(qa_anchor($post['type'], $oid));
                            $oid = $post['parentid'];
                            $title = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY title as title FROM ^posts WHERE postid=#', $oid), true);
                        }
                        //$length = 30;
                        $text = $title;
                        $output .= '<li><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></li>';
                    }
                    $output .= '</ul></div>';
                }
                $output .= '</div>';
            }
            $outa[] = $output;
        }
        $fields = '<div class="badge-user-block widget"><h3 class="widget-title">' . _ra_lang('Badges') . '</h3><div class="widget-inner">' . implode('', $outa) . '</div></div>';
    }
    return $fields;
}
function qa_page_q_comment_follow_list($parent, $commentsfollows, $alwaysfull, $usershtml, $formrequested, $formpostid)
{
    $parentid = $parent['postid'];
    $userid = qa_get_logged_in_userid();
    $cookieid = qa_cookie_get();
    $commentlist = array('tags' => 'ID="c' . qa_html($parentid) . '_list"', 'cs' => array());
    $showcomments = array();
    foreach ($commentsfollows as $commentfollowid => $commentfollow) {
        if ($commentfollow['parentid'] == $parentid && $commentfollow['viewable'] && $commentfollowid != $formpostid) {
            $showcomments[$commentfollowid] = $commentfollow;
        }
    }
    $countshowcomments = count($showcomments);
    if (!$alwaysfull && $countshowcomments > qa_opt('show_fewer_cs_from')) {
        $skipfirst = $countshowcomments - qa_opt('show_fewer_cs_count');
    } else {
        $skipfirst = 0;
    }
    if ($skipfirst == $countshowcomments) {
        // showing none
        if ($skipfirst == 1) {
            $expandtitle = qa_lang_html('question/show_1_comment');
        } else {
            $expandtitle = qa_lang_html_sub('question/show_x_comments', $skipfirst);
        }
    } else {
        if ($skipfirst == 1) {
            $expandtitle = qa_lang_html('question/show_1_previous_comment');
        } else {
            $expandtitle = qa_lang_html_sub('question/show_x_previous_comments', $skipfirst);
        }
    }
    if ($skipfirst > 0) {
        $commentlist['cs'][$parentid] = array('url' => qa_html('?state=showcomments-' . $parentid . '&show=' . $parentid . '#' . urlencode(qa_anchor($parent['basetype'], $parentid))), 'expand_tags' => 'onClick="return qa_show_comments(' . qa_js($parentid) . ', this);"', 'title' => $expandtitle);
    }
    foreach ($showcomments as $commentfollowid => $commentfollow) {
        if ($skipfirst > 0) {
            $skipfirst--;
        } elseif ($commentfollow['basetype'] == 'C') {
            $commentlist['cs'][$commentfollowid] = qa_page_q_comment_view($parent, $commentfollow, $usershtml, $formrequested);
        } elseif ($commentfollow['basetype'] == 'Q') {
            $htmloptions = qa_post_html_defaults('Q');
            $htmloptions['avatarsize'] = qa_opt('avatar_q_page_c_size');
            $commentlist['cs'][$commentfollowid] = qa_post_html_fields($commentfollow, $userid, $cookieid, $usershtml, null, $htmloptions);
        }
    }
    if (!count($commentlist['cs'])) {
        $commentlist['hidden'] = true;
    }
    return $commentlist;
}
 function qa_ajax_comment_form()
 {
     global $qa_content, $incomment, $informat, $errors, $questionid, $ineditor, $innotify, $inemail, $jumptoanchor, $focusonid, $usecaptcha, $qa_login_userid;
     $jumptoanchor = isset($answerid) ? qa_anchor('A', $answerid) : qa_anchor('Q', $questionid);
     $focusonid = 'comment';
     $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_cs');
     $editor = qa_load_editor(@$incomment, @$informat, $editorname);
     $form = array('title' => qa_lang_html(isset($answerid) ? 'question/your_comment_a' : 'question/your_comment_q'), 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, @$incomment, @$informat, 'comment', 4, true), array('error' => qa_html(@$errors['content']), 'rows' => 8))), 'buttons' => array('comment' => array('tags' => 'onclick="ajaxPostComment()"', 'label' => qa_lang_html('question/add_comment_button'), 'ajax_comment' => $this->idx2), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'), 'ajax_comment' => $this->idx2)), 'hidden' => array('editor' => qa_html($editorname)));
     $form['fields']['content']['tags'] = @$form['fields']['tags'] . ' id="comment" onkeydown="if(event.keyCode == 27) toggleComment(false);"';
     // add reminder text if commenting on answer to own question
     $ourid = qa_get_logged_in_userid();
     if (qa_opt('ajax_comment_answer_reminder') && !$this->content['q_view']['raw']['selchildid'] && isset($answerid) && $this->content['q_view']['raw']['userid'] == $ourid && @$this->content['a_list']['as'][$this->idx - 1]['raw']['userid'] != $ourid) {
         $form['fields']['custom_message'] = array('note' => '<div class="ajax-comment-reminder">' . qa_opt('ajax_comment_answer_reminder_text') . '</div>', 'type' => 'static');
     }
     qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($innotify) ? $innotify : qa_opt('notify_users_default'), @$inemail, @$errors['email']);
     if ($usecaptcha) {
         qa_set_up_captcha_field($qa_content, $form['fields'], @$errors, qa_insert_login_links(qa_lang_html(isset($qa_login_userid) ? 'misc/captcha_confirm_fix' : 'misc/captcha_login_fix')));
     }
     $form['ajax_comment'] = 0;
     $this->idx2++;
     return $form;
 }
Example #24
0
    public function activitylist()
    {
        $offset = (int) qa_get('offset');
        $offset = isset($offset) ? $offset * 15 : 0;
        // get points for each activity
        require_once QA_INCLUDE_DIR . 'qa-db-points.php';
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        $optionnames = qa_db_points_option_names();
        $options = qa_get_options($optionnames);
        $multi = (int) $options['points_multiple'];
        $upvote = '';
        $downvote = '';
        if (@$options['points_per_q_voted_up']) {
            $upvote = '_up';
            $downvote = '_down';
        }
        $event_point['in_q_vote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi;
        $event_point['in_q_vote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi * -1;
        $event_point['in_q_unvote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi * -1;
        $event_point['in_q_unvote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi;
        $event_point['a_vote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi;
        $event_point['in_a_vote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi * -1;
        $event_point['in_a_unvote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi * -1;
        $event_point['in_a_unvote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi;
        $event_point['in_a_select'] = (int) $options['points_a_selected'] * $multi;
        $event_point['in_a_unselect'] = (int) $options['points_a_selected'] * $multi * -1;
        $event_point['q_post'] = (int) $options['points_post_q'] * $multi;
        $event_point['a_post'] = (int) $options['points_post_a'] * $multi;
        $event_point['a_select'] = (int) $options['points_select_a'] * $multi;
        $event_point['q_vote_up'] = (int) $options['points_vote_up_q'] * $multi;
        $event_point['q_vote_down'] = (int) $options['points_vote_down_q'] * $multi;
        $event_point['a_vote_up'] = (int) $options['points_vote_up_a'] * $multi;
        $event_point['a_vote_down'] = (int) $options['points_vote_down_a'] * $multi;
        // Get Events
        $userid = qa_get_logged_in_userid();
        $eventslist = qa_db_read_all_assoc(qa_db_query_sub('SELECT id, UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params, `read` FROM ^ra_userevent WHERE effecteduserid=# AND `read`=0 AND event NOT IN ("u_wall_post", "u_message") ORDER BY datetime DESC LIMIT 15 OFFSET #', $userid, $offset));
        if (count($eventslist) > 0) {
            $event = array();
            $output = '';
            $i = 0;
            //
            $userids = array();
            foreach ($eventslist as $event) {
                $userids[$event['userid']] = $event['userid'];
                $userids[$event['effecteduserid']] = $event['effecteduserid'];
            }
            if (QA_FINAL_EXTERNAL_USERS) {
                $handles = qa_get_public_from_userids($userids);
            } else {
                $handles = qa_db_user_get_userid_handles($userids);
            }
            // get event's: time, type, parameters
            // get post id of questions
            foreach ($eventslist as $event) {
                $title = '';
                $link = '';
                $vote_status = '';
                $handle = isset($handles[$event['userid']]) ? $handles[$event['userid']] : qa_lang('main/anonymous');
                $datetime = $event['datetime'];
                $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
                $event['params'] = json_decode($event['params'], true);
                $id = ' data-id="' . $event['id'] . '"';
                $read = $event['read'] ? ' read' : ' unread';
                $url_param = array('ra_notification' => $event['id']);
                $user_link = qa_path_html('user/' . $handle, $url_param, QW_BASE_URL);
                switch ($event['event']) {
                    case 'related':
                        // related question to an answer
                        $url = qa_path_html(qa_q_request($event['postid'], $event['params']['title']), $url_param, QW_BASE_URL, null, null);
                        echo '<div class="event-content clearfix' . $read . '' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/asked_question_related_to_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-link"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_post':
                        // user's question had been answered
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        $title = qw_truncate($event['params']['qtitle'], 60);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/answered_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-answer"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_post':
                        // user's question had been commented
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        if ($event['params']['parenttype'] == 'Q') {
                            $type = qa_lang_html('dude/question');
                        } elseif ($event['params']['parenttype'] == 'A') {
                            $type = qa_lang_html('dude/answer');
                        } else {
                            $type = qa_lang_html('dude/comment');
                        }
                        if (isset($event['params']['parent_uid']) && $event['params']['parent_uid'] != $userid) {
                            $what = qa_lang_html('dude/followup_comment');
                            $type = qa_lang_html('dude/comment');
                        } else {
                            $what = qa_lang_html('dude/replied_to_your');
                        }
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . $what . '</span>
											<strong class="where">' . $type . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-arrow-back"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_reshow':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/question') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_reshow':
                        // user's question had been answered
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/answer') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_reshow':
                        // user's question had been answered
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/comment') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_select':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/selected_as_best') . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-award"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_post']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_vote_up':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        $title = qw_truncate($event['params']['qtitle'], 60);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/upvoted_on_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-thumb-up"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_vote_up':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/upvoted_on_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-thumb-up"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_approve':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_approve':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_favorite':
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $user_link . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/added_you_to') . '</span>
											<strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-heart"></span>									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_favorite':
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $user_link . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/added_your_question_to') . '</span>
											<strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-heart"></span>									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_vote_down':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-thumb-down" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span class="what">' . qa_lang_html('dude/you_have_received_down_vote') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="points">' . qa_lang_sub('dude/you_have_lost_x_points', $event_point['q_vote_down']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_approve':
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/comment') . '</strong>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_reject':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_question_is_rejected') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_reject':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_answer_is_rejected') . '</span>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_reject':
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_comment_is_rejected') . '</span>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_level':
                        $url = qa_path_absolute('user/' . $event['params']['handle']);
                        $old_level = $event['params']['oldlevel'];
                        $new_level = $event['params']['level'];
                        if ($new_level < $old_level) {
                            break;
                        }
                        $approved_only = "";
                        if ($new_level == QA_USER_LEVEL_APPROVED && $old_level < QA_USER_LEVEL_APPROVED) {
                            $approved_only = true;
                        } else {
                            $approved_only = false;
                        }
                        if ($approved_only === false) {
                            $new_designation = qw_get_user_desg($new_level);
                        }
                        $content = strtr(qa_lang($approved_only ? 'notification/u_level_approved_notf' : 'notification/u_level_improved_notf'), array('^new_designation' => @$new_designation));
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-user" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . $content . '</span>
										</div>
										<div class="footer">
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                }
            }
        } else {
            echo '<div class="no-more-activity">' . qa_lang_html('dude/no_more_activity') . '</div>';
        }
        die;
    }
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $parent = isset($answer) ? $answer : $question;
    $postid = qa_db_post_create('C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!($question['hidden'] || @$answer['hidden'])) {
        // don't index comment if parent or parent of parent is hidden
        qa_post_index($postid, 'C', $question['postid'], null, $text, null);
    }
    qa_db_points_update_ifuser($userid, 'cposts');
    qa_db_ccount_update();
    //	$senttoemail and $senttouserid ensure each user or email gets only one notification about an added comment,
    //	even if they have several previous comments in the same thread and asked for notifications for the parent.
    //	Still, if a person posted some comments as a registered user and some others anonymously,
    //	they could get two emails about a subsequent comment. Shouldn't be much of a problem in practice.
    $senttoemail = array();
    $senttouserid = array();
    switch ($parent['basetype']) {
        case 'Q':
            $subject = qa_lang('emails/q_commented_subject');
            $body = qa_lang('emails/q_commented_body');
            $context = $parent['title'];
            break;
        case 'A':
            $subject = qa_lang('emails/a_commented_subject');
            $body = qa_lang('emails/a_commented_body');
            $context = qa_viewer_text($parent['content'], $parent['format']);
            break;
    }
    $blockwordspreg = qa_get_block_words_preg();
    $sendhandle = isset($handle) ? $handle : qa_lang('main/anonymous');
    $sendcontext = qa_block_words_replace($context, $blockwordspreg);
    $sendtext = qa_block_words_replace($text, $blockwordspreg);
    $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
    $sendurl = qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor($parent['basetype'], $parent['postid']));
    if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
        $senduserid = $parent['userid'];
        $sendemail = @$parent['notify'];
        if (qa_email_validate($sendemail)) {
            $senttoemail[$sendemail] = true;
        } elseif (isset($senduserid)) {
            $senttouserid[$senduserid] = true;
        }
        qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
            // find just those for this parent
            if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                $senduserid = $comment['userid'];
                $sendemail = @$comment['notify'];
                if (qa_email_validate($sendemail)) {
                    if (@$senttoemail[$sendemail]) {
                        continue;
                    }
                    $senttoemail[$sendemail] = true;
                } elseif (isset($senduserid)) {
                    if (@$senttouserid[$senduserid]) {
                        continue;
                    }
                    $senttouserid[$senduserid] = true;
                }
                qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
            }
        }
    }
    qa_report_event('c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
function qa_page_q_refresh($start = 0, $state = null, $showtype = null, $showid = null)
{
    $params = array();
    if ($start > 0) {
        $params['start'] = $start;
    }
    if (isset($state)) {
        $params['state'] = $state;
    }
    if (isset($showtype) && isset($showid)) {
        $anchor = qa_anchor($showtype, $showid);
        $params['show'] = $showid;
    } else {
        $anchor = null;
    }
    qa_redirect(qa_request(), $params, null, null, $anchor);
}
function qa_page_q_edit_c_form($commentid, $answerid)
{
    global $commentsfollows, $qa_content, $errors, $incomment, $informat, $ineditor, $questionid, $jumptoanchor, $focusonid, $innotify, $inemail;
    $comment = $commentsfollows[$commentid];
    $content = isset($incomment) ? $incomment : $comment['content'];
    $format = isset($informat) ? $informat : $comment['format'];
    $editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_cs');
    $editor = qa_load_editor($content, $format, $editorname);
    $jumptoanchor = isset($answerid) ? qa_anchor('A', $answerid) : qa_anchor('Q', $questionid);
    $form = array('title' => '<A NAME="edit">' . qa_lang_html('question/edit_c_title') . '</A>', 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, $content, $format, 'comment', 4, true), array('error' => qa_html($errors['content'])))), 'buttons' => array('save' => array('label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array('editor' => qa_html($editorname), 'dosavec_' . qa_html($commentid) => '1'));
    if ($comment['isbyuser']) {
        qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($innotify) ? $innotify : !empty($comment['notify']), isset($inemail) ? $inemail : @$comment['notify'], @$errors['email']);
    }
    return $form;
}